From c1b2bdec6d7063832fcb771e647fd02cac8c8a9b Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Wed, 20 Sep 2023 10:10:49 -0700 Subject: [PATCH] Added base class to place ports on top and bottom --- .../Storage/BaseClasses/PartialStratified.mo | 49 ++------ .../BaseClasses/PartialTwoPortInterface.mo | 113 ++++++++++++++++++ IBPSA/Fluid/Storage/BaseClasses/package.order | 1 + 3 files changed, 123 insertions(+), 40 deletions(-) create mode 100644 IBPSA/Fluid/Storage/BaseClasses/PartialTwoPortInterface.mo diff --git a/IBPSA/Fluid/Storage/BaseClasses/PartialStratified.mo b/IBPSA/Fluid/Storage/BaseClasses/PartialStratified.mo index 554b36357a..64ca1eb38c 100644 --- a/IBPSA/Fluid/Storage/BaseClasses/PartialStratified.mo +++ b/IBPSA/Fluid/Storage/BaseClasses/PartialStratified.mo @@ -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"; @@ -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, @@ -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}, @@ -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; diff --git a/IBPSA/Fluid/Storage/BaseClasses/PartialTwoPortInterface.mo b/IBPSA/Fluid/Storage/BaseClasses/PartialTwoPortInterface.mo new file mode 100644 index 0000000000..231c78b8fb --- /dev/null +++ b/IBPSA/Fluid/Storage/BaseClasses/PartialTwoPortInterface.mo @@ -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=" +

+This partial class implements the same functionality as + +IBPSA.Fluid.Interfaces.StaticTwoPortHeatMassExchanger, +except that port_a and port_b are placed at the top and bottom +of the component. +

+

Implementation

+

+The implementation is done in this package as opposed to + +IBPSA.Fluid.Interfaces +as it is only used by the storage model, and may be removed when the tool limitations +that are discussed in +IBPSA, #1794. +are removed. +

+", revisions=" + +")); +end PartialTwoPortInterface; diff --git a/IBPSA/Fluid/Storage/BaseClasses/package.order b/IBPSA/Fluid/Storage/BaseClasses/package.order index 23ec1825ad..62b42b3b73 100644 --- a/IBPSA/Fluid/Storage/BaseClasses/package.order +++ b/IBPSA/Fluid/Storage/BaseClasses/package.order @@ -1,5 +1,6 @@ Buoyancy IndirectTankHeatExchanger PartialStratified +PartialTwoPortInterface ThirdOrderStratifier Examples