Skip to content

Commit

Permalink
Changed models to make u instead of U a state
Browse files Browse the repository at this point in the history
Also, set nominal attribute for Medium.T as this is a state if mSenFac > 1. For #1412
  • Loading branch information
mwetter committed Nov 9, 2020
1 parent ae1c568 commit 789e741
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
29 changes: 14 additions & 15 deletions IBPSA/Fluid/Interfaces/ConservationEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,23 @@ model ConservationEquation "Lumped volume with mass and energy balance"

// Set nominal attributes where literal values can be used.
Medium.BaseProperties medium(
preferredMediumStates = energyDynamics <> Modelica.Fluid.Types.Dynamics.SteadyState,
p(start=p_start),
h(start=hStart),
u(nominal=1E4,
stateSelect=StateSelect.prefer),
T(start=T_start),
Xi(
start=X_start[1:Medium.nXi],
nominal=Medium.X_default[1:Medium.nXi],
stateSelect=StateSelect.prefer),
Xi(start=X_start[1:Medium.nXi]),
X(start=X_start),
d(start=rho_start,
stateSelect=if massDynamics == Modelica.Fluid.Types.Dynamics.SteadyState
then StateSelect.default else StateSelect.prefer)) "Medium properties";
d(start=rho_start)) "Medium properties";

Modelica.SIunits.Energy U(start=fluidVolume*rho_start*
Medium.specificInternalEnergy(Medium.setState_pTX(
T=T_start,
p=p_start,
X=X_start[1:Medium.nXi])) +
(T_start - Medium.reference_T)*CSen,
nominal = 1E5) "Internal energy of fluid";
(T_start - Medium.reference_T)*CSen) "Internal energy of fluid";

Modelica.SIunits.Mass m(
min=Modelica.Constants.eps,
start=fluidVolume*rho_start)
"Mass of fluid";

Expand All @@ -125,11 +119,8 @@ model ConservationEquation "Lumped volume with mass and energy balance"
parameter Modelica.SIunits.Volume fluidVolume "Volume";
final parameter Modelica.SIunits.HeatCapacity CSen=
(mSenFac - 1)*rho_default*cp_default*fluidVolume
"Aditional heat capacity for implementing mFactor";
"Additional heat capacity for implementing mFactor";
protected
Medium.EnthalpyFlowRate ports_H_flow[nPorts];
Modelica.SIunits.MassFlowRate ports_mXi_flow[nPorts,Medium.nXi];
Medium.ExtraPropertyFlowRate ports_mC_flow[nPorts,Medium.nC];
parameter Modelica.SIunits.SpecificHeatCapacity cp_default=
Medium.specificHeatCapacityCp(state=state_default)
"Heat capacity, to compute additional dry mass";
Expand Down Expand Up @@ -165,6 +156,14 @@ protected
constant Boolean _simplify_mWat_flow = simplify_mWat_flow and Medium.nX > 1
"If true, then port_a.m_flow + port_b.m_flow = 0 even if mWat_flow is non-zero, and equations are simplified";

// Quantities exchanged through the fluid ports
Medium.EnthalpyFlowRate ports_H_flow[nPorts]
"Enthalpy flow rates at the ports";
Modelica.SIunits.MassFlowRate ports_mXi_flow[nPorts, Medium.nXi]
"Mass fraction flow rates at the ports";
Medium.ExtraPropertyFlowRate ports_mC_flow[nPorts, Medium.nC]
"Trace substance flow rates at the ports";

// Conditional connectors
Modelica.Blocks.Interfaces.RealInput mWat_flow_internal(unit="kg/s")
"Needed to connect to conditional connector";
Expand Down
9 changes: 6 additions & 3 deletions IBPSA/Media/Air.mo
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ package Air

InputAbsolutePressure p "Absolute pressure of medium";
InputMassFraction[1] Xi(
start=reference_X[1:1],
start=X_default[1:1],
nominal={0.01},
each stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default)
"Structurally independent mass fractions";
InputSpecificEnthalpy h "Specific enthalpy of medium";
Modelica.Media.Interfaces.Types.Density d "Density of medium";
Modelica.Media.Interfaces.Types.Temperature T(
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default)
nominal=100)
"Temperature of medium";
Modelica.Media.Interfaces.Types.MassFraction[2] X(start=reference_X)
"Mass fractions (= (component mass)/total mass m_i/m)";
Modelica.Media.Interfaces.Types.SpecificInternalEnergy u
Modelica.Media.Interfaces.Types.SpecificInternalEnergy u(
nominal=1E4,
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default)
"Specific internal energy of medium";
Modelica.Media.Interfaces.Types.SpecificHeatCapacity R
"Gas constant (of mixture if applicable)";
Expand Down
8 changes: 4 additions & 4 deletions IBPSA/Media/Antifreeze/PropyleneGlycolWater.mo
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ package PropyleneGlycolWater
"Mass fraction of propylene glycol in water";

redeclare model BaseProperties "Base properties"
Temperature T(stateSelect=
if preferredMediumStates then StateSelect.prefer else StateSelect.default)
"Temperature of medium";
Temperature T "Temperature of medium";

InputAbsolutePressure p "Absolute pressure of medium";
InputMassFraction[nXi] Xi=fill(0, 0)
"Structurally independent mass fractions";
InputSpecificEnthalpy h "Specific enthalpy of medium";
Modelica.SIunits.SpecificInternalEnergy u
Modelica.SIunits.SpecificInternalEnergy u(
nominal=1E4,
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default)
"Specific internal energy of medium";
Modelica.SIunits.Density d=d_const "Density of medium";
Modelica.SIunits.MassFraction[nX] X={1}
Expand Down
10 changes: 7 additions & 3 deletions IBPSA/Media/Specialized/Air/PerfectGas.mo
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ package PerfectGas "Model for air as a perfect gas"
end ThermodynamicState;

redeclare replaceable model extends BaseProperties(
p(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
Xi(each stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
u(nominal=1E4,
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
d(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
Xi(
nominal={0.01},
each stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
final standardOrderComponents=true)

/* p, T, X = X[Water] are used as preferred states, since only then all
Expand Down Expand Up @@ -61,7 +65,7 @@ as required from medium model \"" + mediumName + "\".");
R = dryair.R*(1 - X_steam) + steam.R*X_steam;
//
u = h - R*T;
p = d*R*T;
d = p/(R*T);
/* Note, u and d are computed under the assumption that the volume of the liquid
water is negligible with respect to the volume of air and of steam
*/
Expand Down
11 changes: 5 additions & 6 deletions IBPSA/Media/Specialized/Water/TemperatureDependentDensity.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ package TemperatureDependentDensity
each casRegistryNumber="7732-18-5",
each iupacName="oxidane",
each molarMass=MM_const);

redeclare record extends ThermodynamicState "Thermodynamic state variables"
Temperature T(start=T_default) "Temperature of medium";
AbsolutePressure p(start=p_default) "Pressure of medium";
end ThermodynamicState;

constant Modelica.SIunits.SpecificHeatCapacity cp_const = 4184
"Specific heat capacity at constant pressure";

redeclare model extends BaseProperties(
preferredMediumStates=true) "Base properties"
u(nominal=1E4,
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default))
"Base properties"

equation
h = (T - reference_T)*cp_const;
u = h-reference_p/d;
Expand Down Expand Up @@ -662,7 +663,6 @@ First implementation.
</ul>
</html>"));
end setState_psX;

//////////////////////////////////////////////////////////////////////
// Protected classes.
// These classes are only of use within this medium model.
Expand Down Expand Up @@ -786,8 +786,7 @@ but converted from Celsius to Kelvin.
</ul>
</html>"));
end kinematicViscosity;

annotation(preferredView="info", Documentation(info="<html>
annotation(Documentation(info="<html>
<p>
This medium package models liquid water.
</p>
Expand Down
7 changes: 4 additions & 3 deletions IBPSA/Media/Water.mo
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package Water "Package with model for liquid water with constant density"
final parameter Boolean standardOrderComponents=true
"If true, and reducedX = true, the last element of X will be computed from the other ones";
Modelica.SIunits.Density d=d_const "Density of medium";
Temperature T(stateSelect=
if preferredMediumStates then StateSelect.prefer else StateSelect.default)
Temperature T
"Temperature of medium";
InputAbsolutePressure p "Absolute pressure of medium";
InputMassFraction[nXi] Xi=fill(0, 0)
"Structurally independent mass fractions";
InputSpecificEnthalpy h "Specific enthalpy of medium";
Modelica.SIunits.SpecificInternalEnergy u
Modelica.SIunits.SpecificInternalEnergy u(
nominal=1E4,
stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default)
"Specific internal energy of medium";

Modelica.SIunits.MassFraction[nX] X={1}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
simulateModel("IBPSA.Fluid.Interfaces.Examples.Humidifier_u", method="Radau", stopTime=3600, tolerance=1e-6, resultFile="InterfacesHumidifier_u");
simulateModel("IBPSA.Fluid.Interfaces.Examples.Humidifier_u", method="Cvode", stopTime=3600, tolerance=1e-6, resultFile="InterfacesHumidifier_u");
createPlot(id=1, position={15, 10, 413, 444}, y={"hea1.sta_a.T", "hea1.sta_b.T", "hea2.sta_a.T", "hea2.sta_b.T"}, range={0.0, 4000.0, 15.0, 21.0}, grid=true, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}});
createPlot(id=1, position={15, 10, 413, 220}, y={"hea3.sta_a.T", "hea3.sta_b.T", "hea4.sta_a.T", "hea4.sta_b.T", "mix1.T"}, range={0.0, 4000.0, 15.0, 21.0}, grid=true, subPlot=2, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}});
createPlot(id=3, position={435, 8, 400, 447}, y={"hea1.m_flow", "hea2.m_flow"}, range={0.0, 4000.0, -0.6000000000000001, 0.8}, grid=true, colors={{28,108,200}, {238,46,47}});
Expand Down

0 comments on commit 789e741

Please sign in to comment.