Professional Documents
Culture Documents
GETTING STARTED
Trademarks
MATLAB / Simulink are registered trademarks of The MathWorks, Inc.
Excel is a registered trademark of Microsoft Corporation.
TABLE OF CONTENTS
2 SIMPLE MODELS.......................................................................... 26
2.1 MODELING A CARNOT CYCLE .................................................................................................26
2.2 PRESSURE FEEDBACK DEMO .................................................................................................27
4 REFERENCES .............................................................................. 34
LIST OF FIGURES
Figure 1: Gas turbine example before simulation run ......................................................... 8
Figure 2: Gas turbine example after simulation run and detail showing a thermal efficiency of
about 27%.............................................................................................................. 9
Figure 3: Gas turbine example with improved efficiency of about 32 %. ........................... 11
Figure 4: Main "layers" of Thermolib blockset ................................................................. 12
Figure 5: Accessing signals on the Thermolib Flow Bus with a standard Bus Selector ......... 15
Figure 6: Parameter Mask of Equilibrium Reactor (Detail) ................................................ 16
Figure 7: Flow Display blocks shows physical properties with units ................................... 17
Figure 8: A mass balance automatically created with th_ExportBalance command ............. 18
Figure 9: T-s Diagram for water with an isobare ............................................................. 19
Figure 10: Example "DemoPressureValve" demonstrates the forward flow method ............ 20
Figure 11: Pressure at output varies with valve position, while mass flow is constant ......... 21
Figure 12: DemoPressureValveWithPF with the pressure feedback signals (green goto/from
blocks). Pump operates on constant RPM, while valve position is varying. .................. 22
Figure 13: Simulation result of DemoPressureValveWithPF showing pout satisfying the
boundary condition of 1 bar, while mdot varies with valve position. ........................... 23
Figure 14: DemoCarnot modeling a Carnot cycle ............................................................. 27
Figure 15: Simple Pressure feedback demo with one valve .............................................. 28
Figure 16: Parameter Mask of the Liquid Tank ................................................................ 29
Figure 17: Valve outlet pressure during valve position change (relaxation factor = 1) ........ 30
Figure 18: Valve output pressure during valve position change (relaxation factor = 5) ....... 30
Figure 19: Flow scheme of a combined cycle power plant ................................................ 31
Figure 20: Combined Cycle Power Plant modeled using Thermolib components in Simulink 32
1 INTRODUCING THERMOLIB
This chapter introduces Thermolib, explains what it is and what you can do with that
toolbox.
Thermolib software is a modeling environment for the engineering design and simulation of
thermodynamic and control systems within Simulink and MATLAB. It is based on
fundamental engineering thermodynamic principles and contains a comprehensive library of
thermodynamic and thermochemical blocks that seamlessly integrate into the MATLAB and
Simulink environment. Generic state calculation blocks facilitate the design of user-defined
components. The thermophysical database is derived from the JANAF tables and can be
easily extended by the user. Thereby Thermolib is not limited by ideal gas assumptions and
can even handle mixtures of reactive multi-species multi-phase mixtures. It thus ensures the
consistent treatment of thermodynamic requirements in the MATLAB/Simulink environment
relieving the design engineer of many otherwise tedious tasks.
While Thermolib considerably extends and expands the usability of MATLAB/Simulink for
modeling thermodynamic processes, it has some natural limitations attributable to the solver
structure on which Simulink is based. Most importantly, Thermolib does not cover spatial
transport processes and as such it is not a multi-dimensional flow simulation program.
Geometrical design aspects are not considered. Thermolib works at the system level and
models the input/output behavior of process components as it is familiar to the
thermodynamic process engineer.
In some cases the user will want to include results from detailed multi-dimensional flow
simulations or from experiments to generate characteristic curves like flow dependent heat
exchange coefficients or fuel cell polarization curves. This can easily be taken care of in the
Thermolib components.
For more information on the limitations please read the corresponding chapter in the User
Manual.
Fuel
Combustor
2 3 Electricity
Gas
Turbine
(Brayton)
Generator
Cycle Compressor Turbine
1 4
Intake Air
A compressor feeds compressed air to a combustion chamber where the fuel (in this case
methane, CH4) is injected. For simplicity, complete combustion is assumed. The exhaust gas
from the combustor is then expanded in a turbine to drive a generator shaft. A part of the
work is used to drive the compressor.
This model illustrates the basic principles and capabilities of Thermolib. It shows how blocks
are connected with standard Simulink busses and how flows can be easily displayed using
the flow display block from the Sinks section of Thermolib.
Also, the example shows how gas mixtures are treated - the incoming wet air is a mixture of
O2, N2 and H2O. After being compressed the air is burnt using CH4 as a fuel inside a
combustor. The combustor essentially is a standard chemical reactor taken from the
Thermolib library. The resulting high temperature gas is then expanded in the turbine.
Start MATLAB and load Thermolib (if not already done) by issuing the
Thermolib_Setup
In the upper part you see how the flow sheet of the process is modeled using Thermolib
blocks - with the compressors, the mixer, the combustion chamber and the turbine. In the
lower part is located an efficiency calculation.
When you run the model you will see some widen lines which are standard Simulink busses
representing the media flows between the components. You see sensors and flow display
blocks attached to the flows to show the interesting physical properties of the flow. To show
or use the properties of the flow you can use one of the following methods:
connect a Flow Display block (Thermolib\Sinks) to the flow and select the signals to
display (displayed in SI units),
connect a Sensor block (Thermolib\Miscellaneous) to the flow and select the signals
and units you want to use,
connect a Bus selector (from Standard Simulink blockset in section Commonly used
blocks) to the flow and select your signals of interest (SI-units).
You see the temperature, pressure and concentration information displayed in the grey flow
display blocks and in the displays showing the sensor measurements. Note how the
temperature slightly rises after the compressor and dramatically increases after combustion.
The sources of methane and wet air are modeled using blocks from the "Sources" subgroup
of Thermolib. They serve as reservoirs defining the thermodynamic state (T, p, composition)
of the media sources. The mass flows are defined using Isentropic Compressors
(Thermolib\Components\Hydraulic) with isentropic efficiency. The mass flow is controlled by
the "ctrl" port, which gives the actual mass flow as fraction of the maximal mass flow
configured in the compressor mask (here 1 = 100%).
Figure 2: Gas turbine example after simulation run and detail showing a thermal efficiency of about 27%
In Figure 2 you see that the turbine produces a power of about 10 MW (1.01e7 W), while
the air compressor consumes about the half of this (5 MW). Note, that all powers represent
the mechanical work at the fluid/gas. The mechanical losses (e. g. friction in bearings) are
not considered here.
We will now try to improve the efficiency by changing the turbine inlet properties
(temperature and pressure). To do this we change the outlet pressure of the compressors.
The outlet pressure value outlet press. gives the absolute pressure level for the compressor
output flow in Pascal (e.g. 7e5 Pa = 7 bar in this case).
Change the simulation end time to inf and run the simulation. During simulation you can
play around with the outlet pressure signal by modifying the setting of the gray Slider Gain
block to see how efficiency and overall power will react on the change. As depicted in the
screenshot below, for example, changing the pressure level from 7 to 14 bar increases the
efficiency by more than 5 percent reaching an absolute value of 32 %.
The graphical Simulink environment allows for an intuitive design of thermodynamic system
models in that the physical flow (usually) follows the signal flow so that model components
taken from the library can be arranged in resemblance to the underlying physical topology.
While Simulink provides the graphical interface and modeling environment, Thermolib takes
care of the special thermodynamic requirements. The user only needs to drag and drop the
readymade thermodynamic blocks or process components into his Simulink model. This is
much faster than deriving the equation system from the physical conservation laws and
integrating them with standard Simulink blocks. Apart from the sheer complexity this task
will usually bring about, the above mentioned advantage of graphical programming is lost.
Another advantage, perhaps less apparent but even more important is the consistent and
very efficient treatment of thermodynamic considerations in the Simulink framework, e.g.
fluid mixture properties, state changes involving simultaneous reaction and heat transfer,
chemical and phase equilibrium calculations etc.
The most important part of Thermolib is the Simulink based blockset which provides blocks
to simulate typical thermodynamic process components like heat exchangers, chemical
reactors, pumps, compressors, tanks as well as specialized components like fuel cell stacks.
Thermolib Components
(e. g. Pump, Compressor, Heat exchanger ...)
Thermodynamic
State Changes
(e. g. isentropic pressure change)
Thermolib blockset
All these component blocks are created in Simulink using a lower layer set of blocks to
perform the fundamental thermodynamic state and property calculations (see Figure 4). The
thermodynamic state and property calculations comprise density calculations, the calculation
of saturation temperature and pressure and the necessary conversions between different
thermodynamic state variables (e.g. T=T(H,p,), H=H (T,)). A typical example is to
calculate the complete state of a given mixture given the enthalpy, pressure and the mixture
composition.
In simulation often occurs the task to calculate a final state for a thermodynamic state
change, while given one of the characteristics of the state change. Imagine an isentropic
pressure drop happening in an idealized turbine. There is a subgroup of Thermolib blockset,
which is dedicated to perform such calculations. You find them in the "Thermodynamic State
Changes". See also the example modeling the Carnot cycle below.
You can use all of these blocks to model your thermodynamic process or to set up your own
custom component blocks. You can also start with a Thermolib component block and modify
it as needed. Try looking under the mask of a Thermolib component (e. g. the Compressor
blocks from the gas turbine example) and you can see how the states and properties blocks
are used to model the physical behavior.
The complete list of subgroups of Thermolib blockset is as follows:
The Balance sub-library contains balance-related blocks needed for generating
energy and mass balancing information.
The Components node is further divided into five sub-libraries according to their
intended field of application. They contain higher-level process components such as
heat exchangers, reformers, stack models, components with pressure feedback, etc.
These components constitute the main part of the Thermolib.
The Controllers sub-library contains PI and PID controller blocks with integrated
anti-windup strategies to create simple controller loops for fuel cell systems.
The Miscellaneous sub-library contains blocks like a general sensor and unit
conversion blocks as well as initial condition block.
The Setup sub-library contains the main Model Setup block required for every
simulation using Thermolib.
The Sinks sub-library contains the Flow Display block to observe thermodynamic
signals and properties in a convenient way.
The Sources sub-library contains source blocks for flow streams, so-called flow
busses, and power signals.
Thermodynamic State Changes. These blocks represent an intermediate layer
between "Thermodynamic States & Properties" and "Components". They represent
thermodynamic state changes like "isobaric enthalpy change". Most of these blocks
encapsulate Thermodynamic States and Properties blocks and a bus assignment for
easier use. You can use these blocks as a starting point for your own components.
Thermodynamic States and Properties. These blocks are the fundamental layer
of Thermolib. Here is where the basic thermodynamic calculations take place. Some
of them calculate single thermodynamic properties like "density" while others like "H-
p-State ..." calculate the complete thermodynamic flow bus (FB) based on a subset of
thermodynamic properties of an incoming Incomplete Flow Bus (IFB).
The flow between connected blocks is represented by a Simulink bus signal. The bus
contains a set of the most important properties defining the flow
molar flow rate (ndot),
pressure (p),
temperature (T),
enthalpy flow (Hdot),
entropy flow (Sdot),
flow of the Gibbs free energy (Gdot),
capacity flow (Cpdot=ndot*cpm),
vapor fractions (x) and the
molar species concentrations (psi).
This information is redundant but enables efficient calculation within the blocks; furthermore,
the user can access all state variables before and behind a process component (see Figure
5).
Figure 5: Accessing signals on the Thermolib Flow Bus with a standard Bus Selector
Temperature changes are governed by heat transfer and heat capacity. During transient
phases (e.g. when there is a change in the amount of heat transferred to the solid surface of
a heat exchanger) the internal energy of a component changes. The temperature change
depends on the overall heat capacity of the component, its thermal mass. The thermal
masses can either be configured directly in the dialogue box of a component or by adding a
Thermal Mass block to the media flow. The Thermal Mass block dampens the temperature
change according to the capacity defined. The flow passing through a component exchanges
heat with the thermal mass, thus the temperature of the output flow follows the input
temperature in a damped fashion.
Thermodynamic systems often contain chemical reactions, e.g. combustion. You can model
reactions by using reactor blocks that come along with Thermolib. The two main reactor
blocks are
the equilibrium reactor and
the reactor with a given conversion rate.
The Equilibrium Reactor (Thermolib/Components/Reactors) simulates a non adiabatic
chemical reactor. You can heat/cool it via a second flow and the block calculates the
chemical and thermodynamic equilibrium condition for the given combination of inputs. The
output is in equilibrium. Note that this calculation is done without assuming a specific volume
of the reactor. The set of chemical reactions taking place in the reactor can be freely
configured (see Figure 6).
useful if you have measurement data available describing how the conversion rate depends
on the different operating conditions (see Gas turbine example above).
Any open thermodynamic system is fed by a source of media. Thermolib provides two source
blocks for the configuration of a media source: one is for pure substances, the other is for
defining mixtures. Separate blocks are necessary, because in pure substances the Gibbs
Phase Rule applies. The rule states that the degrees of freedom depend on the number of
phases. Consider this simple example: if you want to define a water liquid/vapor mixture that
is half liquid, half vapor you can only define the temperature OR the pressure independently,
because the other variable is fixed by the vapor pressure curve of the species.
The sink block displays selected properties of the flow including its physical units making it
easier to monitor the flow between the system components.
For certain tasks you may want to use the thermodynamic property database which is
delivered with Thermolib and the thermodynamic state calculations on the MATLAB
command line.
For some of the thermodynamic states and properties blocks in Simulink there is a
corresponding command line function with the same functionality.
You can use these functions together with the powerful plotting capabilities that standard
MATLAB offers. The MATLAB functions can also be used in conjunction with a PDE solver to
tackle systems with distributed parameters.
Example:
The following code plots the temperature versus entropy of water at a constant pressure.
This is refered to as the isobaric curve in T-s-diagram. One way to plot this diagram is to use
the Thermolib block "isobaric enthalpy change" (Thermolib/Thermodynamic State Changes).
However, using the command line function, one is able to produce the same diagram with
the following code on a much more MATLAB-way:
% plot T-S diagram for pure water
load ChemicalMediaData
T = 200:2000;
n = length(T);
psi=ones(1,n);
ndot=ones(1,n);
p = 1e5 * ones(1,n);
psi=ones(1,n);
[State,err] = th_TpState('ndot',ones(1,n),'T',T,'p',p,'psi',psi,...
'Species',{'H2O'},'MediaData',SMediaData)
plot([State.Sdot],T)
title('T-S Diagram for water')
xlabel('molar entropy [J/K*mol]')
ylabel('temperature [K]')
Note the vectorized operation to calculate the state of 1800 different temperatures in one
command. The resulting diagram is shown in Figure 9.
Thermodynamic processes often involve hydraulic coupling and networks to some degree. To
model hydraulics with Thermolib there are two possibilities
Forward flow simulation
Figure 10 and
Figure 11 show example "DemoPressureValve" and its simulation results, which demonstrate
this method.
Figure 11: Pressure at output varies with valve position, while mass flow is constant
The second option takes into consideration the pressure feedback signal travelling upstream
to the source block. In Thermolib you can model this with explicit feedback signals. This will
cause the mass flow to vary (or even stop) depending on the valve position. In example
"DemoPressureValveWithPF" this is demonstrated (Figure 12). The source is now a tank of
liquid water at 1 bar, while the pump operates on RPM=const.
Figure 12: DemoPressureValveWithPF with the pressure feedback signals (green goto/from blocks). Pump
operates on constant RPM, while valve position is varying.
Figure 13: Simulation result of DemoPressureValveWithPF showing pout satisfying the boundary condition of 1 bar,
while mdot varies with valve position.
Thermolib offers both these possibilities. In many models the first method may be sufficient
as the mass flow is often known. In more complex situations you can use the second
method. The methods can also be combined such that the second feedback approach gives
an estimate for the mass flows to be used in the forward calculation method.
To work with the forward calculation method use the blocks from
Thermolib/Components/Hydraulic. When working with pressure feedback use the blocks
from Thermolib/Components/Hydraulic with pressure feedback.
Some blocks can handle both situations so the PFin/PFout (pressure feedback in and
pressure feedback out ports) can be left open or terminated with ground or terminator
blocks. You will find these blocks in both sections. Some other blocks only make sense when
used in conjunction with pressure feedback modeling (e. g. a splitter). They will only be in
the corresponding section.
To model pressure feedback the "PFout" port of a downstream block has to be connected to
the "PFin" port of the corresponding upstream block.
Tank blocks serve as sources. Here you have to choose the option "m.out = f(PF)" in the
block mask. This makes the outgoing mass flow depend on the pressure feedback
information. The "downstream" blocks define the boundary conditions, e.g. the outlet
pressure.
To maintain clarity in the model structure, we recommend using From/Goto blocks to feed
back the signals, rather than directly connecting the blocks with lines. To avoid this often
cumbersome manual work Thermolib has a tool, which creates the From/Goto block
connections automatically from a standard forward network.
Type
th_CreateFeedback
at the MATLAB command line to call this dialog. See more about this topic in the
corresponding section of the user manual.
You may want to start by having a look at our extensive set of examples for hydraulic
modeling in \Examples\PressureFeedback subdirectory of your Thermolib installation. You
will also find these demos via "Help Demos Thermodynamic Systems Library
Pressure Feedback" in the MATLAB help system.
section to break them if needed or consider adding a tank to model the media flow in
the loop (which is more physical).
4. Adapt Simulation parameters (step-size, solver...)
Adapt the simulation settings in Simulink as needed for your model. Think about the
time constants of your model. Typically, the characteristic time scale in
thermodynamic processes is in the order of seconds. Make sure that your maximal
step size is not too big, as this may lead to inaccurate results e. g. in balancing.
5. Add Components, Displays / Scopes, Sensors as needed
Add components and other blocks as needed. Consider adding a "Sensor" block from
the "Miscellaneous" section to choose the signals that you are interested in and
display them in convenient physical units.
To learn more about Thermolib you can use the MATLAB help system. Thermolib integrates
its help pages into the standard help of MATLAB. Go to
command on the MATLAB command line, where you replace <th_command> by the name of
the command line function you need help for. When you use
doc <th_command>
the help for this function will be started in the Help browser.
1.5.2 Bibliography
2 SIMPLE MODELS
This chapter shows three demo models in more detail. This gives you an idea how Thermolib
models could look like.
DemoCarnot
The working fluid is water/steam. In the upper part we see the high temperature/high
pressure states, while the lower part shows the states at low temperature and low pressure.
Note the change of the vapor fraction x, indicating a condensation during transition from
from state 1 to state 2 and an evaporation taking place from state 3 to state 4. We did
choose the example such, that all four states are within the vapor-liquid phase equilibrium of
the working fluid.
Note how all " Hdot" values add up to zero.
See also the other examples in \Examples\BasicThermodynamicCycle in your Thermolib
installation directory for more ideas on how to use the state change blocks.
DemoFlowSimple
Liquid water at a constant pressure of 5 bar flows out of a tank and through a valve, with
the exit pressure downstream of the valve at 3 bar. The valves position changes at t=100 s.
The water source is a liquid tank. The input mass flow to the tank is set to zero. The
Downstream block defines the outlet condition, which is set to 3 bar. From here the pressure
feedback signal pf_1 is fed back to the pressure valve, while the pressure feedback signal
pf_2 from the valve is fed back to the tank.
The tank parameter m.out = f(PF) is chosen, indicating that the flow rate is calculated using
the downstream pressure information.
Taking a look at the simulation results, you will see that the valve outlet pressure moves
back to the 3 bar setpoint after the valve position changes.
Figure 17: Valve outlet pressure during valve position change (relaxation factor = 1)
Note that the pressure is calculated iteratively by adjusting the mass flow from the tank in
the time domain, thus imposing an error in the flow dynamics. The pressure feedback solver
finds solutions for slowly varying pressure drops.
You can improve convergence by tuning the relaxation factor for pressure feedback in the
liquid tank, e.g. by increasing this parameter from 1 to 5 the pressure dynamics become
much more pronounced:
Figure 18: Valve output pressure during valve position change (relaxation factor = 5)
For more detailed description of how pressure feedback works, please have a look at the
corresponding section in the User Manual.
The modeled process with Thermolib components looks like shown in Figure 20.
Figure 20: Combined Cycle Power Plant modeled using Thermolib components in Simulink
Note the higher efficiency of the combined cycle (ca. 50%) compared to the gas turbine
example.
3 RELATED PRODUCTS
Here you can find links to other products, which related to Thermolib in some way.
EshSimulation
Some of our costumers work in the field of domestic heating & cooling applications. Here, in
some cases long term simulations may exceed an entire year but still have to be done with a
high temporal resolution. EshSimulation is a very efficient tool that can handle comparative
simulations with different parameter settings in the shortest time.
Systemlib
Having completed your plant model you may want to create a control application. Here you
will face problems concerning remanent data-storage, alarm handling, time handling etc.
Systemlib offers various functions that will support you with these time consuming tasks.
The HiL-Starter Kit, EshSimulation and Systemlib are EUtech products. For more information
please visit www.eutech-scientific.de.
4 REFERENCES
[1] ftp://ftp.technion.ac.il/pub/supported/aetdd/thermodynamics/
and its mirror: http://garfield.chem.elte.hu/Burcat/burcat.html
[2] NIST-Webbook, http://webbook.nist.gov/chemistry
[3] Fundamentals of Thermodynamics, Richard E. Sonntag, Claus Borgnakke, Gordon
J. Van Wylen, 6.Aufl., 2003, John Wiley & Sons.
[4] Pukrushpan, Jay T. Control of Fuel Cell Power Systems: principles, modeling,
analysis and feedback design. (Advances in industrial control). Springer, 2005.
[5] Larminie, James. Dicks, Andrew. Fuel Cell Systems Explained, 2nd Edition, Wiley
2003.