Description: "Collection of models that test the media models"

- Home > Modelica

## Buildings.Media.Examples

Collection of models that test the media models

### Information

This package contains examples that test the media packages in Buildings.Media.

Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).

### Package Content

Name | Description
--- | ---
AirDerivativeCheck | Model that tests the derivative implementation
AirProperties | Model that tests the implementation of the fluid properties
AirTemperatureEnthalpyInversion | Model to check computation of h(T) and its inverse
AirTestImplementation | Model that tests the medium implementation
WaterDerivativeCheck | Model that tests the derivative implementation
WaterProperties | Model that tests the implementation of the fluid properties
WaterTemperatureEnthalpyInversion | Model to check computation of h(T) and its inverse
WaterTestImplementation | Model that tests the medium implementation
BaseClasses | Package with base classes for Buildings.Media.Examples

## Buildings.Media.Examples.AirDerivativeCheck

Model that tests the derivative implementation

### Information

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.

Extends from Modelica.Icons.Example (Icon for runnable examples).

### Modelica definition

model AirDerivativeCheck "Model that tests the derivative implementation" extends Modelica.Icons.Example; package Medium = Buildings.Media.Air; Modelica.SIunits.SpecificEnthalpy hLiqSym "Liquid phase enthalpy"; Modelica.SIunits.SpecificEnthalpy hLiqCod "Liquid phase enthalpy"; Modelica.SIunits.SpecificEnthalpy hSteSym "Water vapor enthalpy"; Modelica.SIunits.SpecificEnthalpy hSteCod "Water vapor enthalpy"; Modelica.SIunits.SpecificEnthalpy hAirSym "Dry air enthalpy"; Modelica.SIunits.SpecificEnthalpy hAirCod "Dry air 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 conv(unit="K/s") = 1 "Conversion factor to satisfy unit check"; initial equation hLiqSym = hLiqCod; hSteSym = hSteCod; hAirSym = hAirCod; cpSym = cpCod; cvSym = cvCod; equation hLiqCod=Medium.enthalpyOfLiquid(conv*time); der(hLiqCod)=der(hLiqSym); assert(abs(hLiqCod-hLiqSym) < 1E-2, "Model has an error"); hSteCod=Medium.enthalpyOfCondensingGas(conv*time); der(hSteCod)=der(hSteSym); assert(abs(hSteCod-hSteSym) < 1E-2, "Model has an error"); hAirCod=Medium.enthalpyOfNonCondensingGas(conv*time); der(hAirCod)=der(hAirSym); assert(abs(hAirCod-hAirSym) < 1E-2, "Model has an error"); cpCod=Medium.specificHeatCapacityCp( Medium.setState_pTX( p=1e5, T=conv*time, X={0.1})); der(cpCod)=der(cpSym); assert(abs(cpCod-cpSym) < 1E-2, "Model has an error"); cvCod=Medium.specificHeatCapacityCv( Medium.setState_pTX( p=1e5, T=conv*time, X={0.1})); der(cvCod)=der(cvSym); assert(abs(cvCod-cvSym) < 1E-2, "Model has an error"); end AirDerivativeCheck;

## Buildings.Media.Examples.AirProperties

Model that tests the implementation of the fluid properties

### Information

This example checks thermophysical properties of the medium.

Extends from Modelica.Icons.Example (Icon for runnable examples), Buildings.Media.Examples.BaseClasses.FluidProperties (Model that tests the implementation of the fluid properties).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialMedium |
Temperature | TMin | 273.15 - 30 | Minimum temperature for the simulation [K]
Temperature | TMax | 273.15 + 60 | Maximum temperature for the simulation [K]
Pressure | p | Medium.p_default | Pressure [Pa]
MassFraction | X[Medium.nX] | Medium.X_default | Mass fraction [1]

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium |

### Modelica definition

model AirProperties "Model that tests the implementation of the fluid properties" extends Modelica.Icons.Example; extends Buildings.Media.Examples.BaseClasses.FluidProperties( redeclare package Medium = Buildings.Media.Air, TMin=273.15-30, TMax=273.15+60); Modelica.SIunits.SpecificEnthalpy hLiq "Specific enthalpy of liquid"; equation // Check the implementation of the base properties basPro.state.p=p; basPro.state.T=T; basPro.state.X[1]=X[1]; hLiq = Medium.enthalpyOfLiquid(T); if Medium.nX == 1 then assert(abs(h-hLiq) < 1e-8, "Error in enthalpy computation."); end if; end AirProperties;

## Buildings.Media.Examples.AirTemperatureEnthalpyInversion

Model to check computation of h(T) and its inverse

### Information

This model tests whether the inversion of temperature and enthalpy is implemented correctly. If T ≠ T(h(T)), the model stops with an error.

Extends from Modelica.Icons.Example (Icon for runnable examples), Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion (Model to check computation of h(T) and its inverse).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialCondensingGases |
Temperature | T0 | 273.15 + 20 | Temperature [K]

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium |

### Modelica definition

model AirTemperatureEnthalpyInversion "Model to check computation of h(T) and its inverse" extends Modelica.Icons.Example; extends Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion ( redeclare package Medium = Buildings.Media.Air); end AirTemperatureEnthalpyInversion;

## Buildings.Media.Examples.AirTestImplementation

Model that tests the medium implementation

### Information

This is a simple test for the medium model. It uses the test model described in Modelica.Media.UsersGuide.MediumDefinition.TestOfMedium.

Extends from Modelica.Icons.Example (Icon for runnable examples), Modelica.Media.Examples.Tests.Components.PartialTestModel (Basic test model to test a medium).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialMedium | Medium model
AbsolutePressure | p_start | Medium.p_default | Initial value of pressure [Pa]
Temperature | T_start | Medium.T_default | Initial value of temperature [K]
SpecificEnthalpy | h_start | Medium.h_default | Initial value of specific enthalpy [J/kg]
Real | X_start[Medium.nX] | Medium.X_default | Initial value of mass fractions

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium | Medium model

### Modelica definition

model AirTestImplementation "Model that tests the medium implementation" extends Modelica.Icons.Example; extends Modelica.Media.Examples.Tests.Components.PartialTestModel( redeclare package Medium = Buildings.Media.Air); end AirTestImplementation;

## Buildings.Media.Examples.WaterDerivativeCheck

Model that tests the derivative implementation

### Information

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.

Extends from Modelica.Icons.Example (Icon for runnable examples).

### Modelica definition

model WaterDerivativeCheck "Model that tests the derivative implementation" extends Modelica.Icons.Example; package Medium = Buildings.Media.Water; Modelica.SIunits.SpecificEnthalpy hLiqSym "Liquid phase enthalpy"; Modelica.SIunits.SpecificEnthalpy hLiqCod "Liquid phase 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 conv(unit="K/s") = 1 "Conversion factor to satisfy unit check"; initial equation hLiqSym = hLiqCod; cpSym = cpCod; cvSym = cvCod; equation hLiqCod=Medium.enthalpyOfLiquid(conv*time); der(hLiqCod)=der(hLiqSym); assert(abs(hLiqCod-hLiqSym) < 1E-2, "Model has an error"); cpCod=Medium.specificHeatCapacityCp( Medium.setState_pTX( p=1e5, T=conv*time, X={0.1})); der(cpCod)=der(cpSym); assert(abs(cpCod-cpSym) < 1E-2, "Model has an error"); cvCod=Medium.specificHeatCapacityCv( Medium.setState_pTX( p=1e5, T=conv*time, X={0.1})); der(cvCod)=der(cvSym); assert(abs(cvCod-cvSym) < 1E-2, "Model has an error"); end WaterDerivativeCheck;

## Buildings.Media.Examples.WaterProperties

Model that tests the implementation of the fluid properties

### Information

This example checks thermophysical properties of the medium.

Extends from Modelica.Icons.Example (Icon for runnable examples), Buildings.Media.Examples.BaseClasses.FluidProperties (Model that tests the implementation of the fluid properties).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialMedium |
Temperature | TMin | 273.15 | Minimum temperature for the simulation [K]
Temperature | TMax | 373.15 | Maximum temperature for the simulation [K]
Pressure | p | Medium.p_default | Pressure [Pa]
MassFraction | X[Medium.nX] | Medium.X_default | Mass fraction [1]

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium |

### Modelica definition

model WaterProperties "Model that tests the implementation of the fluid properties" extends Modelica.Icons.Example; extends Buildings.Media.Examples.BaseClasses.FluidProperties( redeclare package Medium = Buildings.Media.Water, TMin=273.15, TMax=373.15); equation // Check the implementation of the base properties basPro.state.p=p; basPro.state.T=T; end WaterProperties;

## Buildings.Media.Examples.WaterTemperatureEnthalpyInversion

Model to check computation of h(T) and its inverse

### Information

This model tests whether the inversion of temperature and enthalpy is implemented correctly. If T ≠ T(h(T)), the model stops with an error.

Extends from Modelica.Icons.Example (Icon for runnable examples), Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion (Model to check computation of h(T) and its inverse).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialCondensingGases |
Temperature | T0 | 273.15 + 20 | Temperature [K]

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium |

### Modelica definition

model WaterTemperatureEnthalpyInversion "Model to check computation of h(T) and its inverse" extends Modelica.Icons.Example; extends Buildings.Media.Examples.BaseClasses.TestTemperatureEnthalpyInversion ( redeclare package Medium = Buildings.Media.Water); end WaterTemperatureEnthalpyInversion;

## Buildings.Media.Examples.WaterTestImplementation

Model that tests the medium implementation

### Information

This is a simple test for the medium model. It uses the test model described in Modelica.Media.UsersGuide.MediumDefinition.TestOfMedium.

Extends from Modelica.Icons.Example (Icon for runnable examples), Modelica.Media.Examples.Tests.Components.PartialTestModel (Basic test model to test a medium).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
replaceable package Medium | PartialMedium | Medium model
AbsolutePressure | p_start | Medium.p_default | Initial value of pressure [Pa]
Temperature | T_start | Medium.T_default | Initial value of temperature [K]
SpecificEnthalpy | h_start | Medium.h_default | Initial value of specific enthalpy [J/kg]
Real | X_start[Medium.nX] | Medium.X_default | Initial value of mass fractions

### Connectors

Type | Name | Description
--- | --- | ---
replaceable package Medium | Medium model

### Modelica definition

model WaterTestImplementation "Model that tests the medium implementation" extends Modelica.Icons.Example; extends Modelica.Media.Examples.Tests.Components.PartialTestModel( redeclare package Medium = Buildings.Media.Water); end WaterTestImplementation;