modelConservationEquation

Lumped volume with mass and energy balance

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

Information

Basic model for an ideally mixed fluid volume with the ability to store mass and energy. It implements a dynamic or a steady-state conservation equation for energy and mass fractions. The model has zero pressure drop between its ports.

If the constant simplify_mWat_flow = true then adding moisture does not increase the mass of the volume or the leaving mass flow rate. It does however change the mass fraction medium.Xi. This allows to decouple the moisture balance from the pressure drop equations. If simplify_mWat_flow = false, then the outlet mass flow rate is mout = min (1 + Δ Xw), where Δ Xw is the change in water vapor mass fraction across the component. In this case, this component couples the energy calculation to the pressure drop versus mass flow rate calculations. However, in typical building HVAC systems, Δ Xw < 0.005 kg/kg. Hence, by tolerating a relative error of 0.005 in the mass balance, one can decouple these equations. Decoupling these equations avoids having to compute the energy balance of the humidifier and its upstream components when solving for the pressure drop of downstream components. Therefore, the default value is simplify_mWat_flow = true.

Typical use and important parameters

Set the parameter use_mWat_flow_in=true to enable an input connector for mWat_flow. Otherwise, the model uses mWat_flow = 0.

If the constant simplify_mWat_flow = true, which is its default value, then the equation

  port_a.m_flow + port_b.m_flow = - mWat_flow;

is simplified as

  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. The model Buildings.Fluid.MixingVolumes.Validation.MixingVolumeAdiabaticCooling shows that the relative error on the temperature difference between these two options of simplify_mWat_flow is less than 0.1%.

Implementation

When extending or instantiating this model, the input fluidVolume, which is the actual volume occupied by the fluid, needs to be assigned. For most components, this can be set to a parameter.

Input connectors of the model are
  • Q_flow, which is the sensible plus latent heat flow rate added to the medium,
  • mWat_flow, which is the moisture mass flow rate added to the medium, and
  • C_flow, which is the trace substance mass flow rate added to the medium.

The model can be used as a dynamic model or as a steady-state model. However, for a steady-state model with exactly two fluid ports connected, the model Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation provides a more efficient implementation.

For a model that instantiates this model, see Buildings.Fluid.MixingVolumes.MixingVolume.

Parameters

TypeNameDefaultDescription
Booleansimplify_mWat_flowtrueSet to true to cause port_a.m_flow + port_b.m_flow = 0 even if mWat_flow is non-zero. Used only if Medium.nX > 1
Modelica.Units.SI.VolumefluidVolumeVolume
Modelica.Units.SI.HeatCapacityCSen(mSenFac - 1)*rho_default*cp_default*fluidVolumeAditional heat capacity for implementing mFactor
Dynamics › Conservation equations
Modelica.Fluid.Types.DynamicsenergyDynamics (from LumpedVolumeDeclarations)Modelica.Fluid.Types.Dynamics.DynamicFreeInitialType of energy balance: dynamic (3 initialization options) or steady state
Modelica.Fluid.Types.DynamicssubstanceDynamics (from LumpedVolumeDeclarations)energyDynamicsType of independent mass fraction balance: dynamic (3 initialization options) or steady state
Modelica.Fluid.Types.DynamicstraceDynamics (from LumpedVolumeDeclarations)energyDynamicsType of trace substance balance: dynamic (3 initialization options) or steady state
Advanced › Dynamics
Modelica.Fluid.Types.DynamicsmassDynamics (from LumpedVolumeDeclarations)energyDynamicsType of mass balance: dynamic (3 initialization options) or steady state, must be steady state if energyDynamics is steady state
Initialization
Medium.AbsolutePressurep_start (from LumpedVolumeDeclarations)Medium.p_defaultStart value of pressure
Medium.TemperatureT_start (from LumpedVolumeDeclarations)Medium.T_defaultStart value of temperature
Medium.MassFraction[Medium.nX]X_start (from LumpedVolumeDeclarations)Medium.X_defaultStart value of mass fractions m_i/m
Medium.ExtraProperty[Medium.nC]C_start (from LumpedVolumeDeclarations)fill(0, Medium.nC)Start value of trace substances
Medium.ExtraProperty[Medium.nC]C_nominal (from LumpedVolumeDeclarations)fill(1E-2, Medium.nC)Nominal value of trace substances. (Set to typical order of magnitude.)
Dynamics
RealmSenFac (from LumpedVolumeDeclarations)1Factor for scaling the sensible thermal mass of the volume
Advanced
Booleaninitialize_pnot Medium.singleState= true to set up initial equations for pressure
Booleanuse_mWat_flowfalseSet to true to enable input connector for moisture mass flow rate
Booleanuse_C_flowfalseSet to true to enable input connector for trace substance
General › Ports
IntegernPorts0Number of ports

Connectors

TypeNameDefaultDescription
Modelica.Blocks.Interfaces.RealInputQ_flowSensible plus latent heat flow rate transferred into the medium
Modelica.Blocks.Interfaces.RealInputmWat_flowMoisture mass flow rate added to the medium
Modelica.Blocks.Interfaces.RealInputC_flowTrace substance mass flow rate added to the medium
Modelica.Blocks.Interfaces.RealOutputhOutLeaving specific enthalpy of the component
Modelica.Blocks.Interfaces.RealOutput[Medium.nXi]XiOutLeaving species concentration of the component
Modelica.Blocks.Interfaces.RealOutput[Medium.nC]COutLeaving trace substances of the component
Modelica.Blocks.Interfaces.RealOutputUOutInternal energy of the component
Modelica.Blocks.Interfaces.RealOutput[Medium.nXi]mXiOutSpecies mass of the component
Modelica.Blocks.Interfaces.RealOutputmOutMass of the component
Modelica.Blocks.Interfaces.RealOutput[Medium.nC]mCOutTrace substance mass of the component
Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b[nPorts]portsFluid inlets and outlets

Components

TypeNameDefaultDescription
Medium.BasePropertiesmediumMedium properties
Modelica.Units.SI.EnergyUInternal energy of fluid
Modelica.Units.SI.MassmMass of fluid
Modelica.Units.SI.MassmXiMasses of independent components in the fluid
Modelica.Units.SI.MassmCMasses of trace substances in the fluid
Medium.ExtraProperty[Medium.nC]CTrace substance mixture content
Modelica.Units.SI.MassFlowRatemb_flowMass flows across boundaries
Modelica.Units.SI.MassFlowRatembXi_flowSubstance mass flows across boundaries
Medium.ExtraPropertyFlowRatembC_flowTrace substance mass flows across boundaries
Modelica.Units.SI.EnthalpyFlowRateHb_flowEnthalpy flow across boundaries or energy source/sink

Revisions

  • June 25, 2026, by Michael Wetter:
    Added nominal attribute to m.
    This is for IBPSA, #2163.
  • June 18, 2024, by Michael Wetter:
    Added start and nominal attributes to avoid warnings in OpenModelica due to conflicting values.
    This is for IBPSA, #1890.
  • October 24, 2022, by Michael Wetter:
    Conditionally removed assertion that checks for water content as this is only required if water is added to the medium.
    See #1650.
  • September 9, 2022, by Michael Wetter:
    Changed state variable from mXi to medium.Xi as this allows setting a good nominal attribute without having to use the fluid volume, which is non-literal value that leads to a warning in Dymola.
    This is for 1634.
  • April 26, 2019, by Filip Jorissen:
    Returning getInstanceName() in asserts. This is for 1133.
  • April 16, 2019, by Michael Wetter:
    Changed computation of computeCSen to avoid the volume to become a structural parameter.
    This is for IBPSA, issue 1122.
  • April 16, 2018, by Michael Wetter:
    Reformulated mass calculation so that Dymola can differentiate the equations.
    This is for IBPSA, issue 910.
  • November 3, 2017, by Michael Wetter:
    Set start attributes.
    This is for 727.
  • October 19, 2017, by Michael Wetter:
    Changed initialization of pressure from a constant to a parameter.
    This is for Buildings, issue 1013.
  • January 27, 2017, by Michael Wetter:
    Added stateSelect for mass m.
    This is for Buildings, #642.
  • December 22, 2016, by Michael Wetter:
    Set nominal value for U.
    This is for 637.
  • February 19, 2016 by Filip Jorissen:
    Added outputs UOut, mOut, mXiOut, mCOut for being able to check conservation of quantities. This is for issue 247.
  • January 17, 2016, by Michael Wetter:
    Added parameter use_C_flow and converted C_flow to a conditionally removed connector. This is for #372.
  • December 16, 2015, by Michael Wetter:
    Added C_flow to the steady-state trace substance balance, and removed the units of C_flow to allow for PPM.
  • December 2, 2015, by Filip Jorissen:
    Added input C_flow and code for handling trace substance insertions.
  • September 3, 2015, by Filip Jorissen and Michael Wetter:
    Revised implementation for allowing moisture mass flow rate to be approximated using parameter simplify_mWat_flow. This may lead to smaller algebraic loops. This is for #247.
  • July 17, 2015, by Michael Wetter:
    Added constant simplify_mWat_flow to remove dependencies of the pressure drop calculation on the moisture balance.
  • June 5, 2015 by Michael Wetter:
    Removed preferredMediumStates= false in the instance medium as the default is already false. This is for #260.
  • June 5, 2015 by Filip Jorissen:
    Removed
    Xi(start=X_start[1:Medium.nXi],
           each stateSelect=if (not (substanceDynamics == Modelica.Fluid.Types.Dynamics.SteadyState))
           then StateSelect.prefer else StateSelect.default),
    
    and set preferredMediumStates = false because the previous declaration led to more equations and translation problems in large models. This is for #260.
  • June 5, 2015, by Michael Wetter:
    Moved assignment of dynBal.U.start from instance dynBal of PartialMixingVolume to this model implementation. This is required for a pedantic model check in Dymola 2016. It addresses issue 266. This revison also renames the protected variable rho_nominal to rho_start as it depends on the start values and not the nominal values.
  • May 22, 2015 by Michael Wetter:
    Removed
    p(stateSelect=if not (massDynamics == Modelica.Fluid.Types.Dynamics.SteadyState)
    then StateSelect.prefer else StateSelect.default)
    
    because the previous declaration led to the translation error
    The model requires derivatives of some inputs as listed below:
    1 inlet.m_flow
    1 inlet.p
    
    when translating Buildings.Fluid.FMI.ExportContainers.Examples.FMUs.HeaterCooler_u with a dynamic energy balance.
  • May 6, 2015, by Michael Wetter:
    Corrected documentation.
  • April 13, 2015, by Filip Jorissen:
    Now using semiLinear() function for calculation of ports_H_flow. This enables Dymola to simplify based on the min and max attribute of the mass flow rate.
  • February 16, 2015, by Filip Jorissen:
    Fixed SteadyState massDynamics implementation for compressible media. Mass m is now constant.
  • February 5, 2015, by Michael Wetter:
    Changed initalize_p from a parameter to a constant. This is only required in finite volume models of heat exchangers (to avoid consistent but redundant initial conditions) and hence it should be set as a constant.
  • February 3, 2015, by Michael Wetter:
    Removed stateSelect.prefer for temperature. This is for #160.
  • October 21, 2014, by Filip Jorissen:
    Added parameter mFactor to increase the thermal capacity.
  • October 6, 2014, by Michael Wetter:
    Changed medium declaration in ports to be final.
  • October 6, 2014, by Michael Wetter:
    Set start attributes in medium to avoid in OpenModelica the warning alias set with several free start values.
  • October 3, 2014, by Michael Wetter:
    Changed assignment of nominal value to avoid in OpenModelica the warning alias set with different nominal values.
  • July 3, 2014, by Michael Wetter:
    Added parameter initialize_p. This is required to enable the coil models to initialize the pressure in the first volume, but not in the downstream volumes. Otherwise, the initial equations will be overdetermined, but consistent. This change was done to avoid a long information message that appears when translating models.
  • May 29, 2014, by Michael Wetter:
    Removed undesirable annotation Evaluate=true.
  • February 11, 2014 by Michael Wetter:
    Improved documentation for Q_flow input.
  • September 17, 2013 by Michael Wetter:
    Added start value for hOut.
  • September 10, 2013 by Michael Wetter:
    Removed unrequired parameter i_w.
    Corrected the syntax error Medium.ExtraProperty C[Medium.nC](each nominal=C_nominal) to Medium.ExtraProperty C[Medium.nC](nominal=C_nominal) because C_nominal is a vector. This syntax error caused a compilation error in OpenModelica.
  • July 30, 2013 by Michael Wetter:
    Changed connector mXi_flow[Medium.nXi] to a scalar input connector mWat_flow. The reason is that mXi_flow does not allow to compute the other components in mX_flow and therefore leads to an ambiguous use of the model. By only requesting mWat_flow, the mass balance and species balance can be implemented correctly.
  • March 27, 2013 by Michael Wetter:
    Removed wrong unit attribute of COut, and added min and max attributes for XiOut.
  • July 31, 2011 by Michael Wetter:
    Added test to stop model translation if the setting for energyBalance and massBalance can lead to inconsistent equations.
  • July 26, 2011 by Michael Wetter:
    Removed the option to use h_start, as this is not needed for building simulation. Also removed the reference to Modelica.Fluid.System. Moved parameters and medium to Buildings.Fluid.Interfaces.LumpedVolumeDeclarations.
  • July 14, 2011 by Michael Wetter:
    Added start value for medium density.
  • March 29, 2011 by Michael Wetter:
    Changed default value for substanceDynamics and traceDynamics from energyDynamics to massDynamics.
  • September 28, 2010 by Michael Wetter:
    Changed array index for nominal value of Xi.
  • September 13, 2010 by Michael Wetter:
    Set nominal attributes for medium based on default medium values.
  • July 30, 2010 by Michael Wetter:
    Added parameter C_nominal which is used as the nominal attribute for C. Without this value, the ODE solver gives wrong results for concentrations around 1E-7.
  • March 21, 2010 by Michael Wetter:
    Changed pressure start value from system.p_start to Medium.p_default since HVAC models may have water and air, which are typically at different pressures.
  • February 6, 2010 by Michael Wetter:
    Added to Medium.BaseProperties the initialization X(start=X_start[1:Medium.nX]). Previously, the initialization was only done for Xi but not for X, which caused the medium to be initialized to reference_X, ignoring the value of X_start.
  • October 12, 2009 by Michael Wetter:
    Implemented first version in Buildings library, based on model from Modelica.Fluid 1.0.