# .Buildings.Fluid.Interfaces.ConservationEquation

## 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.

## Revisions

• 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`.

Generated at 2022-07-01T00:34:27Z by OpenModelicaOpenModelica 1.20.0~dev-170-g821fd8f using GenerateDoc.mos