Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Medium.Steam from IBPSA, branch issue1389_mediaSteam #2536

Merged
merged 4 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions Buildings/.copiedFiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,10 @@ Buildings/Media/Examples/BaseClasses/package.order
Buildings/Media/Examples/PropyleneGlycolWaterDerivativeCheck.mo
Buildings/Media/Examples/PropyleneGlycolWaterProperties.mo
Buildings/Media/Examples/PropyleneGlycolWaterTemperatureEnthalpyInversion.mo
Buildings/Media/Examples/SteamDerivativeCheck.mo
Buildings/Media/Examples/SteamProperties.mo
Buildings/Media/Examples/SteamSaturationConsistencyCheck.mo
Buildings/Media/Examples/SteamTemperatureEnthalpyInversion.mo
Buildings/Media/Examples/WaterDerivativeCheck.mo
Buildings/Media/Examples/WaterProperties.mo
Buildings/Media/Examples/WaterTemperatureEnthalpyInversion.mo
Expand Down Expand Up @@ -1262,6 +1266,7 @@ Buildings/Media/Specialized/Water/package.mo
Buildings/Media/Specialized/Water/package.order
Buildings/Media/Specialized/package.mo
Buildings/Media/Specialized/package.order
Buildings/Media/Steam.mo
Buildings/Media/Water.mo
Buildings/Media/package.mo
Buildings/Media/package.order
Expand Down Expand Up @@ -1862,6 +1867,10 @@ Buildings/Resources/Scripts/Dymola/Media/Examples/AirTemperatureEnthalpyInversio
Buildings/Resources/Scripts/Dymola/Media/Examples/PropyleneGlycolWaterDerivativeCheck.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/PropyleneGlycolWaterProperties.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/PropyleneGlycolWaterTemperatureEnthalpyInversion.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/SteamDerivativeCheck.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/SteamProperties.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/SteamSaturationConsistencyCheck.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/SteamTemperatureEnthalpyInversion.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/WaterDerivativeCheck.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/WaterProperties.mos
Buildings/Resources/Scripts/Dymola/Media/Examples/WaterTemperatureEnthalpyInversion.mos
Expand Down
8 changes: 6 additions & 2 deletions Buildings/Airflow/Multizone/DoorOperable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ protected

Modelica.SIunits.VolumeFlowRate VABpOpeClo_flow[2](each nominal=0.001)
"Volume flow rate from A to B if positive due to static pressure difference";
Modelica.SIunits.VolumeFlowRate VABp_flow(nominal=0.001)
"Volume flow rate from A to B if positive due to static pressure difference";

Modelica.SIunits.Area A "Current opening area";
equation
Expand Down Expand Up @@ -174,6 +172,12 @@ November, 2002.
revisions="<html>
<ul>
<li>
June 11, 2021, by Michael Wetter:<br/>
Removed duplicate declaration of <code>VABp_flow</code>.<br/>
This is for
<a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1496\">#1496</a>.
</li>
<li>
January 22, 2020, by Michael Wetter:<br/>
Revised buoyancy-driven flow.
</li>
Expand Down
4 changes: 2 additions & 2 deletions Buildings/Media/Examples/BaseClasses/FluidProperties.mo
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ equation
state_pTX = Medium.setState_pTX(p=p, T=T, X=X);
state_phX = Medium.setState_phX(p=p, h=h, X=X);
state_psX = Medium.setState_psX(p=p, s=s, X=X);
checkState(state_pTX, state_phX, "state_phX");
checkState(state_pTX, state_psX, "state_psX");
checkState(state_pTX, state_phX, errAbs, "state_phX");
checkState(state_pTX, state_psX, errAbs, "state_psX");

// Check the implementation of the functions
ddpT = Medium.density_derp_T(state_pTX);
Expand Down
32 changes: 23 additions & 9 deletions Buildings/Media/Examples/BaseClasses/PartialProperties.mo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ partial model PartialProperties
parameter Modelica.SIunits.Pressure p = Medium.p_default "Pressure";
parameter Modelica.SIunits.MassFraction X[Medium.nX]=
Medium.X_default "Mass fraction";
parameter Real errAbs=1E-8 "Absolute error used in the check of the state calculations";
Medium.Temperature T "Temperature";
Modelica.SIunits.Conversions.NonSIunits.Temperature_degC T_degC
"Celsius temperature";
Expand Down Expand Up @@ -43,17 +44,26 @@ partial model PartialProperties
protected
constant Real conv(unit="1/s") = 1 "Conversion factor to satisfy unit check";

function checkState
function checkState "This function checks the absolute error in the state calculations"
extends Modelica.Icons.Function;
input Medium.ThermodynamicState state1 "Medium state";
input Medium.ThermodynamicState state2 "Medium state";
input Real errAbs=errAbs "Absolute error threshold";
input String message "Message for error reporting";

protected
Real TErrAbs=abs(Medium.temperature(state1)-Medium.temperature(state2))
"Absolute error in temperature";
protected
Real pErrAbs=abs(Medium.pressure(state1)-Medium.pressure(state2))
"Absolute error in pressure";
algorithm
assert(abs(Medium.temperature(state1)-Medium.temperature(state2))
< 1e-8, "Error in temperature of " + message);
assert(abs(Medium.pressure(state1)-Medium.pressure(state2))
< 1e-8, "Error in pressure of " + message);
assert(TErrAbs < errAbs, "Absolute temperature error: " + String(TErrAbs) +
" K. Error in temperature of " + message);
assert(pErrAbs < errAbs, "Absolute pressure error: " + String(pErrAbs) +
" Pa. Error in pressure of " + message);
end checkState;

equation
// Compute temperatures that are used as input to the functions
T = TMin + conv*time * (TMax-TMin);
Expand All @@ -76,13 +86,13 @@ equation
cv = Medium.specificHeatCapacityCv(state_pTX);
lambda = Medium.thermalConductivity(state_pTX);
pMed = Medium.pressure(state_pTX);
assert(abs(p-pMed) < 1e-8, "Error in pressure computation.");
assert(abs(p-pMed) < errAbs, "Error in pressure computation.");
TMed = Medium.temperature(state_pTX);
assert(abs(T-TMed) < 1e-8, "Error in temperature computation.");
assert(abs(T-TMed) < errAbs, "Error in temperature computation.");
MM = Medium.molarMass(state_pTX);
// Check the implementation of the base properties
assert(abs(h-basPro.h) < 1e-8, "Error in enthalpy computation in BaseProperties.");
assert(abs(u-basPro.u) < 1e-8, "Error in internal energy computation in BaseProperties.");
assert(abs(h-basPro.h) < errAbs, "Error in enthalpy computation in BaseProperties.");
assert(abs(u-basPro.u) < errAbs, "Error in internal energy computation in BaseProperties.");

annotation (
Documentation(info="<html>
Expand All @@ -93,6 +103,10 @@ This example checks thermophysical properties of the medium.
revisions="<html>
<ul>
<li>
March 24, 2020, by Kathryn Hinkelman:<br/>
Expand error message for checkState and added absolute error as input.
</li>
<li>
September 16, 2019, by Yangyang Fu:<br/>
Reconstruct the implementation structure to avoid duplicated codes for different media.
This fixes <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1206\">#1206</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ equation
if (time>0.1) then
assert(abs(T-T0)<tol, "Error in implementation of functions.\n"
+ " T0 = " + String(T0) + "\n"
+ " T = " + String(T));
+ " T = " + String(T) + "\n"
+ " Absolute error: " + String(abs(T-T0)) + " K");
end if;
annotation (preferredView="info", Documentation(info="<html>
This model computes <code>h=f(T0)</code> and
Expand All @@ -24,6 +25,10 @@ implemented correctly.
</html>", revisions="<html>
<ul>
<li>
March 24, 2020 by Kathryn Hinkelman:<br/>
Expanded the assert message to include absolute error value.
</li>
<li>
September 16, 2019 by Yangyang Fu:<br/>
Added a parameter <code>tol</code> to control numerical errors.
</li>
Expand Down
71 changes: 71 additions & 0 deletions Buildings/Media/Examples/SteamDerivativeCheck.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
within Buildings.Media.Examples;
model SteamDerivativeCheck "Model that tests the derivative implementation"
extends Modelica.Icons.Example;

package Medium = Buildings.Media.Steam "Medim model";

Modelica.SIunits.Temperature T "Temperature";
Modelica.SIunits.SpecificEnthalpy hVapSym "Vapor phase specific enthalpy";
Modelica.SIunits.SpecificEnthalpy hVapCod "Vapor phase specific enthalpy";
Modelica.SIunits.SpecificHeatCapacity cpSym "Specific heat capacity";
Modelica.SIunits.SpecificHeatCapacity cpCod "Specific heat capacity";
Modelica.SIunits.SpecificHeatCapacity cvSym "Specific heat capacity";
Modelica.SIunits.SpecificHeatCapacity cvCod "Specific heat capacity";
constant Real convT(unit="K/s3") = 270
"Conversion factor to satisfy unit check";
initial equation
hVapSym = hVapCod;
cpSym = cpCod;
cvSym = cvCod;
equation
T = 273.15+110+convT*time^3;
hVapCod=Medium.specificEnthalpy(
Medium.setState_pTX(
p=1e5,
T=T,
X=Medium.X_default));
assert(abs(hVapCod-hVapSym) < 1E-4 * (1+abs(hVapCod)), "Model has an error");
der(hVapCod)=der(hVapSym);

cpCod=Medium.specificHeatCapacityCp(
Medium.setState_pTX(
p=1e5,
T=T,
X=Medium.X_default));
der(cpCod)=der(cpSym);
assert(abs(cpCod-cpSym) < 1E-4 * (1+abs(cpCod)), "Model has an error");

cvCod=Medium.specificHeatCapacityCv(
Medium.setState_pTX(
p=1e5,
T=T,
X=Medium.X_default));
der(cvCod)=der(cvSym);
assert(abs(cvCod-cvSym) < 1E-4 * (1+abs(cvCod)), "Model has an error");

annotation(experiment(
StartTime=0, StopTime=1,
Tolerance=1E-10),
__Dymola_Commands(file="modelica://Buildings/Resources/Scripts/Dymola/Media/Examples/SteamDerivativeCheck.mos"
"Simulate and plot"),
Documentation(info="<html>
<p>
This example checks whether the function derivative
is implemented correctly. If the derivative implementation
is not correct, the model will stop with an assert statement.
</p>
</html>", revisions="<html>
<ul>
<li>
March 16, 2020, by Michael Wetter:<br/>
Changed to relative plus absolute error check in assertion because the specific enthalpy has a
magnitude of <i>1E6</i>, which causes the assertion to fail in JModelica if an absolute accuracy
of <i>1E-2</i> is requested.
</li>
<li>
March 6, 2020, by Kathryn Hinkelman:<br/>
First implementation.
</li>
</ul>
</html>"));
end SteamDerivativeCheck;
58 changes: 58 additions & 0 deletions Buildings/Media/Examples/SteamProperties.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
within Buildings.Media.Examples;
model SteamProperties
"Model that tests the implementation of the steam superheated properties"
extends Modelica.Icons.Example;
extends Buildings.Media.Examples.BaseClasses.PartialProperties(
redeclare package Medium = Buildings.Media.Steam (
p_default=200000),
TMin=273.15 + 100,
TMax=273.15 + 160,
p=200000);

Medium.ThermodynamicState state_phX "Medium state";
Medium.ThermodynamicState state_psX "Medium state";

Modelica.Media.Interfaces.Types.DerDensityByEnthalpy ddhp
"Density derivative w.r.t. enthalpy";
Modelica.Media.Interfaces.Types.DerDensityByPressure ddph
"Density derivative w.r.t. pressure";

equation

// Check setting the states
state_pTX = Medium.setState_pTX(p=p, T=T, X=X);
state_phX = Medium.setState_phX(p=p, h=h, X=X);
state_psX = Medium.setState_psX(p=p, s=s, X=X);
checkState(state_pTX, state_phX, errAbs, "state_phX");
checkState(state_pTX, state_psX, errAbs, "state_psX");

// Check the implementation of the functions
ddhp = Medium.density_derh_p(state_pTX);
ddph = Medium.density_derp_h(state_pTX);

// Check the implementation of the base properties
basPro.state.p=p;
basPro.state.T=T;

annotation(experiment(Tolerance=1e-6, StopTime=1.0),
__Dymola_Commands(file="modelica://Buildings/Resources/Scripts/Dymola/Media/Examples/SteamProperties.mos"
"Simulate and plot"),
Documentation(info="<html>
<p>
This example checks thermophysical properties of the medium.
</p>
</html>",
revisions="<html>
<ul>
<li>
October 30, 2020, by Kathryn Hinkelman:<br/>
Rebased steam medium to PartialMedium and improved steam property consistency
and efficiency.
</li>
<li>
September 12, 2019, by Yangyang Fu:<br/>
First implementation.
</li>
</ul>
</html>"));
end SteamProperties;
Loading