Skip to content

Commit

Permalink
Added base class to place ports on top and bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
mwetter committed Sep 20, 2023
1 parent a8a0980 commit c1b2bde
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 40 deletions.
49 changes: 9 additions & 40 deletions IBPSA/Fluid/Storage/BaseClasses/PartialStratified.mo
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
within IBPSA.Fluid.Storage.BaseClasses;
model PartialStratified
"Partial model of a stratified tank for thermal energy storage"
extends IBPSA.Fluid.Interfaces.PartialTwoPortInterface;
extends IBPSA.Fluid.Storage.BaseClasses.PartialTwoPortInterface;

import Modelica.Fluid.Types;
import Modelica.Fluid.Types.Dynamics;

parameter Modelica.Units.SI.Volume VTan "Tank volume";
parameter Modelica.Units.SI.Length hTan "Height of tank (without insulation)";
parameter Modelica.Units.SI.Length dIns "Thickness of insulation";
Expand Down Expand Up @@ -76,6 +77,7 @@ model PartialStratified
each final m_flow_small=m_flow_small,
each final allowFlowReversal=allowFlowReversal) "Tank segment"
annotation (Placement(transformation(extent={{6,-16},{26,4}})));

protected
parameter Medium.ThermodynamicState sta_default = Medium.setState_pTX(
T=Medium.T_default,
Expand Down Expand Up @@ -331,49 +333,13 @@ Icon(graphics={
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{-76,2},{-90,-2}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,84},{-80,80}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{-76,84},{-80,-2}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{82,0},{78,-86}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,84},{-4,60}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{82,-84},{2,-88}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{6,-60},{2,-84}},
extent={{2,100},{-2,60}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{92,2},{78,-2}},
extent={{2,-60},{-2,-100}},
lineColor={0,0,255},
pattern=LinePattern.None,
fillColor={0,0,127},
Expand Down Expand Up @@ -428,5 +394,8 @@ Icon(graphics={
Line(
points={{22,-74},{70,-74},{70,72}},
color={127,0,0},
pattern=LinePattern.Dot)}));
pattern=LinePattern.Dot), Text(
extent={{-100,100},{-8,70}},
textString="%name",
textColor={0,0,255})}));
end PartialStratified;
113 changes: 113 additions & 0 deletions IBPSA/Fluid/Storage/BaseClasses/PartialTwoPortInterface.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
within IBPSA.Fluid.Storage.BaseClasses;
partial model PartialTwoPortInterface
"Partial model transporting fluid between two ports without storing mass or energy"

replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium "Medium in the component"
annotation (choices(
choice(redeclare package Medium = IBPSA.Media.Air "Moist air"),
choice(redeclare package Medium = IBPSA.Media.Water "Water"),
choice(redeclare package Medium =
IBPSA.Media.Antifreeze.PropyleneGlycolWater (
property_T=293.15,
X_a=0.40)
"Propylene glycol water, 40% mass fraction")));

parameter Boolean allowFlowReversal = true
"= false to simplify equations, assuming, but not enforcing, no flow reversal"
annotation(Dialog(tab="Assumptions"), Evaluate=true);

Modelica.Fluid.Interfaces.FluidPort_a port_a(
redeclare final package Medium = Medium,
m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0),
p(start=Medium.p_default),
h_outflow(start = Medium.h_default, nominal = Medium.h_default))
"Fluid connector a (positive design flow direction is from port_a to port_b)"
annotation (Placement(transformation(extent={{-10,90},{10,110}})));
Modelica.Fluid.Interfaces.FluidPort_b port_b(
redeclare final package Medium = Medium,
m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0),
p(start=Medium.p_default),
h_outflow(start = Medium.h_default, nominal = Medium.h_default))
"Fluid connector b (positive design flow direction is from port_a to port_b)"
annotation (Placement(transformation(extent={{10,-110},{-10,-90}})));

parameter Modelica.Units.SI.MassFlowRate m_flow_nominal
"Nominal mass flow rate" annotation (Dialog(group="Nominal condition"));
parameter Modelica.Units.SI.MassFlowRate m_flow_small(min=0) = 1E-4*abs(
m_flow_nominal) "Small mass flow rate for regularization of zero flow"
annotation (Dialog(tab="Advanced"));
// Diagnostics
parameter Boolean show_T = false
"= true, if actual temperature at port is computed"
annotation (
Dialog(tab="Advanced", group="Diagnostics"),
HideResult=true);

Modelica.Units.SI.MassFlowRate m_flow(start=_m_flow_start) = port_a.m_flow
"Mass flow rate from port_a to port_b (m_flow > 0 is design flow direction)";

Modelica.Units.SI.PressureDifference dp(
start=_dp_start,
displayUnit="Pa") = port_a.p - port_b.p
"Pressure difference between port_a and port_b";

Medium.ThermodynamicState sta_a=
if allowFlowReversal then
Medium.setState_phX(port_a.p,
noEvent(actualStream(port_a.h_outflow)),
noEvent(actualStream(port_a.Xi_outflow)))
else
Medium.setState_phX(port_a.p,
noEvent(inStream(port_a.h_outflow)),
noEvent(inStream(port_a.Xi_outflow)))
if show_T "Medium properties in port_a";

Medium.ThermodynamicState sta_b=
if allowFlowReversal then
Medium.setState_phX(port_b.p,
noEvent(actualStream(port_b.h_outflow)),
noEvent(actualStream(port_b.Xi_outflow)))
else
Medium.setState_phX(port_b.p,
noEvent(port_b.h_outflow),
noEvent(port_b.Xi_outflow))
if show_T "Medium properties in port_b";

protected
final parameter Modelica.Units.SI.MassFlowRate _m_flow_start=0
"Start value for m_flow, used to avoid a warning if not set in m_flow, and to avoid m_flow.start in parameter window";
final parameter Modelica.Units.SI.PressureDifference _dp_start(displayUnit=
"Pa") = 0
"Start value for dp, used to avoid a warning if not set in dp, and to avoid dp.start in parameter window";

annotation (
preferredView="info",
Documentation(info="<html>
<p>
This partial class implements the same functionality as
<a href=\"modelica://IBPSA.Fluid.Interfaces.StaticTwoPortHeatMassExchanger\">
IBPSA.Fluid.Interfaces.StaticTwoPortHeatMassExchanger</a>,
except that <code>port_a</code> and <code>port_b</code> are placed at the top and bottom
of the component.
</p>
<h4>Implementation</h4>
<p>
The implementation is done in this package as opposed to
<a href=\"modelica://IBPSA.Fluid.Interfaces\">
IBPSA.Fluid.Interfaces</a>
as it is only used by the storage model, and may be removed when the tool limitations
that are discussed in
<a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1794\">IBPSA, #1794</a>.
are removed.
</p>
</html>", revisions="<html>
<ul>
<li>
September 20, 2023, by Michael Wetter:<br/>
First implementation to address
<a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1794\">IBPSA, #1794</a>.
</li>
</ul>
</html>"));
end PartialTwoPortInterface;
1 change: 1 addition & 0 deletions IBPSA/Fluid/Storage/BaseClasses/package.order
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Buoyancy
IndirectTankHeatExchanger
PartialStratified
PartialTwoPortInterface
ThirdOrderStratifier
Examples

0 comments on commit c1b2bde

Please sign in to comment.