## 'inStream()'inStream() |

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Returns the mixing value of a stream variable if it flows into the component where the inStream operator is used.

For an introduction into stream variables and an example for the inStream(..) operator, see stream.

inStream(IDENT)

where `IDENT`

must be a variable reference in a connector component declared with the
stream prefix.

In combination with the stream variables of a connector, the inStream() operator is designed to describe in a numerically reliable way the bi-directional transport of specific quantities carried by a flow of matter. inStream(v) is only allowed on stream variables v and is informally the value the stream variable has, assuming that the flow is from the connection point into the component. This value is computed from the stream connection equations of the flow variables and of the stream variables. For the following definition it is assumed that N inside connectors mj.c (j=1,2,...,N) and M outside connectors ck(k=1,2,...,M) belonging to the same connection set are connected together and a stream variable h_outflow is associated with a flow variable m_flow in connector c.

connectorFluidPort ...flowReal m_flow "Flow of matter; m_flow > 0 if flow into component";streamReal h_outflow "Specific variable in component if m_flow < 0"endFluidPort;modelFluidSystem ... FluidComponent m1, m2, ..., mN; FluidPort c1, c2, ..., cM;equationconnect(m1.c, m2.c);connect(m1.c, m3.c); ...connect(m1.c, mN.c);connect(m1.c, c1);connect(m1.c, c2); ...connect(m1.c, cM); ...endFluidSystem;

With these prerequisites, the semantics of the expression

inStream(m_{i}.c.h_outflow)

is given implicitly by defining an additional variable **h_mix_in**_{i},
and by adding to the model the conservation equations for mass and energy corresponding
to the infinitesimally small volume spanning the connection set. The connect equation
for the flow variables has already been added to the system according to the connection
semantics of flow variables:

// Standard connection equation for flow variables 0 =sum(m_{j}.c.m_flowforjin1:N) +sum(-c_{k}.m_flowfork in 1:M);

Whenever the inStream() operator is applied to a stream variable of an inside connector, the balance equation of the transported property must be added under the assumption of flow going into the connector

// Implicit definition of the inStream() operator applied to inside connector i 0 =sum(m_{j}.c.m_flow*(ifm_{j}.c.m_flow > 0orj==ithenh_mix_in_{i}elsem_{j}.c.h_outflow)forjin1:N) +sum(-c_{k}.m_flow* (ifc_{k}.m_flow > 0thenh_mix_in_{i}elseinStream(c_{k}.h_outflow)forkin1:M);inStream(m_{i}.c.h_outflow) = h_mix_in_{i};

Note that the result of the inStream(m_{i}.c.h_outflow) operator is different for each port i,
because the assumption of flow entering the port is different for each of them.
Additional equations need to be generated for the stream variables of outside connectors.

// Additional connection equations for outside connectorsforq in 1:Mloop0 =sum(m_{j}.c.m_flow*(ifm_{j}.c.m_flow > 0thenh_mix_out_{q}elsem_{j}.c.h_outflow)forjin1:N) +sum(-c_{k}.m_flow* (ifc_{k}.m_flow > 0ork==qthenh_mix_out_{q}elseinStream(c_{k}.h_outflow)forkin1:M); c_{q}.h_outflow = h_mix_out_{q};end for;

Neglecting zero flow conditions, the above implicit equations can be
analytically solved for the inStream(..) operators.
The details are given in Section 15.2 of the
Modelica Language Specification version 3.2 Revision 1.
The stream connection equations have singularities and/or multiple solutions if one or more
of the flow variables become zero. When all the flows are zero, a singularity is always
present, so it is necessary to approximate the solution in an open neighborhood
of that point. [*For example assume that m _{j}.c.m_flow = c_{k}.m_flow = 0,
then all equations above are identically fulfilled and inStream(..) can have any value*].
It is required that the inStream() operator is appropriately approximated in that case
and the approximation must fulfill the following requirements:

- inStream(m
_{i}.c.h_outflow) and inStream(c_{k}.h_outflow) must be**unique**with respect to all values of the flow and stream variables in the connection set, and must have a continuous dependency on them.

- Every solution of the implicit equation system above must fulfill the equation
system identically [
*up to the usual numerical accuracy*], provided the absolute value of every flow variable in the connection set is greater than a small value (|m_{1}.c.m_flow| > eps and |m_{2}.c.m_flow| > eps and ... and |c_{M}.m_flow| > eps).

In Section 15.2 a recommended implementation of the solution of the implicit equation system is given, that fulfills the above requirements.