Skip to content

Commit

Permalink
Merge branch 'master' into issue1413_isat
Browse files Browse the repository at this point in the history
  • Loading branch information
JayHuLBL committed Oct 26, 2021
2 parents e2ee8ce + c3c38c9 commit 8de2661
Show file tree
Hide file tree
Showing 37 changed files with 837 additions and 732 deletions.
493 changes: 493 additions & 0 deletions Buildings/Fluid/FixedResistances/BaseClasses/PlugFlowPipe.mo

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Buildings/Fluid/FixedResistances/BaseClasses/package.mo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
within Buildings.Fluid.FixedResistances;
package BaseClasses "Package with base classes for Buildings.Fluid.FixedResistances"
extends Modelica.Icons.BasesPackage;

annotation (preferredView="info", Documentation(info="<html>
<p>
This package contains base classes that are used to construct the models in
Expand Down
1 change: 1 addition & 0 deletions Buildings/Fluid/FixedResistances/BaseClasses/package.order
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Pipe
PlugFlow
PlugFlowHeatLoss
PlugFlowPipe
PlugFlowTransportDelay
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
within Buildings.Fluid.FixedResistances.Examples;
model PlugFlowDiscretized "Simple example of discretized plug flow pipe"
model PlugFlowPipeDiscretized "Simple example of discretized plug flow pipe"
extends Modelica.Icons.Example;
replaceable package Medium = Buildings.Media.Water "Medium in the pipe" annotation (
choicesAllMatching=true);
Expand All @@ -18,7 +18,7 @@ model PlugFlowDiscretized "Simple example of discretized plug flow pipe"
nPorts=1,
p(displayUnit="Pa") = 101325) "Pressure boundary condition"
annotation (Placement(transformation(extent={{82,-10},{62,10}})));
Buildings.Fluid.FixedResistances.PlugFlowDiscretized pip(
Buildings.Fluid.FixedResistances.PlugFlowPipeDiscretized pip(
redeclare package Medium = Medium,
nSeg=nSeg,
dh=0.1,
Expand Down Expand Up @@ -67,13 +67,13 @@ equation
annotation (Line(points={{20,0},{30,0}}, color={0,127,255}));
annotation (
__Dymola_Commands(file=
"Resources/Scripts/Dymola/Fluid/FixedResistances/Examples/PlugFlowDiscretized.mos"
"Resources/Scripts/Dymola/Fluid/FixedResistances/Examples/PlugFlowPipeDiscretized.mos"
"Simulate and Plot"),
experiment(StopTime=1000, Tolerance=1e-006),
Documentation(info="<html>
<p>Basic test of model
<a href=\"modelica://Buildings.Fluid.FixedResistances.PlugFlowDiscretized\">
Buildings.Fluid.FixedResistances.PlugFlowDiscretized</a>.
<a href=\"modelica://Buildings.Fluid.FixedResistances.PlugFlowPipeDiscretized\">
Buildings.Fluid.FixedResistances.PlugFlowPipeDiscretized</a>.
This test includes an inlet temperature step under a constant mass flow rate.
</p>
</html>", revisions="<html>
Expand All @@ -84,4 +84,4 @@ First implementation.
</li>
</ul>
</html>"));
end PlugFlowDiscretized;
end PlugFlowPipeDiscretized;
2 changes: 1 addition & 1 deletion Buildings/Fluid/FixedResistances/Examples/package.order
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ CheckValve
FlowJunction
HydraulicDiameter
Pipe
PlugFlowDiscretized
PlugFlowPipe
PlugFlowPipeDiscretized
PressureDrop
300 changes: 12 additions & 288 deletions Buildings/Fluid/FixedResistances/PlugFlowPipe.mo
Original file line number Diff line number Diff line change
@@ -1,295 +1,19 @@
within Buildings.Fluid.FixedResistances;
model PlugFlowPipe
"Pipe model using spatialDistribution for temperature delay"
extends Buildings.Fluid.Interfaces.PartialTwoPortInterface(
m_flow(start=m_flow_start));
extends Buildings.Fluid.FixedResistances.BaseClasses.PlugFlowPipe(
redeclare final Buildings.Fluid.FixedResistances.HydraulicDiameter res(
final dh=dh,
final from_dp=from_dp,
final length=length,
final roughness=roughness,
final fac=fac,
final ReC=ReC,
final v_nominal=v_nominal,
final homotopyInitialization=homotopyInitialization,
final linearized=linearized,
dp(nominal=fac*200*length)));

constant Boolean homotopyInitialization = true "= true, use homotopy method"
annotation(HideResult=true);

parameter Boolean from_dp=false
"= true, use m_flow = f(dp) else dp = f(m_flow)"
annotation (Dialog(tab="Advanced"));

parameter Boolean have_pipCap=true
"= true, a mixing volume is added that corresponds
to the heat capacity of the pipe wall"
annotation (Dialog(tab="Advanced"));
parameter Boolean have_symmetry=true
"= false, the mixing volume is only on port_b,
which improve performances, but reduces dynamic accuracy."
annotation (Dialog(tab="Advanced", enable=have_pipCap));

parameter Modelica.SIunits.Length dh=sqrt(4*m_flow_nominal/rho_default/v_nominal/Modelica.Constants.pi)
"Hydraulic diameter (assuming a round cross section area)"
annotation (Dialog(group="Material"));

parameter Modelica.SIunits.Velocity v_nominal = 1.5
"Velocity at m_flow_nominal (used to compute default value for hydraulic diameter dh)"
annotation(Dialog(group="Nominal condition"));

parameter Real ReC=4000
"Reynolds number where transition to turbulence starts";

parameter Modelica.SIunits.Height roughness=2.5e-5
"Average height of surface asperities (default: smooth steel pipe)"
annotation (Dialog(group="Material"));

parameter Modelica.SIunits.Length length "Pipe length"
annotation (Dialog(group="Material"));

parameter Modelica.SIunits.Length dIns
"Thickness of pipe insulation, used to compute R"
annotation (Dialog(group="Thermal resistance"));

parameter Modelica.SIunits.ThermalConductivity kIns
"Heat conductivity of pipe insulation, used to compute R"
annotation (Dialog(group="Thermal resistance"));

parameter Modelica.SIunits.SpecificHeatCapacity cPip=2300
"Specific heat of pipe wall material. 2300 for PE, 500 for steel"
annotation (Dialog(group="Material", enable=have_pipCap));

parameter Modelica.SIunits.Density rhoPip(displayUnit="kg/m3")=930
"Density of pipe wall material. 930 for PE, 8000 for steel"
annotation (Dialog(group="Material", enable=have_pipCap));

parameter Modelica.SIunits.Length thickness = 0.0035
"Pipe wall thickness"
annotation (Dialog(group="Material"));

parameter Modelica.SIunits.Temperature T_start_in(start=Medium.T_default)=
Medium.T_default "Initialization temperature at pipe inlet"
annotation (Dialog(tab="Initialization"));
parameter Modelica.SIunits.Temperature T_start_out(start=Medium.T_default)=
T_start_in "Initialization temperature at pipe outlet"
annotation (Dialog(tab="Initialization"));
parameter Boolean initDelay = false
"Initialize delay for a constant mass flow rate if true, otherwise start from 0"
annotation (Dialog(tab="Initialization"));
parameter Modelica.SIunits.MassFlowRate m_flow_start=0 "Initial value of mass flow rate through pipe"
annotation (Dialog(tab="Initialization", enable=initDelay));

parameter Real R(unit="(m.K)/W")=1/(kIns*2*Modelica.Constants.pi/
Modelica.Math.log((dh/2 + thickness + dIns)/(dh/2 + thickness)))
"Thermal resistance per unit length from fluid to boundary temperature"
annotation (Dialog(group="Thermal resistance"));

parameter Real fac=1
"Factor to take into account flow resistance of bends etc.,
fac=dp_nominal/dpStraightPipe_nominal";

parameter Boolean linearized = false
"= true, use linear relation between m_flow and dp for any flow rate"
annotation(Evaluate=true, Dialog(tab="Advanced"));

Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort
"Heat transfer to or from surroundings (positive if pipe is colder than surrounding)"
annotation (Placement(transformation(extent={{-10,90},{10,110}})));

// QEnv_flow is introduced because in discretized pipes, heatPort.Q_flow must be summed over all ports.
// By introducing this variable, both models have the same variable.
Modelica.SIunits.HeatFlowRate QEnv_flow = heatPort.Q_flow
"Heat transfer to or from surroundings (positive if pipe is colder than surrounding)";

Modelica.SIunits.Velocity v = del.v "Flow velocity of medium in pipe";

protected
parameter Modelica.SIunits.HeatCapacity CPip=
length*((dh + 2*thickness)^2 - dh^2)*Modelica.Constants.pi/4*cPip*rhoPip "Heat capacity of pipe wall";

final parameter Modelica.SIunits.Volume VEqu=if have_symmetry
then CPip/(rho_default*cp_default)/2 else CPip/(rho_default*cp_default)
"Equivalent water volume to represent pipe wall thermal inertia";

parameter Medium.ThermodynamicState sta_default=Medium.setState_pTX(
T=Medium.T_default,
p=Medium.p_default,
X=Medium.X_default) "Default medium state";

parameter Modelica.SIunits.SpecificHeatCapacity cp_default=
Medium.specificHeatCapacityCp(state=sta_default)
"Heat capacity of medium";

parameter Real C(unit="J/(K.m)")=
rho_default*Modelica.Constants.pi*(dh/2)^2*cp_default
"Thermal capacity per unit length of water in pipe";

parameter Modelica.SIunits.Density rho_default=Medium.density_pTX(
p=Medium.p_default,
T=Medium.T_default,
X=Medium.X_default)
"Default density (e.g., rho_liquidWater = 995, rho_air = 1.2)"
annotation (Dialog(group="Advanced"));

parameter Boolean have_pipCap_a = have_pipCap and have_symmetry;

BaseClasses.PlugFlow del(
redeclare final package Medium = Medium,
final m_flow_small=m_flow_small,
final dh=dh,
final length=length,
final allowFlowReversal=allowFlowReversal,
final T_start_in=T_start_in,
final T_start_out=T_start_out)
"Model for temperature wave propagation"
annotation (Placement(transformation(extent={{20,30},{40,50}})));
BaseClasses.PlugFlowHeatLoss heaLos_a(
redeclare final package Medium = Medium,
final C=C,
final R=R,
final m_flow_small=m_flow_small,
final T_start=T_start_in,
final m_flow_nominal=m_flow_nominal,
final m_flow_start=m_flow_start,
final show_T=false,
final show_V_flow=false) "Heat loss for flow from port_b to port_a"
annotation (Placement(transformation(extent={{-40,-10},{-60,10}})));
BaseClasses.PlugFlowHeatLoss heaLos_b(
redeclare final package Medium = Medium,
final C=C,
final R=R,
final m_flow_small=m_flow_small,
final T_start=T_start_out,
final m_flow_nominal=m_flow_nominal,
final m_flow_start=m_flow_start,
final show_T=false,
final show_V_flow=false) "Heat loss for flow from port_a to port_b"
annotation (Placement(transformation(extent={{40,-10},{60,10}})));
Sensors.MassFlowRate senMasFlo(redeclare final package Medium =
Medium) "Mass flow sensor"
annotation (Placement(transformation(extent={{-40,50},{-20,30}})));
BaseClasses.PlugFlowTransportDelay timDel(
final length=length,
final dh=dh,
final rho=rho_default,
final initDelay=initDelay,
final m_flow_nominal=m_flow_nominal,
final m_flow_start=m_flow_start) "Time delay"
annotation (Placement(transformation(extent={{-10,-50},{10,-30}})));

// In the volume, below, we scale down V and use
// mSenFac. Otherwise, for air, we would get very large volumes
// which affect the delay of water vapor and contaminants.
// See also Buildings.Fluid.FixedResistances.Validation.PlugFlowPipes.TransportWaterAir
// for why mSenFac is 10 and not 1000, as this gives more reasonable
// temperature step response
Fluid.MixingVolumes.MixingVolume vol_b(
redeclare final package Medium = Medium,
final m_flow_nominal=m_flow_nominal,
final V=if rho_default > 500 then VEqu else VEqu/1000,
final nPorts=2,
final T_start=T_start_out,
final energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
final mSenFac=if rho_default > 500 then 1 else 10) if have_pipCap
"Control volume connected to port_b.
Represents equivalent pipe wall thermal capacity."
annotation (Placement(transformation(extent={{70,20},{90,40}})));
LosslessPipe noMixPip_b(
redeclare final package Medium = Medium,
final m_flow_nominal=m_flow_nominal,
final m_flow_small=m_flow_small,
final allowFlowReversal=allowFlowReversal) if not have_pipCap
"Lossless pipe for connecting the outlet port when have_pipCap=false"
annotation (Placement(transformation(extent={{70,-30},{90,-10}})));

MixingVolumes.MixingVolume vol_a(
redeclare final package Medium = Medium,
final m_flow_nominal=m_flow_nominal,
final V=if rho_default > 500 then VEqu else VEqu/1000,
final nPorts=2,
final T_start=T_start_out,
final energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
final mSenFac=if rho_default > 500 then 1 else 10) if have_pipCap_a
"Control volume connected to port_a.
Represents equivalent pipe wall thermal capacity."
annotation (Placement(transformation(extent={{-90,20},{-70,40}})));
LosslessPipe noMixPip_a(
redeclare final package Medium = Medium,
final m_flow_nominal=m_flow_nominal,
final m_flow_small=m_flow_small,
final allowFlowReversal=allowFlowReversal) if not have_pipCap_a
"Lossless pipe for connecting the outlet port when have_pipCap=false
or have_symmetry=false"
annotation (Placement(transformation(extent={{-90,-30},{-70,-10}})));

Buildings.Fluid.FixedResistances.HydraulicDiameter res(
redeclare final package Medium = Medium,
final dh=dh,
final m_flow_nominal=m_flow_nominal,
final from_dp=from_dp,
final length=length,
final roughness=roughness,
final fac=fac,
final ReC=ReC,
final v_nominal=v_nominal,
final allowFlowReversal=allowFlowReversal,
final show_T=false,
final homotopyInitialization=homotopyInitialization,
final linearized=linearized,
dp(nominal=fac*200*length))
"Pressure drop calculation for this pipe"
annotation (Placement(transformation(extent={{-10,-10},{10,10}},
rotation=0,
origin={0,40})));


initial equation
assert(homotopyInitialization, "In " + getInstanceName() +
": The constant homotopyInitialization has been modified from its default
value. This constant will be removed in future releases.",
level = AssertionLevel.warning);

equation

connect(senMasFlo.m_flow,timDel. m_flow)
annotation (Line(points={{-30,29},{-30,-40},{-12,-40}},
color={0,0,127},
smooth=Smooth.None));
connect(timDel.tauRev,heaLos_a. tau)
annotation (Line(points={{11,-36},{16,-36},{16,-20},{-32,-20},
{-32,16},{-44,16},{-44,10}}, color={0,0,127}));
connect(timDel.tau,heaLos_b. tau)
annotation (Line(points={{11,-44},{34,-44},{34,18},{44,18},{44,10}},
color={0,0,127}));
connect(heaLos_a.port_a,senMasFlo. port_a)
annotation (Line(points={{-40,0},{-20,0},{-20,20},{-44,20},
{-44,40},{-40,40}},color={0,127,255}));
connect(del.port_a,res. port_b)
annotation (Line(points={{20,40},{10,40}},
color={0,127,255}));
connect(senMasFlo.port_b,res. port_a)
annotation (Line(points={{-20,40},{-10,40}},
color={0,127,255}));
connect(heaLos_b.port_a,del. port_b)
annotation (Line(points={{40,0},{20,0},{20,20},{44,20},{44,40},{40,40}},
color={0,127,255}));
connect(heaLos_b.heatPort, heatPort)
annotation (Line(points={{50,10},{50,86},{0,86},{0,100}},
color={191,0,0}));
connect(heaLos_a.heatPort, heatPort)
annotation (Line(points={{-50,10},{-50,86},{0,86},{0,100}},
color={191,0,0}));

connect(heaLos_b.port_b, vol_b.ports[1])
annotation (Line(points={{60,0},{78,0},{78,20}}, color={0,127,255}));
connect(vol_b.ports[2], port_b)
annotation (Line(points={{82,20},{82,0},{100,0}}, color={0,127,255}));
connect(heaLos_b.port_b, noMixPip_b.port_a)
annotation (Line(points={{60,0},{66,0},{66,-20},{70,-20}},
color={0,127,255}));
connect(noMixPip_b.port_b, port_b)
annotation (Line(points={{90,-20},{94,-20},{94,0},{100,0}},
color={0,127,255}));

connect(port_a, vol_a.ports[1])
annotation (Line(points={{-100,0},{-82,0},{-82,20}}, color={0,127,255}));
connect(vol_a.ports[2], heaLos_a.port_b)
annotation (Line(points={{-78,20},{-78,0},{-60,0}}, color={0,127,255}));
connect(port_a, noMixPip_a.port_a) annotation (Line(points={{-100,0},{-94,0},{
-94,-20},{-90,-20}}, color={0,127,255}));
connect(noMixPip_a.port_b, heaLos_a.port_b) annotation (Line(points={{-70,-20},
{-64,-20},{-64,0},{-60,0}}, color={0,127,255}));
annotation (
Line(points={{70,20},{72,20},{72,0},{100,0}}, color={0,127,255}),
Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{
Expand Down
Loading

0 comments on commit 8de2661

Please sign in to comment.