Finally it was not a good idea to use blocks since it did not correctly model the behavior of a stratified tank. I saw that there were a lot of posts from people who had tried to create the code for a laminated tank. I give you what I did :
component stratifiedTank
% Stratified Tank
% This block implements a stratified tank from the modelling proposed in https://iopscience.iop.org/article/10.1088/1742-6596/2173/1/012005/pdf and adapted by myself
nodes
A = foundation.thermal_liquid.thermal_liquid ;% A:top
B = foundation.thermal_liquid.thermal_liquid ; % B:bottom
H = foundation.thermal.thermal;% H:top
end
parameters
section = {1,"m^2"}; %Section
largeur = {1,"m"};%Largeur
longueur = {1,"m"}; %Longueur
h = {50,"W/(m^2*K)"}; % Coefficient de convection thermique eau/eau
hauteurT = {1,"m"};
Tini1 = {290,"K"};
Tini2 = {290,"K"};
Tini3 = {290,"K"};
cp = {4184,"J/(kg*K)"}
rho = {1000,"kg/m^3"}
end
outputs
out1 = {0,"K"};% T1:bottom
out2 = {0,"K"};% T2:top
out3 = {0,"K"};% T3:top
end
variables
T1 = Tini1;
T2 = Tini2;
T3 = Tini3;
mdot_A = {0, 'kg/s'}; % Mass flow rate into port A
Phi_A = {0, 'kW' }; % Energy flow rate into port A
Q_H = {0, 'kW' }; % Heat flow rate into port H
mdot_B = {0, 'kg/s'}; % Mass flow rate into port B
Phi_B = {0, 'kW' }; % Energy flow rate into port B
mdot1 = {0,"kg/s"}
mdot2 = {0,"kg/s"}
mdot3 = {0,"kg/s"}
F1c = 0
F2c= 0
F3c = 0
F1l = 0
F2l = 0
F3l = 0
T1der = {0,"K/s"}
T2der = {0,"K/s"}
T3der = {0,"K/s"}
end
branches
mdot_A : A.mdot -> *;
mdot_B : B.mdot -> *;
Phi_A : A.Phi -> *;
Phi_B : B.Phi -> *;
Q_H : H.Q -> *;
end
intermediates
g = {9.81,"m/s^2"};
hL = hauteurT/3
end
equations
out1 == T1;
out2 == T2;
out3 == T3;
B.p == A.p + hauteurT*g*rho;
if A.T >= T1
F1c == 1
else
F1c == 0
end
if T1 >= A.T && A.T > T2
F2c == 1
else
F2c == 0
end
if T2 >= A.T && A.T > T3
F3c == 1
else
F3c == 0
end
if B.T<= T3
F3l == 1
else
F3l == 0
end
if T3<B.T && B.T<= T2
F2l == 1
else
F2l == 0
end
if T1<B.T && B.T<= T2
F1l == 1
else
F1l == 0
end
mdot1 == 0
mdot3 == 0
mdot2 == mdot_A*F1c-mdot_B*(F2l+F3l)
T1der == der(T1)
T2der==der(T2)
T3der == der(T3)
mdot_A + mdot_B == 0
% Energy conservation
0 == Phi_A + Phi_B+Q_H
Q_H == h*2*(longueur+largeur)*hL* (3*H.T - T1-T2-T3)
rho*hL*section*cp*(T1der+T2der+T3der) == Q_H
if mdot2 <0
rho * hL * section * T1der== h*2*(longueur+largeur)*hL/cp* (H.T - T1) + F1c * mdot_A * (A.T - T1) + F1l * mdot_B * (B.T - T1) + mdot2*(T1-T2)
else
rho * hL * section * T1der == h*2*(longueur+largeur)*hL/cp * (H.T - T1) + F1c * mdot_A * (A.T - T1) + F1l * mdot_B * (B.T - T1)
end
if mdot2 > 0
if mdot3 <0
rho * hL * section * T2der == h*2*(longueur+largeur)*hL/cp * (H.T - T2) + F2c * mdot_A * (A.T - T2) + F2l * mdot_B * (B.T - T2) + mdot3*(T2-T3) + mdot2 * (T1-T2)
else
rho * hL * section * T2der == h*2*(longueur+largeur)*hL/cp * (H.T - T2) + F2c * mdot_A * (A.T - T2) + F2l * mdot_B * (B.T - T2) + mdot2 * (T1-T2)
end
else
if mdot3 <0
rho * hL * section * T2der == h*2*(longueur+largeur)*hL/cp * (H.T - T2) + F2c * mdot_A * (A.T - T2) + F2l * mdot_B * (B.T - T2) + mdot3*(T2-T3)
else
rho * hL * section * T2der == h*2*(longueur+largeur)*hL/cp * (H.T - T2) + F2c * mdot_A * (A.T - T2) + F2l * mdot_B * (B.T - T2)
end
end
if mdot2 >0
rho * hL * section * T3der == h*2*(longueur+largeur)*hL/cp * (H.T - T3) + F3c * mdot_A * (A.T - T3) + F3l * mdot_B * (B.T - T3) + mdot3*(T2-T3)
else
rho * hL * section * T3der == h*2*(longueur+largeur)*hL/cp * (H.T - T3) + F3c * mdot_A * (A.T - T3) + F3l * mdot_B * (B.T - T3)
end
end
end

