Académique Documents
Professionnel Documents
Culture Documents
Plants in Simulink∗
Peter Niebert
VERIMAG, 2, av. de Vignate, Gières, France
May 26, 2000
Abstract
In this work, we report on efforts for building a prototype simulink
library for compositional modelling of hydrodynamic networks. The
work is inspired by a cooperation with the EDF, where the desire for
compositional modelling in a causal framework was exposed. The na-
ture of the dynamics of hydrodynamic systems itself is compositional,
and it is desirable to profit from this compositionality for modelling.
This can be of great importance for quick production of prototype
simulation models for understanding system dynamics.
We explain the modelling technique used and how it relates to
other approaches, give examples to indicate the construction of the
prototypic simulink library and comment on experiences gained with
this model.
1 Introduction
In this work, we consider the modelling hydro- and thermodynamic networks
as used for heat transport in thermal powerplants and other technical appli-
This work was supported in part by contract number 9853, “Application de la technique
∗
1
cations. The aim is to develop a compositional modelling framework on the
basis of the popular simulation package Simulink.
A huge variety of tools for the simulation of hydrodynamics in general
and hydrodynamic networks (as in the case study) in particular are avail-
able, often better suited to the domain than a general purpose simulator like
Matlab/Simulink. However, sometimes other aspects of the simulation envi-
ronment – such as the possibility to generate real time code or compatibility
with simulation models of other parts of the system – may make a particular
tool like Matlab/Simulink preferable to other tools.
A characteristic of modelling with Simulink is the underlying dataflow
model. Models are described by block diagrams, where bigger blocks are built
out of smaller blocks, and blocks are connected by signals, which impose a
direction on the influencing sizes of the system. A block realises a function,
transforming an input signal into an output signal, but possibly using and
changing an internal state. Therefore, often blocks are described as pure
functions in the Laplace transform.
The problem in modelling the phenomena occurring in hydraulic networks
is the lack of a direction of causality, i.e. usually the states of a component in
a hydrodynamic network will usually depend on the state of its neighboring
components and vice versa.
This phenomenon has long been known in the context of physical mod-
elling and different solutions have been chosen. One solution is to avoid flow
diagrams as modelling formalism on the whole and instead to use constraint
based modelling methods as in Modelica to specify the system with Kirchhoff
equations for steady state assumptions. The models obtained this way can
be translated back into block diagram models, but at a price. The resulting
models would not be easy to read.
If on the other hand one wants to stick to block diagrams as primary
specification formalism (and Simulink as corresponding tool), two options
arise: One tries to formulate the Kirchhoff equations as algebraic constraints,
which the simulator (integrator) would have to resolve dynamically. As the
number of connections in the system rises, this is no longer realistic.
Alternatively, one can model the hydrodynamic network in the flavor of
current-potential-equations, as has been developed in [2]. In that work, a
network theory is proposed for modelling processes as they occur in chemical
process control, but naturally the techniques can be applied to hydro- and
thermodynamic networks as well.
We will elaborate the concept for the current application in the following
2
sections and outline a prototype simulink library for hydraulic networks,
which we have developed on this basis.
3
pi pj
connecting
Ci element Cj
Ii Ij
S1 S2 S3
4
terial in a switched manner. Consider for instance the case that there is
water flowing from component 1 to component 2. Then the thermal energy
in component 2 results as immediate mixture of the thermal energy of the
container contents and the inflow, whereas the energy loss of component 1
depends only on the outflow but not the conditions within component 2.
The above way of modelling unavoidably introduces imprecisions rela-
tively to the the continuous modelling via partial differential equations: The
resulting behaviour of the model will usually differ from the behaviour of the
continuous model.
This means that only the last step in the modelling – the modelling of the
atomic components and connections differs from the modelling for simulation.
However, for purposes of simulation for technical applications, the introduced
error will often be small compared to the imprecisions of the actual physical
system. Robust control systems should not rely on these imprecisions in
order to function correctly.
In the following section, we explain in detail the mathematical model of
atomic components used for hydro- and thermodynamic networks.
5
• the kind of the phase: liquid water, vapour, air, etc.
• its volume and more generally the geometry of the component or the
phase;
• its mass;
6
For a thermal connection we assume that the two components are ther-
mally connected by a heat conducting medium.
7
• We make the mass flow a variable of the connection. The mass flows at
the connections of a pipe thus implicitely describe the kinetic energy
of the liquid in the pipe.
The development of the mass flow is then determined via the local
force, more precisely the force gradient at the connection. Given the
connection area and the definition of pressure as force per area, we
can thus determine the flow (in mass per second) as integration of the
average pressure gradient multiplied by the connection surface.
An important advantage of this modelling decision (instead of keeping
track of the acceleration and passing this information to the compo-
nents) is that it allows to close connections (set the flow to zero) without
delay. For the derivative, this would have to be modelled by a Dirac
pulse, which is not supported by Simulink.
• The second – and most crude – design decision coming into the picture
is how to determine the pressure gradient at the connection out of the
mass, temperature and geometry of the connected components.
We thus decided to determine the average pressure in the components
according to an equation of state for liquid water, i.e. a thermodynamic
law relating density, temperature and pressure of water. Such an equa-
tion of state gives us two functions, a function to calculate the density
of water from its temperature and pressure and dually its pressure out
of the temperature and the density. This is elaborated in Section 3.3.
8
from the gravitational center to the connection. Within the connection,
the corresponding information concerning both components is com-
bined by the assumption of a constant pressure gradient between the
centers of the components.
• All of the above is sufficient for the case of horizontal, frictionless and
passive pipes. For the case of pipes passing an elevation, for the case
where viscous friction is modelled, and for active components such as
pumps this is not sufficient.
From an analytic point of view, all of the above cases lead to a change in
pressure between the ends of a pipe. Friction makes the pressure drop
in the direction of the flow. An active pump raises the pressure in the
pumping direction, and gravity raises the pressure in the downwards
direction. In order to model these phenomena, we superimpose their
pressure effects over the mean pressure.
• The flow of enthalpy as mentioned follows the flow of mass. Within
the connection we thus first determine the direction of the flow and
from the temperature of the component with the outflow we derive the
enthalpy flow.
For thermal connections, the modelling technique is simpler, because the
transfer of heat uses a medium with a certain conductivity, thickness and
connection area. Using simple laws of thermal conduction, we thus determine
the enthalpy flow from the differences of temperatures.
This is consistent with the assumption of equally distributed temperature
within a component. Still, this contains the systematic modelling error, that
the change in thermal energy is immediately visible at all other connections
of a component as well.
9
incompressibility of liquids like water is indeed inconsistent with an equation
of state.
Nevertheless, equations of state for water have been formulated to de-
scribe the relation of the three sizes (pressure, density, temperature) within
certain ranges. These equations are approximations using certain assump-
tions on the form of the equation and have several coefficients (playing a
similar role as RS for an ideal gas) which have been determined by curve
fitting experimentally obtained triples.
For the purpose of demonstrating the feasability of the approach, we
have chosen to use a simple equation, the UNESCO equation of state for
seawater (IES80). The reason for chosing this equation was an available
matlab function for computing the density from pressure, temperature and
salinity.
We set salinity to zero and for the resulting simplified function we also
(using a computer algebra system) computed the inverse function to deter-
mine the pressure from density and temperature at salinity zero.
As its name saysm this equation is meant to approximate the equation of
state for water at conditions which occur in the seas of earth. Its applicability
is thus limited and the choice is a compromise.
There are, however, other approximations available such as the recently
published [3], which claims to be very exact over a wide range of pressures
and temperatures.
The matlab code for computing the pressure is given in the appendix.
10
pipe to which energy can be added to heat it) and a counter-current heat
exchanger. These blocks are included as demonstration of the possibility
to compose a collection of locally connected components to a subsystem
independently from the rest of the system.
Most components in the library are masked and allow the specification of
some parameters, typically physical dimensions of the component as well as
information about the initial state (initial temperature and pressure).
Completely lacking at the moment are gaseous phases. As a compensa-
tion, there is a components called water column which represents the liquid
phase of an cylinder open to atmospheric pressure and with a liquid connec-
tion at the bottom.
In the following subsections we show some examples of components in
the library to explain its structure. We assume basic familiarity with block
diagrams.
A complete print of the library is attached in the appendix.
11
massinit
initial mass
1 enthalpy flow 1
Demux
1
In1 mass flow 1
mass pressure
s
mass volume volume temperature
enthalpy density
1 transformation
2 Demux enthalpy flow 2
s
In2 mass flow 2
enthalpy
tempinit
initial enthalpy 1
initial temperature
Out1
length/2
halflength
deltaheight 0.5
9.81
pressure drop due to rise distribute
grav. acceleration (m/s^2)
2
Out2
12
vectorial inputs: pressure temperature distance
[p1]
In1 [p2]
1 Demux [T1]
signals 1 2 Demux [T2]
[d1] signals 2
In2 [d2]
[d1]
[d2]
1 [T1]
[p1]
s
force gradient [T2]
[p2] negative pressure gradient flow flow temperature
enthalpy flow −1 1
Out1
A qinit Gain
2
connection area initial flow
Out2
1
T1
2
−1 1
T2
Out1
enthalpy flow Gain
(lambda*A)/(length*cwater) 2
Out2
13
4.3 Example: A countercurrent heater
As an example of a complex component, Figure 6 shows a countercurrent
heat exchanger. It is modelled by two pipes of three segments, which are
connected by liquid connections. The parallel segments are linked by thermal
connections.
Supposing that a hot current flows through the upper branch from left
to right and a cold current flows through the lower branch from right to left,
then the resulting heat exchange will be stronger due to higher temperature
differences along the pipes (i.e. in the segments) than if the currents both
flow in the same direction.
OutA1
1 2
OutA2
Out1
Out2
In1
In2
Out1
Out2
In1
In2
Out1
Out2
liquid liquid
pipe with friction pipe with friction pipe with friction
connect connect
and thermal connection and thermal connection and thermal connection
Out1
Out2
Out1
Out2
In1
In2
In3
In1
In2
In3
In1
In2
In3
InA2
1 2
InA1
T1
T2
T1
T2
T1
T2
thermal thermal thermal
connect connect connect
Out1
Out2
Out1
Out2
Out1
OutB1 Out2
3 4
Out1
Out2
In1
In2
Out1
Out2
In1
In2
Out1
Out2
OutB2
liquid liquid
pipe with friction pipe with friction pipe with friction
connect connect
and thermal connection and thermal connection and thermal connection
Out1
Out2
Out1
Out2
In1
In2
In3
In1
In2
In3
In1
In2
In3
InB2
3 4
InB1
14
5.1 Appropriate Integration Methods
The modelling technique proposed here is meant for easy compomisition of
understandable simulink models. Unfortunately, the simulation models have
properties which sometimes make the simulation, i.e. numerical integration
slow (not generally suited for the generation of real time code). Neverthe-
less, some measures can be taken which help to come up with sufficiently
performing models.
A key problem in the modelling technique is due to the presence of oscil-
lations of relatively high frequency with relatively low amplitude, which do
not contribute to the macroscopic behaviour of the models. Models with this
property are called stiff. A variable step integrator thus has to reduce the
step size to deal with the high frequency disturbancies unless they vanish to
a magnitude below integration precision.
We usually obtained the best results using Simulinks integration method
ode15s with maximum order 2.
The oscillations are due to the modelling of compressibility, which we
introduced in order to obtain models compositionally. Intuitively, these os-
cillations are due to a discrepancy between the pressure as calculated from
density and the pressure which reflects the macroscopic state of the system
(macroscopic flows, . . . ).
The phenomenon typically occurs at the beginning of a simulation, where
the originally specified pressure (and derived density) is ill chosen, i.e. re-
quires an immediate and strong change of the global system state. This
becomes visible by strongly oscillating pressures and slow integration. Usu-
ally, the oscillation disappears after a short period (simulation time) due to
various aspects of friction in the system. Then the microscopic oscillation
becomes insignificant and the pressure exposes only the macroscopic oscil-
lations. Correspondingly, the integration step size remains large and the
simulation is fast.
For reuse of the simulation model, the results of a first run can be used to
improve the guess of the initial pressure by estimating the mean amplitude
of the microscopic oscillation. A second simulation will then expose a much
shorter period of microscopic oscillation.
Alternatively, a steady state analysis could be used to find better guesses
of the initial parameters.
15
5.2 Importance of friction
As has been mentioned in the previous section, the microscopic oscillations
due to the modelled compressibility of water consume computation time,
unless they disappear due to friction.
While models without friction usually have a simpler look, their simu-
lation with our approach is not neccessarily more efficient. The calculation
overhead due to computations of friction factors etc. is merited by reduced
microscopic oscillation and a consequently much bigger integration step size.
Thus, unless the behaviour of systems without friction is explicitly re-
quested, including friction is a better idea.
16
• Among the most likely errors to occur is an inconsistency of the param-
eters of the two components linked by a connection and the parameter
of the connection itself. It is currently not detected, whether the values
– in particular the area of the connection – are inconsistent.
If they are not, then usually the simulation will produce strange results
and it is not easy to spot the source of the error.
This problem could be solved by making the connection area an output
parameter of the component, so that the connection can compare the
two connection areas and raise an alarm (and stop the simulation), if
they differ.
• The current implementation does not test for over- and underflows of
containers (i.e. water columns). Overflows will just be ignored, under-
flows with negative signs will not produce meaningful results.
Again, testing for error conditions of this kind in the component and
halting the simulation would be an acceptable solution.
6 Modelling Alternatives
The modelling method we presented is not the only option for compositional
modelling. In this section, we address two other approaches, one similar is
spirit (connection-component modelling), the other classical analytical.
Since we started with the connection-component style modelling we present
in Section 6.2 on the basis of analytical models, we will first discuss the clas-
sical approach.
• The forces working on the liquid are described by pressure (force per
area), gravity, and resistance caused by viscous friction.
17
The interplay of the different force, together with the law of preser-
vation of energy, lead to the well-known Bernoulli equation, which
however comes in many variations depending on the detail of physi-
cal modeling. E.g. under the assumption of constant density, in the
absence of viscous friction, and under the assumption of steady state
(i.e. no changes in the flow direction), the Bernoulli equation takes the
2 p
simple form: v2g +z + ρg = const, where v is the vectorial velocity of flow
at a particular point in the liquid, g is the gravitational acceleration,
z is the elevation relative to an arbitrarily chosen reference height, p is
the pressure at this point and ρ is the density of the liquid.
Taking furthermore the force accelerating the liquid as a whole into
account (which is zero under the R assumption of steady flow), the equa-
2 p
tion is changed to v2g + z + ρg + g1 dvdtx dx = const, where dvdtx is the local
acceleration of the flow with time.
Furthermore, the force of resistance can/has to be added. Viscous fric-
tion follows complex physical laws, in particular, Newtonian liquids ex-
pose a non-continuous transition from laminar to turbulent flow, where
the resistance force is stronger under conditions of turbulent flow.
A compositional modelling technique on this basis thus describes the re-
lations of pressures and mass flow within a component individually and then
adds the global constraints, Kirchhoff laws, that
• The pressure at a connection is identical for the connected components.
• The sum of the flows of mass (and enthalpy) at a connection equals
zero.
A model described in this way is not directly suitable for simulation (nu-
meric integretation). A static preparation phase is required beforehand as is
done for instance by Dymola. A Modelica library for hydrodynamics specified
in this way is freely available [1].
18
• Take the flows of the connected components as input.
• an initial pressure and initial mass. These serve as initial guess of the
pressure at the vertex in the network and as an intuitive measure for
the flexibility of the connection. The less mass is involved, the more
rigid is the connection.
19
can be maintained. As a consequence, the models of the components are a
bit more involved, i.e. analytical, and the simulation results will be closer to
analytic models.
Moreover, the description of the components as functions is inverse: they
take pressures as inputs and compute currents as outputs. The technique
can thus be seen as dual to potential current vector modelling.
7 Conclusions
We have elaborated a way of compositionally modelling hydro- and ther-
modynamic networks with Simulink flow diagrams in the spirit of potential
current vector modelling. The resulting Simulink library prototype can be
used to rapidly compose reference models of such networks.
The emphasis is on rapid prototyping, as a consequence the resulting sim-
ulation models will not perform optimally. Moreover, some physical aspects
have been incorporated into the formalism which often play a minor role in
practice. We consider its main uses in experimenting with models before
actually taking the effort of developing an efficient model and for didactic
presentation of models.
References
[1] H. Elmquist et al. Modelica – A unified object-oriented language for
physical systems modelling, 1999. TUTORIAL and RATIONALE.
[3] C.A. Jeffery and P.H.Austin. A new analytic equation of state for liquid
water. Journal of Chemical Physics, 1999.
[4] The Math Works Inc. Simulink – Dynamic System Simulation for MAT-
LAB, 1999.
20