Skip to content

Commit a654e28

Browse files
authored
Merge pull request #8 from antoniofroio/fixes
Added model Gas.Utilities.ClosedSystemInit
2 parents 65c8a5c + 04289e0 commit a654e28

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

ThermoPower/Gas.mo

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,85 @@ The packages Medium are redeclared and a mass balance determines the composition
27442744
</html>"));
27452745
end FanMech;
27462746

2747+
package Utility "Utility models"
2748+
2749+
model ClosedSystemInit
2750+
"Component for the steady-state initialization of closed systems"
2751+
replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
2752+
"Medium model"
2753+
annotation(choicesAllMatching = true);
2754+
parameter Medium.AbsolutePressure pstart "Start value of pressure";
2755+
parameter Boolean initEquationFromInput = false
2756+
"Get initial condition residual from input connector"
2757+
annotation(Dialog(group="External inputs"), choices(checkBox=true));
2758+
parameter Boolean useHomotopy
2759+
"Use homotopy for residual-based initialization";
2760+
final parameter Medium.MassFlowRate w_b(fixed = false, start = 0)
2761+
"Initial balance flow rate eventually equal to zero";
2762+
outer ThermoPower.System system "System wide properties";
2763+
2764+
FlangeB flange(redeclare package Medium = Medium, m_flow(min = 0))
2765+
annotation (Placement(transformation(extent={{-20,-100},{20,-60}},
2766+
rotation=0),
2767+
iconTransformation(extent={{-20,-100},{20,-60}})));
2768+
Modelica.Blocks.Interfaces.RealInput initEquationResidual if initEquationFromInput
2769+
"Residual of initial equation" annotation (Placement(transformation(extent={
2770+
{-60,0},{-20,40}}), iconTransformation(extent={{-60,-10},{-40,10}})));
2771+
protected
2772+
Modelica.Blocks.Interfaces.RealInput initEquationResidual_int
2773+
"Hidden internal connector for conditional connection";
2774+
equation
2775+
0 = flange.m_flow + w_b "Mass balance";
2776+
flange.h_outflow = Medium.h_default
2777+
"Unused value as there is no flow out of the flange";
2778+
flange.Xi_outflow = Medium.X_default[1:Medium.nXi]
2779+
"Unused value as there is no flow out of the flange";
2780+
2781+
connect(initEquationResidual, initEquationResidual_int)
2782+
"Connects conditional input to hidden connector";
2783+
2784+
if not initEquationFromInput then
2785+
initEquationResidual_int = 0 "Not used";
2786+
end if;
2787+
2788+
initial equation
2789+
if initEquationFromInput then
2790+
if useHomotopy then
2791+
homotopy(initEquationResidual_int, (flange.p - pstart)/pstart) = 0
2792+
"Set initial value of residual to zero, simplified equation sets start value of pressure";
2793+
else
2794+
initEquationResidual_int = 0 "Set initial value of residual to zero";
2795+
end if;
2796+
else
2797+
flange.p = pstart "Set initial value of pressure";
2798+
end if;
2799+
2800+
annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
2801+
Line(
2802+
points={{0,0},{0,-60}},
2803+
color={159,159,223},
2804+
thickness=0.5),
2805+
Ellipse(
2806+
extent={{-40,40},{40,-40}},
2807+
lineColor={159,159,223},
2808+
fillColor={159,159,223},
2809+
fillPattern=FillPattern.Solid),
2810+
Text(
2811+
extent={{-32,24},{30,-24}},
2812+
lineColor={255,255,255},
2813+
lineThickness=0.5,
2814+
fillColor={0,0,255},
2815+
fillPattern=FillPattern.Solid,
2816+
textString="Init")}), Diagram(
2817+
coordinateSystem(preserveAspectRatio=false)),
2818+
Documentation(info="<html>
2819+
<p>This component can be used for the steady-state initialization of closed-system where all components have steady-state initial conditions. Without this component such systems would give rise to undetermined initial conditions, i.e., the amount of fluid and the initial pressures in the system would be unspecified.</p>
2820+
<p>Connect the component to one point of the system. If <code>initEquationFromInput = false</code>, the system is initialized with pressure equal to <code>pstart</code> at the connection point.</p>
2821+
<p>It is possible to use a generic initial equation instead of <code>p = pstart</code>, e.g., to set the initial charge of a refrigeration circuit, by setting <code>initEquationFromInput = true</code> and connecting to the input the output of a <a href=\"Modelica://Modelica.Blocks.Sources.RealExpression\">Modelica.Blocks.Sources.RealExpression</a> component, containing the residual of the initial equation. In this case, if <code>useHomotopy = true</code>, the simplified initial equation is <code>(p - pstart)/pstart = 0</code>. To ensure a smooth homotopy transformation, it is recommended to write the residual in normalized form, i.e., with values have the order of magnitude of one, as for the simplified equation.</p>
2822+
</html>"));
2823+
end ClosedSystemInit;
2824+
end Utility;
2825+
27472826
package BaseClasses
27482827
extends Modelica.Icons.BasesPackage;
27492828
partial model Flow1DBase

ThermoPower/Water.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ outlet is ignored; use <t>Pump</t> models if this has to be taken into account c
13741374
end if;
13751375
annotation (
13761376
Diagram(graphics),
1377-
Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
1377+
Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
13781378
Documentation(info="<HTML>
13791379
<p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
13801380
<ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).
@@ -1463,7 +1463,7 @@ outlet is ignored; use <t>Pump</t> models if this has to be taken into account c
14631463
connect(wall2,heatTransfer2.wall);
14641464
annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
14651465
-100},{100,100}}), graphics), Icon(coordinateSystem(
1466-
preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics));
1466+
preserveAspectRatio=false, extent={{-100,-100},{100,100}})));
14671467
end Flow1DFV2w;
14681468

14691469
model Flow1DFV2ph
@@ -1786,7 +1786,7 @@ outlet is ignored; use <t>Pump</t> models if this has to be taken into account c
17861786

17871787
annotation (
17881788
Diagram(graphics),
1789-
Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
1789+
Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
17901790
Documentation(info="<HTML>
17911791
<p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
17921792
<ul><li>The fluid state is either one-phase, or a two-phase mixture.
@@ -2289,7 +2289,7 @@ enthalpy between the nodes; this requires the availability of the time derivativ
22892289
end if;
22902290
annotation (
22912291
Diagram(graphics),
2292-
Icon(graphics={Text(extent={{-100,-40},{100,-80}}, textString="%name")}),
2292+
Icon(graphics={Text(extent={{-100,-60},{100,-100}},textString="%name")}),
22932293
Documentation(info="<HTML>
22942294
<p>This model describes the flow of water or steam in a rigid tube. The basic modelling assumptions are:
22952295
<ul><li>The fluid state is always one-phase (i.e. subcooled liquid or superheated steam).

0 commit comments

Comments
 (0)