# Temperature Control of an Alkaline Electrolyser

The chosen Hybrid system is a model aproximation to a temperature control used at ITBA’s Alkaline Electrolyser. Electrolysis is an exothermic process which produces heating of KOH solution. Intending to analyze process efficience as a function of temperature, it is considered a group of temperatures to make tests. With this results, relationships between power consumed, production of gases and their purity will be concluded.
To maintain system temperature $T_1$, it is considered natural convection $\dot{Q}_{NC}$ with environment temperature $T_0$ of the entire equipment, and dissipated power by a cooling system composed of a countercurrent flow of water and a radiator which also interacts with the environment, $\dot{Q}_{Cool}$. For this approximation it will be considered without the intermediate step of cooling water: $\dot{Q}_{Cool} = K_{Cool}.(T_0 - T_1)$.
This system can be considered Hybrid because of the Cooling System Switching. Through state of q, it is shown the activation of $\dot{Q}_{Cool}$.

Then, the proposed model is:
$\mathcal{H}=(C,f,D,g) \\ \\ x=\left[ \begin{array}{c} x \\ q \end{array} \right] \\ \\ C=\left\{x\in\mathbb{R}^2/(T > T_{min}\; \& \;q=0)\;|\; (T < T_{MAX}\; \& \;q=1) \right \} \\ \\ D=\left\{x\in\mathbb{R}^2/(T\geqslant T_{MAX}\; \& \;q=0)\;|\; (T\leq T_{min}\; \& \;q=1) \right \} \\ \\ f(x)=\begin{bmatrix} 0 \\ \frac{\dot{Q}+[K_{NC}+q.K_{Cool}.(T_0-T_1)]}{C} \end{bmatrix} \\ \\ \\ g(x)=\begin{bmatrix} 1-q \\ T \end{bmatrix}$

Used parameters are:
$T_{Min} = 40 \;^{o}\textrm{C} \\ T_{Max} = 45 \;^{o}\textrm{C} \\ T_{Env} = 20 \;^{o}\textrm{C} \\ \dot{Q} = 1000 \;kW \\ K_{NC} = 5 \;kW/K \\ K_{Cool} = 50 \;kW/K$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function run
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function run

Parameters

% initial conditions
q_0 = 0;
Temp_0 = 20;
x0 = [q_0;Temp_0];

% simulation horizon
TSPAN=[0 1000];
JSPAN = [0 20];

% rule for jumps
% rule = 1 -> priority for jumps
% rule = 2 -> priority for flows
rule = 1;

options = odeset('RelTol',1e-6,'MaxStep',.1);

maxStepCoefficient = .1;  % set the maximum step length. At each run of the
% integrator the option 'MaxStep' is set to
% (time length of last integration)*maxStepCoefficient.
%  Default value = 0.1

% simulate
[t x j] = HyEQsolver( @f,@g,@C,@D,x0,TSPAN,JSPAN,rule,options,maxStepCoefficient);

% plot solution
figure(1) % position
clf
subplot(2,1,1),plotflows(t,j,x(:,1))
grid on
ylabel('q')

subplot(2,1,2),plotjumps(t,j,x(:,1))
grid on
ylabel('q')

figure(2) % velocity
clf
subplot(2,1,1),plotflows(t,j,x(:,2))
grid on
ylabel('Temp')

subplot(2,1,2),plotjumps(t,j,x(:,2))
grid on
ylabel('Temp')

% plot hybrid arc
plotHybridArc(t,j,x(:,2))
xlabel('j')
ylabel('t')
zlabel('Temp')

% figure(3)
% plot(t,y(:,1));


Parameters (Parameters.m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of Parameters for Model of Cooling Hysteresis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global TempMin TempMax Q Knatconv Kcool TempEnv

TempMin = 50;   % °C
TempMax = 55;   % °C

Q = 1000;       % kW
Knatconv = 5;   % kW/K
Kcool = 50;   % kW/K
TempEnv = 20;   % °C


Flow map (f.m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declaration of Flow Map F
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function xdot = f(x)

% Parameters
global Q        % kW
global Knatconv	% kW/K
global Kcool	% kW/K
global TempEnv	% °C

% State variables
q = x(1);
Temp = x(2);

% Differential equations
xdot = [0 ; (Q + (Knatconv + q * Kcool) * (TempEnv - Temp)) / 1000];
end


Flow set (C.m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declaration of Flow Set C
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function inC = C(x)

% Out:
%   0 if value is outside C
%   1 if value is inside C

global TempMin
global TempMax

q = x(1);
Temp = x(2);

if (((Temp < TempMax) && (q == 0)) || ((Temp > TempMin) && (q == 1)))
inC = 1;
else
inC = 0;
end
end


Jump map (g.m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declaration of Jump Map G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function xplus = g(x)

% State variables
q = x(1);
Temp = x(2);

xplus = [1-q ; Temp];
end


Jump set (D.m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declaration of Jump Set D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function inD = D(x)

% Out:
%   0 if value is outside D
%   1 if value is inside D

global TempMin
global TempMax

q = x(1);
Temp = x(2);

if (((Temp <= TempMin) && (q == 1)) || ((Temp >= TempMax) && (q == 0)))
inD = 1;
else
inD = 0;
end
end


Figures 1 and 2 represents temperature $T_1$ and Hybrid arc $\phi$, as a function of continuous and discrete time, $t$ and $j$.