Buildings.Fluid.MixingVolumes.BaseClasses

Package with base classes for Buildings.Fluid.MixingVolumes

Information

This package contains base classes that are used to construct the models in Buildings.Fluid.MixingVolumes.

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

Package Content

Name Description
Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatMoisturePort MixingVolumeHeatMoisturePort Mixing volume with heat and moisture port and initialize_p not set to final
Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatPort MixingVolumeHeatPort Mixing volume with heat port and initialize_p not set to final
Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume PartialMixingVolume Partial mixing volume with inlet and outlet ports (flow reversal is allowed)
Buildings.Fluid.MixingVolumes.BaseClasses.Validation Validation Collection of validation models

Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatMoisturePort Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatMoisturePort

Mixing volume with heat and moisture port and initialize_p not set to final

Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatMoisturePort

Information

Mixing volume with a heat port.

This model is identical to Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume, except that it has a heat and a moisture port.

Note that this model is typically only used to implement new component models that have staggered volumes. In contrast to Buildings.Fluid.MixingVolumes.MixingVolumeMoistAir, it does not set initialize_p to final in order for this model to be usable in staggered volumes which require one pressure to be set to initialize_p = not Medium.singleState and all others to false.

Extends from Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume (Partial mixing volume with inlet and outlet ports (flow reversal is allowed)).

Parameters

TypeNameDefaultDescription
replaceable package MediumPartialMediumMedium in the component
VolumeV Volume [m3]
Nominal condition
MassFlowRatem_flow_nominal Nominal mass flow rate [kg/s]
Dynamics
Equations
DynamicsenergyDynamicsModelica.Fluid.Types.Dynamic...Type of energy balance: dynamic (3 initialization options) or steady state
DynamicsmassDynamicsenergyDynamicsType of mass balance: dynamic (3 initialization options) or steady state
RealmSenFac1Factor for scaling the sensible thermal mass of the volume
Initialization
AbsolutePressurep_startMedium.p_defaultStart value of pressure [Pa]
TemperatureT_startMedium.T_defaultStart value of temperature [K]
MassFractionX_start[Medium.nX]Medium.X_defaultStart value of mass fractions m_i/m [kg/kg]
ExtraPropertyC_start[Medium.nC]fill(0, Medium.nC)Start value of trace substances
ExtraPropertyC_nominal[Medium.nC]fill(1E-2, Medium.nC)Nominal value of trace substances. (Set to typical order of magnitude.)
Advanced
Booleaninitialize_pnot Medium.singleState= true to set up initial equations for pressure
MassFlowRatem_flow_small1E-4*abs(m_flow_nominal)Small mass flow rate for regularization of zero flow [kg/s]
Assumptions
BooleanallowFlowReversaltrue= false to simplify equations, assuming, but not enforcing, no flow reversal. Used only if model has two ports.

Connectors

TypeNameDescription
VesselFluidPorts_bports[nPorts]Fluid inlets and outlets
output RealOutputUInternal energy of the component [J]
output RealOutputmMass of the component [kg]
output RealOutputmXi[Medium.nXi]Species mass of the component [kg]
output RealOutputmC[Medium.nC]Trace substance mass of the component [kg]
input RealInputmWat_flowWater flow rate added into the medium [kg/s]
output RealOutputX_wSpecies composition of medium [kg/kg]
HeatPort_aheatPortHeat port for heat exchange with the control volume

Modelica definition

model MixingVolumeHeatMoisturePort "Mixing volume with heat and moisture port and initialize_p not set to final" extends Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume( dynBal( final use_mWat_flow = true), steBal( final use_mWat_flow = true)); Modelica.Blocks.Interfaces.RealInput mWat_flow(final quantity="MassFlowRate", final unit = "kg/s") "Water flow rate added into the medium"; Modelica.Blocks.Interfaces.RealOutput X_w(final unit="kg/kg") "Species composition of medium"; Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort( T(start=T_start)) "Heat port for heat exchange with the control volume"; protected parameter Real s[Medium.nXi] = { if Modelica.Utilities.Strings.isEqual(string1=Medium.substanceNames[i], string2="Water", caseSensitive=false) then 1 else 0 for i in 1:Medium.nXi} "Vector with zero everywhere except where species is"; Modelica.Blocks.Sources.RealExpression XLiq(y=s*Xi) "Species composition of the medium"; equation connect(mWat_flow, steBal.mWat_flow); connect(mWat_flow, dynBal.mWat_flow); connect(XLiq.y, X_w); connect(heaFloSen.port_a, heatPort); end MixingVolumeHeatMoisturePort;

Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatPort Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatPort

Mixing volume with heat port and initialize_p not set to final

Buildings.Fluid.MixingVolumes.BaseClasses.MixingVolumeHeatPort

Information

Mixing volume with a heat port.

This model is identical to Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume, except that it has a heat port.

Note that this model is typically only used to implement new component models that have staggered volumes. In contrast to Buildings.Fluid.MixingVolumes.MixingVolume, it does not set initialize_p to final in order for this model to be usable in staggered volumes which require one pressure to be set to initialize_p = not Medium.singleState and all others to false.

Extends from Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume (Partial mixing volume with inlet and outlet ports (flow reversal is allowed)).

Parameters

TypeNameDefaultDescription
replaceable package MediumPartialMediumMedium in the component
VolumeV Volume [m3]
Nominal condition
MassFlowRatem_flow_nominal Nominal mass flow rate [kg/s]
Dynamics
Equations
DynamicsenergyDynamicsModelica.Fluid.Types.Dynamic...Type of energy balance: dynamic (3 initialization options) or steady state
DynamicsmassDynamicsenergyDynamicsType of mass balance: dynamic (3 initialization options) or steady state
RealmSenFac1Factor for scaling the sensible thermal mass of the volume
Initialization
AbsolutePressurep_startMedium.p_defaultStart value of pressure [Pa]
TemperatureT_startMedium.T_defaultStart value of temperature [K]
MassFractionX_start[Medium.nX]Medium.X_defaultStart value of mass fractions m_i/m [kg/kg]
ExtraPropertyC_start[Medium.nC]fill(0, Medium.nC)Start value of trace substances
ExtraPropertyC_nominal[Medium.nC]fill(1E-2, Medium.nC)Nominal value of trace substances. (Set to typical order of magnitude.)
Advanced
Booleaninitialize_pnot Medium.singleState= true to set up initial equations for pressure
MassFlowRatem_flow_small1E-4*abs(m_flow_nominal)Small mass flow rate for regularization of zero flow [kg/s]
Assumptions
BooleanallowFlowReversaltrue= false to simplify equations, assuming, but not enforcing, no flow reversal. Used only if model has two ports.

Connectors

TypeNameDescription
VesselFluidPorts_bports[nPorts]Fluid inlets and outlets
output RealOutputUInternal energy of the component [J]
output RealOutputmMass of the component [kg]
output RealOutputmXi[Medium.nXi]Species mass of the component [kg]
output RealOutputmC[Medium.nC]Trace substance mass of the component [kg]
HeatPort_aheatPortHeat port for heat exchange with the control volume

Modelica definition

model MixingVolumeHeatPort "Mixing volume with heat port and initialize_p not set to final" extends Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume; Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort( T(start=T_start)) "Heat port for heat exchange with the control volume"; equation connect(heaFloSen.port_a, heatPort); end MixingVolumeHeatPort;

Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume

Partial mixing volume with inlet and outlet ports (flow reversal is allowed)

Buildings.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume

Information

This is a partial model of an instantaneously mixed volume. It is used as the base class for all fluid volumes of the package Buildings.Fluid.MixingVolumes.

Typical use and important parameters

Set the constant sensibleOnly=true if the model that extends or instantiates this model sets mWat_flow = 0.

Set the constant simplify_mWat_flow = true to simplify the equation

  port_a.m_flow + port_b.m_flow = - mWat_flow;

to

  port_a.m_flow + port_b.m_flow = 0;

This causes an error in the mass balance of about 0.5%, but generally leads to simpler equations because the pressure drop equations are then decoupled from the mass exchange in this component.

To increase the numerical robustness of the model, the constant prescribedHeatFlowRate can be set by the user. This constant only has an effect if the model has exactly two fluid ports connected, and if it is used as a steady-state model. Use the following settings:

Set the parameter use_C_flow = true to enable an input connector for the trace substance flow rate.

Implementation

If the model is (i) operated in steady-state, (ii) has two fluid ports connected, and (iii) prescribedHeatFlowRate=true or allowFlowReversal=false, then the model uses Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation in order to use the same energy and mass balance implementation as is used as in steady-state component models. In this situation, the functions inStream are used for the two flow directions rather than the function actualStream, which is less efficient. However, the use of inStream has the disadvantage that hOut has to be computed, in Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation, using

if allowFlowReversal then
  hOut = Buildings.Utilities.Math.Functions.regStep(y1=port_b.h_outflow,
                                                    y2=port_a.h_outflow,
                                                    x=port_a.m_flow,
                                                    x_small=m_flow_small/1E3);
else
  hOut = port_b.h_outflow;
end if;

Hence, for allowFlowReversal=true, if hOut were to be used to compute the temperature that drives heat transfer such as by conduction, then the heat transfer would depend on upstream and the downstream temperatures for small mass flow rates. This can give wrong results. Consider for example a mass flow rate that is positive but very close to zero. Suppose the upstream temperature is 20°C, the downstream temperature is 10°C, and the heat port is connected through a heat conductor to a boundary condition of 20°C. Then, hOut = (port_b.h_outflow + port_a.h_outflow)/2 and hence the temperature heatPort.T is 15°C. Therefore, heat is added to the component. As the mass flow rate is by assumption very small, the fluid that leaves the component will have a very high temperature, violating the 2nd law. To avoid this situation, if prescribedHeatFlowRate=false, then the model Buildings.Fluid.Interfaces.ConservationEquation is used instead of Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation.

For simple models that uses this model, see Buildings.Fluid.MixingVolumes.

Extends from Buildings.Fluid.Interfaces.LumpedVolumeDeclarations (Declarations for lumped volumes).

Parameters

TypeNameDefaultDescription
replaceable package MediumPartialMediumMedium in the component
VolumeV Volume [m3]
Nominal condition
MassFlowRatem_flow_nominal Nominal mass flow rate [kg/s]
Dynamics
Equations
DynamicsenergyDynamicsModelica.Fluid.Types.Dynamic...Type of energy balance: dynamic (3 initialization options) or steady state
DynamicsmassDynamicsenergyDynamicsType of mass balance: dynamic (3 initialization options) or steady state
RealmSenFac1Factor for scaling the sensible thermal mass of the volume
Initialization
AbsolutePressurep_startMedium.p_defaultStart value of pressure [Pa]
TemperatureT_startMedium.T_defaultStart value of temperature [K]
MassFractionX_start[Medium.nX]Medium.X_defaultStart value of mass fractions m_i/m [kg/kg]
ExtraPropertyC_start[Medium.nC]fill(0, Medium.nC)Start value of trace substances
ExtraPropertyC_nominal[Medium.nC]fill(1E-2, Medium.nC)Nominal value of trace substances. (Set to typical order of magnitude.)
Advanced
Booleaninitialize_pnot Medium.singleState= true to set up initial equations for pressure
MassFlowRatem_flow_small1E-4*abs(m_flow_nominal)Small mass flow rate for regularization of zero flow [kg/s]
Assumptions
BooleanallowFlowReversaltrue= false to simplify equations, assuming, but not enforcing, no flow reversal. Used only if model has two ports.

Connectors

TypeNameDescription
VesselFluidPorts_bports[nPorts]Fluid inlets and outlets
output RealOutputUInternal energy of the component [J]
output RealOutputmMass of the component [kg]
output RealOutputmXi[Medium.nXi]Species mass of the component [kg]
output RealOutputmC[Medium.nC]Trace substance mass of the component [kg]

Modelica definition

model PartialMixingVolume "Partial mixing volume with inlet and outlet ports (flow reversal is allowed)" extends Buildings.Fluid.Interfaces.LumpedVolumeDeclarations; parameter Boolean initialize_p = not Medium.singleState "= true to set up initial equations for pressure"; // We set prescribedHeatFlowRate=false so that the // volume works without the user having to set this advanced parameter, // but to get high robustness, a user can set it to the appropriate value // as described in the info section. constant Boolean prescribedHeatFlowRate = false "Set to true if the model has a prescribed heat flow at its heatPort. If the heat flow rate at the heatPort is only based on temperature difference, then set to false"; constant Boolean simplify_mWat_flow = true "Set to true to cause port_a.m_flow + port_b.m_flow = 0 even if mWat_flow is non-zero"; parameter Modelica.SIunits.MassFlowRate m_flow_nominal(min=0) "Nominal mass flow rate"; // Port definitions parameter Integer nPorts=0 "Number of ports"; parameter Modelica.SIunits.MassFlowRate m_flow_small(min=0) = 1E-4*abs(m_flow_nominal) "Small mass flow rate for regularization of zero flow"; parameter Boolean allowFlowReversal = true "= false to simplify equations, assuming, but not enforcing, no flow reversal. Used only if model has two ports."; parameter Modelica.SIunits.Volume V "Volume"; Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b ports[nPorts]( redeclare each package Medium = Medium) "Fluid inlets and outlets"; Medium.Temperature T = Medium.temperature_phX(p=p, h=hOut_internal, X=cat(1,Xi,{1-sum(Xi)})) "Temperature of the fluid"; Modelica.Blocks.Interfaces.RealOutput U(unit="J") "Internal energy of the component"; Modelica.SIunits.Pressure p = if nPorts > 0 then ports[1].p else p_start "Pressure of the fluid"; Modelica.Blocks.Interfaces.RealOutput m(unit="kg") "Mass of the component"; Modelica.SIunits.MassFraction Xi[Medium.nXi] = XiOut_internal "Species concentration of the fluid"; Modelica.Blocks.Interfaces.RealOutput mXi[Medium.nXi](each unit="kg") "Species mass of the component"; Medium.ExtraProperty C[Medium.nC](nominal=C_nominal) = COut_internal "Trace substance mixture content"; Modelica.Blocks.Interfaces.RealOutput mC[Medium.nC](each unit="kg") "Trace substance mass of the component"; protected Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation steBal( final simplify_mWat_flow = simplify_mWat_flow, redeclare final package Medium=Medium, final m_flow_nominal = m_flow_nominal, final allowFlowReversal = allowFlowReversal, final m_flow_small = m_flow_small, final prescribedHeatFlowRate=prescribedHeatFlowRate) if useSteadyStateTwoPort "Model for steady-state balance if nPorts=2"; Buildings.Fluid.Interfaces.ConservationEquation dynBal( final simplify_mWat_flow = simplify_mWat_flow, redeclare final package Medium = Medium, final energyDynamics=energyDynamics, final massDynamics=massDynamics, final p_start=p_start, final T_start=T_start, final X_start=X_start, final C_start=C_start, final C_nominal=C_nominal, final fluidVolume = V, final initialize_p = initialize_p, m(start=V*rho_start), nPorts=nPorts, final mSenFac=mSenFac) if not useSteadyStateTwoPort "Model for dynamic energy balance"; // Density at start values, used to compute initial values and start guesses parameter Modelica.SIunits.Density rho_start=Medium.density( state=state_start) "Density, used to compute start and guess values"; final parameter Medium.ThermodynamicState state_default = Medium.setState_pTX( T=Medium.T_default, p=Medium.p_default, X=Medium.X_default[1:Medium.nXi]) "Medium state at default values"; // Density at medium default values, used to compute the size of control volumes final parameter Modelica.SIunits.Density rho_default=Medium.density( state=state_default) "Density, used to compute fluid mass"; final parameter Medium.ThermodynamicState state_start = Medium.setState_pTX( T=T_start, p=p_start, X=X_start[1:Medium.nXi]) "Medium state at start values"; // See info section for why prescribedHeatFlowRate is used here. // The condition below may only be changed if StaticTwoPortConservationEquation // contains a correct solution for all foreseeable parameters/inputs. // See Buildings, issue 282 for a discussion. final parameter Boolean useSteadyStateTwoPort=(nPorts == 2) and (prescribedHeatFlowRate or (not allowFlowReversal)) and ( energyDynamics == Modelica.Fluid.Types.Dynamics.SteadyState) and ( massDynamics == Modelica.Fluid.Types.Dynamics.SteadyState) and ( substanceDynamics == Modelica.Fluid.Types.Dynamics.SteadyState) and ( traceDynamics == Modelica.Fluid.Types.Dynamics.SteadyState) "Flag, true if the model has two ports only and uses a steady state balance"; // Outputs that are needed to assign the medium properties Modelica.Blocks.Interfaces.RealOutput hOut_internal(unit="J/kg") "Internal connector for leaving temperature of the component"; Modelica.Blocks.Interfaces.RealOutput XiOut_internal[Medium.nXi](each unit="1") "Internal connector for leaving species concentration of the component"; Modelica.Blocks.Interfaces.RealOutput COut_internal[Medium.nC](each unit="1") "Internal connector for leaving trace substances of the component"; Buildings.HeatTransfer.Sources.PrescribedTemperature preTem "Port temperature"; Modelica.Blocks.Sources.RealExpression portT(y=T) "Port temperature"; Modelica.Thermal.HeatTransfer.Sensors.HeatFlowSensor heaFloSen "Heat flow sensor"; equation /////////////////////////////////////////////////////////////////////////// // asserts if not allowFlowReversal then assert(ports[1].m_flow > -m_flow_small, "In " + getInstanceName() + ": Model has flow reversal, but the parameter allowFlowReversal is set to false. m_flow_small = " + String(m_flow_small) + " ports[1].m_flow = " + String(ports[1].m_flow) + " "); end if; // Actual definition of port variables. // // If the model computes the energy and mass balances as steady-state, // and if it has only two ports, // then we use the same base class as for all other steady state models. if useSteadyStateTwoPort then connect(steBal.port_a, ports[1]); connect(steBal.port_b, ports[2]); U=0; mXi=zeros(Medium.nXi); m=0; mC=zeros(Medium.nC); connect(hOut_internal, steBal.hOut); connect(XiOut_internal, steBal.XiOut); connect(COut_internal, steBal.COut); else connect(dynBal.ports, ports); connect(U,dynBal.UOut); connect(mXi,dynBal.mXiOut); connect(m,dynBal.mOut); connect(mC,dynBal.mCOut); connect(hOut_internal, dynBal.hOut); connect(XiOut_internal, dynBal.XiOut); connect(COut_internal, dynBal.COut); end if; connect(portT.y, preTem.T); connect(heaFloSen.port_b, preTem.port); connect(heaFloSen.Q_flow, steBal.Q_flow); connect(heaFloSen.Q_flow, dynBal.Q_flow); end PartialMixingVolume;