This blog post discusses the fluid connectors based on Modelica.Fluid.Interfaces.FluidPort and the concept of flow and stream variables.
Figure 1: Fluid connectors in Modelica Standard Library
All the components from Modelica.Fluid can be connected using fluid ports. A flow leaving the connector has a negative sign, while a flow entering the connector has a positive sign (see figure 2).
Figure 2: Sign convention in Modelica Standard Library fluid connectors
Connecting the components directly via connectors leads to ideal mixing, which means that the connection point has the mixing temperature and pressure of the connected components. At the connection point, mass and energy balance are fulfilled.
Figure 3: Example of a connection point with ideal mixing and mass and energy balance
Figure 4 shows the fluid connector definition, containing the medium package, the pressure p (potential variable), the mass flow rate m_flow (flow variable), the specific enthalpy h_outflow, the mass fractions X_outflow and the substance fraction C_outflow (stream variables).
Figure 4: Modelica code for Modelica.Fluid.Interfaces.FluidPort.
In the fluid connector there are three stream variables (h_outflow, Xi_outflow and C_outflow) associated with the flow variable m_flow. These variables represent the specific enthalpy, the mass fractions and the concentrations associated to m_flow <0.
To better understand the difference between potential, flow and stream variables, let’s look at a simple connector example:
Let’s imagine we have three components C1, C2 and C3, each with the connector Demo. Connecting C1 to C2 and C1 to C3, the set of equations shown below in points 1 to 3 are automatically generated:
Figure 5: Meaning of connect(c1,c2) & connect(c1,c3);
- Potential variables are identical:
c1.potentialVariable = c2.potentialVariable;
c1.potentialVariable = c3.potentialVariable;
2. The sum of the flow variables is zero:
c1.flowVariable + c2.flowVariable + c3.flowVariable=0;
3. The sum of the product of flow variables and upstream stream variables is zero:
c1.flowVariable*actualStream(c1.h_outflow) + c2.flowVariable*actualStream(c2.h_outflow) + c3.flowVariable*actualStream(c3.h_outflow)=0;
In fluid networks, point 1 above states that the pressure is the same in all the connected ports, point 2 is the mass balance and point 3 is the energy balance:
Let’s build a simple example using Modelica Standard Library models to understand the meaning of h_outflow, inStream(), actualStream():
Figure 6: Simple example
Define the following parameters:
- inlet: p=2 bar, T=70 degC
- orifice: zeta=1, diameter=0,01 m
- outlet: p=1 bar, T=5 degC
- Medium in all the components: Modelica.Media.Water.StandardWater
Simulate using the default settings (stop time= 1s, algorithm: Dassl, tolerance: 0,0001)
Plot the enthalpy of the fluid in the inlet and outlet boundaries and from the enthalpy sensors and compare these values with the variables orifice.port_a.h_outflow and orifice.port_b.h_outflow:
Figure 7: Specific enthalpy values in the model shown in figure 6
The mass flow rate being positive, the enthalpy of the flow is the one defined by the inlet boundary:
orifice.port_a.h_outflow=outlet.medium.h defines the enthalpy that the flow would have if the mass flow rate was negative, flowing from right (outlet) to the left (inlet).
With the orifice being isenthalpic, the specific enthalpy of the flow remains constant and equal to the specific enthalpy of the inlet flow:
is the coefficient of thermal expansion at constant pressure.
Let’s now try with a mass flow rate that changes sign during the simulation:
Figure 8: Simple example with a mass flow rate that changes sign during the simulation
Figure 9 shows that all the enthalpy sensors give the same enthalpy value, and that this value switches between the enthalpy defined by the inlet and outlet boundaries. orifice.port_b.h_outflow=inlet.medium.h, so it represents the enthalpy that the flow would have if it was always flowing from the inlet to the outlet. orifice.port_a.h_outflow=outlet.medium.h and represents the enthalpy that the flow would have if it was flowing from the outlet to the inlet.
Figure 9: Specific enthalpy values in the model shown in figure 8
When plotting h_outflow in the connector of a flow model (a component where the momentum balance is performed) one needs to keep in mind that that is not the enthalpy of the flow at the port! The enthalpy can be measured using enthalpy sensors or from the medium in the volumes (medium.h).
For example, the flow model Modelica.Fluid.Fittings.SimpleGenericOrifice that we have used in this simple example is an isenthalpic component (see the code in figure 10), however orifice.port_a.h_outflow is different from orifice.port_b.h_outflow.
Figure 10: Code in Modelica.Fluid.Fittings.SimpleGenericOrifice setting the isenthalpic transformation.
The quantity on the connector always corresponds to the value close to the connection point, assuming that the fluid is flowing out of the connector, regardless of the actual direction of the flow. This helps avoid singularities when the mass flow goes through zero.
The stream properties for the other flow direction can be inquired with the built-in operator inStream(…), while the value of the stream variable corresponding to the actual flow direction can be returned through the built-in operator actualStream(…).
When using the fluid connectors from Modelica Standard Library, one needs to be aware of a fundamental approximation: the kinetic pressure is neglected, so the momentum balance and the energy balance are only fulfilled if two ports of equal diameter are connected. However, in all circuits where friction dominates, or where components such as pumps determine the flow rate, the kinetic pressure is less important.
This blog post uses Modelica 3.2.2.
M. Otter, F. Casella “Overview and Rationale for Modelica Stream Connectors”, January 27, 2009
Written by: Maura Gallarotti – Fluids Modelling Engineer
Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion