TMATS User Guide Updated
TMATS User Guide Updated
Jeffryes W. Chapman
Vantage Partners, LLC,
Cleveland, OH 44135
Thomas M. Lavelle
NASA Glenn Research Center,
Cleveland, OH 44135
Ryan D. May
Vantage Partners, LLC,
Cleveland, OH 44135
1
Table of Contents
1 Introduction......................................................................................................................................................5
1.1 Identification............................................................................................................................................5
1.2 Notation....................................................................................................................................................6
1.3 System Overview......................................................................................................................................6
1.4 T-MATS quick start guide........................................................................................................................6
1.4.1 Installing T-MATS...........................................................................................................................6
1.4.2 Un-installing T-MATS.....................................................................................................................7
1.4.3 T-MATS examples...........................................................................................................................8
1.4.4 Block Help........................................................................................................................................8
2 T-MATS Library Structure.................................................................................................................................9
3 T-MATS Tools..................................................................................................................................................10
3.1 T-MATS Tools..........................................................................................................................................10
3.1.1 GasTableBuilder.............................................................................................................................10
3.1.2 MapGeneration_Tools....................................................................................................................10
3.1.3 NPSS to TMATS conversion tool...................................................................................................10
3.2 T-MATS Simulink Tools...........................................................................................................................10
3.2.1 GF_Convert....................................................................................................................................10
3.2.2 Block Link Setup............................................................................................................................10
3.2.3 Set IDes..........................................................................................................................................11
4 Callable MATLAB Functions........................................................................................................................11
5 Cantera Integration.........................................................................................................................................12
5.1 Cantera Installation.................................................................................................................................12
5.2 Using T-MATS_Cantera Blocks and scripts...........................................................................................12
5.3 Interfacing with Cantera.........................................................................................................................15
6 T-MATS Simulation creation...........................................................................................................................18
6.1 Simulation Setup....................................................................................................................................18
6.2 T-MATS formatting...............................................................................................................................20
6.2.1 Color Coding..................................................................................................................................20
6.2.2 Simulink Wiring.............................................................................................................................20
6.2.3 Mask format....................................................................................................................................21
2
6.2.4 S-Functions.....................................................................................................................................23
6.3 Units.......................................................................................................................................................23
6.4 Solver Setup...........................................................................................................................................23
6.5 Turbomachinery Plant Setup..................................................................................................................24
6.5.1 Independent and Dependent variables.............................................................................................24
6.5.2 Maps...............................................................................................................................................25
6.5.3 Compressor Variable Geometries (IGVs and VSVs)......................................................................29
6.5.4 Bleeds and Air Bypass....................................................................................................................29
6.5.5 Turbofan modeling options.............................................................................................................31
6.5.6 iDesign............................................................................................................................................32
7 Customization.................................................................................................................................................32
7.1 Library Blocks........................................................................................................................................33
7.1.1 Creating new Simulink Library Browser folders............................................................................33
7.2 S-functions..............................................................................................................................................33
7.3 Tool Creation..........................................................................................................................................34
8 Troubleshooting T-MATS................................................................................................................................35
8.1 Convergence “Errors”.............................................................................................................................35
8.2 Crashing.................................................................................................................................................36
9 Version Compatibility.....................................................................................................................................37
9.1 Version 1.1.2...........................................................................................................................................37
9.2 Version 1.1.3...........................................................................................................................................38
9.3 Version 1.2..............................................................................................................................................38
10 Related Publications...................................................................................................................................39
11 T-MATS Tutorials........................................................................................................................................40
11.1 T-MATS example 1: Newton-Raphson Equation Solver........................................................................40
11.2 T-MATS example 2: Example_GasTurbine_SS.....................................................................................43
11.2.1 Creating the Gas Turbine Plant.......................................................................................................43
11.2.2 Plant Solver integration and plant inputs........................................................................................46
11.3 T-MATS example 3: Example_GasTurbine_Dyn...................................................................................49
11.3.1 General Architecture.......................................................................................................................49
11.3.2 Adding control to the simulation....................................................................................................53
11.3.3 Plant interface with outer loop systems...........................................................................................55
3
11.3.4 Advanced Simulation Structure and Formatting.............................................................................55
12 Acknowledgments......................................................................................................................................57
13 Appendix A.................................................................................................................................................58
Index of Figures
Figure 1. T-MATS/Cantera block hierarchy...........................................................................................................14
Figure 2. Sample simulation architecture for a dynamic system.............................................................................18
Figure 3. Sample T-MATS function block parameters mask..................................................................................20
Figure 4. Sample T-MATS function block parameters mask with vectored inputs and checkboxes......................21
Figure 5. Sample turbojet block diagram................................................................................................................23
Figure 6. Sample compressor map (pressure ratio vs. corrected flow)...................................................................25
Figure 7. Sample compressor map (efficiency vs. corrected flow).........................................................................26
Figure 8. Sample turbine map (corrected flow vs. pressure ratio)..........................................................................27
Figure 9. Sample turbine map (efficiency vs. pressure ratio)..................................................................................27
Figure 10. Sample fan model creation schemes for a gas turbine with bypass.......................................................30
Figure 11: Sample MATLAB internal problem message.......................................................................................35
Figure 11. Model configuration parameters setup..................................................................................................40
Figure 13. Run equation solver...............................................................................................................................41
Figure 14. Gas turbine plant...................................................................................................................................44
Figure 15. Steady-state solver setup.......................................................................................................................46
Figure 16. Iterative NR Solver w JacobianCalc wiring..........................................................................................49
Figure 17. Dynamic gas turbine simple “outer” loop..............................................................................................51
Figure 18. Dynamic gas turbine with controller.....................................................................................................53
Index of Tables
Table 1. T-MATS user’s manual notation................................................................................................................6
Table 2. TMATS thermodynamic functions...........................................................................................................11
Table 3. T-MATS_Cantera flow vector structure for Simulink..............................................................................12
Table 4. Package TMATSC functions and classes.................................................................................................15
Table 5. Class TMATSC.FlowDef methods, Cantera interface functions..............................................................16
Table 6. T-MATS color coding..............................................................................................................................19
Table 7. T-MATS default units and common constants.........................................................................................22
Table 8. Dynamic turbofan model independent and dependent variables...............................................................24
Table 9. Compressor map equations.......................................................................................................................26
Table 10. Compressor map equations.....................................................................................................................28
Table 11. T-MATS library file structure.................................................................................................................31
Table 12. Steady-state turbofan engine example, unused outputs...........................................................................42
Table 13. Example 2 convergence outputs.............................................................................................................47
4
1 Introduction
The Toolbox for the Modeling and Analysis of Thermodynamic Systems (T-MATS) is a Simulink toolbox
intended for use in the modeling and simulation of thermodynamic systems and their controls. The package
contains generic thermodynamic and controls components that may be combined with a variable input iterative
solver and optimization algorithm to create complex systems to meet the needs of a developer.
The goal of the T-MATS software is to provide a toolbox for the development of thermodynamic system models,
which contains a simulation framework, multi-loop solver techniques, and modular thermodynamic simulation
blocks. While much of the capability in T-MATS is in transient thermodynamic simulation, the developer’s main
interests are in aero-thermal applications; as such, one highlight of the T-MATS software package is the
turbomachinery block set. This set of Simulink blocks gives a developer the tools required to create virtually any
steady-state or dynamic turbomachinery simulation, e.g., a gas turbine simulation. In systems where the control or
other related systems are modeled in MATLAB/Simulink, the T-MATS developer has the ability to create the
complete system in a single tool.
T-MATS turbomachinery blocks were created using a philosophy that combines the understandability and logic
of physics-based models with the accuracy and tunability of empirically-developed models. This user’s guide is
written with the assumption that the user is familiar with modeling thermodynamic systems, and a user is
encouraged to see the referenced documentation1,2 for a review of general thermodynamic and modeling principles
before building a simulation.
T-MATS is written in MATLAB®/Simulink® v2015aSP1 (The Mathworks, Inc.), is open source, and is intended
for use by industry, government, and academia. All T-MATS equations were developed from public sources and
all default maps and constants provided in the T-MATS software package are nonproprietary and available to the
public.3 The software is released under the Apache V2.0 license agreement. License terms and conditions can be
found at http://www.apache.org/licenses/LICENSE-2.0.
1.1 Identification
The T-MATS user’s guide applies to version 1.2 of the T-MATS software package, as developed by NASA Glenn
Research Center. The package consists of a T-MATS Simulink library containing the following sub-libraries:
Effectors and Controls, Heat Transfer, Numerical Methods, Solver, Thermo, Thermo_Cantera, Turbomachinery,
Turbomachinery_Cantera, and Volume. In addition, the T-MATS package contains development tools,
“T-MATS tools,” as well as examples to demonstrate how systems may be created using the Simulink libraries.
1
http://www2.chem.umd.edu/thermobook/ :Referenced as of 9/2013
2
Jones, S. M.,”Steady-State Modeling of Gas Turbine Engines using the Numerical Propulsion System Simulation Code,”
GT2010-22350, ASME Turbo Expo, Glasgow, UK, June 14-18, 2010.
3
Jones, S.M.,”An Introduction to Thermodynamic Performance Analysis of Aircraft Gas Turbine Engine Cycles Using the
Numerical Propulsion System Simulation,” NASA/TM-2007-214690, March 2007.
5
1.2 Notation
The notation summarized in Table 1 will be used throughout the T-MATS User’s Guide.
1. Download T-MATS from the GIT server https://github.com/nasa/T-MATS/releases, click the green
download button for the latest version, and extract the files to a folder that can be accessed by MATLAB,
ensuring there are no spaces in the path name. Note that T-MATS was developed in the Microsoft
Windows 7 operating system using MATLAB (baseline v2015aSP1) and Microsoft Software
Development Kit (SDK) 7.1; it is not guaranteed to work on other operating systems, with other
MATLAB versions, or with other compilers. For a full description of compilers compatible with
MATLAB 2015a see http://www.mathworks.com/support/compilers/R2015a/index.html?sec=win64.
2. Navigate to the directory of the desired released version of T-MATS in the downloaded zip file,
TMATS_vXX, in MATLAB.
3. Run Install_TMATS.m; this will set up the paths for T-MATS as well as create the mex files.
If the user does not have elevated privileges, paths may not have been saved properly. If the paths have
not been saved, new paths can manually be added to the pathdef.m file. Open the “Set Path” window by
clicking on the “Set Path” button in the MATLAB toolbar on the HOME tab and add the paths (\
TMATS_Library, \TMATS_Library\MEX, \TMATS_Library\TMATS_Support, and \TMATS_Tools)
to the list. Click “Save” to save the path definitions; a message will pop up warning that administrator
privileges are required and providing the option to instead save the paths to a new pathdef.m file. Save
6
this file to a location on the MATLAB path. Note: this process will save the current path list; before
saving, it should be verified that no unintended paths are on the list. If a temporary install of T-MATS is
desired the temporary install button can be selected on the install popup. Installing with temporary install
will not save the new paths.
4. To add the T-MATS Simulink tools to the Simulink toolbar, create the MATLAB file, startup.m, with the
following lines of code:
load_simulink
Menu_customization_TMATS
The startup.m file may be saved anywhere on the MATLAB path, and these lines function to load
T-MATS editing tools to the Simulink window each time MATLAB is opened. If a startup.m file already
exists, just add the above lines of code.
If, during MATLAB startup, a warning is displayed notifying the user that
Menu_customization_TMATS.m cannot be found, it is probable that the T-MATS paths have not been
added properly in MATLAB. The most common reasons for missing path definitions are that either the
T-MATS paths were not loaded into the pathdef file (see step 3 to solve this issue) or the modified
startup.m file is being used by a version of MATLAB that T-MATS was not installed on. The warning
messages can be removed by either installing T-MATS on the other version or by placing the startup.m
file in a path used only by the desired MATLAB version. It should be noted that, while these warnings
may be annoying, they will have no effect on the performance or functionality of MATLAB if T-MATS
is not used.
5. Optionally, if a user wishes to use the Cantera integrated T-MATS blocks, the MATLAB Cantera toolbox
will need to be installed. Instructions detailing the installation process are detailed in Section 5.1.
At this point the T-MATS library installation is complete. T-MATS modules may be found in the Simulink
Library Browser under the heading “TMATS.” The T-MATS Simulink tools may be found under “Diagram” in
the Simulink model window menu bar.
1. Execute Uninstall_TMATS.m from the same location that Install_TMATS was run. (By default, these files
are both located in the TMATS folder).
a. If paths were added manually to the pathdef.m file during installation, they must be removed
manually by re-saving the pathdef.m file after the Uninstall_TMATS.m file has been run.
2. Remove the following lines from the startup.m file:
load_simulink
Menu_customization_TMATS
7
1.4.3 T-MATS examples
T-MATS includes a number of sample systems set up to help a user gain insight into how to use the T-MATS
library to simulate thermodynamic systems. To gain access to these examples, navigate to the Examples folder
under TMATS_Examples and run TMATS_Run_Example.m. A selection of different examples will be listed in
the MATLAB window (as shown below); the user can then indicate the number corresponding to the example to
open. An alternate way to open an example is to navigate directly to the folder containing the example and run
the *_setup_everything.m file (or by opening the *.slx file, in cases where a setup file does not exist).
>> run('C:\Builds\TMATS\TMATS_Examples\TMATS_Run_Example.m')
Select the enumeration of the T-MATS Example to be setup:
1) NewtonRaphson_Equation_Solver
2) Steady State GasTurbine
3) Dynamic GasTurbine
4) Steady State Dual Spool High Bypass Engine JT9D
5) Dynamic Dual Spool High Bypass Engine JT9D
6) Steady State JT9D, Cantera
7) Cycle Model
8) Linearization Examples
9) Volume Example
10) Cancel Setup
The *_setup_everything.m script will execute every command necessary to set up that particular example, which
may include any of the following: loading variables to the workspace, creating paths, loading busses, and opening
the Simulink model. The paths can be removed by running the corresponding *_Example_cleanup.m file.
8
2 T-MATS Library Structure
The T-MATS Library, as displayed in the Simulink Library Browser, contains four sub-libraries: Effectors and
Controls, Numerical Methods, Solver, Thermo, Thermo_Cantera, Turbomachinery, Turbomachinery_Cantera and
Volume.
1. Effectors and Controls: This sub-library contains the building blocks of the outermost loop of a
simulation. The library blocks are simple representations of effector and control system components.
Depending on the fidelity requirements of the simulation, it may be necessary to develop more complex
models.
2. Heat Transfer: This sub-library contains building blocks to solve the heat flow problem using various
methods, including 0-D lumped mass and 1-D methods using various discretization techniques.
3. Numerical Methods: This sub-library contains the most basic building blocks of the numerical solvers
required to simulate a T-MATS system. These blocks are very generic and can be used to create iterative
solvers for a wide range of systems, even outside of T-MATS.
4. Solver: This sub-library contains blocks that simplify simulation creation, including hybrid blocks,
comprised of blocks from the “Numerical Methods” sub-library, and blocks that are useful for general
simulation development.
5. Thermo: This sub-library contains blocks for general Thermodynamic systems. Many of the blocks
located within this sub-library may be used in other TMATS libraries.
6. Thermo_Cantera: This sub-library contains general use Thermodynamic blocks that require the Cantera
software package to run.
7. Turbomachinery: This sub-library contains the building blocks necessary to create a gas turbine model for
simulation. The blocks are based on basic thermodynamic equations and principles, and use a series of
maps that define the characteristics of the system being modeled. The default maps and constants in
T-MATS are intended only for demonstration.
8. Turbomachinery_Cantera: This sub-library contains turbomachinery blocks that require the Cantera
software package to run.
9. Volume: This sub-library contains building blocks dedicated to solving the 1-D flow problem. And is
based on thermodynamic table lookups, independent of baseline T-MATS, for fluid properties.
T-MATS is intended to be an environment for building thermodynamic simulations in Simulink with the goal of
dynamic analysis and controls design. The sub-libraries discussed above provide the basic building block of a
simulation, however a user may be required to create new blocks, and/or tweak existing blocks, to meet his/her
specific needs.
9
3 T-MATS Tools
T-MATS comes with a set of tools intended to make model creation faster and easier. The tools come in two
types, general tools and Simulink tools. The general tools are intended to add functionality to T-MATS and the
Simulink tools are intended to make T-MATS more user-friendly. All T-MATS tools can be found in the \T-
MATS_Tools folder.
3.1.1 GasTableBuilder
The T-MATS gas table builder utilizes Cantera to create gas properties tables to be used by the baseline T-MATS.
For more information on the Cantera software package see section 5. Information on the tool’s use can be found
in \TMATS\TMATS_Tools\GasTableBuilder.README.html. Using tables generated with this tool can greatly
reduce run time requirements for off operation with nominal gasses.
3.1.2 MapGeneration_Tools
The T-MATS map generation tool offers an example of how an NPSS map may automatically converted to a
format usable in T-MATS. Unfortunately, due to the customizable nature of NPSS naming conventions and
formatting, this tool is not meant to be used directly, but only as an example of how this file may be set up.
3.2.1 GF_Convert
The GF_Convert tool changes the selected Simulink: GoTo block into a Simulink: From block, or vice versa. It
will also convert a Simulink: Outport into a Simulink: Inport and vice versa.
10
3.2.3 Set IDes
Set Ides will look through the current diagram for blocks containing the variable iDesign_M and changes it to the
value specified in the GUI. Note: this only works for the current diagram and if there are sub-models being used
they much be changed separately.
11
of all outputs generated by the ToWorkspace blocks. Note: this tool
will search for all Simulink/ToWorkspace blocks, verify they are
in the form of T-MATS station data (Timeseries with W,h,P,T,FAR)
then use that data to make set plots. It will also search for compressor
and turbine blocks to create map plots and Data busses for placing data
on the maps. Execute command, help TMATS.SSplot, for more
details.
TDplot(filename) Calls the T-MATS transient data viewer. The variable, filename, is the
Simulink diagram name that is generating the desired data. Note: this
tool will search for all Simulink/ToWorkspace blocks, verify they are in
the form of T-MATS station data (Timeseries with W,h,P,T,FAR) then
use that data to make set plots. It will also search for compressor and
turbine blocks to create map plots and Data busses for placing data on
the maps. Execute command, help TMATS.TDplot, for more
details.
It should be noted, Table 2 lists only T-MATS functions that do not make use of the Cantera package. For
T-MATS functions that require the Cantera package, see section 5.
5 Cantera Integration
Some T-MATS blocks have been integrated with the open source Cantera software package. As stated by the
software documentation (http://cantera.github.io/docs/sphinx/html/index.html), “Cantera is a suite of object-
oriented software tools for problems involving chemical kinetics, thermodynamics, and/or transport processes.”
Integration of Cantera brings many new capabilities to T-MATS, including the use of off nominal fuels, alternate
flow path gasses, etc. This is accomplished with the addition of a new MATLAB package that includes a
Simulink sub-library (Turbomachinery_Cantera and Thermo_Cantera), scripts, and classes.
The canteraload.m script defines the Name and Species of the flow streams. Currently there may be up to six flow
types that each contain up to six molecule components. This information is organized into a 6×6 matrices with
rows containing molecule types and columns containing their proportions by weight. Flow compositions are
12
determined from a 6×1 vector where each value relates to one row of the 6×6 matrix. For example, a flow
composition vector of [1 0 0 0 0 0] would relate to Air comprised of: N2; 0.7547, O2; 0.232, and AR; 0.0128 as
seen below (Note, all compositions are proportional by weight). In general the flow composition vector is
generated automatically then used along with the Name and Species matrices to complete and execute Cantera
functions. Because of this, Name and Species form must be consistent with Cantera function notation. Default
definitions for Name and Species is located below and details generic air (row 1), water (row 2), and fuel (row 3).
The remaining 3 rows have not been defined.
In addition to specifying the composition values for the flows, it is also important to create the Cantera phase
object to allow Cantera to communicate with MATLAB appropriately. The phase object is defined by creating
global variable fs in the MATLAB workspace. The variable fs must contain all necessary molecule types that are
used in the load script presented above. Below is an example of the commands that may be used to declare fs.
global fs
fs = importPhase('gri30.cti')
The Cantera function importPhase will import one phase from an input file, in this case gri30.cti. For
T-MATS_Cantera Simulink blocks, flow information is transferred via a 25×1 vector that is defined as shown in
Table 3. This vector contains detailed flow information that may be used for calculations or informational
purposes inside and/or outside of T-MATS blocks. The class containing methods TMATSC.FlowDef and
TMATSC.FlwVec defines names for the flow vector, and may be updated per user requirements. It should be
noted that all communication between Cantera and MATLAB is handled with a MATLAB class, as described in
the next section, and a flow vector is only required because Simulink is incompatible with classes.
13
# Variable Description
1 W gas path flow [pps]
2 s entropy [BTU/(lbm*degR)]
3 Tt total temperature [degR]
4 Pt total pressure [psia]
5 ht enthalpy [BTM/lbm]
6 rhot total density (rho) [lbm/ft^3]
7 gamt total specific heat ratio (gamma)
8 Ts static temperature [degR]
9 Ps static pressure [psia]
10 hs static enthalpy [BTU/lbm]
11 rhos static density (rho) [lbm/ft^3]
12 gams static specific heat ratio (gamma)
13 Vflow flow velocity [ft/sec]
14 MN Mach number
15 A flow area [in^2]
16-21 CompVal_TMATS Flow composition vector, see canteraload.m for
definition of the 6 matter types
22-25 none future use
14
5.3 Interfacing with Cantera
T-MATS blocks that utilize Cantera functions have been built in a hierarchical fashion to allow a user to update
the blocks to a level with which they are familiar. Looking at Figure 1, a simulation may be created in Simulink
using the set of T-MATS_Cantera blocks. These blocks consist of an M-S-function that calls MATLAB scripts
written using the TMATSC MATLAB package. This MATLAB package consists of specialty scripts and a class
called FlowDef that acts as a simplified interface with Cantera. When working with a design any of these levels
may be adjusted to meet task requirements.
Simulation
(Simulink)
T-MATS_Cantera Block
(M-S-function)
Functional script
(MATLAB script)
Cantera Commands
15
The TMATSC MATLAB package contains a class and functions that are used in the creation of the T-MATS
Cantera block set and are summarized in Table 4. Functions located within the package offer file manipulation
and reading scripts useful for manipulating data storage.
The class TMATSC.FlowDef offers the ability to create flow objects that contain all the flow information
required for thermodynamic computations, as well as laying out a simplified interface with Cantera functions, as
shown in Table 5. Interaction with the Simulink environment is accomplished with the generation of a flow
vector, described in Table 3 above, based a flow object. TMATSC functions and class methods can be imported
into a script by implementing the command “import TMATSC.*” or by placing TMATSC. or
TMATSC.FlowDef. , respectively, before the command. This information may also be accessed by typing “help
TMATSC” in the MATLAB command window.
16
Table 5. Class TMATSC.FlowDef methods, Cantera interface functions.
Class Method description
Flow object construction:
flow_new = FlowDef() 0 input Creates empty TMATSC flow object
flow_new = FlowDef(FlowVector) 1 input. Flow constructor based on flow vector.
flow_new = FlowDef(flow, compNN, W, 4 inputs. Create populated flow object with total values only
Tt, Pt) (Total only, based on set_TP)
flow_new = FlowDef(flow, compNN, W, 5 inputs. Create populated flow object (Total and Static,
Ts, Ps, MN) based on set_TsPsMN)
flow_new = CanSet(flow) Set flow object composition values to Cantera format
(CompVal_Can based on CompVal_TMATS flow object
value)
flow_new = CanSet(flow, compNN) Set flow object composition values to Cantera format
(CompVal_Can based on input compNN, 6×1 vector)
Cantera interface functions:
flow_new = flowadd(flow1, flow2) Add flow1 and flow2 together, conserving enthalpy and mass
flow_new = flowcopy(flow) Copy information from one flow to another flow
mass_frac = getMassFraction(flow, c) Return mass fraction of compound c in the object flow
flow_new = set_hP(flow, ht, Pt) Set total conditions based on flow, total enthalpy and total
pressure
flow_new = set_MN1(flow) Set the static conditions to sonic flow based on flow
conditions
flow_new = set_Ps(flow, Ps) Set the static conditions based on flow and static pressure
flow_new = set_SP(flow, S, Pt) Set the total conditions based on flow and input entropy and
total pressure
flow_new = set_TP(flow, Tt, Pt) Set the total conditions based on flow, total temperature, and
total pressure
flow_new = set_TsPsMN(flow, Ts, Ps, MN) Set the conditions based on flow, static temperature, static
pressure, and Mach number
Flow object manual set functions:
flow_new = TotalSet(flow, s, Tt, Pt, ht, Manually sets total variables in flow object
rhot, gamt)
flow_new = StaticSet(flow, Ts, Ps,hs, rhos, Manually sets static variables in flow object
gams)
flow_new = SpeedSet(flow, MN, A, Vflow) Manually sets speed variables in flow object
flow_new = SClr(flow) Clears all static variables in a flow object
flow_vector = FlwVec(flow) Creates 25×1 flow vector
To create an empty flow object, the following code can be executed in the MATLAB command prompt:
NewFlowObject = TMATSC.FlowDef();
Alternatively, a Cantera flow vector, as described in Table 3 , can be used to generate a defined flow object as
shown below:
17
NewFlowObject = TMATSC.FlowDef(Flow_Vector);
The flow vector may be regenerated from the flow object using the FlwVec command:
FlowVector = FlwVec(FlowObjectName);
A good rule of thumb when choosing to use T-MATS_Cantera flow vectors or flow objects, is that a flow object
created from the flow class should be used when working with the MATLAB scripting language, and the flow
vector should be used only when transferring data out of Simulink blocks. It should be noted that when filling in a
flow object manually, the TMATSC.CanSet method must be run after the CompVal_TMATS vector property has
been set to automatically generate the CompVal_Can property, which is required by Cantera commands.
The T-MATS software package contains blocks that allow for easy creation of a thermodynamic model that
requires “outer loop” iteration (over time) and “inner loop” iteration. The iterative solver blocks in the “Solver”
sub-library apply a Newton-Raphson method to iteratively solve for plant independent variables by monitoring
plant dependent variables. For the example in the previous paragraph, the dependent variable is flow error and the
independent variable is R-line. As with all Newton-Raphson techniques, a Jacobian for the plant is calculated by
the solver; this Jacobian is essentially a linear map from the plant independent variables to the dependent
variables, which may change based on the system operating point and the degree of system nonlinearity. In cases
where the Newton-Raphson solver fails to converge in a timely manner due to a non-linearity, the T-MATS solver
blocks will add robustness by recalculating the Jacobian matrix.
An easy way to learn how to use the T-MATS “Solver” sub-library is to look at the examples. There are three
examples included in the T-MATS software package that demonstrate progressively more complicated solver
implementations; for more information on the examples and setup, see the tutorial (Section Error: Reference
source not found). In the first and simplest example, NewtonRaphson_Equation_Solver, the TMATS: SS NR
Solver w JacobianCalc block is used to solve a system of three equations for three unknowns. It should be noted
that the independent variables (x) and the dependent variables (f(x)) are both expressed in the form of a 3x1
vector. The input to the iterative solver block can be of any length, as long as the inputs, outputs, and appropriate
mask input variables are all the same length.
The second example (GasTurbine_SS_Template) sets up a gas turbine with a steady-state solver using the
T-MATS block set. In this example, the TMATS: SS NR Solver w JacobianCalc block is used as the system
solver. The four inputs, or dependent variables (on the right hand side of the solver block), are the normalized
flow errors from the nozzle, turbine, and compressor, as well as shaft acceleration. The independent variables are
18
flow into the engine, R-line (compressor), PR-map (turbine), and mechanical shaft speed. Components in the
“Turbomachinery” sub-library have been color-coded for convenience (more details on the color scheme are in
Section 6.2.1).
The third example (GasTurbine_Dyn_Template) simulates a dynamic gas turbine system. This system requires
setting up a hierarchy with the TMATS: Iterative NR Solver w JacobianCalc block, as shown in Figure 2. The
solver block and the plant (shown here as the IterativeSolver and InnerLoopPlant blocks) must be placed in a
Simulink: While Iterator subsystem block. During operation, this setup will iteratively solve for convergence at
each time step, “pausing” time to converge the system (if convergence has been lost), then begin evolving through
time. To allow for dynamics, the Newton-Raphon solver does not solve for mechanical shaft speed as in the
steady-state solver example; instead Ndot is integrated outside of the solver loop to calculate the shaft speed. In
addition to the while-loop hierarchy, the dynamic gas turbine example also outlines how busses and model calls
may be incorporated in the simulation structure. Most of this added structural complexity is not required and has
been included for demonstrative purposes only. What is required is that the plant and the TMATS: Iterative NR
Solver w JacobianCalc block are in one subsystem, with a Simulink: While Iteration block, and that all outside
effectors are outside of that subsystem, as shown in Figure 2.
For more information on the example and setup, see the tutorial (SectionError: Reference source not found).
19
6.2 T-MATS formatting
6.2.1 Color Coding
The inputs and outputs of T-MATS blocks are color coded to aid in simulation setup:
Color Description
Blue Gas path information containing flow, enthalpy, total temperature,
total pressure, and flow composition (typically fuel to air ratio
(FAR))
Dark Green Independent variable
Green Dependent variable
Red Independent variable that is obtained through integration in a
dynamic simulation, but may be solved for by the solver in a
steady-state simulation (e.g. shaft speed)
Magenta Dependent variable that is integrated in a dynamic simulation, but
may be used as a dependent variable in the iterative solver in the
steady-state simulation (e.g. Ndot)
Pink Contributor to calculation of a dependent variable (e.g. torque)
Yellow Effector command (example fuel flow), not typically used by the
solver
Typically, items of one color connect to items of the same color (red and magenta items may be exceptions, as
noted in Table 6).
20
6.2.3 Mask format
T-MATS makes extensive use of the subsystem mask tools in Simulink. Each T-MATS block comes with a mask
that has been created to allow the user to provide to the block any required parameter or setting without having to
enter the block itself. The mask parameters for each T-MATS block may be viewed by double-clicking on that
block; an example of a T-MATS block mask can be seen in Figure 3.
21
Many T-MATS blocks accept vector inputs, the length of which may determine the number of block inputs,
dependent variables, independent variables, or block outputs. If an input description contains the symbol
(“(size)x1”), then that input needs to be a vector of length “size” as dictated by the design. In a specific module,
the value of “size” needs to be the same for each item. For example, in the compressor block the dimensions of
the input for customer bleed are cbx1 and for fractional bleed are bx1, so the length of the customer bleed vectors
should all be the same (cb) and the length of fractional bleed vectors should be the same (b); it is not required that
cb = b, as demonstrated in Figure 4 where cb = 3 and b = 2.
Figure 4. Sample T-MATS function block parameters mask with vectored inputs and checkboxes.
Maps and tables in T-MATS are entered as mask variables, with two inputs required for 1-D tables (axis and
value breakpoints) and three inputs required for 2-D tables (breakpoints for two axes and for values). The axis
breakpoint arrays will be indicated by the prefix “X_” or “Y_” while prefix “T_” indicates the array of table
values. Scalars, which change the scale of maps and tables, are prefixed with “s_.” The input descriptions of all
tables include a simple equation, surrounded by “(),” that denotes which axis variables are used for that particular
table (e.g., in the compressor, “Wc = f (Nc,R-line)” denotes that an element of table Wc can be expressed as a
function of axis variables Nc and R-line, which are defined right above it). Errors will be encountered if single
element array (1x1) is entered for tables; instead a line or plane of the same number, for 1-D or 2-D tables
respectively, should be entered to create a table with the same value. For example, a 2-D table with x-axis = [0 1],
y-axis = [0 1], and table values = [5 5; 5 5], creates a plane of value 5.
22
6.2.4 S-Functions
Many T-MATS function blocks make use of S-functions, which allow code to be developed in the C
programming language and then be used by Simulink. (See Section 7.2 for more details about S-functions
operation and Appendix A for a simple code example.) It is important to have a basic understanding of
S-functions so the code may be tuned for each user’s need. The C code is compiled for use in Simulink via the
MATLAB mex command.
6.3 Units
Unless otherwise specified all T-MATS blocks and functions make use of English units. The common unit
definitions and constants are detailed in Table 7.
f ( x ( n ))
x ( n+1 )=x ( n )− (1)
J
The Jacobian matrix (J) is a linear map between plant inputs and outputs. It is defined by perturbing each plant
input from an initial condition (x) to find the effect on the plant outputs (f). A more precise mathematical
description of the Jacobian matrix can be seen in Eq. (2).
23
[ ]
∂f1 ∂f1
⋯
∂ x1 ∂ xn
J=¿ ⋮ ⋱ ⋮
(2)
∂fm ∂fm
⋯
∂ x1 ∂ xn
T-MATS solver blocks work in two major steps. In the first step, the Jacobian calculator calculates a linear map
of the plant. Starting at the initial condition, the Jacobian calculator takes turns perturbing each input slightly,
recording the results, and calculating the slope of each output as a function of each input. Once this is completed
for each input, the Jacobian is built, inverted, and sent to the Newton-Raphson block. In the second step, the
Newton-Raphson solver steps toward a solution using the Jacobian developed in the first step. This solver method
makes the assumption that the plant is locally linear, so it is possible that the solver will not converge on a
solution when the system is (highly) nonlinear. The help files for the blocks inside the solver (TMATS: Newton
Raphson Solver and TMATS: Jacobian Calculator) include more information about the solver and how it works.
24
the simulation, the number of independent variables must match the number of dependent variables. Variable
definitions for the dynamic gas turbine example (a simple turbojet) can be seen in Table 8.
(Note: See the color coding section, 6.2.1, for an easy way to find typical independent and dependent variables)
It should be noted that, although certain inputs may be known in some simulations, setting the known independent
variables to constants, and removing dependent variables from the solver, should not be done because minor
changes in the vector of independent variables may drive convergence to a map point that does not exist, which
will result in the simulation crashing. It is more prudent to simply use the known value(s) in the initial conditions
of the independent variables and allow the solver to use the dependent variables to solve for it. If the initial
conditions are indeed the steady-state solutions, the final value of the independent variables will remain close to,
or the same as, the initial values. If precise input/output interdependencies are required, they can be generated
using the TMATS: Jacobian Calculator block in the “Numerical Methods” sub-library.
6.5.2 Maps
The TMATS: Compressor block uses maps to compute efficiency, pressure ratio, and corrected flow for the
compressor, each as a function of corrected compressor speed (Nc) and R-line (typically solved for by the
iterative solver) as shown in Figure 6 and Figure 7. Because of the complication of creating a large
multidimensional table in MATLAB, the compressor maps in Figure 6 and Figure 7 have been broken down into
three different tables for T-MATS, which solve for corrected flow (Wc), pressure ratio (PR), and efficiency (Eff)
separately. In addition, scalars have been provided to modify the inputs and outputs of this interpolation to modify
performance map characteristics. The scaling of the compressor module’s maps is summarized below in Table 9.
It should be noted that, for each turbomachinery component in T-MATS, speed and flow are corrected as in Eq.
(3), where Nmech is mechanical shaft speed, Tin is total temperature at the block input, Tstd is standard day
temperature (518.67degR), Pin is total pressure at the block input, Pstd is standard day pressure (14.7psia), and
Win is flow at the block input.
Nmech
Correct Speed ( Nc )=
√ Tin
Tstd
( )
(3)
25
Figure 6. Sample compressor map (pressure ratio vs. corrected flow).
26
Figure 7. Sample compressor map (efficiency vs. corrected flow).
The TMATS: Turbine block uses maps to compute the efficiency and corrected flow for the turbine. These two
variables are taken as functions of corrected turbine speed (Nc) and PR-map value (typically solved for by the
iterative solver), as shown in Figure 8, and T-MATS uses two tables to represent the turbine map: one solves for
efficiency (Eff) and the other for corrected flow (Wc). As with the compressor map definition, scalars are provided
to allow for modification of performance map characteristics. Scaling of the turbine block’s maps has been
summarized in Table 10.
27
Figure 8. Sample turbine map (corrected flow vs. pressure ratio).
28
Table 10. Compressor map equations.
T-MATS has been designed to be as flexible as possible; however compressor and turbine maps can be defined in
various ways. In cases where the maps are not compatible and cannot be adjusted for use with the T-MATS block
sets, new modules must be created to be compatible with the map version that is desired.
One case where a map can be converted for use in a T-MATS module is when a compressor EM-line is used. An
EM-line is an R-line that has been forced to take the form of a linear equation. The compressor module for
T-MATS is designed to use tables for the map, not equations, but a translation from one map style to the other is
possible by creating an R-line from the EM-line through calculation of various R-line points using the EM-line
equation. Take, for example, the case where corrected flow (Wc) is a table lookup based on compressor speed
(Nc) and EM-line, and the compressor pressure ratio and efficiency are defined as in Eq. (4).
To convert this map to an R-line based map, pairs of Nc and EM-line values may be chosen for calculation of PR
and Eff tables based solely on Nc and EM-line (EM-line values can essentially be used in place of R-line values).
The table for Wc is already in an acceptable form, so translation is not required. In this example, all T-MATS
scalars would be equal to 1 as they do not appear in the compressor map definition.
29
a system outside of the engine (e.g., to cool the cabin, run power generators, etc.) and fractional bleed is used as
cooling flow in turbine components. Bleed flow outputs are vectors of flow path variables (color-coded blue as
described in Table 6) combined in series and contain all information required for general processing. As currently
written, twenty bleed flows of each bleed type may be requested in a block. Each bleed flow may be “pulled off”
the bleed vector output and routed into the intended/appropriate input, such as cooling flow for a turbine.
Main air bypasses in the model may be created using the TMATS: Splitter block, which typically work in
conjunction with a nozzle block. See Section 6.5.5 for more details about how to use a splitter to create a high
bypass engine model.
30
6.5.5 Turbofan modeling options
Modeling a turbofan engine may require the creation of a fan module and the adoption of a system architecture
that partitions flow into a main flow path and a bypass flow path. This architecture can be set up in several ways,
each of which makes use of compressor, splitter, and nozzle T-MATS modules. In T-MATS, a fan may be
modeled as a one-stage compressor, or the two flow paths in a high bypass engine (commonly called the tip and
hub flows) may instead be modeled using one of the three flow-splitting modeling architectures in Figure 10:
Option 1. Split the main flow path before the fan, modeling the tip and hub flows separately with two
compressor blocks.
Option 2. Dedicate separate input flows to the tip and hub, modeling each with separate compressor blocks.
Option 3. Split the main flow path after the fan, modeling the entire fan with one compressor block (tip and
hub flows are combined).
The architecture chosen for a model will mainly be determined by the available maps, and the options in Figure
10 are by no means the only options for modeling tip and hub flow. It should be mentioned that the inclusion of a
bypass flow creates additional independent and dependent variables that must be added to the solver. The
additional independent variables are the input flows, R-lines, and/or splitter bypass ratios for the added
components, while the additional dependent variables are the flow errors associated with these same components.
Figure 10. Sample fan model creation schemes for a gas turbine with bypass.
31
6.5.6 iDesign
Certain T-MATS turbomachinery blocks have the capability of calculating engine map scale factors and internal
variables, based on design or steady-state input parameters, through the process called iDesign. This process may
be turned on through the mask variable iDes_M located under the iDesign tab of appropriate blocks. The iDes_M
value may be set to 0, 1, or 2.
A value of 0 turns iDesign on and will allow the simulation to save key variables (i.e., scale factors and
other key internal variables, such as nozzle throat area, etc.).
A value of 1 turns iDesign off and specifies that the simulation shall use the key variables created when
the system was run with iDesign turned on.
A value of 2 turns iDesign off, but sets the key variables to values specified in the block mask.
Blocks that utilize iDesign (compressor, turbine modules, etc.) require certain design or steady-state variables to
be known and entered into their masks in order for iDesign to work; the help menu for each of these blocks should
be consulted to determine what is required. Once this information has been defined, the simulation can be run.
Typically, an iDesign run involves simulation of a steady-state model to allow the solver to converge to its design
point (or a suitable steady-state value). Once complete, the scale factor for iDesign enabled blocks may be found
in the *_Data output bus, in a specified file, or in the workspace. Be aware that running T-MATS dynamically
with iDesign enabled (0) will produce unpredictable results that should not be used. Also note that, in cases where
the maps have not been scaled, the values calculated by iDesign should be within 1% of 1. Otherwise, in cases
where the maps have been scaled (as in Example_Gas_Turbine_SS) the values calculated by iDesign may vary
widely from 1 with a final value dictated by the requirements of the final map. It is useful to also note that, in
general, if iDesign is used it should be enabled (0) for every block within the model that has the capability.
Enabling only some blocks may result in solver convergence issues.
7 Customization
Although T-MATS blocks are designed to be as general as possible, a user may need to customize an existing
function within T-MATS, or create an entirely new function, to meet the needs of a specific application. This
section will go over how to add new blocks to the library and how to change existing blocks to meet simulation
needs.
The library file structure, in Table 11, reflects how T-MATS blocks are displayed in the Library Browser.
32
7.1 Library Blocks
The T-MATS library is essentially a grouping of useful Simulink blocks that can be connected together to create
complex thermodynamic systems. By adding new library blocks, it is possible to expand and customize the
simulation environment to meet the needs of the simulation. A new block can be added to a T-MATS library by
performing the following steps:
7.2 S-functions
In T-MATS, many blocks utilize Simulink S-functions. S-functions allow for the integration of Simulink with
code written in another programing language (in this case, C or C++), imparting a number of advantages over
using traditional Simulink blocks. One advantage is speed: while many Simulink blocks and MATLAB functions
can run quite fast, compiled C code typically runs much faster. A second advantage is that using S-functions
allows for the use of legacy code, which may not be written in Simulink/MATLAB, in simulation development.
(Legacy code, however, does require some modification to match the special formatting requirements of
S-functions.) It should be noted that in order to use C code in a simulation, a MATLAB-compatible compiler
must be installed and the code must be compiled (using the MATLAB mex function) to produce a MEX file.
S-functions calls are created in Simulink by placing in the model the S-function block located within the
Simulink -> “User-Defined Functions” sub-library in the Simulink Library Browser. By default, S-function code
33
in T-MATS has been written in C. Starting with an example S-function as a template (such as the marked up
function in Appendix A). For the purposes of compilation two types of S-function interface files are used, MEX
file generation file for MATLAB/Simulink operation and TLC file generation for target hardware, executable, or
rapid accelerator mode. Generally, if block operation must be updated the C-code body file may be changed to
reflect the update. However, If the S-function I/O needs to be changed then the mex generation portion and the
TLC files will both need to be updated.
For more information on S-function block setup, creation of MEX files, or functions prefixed with an mdl or ss,
see the MATLAB help functions. Additional T-MATS code that may be used as examples can be found in the
TMATS\TMATS_Library\MEX\C_code folder.
34
8 Troubleshooting T-MATS
8.1 Convergence “Errors”
When running T-MATS modules in a loop with solver blocks, the simulation will first act to converge the plant.
In a simulation with new compressor and turbine maps, it is common for discrepancies in parameters to be
present. These discrepancies are the equivalent of placing the wrong hardware on the gas turbine (e.g. a gas
turbine with a compressor that is too small) and will cause problems with plant convergence. Failures in
convergence often result in Simulink notification of errors in blocks that seemingly have nothing to do with the
solver, such as integrators or state-space blocks, which makes troubleshooting the error more difficult. This is
why, if an error occurs when running a model, the value of dependent variables (f(x)) routed to the solver should
be checked first. If any of the values are inf, NaN, or outside the specified iteration condition limits for the solver,
the simulation is not converging. It should be noted that in some cases T-MATS blocks will issue errors. The
reason for these errors will be justified in the error message and they will not be reviewed in this document.
Troubleshooting a convergence issue can be very difficult. Outlined here are a few ways to troubleshoot a suspect
simulation:
1. Double-check block inputs: Check for errors in the maps and constants used in the simulation.
2. Check solver inputs: Improper independent variable initial conditions, perturbation size, etc. may cause
the solver to get stuck in a local minimum that does not result in system convergence.
3. Check independent/dependent variable matching: Verify that all system independent variables and
dependent variables are accounted for in the simulation/solver.
4. Component testing: If data is available (from another example of the system) at the input and output of
each component (station), the simulation can be broken down to the component-level, feeding the inputs
observed from the other model to the inputs of each block. This can help isolate a specific block that is
not modeled correctly.
5. Steady-state testing: If the system is intended to be run dynamically, try running it in steady-state first to
identify if a problem with the solver parameters is contributing to the convergence problem.
6. Run without solver: Take out all the solvers and run the simulation with constant input to each
independent variable; if there is another example of the system that the model can be compared against,
doing so can help find errors.
7. Analyze the Jacobian: It may be useful to look at the Jacobian (J), which shows the relationship between
independent variables and dependent variables in the system, as the solver tries to converge to a solution.
This value is located within S_Data bus output from the solver blocks and can be displayed using the
Simlunk: Display sink block. Given an understanding of which independent variables should affect
which dependent variables, the values of the Jacobian may be used to determine a possible source of error
in the model.
8. Update the solver: If the solver is using a single Jacobian perturbation it may be necessary to up the
inputs to use a multi-step approach. This can be done by updating the perturbations in the Jacobian
calculator or solver mask.
9. iDesign: The iDesign feature, which can be turned on for each block, forces the simulation to converge;
this feature may be used to help determine how “close” to convergence the simulation is, with the caveat
35
that unrealistic scalars may be produced (e.g. efficiency of a component might be greater than 1). See
Section 6.5.6 for more information on iDesign.
8.2 Crashing
There may be times when a T-MATS simulation will crash and issue a system error, causing MATLAB to close
ungracefully (Figure 11). These internal errors typically arise due to errors in the execution of the compiled C
code (generally when the C code attempts to access memory locations that it doesn’t have access to). This can
occur when:
Attempting to access elements of arrays outside of the memory range (e.g., element 21 of a 15 element
array).
Using pointers incorrectly.
Passing arrays to other functions by reference.
One such error has been observed when a length-1 vector or array is provided for a mask parameter used for table
lookup. If the simulation crashes, one of the first steps should be to check that the mask parameters for each
T-MATS module have proper length. It should be noted this is just one possible reason for the crash.
36
9 Version Compatibility
This section describes version updates that may not be compatible with older versions of T-MATS. Each section
contains a change name, a description of the change, and an action that may fix the problem. It should be noted
this list is intended for functionality choice changes, and bug fixes that may change block or command operation
may not be listed. When updating versions it is always wise to make a copy of your work before updating so that
it may be referenced when troubleshooting new block behavior. All blocks are tested extensively before
release, however it is always possible errors may occur. If an error is found please post it on
https://github.com/nasa/T-MATS/issues and someone from the development team will address it ASAP. For
general questions on version compatibility can be posted on the user’s forum:
https://groups.google.com/forum/#!forum/t-mats-user-group .
37
See Commit: values will not be correct.
16def881d97c817ad9835857eb3cc41b1510cc8
6
Jacobian The Jacobian Calculator was updated to In older versions, it didn’t matter if the
calculator have the ability to do multiple perturbations. Perturbation sizes in the mask of the Jacobian
perturbations In doing this the perturbations input must calculator or one of the solvers was defined
now be defined as an array. This was done as a row or a column vector.
to add robustness to the Jacobian calculator. In the new version perturbations must be
See Commit: defined as sets of row vectors. For example if
2ef69fc23a1cf6be459e259818db61a8dc5859f there are 3 inputs and you want to do 2
1 perturbations for each (1 and -1) the matrix
would look like: [1 1 1; -1 -1 -1]. If it is
defined improperly there will be a matrix
sizing error.
iDesign variable The iDesign function will now crate and use Old *.mat files that contain iDesign scalars
creation binary files for operation (instead of .mat are no longer usable. It is recommend that the
files). This was done to facilitate code scalars be recalculated using the new scheme.
generation. It should be noted that the old file name will
See Commit: be carried over to the new block. The name
394144b917dff4cb7920d35a9d2d62732c27754 specified will most likely not be usable. It is
2 recommended the default value for the file
name be used instead.
Gear box flip The sides of the gear box have been Verify values coming from the gear box are
reversed. This was done to make the inputs what is intended. It may be required to take
more intuitive. the reciprocal of the gear ratio and change the
See Commit: efficiency to reflect the new block.
e292e61f68ab2009ced76377d577d2814281cf8
d
38
10 Related Publications
The following publications may be used for additional reference.
1. Chapman, J.W., Lavelle, T.M., May, R.D., Litt, J.S., Guo, T-H., “Propulsion System Simulation Using the Toolbox
for the Modeling and Analysis of Thermodynamic Systems (T-MATS),” 2014 AIAA Joint Propulsion Conference,
Cleveland, OH, Jul 28-30, 2014.
2. Chapman, J.W., Lavelle, T.M., Litt, J.S., Guo, T-H., “A Process for the Creation of T-MATS Propulsion System
Models from NPSS Data),” 2014 AIAA Joint Propulsion Conference, Cleveland, OH, Jul 28-30, 2014.
3. Lavelle, T.M., Chapman, J.W., May, R.D., Litt, J.S., and Guo, T.H., “Cantera Integration with the Toolbox for the
Modeling and Analysis of Thermodynamic Systems (T-MATS),” 2014 AIAA Joint Propulsion Conference,
Cleveland, OH, Jul 28-30, 2014.
4. Zinnecker, A.M., Chapman, J.W., Lavelle, T.M., and Litt, J.S., “Development of a twin-spool turbofan engine
simulation using the Toolbox for the Modeling and Analysis of Thermodynamic Systems (T-MATS),” 2014 AIAA
Joint Propulsion Conference, Cleveland, OH, Jul 28-30, 2014.
5. Chapman, J.W., Kratz, J., Guo, T-H., Litt, J.S., “Integrated Turbine Tip Clearance and Gas Turbine Engine
Simulation,” AIAA 2016-5047, 2016 AIAA Joint Propulsion Conference, Salt Lake City, UT, 2016.
6. Chapman, J.W., Lavelle, T.M., Litt, J.S., “Practical Techniques for Modeling Gas Turbine Engine Performance,”
AIAA 2016-4527, 2016 AIAA Joint Propulsion Conference, Salt Lake City, UT, 2016.
7. Chapman, J.W., Litt, J.S., “Control Design for an Advanced Geared Turbofan Engine,” AIAA 2017-4820, 2017
AIAA Joint Propulsion Conference, Atlanta, GA, 2017.
39
11 T-MATS Tutorials
The T-MATS software package is a Simulink library that can be used to model any thermodynamic system. In
order to help the user better understand how the various blocks in the library can be assembled, the software
package contains three examples. This tutorial will describe their development and highlight important points
that the user should keep in mind when developing simulations. As a user works through the tutorial, it may be
useful to have the corresponding example from the T-MATS library loaded for comparison.
1) Create plant
In this example, the plant is fully defined, is dependent only on a set of inputs, has 3 independent
variables and 3 dependent variables, and is in the form of polynomials (created with Simulink: Fcn
blocks). For quick reference, the three functions used in the T-MATS example have been reproduced in
Eq. (5).
40
6) Run the simulation
At this point the system can be run. Click the green play button at the top of the Simulink model. If the
simulation solver options have been properly set up, the simulation will run successfully
41
Figure 13. Run equation solver.
42
11.2 T-MATS example 2: Example_GasTurbine_SS
This section will describe how to combine T-MATS blocks to create the simple steady-state gas turbine example
included with T-MATS (GasTurbine_SS_Template.slx). Note that the example model makes use of the Block
Link Setup tool to produce a clean-looking model by replacing lines with Simulink: GoTo and Simulink: From
blocks.
Burner B_Data
Turbine T_Data
Nozzle WOut
Fg
N_Data
Note that using the Block Link Setup tool on each block will automatically place the Simulink:
Terminator blocks at these outputs.
43
6) Set up the input flow
The TMATS: Ambient block converts environmental characteristics to gas turbine thermodynamic
characteristics; place this block in the model and connect the GasPthChar output to the GasPthChar input
of the TMATS: Compressor block. The ambient pressure (Pamb) output of the TMATS: Ambient block
needs to be routed to the Pamb input of the TMATS: Nozzle while the A_Data output is unused and can
be routed to a Simulink: Terminator block.
Set inputs for the environmental conditions (TMATS: Ambient block) and fuel flow (TMATS: Burner
block) to constants, since the simulation will solve for steady-state.
7) Define the mask parameters
Constants and maps for each component should be updated per the user’s particular application. See the
example model for values usable for this particular case. (Note that the actual values for each parameter
are in the setup file, which creates the variables specified for the mask parameters in the Simulink model
file.) The completed gas turbine plant model should resemble Figure 14, where Simulink: Display
blocks have been added at the output of each component.
44
Nozzle
Duct
Turbine
Burner
Compressor
Shaft
Ambient
45
11.2.2 Plant Solver integration and plant inputs
1) Create the solver
Place the TMATS: SS NR Solver w Jacobian Calc block in the model. Multiplex all dependent variables
(component outputs color coded in green) and Ndot (from the shaft) and route the signal to the f(x) input
of the solver block. De-multiplex the output of the solver block, X, and route each independent variable
to one of the dark green inputs of the component blocks; one of the independent variables should be
routed to the NMech input of the shaft block. In this example there are four independent variables and
four dependent variables, as shown in Figure 15, where display blocks have been added to the solver
input and output to aid in determining if the solver has converged to a solution.
2) Set up the solver parameters
Once the signals have been connected, the solver mask parameters should be defined; these parameters
include the initial conditions, the termination conditions, and other values that affect the accuracy of the
solver. See the example for the values used for this model.
46
Figure 15. Steady-state solver setup.
47
3) Configure the solver
Open the simulation configuration window (Simulation -> Model Configuration Parameters on the
Simulink menu bar) and select a fixed-step discrete solver, specifying the start and stop times as well as
the fixed step size. (See the tutorial in Section 11.1 for more information on setting up the solver for
simulation.)
4) Running the simulation
Once the engine model has been created and connected to the solver, the simulation can be run by
pressing the run button located in the menu bar. After completing the run, the display blocks should be
checked for convergence. It can be seen in Table 13 that the independent and dependent variables in
example 2 are being driven to convergence (that is, the flow errors approach zero).
Because the steady-state gas turbine example requires definition of a large number of block parameters, the
example was developed to utilize a setup script (the filename has the suffix “_setup_everything”). When run, this
script creates a path to the SimSetup folder and runs all the files in that folder, which create the variable MWS in
the workspace. This variable is a MATLAB data structure that contains many of the variables used in the
example, which can be accessed with the syntax: MWS.Component.Variable (for example, MWS.HPC.s_Wc can
be used to access the scalar for the Wc map in the HPC). When the simulation is run, Simulink will look for MWS
in the MATLAB workspace and load the required variables. The example has been configured to automatically
remove the temporary paths (created by the setup script) by running a cleanup script when the model file is
closed.
48
11.3 T-MATS example 3: Example_GasTurbine_Dyn
Although it has the capability to solve for a steady-state condition, T-MATS is designed to ultimately be used in a
dynamic simulation environment. This section will describe how to create a dynamic gas turbine simulation using
T-MATS blocks and will also provide demonstration of various MATLAB practices the user may wish to utilize
when developing a new simulation. This example is included in the examples section of T-MATS
(GasTurbine_Dyn_Template.slx).
Before attempting to recreate the dynamic gas turbine simulation example, the user should read through the
previous two examples, as certain topics covered in them will be skipped here. In particular, the description of
how to structure the model assumes that the engine plant model has already been constructed, following the
instructions presented in Section 11.2 for the steady-state gas turbine simulation.
49
Figure 16. Iterative NR Solver w JacobianCalc wiring.
50
5) Setup the outer loop
Outside of the while iterator subsystem, route Ndot to the input of the TMATS: OuterLoop integrator
block from the “Solver” sub-library (a bus selector may be used) and route the output of the integrator
block to the NMech input of the plant (in the inner loop).
To speed up the ability to modify the model when running multiple simulations, the environmental inputs
(to the TMATS: Ambient block) and the fuel flow input (to the TMATS: Burner block), may similarly be
routed from the outer loop to the inner loop. Bus creators may be used to combine these signals with
NMech, as shown in Figure 17, to produce a cleaner-looking model.
51
Figure 17. Dynamic gas turbine simple “outer” loop.
52
11.3.2 Adding control to the simulation
This section will describe how to add a simple feedback controller to the T-MATS simulation that uses shaft
speed as the feedback signal.
53
Figure 18. Dynamic gas turbine with controller.
54
11.3.3 Plant interface with outer loop systems
In a real system, engine effectors and internal states need to be accessed with control system hardware. The
T-MATS package comes with generic controller interface blocks, such as the first-order sensor and actuator
blocks in the “Effectors and Controls” sub-library, which may be used to simulate the dynamics introduced with
added hardware. These blocks may be added to the “outer” loop of the model to increase simulation fidelity.
11.3.4.1 Busses
Busses are a useful way to route signals through a Simulink model while keeping the diagram clean.
Creating Busses:
1) Place a Simulink: Bus Creator block in the model. Any signal fed into that bus creator will be on the bus
and associated with the name of the wire fed into the bus creator. (Note that this is the only step required
if a bus stays within a single model.)
2) The Bus Editor (found in the Edit menu) may be used to create bus elements. A bus that has been created
in the Simulink diagram should also be created in the Bus Editor, being careful to organize the elements
in the same order as they appear in the Simulink diagram.
3) After creating the bus, in the Bus Editor, select “Export to File” in the File menu of the editor. This saves
the bus to a file that must be loaded before opening the Simulink model. (For example, the
setup_everything.m script for the GasTurbine_Dyn_Template example loads all the necessary bus
elements from the folder Bus)
4) To add any element to the bus later, these steps must be repeated (i.e., open the bus editor, add the new
item, then save the item to a file.)
Using Busses:
1) Bus elements may be routed off the bus through the use of the Simulink: Bus Selector block. Simply wire
the bus into the selector, and then use the dialog box to select which bus element(s) to output.
Setting up a model call requires placing a Simulink: Model block, from the “Ports and Subsystems” sub-library, in
the model. Once the block has been placed, the file name of the model to be called should be specified in the
dialog box opened by double-clicking the block. In the gas turbine example with the dynamics solver, calls were
made to external plant and control models. The simulation may use Simulink: Model blocks with busses, which
requires that the bus object creation method be followed.
Model Calls can also be used to simulate the plant in multiple simulation environments. For example, a steady–
state simulation environment and a dynamic simulation environment could be created that both reference the same
55
plant. This way, instead of having to modify two models to update the plant, a single file (containing the plant
model) may be modified and these changes would be reflected in both simulation environments.
56
12 Acknowledgments
The authors would like to thank Alicia Zinnecker and Yuan Liu of N & R Engineering, and Jeffrey Csank of
NASA Glenn Research Center for their work on T-MATS testing and for general technical advice. We would also
like to thank Sanjay Garg at NASA Glenn Research Center for his support in the development of T-MATS, and
the NASA Aviation Safety Program’s Vehicle Systems Safety Technologies (VSST) project for funding this
work.
57
13 Appendix A
MEX generation file:
/* T-MATS -- Burner_TMATS.c
* % *************************************************************************
* % written by Jeffryes Chapman based on work by R. May and T. Lavelle
* % NASA Glenn Research Center, Cleveland, OH
* % February 27th, 2013
* %
* % This file models the Burner Element for T-MATS simulation
* % *************************************************************************/
#define S_FUNCTION_NAME Burner_TMATS
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include "functions_TMATS.h"
#include "types_TMATS.h"
58
/* Set Block parameters tunable
Note: Original version had all parameters set to non-tunable(?) */
for (i = 0; i < NPARAMS; i++)
ssSetSFcnParamTunable(S, i, 1);
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_USE_TLC_WITH_ACCELERATOR);
#define MDL_START
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
}
#endif
59
BurnStruct burnPrms;
burnPrms.LHV = *mxGetPr(LHV_p(S));
burnPrms.dPnormBurner = *mxGetPr(dPnormBurner_p(S));
burnPrms.Eff = *mxGetPr(Efficiency_p(S));
burnPrms.LHVEn = *mxGetPr(LHVEn_p(S));
burnPrms.hFuel = *mxGetPr(hFuel_p(S));
%<LibAddToCommonIncludes("types_TMATS.h")>
%<SLibAddToStaticSources("Bleed_TMATS_body.c")>
%openfile forwardDecls
extern void Bleed_TMATS_body(double *y, double *y1, const double *u, const
double *BldInFlow, const BleedStruct* prm);
BleedStruct bleedStruct;
%closefile forwardDecls Perform Core calculations
%endfunction
60
%%
%function BlockInstanceSetup(block, system) void
%%
%<LibBlockSetIsExpressionCompliant(block)>
%endfunction
%% [EOF]
#ifdef MATLAB_MEX_FILE
#include "simstruc.h"
#endif
void Bleed_TMATS_body(double *y, double *y1, const double *u, const double
*BldInFlow, const BleedStruct* prm)
{
double WIn = u[0]; /* Input Flow [pps] */ Inputs
double htIn = u[1]; /* Input Enthalpy [BTU/lbm] */
double TtIn = u[2]; /* Temperature Input [degR] */
double PtIn = u[3]; /* Pressure [psia] */
double FARIn = u[4]; /* combusted Fuel to Air Ratio [frac] */
double BldInLen = u[5]; /* Length of Bleed Vector input */
61
/*--------Define Constants-------*/
double Wfin, htin, Test;
double WOut, htOut, TtOut, PtOut, FAROut, WbldoutTotal;
double Ws1,hts1,Tts1,Pts1,FARs1, Wfs1;
double dHblds1, dHbldout, Wblds1, Wbldout, Wfblds1, Wfbldout;
int Vtest;
int i;
62
Wfin = FARIn * WIn*divby(1+FARIn);
Wfs1 = Wfblds1 + Wfin;
FARs1 = Wfs1*divby(Ws1 - Wfs1);
htin = t2hc(TtIn,FARIn);
hts1 = (htin* WIn + dHblds1)*divby(Ws1);
Tts1 = h2tc(hts1,FARs1);
Pts1 = PtIn;
htOut = hts1;
TtOut = Tts1;
PtOut = Pts1;
FAROut = FARs1;
WbldoutTotal = 0;
for (i = 0; i < prm->WfracLen; i++)
{
WbldOut[i] = prm->Wfrac[i]*WIn;
WbldoutTotal = WbldoutTotal +WbldOut[i];
}
Test = PtIn;
63