Ecos02 Part A

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

SOFTWARE FOR THE SIMULATION OF POWER PLANT PROCESSES.

PART A.

Brian Elmegaard
Department of Mechanical Engineering
Technical University of Denmark (DTU)
Nils Koppels Alle, Building 402, DK-2800 Kgs. Lyngby, DENMARK
Phone: (+45) 4525 4169, Fax: (+45) 4593 5215, E-mail: [email protected]

Niels Houbak
Department of Mechanical Engineering
Technical University of Denmark (DTU)
Nils Koppels Alle, Building 402, DK-2800 Kgs. Lyngby, DENMARK
Phone: (+45) 4525 4154, Fax: (+45) 4593 5215,
E-mail: [email protected]

ABSTRACT. INTRODUCTION.
Modelling of energy systems has been increas- During the last ten to twenty years, there has
ingly more important. In particular the dynamic been a tremendous development of software
behaviour is critical when operating the sys- for modelling and simulating energy (or pro-
tems closer to the limits (either of the process, cess) systems. The need for precise informa-
the materials, the emissions or the economics, tion about the behaviour of a system has in-
etc.). This enforces strong requirements on creased in connection with a higher degree of
both the models and their numerical solution integration of processes, optimization of pro-
with respect to both accuracy and efficiency. In cesses, getting closer to the limits of strength of
part A of this paper we give a survey on the materials due to temperature, pressure, or
simulation of energy systems, from models and dimensions, or a need for better control of the
modelling, over numerical methods to imple- processes due to for example quality of the
mentational techniques. It covers important product.
aspects of the different phases of modelling of
a (energy) system. It also gives a short intro- There is no ideal tool applicable for types of
duction to robust numerical methods which it is systems to be simulated. Different areas have
strongly recommended to use. Finally, a few different needs in terms of routines for material
important aspects (sparse matrix technique, properties, types of problems to be solved,
handling discontinuities and table look-ups) of special output, discontinuities, etc.. The tool
the implementation of an energy system simu- developer needs not know all the needs of his
lator are described. Part B contains a short future costumers when the tool is designed.
description of many static and/or dynamic
energy system or process simulators. It dis- In many cases these software tools will have
cusses the principal implementation of the (more or less) the same general structure.
model handling in DNA and finally, a small ex- There is the (graphical) user interface - (G)UI,
ample illustrates that too simple component then there is the modelling kernel part which
models may result in an erroneous, singular defines the problem that can be solved, and
model. finally there is the numerical solution routines
that actually solves the mathematical model. In
this paper we will focus on the inter-play be-
tween the modelling kernel and the numerical numerical method depends on the type of the
solution part. problem: algebraic equation system (static
model), differential equation system (dynamic
In our view, it is very important to separate model), differential algebraic equation system
clearly the numerical solution processes from (DAE model), or partial differential equation
the modelling kernel. This allows for an easy system (PDE model). Further, the choice of
extension of the modelling capabilities of the method may also depend on the actual behav-
code as long as it does not require new numeri- iour of the problem: stiff / non-stiff, highly
cal features. Also, when new numerical codes oscillatory or discontinuous being some impor-
become available, they can easily be included. tant properties. It is obvious that applying the
numerical method introduces errors to the
solution; these are iteration error, integration
THE MODELLING PROCESS. error and/or discretization error.
Simulation of a system, i.e. an energy system,
is a task that normally has to be divided into The fourth task is to implement the numerical
several sub-tasks. Each of these tasks is equal- model in a program, to run the program, and to
ly important because the final difference be- present the results. In this process the
tween the physical reality and the simulated representation of real numbers in the computer
solution is the sum of the errors from each sub- introduces rounding errors in the solution.
task.
The main reason for building a process simula-
The first task to be performed is to build a tor; i.e. a power plant simulator, is a desire to
physical model of the real system. This model avoid going through all the four tasks every
is typically a drawing of the system. The bound- time a plant is to be modelled. Essentially, the
aries for the system are specified, and ne- simulator contains the mathematical models of
glected processes and processes accounted predefined components and from these a
for are determined. These approximations to numerical model is generated and solved.
the nature of the problem can cause a differ- Thus, a user may actually solve rather complex
ence between the actual behaviour of the problems without being an expert in numerical
system and the computed solution. analysis, programming, or component models.
In some simulation systems, today, the graphi-
The second task is to make a mathematical cal user interface serves as a tool for perform-
model from the physical model. This is done by ing task one. The danger of this automation is
applying some of the fundamental laws. Con- that the developer may not always himself fully
servation of mass and energy, definition of heat understand the complete consequences of his
exchanger effectiveness, the ideal gas equa- decisions; thus leaving creative users with
tion, and the heat conduction law being exam- unnecessary difficulties.
ples of such fundamental laws. Some of the
laws do have limitations; i.e. an ideal gas need It is good modelling practice to use stepwise
not be ideal under the current conditions (pres- refinement of the model. Always start with the
sure and temperature). This may influence the simplest and least complicated model of the
accuracy of the solution. At this point, it is also system, even if the results are known on be-
determined whether the model is stationary forehand to be too erroneous. Having verified
(static or time independent) or dynamic (time the correct general behaviour of the simple
dependent); the choice will have a big effect on model, new components can be added (one by
the computational effort that later will be re- one). This is useful as long as the refinements
quired in order to solve the model. are, say, 'in one direction'. When changing
direction it could be beneficial to back-track the
The third task is to apply a numerical method to developments to a simpler version and in-
the mathematical model in order to obtain a crease complexity in another direction from
numerical model. Finding the most appropriate here. Later, the two directions can be com-
bined. to generate all the equations himself. Here, the
number of equations can be reduced dramati-
cally by more or less trivial substitutions. This
MATHEMATICAL MODELS OF ENERGY removes the easy parts of the system. A conse-
SYSTEMS. quence of such substitutions might be, though,
In most power plant simulators, the model is that an originally linear problem ends up being
often a network of inter-connected compo- non-linear.
nents: turbine, furnace, heat exchanger, or
pump. The connections between components For most of these component based applica-
are assumed to be without losses. There are tions (in particular those with many compo-
two methods for handling the inter-connections: nents), it is a general observation, that only a
either direct component-component connection few variables appear in any given equation. In
or component-node-component connection. other words, the incidence matrix with one row
The first one has as natural consequence that per equation and one column per variable is
the conservation laws for mass, energy and sparse (only few non-zero elements - of the
momentum are applied on each component; in order 2 to 10 per row). This can (or should) be
the latter case nodal versions must be applied utilized.
as well. In the first case, the splitting and joining
of streams require separate components - in Many energy system models are steady state
the last case joining streams is handled auto- (static) models. Mathematically they can be
matically. described in the following way
(1) 0 = g(z, p) .
The behaviour of a component is normally
given by equations (constitutive relations) and The vector z contains all the unknown vari-
preferably they should be given in residual ables, p represents the parameters and the
form. Complex component models may include function g describes all the residual equations
several table lookups in order to get correct from the components and the conservation
water/steam-, gas-, or other material properties. laws.
These lookups can be expensive and should
be avoided whenever possible. Other compo- Sometimes, one or more of the unknown vari-
nents may contain chemistry; i.e. chemical ables are determined by a differential equation.
reaction equations that have to be satisfied. These variables are called y, their time deriva-
tive y', and mathematically the system can now
The component approach requires access to a be written as
large library of precompiled components and it (2) y' = f(t, y, z, p) , 0 < t < T , y(0) = y0
preferably should allow that the user can define 0 = g(t, y, z, p) , g(0, y0, z(0), p) = 0
his own components. A heat exchanger is one
component but it is normally necessary to have t is the model time. These equations must be
different versions depending on the media solved simultaneously for y and z. Systems of
(gas, gas composition, or liquid), the type of type (2) are referred to as DAEs in semi explicit
heat transfer (convection or radiation) or chang- form.
es of phase (condensation or evaporation).

The component oriented approach usually NUMERICAL METHODS.


generates many equations, but it is very user Having a mathematical formulation of the
friendly. For a given component only a few system as in equation (1), a robust and fast
parameters have to be specified, almost inde- method for the numerical solution is the Newton
pendent of the complexity of the underlying iteration. This well-known method can be
equations. described as follows
(3) J zs = - g(zs, p) 0
J = g(z, p)
An alternative approach for the user, would be zs+1 = zs + zs 0z
Subscript s is the iteration count. J is the Jaco- The numerical solution is only computed at
bian matrix. The first equation in (3) is a linear special points called step points. From the
system of equations that has to be solved in initial solution the solutions at the step points
each iteration. It is assumed that a good initial are generated sequentially. By interpolation the
approximation z0 to the solution exists. Spe- analytical solution can be approximated be-
cially for large systems an approximation to the tween step points. The distance between two
exact Jacobian matrix is used because the cost step points is called the step size (denoted h).
of an iteration is dominated by generating the A good, simple, and popular ODE method is
matrix and solving the linear system. There are the classical 4'th order Runge-Kutta.
(at least) 3 different ways of approximating the (6) K1 = f(tn , yn )
Jacobian; K2 = f(tn + h/2 , yn + h/2*K1)
1) Numerical differentiation (difference ap- K3 = f(tn + h/2 , yn + h/2*K2)
proximation), K4 = f(tn + h , yn + h *K3)
2) rank one updates (Broyden update), and yn+1 = yn + h/6*(K1 + 2*K2 + 2*K3 + K4)
3) assume the Jacobian matrix to be con-
stant for several iterations. Subscript n is the step number. The K-values
are the slopes of the solution curves at various
Numerical differentiation of a scalar function in points, and the final solution update is a linear
one variable can be written as follows combination (an average value) of these slope
0 values over the step. Since the method is of
(4) g(z, p) w (g(z+ , p) - g(z, p)) /
0z order four, it locally approximates all the terms
w (g(z+ , p) - g(z- , p)) / 2 up to order four of the Taylor expansion of the
true solution. That is,
where the last form is a second order central
(7) len+1 = yn+1 - yn,x w O(h5)
difference approximation. The computational
cost of generating either of these approxima-
where yn,x is the value of the analytic solution at
tions are N+1 or 2N calls to the g function,
time tn + h, that passes through the point (tn,
respectively
yn). By embedding either a higher order or a
lower order method into (6) it is possible to
For very large problems the non-linearities are
estimate the local error (len+1) in one step of the
often located in relatively few equations; com-
method. It is customary to use this estimate for
bining 1) and 3) may be advantageous. The
controlling the step size in such a way that the
iteration is converging as long as the residual
local error is kept below a user specified limit.
(g(y, p)) is decaying in each component. As
Steps with a too high local error estimate are
long as this decay is satisfactory, there is no
normally discarded and retried with a smaller
need to update the iteration matrix.
step size. Strategies for step size control can
be found in [3].
In many simulators, a simpler iteration tech-
nique is applied. Substituting the Jacobian
Some ODEs are stiff: Initially a steep transient
matrix with the identity matrix (I), the method is
dramatically varies the solution; after the tran-
called functional iteration or simultaneous
sient has died out, the solution is slowly vary-
iteration. In the sequential version, the solution
ing. The step size strategy will select a small
vector is updated one component at a time (or
step size during the transient and increase the
one model component at a time) and in the
step size when the transient has died out.
parallel version, the whole solution vector is
There are various definitions of stiffness. The
updated by z in one operation.
mathematical way of describing the above is to
say that after the transient has died out, the
The ODE part of (2) is normally written as
solution will no longer contain components in
(5) y' = f(t, y) , 0 < t < T , y(0) = y0
the direction of the eigenvector associated to
the largest (negative real part) eigenvalue.
and is referred to as an initial value problem.
Thus, problems with a large ratio between the
largest and the smallest eigenvalue have the can be found in [4].
potential for being stiff problems. The tricky part (11) K1 = f(tn + b1 h, yn + h K1)
is though, that the interval of integration [0,T] K2 = f(tn + b2 h, yn + h a21 K1 + h K2)
also affects whether a problem is stiff or not. yn+1 = yn + h (c1 K1 + c2 K2)
with
The previous Runge-Kutta method is explicit = 1 - 1/ 2 a21 = 9 - 28*
and is not well suited for solving stiff problems b1 = b2 = a21 +
due to its stability properties. The step size c1 = (43 + 10* ) / 62 c2 = 1 - c1
control will restrict the step size as if the tran-
sient still exists after it has died out. By intro- By substituting
ducing implicitness in the method this can be Y = yn + h K1 (or K1 = (Y - yn) / (h ) )
changed. A simple implicit method is the back-
ward Euler method into the first stage of (11) we get an equation of
(8) yn+1 = yn + h f(tn+1, yn+1) . the form (9) with Y being the iteration variable.

The method is implicit in yn+1. It is rewritten in Both of the above implicit methods can be
(9), which is of the same form as (1). It is embedded with higher order methods in order
solved using the quasi-Newton method pre- to obtain local error estimates for step size
viously described control.
(9) 0 = F(yn+1) = yn + h f(tn+1, yn+1) - yn+1 .
The DAE problem (2) can be solved in one of
This method is much more expensive per step two ways. If an implicit ODE method is used,
than an explicit method since it involves both equation (9) from the ODE part is coupled with
an iteration in the Newton method and the the algebraic part of the system. For explicit
forming and solution of a linear equation methods it is possible to apply a quasi-Newton
system. Another way of defining stiffness could method for solving the algebraic part, each time
be, that a problem is stiff if it is solved faster on the derivatives have to be calculated.
a given computer with an implicit method than
with an explicit method. A special property, called the index, is
associated to DAE problems. By differentiating
One type of implicit ODE methods are the BDF all the equations in the algebraic part of (2) with
methods. For constant step size they can be respect to time, the system may reduce to a
derived from (8) by adding a linear combination (simple) ODE system of the form (5), otherwise,
of backward information one can make another differentiation. The
(10) ckyn-k + ck-1yn-k+1 + ... + c0yn + yn+1 = index is defined as the number of times it is
b h f(tn+1, yn+1) . necessary to perform this differentiation in
order to end up with a system of the form (5).
In each step, the system of non-linear The above methods for solving DAEs only
equations to be solved is in principle identical to works for index one problems. It turns out for
(9). b and c0 to ck are determined in order to higher index problems, that the algebraic part
achieve the appropriate order (k+1). These of the system matrix (0 g(t, y, z, p) / 0z ) is
methods are normally implemented using the singular.
Nordsieck formulation (a Taylor expansion, see DAE problems are covered in detail in [1].
[5]), but this does not change the form of the
system of non-linear equations to be solved in
each step. Coefficients for several of these IMPLEMENTATION DETAILS.
methods can be found in [2]. In the design of simulation software it is very
essential to have a structured approach; that is,
Also implicit Runge-Kutta methods exists. A 2 make sure that the different parts of the
stage, 2'nd order Diagonally Implicit Runge- solution process are kept clearly separated and
Kutta (DIRK) is given in (11). The coefficients anyway very well integrated. This is the
contradiction between easy maintenance and for row-/column- numbers, respectively) long
efficiency, maybe. In many cases, simulation enough to accommodate room for all non-zero
software has a remarkable long life time; thus, entries. This is a typical storage scheme used
the increase in computational power (doubling as user interface by standard sparse matrix
every 18 month) makes it essential to empha- software, see [6]. The scheme can be utilized
sise maintainability. This is not an argument for almost directly by iterative linear equation
disregarding efficiency! solution methods. For the sake of efficiency of
direct solution methods, the information is re-
A static and/or dynamic energy system arranged internally such that all elements in
simulator is a complicated piece of program one row are stored in consecutive locations.
with many possibilities for overlooking a
problem during the design phase. Restoring It should be mentioned, that in a sparse matrix
such a problem afterwards can be a time- framework, the generation of the sparse Jaco-
consuming job. In this section we indicate a few bian matrix by divided differences (4) can
of the problems, that experience shows are benefit from having access to the structure of
easily overlooked. the matrix on before-hand. The structure, or a
major approximation to it, could be available
In the design stage it is very important to try to from an initial analysis of the system to be
imagine the size of the largest system ever to simulated. It is clear that if two variables do not
be solved by the simulator. Why? For large appear in the same equations they can be
systems, the CPU time is crucial. Thus, the perturbed simultaneously. Analytic evaluation
overhead associated with measures used in of the Jacobian matrix is an alternative, but
order to reduce the CPU time for large systems when generating a new component model, all
will often be bearable for small systems even if derivatives including derivatives of state
it doubles the CPU time. An example on such variables from, say, steam tables, must be
a measure is sparse matrix technique. generated as well.

The solution of systems of linear equations is a The effect of using sparse matrix software is
kernel activity in all simulators. The storage often a CPU time that increases only slightly
required for all elements in a matrix of more than linearly with the number of
dimension N, is N2. The number of operations components in a system model. For small
required for solving a system of linear systems, the CPU time spent on linear algebra
equations with the matrix increases with N3 . is insignificant, thus a major overhead resulting
Thus, if most of the elements, more than 98%, from the sparse matrix code is normally
say, of the matrix are zero by definition, there is acceptable.
much to gain by avoiding these elements. In
the below Fig. 1 a possible storage scheme The linear algebra is used for the iterative solu-
that holds the non-zero entries of the matrix in tion of non-linear equations, normally. Since a
any order is illustrated. non-linear model may have 0, 1, or several
solutions, this part of the code must be
designed with care. For the sake of reliability, it
A: a23 a14 a27 a33 a28 .. a22,7
is important that the simulator allows for a
continuous validation of the solution against
row: 2 1 2 3 2 .. 22 user-given bounds on variables and against
internal component-given restrictions. When
col: 3 4 7 3 8 .. 7 such a validation fails, the code must decide
whether the simulation must be stopped with an
Figure 1: Sparse matrix storage scheme. appropriate error message or if some standard
fix-up could be taken and the calculations
The storage requirements are three arrays (one continued.
real array for the values and two integer arrays
In particular for dynamic simulations it is very discontinuities into two categories - time given
important to reduce the number of calls to discontinuities and discontinuities that depends
routines that calculate material properties, i.e. on the solution. The first type immediately
steam tables for power plant simulations. allows the point of discontinuity to be hit
Almost any effort to avoid re-calculations of precisely and only the last type needs iteration
previous values pays off. For example, transfer to locate the point.
values between two connected components
instead of calculating the same values at each Most of the above have been considered
end of the connection. Also, if non-linearities during the design of the DNA code. Further
are concentrated to a few components, then details are given in part B. In [7-8] there is a
after a few iterations many component much more detailed description as well as a
variables have obtained their final values. In users guide.
this and similar cases, there is no need to re-
calculate already known values. In some cases,
accuracy of tabular values is crucial and this CONCLUSION.
costs CPU time; but when accuracy is not so When designing another energy system simu-
essential it is important to be able to switch to lator from the very beginning it is very important
tabular functions that are simpler (based on the to perform a relatively thorough basic problem
ideal gas equation) and cheaper. analysis in order to have a well designed basis
for constructing the simulator. Spending time
A problem, that is closely related to dynamic on using existing simulators in order to find
simulations, is that of dealing with advantages and disadvantages in relation to
discontinuities in a model. An on-off control, the problems that are to be solved, is very
say, can cause serious troubles for the step important. Experience shows, that being forced
size strategy in the ODE solver, as can a to make dramatic design changes in order to
linearly interpolated table of data. A incorporate a certain feature, is very expensive.
discontinuity can only be passed by the A code designed for static problems may only
integrator with a very small step size. The with severe difficulties be changed to also
process of both reducing the step size and handle dynamic problems.
locating the point of discontinuity will cost many
rejected steps. The technique to be used for Try to be very optimistic with respect to the size
reducing the cost for handling discontinuities is (number of variables, components, equations,
as follows: etc.) that the simulator should be able to solve
1. Implement all component models such that within a reasonable time. At some point in time,
the discontinuity is not activated during there will be a user asking for even more!
normal stepping of the integrator.
2. Before a step is accepted, all discontinuities Try to use as much standard software as
must be checked to see if a passage has possible - for several reasons: 1) there are
occurred. absolutely no reasons for inventing the wheel
3. When this happens, locate the point where again, 2) routines for solving standard problems
it happened by interpolation and restart the can be obtained from independent sources and
integration from there. are anyway almost directly interchangeable,
Easy location of the discontinuity can be imple- and 3) it requires a special expertise to develop
mented using functions that change sign when more effective software even for special
a discontinuity appears. Locating a problems than standard software available from
discontinuity is then a question of locating a various libraries. Only in cases where standard
zero of a function within the interval defined by software does not exist, consider building your
the two end-points of the step currently being own. In this situation, still consider the problem
computed. Even though this can dramatically to be solved using 'standard tasks'. The
reduce the cost of passing a discontinuity resulting modularisation will be invaluable in the
further reduction may be obtained by dividing future maintenance and extension of the code.
When modelling large and complex systems it
is necessary to have the right tools. This can be
either a set of basic numerical solution routines NOMENCLATURE.
or a dedicated simulator. Even with the right A: Array holding matrix entries.
tools, it is still necessary to be very careful F( ): A (vector) function.
when building and validating a model. J: Jacobian matrix.
Ki: Stage i values in Runge-Kutta methods.
Equally important is the step by step refinement N: Number of equations.
of a model. Develop and test sub-models T: Final integration time.
before they are glued together to form a Y: Iteration variable (local approximation to
complete system model. Modern simulation solution.
tools have many facilities that are very useful
for making good models and validating them, a: Matrix element or R-K method coefficient.
but these features can never take the b, c: ODE method coefficients.
responsibility for the quality of a model away col: Array holding column numbers.
from the modeler. f( ): A (vector) function of some variables.
g( ): A (vector) function of some variables.
h: Step size in ODE method.
REFERENCES. le: Local error estimate.
[1] Brenan, K.E., Champbell, S.L., and Pet- p: Vector of parameter values.
zold, L.R.: "Numerical Solution of Initial- row: Array holding row numbers.
Value Problems in Differential-Algebraic t: Integration time.
Equations". North-Holland. 1989. y: Dynamic variables.
[2] Gear C.W.: "Numerical Initial Value Pro- z: Static variables.
blems in Ordinary Differential Equations".
Prentice-Hall. 1971. : Increment in the following vector
[3] Gustafsson K.: "Control of Error and : Particular method constant.
Convergence in ODE Solvers". Dept. of
Automatic Control, Lund Institute of Subscripts.
Technology, Lund, Sweden. 1992. (Ph.D n: Integration step number.
thesis) s: Iteration counter.
[4] Nørsett, S.P.: "Semi explicit Runge-Kutta x: Exact solution.
Methods". Mathematics and Com- 0: Initial value.
putation. Vol 6/74, NTH, ISBN 82-7151-
009-6. 1974.
[5] Curtis,A.R.: Numerical Methods for Solv-
ing Stiff Systems of Ordinary Differential
Equations - or - is there a life after Gear?
NPL report DITC 29/83, UK, 1983.
[6] Duff, I.S.: Sparse Matrices and their Uses.
Academic Press, 1981.
[7] Elmegaard, B.: Simulation of Boiler Dyna-
mics - Development, Evaluation and
Application of a General Energy System
Simulation Tool. PhD thesis,
Technical University of Denmark, 1999.
[8] Lorentzen, B.: Power Plant Simulation.
PhD thesis, Technical University of Den-
mark, Laboratory for Energetics, 1995.

You might also like