.ModelicaReference.'stream'

Information

Declare stream variable in a connector to describe bi-directional flow of matter

Examples

connector FluidPort
  replaceable package Medium = Modelica.Media.Interfaces.PartialMedium;
  Medium.AbsolutePressure        p          "Pressure in connection point";
  flow   Medium.MassFlowRate     m_flow     "> 0, if flow into component";
  stream Medium.SpecificEnthalpy h_outflow  "h close to port if m_flow < 0";
end FluidPort;

FluidPort is a stream connector, because a connector variable has the stream prefix. The Medium definition and the stream variables are associated with the only flow variable (m_flow) that defines a fluid stream. The Medium and the stream variables are transported with this flow variable. The stream variable h_outflow is the stream property inside the component close to the boundary, when fluid flows out of the component into the connection point. The stream properties for the other flow direction can be inquired with the built-in operator 'inStream()'. The value of the stream variable corresponding to the actual flow direction can be inquired through the built-in operator 'actualStream()'.

model IsenthalpicFlow "No energy storage/losses, e.g., pressure drop, valve, ..."
  replaceable package Medium=Modelica.Media.Interfaces.PartialMedium;
  FluidPort port_a, port_b:
  Medium.ThermodynamicState port_a_state_inflow "State at port_a if inflowing";
  Medium.ThermodynamicState port_b_state_inflow "State at port_b if inflowing";
equation
  // Medium states for inflowing fluid
  port_a_state_inflow = Medium.setState_phX(port_a.p,
                                            inStream(port_a.h_outflow));
  port_b_state_inflow = Medium.setState_phX(port_b.p,
                                            inStream(port_b.h_outflow));
  // Mass balance
  0 = port_a.m_flow + port_b.m_flow;

  // Instantaneous propagation of enthalpy flow between the ports with
  // isenthalpic state transformation (no storage and no loss of energy)
  port_a.h_outflow = inStream(port_b.h_outflow);
  port_b.h_outflow = inStream(port_a.h_outflow);

  // (Regularized) Momentum balance
  port_a.m_flow = f(port_a.p, port_b.p,
                    Medium.density(port_a_state_inflow),
                    Medium.density(port_b_state_inflow));
end IsenthalpicFlow;

When two or more FluidPort (inside) connectors are connected together, then no connection equations are generated for stream variables. Instead, these equations are constructed by the inStream(..) built-in operator (see example model IsenthalpicFlow) above. If two IsenthalpicFlow components are connected together:

   IsenthalpicFlow dp1;
   IsenthalpicFlow dp2;
equation
  connect(dp1, dp2);

Then, the following connection equations are generated

dp1.p = dp2.p;
0 = dp1.m_flow + dp2.m_flow;

Note, no equation for a stream variable is generated. However, the inStream(..) operators inside the components provide the "ideal mixing" equations:

// within dp1:
  inStream(dp1.port_b.h_outflow) := dp2.port_a.h_outflow;

// within dp2:
  inStream(dp2.port_a.h_outflow) := dp1.port_b.h_outflow;

Syntax

See section on type_prefix in the Modelica Grammar.

Description

A detailed description of the stream keyword and the inStream operator is given in Chapter 15 (Stream Connectors) and Appendix D (Derivation of Stream Equations) of the Modelica 3.4 specification. An overview and a rational is provided in a slide set.

The two basic variable types in a connector potential (or across) variable and flow (or through) variable are not sufficient to describe in a numerically sound way the bi-directional flow of matter with convective transport of specific quantities, such as specific enthalpy and chemical composition. The values of these specific quantities are determined from the upstream side of the flow, i.e., they depend on the flow direction. When using across and through variables, the corresponding models would include nonlinear systems of equations with Boolean unknowns for the flow directions and singularities around zero flow. Such equation systems cannot be solved reliably in general. The model formulations can be simplified when formulating two different balance equations for the two possible flow directions. This is not possible with across and through variables though.

This fundamental problem is addressed in Modelica 3.1 by introducing a third type of connector variable, called stream variable, declared with the prefix stream. A stream variable describes a quantity that is carried by a flow variable, i.e., a purely convective transport phenomenon. The value of the stream variable is the specific property inside the component close to the boundary, assuming that matter flows out of the component into the connection point. In other words, it is the value the carried quantity would have if the fluid was flowing out of the connector, irrespective of the actual flow direction.

The basic idea is sketched at hand of an example: Three connectors c1, c2, c3 with the definition

connector Demo
  Real        p;  // potential variable
  flow   Real m_flow;  // flow variable
  stream Real h;  // stream variable
end Demo;

are connected together with

connect(c1,c2);
connect(c1,c3);

then this leads to the following equations:

// Potential variables are identical
c1.p = c2.p;
c1.p = c3.p;

// The sum of the flow variables is zero
0 = c1.m_flow + c2.m_flow + c3.m_flow;

/* The sum of the product of flow variables and upstream stream variables is zero
   (this implicit set of equations is explicitly solved when generating code;
   the "<undefined>" parts are defined in such a way that
   inStream(..) is continuous).
*/
0 = c1.m_flow*(if c1.m_flow > 0 then h_mix else c1.h) +
    c2.m_flow*(if c2.m_flow > 0 then h_mix else c2.h) +
    c3.m_flow*(if c3.m_flow > 0 then h_mix else c3.h);

inStream(c1.h) = if c1.m_flow > 0 then h_mix else <undefined>;
inStream(c2.h) = if c2.m_flow > 0 then h_mix else <undefined>;
inStream(c3.h) = if c3.m_flow > 0 then h_mix else <undefined>;

If at least one variable in a connector has the stream prefix, the connector is called stream connector and the corresponding variable is called stream variable. The following definitions hold:

For further details, see the definition of the 'inStream()' operator.


Generated at 2024-12-25T19:25:50Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos