Skip to content

Commit

Permalink
Fixed all errors found by running Examples in Modelon Impact
Browse files Browse the repository at this point in the history
All Examples are running and giving reasonable results in Modelon Impact. No regression testing against Dymola has been performed. Added correct computation of density_derp_h in single and mixture ideal gases.
  • Loading branch information
hubertus65 committed Jun 28, 2021
1 parent 08aa31d commit bf8f317
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 114 deletions.
29 changes: 15 additions & 14 deletions ThermofluidStream/Boundaries/PhaseSeperator.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
within ThermofluidStream.Boundaries;
model PhaseSeperator "Parent to Reciever and Accumulator models"
extends Boundaries.Internal.PartialVolume(
redeclare replaceable package Medium = Media.myMedia.Interfaces.PartialTwoPhaseMedium,
redeclare replaceable package Medium =
Media.myMedia.Interfaces.PartialTwoPhaseMedium,
useHeatport=false,
final useInlet=true,
final useOutlet=true,
Expand All @@ -15,10 +16,10 @@ model PhaseSeperator "Parent to Reciever and Accumulator models"
parameter SI.Volume V_par(displayUnit="l")=0.01 "Volume of phase seperator";
parameter Real pipe_low(unit="1", min=0, max=1) "Low end of pipe";
parameter Real pipe_high(unit="1", min=0, max=1) "High end of pipe";
parameter Boolean density_derp_h_from_media=false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));
// parameter Boolean density_derp_h_from_media=false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
// annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
// parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
// annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));
parameter Init init_method = ThermofluidStream.Boundaries.Internal.InitializationMethodsPhaseSeperator.l "Initialization Method"
annotation(choicesAllMatching=true, Dialog(tab="Initialization"));
parameter SI.SpecificEnthalpy h_0 = Medium.h_default "Initial specific enthalpy"
Expand All @@ -44,8 +45,8 @@ protected
SI.SpecificEnthalpy h_bubble = Medium.bubbleEnthalpy(Medium.setSat_p(medium.p))-1 "Bubble Enthalpy of Medium";
SI.SpecificEnthalpy h_dew = Medium.dewEnthalpy(Medium.setSat_p(medium.p))+1 "Dew Enthalpy of Medium";

Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");
// Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
// Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");

initial equation
if init_method == Init.h then
Expand All @@ -61,13 +62,13 @@ initial equation

equation
//this workaround is necessary, because the method density_derp_h is not implemented in all media, and therefore has to be removed conditionally when not implemented"
connect(tmp_dddp, tmp2_dddp);
if density_derp_h_from_media then
density_derp_h = tmp2_dddp;
else
density_derp_h = density_derp_h_set;
tmp2_dddp = 0;
end if;
// connect(tmp_dddp, tmp2_dddp);
// if density_derp_h_from_media then
density_derp_h = Medium.density_derp_h(medium.state);
// else
// density_derp_h = density_derp_h_set;
// tmp2_dddp = 0;
// end if;

V = V_par;
W_v = 0;
Expand Down
24 changes: 9 additions & 15 deletions ThermofluidStream/Boundaries/Volume.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@ model Volume "Model of a vessel with fixed volume"
extends Internal.PartialVolume;

parameter SI.Volume V_par(displayUnit="l") = 0.001 "Volume of the Model";
parameter Boolean density_derp_h_from_media=false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));

protected
Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");
// parameter Boolean density_derp_h_from_media=false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
// annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
// parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
// annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));
//
// protected
// Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
// Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");
equation
//this workaround is necessary, because the method density_derp_h is not implemented in all media, and therefore has to be removed conditionally when not implemented"
connect(tmp_dddp, tmp2_dddp);
if density_derp_h_from_media then
density_derp_h = tmp2_dddp;
else
density_derp_h = density_derp_h_set;
tmp2_dddp = 0;
end if;
density_derp_h = Medium.density_derp_h(medium.state);

V = V_par;
W_v = 0;
Expand Down
30 changes: 15 additions & 15 deletions ThermofluidStream/Boundaries/VolumeMix.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ model VolumeMix "Volume with N inlets that allows mixing"
extends Internal.PartialVolumeN;

parameter SI.Volume V_par(displayUnit="l") = 0.001 "Volume of the Model";
parameter Boolean density_derp_h_from_media = false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));

protected
Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");
// parameter Boolean density_derp_h_from_media = false "EXPERIMENTAL: get density_derp_h from media model. The function is only implemented for some Media."
// annotation(Dialog(tab="Advanced", group="Damping", enable=(k_volume_damping > 0)));
// parameter SI.DerDensityByPressure density_derp_h_set = 1e-6 "Derivative of density by pressure estimation; Approx. 1e-5 for air, 1e-7 for water"
// annotation(Dialog(enable = ((k_volume_damping > 0) and not density_derp_h_from_media), tab="Advanced", group="Damping"));
//
// protected
// Modelica.Blocks.Interfaces.RealInput tmp_dddp(unit="s2/m2") = Medium.density_derp_h(medium.state) if density_derp_h_from_media;
// Modelica.Blocks.Interfaces.RealOutput tmp2_dddp(unit="s2/m2");
equation
//this workaround is necessary, because the method density_derp_h is not implemented in all media, and therefore has to be removed conditionally when not implemented"
connect(tmp_dddp, tmp2_dddp);
if density_derp_h_from_media then
density_derp_h = tmp2_dddp;
else
density_derp_h = density_derp_h_set;
tmp2_dddp = 0;
end if;
// connect(tmp_dddp, tmp2_dddp);
// if density_derp_h_from_media then
density_derp_h = Medium.density_derp_h(medium.state);
// else
// density_derp_h = density_derp_h_set;
// tmp2_dddp = 0;
// end if;

V = V_par;
W_v = 0;
Expand Down
8 changes: 3 additions & 5 deletions ThermofluidStream/Examples/HeatPump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ within ThermofluidStream.Examples;
model HeatPump
extends Modelica.Icons.Example;

replaceable package Medium = Media.XRGMedia.R1234yf_ph constrainedby
Media.myMedia.Interfaces.PartialMedium "Refrigerant Medium"
replaceable package Medium = Media.XRGMedia.R1234yf_ph constrainedby Media.myMedia.Interfaces.PartialMedium "Refrigerant Medium"
annotation(choicesAllMatching=true);
replaceable package Air = Media.myMedia.Air.DryAirNasa constrainedby
Media.myMedia.Interfaces.PartialMedium "Air Medium"
replaceable package Air = Media.myMedia.Air.DryAirNasa constrainedby Media.myMedia.Interfaces.PartialMedium "Air Medium"
annotation(choicesAllMatching=true);

HeatExchangers.DiscretizedHEX condenser(
Expand Down Expand Up @@ -258,7 +256,7 @@ model HeatPump
ThermofluidStream.Utilities.showRealValue showRealValue(
use_numberPort=false,
description="COP",
number=condenser.Q_flow_air/max(0.00001,compressor.W_t)) annotation (Placement(transformation(extent={{80,-94},{154,-56}})));
number=condenser.Q_flow_air/max({0.00001 + compressor.W_t})) annotation (Placement(transformation(extent={{80,-94},{154,-56}})));
ThermofluidStream.Utilities.Icons.DLRLogo dLRLogo annotation (Placement(transformation(extent={{134,-156},{190,-100}})));
equation
connect(source1.outlet, flowResistance2.inlet) annotation (Line(
Expand Down
10 changes: 6 additions & 4 deletions ThermofluidStream/Examples/SimpleCoolingCycle.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ extends Modelica.Icons.Example;
ThermofluidStream.Media.myMedia.Water.ConstantPropertyLiquidWater
constrainedby ThermofluidStream.Media.myMedia.Interfaces.PartialMedium annotation(choicesAllMatching = true);

replaceable package medium_air = ThermofluidStream.Media.myMedia.Air.DryAirNasa
replaceable package medium_air =
ThermofluidStream.Media.myMedia.Air.DryAirNasa
constrainedby ThermofluidStream.Media.myMedia.Interfaces.PartialMedium annotation(choicesAllMatching = true);

ThermofluidStream.HeatExchangers.CounterFlowNTU heatExchange_CounterFlowNTU(
Expand Down Expand Up @@ -41,8 +42,8 @@ extends Modelica.Icons.Example;
r=0.05,
l=1,
redeclare function pLoss =
ThermofluidStream.Processes.Internal.FlowResistance.linearQuadraticPressureLoss (
k=1e5))
ThermofluidStream.Processes.Internal.FlowResistance.linearQuadraticPressureLoss
(k=1e5))
annotation (Placement(transformation(extent={{60,50},{80,70}})));
ThermofluidStream.Sensors.MultiSensor_Tpm multiSensor_Tpm1(redeclare package Medium =
medium_liquid, temperatureUnit="degC")
Expand Down Expand Up @@ -88,7 +89,8 @@ extends Modelica.Icons.Example;
annotation (Placement(transformation(extent={{98,-70},{118,-50}})));

ThermofluidStream.Processes.Fan fan(redeclare package Medium = medium_air,
initM_flow=ThermofluidStream.Utilities.Types.InitializationMethods.state,redeclare function dp_tau_fan =
initM_flow=ThermofluidStream.Utilities.Types.InitializationMethods.state,redeclare
function dp_tau_fan =
Processes.Internal.TurboComponent.dp_tau_const_isentrop (omega_ref=100))
annotation (Placement(transformation(extent={{140,-36},{160,-16}})));
Modelica.Blocks.Sources.RealExpression pump_speed(y=80 + 273.15)
Expand Down
Loading

0 comments on commit bf8f317

Please sign in to comment.