BuildingSystems.Fluid.Interfaces.StaticTwoPortConservationEquation

# .BuildingSystems.Fluid.Interfaces.StaticTwoPortConservationEquation

Partial model for static energy and mass conservation equations

## Information

This model transports fluid between its two ports, without storing mass or energy. It implements a steady-state conservation equation for energy and mass fractions. The model has zero pressure drop between its ports.

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

To increase the numerical robustness of the model, the constant `prescribedHeatFlowRate` can be set. Use the following settings:

- Set `prescribedHeatFlowRate=true` if the only means of heat transfer at the `heatPort` is a prescribed heat flow rate that is not a function of the temperature difference between the medium and an ambient temperature. Examples include an ideal electrical heater, a pump that rejects heat into the fluid stream, or a chiller that removes heat based on a performance curve. If the `heatPort` is not connected, then set `prescribedHeatFlowRate=true` as in this case, `heatPort.Q_flow=0`.
- Set `prescribedHeatFlowRate=false` if there is heat flow at the `heatPort` computed as K * (T-heatPort.T), for some temperature T and some conductance K, which may itself be a function of temperature or mass flow rate.
  If there is a combination of K * (T-heatPort.T) and a prescribed heat flow rate, for example a solar collector that dissipates heat to the ambient and receives heat from the solar radiation, then set `prescribedHeatFlowRate=false`.

If `prescribedHeatFlow=true`, then energy and mass balance equations are formulated to guard against numerical problems near zero flow that can occur if `Q_flow` or `m_flow` are the results of an iterative solver.

#### Implementation

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 only be used as a steady-state model with two fluid ports. For a model with a dynamic balance, and more fluid ports, use BuildingSystems.Fluid.Interfaces.ConservationEquation.

## Revisions

- 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:
  Set nominal attribute for `XiOut`.
  This is for 1634.
- September 18, 2020, by Michael Wetter:
  Removed start value for `hOut` as it will be set by BuildingSystems.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume.
  See #1397.
- February 12, 2019, by Filip Jorissen:
  Removed obsolete division by `TMax` in assert.
  See #1097.
- June 23, 2018, by Filip Jorissen:
  Added more details to energy conservation assert to facilitate debugging.
  See #962.
- March 30, 2018, by Filip Jorissen:
  Added `getInstanceName()` in asserts to facilitate debugging.
  See #901.
- April 24, 2017, by Michael Wetter and Filip Jorissen:
  Reimplemented check for energy conversion.
  See #741.
- April 24, 2017, by Michael Wetter:
  Reverted change from April 21, 2017.
  See #741.
- April 21, 2017, by Filip Jorissen:
  Revised test for energy conservation at small mass flow rates. See #741.
- October 23, 2016, by Filip Jorissen:
  Added test for energy conservation at small mass flow rates.
- March 17, 2016, by Michael Wetter:
  Refactored model and implmented `regStep` instead of `spliceFunction`. This is for #247 and for #300.
- September 3, 2015, by Filip Jorissen:
  Revised implementation of conservation of vapor mass. Added new variable `mFlow_inv_b`. This is for #247.
- January 22, 2016, by Michael Wetter:
  Removed `constant sensibleOnly` as this is no longer used because the model uses `use_mWat_flow`.
  Changed condition that determines whether `m_flowInv` needs to be computed because the change from January 20 introduced an error in BuildingSystems.Fluid.MassExchangers.Examples.ConstantEffectiveness.
- January 20, 2016, by Filip Jorissen:
  Removed if-else block in code for parameter `sensibleOnly` since this is no longer needed to simplify the equations. This is for #372.
- 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:
  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. November 19, 2015, by Michael Wetter:
  Removed assignment of parameter `showDesignFlowDirection` in `extends` statement. This is for #349.
- September 14, 2015, by Filip Jorissen:
  Rewrote some equations for better readability.
- August 11, 2015, by Michael Wetter:
  Refactored implementation of BuildingSystems.Utilities.Math.Functions.inverseXRegularized to allow function to be inlined and to factor out the computation of arguments that only depend on parameters. This is for issue 302.
- July 17, 2015, by Michael Wetter:
  Corrected bug for situation with latent heat exchange and flow reversal not allowed. The previous formulation was singular. This caused some models to not translate. The error was introduced in #282.
- July 17, 2015, by Michael Wetter:
  Added constant `simplify_mWat_flow` to remove dependencies of the pressure drop calculation on the moisture balance.
- July 2, 2015 by Michael Wetter:
  Revised implementation of conservation equations, added default values for outlet quantities at `port_a` if `allowFlowReversal=false` and updated documentation. See issue 281 for a discussion.
- July 1, 2015, by Filip Jorissen:
  Revised implementation so that equations are always consistent and do not lead to division by zero, also when connecting a `prescribedHeatFlowRate` to `MixingVolume` instances. Renamed `use_safeDivision` into `prescribedHeatFlowRate`. See #282 for a discussion.
- May 6, 2015, by Michael Wetter:
  Corrected documentation.
- February 11, 2014 by Michael Wetter:
  Improved documentation for `Q_flow` input.
- October 21, 2013 by Michael Wetter:
  Corrected sign error in the equation that is used if `use_safeDivision=false` and `sensibleOnly=true`. This only affects internal numerical tests, but not any examples in the library as the constant `use_safeDivision` is set to `true` by default.
- September 25, 2013 by Michael Wetter:
  Reformulated computation of outlet properties to avoid an event at zero mass flow rate.
- September 17, 2013 by Michael Wetter:
  Added start value for `hOut`.
- September 10, 2013 by Michael Wetter:
  Removed unrequired parameter `i_w`.
- May 7, 2013 by Michael Wetter:
  Removed `for` loops for species balance and trace substance balance, as they cause the error `Error: Operand port_a.Xi_outflow[1] to operator inStream is not a stream variable.` in OpenModelica.
- March 27, 2013 by Michael Wetter:
  Removed wrong unit attribute of `COut`, and added min and max attributes for `XiOut`.
- June 22, 2012 by Michael Wetter:
  Reformulated implementation with `m_flowInv` to use `port_a.m_flow * ...` if `use_safeDivision=false`. This avoids a division by zero if `port_a.m_flow=0`.
- February 7, 2012 by Michael Wetter:
  Revised base classes for conservation equations in `BuildingSystems.Fluid.Interfaces`.
- December 14, 2011 by Michael Wetter:
  Changed assignment of `hOut`, `XiOut` and `COut` to no longer declare that it is continuous. The declaration of continuity, i.e, the `smooth(0, if (port_a.m_flow >= 0) then ...)` declaration, was required for Dymola 2012 to simulate, but it is no longer needed for Dymola 2012 FD01.
- August 19, 2011, by Michael Wetter:
  Changed assignment of `hOut`, `XiOut` and `COut` to declare that it is not differentiable.
- August 4, 2011, by Michael Wetter:
  Moved linearized pressure drop equation from the function body to the equation section. With the previous implementation, the symbolic processor may not rearrange the equations, which can lead to coupled equations instead of an explicit solution.
- March 29, 2011, by Michael Wetter:
  Changed energy and mass balance to avoid a division by zero if `m_flow=0`.
- March 27, 2011, by Michael Wetter:
  Added `homotopy` operator.
- August 19, 2010, by Michael Wetter:
  Fixed bug in energy and moisture balance that affected results if a component adds or removes moisture to the air stream. In the old implementation, the enthalpy and species outflow at `port_b` was multiplied with the mass flow rate at `port_a`. The old implementation led to small errors that were proportional to the amount of moisture change. For example, if the moisture added by the component was `0.005 kg/kg`, then the error was `0.5%`. Also, the results for forward flow and reverse flow differed by this amount. With the new implementation, the energy and moisture balance is exact.
- March 22, 2010, by Michael Wetter:
  Added constant `sensibleOnly` to simplify species balance equation.
- April 10, 2009, by Michael Wetter:
  Added model to compute flow friction.
- April 22, 2008, by Michael Wetter:
  Revised to add mass balance.
- March 17, 2008, by Michael Wetter:
  First implementation.

Generated at 2026-05-09T18:18:56Z by OpenModelicaOpenModelica 1.26.7 using GenerateDoc.mos