Session3a Paper5
Session3a Paper5
« «
« «
«
«
«
N ... ... 2 1
1 2 ... ... N
«
A
«
1 2 ... ... N
A
B
B
1 2 ... ... N
«
«
«
The DLR ThermoFluidStream Library
«
«
«
port_DCDC B
N ... ... 2 1
A
B
B
A B
A
A
B
B B
port_batteryHeater port_battery
A A
Figure 1. Example simulation of an automotive battery, drive-chain and cabin thermal control system. The glycol-water loop (magenta) is cooling battery, DC-DC converter, charger
and drive-chain. A four-way switch can split it into two separate loops instead of the combined loop that is shown. If needed, the loop is cooled by a radiator against fresh air (blue).
Additionally it can be cooled with a R134a vapor-cycle (orange). The vapor-cycle is also cooling air going to the vehicle cabin (green) and therefore contains two parallel evaporators,
that can independently be shut off by two valves when not in use. It is cooled against fresh air with a condenser. Furthermore, it contains receiver, accumulator and an expansion valve.
Battery and cabin-air can be heated with the battery heater and PTC respectively. Both heat exchangeers of the glycol loop can be bypassed if not in use. One of the fresh-air streams and
the cabin-air stream is supported by a fan, while the other fresh-air stream is driven purely by dynamic pressure from the vehicle speed.
10.3384/ecp21181225
DOI
Session 3A: Libraries
fault connector type is directional, clearly indicating the whereas p̂ is introduced as steady-mass flow pressure
direction of the stream. The library offers a solution for (since p̂ = p if d ṁ/dt = 0). Alongside a stream we ap-
undirected flows too but it is supposed to be used only proximate the thermodynamic state by using p̂ instead of
when inevitable. Third, the modeler shall break loops p, accepting a (mostly) small error for unsteady flow con-
(not merely bypasses, but actual loops) using volume ele- ditions. At each boundary we compensate the accumu-
ments. Mostly, this will happen anyway since actual loops lated difference between p̂ and p with the inertial pressure
need actual reservoirs but cases like the combined loops of r and accelerate the corresponding mass flow with respect
liquid cooling with its two reservoirs require an attentive to r.
modeler. This leads to a very favorable structure of the equation
The translated model contains of 49 states (eighteen of system where all non-linear computations can be brought
which are attributed to the discretized heat exchangers of into explicit form and the only system of equations in im-
the vapour cycle) and contains only four non-linear sys- plicit form is strictly linear. Hence a robust solution of
tems of size one that can each be locally attributed to one the system model can be reliably achieved supposing ro-
of the four volume components. The initialization prob- bust component and media models. More details on the
lem consists of two linear systems that are manipulated approach and also the handling of junctions and splitters
to size zero and poses no problem. The simulation is ro- in (Zimmer 2020).
bust and will run through various topology switches and Another way of looking at this approach is that we use
changing heat-loads, unless one of the media models is different spatial resolutions for p̂ and r. Whereas p̂ may be
driven out of its temperature or pressure ranges. resolved for each component, r is only resolved between
While some parameterization of all components will boundaries of the stream. This is mostly fine because the
have to be made to match measured data of an actual sys- impact of r on the thermodynamic state is typically low
tem, most components come with usable default param- (or even zero for steady flow conditions). However, should
eters, therefore even complex topologies can be quickly the impact of r become vital (unsteady cavitation might be
built up and simulate successfully. such a case), the modeler is advised to increase the spatial
resolution by adding more volume elements at the place
2 Robustness of concern.
2.1 Underlying methodology and assumptions 2.2 Implementation in Modelica
As suggested by its name a thermofluid stream is forming To implement this decomposition, we use a connector that
the central entity of this modeling approach. The stream is contains a pair of potential and flow variable. The flow is
thereby bound either by dedicated boundary models such naturally the mass flow rate and the corresponding poten-
as sources or sinks or by elements that represent a volume tial is the inertial pressure since it is the potential variable
of the medium. that determines the dynamics of the flow. The thermody-
Between these boundaries, the stream consists in a se- namic state is then transferred as a signal. Since we are
quence of components such as compressors, valves, etc. using the standard Modelica.Media library (Casella et al.
that may manipulate the thermodynamic state Θ. Shared 2006), using the state record of the media models seems a
among all these components is a common mass-flow rate. natural choice.
So all components alongside a stream uphold the mass- Listing 1. connectors for directed thermofluid streams
flow balance ṁin = −ṁout .
connector Inlet
The mass-flow rate is always a state variable of the sys-
replaceable package Medium;
tem. Each component of a stream expresses a differential SI.Pressure r;
equation of the form: flow SI.MassFlowRate m_flow;
input Medium.ThermodynamicState state;
d ṁ end Inlet;
L = −∆r (2)
dt
connector Outlet
Whereas r is denoted as inertial pressure and L is the in- replaceable package Medium;
ertance of the fluid. Please note that the inertance is solely SI.Pressure r;
defined by the geometry of the flow and independent of flow SI.MassFlowRate m_flow;
the thermodynamic state: output Medium.ThermodynamicState state;
end Outlet;
Z
L= ds/A The approach chosen here is thus similar to (Otter
(3)
et al. 2019) and a bit different to what has been de-
with s being the length of the flow and A its cross- scribed in (Zimmer, Bender, and Pollok 2018). Although
section area. We can make use of the inertial pressure r the library is approximating the thermodynamic state on
to decompose the general pressure gradient ∆p into the steady mass-flow pressure, this is not made explicit.
This means in practice that when one calls the func-
∆p = ∆ p̂ + ∆r (4) tion Medium.pressure(inlet.state), the return
value is the steady mass-flow pressure p̂ and not p. An zero-mass flow. Even stronger, we demand that each com-
explicit denotation of the steady mass-flow pressure sim- ponent can handle reverse flow in a well-natured man-
ply turns out to be too cumbersome and unpractical on the ner. This means that the equations should not (unneces-
existing media model base. Yet it is important to have the sarily) destabilize the system and if possible represent a
underlying approximation in mind. physically plausible behavior. Care has been taken that
Also a minor extension to the standard Media library is each component fulfills these robustness requirements.
needed to support our interface: a function is added that This is especially relevant for active components such as
retrieves the mass fraction for given thermodynamic state. compressors and turbines that add or substract power to
For this reason, the DLR Thermofluid Stream Library cur- a stream of fluid. Also heat-exchangers require careful
rently uses a modified copy of Modelica.Media. Once the modeling in this respect.
standard has been updated, the copy will be removed. Fur-
thermore, XRG Simulation GmbH provided media mod- 3 Library Overview
els of refrigerants and further media that are compatible to
our library.
3.1 Library structure
A classic component which has a single stream from The central entity of the library is the thermofluid stream
inlet to outlet can be build upon the following basemodel as described by the connector and the previously listed
that already contains the law for the inertial pressure gra- base-class. There will be boundaries for the stream. These
dient. are typically inlets and outlets but note that also volume
elements represent boundaries from the perspective of a
Listing 2. SISO basemodel stream. The inlet of a volume is an outlet of the stream
partial model SISOFlow and vice versa.
replaceable package Medium; The topology of the architecture is formed by splitters
parameter Utilities.Units.Inertance L = and junctions. Different from the fluid library in the MSL,
dropOfCommons.L;
there are extra components for this purpose and it is not
Inlet inlet(redeclare package Medium=
Medium); performed using connector equations. Finally, all those
Outlet outlet(redeclare package Medium= components that manipulate the working fluid of a stream
Medium); are collected under the term processes. Heat exchangers
protected and valves (or similar mechanism) for flow control are
outer DropOfCommons dropOfCommons; moved up to the highest level due to their significance.
equation
inlet.m_flow + outlet.m_flow = 0;
Hence the structure as in Figure 2 results.
der(inlet.m_flow) * L = inlet.r -
outlet.r;
end SISOFlow;
higher-fidelity models in later design stages. Since these class. Different implementations of f in child classes al-
high-fidelity models will vary for each specific application low for pumps, compressors, turbines, fans or other turbo
the modeler will have to implement them for their specific components and for different levels of fidelity. Note that
use-case. Equation 5 holds no assumption on the specific thermody-
namic process of the turbo-component (e.g. compression /
3.2 On specific components expansion with a fixed isentropic coefficient), since differ-
3.2.1 Volume models ent processes can be implemented by different functions f
Volume models take a special role in the thermofluid- in Equation 5a.
stream approach, as they should be used to break alge- Equation 5b can be replaced by a boundary condition
braic loops for circular fluid flow, isolating the non-linear on ω, when the angular dynamics of the component is not
equation systems locally between the different compo- of interest.
nents (Zimmer 2019a). Each closed fluid loop should con- Equation 5c is additionally normalized for low mass-
tain at least one volume model. flow, effectively limiting |∆h|. If the fluids enthalpy is in-
We provide volume models with one or multiple inlets creased in the component, any work the fluid cannot take
with or without flexible walls, as well as reservoir, ac- on is dumped onto a heat-port. If enthalpy is taken from
cumulator and receiver models, which are also volumes the fluid (e.g. in a turbine) τs is reduced to still fulfill Equa-
and can be used to break loops. All of these are derived tion 5c in case of normalization, limiting the work that can
from base classes of volumes making it easy to implement be taken out of the fluid.
additional specialized volume models if required by the 3.2.3 Heat exchangers
modeler. The base classes define three differential con- For heat exchange between two fluids, two different ap-
servation equations xvolume = (M,U, Mi ) with M, U, and proaches are used in this library. For applications with
Mi , being the mass, inner energy and mass of the different single-phase fluids on both sides, the ε-NTU method is
mass fractions in a mixture respectively. For maximum implemented. For fluids with phase transition (for exam-
flexibility, volumes offer a broad range of options, like re- ple refrigerants), the heat exchanger is discretized in mul-
moving inlet or outlet, or adding a heat-port, as well as tiple heat exchanging elements.
different initialization methods.
In order to avoid very fast, undampened oscillations ε-NTU method
between two or more directly coupled volumes or other When the outlet temperatures of the heat exchanger are
boundaries, a damping term on the change of mass con- not known a priori, the ε-NTU method is most conve-
tained by the volume (Zimmer 2019b) is implemented in nient. It provides relatively simple correlations for dif-
all volumes. Contrary to an artificial flow resistance on the ferent types of heat exchangers (counter-flow, cross-flow,
inlet or outlet, the damping term does not affect the steady- parallel-flow, etc.). The effectiveness ε of a heat ex-
state solution since it acts only on the change of mass in changer is defined as the ratio between the actual and the
the volume. Nonetheless, the damping can be switched off maximum heat flow rate:
by modifying the volumes parameters. With this damping,
directly coupled boundaries may still result in very fast os- Q̇ Q̇
ε= = (6)
cillations, but at least the dynamics are damped and should Q̇max Cmin ∆Tmax
be well manageable for a stiff-system solver. If possible
though, direct coupling of volumes to other volumes or To obtain the maximum possible heat flow rate, the heat
boundaries should be avoided. capacity rates C = cp ṁ on both sides (hot/cold) of the
heat exchanger are compared. The side with the smaller
3.2.2 Turbo components heat capacity rate (C = Cmin ) needs less energy to ex-
All components that transfer work between a mechanical perience the maximum temperature difference (∆Tmax =
flange and the fluid share a common partial model "Par- Th,in − Tc,in ).
tialTurboComponent" governed by Equation 5 With those quantities, the so called Number of Transfer
Units (NTU) can be calculated:
(∆p, τs ) = f (ṁ, ω, Θin ) (5a)
kA
J ω̇ = τ − τs (5b) NTU = (7)
Cmin
∆h = τs ∗ ω/ṁ (5c)
where k is the overall heat transfer coefficient and A is
where ∆p is the pressure gain over the component, ω is the the surface area for heat transfer. For any heat exchanger
angular velocity, J the moment of inertia, τ the torque ap- it can be shown that (Schlünder et al. 1997):
plied to the flange, τs the torque needed to maintain static
operation in the current conditions and ∆h the specific en- ε = f (NTU,Cr ) (8)
thalpy the fluid gains from inlet to outlet.
Equation 5a represents the pressure/torque characteris- This means the effectiveness ε of the heat exchanger is
tic of the component and is not implemented in the partial a function of the dimensionless number of transfer units
thermalConductor[]
ids unmixed, the effectiveness can be obtained by:
G=G/nCells
1
ε = 1 − exp NTU 0.22 exp[−Cr NTU 0.78 ] − 1 (9)
Cr
the actual phase in each discretization element, therefore it very practical and are using the sensors mostly in this way,
is dependent on the vapor quality. According to the single which is why the actual signal output is conditionally re-
phase, for each phase (liquid, vapor, two-phase) a nom- moved by default.
inal coefficient of heat transfer can be set and the actual
coefficient is calculated accordingly:
mc
degC 20.11
|ṁ|
Uliq = Uliq,nom
ṁnom
(17a) bar 0.96
Uvap = Uvap,nom
|ṁ|
me
(17b)
(kg/s)4.45
ṁnom
Utp = Utp,nom (17c)
Figure 4. Exemplary sensor displaying three quantities
The Reynolds exponents for normalisation of the heat
transfer coefficient for evaporation (me = 0.5) and con-
densation (mc = 0.4) are taken from (Yan and Lin 1999b) 3.3 Specific solution for undirected flows
and (Yan and Lin 1999a). In the two-phase region, a con-
Within the library we provide a package containing com-
stant coefficient of heat transfer is assumed. Furthermore
ponents that can have undirected flows. It is similarily
a minimum value for the coefficient of heat transfer Umin is
structured to the main library but contains less compo-
introduced to ensure heat transfer at zero mass flow. The
nents. For these components however, the direction of
coefficient of heat transfer on the two-phase side of the
mass-flow does not need to be known a-priori and is deter-
heat exchanger depends on the actual phase. Therefore
mined dynamically during the simulation. The approach
the vapor quality χ has to be calculated in each element,
for undirected stream-dominated flow simulation was in-
using the dew and bubble enthalpies of the fluid:
troduced in (Zimmer 2019a). Note that this approach is
h − hbubble still stream-dominated and, while we continue to demand
χ= (18) robustness for low and zero mass-flow, the results may not
hdew − hbubble
be valid for these conditions. The undirected simulations
The coefficient of heat transfer used in the two-phase are therefore interesting for applications where non-zero
elements thus is formulated as a function of the vapor mass-flow operating points are present for both flow direc-
quality U(χ). For smooth transition between different tions while the switching dynamics between mass-flow di-
coefficients during phase change, an interpolation is ap- rections are not of interest. In practice, this will be the case
plied. The definition of the vapor quality (Equation 18) al- for many applications, like a combined vapor-cycle/heat-
lows it to go below zero (when subcooled) and above one pump.
(when superheated). This allows the interpolation to be
When the direction of mass-flow is reversed, the flow
formulated across the phase boundaries and avoids jump-
of information is reversed with it. Therefore a undirected
ing in those critical regions. The test models for a con-
connector carries information about the thermodynamic
denser and evaporator show robust and valid behavior of
state in both directions: forward and rearward (see List-
the discretized heat exchanger, although the performance
ing 3).
is highly dependent on the number of discrete elements.
Section 3.3 contains a corresponding application example.
Listing 3. Two connectors for undirected flows
3.2.4 Valve models connector Thermalplug_fore
Valve characteristics can be very important for the con- replaceable package Medium;
trol design and the control authority. The library hence SI.Pressure r;
flow SI.MassFlowRate m_flow;
features different types with different pressure gradient input Medium.State state_rearwards;
curves. Also some functional valve models are directly output Medium.State state_forewards;
combined with splitter models in order to facilitate topo- end thermalplug_fore;
logical changes in complex architectures (Figure 1).
connector Thermalplug_rear
3.2.5 Sensor models replaceable package Medium;
All implemented sensor models can be used in two ways. SI.Pressure r;
flow SI.MassFlowRate m_flow;
Firstly, they output the measured signal as a RealOutput
input Medium.State state_forewards;
as it is common for Modelica sensor models. Addition- output Medium.State state_rearwards;
ally, they display the current signal value during simula- end thermalplug_rear;
tion using the DynamicSelect command (see Figure 4).
This enables the user to get a fast, intuitive understand- Each component also computes its influence on the
ing of the current state of the simulation without the need state in both the forward and backward direction (see
for displaying any signal curve. We found the second use Equation 19).
N......2 1
1 2 ......N
«
1 2 ......N
N......2 1
« « « «
« « « «
When connecting these undirectional components in a
complex topology, junctions and splitters cannot be distin-
guished and become generic nodes. The implementation
of a node has to avoid cyclic dependencies of the signal
flow as well as to provide a regularization around the zero- B
B
mass flow regime. It is thus almost a re-implementation
A
A
B
of the Modelica stream connector (Franke, Casella, Ot-
ter, et al. 2009). Unfortunately the regularization of the
stream connector semantics is numerically vague and also
not subject to a regularization parameter. The width of
the regularization scheme may however play an impor-
tant role in situations of flow reversal and also influences
the eigenvalues of the system. Hence a proper option for
A
parametrization is needed and the Modelica stream con- Figure 5. Example of a reversible heatpump that contains two
nector itself could thus not be used for this library. Here, undirected heat exchangers. The operating mode of the cycle
the default value of the regularization width is specified by can be switched during simulation.
the dropOfCommons.
It is strongly advisable to use undirected components
only when the flow-direction is really unknown. Knowing boundary conditions for the air side and the compressor
the direction a priori is a too valuable piece of informa- and the cycle can be reversed during simulation.
tion to throw away. For instance, using directed compo-
nents helps avoiding spurious loops (those which appear
3.4 Specific solution for dynamic pressure
in the connection graph but are never realized by the fluid The dynamic pressure arises from the macroscopic motion
flow) and the need to cut those loops. Also creating mod- of the fluid. Its computation for a given mass flow rate
els that work in both directions is not always reasonable hence requires also information on the geometry. Typi-
and certainly creates often code that is needlessly com- cally the cross-section area is used to compute the veloc-
plex. Please note that we provide also adapters between ity:
directed and undirected stream networks. These can be
used to isolate parts of the network that require undirected ṁ
v=
flow, and keep the rest directed. Aρ
An example architecture that contains undirected com- The dynamic pressure q is then
ponents is given in Figure 5. It shows a reversible heat-
pump as it can be used for residential air conditioning. The ṁ2
specialty of this system is that the direction of the refrig- q = ρ/2v2 =
2ρA2
erant flow can be reversed. The heat exchangers can thus
act as evaporator or condenser according to the current cy- If the dynamic pressure is vital for each part of the sys-
cle operation. In cooling mode (blue arrows), the indoor tem, it is a natural choice to include the cross-section area
unit acts as an evaporator and the outdoor unit (blue) acts in the connector and specify the geometry at each compo-
as a condenser. Thus the heat is absorbed from the inside nent. However, we do not think that this represents the
air and rejected to the outside. In heating mode (red ar- majority of use-cases for our library. Many thermody-
rows) the cycle is reversed which makes the indoor unit namic processes are adequately described without needing
the condenser and the outdoor unit the evaporator. Hence the dynamic pressure. Its occurrence is mostly confined to
the heat is absorbed from the outside and rejected to the special sub-systems like ram-air inlets, venturi pumps, or
inside. The system is built out of a combination of undi- diffusors. Under this presumption, the need to describe the
rected and directed components. It consists of a undi- geometry in all components does more harm than good.
rected phase separator (receiver) and two separate meter- Providing a localized solution for the dynamic pressure
ing devices (magenta). This allows us to control the super- seems to be the most useful approach. In this way, it can be
heating temperature after the evaporator in both operating considered when needed and ignored otherwise. Hence,
modes. In practice, the change of flow direction is carried we introduce special boundaries for entering and exiting a
out by a reversing valve. In our example we control the zone where dynamic pressure is considered. One side of
flow direction by a system of valves and undirected junc- this boundary expresses the static pressure for a specified
tions (yellow). The example simulates robustly with fixed velocity assumption whereas the other side computes the
velocity resulting from mass flow-rate, density and cross- 4.2 Adapt to your own needs: A use case
section area. The boundary then assigns a pressure differ-
While many use-cases can be simulated by the libraries
ence so that the total pressure balance is upheld. A typical
standard components, many others will require special-
use of such a boundary is its use of ram-air going through
ized components. The relative flat implementation style
a heat exchanger as in a car as shown in Figure 1.
enables the modeler to easily implement own components
A typical component that uses dynamic pressure is a and adapt the library for their needs. An example for this
nozzle that accelerates (or decelerates) a fluid. In case the is provided in Figure 6. It depicts a simulation model for
fluid is diffused an increase in mass-flow rate will increase an espresso machine.
the outlet pressure. Hence a correct formulation of the
boundary conditions is needed because otherwise the in-
ertial dynamics of the fluid may destabilize the system. A
environment
corresponding example of the Venturi-effect is part of the
K
T=25 °C
library.
thermalResistor
4 Easy-to-read, easy-to-adapt
R=2 K/W
brewingHead
4.1 General modeling style of components
500 J/K
In general, the library is structured by a flat hierarchy, lim-
iting the use of partial models, functions and packages to
only those cases with high usefulness. This is done in- PTC
A
Components are implemented to provide a formula-
B
B
tion of Equation 1 in explicit form, whenever feasible.
Nonetheless, sometimes certain quantities that are re-
quired to compute the outlet state Θout depend not only on
the inlet state Θin mass-flow ṁ and component state x, but
also on the outlet state itself. An example is the change
in dynamic pressure, that depends on the outlet density.
B
A
arated in small local ones, for general simulation speed
and the real-time application of the library, even small
non-linear systems are undesirable. Therefore we decided
to avoid non-linear equation systems larger than size 1.
Figure 6. Example of a model with individualized component
This can be achieved by reformulating the equations in
models. This model simulates an espresso machine composed of
a manner and/or applying simplifications until the com- water source and pump (green), boiler, water and steam outlets
ponents’ non-linear equation systems drop to the desired (blue), brewing head with cycling water (yellow) and valve, cof-
size, or by introducing the problematic quantity as an ar- fee strainer and cups (magenta). Cold water enters the machine
tificial state within the component x̃, effectively imple- through a source at atmospheric pressure and gets pressurized by
menting a fast low-pass on it, as it was done in subsub- a pump to 8.5 bar. Part of the water goes through a control valve
section 3.2.3. While the latter solution avoids simplifica- into a boiler, where the pressure is regulated by heating through
tions, it introduces additional artificial states, whose time- a PTC and the water level is controlled by the valve. For this
constants have to be chosen with care. While this is not an purpose the boiler outputs both of these quantities. From the
boiler, steam or boiling water can exit if the corresponding valve
ideal solution, when done right the result is a fast running
is opened. The boiler is in thermal contact to a secondary small
and accurate simulation, with only local non-linear sys- volume from which water cycles to the brewing head and back,
tems of maximum size 1. For hard real-time applications heating up the brewing head. If the machine is at temperature,
the remaining non-linear systems can still be resolved by the valve in front of the coffee strainer is opened and water flows
adding additional states in the corresponding components. from the pump into the cups, picking up heat in the secondary
While implementing the models, we documented the volume and the brewing head.
sources of equations, as well as the simplifications and
mental models for the components in code and the doc- While many standard components are used, the sinks
umentation annotation. Furthermore, intuitive icons pro- for steam and boiling water, the coffee strainer, the cups
vide a good readability of the high-level models. and the boiler are specialized components. All except the