Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ThermofluidStream/DropOfCommons.mo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

parameter Boolean displayInstanceNames = true "= true, if ThermofluidStream instance names are displayed" annotation(Dialog(group="Layout"),Evaluate=true, HideResult=true, choices(checkBox=true));
parameter Boolean displayParameters = true "= true, if displaying parameters is enabled" annotation(Dialog(group="Layout"),Evaluate=true, HideResult=true, choices(checkBox=true));
parameter Boolean displayColor = false "= true, if pressure drop is displayed in color" annotation(Dialog(group="Layout"),Evaluate=true, HideResult=true, choices(checkBox=true));
final parameter Integer instanceNameColor[3] = {28,108,200}; // Default Color: {28,108,200}

annotation (defaultComponentName="dropOfCommons",
Expand Down Expand Up @@ -63,11 +64,11 @@
<li>It provides <strong>default physical constants</strong> (e.g., gravity acceleration) and flow properties (e.g., inertance) that are used by all components in the model.</li>
<li>It defines <strong>regularization parameters</strong> (e.g., minimal density, minimal pressure, mass flow threshold, angular velocity, and volume damping factor) that ensure numerical stability of transient simulations. These parameters must be adjusted to match the characteristics of the simulated system, for example, if the system&rsquo;s design involves mass flows on the order of magnitude of the regularization threshold (m_flow_reg), or angular velocities near omega_reg, their values should be updated to prevent artificial inaccuracies. Detailed information on the volume damping factor is available in the <a href=\"modelica://ThermofluidStream.Boundaries.Internal.PartialVolume\">PartialVolume</a> documentation.</li>
<li>It defines <strong>global assertion and error handling</strong> behavior via the <span style=\"font-family: Courier New;\">assertionLevel</span> parameter.</li>
<li>It provides <strong>layout and visualization settings</strong> for model diagrams, such as displaying instance names and parameter values.</li>
<li>It provides <strong>layout and visualization settings</strong> for model diagrams, such as displaying instance names, parameter values, and visualization (in color) for e.g. resistance pressure drop.</li>
</ul>
<p>Since the global parameters defined in DropOfCommons are used by multiple ThermofluidStream components, exactly one instance of this model needs to be present at the top level of a simulation model. The basic declaration is: </p>
<p style=\"margin-left: 40px;\"><strong><span style=\"font-family: Courier New;\">inner</span></strong> ThermofluidStream.DropOfCommons dropOfCommons </p>
<p>Note, it must be an <strong>inner</strong> declaration with instance name <strong>dropOfCommons</strong> so that all components of a ThermofluidStream model can reference it. When dragging the &quot;DropOfCommons&quot; object from the package browser into the diagram layer, this declaration is automatically generated (defined via annotations in the model). </p>
<p>Note, it must be an <b>inner</b> declaration with instance name <b>dropOfCommons</b> so that all components of a ThermofluidStream model can reference it. When dragging the &quot;DropOfCommons&quot; object from the package browser into the diagram layer, this declaration is automatically generated (defined via annotations in the model). </p>

Check warning on line 71 in ThermofluidStream/DropOfCommons.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.

Check warning on line 71 in ThermofluidStream/DropOfCommons.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.
Comment thread
tobiasreischl marked this conversation as resolved.
Outdated
<p>All flow, density, pressure, and visualization parameters in a simulation model are resolved relative to the settings in this dropOfCommons instance. Adjusting these parameters allows controlling global simulation behavior, visualization preferences, and regularization methods consistently across all components. </p>
</html>"));
end DropOfCommons;
135 changes: 72 additions & 63 deletions ThermofluidStream/Processes/FlowResistance.mo
Original file line number Diff line number Diff line change
@@ -1,92 +1,100 @@
within ThermofluidStream.Processes;
model FlowResistance "Flow resistance model"
extends Interfaces.SISOFlow(
final L=if computeL then l/areaHydraulic else L_value,
final clip_p_out=true);
extends Interfaces.SISOFlow(final L=if computeL then l/areaHydraulic else
L_value, final clip_p_out=true);

import Modelica.Constants.pi "Constant Pi";
import ThermofluidStream.Processes.Internal.ShapeOfResistance "Shape of cross sectional area";

replaceable function pLoss = Internal.FlowResistance.pleaseSelectPressureLoss
constrainedby Internal.FlowResistance.partialPressureLoss "Pressure loss function"
annotation (
choices(
choice(
redeclare function pLoss = ThermofluidStream.Processes.Internal.FlowResistance.pleaseSelectPressureLoss
constrainedby Internal.FlowResistance.partialPressureLoss
"Pressure loss function" annotation (choices(
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.pleaseSelectPressureLoss
"No function selected"),
choice(
redeclare function pLoss = ThermofluidStream.Processes.Internal.FlowResistance.linearQuadraticPressureLoss
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.linearQuadraticPressureLoss
"Linear-quadratic"),
choice(
redeclare function pLoss = ThermofluidStream.Processes.Internal.FlowResistance.laminarPressureLoss
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.laminarPressureLoss
"Laminar (Hagen-Poiseuille)"),
choice(
redeclare function pLoss = ThermofluidStream.Processes.Internal.FlowResistance.laminarTurbulentPressureLoss
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.laminarTurbulentPressureLoss
"Laminar-turbulent (Cheng2008)"),
choice(
redeclare function pLoss =
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.laminarTurbulentPressureLossHaaland
"Laminar-turbulent (Haaland1983)"),
choice(
redeclare function pLoss =
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.zetaPressureLoss
"Fixed pressure loss coefficient"),
choice(
redeclare function pLoss =
choice(redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.referencePressureLoss
"Use reference point (dp, m_flow, d)_ref")),
Documentation(info="<html>
"Use reference point (dp, m_flow, d)_ref")), Documentation(info="<html>
<p>
This function computes the pressure loss of the fluid depending on the massflow,
some medium properties and the geometry of the pipe.
</p>
</html>"));
parameter SI.Length l(min=0) "Length"
annotation (Dialog(group = "Geometry"));
parameter ShapeOfResistance shape=ThermofluidStream.Processes.Internal.ShapeOfResistance.circular "Cross section shape"
annotation (Dialog(group = "Geometry",enable = true));
parameter SI.Radius r(min=0) = 0 "Radius"
annotation (Dialog(group = "Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.circular)));
parameter SI.Length a(min=0) = 0 "Rectangle width"
annotation(Dialog(group = "Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.rectangle)));
parameter SI.Length b(min=0) = 0 "Rectangle height"
annotation(Dialog(group = "Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.rectangle)));
parameter SI.Length l(min=0) "Length" annotation (Dialog(group="Geometry"));
parameter ShapeOfResistance shape=ThermofluidStream.Processes.Internal.ShapeOfResistance.circular
"Cross section shape" annotation (Dialog(group="Geometry", enable=true));
parameter SI.Radius r(min=0) = 0 "Radius" annotation (Dialog(group="Geometry",
enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.circular)));
parameter SI.Length a(min=0) = 0 "Rectangle width" annotation (Dialog(group="Geometry",
enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.rectangle)));
parameter SI.Length b(min=0) = 0 "Rectangle height" annotation (Dialog(group="Geometry",
enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.rectangle)));
parameter SI.Area areaCrossInput(min=0) = 0 "Cross-sectional area"
annotation(Dialog(group = "Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.other)));
parameter SI.Length perimeterInput(min=0) = 0 "Wetted perimeter"
annotation(Dialog(group = "Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.other)));
parameter Boolean computeL = true "= true, if inertance L is computed from the geometry"
annotation(Dialog(tab="Advanced",group="Inertance"),Evaluate=true, HideResult=true, choices(checkBox=true));
parameter Utilities.Units.Inertance L_value = dropOfCommons.L "Inertance"
annotation(Dialog(tab="Advanced",group="Inertance", enable=not computeL));
parameter SI.Density rho_min = dropOfCommons.rho_min "Minimal inlet density"
annotation(Dialog(tab="Advanced"));
annotation (Dialog(group="Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.other)));
parameter SI.Length perimeterInput(min=0) = 0 "Wetted perimeter" annotation (
Dialog(group="Geometry", enable=(shape == ThermofluidStream.Processes.Internal.ShapeOfResistance.other)));
parameter Boolean computeL=true
"= true, if inertance L is computed from the geometry" annotation (
Dialog(tab="Advanced", group="Inertance"),
Evaluate=true,
HideResult=true,
choices(checkBox=true));
parameter Utilities.Units.Inertance L_value=dropOfCommons.L "Inertance"
annotation (Dialog(
tab="Advanced",
group="Inertance",
enable=not computeL));
parameter SI.Density rho_min=dropOfCommons.rho_min "Minimal inlet density" annotation (Dialog(tab="Advanced"));
parameter SI.Pressure dp_ref_color = 1e5 "Reference pressure drop value for the intensity of coloring" annotation(Dialog(tab="Layout", group="Visuals", enable=dropOfCommons.displayColor));

final parameter SI.Length D_h = 4*areaCross/perimeter "Hydraulic diameter";
final parameter SI.Length perimeter=
if shape == ShapeOfResistance.circular then 2*pi*r
elseif shape == ShapeOfResistance.rectangle then 2*a+2*b
else perimeterInput "Perimeter";
final parameter SI.Length D_h=4*areaCross/perimeter "Hydraulic diameter";
final parameter SI.Length perimeter=if shape == ShapeOfResistance.circular
then 2*pi*r elseif shape == ShapeOfResistance.rectangle then 2*a + 2*b
else perimeterInput "Perimeter";
final parameter SI.Area areaCross=if shape == ShapeOfResistance.circular
then pi*r*r elseif shape == ShapeOfResistance.rectangle then a*b else
areaCrossInput "Cross-sectional area";
final parameter SI.Area areaHydraulic=pi*D_h*D_h*1/4
"Hydraulic cross-sectional area";

final parameter SI.Area areaCross=
if shape == ShapeOfResistance.circular then pi*r*r
elseif shape == ShapeOfResistance.rectangle then a*b
else areaCrossInput "Cross-sectional area";

final parameter SI.Area areaHydraulic= pi*D_h*D_h*1/4 "Hydraulic cross-sectional area";
Real phi(min=0, max=1) "Normalized pressure for coloring the flow resistance";

protected
SI.Density rho_in = max(rho_min, Medium.density(inlet.state)) "Inlet density";
SI.DynamicViscosity mu_in = Medium.dynamicViscosity(inlet.state) "Inlet dynamic viscosity";
SI.Density rho_in=max(rho_min, Medium.density(inlet.state)) "Inlet density";
SI.DynamicViscosity mu_in=Medium.dynamicViscosity(inlet.state)
"Inlet dynamic viscosity";

equation
dp = -pLoss(m_flow, rho_in, mu_in, D_h/2, l);
dp = -pLoss(
m_flow,
rho_in,
mu_in,
D_h/2,
l);
h_out = h_in;
Xi_out = Xi_in;

phi = if dropOfCommons.displayColor then
noEvent(max(0, min(1, abs(dp)/dp_ref_color)))
else 0;
annotation (
Icon(coordinateSystem(preserveAspectRatio=true), graphics={
Text(visible=displayInstanceName,
Text(
visible=displayInstanceName,
extent={{-150,120},{150,80}},
textString="%name",
textColor=dropOfCommons.instanceNameColor),
Expand All @@ -105,7 +113,8 @@
extent={{-60,60},{60,-60}},
lineColor={28,108,200},
lineThickness=0.5,
fillColor={255,255,255},
fillColor=DynamicSelect({255,255,255}, if dropOfCommons.displayColor == true
then {255,integer(255*(1 - phi)),integer(255*(1 - phi))} else {255,255,255}),
fillPattern=FillPattern.Solid),
Line(
points={{40,0},{-48,0}},
Expand All @@ -123,11 +132,11 @@
thickness=0.5,
smooth=Smooth.Bezier,
origin={0,25},
rotation=180)}), Diagram(coordinateSystem(preserveAspectRatio=true)),
rotation=180)}),
Diagram(coordinateSystem(preserveAspectRatio=true)),
Documentation(info="<html>
<p>
Implementation of a flow resistance pipe with different selectable
flow resistance functions (laminar, laminar-turbulent, linear-quadratic).
</p>
<p>Implementation of a flow resistance pipe with different selectable flow resistance functions (laminar, laminar-turbulent, linear-quadratic). </p>
<p>The pressure drop can be displayed with the coloring (<code>displayColor</code> in the <b>DropOfCommons</b>). <code>p_ref_color</code> can be adjusted depending on expected pressure drop and intensity of coloring. Coloring ranges from 0 to 100 &percnt; red, with 100 &percnt; red at <code>dp = dp_ref_color</code>.</p>

Check warning on line 139 in ThermofluidStream/Processes/FlowResistance.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.
Comment thread
tobiasreischl marked this conversation as resolved.
Outdated
<p><code>dp_ref_color</code> needs to be defined according to the use case.</p>
</html>"));
end FlowResistance;
3 changes: 2 additions & 1 deletion ThermofluidStream/Processes/Tests/Flow_Resistance.mo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Medium model for the test. Can be anything.
tf.Boundaries.Sink sink(redeclare package Medium = Medium, p0_par=100000)
annotation (Placement(transformation(extent={{20,-10},{40,10}})));

inner tf.DropOfCommons dropOfCommons(L=1, assertionLevel = AssertionLevel.warning)
inner tf.DropOfCommons dropOfCommons(L=1, assertionLevel = AssertionLevel.warning,
displayColor=true)
annotation (Placement(transformation(extent={{60,60},{80,80}})));

tf.Processes.FlowResistance flowResistance(
Expand Down
Loading