Sei sulla pagina 1di 10

The Modelica Fluid and Media Library for Modeling of Incompressible and Compressible Thermo-Fluid Pipe Networks

The Modelica Fluid and Media library for modeling of


incompressible and compressible thermo-fluid pipe networks
Francesco Casella1, Martin Otter2, Katrin Proelss3, Christoph Richter4, Hubertus Tummescheit5
1
Politecnico di Milano, Dipartimento di Elettronica e Informazione, Italy
2
German Aerospace Center (DLR), Institute of Robotics and Mechatronics, Germany
3
Technical University Hamburg-Harburg, Institute for Technical Thermodynamics, Germany
4
Technical University Braunschweig, Institute for Thermodynamics, Germany
5
Modelon AB, Ideon Science Park, Lund, Sweden

Abstract library [4]. Other domains, such as gas dynamics,


would require a more sophisticated setup.
The new library Modelica_Fluid is a free Modelica The basic concepts of the Modelica_Fluid library, in
package providing components describing zero- and particular the fluid connectors and the use of re-
one-dimensional thermo-fluid components, which placeable medium models, were laid out in [2]. Since
can be connected in arbitrary networks. The purpose then, the library design has been refined and tested
of the library is to provide standard interfaces for by several people belonging to the Modelica Asso-
thermo-fluid components, demonstrate how to build ciation. The structure of the library is now stable –
such models, and include a growing set of models of contributions are welcome to increase the number of
common use. The component equations are provided components. The goal is that this library
decoupled from the equations to compute the fluid becomes part of the Modelica standard library, after
properties, which are provided by the it has been tested by end users on a significant num-
Modelica.Media library through standard interfaces; ber of different applications and is improved based
incompressible and compressible fluids, single or on the feedback.
multiple substances, one- and multiple-phase fluids A screen shot of the library is
can be used, where appropriate. Newly introduced shown on the right side. The
features of the Modelica.Media library are briefly Examples package contains
reviewed. After extensive testing by interested users, models that demonstrate vari-
the library will be included in the Modelica standard ous features of the library, as
library as Modelica.Fluid. well as some system models,
such as a drum boiler [6] and
an experimental batch plant [5]
1 Introduction model.
A typical (small) example is
The Modelica_Fluid library provides basic interfaces shown in Figure 1 below: It
and components to model thermo-hydraulic systems shows a system where water is
with zero-dimensional and one-dimensional compo- pumped from a source by 4
nents. It is not the intention that this library covers pumps in parallel (fitted with
all possible application cases, because the modelling check valves), through a pipe
assumptions can vary widely. Instead, the goal of the whose outlet is 50 m higher
Modelica_Fluid library is to demonstrate how to than the source, into a reservoir
implement components of thermo-hydraulic proc- placed on an 18-m high tower. The users are repre-
esses in Modelica, provide standard connectors sented by an equivalent valve, connected to the res-
which fit for a wide range of applications, and pro- ervoir. The water controller is a simple on-off con-
vide a reasonable set of components, which can be troller, acting on the gauge pressure measured at the
used as they are, or can be modified to suit specific base of the tower; the output of the controller is the
user needs. For special applications it is possible to rotational speed of the pumps. A typical simulation
implement libraries with simpler media and compo- is over 2000 s. The pump turns on and off to keep
nents, e.g., the Modelica.Thermal.FluidHeatFlow the reservoir level around 2.5 meters, which means

The Modelica Association 631 Modelica 2006, September 4th – 5th


F. Casella, M. Otter, K. Proelss, C. Richter, H. Tummescheit

20.5 meters higher than the base of the tower, corre- The medium models, i.e., the equations to compute
sponding to a gauge pressure of 2 bar. all the fluid properties from the independent thermo-
dynamic state variables, are included in the compo-
PressureSetP... controller PumpRPMGen... PT1 nent models as replaceable instances of objects from
refer...
the Modelica.Media standard library. This allows to
P...

k=2e5
u
T=50
use the same component model with different fluids
(or with different models of the same fluid) by just
valveOpening
replacing the medium model.
reservoir
ambient
ambient...
defaults startTime=0
level_st...
g

pipe
1.8 p...
sink
3 Fluid Connectors
reservoirPre...

source
userValve In this section the design of the fluid connectors is
n
explained. A major design goal was that components
pumps can be arbitrarily connected and that the important
Figure 1: Pumping system for drinking water balance equations are automatically fulfilled when
two or more components are connected together at
one point as shown in the next figure:
2 General design principles pipe3

Compared to other engineering modeling fields, such


as electrical systems or multibody systems, the task
of providing a “standard” library for thermo-fluid pipe1 pipe2
systems is much more difficult, due to the much
greater variety of modeling assumptions that can be
made, depending on the specific application needs. Figure 2: Connected pipes fulfilling the ideal mixing
The Modelica_Fluid library tries to strike a balance, condition at the connection point.
providing a sufficiently general framework, which
As will be explained below, in such a case the bal-
covers a wide range of applications without adding
ance equations define ideal mixing, i.e., the connec-
too much overhead to the simplest cases.
tion point has the mixing temperature if the fluids
The scope of the library includes zero- and one- from the three components would be ideally mixed
dimensional models of thermo-hydraulic compo- in an infinitely small time period. If more realistic
nents, i.e. objects where the flow of one or more flu- modeling is desired that takes into account dissipa-
ids must be described, and energy transfer and stor- tion and other mixing losses, an explicit model has to
age phenomena play a significant role. be used in the connection point, e.g., from the Mode-
The thermo-fluid connectors are designed in order to lica_Fluid.Junctions library. An example is given in
ensure that mass and energy balances are fulfilled at the next figure:
the connection point, even in presence of flow direc-
tion reversal. On the other hand, the momentum bal-
pipe3

ance is fulfilled exactly only when two aligned ob-


jects with equal flange diameters are connected; in
other cases, the momentum balance at the connecting pipe1 pipe2
points is approximated. The exact treatment of mo-
mentum balances at the interfaces in those cases
would add a significant complexity and overhead to splitter
the library, which is unnecessary in most technical Figure 3: Connected pipes with a splitter junction
thermodynamics applications, where gas dynamics where the losses are described in the junction model.
phenomena (wave propagation, high Mach numbers)
For a single substance medium, the connector defini-
do not play a significant role. Gas dynamics systems
tion in Modelica_Fluid.Interfaces.FluidPort reduces
are then outside the scope of the Modelica_Fluid
to
library.
The library models can describe two-phase flows, as
long as the flow is homogeneous, i.e., both phases
have the same velocity.

The Modelica Association 632 Modelica 2006, September 4th – 5th


The Modelica Fluid and Media Library for Modeling of Incompressible and Compressible Thermo-Fluid Pipe Networks

connector FluidPort 3.2 Property Propagation over Ports


replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium;
A connector should have only the minimal number
Medium.AbsolutePressure p; of variables to describe the interface, otherwise there
flow Medium.MasFlowRate m_flow;
will be connection restrictions in certain cases.
Medium.SpecificEnthalpy h;
Therefore, in the connector no redundant variables
flow Medium.EnthalpyFlowRate H_flow
end FluidPort; are present, e.g., the temperature T is not present be-
cause it can be computed from the connector vari-
The first statement defines the medium flowing ables pressure p and specific enthalpy h.
through the connector. In package Medium, medium
specific types such as "Medium.AbsolutePressure" This approach has one drawback: If two components
are defined that contain medium specific values for are connected together, then the medium variables on
the min, max and nominal attributes. Furthermore, both sides of the connector are identical. However,
Medium.MassFlowRate is defined as: due to the connector, only the two equations
type MassFlowRate = port1.p = port2.p; port1.h = port2.h;
Modelica.SIunits.MassFlowRate( are present. Assume, that p, T are the independent
quantity="MassFlowRate." + medium variables and that the medium properties are
mediumName, ...); computed at one side of the connections. This means,
A Modelica translator will check that the quantity the following equations are basically present:
and unit attributes of connected interfaces are identi- port1.h = h(port1.p,port1.T);
cal. Therefore, an error occurs, if connected Fluid- port2.h = h(port2.p,port2.T);
Ports do not have a medium with the same medium port1.p = port2.p;
port1.h = port2.h;
name.
The variables in the connector have the following These equations can be solved in the following way:
port1.h := h(port1.p,port1.T);
meaning: p is the absolute pressure at the connection
port2.p := port1.p;
point, m_flow is the mass flow rate from the connec- port2.h := port1.h;
tion point in to the component, h is the specific mix- 0 = port2.h - h(port2.p,port2.T);
ing enthalpy in the connection point and H_flow is The last equation states that port2.T is computed by
the enthalpy flow rate from the connection point into solving a non-linear system of equations. If port1.h
the component. and port2.h are provided as Modelica functions, a
Modelica translator, such as Dymola [1], can replace
3.1 Balance Equations at Connection Points this non-linear system of equations by the equation:
port2.T = port1.T;
Assume that 3 FluidPorts port1, port2, port3, are
because after alias substitution there are two function
connected together: Since, m_flow and H_flow are
calls
flow variables, a Modelica translator will generate
port1.h := h(port1.p,port1.T);
the following connection equations:
port1.h := h(port1.p,port2.T);
port1.p = port2.p = port3.p
port1.h = port2.h = port3.h Since the left hand sides of the function calls and the
0 = port1.m_flow + port2.m_flow + first arguments are the same, the second arguments
port3.m_flow must also be identical, i.e., port2.T = port1.T. This
0 = port1.H_flow + port2.H_flow + type of analysis seems to be only possible, if the spe-
port3.H_flow cific enthalpy is defined as a function of the inde-
These are exactly the equations that state ideal mix- pendent medium variables. Due to this requirement,
ing for an infinitesimal small control volume in the all media in the Modelica.Media library define the
connection point: The intensive quantities at the specific enthalpy always as a function and therefore
ports are identical and the mass balance as well as by appropriate tool support no unnecessary non-
the energy balance is fulfilled (note that no mass or linear system of equation appears and in the gener-
energy is stored in the infinitesimal volume). The ated code, propagation of medium properties over a
momentum balance is not taken into account, and connector does not lead to an overhead.
therefore a connection without an explicit junction
model is only valid, if the momentum balance has 3.3 Upstream Discretization
not much influence or is fulfilled since two ports
with the same diameter are connected together. When implementing a fluid component, the diffi-
culty arises that the value of intensive quantities
(such as p, T, ρ) shall be accessed from the upstream

The Modelica Association 633 Modelica 2006, September 4th – 5th


F. Casella, M. Otter, K. Proelss, C. Richter, H. Tummescheit

volume. For example, if the fluid flows from volume Equations due to
A to volume B, then the intensive quantities of vol- connect(A.port,B.port), connect(A.port,C.port):
ume B have negligible influence on the fluid be- A.port.p = B.port.p = C.port.p
tween the two volumes. On the other hand, if the A.port.h = B.port.h = C.port.h
flow direction is reversed, the intensive quantities of 0 = A.port.m_flow + B.port.m_flow +
volume A have negligible influence on the fluid be- C.port.m_flow
0 = A.port.H_flow + B.port.H_flow +
tween the two volumes. Such a situation is handled
C.port.H_flow
with the following code fragment:
import IF = Modelica_Fluid.Interfaces; Equations inside components A,B,C:
replaceable package Medium = A.port.H_flow = A.port.m_flow*(
Modelica.Media.Interfaces.PartialMedium; if A.port.m_flow > 0 then A.port.h
IF.FluidPort_a port1(redeclare package else A.h;
Medium = Medium); B.port.H_flow = B.port.m_flow*(
IF.FluidPort_b port2(redeclare package if B.port.m_flow > 0 then B.port.h
Medium = Medium); else B.h;
equation C.port.H_flow = C.port.m_flow*(
// Handle reverse and zero flow if C.port.m_flow > 0 then C.port.h
port1.H_flow = semiLinear(port1.m_flow, else C.h;
port1.h, port2.h); where A.h, B.h, C.h, is the specific enthalpy inside
the respective component. All equations together
// Energy and mass balance; here: form a linear system of equations to compute the
port1.H_flow + port2.H_flow = 0;
port1.m_flow + port2.m_flow = 0;
mixing enthalpy A.port.h = B.port.h = C.port.h
... in the connection point. It has the solution [2]:
A.port.h = -( (if A.port.m_flow > 0 then 0
The enthalpy flow rate in port1 is in principle com- else A.port.m_flow*A.h)+
puted with an if clause: (if B.port.m_flow > 0 then 0
port1.H_flow = port1.m_flow * else B.port.m_flow*B.h)+
(if port1.m_flow > 0 then (if C.port.m_flow > 0 then 0
port1.h else C.port.m_flow*C.h) )
else / ( (if A.port.m_flow > 0 then
port2.h); A.port.m_flow else 0)+
However, instead of using this if-clause, the corre- (if B.port.m_flow > 0 then
sponding built-in Modelica operator semiLinear() is B.port.m_flow else 0)+
actually used: (if C.port.m_flow > 0 then
C.port.m_flow else 0) )
port1.H_flow = semiLinear(port1.m_flow,
port1.h, port2.h); Therefore, independently of the flow directions in
The main reason is that this operator will allow a the 3 ports, the mixing enthalpy is always uniquely
Modelica translator certain symbolic transformations computed, provided at least one mass flow rate does
that lead to a more robust numerical computation not vanish (see [2] for details how to handle the case
(see explanation in the Modelica Specification 2.2). if all mass flow rates vanish). From the mixing en-
thalpy and the port pressure, all other mixing quanti-
If the above component is connected between two ties can be computed, such as mixing temperature.
port volumes (Modelica_Fluid.Pipes.BaseClass-
es.PortVolume), i.e., the independent medium vari-
If two ports A and B are connected together, the re-
ables in port1 and port2 are states, then port1.h and sulting system of equations has a solution that is
port2.h are either states (i.e., known quantities in the unique also for zero mass flow rates:
A.port.h = if A.port.m_flow > 0 then B.h
model) or are computed from states at each integra-
else A.h
tion time step. In such a situation, the above if-clause
B.port.h = A.port.h
represented by the "semiLinear" operator is uncriti-
cal, because it depends only on known variables and In some situations, the user can guarantee that the
can be directly computed. fluid flows only in one direction. In the Mode-
lica_Fluid library this can be defined in the Ad-
If instead, say, pressure loss components are con- vanced menu of components by parameter flowDi-
nected, then all port variables are unknown and sys-
rection. Based on this parameter setting, correspond-
tems of equations occur. For example, three ports,
ing “min” and “max” attributes are defined for the
A.port, B.port, C.port, are connected together. This mass flow rate in a connector, such as:
results in the following equations:

The Modelica Association 634 Modelica 2006, September 4th – 5th


The Modelica Fluid and Media Library for Modeling of Incompressible and Compressible Thermo-Fluid Pipe Networks

FluidPort_a port_a(m_flow(min = if ple component model to compute all required fluid


allowFlowReversal then properties:
–Modelica.Constants.inf else 0)
replaceable package Medium =
When port_a.m_flow is referenced in a semiLinear() Modelica.Medium.Interfaces.PartialMedium;
operator, the tool can deduce that only one branch of Medium.ThermodynamicState state;
the if-clause can appear and can utilize only this Medium.SpecificEnthalpy h;
...
branch for the further symbolic processing. As a re- state = Medium.setState_pT(1e5, 273.15);
sult, if-clauses that define the reversing flow are re- h = Medium.specificEnthalpy(state);
moved. The function setState_pT() will return the state for
the given input variables pressure (p) and tempera-
ture (T) independently from the actual entries in the
4 Medium models thermodynamic state record. For example, if the me-
dium state is p and h and setState_pT(..) is called,
Modelica_Fluid uses the free li- for most media a non-linear equation in one un-
brary Modelica.Media that was known will be solved to compute h (this computation
developed to provide a standard- is performed reliably and efficiently). The second
ized interface to media models part of the function name following the underscore
and a large number of ready-to- indicates the required input variables which is the
use media models based on that standard for all function names within Mode-
interface. The basic concept of lica.Media. The more general function to compute
Modelica.Media is described in the state would be setState_pTX() which also re-
[2]. It was included in the Mode- quires the nX mass fractions X[nX] for a multiple
lica Standard Library in version 2.2. The library has substance medium as input. Using the thermody-
been continuously improved to fit the requirements namic state record in models is a more function-
of Modelica_Fluid. The picture on the left shows the based approach to medium modeling and is used in
structure of Modelica.Media. Modelica.Media allows static components, e.g., pressure loss models or the
for a decoupling of the formulation of the balance heat transfer to the wall of a pipe.
equations within a Modelica_Fluid component
Modelica.Media also offers an object-oriented ap-
model and the definition of the medium. Different
proach that uses the model BaseProperties defined
interfaces are provided in Media.Interfaces that are
for each medium interface. This approach is more
used as base classes for the implementation of differ-
suitable for dynamic component models, e.g., a vol-
ent medium models of different nature, e.g., ideal
ume or a tank, than the function-based approach. The
gases, real gases, two-phase mediums. For every
provided base property model can be extended by the
medium a record called ThermodynamicState is im-
user to best meet the specific requirements. The pur-
plemented that contains the minimum set of vari-
pose of using the thermodynamic state model in the
ables required to describe the state of the medium.
function based and in the object oriented approach is
The thermodynamic state record for a pure compo-
to be able to write models that are independent of the
nent ideal gas is
input variables to the fluid property model. The state
record ThermodynamicState
SI.AbsolutePressure p;
selection mechanism described in [2] makes it possi-
SI.Temperature T; ble to obtain numerically efficient models for differ-
end ThermodynamicState; ent fluids with the same component models. The ba-
The thermodynamic state record can be used to com- sic idea is sketched at hand of the following imple-
pute all other fluid properties except for the satura- mentation of a port volume:
replaceable package Medium =
tion properties which will be explained later. The
Modelica.Media.Interfaces.PartialMedium;
functions to compute additional fluid properties are Modelica_Fluid.Interfaces.FluidPort_a
all contained within package Media.Interfaces. A port(redeclare package Medium = Medium);
function without an underscore in its name assumes Medium.BaseProperties medium (
the thermodynamic state record as an input. The preferredMediumStates = true);
function specificEnthalpy() for example will equation
compute the specific enthalpy from the thermody- medium.p = port.p;
namic state. medium.h = port.h;
M = V*medium.d;
The following code fragment demonstrates how the U = M*medium.u;
thermodynamic state record could be used in a sim- der(M) = port.m_flow; // mass balance
der(U) = port.H_flow; // energy bal.

The Modelica Association 635 Modelica 2006, September 4th – 5th


F. Casella, M. Otter, K. Proelss, C. Richter, H. Tummescheit

In a port volume it is desired that the independent value for p and initial values for X and for T or h
medium variables are used as states (e.g., p,T or p,h are defined.
depending on the medium). The BaseProperties in- Depending on the selected option, a value such as
stance medium contains the basic medium equations. “p_start” is interpreted from the component as either
If parameter preferredMediumStates is set to true, being an initial value (i.e. introducing an initial
then attribute StateSelect.prefer is set to the inde- equation p = p_start) or a guess value (i.e. setting the
pendent medium variables and therefore the tool will start value of p to p_start with fixed = false).
use these variables as states for the mass and energy
For every medium either T or h can be defined as
balance, if this is possible. This means, that the port
start value. Assume that T_start is selected as value
volume equations can be implemented without
to be provided (either initial or guess value). De-
knowledge about the independent medium variables.
pending on the situation, a tool might use h as itera-
Modelica.Media requires the implementation of tion variable for a non-linear system of equations,
medium models in Modelica. This approach allows e.g., because h is the independent medium variable.
the solver to use as much analytical information Then, the setting of T_start would have no effect.
about the medium models as possible when manipu- For this reason, modifiers are defined in the initiali-
lating the system of equations. However, it is often zation menu, e.g. for h_start:
also very desirable to use existing fluid property li- parameter Medium.SpecificEnthalpy h_start=
braries written in C or in FORTRAN. A new inter- if use_T_start then
face to an external medium library has been devel- Medium.specificEnthalpy_pTX(
oped for Modelica.Media that supports external p_start, T_start, X_start)
medium libraries. This new interface is currently else Medium.h_default;
included in the developer version of Mode- If use_T_start is true, the menu for h_start is dis-
lica.Media and will be tested thoroughly before abled, i.e., the user cannot input a value and there-
including it in the Modelica Standard Library. fore function specificEnthalpy_pTX(..) is called to
compute the start value of the specific enthalpy
based on p_start and T_start. If use_T_start = false,
5 Initialization the user can provide a modifier with a new value that
overwrites the if-clause in the modifier. Otherwise
Every fluid component with states has a menu “Ini- the default value of h for this medium is used as ini-
tialization”. A screen shot of this menu of model tial value.
Modelica_Fluid.Volumes.MixingVolume is shown To summarize, the medium is always initialized with
in the next figure: a consistent set of variables p, T, h, X where either T
or h is computed from the other 3 variables with the
corresponding medium function.

6 Regularizing characteristics
Pressure drop equations and other fluid characteris-
tics are usually computed by semi-empirical equa-
tions. Unfortunately, the developers of semi-
Parameter initType defines the type of the initializa-
empirical equations nearly never take into account
tion and has the following options:
that the equation might be used in a simulation pro-
• initType == InitialValues: gram. As a consequence, these semi-empirical equa-
Initial values of p,X and of T or h are defined. tions can nearly never be used blindly but must be
• initType == SteadyState: slightly modified or adapted in order that obvious
The derivatives of the states are set to zero dur- simulation problems are avoided. For example, tur-
ing initialization. Since usually non-linear sys- bulent flow in a pipe might be described by the fol-
tems of equations occur, guess values for the lowing type of equation:
states are defined for p, X and for T or h. y = if x >= 0 then sqrt(k1*x)
else -sqrt(k2*abs(x));
• initType == SteadyStateHydraulic:
The pressure derivatives are set to zero during A plot of this characteristic is shown in the next fig-
initialization, but the thermal states (T or h) are ure:
initialized with a start value. Therefore, a guess

The Modelica Association 636 Modelica 2006, September 4th – 5th


The Modelica Fluid and Media Library for Modeling of Incompressible and Compressible Thermo-Fluid Pipe Networks

where x_small defines the region of the newly intro-


duced two polynomials around x = 0. The result of
applying this function is shown in the next figure.

The difficulty with this function is that the derivative


at x=0 is infinity. The actual physical characteris-
tic doesn't show this singularity. E.g., for pipe The “blue” curve is the exact characteristic accord-
flow, the flow becomes laminar for small velocities ing to the equation above, where as the “red” curve
and therefore around zero the sqrt() function is re- is the regularized approximation of regRoot2(..) that
placed by a linear function. Since the laminar region has much better numerical properties.
is usually of not much practical interest, the above
approximation is used.
The direct implementation above does not work in 7 Selected Components
Modelica, because an event is generated when x < 0
changes sign. In order to detect this event, event it- In the previous sections, the features have been de-
eration takes place. During the event iteration, the scribed that are needed in order that component
active if-branch is not changed. For example, assume models can be implemented. In this section some of
that x is positive (= "else" branch) and shall become the provided component models will be shortly
negative. During the event iteration x is slightly sketched.
negative and the else branch, i.e., sqrt(x), is evalu-
ated. Since this result in an imaginary number, an 7.1 Pressure Losses
error occurs. It would be possible to fix this, by using
the noEvent() operator to explicitly switch off an Package PressureLosses contains models and func-
event: tions providing pressure loss correlations. All models
y = noEvent( if x<0 then sqrt(k1*x) in this library have the property that no mass and no
else -sqrt(k2*abs(x))); energy is stored in the component. Therefore, none
Still, it is highly likely that good integrators will not of the models has a state. The basic correlations are
work well around x=0, because they will recognize models that are imple-
that the derivative changes very sharply and will re- mented with functions
duce the step size drastically. of sublibrary Pressure-
Losses.BaseClasses.
In Modelica_Fluid.Utilities several
These functions might
utility functions are provided to
also be directly called
regularize such types of equations
(e.g. in an implementa-
(see screen shot on right side). For
tion of another compo-
example, regRoot2(..) replaces the
nent, such as the dis-
function above by two polynomials
tributed pipe).
of third order around zero, so that
the overall function is continuous, All functions are con-
is strict monotonically increasing and has a continu- tinuous and have a fi-
ous first derivative everywhere. Additionally, either nite, non-zero, smooth,
the second derivatives of the two polynomials at zero first derivative. The
are identical (= default) or a user defined first deriva- functions are all guaranteed to be strict monotoni-
tive at zero can be provided, to, e.g., correctly de- cally increasing. The mentioned properties guarantee
scribe the laminar region around zero. In the first that a unique inverse of every function exists. In fact,
case, the equation above is replaced by: for all correlations a function is provided in the form
y = regRoot2(x, x_small, k1, k2);
m_flow = f(p) and also its inverse, p = g(m_flow) is
given. A similar naming convention as in the Media

The Modelica Association 637 Modelica 2006, September 4th – 5th


F. Casella, M. Otter, K. Proelss, C. Richter, H. Tummescheit

library is used, e.g. massFlowRate_dp(..) means that dium model may not provided a function to compute
the functions compute the mass flow rate and that the the viscosity.
input argument is dp (the pressure difference be- Model “suddenExpansion” defines suddenExpansion
tween two ports). Most functions consist of one a sudden expansion of a pipe and
statement, so that, e.g., Dymola inlines the function computes the correlation factors for
and therefore no call overhead is present. the two flow directions from the
The pressure loss correlation “Sim- orifice two pipe diameters according to
pleGenericOrifice” defines a stan- Idelchick [2].
dard quadratic correlation of the In the same way “orifice” defines a orifice
form: sharp edged orifice where the cor-
1 zeta=0.5 relation factors for the two flow
Δp = ⋅ ζ ⋅ ρ ⋅ v v directions depends, e.g., on the
2
opening angle of the orifice [2].
where Δp is the pressure difference between two
Model “StaticHead” models only the pressure drop
ports, v is the fluid velocity (that can be computed
due to gravity.
from the mass flow rate, density and pipe area) and ζ
is the constant pressure loss coefficient, for the fluid Finally, model “WallFrictionAndGravity” models
flow from port_a to port_b that can be, e.g., deduced wall friction and also takes into account gravity. The
from some of the standard books like Idelchick [3]. implementation is based on [2,3]. The user can select
Screen shots of the parameter menu are shown in the either the different regions (only laminar, only quad-
next two figures: ratic turbulent, laminar + quadratic turbulent) or the
detailed characteristic. The latter one is shown in the
next figure [2,3].

Basically, the medium, the correlation factor and the


diameter has to be defined at which ζ is defined. The
“Advanced” menu is the same for all components of
the PressureLosses package and defines how the
computation of the correlation is performed:

Figure 1. Moody Chart: lg(λ) = f (lg(Re), Δ), ζ= λL/D

7.2 Pipes

If from_dp is true, the mass flow rate is computed Different pipe models
from the pressure drop, otherwise the computation is are defined in package
reversed. The “flowDirection” defines whether re- Pipes, as shown in the
versal flow shall be taken into account. “use_Re” screen shot at the right.
defines the laminar region by the Reynolds number LumpedPipe is a simple
(e.g. Re < 2000 for smooth wall friction), otherwise pipe model consisting of one volume and two pres-
it is defined approximately by a small pressure drop sure loss correlations for the wall friction, as well as
or a small mass flow rate depending on the selected a heat transfer port to describe the heat transfer
computation direction. Finally, if show_Re = true, through the wall. The model is especially useful for
the Reynolds-Number is computed in order to utilize demonstration purposes because it is just built from
it, e.g., in a plot. By default the computations with basic components:
the Reynolds number are not performed, since a me-

The Modelica Association 638 Modelica 2006, September 4th – 5th


The Modelica Fluid and Media Library for Modeling of Incompressible and Compressible Thermo-Fluid Pipe Networks

thermalPort
one dimension. They largely depend on the specific
application, thus have to be replaceable in a model in
port_a port_b
frictionAndGr... frictionAndGr... order to provide the required flexibility, but at the
same time need to be known in the lowest hierarchi-
volume cal level of a system, the governing balance equa-
The other two pipe models are discretized pipes con- tions.
sisting of n volumes. More details are given in the The distributed pipe model contains a replaceable
next subsection. heat object that determines the relationship between
the thermal port properties, heat flow and tempera-
7.3 Heat Exchanger ture, and the bulk flow, namely the medium tempera-
ture and the sensible heat term in the energy balance.
A basic heat exchanger model can be found under The library currently only provides the simplest
Components.HeatExchangers.BasicHX. It demon- model possible to describe a sensible heat transfer,
strates the usage of several models from the Fluid by means of a constant heat transfer coefficient. But
library and the interfaces provided to adapt them to an implemention of e.g. Nusselt correlations from
fit personal needs. The heat exchanger is composed the literature is easily done by inheriting from the
of two pipe flow models and one wall element as base model Pipes.BaseClasses.HeatTrans-
shown in figure 4. The wall determines a co- or fer.PartialPipeHeatTransfer. Besides geomet-
counterflow orientation of the two medium flows. It rical parameters, such as the hydraulic diameter and
also adds the major thermal capacity to the set. Heat cross sectional flow area the heat object also
conduction is assumed to be one-dimensional, per- “knows” mass flow rate and the medium.state
pendicular to both fluid flows.
record (see section 4) of the fluid flow, which makes
it possible to compute required transport properties
pipe_2 by function call if and only if needed in the respec-
port_a2 tive correlation. For further information concerning
the models mentioned here the reader may be re-
ferred to the online documentation of the library.
Figure ? shows the results of an example model in
port_a1 wall port_b1
the library. One of the two fluid flows in the heat
exchanger changes its direction midway, and be-
cause it is fed from a colder source changes the di-
port_b2 rection of heat flow.
pipe_1 30
Figure 4: Heat exchanger component
20
On both fluid sides medium packages from the Mod-
elica.Media library can be chosen. An instance of the 10
Q flow in kW

respective BaseProperties model as described in Heat flow fluid 1


section 4 is automatically included in each of the two 0 Heat flow fluid 2
distributed flow models from the component package
Pipes. They follow an upwind discretization −10
scheme, the number of segments being the same for
both pipes and the wall. Dynamic energy and mass −20
balances interlace on a staggered grid with static
momentum balances for each control volume. Two −30
half momentum balances on each end make the 0 20 40 60 80 100
component fully symmetric. The port interface cor- Time in s
responds to the general design principle outlined in Figure 5: Heat flow rates in both heat ex-
section 3 and allows for flow reversal. A uniform changer fluids (water) while one of them
cross sectional area is assumed along the entire flow changes direction.
path.
Empirical heat transfer and pressure drop correla-
tions allow us to reduce 3D fluid flow problems to

The Modelica Association 639 Modelica 2006, September 4th – 5th


F. Casella, M. Otter, K. Proelss, C. Richter, H. Tummescheit

8 Conclusions examples, symbolic algorithms and the further de-


sign of the library (alphabetical list): John Batteh,
The 1.0 Beta 1 version of the Modelica_Fluid library Jonas Eborn, Rüdiger Franke, Anton Haumer, Hen-
described in this article is in a rather stable stage and ning Knigge, Chuck Newman, Hans Olsson, Katja
the most important basic problems have been re- Poschlad, Manuel Remelhe, Sven Erik Mattsson,
solved. Especially, it was possible to reach the fol- Mike Tiller, Allan Watson.
lowing quite ambitious goals: The Modelica.Media library development is organ-
(a) The component equations are independent from ized by Hubertus Tummescheit. For the long list of
the medium equations (especially, a component can contributors, see
be used for media that have different sets of inde- Modelica.Media.UsersGuide.Contact.
pendent variables, such as T, pT, or p,h, or p,T,X or
T,X etc.). This has the big advantage that pump,
pipe, valve models etc., can be implemented just 10 References
once and utilized for quite different media. Of
course, there are limits, e.g., one and two phase flow [1] Dynasim (2006). Dymola Version 6.0. Dynasim AB,
is always differently described in a component. On Lund, Sweden. Homepage: http://www.dynasim.se/.
the other hand, all components of the Fluid library [2] Elmqvist, H., Tummescheit H., and Otter M.( 2003).
support incompressible and compressible as well as Object-Oriented Modeling of Thermo-Fluid Systems.
one and multiple substance media. Proceedings of 3rd Int. Modelica Conference,
Linköping, Sweden, ed. P. Fritzson, pp. 269-286.
(b) Components can be arbitrarily connected to- http://www.modelica.org/Conference2003/papers/h4
gether. Also models such as a pipe can be flipped. 0_Elmqvist_fluid.pdf
The Modelica connection semantics generates ideal [3] Idelchik I.E. (1994): Handbook of Hydraulic Resis-
mixing equations so that the mass and energy bal- tance. 3rd edition, Begell House, ISBN 0-8493-9908-
ance is fulfilled. If this is not desired, junction mod- 4.
els have to be used. This is especially the case when [4] Kral A., Haumer A. Plainer M. (2005): Simulation of
the momentum balance in a junction cannot be ne- a thermal model of a surface cooled squirrel cage in-
glected. There are still some unresolved issues, e.g., duction machine by means of the SimpleFlow-library.
the Pipes.DistributedPipe model is discretized in 4th int. Modelica Conference, Hamburg-Harburg.
such a form that at the two ends of a pipe momentum http://www.modelica.org/events/Conference2005/onl
balances are present (and not mass and energy bal- ine_proceedings/Session3/Session3b1.pdf
ances of a volume). When connecting pipes of this [5] Poschlad K., Remelhe M.A.P., and Otter M. (2006):
form directly together (without using a port volume Modeling of an Experimental Batch Plant with
in the connection point), non-linear systems of equa- Modelica. 5th int. Modelica Conference, Vienna.
tions appear. [6] Rüdiger Franke (2003): On-line Optimization of
The goal is to continuously improve the Mode- Drum Boiler Startup. Proceedings of the 3rd Int.
lica_Fluid library, especially to include more com- Modelica Conference, Linköping, 2003.
http://www.modelica.org/events/Conference2003/pap
ponent models. Contributions from users of the li- ers/h29_Franke.pdf
brary are welcome. The actual version of the library
can be downloaded from
http://www.modelica.org/library/

9 Acknowledgments
The development of the Modelica_Fluid library
started in year 2002 and many have contributed:
The Fluid library development was organized in
2002-2004 by Martin Otter and since 2004 it is or-
ganized by Francesco Casella. The essential basic
design of the Fluid library, especially component
interfaces, handling of reversing flow with the se-
miLinear() operator, property propagation is from
Hilding Elmqvist. Besides the authors, the following
people contributed to the fluid component models,

The Modelica Association 640 Modelica 2006, September 4th – 5th

Potrebbero piacerti anche