Paper 1 PDF
Paper 1 PDF
Paper 1 PDF
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
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:
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
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].
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-
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
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,