Buildings.Media.Examples.BaseClasses

Package with base classes for Buildings.Media.Examples

Information

This package contains base classes that are used to construct the models in Buildings.Media.Examples.

Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).

Package Content

Name Description
Buildings.Media.Examples.BaseClasses.FluidProperties FluidProperties Model that tests the implementation of the fluid properties
Buildings.Media.Examples.BaseClasses.PartialProperties PartialProperties Partial model that contains common parameters of the fluid properties
Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion TestTemperatureEnthalpyInversion Model to check computation of h(T) and its inverse with a controlleable tolerance

Buildings.Media.Examples.BaseClasses.FluidProperties

Model that tests the implementation of the fluid properties

Information

This example checks thermophysical properties of the medium.

Extends from PartialProperties (Partial model that contains common parameters of the fluid properties).

Parameters

TypeNameDefaultDescription
replaceable package MediumPartialMedium 
TemperatureTMin Minimum temperature for the simulation [K]
TemperatureTMax Maximum temperature for the simulation [K]
PressurepMedium.p_defaultPressure [Pa]
MassFractionX[Medium.nX]Medium.X_defaultMass fraction [1]
RealerrAbs1E-8Absolute error used in the check of the state calculations

Modelica definition

partial model FluidProperties "Model that tests the implementation of the fluid properties" extends PartialProperties; Medium.ThermodynamicState state_phX "Medium state"; Medium.ThermodynamicState state_psX "Medium state"; Modelica.Media.Interfaces.Types.DerDensityByPressure ddpT "Density derivative w.r.t. pressure"; Modelica.Media.Interfaces.Types.DerDensityByTemperature ddTp "Density derivative w.r.t. temperature"; Modelica.Units.SI.Density[Medium.nX] dddX "Density derivative w.r.t. mass fraction"; 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 ddpT = Medium.density_derp_T(state_pTX); ddTp = Medium.density_derT_p(state_pTX); dddX = Medium.density_derX(state_pTX); end FluidProperties;

Buildings.Media.Examples.BaseClasses.PartialProperties

Partial model that contains common parameters of the fluid properties

Information

This example checks thermophysical properties of the medium.

Parameters

TypeNameDefaultDescription
replaceable package MediumModelica.Media.Interfaces.Pa... 
TemperatureTMin Minimum temperature for the simulation [K]
TemperatureTMax Maximum temperature for the simulation [K]
PressurepMedium.p_defaultPressure [Pa]
MassFractionX[Medium.nX]Medium.X_defaultMass fraction [1]
RealerrAbs1E-8Absolute error used in the check of the state calculations

Connectors

TypeNameDescription
replaceable package Medium 

Modelica definition

partial model PartialProperties "Partial model that contains common parameters of the fluid properties" replaceable package Medium = Modelica.Media.Interfaces.PartialMedium; parameter Modelica.Units.SI.Temperature TMin "Minimum temperature for the simulation"; parameter Modelica.Units.SI.Temperature TMax "Maximum temperature for the simulation"; parameter Modelica.Units.SI.Pressure p=Medium.p_default "Pressure"; parameter Modelica.Units.SI.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.Units.NonSI.Temperature_degC T_degC "Celsius temperature"; Medium.ThermodynamicState state_pTX "Medium state"; Modelica.Units.SI.Density d "Density"; Modelica.Units.SI.DynamicViscosity eta "Dynamic viscosity"; Modelica.Units.SI.SpecificEnthalpy h "Specific enthalpy"; Modelica.Units.SI.SpecificInternalEnergy u "Specific internal energy"; Modelica.Units.SI.SpecificEntropy s "Specific entropy"; Modelica.Units.SI.SpecificEnergy g "Specific Gibbs energy"; Modelica.Units.SI.SpecificEnergy f "Specific Helmholtz energy"; Modelica.Units.SI.SpecificEnthalpy hIse "Isentropic enthalpy"; Modelica.Media.Interfaces.Types.IsobaricExpansionCoefficient beta "Isobaric expansion coefficient"; Modelica.Units.SI.IsothermalCompressibility kappa "Isothermal compressibility"; Modelica.Units.SI.SpecificHeatCapacity cp "Specific heat capacity"; Modelica.Units.SI.SpecificHeatCapacity cv "Specific heat capacity"; Modelica.Units.SI.ThermalConductivity lambda "Thermal conductivity"; Modelica.Units.SI.AbsolutePressure pMed "Pressure"; Medium.Temperature TMed "Temperature"; Modelica.Units.SI.MolarMass MM "Mixture molar mass"; Medium.BaseProperties basPro "Medium base properties"; protected constant Real conv(unit="1/s") = 1 "Conversion factor to satisfy unit check"; 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 "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(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); T_degC =Modelica.Units.Conversions.to_degC(T); // Check the implementation of the functions d = Medium.density(state_pTX); eta = Medium.dynamicViscosity(state_pTX); h = Medium.specificEnthalpy(state_pTX); u = Medium.specificInternalEnergy(state_pTX); s = Medium.specificEntropy(state_pTX); g = Medium.specificGibbsEnergy(state_pTX); f = Medium.specificHelmholtzEnergy(state_pTX); hIse = Medium.isentropicEnthalpy(p, state_pTX); beta = Medium.isobaricExpansionCoefficient(state_pTX); kappa = Medium.isothermalCompressibility(state_pTX); cp = Medium.specificHeatCapacityCp(state_pTX); cv = Medium.specificHeatCapacityCv(state_pTX); lambda = Medium.thermalConductivity(state_pTX); pMed = Medium.pressure(state_pTX); assert(abs(p-pMed) < errAbs, "Error in pressure computation."); TMed = Medium.temperature(state_pTX); 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) < errAbs, "Error in enthalpy computation in BaseProperties."); assert(abs(u-basPro.u) < errAbs, "Error in internal energy computation in BaseProperties."); end PartialProperties;

Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion

Model to check computation of h(T) and its inverse with a controlleable tolerance

Information

This model computes h=f(T0) and T=g(h). It then checks whether T=T0. Hence, it checks whether the function T_phX is implemented correctly.

Parameters

TypeNameDefaultDescription
replaceable package MediumModelica.Media.Interfaces.Pa... 
TemperatureT0273.15 + 20Temperature [K]
Realtol1E-8Numerical tolerance

Connectors

TypeNameDescription
replaceable package Medium 

Modelica definition

partial model TestTemperatureEnthalpyInversion "Model to check computation of h(T) and its inverse with a controlleable tolerance" replaceable package Medium = Modelica.Media.Interfaces.PartialMedium; parameter Modelica.Units.SI.Temperature T0=273.15 + 20 "Temperature"; parameter Real tol = 1E-8 "Numerical tolerance"; Modelica.Units.SI.Temperature T "Temperature"; Modelica.Units.SI.SpecificEnthalpy h "Enthalpy"; Medium.MassFraction Xi[:] = Medium.reference_X "Mass fraction"; equation h = Medium.specificEnthalpy_pTX(p=101325, T=T0, X=Xi); T = Medium.temperature_phX(p=101325, h=h, X=Xi); if (time>=0.1) then assert(abs(T-T0)<tol, "Error in implementation of functions.\n" + " T0 = " + String(T0) + "\n" + " T = " + String(T) + "\n" + " Absolute error: " + String(abs(T-T0)) + " K"); end if; end TestTemperatureEnthalpyInversion;