Buildings.Fluid.BaseClasses.FlowModels.Validation

Collection of validation models

Information

This package contains validation models for the classes in Buildings.Fluid.BaseClasses.FlowModels.

Note that most validation models contain simple input data which may not be realistic, but for which the correct output can be obtained through an analytic solution. The examples plot various outputs, which have been verified against these solutions. These model outputs are stored as reference data and used for continuous validation whenever models in the library change.

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

Package Content

Name Description
Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck BasicFlowFunction_dp_DerivativeCheck Model that checks the correct implementation of the 1st order derivative of the flow function
Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck2 BasicFlowFunction_dp_DerivativeCheck2 Model that checks the correct implementation of the 2nd order derivative of the flow function
Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck BasicFlowFunction_m_flow_DerivativeCheck Model that checks the correct implementation of the 1st order derivative of the flow function
Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck2 BasicFlowFunction_m_flow_DerivativeCheck2 Model that checks the correct implementation of the 2nd order derivative of the flow function
Buildings.Fluid.BaseClasses.FlowModels.Validation.InverseFlowFunctions InverseFlowFunctions Test model for flow function and its inverse
Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_dp InvertingBasicFlowFunction_dp Test model that inverts basicFlowFunction_dp
Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_m_flow InvertingBasicFlowFunction_m_flow Test model that inverts basicFlowFunction_m_flow

Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck

Model that checks the correct implementation of the 1st order derivative of the flow function

Information

This model validates the implementation of Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp and its first order derivative Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp_der. If the derivative implementation is wrong, the simulation will stop with an error.

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

Parameters

TypeNameDefaultDescription
Realk0.35Flow coefficient
MassFlowRatem_flow_turbulent0.36Mass flow rate where transition to turbulent flow occurs [kg/s]

Modelica definition

model BasicFlowFunction_dp_DerivativeCheck "Model that checks the correct implementation of the 1st order derivative of the flow function" extends Modelica.Icons.Example; constant Real gain=2 "Gain for computing the mass flow rate"; parameter Real k=0.35 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_turbulent=0.36 "Mass flow rate where transition to turbulent flow occurs"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.MassFlowRate m_flow_comp "Comparison value for m_flow"; Modelica.SIunits.PressureDifference dp "Pressure drop"; Modelica.SIunits.MassFlowRate err "Integration error"; initial equation m_flow = m_flow_comp; equation dp = time*gain; m_flow = Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp( dp=dp, k=k, m_flow_turbulent=m_flow_turbulent); der(m_flow) = der(m_flow_comp); err = m_flow - m_flow_comp; assert(abs(err) < 1E-3, "Error in implementation."); end BasicFlowFunction_dp_DerivativeCheck;

Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck2 Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_dp_DerivativeCheck2

Model that checks the correct implementation of the 2nd order derivative of the flow function

Information

This model validates the implementation of Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp and its second order derivative Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp_der2. If the derivative implementation is wrong, the simulation will stop with an error.

Implementation

The pressure drop dp is increased non-linearly in order for the first and second derivatives in Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp_der2 to be non-zero during part of the simulation. This will ensure full code coverage of this function.

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

Parameters

TypeNameDefaultDescription
Realk0.35Flow coefficient
MassFlowRatem_flow_turbulent0.36Mass flow rate where transition to turbulent flow occurs [kg/s]

Modelica definition

model BasicFlowFunction_dp_DerivativeCheck2 "Model that checks the correct implementation of the 2nd order derivative of the flow function" extends Modelica.Icons.Example; parameter Real k=0.35 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_turbulent=0.36 "Mass flow rate where transition to turbulent flow occurs"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.MassFlowRate m_flow_comp "Comparison value for m_flow"; Real der_m_flow(unit="kg/s2") "1st order derivative of mass flow rate"; Real der_m_flow_comp(unit="kg/s2") "2nd order derivative of comparison value for m_flow"; Modelica.SIunits.PressureDifference dp "Pressure drop"; Modelica.SIunits.MassFlowRate err_m_flow "Integration error for m_flow"; Real err_der_m_flow(unit="kg/s2") "Integration error for der_m_flow"; initial equation m_flow = m_flow_comp; der_m_flow = der_m_flow_comp; equation // Multiply by 1 to avoid a warning due to unit mismatch, // and raise to third power so that dp_der2 has positive and negative sign // in Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp_der2 dp = 1*time^3; m_flow = Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp( dp=dp, k=k, m_flow_turbulent=m_flow_turbulent); // Equate first and second order derivatives der_m_flow = der(m_flow); der_m_flow_comp = der(m_flow_comp); der(der_m_flow) = der(der_m_flow_comp); // Error control err_m_flow = m_flow - m_flow_comp; assert(abs(err_m_flow) < 1E-3, "Error in implementation."); err_der_m_flow = der_m_flow - der_m_flow_comp; assert(abs(err_der_m_flow) < 1E-3, "Error in implementation."); end BasicFlowFunction_dp_DerivativeCheck2;

Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck

Model that checks the correct implementation of the 1st order derivative of the flow function

Information

This model validates the implementation of Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow and its first order derivative Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow_der. If the derivative implementation is wrong, the simulation will stop with an error.

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

Parameters

TypeNameDefaultDescription
Realk0.35Flow coefficient
MassFlowRatem_flow_turbulent0.36Mass flow rate where transition to turbulent flow occurs [kg/s]

Modelica definition

model BasicFlowFunction_m_flow_DerivativeCheck "Model that checks the correct implementation of the 1st order derivative of the flow function" extends Modelica.Icons.Example; constant Real gain=0.5 "Gain for computing the mass flow rate"; parameter Real k=0.35 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_turbulent=0.36 "Mass flow rate where transition to turbulent flow occurs"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.PressureDifference dp "Pressure drop"; Modelica.SIunits.PressureDifference dp_comp "Comparison value for dp"; Modelica.SIunits.PressureDifference err "Integration error"; initial equation dp = dp_comp; equation m_flow = time*gain; dp = Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow( m_flow=m_flow, k=k, m_flow_turbulent=m_flow_turbulent); der(dp) = der(dp_comp); err = dp - dp_comp; assert(abs(err) < 1E-3, "Error in implementation."); end BasicFlowFunction_m_flow_DerivativeCheck;

Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck2 Buildings.Fluid.BaseClasses.FlowModels.Validation.BasicFlowFunction_m_flow_DerivativeCheck2

Model that checks the correct implementation of the 2nd order derivative of the flow function

Information

This model validates the implementation of Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow and its second order derivative Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow_der2. If the derivative implementation is wrong, the simulation will stop with an error.

Implementation

The mass flow rate m_flow is increased non-linearly in order for the first and second derivatives in Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow_der2 to be non-zero during part of the simulation. This will ensure full code coverage of this function.

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

Parameters

TypeNameDefaultDescription
Realk0.35Flow coefficient
MassFlowRatem_flow_turbulent0.36Mass flow rate where transition to turbulent flow occurs [kg/s]

Modelica definition

model BasicFlowFunction_m_flow_DerivativeCheck2 "Model that checks the correct implementation of the 2nd order derivative of the flow function" extends Modelica.Icons.Example; Buildings.Utilities.Diagnostics.CheckEquality cheEqu1(threShold=1e-3) "Block for checking integration error"; Buildings.Utilities.Diagnostics.CheckEquality cheEqu2(threShold=1e-3) "Block for checking integration error"; parameter Real k=0.35 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_turbulent=0.36 "Mass flow rate where transition to turbulent flow occurs"; Modelica.SIunits.PressureDifference dp "Pressure drop"; Modelica.SIunits.PressureDifference dp_comp "Comparison value for dp"; Real der_dp(unit="Pa/s") "1st order derivative of pressure drop"; Real der_dp_comp(unit="Pa/s") "2nd order derivative of comparison value for pressure drop"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.PressureDifference err_dp "Integration error for dp"; Real err_der_dp(unit="Pa/s") "Integration error for der_dp"; initial equation dp = dp_comp; der_dp = der_dp_comp; equation // Divide by 8 to avoid a warning due to unit mismatch, and // and raise to third power so that m_flow_der2 has positive and negative sign // in Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow_der2 m_flow = time^3/8; dp = Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow( m_flow=m_flow, k=k, m_flow_turbulent=m_flow_turbulent); // Equate first and second order derivatives der_dp = der(dp); der_dp_comp = der(dp_comp); der(der_dp) = der(der_dp_comp); // Error control cheEqu1.u1 = dp; cheEqu1.u2 = dp_comp; err_dp = cheEqu1.y; assert(abs(err_dp) < 1E-3, "Error in implementation."); cheEqu2.u1 = der_dp; cheEqu2.u2 = der_dp_comp; err_der_dp = cheEqu2.y; assert(abs(err_der_dp) < 1E-3, "Error in implementation."); end BasicFlowFunction_m_flow_DerivativeCheck2;

Buildings.Fluid.BaseClasses.FlowModels.Validation.InverseFlowFunctions Buildings.Fluid.BaseClasses.FlowModels.Validation.InverseFlowFunctions

Test model for flow function and its inverse

Information

This model tests the inverse formulation of the flow functions. The pressure difference dp and dpCalc need to be equal up to the solver tolerance, except for a small neighborhood around the origin. In this neighborhood around the origin, the functions Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp and Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow are not invertible.

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

Parameters

TypeNameDefaultDescription
Realk0.5 
MassFlowRatem_flow_nominal1Nominal flow rate [kg/s]

Modelica definition

model InverseFlowFunctions "Test model for flow function and its inverse" extends Modelica.Icons.Example; Modelica.SIunits.MassFlowRate m_flow; Modelica.SIunits.PressureDifference dp(displayUnit="Pa") "Pressure difference"; Modelica.SIunits.PressureDifference dpCalc(displayUnit="Pa") "Pressure difference computed by the flow functions"; Modelica.SIunits.Pressure deltaDp(displayUnit="Pa") "Pressure difference between input and output to the functions"; Modelica.SIunits.Time dTime=2; parameter Real k=0.5; parameter Modelica.SIunits.MassFlowRate m_flow_nominal=1 "Nominal flow rate"; equation dp = (time - 0.5)/dTime*20; m_flow = FlowModels.basicFlowFunction_dp( dp=dp, k=k, m_flow_turbulent=m_flow_nominal*0.3); dpCalc = FlowModels.basicFlowFunction_m_flow( m_flow=m_flow, k=k, m_flow_turbulent=m_flow_nominal*0.3); deltaDp = dp - dpCalc; end InverseFlowFunctions;

Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_dp Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_dp

Test model that inverts basicFlowFunction_dp

Information

This model tests whether the Modelica translator substitutes the inverse function for Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp. Specifically, this function declares in its annotation section that its inverse is provided by Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow. Translating this model should therefore give no nonlinear equations after the symbolic manipulation.

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

Parameters

TypeNameDefaultDescription
Realk0.5Flow coefficient
MassFlowRatem_flow_nominal1.5Nominal mass flow rate [kg/s]

Modelica definition

model InvertingBasicFlowFunction_dp "Test model that inverts basicFlowFunction_dp" extends Modelica.Icons.Example; parameter Real k=0.5 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_nominal=1.5 "Nominal mass flow rate"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.PressureDifference dp(displayUnit="Pa") "Pressure difference"; equation m_flow = 4*(time - 0.5); m_flow = FlowModels.basicFlowFunction_dp( dp=dp, k=k, m_flow_turbulent=m_flow_nominal*0.3); end InvertingBasicFlowFunction_dp;

Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_m_flow Buildings.Fluid.BaseClasses.FlowModels.Validation.InvertingBasicFlowFunction_m_flow

Test model that inverts basicFlowFunction_m_flow

Information

This model tests whether the Modelica translator substitutes the inverse function for Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_m_flow. Specifically, this function declares in its annotation section that its inverse is provided by Buildings.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp. Translating this model should therefore give no nonlinear equations after the symbolic manipulation.

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

Parameters

TypeNameDefaultDescription
Realk0.5Flow coefficient
MassFlowRatem_flow_nominal0.5Nominal mass flow rate [kg/s]

Modelica definition

model InvertingBasicFlowFunction_m_flow "Test model that inverts basicFlowFunction_m_flow" extends Modelica.Icons.Example; parameter Real k=0.5 "Flow coefficient"; parameter Modelica.SIunits.MassFlowRate m_flow_nominal=0.5 "Nominal mass flow rate"; Modelica.SIunits.MassFlowRate m_flow "Mass flow rate"; Modelica.SIunits.PressureDifference dp(displayUnit="Pa") "Pressure difference"; equation dp = 4*(time - 0.5); dp = FlowModels.basicFlowFunction_m_flow( m_flow=m_flow, k=k, m_flow_turbulent=m_flow_nominal*0.3); end InvertingBasicFlowFunction_m_flow;