Repository navigation
Stream connectors
In Modelica the concept of stream connectors can be a bit hard to get the head around. Here's an attempt to explain it.
Consider a heated pipe with no pressure loss. A thermo-hydraulic model doesn't get much simpler than this. Here's the code for the pipe and the stream connector:
connector FluidPort
flow Modelica.SIunits.MassFlowRate m_flow;
Modelica.SIunits.Pressure p;
stream Modelica.SIunits.SpecificEnthalpy h_outflow;
end FluidPort
model HeatedPipe "Static model of a heated pipe"
Modelica.Fluid.Interfaces.FluidPort_a a;
Modelica.Fluid.Interfaces.FluidPort_b b;
input Modelica.SIunits.HeatFlowRate Q = 10e3 "Supplied heat";
equation
//mass balance
a.m_flow + b.m_flow = 0;
//momentum balance
a.p = b.p;
//energy balance
a.m_flow*actualStream(a.h_outflow) + b.m_flow*actualStream(b.h_outflow) + Q = 0;
a.h_outflow = b.h_outflow;
end HeatedPipe;The two connectors a and b each contain three variables of which one is a flow variable. That means that the model HeatedPipe must provide exactly ∑variables − ∑inputs − ∑flow variables = 6 - 0 - 2 = 4 equations.
The two obvious equations are the mass and the momentum balance:
//mass balance
a.m_flow + b.m_flow = 0;
//momentum balance
a.p = b.p;The implementation of the energy balance is a bit harder to understand:
//energy balance
a.m_flow*actualStream(a.h_outflow) + b.m_flow*actualStream(b.h_outflow) + Q = 0;
a.h_outflow = b.h_outflow;It contains two equations that might best be understood by looking at the two cases
- The mass flow is in the nominal direction (a→b)
- The mass flow is in the reverse direction (b→a)
In both cases the upstream enthalpy is available for HeatedPipe and is calculated as a downstream enthalpy by some other component (or is the result of a mixing calculation). Let's name it h_mix_a og h_mix_b.
Case 1
The mass flow is in the nominal direction (a→b). In this case it means that
actualStream(a.h_outflow) == inStream(a.h_outflow) == h_mix_a;
actualStream(b.h_outflow) == b.h_outflow;Since a.m_flow, b.m_flow and h_mix_a are known (as boundary values or calculated by adjacent components), b.h_outflow can explicitly be calculated from the energy balance as:
b.h_outflow = (-Q - a.m_flow*h_mix_a)/b.m_flow;and a.h_outflow which is just a dummy value since the flow does not leave through port a is assigned (arbitrarily) with b.h_outflow.
Case 2
The mass flow is in the reverse direction (b→a). In this case it means that
actualStream(a.h_outflow) == a.h_outflow;
actualStream(b.h_outflow) == inStream(b.h_outflow) == h_mix_b;Since a.m_flow, b.m_flow and h_mix_b are known (as boundary values or calculated by adjacent components), a.h_outflow can explicitly be calculated from the energy balance as:
a.h_outflow = (-Q - b.m_flow*h_mix_b)/a.m_flow;and b.h_outflow which is just a dummy value since the flow does not leave through port b is assigned (arbitrarily) with a.h_outflow.
With the stream variables (variables with the stream prefix) comes two functions
inStream(stream_var)actualStream(stream_var)
They return the following values:
inStream(...)
inStream(port.h_outflow) returns the upstream mixing enthalpy when port.m_flow > 0.
When port.m_flow <= 0 another equation must be provided outside the scope of the inStream() function, I.e.
inStream(port.h_outflow) = if port.m_flow > 0
then h_mix;
else //undefined;actualStream(...)
actualStream(port.h_outflow) = if port.m_flow > 0
then inStream(port.h_outflow)
else port.h_outflow;