Mastering EES 01
Mastering EES 01
F-Chart Software
Box 44042
Madison, WI 53744
http://fchartsoftware.com
Starting with version 9.370, EES provides a Mastering EES menu item in the Help menu. If
the Mastering-EES.pdf file is placed in the same directory as the EES application, selecting
the Mastering EES menu item will start Adobe Reader, open the Mastering-EES.pdf file and
automatically enter the password.
TABLE OF CONTENTS
Acquiring EES
EES is licensed and distributed solely by F-Chart Software LLC. A license for EES can be
purchased directly from the company website, http://fchartsoftware.com. Single and multi-user
licenses are available. In addition, the company offers academic licenses for educational
institutions involved in formal classroom instruction and academic research leading to a degree.
Details and costs for the different license options can be found at http://fchartsoftware.com/ees/.
If you do not have access to EES, you can download a demonstration copy of the program from
http://fchartsoftware.com/ees/demo.php. The demonstration copy will allow you to examine
most of the features and examples that are provided in this book.
Commercial and Professional versions are available. The Commercial version provides all of the
basic functionality of EES, includes the ability to solve 6000 simultaneous equations and allows
access high accuracy property information. It can be used to conduct parametric studies, do unit
conversion and check unit consistency, provide publication quality plots, perform uncertainty
analyses, and many other things.
The current versions of EES are 32-bit Windows executable programs that are designed to run on
all modern 32 and 64-bit Windows operating systems such as Windows XP, Windows 7, 8 and
10. There is also a 64-bit Professional version of EES, as described in Appendix G.
Installing EES
Installing EES is relatively straightforward, but there are a few options that merit discussion. To
install the program, you will need both the Setup_EES.exe and EES.dft files. These files should
have been provided to you when you purchased the program or by a system administrator if you
obtained the program from your company or institution. There are a few institutions where the
EES.dft file has already been bundled with the setup file. Execute the Setup_EES.exe program
and click the Next button from the Welcome screen. Read the license agreement and, if you
agree, click the I Agree button and then click the Next button. Continue to click the Next button
until you see the Select Destination Directory dialog, shown in Figure 1-1.
The default directory that EES will be installed into is named EES32. EES is a 32-bit program,
but it will operate on all modern 32-bit and 64-bit Windows operating systems. (See Appendix
G for information on the 64-bit Professional version.) You can change the directory name, if you
wish, by clicking the Browse button. Depending on the particular installation program, you will
need to copy the EES.dft file to the directory that you choose to install EES. Click the Next
button after you have selected the directory.
The next window, shown in Figure 1-2, provides several installation options. If selected, the
Install Heat Transfer Library option will install an extensive set of library functions that facilitate
heat transfer calculations. These functions have been developed to accompany the text book
Heat Transfer, by G. F. Nellis and S.A. Klein (2009). Selection of this option is recommended
unless you are sure that you will never be doing any heat transfer calculations. A discussion of
these library functions is provided in Chapter 12.
Chapter 1: Introduction to EES 3
EES allows you to save custom Units and Constants files as discussed in Sections 1.5 and 1.9. If
you have done this, unselect the Overwrite Units files and Overwrite Constants.txt file in Figure
1-2. Otherwise these files will be replaced by the files in the installation program.
Clicking the Next button will install the program. If EES fails to start, the most likely problem is
that the EES.dft file is not contained in the directory that the program was installed into. In this
case, copy the EES.dft into the install directory and then restart EES by double-clicking on the
EES.exe icon or by entering C:\EES32\EES.exe in the Windows run dialog.
Silent Installation
It is possible to install EES silently, so that it installs the program with the default options and
without displaying any confirmation windows. To do a silent install, enter:
C:\myDir\Setup_EES.exe /s
into the Windows Run dialog after replacing myDir with the directory name where the
Setup_EES.exe program is located. By default, EES will place the program in the C:\EES32
directory (for the 32-bit version) or in the C:\EES64 dir (for the 64-bit version).
Online Help
Extensive online help is provided with the EES program installation. The index page for this
help file is shown in Figure 1-3. The online help can be made visible by selecting Help Index
from the Help menu or by pressing the F1 key. The help file is heavily hyperlinked. Clicking on
a word shown in blue font will move the display focus to that subject. There is also a Contents
box and an Index in the left pane of the Help window, as seen in Figure 1-3. Clicking on any
item in the Contents box will link directly to page for that item. The Index page allows you to
search for a specified keyword.
4 Chapter 1: Introduction to EES
Online help information for built-in and library functions can accessed by selecting the function
name in the Equations window (e.g., by double-clicking) followed by a right-click to bring up a
popup menu. Help for the selected function will be one of the options.
The EES help is in file EES.chm. The .chm extension stands for compiled HTML file and it is
the preferred method for distributing online help for Windows programs. However, some
networks do not allow .chm files to be transferred from a server to a client computer due to
possible security concerns. If you find that the online help is not working, we recommend that
you contact your Information Technology person, as this problem can be resolved. (See
http://www.helpscribble.com/chmnetwork.html or http://support.microsoft.com/kb/896358).
However, the EES help files are also located on the F-Chart Website on page
http://fchartsoftware.com/ees/eeshelp/ees_help_index.htm, which provides an alternative if the
EES.chm file is not made available. Note that the online help file has a Search tab that can be
used to search for keywords.
Several other methods of providing help are available within EES. They can all be accessed
from the Help menu. The EES manual is a .pdf file that is provided with EES and also available
on the F-Chart web site on page http://fchartsoftware.com/assets/downloads/ees_manual.pdf.
The manual can be accessed with the EES manual command if the manual is placed in the same
folder as the EES application.
The Mastering EES eBook that you are currently reading can also be accessed from the Help
menu by selecting the Mastering EES menu command. Accessing Mastering EES in this manner
requires that the Mastering-EES.pdf file be placed in the same folder as the EES application.
EES will attempt to automatically enter the password when this menu command is selected.
Note that there is a Check for New Mastering EES command in the Help menu. Selecting this
command will check to see if a newer version of the Mastering EES ebook is available and if so,
provide the option to download it from the website.
A number of short YouTube tutorials have been prepared directed to particular skills in EES,
such as plotting, using Parametric tables, and checking units. These tutorials can be accessed
from the YouTube Tutorials command in the Help menu.
Chapter 1: Introduction to EES 5
Entering Equations
Consider the following set of equations:
x+ y =3 (1-1)
y=z 4 (1-2)
z = x2 3 (1-3)
Equations (1-1) through (1-3) are three non-linear equations in the three unknowns x, y, and z.
However, they are not directly solvable using most formal programming languages (e.g.,
MATLAB or Fortran) because they are equations rather than assignments. In order to solve this
system of equations using a formal programming language, it would be necessary to either
employ an iterative solution technique (e.g., successive substitution) or carry out sufficient
algebra to convert the equations into assignments. Let's take the latter approach here.
Substituting Eq. (1-3) into Eq. (1-2) provides:
y = x2 3 4 (1-4)
x + x2 7=3 (1-5)
x 2 + x 10 = 0 (1-6)
Equation (1-6) is a quadratic equation that can be solved using the quadratic formula:
1 1 4 ( 10 )
2
x= (1-7)
2
Chapter 1: Introduction to EES 7
At its most fundamental level, EES is an equation solver that solves sets of nonlinear equations
directly. For example, the three equations (1-1) through (1-3) can be entered directly into the
Equations Window, as shown in Figure 1-4.
Figure 1-4: Equations Window with Eqs. (1-1) through (1-3) entered.
In this book, text that is entered in the Equations Window will be shaded, as shown below.
x+y=3 y=z-
4 z=x^2-3
The Variable Information palette appears to the right of the Equations window. It shows the
variables that have been defined and their units. Click the Update button to update the palette to
the current contents of the Equations window. Slide the bar that separates the Equations window
and the palette left or right to adjust the size of the palette. Variable information for the Main
Program is shown by default. Click the Menu button to show variable information for
Procedures, Functions, Subprograms and Modules that are defined in the Equations window.
Figure 1-5: Equations Window after clicking the Update button in the Variable Information palette
8 Chapter 1: Introduction to EES
EES has identified one of the two solutions to the equation set. The other solution can be found
by changing guess values, as explained below. The process of solving the equations was done
internally; the user is not required to carry out any algebra or iteration.
There are several ways to view or change variable information. The simplest is to simply click
the mouse button on the variable name in the Variable Information palette. This action will
bring up the information for this one variable, as shown in Figure 1-9. The guess value, limits
units, alternate units and other information can be viewed or changed for the selected variable in
this dialog.
Figure 1-9: Dialog that appears after clicking on a variable in the Variable Information palette
Selecting the Hilite vars used once control in the Varialble Palette will highlite variable in the
selected program unit with a buff yellow background. For example, add the equation, xy=x+y to
the equations shown in Figure 1-5. Click the Hilite var used once button and the display will
appear as seen in Figure 1-10. Variables that are used only once are sometimes the result of a
typing error and highlighting them may help identify such problems.
10 Chapter 1: Introduction to EES
Note that the Variable Information dialog can be used as a smart Find command. Right-clicking
on a variable in the palette will locate it in the Equations window. Right-clicking on the variable
a second time will find the next occurrence of the variables.
In some cases, it is more convenient to display the variable information for all variables in the
program unit. This can be accomplished by selecting Variable Info from the Options menu (or
by pressing F9 or by right-clicking the Update button in the Variable Information palette.) The
full Variable Information dialog will appear, as shown in Figure 1-11.
Guess Values
There is a row corresponding to each of the three variables that make up the problem. Columns
allow the user to change various characteristics of these variables. The first column corresponds
to the guess values for each variable; these are the values used to start the iterative solution
process. By default, the guess value for each variable is 1. Note that x = 1, y = 1, and z = 1 is not
the correct solution, but it is closer to the solution x = 2.702, y = 0.2984, and z = 4.298 than it is
to the alternative solution x = -3.702, y = 6.702, and z = 10.7. In order to converge to the other
solution, it is necessary to change the guess values. For example, change the guess value of x to
something closer to x = -3.702 (e.g., -5), select OK and press F2 (the shortcut for the Solve
command). The solution identified by EES is shown in Figure 1-12. Guess values can also be
provided using other EES variables or equations, as described in Section 5.3.
Chapter 1: Introduction to EES 11
Limits
Lower and upper limits for each variable can also be set in the Variable Information Window.
For example, in order to identify only a solution for which the value of x is negative, the Variable
Information Window could have been set up as shown in Figure 1-13.
Figure 1-13: Variable Information Window with limits set for the variable x.
Display Format
All EES numerical values use extended precision that internally provides 20 significant figures
of precision. However, the display format can be separately specified for each variable in the
Variable Information Window. The A in the first of the three columns under the word Display
indicates Auto format. Several other display formats are possible. For example, click on the A
under display for the variable y and select Fixed decimal (F) with 9 significant figures. Click on
the N (normal) in the third display column on the same row and select boxed (X). Hit OK and
then solve the equations to obtain the solutions window shown in Figure 1-14. Notice that the
solution for y is shown in fixed decimal format to 9 significant figures and the result is boxed.
Figure 1-14: Solutions Window with an altered format for the variable y.
12 Chapter 1: Introduction to EES
In addition to numerical formats, EES also provides a Date, Time, and String format. The
display format can also be set directly in the Solution Window by right-clicking on a variable
and using the resulting Specify Format and Units dialog, described below.
The units column shows the units that have been entered for the variables. Units can be entered
directly into the column. Note that Units header is a drop down list. Clicking the arrow to the
right of Units allows for a selection of displaying/entering the base or alternative units.
y=z-4
x+y=3 x^2-
3=z
The Equations Window functions a lot like a word processor. You can use the cut (Ctrl+X),
copy (Ctrl+C), paste (Ctrl+V), Find, Replace, and undo (Ctrl-Z) commands just as you would in
Microsoft Word® or other programs that manipulate text. Multiple undo/redo capability is
provided for up to 32 changes. Equations are typically entered one per line; however, multiple
equations can be entered on the same line provided that they are separated by a semicolon (or a
colon if you are using European format):
The mathematical operators and order of operation used in the equations are consistent with
those used by most any programming language. For example, the equation:
a=2^3+3*4+2
will result in a = 22. Variable names in EES must start with a letter but they can include any
U.S. keyboard character except ( ) * / + - { } or ;. EES is case-insensitive; that is, the symbols x
and X are interpreted to be the same variable in the Equations Window. Very long equations can
be broken into two lines for ease of reading or improved printing by using the ampersand (&).
Our example doesn't include any long equations, but we could still break the first equation into
two lines according to:
x+y&
=3
y=z-4 z=x^2-
3
Chapter 1: Introduction to EES 13
Comments
It is good practice to annotate your EES code in order to clarify the meaning behind the equation
set. Typically each equation is followed by a comment that is ignored by the equation solver
itself but is visible to the user. Comments in the Equations Window should be enclosed either in
curly braces or quotes. Any line that begins with two forward slashes is also considered a
comment. The comments are displayed in blue (by default) in the Equations Window to indicate
that they are not part of the equation set that will be solved. Comments that begin with the !
character (referred to as comment type 2) are displayed in red by default. The default colors for
comments can be changed in the Equations tab of the Preferences dialog (Options menu).
Occasionally it will be useful to temporarily remove an equation or a group of equations from the
Equations Window. Of course, you could just delete the equation(s) and then type them back in
if and when they are needed again. However, a better solution is to "comment them out".
Highlight the equation(s) to be removed and then right-click to bring up a pop-up menu, as
shown in Figure 1-15. Select Comment {} in order to place curly brackets around the entire
section of highlighted code, temporarily removing it from the equation set. To restore the
equation(s), highlight the commented code, right-click and select Undo Comment {}.
Active hypertext can also be entered in comments in the Equations Window. EES will
automatically recognize hypertext links that begin with http:\\, https:\\, or file:. For example, enter:
"http:\\fchartsoftware.com"
and notice that it becomes a link to that web page. A summary of the recognized hypertext links
is provided in Table 1-1.
14 Chapter 1: Introduction to EES
The built-in math functions can be conveniently accessed by selecting Function Information
from the Options menu, which displays the Function Information dialog appearing in Figure 1-
16. By default, all the built-in math and string functions are initially shown in the list on the left
side of the dialog. The list of functions can be reduced by selecting a function classification
from the list on the right side. An example of the proper use of the selected function is shown in
the Ex: edit control at the bottom of the dialog. The text in the Ex: edit control can be edited in
the conventional manner. Clicking the Paste button will paste the contents of this control into
the Equations Window at the current cursor position.
(.lib/.lib64) files, as described in Chapter 11. They can even be coded so that the units of the
input and output variables will be checked by EES, in the same manner as for internal functions
and procedures. Warning and error messages can be returned from the external routines and
displayed by EES. External functions and procedures will be automatically loaded when EES
starts if they are placed in the Userlib directory. Alternatively, they can be manually loaded
using the Load Library command from File menu or the $INCLUDE directive. Help files can be
provided for documenting external functions and procedures in the same manner as described in
Chapter 11 for library files. External functions and procedures offer some significant
advantages. Because they are written in a compiled language they will execute much faster
(10x) than their internal counterparts. Also, the equations that are employed in external
functions or procedures are not visible to the user. External functions and procedures are written
as dynamic link library routines in the Windows operating system, as explained in this chapter.
Figure 1-16: Function Information dialog showing math and string functions.
16 Chapter 1: Introduction to EES
String Variables
EES provides both numerical and string variables. A string variable is identified with a variable
name that ends with the $ character. The variable name must begin with a letter and consist of
30 or fewer characters, including the $ character. String variables can be set to string constants,
which are strings that enclosed with single quote marks.
A$ = 'carbon dioxide'
String variables can be used in EES equations anywhere in which character information is
provided. For example the name of a fluid provided to a thermophysical property function may
be a string variable, as shown in Section 4.3. A string variable may be used to supply the units
of other variables, as shown in Section 1.5. String variables may be passed as arguments to
internal functions, procedures, modules, and subprograms or to external functions and
procedures as described in Chapters 3 and 10. String variables are very useful in the Diagram
window, as shown in Chapter 15. String functions are provided to manipulate string variables
and to convert them to or from numerical values. A complete list of string functions is provided
in Appendix B. String functions can be accessed from the Function Information dialog, as
shown in Figure 1-16.
where TabStop1, TabStop2, etc. are numerical values corresponding to the desired positions of the
tabs and Units indicates the units used for the tabs. The value of Units must either be in (for inch)
or cm (for centimeter). The code below sets two tab stops at 1 inch and 2 inch; notice that the
locations of the comments have shifted to 1 inch, which is consistent with the first tab stop set in
the $TabStops directive.
$TabStops 1 2 in
The first panel will display either US or EU. If US is displayed, the decimal separator is the
decimal point; otherwise it is a comma. The next panel displays the line and character on that
line at which the cursor is positioned. The various values of the current settings are displayed in
subsequent panels on the status bar, including the word wrap, overwrite, and caps lock settings.
Clicking the mouse button with the cursor positioned in any of these panels allows the settings to
be changed. The current unit system (discussed in Section 1.5) is displayed. The Warning panel
controls whether or not a window showing any warnings messages will be automatically
displayed after calculations are completed. These warnings can be manually displayed by
selecting Warnings from the Windows menu. The next two panels indicate whether unit
checking, and complex algebra are currently activated. The last panel toggles the syntax
highlighting setting. See section 1.9 for information relating to syntax highlighting.
lower case of the a variable name to the way it is first entered. Up to five tab stops can be set in
this dialog in either centimeters or inches. (Click cm or in to toggle the unit setting.) If the
Preferences are stored, using the Store button, these settings will be the defaults. Tab stops can
also be set with the $TabStops directive. See section 1.9 for more detail on syntax settings.
Additional display setting are provided on the General Display page shown in Figure 1-19. The
font type and size affects the font in all of the windows - not just the Equations window. There
are two types of comments. Comments that begin with an explanation character (!) can have a
different color then normal comments. For late-night coders, the background color for the
Equations, Solutions, and Residuals windows can be dimmed to a specified shade a gray with the
slider control provided to the right of Screen background.
Chapter 1: Introduction to EES 19
The Formatted Equations window is particularly useful for viewing large equations with multiple
parentheses. For example, consider the equation:
1.25 64 3.44
+
+
4 +
f = 3.44 4 L 4 L (1-10)
ReD L+ + 0.00021
1+
( L+ )
2
Equation (1-10) is the correlation provided by Shah and London (1978) for the average friction
factor associated with developing flow in a round tube. The symbol ReD is the Reynolds number
and L+ is the dimensionless length of the tube. This correlation can be entered in the Equations
Window as shown below. Note that Chapter 12 discusses the EES heat transfer library which
implements this and other useful correlations automatically.
The equation for f is difficult to read or debug in the word processing format used by the
Equations Window. It is much easier to view in the Formatted Equations Window, as shown in
Figure 1-21.
20 Chapter 1: Introduction to EES
Notice that the symbol f_bar is interpreted as f with an overbar in the Formatted Equations
Window. Similarly Re_D is interpreted as Re with a subscript D and L|plus is interpreted as L
with a superscript +. Greek symbols are also interpreted correctly; notice that the variable sigma
is interpreted as . The formatting options that are available are summarized in Table 1-
2. Section 1.6 shows how equations in the Formatted Equations Window can be copied in
various formats in order to facilitate writing reports or papers.
may want to use the splitter bar to work on it. Select the red rectangle and adjust its position to
create two sections, as shown in Figure 1-22.
Password Protection
In the Professional version of EES, it is possible to password protect the Equations Window so
that only you can edit it. Right click in the Equations Window and select Protected from the
resulting pop-up menu. You will be prompted to enter and then re-enter a password, after which
the background color will change to indicate that the text is now read only. Any subsequent
attempt to edit the protected regions of the Equations Window will not be allowed until you
unprotect the text. The text can be unprotected by right clicking on it and selecting Protected, at
which time you must enter the password.
22 Chapter 1: Introduction to EES
Key Variables
The Solution Window in a large EES program will contain many variables. Variables are listed
in alphabetical order; however, it may be difficult to quickly and easily identify the small subset
of variables that are of particular interest. To focus attention on a particular variable, it is
possible to highlight its appearance. For example, open the example file named Dinner.ees
located in the Userlib\Examples folder within the folder containing the EES application. (In the
64-bit version, the file will be named Dinner.ees64 and located in the \Userlib64\Examples
folder.) You can access the example directly by selecting Getting Started with EES from the
Examples menu at the right of the menu bar and then selecting “Settling the bill”. Solve the
equations by pressing F2 and the Solution Window should appear. Select the variable Debbie in
the Solution Window and right-click on it. The Specify Format and Units dialog that appears is
shown in Figure 1-23.
The Specify Format and Units dialog allows you to change the formatting that is used to display
the variable in the Solutions Window. For example, you can box the variable and change its
background color. You can also select a subset of all of the variables in your Solution Window
and make them key variables. Select the variable of interest by clicking the mouse on it (or by
pressing the Tab key until the variable is selected). Then either press the Return key or press the
right mouse button. This action will display the Specify Format and Units dialog. Click the Key
Variable check box and an edit box will appear in which you can write some descriptive
comments about the variable, as shown in Figure 1-24. Select OK and you will see that a new
tab will appear in the Solutions Window allowing access to the Key Variables Window. All of
the variables that have been identified as key variables are placed in the Key Variable Window
together with their associated descriptive comments, as shown in Figure 1-25. The position of
each line in the Key Variable Window can be changed dragging the mouse, i.e., pressing and
holding the mouse button down on the desired line while moving the mouse to the new location.
Chapter 1: Introduction to EES 23
Note that you can customize the Key Variables window in several ways. Clicking the right
mouse will bring up a pop-up menu, as shown in Figure 1-26, that allows text, separators
(horizontal lines) and text centered within a separator to be added, edited or deleted. The first
menu command will differ depending on where the mouse was clicked. (In Figure 1-26, the
mouse was clicked on the text with separator). Text, headers, separators and new Key variables
initially appear above the item that receives the mouse click. Clicking at the bottom of the
window below all other items allows new items to be entered at the bottom of the list. However,
the order in which the items initially appear is not fixed. All items in the Key Variables window
can be 'dragged' to a different location by pressing and holding the left mouse down on the item
that is to be moved while moving the cursor up or down, as illustrated in Figure 1-27.
Figure 1-26. Right-click in the Key Variables window to bring up a popup menu.
24 Chapter 1: Introduction to EES
Figure 1-27: Items in the Key Variables window can be 'dragged' to a different position.
1.3Parametric Tables
Section 1.2 described how to use EES to obtain a single solution to a set of equations. It is often
interesting to run a parametric study in which the effect of one variable (the independent
variable) on another variable (the dependent variable) is studied. For example, let's estimate the
pressure loss incurred by the flow of water through a 45º elbow as a function of the flow rate.
The inner diameter of the elbow is D = 2 cm and the density of water is = 1000 kg/m3. The
dimensionless resistance coefficient for this type of elbow is estimated to be K = 0.3. The
pressure loss can be estimated according to:
P=K (1-11)
u2
2
where u is the velocity of the water. The inputs are entered in the Equations Window; note that
we'll start with V = 100 liter/min and subsequently vary this value.
$TabStops 2.5 in
"Inputs"
K=0.3 "K factor for a 45 degree elbow, dimensionless"
V_dot=100 "volumetric flow rate, in liter per min"
D=2 "inner diameter of elbow, in cm"
rho=1000 "density of water, in kg/m^3"
In Section 1.5, we will discuss how EES can help you deal with unit assignments and
conversions. For now we'll have to keep track of units manually. Notice that the units assigned
to each variable are indicated in the associated comment. The cross sectional area of the elbow
is given by:
2
Ac = D (1-12)
4
Chapter 1: Introduction to EES 25
The units of the variable A_c must be cm2 (because the units of the variable D is cm). Also, the
variable pi# is a built-in constant in EES corresponding to the value of (other built-in constants
are discussed in Section 1.9). The velocity of the water is:
V
u= (1-13)
Ac
u=V_dot/A_c "velocity, in liter/min-cm^2"
As written, the units for the variable u must be liter/min (the units for the variable V_dot) divided
by cm2 (the units for the variable A_c). Therefore, the units for u must liter/min-cm2. Note that
in this book, the hyphen sign will be used to indicate multiplication on one side of the divisor in
liter
the context of units; therefore liter/min-cm2 should be read as . EES uses the same
min cm 2
convention for unit specifications, although the hyphen can be replaced with a space or a dot
(Alt-250 on a U.S. keyboard).
The units for the variable u, as calculated, don't make a lot of sense; let's convert the units to
cm/min, which are more reasonable:
liter 1000 cm3 = cm (1-14)
min-cm 2 1 liter min
The EES code, with the unit conversion, is:
Again, the units for the variable DELTAP don't make a lot of sense; as calculated, the units are kg-
cm2/m3-min2. Nobody will understand your result when expressed in these units. Let's convert
to kPa, which are more commonly used:
kg-cm 2 kPa-m 2 N-s 2 m2 min 2 = kPa (1-15)
m3 -min 2 1000 N kg-m 1002 cm 2 602 s 2
Notice that we had to look up four separate unit conversion factors in order to accomplish the
unit conversion indicated by Eq. (1-15). Section 1.5 shows that EES greatly reduces the hassle
and potential errors that are associated with working with units.
The window on the left side of the dialog provides a list of all of the variables that are included
in the Equations Window. Highlight the independent and dependent variables of interest (in this
case, the variables V_dot and DeltaP) by clicking on them and then select Add to add the variables
to the window on the right side, which lists variables to be included in the table. Any other
variables that you wish to include in the table can also be added. You can select the variables
one at a time or all at once. Select OK in order to create the Parametric Table, shown in Figure
1-29. By default, there are 10 runs (rows) in the table. Runs can be added or removed by
selecting Insert/Delete Runs from the Tables menu or by right-clicking on any run number and
selecting Insert Runs or Delete Runs. There is a column for each of the variables included in the
table. Columns can be added or deleted by selecting Insert/Delete Vars from the Tables menu or
right clicking on any variable and selecting Insert Column or Delete.
Alter Values
To carry out a parametric study in which the volumetric flow rate is changed, it is necessary to
fill in the column for the variable V_dot with flow rate values that are of interest. This process
can be done manually, one run at a time. More typically, you will right-click on the column of
interest and select Alter Values or click on the triangular icon in the column header to bring up
the dialog shown in Figure 1-30.
Select the rows to be filled in (rows 1 to 10, for this example) and the pattern to be used to enter
the values. In Figure 1-30, the dialog is filled in so that the volumetric flow rate varies from 200
liter/min (in row 1) to 2000 liter/min (in row 10) in equally spaced intervals, as shown in Figure
1-31. Other options can also be specified by clicking on the drop down menu under First Value.
For plots that will use a logarithmic scale, the selection Last (Log) is particularly useful as it
logarithmically spaces the values in the table.
In the Professional version, the value entered for Last Row (upper left of Figure 1-30) can be set
to value greater than the current number of rows in the Parametric table. After confirmation,
EES will extend the number of rows in the table to this value. The Professional version also
allows EES variables (in addition to numerical values) to provide the First Value Last/Increment
values.
28 Chapter 1: Introduction to EES
The dialog is initially set so that EES will start with run 1 and end with run 10. By pressing OK,
EES will go to run 1 of the Parametric Table shown in Figure 1-31 and find that the value of the
variable V_dot is set to 200. Therefore, you can imagine that EES places the following equation
in the Equations Window.
V_dot=100
already exists in the Equations Window. The variable V_dot cannot have multiple values as it
causes the equation set to be over-constrained (8 equations and 7 variables). Solving the table
will result in the error dialog shown in Figure 1-33.
This problem can be alleviated by commenting out the equation that specifies the volumetric
flow rate in the Equations Window. Highlight the statement, right-click, and select Comment {}
in order to temporarily remove it from the equation set.
Now solve the table to obtain the solved Parametric Table shown in Figure 1-34.
It will sometimes be useful to solve only a portion of the table. This is easily accomplished by
changing the first and last run numbers in the Solve Table dialog.
All tables in the Professional version are equipped with a column-sizing control that
automatically sets the required width of the columns in the table. The control is a double-headed
arrow appearing in the upper left cell of the table, as shown in Figure 1- 35. When it is not
enabled, the arrowheads are gray-filled as seen in Figure 1- 35a. Clicking on the control resizes
the columns so that contents of the column just fit. The arrowheads will then be filled with a
light blue color, Figure 1- 35b. Holding the Ctrl key while clicking on the control returns the
column widths to their default size.
30 Chapter 1: Introduction to EES
Figure 1- 35: Parametric table in Professional version showing column sizing control a) off and b) on
In the Professional version of EES, the start and stop values can be set to variables. For
example, add the lines:
Open the Parametric Table, right click on the DeltaP variable column and select Alter Values.
Select Clear Values to clear the column. Solve the table again. This time, click on the arrow
next to First Run Number and change it to First Run Variable and then select startrow. Change
Last Run Number to Last Run Variable and select endrow. The result is shown in Figure 1-36.
Select OK and you will see that only runs 3 through 7 have been filled in.
Figure 1-36: Solve Table dialog with first and last runs set with variables.
Chapter 1: Introduction to EES 31
Formatting Columns
The Parametric Table shows the value of pressure drop for each corresponding value of
volumetric flow rate. In Section 1.4 we will see how to use this information to prepare a plot.
Before we do that, let's look at some other features of Parametric Tables. The position of the
columns can be adjusted by dragging (i.e., pressing the left mouse button and then moving
mouse while holding down the mouse button) the column headers. The units, alternate units, and
format of the columns can be adjusted by right-clicking on the column and selecting Properties
to bring up the Format Properties Table dialog shown in Figure 1-37 (for the column
corresponding to the variable DELTAP). The format used to display the results, the background
color, and the column width can also be adjusted. The column number can also be set in this
dialog. At the bottom of the dialog, statistics are provided for the entries in the column.
A more elegant method for removing one or more lines of code when a Parametric Table is being
solved is to use the $If directive. The $If directive is used according to:
$If Condition
line(s) of code to be executed if Condition is true
32 Chapter 1: Introduction to EES
$Else
line(s) of code to be executed if Condition is false
$EndIf
where Condition is a keyword that indicates an execution condition. There are many such
keywords recognized by EES and these are discussed in more detail in Chapter 14. One
keyword is ParametricTable, which evaluates to true when the equations are being solved from a
Parametric Table. For our problem, we want to specify the value of the variable V_dot in the
Equations Window only if the value of ParametricTable is false:
$If ParametricTable
$Else
V_dot=100 "volumetric flow rate, in liter per min"
$EndIf
$IfNot ParametricTable
V_dot=100 "volumetric flow rate, in liter per min"
$EndIf
You should find that your equation set now runs if you select either Solve or Solve Table from
the Calculate menu (or if you press either F2 or F3, respectively).
The table can be saved as a text (.txt) or comma separated values (.csv) file; either of these file
formats can be opened by most any other software or spreadsheet Section 1.8 provide details on
Lookup File formats. The table can also be saved in a format that can be reopened by a different
EES program as a Lookup Table (.lkt). Lookup Tables are discussed in Section 1.8. Finally,
data can also be saved as an .xlsx file using the Save Table command in the Tables menu to
allow exporting to Excel. In this case, the first row in the Excel file will be the name of the
column. The second row will be the units. The data in the table will start in the third row.
Lookup files saved in the format can be opened with the Open Lookup Table command. Note
that a Parametric table can also be saved as a .PAR file using the Store Parametric Table
command in the Tables menu. A .PAR file can only be read by EES. This format is useful if
you wish to move a Parametric table to another EES file.
Select Copy to place the information on the clipboard. Open another spreadsheet or word
processor and then paste the information. The result is shown in Figure 1-42(a) using Excel. If
the Copy with Headers option is selected then the header for each column is also copied; the
result is shown in Figure 1-42(b). Notice in both cases that the number of significant figures
associated with the data that is copied corresponds to the number of significant figures used to
display the information in the Parametric Table. If the Copy (E-format) option is selected then
the data are copied with 12 significant figures so that there is no loss of accuracy associated with
the copy/paste operation, as shown in Figure 1-42(c).
Chapter 1: Introduction to EES 35
When the Copy command is issued, EES actually copies the data to the clipboard in two formats.
The first format uses the number of significant figures that are displayed and this is what appears
in an external program. In the second format, EES retains all of the significant digits. If you
paste data from one column of a table to another (or to any other table in EES), EES will paste
the data with all of the significant figures so there is no loss in precision during the copy process.
1.4Basic Plotting
Section 1.3 described how to create a Parametric Table that includes the value of a dependent
variable at each of several values of an independent variable. This information is viewed most
conveniently in the form of a plot. EES allows the generation of several types of plots, as
discussed in Chapter 9. In this section, only the most basic X-Y type plot is discussed. Data
contained in the Parametric Table created in Section 1.3 will be plotted in this section. Data
contained in Lookup Tables (see Section 1.8), Arrays (see Section 1.7), and Integral Tables (see
Chapter 7) can also be used for this purpose.
Generating a Plot
To generate a plot, select New Plot Window from the Plots menu in order to access the New Plot
Setup dialog shown in Figure 1-43. At the top of the dialog you can provide a title (in the Tab
Name field) and some descriptive text. The upper right portion of the dialog is used to select the
source of the data; here it is a Parametric Table and the title of the table is DP. As shown in
Figure 1-43, the New Plot dialog is set up to plot all 10 rows in the table but it is also possible to
plot only a subset of the rows. The two windows in the dialog allow you to specify the
independent (X-Axis) and dependent (Y-Axis) data. Figure 1-43 shows the New Plot dialog set
up to plot the pressure loss as a function of the flow rate. Select OK to create the plot, which is
shown in Figure 1-44.
Note that in the Professional version, variables may be plotted in their base or alternate set of
units. Alternate units can be entered in the Format Table dialog, as shown in Section 1.5.
36 Chapter 1: Introduction to EES
Modifying Axes
Almost every aspect of the plot can be modified in order to customize or improve it. A detailed
discussion of plotting options is provided in Chapter 9. Some of the common options are
described in this section.
Double-click (or right-click) on either axis label to bring up the Format Text Item dialog. You
can change the axis label to a descriptive text with units and change the font. A gray triangular
icon is visible at the bottom right of the plot when the plot toolbar is visible. You can resize the
plot by selecting the gray triangle in the bottom right-corner and holding the mouse button down
on the icon while moving the mouse to an alternative location. Note that the size of all text and
graphic items in the plot changes in proportion to the size of the plot unless the Ctrl key is held
down during this process. The axis scale can be adjusted by placing the mouse over any of the
axes (left, right, bottom, or top) and clicking the right mouse button. This action will bring up
the Modify Axis dialog shown in Figure 1-45, which allows you to make adjustments in the axis
scale, add grid lines, etc.
An improved plot of pressure loss as a function of flow rate is shown in Figure 1-46(a). By
selecting the Automatic scaling option in the Modify Axis dialog, the axis scale will be
automatically adjusted to encompass the data being presented. The axis labels can be scaled by a
factor of 10, 100, 1000, etc. by adjusting the Scale by 10^ option; Figure 1-46(b) shows the result
of scaling the labels by 100 (102). Select the top to bottom option in the Modify Axis dialog in
order to invert the scale, as shown in Figure 1-46(c).
38 Chapter 1: Introduction to EES
(a) (b)
(c)
Figure 1-46: Improved plot of pressure loss as a function of flow rate (a) with default y-axis format, (b) with
y-axis scaled by a factor of 102, and (c) with y-axis scaled from top-to-bottom.
Note that the range of values included on the X or Y axis can also be changed without use of the
Modify Axis dialog. This is done by simply positioning the mouse cursor on an axis and
dragging it. For example, if you wish the starting value of Flow rate shown in Figure 1-46 to be
less that 0, move the mouse over the left Y axis. The cursor will change to a . Press and hold
the left mouse button while moving the most slightly to the left. Release the mouse when the
axis is in the desired position.
Chapter 1: Introduction to EES 39
Overlaying Plots
Multiple data series can be overlaid onto the same plot. Change the resistance coefficient to K =
1.4 and run the Parametric Table again. Select Overlay Plot from the Plots menu in order to plot
pressure loss as a function of flow rate for the adjusted value of K. Your plot should now have
two sets of data, as shown in Figure 1-47.
(a) (b)
(c)
Figure 1-47: Plot with two data series (a) unmodified, (b) with error bars, and (c) with text annotations.
Modifying Plots
Double click (or right click) anywhere on the plot (other than on a text or graphic item) in order
to access the Modify Plot dialog shown in Figure 1-48. This dialog allows you to add and adjust
grid lines and modify the border and size of the plot. The upper window lists all of the data
series that appear in the plot. You can delete one or more of these series by selecting Delete
40 Chapter 1: Introduction to EES
button. The underlying data set that is used in the plot to can be extracted to a Lookup Table by
selecting Get Data button. The characteristics of each data series (e.g., the line thickness, color,
symbols, etc.) can be adjusted. The Smoothing option allows you to adjust the line passing
through the data using either a cubic spline, polynomial fit, or moving average.
The parameters in the Border box allow setting of the upper left corner of the plot and its width
and height. These width and height can also be changed by dragging the lower right corner of
the plot with the mouse button depressed. However, the setting here allow all plots to have the
same size and position .
At the bottom left of the Modify Plot dialog, controls are provided to allow data to be placed on
the primary (X1 and Y1) or secondary axes (X2 and Y2). The primary axes are shown at the
bottom (X-axis) and left (Y-axis) of the plot. The secondary axes are initially shown at the top
(X-axis) right (Y-axis), but they can be moved anywhere as detailed in section 9-1.
The controls at the bottom right allow the X and Y axes to exchange position and set the
background color of the plot rectangle. By default, the plot rectangle has a white background.
Clicking in the box to the right of Background color will bring up a color dialog that allows any
background color to be selected.
Chapter 1: Introduction to EES 41
Automatic Update
The Automatic update option in the Modify Plot dialog causes the data series to be re-plotted
each time the data source changes (e.g., the data in the Parametric Table are adjusted). This
option is useful if you want to adjust parameters in your model and immediately see how they
affect a plotted result. Once the Automatic update option is selected, the Data button becomes
live. Clicking this button will bring up the Modify Automatic Plot Data dialog, which allows
you to adjust the range of data that is plotted. Note that this dialog provides a check box for All
rows in table. If this box is selected, the range of plotted data will automatically change as the
number of rows of data change. If this option is not checked, then only the specified rows will
be updated.
Figure 1-49: Modify Automatic Plot Data after clicking the Data button.
Error Bars
Select Y-axis in the Modify Plot dialog to bring up the Specify Error Bar Information dialog
shown in Figure 1-50(a). The error bars can be set according to either an absolute or relative
uncertainty. Select an Absolute uncertainty of 50 kPa for the y error bar. Repeat the process for
the x error bar using an uncertainty of 50 liter/min in order to generate the plot shown in Figure
1-47(b). Alternatively, the uncertainty values used to generate the error bars can be obtained
from a table. It is also possible to generate asymmetric error bars by de-selecting the Identical
upper and lower values option in the Specify Error Information dialog, which brings up a
separate window for selecting the upper and lower uncertainty values, as shown in Figure 1-
50(b).
42 Chapter 1: Introduction to EES
(a) (b)
Figure 1-50: Specify Error Bar Information dialog (a) with identical upper and lower values, and (b) with
different upper and lower values.
Selecting the text tool opens the Format Text dialog, shown in Figure 1-52(a). You can type
text into the window in order to annotate your figure, as was done in Figure 1-47(c). The size,
font, style, and background of the text can be selected with the controls in this dialog. Clicking
the or button will change the selected text in the text field into a subscript or superscript,
respectively. For example, to enter Tinitial, type Tinitial into the text field. Then select initial and
click the button. The text field will change to T\dinitial\. The \d instructs EES to display the
following text up to the next \ as a subscript. \u in place of \d will result in a superscript. You
can enter these codes directly, without using the buttons if you prefer. Clicking the button
will insert a line break, carriage return code in the text string which will appear as \m in the text
edit box. When this option is selected, a check box will appear offering the option of centering
the lines of text with respect to each other.
Chapter 1: Introduction to EES 43
In the Professional version, you can also link the position of the text to a certain data point using
the Link Text to Data Point in Plot option at the bottom of Figure 1-52(a). This capability is
particularly useful if you have a plot that is automatically updated as you change parameters and
you would like the annotations to remain in their correct locations with respect to the data series.
(a) (b)
Figure 1-52: Format Text dialog with (a) Text item and (b) EES variable selected.
By default, the text tool is set to place a text item onto the plot; therefore the Text item radio
button is filled in at the top of the dialog. However, you can also annotate the plot using the
value of an EES variable by selecting the EES variable radio button. The resulting dialog is
shown in Figure 1-52(b). Use the pull down menu to select the appropriate variable (in our case
K). If the radio button Show name is selected, then both the value and the name of the variable
will be shown. If the Show units radio button is selected, then the units of the variable will also
be shown provided that they are set, as discussed in Section 1.5. The Integral radio button
automatically integrates one of the data series shown in the plots (selected by the user from a
dropdown menu) and places the value on the plot.
Note that strings of international characters can be displayed on the plot by entering the string in
the text box. EES will automatically detect if the entered text contains international characters.
If so, a blue (International Characters in use) message will appear under the text, as shown in
Figure 1-53. The subscript, superscript, and symbol buttons are disabled when international
characters are used. Also, a background color can be set for any text item, as shown in Figure 1-
53.
44 Chapter 1: Introduction to EES
There are several other useful tools in the Plot tool bar shown in Figure 1-51. The line tool
allows you to draw lines on your plot. By holding the shift key down during the drawing
process, the lines are constrained to horizontal, vertical, or 45°. The polyline tool allows you
to draw a series of connected lines. The square , circle , and polygon tools allow
rectangular, circular, and polygon regions to be outlined on the plot (note that the polygon tool is
only available in the Professional version). Holding the Shift key down while drawing these
objects forces them to have a constant aspect ratio.
When the plot tool bar is visible you can also copy graphic objects from other applications (e.g.,
PowerPoint®) and paste them into the plot window. The elbow shown at the bottom right of
Figure 1-54 was inserted in this manner. Right click on any of the objects on a plot in order to
change its properties (e.g., to add arrows to lines or to shade regions in opaque or semi-
transparent colors) or move objects forward (in front of) or backwards (behind each other) each
other. Select multiple objects at once by clicking on them one by one while holding the Shift
key down. Alternatively, you can select a rectangular region on the plot by pressing and holding
the left mouse button down at the upper left corner of the region and moving the mouse to the
lower right corner of the region. All objects within the region will be selected. The properties of
all selected objects can be changed at once.
Chapter 1: Introduction to EES 45
The alignment tool will be activated when multiple objects are selected. The alignment tool
can be used to align the positions of a group of selected objects vertically and/or horizontally.
Figure 1-54 shows a carefully formatted plot of pressure loss as a function of flow rate through a
45º elbow calculated using various values of the resistance coefficient. The alignment tool is
also activated when the X or Y-axis label is selected. In this case, the alignment tool can be used
to move the label to the center the axis.
Text and graphic items in Plot windows can be moved with the arrow keys when the Plot tool bar
(Figure 1-51) is visible. When an arrow key is pressed the first time, the selected items will
move 5 pixels. If the key is held down, the selected items will move quickly. Releasing and
pressing the key again (within 3 seconds) will move the selected items by 1 pixel, allowing fine
control. If the arrow key is then held down for more than 3 seconds, the speed at which the
selected items move in the designated direction will increase.
Figure 1-54: Formatted plot of pressure loss as a function of flow rate through a 45º elbow for various values
of the resistance coefficient.
The plot is normally locked in position in the plot window. However, it can be moved using the
Move plot tool (it can also be moved if the Ctrl key is held down). This tool is particularly
useful if the plot is located too close to the left or top of the plot window.
The Zoom tool allows a rectangular region of the plot to be selected, as shown in Figure 1-
56(a). A new plot is subsequently created, as shown in Figure 1-56(b), which includes the
selected region and therefore provides a zoomed in view of a certain region of the original plot.
46 Chapter 1: Introduction to EES
Figure 1-55: Plot window with cross hairs and status bar (at bottom).
(a) (b)
Figure 1-56: (a) Plot with the zoom feature activated and (b) new plot with zoomed in region.
Chapter 1: Introduction to EES 47
1.5Units
In Section 1.3 we calculated the pressure loss through a 45º elbow. During the process of
solving the problem we found that it was tedious keeping track of the units of each variable and
converting between different units. Variables in engineering problems typically represent
physical quantities and therefore they will have units. EES allows you to assign not only a value
to each variable, but also its units. This is an incredibly useful feature of EES because the unit
consistency of the equations will be examined by EES and any unit conversion errors will be
flagged. Further, EES facilitates the process of converting between units by including a large
number of built-in unit conversion factors. EES can also display variables in dual units.
Unit System
Units are commonly categorized as belonging to the English or SI (Systems International) unit
system. If you are accessing any of the built-in thermodynamic or transport property functions
or any of the trigonometric functions in EES, then it is important that you specify the units
system that you will be using. This is done by selecting Unit System from the Options menu to
access the Unit System tab of the Preferences dialog, shown in Figure 1-57. You can select
which unit system (English or SI) you will be using. Most of the settings in this page become
important only when accessing property databases, as discussed in Chapter 4. In the section
labeled Trig functions you must specify whether you want to provide arguments to trigonometric
functions in radians or degrees.
Entering Units
Let's return to the example from Section 1.3. The inner diameter of the elbow is D = 2 cm and
the density of water is = 1000 kg/m3. The dimensionless resistance coefficient is estimated to
be K = 0.3, allowing the pressure loss can be estimated according to:
P=K (1-16)
u2
2
48 Chapter 1: Introduction to EES
where u is the velocity of the water. We will compute the pressure loss when the volumetric
flow rate is V = 100 liter/min. The inputs are entered in EES as before:
"Inputs"
K=0.3 "K factor for a 45 degree elbow, dimensionless"
D=2 "diameter"
rho=1000 "density"
V_dot=100 "flow rate"
Solve the equations and examine the Solution Window, shown in Figure 1-58(a). The value of
each variable is indicated, but no units have been set.
(a) (b)
Figure 1-58: Solutions Window showing input parameters (a) with no units set and (b) with units set.
There are several ways to set the units (and alternate units) of each variable. The units of a
numerical constant (e.g., 2 or 1000) can be set directly in the Equations Window by placing the
unit within square brackets directly after the value. The units of each input variable can
therefore be set as they are entered.
"Inputs"
K=0.3 [-] "K factor for a 45 degree elbow, dimensionless"
D=2 [cm] "diameter"
rho=1000 [kg/m^3] "density"
V_dot=100 [liter/min] "flow rate"
The resulting Solutions Window is shown in Figure 1-58(b). Both the value and units for each
variable are indicated. Notice that using the hyphen alone as a unit specification indicates that
the variable K is dimensionless (i.e., it has no units). A space could be used in place of the
hyphen. The units for each variable can also be set by right-clicking on the variable in the
Solution Window in order to access the Specify Format and Units dialog, shown in Figure 1-59
for the variable D.
Chapter 1: Introduction to EES 49
It is also possible to set the units of a variable directly from the Equations window. This is done
by clicking on the variable name in the Variable Information palette. This action will bring up
the Variable Information dialog for the selected variable.
Finally, the units for each variable can be set in the Variable Information dialog that is accessed
by selecting Variable Info from the Options menu (or by pressing F9 or right-clicking the Update
button in the Variable Information palette).
Dual Units
Note that two fields are provided for units in Figure 1-59. If a second (alternate) set of units is
provided, it must have the same dimensions as the primary set of units. In this case, EES will
display the variable in the Solution Window in both sets of units. However, only values in the
primary units are used in the calculations. For example, we can enter in (for inches) in the
alternate units field, as seen in Figure 1-60a. Click the OK button and the Solution Window will
appear with the value of D shown both in cm and in inches (Figure 1-60b). EES uses its internal
unit conversion routines to determine the value (shown in brown font) for the second set of units.
Figure 1-60: a) Entering a second set of units and b) Display in the Solutions Window.
Dual units can be made to display in Parametric, Arrays, Lookup, and Integral tables as well. A
field is provided for alternate units in the Format Table dialog shown in Figure 1-37 and Figure 1-
61. This dialog can be made to appear by right-clicking in the header cell in any of the tables and
then selecting Properties from the pop-up menu that appears, as shown in Figure 1-61. Dual units
can be used to create plots with scales for both unit systems as shown in Section 9.1.
50 Chapter 1: Introduction to EES
Note that the Format Table dialog has a check box control named ‘Show values in alternate
units’. If an alternate set of units is provided with the same dimensions as the primary set and
this check box is selected, values will be displayed in both units, as seen in Figure 1-62.
The Professional version allows variables to be plotted in their primary or alternate units. See
section 9.1 for an example of this capability.
Chapter 1: Introduction to EES 51
Checking Units
The cross sectional area of the elbow is given by:
2
Ac = D (1-17)
4
By default, EES will not automatically set the units of A_c. Solve the problem and access the
Solution Window, shown in Figure 1-64(a). Notice that there is no unit listed after the variable
A_c and also that a red warning message has appeared at the bottom of the Solution Window
indicating that EES has detected a potential problem with the unit consistency of the equations.
(a) (b)
52 Chapter 1: Introduction to EES
(c)
Figure 1-64: Solution Window with (a) the units of A_c not set, (b) the units of A_c set by the user, and (c) the
units of A_c automatically set by EES.
Select Check Units in order to bring up the Check Units window shown in Figure 1-65. EES has
identified that Eq. (1-17) is not dimensionally consistent if A_c is dimensionless and D has units
cm. It is evident that the units of the variable A_c must be cm2.
Clicking the left or right mouse button on an equation that has unit issues will bring up the pop-
up menu in Figure 1-66.
The first menu option will display the formatted equation showing the units of all variables and
constants. This display makes it easy to identify unit problems. The second option will move
the focus to the equation in the Equations window. The third option opens the Variable
Information dialog where the units of one or more variables in the equation can be specified.
The last option disables unit checking for the selected equation.
By default, EES automatically performs this type of unit check each time the system of equations
is solved. Although not recommended, this option can be deactivated by selecting Preferences
from the Options menu and selecting the Options tab to access the dialog shown in Figure 1-67.
Automatic unit checking can also be controlled with the $CheckUnits directive. Placing
$CheckUnits AutoOn at the top of the Equations Window activates automatic unit checking and
Chapter 1: Introduction to EES 53
$CheckUnits AutoOff deactivates it. The $CheckUnits On and $CheckUnits Off directives can be
placed around a set of equations in order to locally deactivate the unit checking for these
equations, as discussed in Section 14.2. The unit consistency of the equation set can also be
checked at any time by selecting Check Units from the Calculate menu (or by selecting F8).
It is not possible to set the units for the variable A_c in the Equations Window using square
brackets because the right side of Eq. (1-17) is not a numerical constant. For example, typing:
will result in EES interpreting the constant 4 in the denominator as having units cm2.
Alternatively, typing:
will result in EES interpreting the square bracket as the subscript in an array (discussed in
Section 1.7), leading to an error message. Rather, the units of the variable A_c must be set either
by right-clicking on the variable in the Solutions Window and entering the units or by using the
Variable Information window. The result is shown in Figure 1-64(b). Note that the red unit
warning is now gone.
should be confirmed by the user by right-clicking on these variables in the Solutions window and
then making any necessary changes in the dialog window that appears.
Automatic unit setting can also be activated by placing the $AutoSetUnits On directive at the top
of the EES Equations Window:
$AutoSetUnits On
V
u= (1-18)
Ac
u=V_dot/A_c "velocity"
As written, the units for the variable u must be liter/min (the units for the variable V_dot) divided
by cm2 (the units for the variable A_c). Therefore, the units for u must liter/min-cm2. (Again,
note that in this book and also in EES, the hyphen sign will be used to indicate multiplication on
one side of the divisor in the context of units). If we set the units for u to liter/min-cm2 in the
Solutions Window, then EES will find no unit inconsistencies. Of course, the units liter/min-cm2
don't make a lot of sense for a velocity and it would be better to convert the value to a more
reasonable set of units, like cm/min. We could do this manually, looking up each of the various
unit conversion factors that are required to arrive at the conclusion that we need to multiply by
1000:
Fortunately, EES has built-in unit conversion information that is easily accessible using the
convert function. The convert function simply retrieves the conversion factor between two units
and therefore the function requires two arguments; the first argument is the unit to convert from
while the second is the unit to convert to. By adding the convert function to the equation
calculating the velocity:
u=V_dot/A_c*convert(liter/min-cm^2,cm/min) "velocity"
the unit conversion is easy and transparent to the user. The convert function returned the correct
unit conversion multiplier (1000) for the unit conversion that is specified by the two arguments.
This is particularly evident in the Formatted Equations Window, shown in Figure 1-68.
Chapter 1: Introduction to EES 55
The units of the variable u should now correctly be set as cm/min in the Solutions Window or in
the Variable Information dialog. EES will not automatically set the units in this situation.
Finally, Eq. (1-11) is used to compute the pressure loss and the result is converted to kPa:
The units of the variable DELTAP can be set to kPa in the Solutions Window. The unit
assignments of each variable will automatically be stored and the units will be indicated
whenever you use the variables, such in a Parametric Table or plot.
If you set a variable to a numerical constant followed by its units in brackets, EES will
automatically assign the units to the variable. Starting with version 9.437, EES will also
automatically assign the units to variables that have been set to a value using the Convert
command. For example, the following example will set the value of L to 12 and its units to ft.
The unit list can be modified so that it is most useful to you. You really want to include only a
small number of units that you use a lot in order for it to save you time. The buttons to the right
facilitate this process. Units can be added or removed with the Add New and Remove buttons,
respectively. The entire list can be cleared with the Clear button. If you change the units list and
want that change to be recorded beyond the current EES session then you should save the new
file using the Save button.
EES will automatically load the default SI and English units lists (SI_DefaultUnits.unt and
Eng_DefaultUnits.unt, respectively) upon opening. You may have your own, separate units list
that you have developed and would like to use. This is easy to do because the units list is simply
a text file that can be opened and edited with any text editor (e.g., Notepad®). For example,
Figure 1-70(a) illustrates a text file that is saved as MyUnits.unt. This units list can be loaded
using the Load button in Figure 1-69 and then used for the duration of the EES session, as shown
in Figure 1-70(b). Alternatively, a custom units list can be merged with an existing list using the
Merge button.
(a) (b)
Figure 1-70: The unit list saved as (a) MyUnits.unt file and (b) loaded into EES.
Chapter 1: Introduction to EES 57
If you don't want to load your custom units list each time you start EES then you can use the
$INCLUDE directive. The $INCLUDE directive provides an automatic method of loading a variety
of files when you run your EES code. Place the statement:
$INCLUDE MyUnits.unt
at the top of the EES file and you will find that the units list is automatically set as shown in
Figure 1-70(b). Note that regardless of how the units in the units list are organized, they are
simply a subset of the large set of units that are recognized by EES.
Applying this strategy to our pressure loss problem leads to the following equation set:
and the Solution Window shown in Figure 1-71. While it is not necessary that you take this
approach, it certainly makes solving systems of engineering equations much easier. The settings
for the base SI unit system are as shown in Figure 1-57.
Note that EES allows an alternate set of units to be specified for each variable, as shown in
Figure 1-59. The last three lines of the program are not needed if alternate units of liter/min,
cm/min, and kPa are provided for variables V_dot, u, and DELTAP, respectively. The Solution
window with these alternate units set appears as shown in Figure 1-72.
Figure 1-72: Solution Window using alternate units for variables V_dot, u, and DELTAP
Chapter 1: Introduction to EES 59
Note that there can be confusion in temperature units. In some cases, you may wish to convert a
temperature difference in Celsius to an equivalent temperature difference in Fahrenheit. In this
case you would not use the ConvertTemp function, but instead, use the Convert function, e.g.,
Convert(C,F). For clarity, EES provides temperature difference units , DELTAF, DELTAC,
DELTAR and DELTAK. For example, a variable representing a temperature difference could be
assigned units of DELTAC, which will be displayed as C in the Solutions Window. Use of the
temperature difference units is particularly important when using the Dual units option in the
Specific Format and Units dialog (Figure 1-59) as EES will automatically assume that a variable
having units of F, C, R, or K is a temperature rather than a temperature difference.
Adding Units
EES includes several hundred units and is therefore likely to include any unit you might run
across. However, it is possible to add to the list of units recognized by EES. For example,
braking distances are often expressed in car lengths where 1 car = 4 m. The unit ‘car’ is not
recognized by EES. The equation:
We can add the unit car to the list of those that are recognized by EES by opening the file
Units.txt found in the root EES installation directory using any convenient editor (e.g.,
Notepad®), as shown in Figure 1-74.
60 Chapter 1: Introduction to EES
Figure 1-74: Units.txt file opened using Notepad® with the unit car added.
Instructions for adding units are found at the top of the Units.txt file. Unit conversions are
organized according to dimension. Locate the dimension of interest (in this case, Length). The
first entry in the unit list (in this case, m) is the basis used for conversion of all other units in that
dimension. Reading down the list, this should be clear (1 Angstrom = 1x10-10 m, 1 nm = 1x10-9
m, etc.). Add the appropriate entry at the bottom of the list, as shown in Figure 1-74, and save
the units.txt file. When EES is re-started it will load the new set of unit conversions and the
statement:
will not result in an error. The units of the variable L should be set to m in the Solution Window,
as shown in Figure 1-75. Note that you must de-select the Overwrite Units files selection when
updating EES (see Figure 1-2) or your modified units.txt file will be overwritten when a new
version of EES is installed.
Chapter 1: Introduction to EES 61
Figure 1-76: Variable Information dialog shown a string variable used for the units of a variable.
U$='kJ/kg'
h_SI=15 [U$]
h_Eng=h_SI*convert(U$, Btu/lb_m)
Note that providing alternate units in the Variable Information is an easier way to show results in
two sets of units. See Section 15.6 for an example using string variables to allow units to be in
either English or SI units in the Diagram window.
1.6Printing
Once you have completed your EES solution, you will need to document the results in some
way. This section discusses how you can output information from the EES file.
62 Chapter 1: Introduction to EES
Note that, by default, not all of the windows in your EES file will be printed. You need to select
from among those shown along the left side of the dialog. While there is only one Equations
Window, there may be more than one Parametric, Lookup, Array and Integral Tables and Plots.
You will need to indicate both whether you want these items to be printed as well as which of
these items are to be printed. A black check mark indicates that all of the items will be printed,
an open box indicates that none will be printed, and a gray check mark indicates that a subset has
been selected. For example, if more than one Plot window is present in the EES code, then
clicking on the Plots box will bring up the Select Plots to print dialog shown in Figure 1-77(b).
Select Preview in the Print dialog to bring up an on-screen display of the printed output.
(a) (b)
Figure 1-77: (a) Print and (b) Select Plots to print dialogs.
The Print Setup selection from the File menu allows you to set up the details of the printing
process (e.g., orientation, paper size, etc.). By default, the font and style used for the printed
output is the same as those used for the on-screen display. However, the Printer tab on the
Preferences dialog allows you to adjust these values independently.
Copying Equations
It is also possible to copy equations from the Formatted Equations Window in EES so that they
can be pasted into various applications. We will use Eq. (1-10), repeated below, as an example.
Chapter 1: Introduction to EES 63
1.25 64 3.44
+
+
4 +
f = 3.44 4 L 4 L (1-20)
ReD L+ + 0.00021
1+
( L+ )
2
f_bar=(4/Re_D)*(3.44/sqrt(L|plus)+(1.25/(4*L|plus)+64/4-3.44/sqrt(L|plus))/(1+0.00021/L|plus^2))
Open the Formatted Equations Window, shown in Figure 1-78. Highlight the equation and right
click to access the pop-up menu shown in Figure 1-79.
Clicking on a comment in the Formatted Equations Window that contains a URL beginning with
http: or https: will automatically start your browser open this page. If you do not wish to have
hypertext links active, select the Enable http links menu command from the Formatted Equations
pop-up menu so as to remove the check mark.
The three options at the bottom of the pop-up menu allow the equation to be copied and pasted in
a variety of formats. If the Copy as EES picture option is selected then the equation will be
placed on the clipboard as a picture (i.e., in windows metafile format), from which it can be
pasted into another application.
The next two options are only available in the Professional version of EES. The Copy as LaTeX
option translates the equation into LaTeX code that is placed on the clipboard. The Copy as
64 Chapter 1: Introduction to EES
MathType option translates the equation into MathType format that can subsequently be placed
in another application such as Microsoft Word® provided that the MathType® software is
installed.
LaTeX Report
EES can be used to create a high quality report that includes the Diagram, Equations, and
Solution Windows as well as any tables and plots. The report is created in the form of a TeX
document (.tex) that can be automatically processed by a LaTeX compiler to produce a device
independent (.dvi) output file that can be printed by various utilities. The PDFLaTeX accessory
available with the TeX compiler also produces a portable document interface (.pdf) file that is
compatible with Adobe Reader. The entire process can be made transparent to the user so that
the Latex Report feature effectively becomes a printer to produce .pdf files. The output quality
of the Latex Report feature is much higher than that obtained with the EES Print command.
Both the LaTeX software and Adobe Acrobat Reader must be installed on your computer in
order to use this feature. These programs are available at no cost. Download the distribution
MiKTeX installation file (i.e., the latest version of the MiKTeX software) from the web page
https://miktex.org/download using the instructions provided when you click the Help button in
the Create LaTeX/PDF report dialog shown in Figure 1-80. Choose the Basic MiKTeX Installer
option for your operating system (32 or 64-bit). Note that EES must eventually know the
directory path in which the MiKTeX software is installed so you should make a note of it. In
order to configure EES to work with the MiKTeX package, start EES and select Create
LaTeX/PDF Report from the File menu in order to access the Create LaTeX/PDF Report dialog
shown in Figure 1-80. Click the Setup button and navigate to the pdfLaTeX executable file
(typically found in the miktex/bin subdirectory of the installation directory). If you install
MiKTeX in its default directory, EES will likely find it without your intervention.
Chapter 1: Introduction to EES 65
In order to generate a report, access the dialog shown in Figure 1-80 by selecting the Create
LaTeX/PDF Report command in the file menu and enter the desired filename in the edit field at
the top of the window. By default, the filename will be the name of the EES file with a .tex
extension. The text entered in the Title field will be displayed at the top of the report. The
controls at the left side of the dialog allow you to select the items that will be included in the
report from among the various items in the EES file. If multiple items of the same type exist
(e.g., there are two plots in the EES file used to create Figure 1-80) then clicking on the value
within the square brackets will bring up a dialog that allows you to select a subset of the items.
The Equations Window selection provides some additional controls such as line numbering and
placing each equation and comments on separate lines. Very long equations may run off of the
right side of the report. It may be necessary to use the & character to break long equations into
segments in the Equations Window. The Solutions and Table group boxes each provide a
control that allows you to specify the number of columns per page to ensure that the text does not
run off the page of the report. The diagrams and plots that are to be included with the LaTeX
document are stored in separate jpeg files. The resolution of these files can be controlled using
the JPG quality control.
Towards the bottom right of the dialog there are three checkboxes. If the Create PDF document
checkbox is selected then EES will attempt to start the PDFLaTeX application and compile the
.tex file in order to create a .pdf file. If the Display PDF document checkbox is selected then
EES will attempt to start Adobe Acrobat and display the .pdf file directly after it is created.
Finally, if the Delete TEX document checkbox is selected then the .tex file and .jpg files will be
deleted, leaving only the .pdf file. Select Create to start the process of generating and compiling
the report.
66 Chapter 1: Introduction to EES
1.7Arrays
The variables that have been discussed in Sections 1.1 through 1.6 are all scalar variables; that is,
they can be assigned only one value. It will often be useful to use array variables which can be
assigned multiple values. Arrays are EES variables that have an array index enclosed in square
brackets at the end of the variable name. Data stored in arrays can be used to generate plots in
the same way that data stored in Parametric Tables can be used for this purpose, as discussed in
Section 1.4.
The value and units of the variable T_scalar can be examined in the Solution Window. The array
T_array[], assigned below, consists of three separate variables: T_array[1], T_array[2], and
T_array[3]. The value in subscripts is the index of the array; therefore, T_array[1] is the first
element of the array, and so on.
The values in the variable T_array[] will be stored in the Arrays Table Window, shown in Figure
1-81 and accessed by selecting Arrays from the Windows menu.
The array variables T_array[1], T_array[2], and T_array[3] behave just as ordinary EES variables.
They each have units, limits, guess values, etc. One purpose of using arrays is to organize
information; for example, each array variable may correspond to a thermodynamic state in a
system. Also, mathematical operations that are common to each element of an array can be
performed easily using the Duplicate command, discussed subsequently.
A string array variable must have the $ character just before the left bracket that holds the array
index. For example:
Chapter 1: Introduction to EES 67
A$[1]='Hello'
A$[2]='World'
T_array[1..3]=[100 [K], 200 [K], 300 [K]] "assignment using array notation"
Note that EES expects the correct number of values (three in the example above) to exist within
the square brackets on the right side of the equation above or it will post an error. If more than
three values were provided in the square brackets on the right side of the equation then the first
three would be used and EES would post a warning.
Two-Dimensional Arrays
If two indices are used for array assignments then the array will be two-dimensional (i.e., a
matrix rather than a vector). For example, the statement below:
The statement below assigns the value in the 2nd row (the first subscript) and 3rd column (the
second subscript) to the variable X. Examining the Solution Window shows that the scalar
variable X is equal to 600.
The Array Editor provides a convenient way to work with arrays. Ultimately the arrays accessed
by the Array Editor are listed in the Equations Window. In order to be recognized by the Array
Editor the array definition must begin with the comment {Array Name} and end with the comment
{Array Name end} where Name is the name of the array. For example, the statement below:
{Array a}
a[1,1..3]=[1,2,3]
a[2,1..3]=[4,5,6]
{Array a end}
would define the array a in a way that is recognized by the Array Editor. When the Array Editor
is opened, the dropdown menu at the top of the editor can be used to select from among any of
the arrays that have currently been defined in the Equations Window using this syntax. Note that
any array defined in the Array editor itself will use this syntax. Alternatively, a new array
variable can be created by selecting Enter array name from the Array drop down menu.
Modifications to existing arrays made in the Array Editor will show up in the Equations
Window. (Note that the Array Editor will not detect or be able to modify arrays that were not
created in the Array Editor.) This feature makes it easy to import data from other applications
such as Excel or MATLAB. For example, suppose you want to access a 5x5 array of data
generated in Excel, as shown in Figure 1-83.
Select Array Editor from the Edit menu. Name the array (D) and choose the right number of
rows and columns (5 and 5). Copy the data from Excel and select the Paste button ( ) to
place the data into the Arrays Editor, as shown in Figure 1-84.
Chapter 1: Introduction to EES 69
Select OK and the array D[] will be created in the Equations Window.
{Array D}
D[1..5,1]=[0.835379821,0.536458607,0.607826536,0.50104002,0.250295049]
D[1..5,2]=[0.596997554,0.795630883,0.179900142,0.205868913,0.439109551]
D[1..5,3]=[0.142993304,0.210596416,0.161575547,0.576841329,0.4000961]
D[1..5,4]=[0.70532211,0.077083658,0.333396857,0.179171305,0.198072072]
D[1..5,5]=[0.081197923,0.285540063,0.419114502,0.147024152,0.863134795]
{Array D end}
Run the EES program and you will see the array D[] created in the Arrays Table, as shown in
Figure 1-85. Again, do not modify or delete the comments that EES places around the array
values, as these are used to identify the array to the Array editor.
The variable index is iterated from the value start to the value stop. The equation(s) contained
between the Duplicate and End statements are written for each iteration. For example, the EES
code:
duplicate i=1,4
T[i]=i
end
is equivalent to writing:
T[1]=1
T[2]=2
T[3]=3
T[4]=4
When using Duplicate statements it is particularly important to remember that EES uses equations
rather than assignments. That is, do not accidentally place equations within a Duplicate statement
unless you actually want these equations to be duplicated in the Equations Window. A common
mistake that new users of EES make is shown below:
duplicate i=1,4
T[i]=i
x=4
end
T[1]=1
x=4
T[2]=2
x=4
T[3]=3
x=4
T[4]=4
x=4
which leads to 8 equations in 5 unknowns. Solving the EES code will lead to an error message.
Nested Duplicate statements can be used to generate two-dimensional arrays. For example, the
code below:
duplicate i=1,3
duplicate j=1,4
D[i,j]=i+j
end
end
Figure 1-86: Two dimensional array generated using a nested Duplicate statement.
It is possible to define array variables with more than two indices but this practice is not
recommended.
T[1..3]=[100,200,300]
might represent a set of temperatures. Select Variable Info from the Options menu to access the
Variable Information Window, shown in Figure 1-87(a). By default, each element of the array is
shown and the guess values, limits, and units can be set differently for each element. This
arrangement is inconvenient if all elements share a common set of characteristics. De-select the
show array variables button in the upper left corner in order to collapse the array, as shown in
Figure 1-87(b). Any characteristic set for the row T[] will be applied to each element of the
array.
72 Chapter 1: Introduction to EES
(a)
(b)
Figure 1-87: Variable Information Window (a) with each element of T shown and (b) with the array T
collapsed.
It is possible to assign different values of the guess values or limits to each element in an array
using a different array that is setup just for this purpose. This capability is discussed in Section
5.3.
It is often the case that you will want to redefine the size of the arrays that you use in an EES
program. For example, arrays are particularly useful in order to solve the system of algebraic
equations that result from numerical models. These equations correspond to a set of equations
written for each node or control volume defined within a computational domain. One of the
most important things that you should do with a numerical model is to verify that the number of
nodes is sufficiently large that the numerical model has converged. This check is typically done
by increasing the number of nodes and observing how the solution changes. The final number of
nodes that is used is always a compromise between computational time and accuracy.
Based on this discussion, it is clear that you can easily introduce many variables using arrays that
you do not ultimately wish to use. In order to clear these variables from memory you must use
Chapter 1: Introduction to EES 73
the Purge Unused Variable command from the Options menu, at which point EES will check if
there are unused variables in memory and ask whether you want to purge or keep them. Solving
the EES code below generates a 50x50 two-dimensional array D[]. The EES program includes
2502 variables, all of the entries in the array D[] as well as the variables Nx and Ny.
Now reduce the values of the variables Nx and Ny, as shown below, in order to generate a 10x10
array and reduce the number of active variables to 102.
Because EES retained the original 2502 variables in memory there are currently 2400 unused
variables. In order to purge these variables and reduce the size of the EES file select Purge
Unused Variables from the Options menu. You will be asked to confirm that you want to purge
the unused variables with the dialog shown in Figure 1-88.
It is wise to save the file with a different name before you purge variables.
74 Chapter 1: Introduction to EES
Select OK in order to generate the blank Lookup Table shown in Figure 1-90(a).
Entering Data
Data can be typed directly into the cells of the table or pasted from the clipboard. Alternatively,
the values in a selected column can be entered, cleared, or changed by either selecting the
triangle icon ( ) or right clicking on the column header and selecting Alter Values; either
option brings up the Alter Values dialog. Select Enter Values and then indicate the pattern that
should be used. For example, Figure 1-91(a) shows the Alter Values dialog set up in order to
enter values ranging from 0 to 10 in equal increments, leading to Figure 1-90(b).
The column widths can be adjusted manually by dragging the divider between cells in the header
(top) row. Also, note the double arrow in the upper left cell above the Paste Special button in the
Professional version. Clicking this button will adjust the width of each column in the Lookup
Chapter 1: Introduction to EES 75
Table to fit the data. Clicking the button again will return the column widths to their original
values.
(a) (b)
Figure 1-91: Alter Values dialog shown (a) with Enter Values selected and (b) with Enter Equation selected.
In the Professional version, a value greater than the current number of rows can be entered in the
Last Row field (upper left in Figure 1-90). In this case, EES will, after confirmation, increase
the number of rows in the Lookup table to this value.
When text data are available on the clipboard, the Paste Special (green) button will be visible in
the upper left cell of the Lookup table as shown in Figure 1-90. Clicking this button will bring
up the Paste Special dialog (Figure 1-92). This dialog will allow data that use tabs, commas,
spaces, or semicolons to separate values in each column. In addition, this dialog makes it
possible to paste the column names and/or units into the Lookup table starting at a specified row
and column.
Using the Enter Equation option, values can be entered into the selected column of the table as a
function of values in other columns, previously-defined variables in the EES worksheet and EES
functions. Using this capability results in the Lookup table operating much like as spreadsheet
program. The #X sequence is used to refer to values in another column. For example the
following entry would set the values in column 1 of the Lookup table to 5* the values in column
2. The changes are applied only to the rows indicated in the edit boxes at the upper left of the
dialog.
Any of the EES functions can be used in the equation. For example, the following entry converts
temperatures in C (in column 2 of the table) to K.
In some cases, it is necessary to refer to a particular row of a column in the Lookup table. This
capability is available by including the row number in brackets. For example, the following
equation sets all of the values in column 1 to the value in row 3 of column 2.
Finally, is sometimes necessary to refer a row above or below the current row for which a value
is being entered. #R refers to the current row. #R can be used in a subscript. Entering #2[#R] is
exactly equivalent to entering #2. However, you can offset the row values by entering the offset
to #R. For example, the following equation copies the values in column 2 to column 1, but it
offsets the row so that the value in column 1 row 2 is equal to the value in column 2 row 1, and
so on for the entire row range.
Chapter 1: Introduction to EES 77
Note that EES will not provide an error if the row is less than zero or greater than the maximum
number of rows.
The Professional version provides the option to automatically update the values in a column that
have been set with an equation. Checking automatic update will result in the values assigned
with an equation being updated whenever the values it depends upon are changed. The values in
a Lookup table can be changed by the Lookup command in an EES function or EES Macro, by
the $CopytoLookup directive, or by entering or pasting values into the table.
To save an existing Lookup Table, right click on the tab for the Lookup Table to bring up the
Information Dialog for the Lookup Table, as shown in Figure 1-93.
The dialog allows you to edit the name, add some descriptive text, duplicate the Lookup Table
and alter its position with regard to other Lookup Tables in the EES file. The Save button allows
you to save the Lookup Table in a variety of formats. The data alone can be saved in an ASCII
text (.txt) or comma separated value (.csv) file that can be read by most other applications. The
data with the headers can also be saved in a text file. The table can also be saved in the EES-
specific Lookup File or Lookup Table formats. The Lookup Table (.lkt/.lkt64) format is a binary
format that can subsequently be opened in other EES files or read directly by EES when using
78 Chapter 1: Introduction to EES
Lookup Table/File functions. This format is typically easiest to use and corresponds to a Lookup
Table that is saved by and can subsequently be opened by the EES software. Lookup Files saved
in the .lkt/.lkt64 format are scecure because they are written in a binary format that cannot be
read by any application other than EES. All of the information associated with the file including
column names, units and column format, is saved in the .lkt/.lkt64 file. See Lookup File Formats
in the online help for details about these data file types.
Note that deleting the Lookup table means that the data that it contains will not be saved with the
EES file the next time the EES file is saved. However, the Delete command does not delete a
Lookup table that has been saved separately in Lookup File that has an .lkt, .txt, .csv, or other file
name extension.
X = Lookup('TableName',Row,Column)
where 'TableName' is a string containing either the name of the table of interest (i.e., the name
shown in the tab in the Lookup Window) or the name of the Lookup File stored on disk
Chapter 1: Introduction to EES 79
(including the directory information and file name extension). TableName may be provided with
a string variable. Note that all of the built-in functions listed in Appendix A, Table A-9 can
access a Lookup File stored on disk (rather than a Look Table displayed in EES) by providing
the name of the file rather than the name in the Lookup Table tab. Row is the number of the row
in the table and Column is either the number or name of the column. For example, the command:
will result in the variable X being assigned 0.4947 if the Lookup Table shown in Figure 1-90(c)
is available in the EES file. Non-integer values of the column or row will result in linear
interpolation; however, the Interpolation functions discussed in Chapter 2 are more appropriate
for this type of operation and provide the option of higher order interpolation..
Data can be written to a Lookup Table using the Lookup command in a Function or Procedure or
with the $CopytoLookup directive. Functions and Procedures are described in Chapter 3.
format for the data. EES assigns the names "COLUMN1', 'COLUMN2', etc. and these column
names should be used when the file is used with the Interpolate or Differentiate commands.
Automatic formatting is used to display the data if the file is read into the Lookup Table with the
Open Lookup Table command. The following example shows the .TXT data needed for a
Lookup file with five rows and three columns, with no column header information.
5 3
1 11 111
2 22 222
3 33 333
4 44 444
5 55 555
If the number of rows is a negative number, EES will determine the number of rows of data in
the file when the file is read.
If the number of columns is a negative number, EES will expect to find the format specification.
A format specification consists of one or two characters. The first character is the type of format
and the second character is the number of digits provided for this format. Valid format
specifications are:
A auto format. A followed by a number, e.g., A3, is accepted but the number is ignored.
F# fixed decimal format with # digits after the decimal point, e.g., F3
E# exponential format with # digits after the decimal point or #+1 significant figures, e.g., E2
N# N significant figure format with # being the number of significant figures, e.g., N4
G# engineering format with # significant figures, e.g., G4
T# Time format; if # is 0, the default format is used; if # is 1, the format is
hours:minutes:seconds; if # is 2, the format is hours:minutes
D# Date format; # must be between 0 and 9 representing different date formats. 0 is the
default format
S string format. S followed by a number, e.g., S0, is accepted but the number is ignored.
The format specification is followed by one or more spaces and then the column heading and
units for each column. If a column contains string data, then the format specification must be S
(or S#) and the string data must be contained in single quotes. Units are optional but if supplied,
they must be enclosed in square brackets with a least one space separating them from the column
name. The following lines contain the .TXT data for each row, separated by one or more spaces
or a tab. The example below would create a table with 2 rows and 3 columns. The columns
would be formatted with E4, F1, and S format specifications and the column names will be
ColA, ColB, and Name.
2 -3
E4 ColA [Btu]
F0 ColB
S Name
1.23E-12 2.2 'A'
2.34E-11 4.8 'B'
Chapter 1: Introduction to EES 81
The Save Table command in the Tables menu and the $SaveTable directive provides a way to
save a Lookup table as a .txt file including the column header information.
Files having filename extensions other than .TXT, .LKT, .LKT64, .CSV, or .DAT can be read
provided that they are ASCII files with numerical values separated by a space or comma.
Lookup files with ASCII data may be read in with specifications provided by a FORMAT (.fmt)
file. See the online help for details relating to this file.
Built-In Constants
Constants in EES are denoted by a # sign after the name; constants are like variables in EES
except that their values cannot be changed in the Equations Window. A large number of
common physical constants are pre-assigned in EES. These entries can be viewed by selecting
Constants from the Options menu in order to access the Constants dialog, shown in Figure 1-95.
82 Chapter 1: Introduction to EES
Many physical constants of interest are available; for example, pi# is the value of (actually, pi
also refers to and is the only built-in constant in EES that does not require the use of #). R#
is the universal gas constant, k# is Boltzmann’s constant, etc. These constants are provided in
the unit system that has been specified by the user, as discussed in Section 1.5. The order of
the constants appearing in this dialog can be changed by clicking on the column header.
For example, clicking on Name at the top of column 1 will rearrange the order of the table so that
the entries are ordered alphabetically in terms of their names. Clicking a second time on Name
will reverse the order.
Adding Constants
It is possible to add constants by selecting Add from the Constants dialog in Figure 1-96 in order
to access the Add New Constant dialog shown in Figure 1-96.
The Add New Constant dialog prompts the user for the name, description, and value of the
constant in both SI and English units. For example, suppose we want to enter the Bohr radius,
a0, to our EES program. The value of the Bohr radius is 5.291772x10-11 m (or 1.736146x10-10 ft)
according to Mohr et al. (2011). The Add New Constant dialog should be filled out as shown in
Figure 1-96. If you select OK and access the Constant dialog by selecting Constants from the
Options menu then you will see that the constant a_0# has been added to the bottom of the
dialog, as shown in Figure 1-95. The new constants list can be saved by selecting the Store
Chapter 1: Introduction to EES 83
button in the Constants dialog so that it is available each time EES is opened. Note that you will
need to de-select the Overwrite Constants.txt file in the installation process, shown in Figure 1-2,
in order to keep your added constants when you update or reinstall the EES program.
Alternatively, make a copy of the Constants.txt file to ensure that it is not overwritten when you
install a new version of EES.
The user can also specify the value of constants in an EES program using the $Constant directive.
The calling protocol for the $Constant directive is:
where Name# is the name of the constant, ValueSI and ValueEng are the values of the constant in
the SI and English units specified by [UnitsSI] and [UnitsEng], respectively. For example, the Bohr
radius can be entered in EES according to:
Finally, it is possible to edit the Constants.txt file directly to add a constant that is loaded each
time EES is opened. See Section 14.3 for more detail relating the $Constant directive.
a=b+2
b^2=4+c
c=a-b
Open the Calculator Window by selecting Calculator from the Windows menu (or selecting the
button), as shown in Figure 1-98.
The result of any command preceded by a question mark will be displayed in the Calculator
Window. For example, the command:
?a+b
will lead to 6.899, as shown in Figure 1-98. New variables can also be defined in the Calculator
Window (provided that they don't already exist in the Equations Window). For example, we can
define the variable d in the Calculator Window:
d=a+b
and then use the variable d in a new expression, also shown in Figure 1-98. Use % to refer the
last calculated variable.
The Display preferences are shown in Figure 1-100. The fields in this window control some of
the basic display options. These options are applied independently of the setting of the Syntax
Highlighting control in the status bar of the Equations window. One of the most useful options is
the size of the font. The default size is 10, but the drop-down menu allows sizes to be selected
from 8 to 24. Large font sizes are useful when projecting EES in a classroom or presentation.
The screen can be dimmed with gray tones using the slider control at the bottom of this dialog.
The options in the Syntax tab are shown in Figure 1-102. The Tab Stops option places tabs at the
specified locations, which are very useful for organizing the content. This option can be also
specified with the $TabStops directive as described in Appendix C. All of the other options
86 Chapter 1: Introduction to EES
affect the appearance of the content in the Equations window when the Syntax Highlighting
control in the status bar at the bottom of the Equations window
(
Figure 1-101) is selected. Clicking the Equations window button in the button bar below the
main menu bar when the Equations window is visible will also toggle the syntax highlighting
display on/off.
Syntax highlighting affects the display of keywords and both built-in and user-supplied
Functions, Procedures, Modules and Subprograms. The display options allow the both the case
and style of Function names and EES Keywords to be independently controlled. Syntax
highlighting can enhance the display and make the equations easier to read as shown in Figure 1-
103, where a section of the Equations window is shown both without and with syntax
highlighting using the default options.
Note that syntax highlighting can increase the time required for EES to refresh the display. If
you have a very large EES program and the display is slow, you may want to turn off syntax
highlighting.
Clicking the Reset button will reset all preferences to their original (as-shipped) settings.
Chapter 1: Introduction to EES 87
Pressing OK will set the preferences you selected to be in effect for only the current session.
However, selecting the Store button will cause the preferences to be saved in an EES Preferences
(.prf) file. If you save the file as EES.prf in the EES working directory (which is the default
selection that is used when you select Store), then these preferences will automatically be loaded
whenever EES is started. Alternatively, you can save a .prf file that you want to apply only to
the current file in an alternative directory and subsequently load it using the Load button in
Figure 1-99.
Even more convenient is to load the preferences automatically using the $INCLUDE directive.
The $INCLUDE directive is discussed more completely in Section 14.5. Briefly, it provides a
method to automatically load various types of external files in an EES program. One type of file
that can automatically be loaded is the Preferences file.
For example, select Preferences from the Options dialog and then select the Display tab. Adjust
the font, size, etc. as you see fit and select Store. Save the .prf file in a directory of your
choosing (e.g., C:\temp\My Preferences.prf). Place an appropriate $INCLUDE directive at the top
of your EES file.
If you close and re-open the file you should find that the selections that you made in the
Preferences dialog and saved in the file My Preferences.prf are automatically loaded and used in
your EES file.
References
Mohr, P.J., B.N. Taylor, and D.B. Newell, "The 2010 CODATA Recommended Values of the
Fundamental Physical Constants (Web Version 6.0)," NIST, Gaithersburg, MD, 20899,
(2011).
Nellis, G.F. and S.A. Klein, Heat Transfer, Cambridge University Press, New York, (2009).
Shah, R.K. and A.L. London, Laminar Flow Forced Convection in Ducts, Academic Press, New
York, (1978).
2 CURVE FITTING & INTERPOLATION
Discrete data are often used to provide the basis for continuous functions. For example, we may
measure the thermal conductivity of a material at a few discrete temperatures and then, either
through curve fitting or interpolation, use these data to predict the thermal conductivity at any
temperature within the measurement range (and even beyond). EES provides several powerful
methods for accomplishing curve fitting and interpolation and these are discussed in this chapter.
These data can be entered in a Lookup Table as discussed in Section 1.8 and shown in Figure 2-
1. The data in the Lookup Table can subsequently used to create a plot as discussed in Section
1.4 and shown in Figure 2-2(a).
Chapter 2: Curve-Fitting and Interpolation 89
(a) (b)
(c)
Figure 2-2: Plot (a) showing data only, (b) data with 2ndorder polynomial curve fit shown, and (c) data with
curve fit given by Eq. (2-3) shown.
90 Chapter 2: Curve-Fitting and Interpolation
Select Curve Fit from the Plots menu in order to access the Curve Fit Plotted Data dialog shown
in Figure 2-3. The left window shows each of the data series that appear in the plot; in this case
there is only conductivity as a function of temperature. On the right side, the user can select
from a number of different mathematical forms for the curve fit. The corresponding equation is
shown in the window at the bottom of the dialog.
Figure 2-3: Curve Fit Plotted Data dialog with 2nd order polynomial fit selected.
In Figure 2-3, the curve fit selected is a second order polynomial and the equation that is listed
is:
When the Fit button is selected, EES will attempt to determine the best values of the
undetermined coefficients in the equation (in this case the variables a0, a1, and a2) using the linear
least squares method. The result is shown in Figure 2-4; note that the equation is shown in red
font and the unknown coefficients have been replaced with their best fit value.
Figure 2-4: Curve Fit Plotted Data dialog with best-fit 2nd order polynomial fit shown.
Chapter 2: Curve-Fitting and Interpolation 91
There are several useful options that appear in the dialog once the curve fit has been determined.
The Plot button causes the curve fit to be overlaid onto the plot. The Place equation on plot
option causes the mathematical equation associated with the curve fit to be shown in the plot, as
shown in Figure 2-2(b). The Copy equation to Clipboard option causes the equation to be placed
on the clipboard so that it can subsequently be pasted into the Equations Window or another
application. The Stats button allows access to the Curve Fit Statistics dialog that is shown in
Figure 2-5.
The Curve Fit Statistics dialog lists the value and the standard error associated with each
coefficient. The rms and bias errors of the curve fit are also shown. The rms error of a curve fit
is computed according to:
1
(Y )
2
rms = N Y
i m,i
(2-1)
N i=1
where N is the number of data points, Yi is the value of the dependent variable, and Ym,i is the
value of the dependent variable that is estimated using the curve fit. The bias error is computed
according to:
(Y Ym,i )
N
bias = 1 i (2-2)
N i=1
The rms error provides an indication of the deviation between the curve fit and the data. The
bias error provides an indication of a more systematic overestimate or underestimate that is
associated with the curve fit.
It is also possible to enter a custom equation form into the Curve Fit Plotted Data dialog. Any
unknown coefficients that must be determined in order to complete the curve fit should be
entered as a0, a1, etc. For example, you may want to curve fit the equation:
a1 a2
k=a + + (2-3)
0
( 700 T ) ( 700 T)
2
92 Chapter 2: Curve-Fitting and Interpolation
where a0, a1, and a2 are coefficients that should be adjusted in order to minimize the difference
between the data and the curve fit. Select Curve Fit from the Plot menu and then select
Enter/edit equation, as shown in Figure 2-6. Select Fit in order to bring up the dialog shown in
Figure 2-7, which allows the user to enter guess values and limits on the unknown coefficients.
Select OK in order to obtain the best fit values of a0, a1, and a2. The resulting curve fit is shown
in Figure 2-2(c).
Figure 2-6: Curve Fit Plotted Data dialog with user-specified equation entered.
Figure 2-7: Dialog to set guess values and limits on unknown coefficients.
Note that if these data exist in a Lookup Table, as shown in Figure 2-1, then they can be placed
in arrays using the Lookup command that is discussed in Section 1.8.
Duplicate i=1,8
T[i]=Lookup('Conductivity',i,1)
k[i]=Lookup('Conductivity',i,2)
end
Call CurveFit1D(FitType$, X[1..N], Y[1..N]: a0, a1, ..., aM, RMS, Bias, R|2, a_stderr[1..M])
Procedures are discussed in more detail in Section 3.3. Procedures are very similar to functions
in EES, which we have already encountered several times. Procedures allow multiple outputs
and must be preceded by the Call statement. Any argument to the left of the colon is an input and
those to the right of the colon are outputs. Inputs are typically provided to the procedure while
output variables are assigned by the procedure. For the procedure CurveFit1D, the first input is
FitType$ which is a string that specifies the functional form of the curve fit; the choices
correspond to the standard choices that are available in the Curve Fit Plotted Data dialog in
Figure 2-3 and are summarized in Table 2-2.
Table 2-2: Summary of curve fit types that are available in the CurveFit1D procedure.
Description FitType$ String Form of curve fit
Linear fit 'Linear' y = a0 + a1 x
1st order polynomial 'Polynomial 1' or 'Poly1' y = a0 + a1 x
2nd order polynomial 'Polynomial 2' or 'Poly2' y = a 0 + a 1 x + a 2 x2
3rd order polynomial 'Polynomial 3' or 'Poly3' y = a 0 + a 1 x + a 2 x2 + a 3 x3
4th order polynomial 'Polynomial 4' or 'Poly4' y = a0 + a1 x + a2 x2 + a3 x3 + a4 x4
5th order polynomial 'Polynomial 5' or 'Poly5' y = a0 + a1 x + a2 x2 + a3 x3 + a4 x4 + a5 x5
6th order polynomial 'Polynomial 6' or 'Poly6' y = a0 + a1 x + a2 x2 + a3 x3 + a4 x4 + a5 x5 + a6 x6
Exponential fit 'Exponential' or 'Exp' y = a0 exp(a1 x)
Power 'Power' y = a0 x a
1
The second and third input arguments are the dependent and independent data arrays,
respectively. The first outputs are the unknown coefficients provided in the array a that has m
elements, where m depends on the form of the curve fit. The remaining outputs are optional (that
is, variables that do not need to be provided and assigned by the procedure). The outputs RMS
and Bias are the rms and bias errors associated with the curve fit, defined by Eqs. (2-1) and (2-2),
respectively. The output R|2 is the correlation coefficient between the dependent and
independent variables. The array a_stderr is the standard error of the curve fit coefficients,
defined as the square root of the estimated variance of the parameter. The outputs RMS, Bias, R|2,
and a_stderr are optional and can be left out of the calling statement.
leads to the Solutions Window shown in Figure 2-8. Note that the coefficients are identical to
those shown in Figure 2-2(b) and Figure 2-4 and the statistics (e.g., the rms and bias errors) are
identical to those shown in Figure 2-5.
2.2Linear Regression
The curve fitting options discussed in Section 2.1 are useful for situations where a dependent
variable is regressed to a single independent variable. For example, in Table 2-1 thermal
conductivity is assumed to be only a function of temperature. Often a dependent variable will be
a function of several independent variables. For example, refrigeration compressor performance
data is often provided as a function of both evaporating and condensing temperature. An
example of such data can be found in the Lookup Table CompressorMap.lkt which is located in
the UserLib\Examples subfolder within the folder that the contains the EES application. (In the
64-bit version, this file will have a .lkt64 file name extension and located in the
Userlib64\Examples folder.) Open this Lookup Table by selecting Open Lookup Table from the
Tables menu; the first few rows of the table are shown in Figure 2-9.
Chapter 2: Curve-Fitting and Interpolation 95
Notice that both the mass flow rate and power (two dependent variables) are provided for an
array of condensing and evaporating temperatures (two independent variables). It would not be
appropriate to use the curve fitting options discussed in Section 2.1 for this situation. The
advantage of the Linear Regression command in EES is that it allows multiple (up to 9)
independent variables to be considered. Select Linear Regression from the Tables menu to
obtain the Linear Regression dialog shown in Figure 2-10.
Figure 2-10: Linear Regression dialog while equation form is being selected.
Equation Statistics
Selecting the Stats button provides the standard error of each coefficient as well as the rms error,
bias error, and R2 parameter of the curve fit as shown in Figure 2-12. The coefficients can be
copied to the clipboard from this dialog.
96 Chapter 2: Curve-Fitting and Interpolation
Regression Plot
Select Plot in order to generate a plot showing the predicted value of the dependent variable
obtained using the curve fit as a function of the value of the independent variable for each of the
data points, as shown in Figure 2-13. The red line indicates a perfect fit and the scatter of the
data about this line indicates the goodness of the fit.
Figure 2-13: Predicted value of mass flow rate as a function of the mass flow rate.
T_evap=42 [F]
T_cond=72 [F]
m_dot=6.07526921E+03-1.37537396E+02*T_cond+1.27479708E+00*T_cond^2&
-3.95202020E-03*T_cond^3+4.76688312E+01*T_evap+2.63095238E-01*T_evap^2&
+3.48484848E-03*T_evap^3-1.58900227E-01*T_cond*T_evap
Note that running the program will result in the Solutions Window shown in Figure 2-14(a),
which shows that there are unit warnings, even though the units of the variables T_cond, T_evap,
and m_dot have all been set correctly (to ºF, ºF, lbm/hr, respectively).
(a) (b)
Figure 2-14: Solutions Window (a) with unit warning and (b) without unit warnings.
98 Chapter 2: Curve-Fitting and Interpolation
or use the $CheckUnits directive to disable unit checking for the curve fit. The $CheckUnits
directive allows unit checking to be selectively disabled for an equation or set of equations;
$CheckUnits Off disables unit checking and $CheckUnits On restores unit checking.
$CheckUnits Off
m_dot=6.07526921E+03-1.37537396E+02*T_cond+1.27479708E+00*T_cond^2&
-3.95202020E-03*T_cond^3+4.76688312E+01*T_evap+2.63095238E-01*T_evap^2&
+3.48484848E-03*T_evap^3-1.58900227E-01*T_cond*T_evap
$CheckUnits On
Either option should result in the Solutions Window shown in Figure 2-14(b).
Interpolation in EES is accomplished using data provided in a Lookup Table. For example, the
data in Table 2-1 are entered in the Lookup Table shown in Figure 2-1. The Interpolate1,
Interpolate2, and Interpolate3 functions in EES provide 1-D interpolation using linear, quadratic,
and cubic interpolation methods, respectively. The Interpolate function is identical to the
Interpolate3 function and uses cubic interpolation. The calling protocol for each of these
functions is the same:
The string variable or constant 'Table Name' corresponds to the name of the Lookup Table to use
for the interpolation. The string variables or constants 'Dependent Variable' and 'Independent
Variable' correspond to the column header names associated with the dependent and independent
variables, respectively. The next argument specifies the value of the independent variable using
the numerical value or expression Value. If they are provided, EES For the Interpolate function to
work properly, it is necessary that the entries in the column containing the independent variable
vary monotonically (either increasing or decreasing). Arguments StartRow and StopRow are
optional. They can be provided as numerical constants or EES variables that have been
Chapter 2: Curve-Fitting and Interpolation 99
previously set. If they are provided, only the data in these rows will be used. Otherwise, all
rows in the Lookup table will be used.
To carry out cubic interpolation using the data in the Lookup Table 'Conductivity' use the
command:
T=311 [K] "Temperature"
k=Interpolate('Conductivity', 'Conductivity', 'Temperature', Temperature=T)
which returns k = 6.24 W/m-K. If the value of the independent variable lies outside of the range
included in the table, then the Interpolate commands will attempt to extrapolate but EES will
display a warning. For example, the code:
T=150 [K] "Temperature"
k=Interpolate('Conductivity', 'Conductivity', 'Temperature', Temperature=T)
will lead to the reasonable extrapolation k = 4.04 W/m-K, but it will also lead to the warning
shown in Figure 2-15 (provided that Display Warning Messages is selected in the Options tab of
the Preferences dialog).
Note that it is not necessary to load a Lookup Table into the EES program in order to use it as the
basis for interpolation. The string 'Table Name' can also refer to the name of an existing Lookup
Table that is stored in a file with an .lkt/.lkt64 file name extension. In this case, the .lkt/.lkt64
file name extension must be included in ‘Table Name’.
Interpolate2D('Table Name', 'Independent Variable 1', 'Independent Variable 2', 'Dependent Variable',
Independent Variable 1 = Value1, Independent Variable 2 = Value2)
The parameter 'Table Name' refers to the Lookup Table where the data are stored (again, either in
the EES program or in a disk file). The parameters 'Independent Variable 1' and 'Independent
Variable 2' are the column headings corresponding to the two independent variables while the
parameters 'Dependent Variable' is the column heading corresponding to the dependent variable.
For example, the following code uses the Interpolate2D function in conjunction with the
CompressorMap.lkt Lookup Table shown in Figure 2-9:
T_evap=42 [F]
T_cond=72 [F]
m_dot=Interpolate2D('CompressorMap', 'T_cond', 'T_evap','m_dot' , T_cond=T_cond, T_evap=T_evap)
and leads to m = 3561 lbm/hr; this value is similar to the value obtained using the linear
regression curve fit ( m = 3550 lbm/hr) at the same conditions in Figure 2-14.
The Interpolate2D function will accept a seventh, optional parameter, N, that controls the
interpolation algorithm. If N is less than zero then the default method, bi-quadratic interpolation,
is used. If N is greater than zero then a multi-quadric radial basis function interpolation method
is used. The absolute value of the variable N sets the maximum number of data points that are
used in the interpolation process. For example, if N is set to -32 then bi-quadratic interpolation
with 32 data points will be used but if N is set to 32 then multi-quadric radial basis functions with
32 data points will be used. If N is not specified then 16 data points are used. More data points
will lead to more accurate results, but the interpolation process will be more computationally
intensive. The minimum number of data points that can be specified is 8 or the number of data
points in the table. In order to use radial basis functions with 32 data points, enter the following
equation:
T_evap=42 [F]
T_cond=72 [F]
m_dot=Interpolate2D('CompressorMap', 'T_cond', 'T_evap','m_dot' , &
T_cond=T_cond, T_evap=T_evap, 32)
are the values of the dependent variable at each unique combination of independent variables; for
example, the mass flow rate at Tevap = 35ºF and Tcond = 100ºF is m = 2700 lbm/hr.
The variable 'Table Name' again refers to the name of the Lookup Table or Lookup file on disk.
The values of the two independent variables follow; Independent Variable 1 Value is the value of
the independent variable that defines the individual columns (e.g., the condenser temperature in
Figure 2-16) and Independent Variable 2 Value is the value of the independent variable that defines
the individual rows (e.g., the evaporator temperature in Figure 2-16). The EES code:
T_evap=42 [F]
T_cond=72 [F]
m_dot=Interpolate2DM('CompressorMapMatrix',T_cond,T_evap)
provides m = 3569 lbm/hr, which is similar to the value obtained using the Interpolate2D function.
3 FUNCTIONS AND PROCEDURES
An EES function is a code segment that accepts one or more inputs and returns a single result
associated with the Function name. An EES procedure is similar to a function, but it can return
one or more results and it is accessed by the Call statement. The code that is employed in
functions and procedures is dramatically different from the code used in the main part of an EES
program; functions and procedures utilize assignment statements rather than equalities.
Functions and procedures provide several important advantages. First, they make it easier to
program a large model by allowing the code to be broken up into a number of smaller parts that
are each easier to understand and debug. Second, EES functions and procedures allow the use of
programming logic statements, such as If-Then-Else, Repeat-Until and GoTo statements, which
cannot be used in the main body of EES. Third, functions and procedures can be saved in a file
after they have been debugged and verified, allowing them to be re-used in other EES programs
or in a library file, as explained in Chapter 11. This chapter presents the basic capabilities of
functions and procedures. Subprograms and modules share some of the advantages of functions
and procedures but utilize equations rather than assignments as discussed in Chapter 10.
This statement can not be a valid equation, since the variable X can never equal X + 1. If you
enter this statement into the EES Equation Window, it will attempt to solve it numerically, using
the methods described in Section 5.1. With the default stopping criteria, EES will find a solution
of X = 5x1017. With this value of X, the residual (which is related to the difference between the
left and right sides of the equation) is smaller than the default tolerance; therefore, it appears to
EES to be a valid solution. However, this is probably not the solution that was intended.
The equation X = X+1 is an assignment statement. Assignment statements explicitly assign the
value of the variable on the left side of the equal sign (in this case X) to the value of the
expression on the right side of the equal sign (in this case X + 1). All of the variables appearing
on the right side of the equal sign in an assignment statement must have previously defined
values. For example, if the current value of X is 8 then the execution of this assignment
statement would change it to be 9.
Chapter 3: Functions and Procedures 103
X:=X+1
This requirement has been relaxed in current versions of EES by the implementation of the
option Allow = in Function/Procedure equations that can be selected in the Options tab of the
Preferences dialog as shown in Figure 3-1. This option is selected by default and it causes EES
to accept both the equal sign and the assignment operator in functions and procedures.
Figure 3-1: Preferences dialog showing the option that allows the = sign for assignment statements.
Assignment statements are much more structured than equations. Each statement entered in a
function or procedure must be arranged so that the variable that is being assigned a value appears
by itself on the left side of the statement. The statements are executed in exactly the order that
they are entered. A major advantage of assignment statements is that they allow the use of logic
constructs, such as If-Then-Else statements, as described in Section 3.4.
3.2Functions
Internal EES functions can be written directly in the Equations Window. External functions can
be written in any compiled language, as discussed in Chapter 19.
Format of Functions
Internal functions must be formatted as shown below:
104 Chapter 3: Functions and Procedures
Assignment statement(s) - note that one of these must have the form:
Function_Name = ...
End
Function declarations must appear at the top of the Equations Window, before any of the
equations in the main body of the EES program. Function declarations must begin with the
keyword Function. The function name (Function_Name) and arguments (Input 1, etc.) follow on
the same line. The arguments are enclosed in parentheses and separated by a list delimiter
(which is the comma for the U.S. system and the semicolon for the European system). The
function declaration is terminated by the keyword End. The statements appearing in functions
(and procedures) must be assignment statements (as discussed in Section 3.1) or logic statements
(discussed in Section 3.4). EES processes these statements in the order that they appear unless
directed otherwise by the logic statements.
A function must have at least one argument and it must be called with the same number of
arguments that appear in the Function declaration. The names of the arguments in the calling
statement need not match the name of the arguments in the function declaration; only their order
matters. The statements within the function can only refer to variables that are passed to the
function as input arguments or previously defined within the function itself. All variables used
in the body of a function are local to the function except global variables in the main body of an
EES program that have been defined using the $Common directive, which is described in Section
14.3. Functions return the value assigned in the statement Function_Name = ... in the function
body.
Functions may refer to any other built-in function, procedure, or other program entities that have
been loaded using a library file (see Chapter 11). However functions cannot call themselves, i.e.,
they cannot be used recursively. Functions may not call a module but they may call
subprograms (described in Chapter 10). Functions (and procedures) MUST use the unit system
settings that are set in the main program. Different unit system for each function or procedure
can not be specified.
16
1.5 1/12
12 16
f = 8 8 + 37530
+ 2.457 ln
1 (3-1)
0.9
Re 7 + 0.27 RR Re
Re
The function that returns the friction factor f will be called f_Darcy. A listing of the function
follows.
The Function should appear at the top of the Equations Window, before any of the equations in
the main section of the EES program. The Function is accessed by its name with values
provided for Reynolds number and relative roughness. The following code, entered after the
function declaration:
will result in the Solution Window shown in Figure 3-2(a). Notice that in addition to the Main
tab that shows the variables in the Equations Window there is now a second tab with a label that
corresponds to the function workspace. Selecting the f_Darcy tab brings up the Solutions
Window shown in Figure 3-2(b), which contains the values of the variables in the function
workspace during the last call to the function.
(a) (b)
Figure 3-2: Solutions Window showing (a) Main and (b) f_Darcy tabs.
106 Chapter 3: Functions and Procedures
RT a
P= (3-2)
( v - b) v ( v + b ) + b ( v - b)
For the fluid of interest, the parameters in the Peng-Robinson equation of state are R = 188.9
J/kg-K, a = 70.89 N-m4/kg2 and b = 0.0006059 m3/kg. The function is named PR and placed at
the top of the Equations Window:
Function PR(v,T)
R = 188.9 [J/kg-K]
a = 70.89 [N-m^4/kg^2]
b = 0.0006059 [m^3/kg]
PR = R*T/(v-b)-a/(v*(v+b)+b*(v-b))
End
Note that the units of the constants are specified within square brackets, as discussed in Section
1.5. The function PR is called in order to estimate the pressure at v = 0.1 m3/kg and T = 325 K
with the following code:
(a) (b)
Figure 3-3: (a) Main tab of the Solutions Window showing unit warnings and (b) PR function tab showing
units set for each variable.
Chapter 3: Functions and Procedures 107
Notice that even with the units of all of the variables in the Equations Window set correctly, EES
is still reporting several possible unit problems. Select Check Units in order to view the Check
Units dialog shown in Figure 3-4. The unit warnings result from the fact that the units of the
variables used within the PR function workspace have not been set and are therefore inconsistent
with each other and also inconsistent with the units of the arguments passed back and forth
between the function and the Equations Window. EES checks the unit consistency of the
variables in functions and procedures (and modules and subprograms, discussed in Chapter 10)
as well as the variables in the Equations Window. Select the PR tab in the Solutions Window
and specify the units of each of the variables in the PR workspace, as shown in Figure 3-3(b).
Note that the units of each of the variables internal to the PR workspace (a, b, and R) as well as
the input arguments (v and T) and the output (PR) must all be set to avoid unit consistency
warning .
No array variables are used in Function PR. If they were used, the Show array variables check
box at the upper left of dialog in Figure 3-5 would be enabled. If a check appears in the box,
then the individual array elements, e.g., x[1], appear in each row and variable information can be
changed for each element. If the check is removed, only the array name is displayed, e.g., x[].
Changes made to the variable information for the array are applied to all current elements in the
array.
108 Chapter 3: Functions and Procedures
Changes to variable information for an entire array can also be accomplished using the $VarInfo
directive by providing the array name followed by open and close brackets, [], The following
example sets the guess, lower and upper bounds and the units for all elements of the T array.
3.3Procedures
EES procedures are very much like EES functions, except that they allow multiple outputs and
must be accessed using the Call command.
Format of Procedures
The format of a procedure is shown below:
Assignment statement(s) - note that some of these must have the form:
Output 1 = ...
Output 2 = ...
...
Output M = ...
End
Procedure declarations must appear at the top of the Equations Window together with any
function declarations and they must begin with the keyword Procedure. The procedure name
(Procedure_Name) and argument list follow on the same line. The argument list is enclosed in
parentheses. The first set of arguments are inputs (Input 1, Input 2, etc.); these are values that are
typically known and specified at the time that the procedure is called. The input list is
terminated by a colon that is followed by the output list (Output 1, Output 2, etc.). The outputs
must be calculated within the procedure body. The procedure is terminated by the keyword End.
Like functions, discussed in Section 3.2, the code used to write procedures must be assignment
statements or logic statements. EES processes these statements in the order that they appear.
Following the Call command, the values of the output variables (Output 1, Output 2, etc.) will be
assigned by the procedure. A procedure must be called with the same number of inputs that
appear in the Procedure statement. However, it is not necessary to provide all of the outputs, as
explained below. The name of the arguments in the calling statement need not match the name
of the arguments in the Procedure statement; only their order matters. The arguments may be
constants, string variables, numerical variables, or algebraic expressions. Just as with a function,
the procedure has its own local workspace. Statements within the procedure cannot refer to
variables that are not passed to the procedure, previously defined within the procedure itself, or
defined to be global using the $Common directive.
Functions may refer to any other built-in function, procedure, or other program entities that have
been loaded using a library file (Chapter 11). However procedures, like functions, cannot call
themselves. Procedures may not call a module but they may call subprograms (described in
Chapter 10).
Example of a Procedure
We will illustrate the use of a procedure with a simple example that finds the product, ratio, sum
and difference (M, D, A, S) of two values (X and Y):
Call Test(33,44: Product, Ratio, Sum, Difference) "Call to the Test Procedure"
When this code is executed, EES will assign X and Y in Procedure Test to be 33 and 44,
respectively. It will evaluate each of the four outputs and assign them to the four values in the
output list: Product, Ratio, Sum, and Difference. A tab in the Solutions Window shows the
variables in the Main Equations Window and the workspace for the procedure Test, as shown in
Figure 3-6.
110 Chapter 3: Functions and Procedures
(a) (b)
Figure 3-6: Tabs in the Solution Window for (a) Main Equation Window and (b) the workspace for the
procedure Test.
Note that is it not necessary to provide variables for every output. If for example, you only want
to have Procedure Test return Sum, the Call statement can appear as:
Call Test(33,44: {Product}, {Ratio}, Sum, {Difference}) "Call to the Test Procedure to return Sum"
or
Note that the appropriate number of list separators (commas for the English system and
semicolons for the European system) must be provided.
Although a procedure is normally written to accept inputs and return outputs, it is also possible
to call the procedure from the Equations Window, subprogram, or module by supplying it with
some of the output values in order to have it calculate one or more of the input values. This is
possible because EES interprets the procedure as a set of equations relating each output to the
inputs. Therefore, it will attempt to solve the resulting set of equations iteratively. For example,
the procedure Test could be called in the following manner:
Call Test(X, Y: Product, Ratio, 88, 32) "Alternative call to the Test Procedure"
In this case, the values of the last two outputs are specified. These outputs are the sum and
difference of the inputs, X and Y. EES will attempt to determine the values of the inputs X and Y
that provide the specified outputs, using iteration if necessary. After solving, the Solution
window will appear as shown in Figure 3-7.
Figure 3-7: Solution window showing local results for Procedure Test.
Chapter 3: Functions and Procedures 111
When a procedure is called from within a function or another procedure, it is interpreted as a set
of assignment statements, one for each output. In this case, it is not possible to provide values
any of the outputs in order to determine one or more of the inputs.
Like EES functions, procedures can be saved separately and used in other EES programs. The
most convenient way to do this is to save the procedure as a library file, as detailed in Chapter
11. EES supports both internal and external procedures. Internal procedures are entered directly
at the top of the Equations Window, as described in this section. External procedures are written
in a high-level language such as C, Pascal, or FORTRAN and called from EES. The Call
statement for both types of procedures is identical. Chapter 19 provides instructions for writing
and using external functions and procedures.
3.4Logic Statements
A major advantage of the assignment statements that are used in EES functions and procedures is
that they can include logic statements in order to control the order of the execution of the
assignment statements. EES functions and procedures recognize several types of logic
statements, as described in this section. These logic statements can not be used in modules,
subprograms or in the main body of an EES program.
If-Then-Else Statements
The most common logic statement is the If-Then-Else statement. EES provides two formats for
these types of statements, which are referred to as the single-line and the multiple-line formats.
The single-line format has the following form:
The Then keyword and Statement 1 are required. Statement 1 can be either an assignment
statement or a GoTo statement, as described below. The Else keyword and Statement 2 are
optional. A single-line If-Then-Else statement must be placed on one line with no line breaks;
however, there is no limit on the number of characters that can be used in this line.
The major difference between these two formats is that the multiple-line format allows one or
more assignment statements or logic statements to be executed depending on the result of the
Conditional Test, whereas the single-line format allows only one statement to be executed. The
Else and EndIf keywords appearing in the multiple-line format must each appear on a line by
itself, as shown above. Indentation can be used to make the logic flow more clear. Multiple-line
112 Chapter 3: Functions and Procedures
If-Then-Else statements can include additional If-Then-Else statements, which provides nested
conditional evaluation.
The Conditional Test yields either a true or false result using relational operators. The relational
operators recognized by EES are summarized in Table 3-1.
The parentheses around the conditional test are usually optional, but they are recommended for
reading clarity. However, there are situations in which the parentheses are required in order to
obtain the intended result. EES processes the logical operations from left to right unless
parentheses are provided in order to change the parsing order. Note that the parentheses around
the (x>0) and (y<>3) are required in the following single-line If-Then-Else statement in order to
override the default left to right logical processing order:
All variables (except string variables) used in EES are represented with real floating-point 10-
byte numbers that provide 20 significant figures of numerical precision. EES does not provide
integer data types. For this reason, care should be taken when using the = relational operator, as
two values may be quite close to one another, but not exactly equal. The <= or >= operators
should usually be used instead of the = operator. Alternatively the Round and Trunc functions
can be used to ensure that a value is exactly equal to an integer. String variables should be
compared with the = operator.
Return Statements
The Return statement can only be used within functions and procedures. When EES encounters a
Return statement, it will exit the function or procedure and control will resume at the point where
the function or procedure was called. The Return statement is used in logic constructions with
the If-Then-Else or Repeat-Until statements.
The following example develops a function named Nusselt which uses logic to provide the
appropriate value of the non-dimensional Nusselt number for fully-developed flow in a circular
pipe subjected to a constant heat flux given the Reynolds number (Re), Prandtl number (Pr), and
Chapter 3: Functions and Procedures 113
the relative roughness (RR). The function uses correlations presented in Nellis and Klein
(2009)1. For laminar flow (Re < 2300), the Nusselt number is a constant:
Nu = 4.36 (3-3)
The function begins by assigning Nusselt a value consistent with laminar flow and the using the
Return statement to return to the main program if Re < 2300.
For turbulent flow (Re > 2300), the friction factor is computed according to:
2 RR + 13
2
f = 2.0 log 2 RR 5.02 (3-4)
10
Re
10
log
7.54 Re
7.54
and used to compute the Nusselt number according to the Gnielinski correlation:
f
( Re 1000 ) Pr
Nu =
8
(3-5)
( 2
1+12.7 Pr 3 1 8
f
)
Note that the Gnielinski correlation is only valid for 2300 < Re < 5x106. The function continues
by using Eqs. (3-4) and (3-5) to assign Nusselt a value that is consistent with turbulent flow. The
Return statement is used to return to the calling program if the Reynolds number is less than
5x106.
Finally, the function returns a value of -9 when the Reynolds number provided is greater than
5x106 in order to indicate that the correlation is not valid.
A much better way to handle this situation is to use the Warning or Error procedures, which are
described in Section 3.7. The function is tested at various Reynolds numbers:
1
Note that the Heat Transfer library, discussed in Chapter 12, provides a much more powerful version of this
function as well as other functions and procedures based on the Nellis and Klein Heat Transfer textbook.
114 Chapter 3: Functions and Procedures
GoTo Line#
where Line# is a statement label that must be an integer number between 1 and 30000. Statement
labels precede an assignment statement and are separated from the statement by a colon (:). A
statement label may also appear on a line by itself. The GoTo statement must be used with If-
Then-Else statements to be useful.
The following function illustrates the use of GoTo and If-Then-Else statements in the calculation
of the factorial of a value supplied as the argument.
Function Fact(N)
F:=1 "factorial"
i:=0 "counter"
10: i:=i+1 "increment counter"
F:=F*i "multiply factorial by counter"
If (i<N) Then GoTo 10 "see if counter has reached N"
Fact:=F "assign factorial"
End
The Fact function is tested and compared to the value returned by the built-in Factorial function in
EES.
Y= Fact(7) "Fact(7)=5040"
Y2=Factorial(7) "EES built-in factorial function"
Chapter 3: Functions and Procedures 115
Repeat-Until Construct
Looping within functions and procedures can be implemented with If-Then-Else and GoTo
statements described above. However, it is generally more convenient and readable to use a
Repeat-Until construct. The Repeat-Until construct has the following format.
Repeat
Statement(s)
...
Until (Conditional Test)
The Conditional Test is the same type of conditional test used in If-Then-Else statements. The Fact
function written above using a GoTo statement can be implemented more simply using a Repeat-
Until construct, as shown in the following example:
Function Fact(N)
Fact:=1 "factorial"
If (N=0) then Return "check for N=0"
Repeat
Fact:=Fact*N "start with argument"
N:=N-1; "decrement argument by one"
Until (N<=1)
End
Note the use of the Return statement to terminate the function in the event that the argument is
zero. The Repeat-Until construct can only be used in functions and procedures.
Case Statements
Case statements provide logical operations and they are similar to If-Then-Else statements in this
respect. Like If-Then-Else and Repeat-Until statements, CASE statements can only be used in EES
Functions or Procedures. CASE statements are much more convenient to use than nested If-Then-
Else statements when the logic control must select from multiple options.
The Case statement must be followed on the same line with the Case decision variable, which
may be an EES numerical (e.g., X) or string variable (e.g., X$). The Case options are identified
with Case labels followed by a double colon (::). If the Case decision variable is an EES
numerical variable, the Case labels must be integers. If the Case decision variable is a string
variable, the Case labels must be string constants surrounded by single quotes. An equation is
normally placed on the same line after the Case label. Additional equations may follow and
these equations will be executed if the Case variable matches the Case label. An Else label may
optionally be used (without quotes) with either the numerical or string versions. Control will
transfer to the first equation after the Else keyword if the Case variable does not match any of the
Case lables.An ENDCASE keyword is used to finalize the Case statement.
116 Chapter 3: Functions and Procedures
Case statements may not be used in a nested manner. The following simple example of the Case
statement using a numerical case variables illustrates the syntax of the Case statement.
FUNCTION TESTCASE(V)
CASE V
1:: X=V+41
Y=SQRT(X)
TESTCASE=X+Y
3:: TESTCASE=V^2
5:: GOTO 3
else:: Call Error('V must be 1, 3, or 5. A value of XXXF0 was provided.',V)
ENDCASE
Return
3: TESTCASE=3
END
G=TESTCASE(1)
A more useful example of the Case statement, as well as other EES capabilities, are employed in
the next example. This example includes a Procedure to calculate the coefficient of performance
(COP) and refrigerating capacity (Capacity) for different types of refrigeration compressors
based on the ANSI/AHRI 540 performance rating standard. See the listing of this program
below. The Procedure expects the following inputs:
Type$: a string variable that provide the identifier for the compressor. Here the compressors
are labeled as 'A', 'B', or 'C', but any identification string could be used.
Unit$: A string variable that is either 'SI' or 'ENG'. The empirical relations used in the
procedure are based on the English system with temperatures in °F and capacity in
Btu/hr. However, by supplying Unit$, the procedure can automatically convert units
so that temperatures can be provided in °C and Capacity is output in kW.
T_S: The refrigerant suction temperature in °F or °C, depending on Unit$.
T_D: The refrigerant discharge temperature in °F or °C, depending on Unit$.
Procedure Ansi540 returns the COP and Capacity (in Btu/hr or kW, depending on Unit$).
If (Units$='SI') Then
T$='F'
Chapter 3: Functions and Procedures 117
Cap$='kW'
Else
T$='F'
Cap$='Btu/hr'
Endif
T_Sc=converttemp(T$,F,T_S) "convert temperatures to F for use with the ANSI/AHRI 540-2004
coefficients"
T_Dc=converttemp(T$,F,T_D)
Case Type$
'A':: CapCoef[1..10]=[2.727E+04,4.569E+02,-9.822E+01,5.798E+00,1.351E+00,-1.063E-01,2.998E-
02,-2.456E-02,-1.467E-02,2.934E-04]
EERCoef[1..10]=[3.434E+01,7.155E-01,-5.268E-01,5.467E-03,-9.296E-03,3.492E-03,1.564E-
05,-4.482E-05,3.559E-05,-9.443E-06]
'B':: CapCoef[1..10]=[2.434E+04,5.720E+02,-1.077E+02,5.664E+00,-2.115E+00,4.378E-01,1.694E-
02,-2.336E-02,2.218E-03,-2.310E-03]
EERCoef[1..10]=[3.234E+01,7.407E-01,-4.776E-01,5.702E-03,-9.813E-03,3.129E-03,1.693E-
05,-4.763E-05,3.910E-05,-8.669E-06]
'C':: CapCoef[1..10]=[3.022E+04,6.132E+02,-2.130E+02,7.160E+00,-2.341E+00,1.326E+00,2.389E-
02,-3.973E-02,2.311E-03,-5.177E-03]
EERCoef[1..10]=[3.434E+01,7.155E-01,-5.268E-01,5.467E-03,-9.296E-03,3.492E-03,1.564E-
05,-4.482E-05,3.559E-05,-9.443E-06]
else:: Call error('ANSI/AHRI 540-2004 coefficients are not available for compressor type
XXXS1.',Type$);
Endcase
$CheckUnits Off {don't check units for these empirical equations}
{Note that & in following statements allows equation to continue on following line.}
Cap=CapCoef[1]+CapCoef[2]*T_Sc+CapCoef[3]*T_Dc+CapCoef[4]*T_Sc^2+&
CapCoef[5]*T_Sc*T_Dc+CapCoef[6]*T_Dc^2+CapCoef[7]*T_Sc^3+CapCoef[8]*T_Dc*T_Sc^2+&
CapCoef[9]*T_Sc*T_Dc^2+CapCoef[10]*T_Dc^3
EER=ERCoef[1]+ERCoef[2]*T_Sc+EERCoef[3]*T_Dc+EERCoef[4]*T_Sc^2+&
EERCoef[5]*T_Sc*T_Dc+EERCoef[6]*T_Dc^2+EERCoef[7]*T_Sc^3+&
EERCoef[8]*T_Dc*T_Sc^2+EERCoef[9]*T_Sc*T_Dc^2+EERCoef[10]*T_Dc^3
COP=EER*convert(Btu/W-hr,'-')
$CheckUnits On
Capacity=Cap*convert(Btu/hr,Cap$) "convert to user-specified unit system"
End
$ifnot ParametricTable
Type$='B'
Units$='Eng'
T_S=20 [F]
T_D=110 [F]
$endif
Call ansi540(Type$, Units$, T_S, T_D : COP, Capacity)
A Case statement, with Type$ as the Case variable string is used to set the 10 coefficients
required in the empirical fits for capacity and EER for each compressor type. Note the
coefficient arrays are entered using a shorthand array notation. If Type$ is not 'A', 'B', or 'C',
control transfer to the Else label and an error is thrown and the program will stop.
An If-Then-Else is used at the start of the program to set string variables T$ and Cap$. The units
of variables T_S and T_D are set to T$ and the units of Capacity are set to Cap$ with the
Variable Information dialog, as shown in Figure 3-9.
118 Chapter 3: Functions and Procedures
Unit checking is disabled with the $CheckUnits Off directive for the empirical equations for
capacity and EER. Otherwise appropriate units would need to be supplied for the coefficients.
Function PR(v,T)
R = 188.9 [J/kg-K]
a = 70.89 [N-m^4/kg^2]
b = 0.0006059 [m^3/kg]
PR = R*T/(v-b)-a/(v*(v+b)+b*(v-b))
End
In some cases, you may not know the units of the variables in a function or procedure until it is
executed. The PR function above, for example, is written with the expectation that it will be
called with the EES unit system configured for standard SI units of m, K, J, and Pa. It would be
nice to be able to have this function work properly when called from an EES program that is
using any set of units. This is particularly important for those functions or procedures that are
placed in libraries. This capability can be implemented using the UnitSystem$ function.
Unit$ = UnitSystem$(Dimension$)
Chapter 3: Functions and Procedures 119
where Dimension$ is a string containing the dimension of interest. The UnitSystem$ function
returns the string Unit$ containing the expected units of the dimension for the unit system settings
that EES is configured to work in. The unit system settings can be specified as discussed in
Section 1.5 using either the $UnitSystem directive in the Main body of the EES program or the
Unit System tab of the Preferences dialog.
Let's rewrite function PR so that it operates correctly regardless of the unit system that EES is
configured to use. First, the UnitSystem$ function is used to determine the units that are
associated with specific volume, temperature, and pressure.
Function PR(v,T)
"Obtain the unit settings in EES"
v$=UnitSystem$('Volume') "V$ is the specific volume units that EES is set to"
T$=UnitSystem$('Temperature') "T$ is the temperature unit that EES is set to"
P$=UnitSystem$('Pressure') "P$ is the pressure units that EES is set to"
Next, the values of the specific volume and temperature are converted from the unit system that
EES is currently configured to work in (i.e., the units of the inputs v and T) to the base SI units
required to implement the Peng-Robinson equation of state (v_SI and T_SI). This conversion is
accomplished using the convert and converttemp functions using the strings v$ and T$.
The calculations are carried out in base SI units, as before, in order to obtain the pressure
predicted by the Peng-Robinson equation of state in base SI units (PR_SI).
Finally, the pressure is converted to the unit system expected by EES based on the current unit
system settings. This is accomplished using the convert function and the string P$:
The function can now be used with any EES unit settings. For example, in the code below the
units are set to the English unit system.
The units of the variables in the PR function workspace should be set in the appropriate page of
the Variable Information Window, as shown in Figure 3-10.
Note that the units for variables such as a, b, and T_SI can all be set in a straightforward way
because they are unambiguous; these are variables that will be in base SI units regardless of the
EES unit settings. However, there is no way in general to know the units of variables such as v,
T, and PR as these variables will have units that are consistent with the unit settings in EES.
Therefore, the units for these variables are set using the strings v$, T$, and P$, respectively, so
that they will automatically adjust based on the current EES unit settings.
Arrays as Arguments
Shown below is a short function that is designed to calculate the sum of the squares of all of the
elements in the array A[] that is provided to it as the second argument. The number of elements
in the array is provided as the first argument to the function. Note that array range notation, i.e.,
[1..N], is used to indicate all of the array elements between index 1 and index N. The function
SumSquares uses a Repeat-Until construct to loop through all of the elements and sum their
squares.
There are, however, several potential problems with this code. For example, if you change N
from 5 to 150, you will see the error message shown in Figure 3-11.
Figure 3-11: Error message that appears when you try to call the function SumSquares with N = 150.
Why did EES solve this program when N = 5 but not when N = 150? The explanation for this
problem requires an understanding of how EES handles the equations that are entered in the
Equations Window. All equations in EES are compiled; that is, they are translated into an
internal form that minimizes the computational effort required to evaluate them. EES starts at
the top of the Equations Window and compiles the equations one by one. The Equations
Window starts with the function declaration for SumSquares. However, EES cannot possibly
know the value of N that will be provided to the function as an argument. Without knowing the
value of N, EES cannot compile the equations that define the function.
When EES does not know the value of an array index limit, it will assume that it is 100 by
default. The A[1..N] appearing in the function declaration for SumSquares is therefore interpreted
to be A[1..100] when the function is compiled. Any value of N that is less than or equal to 100
will work properly when this function is called, but the function fails when N is greater than 100.
There are several ways to solve this problem. First, we can change the default for the array size
that EES uses with a $DefaultArraySize directive. For example, if we add the following
directive to the top of the Equations window for the program listed above will run as expected.
$DefaultArraySize=150.
122 Chapter 3: Functions and Procedures
Alternatively, we could change the upper limit of the array index to be 150 in the function
declaration.
Now, the program will solve when N is set to 150 or any value that is less than or equal to 150
because EES is reserving 150 elements for array A in the function. Note that the upper array
index does not need to equal the size of the array provided to the function in the calling program
(although that is desirable). It only has to be greater than the size of the array provided by the
calling program. The maximum allowable array size that can be passed to a function in this
manner is 2000 in the current implementation of EES.
Function SumSquares(N)
$Common X[1..150] "provides read-only access to the array X[]"
S:=0 "initialize sum"
i:=1 "initialize index"
Repeat
S:=S+X[i]^2 "sum the square of each element"
i:=i+1 "increment the element"
Until (i>=N) "stopping condition"
SumSquares:=S "set the Function name to the calculated value"
end
This method of passing information to a function is also not convenient because the value of N is
not adjustable. If the upper limit is set to 200 in the $Common directive, an error message will be
issued. Similarly if N is changed to 50 in the calling program then an error message will be
issued. The above example requires N to be changed in both the Main program and the function
if its value is changed.
Chapter 3: Functions and Procedures 123
Function SumSquares(A[1..N#])
S:=0 "initialize sum"
i:=1 "initialize index"
Repeat
S:=S+A[i]^2 "sum the square of each element"
i:=i+1 "increment the element"
Until (i>=N#) "stopping condition"
SumSquares:=S "set the function name to the calculated value"
end
duplicate i=1,N#
X[i]=i "set the value of the array elements"
end
SS=SumSquares(X[1..N#]) "Call the sum of squares function"
The following example computes the temperature of an object that is initially at Tini and is
subjected to convection and radiation from an environment at T∞. The surface area of the object
is As and the total heat capacity is C. The convective heat transfer coefficient is h and the object
is assumed to have an emissivity of = 1. Assuming that the object is at a uniform
temperature, the time rate of change of its temperature is given by:
( ) ( 4 4
)
dT As h T T + As T T
= (3-6)
dt C
coefficient (h_bar), surface area (A_s), initial temperature (T_ini), ambient temperature (T_infinity),
heat capacity (C), and the total number of time steps (N).
duration (3-7)
t= N
The temperature at the initial time (T1) is the initial temperature and the initial time (time1) is
zero. The index of the time step (i) is initially set to 1.
Each time step is taken using a Repeat-Until construct. Within the construct, the time at index i+1
is computed:
The use of the Euler technique to integrate Eq. (3-6) leads to the temperature at index i+1:
A h (T T ) + A (T 4 T 4 )
i t
Ti+1 = Ti +
i s
(3-9)
s C
Repeat
time[i+1]=time[i]+Dtime
T[i+1]=T[i]+(A_s*h_bar*(T_infinity-T[i])+A_s*sigma#*(T_infinity^4-T[i]^4))*Dtime/C
i:=i+1
Until(i>N)
Temp=T[N+1]
End
N=5 [-]
duration=100 [s] "duration of process"
h_bar=100 [W/m^2-K] "heat transfer coefficient"
A_s=0.01 [m^2] "surface area"
T_ini=300 [K] "initial temperature"
T_infinity=500 [K] "ambient temperature"
C=100 [J/K] "total heat capacity"
T_final=Temp(duration, h_bar, A_s, T_ini, T_infinity, C, N) "final temperature"
which leads to the result T_final = 449 K. Note that the units for the variables used in the
function Temp can be set most easily be selecting the option Function TEMP from the drop down
menu in the Variable Information dialog and then de-selecting the Show array variables option.
In this way, all of the units in the arrays T[] and time[] can be specified at the same time, as shown
in Figure 3-12.
Figure 3-12: The Function TEMP page of the Variable Information dialog.
The arrays T[] and time[] are not passed from the function workspace back to the EES program.
The array variables from the last call to the function are available by examining the Temp tab of
the Solutions Window, as shown in Figure 3-13.
There may be times when it is useful to plot the results contained in the arrays that are used
within a function or procedure. The array variables associated with the last call to function Temp
can be placed in a separate Arrays Table by placing the $Arrays On directive at the top of the
function.
$Arrays On
Dtime:= duration/N "Time step"
T[1]:= T_ini "initial temperature"
time[1]:=0
i:=1
Repeat
time[i+1]=time[i]+Dtime
T[i+1]=T[i]+(A_s*h_bar*(T_infinity-T[i])+A_s*sigma#*(T_infinity^4-T[i]^4))*Dtime/C
i:=i+1
Until(i>N)
Temp=T[N+1]
End
The Arrays Window for the Temp function is shown in Figure 3-14(a). The data stored in the
Arrays Window can be plotted, as shown in Figure 3-14(b). Note that the $Arrays Off directive
can be used to restore the array variables to the Solution Window.
(a) (b)
Figure 3-14: (a) Arrays Window for the Temp function and (b) temperature as a function of time.
Chapter 3: Functions and Procedures 127
The Lookup command was introduced in Section 1.8 as one of several ways to read data from an
existing Lookup Table or from a Lookup File stored on disk. For example, the equation
X=Lookup('Lookup 1', 3, 2)
will set the value of variable X to be the value found in the third row and second column of the
Lookup table named 'My Lookup Table'. Alternatively, the equation
X=Lookup('C:\EES_Stuff\myData.lkt', 3, 2)
will set the value of variable X to be the value found in the third row and second column of the
Lookup File previously stored in file C:\EES_Stuff\myData.lkt. A string variable can be used to
provide the file name, e.g.,
TN$='C:\EES_Stuff\myData.lkt'
X=LookupTN$, 3, 2)
The row and column numbers can be provided with EES variables. Further, the column can be
provided with a string constant or string variable that provides the name of the column. Access
to data with the Lookup command in this manner is available in the Main program, as well as in
Subprograms, Modules, Functions and Procedures.
However, Functions and Procedures can also use the Lookup command to write data to an
existing Lookup Table, which is not possible from the Main Program, Modules, or Subprograms.
The Lookup command is inverted to write data. For example, the following equation in a
Function or Procedure will write the current value of variable X in the third row, second column
of the Lookup table named 'My Lookup Table'.
More generally, the following code provides a general function that can be called from the Main
program or a Subprogram to write a value to a specified row and column in a specified Lookup
table. Note that a Lookup table with the specified name must exist in order for this code to work.
It is not possible to write data to a Lookup File (stored on disk).
Function writetolookup(T$,Row,Col,Value)
lookup(T$,Row,Col)=Value
writetolookup=Value
128 Chapter 3: Functions and Procedures
End
T$='Lookup 1' {Create a Lookup table named Lookup 1 with 2 columns and 20 rows before running}
Duplicate i=1,20
X[i]=writetolookup(T$,i,1,i)
Y[i]=writetolookup(T$,i,2,i^2)
End
Note that the $CopytoLookup directive, available in the Professional version, provides the same
capability without requiring the need to provide a function.
The Beep command is useful for signaling an event and for debugging The format of this
command is
Beep #
Print 'filename' x, y, z
Filename is the name of the text file into which the values of the designated variables will be
written. Filename can be a string constant or a string variable.
x, y, and z are names of variables within the Function or Procedure for which the values will be
written to the designated file. The Print command will allow one or more variable names to be
specified. The values of the variables appearing in the Print command must be defined before
the Print command is executed.
The Print command will write to the specified text file each time the Print command is executed,
creating a new row in the file output. The first column of each row will show the name of the
Function or Procedure followed by the number of times the Function or Procedure has been
called since the start of the calculations in parentheses. See Figure 3-16. The file will be
cleared at the start of the calculations unless the Print command is followed by the /A option. In
this case, the new information will be appended to the existing file; e.g.,
Print/A 'filename', x, y, z
Chapter 3: Functions and Procedures 129
The following function will output values of i, x, and y in text file 'C:\temp\text.txt'.
Warnings can also be enabled by placing a $Warnings On directive in the Equations Window or
by selecting the Display Warning Messages checkbox in the Options tab of the Preferences
130 Chapter 3: Functions and Procedures
dialog. Placing a $Warnings Off directive before an equation will ensure that it will not generate
a warning message.
The Warning procedure can be called with a warning string provided according to:
where the string would contain a descriptive message about the problem. In this case, EES will
generate the warning message contained in the string. The Warning procedure can also be called
with both a warning string and a numerical variable, according to:
where Y is a number or a numerical variable. In this case, the characters XXX in the string will be
replaced with the value of the parameter Y. If a formatting option (e.g., F1 for fixed decimal with
one significant figure in the call above) follows the characters XXX then the display of the
variable Y will be formatted accordingly. If no format is supplied, automatic format is assumed.
The Warning procedure can be called with a warning string and a string variable, according to:
where Y$ is a string variable. In this case, the string contained in Y$ will replace the characters
XXX$ when the warning is issued. Finally, the Warning procedure can be called with only a
numerical variable:
In this case, EES will generate the following generic warning message: "A warning message was
issued due to the value XXX in ZZZ." Where the characters XXX will be replaced with the value of
Y and the characters ZZZ will be replaced by the name of the function or procedure in which the
Call Warning statement appears.
As an example, a call to the Warning procedure has been added to the Nusselt function that was
presented in Section 3.4. The Warning procedure is called if the Reynolds number provided by
the user is outside of the range of the correlation.
will display the warning shown in Figure 3-18 (provided that warnings are enabled).
Figure 3-18: Warning message displayed when function Nusselt is called with Re = 6e6.
The calculations will complete and the Solutions Window will indicate that the value of the
variable Nu#_outofRange has been set and that 1 warning was issued, as shown in Figure 3-19.
Call Error ('Reynolds number must be <= 5e6 in Function Nusselt. &
A value of XXXE2 was provided', Re)
then the error message shown in Figure 3-20 will be displayed when the solve command is
issued.
132 Chapter 3: Functions and Procedures
Figure 3-20: Error message displayed when calling Function Nusselt with Re = 6e6.
Clicking the Traceback button will show the line that initiated the error message provided that
the code is contained in the Equations Window rather than in a library file stored on disk
References
Churchill, S.W. 1977, 'Friction Factor Spans All Fluid Flow Regimes,' Chem. Eng. (Rugby,
U.K.) 84(24), pp.91-91.
Klein, S.A. and Nellis, G.F., Thermodynamics, Cambridge University Press, New York, (2012).
Nellis, G.F., and Klein, S.A, Heat Transfer, Cambridge University Press, New York, (2009).
4 PROPERTY DATA
Historically, thermodynamic and transport property data for fluids were provided in tabular and
graphical forms. You do not have to solve many engineering problems before the limitations
associated with the use of tabular or graphical property information become evident. Looking up
property values in tables usually requires either single or double interpolation. The process is
time-consuming and likely to introduce mathematical errors. Graphical property data do not
require interpolation, but using these graphs is tedious and the accuracy of the data is limited. It
is not easy or even practical to carry out the parametric studies that are required for optimization
or design using tabular or graphical property information.
EES provides high accuracy thermodynamic and transport thermophysical property data for
many substances. These data are accessed with the built-in property functions described in this
chapter. These property functions, integrated with the equation solving and plotting capabilities,
make EES a useful tool for engineering calculations in which property data are required.
4.1Unit System
It is necessary to specify the unit system that EES will use for the thermodynamic and transport
property functions. The unit system controls both the units of the input parameters that EES
expects for variables provided to the property functions as well as the units of the properties that
are returned by the functions.
m
n= (4-1)
MW
The molar base unit in EES is the kmol in SI units and the lbmol in English units.
$UnitSystem SI Mass [or Mole] Deg [or Rad] Pa [or kPa, bar, MPa] C [or K] J [or kJ]
Notice that each of the selections required by the user in the Unit System dialog, shown in Figure
4-1, can be made using the $UnitSystem directive. As an example, the following line placed in
the Equations Window will set the EES unit system to standard SI units with temperature in K,
pressure in Pa, and energy in J. Specific properties are expressed on a mass basis and
trigonometric functions will expect and return angles in radians.
The selections can be made in any order. The $UnitSystem directive in English units has the
following format:
$UnitSystem Eng Mass [or Mole] Deg [or Rad] psia [or atm] F [or R]
Mixed SI/English unit system specifications are not allowed. Each specification in the
$UnitSystem directive is separated with a space. It is not necessary to enter all of the units,
although it is good practice to do so. The $UnitSystem directive is normally placed at the top of
the Equations Window. If a $UnitSystem directive is used, it will override any settings that are
made with the Unit System dialog.
Normally, the $UnitSystem directive is placed at the top of the Main equations window.
However, Functions, Procedures, and Subprograms can each have separate unit setting by
Chapter 4: Property Data 135
placing a $UnitSystem directive within the program unit in the Equations window. If no
specification is provided, the unit settings for Functions, Procedures, and Subprograms are the
same as those for the calling program unit.
4.2Function Information
EES provides property information for many substances. The calling format and the number of
input parameters for the property functions depend on the nature of the substance and the type of
property. Some property functions (e.g., ammonia-water mixtures) are provided by external
programs (see Chapter 19) and these are called with a different format than is used for built-in
property functions. The format of all of the property functions can be examined by selecting
Function Information from the Options menu in order to access the Function Information dialog
shown in Figure 4-3.
There are seven radio buttons at the top of the Function Information dialog. The internal
property data functions that are the primary subject of this chapter are accessed by selecting the
Thermophysical properties radio button (shown in Figure 4-3). After this button is selected, a
palette showing six categories for the built-in property data will appear (Figure 4-3). The
property information for these categories are described in the following sections. Additional
property functions may be available by selecting either the EES library routines or External
routines buttons. Information on each of these alternatives is provided in the following sections.
136 Chapter 4: Property Data
FunctionName is the name of the property function being called; the name of the function
corresponds to the property that is returned. For example, the Enthalpy function returns the
specific enthalpy, the Volume function returns specific volume, etc. The first argument (Fluid$) is
a string that specifies the name of the fluid being considered. Two properties are required to fix
the state; the second and third arguments indicate which two properties are specified and their
values. Property1 is an indicator that identifies the first property that is specified and Value1 is the
value of that property (in the units specified by the unit system, as discussed in Section 4.1). If
Property 1 is T, then the temperature is specified, H indicates that the specific enthalpy is
specified. (See Table 4-3 for a list of the indicators that can be used with real fluids.) Property2
and Value2 are the indicator and value of the second property that is specified to fix the state.
The function will return the value of the property in the units specified by the unit system.
As a simple example, the code below determines the specific volume of the refrigerant R134a at
350 K and 250,000 Pa.
Solving provides v = 0.1108 m3/kg. Note that EES will check to ensure that the units of the input
temperature is K and the units of the input pressure is Pa, consistent with the $UnitSystem
directive. Further, EES will check that the units of variable v are set to m3/kg. If any of these
conditions are not met then a warning will be issued when the Check Units command is selected
from the Calculate menu. A warning will also be issued when the calculations are completed if
the Check Units Automatically option is selected in the Options tab of the Preferences dialog
(Options menu).
Table 4-1: Thermodynamic and transport property functions for ideal gas and real fluids and their units.
EES Function Name Returns SI Units English Units
AcentricFactor1 acentric factor none none
CompressibilityFactor compressibility factor none none
Conductivity thermal conductivity W/m-K Btu/hr-ft-R
Cp constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Cv constant volume specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Density density kg/m3 lbm/ft3
Dipole1 dipole moment Debye Debye
ek_LJ1 Lennard-Jones energy potential K R
Enthalpy8 specific enthalpy J/kg, kJ/kg Btu/lbm
Enthalpy_Formation7,8 Enthalpy of formation J/kg or kJ/kg Btu/lbm or lbmol
Enthalpy_fusion1,8 specific enthalpy of fusion J/kg, kJ/kg Btu/lbm
Enthalpy_vaporization4,8 specific enthalpy of vaporization J/kg, kJ/kg Btu/lbm
Entropy8 specific entropy J/kg-K, kJ/kg-K Btu/lbm-R
‘ideal’, ‘real’, ‘brine’,
FluidType$1 none none
‘incompressible’ or ‘mixture’
Fugacity fugacity Pa, kPa, bar, MPa psia, atm
HenryConstant_Water9 Henry's Law constant Pa, kPa, bar, MPa psia, atm
IdealGasThermoProps10 T, P, v, h, s, u n.a n.a
IntEnergy8 specific internal energy J/kg, kJ/kg Btu/lbm
IsentropicExponent5 -(v/p)(∂P/∂v)|s none None
IsothermalCompress -(1/v)( (∂v/∂P)|T 1/kPa, 1/Pa, etc. 1/psia, 1/atm
HigherHeatingValue7,8 Higher heating value J/kg or kJ/kg Btu/lbm or lbmol
LowerHeatingValue7,8 Lower heating value J/kg or kJ/kg Btu/lbm or lbmol
Pressure absolute pressure Pa, kPa, bar, MPa psia, atm
MassFraction Mass fraction for NH3H2O6 none none
MolarMass1 molecular weight kg/kmol lbm/lbmol
NormalBoilingPt1 normal boiling point °C, K °F, R
P_crit1 critical pressure Pa, kPa, bar, MPa psia, atm
P_melting3 melting pressure Pa, kPa, bar, MPa psia, atm
P_sat3 saturation pressure Pa, kPa, bar, MPa psia, atm
P_sublimation3 sublimation pressure Pa, kPa, bar, MPa psia, atm
Phase$ phase, e.g., ‘superheated’ none none
Prandtl Prandtl number none none
Quality quality none none
RealThermoProps10 T, P, v, h, s, u, x n.a. n.a.
sigma_LJ1 Lennard-Jones length potential m ft
SoundSpeed speed of sound m/s ft/s
SpecHeat8 constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
SurfaceTension3 surface tension N/m lbf/ft
T_crit1 critical temperature °C, K °F, R
T_sat2 saturation temperature °C, K °F, R
T_triple1 triple point temperature °C, K °F, R
Temperature temperature °C, K °F, R
v_crit1,8 critical specific volume m3/kg ft3/lbm
Viscosity viscosity kg/m-s lbm/ft-hr
VolExpCoef coefficient of thermal expansion 1/K 1/R
Volume8 specific volume m3/kg, ft3/lbm
Chapter 4: Property Data 139
1
The function requires only the name of the fluid.
2
The function requires the name of the fluid and the pressure.
3
The function requires the name of the fluid and the temperature.
4
This function requires either temperature or pressure
5
This function is implemented for fluids that use a high accuracy equation of state
6
See section 4.9 for NH3H2O
7
Only implemented for ideal gases, NASA gases and organic incompressible fluids.
8
Specific properties can be on a mass or molar basis, depending on the Unit System settings.
9
Returns the Henry's Law constant for a fluid in water solvent.
10
This procedure requires two inputs to fix the state and will return all thermodynamic properties.
The P_melting and P_sublimation functions provide the pressure at which a solid melts or sublimes, respectively,
as a function of temperature. Therese functions are provided for a subset of the real fluids, The fluids for which the
functions are available can be seen by clicking on the function name in the Funtion Information dialog (Figure 4-5).
The functions can be used to create a pressure-temperature diagram as shown in Figure 4-4 for water.
Figure 4-4: Pressure-temperature plot for water. Note the unusual behavior of the melting curve.
The procedure requires as inputs the name of the fluid and two specified property values (with
their property indicators) to fix the state, in the same manner as any of the real fluid property
functions. In this example, temperature and pressure are specified for fluid R134a. However, the
RealThermoProps procedure returns as outputs the temperature (T), pressure (P), specific
volume (v), specific enthalpy (h), specific entropy (s), specific internal energy (u) and quality (x)
in this order. It provides a coding shortcut that requires the user to enter fewer lines of code into
the Equations window to determine multiple property values at a single state.
Note that in the example above, the values for EES variables T and P have been set before the
RealThermoProps procedure is called. EES recognizes that the outputs (T and P) are the same as
the inputs and does not try to reassign them with an equation of the form T=T, which would
introduce an error. If the call were entered as,
The RealThermoProps procedure can be entered using the Function Information dialog in the
Options menu, as shown in Figure 4-5. Note that entering a state specification, such as [1]
shown in the box to the right of the example at the bottom of the dialog, will apply that
specification automatically to every EES variable in the example box. The text within the
example box can then be further edited as desired before clicking the Done button.
Figure 4-5: Using the Function Information dialog with the RealThermoProps procedure.
Chapter 4: Property Data 141
It is not necessary to provide EES variables for each of the outputs. Unwanted outputs can be
eliminated by leaving those spots blank in the output list. For example, if specific volume and
specific internal energy are not of interest, the call statement to the RealThermoProps procedure
can be written as:
Table 4-2: Names of the built-in real fluids and fluid mixtures.
Acetone Krypton R32 R454A4
Acetylene MDM R40 R454B4
Air_ha MD2M R41 R454C4
Ammonia MD4M R113 R455A4
Argon MM R114 1 R460A4
Benzene m-Xylene R115 R466A4
Butene Methane R116 R500 1, 4
CarbonDioxide Methanol R123 R502 1, 4
CarbonMonoxide m-xylene R124 R507A4
CarbonylSulfide n-Butane R125 R508B 1, 4
Cis-2-Butene n-Decane R131B R513A4
Cyclohexane n-Dodecane R134a R514A4
Cyclopentane n-Heptane R141b 1 R515A4
D4 n-Hexane R142b R515B4
D5 n-Nonane R143a R600
Deuterium n-Octane R143m R600a
DimethylCarbonate n-Pentane R152a R717
DiEthylEther n-Undecane R161 R7182
DiMethyEther Neon R218 R744
Ethane Neopentane R227ea R1216
Ethanol NH3H2O3 R236ea R1224yd(Z)
Ethylbenzene Nitrogen R236fa R1225ye(Z) 1
Fluorine NitrousOxide R245fa R1233zd
Helium Novec649 R290 R1234yf
HFE7000 o-Xylene R365mfc R1234ze
HFE7100 1 Orthohydrogen R404A4 R1243zf
HFE7200 1 Oxygen R407C4 RE245cb2
HFE7500 1 Parahydrogen R407H4 RE245fa2
HFO1336mzz(Z) 1 Propane R410A4 RC318
Hydrogen Propylene R417A4 SES36
Hydrogen Chloride p-Xylene R423A 1, 4 Steam2
HydrogenSulfide R11 1 R427A4 Steam_IAPWS 2
Ice R12 1 R438A4 Steam_NBS
Isobutane R13 1 R448A4 SulfurDioxide
Isobutene R13I1 R449A4 SulfurHexafluoride
Isohexane R14 1 R450A4 Toluene
Isooctane R22 R452A4 Trans-2-Butene
Isopentane R23 R452B4 Water2
Isopropanol 1 R453A4 Xenon
1. This fluid used the Martin-Hou (1955) equation of state to relate properties.
2. Steam_IAPWS uses the high accuracy properties issued by the Int. Assoc. for the Properties of Water and
Steam (IAPWS). Starting with version 10.364, Steam, Water, and R718 all refer to Steam_IAPWS.
3. See section 4.9 for NH3H2O
4. Refrigerant mixture modeled as a pseudo-pure fluid.
Chapter 4: Property Data 143
Property Indicators
The thermodynamic and transport functions for real fluids typically require that two properties
be set in order to fix the state and allow the calculation of the property of interest. Some
properties (e.g., the saturation pressure which is returned by the function P_sat, or the saturation
temperature that is returned by the function T_sat) require only one input property. The critical
properties (returned by the functions T_crit, P_crit, and v_crit) are unique for a specific fluid and
therefore require no input properties other than the fluid name. Table 4-1 indicates the real fluid
property functions that require less than two input parameters to fix the state. EES is flexible
with regard to what properties can be used to fix the state and in what order they are provided.
Therefore, an indicator is required to specify the properties that are provided. This indicator is a
single, case-insensitive letter that is followed by an equal sign. The numerical constant or
algebraic expression that provides the value of the specified property follows the equal sign. The
property indicators that are recognized in function arguments and their meaning are listed in
Table 4-3.
F$='Water'
MW=molarMass(F$) "molar mass of water"
P_c=P_crit(F$) "critical pressure of water"
After solving, the Solution Window will appear as shown in Figure 4-6.
144 Chapter 4: Property Data
Figure 4-6: Solution window that appears after solving the equations with units specified.
The examples shown above use temperature (T=) and pressure (P=) as the arguments for the two-
argument functions. However, the property functions accept any valid combination of properties
in order to fix the state. For example, the specific entropy can be determined from the specific
volume and specific enthalpy by adding the following equation to the example.
Two-Phase State
Some combinations of properties can not be used to fix the state. For example, the temperature
and pressure for a two-phase state are not independent for a pure fluid. Therefore, the
temperature and pressure associated with a two-phase state can not be used to determine other
properties. Consider the following example, which determines the normal boiling point of
ethanol.
F$='Ethanol' "fluid"
P=Po# "standard barometric pressure"
T_bp=T_sat(F$,P=P) "normal boiling point"
Note the use of the built-in constant Po#, which corresponds to the standard barometric pressure
in the pressure units specified with the Unit System dialog or $UnitSystem directive. Solving
these equations will show that the normal boiling point of ethanol is 351.4 K. Now, add the
following equation, which attempts to determine specific volume at the normal boiling point and
standard barometric pressure.
If you try to solve this set of equations you will receive the error message shown in Figure 4-7.
Chapter 4: Property Data 145
Figure 4-7: Error message resulting from using saturation temperature and pressure as arguments.
The specific volume cannot be determined given the saturation temperature and pressure since
there are many states that all have this temperature and pressure (ranging from saturated vapor to
saturated liquid). EES should catch this error.
For two-phase states, it is often convenient to specify the quality as one of the arguments. The
quality is the mass fraction of the substance that is in the vapor state. A quality of zero therefore
corresponds to saturated liquid whereas a quality of one corresponds to saturated vapor. Values
of quality below zero or above one are meaningless. The Quality function will return the quality
of the state if it is the two-phase region. The Quality function will return -100 for a state that is in
the subcooled liquid phase and 100 for a superheated state.
The specific volumes of ethanol in saturated liquid state and vapor states are found using the
following equations:
Figure 4-8: Function Information dialog for Real fluids showing the Example box for Ammonia.
Click the Fluid Info button to obtain information regarding the source(s) of the property
information that were used to develop the property functions. In the box labeled Independent
Properties the user can select the two properties that are used to fix the state. The text provided
in the Example box at the bottom of the dialog will adjust to conform to the selected property,
fluid, and independent variables, as shown in Figure 4-8. In many cases, each independent
property corresponds to an entry in an array of properties where each index is a state in a cycle.
Therefore, the value entered in the edit box to the right of the Example box is appended to each
independent variable. (It is blank by default). Select Paste to enter the resulting property call in
the Equations Window:
h[1]=Enthalpy(Ammonia,v=v[1],T=T[1])
Chapter 4: Property Data 147
Qcond
TH
4
compressor
throttle 3
valve condenser
Wc
1 evaporator
2
TC
Qevap
Figure 4-9: The simple vapor compression cycle.
The inputs are entered in EES and the unit system is specified using the $UnitSystem directive.
Assuming that the condenser is a perfect heat exchanger, the refrigerant at state 4 is saturated
liquid (x4 = 0) at T4 = TH.
These two intensive properties fix state 4, allowing the specific entropy, pressure, and specific
enthalpy (s4, P4, and h4) to be determined using the property functions Entropy, Pressure, and
Enthalpy, respectively.
Similarly, the refrigerant leaving the evaporator at state 2 is saturated vapor (x2 = 1) at T2 = TC.
148 Chapter 4: Property Data
These two intensive properties fix state 2, allowing the specific entropy, pressure, and specific
enthalpy (s2, P2, and h2) to be determined.
The fluid leaving the condenser is expanded to state 1 in the isenthalpic throttling valve (h1 = h4).
Assuming that there is no pressure loss in the evaporator, P1 = P2. The specific enthalpy and
pressure together fix state 1, allowing the specific entropy and temperature (s1 and T1) to be
determined.
The fluid leaving the evaporator is compressed to state 3 in a compressor that is assumed to be
reversible and adiabatic, therefore s3 = s2. Provided that there is no pressure loss in the
condenser, P3 = P4. The specific entropy and pressure together fix state 3 allowing the specific
enthalpy and temperature (h3 and T3) to be determined.
Solving provides all of the properties at each state conveniently organized in the Arrays Table,
shown in Figure 4-10. In Section 4.6, we will show how properties in the Arrays Table can be
used to create property plots in which the cycle state points are shown (e.g., a T-v or P-h
diagram).
Q
cond
=h h
3 4 (4-2)
m
Qevap (4-3)
=h h
2 1
m
Wc = h h (4-4)
3 2
m
The Coefficient of Performance (COP) for the cycle is:
Q / m
COP = W evap
/ m
(4-5)
comp
The Energy Efficiency Ratio (EER) for the cycle is equal to the COP expressed in units Btu/hr-
W.
"Energy balances"
Q_dot_cond\m_dot=h[3]-h[4] "condenser"
Q_dot_evap\m_dot=h[2]-h[1] "evaporator"
W_dot_c\m_dot=h[3]-h[2] "compressor"
COP=Q_dot_evap\m_dot/W_dot_comp\m_dot "Coefficient of Performance"
EER=COP*convert(-,Btu/hr-W) "energy efficiency rating"
Equations of State
The relationship between the properties of real fluids can be quite complex. The EES database
employs equations of state to relate these properties. Most of the fluids use the fundamental
equation of state as the basis for the property relations, as described by Span (2000). This
manner of relating properties is regarded as the most accurate method available. However, some
fluids in the EES database are represented by the Martin-Hou (1955) equation of state. The
fluids that use this equation of state are identified in Table 4-2. The Martin-Hou equation of
state implementation provides accurate property information in the saturated and superheated
regimes, but assumes that subcooled liquids are incompressible. The specific volume, specific
internal energy and specific entropy of subcooled liquids are assumed to be equal to the values of
the specific volume, specific internal energy and specific entropy of a saturated liquid state at the
same temperature. Specific information regarding the source of information for each fluid can
be seen by selecting the fluid name and then clicking the Fluid Info button in Figure 4-3.
150 Chapter 4: Property Data
Properties of Water
There are several fluid names that all correspond to water. For versions prior to 10.364, the fluid
names Water, Steam, Steam_NBS, and R718 are treated identically. All of these fluid names
provide water properties using property correlations published by Haar, Gallagher, and Kell
(Hemisphere, 1984). These property correlations were the basis for the international standard for
water properties prior to 1995.
The fluid Steam_IAPWS provides the most accurate property data for water using the 1995
Formulation for the Thermodynamic Properties of Ordinary Water Substance for General and
Scientific Use, issued by The International Association for the Properties of Water and Steam
(IAPWS). This correlation replaced the 1984 formulation of Haar, Gallagher, and Kell. The
new formulation is based on the correlations of Saul and Wagner (1987), with modifications to
adjust to the International Temperature Scale of 1990. The modifications are described by
Wagner and Pruss (1993). The Saul and Wagner correlation provides accurate results for
temperatures between 273.15 K and 1273.15 K at pressures up to 1000 MPa. The formulation
allows extrapolation of properties to 5000 K. Starting with version 10.364, Steam, Water, R718
and Steam_IAPWS all use the IAPWS formulation for water. If the earlier correlations are
desired, specify Steam_NBS as the fluid name.
Water is an unusual substance in that its specific volume in the solid state can be larger than it is
in the liquid state. The fluid Ice provides access to the properties of solid water (i.e., ice) in the
calculations when specific volume is provided as one of the arguments. However, water may
have two states (one solid and one liquid) with the same specific volume. Specifying Ice as the
substance will force the lower temperature (i.e., solid state) solution, as in the following
example. Note that setting the quality to zero results in a specification of the solid state at this
specific volume.
2. The ASHRAE Standard (ASH) reference state sets the values of specific enthalpy and
specific entropy to 0 for saturated liquid at -40°C (-40°F). Note that this option is not
applicable to fluids for which the critical temperature is less than -40°C.
3. The Normal Boiling Point (NBP) reference state sets the values of specific enthalpy and
specific entropy to 0 for saturated liquid at the normal boiling point (i.e., the saturation
temperature at one atmosphere). Note that this option is not applicable to fluids for which
the critical pressure is less than one atmosphere.
where FluidName is the name of the real fluid (as it appears in Table 4-2) or an EES string
variable, e.g., R$ that has been assigned to the name of the real fluid. Note that the $Reference
directive is not applicable to fluids that are modeled with the Martin-Hou or Ideal Gas equations
of state. The ReferenceID must be IIR, ASH, NBP, or DFT (which indicates the default reference
state). If the reference state choice is not applicable to the fluid then the reference state will
remain at its default value.
By default, the reference state for the refrigerant R134a is set to the ASHRAE Standard. The
EES code below changes the reference state for the fluid to the IIR standard.
It is possible for the user to add real fluid property information to EES based on the Martin-Hou
equation of state, as described in Section 4.10.
PV = n Runiv T (4-6)
where P is the absolute pressure, V is the volume, n is the number of moles of gas, Runiv is the
universal gas constant (which does not depend on the type of gas), and T is the absolute
152 Chapter 4: Property Data
temperature (i.e., the temperature expressed in either the Kelvin or Rankine scale). The value of
Runiv is provided in EES in the specified unit system with the constant R#. The ideal gas law can
also be expressed on a mass basis according to:
PV = m R T (4-7)
where m is mass of gas and R is the ideal gas constant, expressed on a mass basis (R = Runiv/MW
where MW is the molar mass of the gas). The specific volume of the gas can be defined on either
a molar or mass basis by dividing the volume by the number of moles or mass, respectively. The
definition of an ideal gas also requires that the specific internal energy (and thus the specific
enthalpy) is a function only of temperature.
Most of the property functions listed in Table 4-1 can be used with the built-in ideal gases.
Some of the property functions are not needed for ideal gases, but they still work properly. For
example, the compressibility factor of an ideal gas is always 1 at any state and its fugacity is
always equal to its pressure. Additional ideal gas property information can be added, as
explained in Section 4.10.
The use of an ideal gas fluid affects the number of arguments that the property functions require
in some cases and also the reference state used for specific internal energy, specific enthalpy and
specific entropy. The EES code below determines the specific enthalpy of nitrogen at T = 300 K
and P = 100000 Pa using the real gas fluid Nitrogen.
Chapter 4: Property Data 153
If you attempt to determine the specific enthalpy of nitrogen at T = 300 K and P = 100000 Pa
with the ideal gas fluid N2 using the same two properties (temperature and pressure) to fix the
state:
h_IG=enthalpy(N2,T=T,P=P) "enthalpy of N2"
Because N2 is an ideal gas, the specific enthalpy (and specific internal energy) can only be a
function of temperature. Therefore, the Cp, Cv, Enthalpy and IntEnergy functions in EES will only
accept temperature (or combinations of two properties from which temperature can be
determined, such as specific volume and pressure) in addition to the fluid name. Therefore, the
specific enthalpy should be determined according to:
h_IG=enthalpy(N2,T=T) "enthalpy of N2"
which leads to hIG = 1,920 J/kg. The large difference between hRG and hIG is due to the fact that
the reference states used for the fluids Nitrogen and N2 are very different. The reference states for
the specific enthalpy of all ideal gases (except air) are chosen relative to the elements from which
the gas is formed having a specific enthalpy of 0 kJ/kmol at 25°C (298.15 K). This reference
state choice makes it convenient to use the ideal gas property information for energy calculations
involving chemical reactions, as explained below.
The procedure requires as inputs the name of the ideal gas and two specified property values
(with their property indicators) to fix the state, in the same manner as other property functions. In
this example, temperature and pressure are specified for ideal gas air. The IdealThermoProps
procedure returns as outputs the temperature (T), pressure (P), specific volume (v), specific
enthalpy (h), specific entropy (s), and specific internal energy (u) in this order. It provides a
coding shortcut that requires the user to enter fewer lines of code into the Equations window to
determine multiple property values at a single state.
Note that in the example above, the values for EES variables T and P have been set before the
IdealGasThermoProps procedure is called. EES recognizes that the outputs (T and P) are the
same as the inputs and does not try to reassign them with an equation of the form T=T, which
would introduce an error. If the call were entered as,
The IdealGasThermoProps procedure can be entered using the Function Information dialog in
the Options menu, as shown in Figure 4-12. Note that entering a state specification, such as [1]
shown in the box to the right of the example at the bottom of the dialog, will apply that
specification automatically to every EES variable in the example box. The text within the
example box can then be further edited as desired before clicking the Done button.
It is not necessary to provide EES variables for each of the outputs. Unwanted outputs can be
eliminated by leaving those spots blank in the output list, or just leaving them out if they are at
the end of the list. For example, if specific volume and specific internal energy are not of
interest, the call statement to the IdealGasThermoProps procedure can be written as:
combustor
2 3
compressor Wc Wgt gasifier
turbine
1 4
"Input conditions"
T_amb=converttemp(C,K,20[C]) "ambient temperature"
P_atm=1 [atm]*convert(atm,Pa) "ambient pressure"
T_comb=1500 [K] "temperature leaving combustor"
PR=5 [-] "pressure ratio"
"State 1"
call IdealGasThermoProps(Air,T=T_amb,P=P_atm:T[1],P[1], ,h[1],s[1]) "state 1 properties"
"State 2"
P[2]=PR*P[1] "pressure"
s[2]=s[1] "entropy balance on reversible
compressor"
call IdealGasThermoProps(Air,s=s[2],P=P[2]: T[2],P[2], , h[2]) "state 2 properties"
W_dot_c\m_dot=h[2]-h[1] "work per mass required by
compressor"
156 Chapter 4: Property Data
"State 3"
T[3]=T_comb "combustor energy balance"
P[3]=P[2] "no pressure loss"
call IdealGasThermoProps(Air,T=T[3],P=P[3]: T[3],P[3], ,h[3], s[3]) "state 3 properties"
"State 4"
s[4]=s[3] "entropy balance on reversible gasifier
turbine"
call IdealGasThermoProps(Air,s=s[4],P=P[4]: T[4], P[4], , h[4]) "state 4 properties"
W_dot_gt\m_dot=(h[3]-h[4]) "work per mass associated with
reversible gasifier turbine"
W_dot_gt\m_dot=W_dot_c\m_dot "power from gasifier turbine must equal
power required by compressor"
"State 5"
P[5]=P_atm "exit pressure"
s[5]=s[4] "entropy balance on reversible power
turbine"
call IdealGasThermoProps(Air,P=P[5],s=s[5]: T[5],P[5], ,h[5]) "state 5 properties"
W_dot_pt\m_dot=(h[4]-h[5]) "work per mass associated with power
turbine"
eta=W_dot_pt\m_dot/(h[3]-h[2]) "efficiency"
BWR=W_dot_c\m_dot/(W_dot_pt\m_dot+W_dot_gt\m_dot) "back work ratio"
The NASA ideal gas property library was integrated into EES in version 8.528. Prior to this
version, ideal gas data from the NASA database had to be accessed with a call to the NASA
external procedure. This external procedure is still of interest because it provides data for solid
materials as well as gases. The use of this external procedure is discussed in Section 4.9.
Chapter 4: Property Data 157
Table 4-5: Thermodynamic property functions available for the Ideal Gas and NASA database
Function Name Returns SI Units English Units
CompressibilityFactor compressibility factor none none
Conductivity2 thermal conductivity W/m-K Btu/hr-ft-R
Cp constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Cv constant volume specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Density density kg/m3 lbm/ft3
2
Dipole dipole moment Debye Debye
EK_LJ2 Lennard–Jones energy potential K R
Enthalpy specific enthalpy J/kg, kJ/kg Btu/lbm
J/kg, kJ/kg, J/kmol, Btu/lbm,
Enthalpy_formation2 enthalpy of formation
kJ.kmol Btu/lbmol
J/kg, kJ/kg, J/kmol, Btu/lbm,
Enthalpy_fusion2 enthalpy of fusion
kJ.kmol Btu/lbmol
Entropy specific entropy J/kg-K, kJ/kg-K Btu/lbm-R
Real, ideal, brine or
FluidType$ none none
incompressible
Fugacity fugacity Pa, kPa, bar, MPa psia, atm
J/kg, kJ/kg, J/kmol, Btu/lbm,
HigherHeatingValue2 higher heating value
kJ.kmol Btu/lbmol
IntEnergy specific internal energy J/kg, kJ/kg Btu/lbm
IsentropicExponent ratio of cp/cv none none
IsothermalCompress Inverse pressure Inverse pressure Inverse pressure
J/kg, kJ/kg, J/kmol, Btu/lbm,
LowerHeatingValue2 lower heating value
kJ.kmol Btu/lbmol
P_crit2 critical pressure Pa, kPa, bar, MPa psia, atm
Pressure absolute pressure Pa, kPa, bar, MPa psia, atm
MolarMass1 molecular weight kg/kmol lbm/lbmol
Sigma2 Lennard-Jones length potential m ft
SoundSpeed speed of sound m/s ft/s
SpecHeat constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
T_crit2 Critical temperature °C, K °F, R
Temperature temperature °C, K °F, R
3
V_crit Critical specific volume m /kg ft3/lbm
2
Viscosity viscosity kg/m-s lbm/ft-hr
VolExpCoef coefficient of thermal expansion 1/K 1/R
Volume specific volume m3/kg ft3/lbm
1. The function requires only the name of the fluid.
2. Only available for the built-in ideal gases listed in Table 4-4 and NASA ideal gases containing C, O, and H.
the string F$) as well as the inlet temperature and pressure (Tin and Pin), the outlet pressure (Pout),
and the isentropic efficiency ().
Function Turbine(F$,T_in,P_in,P_out,eta)
The inlet state is fixed by the inlet temperature and pressure. The inlet specific entropy is
determined using the Entropy function. Note that specific entropy (sin) is a function of
temperature and pressure regardless of whether the fluid is an ideal gas or a real fluid.
The inlet specific enthalpy (hin) is determined using the Enthalpy function. Note that the Enthalpy
function must be called using only temperature if the fluid provided by the string F$ is an ideal
gas. Otherwise both temperature and pressure must be used. This logic is accomplished using
the IsIdealGas function and an If-Then-Else construct (Section 3.4).
If (FluidType$=’Ideal’) Then
h_in=Enthalpy(F$,T=T_in) "inlet specific enthalpy for ideal gas fluid"
Else
h_in=Enthalpy(F$,T=T_in,P=P_in) "inlet specific enthalpy for real fluid"
EndIf
The specific enthalpy at the outlet state for a reversible turbine (hout,s) is obtained from the outlet
pressure and inlet specific entropy using the Enthalpy function. Note that pressure and specific
entropy together are required in order to determine temperature; therefore, both inputs are
required regardless of whether the fluid is a real fluid or an ideal gas.
The outlet specific enthalpy of the actual turbine (hout) is computed according to:
The outlet state is fixed by the outlet specific enthalpy and outlet pressure. Specific enthalpy is a
function only of temperature for an ideal gas. Therefore, the converse must also be true;
temperature must be a function only of specific enthalpy for an ideal gas. If the fluid is an ideal
gas then the outlet temperature is obtained using the Temperature function called only with
specific enthalpy. Otherwise the Temperature function is called with both specific enthalpy and
pressure.
If (FluidType$(F$)=’Ideal’) Then
Turbine=Temperature(F$,h=h_out) "outlet temperature for ideal gas fluid"
Else
Chapter 4: Property Data 159
The function Turbine will work when called with either an ideal gas (e.g., Air):
If the name of the substance is recognized by the Incompressible library (see section 4.8), the
function returns ‘Incompressible’. In this case, the substance name must correspond to a Lookup
table containing the property data and located in the ..\UserLib\EES_System\Incompressible
folder or a subfolder within that folder. As an example,
G$=FluidType$(‘Glycerin’)
If the name of the fluid is recognized as a fluid in the Brine library (see section 4.7), the function
returns ‘Brine’. For example,
CH 4 + 2 O2 CO2 + 2 H 2 O (4-9)
160 Chapter 4: Property Data
The lower heating value of methane is the difference between the molar specific enthalpy of the
reactants and the molar specific enthalpy of the products for this reaction evaluated at 25ºC and
assuming that the water in the products is all in the gas phase. This calculation can be easily
accomplished using EES because the reference state used for the ideal gases involved in the
reaction includes the specific enthalpy associated with the chemical bonds in the molecules.
Therefore, the specific enthalpy reported by EES for an ideal gas is the standardized specific
enthalpy that can be directly used in energy balances for chemical reactions.
The $UnitSystem directive is used to specify a molar rather than a mass basis. The molar specific
enthalpies of each of the substances involved in the reaction ( hCH 4 , hO2 , hCO2 , and hH 2O ) are
determined using the Enthalpy function and assuming that the substances behave as an ideal gas.
$UnitSystem SI Mole J K Pa
The enthalpy of the reactants and the products of the reaction shown in Eq. (4-9) per mole of
CH4 (HR and HP) are computed:
H P = hCO + 2 hH O (4-11)
2 2
LHV = H R HP (4-12)
Solving leads to LHV = 8.025x108 J/kmol. Dividing by the molar mass of CH4 results in the
lower heating value expressed on a unit mass basis.
The lower heating value for methane is 50,023 kJ/kg. Note that this value can be more simply be
determined using the LowerHeatingValue function, e.g.,
LHV=LowerHeatingValue(CH4)
Chapter 4: Property Data 161
4.5Psychrometric Properties
Psychrometics is the term used to refer to the study of mixtures of air and water vapor at
conditions near atmospheric pressure and temperature. The properties of these mixtures are of
practical interest for heating and cooling applications.
All of the properties that are of interest for other fluids (e.g., specific enthalpy, thermal
conductivity, etc.) are also available for air water vapor mixtures using the fluid AirH2O. Other
properties that are specific to psychrometrics include the dew point and wet bulb temperatures.
The dew point temperature (Tdp) is defined as the temperature at which water will condense
when the mixture is cooled at constant pressure. The wet bulb temperature (Twb) refers to the
temperature a wetted material such as a piece of cotton will come to when it is exposed to humid
air at a specified state. The wet bulb temperature is usually approximated with the adiabatic
saturation temperature of the air water mixture (Tas), which is the temperature that an air water
vapor mixture will achieve if it is humidified adiabatically. Detailed information on these
properties is provided in Klein and Nellis (2012).
162 Chapter 4: Property Data
Table 4-6: Thermodynamic and transport property functions for air-water vapor mixtures that can be
accessed using the fluid AirH2O.
Function Name Returns SI Units English Units
CompressibilityFactor compressibility factor none none
Conductivity thermal conductivity W/m-K Btu/hr-ft-R
Cp constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Cv constant volume specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Density density kg/m3 lbm/ft3
DewPoint dew point temperature °C, K °F, R
Enthalpy specific enthalpy J/kg, kJ/kg Btu/lbm
Entropy specific entropy J/kg-K, kJ/kg-K Btu/lbm-R
Fugacity fugacity Pa, kPa, bar, MPa psia, atm
HumRat humidity ratio none none
IntEnergy specific internal energy J/kg, kJ/kg Btu/lbm
RelHum relative humidity none none
SpecHeat constant pressure specific heat J/kg-K, kJ/kg-K Btu/lbm-R
Temperature temperature °C, K °F, R
Viscosity viscosity kg/m-s lbm/ft-hr
Volume specific volume m3/kg ft3/lbm
Wetbulb adiabatic saturation temperature °C, K °F, R
Chapter 4: Property Data 163
Table 4-7: One letter indicators for EES property functions with AirH2O.
Indicator Thermodynamic Property
B thermodynamic wet bulb temperature (only for substance AirH2O)
D dew point temperature (only for substance AirH2O)
H dry air specific enthalpy1
P pressure
R relative humidity (only for substance AirH2O)
S dry air specific entropy1
T temperature
U dry air specific internal energy1
V dry air specific volume1
W humidity ratio (only for substance AirH2O)
1. Note that the term dry air specific indicates that the property is returned per
mass of dry air in the air water mixture rather than per mass of mixture. This is
the conventional method for providing specific properties for an air water
mixture.
Psychrometrics Example
The following example determines all of the available thermodynamic and transport properties
for an air water mixture at 25°C and 101.3 kPa with a 40% relative humidity.
The Solution Window that results after solving this example is shown in Figure 4-14. Note that
the wetbulb and dewpoint temperatures are displayed in both K and °C because alternate units
have been selected for these variables as discussed in Section 1.4 Dual Units.
164 Chapter 4: Property Data
Figure 4-14: Solution Window resulting from solving the psychrometric example.
As indicated in Table 4-7, a variety of different combinations of properties can be used as the
independent variables in the property calls. For example, the same solution that is shown in
Figure 4-14 would result if the thermodynamic function calls were written as:
The procedure requires three inputs. Any valid combination of inputs is accepted but one must
be atmospheric pressure. The substance name (AIRH2O) is not required, but it can be provided.
Each of the three inputs must be identified with the usual one-letter property identifier and equal
sign. The list of input property identifiers needed in the calling arguments and instructions are
listed in Table 4-7. The value and units of the inputs and outputs are determined by the Unit
System setting.
The example providing psychrometric properties can be considerable shortened by using the
PsychProps procedure as shown in the following example code.
The solution to this equation set is shown is the same as when using the individual property calls
and it is shown in Figure 4-14. Note that transport properties are not provided by the PsychProps
procedure.
4.6Property Plots
Property plots are commonly used in thermodynamic cycle models. For many years such plots
were used to estimate properties graphically. Even if property information is obtained using
other means, property plots are still very useful for visualizing thermodynamic cycles and
processes. Cycle states and process trajectories can be understood more easily by overlaying
them onto plots with property coordinates (e.g., T-v plots, T-s plots, and P-h plots).
Property plots can be produced for any built-in ideal gases and real fluids as well as for air-water
vapor mixtures (i.e., psychrometric charts) and brines. The fluid type is selected with the radio
button control at the top of the dialog. The fluid is selected from the list at the upper left of the
dialog window. The type of plot is selected with the list in upper center of the dialog by
selecting a radio button. The allowable plot types depend on the choice of fluid type. The lower
half of the dialog provides the opportunity to enter up to six values that will be used to generate
lines of a constant property (e.g., isotherms, isobars, or isochors). The constant property choice
depends on the type of property plot that has been selected. For example, lines of constant
pressure and constant specific volume can be optionally placed on a temperature-specific entropy
plot (T-s plot) as shown in Figure 4-16. Suggested values for the constant properties are
automatically generated, but they can be changed or deleted based on user preference. The
constant property line is plotted only if the check box preceding the edit control showing the
value is checked. The values can be provided with numerical constanst, as shown in Figure 4-
15: Property plot dialog window. To uncheck all of the values (i.e., to forego generating lines of
constant property), de-select the Include lines of by clicking in the space between the brackets [ ]
above the list. Note that the colors for the constant property lines can be specified.
Ammonia
300
250
200
150
T [°C]
7000 kPa
100
3000 kPa
50
800 kPa
0
100 kPa
0.2 0.4 0.6 0.8
-50
-100
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
s [kJ/kg-K]
Figure 4-16: Temperature-specific entropy plot for Ammonia.
Ammonia
5
10
4 130°C
10
3
10 25°C
-17°C
2
10
1
10
-500 0 500 1000 1500 2000 2500
h [kJ/kg]
Figure 4-17: Pressure-specific enthalpy plot for Ammonia
168 Chapter 4: Property Data
EES selects a default maximum temperature for plotting T-s, T-v, and T-h plots, that may be
lower than the maximum temperature for which the property correlation is valid. In this case, a
Max. Temperature controller will appear, in the dialog, as seen in Figure 4-15. The maximum
temperature used for constructing the plot can be increased moving the slider control to the right.
The temperature corresponding to the slider position is displayed to the left of the controller.
The temperature can alternatively be entered directly into this edit box.
The P-T plot option will display the vaporization curve and critical point for the selected fluid in
pressure-temperature coordinates. In addition, the triple point, fusion (solid-liquid) and
sublimation (solid-gas) lines will be displayed if this information is available, as shown in Figure
4-18.
5x105 Ammonia
105
104
103
Pressure [kPa]
102
101
100
10-1
Critical point
Fusion line
Sublimation line
5x10-5
-250 -200 -150 -100 -50 0 50 100 150
Temperature [°C]
Figure 4-18: Pressure-temperature plot for ammonia showing the vaporization, sublimation and fusion lines
For mixtures that exhibit a temperature glide (e.g, refrigerants having an R4xx name), the bubble
point and dew point lines will both be displayed, as seen in Figure 4-19.
Chapter 4: Property Data 169
Figure 4-19: Pressure-temperature plot for R454A showing bubble and dew point lines.
Air
3,000
2,500
2,000
1,500
T [°C]
1,000
500
-500
4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0
s [kJ/kg-K]
Figure 4-20: Temperature-specific entropy plot for Air.
Psychrometric Plots
If the Psych Chart radio button is selected then the Property Plot dialog will appear as shown in
Figure 4-21. The dialog allows the pressure and the dry-bulb temperature limits to be entered.
Lines of constant wet-bulb temperature and specific volume can optionally be placed on the plot,
as well as lines of constant relative humidity. Note that the dialog provides a choice of two
formats for the psychrometric chart. The Carrier type provide a plot with humidity ratio on the
ordinate and dry bulb temperature on the abscissa, whereas these axes are interchanged in the
Mollier plot. The psychrometric plot produced with the information in Figure 4-21 is shown in
Figure 4-22.
Chapter 4: Property Data 171
AirH2O
0.050
Pressure = 101.3 [kPa]
0.045
0.040
35°C
0.035 0.8
Humidity Ratio
0.030
30°C
0.6
0.025
25°C
0.020
0.4
20°C
0.015
15°C
0.010
10°C 0.2
0.005
0.000
0 5 10 15 20 25 30 35 40
T [°C]
Figure 4-22: Psychrometric chart produced using the input shown in Figure 4-21.
172 Chapter 4: Property Data
After solving this problem, a pressure–specific enthalpy property plot is constructed for Ammonia
(Figure 4-25). The Overlay Plot is then used to display the property information for all four
states in the refrigeration cycle on the property plot. The options in the Overlay Plot dialog are
shown in Figure 4-26. Note that the 'Add point labels' check box is selected. This option will
place the subscript number of each plotted point next to its symbol on the plot so that the state
can be easily identified. Also notice that the Automatic update check box is selected so that any
changes that are made to the refrigeration cycle model will be immediately reflected in the
property plot. The completed plot is shown in Figure 4-27. Note that the line tool has been used
to connect point 1 to point 4 to close the cycle.
Figure 4-25: Property plot dialog used to produce a P-h plot for ammonia.
Chapter 4: Property Data 175
Figure 4-26: Overlay Plot dialog used to generate Figure 4-27 for the refrigeration cycle example.
105
104
360 K
4 320 K 3
P [kPa]
3
10
280 K
1 2
102 240 K
101
-2.5x105 2.5x105 7.5x105 1.3x106 1.8x106
h [J/kg]
Figure 4-27: Pressure-specific enthalpy plot with refrigeration cycle property information overlaid.
176 Chapter 4: Property Data
4.7Brine Properties
Brines are also called secondary refrigerants. These fluids are mixtures of water and another
substance that result in a reduction of the freezing point. The properties of primary interest for
brines are its specific heat capacity and its freezing point. The thermal conductivity and
viscosity of brines are also of interest because they affect the heat transfer characteristics as well
as the pressure drop and therefore the pumping costs. Brine property correlations have been
published by the International Institute of Refrigeration (Melinder (2010)) and these correlations
have been implemented in EES. All of the brine properties are functions of temperature and the
concentration of the solute.
1
This function requires temperature, concentration, and pressure in addition to the name of the substance.
2
This function requires only concentration in addition to the name of the substance.
3
Only the substance name is required
Chapter 4: Property Data 177
Figure 4-28: Function Information dialog that results when the Brines button is selected.
The following example determines property information for a 40% mass concentration of
ethylene glycol in water ('EG') at 0°C (273.2 K).
Solving provides = 1060 kg/m3, Tfp = -23.87°C, cP = 3434 J/kg-K, = 0.005799 Pa-s, k =
0.4099 W/m-K, and Tbp=379.2 K (106°C
where Brine$ is the name of the mixture (as given in Table 4-9), Conc is the concentration (in
mass %), Temp is the temperature (in °C), FreezingPt is the freezing temperature (in °C), Density
is the density of the fluid (in kg/m3), SpecHeat is the specific heat capacity (in kJ/kg-K),
ThermalC is the thermal conductivity (in W/m-K), DynVisc is the dynamic viscosity (in Pa-s), and
Pr is the Prandtl number. Note that the units of the inputs and outputs to this procedure must be
as indicated above and summarized in Table 4-10, regardless of the settings of the unit system in
EES.
Chapter 4: Property Data 179
Table 4-10: Required units for variables used with the BrineProp2 external procedure.
Variable Property Units
Conc concentration in mass percent none
Temp temperature °C
FreezingPt freezing point °C
Density density kg/m3
SpecHeat specific heat kJ/kg-K
ThermalC thermal conductivity W/m-K
DynVisc dynamic viscosity Pa-s
Pr Prandtl number none
The following line of code, added to those from the previous section, provides the property
information for a 40% mass concentration of ethylene glycol in water at 0°C using the BrineProp2
procedure.
Solving provides = 1061 kg/m3, Tfp = -23.81°C, cP = 3431 J/kg-K, = 0.005786 Pa-s, and k =
0.4096 W/m-K. Note the slight differences between these properties and those obtained in the
previous section due to the fact that an older set of correlations are being used within the
BrineProp2 procedure.
4.8Incompressible Substances
The Incompressible Substance library in EES provides the properties of incompressible solid and
liquid substances as a function of temperature. Information and example function calls for the
Incompressible Substance library are obtained by clicking the Incompressible button in the
palette that appears when Thermophysical properties is selected in the Function Information
dialog, as shown in Figure 4-29. Click the Function Info button to open the online help to the
page that describes the selected property function. Click the Property Info button to determine
the temperature range and properties that are available for the selected substance, and also to see
the references that the property data are based upon.
180 Chapter 4: Property Data
Figure 4-29: Function Information dialog window configured for Incompressible substances.
Shown on the right side of the Function Information dialog (Figure 4-29) are the names of
substances for which the selected Incompressible substance function can be applied. Note that
not all of the property functions are available for or apply to all of the substances. For example,
the saturation vapor pressure function (P_sat) is only applicable to liquid substances. The
MolarMass function is only implemented for substances in which the molecular weight is
known. The substance name must be provided as the first argument in the function call. It can
be entered as a string constant (with optional quotes) or a string variable. The drop-down list
box in the center allows a selection criterion to be applied to the list of substances. The selection
criteria are: All Data, Building Materials, Fluids, Insulation, Liquid Metal, Metals,
Miscellaneous and Molten Salts. The names of the substance for which property data are
available in the Incompressible library are provided in Table 4-12, Table 4-13, Table 4- 14, and
Table 4- 15. Using the selection criterion shortens the list of substance names. Some substances
appear in several lists. An example of the function, applied to the selected substance, appears in
the Example box at the bottom of the dialog. This text in the example can be edited. At the right
of the edit box is a index field. Entering an index, e.g., _1, in this field appends this index to all
variables in the Example box, as shown in Figure 4-29.
Table 4-13: List of Building Materials and Insulation in the Incompressible library.
Building Materials Building Matls, cont. Insulation Insulation, cont.
Acoustic_tile Rock_sandstone Blanket_Al_silica_rho_128 loose_fill_wood
Asphalt Sand Blanket_Al_silica_rho_48 Pipe_ins_Asbestos_4ply
Brick_common Sheathing_regular_density Blanket_Al_silica_rho_64 Pipe_ins_Asbestos_6ply
cement_mortar Wood_aspen Blanket_Al_silica_rho_96 Pipe_ins_Asbestos_8ply
Clay Wood_balsa Blanket_glass_fiber_rho_12 Pipe_ins_calcium_silicate
Concrete_stone_mix Wood_cypress Blanket_glass_fiber_rho_16 Pipe_ins_cellular_glass
Gypsum_plaster_sand Wood_fir Blanket_glass_fiber_rho_24 Pipe_ins_diatomaceous
Hardboard_high_density Wood_hickory Blanket_glass_fiber_rho_32 Pipe_ins_magnesia_85
Hardboard_siding Wood_oak Blanket_glass_fiber_rho_48 Pipe_ins_polystyrene_beads
Particle board_high_density Wood_pine Glass fiber duct liner Pipe_ins_polystyrene_extru35
Particle board_low_density Wood_redmaple Glass_fiber_batt_rho_16 Pipe_ins_polystyrene_extru56
Plywood Wood_silvermaple Glass_fiber_batt_rho_28 Pipe_ins_silica
Rock_granite Wood_spruce Glass_fiber_batt_rho_40 Polystyrene
Rock_limestone Wood_sugarmaple loose_fill_perlite Polystyrene_molded_beads
Rock_marble Wood_whiteash loose_fill_vermiculite_122 Polystyrene_R12_extruded
Rock_quartzite loose_fill_vermiculite_80 Polyurethane
Table 4- 14: List of Organic Liquids and Heat Transfer Fluids in the Incompressible library.
Organic Liquids Organic Liquids Heat Transfer Fluids Heat Transfer Fluids
continued continued
1,3-propylene_glycol Formic_Acid Baysilone_M10 Fluorinert_FC43
Acetaldehyde Glycerin Baysilone_M100 Fluorinert_FC70
Acetic_Acid Iodobenzene Baysilone_M12500 Fluorinert_FC72
Acetonitrile Isobutanol Calflo_FG Formaldehyde
Aniline Isopentanol Diphyl Marlotherm_SH
Anthracene Methyl_Mercaptan Dowfrost_GEO_20 Paratherm_CR
Benzyl_alcohol MethylAmine Dowtherm_A Paratherm_GLT
Benzyl_Chloride Naphthalene Dowtherm_G Paratherm_HE
Biphenyl n-Butanol Dowtherm_J Paratherm_HR
Bromobenzene n-Decanol Dowtherm_MX Paratherm_LR
Carbon_Tetrachloride n-Heptanol Dowtherm_Q Paratherm_NF
Chlorobenzene n-Hexanol Dowtherm_RP Syltherm_800
Chloroform n-Nonanol Dowtherm_T Syltherm_XLT
CycloHeptane n-Octanol Dynalene_600 Thermia_A
CycloHexanol Novec_7100 Dynalene_HT Thermia_D
CycloPentane Novec_7500 Dynalene_SF Therminol_55
Diesel#2 n-Pentanol Engine_Oil_10W Therminol_59
DiethylAmine n-Propanol Engine_Oil_15W Therminol_66
diethylene_glycol n-PropylAmine Engine_Oil_20W Therminol_72
Engine_Oil_unused Phenol Engine_Oil_25W Therminol_LT
Ethyl_Acetate Pyridine Engine_Oil_5W Therminol_VP1
EthylAmine sec-Butanol Engine_Oil_unused Therminol_XP
ethylene_glycol Styrene Fluorinert_FC104 Xceltherm_600
Ethylenediamine Tetrahydrofuran Fluorinert_FC3283 Xceltherm_HT
Fluorobenzene TriethylAmine Fluorinert_FC40 Xceltherm_LV
184 Chapter 4: Property Data
Table 4- 15: List of Miscellaneous, Molten Salts and Liquid Metals in the Incompressible library.
Miscellaneous Molten Salts Liquid Metals
Al_oxide_polycryst Dynalene_MS1 Aluminum_liquid
Al_oxide_sapphire Dynalene_MS2 Bismuth_liquid
Bakelite Effge_ASD Cadmium_liquid
Beryllium_oxide Hitec_XL Cesium_liquid
Coal_anthracite Salt(25KF_75KBF4) Cobalt_liquid
Cotton Salt(31RbF_69RbBF4) Gallium_liquid
Fused_silica Salt(45NaNO3_55KNO3) Indium_liquid
G10_normal Salt(46.5LiF_11.5NaF_42KF) Iron_liquid
G10_warp Salt(49LiF_29NaF_29ZrF4) lead_liquid
Glass_Pyrex Salt(58KF_42ZrF4) Lithium_liquid
Glass_soda_lime Salt(58LiCl_42RbCl) Mercury_liquid
Naphthalene_solid Salt(58NaCl_42MgCl2) NaK(22_78)_liquid
Paper Salt(59.5LiCl_40.5KCl) NaK(44_55)_liquid
Paraffin_Wax Salt(59.5NaF_40.5ZrF4) PbBi(44.5_55.5)_liquid
Rubber_vulcanized_hard Salt(60NaNO3_40KNO3) Potassium_liquid
Rubber_vulcanized_soft Salt(67LiF_33BeF2) Silicon_liquid
Silicon_Carbide Salt(68KCl_32MgCl2) Sodium_liquid
Snow_rho_166 Salt(7NaNO3_ 40NaNO2_ 53KNO2) Thallium_liquid
Snow_rho_500 Salt(8NaF_92NaBF4) Tin_liquid
Soil Molten Salts Zinc_liquid
Sulfur Dynalene_MS1
Teflon Dynalene_MS2
Thorium_dioxide Effge_ASD
Titanium_dioxide Hitec_XL
Miscellaneous Salt(25KF_75KBF4)
Al_oxide_polycryst Salt(31RbF_69RbBF4)
Al_oxide_sapphire Salt(45NaNO3_55KNO3)
Bakelite Salt(46.5LiF_11.5NaF_42KF)
Beryllium_oxide
Coal_anthracite
Cotton
Fused_silica
The following example provides the density, specific heat capacity, viscosity and thermal
conductivity of a molten salt that consists of 60% sodium nitrate and 40% potassium nitrate
(substance ‘Salt (60% NaNO3, 40% KNO3)’) at T = 550ºC (823.15 K).
Chapter 4: Property Data 185
The result is = 1738 kg/m3, c = 1543 J/kg-K, = 0.001188 Pa-s, and k = 0.5487 W/m-K.
The data in each file have typically been obtained from different sources. You can view what
data are available and their applicable temperature range by clicking the Property Info button
above the list of substances As an example, the property information for copper is shown in
Figure 4- 30.
186 Chapter 4: Property Data
The source of the property information is shown when you click the References button. Many
of the references are available on the internet and hot links are provided for these references.
Clicking the link will start your browser and point it at the reference information.
You can view, change, or add to the data that are used as the basis for the Incompressible
property routines by opening the associated Lookup File so that it is visible in the EES Lookup
Table. For example, to examine the data for glycerin, select Open Lookup Table from the Tables
Chapter 4: Property Data 187
Figure 4-32: Lookup Table containing the data for the substance Glycerin.
The first column in all of the incompressible property tables in temperature in K. Temperature
and the corresponding data must be provided with increasing temperature. Separate columns for
each property. The properties that EES currently will recognize and the units that they must be
supplied in are listed in Table 4-17.
Table 4-17: Column names and corresponding properties and units recognized by EES in .lkt/.lkt64 tables.
Column Name Property Units
alpha linear coef. of thermal expansion 1/K
beta volumetric coef. of thermal expansion 1/K
c specific heat capacity kJ/kg-K
DELTAh_vap specific enthalpy change of vaporization kJ/kg
DELTAL\L_293 linear expansion1 none
E Young’s modulus GPa
epsilon emissivity none
IntK Integrated thermal conductivity W/m
k thermal conductivity W/m-K
mu dynamic viscosity Pa-s
nu Poisson’s ratio none
Pv vapor pressure kPa
rho density kg/m3
rho_e electrical resistivity ohm-m
s specific entropy kJ/kg-K
sigma surface tension N/m
Su ultimate stress MPa
Sy yield stress MPa
u specific internal energy kJ/kg
The References column provides string information containing up to 256 characters. The first
row in the References column provides general information. Each row thereafter provides
reference information for the corresponding column. For example, the string in row 7 of the
References column in Figure 4-32 provides information about the property in column 7, which in
188 Chapter 4: Property Data
this case is specific internal energy. The reference information can include an internet link. The
link is recognized by the http:// that normally precedes web links.
The ColumnID column also provides string information. It is used to identify the constants in
the Constants column. The constants consist of molar mass, freezing point, phase (0 for solid or
1 for liquid), enthalpy change of fusion, normal boiling point, and the critical temperature,
pressure, and volume. These constants must be provided in the order shown in Figure 4-32.
Note: If you make any changes to the files in the Incompressible folder, be sure to keep a
backup copy in a safe location. Otherwise, your changes may be overwritten the next time EES
is installed.
The specific heat capacity and conductivity data as a function of temperature are shown in Figure
4-33.
Chapter 4: Property Data 189
Figure 4-33: Specific heat capacity and conductivity of manganin as a function of temperature.
In order to have manganin appearing when the Metals is selected from the dropdown selection
criteria, you must save file in the Manganin.lkt in the Metals subdirectory.
Next, generate a Lookup Table with one column for temperature (labeled T with units K) and a
separate column for each property that is included. The names and units for each column must
correspond to those shown in Table 4-17. Note that EES correctly converts units to the current
unit system settings when returning a value from the Incompressible properties; however, it
assumes that the data are provided with the units shown in Table 4-17. Also note that not all
properties must be provided for each substance (and the properties that are provided do not need
to be provided at all of the temperatures that are included in the table).
Optionally add a Reference column. This column must contain string data. Right click on the
column header, select Properties from the pop-up menu and then set the Style to be string, as
shown in Figure 4- 34: Specifying string information in a Lookup table column Reference
information for each property appear in the corresponding row of the references column.
190 Chapter 4: Property Data
The Lookup Table required to add the specific heat capacity and conductivity of manganin is
shown in Figure 4-35. (Reference information were not added.) Constants, such as molar mass,
freezing point, etc. can also optionally be added, as shown in Figure 4-32.
Chapter 4: Property Data 191
Save the Lookup Table in EES Lookup File format (i.e., as a .lkt/.lkt64 file) in the
Incompressible folder. Make sure that the name of the table corresponds to the name of the
substance. For this example, the table should be saved as Manganin.lkt. Be sure to save a copy
of this file in another location so that it is not deleted during your next EES update.
Start a new version of EES and you should find that the substance Manganin has been added to
the Incompressible library. Select Function Info from the Options menu and then select the
Thermophysical properties button. Select the Incompressible button. Choose the conductivity or
specHeat function and then select either All data (or Metals) and you will see that the substance
Manganin appears in the list, as shown in Figure 4-36.
192 Chapter 4: Property Data
Figure 4-36: Function Information dialog showing the new substance Manganin.
4.9NH3H2O (Ammonia-Water)
The fluid NH3H2O provides the thermodynamic and transport properties of ammonia-water
mixtures in subcooled, saturated and superheated conditions. Since NH3H2O is a mixture, its
implementation differs somewhat from that for the pure substances. First, it requires three
independent properties to fix the state. Second, there is a new property function called
MassFraction that returns the mass fraction of ammonia. Third, property designators X and Q are
used to indicate mass fraction and quality, respectively, for NH3H2O. This is very different from
their use with other EES fluids. Table 4-19 lists the property functions that can be used with the
fluid NH3H2O and the units in the SI and English systems.
Chapter 4: Property Data 193
Table 4-19: Property function for the fluid NH3H2O and their units.
Function Name Returns SI Units English Units
Conductivity1 thermal conductivity W/m-K Btu/hr-ft-R
Density density kg/m3, kmol/m3 lbm/ft3, lbmol/ft3
Enthalpy specific enthalpy J/kg, kJ/kg, J/kmol, kJ/kmol Btu/lbm, Btu/lbmol
J/kg-K, kJ/kg-K, Btu/lbm-R
Entropy specific entropy
J/kmol-K, kJ/kmo-K Btu/lbmol-R
IntEnergy specific internal energy J/kg, kJ/kg, J/kmol, kJ/kmol Btu/lbm, Btu/lbmol
J/kg-K, kJ/kg-K, Btu/lbm-R
SpecHeat specific heat capacity
J/kmol-K, kJ/kmo-K Btu/lbmol-R
SurfaceTension2 surface tension N/m lbf/ft
MassFraction mass fraction of ammonia none none
Pressure pressure Pa, kPa, bar, or MPa Psia or atm
Quality quality3 None None
Temperature temperature °C or K °F or R
Viscosity1 dynamic viscosity Pa-s lbm/ft-hr
Volume specific volume m3/kg, m3/kmol ft3/lbm, ft3/lbmol
1. Function can only be used in liquid or vapor states.
2. Function can only be used in a two-phase state.
3. Quality between 0 and 1 indicates a two-phase state. Quality = -0.001 indicates a subcooled state. Quality
= 1.001 indicates a superheated state.
Table 4-20 lists the acceptable property designators for the fluid NH3H2O. Note that the key
difference between this and other EES fluids is that X= indicates a specified mass fraction
(rather than quality) and Q= indicates a specified quality.
The input properties and properties returned by the functions will be in the unit system set with
the $UnitSystem directive or by selecting Unit System from the Options menu. For example, we
can determine the properties of an ammonia-water mixture that is 50% ammonia by mass at
10°C and 1 MPa.
$UnitSystem SI C kPa
Solving indicates that h = -194.8 kJ/kg, Q = -0.001, k = 0.4791 W/m-K, and mu = 0.001294 Pa-s.
The value of quality (-0.001) indicates that the state is a subcooled liquid and therefore it is not
possible to obtain the surface tension. The command:
would lead to an error indicating that SurfaceTension can only be used for saturated solutions.
The thermodynamic property data for ammonia-water mixtures used for the fluid NH3H2O are
based on the mixture equation of state described in:
Viscosity for the liquid phase and surface tension data are from a technical report prepared by
Conde Engineering:
Conde Engineering, 2004, Thermophysical Properties of {NH3 + H2O} Solutions for the
Industrial Design of Absorption Refrigeration Equipment,
http://www.mie.uth.gr/ekp_yliko/nh3_h2oproperties_1.pdf
The thermodynamic properties provided by the fluid NH3H2O have a different reference state
than either of the pure fluids Water or Ammonia and therefore properties like specific enthalpy
obtained using NH3H2O with 100% mass fraction of ammonia will not match those obtained
using the pure fluid Ammonia (and those obtained with 0% mass fraction will not match those
obtained using the pure fluid Water).
Ammonia-water mixtures are used in absorption refrigeration cycles, such as the simple cycle
shown in Figure 4-37. In this cycle, an ammonia-water solution is heated in the generator,
which produces a vapor at state 3 which has a high mass fraction of ammonia. (The rectifier that
further strips water vapor from the vapor is in this cycle, but would be required in practice.) The
vapor is condensed (state 4) and expanded (state 1) into an evaporator where it creates a cooling
effect as the liquid evaporates. The vapor (state 2) enters an absorber where it is absorbed into a
liquid solution (state 5), and pumped to the generator pressure (state 6). The liquid leaving the
generator is weak in ammonia (state 7) and is returned through a throttle (state 8) to the absorber
where it can absorb the ammonia-rich vapor at state 2.
Chapter 4: Property Data 195
throttle 4 3 mgen
valve condenser
7
generator
valve 2
1 evaporator
Tevap = 3°C absorber 8
6 mabs
Qevap 2
T = 5°C 5 pump
C Tabs = 32°C Qabs p = 0.62
Pabs = 400 kPa W p
Figure 4-37: A simple absorption cylcle using ammonia-water as the working fluid pair
The following EES code calculates the heat effects in the Generator, Condenser, Evaporator and
Absorber and the COP of the cycle.
$UnitSystem SI Mass J K Pa C
Q[4]=quality(NH3H2O,T=T[4],P=P[4],X=X[4])
After solving, the Solution window will show that the coefficient of performance (COP) for this
cycle is 0.2144. The COP can be improved using a heat exchanger between streams identified
as 6 and 7 in Figure 4-37. The EES code for this cycle is provided as an example in the EES
Userlib\Examples folder.
IdealGasMixtureProps is an EES Procedure that will determine the specific enthalpy, entropy,
viscosity, thermal conductivity, specific heat capacity and Prandtl number for a mixture of ideal
gases. This Procedure is written in EES and located in the Userlib folder.
Inputs:
F$ a string constant or string variable that contains the names of 1 or more (up to 20)
names of ideal gases that are contained in the EES property library. The names of the
gases are separated with a + sign, e.g., 'CH4+C3H8'.
T the temperature in the units EES is configured to work in.
P the pressure in the units EES is configured to work in. (Pressure is used only for
calculation of specific entropy.)
f[1..N] the mass or mole fractions of the gases represented by string F$. The sum of the values
of f must add to 1.0. Supply mass fractions if EES is configured to work with specific
properties on as mass basis. Otherwise, supply mole fractions.
198 Chapter 4: Property Data
Outputs:
MW the molar mass of the mixture in kg/kmol or lbm/lbmol
h the specific enthalpy of the mixture determined as the mole fraction-weighted average of
the gases in the mixture. The units of h will be returned on a per unit mass basis if EES is
configured to provide properties on a mass basis. Otherwise the units of h will be
returned on a molar basis.
s the specific entropy of the mixture determined as the mole fraction-weighted average of
the gases in the mixture plus the entropy change of mixing the gases. The units of s will
be returned on a per unit mass basis if EES is configured to provide properties on a mass
basis. Otherwise the units of s will be returned on a molar basis.
mu the viscosity of the gas mixture determined using the Wilke Approximation as described
in section 9.5 of Poling et al. (2000).
k the thermal conductivity of the gas mixture determined using the Mason and Saxena
modification, as described in section 10.6 of Poling et al. (2000).
cp specific heat capacity of the mixture. The units of cp will be returned on a per unit mass
basis if EES is configured to provide properties on a mass basis. Otherwise it will be
returned on a molar basis.
Pr Prandtl number of the mixture
As an example, the following program is used to prepare plots of specific entropy and viscosity
for ideal gas mixtures of methane (CH4) and hydrogen (H2) as a function of mole fraction at
20°C and standard barometric pressure.
A Parametric table with columns for y[1] (the CH4) mole fraction, h, s, mu, and k is generated.
Values for y[1] between 0.001 and 0.999 are entered. The table is solved. A plot of the specific
entropy and viscosity versus CH4 mole fraction is shown in Figure 4-38.
Chapter 4: Property Data 199
Figure 4-38: Specific entropy and viscosity of CH4-H2 mixtures at 20°C, 101.3 kPa as a function of CH4
mole fraction.
Figure 4-39: Function Information dialog window configured to show External routines.
The NASA external procedure is accessed from EES with the following calling format:
The string Substance$ is the name of the ideal gas or condensed substance; the name must be
either enclosed in single quotes (e.g., 'CO2') or defined with an EES string variable. The input
variable T is the temperature, which must be provided in units K, regardless of the unit system
settings in EES. The output variables cP, h, and s are the specific heat capacity (in kJ/kmol-K),
specific enthalpy (in kJ/kmol), and specific entropy (in kJ/kmol-K) at the given temperature and
a pressure of 1.0 bar. The specific enthalpy is referenced to zero for stable elements at 25ºC
(298.15 K) and the specific entropy is referenced to zero according to the Third Law of
Thermodynamics. This choice of reference makes it easy to carry out calculations related to
chemical reactions, as discussed in Section 4.4. Note that the variables cP, h, and s are returned
in the units indicated above, regardless of the unit settings in EES.
Ideal gas carbon dioxide (CO2) is a built-in ideal gas. We can use the NASA external procedure
to compare the property values built into EES with the values obtained from the NASA external
procedure at a temperature of 1000 K:
Chapter 4: Property Data 201
Call NASA(G$,T: cP_NASA, h_NASA, s_NASA) "property information from the NASA program"
Note that the $UnitSystem directive sets EES to operate in the same unit system as the NASA
external program so that the values obtained from EES and the NASA database can be directly
compared. The Solution Window is shown in Figure 4-40 and indicates that the values differ,
but by only a small amount. The NASA value is likely to be more accurate.
Figure 4-40: Solution Window for the NASA external procedure example.
The NASA external procedure is accessed for condensed substances in the same manner. For
example, the thermodynamic properties of solid carbon, which is named 'C(gr)' in the NASA
database, is found at 298.15 K using the following line of code.
As expected, the specific enthalpy of solid carbon at 298.15 K is 0 kJ/kmol because solid carbon
is a stable element and 298.15 K is the standard reference temperature. The specific entropy at
these conditions is 5.734 kJ/kmol-K.
Ammonia-Water Properties
Note: Starting with version 9.694, properties of ammonia-water mixtures can be accessed
using fluid NH3H2O, in the same manner as for pure fluids. See Section 4.9.
Mixtures of ammonia and water are the working fluids in some power and refrigeration cycles.
Approximate property data for ammonia-water mixtures based on correlations developed by
202 Chapter 4: Property Data
Ibrahim and Klein (1993) are provided by the NH3H2O external procedure. The NH3H2O external
procedure resides in the \Userlib\EES_System directory and it is provided with all versions of
EES. Information on the use of the NH3H2O external procedure can be obtained from the
Function Information dialog shown in Figure 4-39 by clicking on NH3H2O. Newer and more
accurate properties for ammonia-water mixtures are available in the REFPROP program
distributed as Standard Reference Database 23 by the National Institute of Standards and
Technology (NIST). Information about an interface that allows the REFPROP program to be
called from EES is provided in a subsequent section.
There are eight thermodynamic properties that are considered by the procedure NH3H2O. These
properties are numbered and described in Table 4-21. The units of each property are also listed.
An ammonia-water mixture requires three properties to fix the state. The first input, Code, is a
three digit integer indicating which three of the eight properties are provided as input values.
The numerical values assigned to the properties are shown in Table 4-21 For example, a value
123 indicates that the values of properties 1 (temperature), 2 (pressure), and 3 (ammonia mass
fraction) are provided by the inputs In1, In2, and In3, respectively. All eight properties are
provided in the outputs; therefore, three of these outputs will have the same values as the
corresponding three inputs, depending on the value of the input Code.
The inputs and outputs for the NH3H2O routine must be in the units designated in Table 4-21,
regardless of the unit setting made in EES. The ammonia mass fraction lies between 0 and 1 for
saturated states. Subcooled states are indicated with a mass fraction of x = -0.001 and
superheated states with x = 1.001.
The NH3H2O procedure supports Code values of 123, 128, 137, 138, 148, 158, 168, 178, 234,
235, 238, 248, 258, 268, and 278. However, one (or more) output values can also be fixed in
which case EES will attempt to determine the corresponding input values in an iterative manner
provided that the procedure NH3H2O is called from the Equations Window or a subprogram. In
this way, EES can be used to determine the properties of ammonia-water given any three
independent properties.
Chapter 4: Property Data 203
It is often most convenient to place the NH3H2O call within a function or procedure in the EES
Equations Window, as demonstrated in the following example. Placing the call to NH3H2O in a
procedure eliminates any problem that would otherwise be involved with using the same variable
name for both an input and output in the Equations Window. For example, the procedure below
returns the specific enthalpy and specific entropy given the temperature, pressure, and mass
fraction of ammonia.
Procedure hs(T, P, x: h, s)
call NH3H2O(123, T, P, x: T, P, x, h, s, u, v, q)
end
Note that within the procedure it is fine that three of the output variables (T, P, and x) have the
same name as the three input variables. This would not be possible in the main body of the
Equations Window. The following code uses the subroutine hs to determine the specific
enthalpy and specific entropy of a 50% mass fraction ammonia-water mixture at 450 K and 10
bar:
T=450 [K]
P=10 [bar]
x=0.50 [-]
Call hs(T,P,x: h,s)
Three separate property libraries are provided for mixtures of lithium bromide and water. The
original library LiBr.DLL located in the ..\USERLIB\LIBR folder within the EES directory.
These property functions are based on information from the 1989 ASHRAE Handbook of
Fundamentals. Use of these property functions is not recommended because more accurate
property functions are available. The LiBr.DLL properties are provided in EES solely for
204 Chapter 4: Property Data
Property correlations for lithium chloride-water solutions have also been developed by Patek and
Klomfar (2008) and these are implemented in the LiClH2O.lib (or .lib64) EES library file.
Information about these libraries can be obtained from the Function Information dialog window
by clicking the EES library routines button at the top right of the screen. Next select the library
file by clicking on its name and then click the Function Info button.
The property functions for lithium bromide-water solutions and the possible units for the
properties that are returned are listed in Table 4-22. All of the property information provided to
and returned by these functions must be in the selected unit system, as described in Section 4.1.
Most of these property functions require temperature (T) and salt concentration (x) as input
arguments. The salt concentration is taken to be the mass fraction if EES is configured to
operate with specific properties expressed on a per unit mass basis. If the EES unit system is set
to a molar basis, the salt concentration is taken to be the mole fraction in the Patek and Klomfar
property library.
Table 4-22: Property functions for lithium bromide-water solutions and their units.
(Patek and Klomfar library functions.)
Function Name Returns SI Units English Units
Cond_LiBrH2O(T,x) thermal conductivity W/m-K Btu/hr-ft-R
J/kmol-K, kJ/kmol-
Btu/lbmol-R
Cp_LiBrH2O(T,x) specific heat capacity K, J/kg-K,
Btu/lbm-R
kJ/kmol-K
J/kg, kJ/kg, J/kmol, Btu/lbm
h_LiBrH2O(T,x) specific enthalpy
kJ/kmol Btu/lbmol
massfraction_LiBrH2O(x) mole fraction given mass fraction none none
molefraction_LiBrH2O(w) mass fraction given mole fraction none none
P_LiBrH2O(T, x) pressure Pa, kPa, bar, MPa psia, atm
Q_LiBrH2O(h,P,z :Q,T, x) quality, temperature and composition °C, K for T °F, R for T
J/kmol-K, kJ/kmol-
Btu/lbmol-R
s_LiBrH2O(T,x) specific entropy K, J/kg-K,
Btu/lbm-R
kJ/kmol-K
T_LiBrH2O(P, x) temperature °C, K °F, R
x_LiBrH2O(T, P) equilibrium composition none none
Visc_LiBrH2O(T, x) viscosity Pa-s lbm/ft-hr
As an example, the following code will return the specific heat capacity and viscosity of a 50%
mass fraction lithium bromide-water solution at 50°C:
Chapter 4: Property Data 205
Solving provides C = 2.183 kJ/kg-K and = 0.002095 Pa-s. The property correlations for
lithium chloride-water solutions have the same form and units as those for lithium bromide-water
solutions, with Br in each function replaced by Cl. However, thermal conductivity and viscosity
functions for lithium chloride solutions are currently not provided.
The GENEOS Library
The GENEOS library uses a modification of the Redlich-Kwong equation of state proposed by
Soave (1972) to provide approximate thermodynamic property information for any fluid for
which critical properties are available. This library is included with all versions of EES.
Information about the GENEOS library can be accessed using the Function Information dialog
window by clicking on the External Routines button and then the GEN_EOS folder, as shown in
Figure 4-39. The library consists of the four functions that are listed in Table 4-23. All of these
functions require the reduced temperature (Tr) and reduced pressure (Pr) as inputs. Reduced
temperature is the ratio of the temperature to the critical temperature and reduced pressure is the
ratio of pressure to the critical pressure. The acentric factor (w) is an optional input to the
functions in the GENEOS library. If the acentric factor is not provided, then a default value will
be used; however, the accuracy of the results is likely to improve if the acentric factor for the
fluid of interest is provided. The definition of the acentric factor, as well as more details about
the use of the GENEOS library functions can be found in Klein and Nellis (2012).
The Peng-Robinson library is included with all versions of EES. Information on the functions in
the Peng-Robinson library can be viewed from the Function Information dialog window by
206 Chapter 4: Property Data
clicking on Peng_Robinson.DLL folder shown near the top of the list in Figure 4-39. Information
on how to apply the Peng-Robinson library functions is provided by Klein and Nellis (2012).
The EES_REFPROP interface has been developed for REFPROP versions 8 and newer in order
to allow the NIST property database to be used with the equation-solving and other features of
EES in a manner that is similar to the use of the EES built-in properties. Note that EES provides
built-in high accuracy property data for many pure fluids, so this interface should only be of
interest when property data for the pure fluid or mixture of interest are not available in EES. The
EES_REFPROP interface is an extra cost option. A summary of the EES_REFPROP commands
is provided below. Additional information about this interface can be found on the F-Chart
Software website at http://fchartsoftware.com/ees/ees-refprop.php. Note the EES can also read
REFPROP 10 pure fluid (.fld) files and thereby provide property data for these data. However,
this approach does not provide properties for mixtures. Also transport property information is
not provided using .fld files at this time.
EES_REFPROP will return thermodynamic property information for a specified state, which
may include molecular weight, saturation property information, transport properties, fugacity or
critical properties depending on the value of the parameter MODE. The required inputs and
calculated outputs differ for different values of MODE as explained below.
The first argument in the EES_REFPROP Call statement identifies the fluid system which may
be a pure fluid or a mixture of up to 20 components. Fluid names are ordinarily the familiar
refrigerant names, e.g., R12, R134a, etc. or any mixture name previously defined within the
REFPROP program, e.g., R406c. A complete list of fluid names is provided in the REFPROP
and manuals. The fluid system name can be a string constant enclosed within single quotes or an
EES string variable, e.g, FLUID$ that has been set to the name of the fluid. A mixture of pure
components is identified by use of a plus (+ sign between the component names, e.g.,
'R134a+R32'. Upper and lower case letters are treated identically. Spaces should not appear in
the fluid system name.
Chapter 4: Property Data 207
The second argument, MODE, is an integer that identifies the calculations to be done and the
necessary inputs and outputs. Rather than specify an integer for MODE, however, it is more
convenient to use a text code in the form of an EES variable. For example, MODE=12 indicates
that thermodynamic properties corresponding to specified inputs of temperature and pressure are
to be calculated. However, you can use variable TP (which is set to 12) rather than 12 itself for
MODE. The file EES_REFPROP.TXT includes EES variables for each of the modes listed
below. To make use of these codes, ensure that the EES_REFPROP.TXT file is in the
\EES32\USERLIB\ subdirectory and include the following line at the top of your EES file.
$INCLUDE \EES32\USERLIB\EES_REFPROP\EES_REFPROP.TXT
By default, the EES_REFPROP expects inputs and outputs to be in SI units with temperature in
K, pressure in kPa, energy in kJ with specific properties on a molar basis. Viscosity is returned
in Pa-s and thermal conductivity has units of W/m-K. However, if a $ConvertEESREFPROPUnits
directive is placed in the Equations Window, EES will automatically convert all inputs to and
outputs from the EES_REFPROP interface so that they correspond to the unit system set in
EES. Specific properties on a molar basis are also converted to a mass basis if EES is set to
return properties on a mass basis.
Each of the MODES and their associated inputs and outputs are provided below.
MODE = MW (=0)
Description: Molecular mass of a specified pure fluid or mixture
In1 = mole fraction of first component in saturated liquid (skip for pure fluid)
...
InN = mole fraction of next to last component
Out1 = Molecular weight
MODE = TP (=12)
Description: Calculate thermodynamic properties for given temperature and pressure
In1 = Temperature
In2 = Pressure in
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Out1 = Temperature
Out2 = Pressure
Out3 = Density
Out4 = Specific volume
Out5 = Specific enthalpy
Out6 = Specific entropy
Out7 = Quality molar basis(<0 for subcooled liquid, >1 for superheated vapor)
Out8= Specific heat at constant volume (Cv)
Out9 = Specific heat at constant pressure (Cp)
Out10 = Speed of sound (not applicable for two-phase state)
Chapter 4: Property Data 209
Out11 = Quality mass basis(<0 for subcooled liquid, >1 for superheated vapor)
Out12..12+N = mole fractions of the liquid phase for the N components in the mixture
Out12+N+1..Out12+2N = mole fractions of the vapor phase for the N components
MODE = TD (=13)
Description: Calculate thermodynamic properties for given temperature and density
In1 = Temperature
In2 = Density
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = TV (=14)
Description: Calculate thermodynamic properties for given temperature and specific volume
In1 = Temperature
In2 = Specific volume
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = TH (=15)
Description: Calculate thermodynamic properties for given temperature and specific enthalpy
In1 = Temperature
In2 = Specific enthalpy
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = TS (=16)
Description: Calculate thermodynamic properties for given temperature and specific entropy
In1 = Temperature
In2 = Specific entropy
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = TQ (=17)
Description: Calculate thermodynamic properties for given temperature and molar quality
In1 = Temperature
In2 = Quality (0 for saturated liquid, 1 for saturated vapor)
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
210 Chapter 4: Property Data
MODE = PD (=23)
Description: Calculate thermodynamic properties for given pressure and specific enthalpy
In1 = Pressure
In2 = Density
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = PH (=25)
Description: Calculate thermodynamic properties for given pressure and specific enthalpy
In1 = Pressure
In2 = Specific enthalpy
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = PS (=26)
Description: Calculate thermodynamic properties for given pressure and specific entropy
In1 = Pressure
In2 = Specific entropy
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = PQ (=27)
Description: Calculate thermodynamic properties for given pressure and molar quality
In1 = Pressure In2 = Quality molar basis (0 for saturated liquid, 1 for saturated vapor)
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Outputs: Same as for MODE = TP
MODE = ST (=70)
Description: Calculate surface tension for given saturation temperature
In1 = Temperature
In2 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Out1: surface tension of fluid or mixture
In1 = Temperature
In2 = Density
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Out1..OutN: fugacity of each fluid
MODE = DC (=95)
Description: Calculate the dielectric constant for given temperature and density
In1 = Temperature
In2 = Density
In3 = mole fraction of first component (skip for pure fluid)
...
InN = mole fraction of next to last component
Out1: dielectric constant of the fluid
The following example EES file shows how the EES_REFPROP interface can be used to
calculate the properties of a mixture of R32 and R134a. In this example, the
$ConvertEESREFPROPUnits directive is used so that the inputs to and the outputs from the
interface are automatically converted to the EES unit system, which in this example is English
units.
Mixture$='R32+R134a'
mf=0.3 "mole fraction"
TF=80 [F] "temperature"
rho_m=80[lbm/ft^3] "density"
TD=13 "mode for flash calculation, given temperature and density"
Call EES_REFPROP(Mixture$, TD, TF, rho_m, mf :T,
P,rho,v,h,s,Q,Cv,Cp,w,Qm,x_R32,x_R134a,y_R32,y_R134a)
CRIT=100 "mode for calculation of critical properties"
Call EES_REFPROP(Mixture$, CRIT, mf : Tc, Pc, rhoc)
ST=70 "mode for calculation of surface tension"
Call EES_REFPROP(Mixture$, ST, TF, mf : sigma)
TRN=90 "mode for calculation of transport properties"
Call EES_REFPROP(Mixture$, TRN, TF, rho, mf : Visc, Cond)
212 Chapter 4: Property Data
The Solution window for this example appears as follows: Note that the results use the ability of
EES to display variables in a primary and alternative set of units.
Ideal gas property files must have an .idg filename extension. An equation of state is not needed
since it is assumed that the fluid obeys the ideal gas equation of state. Correlations are required
for the specific heat capacity at constant pressure, viscosity, and thermal conductivity as a
function of temperature. Note that particular attention must be paid to the reference states if the
gas is to be used in calculations involving chemical reactions. Therefore, the enthalpy of
formation and the Third-Law entropy values at 298.2 K and 1 bar (or 1 atm) must be supplied.
The first line provides the name of the ideal gas in the variable Name. The second line provides
the molar mass in the variable MW. The next lines provide the inputs for the correlation used to
calculate the specific heat capacity at constant pressure. The form of the correlation is:
9
T bi
cP ( T ) = ai (4-13)
i=0 Tn
The next lines provide the reference temperature (Tref) and pressure (Pref) in K and kPa,
respectively. The enthalpy of formation (hform) and Third law entropy (s0) in kJ/kmol and
kJ/kmol-K, respectively, at the reference conditions must be provided. The remaining lines
provide correlations for the viscosity and thermal conductivity. The form of these correlations
are:
5
(T ) = i
vT (4-14)
i=0 i 1
and
k (T ) = 5
ti T i 1 (4-15)
i=0
An example file providing the parameters for ideal gas CO2 is provided below. This file is, of
course, not needed since EES provides built-in property data for carbon dioxide modeled as an
ideal gas with the fluid CO2. The properties of a new ideal gas can be entered by editing this file
appropriately. Note that the first row in the file causes the new gas to be named TestCO2; this is
the name that will be recognized in EES.
Place the text file above in the \Userlib directory as TestCO2.idg and start EES. Select Function
Info from the Options menu and select Ideal Gases. The gas TestCO2 is now available from the
list of gases, as shown in Figure 4-32.
216 Chapter 4: Property Data
Figure 4-41: Function Information dialog showing the added ideal gas substance TestCO2.
Providing Real Fluid Property Data represented by the Martin-Hou Equation of State
Property information can be added for fluids that can be represented by the Martin-Hou (1955)
equation of state. The input parameters for a real fluid are provided in a file that has an .mhe (for
Martin-Hou Equation) filename extension. This file must be placed in the ..\UserLib
subdirectory if it is to be automatically loaded when EES is started.
//Comment line 1
//Comment line 2
//additional comment lines as necessary
Name|Fluid Information message
MW {molecular weight}
0 {not used}
ad {ad Liquid density fit=ad+bd*Tz^(1/3)+cd*Tz^(2/3)+dd*Tz+ed*Tz^(4/3) }
bd {bd +fd*sqrt(Tz)+gd*(Tz)^2}
cd {cd where Tz=(1-T/Tc) and Liquid Density[=]lbm/ft3 }
dd {dd}
ed {ed}
fd {fd}
gd {gd}
ap {ap Vapor pressure fit: lnP=ap/T+bp+cp*T+dp*(1-T/Tc)^1.5+ep*T^2}
Chapter 4: Property Data 217
The file consists of 75 lines after one or more comment lines that begin with the // characters.
The first line after the comments provides the name of the fluid that EES will recognize in the
property function statements (the variable Name). An optional comment can be placed on this
line after the | character; this comment will be displayed when the Fluid Info button in the
Function Information dialog is pressed while this fluid is selected. The fluid itself will appear in
alphabetical order with the other fluid names in the Function Information dialog.
The next 74 lines each contain one number. A comment in curly braces follows on the same line
(after one or more spaces) to identify the number. The molecular weight, MW, must be provided
followed by the coefficients for the correlation for liquid density:
2 4
l ( T ) = ad + bd Tz
1 1
+ cd Tz 3 + d d Tz + ed Tz 3 + f d Tz 2 + g d Tz
2
3 (4-16)
T
Tz = 1 (4-17)
Tc
where Tc is the critical temperature. Note that each of the coefficients must be provided in units
that are consistent with l in units of lbm/ft3 and T in units of R. The coefficients for the
correlation for vapor pressure:
ap
ln ( P ) = + b + c T + d 1 T + e T 2
1.5
(4-18)
v p p p p z
T Tc
must be provided in units that are consistent with Pv in psia and T in units of R.
The details of the equation of state are provided next. Pressure, volume and temperature are
related by the Martin-Hou equation of state in the following form:
T T
RT A 2 + B2 T + C 2 exp A 3 + B3 T + C3 exp
P= + Tc
+ Tc
( v b) ( v b) ( v b)
2 3
(4-19)
T T T
A4 + B4 T + C4 exp A5 + B5 T + C5 exp A6 + B6 T + C6 exp
T T T
+ c
+ c
+ c
The coefficients must be provided in units that are consistent with P in psia, T in R, and v in
ft3/lbm. A method for obtaining the coefficients is described by Martin and Hou (1955).
A correlation for the ideal gas specific heat capacity at constant volume (cv0) must be provided in
the following form:
ec
c (T ) = a +b T +c T2 + d T3 + (4-20)
v0 c c c c
T2
where the coefficients should provided in units that are consistent with cv0 in Btu/lbm-R and T in
R. The values of href and sref are the specific enthalpy and specific entropy at reference
conditions (saturated liquid at -40ºF).
Finally, coefficients for the gas and liquid phase viscosity and thermal conductivity correlations
must be provided. The first parameter (VCT) provides the type of correlation for viscosity;
currently there are two choices, VCT = 2 indicates polynomial for gas and liquid viscosity while
VCT = 2.1 indicates polynomial for gas viscosity and a logarithmic function for liquid viscosity.
A polynomial correlation for gas phase viscosity is provided by:
x1012 = A + B T + C T 2 + D T 3 (4-21)
g gv gv gv gv
x1012 = A + B T + C T 2 + D T 3 (4-22)
l lv lv lv lv
You may need to curve fit tabular property data or data obtained from a correlation in a different
form to obtain the appropriate parameters. The file below includes the information for the fluid
isopropanol.
0 {gd}
-1.288927E+04 {ap Vapor pressure fit: lnP=a/T+b+cT+d(1-T/Tc)^1.5+eT^2}
3.156751E+01 {bp where T[=] R and P[=]psia}
-1.763007E-02 {cp}
0 {dp}
6.209092E-06 {ep}
0 {not used}
0.178564 {R Gas constant in psia-ft3/lbm-R}
9.28443E-03 {b Constants for Martin-Hou EOS/English_units}
-22.07494 {A2}
9.56524E-03 {B2}
-520.92446 {C2}
1.64008E+00 {A3}
-1.11778E-03 {B3}
28.73835 {C3}
-1.76126E-02 {A4}
0 {B4}
0 {C4}
0 {A5}
2.18204E-07 {B5}
-7.35278E-03 {C5}
0 {A6}
0 {B6}
0 {C6}
5.47500 {Bexp - Martin-Hou exponential constant}
0 {alpha}
0 {C'}
3.764019E-02 {ac cv(0 pressure) = ac + bc T + cc T^2 + dc T^3 + ec/T^2 }
6.168131E-04 {bc where T[=]R and Cv[=]Btu/lb-R }
-1.411459E-07 {cc}
7.379913E-12 {dc}
0 {ec}
273.062322 {href offset set to 0 for sat'd liquid at -40F}
0.0459364 {sref offset}
690.961 {Pc [=] psia}
914.958 {Tc [=] R}
0.05408 {vc [=] ft3/lbm}
0 {not used}
0 {not used}
2.1 {Viscosity correlation type: 2.1 indicates log type for liquid}
200 {Lower limit of gas viscosity correlation in K}
1000 {Upper limit of gas viscosity correlation in K}
-10.859E5 {Agv GasViscosity*1E12=Agv+Bgv*T+Cgv*T^2+Dgv*T^3}
3.0873e4 {Bgv where T[=]K and GasViscosity[=]N-s/m2 }
-4.8098 {Cgv}
0 {Dgv}
185 {Lower limit of liquid viscosity correlation in K}
508 {Upper limit of liquid viscosity correlation in K}
-0.7009 {Alv log10(Liquid Viscosity)=Alv+Blv/T+Clv*T+Dlv*T^2}
8.415e2 {Blv where T[=]K and Liquid Viscosity[=]N-s/m2}
-8.6068e-3 {Clv}
8.2964e-6 {Dlv}
2 {Conductivity correlation type: set to 2: do not change}
350 {Lower limit of gas conductivity correlation in K}
560 {Upper limit of gas conductivity correlation in K}
0.0165723 {Agk} GasConductivity=Agk+Bgk*T+Cgk*T^2+Dgk*T^3
-4.93183e-5 {Bgk where T[=]K and GasConductivity[=]W/m-K}
1.80816e-7 {Cgk}
0 {Dgk}
185 {Lower limit of liquid conductivity correlation in K}
483 {Upper limit of liquid conductivity correlation in K}
2.209607E-01 {Alk LiquidConductivity=A+B*T+C*T^2+D*T^3 (from 3M data)}
-4.746872E-04 {Blk where T[=]K and LiquidConductivity[=]W/m-K}
Chapter 4: Property Data 221
1.090827E-06 {Clk}
-1.456185E-09 {Dlk}
0 {not used: terminator}
Placing the file isopropanol.mhe in the ...\UserLib (UserLib64 for the 64-bit version)
subdirectory and EES will automatically add the real fluid isopropanol to the list of fluids, as
shown in Figure 4-42.
Figure 4-42: Function Information dialog showing the added real fluid isopropanol.
The properties for the additional fluid are obtained just as any for any of the built-in properties in
EES. For example, the enthalpy for this substance would be obtained as follows:
EES can access the property data provided by REFPROP for pure fluids and fluid mixtures
using the EES_REFPROP interface as described in Section 4.10. This interface provides the
most direct way to utilize the thermodynamic and transport property data from REFPROP in
EES.
The coefficients in the equations REFPROP uses to calculate property data for pure fluids are
provided in .fld files that are distributed with the program. These files are contained in the
Fluids folder within the REFPROP directory, e.g., C:\Program Files (x86)\REFPROP\Fluids.
Each file provides information for a separate fluid. For example, CO2.FLD provides the
necesary information for carbon dioxide.
EES can read .fld files developed for REFPROP version 10 using the $INCLUDE directive. For
example, the following directive will read the REFPROP .fdl file for carbon dioxide.
After executing this directive, EES is able to provide thermodynamic property information for
the fluid, in the same manner as for built-in fluids. The fluid name used in EES property
functions is the file name (without the .fld) appended with _rp. For example,
$UnitSystem SI K kP kJ mass
h_f=enthalpy(CO2_rp,T=250 [K],x=0)
h_g=enthalpy(CO2_rp,T=250 [K],x=1)
will return the specific enthalpy of saturated liquid and vapor for carbon dioxide at 250 K. The
fluid name can be provided using a string variable, e.g., F$='CO2_rp'.
Notes:
1. The values returned by EES in this manner will not be exactly the same as those provided by
REFPROP. EES uses the coefficients in the fld file for its own property calculations, which
are similar but not identical to those in REFPROP. The differences should be minor.
2. Tansport properties (viscosity, thermal conductivity, surface tension) are not provided for .fld
fluids at this time.
3. Online help listing the source and applicable ranges of property information are not provided
for fluids entered with .fld files. Please use the REFPROP program to view this information.
4. The default reference states for specific enthalpy and specific entropy provided in the .FDL
file may be changed in EES using the $Reference directive, e.g.,
$Reference CO2_rp IIR
5. The Property Plot command in the Plot menu can be applied to fluids using the .fld files, as
shown in Figure 4-43 and Figure 4-44.
Chapter 4: Property Data 223
10
5 CO2rp
4
10
P [kPa]
280 K
250 K
3
10
References
Haar, L. Gallagher, J.S., and Kell, G.S (Hemisphere, 1984). NBS/NRC Steam Tables,
Hemisphere Publishing Company, Washington, (1984).
Ibrahim, O.M., Klein, S.A.,"Thermodynamic Properties of Ammonia-Water Mixtures,"
ASHRAE Trans.: Symposia, 21, 2, 1495 (1993).
Klein, S.A. and Nellis, G.F., Thermodynamics, Cambridge University Press, New York, (2012).
Martin, J.J. and Hou, Y.C., ”Development of an Equation of State for Gases,” A.I.Ch.E Journal,
1:142, (1955)
McBride, B.J., Zehe, M.J., and Gordon, S "NASA Glenn Coefficients for Calculating
Thermodynamic Properties of Individual Species", NASA/TP-2002-211556, Sept. (2002),
http://gltrs.grc.nasa.gov/reports/2002/TP-2002-211556.pdf
Melinder, Å Properties of Secondary Working Fluids for Indirect Systems, IIF/IIR, 2010,
http://www.iifiir.org/en/details.php?id=1177
National Institute of Standards and Technology, NIST Standard Reference Database 23, NIST
Reference Fluid Thermodynamic and Transport Properties Database (REFPROP): Version
10, https://www.nist.gov/srd/refprop.
Patek, J. and Klomfar, J., "A computationally effective formulation of the thermodynamic
properties of LiBr-H2O from 273 to 500 K over full composition range", Int. J. of
Refrigeration, Vol 29, pp. 566-578, (2006)
Patek, J. and Klomfar, J., "Thermodynamic properties of the LiCl-H2O system at vapor-liquid
equilibrium from 273 K to 400 K", Int. J. of Refrigeration, Vol. 31, pp. 287-303, (2008)
Peng, D and Robinson, D.B., "A New Two-Constant Equation of State", Ind. Eng. Chem.
Fundam., Vol. 15, No. 1, pp. 59-64,(1976)
Poling, B.E., Prausnitz, J.M, and O'Connell, J.P., The Properties of Liquids and Gases, 5th
edition, McGraw-Hill, (2000), ISBN 0-07-011682-2
Saul, A. and Wagner, W., “International Equations for the Saturation Properties of Ordinary
Water Substance,” J. Phys. Chem. Ref. Data, 16, 893 (1987)
Soave, G., “Equilibrium Constants from a Modified Redlich-Kwong Equation of State,”
Chemical Engineering Science, Vol. 27, pp. 1197-1203, (1972)
Span, R., Multiparameter Equations of State, Springer, ISBN 3-540-67311-3, (2000)
Wagner, W., and Pruss, A. “International Equations for the Saturation Properties of Ordinary
Water Substance. Revised According to the International Temperature Scale of 1990,” J.
Phys. Chem. Ref. Data, 22, 783, (1993)
5 CONVERGENCE AND DEBUGGING
EES is not a programming language like C, Pascal, FORTRAN or MATLAB. Programming
languages use assignments; that is, they require the user to enter statements in which the variable
that is to be determined (i.e., assigned a value) is on the left of the equal sign. All variables
appear on the right of the equal sign and they must have pre-determined values.
EES is very different because it is an equation-solver. EES uses equations that are simply
relationships between variables. These equations can be entered in any way that you wish.
There is no requirement that the variables on the right side of an equation have pre-determined
values. The equations can be entered in any order that you wish. The equations can be linear or
non-linear. Non-linear equations may have multiple solutions and necessarily require iterative
solution methods. Unlike any programming language, EES automatically recognizes when
iteration is needed and it will internally apply a variety of powerful numerical methods to solve
the system of equations that have been entered into the Equation Window. However, it is not
always possible to solve sets of non-linear equations without some user input. The most
important user input required for this purpose is a set of guess values that can be used as a
starting point in the iterative solution process. This chapter reviews the basic solution methods
that EES employs to solve sets of non-linear equations in order to demonstrate the need for guess
values. It also describes debugging techniques that are available in EES that can be used to
ensure that the equation set converges to the solution that you intended.
This equation does not have an analytic solution. It must be solved numerically. The most
convenient way to solve one or more non-linear equations is to rewrite the equation(s) in terms
of a residual by subtracting the right side of the equation from the left side. Equation (5-1) can
be rewritten in terms of the residual, f(x):
A solution to this equation is a value of x that causes the residual, f(x), to be zero. Non-linear
equations may have multiple solutions. This is one reason that guess values and bounds may be
needed during the solution process in order to ensure that the solution that is obtained is the
desired solution, as discussed in Section 2.2.
A plot of f(x) for values of x between 0 and 15 is shown in Figure 5-1. There is only one real
solution in this range and that solution occurs at x = 11.5726.
One way to numerically identify this solution is to use a Taylor’s series expansion of Eq. (5-2),
as shown in Eq. (5-3); note that only the first through third order terms are shown for clarity. In
Eq. (5-3), xi is the current (or guessed) value of x and xs is the solution; i.e., the value of x that
results in the residual f(xs) being equal to zero.
df (xi ) 1 d 2 f (xi ) 1 d 3 f (xi )
f (x ) = f (x ) + (x x )+ x) + (x )
2
... = 0
3
x
(x
s i dx 2 s i s i
s i
dx dx3
2! 3!
(5-3)
Equation (5-3) provides the exact solution to the problem but is not solvable due to the infinite
nature of the series. The numerical iteration technique ignores the second order and higher
terms, allowing Eq. (5-3) to be written as:
where
df ( xi )
J ( xi ) = (5-5)
dx
Chapter 5: Convergence and Debugging 227
and xi+1 is an improved estimate for x, i.e., a value that hopefully results in a value of f(xi+1) that
is closer to zero but not exactly equal to zero since Eq. (5-4) is an approximation. We are trying
to find a value of xi+1 that causes f(xi+1) to be closer to zero. Therefore, the left side of Eq. (5-4)
can be set to zero in order to select our best value of xi+1:
f (x )
xi+1 = xi i (5-7)
J ( xi )
Equation (5-7) provides a method in which improved estimates of x can be obtained iteratively.
This solution technique is called Newton’s method and it is very efficient at finding a solution,
when it works.
To solve the equation, Newton’s method proceeds using the following steps.
1. An initial guess is made for x1 (e.g., 10).
2. The residual, f(x1), is evaluated from Eq. (5-2).
3. The derivative, J(x1), is evaluated (typically numerically but in this case analytically):
df ( x1 )
3.5 ( 2 ) x + 2 = 2.5 (10 ) 3.5 ( 2 )(10 ) + 2 = 11.06
1.5
J (x ) = = 2.5 x
1.5
(5-9)
1 1 1
dx
4. The next estimate for x, x2, is calculated using Eq. (5-7).
f ( x1 ) ( 23.77 )
x =x = 10 = 12.15 (5-10)
J ( x1 )
2 1
11.06
Steps 2 to 4 are repeated using the most recent value of x in order to evaluate the residual, f, and
its derivative, J. Each iteration (hopefully) provides an improved estimate for x.
The EES program below automatically carries out 5 of these iterations using the Duplicate
command and arrays, discussed in Section 1.7.
The Arrays Table in Figure 5-2 shows the results of the iterative process.
Note that Newton’s method converged to a solution of 11.57 (which is the solution that was
graphically identified in Figure 5-1) after just a few iterations. When Newton’s method works, it
works well.
Stopping Criteria
Some type of criterion is needed to stop the iteration process. The criterion could be the number
of iterations (as was used in the EES program above, which was terminated after 5 iterations).
Alternatively, we could monitor the absolute value of the residual, f(x), or the absolute value of
the change in the independent variable between iterations, xi+1 − xi, and stop the iteration process
when these indicators become smaller than a specified tolerance. These are the criteria that can
be selected in the Stop Crit tab of the Preferences dialog (selected from the Options menu). The
stop criteria set in Figure 5-3 will cause the iteration process to stop when the number of
iterations reaches 250, or the relative residual (i.e., the residual normalized by the value of the
left side of the equation, assuming it is not zero) is reduced below 1x10-6, or the change in
variables between iterations is reduced below 1x10-9. In addition, the iterations will stop if the
elapsed time reaches 3600 s.
Chapter 5: Convergence and Debugging 229
The stop criteria used by EES can also be specified using the $StopCriteria directive. For
example, the statement:
placed at the top of the Equations Window will result in the same stop criteria shown in Figure 5-
3. Stop criteria specified with the $StopCriteria directive override those set in the Stop Crit tab of
the Preferences dialog.
Unfortunately, Newton’s method (or any other iterative method for solving non-linear sets of
equations) does not always work. A poor initial guess can cause the method to diverge or to
encounter a numerical problem (e.g., raising a negative number to a non-integer power). Try, for
example, running the EES program with an initial guess of 5 instead of 10 and see what happens.
(You will not be able to obtain a solution using Newton’s method.) The first estimate of the
unknown quantity (i.e., x1) is called a guess value. As you can see from this simple example, the
choice of guess value is very important. Guess values and lower and upper bounds for each
variable in EES can be specified by selecting Variable Info from the Options menu, as discussed
in Section 1.2.
x 2 + y 2 = 18
2 (5-11)
x3 = 2
y
230 Chapter 5: Convergence and Debugging
f1 ( x, y )
f = (5-12)
f 2 ( x, y )
where
f1 ( x, y ) = x 2 + y 2 18
2
f ( x, y ) = x 3 +2 (5-13)
2
y
The Jacobian for a system of two equations in two unknowns is a 2x2 matrix. The first column
of the first row contains the partial derivative of the first equation with respect to the first
variable:
f1
J = =2x (5-14)
1,1
x
The second column of the first row contains the partial derivative of the first equation with
respect to the second variable:
f1
J = =2y (5-15)
1,2
y
The first column of the second row contains the partial derivative of the second equation with
respect to the first variable:
f
J 2,1 = 2 = 3 x2 (5-16)
The second column of the second row contains the partial derivative of the second equation with
respect to the second variable:
f2 2
J = = (5-17)
2,2
y y2
In general Ji,j is the partial derivative of equation i with respect to variable j. For this example,
the Jacobian matrix is:
Chapter 5: Convergence and Debugging 231
2x 2y
(5-18)
J = 2
3x 2
y 2
Newton’s method, as presented in Eq. (5-7), can be extended for this system of two equations
and two unknowns according to:
xi+1 xi
= J 1f (5-19)
yi+1 yi
1
where J is the inverse of the Jacobian matrix. For a 2x2 matrix, the inverse can be written as:
J1,2
1 J 2,2 (5-20)
J 1
=
( J 1,1 J 2,2 J1,2 J 2,1 ) J 2,1 J1,1
(J 2,2 f1 J1,2 f 2 )
We can illustrate this solution process in EES. Initial guesses for x (x1) and y (y1) are needed to
start the iterative process. Consider the following initial set of guesses:
x 2
1 = (5-23)
y1 3
"initial guesses"
x[1]=2
y[1]=3
The iterative process is carried out 10 times using a Duplicate loop. The residual is computed
according to Eq. (5-13).
232 Chapter 5: Convergence and Debugging
"calculate Jacobian"
J11[i]=2*x[i]
J12[i]=2*y[i]
J21[i]=3*x[i]^2
J22[i]=2/y[i]^2
Run the EES code to obtain the Arrays Table shown in Figure 5-4.
Figure 5-4: Arrays Table showing iteration results for 10 iterations of Newton's method.
The values of the variables x and y converge to -1.147 and 4.085, respectively, after 8 iterations;
this is the correct solution to this problem. Of course, it is not necessary to do the iterations
explicitly to solve this system of equations in EES. The solution could have been obtained by
entering the following two equations directly into the Equations Window:
Solving will show the same result as obtained for the last iteration in Figure 5-4. However, to
obtain these results, EES internally had to use a numerical technique that is similar to Newton’s
method.
Newton’s method applies to both linear and non-linear sets of equations. If the equations are
linear then convergence will generally occur after one iteration, regardless of the guess values
that are provided for the unknown variables. For a set of non-linear equations the number of
iterations required depends on the guess values as well as on the stopping criteria. The stopping
criteria are set from the Stop Crit tab in the Preferences dialog (selected from the Options menu).
The Jacobian matrix plays a key role in the solution of algebraic equations. It is also used to
block the set of equations, as explained in the next subsection. EES evaluates the Jacobian
matrix numerically, which necessarily introduces some error. The accuracy of the Jacobian may
change the number of iterations required to solve the equations, but it does not necessarily affect
the accuracy of the solution. Because EES does all calculations with 80 bit precision (about 20
decimal places), numeric evaluation of the Jacobian rarely results in numerical problems from
loss of precision.
In most equation sets, many of the elements of the Jacobian matrix are zero. It is wasteful to
store these zero elements and even more wasteful to use them in multiplication processes. A
matrix with many zero elements is called a sparse matrix. Special techniques are available to
efficiently work with sparse matrices; EES automatically uses sparse matrix routines as needed.
Without the use of sparse matrix techniques, the number of simultaneous equations that could be
solved in a reasonable time using EES would be substantially reduced. Certainly it would not be
possible to solve problems with 6,000 equations, which is the current limit in the Commercial
version. (12,000 equations can be used in the Professional version and 24,000 can be used in the
64-bit Professional version.)
Newton’s method does not always work. This is particularly true if the guess values are not
reasonably close to the desired solution. The value of the residuals of the equations should
become closer to zero after each iteration. When EES is unable to reduce the residuals using
Newton’s method, it will attempt to use several alternative backup methods. One method is to
reduce the step size, according to:
xi+1 xi
= J 1f (5-24)
y
i+1 yi
where is a factor between 0 and 1. Smaller values of improve the chances of having
a difficult set of equations converge, but using any value of less than one increases the number
of iterations required to obtain a solution. For example, when is 0.5, approximately 18
iterations are required to achieve the result that was obtained in Figure 5-4 with 8 iterations.
EES will control the value of during the calculations in order to cause the residuals to be
closer to zero during each iteration. If this method is also unsuccessful then EES will attempt
a few other methods and finally quit if it is unable to solve the equations.
234 Chapter 5: Convergence and Debugging
To illustrate this method, consider the set of eight equations in eight unknowns shown below:
x3 + x8 = 11 (5-25)
x4 = x7 + 4 (5-26)
x5 x6 x7 = 8 (5-27)
x1 + x4 x = 1
2
6 (5-28)
x2 + x8 = 10 (5-29)
x3 x5 + x7 + x8 = 5 (5-30)
x7 = 7 (5-31)
x1 + x6 + x7 = 14 (5-32)
These equations have been entered into the Equations Window (Figure 5-5) and used to obtain
the solution shown in Figure 5-6.
Figure 5-5: Eqs. (5-25) through (5-32) entered in to the Equations Window
Chapter 5: Convergence and Debugging 235
These equations could be solved as one simultaneous set. However, they can be more easily
solved if they are reordered and blocked; EES accomplishes this automatically. For example, the
process of solving Eqs. (5-25) through (5-32) can be simplified substantially if one recognizes
that Eq. (5-31) and Eq. (5-26):
Block 0
x7 = 7 (5-33)
x4 = x7 + 4
can be solved immediately and alone in order to provide x7 = 7 and x4 = 11. With x7 and x4
known, Eq. (5-28) and Eq. (5-32):
Block 1
x + x x2 = 1 (5-34)
1 4 6
x1 + x6 + x7 = 14
can be solved simultaneously to determine x1 = 3.113 and x6 = 3.887. With x1, x4, x6, and x7
known, Eq. (5-27):
Block 2
(5-35)
x5 x6 x7 = 8
Block 3
x3 + x8 = 11 (5-36)
x3 x5 + x7 + x8 = 5
Block 4
(5-37)
x2 + x8 = 10
236 Chapter 5: Convergence and Debugging
can be solved for x2 = -3.832. At this point, all of the equations have been solved and, in this
case, a maximum of two equations needed to be solved simultaneously.
Blocking and reordering the equations is useful even when all of the equations are linear;
however, in this case it is not essential. When one or more of the equations are nonlinear, as in
this example, then blocking of equations is indispensable as it reduces the required number of
iterations needed to solve the problem and improves the likelihood of finding a solution. It is
much easier to solve several small sets of equations than one larger set. EES is able to recognize
groups of equations prior to solution by inspecting the Jacobian matrix using the Tarjan (1972)
algorithm.
Section 5.1 summarized the solution methods that EES employs to solve equations. EES
modifies each equation so that it is represented as a residual by subtracting the right side of the
equation from the left side. EES will then reorder and block the equations in order to optimize
the computational efficiency of the solution process. Consequently, the equations that you enter
may be solved in an order that is different from the order that you entered them. Knowing the
order in which EES solves the equations can be very helpful to understanding the nature of your
system of equations. This information can be also be very helpful for debugging purposes. The
order that the equations are solved, the values of the residuals, and other information are
presented in two formats. In the Commercial version, this information is shown in the Residuals
Window,, which is discussed in Section 5.2. In the Professional version, this information is
presented in the Computational Flow Window, which is discussed in Section 5.3. (The
Residuals Window can also be made to appear in the Professional version by holding the Ctrl
key down while selecting Computational Flow from the Windows menu.)
Blocks
Figure 5-7 shows the Residuals Window (select Residuals from the Windows menu) for the
equation set associated with Eqs. (5-25) through (5-32). The first column shows the block
number which indicates the reordering that EES has done to solve the equations; note that this
blocking results in the same result that was identified in Eqs. (5-33) through (5-37). Equations
that have a single unknown and can be solved one at a time are assigned to Block 0, as shown in
Eq. (5-33). The order that the equations appear in block zero is the order in which EES attempts
to solve them. For example, note that EES has chosen to solve Eq. (5-31) first, even though it
was the seventh equation in order of appearance in the Equations Window. With x7 known, x4
can be found by solving Eq. (5-26). That completes Block 0 for this example because the next
Chapter 5: Convergence and Debugging 237
two equations must be solved simultaneously in Block 1 in order to determine x1 and x6. Note
that the variables x_1 and x_6 are shown in bold in the rows for Block 1 because these are the
unknown variables in this block. Blocks 0 through 4 are solved sequentially, with all of the
equations in the same block (except block 0) being solved simultaneously.
Residuals
The Residuals Window displays the relative and absolute residuals for every equation in the
main program, as well as in subprograms and modules (discussed in Chapter 10). The absolute
residual of an equation is the difference between the values on the left and right hand sides of the
equation. The relative residual is the absolute value of the residual divided by the value of
magnitude of the left side of the equation. If the value of the left hand side of an equation is zero
(or close to zero), then the relative residual is assigned to be equal to the absolute residual. EES
monitors the value of the relative residuals during iterative calculations to determine when the
equations have been solved to the accuracy specified in the Stopping Crit tab of the Preferences
dialog or the $StopCriteria directive. Using the relative residuals instead of the absolute residuals
in the stopping criteria makes it possible to specify a tolerance that is independent of the scale of
each equation.
Units
The Units column in the Residuals Window indicates the status of the unit checking; OK appears
if EES did not find any unit checking problem. Figure 5-7 indicates that there are no unit
conversion problems since units were not entered for any of the variables. If, for example, we
set the units of variable x_7 to ft and resolve this problem then the Residuals Window would
appear as shown in Figure 5-8.
238 Chapter 5: Convergence and Debugging
In Figure 5-8, the equations that failed the unit checking process are indicated by a ? in the Units
column. Clicking the right mouse button on the ? will cause the pop-up menu shown in Figure
5-9 to appear.
Figure 5-9: Pop-up menu that appears after right-clicking in the Units column.
The pop-up menu in Figure 5-9 has provides several options for addressing the unit problem.
One option is to disable the unit checking for the selected equation. If unit checking for an
equation is disabled, then the Units column will show an X, as seen for the second equation in
Figure 5-9. The Check Units option will provide a more detailed description of the unit
inconsistency.
why 11 calls were required. A very large number of calls for an equation usually indicates that
the guess values for the variables involved in that equation could be improved.
Clicking on any row in the Residuals Window will display the variables that are in the equation
with their units in the status bar at the bottom of the window, as seen for the fifth equation in
Figure 5-8. The height of the status bar will automatically adjust so allow all of the variables in
the selected equation to be displayed. The Doubling-clicking the left mouse button (or clicking
the right mouse button) on a row in the Residuals Window will cause the Equations Window to
be brought to the front with the selected equation highlighted. The Find command from the
Search menu can be used to help locate the equations in large problems. The entire contents of
the Residuals window can be copied as tab-delimited text to the Clipboard. To do this, select the
Select All command from the Edit menu and then the Copy command from the Edit menu while
the Residuals window is foremost.
Internally, EES treats a call to a procedure as M separate function calls, where M is the number
of output parameters in the procedure. Therefore, the call to the procedure Test corresponds to
four function references. For example, the code:
Call Test(33,44: Product, Ratio, Sum, Difference) "Call to the Test Procedure"
will lead to the Residuals Window shown in Figure 5-10(a). Even though the Equations Window
contained only one call to the procedure Test, the Residuals Window shows four separate
functions corresponding to each of the outputs of this procedure. The first row is Product =
Test(33,44,1) which should be read as an equation setting the value of the variable Product by
calling the procedure Test with inputs X = 33 and Y = 44. The 1 indicates that Product occupies
the first output argument position. The remaining three rows correspond to the other outputs.
Because the inputs are specified, the four equations are blocked sequentially.
Procedures can also be called with one or more of the outputs set in order to determine one or
more of the inputs. For example, the procedure Test could be called according to:
Call Test(X, Y: Product, Ratio, 88, 32) "Alternative call to the Test Procedure"
which would lead to the Residuals Window shown in Figure 5-10(b). The Residuals Window
shows that EES used the equations corresponding to the known third and fourth outputs in order
240 Chapter 5: Convergence and Debugging
to determine variables X and Y simultaneously. Thus these two equations were placed in Block
1. Then, the variables Product and Ratio were determined. EES saves the input and output values
for each procedure call and reuses this information, if possible, in order to reduce unnecessary
computation.
(a)
(b)
Figure 5-10: Residuals Window for the call to the procedure Test with (a) inputs set and outputs calculated
and (b) two outputs set and the inputs calculated.
Figure 5-11 shows the Computational Flow Window (select Computational Flow from the
Windows menu) for the equation set shown in Figure 5-5.
Chapter 5: Convergence and Debugging 241
Figure 5-11: Computational Flow window for Eqs. (5-25) through (5-32).
The Computational Flow window is divided into three panes. The pane on the left shows a tree
view of all information flow. A separate tree structure is provided for the Main program and for
every Subprogram in the Equations window. Right-click the Main tree node and select Show All
Equations from the popup menu in order to obtain Figure 5-12.
EES reorders and blocks the equations to allow an efficient solution, as described in Section 5.1.
First, it looks through the equations and executes those that assign variables to constants. These
equations are shown in the first tree node labeled Constants, which in this case includes only the
equation that assigns variable x_7 to a constant value of 7. Next, EES will attempt to solve
equations that include a single unknown variable (note that variables assigned to constants are
not unknown at this point). These equations are placed in the Single Unknown Equations tree
node in the order that they are solved. In this case, the variable x_4 can be found by solving Eq.
(5-26) since the value of x_7 is known. Next, EES will next look for groups of equations that can
be solved simultaneously (i.e., blocks). In this case, EES finds Eqs. (5-28) and (5-32), which are
solved simultaneously in order to determine the values of variables x_1 and x_6. These equations
are placed in Block 1. This process is repeated in each successive block until all of the equations
are included.
The equations included in each block can be shown or hidden. In large problems, it may be best
to only shown the equations in the blocks that are of interest. Clicking the left mouse button on a
block shown with a + box at its left will display the equations in that block. The + sign will then
become a - sign. Clicking again will hide the equations.
242 Chapter 5: Convergence and Debugging
The parenthesized number that follows the block name is the number of times that the block was
called during the calculation procedure. For example, the equations in Block 1 were evaluated
11 times in order to obtain the solution.
Clicking the left mouse button on a block name selects that block. All of the variables that are
involved in the equations for the selected block will then be displayed in the top right panel.
This panel shows the variable name, the block that its value was determined in, the value of the
variable and its units, as shown in Figure 5-13 for Block 1
Variables for which the block number is shown in red have values that are determined in the
selected block. For example, Figure 5-13 shows that variables x_1 and x_6 were determined in
this block, using variable x_7, which is a constant and variable x_4 which was determined by
solving a single equation, possibly involving other known variables. The variables are initially
shown in the order that they appear in the equations for the selected block. Clicking the left
mouse button in the Variable cell will reorder the variables so that they are displayed in
alphabetical order. Click again to show the variables in reverse alphabetical order. Clicking a
third time restores the original order. Similar behavior occurs by clicking in the Block cell,
which will reorder the list in terms of the block number.
Note that the information in the Block column identifies where in the program the variable is
defined. If a number is shown, the variable is determined by the equation(s) in the block having
this number. However, the block column may display any of the keywords that are identified in
Table 5-1.
Chapter 5: Convergence and Debugging 243
Table 5-1: Keywords that can appear in the Block column and their meaning.
Clicking on an equation in the tree view pane will display the variable information for the
selected equation, rather than for the entire block. In addition, a third pane will appear at the
bottom right of the window showing the absolute and relative residuals for the selected equation.
Figure 5-14: Computational Flow window showing variables and residuals for a selected equation.
The absolute residual (Abs. Resid) is the difference between the left and right hand sides of the
equation that results when the calculated values for the variables are substituted into the
equation. The relative residual (Rel. Resid) is the absolute value of absolute residual divided by
the value of the left-hand side of the equation, assuming that it is not equal to zero; if the left-
hand side of the equation is identically zero, then the relative residual is reported to be the same
as the absolute residual. During the calculations, the solution process has converged when the
maximum relative residual value for all equations is less than the residual tolerance that is
specified in the Stop Crit tab of the Preferences dialog (which can be accessed by selecting
Preferences from the Options menu). Alternatively, the residuals tolerance can be specified
using the $StopCriteria directive. Also shown is the number of evaluations (including those
required to calculate numerical derivatives) that were required to solve the equation, the time (in
milliseconds) required to solve the equation and the status of the unit checking for the selected
244 Chapter 5: Convergence and Debugging
equation (OK indicates that the unit check is successful, ? indicates that the unit check has failed,
and an X indicates that unit checking has been disabled for this equation).
Clicking the right mouse button on an equation in the tree view pane will bring up a pop-up
menu, as shown in Figure 5-15.
Figure 5-15: Computational Flow window showing pop-up menu for equations.
The Locate in Equations Window menu item will open the Equations window and bring it to the
front of all other windows with the selected equation highlighted. The Variable Information
menu item will bring up an abbreviated version of the Variable Information dialog that shows
only those variables that are in the selected equation; the guess values, limits, and units of these
variables can be changed within this dialog. The Disable/Enable Unit Checking menu item will
either disable or enable the unit checking for the selected equation. (It is sometimes convenient
to disable unit checking for empirical equations that involve constants with units.)
Clicking the right-mouse button on a variable name or block number in the upper right panel will
bring up a pop-up menu for the selected variable, as shown in Figure 5-16.
Figure 5-16: Computational Flow window showing popup menu for variable.
Chapter 5: Convergence and Debugging 245
The Variable Information item in the popup menu displays an abbreviated version of the
Variable Information dialog showing just the variables for the selected block or equation. The
second line of the popup menu will move the focus of the tree view to the tree node in which the
selected variable was defined (in Figure 5-16 the second line will move to the Single Unknown
Equations node). The last two menu items are only enabled if the selected variable was defined
in a Parametric Table or in the Diagram window, respectively. In this case, selecting the menu
item opens the Parametric Table or Diagram window and highlights the column or location
where the variable is defined.
Figure 5-17: Find command (Search menu) in the Information Flow window
The Find command can be used to show which blocks a variable is defined in. Select Find from
the Search menu and enter the name of the variable (Figure 5-17). Click the Find Next button
and the next block that contains this variable will be selected showing the equations and
variables that use the variable. Click the Find Next button again to move to the next occurrence
of the variable. This process can be continued until all occurrences of the variable are located.
If EES is configured to manipulate complex numbers, two equations, one each for the real and
imaginary parts, will be generated for each equation entered in the Equations window. The real
and imaginary equations are identified by a r and i located just to the left of the equation.
The Computational Flow window can be very helpful for identifying the source of convergence
problems. As an example, modify the equation set shown in Figure 5-5 by adding an equation
for variable ss and change the constant -1 on the right side of the fourth equation to ss. The
modified equations are shown in Figure 5-18.
Select Solve from the Calculate menu (or press F2) to solve this equation set. The problem will
not converge with the default stop criteria, leading to the error message shown in Figure 5-19.
246 Chapter 5: Convergence and Debugging
Figure 5-19: Error message resulting from the attempt to solve the modified equation set.
Select Yes to show the Computational Flow window (the Computational Flow Window can also
be accessed from the Windows menu), shown in Figure 5-20.
Figure 5-20: Computational Flow window showing the block in which a solution was not obtained.
Note the small icons to the left of each branch of the tree information. The possible icons and
their meanings are provided in Table 5-2.
Table 5-2: Tree node icons and their interpretations in the Computation Flow window.
In Figure 5-20 EES was able identify that the problem with the equation set occurred in Block 1.
In much larger problems, this information would be of significant value. Click on the Block 1 to
show the equations. In this case, EES also correctly identified the equation in the block that
caused the problem. EES did not attempt to solve the equations in Blocks 2, 3 or 4, as indicated
by the red icon.
It is possible to display the Computation Flow Window in a debugging situation. If the number
of equations is less than the number of unknowns then EES will not be able to solve the equation
set, but the Computation Flow window can be made visible by selecting it from the Windows
menu. Look for a block preceded by the yellow question mark icon as this likely identifies the
location of the missing equation.
Chapter 5: Convergence and Debugging 247
By default, the guess values of all variables in EES are 1.0 and the lower and upper bounds are
negative and positive infinity, respectively. The guess value, limits, display format, units and
other information for each variable in an EES program can be specified using the Variable
Information command in the Options menu, as noted in Section 1.2. The Variable Information
command provides some additional capabilities that are discussed here.
Z=37
X[1]^2+X[2]^2=Z
X[1]/X[2]=1.2345
Entering the Solve command (or pressing F2) will provide a solution for these equations: X[1] =
4.727 and X[2] = 3.829. However, this is not the only possible solution. Another solution to
these equations is: X[1] = -4.727 and X[2] = -3.829. EES only converges to and displays one
solution, even when multiple solutions exist. The solution it displays depends on the guess
values and possibly on the variable bounds. To demonstrate this dependence, select the Variable
Information command from the Options menu in order to display the Variable Information
Window, shown in Figure 5-21.
The Variable Information Window shows that the guess values for X[1] and X[2] are both 1; this is
the default value for all variables. EES shows the guess value for Z to be 37 and displays this
value in bold font. However, the guess value for Z is not 37. EES is displaying this value
because it thinks that this is the value of variable (and it is correct in this case). Even though a
value is provided, you can edit it if you wish. If you click in the edit box containing the 37, it
will change to 1 (the real guess value) and remove the bold font. Change the guess values of X[1]
248 Chapter 5: Convergence and Debugging
and X[2] to be -1. Also set the upper bounds for these variables to be 0, as shown in Figure 5-22.
Then click the OK button to dismiss the dialog.
Figure 5-22: Variable Information dialog window with altered guess values and bounds.
Solve the equations (press F2) and you will see that EES has converged to the alternate solution:
X[1] = -4.727 and X[2] = -3.829. The solution that EES converges to is primarily controlled by the
guess values and, to a lesser extent, the bounds specified for each variable. Some equations sets
cannot be solved at all unless good guess values are provided.
Z=37
X[1]^2+X[2]^2=Z
X[1]/X[2]=1.2345
X_g=-1
Bring up the Variable Information dialog and set the guess value for X[1] and X[2] to be X_g, as
shown in Figure 5-23. Click the OK button.
Figure 5-23: Variable Information dialog showing guess values entered with a variable.
Solve the equations and you should find that EES has converged to a solution in which both X[1]
and X[2] are negative. Change X_g to 1 in the Equations Window and solve again. EES will
converge to values of X[1] and X[2] that are both positive. The guess values and lower and upper
limits can also be entered using variables that are specified in the Diagram Window (discussed in
Chapter 5: Convergence and Debugging 249
Chapter 15) or in a Parametric Table. This capability is very useful in some problems where the
guess values that you need to obtain the desired solution change depending on other information
in the problem. For example, the equation that provides the Mach number in a converging-
diverging nozzle given its cross-sectional area has two roots. In the converging section, the
correct root leads to a Mach number that is less than one. In the diverging section, the other root
should be selected, which leads to a Mach number that is greater than one. In order to control
the solution process, a guess for Mach number that is less than one in the converging section and
greater than one in the diverging section could be entered in a column of a Parametric Table and
then used to control which root is calculated by EES.
The Professional version of EES extends this capability by allowing guess values and limits to be
specified with equations that involve variables defined in the Equations Window and numerical
constants. As a trivial example, the guess values for X[1] and X[2] could have been entered as
X_g/2+0.01.
Figure 5-24: Variable Information Window showing collapsed view for array variables.
One advantage of the collapsed array display option is that it reduces the number of rows in the
table so that other, non-array variables can be more easily located. However, another advantage
is that it facilitates changing all of the guess values or limits in the array to have the same value.
For example, if the guess value for X[] is changed from 1 to -1 then the guess values of all
variables in the X array (X[1] and X[2], in this case) will be set to -1. You can confirm this change
by selecting the Show array variable control so that all of the variables in the X[] array are again
visible. Note that the change only occurs if the displayed value is changed while in the collapsed
view. If the displayed value already shows the desired value, but not all of the array elements are
set to this value, then it is necessary to change the displayed value to some other value and then
change it back to its original value. This action will ensure that all of the array variables are
250 Chapter 5: Convergence and Debugging
changed to have the same guess value. The lower and upper bounds, display format, and units
can all be changed for array variables in the same manner.
If you click the Yes button, EES will make the indicated change in the variable name and
proceed to display the next requested variable name change. If you click the All button, EES
will make all of the changes that you requested with no further confirmations. All variable
information, including the guess value, lower and upper bounds, and units, is assigned to the new
variable name. Also, if the variable appeared in a Parametric Table then its name will be
changed there as well. You could of course use the Find/Replace commands in the Search menu
to change variable names. For example, you could change every occurrence of X[ to Y[.
However, EES would then assume then that Y[i] array elements are new variables. The guess
values, limits, units and other information that were assigned to the X[i] array elements would not
be assigned the Y[i] variables. Also, no changes will be made to any Parametric Table (i.e., if X[1]
was a variable in a Parametric Table then it would still appear in the Parametric Table after the
Find/Replace process is completed).
Figure 5-26: Variable Information Window showing the buttons to read and save .VAR files.
Clicking the Save button will bring up the Save Variable Information dialog window where you
can specify a file name having a .var file name extension. After confirmation, EES will write all
of the information for each variable that is shown in the Variable Information dialog window to
the specified file. The .var file is a text file that can be opened, viewed and edited in any editor,
such as Notepad. For example, the .var file created from the Variables Information Window in
Figure 5-26 is shown in Figure 5-27. Units were not assigned to any of the variables in Figure 5-
26, but if they were, the units would also appear in the .var file. The same is true for the
comments.
Figure 5-27: Listing of the .var file created after clicking the Save Variable Info button.
Selecting the Read button will bring up a standard file open dialog that allows navigation to a
.vr file that has been previously saved. Reading a .var file will assign all of the attributes (i.e.,
guess value, bounds, units, etc.) to every variable that has a name that exists in the .var file,
including variables that are in functions, procedures subprograms and modules as well as in the
main program. Variable Information (.var) files provide a more general and more powerful way
of saving default information for variables than is possible with the Default Variable dialog.
Bi
tan ( i ) = (5-38)
i
Equation (5-38) is the eigencondition for the separation of variables problem related to transient
conduction in a plane wall, as discussed in Nellis and Klein (2009). The symbol Bi indicates the
252 Chapter 5: Convergence and Debugging
Biot number and i indicates the ith eigenvalue. Equation (5-38) has multiple roots and each
successive root is referred to as an eigenvalue; in order to solve the problem, it is necessary to
identify an arbitrary number of sequential roots.
The EES code below evaluates both the left (LHS) and right (RHS) sides of Eq. (5-38):
Create a Parametric Table in which the variable zeta is varied from just above 0 (to avoid a
division by zero error when calculating the value of RHS) to 14.137 (approximately
9/2). Generate the plot shown in Figure 5-28. Notice that the left and right sides of the
eigencondition are equal (i.e., the equation is satisfied) at multiple values of . Further
examination of Figure 5- 28 shows that these intersections occur in well-defined intervals. The
first root of Eq. (5-38) lies in the range 0 < 1 < /2, the second root lies in the range < 2 <
3/2, and so on. In general, the ith eigenvalue must lie in the range:
( i 1) i ( i 1) + (5-39)
2
Figure 5-28: Right and left hand sides of the eigencondition, Eq. (5-38).
EES can be used to generate an array of eigenvalues by controlling the guess values and limits of
each of the elements using arrays that are defined just for this purpose. Use a Duplicate statement
to generate an array of lower and upper bounds appropriate for each eigenvalue.
Generate an array that contains reasonable guess values for each eigenvalue; here, the guess is
taken to be the average of the upper and lower bounds.
duplicate i=1,N
guess[i]=pi*(i-1)+pi/4 "guess"
end
duplicate i=1,N
tan(zeta[i])=Bi/zeta[i] "eigencondition"
end
Solving the EES code leads to the Arrays Table shown in Figure 5-29(a); note that only the first
eigenvalue was identified for every value of the array zeta[]. In order to control the solution
process, open the Variable Information dialog and de-select the Show array variables option.
Enter the arrays guess[], lowerbound[], and upperbound[] in the appropriate columns for the array
zeta[] as shown in Figure 5-30. Select OK and solve the EES code again in order to obtain the
Arrays Table shown in Figure 5-29(b). Notice that each value of the array zeta[] now
corresponds to each successive eigenvalue.
(a) (b)
Figure 5-29: Arrays Table (a) without controlling the guess values and limits of the array zeta[] and (b) after
using the arrays guess[], lowerbound[], and upperbound[] to control the solutions to the array zeta[].
254 Chapter 5: Convergence and Debugging
Figure 5-30: Variable Information Window showing the use of arrays to control the solution process.
The Default Variable Information dialog allows you to set a common guess value, limits, and
units for all variables that begin with the same letter. For example, if all variables that begin
with the letter T represent temperatures then you may want to set the units of these variables
automatically to K and provide more reasonable guess values (e.g., 300 K) and limits (e.g., 10 K
to 1000 K), as shown in Figure 5-31. Date and Time formats can be specified in the Default
Variable Information dialog. These settings can be stored in the preferences file by selecting
Store so that they remain in effect for future EES sessions.
Figure 5-32: Error message indicating that equation set cannot be solved
Clicking the Yes button will bring up the Debug window, which will appear as seen in Figure
5-33.
This window provides two lists of variables. Clicking the left mouse button on a variable
name in either list will highlight the variable in the Equations Window. The first list shows
the variables that are most likely to be involved in any missing or extra equations. (The
256 Chapter 5: Convergence and Debugging
information used to construct this list is determined by examination of the blocking order of
the equations in the Residuals window. You may also find the information in the Residuals
or Computational Flow windows helpful in identifying the problem with your equation set.)
The second list shows all variables which are referenced only once in the Equations Window.
These variables are possibly spelled wrong or otherwise not being directly used in the
problem, except for informational purposes. Clicking the Solve button will result in EES
solving the equation set as far as it can with the current equations. The partial solution will
appear in the Solutions window. Variables that could not be determined with this partial set
of equations are shown in gray font.
Constrained Solution
In some cases, a problem cannot be solved to within the specified tolerances because the
lower and/or upper bounds one or more variables have restricted the solution. If this
happens, EES will present a dialog box warning of this problem and offer more information.
If the user wishes to see the additional information, the Debug window will appear similar to
Figure 5-34 showing the variables that are constrained and the affected equations. Clicking
the left mouse button on a variable name will open the Variable Info dialog window in which
the lower or upper bound can be changed. Clicking on an equation will move the cursor to
that equation in the Equations window.
5.6Debugging Techniques
The numerical methods built into EES are robust and powerful. Nevertheless, you will likely
encounter situations where your set of equations does not solve. The most common reason for
the equations not solving is that there is some error in the equations that you have entered. It
could be that there is a unit conversion problem or a sign error. Even one small problem may be
sufficient to prevent EES from being able to solve the equations that have been entered. On the
other hand, sometimes even a properly formulated set of equations may not solve if one or more
of the equations are non-linear so that they depend on the guess values that you supply
EES is not a programming language. It is an equation-solving application. It does not solve the
equations in the order in which they are entered into the Equations Window, but rather reorders
them as it sees fit in an attempt to solve the equations in an optimal manner, as explained in
Section 5.1. When EES is able to solve a set of equations, it does so efficiently. However, it is
relatively difficult to identify the cause of a problem when EES does not solve your equation set
because you do not directly control the solution process. This section provides a number of
techniques that should help you coax a stubborn set of equations to a solution in EES.
There are several reasons for entering equations in a sequential order. First, it allows your
program to be debugged as it is being written. It is a frustrating to enter a large set of equations
and then finally hit Solve only to see EES fail to converge. It will be difficult to debug such a
large EES program. It is much easier to enter equations one at a time and verify that EES can
solve the set of equations that results after each equation is entered. When problems are
encountered, they can immediately be isolated to the last equation that was entered. This method
is good engineering practice. When something goes wrong with an experiment or device, an
experienced engineer will immediately try to isolate the problem by testing each sub-system of
the device alone.
There is another advantage to using the sequential approach discussed in the previous paragraph.
EES solves a set of non-linear equations using an iterative approach; the approach starts from an
initial point that is characterized by a set of “guess” values for each variable and iteratively
improves the solution. The solution process is easier if the guess values for each variable are
close to the final solution. Obtaining a series of intermediate solutions usually allows the user to
easily obtain a very good set of guess values.
258 Chapter 5: Convergence and Debugging
Selecting the Update Guesses command will cause the guess values of all variables to be set to
their most recently calculated values. Updating the guess values can also be accomplished by
pressing the Update button in the Variable Information Window or by placing the directive
$UpdateGuesses in the Equations Window. The $UpdateGuesses directive differs slightly from
the Update Guesses menu command. The Update Guesses menu command updates the guess
values throughout the entire EES program (i.e., in the main body and all subprograms) whereas
the $UpdateGuesses directive only operates within the scope (i.e., the main program or
subprogram) in which it is located. Subprograms are discussed in Chapter 10. In any case, the
guess values can only be updated if the current set of equations was successfully solved. If the
equation set has not been successfully solved then the Update Guesses command and speed
button will be disabled.
The following example illustrates the sequential solution technique and the use of the Update
Guesses command. The problem is to determine the temperature, T, of a surface that is
experiencing radiation heat transfer with two surfaces, one at temperature TH = 1000 K and the
other at TL = 300 K. The areas exposed to the high and low temperature surfaces are AH = 1 m2
and AL = 0.5 m2, respectively. The rate of radiation heat transfer to the surface from TH is given
by:
Q H = A (TH4 T 4 (5-40)
H
)
where is the Stefan-Boltzmann constant (5.67x10-8 W/m2-K4); note that this is a built-
in constant in EES (sigma#), as discussed in Section 1.9. The rate of radiation heat transfer
from the surface to TL is given by:
QL = A L (T 4 T 4 (5-41)
) L
Q
L = Q (5-42)
H
$UnitSystem SI K Pa J
"known information"
sigma=sigma# "Stefan-Boltzmann constant"
A_L=0.5 [m^2] "area of low temperature surface"
Chapter 5: Convergence and Debugging 259
It would be good practice to solve the equations entered up to this point in order to ensure that
there are no typographical errors. We could next try to directly enter and solve the set of
equations in Eqs. (5-40) through (5-42).
EES will not converge when you try to solve these and instead it will display the error message
shown in Figure 5-35. (Residuals window will be replaced by Computational Flow window in
the Professional version.)
Figure 5-35: Error message displayed by EES when you try to solve Eqs. (5-40) through (5-42).
The error message directs us to view the Residuals Window. Clicking the Yes button will cause
the Residuals or Computational Flow Window to display as shown in Figure 5-36. The
Computational Flow window (Figure 5-37) provides similar information.
Figure 5-37: Computational Flow Window showing Block 1 did not converge.
Figure 5-37 show that the convergence problem occurs in the three equations that together form
Block 1. In a larger problem, this information may be useful as it isolates the location of the
problem. However, in this case, we already knew that the last three equations we entered were
the source of the convergence problem.
Entering Eqs. (5-40) through (5-42) simultaneously caused this convergence problem. Let's take
an alternative approach where the equations are entered one at a time. Delete the last three
equations in the Equations Window. In order to take a sequential (rather than simultaneous)
approach, we enter Eq. (5-40) and then solve it. Next, enter Eq. (5-41) and solve. Finally, enter
Eq. (5-42) and solve. However, this approach appears to fail for this example because Eq. (5-40)
involves two unknowns, QH and T. In order to carry on, it is best to enter a temporary equation
that provides a guess for the unknown T. We know that the temperature of the surface must lie
between TL and TH; a reasonable guess is therefore the average.
This equation is clearly temporary and it must be removed eventually in order to obtain the
correct solution; this can be emphasized by highlighting the equation, as shown above. (To
highlight the equation, select it and then click the right mouse button.) With a temporary value
of T specified, it becomes possible to enter Eq. (5-40) and solve the resulting set of equations:
The units for the variables can be entered and checked and the solution debugged if necessary.
Equation (5-41) can be entered next and the new equation set solved.
Although the equations solved, the solution is not correct because we entered an arbitrary value
for T. However, the solution does serve a purpose. The current values for the variables Q_dot_L,
Chapter 5: Convergence and Debugging 261
Q_dot_H, and T are very good guess values; much better than the default guess values that would
otherwise be used. Select the Update Guesses command from the Options menu or the speed
button tool bar. After the confirmation, EES will assign the current values of all variables to be
the guess values for those values. For example, the variable T initially had a guess value of 1 K.
Now its guess value will be 650 K. Next, delete (or comment out) the temporary equation that
specified T and enter the steady-state requirement given by Eq. (5-42).
Now, when you try to solve the equation set there will be no convergence problems. The correct
value of T is 904.5 K, which is still pretty far from the guess value but close enough to allow the
equations to converge.
This example illustrates the basic method of entering equations sequentially, using temporary
equations as needed to supply guesses, and applying the Update Guesses command. There are
other ways to make EES solve these equations, such as by adjusting guess values at the start of
the solution process. However, the sequential method is, in the opinion of the authors, the best
way to ensure that you are in control of the solving process with EES.
Edit the Equations Window so the following equations appear. Select the Reset Guesses
command in the Options menu to set the guess values of all variables back to their default values.
$UnitSystem SI K Pa J
"known information"
sigma=sigma# "Stefan-Boltzmann constant"
A_L=0.5 [m^2] "area of low temperature surface"
T_L=300 [K] "temperature of low temperature surface"
A_H=1.0 [m^2] "area of high temperature surface"
T_H=1000 [K] "temperature of high temperature surface"
These equations will not solve with the default guess values. The Residuals (Commercial
version) or the Computational Flow (Professional version) Window will appear as shown in
Figure 5-38 or Figure 5-39.
Figure 5-38: Residuals window showing ****** for blocks in which calculations were not attempted.
Figure 5-39: Computational Flow window showing red icons where calculations were not attempted.
Note the ****** in the Residuals Window for Block 2; these stars indicate that calculations for
this block (and any following blocks) were not attempted. The red icons in the Computational
Flow window have the same interpretation. The reason that the calculations were not attempted
is that calculations failed in the preceding block, Block 1, for the reasons explained in the
previous section. The variables that EES was trying to solve for in Block 1 are shown in bold
font in the equations for this block. This information quickly indicates the source of the problem
within what might be a large set of equations. Debugging efforts can be directed to the equations
in Block 1. For example, the equations in the block that did not solve should be checked to
ensure that they are properly entered. It may be necessary to adjust the guess values for the
variables appearing in bold font. Note that Figure 5-38 also shows that there are unit conversion
problems with some of the equations in block 1. These unit conversion problems should be
eliminated before further attempts are made to solve the equation set, as they could result from
Chapter 5: Convergence and Debugging 263
errors in the equations that may be the source of the problem. In this example, the unit
conversion errors occurred because the units for the variables Q_dot_H and Q_dot_H were not
specified.
Normally, the block numbers appear in sequential order. When one or more equations are
missing, EES will skip a block number at the point in which it encounters this problem. The
equations in the following blocks should be carefully reviewed to determine whether they are
correctly and completely entered. There is clearly a problem somewhere in the equation set if
EES skips a block number.
Common Problems
The most common reason that a set of equations will not solve is that there is an incorrect
equation (which can often be identified by inconsistent units) or inappropriate guess values.
These problems are usually detected early in the process of entering the equation provided that
the sequential process recommended earlier is followed. However, there are some common
problems that do not show up in the Residuals Window and may not be easy to identify.
One common problem that prevents EES from converging to a solution is the presence of a
redundant equation. An example of a redundant equation is demonstrated in the following
simple example.
z=50
x+y=0.022
z*x+z*y=0.022*z
EES may or may not obtain a solution to this equation set, depending on stopping criteria.
However, even if a solution is obtained it will not be unique. The equation set consists of three
equations in three unknowns (x, y, and z) and therefore it would appear that the equations are
solvable. However, closer inspection shows that second and third equations are actually
identical; the third equation is equal to the second equation multiplied by the variable z. The
third equation provides no new information and is redundant. When this equation is removed,
another relation between x and y must be provided if the equation set is to be solved.
A somewhat more subtle example of a redundant equation can occur when using the built-in
property functions, discussed in Chapter 4. This situation is demonstrated in the following
equations.
$UnitSystem Mass SI K Pa J
P=100000 [Pa]
h=Enthalpy(Steam,T=T, P=P)
T=Temperature(Steam, h=h, P=P)
EES will not solve this equation set, although it appears to be simple and complete; there are
three equations in the three unknown variables P, h, and T. However, note that the last two
equations both rely on fundamentally the same relationship between h, T, and P. The equations
in the Enthalpy function that return the specific enthalpy as a function of temperature and pressure
264 Chapter 5: Convergence and Debugging
are the same as the equations in the Temperature function that return temperature given specific
enthalpy and pressure. Therefore, one of the last two equations is redundant. EES may return a
solution, depending on the unit system and stopping criteria, but the result will not be correct.
Some other equation relating specific enthalpy and temperature must be entered in place of one
of the last two equations.
Another common problem is related to the fact that the properties of pure fluids can not be
obtained from temperature and pressure in the two-phase regime. Consider the following
example:
$UnitSystem SI K Pa J mass
h=1000000 [J/kg]
P=100000 [Pa]
h=Enthalpy(Steam,T=T,P=P)
EES will not be able to solve these equations, although they seem simple enough. The error
message shown in Figure 5-40 results when you try to solve these equations.
Figure 5-40: Error message that results when trying to determine properties of two-phase state using
temperature and pressure.
The problem in this case is that the state defined by the specific enthalpy and pressure is in the
two-phase liquid-vapor regime. In this regime, temperature and pressure are not independent.
Consequently, it is not possible to determine the temperature with the equation that uses the
Enthalpy function called with pressure and temperature used as inputs. The problem would solve
if the last equation were replaced with one that uses the Temperature function, as shown below.
{h=Enthalpy(Steam,T=T,P=P)}
T=Temperature(Steam, h=h, P=P)
$Trace /# X, Y, Z
The /# parameter in the $Trace directive is optional. The number following the / character (#)
indicates the maximum number of iterations that will be recorded in the Trace Table. By default,
this number is 1000. The variables X, Y, and Z are the variables in the main section of the EES
program that will appear in the Trace Table. There is no specific limit on the number of
variables that can be traced; however, it is best to confine the list to those variables that are
suspected of causing a convergence problem. Variables that are involved in functions,
procedures, modules, or subprograms can not be traced.
The $Trace directive will place the intermediate values of the specified variables in a Lookup
Table having the name TRACE. If a Lookup Table having the name TRACE already exists, then
it will be deleted at the start of the calculations. If you wish to keep the previous results of a
Lookup Table named TRACE then the table must be renamed before running the program.
The $Trace directive will be created when the Solve command is issued. It will have no effect
when used with Solve Table or other commands in the Calculate menu. It is best to place the
$Trace directive at the top of the program so that it is processed before any of the specified
variables appear in equations.
As an example, the $Trace directive is used to debug the radiation problem that did not converge
with the default guess values.
Select Solve and you will again find that the program does not converge. However, the $Trace
directive has resulted in the generation of a Lookup Table called TRACE. The first 10 rows of
the Lookup Table are shown in Figure 5-41. The trace process clearly shows the wild variations
in the temperature that occur with each iteration.
266 Chapter 5: Convergence and Debugging
Figure 5-41: Excerpt of the Lookup Table produced by the $Trace directive.
Equations are solved in blocks and the block structure can be examined in the Residuals
Window. The block for each variable in the Trace Table is shown below the variable name (see
Figure 5-41). Note that iterations for variables that are in different blocks cannot be directly
compared as they are not occurring at the same time.
References
Tarjan, R. “Depth-First Search and Linear Graph Algorithms,” SIAM J. Comput., 1, 146-160,
(1972)
6 OPTIMIZATION
To this point we have talked about using EES to solve problems that involve fixed inputs and
result in a single solution. In Section 1.3, the use of Parametric Tables was presented as a
method for carrying out a parametric study or one or more variables. Optimization is a process
in which one or more variables are varied in order to minimize or maximize an objective
function. The objective function can be the cost, weight, efficiency, or any physical
characteristic that is determined through the equations in the EES program. In some cases, there
may be more than one characteristic that must be optimized. In this case, it is necessary to create
a single objective function as a weighted sum of these characteristics.
hot air
Th,in = 25C
furnace
C= 10 kW/K
energy recovery
heat exchanger
cold air
Tc ,in = 15C
C= 10 kW/K
Figure 6-1: Energy recovery heat exchanger.
268 Chapter 6: Optimization
The capacitance rate (i.e., the product of mass flow rate and specific heat capacity) of the cold
and hot air streams are the same, C= 10 kW/K. The cold air enters at Tc,in = -15ºC and the hot
air enters at Th,in = 25ºC. We would like to determine the conductance (UA) of the heat
exchanger that is most economical, assuming that the system operates for 100 days/year for 5
years. The value of the energy saved is 0.73$/therm (a therm is an energy unit commonly used
for natural gas that is equivalent to 105.5 MJ). The cost of the heat exchanger is given by:
$-K
HX = 2.5 (6-1)
UA
W
Cost
UA
NTU = (6-2)
C
NTU
=1+ NTU (6-3)
(Note that this effectiveness relation in Eq. (6-3) could have been accessed using the Heat
Transfer application library in EES, as discussed in Chapter 12.) The effectiveness is the ratio of
the actual rate of heat transfer to the maximum possible rate of heat transfer:
Q
= Q (6-4)
max
Chapter 6: Optimization 269
where
The heat exchanger cost is calculated according to Eq. (6-1). The total amount of energy saved
is the product of the rate of heat transfer and the operating time. The value of this energy
(neglecting the time value of money) is the product of the energy and the cost of the natural gas.
The net savings (NetSavings) is the fuel cost savings less the heat exchanger cost.
Solving provides a net savings of $34,240 for the value of UA that was selected to develop the
model. A Parametric Table is created that includes the variables UA_kWpK, HX_cost, Savings,
and Net_savings. Figure 6-2 illustrates the results of the parametric study and shows that there is
an optimal value of UA that maximizes net savings.
Figure 6-2: Savings, heat exchanger cost, and net savings as a function of the heat exchanger conductance.
270 Chapter 6: Optimization
Objective Function
The first step in an optimization problem is to identify the objective function. The objective
function is the variable that is to be minimized or maximized. In the above example, the
objective function is the net savings. An optimization problem can only have one objective
function. However, it is possible to define an objective function that is provides a weighted sum
of several quantities that you wish to optimized. For example, an engineering problem may need
to minimize the mass (m) of a device while maximizing its power output (P). In this case, an
objective function could be defines as
Obj = w1 (1/ m ) + w2 ( P )
where w1 and w2 are weights that you assign the indicate the relative importance of minimizing
the mass (i.e., maximizing inverse mass) and maximizing power. Setting w1 to a much larger
value than w2 will cause the optimization to put more importance on minimizing mass than on
maximizing power.
Degrees of Freedom
The optimal value of UA can be determined using the built-in optimization algorithms in EES.
In order to carry out optimization, EES requires at least one free parameter that can be varied.
With UA set, the problem is completely specified. Therefore, if you select Min/Max from the
Calculate menu in order to initiate the optimization, then the error message shown in Figure 6-3
will be displayed.
It is necessary to comment out the equations that specify values of the optimization variables to
proceed with the optimization. In this case, the equation that specifies UA is commented out.
Figure 6-4: Find Minimum or Maximum dialog for one-dimensional optimization (Professional version).
The top left portion of the window requires that you select the optimization target (i.e., the
objective function) from the list of variables and specify whether the optimization target is to be
minimized or maximized. In this case we wish to maximize the value of the variable
Net_savings, as shown. The top right window allows you to select the independent (i.e., the
optimization) variable(s). EES determines the number of free parameters associated with the
equations and requires that this number of independent parameters be selected. For this problem
(with UA commented out) there is only one free parameter, which we have chosen to be variable
UA_kWpK.
Stopping Criteria
The Controls box in the Find Minimum or Maximum dialog shown in Figure 6-4 allows the
termination criteria for the optimization process to be specified. The process will terminate
when either the maximum number of calculations are reached or the relative convergence
tolerance is achieved. The relative convergence tolerance refers to the change in the
optimization target normalized by its value between successive iterations. If the Stop if error
occurs box is unchecked then EES will not terminate the optimization process if it attempts to
solve the equations for a value of the optimization variable that results in an error. Rather, it will
consider this value of the independent variable to be non-viable (and therefore not optimal) and
move on to other values.
272 Chapter 6: Optimization
Select OK in order to return to the Find Minimum or Maximum dialog. All that remains is to
select the optimization method. In this problem there is only one free parameter, therefore a one-
dimensional optimization will be accomplished using either of the two methods shown under the
heading Method: Golden Section search or Quadratic approximations. The methods required for
a multi-dimensional optimization are different and are discussed in Section 6.2.
Next, two test points are located within the range. The first test point, identified as point 3 in
Figure 6-6, is located a distance of g (UA2 - UA1) from the left edge, where g is the Golden Ratio
equal to 0.6182. The range of UA is initially 38 W/K so point 3 is located at UA = 23.5 W/K.
The second test point is located at a value of UA that is g (UA2 - UA1) from the right edge which
is UA = 14.5 W/K. The objective function (NetSavings) is evaluated at points 3 and 4. Point 4
exhibits a larger value of NetSavings. The result is that the range of UA containing the maximum
value of NetSavings can be narrowed by eliminating all points to the right of point 3. The
process is repeated by locating two points within the reduced range between point 1 and point 3.
However point 4 is already a located a distance of g (UA3 - UA1) from the left edge. This, in fact,
is how the value of g was determined. Therefore, it is not necessary to reevaluate NetSavings at
this point. Point 5 is located a distance of g (UA3 - UA1) from the right edge and NetSavings is
evaluated at this point. Since NetSavings is higher at point 4 then at point 5, all values to the left
of point 5 are eliminated and the reduced range is between points 3 and 5. This process
continues until the stopping criteria selected for the optimization are achieved.
Chapter 6: Optimization 273
Select the Golden Section search and then hit OK to initiate the optimization. The result is
shown in Figure 6-7. The optimal value of UA has been identified to be 11.87 W/K resulting in a
net savings of $35,217. The optimization required 30 iterations to find this result.
The solution at the optimal value of UA is contained in the Solution Window, Figure 6-8.
274 Chapter 6: Optimization
The objective function (NetSavings) is assumed to depend on the optimization variable (UA) in a
quadratic manner:
Chapter 6: Optimization 275
The coefficients a, b, and c in Eq. (6-6) are selected in order to fit the three points. The quadratic
function that passes through points 1, 2, and 3 is shown as quadratic 1 in Figure 6-9. The
optimal value of the optimization variable is predicted using the quadratic equation by setting the
derivative to zero. Taking the derivative of Eq. (6-6) provides:
2 aUAopt + b = 0 (6-7)
b
UAopt = (6-8)
2a
The value of the objective function at UAopt is computed, leading to point 4. The point with the
smallest value of the objective function (for maximization) is discarded and the process is carried
out again using the remaining three points (in this case points 1, 3, and 4). The new quadratic
equation is labeled quadratic 2 in Figure 6-9 and leads to the identification of point 5. This
process continues until the stopping criteria set for the optimization are achieved.
For most functions, the Quadratic Approximations method will converge to the optimal solution
more quickly than the Golden Section method. If Quadratic Approximations is selected from the
Find Minimum or Maximum dialog then the result is shown in Figure 6-10. Notice that the same
result as the Golden Section search (Figure 6-7) was achieved, but the process required only 18
iterations.
The Find Minimum or Maximum dialog shown in Figure 6-4 shows additional capabilities
provided in the Professional version. The Professional version of EES provides an option to log
results to a file. Clicking the Log results check box at the bottom of the dialog will provide the
option of either logging all points or logging the best points as they are identified to a file
276 Chapter 6: Optimization
selected by the user. The logged data can include selected variables as well as the independent
and dependent optimization variables.
The Professional version also provides the option to display the sensitivity of the optimum result
to variations in the independent variable(s) around the optimum. This capability is enabled by
clicking the Display Sensitivities in Solution check box at the center right of the dialog. If this
option is selected, EES will vary the value of each optimization variable from its optimum value
by the specified percentage and determine the objective function. The results are displayed in
the Solution window, as seen in Figure 6-11 for this problem. Note that the small table at the top
of the Solution window displays the optimum value of objective function and its values if the
optimization variable is reduced or increased by 10%.
Min/Max Table
It is sometimes useful to carry out optimizations within the context of a parametric study. For
example, in this example we might want to determine the optimal conductance as a function of
some other parameter (e.g., the cost of the heat exchanger or the capacitance rate of the fluids).
This type of study can be accomplished using the Min/Max Table command. In order to utilize
the Min/Max Table command it is necessary to create a Parametric Table that includes the
dependent parameter that is being optimized (NetSavings), the independent parameter that is
being adjusted (UA), and the parameter that is being parametrically varied, which in this case is
the capacitance rate ( C). Any other parameter of interest can also be included in the table.
Comment out the value of C that is specified in the Equations Window and vary the parameter
from 5,000 W/K to 50,000 kW/K in the table, as shown in Figure 6-12(a).
Chapter 6: Optimization 277
(a) (b)
Figure 6-12: Parametric Table (a) before and (b) after the Min/Max Table command is executed.
Select Min/Max Table from the Calculate menu in order to access the Minimize or Maximize
Table dialog. Set the dependent and independent variables in the usual way, as shown in Figure
6-13.
Select OK to initiate the calculations. Each row of the Parametric Table will be solved by
carrying out the specified optimization with a different value of the variable C. The result is
shown in Figure 6-12(b). The value of UA indicated in each row is the optimal value that results
in the maximum value for NetSavings, also listed in the row, for the value of C that is specified
in that row.
Figure 6-14: Optimal value of conductance and the associated net savings as a function of the capacitance
rate of the fluids.
6.2Multi-Dimensional Optimization
Typical design problems will involve multiple optimization variables and therefore require
multi-dimensional optimization. The Commercial version of EES will allow up to 20
independent variables and the Professional version (9.370 or newer) will allow up to 80
independent variables. In this section we will examine the multi-dimensional optimization
algorithms that are available in EES in the context of the two-dimensional surface defined by the
equation:
r12 r12 r2
f = 0.7 exp +
1 0.7 exp exp 2
(6-9)
2
2 2
0.2 0.2 0.05
where
r1 = (x 0.5) + ( y 0.5 )
2 2
(6-10)
Chapter 6: Optimization 279
(x 0.2 ) + ( y 0.2 )
2 2
r2 = (6-11)
r1=sqrt((x-0.5)^2+(y-0.5)^2)
r2=sqrt((x-0.2)^2+(y-0.2)^2)
f=0.7*exp(-r1^2/0.2^2)+(1-0.7*exp(-r1^2/0.2^2))*exp(-r2^2/0.05^2)
Note that these multi-dimensional optimization algorithms discussed in this section can be easily
extended to higher dimensions than two but are most easily visualized in two-dimensions.
Contours of constant f in the parameter space of x and y are shown in Figure 6-15.
Select Min/Max from the Calculate menu in order to access the Find Minimum or Maximum
dialog, shown in Figure 6-16.
280 Chapter 6: Optimization
The objective function f should be maximized by adjusting the two independent variables (x and
y). Set the bounds for both x and y to be from 0 to 1 and the guess values to be 0.7.
In the context of this two-dimensional problem, the initial one-dimensional optimization occurs
along the line x = 0.7 as shown by path 1 in Figure 6-18. The objective function is maximized
along this line at approximately y = 0.5. The second one-dimensional optimization occurs along
the line y = 0.5 as shown by path 2. The objective function is maximized along this line at
approximately x = 0.5. In this case, the optimum is located when these two one-dimensional
optimizations are completed because the axes of the contours align with the axes of the plot.
More commonly the axes of the contours and the plot are not aligned and many one-dimensional
searches are required to locate the optimum point. EES employs a method referred to as
conjugate directions in order to improve the efficiency of the optimization. The conjugate
directions method makes the one-dimensional searches along directions that are oriented more
favorably than those defined by the independent variable in the problem. More information
about this technique can be found in Press et al. (1989).
282 Chapter 6: Optimization
Select Conjugate Directions method and then OK in order to initiate this method of optimization.
The result is shown in Figure 6-19; it required 44 iterations (i.e., function evaluations) to arrive
at the optimal value x = 0.5 and y = 0.5 where the objective function is f = 0.7. Notice from
Figure 6-15 that this is not the global maximum but rather a local maximum; the true optimal
solution corresponds to the much smaller but taller peak at x = 0.2 and y = 0.2. The Conjugate
Directions method is sensitive to the guess values for the optimization variables (which
correspond to the starting point of the optimization process). If a guess value that is closer to the
peak is specified (e.g., x = 0.15 and y = 0.15) then the Conjugate Directions method may
converge to the global optimal value of x = 0.2 and y = 0.2 where the objective function is f = 1.
An advantage of the Nelder-Mead method is that derivatives of the objective function are not
required. However, Press et al. indicate the method is not as successful as either the Conjugate
Directions or Variable Metric techniques described earlier in this section. There is some
evidence that the Nelder-Mead optimization technique is more robust for constrained
optimization problems, described in Section 6.3.
The Professional version of EES provides a choice of 5 optimization method for problems
having two or more degrees of freedom. Of the algorithms, only this method and the Genetic
method (see below) are capable of to locating a global optimum when local optima exist in the
search region. Experience with the DIRECT algorithm shows that it is capable of finding a
global optimum with many fewer function evaluations than the Genetic method. However, it is
not as efficient as the Conjugate Directions, Variable Metric or Nelder-Mead Simplex methods
when local optima do not exist.
Max. function calls is the upper limit of the number of times EES will solve the equations while
searching for the optimum.
Rel. conv. tolerance is a stopping criterion. The smaller this number, the more accurate the
optimum will be and the more function evaluations it will require to locate the optimum. EES
284 Chapter 6: Optimization
will also terminate the search for the optimum if an improved estimate of the optimum is not
located in (Max. function calls / 5) function evaluations.
Stop if error occurs will cause the optimization to stop if an error is encountered during the
calculations. In most cases with a well-formulated problem, it is best to leave this option
unchecked so that EES can continue to look for an optimum solution.
The genetic method intends to mimic the processes occurring in biological evolution. A
population of individuals (i.e., sample points) is initially chosen at random from the range
specified by the bounds of the independent variables. The individuals in this population are
surveyed to determine their fitness (i.e., the values of the objective function). Then a new
generation of individuals is generated in a stochastic manner by 'breeding' selected members of
the current population according to their fitness. The characteristics of an individual that are
passed on to the next generation are represented by encoded values of its independent variables.
The probability that an individual in the current population will be selected for breeding the next
generation is an increasing function of its fitness. The 'breeding' combines the characteristics of
two parents in a stochastic manner. Additional random variations are introduced by the
possibility of 'mutations' that cause the offspring to have characteristics that differ markedly from
those of the parents. In the current implementation, the number of individuals in the population
remains constant for each generation. The number of individuals, number of generations, and
mutation rate can be adjusted once the Genetic method is selected, as shown in Figure 6-21.
Figure 6-23 illustrates the progression of the genetic optimization method; the populations for a
few selected generations are shown. In the first generation, Figure 6-23(a), the members are
uniformly distributed throughout the parameter space (although one member is located exactly at
the coordinates associated with the guess value, x = 0.7 and y = 0.7). The population slowly
converges towards the broad peak, as shown in Figure 6-23(b) for generation 5. Mutations cause
individual members in later generations to move away from this broad peak, as shown in Figure
6-23(c) for generation 23. If even one member happens to come near the second, smaller but
steeper peak then the entire population will eventually be attracted there. This is shown in
Figure 6-23(d) for generation 77.
Chapter 6: Optimization 285
Figure 6-21: Find Minimum or Maximum dialog with genetic method selected.
The primary advantage of genetic optimization is its ability to reliably find a global optimum
even if there are many local optimal values in the problem. The other techniques discussed in
the context of this example tended to locate the small broad peak and bypass the large sharp peak
unless the guess values happened to be set very near that location. Genetic optimization will
inevitably find the sharp peak given a sufficiently large population and number of generations.
The disadvantage of genetic optimization is that it takes a long time since many of the members
of each population are not useful. Figure 6-22 shows the dialog that results when the genetic
optimization is complete. Notice that more than 8,000 iterations were required, compared to 44
for the Conjugate Directions method in Figure 6-19.
(a) (b)
(c) (d)
Figure 6-23: Progression of the genetic optimization method: (a) generation 1, (b) generation 5, (c) generation
23, and (d) generation 77.
6.3Constrained Optimization
The independent variables in an optimization must be constrained by specified upper and lower
bounds. However, it is possible that other quantities within the simulation must also be
constrained during the optimization process. Consider the objective function:
f = (1 x ) + 2 ( y
2
x2 (6-12)
)
2
Minimization of the objective function can be accomplished with any of the four methods
discussed in Section 6.2 and should result in f = 0 at x = 1 and y = 1, as shown in Figure 6-24.
We can constrain the optimization in various ways. For example:
x+3y 3 (6-13)
which requires that all viable points be below the line labeled constraint in Figure 6-24.
z = x+3y (6-14)
and set an upper bound on z that is equal to 3 in the Variable Information window, as shown in
Figure 6-25. To obtain the same results as shown in these examples, set the Max. function calls
to 800 and the Rel. conv. tolerance to 1E-10 in the Controls section of the dialog.
288 Chapter 6: Optimization
Figure 6-25: Variable Information window with upper bound set for z.
Choose one of the optimization methods, for example the Variable Metric method, and the result
should be as shown in Figure 6-26a . Note that is often possible to improve the optimization
result by updating the guess values and selecting a different optimization algorithm, such as the
Variable Metric method. The point identified as the constrained minimum is shown in Figure 6-
24.
Figure 6-26: Result of using the a) Variable Metric and b) Conjugate Gradient method to carry out the
constrained optimization by setting an upper bound on the constraint variable z.
Parameterizing Variables
It is often the case that the constraints narrow the allowable range of the independent variables.
This type of situation is encountered when you are optimizing concentrations (the allowable
range for each concentration is limited by those already selected), extraction pressures,
intermediate refrigeration temperatures, etc. In this situation it is often best to define a new
variable that parameterizes the allowable range.
In this example, once the value of the independent variable y is selected, the allowable range for
x is defined by:
2 x 3 3y (6-15)
We can define a new variable, , that can only take on values between 0 and 1 as it encompasses
the entire allowable range of x. Therefore, x should be assigned based on:
Chapter 6: Optimization 289
Now select y and to be the independent variables in the optimization, as shown in Figure 6-
27, and set the bounds on to be from 0 to 1, as shown in Figure 6-28.
Carrying out the optimization using the Variable Metric method leads to the result shown in
Figure 6-29. Note that only 156 iterations were required using the parameterization method
(Figure 6-29) compared with 292 iterations using the technique of bounding a constraint variable
(Figure 6-26). This reduction in computational time occurs because every value of and y that is
selected satisfies the constraint and therefore no time is wasted on independent variables that are
subsequently discarded.
290 Chapter 6: Optimization
Figure 6-29: Result of using the Conjugate Directions method to carry out the constrained optimization using
a parameter .
Penalty Function
The use of a parameterizing variable is clearly the best option for this problem. However, there
are problems where it is not possible to use this technique. In this case, it may be useful to
enforce the constraint by applying a penalty function that is large and proportional to the degree
to which the constraint is violated. The penalty function allows the optimization algorithm to
navigate into and back out of the region that is forbidden by the constraint. In this problem, we
might enforce a penalty function only if the constraint, Eq. (6-13), is violated and therefore:
x+3y 3 (6-17)
The size of the penalty function should be (1) large relative to the size of the function being
optimized; (2) proportional to the degree to which the constraint is not satisfied (i.e., x + 3y – 3),
and (3) zero if the constraint is satisfied. One possibility for the penalty function is:
0 if x + 3 y 3
pf = (6-18)
20 +10 ( x + 3 y 3 ) if x + 3 y
3
The penalty function can be implemented directly in the Equations Window using the If function
in EES. The If function has the following format:
If(A,B,C,D,E)
and returns C if A < B, D if A = B, and E if A > B. Therefore, the penalty function can be
implemented according to:
f = (1 x ) + 2 ( y x 2 ) + pf
2 2
(6-19)
original objective function
The addition of the penalty function has essentially transformed the objective function from the
smooth surface shown in Figure 6-24 to a surface with a “cliff” along the constraint line and a
sloping hill above it, as shown in Figure 6-30. (The surface in Figure 6-30 was drawn using the
3-D surface plotting option described in Chapter 9.)
Running the optimization with the penalty function using the Variable Metric technique leads to
the result shown in Figure 6-31.
Figure 6-31: Result of using the Variable Metric technique to carry out the constrained optimization using a
penalty function.
292 Chapter 6: Optimization
Notice that 302 iterations are required, which is not as good as parameterization, but about the
same as using a bound on a constraint variable in this case.
x1 sin ( x1 ) x2 = 0 (6-20)
1
+2x x 5= 0 (6-21)
1 2
x1
x1*sin(x1)-x2=0 1/x1+2*x1-x2-
5=0
but will not solve if the default guess values and bounds are used, leading to the message shown
in Figure 6-32.
The problem can be cast as an optimization problem by setting a value for x1:
The degree to which Eq. (6-21) is not solved is computed according to:
Solving leads to err = 2.841. Note that the value of the variable err will be zero if both equations
are solved. The use of the absolute value (abs) function requires that the value of err will be
always positive. Therefore, the problem has been recast as a minimization problem; minimize
the value of the variable err by adjusting the variable x1 in order to find the solution to the
equations.
and select Min/Max from the Calculate menu to access the Find Minimum or Maximum dialog
shown in Figure 6-33. Place reasonable bounds on the variable x1 and select OK. The result is
x1 = 2.795, x2 = 0.9483, and err = 0.000397. The solution can be obtained more precisely by
changing the stopping criteria on the optimization.
Curve Fitting
Chapter 2 discussed the options that are available within EES for curve fitting. However, curve
fitting can also be cast as an optimization problem in which some measure of the disagreement
between the predicted values and the data is minimized by adjusting the values of the
coefficients of the equation used for the curve fit. For example, Table 6-1 lists pressure,
temperature, and specific volume data for carbon dioxide. We could use these data to find the
best-fit coefficients (a and b) for the van der Waals equation of state:
RT a
P= (6-22)
( b)
v v2
Table 6-1: Pressure, temperature, and specific volume for carbon dioxide.
Pressure Temperature Specific volume
(MPa) (ºC) (m3/kg)
8 30 0.001423
9 30 0.001343
10 30 0.001296
11 30 0.001262
8 40 0.003601
9 40 0.00206
10 40 0.001587
11 40 0.001461
8 50 0.004562
9 50 0.003509
10 50 0.002602
11 50 0.001989
The data are entered into a Lookup Table in EES, as shown in Figure 6-34.
Chapter 6: Optimization 295
Initial values for a and b are guessed in order to set up the problem and the value of R is
computed.
Setup a Duplicate loop in order to cycle through each of the 12 rows of Lookup Table. Use the
LookUp command, discussed in Section 1.8, to obtain the pressure, temperature, and specific
volume at each data point.
duplicate i=1,12
P[i]=LookUp('CO2Data',i,1)*convert(MPa,Pa) "pressure from table, converted to Pa"
T[i]=ConvertTemp(C,K,LookUp('CO2Data',i,2)) "temperature from table, converted to K"
v[i]=LookUp('CO2Data',i,3) "specific volume from table"
Use Eq. (6-22) to compute the pressure based on the curve fit, Pfit, at the specific volume and
temperature associated with the data point.
Calculate the square of the error between the actual pressure and the pressure calculated from the
curve fit.
296 Chapter 6: Optimization
err[i]=(P[i]-P_fit[i])^2 "error"
end
The total error is defined as the square root of the sum of the error associated each data point,
divided by the number of data points.
Solving provides err = 1.566x107 Pa for a = 100 N-m4/kg2 and b = 0.01 m3/kg. The best-fit
coefficients can be found by commenting out the specified values of a and b.
Min/Max is selected from the Calculate menu in order to bring up the Find Minimum or
Maximum dialog, shown in Figure 6-35. Minimize the value of err by varying a and b. Set
some reasonable bounds and guesses for these independent variables and select OK to initiate the
optimization,
The results of the optimizations are shown in Figure 6-36. Note that the values of a and b
identified by the optimization are close to those calculated theoretically based on the critical
parameters of carbon dioxide, a = 138.2 N-m4/kg2 and b = 0.0007129 m3/kg.
References
Klein, S.A. and G.F. Nellis, Thermodynamics, Cambridge University Press, (2011).
Nelder, J.A. and Mead, R., The Computer Journal, Vol. 7, p. 308, (1965).
Press, W.H., B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, Numerical Recipes in Pascal,
Cambridge University Press, (1989).
Jones, D.R., Perttunen, C.D., and Stuckmann, B.E., Lipschitzian optimization without the
lipschitz constant, Journal of Optimization Theory and Applications, 79:157, 1993.
Gablonsky, J.M. , DIRECT Version 2.0 User Guide, North Carolina State University,
Department of Mathematics, Center for Research in Scientific Computation, Box 8205,
Raleigh, NC 27695-8205, April 18, 2001, [email protected]
7 INTEGRATION
The result of an engineering analysis is often one or more ordinary differential equations that are
sufficiently complex as to require numerical, rather than analytical solution. Partial differential
equations can also be solved by approximating them as a set of ordinary differential equations.
There are a variety of numerical techniques that can be used to solve ordinary differential
equations; these techniques range from explicit to implicit and from low order to high order. In
the first section of this chapter, we will briefly review these techniques and discuss their
characteristics. EES has a built in, powerful, numerical integration algorithm that can be used to
solve one or more ordinary differential equations. The remainder of this chapter discusses the
proper use of this feature of EES.
The numerical solution to any transient problem begins with the derivation of the governing
differential equation, which allows the calculation of the rate of change of the dependent
parameter to be computed as a function of the value of the dependent parameter and time. The
solution to the problem is therefore a matter of integrating the governing differential equation
forward in time. There are a number of techniques available for numerical integration, each with
its own characteristic level of accuracy, stability, and complexity. These numerical integration
techniques are introduced and discussed in this section in order to understand the Integral
command in EES, which provides an automated method for numerical integration. The EES
Integral command automatically implements a sophisticated, adaptive step-size integration
technique that is described in Section 7.2.
The governing differential equation that provides the rate of change of a variable (or several
variables) given its own value (or values) is sometimes referred to as the state equation(s) in the
context of a dynamic system. State equations characterize the transient behavior of many
engineering problems in dynamics, kinematics, fluids, electrical circuits, heat transfer and
thermodynamics.
Example ODE
In this section, the ODE:
dy
+ 4t y = 2t (7-1)
dt
Chapter 7: Integration 299
with initial condition y = 0 at t = 0 is solved numerically. This ODE is relatively simple and
therefore an analytical solution can be determined and used as the basis for evaluating the
accuracy of the numerical solutions that are discussed in this section.
Analytical Solution
Equation (7-1) can be separated:
dy
= t dt (7-2)
(2 + 4 y)
and integrated:
+
y
dt+
t
dy = t (7-3)
0 (2 + 4 y) 0
w = 2+4 y (7-4)
dw = 4 dy (7-5)
+
t
+t
2+4 y
dw = (7-6)
dt
2 4w 0
2
1 2+4 y t (7-7)
ln =
4 2 2
Equation (7-7) is solved for y:
y = exp ( 2 t 2 )
1 1
(7-8)
2 2
Discretizing Time
The solution to this problem can also be obtained numerically using one of several available
numerical integration techniques. Each numerical technique requires that the total simulation
time (tsim) be broken into small time steps. The simplest possibility uses equal-sized steps, each
with duration t:
t sim
t= (7-9)
( M 1)
where M is the number of times at which the solution will be evaluated. The solution at each
time step (yj) is computed by the numerical model, where j indicates the time step (y1 is the initial
condition at t1 = 0). The time corresponding to each time step is therefore:
( j 1)
tj = tsim for j = 1..M (7-10)
( M 1)
dy
y j +1 = y j + t (7-11)
dt y= y j ,t =t j
Chapter 7: Integration 301
Because the value of the solution at the end of the time step (yj+1) can be calculated explicitly
using information at the beginning of the time step (yj), Euler’s method is referred to as an
explicit numerical technique. The solution at the end of the first time step (y2) is given by:
dy
y2 = y1 + t (7-12)
dt y = y1 ,t =0
dy
where is computed using the governing differential equation. Equation (7-12) is
dt y = y1 ,t =0
written for every time step, resulting in a set of explicit equations that can be solved sequentially
for y at each discrete time.
As an example, we can solve Eq. (7-1) with y1 = 0 at t1 = 0. The time step duration and the array
of times for which the solution will be computed is specified using Eqs. (7-9) and (7-10):
The initial value of the variable y is specified as the first element in the array y.
It is often useful to carry out a single step in a numerical solution before simulating all of the
steps. The value of the time rate of change of y at y = y1 and t = t1 is determined using Eq. (7-1)
and substituted into Eq. (7-12):
Once we have established that it is possible to take one step, it is easy to take all of the steps.
Comment out the code used to take a single step:
and setup a duplicate loop that goes from j = 1 to j = (M - 1). Copy the code to take one step and
place it inside the duplicate loop. Change the element index 1 to j and the element index 2 to j
+1.
dydt[j]+4*t[j]*y[j]=-2*t[j]
y[j+1]=y[j]+dydt[j]*Dt
end
Solving the EES code results in a solution for y at every value of t in the Arrays Table. The
numerical solution is overlaid onto the analytical solution in Figure 7-2. Clearly the numerical
solution is approximate. However, the approximation improves as the number of time steps used
in the simulation increases (i.e., the duration of the time step is reduced). Figure 7-2 shows that
numerical simulation more closely approaches the analytical solution if the time step duration is
reduced from t = 0.125 s to t = 0.05 s.
Figure 7-2: Euler solution with t = 0.125 s and t = 0.05 s overlaid onto the analytical solution.
The analytical solution allows us to compute the error associated with the numerical solution
according to the discrepancy between the numerical and analytical solution at each value of time.
The maximum error at any time step, sometimes referred to as the global error, is computed
using the Max function.
duplicate j=1,M
y_an[j] = -1/2+exp(-2*t[j]^2)/2 "analytical solution"
err[j]=abs(y_an[j]-y[j]) "error"
end
error=Max(err[1..M]) "maximum or global error"
Figure 7-3 illustrates the global error associated with Euler's technique as a function of the time
step duration.
Chapter 7: Integration 303
Figure 7-3: Global error as a function of the time step duration for Euler’s technique and Heun’s technique.
Figure 7-3 shows that the global error is proportional to the duration of the time step to the first
power and therefore Euler's technique is referred to as a first order technique. This characteristic
of the solution can be inferred by examination of Eq. (7-12), which is essentially the first two
terms of a Taylor series expansion of the function y about time t = 0:
dy d2y t2 d 3 y t3
y2 = y1 + dt t+ 2 + + ... (7-13)
dt 2! dt 3 3!
y= y1 ,t =0 y = y1 ,t =0 y= y1 ,t =0
Euler's approximation local err neglected terms
Examination of Eq. (7-13) shows that the local error associated with each time step corresponds
to the neglected terms in the Taylor’s series and is therefore approximately proportional to t2
(neglecting the smaller, higher order terms). The local error accumulates during a simulation and
becomes the global error, resulting in an error that is proportional to the product of the number of
time steps and the local error:
t sim
M= (7-15)
t
which agrees with the error characteristic observed in Figure 7-3. Most numerical techniques
that are commonly used have higher order and therefore achieve higher accuracy.
Another drawback of Euler’s technique (and of any explicit numerical technique) is that it may
become unstable if the duration of the time step is too large. For our example, if the time step
duration is increased above approximately 0.6 s, then the numerical solution becomes unstable,
as shown in Figure 7-4. The time step at which the solution becomes unstable is called the
critical time step.
dy
ŷ j +1 = y j + t (7-17)
dt y= y j ,t =t j
However, Heun’s method uses the results of the predictor step to carry out a corrector step. The
solution predicted at the end of the time step ( ŷ j +1 ) is used to predict the rate of change at the
Chapter 7: Integration 305
dy
end of the time step ( ). The corrector step predicts the solution at the end of the time
dt y= ŷ j+1 ,t =t j+1
step (yj+1) based on the average of the time rates of change at the beginning and end of the time
step:
y =y dy t (7-18)
+
dy
+
j +1
j
dt y= y j ,t =t j dt y= ŷ j+1 ,t =t j+1
2
Heun’s method is illustrated in the context of the simple problem discussed previously. The
process of moving through the first time step begins with the predictor step:
dy
ŷ = y + t (7-19)
2 1
dt y= y1 ,t =t1
y =y dy t (7-20)
+
dy
+
2 1
dt y= y1 ,t =t1 dt y= ŷ2 ,t =t2 2
Once we have established that it is possible to take one step it is easy to take all of the steps.
Comment out the code used to take a single step:
and setup a duplicate loop that goes from j = 1 to j = (M - 1). Copy the code required to take one
step and place it inside the duplicate loop. Change the element index 1 to j and the element
index 2 to j +1.
Figure 7-5 illustrates the analytical solution as well as the Euler's solution and Heun's solution
with t = 0.125 s. There is an improvement in accuracy associated with the use of
Heun's technique for the same time step duration. Figure 7-3 illustrates the global error for
Heun's technique as a function of the time step and shows this improvement in accuracy. Notice
that the global error is proportional to the time step to the second power; Heun's technique is
second order with respect to global error.
Figure 7-5: Analytical and numerical solutions with Euler's and Heun's technique for t = 0.125 s.
Heun’s method is a two-step predictor/corrector technique that improves the order of accuracy
by one (i.e., the order of Heun’s method is two whereas the order of Euler’s method is one). It is
possible to carry out additional predictor/corrector steps that further improve the accuracy of the
numerical solution. One of the most popular higher order techniques is the fourth order Runge-
Kutta method (which involves four predictor/corrector steps and is therefore fifth order
accurate).
Chapter 7: Integration 307
dy
y j +1 = y j + t (7-21)
dt y= y j+1 ,t =t j+1
The time rate of change at the end of the time step depends on the solution at the end of the time
step (yj+1). Therefore, yj+1 cannot be calculated explicitly using information that is available at
the beginning of the time step (yj) and instead an implicit equation is obtained for yj+1. Because
EES solves implicit equations automatically, it is easy to implement the fully implicit technique.
The fully implicit solution does not become unstable even when the duration of the time step is
greater than the critical time step. Figure 7-6 illustrates the analytical solution as well as the
Euler and fully implicit solution with t = 0.625 s. Notice that the fully implicit solution remains
stable while the Euler's solution does not.
Figure 7-6: Euler's technique and fully implicit technique with t = 0.625 s.
308 Chapter 7: Integration
y =y dy t (7-22)
+
dy
+
j +1
j
dt y= y j ,t =t j dt y= y j+1 ,t =t j+1 2
Notice that the Crank-Nicolson is an implicit method because the solution for yj+1 involves a time
rate of change that must be evaluated based on yj+1. Therefore, the technique will have the
stability characteristics of the fully implicit method. The solution also involves two estimates for
the time rate of change and will therefore be second order accurate with respect to the global
error. Because EES solves implicit equations it is relatively easy to implement a Crank-Nicolson
solution using EES:
"Crank-Nicolson technique"
duplicate j=1,M
dydt[j]+4*t[j]*y[j]=-2*t[j] "time rate of change at t[j] and y[j]"
end
duplicate j=1,(M-1)
y[j+1]=y[j]+(dydt[j]+dydt[j+1])*Dt/2 "Crank-Nicolson solution"
end
The Crank-Nicolson method is a popular choice because it is simple yet it combines high
accuracy with stability.
The introduction to numerical integration provided in this section should make the difference
between implicit and explicit techniques clear and emphasize the importance of the order of the
integration technique and the size of the step that is taken. In this section, the various integration
techniques were implemented manually, taking steps using a duplicate loop and storing all of the
intermediate variables in arrays. This process is inconvenient and EES offers a better alternative.
The EES Integral command provides a high order, semi-implicit adaptive step-size integration
technique that will automatically operate on one or more state equations that are entered in the
Equations Window.
Chapter 7: Integration 309
F = Integral(Integrand, VarName,LowerLimit,UpperLimit,StepSize)
where Integrand is the EES variable or expression that must be integrated, VarName is the
integration variable, LowerLimit and UpperLimit define the limits of integration, and StepSize
(optionally) provides the duration of the time step.
For this problem, the first step would be to set some arbitrary value of the dependent variable (y)
and time (t):
"Integral Solution"
y=0 "arbitrary value of y"
t=0 "arbitrary value of t"
Next, enter the equations necessary to provide the time rate of change of y. In this case we need
only to program Eq. (7-1):
310 Chapter 7: Integration
tsim
dy
(7-23)
y = yini + +0
dt
dt
where yini = 0 is the initial condition. Therefore, the solution to our example problem is obtained
by calling the Integral function with Integrand replaced with the variable dydt, VarName replaced
with the variable t, LowerLimit replaced with 0, UpperLimit replaced with the variable t_sim, and
StepSize with Dt, the specified duration of the time step:
"Integral Solution"
{y=0 "arbitrary value of y"
t=0 "arbitrary value of t"}
dydt+4*t*y=-2*t "state equation"
Note that array variables and duplicate loops are not needed for the numerical integration when
the EES Integral function is used. The elimination of array variables allows much larger
problems to be solved and improves the computational speed.
In order to accomplish the numerical integration, EES will adjust the value of the variable t from
0 to t_sim in increments of Dt. At each value of time, EES will iteratively solve all of the
equations in the Equations Window that directly or indirectly depend on t. For the example
above, this process will result in the variable y being evaluated at each value t. When the
solution converges, the value of the variable t is incremented and the process is repeated until the
variable t becomes equal to t_sim. The result is shown in the Solution Window, Figure 7-7,
which shows the value of all of the variables at the end of the process (i.e., the result of the
integration, which is y at t = tsim).
Chapter 7: Integration 311
where VarName is the integration variable and x, y, z are dependent variables defined in the Main
section of the Equation Window that are of interest. The variables must be separated by a space
or list delimiter (comma or semicolon). Algebraic equations involving variables are not accepted
within the $IntegralTable directive. The first column in the Integral Table will contain values of
the integration variable and the remaining columns will contain the values of the other variables.
The colon followed by the parameter Step (which can either be a number or a variable name) is
optional. If a value is provided for Step, then the integration variables will be reported in the
Integral Table at increments of the integration variable specified by Step. The output step size
may be a variable name, rather than a number, provided that the variable has been set to a
constant value preceding the $IntegralTable directive. The step size that is used to report
integration results is totally independent of the duration of the time step that is used in the
numerical integration. If the numerical integration step size and output step size are not the
same, then linear interpolation is used to determine the integrated quantities at the specified
values of the integration variable. If the colon and an output step size is not specified, then EES
will output all specified variables at every time step.
Solving the EES code will result in the generation of an Integral Table that is filled with
intermediate values resulting from the numerical integration. The values in the Integral Table
can be plotted, printed, saved, and copied in exactly the same manner as for other tables. The
Integral Table is saved when the EES file is saved and the table is restored when the EES file is
loaded. If an Integral Table exists when calculations are initiated, it will be deleted if a new
Integral Table is created by the calculations.
Use the EES code below to generate an Integral Table containing the results of the numerical
simulation as well as the analytical solution:
$IntegralTable t, y
312 Chapter 7: Integration
After solving the code with a time step duration, Dt, of 0.1 s, the Integral Table shown in Figure
7-8 will be generated. Note that the result of every time step is included in the Integral Table
because the optional colon and output step size were not provided.
The results of the integration can be plotted by selecting the Integral Table as the source of the
data to plot. Figure 7-9 shows the results obtained from the Integral command with a fixed step
size overlaid onto the analytical solution.
Figure 7-9: Analytical solution and the results obtained from the Integral command with a fixed step size.
Chapter 7: Integration 313
The user can specify how often the step interval will be examined and adjusted, as well as the
absolute minimum and maximum number of integration steps that will be allowed. The relative
error criteria used to either reduce or increase the step size can also be specified. It is advisable
to use the $IntegralAutoStep directive to set the unit system so that your code produces consistent
results across various computers and is as transparent as possible. For example, the code:
specifies each of these integration parameters. The integration step size is varied after each step
(Vary = 1) and the number of steps must be greater than 5 (Min = 5) and less than 2000 (Max =
2000)2. The integration step will be reduced if the relative error is larger than 1x10-1 (Reduce =
1e-1) and increased if the relative error is less than 1x10-3 (Increase = 1e-3).
Removing the specified time step from the Integral command and including the $IntegralAutoStep
directive:
2
The minimum number of steps was set to 5 (rather than 50) so that the non-uniform step duration can be seen in
Figure 7-11.
314 Chapter 7: Integration
will generate the numerical solution shown in Figure 7-11. Notice the non-uniform time step
duration that is selected to maintain accuracy while maximizing the computational speed.
x2
m = 0.1 kg
m = 0.1 kg
The top mass is initially displaced an amount x2,ini = 0.05 m from its equilibrium position and
then released. These inputs are entered in EES.
$UnitSystem SI Mass J kg K Pa
$IntegralAutoStep Vary=1 Min=5 Max=2000 Reduce=1e-1 Increase=1e-3
"Inputs"
m=0.1 [kg] "mass"
k=100 [N/m] "spring constant"
b=1 [N-s/m] "damper"
We are interested in predicting the position of the two masses (x1 and x2) as a function of time as
they return to equilibrium. The dependent variables for this situation are x1 and x2 as well as v1
and v2, the velocities of the masses. In order to implement any numerical integration technique,
it is necessary to develop the state equations for the problem. That is, we must be able to predict
the time derivatives of x1, x2, v1, and v2 given their values and the value of time. Initially,
arbitrary values for the state variables are entered:
dx1 (7-24)
= v1
dt
dx2 (7-25)
= v2
dt
The derivatives of the velocities (accelerations) are obtained from force balances on each mass.
Neglecting gravity, the force balance on the top mass provides the time rate of change of v2:
dv2
k x +k x bv +bv = m (7-26)
2 1 2 1
dt
The force balance on the lower mass provides the time rate of change of v1:
dv1
kx 2k x +bv 2b v = m (7-27)
2 1 2 1
dt
Solving provides all of the state variable derivatives; therefore, we have successfully
implemented the state equations and can move on to the numerical integration. Comment out the
specified values of the state variables.
Implement the integration of each of the state variables using four Integral commands.
+dxdt
tsim
1 1,ini
x =x + 1
dt (7-28)
0
+dxdt
tsim
2 2,ini
x =x + 2
dt (7-29)
0
+dvdt
tsim
1 1,ini
v =v + 1
dt (7-30)
0
Chapter 7: Integration 317
+dvdt
tsim
2 2,ini
v =v + 2
dt (7-31)
0
The results are stored at each time step in an Integral Table using the $IntegralTable directive.
$IntegralTable t, x1,v1,x2,v2
Figure 7-13: Positions of the two masses (relative to their equilibrium position) as a function of time.
IntegralValue(t,'X')
where t is the value of the integration variable at which the value of the variable X will be
determined. The variable X must be one of the variables contained in the Integral Table.
There are many reasons that you might want to use data stored within the Integral Table. One
common reason for using the IntegralValue command is to retrieve a temperature or pressure at a
previous value of time so that the properties required by the state equation can be evaluated
318 Chapter 7: Integration
explicitly (i.e., using previous temperatures that are already known) as opposed to implicitly
(i.e.,. using the unknown temperature at the end of the current time step).
Consider the flow of carbon dioxide through a round tube, shown in Figure 7-14.
L = 10 m
carbon dioxide
Tin = 25C
P = 10 MPa
m = 0.01 kg/s
The inlet temperature of the carbon dioxide is Tin = 25ºC and the mass flow rate is m= 0.01
kg/s. The tube is L = 10 m long and it has an outer diameter of D = 2 cm. The outer surface of
the tube is exposed to a constant heat flux, = 3000 W/m2. The pressure of the carbon dioxide
q
may be assumed to be constant and can vary from 7.4 MPa to 10.0 MPa; initially assume that the
pressure is 10 MPa. The inputs are entered in EES:
"Inputs"
m_dot=0.01 [kg/s] "mass flow rate"
T_in=ConvertTemp(C,K,25 [C]) "inlet temperature"
D=2 [cm]*convert(cm,m) "diameter"
L=10 [m] "length"
q``=3000 [W/m^2] "heat flux"
P=10 [MPa]*convert(MPa,Pa) "pressure"
We are interested in predicting the bulk temperature of the carbon dioxide as a function of
position in the tube. The state variable is temperature (T) and the integration variable is position
(x). Initially, arbitrary values of these variables are defined:
"Dependent variables"
x=0.1 [m] "position"
T=300 [K] "temperature"
dh
mh + q D dx = mh + m (7-32)
dx
dx
where h is specific enthalpy. Expanding the specific enthalpy term and recognizing that pressure
is constant provides:
Chapter 7: Integration 319
h dT
q D = m (7-33)
P dx
T
The partial derivative of specific enthalpy with respect to temperature at constant pressure is the
specific heat capacity at constant pressure (cP); therefore, the state equation for this problem is:
dT qD (7-34)
=
dx mcP ( T )
The specific heat capacity is evaluated at the temperature (T) and pressure (P):
Solving leads to dTdx = 6.312 K/m. Comment out the specified values of x and T
"Dependent variables"
{x=0.1 [m] "position"
T=300 [K] "temperature"}
then you are likely to encounter the error message shown in Figure 7-16.
This error occurs because EES uses a semi-implicit numerical solution algorithm and therefore
very large variations in the properties with temperature may cause it to be unable to converge
during a particular step. Figure 7-17(a) illustrates a temperature-specific entropy diagram for
carbon dioxide (made using a property plot generated in EES, as discussed in Section 4.6). Note
that the pressures and temperatures considered in this problem are very near the critical point
(Tcrit = 30.98ºCand Pcrit = 7.377 MPa). Figure 7-17(b) illustrates the specific heat capacity as a
function of temperature for various values of pressure and shows that cP varies dramatically with
temperature as the pressure is reduced towards the critical pressure.
Chapter 7: Integration 321
(a) (b)
Figure 7-17: (a) Temperature-specific entropy diagram for carbon dioxide and (b) specific heat capacity of
carbon dioxide as a function of temperature for several values of pressure near the critical pressure.
One method of overcoming this problem with the numerical integration is to make the algorithm
explicit in terms of the properties; that is, the value of cP will always be evaluated using the
temperature from the previous step in the integration. The resulting value of cP will be assumed
to be constant during the current integration step. This approach is made possible using the
IntegralValue function.
We need to write a function T_last that returns the value of the temperature at the previous length
step unless x = 0 in which case it returns the inlet temperature. The function is placed at the top
of the EES code.
Function T_last(x,T_in)
If (x=0) Then
T_last=T_in
Else
T_last=IntegralValue(x-0.001 [m],T)
EndIf
End
Rather than compute cP using the value of T that is being adjusted actively in order to take the
integration step,
{c=cP(CarbonDioxide,T=T,P=P) "specific heat capacity"}
the explicit technique obtains the value of T from the previous time step using the function T_last
and uses that temperature to evaluate cP:
"Explicit"
Tl=T_last(x,T_in) "last value of temperature"
c=cP(CarbonDioxide,T=Tl,P=P) "specific heat capacity"
Double Integration
Numerical integration with two variables can be nested in order to carry out double integration.
As an example, consider a rectangular block with an initial temperature distribution given by:
(2 x, y ) = 300 K +10
K K
T x 2 + 20 (7-36)
y
m 2 m 2
ini
The width of the block in the x-direction is W = 2 m and the height in the y-direction is H = 1 m.
The initial temperature is shown in Figure 7-18 on a contour plot; note that the generation of
contour plots is discussed in Section 9.3.
If the edges of the block are insulated then the final, uniform temperature of the block can be
determined using an energy balance. We will assume that the material has a constant specific
heat capacity. The initial internal energy per unit length is:
H W
U ini = + + c T ( x, y ) dx (7-37)
dy
y=0 x=0
H W
+ + c T ( x, y ) dx dy = c T final W (7-40)
H
y=0 x=0
1
outer integral
T = H W T ( x, y ) dx dy (7-41)
final
WH + +
y=0 x=0
inner integral
As with the integrations discussed thus far, it is worthwhile making sure that the integrand of the
double integral (T) can be evaluated at arbitrary values of the integration variables (x and y).
"integrand"
T=300 [K]+10 [K/m^2]*x^2+200 [K/m^2]*y^2 "temperature"
Once the integrand has been programmed, the specified values of x and y should be commented
out:
{x=0 [m]
y=0 [m]}
The double integral in Eq. (7-41) can be evaluated using two nested Integral commands. The
inner integral is:
Integral(T,x,0,W)
Solving provides Tfinal = 380 K. Note that the double integral could have equivalently been
evaluated according to:
Subprogram integral2(a:y)
f=x*exp(a*x)
y=integral(f,x,0,2) "second integral"
$IntegralTable x:0.1 y
End
Call integral1(2:Int1)
Call integral2(2:Int2)
f=x^2
y=integral(f,x,0,3) "third integral"
$IntegralTable x:0.1 y
Figure 7- 19: Integral Table showing three tabs, one for each integral in the Subprograms and the Main
Program.
Note that the IntegralValue function can only access the Integral Table for the Main program.
Chapter 7: Integration 325
F = Integral(Integrand, VarName)
where F is the integral and VarName is the name of the integration variable. The variables F and
VarName must be included in the Parametric Table and values of the variable VarName must be
specified in order to provide the limits and step size. It is not necessary that the step size be
constant. The variable Integrand must be calculated in the Equations Window.
dy
+ 4t y = 2t (7-42)
dt
from t = 0 to t = 2.5. First, set up the Parametric Table containing both the integration variable
(t) and the dependent variable (y). Set the values of t in order to specify the limits and step size.
The result is shown in Figure 7-20(a).
Figure 7-20: Parametric Table (a) before solving and (b) after solving.
Enter Eq. (7-42) in the Equations Window in order to evaluate the derivate of y with respect to t.
The value of y at any time (t) specified in the Parametric Table is found using the Integral
command. The analytical solution can also be entered for comparison to the numerical solution.
Select Solve Table from the Calculate menu in order to fill in the values of y, as shown in Figure
7-20(b). The solution is shown in Figure 7-21 together with the analytical solution given by Eq.
(7-8).
Figure 7-21: Solution obtained using the table-based integral function and the analytical solution.
Note that table-based integrals can be used to calculate the uncertainty of an integral, as shown in
section 8.4.
L = 5 cm
T = 200C
h = 500 W/m -K
2
k = 5 W/m-K
= 2000 kg/m3
c = 200 J/kg-K
Figure 7-22: A plane wall exposed to a convective boundary condition at time t = 0.
Chapter 7: Integration 327
The plane wall has thickness L = 5.0 cm and properties k = 5.0 W/m-K, = 2000 kg/m3, and c =
200 J/kg-K. The wall is initially at Tini= 20ºC when at time t = 0, the surface (at x = L) is
exposed to fluid at T∞ = 200ºC with average heat transfer coefficient h = 500 W/m2-K. The
wall at x = 0 is adiabatic. The known information is entered into EES.
"Inputs"
L=5 [cm]*convert(cm,m) "wall thickness"
k=5.0 [W/m-K] "conductivity"
rho=2000 [kg/m^3] "density"
c=200 [J/kg-K] "specific heat capacity"
T_ini=converttemp(C,K,20 [C]) "initial temperature"
T_infinity=converttemp(C,K,200 [C]) "fluid temperature"
h_bar=500 [W/m^2-K] "heat transfer coefficient"
T (7-44)
x =0
x=0
T
k
=h T (7-45)
T x=L
x x=L
Tt =0 = Tini (7-46)
In order to solve this problem, it is necessary to position nodes throughout the material as shown
in Figure 7-23. The axial position of each node is given by:
L
x= (7-48)
(N
1)
"Setup grid"
N=6 [-] "number of nodes"
Duplicate i=1,N
x[i]=(i-1)*L/(N-1) "position of each node"
End
DELTAx=L/(N-1) "distance between adjacent nodes"
x
Figure 7-23: Nodes positioned within the computational domain.
dT dT
dx dx
=
dTi x= xi + x/2
x= xi x/ 2 for i = 2.. ( N (7-49)
dt x
1)
Substituting:
dT (Ti+1 Ti
dx ) (7-50)
x= xi + x/2
=
x
dT
dx (Ti Ti 1 ) (7-51)
x= xi x/ 2
=
x
dTi
=
(Ti+1 + Ti 1 2Ti ) for i = 2.. ( N (7-52)
dt x2
1)
which is the state equation for each of the internal node temperatures.
Chapter 7: Integration 329
dT dT
dT1 dx dx x=0
=
x= x/ 2
(7-53)
dt x
2
dT (T2 T1
dx ) (7-54)
x= x/2
=
x
dT1 (T T )
= 2 2 21 (7-55)
dt x
dT dT
dTN x=L dx x=L x/2
dx
x
(7-56)
dt =
2
dT (TN TN 1 )
= (7-57)
dx x= L x/ 2 x
h (T (TN TN )
k N T )
1
x
dT
N
= 2 (7-58)
dt x
The first step in the solution process is to assign arbitrary values for the integration variable (t)
and the state variables (T1 through TN) and calculate the time rate of change of each of the state
variables using Eqs. (7-52), (7-55), and (7-58).
330 Chapter 7: Integration
Once the state equations have been implemented and checked it is possible to comment out the
arbitrary values of t and T1 through TN
and use the Integral command to integrate the set of simultaneous ODEs represented by Eqs.
(7-52), (7-55), and (7-58) through time.
+dTdt
tsim
i ini
T =T + i
for i = 1..N (7-59)
0
Note that the problem considered here is identical to the bounded transient conduction problem
that is included in the Transient Conduction menu of the Heat Transfer Library, discussed in
Section 12.9 and therefore this solution can be directly compared to the analytical solution using
the function planewall_T.
Duplicate i=1,N
T_an[i]=planewall_T(x[i], time, T_ini, T_infinity, alpha, k, h_bar, L)
End
A $IntegralTable directive is used to store the trajectory of the integration process for each node.
$IntegralTable time:1,T[1..N]
The numerical and analytical solution for the temperature at each axial location as a function of
time is shown in Figure 7-24.
Chapter 7: Integration 331
Figure 7-24: Numerical and analytical solution for the temperature at various axial locations as a function of
time.
332 Chapter 17: Distributable Programs
8 UNCERTAINTY PROPAGATION
Variables in engineering problems typically represent physical quantities. Therefore, EES
allows variables to be assigned units, as discussed in Section 1.5. Variables in engineering
problems may also be characterized by some uncertainty, particularly if they are the result of
measurements. The results of calculations that involve these variables will, themselves, have
some uncertainty. The process of keeping track of how the uncertainty of measured variables
causes uncertainty in calculated variables is referred to as uncertainty propagation. The most
common technique for propagation of uncertainty is referred to as the Root Sum Squares (RSS)
method and it is reviewed in Section 8.1. EES allows the user to specify not only a value and a
unit to each variable, but also an uncertainty. The propagation of this uncertainty through the
calculations using the RSS method is automatically accomplished using EES’ internal
uncertainty propagation capability, described in this chapter.
Q = Q ( x1 , x2 ,..., xN ) (8-1)
then the uncertainty in Q (uQ) can be divided into its elemental uncertainties due to each of the
measured variables ( u Q, x through uQ, x ). The elemental uncertainty in Q due to measurement xi
1 N
is given by:
Chapter 8: Uncertainty Propagation 333
The elemental uncertainties can be combined to provide the total uncertainty in Q by taking the
square root of the sum of squares of the elemental uncertainties:
$UnitSystem SI Mass J K Pa
The argon is assumed to behave according to the ideal gas law. The ideal gas constant is
obtained according to:
Runiv
R= (8-4)
MW
where Runiv is the universal gas constant and MW is the molar mass of argon. We will assume
that there is no uncertainty in the value of the ideal gas constant. The specific volume of argon is
computed according to the ideal gas law:
RT (8-5)
v= P
The elemental uncertainty in the specific volume due to the uncertainty in temperature is given
by:
334 Chapter 8: Uncertainty Propagation
v R
u = u = u (8-6)
v ,T T T
T P
and the elemental uncertainty in the specific volume due to the uncertainty in pressure is given
by:
RT
uv ,P = v u = u (8-7)
P
P P 2 P
Solving provides v = 0.06584 m3/kg with elemental uncertainties uv,T = 0.00027 m3/kg and uv,P =
-0.0016 m3/kg. The total uncertainty in specific volume is uv = 0.001574 m3/kg.
V
m= (8-9)
v
The elemental uncertainty in the mass due to the uncertainty in the volume is:
m
u = u uV (8-10)
m ,V V =
V v
and the elemental uncertainty in the mass due to the uncertainty in the specific volume is:
V
um ,v = m uv = u (8-11)
v v 2 v
Solving provides m = 0.1519 kg with elemental uncertainties um,V = 0.0061 kg and um,v = -0.0036
kg. The total uncertainty in the mass is um = 0.007078 kg.
$UnitSystem SI Mass J K Pa
"Inputs"
T=ConvertTemp(C,K,22.3 [C]) "temperature"
u_T=1.2 [K] "uncertainty in temperature"
P=934 [kPa]*convert(kPa,Pa) "pressure"
u_P=22 [kPa]*convert(kPa,Pa) "uncertainty in pressure"
Vol=10 [liter]*convert(liter,m^3) "volume"
u_Vol=0.4 [liter]*convert(liter,m^3) "uncertainty in volume"
The calculations required to obtain the mass, Eqs. (8-4), (8-5), and (8-9) are entered:
Solving provides m = 0.1519 kg but no indication of the uncertainty in this calculated mass.
The list of variables in the window on the right has been identified by EES as being measured
variables that could have some uncertainty assigned to them. The variables that initially
336 Chapter 8: Uncertainty Propagation
populate this list are simply constants; that is, variables that are independent of all other
variables. The variables in the window on the left are judged by EES to be calculated quantities.
Note that the variables listed in red can be moved from the list of calculated variables to the list
of measured variables. Select from the list of measured variables those that have some
uncertainty (i.e., the variables P, T, and Vol in Figure 8-1). The maximum number of "measured"
variables is 30 in the Commercial version of EES and 200 in the Professional version. Select Set
uncertainties in order to access the Uncertainties of Measured Variables dialog, shown in Figure
8-2.
The uncertainties can be set on an absolute or relative basis using either numerical constants or
variables. The units column provides the units for the measured variable and these are the units
that must be used to set uncertainty on an absolute basis. In Figure 8-2, the uncertainties are set
using the variables u_P, u_T, and u_Vol which have been assigned in the Equations Window.
Alternatively, numerical values could have been entered.
The Professional version will provide Open and Save buttons surrounding the Set Uncertainties
button, as seen in Figure 8-1. These buttons can be used to save and later retrieve the uncertainty
specifications made in the Set Uncertainties dialog. The information is saved in an .unc file.
Using these files, it is possible to conduct different uncertainty analyses without having to re-
enter any of the uncertainty information.
Array variables can be selected to be the among the measured variables in an uncertainty
analysis. For example, a calculated result may depend upon ten temperatures that are in array T
In the Professional version, the uncertainty values for all of the array variables selected for the
uncertainty analysis may be set at once for the entire array, e.g., T[] by unchecking the Show
Array Variables that will be displayed at the upper left corner of the dialog.
An alternate set of units can be specified for any variable. For example, alternate units for Vol
could be set to cm3 in several ways. One way is to include the following $VarInfo directive in
the Equations window.
When alternate units are specified for measured variables, the uncertainty values may be entered
in either the base or alternate units. The Uncertainties of Measured Variables will provide a
drop-down list in the units column for each variable that has base and alternate units. Selecting
Chapter 8: Uncertainty Propagation 337
the alternate units will result in use of a red font for the value, units, and uncertainty value, as
shown in Figure 8-3 to remind the user the Absolute Uncertainty should be entered in the
alternate units.
Figure 8-3: Uncertainties of Measured Variables dialog with alternate units for Vol selected.
Figure 8-4 shows that the specific volume is v = 0.0658 m3/kg with a total uncertainty of uv =
0.001574 m3/kg and the mass is m = 0.1519 kg with a total uncertainty of um = 0.007078 kg. The
source of the uncertainty in these values is also delineated. For example, Figure 8-4 shows that
74% of the total uncertainty in mass can be assigned to the uncertainty in the measurement of
volume.
338 Chapter 8: Uncertainty Propagation
Internally, EES is carrying out the same procedure that we did by hand in Section 8.1 and
therefore these results are identical. The difference is that EES calculates the required partial
derivatives (e.g., the partial derivative of specific volume with respect to pressure) numerically
rather than analytically. As a result, it is possible to carry out uncertainty analyses for large and
complex systems of equations where analytical derivatives are not available. For example, rather
than using the ideal gas law, we can utilize the equation of state for real fluid argon that is
accessed with the volume function:
Carrying out the uncertainty propagation calculations leads to the solution shown in Figure 8-5.
The results are very similar to those for the ideal gas representation of argon in this case.
However, this would not have been the case at higher pressures where deviations from ideal gas
behavior occur. It would not have been possible to analytically determine the partial derivatives
for real fluid argon.
Figure 8-5: Uncertainty Results tab of the Solutions Window using the volume function.
UncertaintyOf Function
The UncertaintyOf function returns the assigned or calculated uncertainty of the variable that is
provided as the argument of the function. For example, the command:
would provide um = 0.007078 kg when the uncertainty propagation calculations are run for the
example from the last section. Note that the value of um will be zero if the calculations are not
initiated using the Uncertainty Propagation command. The EES code:
UmV=Uncert.ParDif(m,Vol)
PercentUmV=Uncert.Percent(m,Vol)
Variables UmV and PercentUmV will display in the Solution window to be 15.19 and 73.69,
respectively in the Solution window. The units of variables UmV and PercentUmV should be set
to 'kg/m3' and '%', respectively to eliminate the unit warnings.
and set up a Parametric Table that includes the variables T, m, and v. Vary the values of
temperature using the Alter Values command, so that the Parametric Table appears as shown in
Figure 8-6(a).
(a)
340 Chapter 8: Uncertainty Propagation
(b)
Figure 8-6: Parametric Table with (a) the values of T set and (b) the uncertainty propagation carried out.
Select Uncertainty Propagation Table from the Calculate menu in order to access the Determine
Propagation of Uncertainty dialog, shown in Figure 8-7. Calculated variables can be selected
from the window on the left; these include only those variables that are in the Parametric Table.
Measured variables can be selected from the window on the right, which includes variables in the
Parametric Table as well as those defined in the Equations window. The uncertainties of all
measured variables must be specified.
Select OK to initiate the propagation of uncertainty calculations. The values of the calculated
variables in the table will be assigned along with their uncertainties, as shown in Figure 8-6(b).
The error bars can be removed by double clicking on the graph and de-selecting the error bars.
q
electrical heater
The mass flow rate ( m) through the tube is controlled and measured. The experimental
uncertainty of the mass flow rate measurement is um = 0.005 kg/s. The diameter of the tube is D
= 0.115 inch and its length is L = 6 inch; these characteristics have been measured with an
uncertainty of uD = 50 m and uL = 1 mm, respectively. The tube is surrounded by a copper
sleeve so that its wall is nearly isothermal. A measured rate of heat input ( q) is applied to the
test section electrically using a heater that is installed on the outer surface of the copper. The
rate of heat input is measured with a precision of uq = 1 W. The temperature of the wall (Twall)
is measured as is the bulk temperature of the fluid entering and leaving the tube (Tin and Tout).
The temperatures are each measured with an uncertainty of uT = 1 K. The measurements are
carried out over a range of mass flow rates and the data are shown in Table 8-1.
Mass flow Inlet fluid Wall temperature Outlet fluid Rate of heat
rate (kg/s) temperature (ºC) (ºC) temperature (ºC) addition (W)
0.012 21.4 41.2 25.74 217.8
0.022 21.7 43.5 26.47 438.8
0.031 21.3 43.1 25.95 603.6
0.041 21.5 40.9 25.54 692.3
0.052 21.6 42.6 25.87 928.4
0.061 21.4 44.2 25.95 1161
0.071 21.3 42.9 25.54 1260
0.083 21.7 42.0 25.61 1359
The data in Table 8-1 are entered into a Lookup Table, as shown in Figure 8-10.
Each run of the table can be processed in the Equations Window and the results placed in a
Parametric Table using the TableRun# function in EES. The TableRun# function returns the
current row of the Parametric Table that is being run when the Equations Window is activated
using the Solve Table command. If the Equations Window is activated using the Solve
command, then the TableRun# command returns zero. The mass flow rate, temperatures, and rate
of heat transfer for the row being processed is obtained using the Lookup command and the
TableRun# function:
If the Solve command is used then the TableRun# will return zero which leads to the Lookup
command returning the value from the first row in the table (because there is no row zero) and a
Chapter 8: Uncertainty Propagation 343
warning is issued. The heat transfer coefficient ( h ) is computed from the data using the
formula:
q= h D L
(Tout Tin ) (8-13)
( Twall Tin
ln
) T
( Twall out )
q_dot=h_bar*pi*D*L*(T_out-T_in)/ln((T_wall-T_in)/(T_wall-T_out))
A Parametric Table is created with 8 rows (one for each of the data points in Table 8-1 and
corresponding row in the Lookup Table shown in Figure 8-10). The variables m_dot and h_bar
are included in the Parametric Table, as shown in Figure 8-11(a).
Select Solve Table from the Calculate menu in order to populate the table with the values of heat
transfer coefficient that are calculated for each data point, as shown in Figure 8-11(b). The
uncertainty propagation calculations are carried out by selecting Uncertainty Propagation Table
from the Calculate menu, which provides access to the Determine Propagation of Uncertainty
dialog shown in Figure 8-12.
344 Chapter 8: Uncertainty Propagation
Select OK to set the uncertainties and then select OK again in order to run the Parametric Table.
The results are shown in Figure 8-11(c); note that each calculated quantity now includes an
uncertainty. Plotting the data shown in Figure 8-11(c) produces the plot with error bars that is
shown in Figure 8-14.
Chapter 8: Uncertainty Propagation 345
Figure 8-14: Calculated heat transfer coefficient as a function of mass flow rate with error bars indicated.
As an example, we will estimate the work required to compress ammonia vapor and the
uncertainty associated with this estimate. The pressure and volume of the ammonia during the
compression process have been experimentally measured and the data are provided in Table 8-2.
The pressure has an uncertainty that is equal to 5% of the measured value. The uncertainty in the
volume is 0.5 in3.
346 Chapter 8: Uncertainty Propagation
W = + PdV (1-14)
The integral will be determined numerically using a table-based integration. Start EES and enter
the following lines into the Equations window.
"Uncertainty of an Integral"
$UnitSystem Eng F psia mass
W=Integral(P,V)*convert(psi-in^3, Btu)
Create a new Parametric table with 7 rows and columns for P, V, and W. Enter the experimental
values of pressure and volume into the Parametric table. The table should appear as shown in
Figure 8-15.
The value of the work required for the compression is found by solving the table (press F3). The
required work for the entire compression process is shown in the last row for column W to be
-0.5587 Btu. The value is negative, indicating the work must be supplied for this process.
However, the calculations have not yet taken into consideration the uncertainty in the pressure
and volume measurements. The uncertainty associated with W, based on the uncertainties in the
7 measurements of P and V can be found using the Uncertainty Table command in the Calculate
menu. Select P and V as the Measured variables and W as the Calculated variable (Figure 8-
17).
Click the Set uncertainties button and enter the uncertainties for P and V (Figure 8-18).
348 Chapter 8: Uncertainty Propagation
Click the OK buttons to start the uncertainty calculations. When the calculations are completed,
the Parametric table should appear as shown. You can make the sum row appear by adding a
$SumRow On directive, or by right-clicking in the Run column and selecting Show Sum from
the pop-up menu.
The result of this calculation is that the integral, W, is -0.5587 ± 0.0216. The uncertainty value
is the square root of the sum of the squares of the uncertainty values shown in each row of the
table and it is displayed in the Sum row.
349 Chapter 17: Distributable Programs
9 ADVANCED PLOTTING
The basic plotting features that are provided by EES were described in Section 1.4. This chapter
presents some additional types of plots that are available as well as some options for copying and
documenting plots in EES.
Figure 9-1: New Plot Window selection from the Plots menu.
Notice that there are several other plotting options available in EES, including Bar Plots, X-Y-Z
(or 3-D) plots, and Polar Plots.
Point Labels
It is possible to associate a text label with each plotted point. The label can be a number or text.
The most common use of this capability is to display the subscript number of an array variable in
the plot, which allows identification of a thermodynamic state. An example of using plot point
labels for this purpose is provided in Figure 4-22 in Section 4.6. The Commercial version
allows numbers for the point labels. When plotting data from the Parametric and Lookup tables,
these numbers are the run or row numbers. The subscript number is used when plotting data
from the Arrays table.
The Professional version extends the capability of point labels by allowing strings that are
defined in the table to serve as point labels. The following simple program illustrates this
capability. The program plots the acentric factor of alcohols in the Incompressible Fluids library
as a function of their respective molecular weights. A listing of the program follows.
350 Chapter 9: Advanced Plotting
A Parametric table is created with columns for Fluid$ (the name of the fluid), MW, P_crit,
T_crit, and omega. The names of the fluids are entered, as shown in Figure 9-2.
Running this program will fill the columns with the thermodynamic properties of each fluid.
Next create a plot of acentric factor (omega) versus the molecular weight (MW) using the New
Plot Setup for an X-Y plot. The Plot Setup dialog appears in Figure 9-3.
Note that only the symbols will be plotted without a plot line. We wish to identify each symbol.
This is done by selecting the 'Add point labels' control. A popup menu is provided under this
control. Click on the arrow at the right of this menu to display its contents. Select Fluid$. The
strings in this column will provide the labels. Click OK. The plot appears in
Figure 9-4.
0.7
isopropanol
0.65
ethanol
w [-]
0.6
methanol
0.55
0.5
20 30 40 50 60 70
MW [kg/kmol]
Figure 9-4: Plot of acentric factor versus molecular weight with point labels used for identification.
Note that each point is identified by a string taken from the same row in the table as the point
coordinates. The label is initially positioned to the right of the point. However, it can be
manually moved. The position of the label relative to the point symbol will be maintained if the
plot size is changed or the axes are scaled. If the plot line is deleted, the point labels will also be
deleted.
$TabStops 3.5 in
"Inputs - converted to base SI units"
352 Chapter 9: Advanced Plotting
After the equations have been entered and checked, create a Parametric table with 10 rows and
columns for variables for V_dot_lpm, V_dot_cfm, DELTAP_kPa, and DELTAP_inH2O. Note that in
Professional version, it is possible to dual units assigned to data in the Parametric table as
described in Section 1.5, so only two rather than four columns would be needed. However, this
capability will not be used here so that the example works for both the Commercial and
Professional versions. Fill the V_dot_lpm column with data ranging from 0 to 2 liters/min. Solve
the table. It should now appear as shown in Figure 9-5.
Figure 9-5: Parametric table showing volumetric flow versus pressure loss in two sets of units.
Select New Plot Window|X-Plot from the Plots menu and plot V_dot_lpm on the X-axis and
DELTAP_kPa on the Y-axis. Note that the plot axes have been scaled so that the maximum
values are 2.5 liter/min on the X-axis and 0.8 kPa on the Y-axis. The corresponding values of
Chapter 9: Advanced Plotting 353
these maxima in English units are 0.0883 cfm and 3.2117 inH2O. The Calculator window (see
Section 1.9) is very useful for doing these extraneous calculations. These values will be needed
to scale the axes plotted in the English system.
Next select the Overlay Plot menu item from the Plots menu and set V_dot_cfm to be the X-axis
variable on scale X2 (upper X-scale) and DELTAP_inH2O to be the Y-axis variable on scale Y1
9right Y-scale. Set the maximum value for V_dot_cfm to be 0.0883 and the maximum value for
DELTAP_inH2O to be 3.2117, as shown in Figure 9-6.
Figure 9-6: Setup Overlay dialog with inputs appropriate for dual X and Y axis scales.
Click OK. If you have properly entered the axis minima and maxima, EES will plot a line with
symbols directly on top of the existing line. If the lines are not exactly the same, the limits that
you have entered need to be corrected. Hide the line that was just plotted by right-clicking in the
plot window and changing the line and symbol types to none. Note that EES created a second X-
axis scale at the top of the plot and a second Y-axis at the right of the plot, including axis labels.
You may wish to edit the labels as usual so that they appear as you wish. The plot should now
appear as shown in Figure 9-7.
If you are satisfied with the appearance of this plot, your job is done. However, you can
optionally move the top X-axis and the right Y-axes to other locations. To do this, hold the Ctrl
key down and press the up/down arrow keys to move the upper X-axis and the left/right keys to
move the right Y-axis. Position the axes where you wish. Then you can use other formatting
options, such as horizontal and vertical lines to separate the scales and addition labels to make
the information in the plot clear.
354 Chapter 9: Advanced Plotting
Vcfm [cfm]
0 0.02 0.04 0.06 0.08
0.8
3
0.6 2.5
PinH2 [inH2O]
PkP [kPa]
0.4
1.5
1
a
0.2
O
0.5
0 0
0 0.5 1 1.5 2 2.5
Vlpm [liter/min]
Figure 9-7: Plot of pressure loss versus volumetric flow rate with two scales.
0.8
3
0.6
DPinH2O [inH2O]
DPkPa [kPa]
0.4
1
0.2
0 0
0 0.5 1 1.5 2 2.5 Vlpm [liter/min]
0 0.02 0.04 0.06 0.08 Vcfm [cfm]
Figure 9-8: Plot of pressure loss versus volumetric flow rate with the top and right axes moved.
Chapter 9: Advanced Plotting 355
When the cross-hairs tools is enabled, a status bar will be provided at the bottom of the plot
window showing the x and y coordinates corresponding to the position of the red cross-hairs. If
there is a right Y axis and/or a top X axis, the coordinates of the cursor will be displayed for
these axes as well. If the plot was generated by the Property Plot command, then the values of
thermodynamic properties corresponding to the cursor position will be displayed in the status
bar, as seen in Figure 9-9.
Figure 9-9: Property plot showing use of cross-hairs to identify property values.
The cross-hairs can also be used to identify the location of a plotted point in a table. Position the
cross-hairs over a plotted symbol and press the right mouse button. The status bar will show the
coordinates of the point, the table that the data originated in and the row in that table as seen in
Figure 9-10. If the table used to plot the data exists, it will be made visible highlighting the row
that corresponds to the plotted data. To cancel the cross-hairs, move the mouse so that the cross-
hairs is no longer in the plot rectangle. The status bar and the cross-hairs will then disappear.
356 Chapter 9: Advanced Plotting
Figure 9-10: Right-click on a plotted point to show the table used to plot the data.
Bar Plots
A bar chart is a chart that has rectangular bars with lengths that are proportional to the values that
they represent. This type of plot is ideal for illustrating binned data (e.g., histograms or other
data where a number of counts have been assigned to various bins) or discontinuous or discrete
data (e.g., color or college major). Consider Table 9-1, which lists the grades assigned in an
undergraduate class; the average value of these scores is x = 84.3 and the standard deviation is
= 7.2.
A- 90-93 26
B+ 87-90 33
B 83-87 42
B- 80-83 36
C+ 77-80 30
C 73-77 17
C- 70-73 6
D+ 67-70 2
D 63-67 0
D- 60-63 1
These data are entered in a Lookup Table, shown in Figure 9-11(a). Note that the letter grades
can be entered in the first column of the Lookup Table only after it has been formatted to be of
type “string” by right-clicking on the column heading and selecting properties. Select string as
the Style, as shown in Figure 9-12.
(a)
358 Chapter 9: Advanced Plotting
(b)
Figure 9-11: Lookup Table (a) containing data from Table 9-1 and (b) with a column that includes the center
of each range.
Figure 9-12: Format the Grade column of the Lookup Table as string.
In order to create a fifth column that contains the center of each range, right click on the fourth
column and select Insert column to the right. Right-click on the new column and select Alter
Values; use the Enter Equation option, as shown in Figure 9-13 to create the Lookup Table
shown in Figure 9-11(b).
Chapter 9: Advanced Plotting 359
Figure 9-13: Enter Equation option to create column with center of each range.
To create a bar chart showing these results, select New Plot Window from the Plots menu and
then select Bar Plot. Select the column Center of range as the X-Axis and Number of students as
the Y-Axis to create the histogram shown in Figure 9-14.
p=
1
exp
(x x )
(9-1)
2 2
x_bar=84.3 "mean"
sigma=7.2 "standard deviation"
p=exp(-(x-x_bar)^2/sigma^2)/sqrt(2*pi) "normal probability distribution"
A Parametric Table is created containing the variables x and p. The value of the variable x is
varied from 60 to 100. The value of the variable p is calculated for each value of x using the
Solve Table command. Select Overlay Plots from the Plots menu and then select the Parametric
Table as the data source with the variable x as the X-Axis and p as the Y-Axis. Plot these results
Chapter 9: Advanced Plotting 361
on the right y-axis. If the symbol is chosen to be a cross-hatched bar (the default), the plot will
appear as shown in Figure 9-16 with both bar plots visible.
The most recent plot appears in front of earlier plots. In some cases, such as this one, this order
is not desirable. The order of bar or X-Y plots can be rearranged by selecting Modify Plot from
the Plots menu or by clicking the right-mouse button when the mouse is positioned within the
plot rectangle (but not on a text or graphic item). The Modify Plot dialog will display all of the
plots. To change the order of the plots, press and hold the right mouse button down on the name
of the plot you wish to move. The cursor will change to a drag cursor, as shown in Figure 9-
17(a). Move the cursor to the position that you wish the plot to appear at and release the mouse
button. The position of the plot will change and the word reordered will be shown in red below
the list, as seen in Figure 9-17(b). Press the OK button and the plot will be drawn with the
probability distribution bar plot in the background.
(a) (b)
Figure 9-17: Changing the order of plots in the Modify Plot dialog
In this case, however, the plot would look best if the normal probability distribution were shown
with a line, rather than with bars. Right-click in the plot rectangle to bring up the Modify Plot
dialog again. Click the symbol control to change the symbol to none. Change the line type to a
solid line. The plot will appear as shown in Figure 9-18 after the OK button is pressed and the
legend information is added with the Add text button on the plot tool bar.
362 Chapter 9: Advanced Plotting
Figure 9-19: Histogram of students’ grades with string values for x-axis.
Chapter 9: Advanced Plotting 363
Figure 9-20: Data in a Lookup table that will be plotted as side-by-side bar plot
A bar plot of the energy values as a function of year can be created in one step by selecting Bar
Plot from the Plots menu shown in Figure 9-1. Select Year for the X-axis and the energy
quantities for the Y-axis in the New Plot Setup dialog. Then check the Side-by-side bar plot
option, as shown in Figure 9-21.
364 Chapter 9: Advanced Plotting
Click OK and enter Energy [Billion Btu] for the Y-axis label. Next, select Modify Plot from the
Plots menu or more simply, right-click anywhere within the plot rectangle to bring up the Modify
Plot dialog shown in Figure 9-22. Note that it is possible to select the ‘Side-by-side bar plot’
control in this dialog also, if it were not already selected in the Plot setup dialog in Figure 9-21.
Changes to the appearance of the bar plot can be made in this dialog. The fill type and color for
each variable can be specified. The spacing between the groups of bars can be changed using the
slider control in the Symbol box.
The completed plot is shown in Figure 9-23 after modifying the display of the Y-axis and adding
a legend to identify the bars.
Chapter 9: Advanced Plotting 365
Figure 9-22: Selecting a side-by-side bar plot in the Modify Plot dialog.
x 106
120
Residential Commercial Industrial Transportation Total
100
Energy [Billion Btu]
80
60
40
20
0
2005 2006 2007 2008 2009 2010 2011
Year
Figure 9-23: Completed Side-by-side bar plot
366 Chapter 9: Advanced Plotting
Plotting Dates
In addition to numerical data types with different formats, EES provides data types for dates,
time, and strings. Dates and times are stored internally as numbers and they can be plotted like
other numbers. For consistency with other programs, such as EXCEL, EES stores dates as the
number of days that have passed since December 30, 1899. Here it is shown how a plot with
date information can be constructed.
The data that are to be plotted have been copied from EXCEL and pasted into a Lookup table
name Energy Imbalance. (These data are provided in the plotting dates.ees file located in the
Examples folder.) Note that the Date column must initially be configured to hold dates. This is
done by right-clicking on the header cell for the Date column and selecting Properties from the
popup menu. Then select Date from the Style choice and one of the 10 date format.
Chapter 9: Advanced Plotting 367
The data can not be plotted in the usual fashion. The energy imbalances in columns 2 and 3 will
be plotted versus date, as shown. Note that the date format as it is to appear on the plot can be
specified.
-2
Energy Imbalance
-4
-6
-8
2016-04-29 2016-05-05 2016-05-11 2016-05-17 2016-05-23 2016-05-29
Date
368 Chapter 9: Advanced Plotting
The dates are relatively long and so it is advantageous to display them vertically or on an angle.
This can be accomplished by right-clicking the X-axis to bring up the Modify Axis dialog. Enter
the angle that the date will be displayed at. Note that the angle must be between -90 and 90.
The plot can be further improved by removing the Date label, adding a legend, and increasing the
size of the symbols. The completed plot appears below.
Chapter 9: Advanced Plotting 369
Polar Plots
EES allows the generation of a polar plot. A polar plot has circumferential and radial axes and it
is a convenient method for representing data in polar coordinates. For example, consider the
equation for a polar rose:
r = a cos ( k ) (9-2)
where a and k are constants, r is the radial location and is the angular position. Equation (9-2)
is entered in EES.
a=1
k=3
r=a*cos(k*theta)
A Parametric Table is generated and the variables theta and r are added to the table. The value of
theta is varied from 0 to 2 and the table is solved. Select New Plot Window from the Plots
menu and then select Polar Plot. Setup the polar plot with the variable theta as the
circumferential axis and the variable r as the radial axis. Be sure to select radians as the angular
units, as shown in Figure 9-24. The resulting polar plot is shown in Figure 9-25.
0.2
0.4
0.6
0.8
1
r
Figure 9-25: Polar plot.
The number of radial contours can be adjusted by specifying a value for the interval in Figure 9-
26(a). The position of the contour labels is controlled with the Angle parameter. Angle is
always entered in degrees and valid entries are from -90° to 90°. The radial contours will be
labeled along a radius with a constant circumferential value equal to the value entered for the
Angle.
Chapter 9: Advanced Plotting 371
Figure 9-26: Modify Axis Dialog for a) Radial and b) Circumferential axes of Polar Plots.
Click the Circumferential button to access the attributes of the circumferential axis. By default,
the circumferential direction increases in the counter-clockwise direction. This choice is not
suitable for wind maps and other applications. It can be changed to clockwise by checking the
Clockwise control. The location of zero for the circumferential axis can be changed from the
right side of the plot to the top by checking the Zero at top control.
The interval used for the x-axis of the plot will be the range divided by seven and rounded to the
nearest integer (using the Floor function in EES).
The values to plot will be generated within an array that includes N = 100 values. The value of
the argument (x) is varied from xmin to xmax in equal increments:
x =x +
( i 1) ( x x ) for i = 1..N (9-3)
i min
( N 1) max min
and the value of the Bessel function is evaluated at each value of x using the EES function
BesselJ.
372 Chapter 9: Advanced Plotting
The values in the Arrays Table are used to prepare a plot of J0[i] versus x[i] . Double click on the
plot and select Automatic Update so that the plot automatically changes if the data in the array
are changed. Double click on the x-axis of the plot in order to access the Modify Axis dialog.
Specify the minimum, maximum, and interval for the axis using the variables x_min, x_max, and
x_int, as shown in Figure 9-27.
Figure 9-27: Modify Axis dialog showing the limits and interval set using variables.
(a) (b)
Figure 9-28: Plot for (a) xmin = 0 and xmax = 6 and (b) xmin = 2 and xmax = 8
Chapter 9: Advanced Plotting 373
Change the values of the limits in the Equations Window to xmin = 2 and xmax= 8 :
The plot will be copied using the attributes that are specified in the Plot tab of the Preferences
dialog. To view or changes these preferences, select Preferences from the Options menu and
then select the Plot tab, shown in Figure 9-29, in order to adjust the format used to copy the plot
to the clipboard. The attributes that affect how the plot is copied appear in the Clipboard Copy
box at the bottom of the dialog. The plot can be copied in color or in black and white, depending
on whether the Copy in color check box is selected. The plot can be copied as a picture (i.e., an
enhanced metafile) and/or a high resolution bitmap. The resolution of the bitmap can be adjusted
from 100 dpi (dots per inch) to 1200 dpi. The picture option, which provides a set of instructions
to reproduce the plot, uses relatively little memory. A high resolution bitmap will produce a
higher quality image that is a more exact replica of what is seen on screen, but it uses more
memory. The differences are only visible when the plot is printed, as most screens do not
provide sufficient resolution to see the differences.
The plot can be saved in a file in a variety of formats and later imported into other applications.
Click the right mouse button on the appropriate tab in order to access the Plot Information dialog
shown in Figure 9-30.
Click the Save button in order to access the Save Plot dialog shown in Figure 9-31. This dialog
is primarily dedicated to determining where on your computer the plot file will be stored. The
plot can be saved as an enhanced metafile (.emf), bitmap (.bmp), jpeg (.jpg), tiff (.tif), or picture
(.wmf) file, depending on the selection of the file type made just below the file name edit box.
Plot Templates
You may spend a substantial amount of time formatting a plot and making it look just right. In
the Professional version of EES, your formatting preferences can be saved by selecting Save
Template in the Information dialog shown in Figure 9-30. To illustrate this feature, save the
formatting options used to generate a plot as the file template.ept (the file extension .ept stands
for EES plot template). An .ept file is a text file that can be opened in a text editor such as
Notepad and modified by the user. Now, duplicate a plot and adjust some of the formatting
options; for example, change the font of the axis labels and/or text items, the size of the plot, or
any other characteristic. Right-click on the tab for the duplicated plot and select Open Template
in the Information dialog. Navigate to the file template.ept that you saved previously and select
Open. Select OK and you should see that the plot format returns to its original style. This option
is particularly useful if you are writing a report in which every plot should have a uniform
format.
As an example, consider the temperature distribution in a semi-infinite body that has been
subjected to a pulse of energy at its surface at time zero. The solution to this problem is
available using the function SemiInf4 in the Heat Transfer application library that is included in
EES, as discussed in Section 12.9. The function SemiInf4 can be accessed by selecting Function
Info from the Options menu and then selecting the Heat Transfer radio button and Transient
Conduction from the associated drop down menu, as shown in Figure 9-33. Select Semi-Infinite
Body from the drop down menu in the lower part of the window and then scroll to the correct
solution, SemiInf4.
Chapter 9: Advanced Plotting 377
The calling protocol for the function SemiInf4 can be examined by selecting the Info button:
T=SemiInf4(T_i,E``,rho,c,alpha,x,t)
where T_i is the initial temperature, E`` is the surface energy per area, rho, c, and alpha are the
density, specific heat capacity, and thermal diffusivity of the material, respectively, x is the
position (relative to the surface), and t is the time (relative to the application of the pulse of
energy).
We will animate the solution to this problem for the case where the initial temperature is Ti = 300
K, the surface heat pulse is E" = 1x106 J/m2, the material properties are = 8933 kg/m3, c = 385
J/kg-K, and = 1.166x10-4 m2/s.
The temperature at each of these values of position and time is calculated using nested duplicate
loops in order to create the matrix of temperatures.
duplicate j=1,m
duplicate i=1,n
T[i,j]=SemiInf4(T_ini,E``,rho,c,alpha,x[i],time[j])
end
end
Plot each of the temperature arrays as a function of the position array in order to generate the plot
shown in Figure 9-35. All of the temperature arrays can be plotted at one time by selecting x[i]
from the X-axis list and all of the temperature arrays from the Y-axis list. You will need to click
on each temperature array to select it.
The Time Sequence Display option is available at the lower part of the dialog. Select Time
Sequence display and adjust the speed of the animation. Select Loop in order to replay the
animation each time it completes. Select OK and a control panel will appear on the upper left
corner of the plot that controls the time sequence display, as shown in Figure 9-37.
Figure 9-37: Plot showing the control panel for the time sequence display.
Each data series in the plot is assigned to a frame. Pressing the play button ( ) will activate
the time sequence display. The pause button ( ) stops the display at the current frame and
the stop button ( ) stops the display and resets it. The loop button ( ) causes the
display to loop after it completes.
Figure 9-38: Modify Plot dialog showing the time sequence display frames.
At the bottom of the dialog is an area labeled Time Sequence Display. Each plot overlay is
displayed in a separate frame. The plots can be displayed one at a time and then subsequently
removed if "Display if frame #" is set to = followed by the appropriate frame number, as shown
in Figure 9-38. Alternatively, the plots can be displayed one at a time and then persist if the
Display if frame # is set to >=. The frame numbers are set by default to the order in which the
plot overlays occur.
Figure 9-39: Format Text Item dialog showing the time series display.
Activate the time sequence display by selecting the play button on the control panel shown in
Figure 9-37 and you should see the text item appear during the last half of the animation. By
default, all plot objects and text items are set to display if frame >= 0 so that they persist during
the entire animation.
Making a Movie
In order to make a movie that can be played from other software (e.g., Windows Media Player),
it is necessary to save each frame of the plot as a separate image and then use some software
(e.g., Windows Movie Maker) to assemble the images. Right click on the plot tab. When the
Time Sequence display is enabled, the Save button in this dialog becomes the Movie button, as
shown in Figure 9-40.
Chapter 9: Advanced Plotting 383
Figure 9-40: Save each image of the time sequence by selecting the Movie button.
Click the Movie button and the Save Each Frame in a Separate File for a Movie dialog will
appear, as seen in Figure 9-41. It is best to create a new folder to hold all of the movie files.
Here the folder name is Movie. Enter a file name (e.g., frame) in the File Name box. In this
case, the file name extension is set to .emf, but it could be set .jpg, .tif, or .bmp. Click the Save
button and a separate .emf file will be generated for each frame; each file will be given the name
specified in the File Name box followed by _# where # is the sequential frame number.
Figure 9-41: Save Each Frame in a Separate File for a Movie dialog.
384 Chapter 9: Advanced Plotting
Each type of movie-making software has its own protocol for assembling frames into a movie.
In Windows Movie Maker, select Import pictures from the Capture Video heading and then
select each frame that was saved. Choose Options from the Tools menu and then select the
Advanced tab. Change the duration and transition times according to how fast you would like
the video to play, as shown in Figure 9-42.
Select all of the frames and drag them to the storyboard, as shown in Figure 9-43. Select the
play button above the storyboard to preview the movie. Finally, select Finish Movie and Save to
my computer in order to save the movie in a format that is playable by most software (e.g.,
Windows Media Player).
Chapter 9: Advanced Plotting 385
9.3Three-Dimensional Plots
EES provides the capability to plot a dependent variable as a function of two independent
variables in what are referred to as three-dimensional (or X-Y-Z) plots. EES can generate
several types of 3-D plots including contour plots, gradient plots, 3-D surface plots and 3-D point
points. These plots are discussed in this section in the context of the simple conduction problem
shown in Figure 9-44.
386 Chapter 9: Advanced Plotting
W=1m
Tx = 0 = 0 Tx = W = 0
Ty = 0 = Tb
Figure 9-44: Plate subjected to fixed base and edge temperatures.
The temperature in a plate varies only in the x- and y-directions (i.e., the top and bottom of the
plate are insulated). The plate is W = 1 m wide and extends infinitely into the y direction. The
base of the plate (at y = 0) is subjected to a fixed temperature, Tb = 1 K. The edges of the plate
(at x = 0 and x = W) are subjected to fixed temperature 0 K. The solution to this problem can be
obtained analytically using separation of variables as discussed in Nellis and Klein (2009):
2Tb 1+ cos ( i i x i y
sin
T= (9-4)
exp
)
i=1 (i W W
)
The first N = 100 terms of the solution are programmed in EES and used to compute the
temperature at x = 0.1 m and y = 0.1 m.
In three column form, the independent variables can be provided in any order and they do not
have to be located on a regular grid. The first step that EES will do internally is
interpolate/extrapolate the provided data to provide a suitable grid. To generate the data that will
be plotted, we will vary the independent variable x from 0 to 1 m in 21 discrete values. The
dependent variable y will be varied from 0 to 2 m in 41 discrete values. Therefore, the
Parametric Table must contain 21x41 = 861 rows. To populate the column containing x, right
click on the column header and select Alter Values to obtain the dialog shown in Figure 9-45(a).
Vary x from 0 to 1 m and select Repeat pattern every 21 rows, as shown.
To populate the column containing y, repeat the same process but vary y from 0 to 2 m and select
Apply pattern every 21 rows, as shown in Figure 9-45(b). If you examine your Parametric Table
you will find that the dependent variables form a 2-D grid over the computational domain 0 < x <
1 m and 0 < y < 2 m. Comment out the values of x and y that were previously entered in the
Equations Window:
{x=0.1 [m] "x-position"
y=0.1 [m] "y-position"}
and solve the table to obtain a set of data in three column format.
For this problem, select the variables x and y as the independent variables and T as the contour
variable. The minimum and maximum values of the contours and the interval between contours
can be defined. The data in the columns must be interpolated/extrapolated by the internal
plotting algorithms so as to provide values of the independent variable over the entire selected
range of the dependent variables at relatively fine intervals. This process will be done using
either Radial basis functions or Bi-quadratic polynomials depending on the selection from the
drop-down menu in the lower right corner of the dialog. The grid size is controlled by the
resolution slider. The smoothing slider is useful for experimental data or for a very sparse data
set where outliers or large gaps may be present; normally the smoothing slider should be set to
zero. Select OK in order to generate the contour plot shown in Figure 9-47.
Figure 9-47: Isometric lines contour plot showing temperature as a function of x and y.
Chapter 9: Advanced Plotting 389
1.5
1
1.25 0.9
0.8
1 0.7
y-position [m]
0.6
0.75 0.5
0.4
0.3
0.5
0.2
0.1
0.25
0
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x-position [m]
(a)
1.5
1
1.25 0.9
0.8
1 0.7
y-position [m]
0.6
0.75 0.5
0.4
0.3
0.5
0.2
0.1
0.25
0
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x-position [m]
(b)
Figure 9-48: Color band contour plot using (a) full spectrum color and (b) blue to red color.
Three color schemes are available. The color scheme shown in Figure 9-48 is called the Full
Spectrum color scheme and it uses all of the colors of the rainbow. An alternative color scheme
uses colors ranging from blue to red. In some cases, this color scheme is more easily associated
with a value. The third option is gray scale. To change the color scheme, click the right mouse
button anywhere within the plot rectangle in order to display the Modify Plot dialog shown in
Figure 9-49(a). The color scheme can be changed to blue to red by unchecking the Full spectrum
check box. Controls are also provided to hide or show the legend and to superimpose gradient
arrows, which are discussed in the following section.
390 Chapter 9: Advanced Plotting
Figure 9-49: Modify Plot dialog for (a) a color band contour plot and (b) a gradient plot
Gradient Plot
If Gradient plot is selected from the list in the X-Y-Z Plot Setup dialog in Figure 9-46 then a
Color Band plot is generated that includes arrows indicating the direction and magnitude of the
gradient of the independent variable, as shown in Figure 9-50. The frequency and maximum
length of the arrows, as well as the size of the arrowhead, can be modified by right-clicking on
the plot. This action will bring up the Modify Plot diagram shown in Figure 9-49(b).
1.5
1
1.25 0.9
0.8
1 0.7
y-position [m]
0.6
0.75 0.5
0.4
0.3
0.5
0.2
0.1
0.25
0
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x-position [m]
Figure 9-50: Gradient plot.
Chapter 9: Advanced Plotting 391
A 3-D surface plot can be created using the temperature as a function of x and y position data
generated in the previous section. Select New Plot and then X-Y-Z from the Plots menu. Select
3-D Surface from the list in the X-Y-Z Plot Setup dialog shown in Figure 9-46 in order to display
a three-dimensional, rotatable projection of the surface. The resulting plot is shown in Figure 9-
51.
The control panel shown in Figure 9-52 is provided at the bottom of the plot window. If the
panel is not visible, click the right mouse button anywhere in the plot and it will appear. The
same action will make it disappear. Alternatively, you can use the Show/Hide Tool Bar menu
item in the Plots menu to control the visibility of the control panel.
392 Chapter 9: Advanced Plotting
The Axes check box controls the visibility of the three axis lines. This check box has three
positions that are activated by clicking the box. If it is not checked, the axis lines are not visible.
If it is checked with a gray check, the axis lines are drawn without labels, as shown in Figure 9-
51. Clicking the box one more time will show the axis lines with axis labels. The legend
displayed at the left of the plot window in Figure 9-51 can be made visible or hidden with the
Legend check box. The Perspective check box, if selected, distorts the display so that objects
that are further back appear smaller. The Resolution slider controls the size of the polygons used
to form the surface plot. High resolution (slider bar to the right) results in a crisp plot, but
rendering and rotating may be slower
The Color check box has three positions that engage with a mouse click. The three possibilities
are black and white (no check); color display with colors ranging from blue to red (gray check);
and color display with full spectrum color (black check). Normally, the color (or shade of gray
for black and white plots) is a visual indicator of the Z-axis variable. However, it is possible to
have the color provide a totally different piece of information, which effectively provides a 4-D
plot.
To demonstrate this capability, we will assign the color of the surface plot to a variable C, which
is included in the equations used to generate T as a function of x and y. The variable C is set to 0
if the temperature is less than 0.5 K and 1 if it is greater than 1 K.
C=if(T,0.5,0,0,1)
Add a fourth column for the variable C to the Parametric table and resolve the table. Select 3-D
Surface from the list in the X-Y-Z Plot Setup dialog in Figure 9-46, as was done before. Select T
to be the Z-axis variable. Next click on Z-Axis Variable located above the Z-axis list. It will
change to Color Variable and the list will be displayed in yellow. Note that if you click Color
Variable then it will return the display to Z-Axis Variable. Select variable C, as shown in Figure
9-53, and the click the OK button. The plot shown in Figure 9-54 will be generated and it will
indicate with its color the areas in which the temperature is greater than 0.5 K. Note that Figure
9-54 shows colors that indicate values that are between 0 and 1 even though all of the original
data for variable C were either 0 or 1. This effect occurs because EES must grid the data to
create the plot and it uses interpolative procedures to do so. The effect of interpolated variables
can be minimized using the color slider control shown at the left of Figure 9-52.
The Gridlines and Size box provides slider controls to separately scale the X, Y and Z axes.
Moving the slider to the right increases the scale factor for the selected axis. The slider can be
moved with the mouse or with the left/right arrow keys. The check boxes for X and Y control
the visibility of surface grid lines. The vertical slider scales the X, Y, and Z directions
uniformly. Moving the slider down increases the apparent size of the plot in the window. This
Chapter 9: Advanced Plotting 393
slider can also be controlled with the up/down arrow keys. The lower and upper limits of the
plotting range for the surface can be changed by right-clicking on the slider control for the X and
Y axes; doing so will bring up a small dialog in which you can enter the lower and upper limit
for which the surface plot will be drawn.
Figure 9-53: X-Y-Z Plot Setup dialog with the color variable assigned to variable C.
Figure 9-54: 3-D plot of T as a function of x and y. The color is set to variable C.
394 Chapter 9: Advanced Plotting
The Grid Position box provides controls to display X, Y and Z orthogonal grids. The visibility
of these grids is controlled with the checkboxes. For example, the grid in the YZ plane will be
visible if the checkbox preceding X is checked. The grid can be moved to any position within the
range of allowable values using the slider control. The slider controls can be controlled using the
mouse or the left/right arrow keys. The current location of the grid is shown in the box to the
right of the slider. A value can be directly entered into this box in order to move the grid to the
specified value. By default, the grid spans the entire range for each variable. However, this
default can be changed. For example, right click on the slider for the X grid. A small dialog will
appear that allows the minimum and maximum X values for the grid to be changed. Change the
default values of 0 and 1 to 0.5 and 1, as shown in Figure 9-55. Click the OK button and the 3-D
surface plot will be redrawn as shown in Figure 9-56
Figure 9-56: 3-D plot of T as a function of x and y with the X grid drawn between 0.5 and 1.
Chapter 9: Advanced Plotting 395
The Axis Scale and Labels box provides controls to label the axes. If the Axis scale values
check box is checked, the lower and upper limits of the scales for the X, Y, and Z axes will be
displayed. If the Axis variable names check box is checked, the names of the variables plotted
on the X, Y and Z axes will be displayed. Clicking the Isometric button will orient the axes in an
isometric manner that best shows the axis scale values and axis names. Clicking the Top button
will rotate the display so that the view is of the X-Y plane looking down the positive Z-axis
towards the origin. The Front button presents a Y-Z plane viewed along the positive X axis. The
Side button displays the X-Z plane from the positive Y axis.
The tool bar provides buttons to place text, lines, boxes, and circles on the plot in the same
manner as for X-Y plots. An align button is also provided. The help button accesses the online
help page with information on the use of the control panel.
Holding the Shift and Ctrl keys down will cause the 3-D coordinates to be displayed in the
window caption, provided that the X and Y-axis grids are visible. The information displayed is
the current locations of the X and Y grids, followed by the value of Z on the surface for the
specified values X and Y. If the color corresponds to a variable other than Z, its value on the
surface at the specified X and Y coordinates is also shown. If the X and Y grids are moved using
the mouse to manipulate the slider control while the Shift and Ctrl keys are held down, the
information in the window caption will be automatically updated. This option provides the most
convenient way to accurately read the 3-D coordinates.
duplicate j=1,m
396 Chapter 9: Advanced Plotting
duplicate i=1,n
T[i,j]=SemiInf4(T_ini,E``,rho,c,alpha,x[i],time[j])
end
end
Running this simulation will result in an Arrays Table that includes 20 columns corresponding to
the spatial temperature distribution at each of the simulated times in addition to the column time
that includes the times simulated (3 s to 60 s) and the column x that includes the locations
simulated (0 m to 0.25 m). Select the Sort button at the upper right of the Arrays Table window
and the temperature information will be placed in rows 1 through 41 of columns 1 through 20.
Select New Plot Window from the Plots Window and then X-Y-Z plot. Select 2-D table data
under type in order to access the dialog shown in Figure 9-57.
Figure 9-57: X-Y-Z Plot Setup dialog using 2-D table data.
Select 3-D plot and then specify the columns (1-20) and rows (1-41) that contain the data.
Specify the range for the X-Axis (3 s to 60 s) and the range for the Y-Axis (0 m to 0.25 m). The
resulting plot is shown in Figure 9-58. Note that text to label the axes has been added using the
text tool in the control panel in the same manner as for X-Y plots.
Chapter 9: Advanced Plotting 397
$UnitSystem SI K kPa kJ
$TabStops 0.2 3.5 in
N=100 "number of data point"
T_low=300 [K] "lowest temperature considered"
T_c=T_crit(water) "critical temperature"
duplicate i=1, N
T[i]=T_low+(T_c-T_low)*i/N "temperatures between T_low and T_c"
P[i]=pressure(Water,T=T[i],x=1) "saturation pressure"
vg[i]=volume(Water,T=T[i],x=1) "specific volume of saturated vapor"
vf[i]=volume(Water,T=T[i],x=0) "specific volume of saturated liquid"
lvg[i]=ln(vg[i]) "natural log of saturated vapor volume"
lvf[i]=ln(vf[i]) "natural log of saturated liquid volume"
lnP[i]=ln(P[i]) "natural log of pressure"
end
398 Chapter 9: Advanced Plotting
Solve the program (select F2) and the select New Plot Window and then X-Y-Z plot from the
Plots menu. Select 3-D Points as the plot type and choose the X, Y, and Z-Axis variables as
indicated in Figure 9-59. The limits for the Z-Axis Variable (log of the specific volume) are
selected so that both saturated liquid and vapor will be displayed on the plot.
Figure 9-59: Plot Setup for a 3-D Points plot of the vapor dome for water.
Click OK and the plot will be generated showing the saturated vapor line in 3-D space. Next,
select Overlay Plot from the Plots menu. Select the arrays T[i] and lnP[i] for the X-axis and Y-axis
variables, as before. Select lvg[i] for the Z-axis variable. Change the color to red so that the
saturated liquid line is distinct from the saturated vapor line. Click OK. The plot will appear as
shown in Figure 9-59. The plot can be rotated to allow views from any direction. The control
panel that appears below the plot operates in the same manner as for the 3-D surface plots. One
difference is that the control panel provides a Modify Plot button (see Figure 9-61) that allows
the color, symbol, symbol size, line type and other information to be modified for any of the
overlaid 3-D plots. It is also possible to delete a plot within the Modify-Plot dialog.
Chapter 9: Advanced Plotting 399
Figure 9-60: 3-D plot of ln(specific volume) for saturated liquid and vapor as a function of temperature and
ln(pressure).
It is also possible to overlay 3-D point plots on a 3-D surface plot. The 3-D surface plot must be
created first. To illustrate, we will overlay the saturation specific volume plots in Figure 9-60 on
a surface plot of temperature, ln(pressure) and ln(specific volume). Add the following equations
to the Equations Window.
Create a Parametric Table with 400 runs and columns for the variables T, P, v, lnP and lnv. Fill
the Parametric Table with temperature data ranging from 300 to 700 K using the Repeat pattern
every options for 20 rows, as shown in Figure 9-62(a). Fill in the pressure column with values
between 1 and 25000 kPa. Use the Last (log) option to space the pressures logarithmically and
Apply the pattern every 20 rows, as shown in Figure 9-62(b). Solve the Parametric Table (using
the F3 key).
400 Chapter 9: Advanced Plotting
(a) (b)
Figure 9-62: Filling the Parametric table with (a) temperature and (b) pressure data for the 3-D plot.
Select New Plot Window and then X-Y-Z plot from the Plots menu. Select 3-D Surface as the
plot type and choose the X, Y, and Z Axis variables to be T, lnP and lnv, respectively. Select OK
and then overlay the saturated specific vapor volume and saturated liquid specific volume data
from the Arrays Table onto this plot, following the same procedure used to create Figure 9-60.
The plot will appear as shown in Figure 9-63. The saturated liquid line shown in red is partially
obscured by the surface plot, but it can be viewed as the plot is rotated.
Figure 9-63: 3-D plot of ln(specific volume) as a function of temperature and ln(pressure)
Chapter 9: Advanced Plotting 401
1. Select the Plot Thumbnails menu command, which appears at the bottom of the Plots menu
as shown in Figure 9-65.
2. From the Windows menu, select Plot Windows. A fly-out menu will appear with Plot
Thumbnails at the top, as seen in Select the Plot Thumbnails menu command, which appears
at the bottom of the Plots menu as shown in Figure 9-66.
Figure 9-66: Windows menu showing the Plot Thumbnails menu command
3. The button bar below the main menu provides a button to access the plot windows. This
button appears as . Hold the Ctrl key down or right-click on this button to make the Plot
Thumbnails window appear.
Select a plot in the Plot Thumbnails window by using the arrow keys to navigate from plot to
plot. The status bar at the bottom of the window shows the plot tab position, the plot tab caption
and the plot description (which can be entered or edited by right-clicking on the plot window tab)
for the selected plot. Click the left or right mouse button on a plot to open and move the focus to
the Plot window for that plot. The slider control at the lower right of the Plot Thumbnails
window controls the size of the thumbnails. Sliding it to the right enlarges the thumbnails and
sliding it to the left reduces the size. Resize the Plot Thumbsnails window to make the display
appear as desired.
References
Nellis, G.F. and S.A. Klein, Heat Transfer, Cambridge University Press, New York, (2009).
10 SUBPROGRAMS and MODULES
Subprograms are internal EES programs that can be called from the main EES program or from
other subprograms. Modules are similar to subprograms, but they are implemented in a manner
that results in the equations in the module being integrated and solved together with the
equations in the Equations Window. Most problems can be successfully solved using either a
subprogram or a module, but the convergence properties of the two approaches differ. The
format of a module or subprogram is similar to that of an internal procedure, discussed in
Chapter 3. The module or subprogram is supplied with inputs and it calculates and returns
outputs. Like a procedure, a module or subprogram statement can use a colon in the argument
list in order to separate inputs from outputs; however, the colon is optional for a module or
subprogram (although it is recommended). This chapter describes how modules and subprogram
can be effectively used within an EES program.
10.1 Subprograms
A subprogram is a stand-alone EES program that can be called from the main EES program. It
can also be called from a function, procedure or another subprogram. Subprograms are not
recursive; i.e., they cannot call themselves.
Format of a Subprogram
The format of a subprogram is shown below3:
Equation(s) - note that these equations must be sufficient to compute the outputs given the inputs
End
The format of a subprogram is similar to that of a procedure, as described in Section 3.3. Both
types of code segments must be entered in the Equations Window before the first equation in the
main EES program appears and both must provide an argument list that includes the input and
output variables. However, there are significant differences between a subprogram and
procedure. The major difference is that the statements that appear in a subprogram are equations
like those that are used in the main EES program. Therefore, the equations can be entered in any
order and it is not necessary to isolate the variable that is being determined on the left side of the
equal sign. The statements that appear within a procedure are, in contrast, assignment statements
as discussed in Section 3.1. Logic constructs such as If-Then-Else and Repeat-Until statements can
be used in a procedure but not within a subprogram.
3
Note that the list separator is a semicolon (instead of a comma) if the computer is configured to operate in the
European system in which the decimal separator is a comma.
404 Chapter 10: Subprograms and Modules
Each subprogram has its own variable information page in the Variable Information dialog and
its own tab in the Solution Window. Subprograms can use array variables. Each subprogram
will have its own tab in the Arrays Table window if the $Arrays On directive appears in the
subprogram. Each subprogram can have up to 6,000 equations in the Commercial version of
EES, 12,000 equations in the Professional version, and 24,000 in the 64-bit Professional version.
The argument list for a subprogram normally includes a colon to separate inputs from outputs;
however, the colon is optional. If a colon is not provided then EES will determine the required
number of inputs from examination of the number of equations in the subprogram. Inputs
always appear before outputs in the argument list, regardless of whether or not a colon is used.
Variables that are defined as being inputs differ from those defined as being outputs in the
manner in which the guess values and limits are assigned, as explained subsequently. The input-
output designation of the arguments does not restrict the use of a subprogram in that it is usually
possible to specify the values of one or more outputs so as to calculate a corresponding number
of inputs.
Calling a Subprogram
A subprogram may be called from the main EES program, a function, a procedure or another
subprogram using the Call statement. The Call statement for a subprogram has the same format as
for a procedure. For example:
Note that if the subprogram header employs a colon to separate inputs and outputs, the Call
statement must also use the colon. Use of the colon is recommended unless the subprogram is
intended to have a varying number of inputs. The number and type (string or numerical) of the
variables passed to the subprogram must exactly match the number and type declared in the
subprogram header statement. Variable information can also be passed into the subprogram
from the main EES program using a $Common directive, as described in Section 14.3.
Note that is it is not necessary to provide all of the outputs in the Call statement provided list
separators are used so that the total number of outputs is evident.
Subprogram Execution
When a Call statement for a subprogram is executed, EES clears its variable space, loads the
subprogram and attempts to solve the equations in the subprogram. The first thing EES will do
is to check to see if the number of equations in the subprogram plus the number of inputs to the
subprogram is equal to the total number of variables. If this is not true then the problem cannot
be solved.
Consider as a simple example, the following subprogram with one input (X) and two outputs (Y
and Z). The subprogram consists of a single equation:
X = 2Y + 3 Z (10-1)
Subprogram DOF(X: Y, Z)
X=2*Y+3*Z
end
Chapter 10: Subprograms and Modules 405
When EES attempts to solve this subprogram it will realize that there are three variables (X, Y,
and Z) but the sum of the number of inputs (1) and the number of equations (1) is only two;
therefore, the problem is under-specified. For example, enter the equations:
A=5
Call DOF(A: B, C)
in the Equations Window. The equations in the subprogram cannot be solved and therefore the
error message shown in Figure 10-1 is displayed.
Figure 10-1: Error message resulting from trying to solve the under-specified problem.
X 2 =Y2 + Z2 (10-2)
Subprogram DOF(X: Y, Z)
X=2*Y+3*Z
X^2=Y^2+Z^2
end
A=5
Call DOF(A: B, C)
then the problem will solve, returning the values of B and C to the Main program.
The Residuals Window will also provide information for the equations in the subprogram, as
seen in Figure 10-3. In this case, the Residuals window shows that variables Y and Z were
determined simultaneously using the two equations in the subprogram. The variable X is an
input whereas the variables Y and Z are outputs and are thus shown in bold. The value of X and
the two equations in the Subprogram are used to solve for the values of Y and Z.
One of the advantages of a subprogram is that it can be called multiple times. Another is that the
values of one or more of the outputs can be specified in order to calculate one or more inputs.
For example, we could add another call to the subprogram DOF at the bottom of the Equations
Window:
Subprogram dof(X: Y, Z)
X=2*Y+3*Z
X^2=Y^2+Z^2
End
A=5
Call dof(A: B, C)
B2=6
Call dof(A2: B2, C2)
Note that in the second call to the subprogram DOF the value of B2 is specified even though it is
still considered to be an output of the subprogram. EES will automatically adjust the value of the
variable A2 (which is the input to the subprogram) and repeatedly call the subprogram DOF until
the calculated value of B2 is equal to the specified value (6). With the two Call statements in the
program, the values of variables B, C, A2, and C2 will all be determined, as shown in the Solution
Window for the Main program, Figure 10-4. The Solution and Residuals Window for the
subprogram DOF will only show the results for the last call to the subprogram.
Chapter 10: Subprograms and Modules 407
Figure 10-4: Solution Window showing results for the Main program
The equations in the subprogram DOF are non-linear and thus they can have more than one
solution. The solution that results when B2 in the main program (and therefore Y in the
subprogram DOF) is set to 6 is shown in Figure 10-4: A2 = 6.294 in the main program (and X =
6.294 in the subprogram DOF). However, what if you knew that the variable A2 in the Main
program (and therefore the variable X in subprogram DOF) must have a negative value? In this
case, it seems logical to try to set the guess value for the variable X in the subprogram DOF to a
negative value and also constrain it to have an upper limit of zero using the Variable Information
window. This situation illustrates the distinction between inputs and outputs to a subprogram.
The guess value and limits of the inputs to a subprogram assume the values that are set for those
parameters in the calling program and therefore these values cannot be adjusted using the
Variable Information dialog for the subprogram. Figure 10-5 illustrates the Variable Information
dialog for the subprogram DOF; notice that the word Input is displayed in gray for the guess
value and lower/upper limit fields for the input variable X. These fields are disabled.
In order to limit the value of A2 (and therefore the value of X during the second call to DOF) to a
negative value, the guess value and limits of the variable A2 in the calling program must be set.
In this example, the calling program is the main program and the Variable Information dialog for
408 Chapter 10: Subprograms and Modules
the main program is shown in Figure 10-6 with the guess value upper limit of A2 set to -1 and
zero, respectively. After this change is made, solving will result in A2 = -9.294, and C2 = -7.098.
Figure 10-6: Variable Information dialog for variables in the Main program.
The manner in which the Integral function is implemented places a number of restrictions on the
use of integrals within the main program. For example, it is not possible to have two or more
integrals that use the same integration variable with different limits in the main program. It is
not possible to directly determine the limit of an integral that provides a specified value of the
integrated value. Finally, EES may not be able to solve problems efficiently when two or more
Integral functions are used with different integration variables. These limitations can be
overcome by using subprograms to implement the Integral function.
As an example, we will approximate the pressure of a fluid (P) as a function of its specific
volume (v) and temperature (T) using the Peng-Robinson equation of state, which is given in Eq.
(10-3). (See Klein and Nellis (2011) for more information about this and other equations of
state.)
RT a
P= (10-3)
( v - b) v ( v + b ) + b ( v - b)
For this fluid, the ideal gas constant is R = 188.9 J/kg-K and the constants in Eq. (10-3) are a =
70.89 N-m4/kg2 and b = 0.0006059 m3/kg. We wish to determine the work per unit mass of fluid
that is required to isothermally compress from P1 = 1x105 Pa to P2 = 5x106 Pa at T = 350 K. We
also would like to determine the work per unit mass that is required to isothermally compress the
fluid from P2 to P3 = 1x107 Pa at the same temperature. The inputs are entered in EES:
The specific volumes of the fluid at states 1, 2, and 3 are evaluated using Eq. (10-3).
RT a (10-4)
P1 = ( v - b ) v ( v + b) + b ( v - b)
1 1 1 1
RT a (10-5)
P2 = ( v - b ) v ( v + b) + b ( v - b)
2 2 2 2
RT a (10-6)
P3 = ( v - b ) v (v + b) + b (v -b)
3 3 3 3
The compression work per unit mass required to go from state 1 to state 2 is given by the
integral:
+
W12 = 2 P dv (10-7)
m v1
where the integrand, P, is evaluated at T = 350 K and the integration variable is v. The integral
in Eq. (10-7) is evaluated using the Integral command.
The work per unit mass required for the compression process is W12/m = -258,370 J/kg; the
negative sign indicates that work is required for this process.
Next, we wish to determine the additional work that is required to compress the fluid from P2 to
P3 isothermally at T.
+
W23 = 3 P dv (10-8)
m v2
410 Chapter 10: Subprograms and Modules
It is tempting to solve Eq. (10-8) using another numerical integration, this time with limits v2 and
v3:
Trying to solve these equations will result in the error message shown in Figure 10-7. The
equation set fails to solve because the two Integral statements use the same integration variable
(v) with different limits.
Figure 10-7: Error message that results when two integrals with the same integration variable are evaluated
using different limits.
A solution to this problem could be obtained by introducing a second integration variable (vx)
and relating a second integrand (Px) to vx using the Peng-Robinson equation:
This problem could be solved more elegantly using subprograms. A subprogram named PR is
developed in order to solve the Peng-Robinson equation of state with specific volume and
temperature (v and T) provided as inputs and pressure (P) returned as the output:
Subprogram PR(v,T: P)
R=188.9 [J/kg-K] "gas constant for fluid"
a=70.89 [N-m^4/kg^2] "Peng-Robinson parameter a"
b=0.0006059 [m^3/kg] "Peng-Robinson parameter b"
P=R*T/(v-b)-a/(v*(v+b)+b*(v-b)) "Peng-Robinson equation of state"
end
A second subprogram named W_c calculates the work per unit mass associated with the
isothermal compression process. The inputs to the subprogram W_c are the temperature, initial
pressure, and final pressure (T, P_i, and P_f). The output is the work per unit mass (W).
The specific volumes at the beginning and end of the compression process are computed by
calling the Subprogram PR.
The compression work per unit mass required to go the initial to the final state is given by the
integral in Eq. (10-7) where the integrand, P, is evaluated at T and the integration variable v
using the subprogram PR. The integral is evaluated using the Integral command.
"Inputs"
T=350 [K] "temperature during compression"
P[1]=1e5 [Pa] "pressure at state 1"
P[2]=5e6 [Pa] "pressure at state 2"
P[3]=1e7 [Pa] "pressure at state 3"
The work per unit mass associated with the compression from states 1 to 2 (W12) and from states
2 to 3 (W23) are both obtained using the subprogram W_c.
When you attempt to solve these equations, you will likely receive the error message in Figure
10-8.
Figure 10-8: Error message when solving without first entering limits for specific volume.
It is necessary to specify guess values and/or limits on some of the variables in order to solve this
problem. The Residuals Window is shown in Figure 10-9(a) and the Solution Window for the
subprogram PR is shown in Figure 10-9(b).
412 Chapter 10: Subprograms and Modules
(a)
(b)
Figure 10-9: (a) Residuals Window and (b) Solution Window for the subprogram PR.
Notice that the Residuals Window shows that the pressure in subprogram PR is not solved to
within tolerance and the Solution Window shows that the specific volume in the last call to the
PR subprogram is a large negative number. Clearly this is not a physically possible solution. It
is necessary to place a lower limit of zero on variable v in the subprogram PR. Select Variable
Info from the Options menu and then use the drop-down list in the top center of the dialog to
select the variable information for subprogram PR, as shown in Figure 10-10.
Chapter 10: Subprograms and Modules 413
The Variable Information Window shows that the variable v is an input to subprogram PR.
Therefore, we cannot set the guess value or limits for this variable because they are controlled by
the calling program. The calling program in this case is subprogram W_c. Use the drop-down
list to display the variable information for subprogram W_c, as shown in Figure 10-11.
Notice in Figure 10-11 that the variables v, v_i, and v_f are not inputs and therefore it is possible
to adjust their guess values and bounds. Enter lower bounds of zero for the variables v, v_i and
v_f. Although it is unnecessary, we can also enter a better guess value and lower bound for the
variable P. The lowest possible value for P is P_i so this value is used as the guess value and
lower limit. Click the OK button and then solve the equations. Both integrals will be now be
evaluated without problem.
+Y dY = 33 (10-9)
2
Because EES solves implicit equations iteratively, it would seem like Eq. (10-9) should be
relatively easy to solve directly using the equation:
However, solving will lead to the error message shown in Figure 10-12.
Figure 10-12: Error message associated with attempting to solve for the limits of an integral.
EES is not able to determine the derivative of the residual of the Integral command with respect
to variable a, and therefore it cannot solve this problem numerically.
It is possible to determine the limit of the integral using a subprogram. A subprogram named
Limit is developed that takes as its input the value of a and provides as its output the integrated
value, X:
a
+Y dY = X (10-10)
2
Subprogram Limit(a: X)
Integral(Y^2,Y,0,a)=X
End
Subprogram Limit is called from the main EES program by specifying the output (X = 33) and
allowing EES to iterate in order to identify the associated value of the input variable a.
When the Solve command is applied, EES will iteratively call subprogram Limit with different
values of a until the value of a that results in an integrated value of X = 33 is found. The value
identified by EES, a = 4.626, agrees with the analytical solution of 3 99 .
Note that the calculation would fail to solve if the order of the arguments in subprogram Limit
was reversed. As shown above, a is an input to subprogram Limit and its value is adjusted in the
calling program. If X were the input, then the variable a would be considered an output and the
subprogram Limit would then try to adjust its value in order to solve the equation set; this
situation would result in the same error message that is shown in Figure 10-12.
Chapter 10: Subprograms and Modules 415
10.2Modules
A module serves the same purpose as a subprogram. Both code segments provide a means to
compartmentalize a set of equations within an EES program and both use equations rather than
assignment statements. The equations can be entered in any order in implicit form, just as they
can within the main section of an EES program. Because they use equations, neither
subprograms nor modules can directly use logic statements, such as If-Then-Else or Repeat-Until
constructs. Subprograms and modules are both accessed using the Call statement.
Module Execution
The difference between subprograms and modules is subtle and is related to how their equations
are solved. The solution process will be demonstrated with the simple program shown below.
Note that this is exactly the same program that was used to demonstrate subprograms in Section
10.1, except that the Subprogram keyword has been changed to Module.
Module DOF(X: Y, Z)
X=2*Y+3*Z
X^2=Y^2+Z^2
end
A=5
Call DOF(A: B, C)
B2=6
Call DOF(A2: B2, C2)
As noted in Section 10.1, when a Call statement for a subprogram is executed, EES clears its
variable space, loads the subprogram and then solves the equation set contained in the
subprogram. When the calculations in the subprogram are completed, EES will reload all of the
information that was in memory before the subprogram was called and proceed with the solution
process.
The process is very different when a module is called. EES compiles all of the equations in the
Equations Window before it attempts to solve them. When EES encounters a Call statement for a
module, it transparently grafts the equation set associated with the module into the equations in
the main EES program. The steps necessary for this process are as follows. First, every variable
in the module, including each input and output variable in the module statement, is renamed with
a unique qualifier that EES can recognize. In the example above, the variables within the first
call to module DOF are renamed DOF\1.X, DOF\1.Y, and DOF\1.Z. Then EES adds one equation
for each input that sets the value of the input parameter in the calling program to the value in the
module. In the example above, this process is equivalent to writing:
DOF\1.X = A
for the first call to the module. All of the equations in the module, with their renamed variables,
are merged with the equations in the main EES program. For this example, the first call to the
module will result in:
416 Chapter 10: Subprograms and Modules
DOF\1.X=2*DOF\1.Y+3*DOF\1.Z
DOF\1.X^2=DOF\1.Y^2+DOF\1.Z^2
Finally, EES adds one equation for each output that sets the value of the output variable in the
module to the corresponding EES variable in the argument list.
DOF\1.Y = B
DOF\1.Z = C
If the module is called a second time then the process described above is repeated, but with a
different qualifier for the variable names in the module. The second call to the module in this
example will lead, internally, to:
DOF\2.X = A2
DOF\2.X=2*DOF\2.Y+3*DOF\2.Z
DOF\2.X^2=DOF\2.Y^2+DOF\2.Z^2
DOF\2.Y = B2
DOF\2.Z = C2
The net effect is that a copy of all of the equations in the module is merged into the main EES
program each time a Call statement to a module is encountered. Solving this example is therefore
equivalent to solving:
A=5
DOF\1.X = A
DOF\1.X=2*DOF\1.Y+3*DOF\1.Z
DOF\1.X^2=DOF\1.Y^2+DOF\1.Z^2
DOF\1.Y = B
DOF\1.Z = C
B2=6
DOF\2.X = A2
DOF\2.X=2*DOF\2.Y+3*DOF\2.Z
DOF\2.X^2=DOF\2.Y^2+DOF\2.Z^2
DOF\2.Y = B2
DOF\2.Z = C2
EES currently allows up to 6,000 equations in the Commercial version,12,000 in the Professional
version, and 24,000 in the 64-bit Professional version so rather large problems can be developed
in this manner. EES then uses its efficient blocking techniques to reorganize all of the equations
for an optimal solution.
Chapter 10: Subprograms and Modules 417
Figure 10-13: Solution window showing the local results for both calls to the module DOF.
Figure 10-14: Residuals Window showing the order in which the equations are called.
Figure 10-14 shows how the module statements are included with equations in the Main program
and blocked together with these equations. Equations from a module are identified with the
module name followed by a backslash and then the call index number. For example, the
equation:
in Block 1 originated from the first call to module DOF and it was used to determine the variables
DOF\1.Y and DOF\1.Z. The equation:
DOF\2: X=2*Y+3* Z
in Block 4 originated from the second call to module DOF and it was used to determine the
variables DOF\2.X and DOF\2.Z.
enabled in the main program in order to use them in a subprogram. Complex numbers can
not be used in modules.
7. Subprograms and modules can both be stored as library files, just like internal functions and
procedures, as described in Chapter 11. However, it is recommended that subprograms,
rather than modules, be used for library files. The equations in modules are integrated with
those in the Main program and the combined set of equations may not always solve as
expected, depending on the equations contained in the user’s program. The subprogram
equations are solved separately, providing some isolation from the main program.
8. Both subprograms and modules can significantly increase the capabilities of your EES
program.
References
Klein, S.A. and Nellis, G.F., Thermodynamics, Cambridge University Press, New York, (2011).
421
Internal functions and procedures are EES code units that are composed of assignment
statements rather than equations, as described in Chapter 3. The assignment statements used in
functions and procedures are similar to those used in most programming languages.
Subprograms and modules are callable code units that use equations, like those used in the main
EES program, as described in Chapter 10. EES allows files containing one or more functions,
procedures, and/or subprograms to be saved as library files with a .lib file name extension. The
64-bit version identifies library files with a .lib64 file name extension. These files can be loaded
manually or automatically when EES is started. The code units in these files operate just like the
built-in functions in EES and can therefore be accessed conveniently and transparently by the
user. Online help files can be prepared in several formats and associated with the library files.
The library file concept is among the most powerful features of EES because it allows the user to
easily write customized and reusable code for personal use or for use by others. Library files can
also be written in compiled languages, such as C++ or FORTRAN. These library files are called
external library files and they are described in Chapter 19.
The key to making a code unit reusable is to save it in a manner in which it can later be used
easily by other EES programs. Of course, it would be possible to simply open a previously
saved EES program, copy the code unit of interest, and then paste it into another EES program.
However, aside from being somewhat inconvenient, this manner of moving a code unit from one
EES program to another would not copy the variable information, such as the guess values,
limits, display format and units associated with each variable. A much better alternative is to
save the EES file containing the code unit of interest as a library file having a .lib/.lib64 file
name extension. Library files save the information in the Equations Window as well as any
associated variable information.
422 Chapter 11: Internal Library Files
EES does not provide a built-in function for specific exergy. Therefore, we will write a general
function that returns specific exergy as a function of temperature and pressure. To be useful, our
function must work in any unit system and for any fluid in the EES database. The name of the
function is Exergy and it is declared according to:
The inputs to the function include the fluid name (in the string F$), the temperature, pressure,
velocity, and elevation of the fluid (T, P, Vel, and z), and the temperature and pressure of the dead
state (T_o and P_o). The Exergy function will use the built-in property functions that are
described in Chapter 4.
The strings T$ and P$ will contain the units for temperature and pressure that are consistent with
EES' current unit system settings. The UnitSystem function is used to determine if the current
unit system setting is SI or English and the units for length (L$) and velocity (Vel$) are set
accordingly. The UnitSystem function takes a string argument corresponding to a unit system
Chapter 11: Internal Library Files 423
setting and returns true (1) or false (0) depending on whether the argument is consistent with
current unit system settings. For example, UnitSystem('Deg') will return true (1) if EES is
currently configured to use degrees in its trigonometric functions and false (0) otherwise.
if (UnitSystem('SI')=1) then
L$='m' "L$ is the length units EES is set to"
Vel$='m/s' "Vel$ is the velocity units EES is set to"
else
L$='ft'
Vel$='ft/s'
endif
The inputs are each converted to their base SI unit values using the Convert and ConvertTemp
functions; note that string variables are used within these conversions.
The properties required to compute specific exergy include the specific internal energy, specific
entropy, and specific volume of the fluid at the dead state. The specific internal energy is
computed differently depending on whether the fluid is an ideal gas or not, as determined using
the IsIdealGas function in EES. The specific internal energy of an ideal gas is a function of
temperature alone. The specific internal energy of a real fluid is a function of temperature and
another property such as pressure. Note that the units of the property returned by the IntEnergy
function are consistent with the unit settings in EES; these units are obtained using the
UnitSystem$ function and contained in the string u$. The specific internal energies are converted
to base SI units.
The same process is used to determine the specific entropies and specific volumes and they are
converted to base SI units.
Equation (11-1) is used to compute the specific exergy in base SI units. The specific exergy is
converted to units that are consistent with those set in EES.
The units of each variable are set in the Variable Information dialog, as shown in Figure 11-1.
Note that the string variables are used for the units that are consistent with the current EES
settings. For example, the temperature units that EES is set to are provided in string variable T$,
which was set according to T$=UnitSystem$('Temperature').
Figure 11-1: Variable Information dialog showing unit settings for the variables in the Exergy function.
Chapter 11: Internal Library Files 425
The result is x = 781.5 kJ/kg with no reported unit warnings. Change the unit system and the
units of the variable in the main program to the English system:
in order to obtain x = 336 Btu/lbm which is consistent with 781.5 kJ/kg and again, there are no
unit warnings. Additional tests for different fluids indicate that the function is working properly.
Now it can be saved as a library file.
This library file is saved with the name Exergy.lib using the Save As command in the File menu,
as shown in Figure 11-2. The file can be saved in any directory. However, if the library file is
saved in the Userlib (or UserLib64) folder within the EES directory, as shown, it will be
automatically loaded when EES is started.
Note that, in general, one EES library file can contain any number of functions, procedures, or
subprograms.
function: Exergy. The fact that the function appears in this list indicates that it has been loaded
and it is ready to be used.
Figure 11-3: Function Information dialog showing that the function Exergy is loaded.
$UnitSystem SI C kPa kJ
F$='air'
T=76.85 [C] "temperature"
T_o=25 [C] "dead state temperature"
P=200 [kPa] "pressure"
P_o=Po# "dead state pressure"
Vel=44 [m/s] "velocity"
z=180 [m] "elevation"
x=exergy(F$,T, P, Vel, z, T_o, P_o) "specific exergy for state"
Solve and you should see that x = 15.49 kJ/kg. The function Exergy can be used in the same way
as any built-in function.
428 Chapter 11: Internal Library Files
There are two ways to manually load a library file. The Professional version provides a Load
Library command in the File menu. This command allows selection of a directory. After
confirmation, all EES external programs in the directory (and in sub-directories within this
directory) will be loaded. The external programs are identified with file name extensions of
.FDL, .DLL, .DLP, .DLF, and .LIB. (For the 64-bit version, the file name extensions are .FDL64,
.DLL64, .DLP64, .DLF64, and .LIB64.) You can confirm that the library has been loaded by
selecting the Function Information command from the Options menu, as illustrated in Figure 11-
3.
The second way to load a library file is to use the $INCLUDE directive. The use of this and other
directives is described in Chapter 14. For example, if the Exergy.lib file had been saved in the
folder C:\temp\ then it would be loaded if the following statement appears in the EES Equations
Window:
$INCLUDE C:\temp\Exergy.lib
It is not necessary to include the directory information if the library file is located in the directory
that EES is installed in.
Note that thee $INCLUDE directive will not attempt to load a library file that has been
previously loaded. However, the Load Library command will reload the specified library file,
overwriting the existing version. This feature of the Load Library command is convenient when
you are developing external library files and need to test the latest version without having to
close and reopen EES.
Figure 11-5: Result of clicking the Function Info button before help information has been provided.
430 Chapter 11: Internal Library Files
{$Exergy
Exergy(F$, T, P, Vel, z, T_o, P_o) returns the specific exergy of a fluid.
F$ is the name of the fluid
T is the temperature in EES temperature units
P is the pressure in EES pressure units
Vel is the velocity in m/s (SI) or ft/s (Eng)
z is the elevation in m (SI) or ft (Eng)
T_o is the dead state temperature in EES temperature units
P_o is the dead state pressure in EES pressure units
}
Now save the library file, close EES and restart it. If you saved the library file in the Userlib (or
Userlib64) folder, it will automatically load. If not, load it with the Load Library command from
the File menu or by using the $INCLUDE directive. Select the Function Information command
from the Options menu and find the Exergy function, as shown in Figure 11-3. Select Exergy in
the Exergy.lib folder and click the Function Info button; you should see the help information
appearing in Figure 11-6.
Help files having an .htm or .pdf format can be generated in several ways. Perhaps the easiest
way is to use a word processor. For example, Microsoft Word allows a file to be saved with an
.htm file name extension. A portable document format (.pdf) file can be obtained by printing a
file from a word processor to a pdf printer, which is provided by Adobe Acrobat or other
software. Figure 11-7 shows help information for the Exergy function entered into Microsoft
Word, including a hypertext link to a reference. Save this file as Exergy.htm in the same
directory as the Exergy.lib file. EES will load the Exergy.htm help file at the same time that the
Exergy.lib file is loaded. The help information in the Exergy.htm file can be accessed from the
Help for External Libraries command in the Help menu or by clicking the Function Info button
in the Function Information dialog in Figure 11-3. Either method will start your browser
program and load the help file, as shown in Figure 11-8. A .pdf file could be used in exactly the
same manner.
Figure 11-7: Help information for the Exergy function entered in Microsoft Word.
432 Chapter 11: Internal Library Files
Figure 11-8: Browser program showing help information for the Exergy function.
A .chm file (compiled html) is a binary help file that contains hyperlinked contents. This is a
common type of help file that is used to provide the online help for many programs in newer
Microsoft Windows operating systems. (The .chm format has replaced the older .hlp help file
format that was previously the default format for help files.) A help compiler program such as
the HTML Help Workshop or Help Scribble (http://www.helpscribble.com/) can be used to build
a .chm file. EES will recognize the .chm file if it has the same name as the library file and it will
display the help information when the Help for External Libraries command is selected from the
Help menu or the Function Info button in the Function Information dialog is activated.
Chapter 11: Internal Library Files 433
Figure 11-9: Application library information for the Boiling and Condensation library.
434 Chapter 11: Internal Library Files
A textbook index file is a text file that is identified with the filename extension (.txb). When
EES reads a textbook index file, it creates a menu at the far right of the menu bar, as shown in
Figure 11-12. Each menu item opens a dialog window from which one or more EES programs
can be selected. The menu thus provides easy access to a large number of EES programs and is
useful for organizing programs that are related to a specific topic. This menu is used by default
to provide easy access to example problems for a text book; however, it can be configured by a
user for any purpose.
Figure 11-10: User-created Textbook menu, is placed at the far right of the menu bar.
The format of the textbook index file is quite simple. The menu shown in Figure 11-12 was
created with the textbook index file that is shown in Figure 11-13. Note that the line numbers
have been added for reference, but they are not part of the information in the file.
Chapter 11: Internal Library Files 435
Figure 11-11: Listing of the .txb file used to generate the Textbook menu shown in Figure 11-12.
Line 1 of the .txb file provides the menu title, which will appear in the menu bar to the right of
the Help menu. Line 2 is reserved for a version number used internally by EES. Enter a 1 on
this line. Lines 3, 4, and 5 provide user-supplied information that will be displayed in the dialog
that appears whenever one of the menu items is selected. The information on line 3 is considered
to be a title and it is displayed in bold red font, as shown in Figure 11-14.
Figure 11-12: Dialog that appears when the first menu item in the textbook menu is selected.
436 Chapter 11: Internal Library Files
Line 6 is reserved for future use. Enter the word reserved on this line. The remaining lines
provide a set of information in groups. Each group begins with a menu item name preceded by
the > character (e.g., line 7 in Figure 11-13) and then either one or more subgroups or problem
descriptions. The menu item name is the name that will appear in the Textbook menu, e.g, Your
menu item 1. The characters >- together will place a break line in the menu. Note that a second
level of menu nesting is supported. If a menu item name is preceded with >> then this menu
item will become a 'flyout' or submenu that is displayed when the parent menu item is chosen, as
shown in Figure 11-12 for Your menu item 2.
Each problem description line contains four pieces of information that are separated by the |
character. The first item is a descriptive name for the problem, which may be up to 128
characters. This is the name that will appear in the dialog when the menu item is chosen, as seen
in Figure 11-14. The second item is the filename corresponding to the EES program file that will
be opened if the problem is selected. This filename may be partially or fully qualified with
directory information, e.g., C:\myBook\Chapter1\Problem1.ees or ..\Chapter1\Problem1.ees.
The partial qualification is relative to the directory that EES is installed in. (Note that the 64-bit
version uses .ees64 file name extensions.) The third item is an optional help file that is to be
associated with the EES file. The help file can be an .htm, .pdf, or .chm file. If no help file
name is provided, you should enter no.hlp. If help is provided, then the help file can be accessed
from an additional menu item that is placed in the Help menu. The final item was intended to be
the file name for a figure associated with the EES file. However, EES does not currently use the
filename, so enter no.bmp as a placeholder. The textbook index file should be placed in a sub-
directory that includes all of the referenced EES programs and associated help files.
EES currently uses the Textbook menu to display examples in the default installation. The
Examples menu provides convenient access to a number of instructive EES programs that may
be of use to a new user. You can remove this menu by deleting or renaming the Examples.txb
file; any other existing .txb file in the Userlib (or Userlib64) folder can be deleted as well.
The Library Manager is accessed by clicking the Auto Load button at the bottom of the Function
Information dialog when the EES library routines, External Routines, or an application library
Chapter 11: Internal Library Files 437
button is selected. For example, notice the Auto Load button in Figure 11-9. Selecting the Auto
Load button will bring up a dialog window having the appearance shown in Figure 11-15. Each
file in the Userlib (or Userlib64) folder (or its subfolders) appears in the list. The check box to
the left of the list controls whether or not the file is automatically loaded when EES is started. If
the checkbox is gray then the function is located in the EES_System directory and therefore its
load status cannot be changed in the Library Manager. Changing the loading status of any file
has an immediate effect. If a file is not currently loaded, clicking the check box will
automatically load the file and also ensure that it is loaded the next time EES is started. Un-
checking a box will remove a loaded file from memory and prevent it from loading the next time
EES is started. Information is written by the Library Manager into the file LibraryManager.txt in
the Userlib folder. Deleting this file will cause all files to be automatically loaded.
References
Klein, S.A. and Nellis, G.F., Thermodynamics, Cambridge University Press, New York, (2011).
Nellis, G.F. and S.A. Klein, Heat Transfer, Cambridge University Press, New York, (2009).
12 THE HEAT TRANSFER LIBRARY
The heat transfer library in EES was originally developed during the writing of Heat Transfer by
Nellis and Klein (2009). The objective of the library is to automate the reference materials that
are commonly used to solve heat transfer problems so that it is not necessary to obtain
information from figures, tables or equations. The heat transfer library includes functions that
are capable of calculating quantities that are frequently required when solving heat transfer
problems. Examples include view factors, heat exchanger effectiveness-NTU solutions,
convection coefficients, friction factors, conduction shape factors and related information. The
functions are easy to navigate through as they are organized into an application library, as
discussed in Section 11.4. The various heat transfer library categories are discussed in this
chapter. Note that the categories and functions may change as new features are continuously
being added. One of the advantages of the heat transfer library is that it is easy to add functions
or change existing functions. For more information on the underlying theory that is used to
develop the heat transfer library please see Nellis and Klein (2009).
As an example, we will use the Boiling and Condensation library to calculate the average heat
transfer coefficient for R134a that is evaporating in a 2.0 cm diameter tube. The R134a steadily
enters the tube at 260 K with a quality of 0.36 at a mass velocity of 200 kg/s-m2 and exits as
saturated vapor (quality = 1). The average heat flux for the tube is 1600 W/m2.
Select Function Information from the Options menu and click on the radio button titled Heat
Transfer. If it is not already selected, click in the list to right of the radio button to select the
Boiling and Condensation library, as shown in Figure 12-1. This library provides functions for
the subjects of Boiling, Condensation and Pressure Drop. The Boiling subject should be
selected by default, but if it is not, click the drop-down list that is shown on the right of the
picture to select the Boiling category. The available functions for the Boiling category are each
shown with a picture using the application library tools described in Section 11.4. Use the
scroll bar under the picture to select the Film_Boiling_Avg function. The Function Information
should now appear, as shown in Figure 12-1. Clicking the Info button in this dialog will
provide specific information for the selected function. The heat transfer library code is written
as an EES library. Clicking the View button will display the EES code associated with this
function in the library. Clicking the Index button will open the help file to an index page that
displays information for all of the functions in this library. An example of the function call
appears in the Example box. Click the Done button to close the dialog window.
Chapter 12: The Heat Transfer Library 439
Table 12-1: Organization of the Boiling and Condensation heat transfer library.
Menu Function Description
Boiling Nucleate_Boiling_Rohsenow returns the heat flux associated with nucleate boiling using
the Rohsenow correlation
Nucleate_Boiling_Kutateladze returns the heat flux associated with nucleate boiling using
the Kutateladze correlation
Film_Boiling_Shah returns the heat flux associated with film boiling using the
Shah correlation
Film_Boiling_Chen returns the heat flux associated with film boiling using the
Chen correlation
Flow_Boiling returns the local heat transfer coefficient & wall temperature
for flow boiling
Flow_Boiling_Shah_avg returns the average heat transfer coefficient for flow boiling
over a range of quality
Critical_Heat_Flux returns the critical heat flux
CHF_local returns the critical heat flux for flow boiling of water
flowing through a vertical tube.
CHF_tube returns the critical heat flux for flow boiling of water
flowing through a vertical tube as well as the inlet
temperature.
Condensation Cond_Tube Returns the local heat transfer coeffient for condensation in
a tube or micro-channel using at any orientation using the
correlations of Shah (2016), Int J. of Refrigeration
Cond_Tube_avg Returns the average heat transfer coeffient for condensation
in a tube or micro-channel using at any orientation
Cond_HorizontalTube returns the local heat transfer coefficient & flow regime for
flow condensation
Cond_HorizontalTube_avg returns the average heat transfer coefficient for flow
condensation
Cond_vertical_plate returns the heat transfer coefficient for film condensation
from a vertical plate
Cond_horizontal_Cylinder returns the heat transfer coefficient for film condensation
from the outer surface of a horizontal cylinder
Cond_horizontal_N_Cylinders returns the heat transfer coefficient for film condensation
from the outer surface of a bank of horizontal cylinders
Cond_finned_tube returns the heat transfer coefficient for film condensation
from the outer surface of a horizontal cylinder with annular
fins
Cond_horizontal_up returns the heat transfer coefficient for film condensation
from an upward facing plate
Cond_horizontal_down returns the heat transfer coefficient for film condensation
from a downward facing plate
Pressure DELTAP_2phase_horiz returns the pressure drop for two-phase flow through a tube
Drop over a range of qualities
440 Chapter 12: The Heat Transfer Library
Figure 12-1: Function Information dialog showing information for the Flow_Boiling_Shah_Avg function.
Enter the known information for this problem into an empty Equations Window.
$UnitSystem SI K Pa J
$TabStops 3 in
Fluid$='R134a'
T_sat=260 [K] "boiling saturation temperature"
G=200 [kg/m^2-s] "mass velocity"
d=0.020 [m] "tube inner diameter"
x_in=0.36 "quality at inlet"
x_out=1.00 "quality at outlet"
q``=1600 [W/m^2] "surface heat flux"
Open the Function Information dialog and if necessary, select the Boiling and Condensation
library and scroll to the Flow_Boiling_Avg function. Click the Paste button to paste the contents
of the examples edit box into the Equations Window.
All of the inputs to the function have been specified. Select the Solve command. The Solutions
Window should show that the average heat transfer coefficient is 2351 W/m2-K.
0.05
As,fin/As,out = 0.913
D h = 3.63 mm
= 0.534
Colburn jH and friction factor
0.04 2 3
A s,out/V = 587 m /m
0.03
f
0.02
0.01
jH
0
400 500 1000 2000 5000 10000
Reynolds number
Figure 12-2: Typical compact heat exchanger chart showing the Colburn jH factor and friction factor as a
function of Reynolds number.
442 Chapter 12: The Heat Transfer Library
Figure 12-3: Function Information dialog for the Compact HX heat transfer library.
When the drop down menu to the right of the figure in the lower panel is selected, the user will
see four categories of functions labeled Non-dimensional, Geometry, Coefficient of Heat
Transfer, and Pressure Drop. Under each category there is a list of different types of cores.
Selecting a certain type of core allows the user to scroll through the various specific geometries
for which data are available.
Non-Dimensional Functions
Non-Dimensional functions provide the dimensionless parameters (jH and f) as a function of
Reynolds number; that is, they provide the information that could be obtained directly from
Figure 12-2. This information is useful when it is necessary to compute the engineering
quantities of interest (heat transfer coefficient and pressure drop) using the definition of the
dimensionless parameters together with knowledge of the properties of the fluid and the core
geometry.
Geometry Functions
Geometry functions provide the core-level geometric details of the core. These geometry
factors are summarized in Table 12-2.
Chapter 12: The Heat Transfer Library 443
Table 12-2: Geometric details of the core returned by the Geometry functions in the Compact Heat
Exchanger library.
Parameter SI Unit English Unit Description
D_o m ft outer diameter of tube1
fin_pitch 1/m 1/ft number of fins per unit length
D_h m ft hydraulic diameter of passages
fin_thk m ft thickness of fins2
sigma - - ratio of the minimum free flow area to the frontal area
alpha m2/m3 ft2/ft3 ratio of the heat transfer surface area to the total volume
A_fin\A - - ratio of the finned surface area to the total surface area
b_1 m ft thickness of passage through which fluid 1 flows
1. only applicable to circular tube and pin-fin plate-fin geometries; a value of -9999 will be returned for other
geometries
2. not applicable to pin-fin plate-fin geometry
For example, consider a heat exchanger composed of the finned tube core shown in Figure 12-3
which is used in the following EES code:
The CHX_geom_finned_tube procedure call provides the core-level geometry for the finned tube
core fc_tubes_s80_38T: Do = 10.2 mm, finpitch = 315 1/m, Dh = 3.6 mm, finthk = 0.33 mm, =
0.534, = 587 m2/m3, and Afin/A = 0.913.
calculates the heat transfer coefficient for air flowing through a heat exchanger core composed
of finned tube core fc_tubes_s80_38T. The mass flow rate of air is m = 0.2 kg/s, the
temperature is T= 300 K, the pressure is P = 100,000 Pa, and the frontal area is Afr = 0.1 m2.
The resulting heat transfer coefficient is h = 55.6 W/m2-K.
444 Chapter 12: The Heat Transfer Library
calculates the pressure drop for air flowing through a heat exchanger core composed of finned
tube core fc_tubes_s80_38T. The mass flow rate of air is m= 0.2 kg/s, the inlet and outlet
temperatures are Ti = 300 K and To = 300 K, the pressure is P = 100,000 Pa, the frontal area is
Afr = 0.1 m2, and the length is L = 0.2 m. The resulting pressure drop is P = 41.8 Pa.
The index to the Conduction Shape Factors library in EES can be most easily viewed by
selecting Conduction Shape Factors from the Heat Transfer Library drop down menu and then
clicking the Index button. The graphical display of the various geometries that appears, shown
in Figure 12-4, can be scrolled through; selecting a particular case leads to a dialog that
provides additional information.
Chapter 12: The Heat Transfer Library 445
Spreading Resistances
Spreading resistance function provide a heat transfer resistance that can be used to determine
the steady-state heat transfer rate for the shown in Figure 12-5.
12.4Convection
The Convection library contains functions that are used to compute heat transfer and pressure
drop for single phase heat transfer processes. The correlations programmed in EES include
internal and external forced convection, free convection, and flow through some regenerator
packings.
Note that both dimensional and non-dimensional versions of most internal flow procedures are
available. The non-dimensional versions provide the non-dimensional quantities of interest
(e.g., Nusselt number and friction factor) given the non-dimensional conditions (e.g., Reynolds
number and Prandtl number). The dimensional versions provide the dimensional quantities of
interest (e.g., heat transfer coefficient and pressure drop) given the dimensional conditions (e.g.,
fluid, temperature, pressure, velocity, etc.). These two versions of the function are related. The
dimensional version of the function calculates the non-dimensional input parameters to the non-
dimensional version of the function. The non-dimensional version is called to obtain the non-
dimensional quantity of interest which is finally used to obtain the dimensional quantities of
interest.
448 Chapter 12: The Heat Transfer Library
Table 12-3: Organization of the forced internal convection portion of the heat transfer library.
Menu Function Description
Internal Flow - PipeFlow returns the average heat transfer coefficient1 and total pressure drop for
Dimensional flow through a round tube given the dimensional conditions
DuctFlow returns the average heat transfer coefficient1 and total pressure drop for
flow through a rectangular duct given the dimensional conditions
Annulus returns the average heat transfer coefficient1 and total pressure drop for
flow through an annular space given the dimensional conditions
HelicalPipeFlow returns the average heat transfer coefficient1 and total pressure drop for
flow through an helical pipe given the dimensional conditions
Tube_Bundel returns the average heat transfer coefficient1 and total pressure drop for
flow through an ideal square or triangular tube bundle given dimensional
conditions
PipeDimensions provides dimensional information for standard pipe sizes
Internal Flow – PipeFlow_ND returns the average Nusselt number1 and average friction factor for flow
Non- through a round tube given the non-dimensional conditions
dimensional DuctFlow_ND returns the average Nusselt number1 and average friction factor for flow
through a rectangular duct given the non-dimensional conditions
Annulus_ND returns the average Nusselt number1 and average friction factor for flow
through an annular space given the non-dimensional conditions
HelicalPipeFlow_ND returns the average Nusselt number1 and average friction factor for flow
through an helical pipe given the non-dimensional conditions
Tube_Bundle_ND returns the average Nusselt number1 and average friction factor for flow
through an ideal square or triangular tube bundle given the non-
dimensional conditions
Internal Flow – PipeFlow_local returns the local heat transfer coefficient1 and local pressure gradient for
Dim (local) flow through a round tube given the dimensional conditions
DuctFlow_local returns the local heat transfer coefficient1 and local pressure gradient for
flow through a rectangular duct given the dimensional conditions
AnnularFlow_local returns the local heat transfer coefficient1 and local pressure gradient for
flow through an annular space given the dimensional conditions
Internal Flow – PipeFlow_N_local returns the local Nusselt number1 and local friction factor for flow
Non-dim through a round tube given the non-dimensional conditions
(local) DuctFlow_N_local returns the local Nusselt number1 and local friction factor for flow
through a rectangular duct given the non-dimensional conditions
AnnularFlow_N_local returns the local Nusselt number1 and local friction factor for flow
through an annular space given the non-dimensional conditions
1. both the constant wall temperature and constant heat flux values are returned
Table 12-4: Organization of the forced external convection portion of the heat transfer library.
Menu Function Description
External External_Flow_Sphere returns the drag force and average heat transfer coefficient for
Flow – flow over a sphere given the dimensional conditions
Dimensional External_Flow_Cylinder returns the drag force per unit length and average heat transfer
coefficient for flow over a cylinder given the dimensional
conditions
External_Flow_Plate returns the average shear stress and average heat transfer
coefficient for flow over a flat plate given the dimensional
conditions
External_Flow_Inline_Bank returns the pressure drop and average heat transfer coefficient
Chapter 12: The Heat Transfer Library 449
Free Convection
There are two menus that pertain to free convection (i.e., natural convection where fluid motion
is induced by buoyancy force); the organization of these menus is shown in Table 12-5. Notice
that there are again both dimensional and non-dimensional versions for most of the procedures.
450 Chapter 12: The Heat Transfer Library
Table 12-5: Organization of the free convection portion of the heat transfer library.
Menu Function Description
Free Convection Tilted_Rect_Enclosure returns the heat transfer coefficient for a tilted rectangular
– Dimensional enclosure given the dimensional conditions
FC_plate_vertical returns the heat transfer coefficient for a heated (or cooled)
vertical plate given the dimensional conditions
FC_plate_horizontal1 returns the heat transfer coefficient for a heated upward
facing (or cooled downward facing) horizontal plate given
the dimensional conditions
FC_plate_horizontal2 returns the heat transfer coefficient for a heated downward
facing (or cooled upward facing) horizontal plate given the
dimensional conditions
FC_plate_tilted returns the heat transfer coefficient for a tilted plate that is
either heated or cooled given the dimensional conditions
FC_sphere returns the heat transfer coefficient for a heated (or cooled)
sphere given the dimensional conditions
FC_horizontal_cylinder returns the heat transfer coefficient for a heated (or cooled)
horizontal cylinder given the dimensional conditions
FC_vertical_cylinder returns the heat transfer coefficient for a heated (or cooled)
vertical cylinder given the dimensional conditions
FC_vertical_channel returns the heat transfer coefficient for a heated (or cooled)
vertical channel formed by two infinite plates given the
dimensional conditions
Free Convection Tilted_Rect_Enclosure_ND returns the Nusselt number for a tilted rectangular enclosure
– Non- given the non-dimensional conditions
dimensional FC_plate_vertical_ND returns the Nusselt number for a heated (or cooled) vertical
plate given the non-dimensional conditions
FC_plate_horizontal1_ND returns the Nusselt number for a heated upward facing (or
cooled downward facing) horizontal plate given the non-
dimensional conditions
FC_plate_horizontal2_ND returns the Nusselt number for a heated downward facing (or
cooled upward facing) horizontal plate given the non-
dimensional conditions
FC_sphere_ND returns the Nusselt number for a heated (or cooled) sphere
given the non-dimensional conditions
FC_horizontal_cylinder_ND returns the Nusselt number for a heated (or cooled)
horizontal cylinder given the non-dimensional conditions
FC_vertical_cylinder_ND returns the Nusselt number for a heated (or cooled) vertical
cylinder given the non-dimensional conditions
FC_vertical_channel_ND returns the Nusselt number for a heated (or cooled) vertical
channel formed by two infinite plates given the non-
dimensional conditions
Impinging Jets
The Impinging Jets library setermine the heat transfer coefficients for single round and slot jets
and arrays of round and slot jets.
Chapter 12: The Heat Transfer Library 451
Regenerator Packings
Regenerator packings are matrices of solid material with a geometry that provides a high surface
area per volume so that fluid flowing through the packing is in intimate contact with the solid.
Typical regenerator packings are beds of spheres or stacked screens. There are two menus that
pertain to flow through regenerator packings. The organization of these menus is shown in
Table 12-6. Notice that again both dimensional and non-dimensional versions of these functions
are available.
452 Chapter 12: The Heat Transfer Library
Table 12-6: Organization of the regenerator packing portion of the heat transfer library.
Menu Function Description
Regenerator PackedSpheres returns the friction factor, heat transfer coefficient and
Packing – number of transfer units for a packed bed of spheres given
Dimensional the dimensional conditions
Screens returns the friction factor, heat transfer coefficient and
number of transfer units for a packed bed of screens given
the dimensional conditions
Triangular_channels returns the friction factor, heat transfer coefficient and
number of transfer units for a packed bed of triangular
channels given the dimensional conditions
Regenerator PackedSpheres_ND returns the friction factor and Colburn j-factor for a
Packing – packed bed of spheres given the non-dimensional
Non-dimensional conditions
Screens_ND returns the friction factor and Colburn j-factor for a
packed bed of screens given the non-dimensional
conditions
Triangular_channels_ND returns the friction factor and Colburn j-factor for a
packed bed of triangular channels given the non-
dimensional conditions
12.5Fin Efficiency
Fins are surfaces that extend into a fluid from a base material in order to increase the surface
area that is exposed to convection. The fin efficiency is used to encapsulate the solution for
various types of fin geometries. Fin efficiencies are derived with the assumption that the
extended surface approximation applies; that is, the temperature distribution is 1-D. The fin
efficiency is defined as:
q
= (12-2)
h As ( Tb T )
fin
where h is the heat transfer coefficient between the fluid and the surface, As is the area of the
fin that is exposed to fluid, Tb is the temperature of the base material, T∞ is the temperature of
the fluid, and q is the rate of heat transfer from the fin to the fluid. Fin efficiency solutions in
EES are provided both in dimensional and non-dimensional terms, like the convection solutions.
The organization of the Fin Efficiency library is shown in Table 12-7.
Chapter 12: The Heat Transfer Library 453
Note that in order for the fin efficiency solutions to be useful, it is necessary to know the surface
area that is exposed to fluid, As in Eq. (12-2). The equations for the surface area are included in
the Help information for each fin type; this information can be accessed by selecting Info from
the Function Information dialog.
12.6Fouling Factors
Heat exchangers that operate for a prolonged period of time will become “fouled”; that is,
contamination will build up on the surfaces. This contamination will lead to an additional
resistance to heat transfer and therefore degrade the heat exchanger performance. The
resistance to heat transfer that results from fouling (Rf) is typically calculated using an area-
specific fouling factor ( Rf ):
R
Rf = (12-3)
f
As
where As is the surface area that is exposed to fluid. Area-specific fouling factors are provided
empirically for specific types of fluids and treatments (e.g., city water, river water, treated
water, etc.). The Fouling Factor library provides some values of the area-specific fouling
factors, as shown in Figure 12-6. These are organized by fluid type and then by treatment.
454 Chapter 12: The Heat Transfer Library
12.7Heat Exchangers
Heat exchanger solutions for various configurations have been derived under the assumption of
constant property fluids, no axial conduction or jacket heat loss, and uniform conductance.
These solutions are typically represented in either log mean temperature difference (LMTD) or
effectiveness-NTU ( - NTU) form.
where q is the rate of heat transfer, UA is the conductance of the heat exchanger, and Tlm is
the log mean temperature difference. The log mean temperature difference is computed
according to:
The parameter Tlm,cf in Eq. (12-4) is the log mean temperature difference for a counterflow
heat exchanger:
where TH,in and TH,out are the hot fluid inlet and outlet temperatures, respectively, and TC,in and
TC,out are the cold fluid inlet and outlet temperatures, respectively. The parameter F in Eq.
(12-5) is a configuration-specific correction factor that must be less than unity. The correction
factor is typically obtained as a function of two dimensionless parameters, P and R, using charts
of the type shown in Figure 12-7 which is for a crossflow heat exchanger with both fluids
unmixed.
1
Log-mean temp. difference correction factor, F
R = 0.2
0.9
0.4
0.6
0.8
0.8 1
1.5
2
3
0.7 4
0.6
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
LMTD effectiveness, P
Figure 12-7: Correction factor for a crossflow heat exchanger with both fluids unmixed as a function of the
parameters P and R.
(T C ,out TC ,in )
P= (12-7)
(T H ,in T C ,in )
(T H ,in TH ,out )
R= (12-8)
(T
C ,out T C ,in )
The first menu under the Heat Exchanger library is labeled F for LMTD, as shown in Figure 12-
8. The user can scroll through the various configurations, as shown.
456 Chapter 12: The Heat Transfer Library
Figure 12-8: The F for LMTD menu under the Heat Exchanger library.
F=LMTD_CF(Configuration$, P, R)
Effectiveness-NTU Solutions
The effectiveness-NTU ( - NTU) form of the solution is typically considered to be
more convenient than the LMTD form. The two forms are algebraically identical; however,
the - NTU form is easier to use for almost any problem. The - NTU form of a heat
exchanger solution is essentially a relationship between the effectiveness of a heat
exchanger (), the H
number of transfer units (NTU) and the capacitance rates of the fluids ( CC and C ) that has
been derived for a specific heat exchanger configuration. The effectiveness is defined as:
q
= (12-9)
Cmin ( TH ,in TC ,in )
UA
NTU = (12-10)
Cmin
The effectiveness-NTU solutions are typically arranged to either provide the effectiveness given
NTU (which is useful for simulating a particular heat exchanger) or the NTU given the
effectiveness (which is useful for designing a heat exchanger). There are two menu items
labeled NTU -> Effectiveness and Effectiveness -> NTU in the Heat Transfer library which
provide the solutions in each of these formats for a variety of heat exchanger configurations.
For example, Figure 12-9 illustrates the Function Information dialog for the function under the
NTU -> Effectiveness menu that provides the value of given NTU for a crossflow
heat exchanger in which both fluids are unmixed.
Figure 12-9: Function Information dialog showing the function that provides given NTU for a
crossflow heat exchanger in which both fluids are unmixed.
There are a number of different methods for computing the view factor between two surfaces
including inspection, integration of the view factor equation, or Monte Carlos simulations.
However, the view factor for many different surface combinations have been determined and
are available from different sources in the form of equations, figures, and tables. Many of these
view factor solutions have been programmed in EES and are available in the View Factor
library. The view factor library is divided into three menus. The 2-Dimensional menu provides
view factors for surfaces that extend infinitely; these view factors can be obtained using the
Crossed and Uncrossed Strings method described by McAdams (1954). The 3-Dimensional
menu provides view factors for a large number of three-dimensional surfaces. The Differential
menu provides view factors in which one or both of the surfaces are differentially small; these
are useful for problems with non-uniform temperature in which integration is required.
The best way to view and use the view factor library is to select the Index button and view the
available functions graphically, as shown in Figure 12-10 for the three-dimensional view factor
library.
Note that the functions in the view factor library return F1,2; that is, the view factor from surface
1 to surface 2. Therefore, it is important to understand which of the two surfaces is identified as
being surface 1 and which is surface 2. These surfaces are labeled on the diagram associated
with the view factor function.
Chapter 12: The Heat Transfer Library 459
Figure 12-10: Graphical index of part of the three-dimensional view factor library.
+ E0
=+ E
E d d =T 4 (12-12)
0 b,
E is the rate at which radiation is emitted in all directions at wavelength from a surface and
Eb, is the blackbody emission rate at the same wavelength and temperature. The rate of
blackbody radiation is given by Planck’s law, which is represented as
460 Chapter 12: The Heat Transfer Library
Eb, = C1 (12-13)
5
(e C2 /T
1)
The constants in Eq. (12-13) are built in constants that can be viewed from the Constants item in
the Options menu, as described in Section 1.9.
C_1=C1#
C_2=C2#
sigma=sigma#
The list of surfaces for which total hemispherical emissivity is available can be viewed from the
Function Information dialog, as shown in Figure 12-11.
Figure 12-11: List of substances for which total hemispherical data are available.
The data are accessed with the Emissivity_TotHemi function, which accepts the name of the
substance and its temperature, e.g.,
T=400 [K]
epsilon=Emissivity_TotHemi('Aluminum_Polished',T])
Chapter 12: The Heat Transfer Library 461
462 Chapter 12: The Heat Transfer Library
12.10Transient Conduction
Analytical solutions to a number of transient conduction problems for typical shapes under
common boundary conditions have been derived and several of these are available in the
Transient Conduction library. These solutions are divided by whether the object of interest is
semi-infinite or bounded. Semi-infinite objects have an infinite extent in the direction away
from the surface at which the thermal disturbance occurs; for short times, all objects can be
considered to be semi-infinite. The organization of the Transient Conduction library is shown
in Table 12-8.
sphere_Q returns the total heat transfer (relative to time = 0) into a cylinder
subjected to a step change in the temperature of the fluid adjacent
to the surface (w/ a convective boundary condition) given
dimensional inputs
Bounded 1-D - each of the functions in the Bounded 1-D - Dimensional library are also available
Non-dimensional in the non-dimensional library by adding _ND to the function name
12.11Pipe Dimensions
The pipe dimensions library provides information on the size of standard pipes, including the
inner diameter, outer diameters, wall thickness and flow area. This convienent library is
applicable for both english and metric pipe sizes. The procedure is called with the following
format.
Size is any of the following accepted industry size specification in inches or mm. If units are set
to English, then use the inch sizes otherwise use the mm sizes.
Inch mm Inch mm
0.125 6 7.000 175
0.250 8 8.000 200
0.375 10 9.000 225
0.500 15 10.00 250
0.750 20 11.00 275
1.000 25 12.00 300
1.250 32 14.00 350
1.500 40 16.00 400
2.000 50 18.00 450
2.500 65 20.00 500
3.000 80 24.00 600
3.500 90 26.00 650
4.000 100 28.00 700
4.500 115 30.00 750
5.000 125 32.00 800
6.000 150
Schedule$ can be: 5s, 5, 10s 10, 20, 30, 40s, 40 60, 80s, 80, 100, 120, 140, 160 or DblEH
Schedule$='10'
Call pipedimensions(Size, Schedule$: OD, ID, WallThickness, FlowArea)
Solution
FlowArea=0.0002302 [m^2]
ID=17.12 [mm]
OD=21.34 [mm]
WallThickness=2.108 [mm]
hL
K=
V2 / ( 2g )
P
hL =
g
P is the pressure loss introduced by the piping component, is the density, and g is
gravitational acceleration.
This Minor Looses file provides the values of resistance coefficients for the pipe components
shown in Figure 12-12. The online help provided in the Function Information command
(Options menu) indicates the required inputs for each of the piping components.
Chapter 12: The Heat Transfer Library 465
466 Chapter 12: The Heat Transfer Library
The flow measurement functions include an orifice plate and flow nozzle, as shown in Figure 12-
13.
As an example, the following code will determine the pressure drop of a flow of 2.43 kg/s of
methanol liquid at 20°C and 100 kPa flowing through an orifice place in which the upstream
diameter is 4 cm and the orifice diameter is 3 cm.
$UnitSystem SI C kPa kJ
Call orificeplate('Methanol',20[C],100 [kPa],2.43 [kg/s],0.04 [m], 0.03 [m]:DELTAP,V_dot,Re)
Solution
DELTAP=14.14 [kPa]
Re=131998
V_dot=0.003072 [m^3/s]
References
Kayes, W.M. and A.L. London, Compact Heat Exchangers, 3rd Edition, McGraw Hill, New
York, (1984).
Klein, S.A. and Nellis, G.F., Thermodynamics, Cambridge University Press, New York, (2011).
Chapter 12: The Heat Transfer Library 467
McAdams, W.H., Heat Transmission, 3rd Edition, McGraw-Hill, New York, (1954).
Nellis, G.F. and S.A. Klein, Heat Transfer, Cambridge University Press, New York, (2009).
468
13 COMPLEX ALGEBRA
Variables in EES are associated with several types of information in addition to their numerical
values. For example, variables can include units, limits, and guess values. If the Complex
Algebra option is selected, then variables in EES can also have both real and imaginary parts.
In this case, EES will carry out complex algebra automatically when performing the
calculations required by the program. Complex numbers are often used in engineering analysis.
A=2
(a) (b)
Figure 13-1: Solution Window with (a) complex algebra de-activated, and (b) complex algebra activated.
A = Ar + Ai j (13-1)
where the subscript r indicates the real part and the subscript i indicates the imaginary part. The
symbol j in Eq. (13-1) indicates the square root of negative one, 1 ; often the symbol i is used
for this purpose. To activate complex algebra in EES, select Preferences from the Options
menu and then scroll to the Complex tab, as shown in Figure 13-2. Select Do complex algebra
and then indicate whether the symbol i or j is to be used to indicate 1.
Chapter 13: Complex Algebra 469
An alternative (and more convenient) method for activating complex algebra is to utilize the
$Complex On directive. For example, the directive below:
$Complex On j
activates complex algebra and specifies that the symbol j will be used to indicate 1.
Another way to active complex algebra is to click in the complex section of the status bar at the
bottom of the Equations Window, as shown in Figure 13-3. There are three positions for this
tab. Complex: Off, Complex: On (i) and Complex: On (j). Each click in this section of the
status bar will toggle the complex algebra setting to the next option. This field will display a
red background when EES is configured to operate in Complex mode. The background of the
Complex field will be red when the Complex option is selected.
$Complex On j
A_r=2 "real part of A"
A_i=2 "imaginary part of A"
470 Chapter 13: Complex Algebra
Solving results in the Solution Window shown in Figure 13-1(b). Both parts of the complex
variable can also be assigned at the same time:
$Complex On j
A=2+2*j "assigning both parts at once"
$Complex On j
A=2
automatically sets both the real and imaginary parts of the variable A; the imaginary part is set to
zero and the real part to two.
A = Am A (13-2)
where Am is the magnitude of the complex variable and A is its phase. Equation (13-2) is the
polar form of a complex number. The magnitude and phase are related to the real and
imaginary components according to:
2 2
Am = Ar + Ai (13-3)
A
A = tan 1 i (13-4)
Ar
Complex variables can be defined in EES in their polar form according to Eq. (13-2). The
magnitude is entered first followed by the symbol < and the angle:
$Complex On j
$UnitSystem SI Mass J K Pa Rad
A=2<0.5
Complex numbers can be output in either rectangular or polar form and the polar form can be
expressed in either radians or degrees. Right-click on the value of A in the Solution Window to
select the output format, as shown in Figure 13-5. If the output format is set to polar(rad) then
the Solution Window will appear as shown in Figure 13-4(b).
Chapter 13: Complex Algebra 471
(a) (b)
Figure 13-4: Solution (a) displayed in rectangular form, and (b) displayed in polar form.
Figure 13-5: Selecting the output format for a complex variable in the Solution Window.
Notice that there was no designation of the unit for the angle in the above EES code; therefore,
it is assumed that the angle (0.5) has units that are consistent with the unit system settings in
EES (radians, according to the $UnitSystem directive). It is better to directly specify the unit for
the angle in a polar specification of the angle. This can be done by entering either rad or deg
immediately after the angle (without square brackets or a space):
$Complex On j
A=2<0.5rad
The CIS function can be employed in place of the < symbol to establish the angle:
$Complex On j
A=2*CIS(0.5rad)
(a) (b)
Figure 13-6: (a) Specify units using the Specify Format and Units dialog and (b) the resulting Solution
Window.
The units of complex variables used in calculations will be checked in the usual manner.
The guess value and limits of the complex and real parts of the variable can be set
independently; however, the units of both parts will automatically be adjusted to be the same.
Complex Algebra
Calculations accomplished using complex variables will automatically carry out complex
algebra. For example, the variables A and B can be defined as:
A = 2+2 j (13-5)
and
B = 3 +1 j (13-6)
C = A B = ( 2 + 2 j )( 3 +1 j ) = ( 6 + 2 j + 6 j + 2 j 2 ) = 4 + 8 j (13-7)
$Complex On j
A=2+2*j
B=3+1*j
C=A*B
Table 13-3: Built-in functions that do not operate with complex numbers.
Function(s) Description
ArcX where X=Cos, Cosh, etc. arc-cosine, arc-hyperbolic cosine, etc.
Average average of arguments
BesselX where X = I, _I0, J, etc. Bessel and modified Bessel functions
Ceil, Trunc, Round, Floor rounding functions
Chi_Square, Gamma_, Probability probability functions
Erf, Erfc Gaussian error function and complementary error function
Max, Min maximum and minimum of arguments
Mod modulus of the arguments
Sign sign of the argument
StdDev standard deviation of arguments
+ iC +
iL
iR
Vin C R Vout
- -
The constitutive equations for the inductor, capacitor, and resistor are:
Chapter 13: Complex Algebra 475
VL
iL = (13-9)
LD
iC = C DVC (13-10)
VR
i = (13-11)
R
R
where D represents the differential operator, iL, iC, and iR are the current through the inductor,
capacitor, and resistor, respectively, and VL, VC, and VR are the voltage drop across each of these
elements (in the direction of the current). A current balance leads to:
iL = iC + iR (13-12)
VL
= C DVC + VR (13-13)
LD R
The voltage across the resistor and capacitor are the same and equal to the output voltage:
VC = VR = Vout (13-14)
The voltage across the inductor is equal to the difference between the input and output voltages:
Substituting Eqs. (13-14) and (13-15) into Eq. (13-13) leads to:
(Vin Vout )
= C DV +
Vout (13-16)
out
LD R
Vout
TF ( D ) = 1
Vin = L C D 2 + L D +1
(13-18)
R
476 Chapter 13: Complex Algebra
where = 2 f is the angular frequency and TFm( j) and TF ( j) are the magnitude and
angle associated with the complex number that is obtained by substituting j into the transfer
function for the differential operator.
Complex algebra is activated using the $Complex On directive and the inputs are entered in EES:
The angular frequency is calculated and the value of the transfer function at D = j is
determined.
A value is specified for time (t = 0) and the input and output voltages are computed according to
Eqs. (13-8) and (13-19), respectively. Note the use of the Magnitude and AngleRad functions to
determine the magnitude and angle of the transfer function, respectively.
Parametric Table
We might want to prepare a plot showing the input and output voltages as a function of time
during one cycle (0 < t < 0.001 s). Select New Parametric Table from the Tables menu in order
to access the New Parametric Table dialog, shown in Figure 13-10(a).
Chapter 13: Complex Algebra 477
(a)
(b)
Figure 13-10: New Parametric Table dialog (a) with all variables complex and (b) with some variables
declared to be real using the $Real directive.
Notice that internally EES has created two variables for each of the variables in the problem;
one for the real component (indicated by _r) and the other for the imaginary component
(indicated by _i). In order to parametrically vary the value of the variable t, both t_r and t_i must
be set. There are a number of ways to accomplish this. We could put both the variables t_r and
t_i in the table as well as V_out_r and V_in_r. Set the value of t_i to 0 in every row and vary t_r
from 0 to 0.001 s, as shown in Figure 13-11. Comment out the specified value of time in the
Equations Window:
Figure 13-11: Parametric table with t_r, t_i, V_out_r and V_in_r.
Plot the values of V_out_r and V_in_r as a function of t_r in order to obtain Figure 13-12.
Select New Parametric Table from the Tables menu and you will see that only the variables D
and TF are complex and therefore only these variables have a real and complex part in the
variable list, as shown in Figure 13-10(b). It is only necessary to select the variables t, V_in, and
V_out in order to carry out the parametric study.
Subprograms
Functions, modules, and procedures cannot operate in complex mode. However, subprograms
do support complex algebra. Subprograms can be utilized in complex mode even if the
Equations Window is not operating in complex mode, allowing complex calculations to be
localized while the rest of the calculations are carried out in the normal way.
14 DIRECTIVES
EES compiles the information in the Equations Window into a stack-based form that allows for
efficient computation before calculations are initiated. The information in the Equations
Window consists mostly of equations, but it can also contain directives. Directives are
instructions to the EES compiler that are acted on only during the compilation process.
Directives are identified with a $ symbol as the first character. Directives can be used to
accomplish tasks as simple as controlling the tab locations in the Equations Window or as
complicated as controlling the order in which the equations are solved. We have referred to
directives throughout this book. This chapter presents a comprehensive list of the directives that
are available in EES. The directives are organized based on their purpose. A complete list of the
directives implemented at the time of publication is provided in Appendix C. The following
sections describe the directives and provide examples of their use.
$Allow ‘//’
Normally, all characters following a // on a line in the Equations window are treated as a
comment. There are rare circumstances where it is necessary to use the character string '//'.
Placing an $Allow '//' at the top of the Equations window will cause the // characters at an
position other than the beginning of a line to be ignored.
$Arrays
Arrays are discussed in Section 1.7. Array variables can have multiple values and therefore
behave as vectors or matrices. Array variables in the Main EES program are, by default,
displayed in the Arrays Window. For example, consider the EES code:
duplicate i=1,4
A[i]=i
end
which creates an array A[] that has four elements. Solve this problem and select Arrays from the
Windows menu to access the Arrays Window, as shown in Figure 14-1(a).
Chapter 14: Directives 481
(a) (b)
Figure 14-1: Array shown in (a) the Arrays Window and (b) the Solution Window.
Placing the $Arrays directive in the Main EES program controls whether the array is displayed in
the Arrays Window ($Arrays On) or the Solutions Window ($Arrays Off). The EES code:
$Arrays Off
duplicate i=1,4
A[i]=i
end
will result in array variables shown in the Solution Window, as shown in Figure 14-1(b), rather
than in the Arrays window.
Arrays can be used within functions and procedures, as discussed in Section 3.6. They can also
be used in subprograms and modules, which are described in Chapter 10. It is not always
convenient to pass arrays as input or output arguments from a function, procedure, subprogram,
or a module. In many cases, the only reason for passing an array out is so that the values within
the array can be used to create a plot or saved to a file. By default, array variables that are used
within a function, procedure, subprogram, or module are placed in the associated Solution
Window tab and therefore cannot be plotted. By placing the $Arrays On directive within
function, procedure, subprogram, or module, the array variables in that code section are placed
within the associated tab of the Arrays Window and they therefore can be plotted or saved to a
file. This option is illustrated in Section 3.6.
$Bookmark
For large EES programs it is convenient to be able to quickly jump to a particular location in the
program. You will find the $Bookmark directive to be a convenient method of navigating your
program. The format of the $Bookmark directive is:
$Bookmark Name
where Name is a descriptive name given to that location in the code. For example, open the EES
code titled "A heat pump cycle using R134a" which can be found by selecting EES Example
Problems from the Examples menu and then selecting Properties, thermodynamic. This is not a
particularly large program, but we can use it to illustrate the process of setting and using
bookmarks. Set a bookmark (called Compressor) at the location in the code where the
482 Chapter 14: Directives
compressor is analyzed and another bookmark (called Condenser) at the location where the
condenser is considered.
$Bookmark Compressor
"!Compressor"
x[1]=1 "saturated vapor at compressor inlet"
P[1]=pressure(R134a,T=T[1],x=x[1])
h[1]=ENTHALPY(R134a,T=T[1],x=x[1])
s[1]=entropy(R134a,T=T[1],x=x[1])
s_ID[2]=s[1] "ideal compressor is isentropic"
P[2]=pressure(R134a,T=T[3],x=1)
h_ID[2]=enthalpy(R134a,P=P[2],s=s_ID[2])
W_c_ID=-(h_ID[2]-h[1])*m_dot; "power requirement for ideal compressor"
ComEff=0.60 "Isentropic efficiency"
W_c=W_c_ID/ComEff "power requirement for actual compressor"
h[2]=h[1]-W_c/m_dot "energy balance on adiabatic compressor"
VolFlow=m_dot*volume(R134a,T=T[1],x=x[1])
VolFlow=4.3E-3 [m^3/s] "compressor volumetric flowrate"
"!Condenser"
$Bookmark Condenser
T_H=20 [°C] "building air temperature"
Beta=1.75 [kW/C] "HX effectiveness-capacitance rate product"
Q_H=Beta*(T[3]-T_H) "heat exchanger relationship"
Q_H=(h[2]-h[3])*m_dot "energy balance"
h[3]=ENTHALPY(R134a,T=T[3],x=0) "saturated liquid at condenser outlet"
P[3]=P[2]
Right click in the Equations Window (or the Formatted Equations Window) to bring up the pop-
up menu, shown in Figure 14-2. All of the bookmarks that have been entered into the Equations
Window will appear at the bottom of the menu. Selecting one of the bookmark menu items
immediately moves the cursor and display of the window to the related portion of the equation
set.
$DiagramUpdate On/Off
$DiagramUpdate On/Off directives can be used to improve the response time to changes made in
control settings in the Diagram windows. These directives are useful only when there are many
lines of code in the Equations window and the time required to process them is significant. See
Section 16-2.
$Font
$Font allows the font name and font size to be specified in the Equations Window. The protocol
is:
where FontName is the optional name of a font installed in your system folder and FontSize is an
optional input that controls the size (an integer between 5 and 40). If the FontName is not
provided, only the font size will be changed.
$HideWindow
The $HideWindow directive causes a specified window to be hidden. The protocol for the
$HideWindow directive is:
$HideWindow WindowName
where the parameter WindowName indicates the window to be hidden. The parameter
WindowName can be set to any of the values listed in Table 14-1.
$Private
The development of library files that can contain internal functions, procedures and subprograms
is discussed in Chapter 11. The EES code associated with a library file can normally be viewed
from within the Function Information dialog by selecting the View Code button. For example,
selecting the View Code button in the Function Information dialog shown in Figure 14-3 will
allow the user to examine the EES code associated with the function Eb in the Blackbody library.
484 Chapter 14: Directives
Figure 14-3: Function Information dialog for EES library routines showing the View Code button.
If the $Private directive is placed inside of a function, procedure or subprogram that is contained
in a library file, then the EES code for the function will not be accessible using the View Code
button. For example, if the Blackbody.lib file is opened from the Userlib\Heat Transfer\ folder and
the $Private directed is inserted within the declaration for the function Eb:
function Eb(T,lambda)
$Private
C1=3.7420e8
C2=1.4388e4
sigma=5.670e-8 [W/m^2-K^4]
Eb=C1/(lambda^5*(exp(C2/(lambda*T))-1))
end
then the function Eb will be removed from the list under Blackbody.lib. The help information
for the private function can still be accessed by selecting Function Info for the library.
Chapter 14: Directives 485
$ShowWindow
By default, the Solution Window is shown after the calculations are completed (unless the
calculations were initiated from the Diagram Window, as discussed in Chapter 15). The
$ShowWindow directive allows a different window to be brought forward at the completion of the
calculations. The format is:
$ShowWindow WindowName1 'WindowName2'
where WindowName1 is the name of the window to be shown. The types of window and their
associated names are summarized in Table 14-2.
The parameter 'WindowName2' is a string or string variable containing the specific name of the
window, should there be more than one instance of the type of window specified by
WindowName1. For example, you may have several Plot windows, but you want to show Plot2
after calculations are completed:
To have the Key Variables Solution window appear after solving, you could enter
The parameter 'WindowName2' can be replaced by an integer, in which case it specifies the
position of the tab that will be displayed.
486 Chapter 14: Directives
$SumRow
It is possible to include a row at the bottom of a Parametric Table that shows the sum of each of
the columns. Consider the Parametric Table shown in Figure 14-4(a) which does not include a
sum row. In order to add a sum row, check the Include a Sum row in the Parametric table in the
Options tab of the Preferences dialog as shown in Figure 14-5. The resulting Parametric Table is
shown in Figure 14-4(b). The sum row option can also be activated with the directive $SumRow
On or deactivated with the directive $SumRow Off.
$SumRow On
(a) (b)
Figure 14-4: Parametric Table (a) without sum row and (b) with sum row.
Figure 14-5: The option to Include a Sum row in the Parametric table is checked.
$Syntax
Chapter 14: Directives 487
The $Syntax directive provides an alternative to using the Syntax Highlighting page of the
Preferences dialog to set the case and style for function names and keywords. It also provides a
convenient method to set the syntax highlighting preferences for each individual file. The format
of the $Syntax directive is:
$Syntax OFF/ON Keywords(Case, Style) FuncNames(Case, Style)
where Case and Style are chosen from the following lists
Case: (ASTYPED, LOWERCASE, UPPERCASE, 1STLETTERUC)
Style: (PLAIN, ITALIC, BOLD, UNDERLINE, BOLDITALIC)
Examples:
$Syntax Keywords(lowercase, bold) FuncNames(1stLetterUC, bolditalic)
$Syntax Off
$Syntax FuncNames(asTyped, bold)
$TabStops
The $TabStops directive sets the tabs that are used in the Equations Window. Up to five tab stops
may be set with this directive. The format for the $TabStops directive is:
where Stop1 through Stop5 are numerical values in increasing order. The Unit must be either in
(inch) or cm (centimeter). If no units are specified then inch is assumed if the Unit System is set
to English and centimeter if the Unit System is set to SI.
$Warnings
Warnings in EES are generated for a variety of reasons. Warnings are generated internally by
the EES program if the equations appear to be singular. Warnings can be generated within
property correlations if they are used outside of their published range of applicability. Functions
and procedures may also generate user-defined warnings, as discussed in Section 3.8. Warning
messages will be issued, if needed provided that warnings are enabled by a $Warnings On
directive. If $Warning directives are not used in a program, warning will appear if they are
enabled in the Options tab of the Preferences dialog. Warning messages will be disabled for all
equations that follow the $Warnings Off directive. $Warnings On and Off directive can be used
multiple times within a program to control which equations can or can not issue warning
message. By default, any warnings that are generated are automatically displayed after the
calculations have been completed. However, the automatic display of warnings that have been
issued can be turned off with the Warning control in the status bar at the bottom of the Equations
Window. Warning can also be displayed by selecting the Warning menu item from the Windows
menu.
488 Chapter 14: Directives
$CheckUnits
The process of checking units and some of the features of the $CheckUnits directive are discussed
in Section 1.5. By default, EES will check the units of each equation each time that the program
is run and report any unit warnings. This feature can be activated and deactivated by placing the
$CheckUnits AutoOn or $CheckUnits AutoOff directive at the top of the Equations Window.
Unit checking can also be selectively deactivated for one or more sets of selected equations by
enclosing them within a $CheckUnits Off directive and a $CheckUnits On directive, as shown.
$CheckUnits Off
Equation(s) which will not have their units checked
$CheckUnits On
This capability is useful if you would like to avoid entering the units of each of the constants in a
curve-fit, as discussed in Section 2.2.
$UnitSystem
The $UnitSystem directive is discussed in Section 1.5 and provides a method for specifying the
unit system settings in EES. All of the specifications that could be set in the Unit System tab of
the Preferences dialog, shown in Figure 14-6, can be set using the $UnitSystem directive.
$UnitSystem SI Mass (or Mole) Deg (or Rad) kPa (or Pa, bar, MPa) J (or kJ) C (or K)
or
$UnitSystem Eng Mass (or Mole) Deg (or Rad) psia (or atm) F (or R)
Note that it is not possible to specify a mixed unit system. For example, if the unit system is SI,
then specifying F for the temperature units will result in temperature units of C, not F.
Functions, Procedures, and Subprograms can each have separate unit setting by placing a
$UnitSystem directive within the program unit in the Equations window. If no specification is
provided, the unit settings for Functions, Procedures, and Subprograms are the same as those for
the calling program.
The $Common directive is placed within the declaration of the function, procedure, module or
subprogram of interest. Variables following the $Common directive and separated by commas
(when using the decimal point as the decimal separator) or semicolons (when the comma is the
decimal separator) are accessible within the code segment. For example, consider the function
Test:
Function Test(A,B)
$Common C,D
Test=A+B+C+D
End
A=1
B=2
C=3
D=4
E=5
The function Test has access to variables A and B because they were passed as input arguments
but it also has access to variables C and D through the $Common directive. Note that the value of
a variable accessed using the $Common directive cannot be changed within the function (i.e., the
information flow is only one-way, which is different from common variables in most formal
programming languages). Modifying the function Test as shown below:
Function Test(A,B)
$Common C,D
Test=A+B+C+D
C=2
End
Figure 14-7: Error message associated with changing the value of a common variable within a function.
$Constant
The $Constant directive allows the specification of a user-defined constant that is available within
a specific EES file, as discussed in Section 1.9. The calling protocol for the $Constant directive
is:
where Name# is the name of the constant, ValueSI and ValueEng are the values of the constant in
the SI and English units specified by [UnitsSI] and [UnitsEng]. For example, a constant that
provides the Bohr radius can be entered in EES according to:
Chapter 14: Directives 491
Multiple constants can be defined using the $Constant directive; however, each constant must be
defined on its own line and these directives should appear before the constant is used. Constants
are global; that is, they are available in all functions, procedures, subprograms, and modules as
well as the Main program.
Constants are useful to specify the size of an array that is passed to a function or procedure using
array range notation, as discussed in Section 3.6. For example, the EES code below uses the
constant N# to set the size of the array A[ ] that will be passed to the function SumSquares.
Function SumSquares(A[1..N#])
S:=0 "initialize sum"
i:=1 "initialize index"
Repeat
S:=S+A[i]^2 "sum the square of each element"
i:=i+1 "increment the element"
Until (i>=N#) "stopping condition"
SumSquares:=S "set the function name to the calculated value"
end
$Complex On j
$Real
The variables following the $Real directive are assumed to be real when EES is operating in
complex mode. These variables cannot have a nonzero imaginary part and therefore only their
real component can be manipulated. The $Real directive is discussed in Section 13.2.
Table when it is called from within an internal function or procedure. The $CopyToLookup
directive is available in the Professional version of EES and it provides a better way to move
selected variables to a lookup table.
The parameters 'TableName' and 'ColumnName' specify the table and the column where the
variables will be written; these parameters can either be strings or string variables.
'ColumnName' is the name of the column in the Lookup table that the data will be written to.
'ColumnName' can be a string constant surrounded by single quotes or a string variable that has
been previously defined. In addition, the units for the column can be specified by following the
column name with a backslash (\) and then the units.
The value of StartRow is the row in which the first data item will be written and it can either be
an integer or a variable. Each additional data item will be written in a successive row. Data
items to be written appear last and they are listed in the order that they are to be written to the
table. Note that the array range notation, discussed in Section 1.7, can be used to specify a range
of elements within an array.
There are several optional flags at the start of the directive. The /T flag indicates that a new table
with the name 'TableName' should be created if it does not already exist. The /C flag indicates
that a new column with the name 'ColumnName' should be created if it does not already exist.
Finally, the flag /R indicates that additional rows should be added, if necessary, in order to write
all of the data in the list. The $CopyToLookup directive can be used within the Main EES
program and also within functions, procedures, and subprograms.
n=10
duplicate i=1,n
X[i]=i^2
end
$CopyToLookup /T /C /R 'Data Table', 'Q_dot\W', 1, X[1..n]
$Export
The $Export directive allows variables within an EES program to be written to an ASCII file.
This ASCII file can subsequently be read into EES by using the Open Lookup Table command
from the Tables menu, as discussed in Section 1.8, or by using the $Import directive. The ASCII
file can also be read into other applications, such as a spreadsheet program.
The parameter ‘FileName’ indicates the name of the file to which the variables are exported. The
extension of the file name controls its format. Allowable extensions include .csv (comma-
separated values, a format recognized by most other software), .dat (in which values are
separated by a space), and .tab (in which values are separated by a tab). If the filename
extension is .txt then EES will save the file in the Lookup File Format with header information
unless the /H option is used. The header information will include the name of the variable, its
units, and display format. The resulting file can be read directly using the Open Lookup Table
command from the Tables menu. Note that if the file name is ‘ClipBoard’ then the variables will
be placed as tab-delimited text onto the clipboard, from which they can be pasted to any other
application.
These variables appearing in the $Export directive can be variable names, numbers, or constants.
Array range notation, discussed in Section 1.7, can also be used. Each variable can optionally by
followed with a colon and a format specification statement. The format statements indicate the
type of formatting that should be used to write the variables in the variable list. The format
selections are discussed in Section 1.2 and repeated here. If no format specification is present
then the variables will be exported in floating point format with 8 decimal places (F8). The
indicator Fn indicates floating point with the numerical parameter n indicating the number of
494 Chapter 14: Directives
decimal places. The format indicator En specifies exponential format where n is number of
significant figures. If the format specification is A then the format used with be the same as the
format that is used to display the variable in the Solution Window of the EES program.
There are many optional flags at the beginning of the $Export statement. Their purposes are as
follows:
/A indicates that the values should be appended to the end of the file, if one already exists.
/Cindicates that the file will be cleared before each export operation if it exists. The /C
and /A options are mutually incompatible and should not be used together.
/D indicates that the exported values are formatted to appear just as they do in the
Solutions window, rather than in E format with 9 significant figures. This option is
ignored if a format specification is provided with the variable.
/F indicates that only the results associated with the final run in the Parametric Table
should be exported. Without this option, the $EXPORT directive will export results after
each row in the Parametric Table has completed its calculations. The option is ignored if
the Parametric Table is not used.
/H indicates the header information that allows the .TXT file to be read into an EES
Lookup File will not be written. This option is ignored for files having a filename
extension other than .TXT.
/L suppresses the carriage return-linefeed that is normally added after all of the variables
in the $Export command are written to a file. In its place, a separator character is written
which could be a comma, tab, or space, depending on the filename extension of the
export file. Combined with the /A flag, this flag allows exporting a series of values from
multiple $Export statements all on a single line. If the $Export command is used in an
EES program that involves a Parametric Table, then by default the results associated with
each run will be exported to the file.
/N instructed EES to export each variable onto a separate line. (This option should not be
used with the /L option.)
/U flag indicates that the units of the exported values are exported with the values. Units
are enclosed in brackets and are separated with a tab character from the values.
/V indicates that the variable names of the exported values are exported with the values.
The variable name precedes the value and is separated with a tab. Use the /N option to
force each variable to be written on a separate line.
Chapter 14: Directives 495
The $Export directive can be placed anywhere in your EES program including within functions,
procedures, and subprograms. Multiple $Export directives will be evaluated in the order that they
appear in the Equations Window.
$ExportPlot
The $ExportPlot directive provides an easy way to save a plot to a file after each calculation.
Plots can be saved with .bmp, .emf, .gif, .jpg, or .tif file formats. The format of the $ExportPlot
directive is as follows:
FileName is the name of the file that will be saved. The file name extension provided in the
filename determines which file format will be used to save the file. 'PlotName' is the name that
appears on the tab of the plot window. Alternative, an integer can be provided to determine the
plot to be saved. The /R=N parameter is optional and it determines the resolution of the plot. If it
is provided N must be an integer between 0 and 4 with the following meaning.
$Import
The $Import directive will read a list of variables from an ASCII file. The file could have been
written in many ways, for example, by another EES program, a MATLAB program, or by a
previous execution of the current EES program using the $Export directive. The $Import and
$Export directives provide a convenient means for communicating between EES and other
software.
The parameter ‘FileName’ indicates the name of the file from which the variables are imported; if
the file name is ‘ClipBoard’ then the variables will be read from the clipboard in text format. The
variable list includes variables that are used in the EES program. The values of these variables
will be imported from the file. Array range notation and string variables are both supported.
The /skiplines=n flag is optional; if used, the flag will cause the first n lines of the file to be
skipped and the import process will begin on the next line. n can be an integer or the name of an
EES variable that has previously been set to a value in the EES program or in a macro file.
The $Import directive can be placed anywhere within the Equations Window and will be executed
before the calculations are initiated. The $Import directive will only execute once at the start of
calculations even if the calculations are repeated within a Parametric Table. Multiple $Import
directives will be evaluated in the order that they occur in the Equations Window.
496 Chapter 14: Directives
One use for the $Import and $Export directives is to identify a periodic steady state solution to a
problem that has a harmonic forcing function. For example, consider the ordinary differential
equation:
dy
+ 0.2 y = 0.2 sin ( t ) (14-1)
dt
The forcing function, 0.2 sin(t), repeats every 2 seconds and therefore there must be a periodic
steady state solution to the differential equation that is independent of the initial condition. The
solution will approach periodic steady state after a large number of cycles have been simulated.
Periodic steady state has been achieved when the solution at t = 2 is the same as t = 0 (i.e., the
value of y is the same at the beginning and end of the cycle).
We can solve Eq. (14-1) numerically using the Integral command in EES, discussed in Section
7.2. An arbitrary initial condition, y0, is assumed:
t =2
dy
y = y0 + + dt dt
t =0
(14-2)
Figure 14-9: Solution for y as a function of t for one cycle starting from an arbitrary initial condition.
The solution shown in Figure 14-9 is not the periodic steady state solution because the final
solution and initial condition are not the same. In order to obtain the periodic steady state
solution, it is necessary to have the starting value of y equal to its final value. This solution can
be found by using a $Import directive to obtain the initial condition, y0, from the Clipboard and
then using a $Export directive to export the final solution to the Clipboard. Copy the value 0.2 to
the Clipboard. Replace the specification of y_0 in the Equations Window with a $Import
directive, as shown.
Repeated solutions of the EES program correspond to successive simulations of the cycle; each
simulation begins where the last cycle ended. Figure 14-10 shows the solution for the first five
cycles; notice that cycle five approaches the periodic steady state solution.
498 Chapter 14: Directives
Figure 14-10: Solution for y as a function of t for several cycles, each starting with an initial condition that is
equal to the final value of the previous cycle.
$OpenLookup
The $OpenLookup directive is available in the Professional version of EES. The $OpenLookup
directive opens a file and reads the data contained in the file into a Lookup Table. The
$OpenLookup directive allows the use of a format file (.fmt) to specify the structure and format of
the data in the file. This capability allows data to be constructed from a wide variety of sources
and subsequently read into a Lookup Table and conveniently used with EES programs.
The string ‘FileName’ contains the name of the file that contains the data and it can either be a
string or a string variable. The /Format flag is optional, but can be used to specify a format file
(.fmt) that contains the format specification that should be used to read the file. The details of
how to create a .fmt file can be found in the EES online help by searching for .fmt.
The /Rename flag is optional and can be used to rename the Lookup Table to the string
‘LookupTableName’. If the /Rename flag is not present, then the Lookup Table will have the same
name as the file containing the data, ‘FileName’.
Note that when EES encounters the $OpenLookup directive it will immediately check to see if a
Lookup Table with the specified name has already been opened. If the time/date information in
the corresponding disk file has not changed then no action will be taken. Therefore, the
$OpenLookup directive will not needlessly reconstruct the Lookup Table each time the equations
are solved.
Chapter 14: Directives 499
If a single question mark (?) is provided in place of the file name string ‘FileName’, then EES will
allow the user to navigate to the file that is to be read using a standard Open File dialog. The
resulting file name will be substituted for the ? so that the Open File dialog is not presented
during every execution of the program. The use of a double question mark (??) will result in the
Open File dialog being presented each time the equations are compiled and solved.
$SaveLookup
The $SaveLookup directive is available in the Professional version of EES. The $SaveLookup
directive will save a specified Lookup Table to a disk file after the calculations are completed.
The format for the directive is:
where 'LookupTableName' is the name of the Lookup Table and 'FileName' is the name of the disk
file. As with the $OpenLookup directive, the use of the ? or ?? symbols in place of the file name
will open a dialog that allows the user to navigate to a selected file. A single question mark will
use the file name that was first entered for each successive calculation, overwriting the contents
each time the equations are solved. A double question mark will prompt the user to identify a
file each time the equations are solved. Note that the $SaveLookup directive is not as generally
useful as the $SaveTable directive and is only included for backward compatibility.
$SaveTable
The $SaveTable directive saves the contents of a selected table to a disk file upon completing
calculations. The format is:
where 'TableName' is the name of the table (either a string or a string variable). The format for
the table name string should be 'Type of Table:Name of Table'. Type of Table is either Parametric,
Lookup, Arrays, or Integral depending on the type of table to be saved. Name of Table is the
name of the table to be saved. For example, to save the Parametric table named Table 1,
'TableName' would be 'Parametric:Table 1'. If no colon and name are provided then the table that
is foremost when the $SaveTable directive is executed will be saved.
The parameter 'FileName' is the name of the disk file, which can be a string constant or string
variable. The file name should include the extension, which will dictate the format that is used.
Allowable formats are EES Lookup Table (.lkt), text file (.txt), and comma-separated values
(.csv). The file name can also include directory information; if no directory information is
provided then the file will be saved in the current directory which is typically the directory from
which the EES file is read. Note that information about the current directory can be obtained
using the EESFileDir$ function. As with the $SaveLookup directive, the use of the ? or ?? symbols
in place of the file name will open a dialog that allows the user to navigate to a selected file. A
single question mark will use that file name for each successive calculation, overwriting the
contents each time the equations are solved. A double question mark will prompt the user to
identify a file each time the equations are solved.
500 Chapter 14: Directives
There are a number of optional flags that are included at the end of the directive; none of these
can be used when you are saving to a disk file with Lookup Table (.lkt) format.
$SaveVarInfo /A
The $SaveVarInfo directive can be used in the Professional version to save variable information
(e.g, guess values, limits, units, and format) to a .var/.var64 file. This information can be
retrieved with a $INCLUDE directive or with the Load buttons in the Variable Information
dialog and the Diagram window. This directive provides an automatic way to save the variable
information in a Distributable program.
The $SaveVarInfo directive has two forms. If there is no file name following on the same line,
the file name for the variable information file will be the same as the EES file name or the name
of the file selected in the Distributable program, but with a .var/var64 file name extension.
Distributable programs will look for and automatically load a .var/var64 file having the same
parent name as the EES program in the executable program. Alternatively, a string constant or
string variable containing the name of a .var/var64 file can be supplied as a parameter following
the $SaveVarInfo directive, e.g.,
H$:='C:\EES\mydata.var'
$SaveVarInfo H$
In this case, the variable information will be saved in the specified location.
By default, only variable information in the Main program is written to the file. If an optional /A
is provided, variable information will also be written for Functions, Procedures, Subprograms
and Modules that are being used in the program.
Chapter 14: Directives 501
$DefaultArraySize=100
This directive controls the size EES automatically assumes for arrays that are passed to
Functions and Procedures. See Section 3.6 for details.
Equations that are placed between a $DoLast and $EndDoLast directive will automatically be
compiled and solved only after all of the other equations have been compiled and solved.
Multiple pairs of $DoLast and $EndDoLast directives can be used, but they cannot be nested.
Consider a simple example. The size of an array (N) is to be determined by solving the
following simultaneous set of equations:
a+ N +b =5 (14-3)
502 Chapter 14: Directives
2 N 3 + a = 10 (14-4)
b=2 (14-5)
a+N+b=5 2*N-
3+a=10
b=2
duplicate i=1,N
A[i]=i^2
end
Solving this set of equations will lead to the error message shown in Figure 14-11.
The equations required to determine N must be compiled and solved before the Duplicate loop is
compiled. The problem can be solved by placing the Duplicate statement between a $DoLast and
a $EndDoLast directive.
a+N+b=5 2*N-
3+a=10
b=2
$DoLast
duplicate i=1,N
A[i]=i^2
end
$EndDoLast
To disable the automatic unit conversion, follow the directive with the Off keyword, i.e.,
$ConvertEESREFPROPUnits Off or delete the directive.
order of evaluation, e.g., $IF (T$='T') and ((P$='kPa) or (P$='bar')) The conditional statements
that are recognized by EES are summarized in Table 14-3.
The $If directive is extremely useful in a variety of contexts. We used the command $If
ParametricTable in Section 1.3 to set variables that are used with the Solve command but not with
the Solve Table command. The $If directive removed the equations in the Equations Window
504 Chapter 14: Directives
that specify the values of variables that were being parametrically varied by solving a Parametric
Table.
The $If directive is also useful for controlling the execution of a program so that you can
gradually add sophistication and complexity while maintaining reasonable guess values and
therefore assuring convergence. The process that EES uses to solve a nonlinear set of equations
and the importance of guess values is discussed in Chapter 5. Often it is possible to solve a
simple, or linearized, version of a problem in order to establish reasonable guess values for a
more complicated, nonlinear version of the same problem. Rather than rewriting the EES code,
the $If directive allows the program to switch between a linear and nonlinear version by changing
the value of a string variable.
As a simple example, consider a cylindrical conductor that carries current = 70 amp along its
axis. The conductor is D = 4 mm in diameter and L = 1 m long. The ends of the conductor are
maintained at TH = 293.2 K. The outer surface of the conductor is insulated from convection or
radiation. The conductor has constant electrical resistivity e = 1x10-8 ohm-m and a temperature
dependent conductivity:
W
kWT = 150 0.1 T 300 K
( ) m- 2 ( ) (14-7)
m-K
K
2
Ac = D (14-8)
4
The temperature distribution can be accomplished numerically using the method discussed in
Nellis and Klein (2009). Nodes are positioned linearly along the axis of the conductor; the axial
location of each node (x) is given by:
L
xi = i for i = 1..N (14-9)
( N 1)
where N is the number of nodes. The distance between adjacent nodes is:
Chapter 14: Directives 505
L
x= (14-10)
(N
1)
The temperature of the end nodes are set to the specified end temperature:
T[1]=T_H
T[N]=T_H
The temperatures of the inner nodes, i = 2 to i = N - 1, are obtained using energy balances. The
rate of ohmic dissipation within each node must be balanced by the rate of conduction out of
each node:
x current 2 k A (T T k A (T T )
) ( )
e
= LHS ,i c i i 1 RHS ,i c i i 1
for i = 2.. N 1 (14-11)
x
+
Ac x
where kLHS is the conductivity evaluated at the average of the nodal temperature (Ti) and the
temperature of the node to the left (Ti-1) and kRHS is the conductivity evaluated at the average of
Ti and Ti+1:
(Ti + Ti 1 )
k LHS ,i = for i = 2.. ( N 1) (14-12)
2
(Ti + Ti+1 )
k RHS ,i = for i = 2.. ( N 1) (14-13)
2
These equations are implemented using a Duplicate loop:
Duplicate i=2,(N-1)
k_LHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i-1]+T[i])/2-300 [K])
k_RHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i+1]+T[i])/2-300 [K])
rho_e*Dx*current^2/A_c=k_LHS[i]*A_c*(T[i]-T[i-1])/Dx+k_RHS[i]*A_c*(T[i]-T[i+1])/Dx
end
Solving leads to the Arrays Table shown in Figure 14-12(a). Notice that the solution is
nonphysical and involves negative conductivities and very large temperatures; this solution
occurs because the guess value for each of the temperatures in the array are set to their default
value (1 K).
One method of approaching this problem is to solve the problem using a constant value of
conductivity, which results in a linear set of equations. The solution to the linear set of equations
can be used as reasonable guess values from which to start the solution to the nonlinear set of
506 Chapter 14: Directives
equations. Define a string variable Mode$ that will be set to 'nonlinear' or 'linear' depending on the
equation set to be solved.
Mode$='linear'
If the value of Mode$ is set to 'linear' then the conductivities are set to constant values using the $If
directive. Otherwise the temperature dependent conductivities are used.
$If Mode$='Linear'
k_LHS[i]=50 [W/m-K]
k_RHS[i]=50 [W/m-K]
$Else
k_LHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i-1]+T[i])/2-300 [K])
k_RHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i+1]+T[i])/2-300 [K])
$EndIf
(a)
(b)
Chapter 14: Directives 507
(c)
Figure 14-12: Arrays Table showing the solution of (a) the nonlinear equations solve with the guess values set
to their default values, (b) the solution to the linear equations, and (c) the solution to the nonlinear equations
with guess values set to the linear equations solution.
Note that the equation set that is not used is grayed out and not compiled. The solution to the
linear set of equations is shown in Figure 14-12(b); the solution set is reasonable regardless of
guess values since the equations are linear. Select Update Guess Values from the Calculate
menu in order to set the guess values for each nodal temperature to the linear solution. Then
switch the value of Mode$ to 'nonlinear'.
Mode$='nonlinear'
$If Mode$='Linear'
k_LHS[i]=50 [W/m-K]
k_RHS[i]=50 [W/m-K]
$Else
k_LHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i-1]+T[i])/2-300 [K])
k_RHS[i]=150 [W/m-K]-0.1 [W/m-K^2]*((T[i+1]+T[i])/2-300 [K])
$EndIf
and the solution shown in Figure 14-12(c) is obtained. The more reasonable guess values have
resulted in the correct solution to the nonlinear equations.
$Include /R
The $Include directive automatically loads various types of external information into an EES file.
The $Include directive should be placed at the top of the EES Equations Window in order to
ensure that it is processed before the equations are compiled. The format is:
$INCLUDE FileName
508 Chapter 14: Directives
where FileName indicates the file that contains the information to be loaded. The file name must
include the extension and the complete path name.
There are various types of information that can be included using the $Include directive. A .txt
file can be loaded that includes EES equations that will be compiled together with those in the
Equations Window. Note that the included equations must not themselves utilize a $Include
directive.
The $Include directive can also be used to automatically load a library file that contains a set of
internal functions and procedures (.lib), as discussed in Chapter 11, or a library file that contains
a set of external functions (.dlf) and procedures (.fdl or .dlp), as discussed in Chapter 19. Finally
the $Include directive can be used to load REFPROP fluid (or .fld) files as discussed in Section
4.11. By default, EES will not reload a library file that has been previously loaded. However,
the library file will be reloaded if the /R option is provided with the $Include directive. This
option is convenient when you are simultaneously running EES and developing a library file as
EES will use the most recent version of the library file without having to restart.
The process of defining new units in a .unt file is discussed in Section 1.5. The .unt file can be
included with a $INCLUDE directive. The process of defining and storing your preferences
indicating how EES is configured is discussed in Section 1.9. The preferences can be stored as a
.prf file and subsequently automatically loaded using a $Include directive. This option is
particularly useful if you are running EES on a network installation in which you may not have
control of or authorization to change the default .prf file.
In the Professional version of EES, the $INCLUDE directive can be used to load a variable
information file (.var) that is either written using the Save Inputs button in the Diagram Window
or the Save option in the Variable Information dialog. The $INCLUDE directive can also be used
to automatically load one or more macro files (.emf). Each macro file loaded in this manner is
placed in a separate tab in the Macro Window. See Chapter 18 for information relating to
macros and the Macro Window.
$Input
The $Input directive available in the Professional version will provide a dialog box that will
prompt the user to enter the value of an EES numerical or string variable when any of the Solve
commands are issued. This directive is useful when it is necessary to run successive calculations
with different values of an input. Because of the prompt, it is not possible to forget to enter the
value of the EES variables. The format is
$Input R
where R is the EES variable name. Use R$ to enter a string variable. Note that a message can be
appended to the variable name with a backslash (\) that will be displayed in the dialog box, as
shown in the following example.
T=300 [K]
P=1000 [kPa]
h=enthalpy(R$,T=T,P=P)
When the Solve command is given, the following dialog box will be displayed to provide the
refrigerant name.
$IntegralAutoStep
The $IntegralAutoStep directive allows the user to specify the parameters that are used to
automatically control the size of the integration steps in a numerical integration accomplished
with the Integral command. This directive is discussed in Section 7.2 and allows the user to
specify the same parameters that would otherwise be controlled in the Integration tab of the
Preferences dialog.
$IntegralTable
The $IntegralTable directive controls the creation of an Integral Table, which contains the
integration variable and any other variables of interest that are computed during the numerical
evaluation of an integral with the Integral command. Only one $IntegralTable directive may be
used in the Main program and each Subprogram. The $IntegralTable directive is discussed in
Section 7.2.
$MaxCalls
The $MaxCalls directive can be placed within a function or procedure in order to limit the number
of times that it is called. The format is:
$MaxCalls = N
where N is the maximum allowable number of times that the function can be called (N must be
greater than 2). The $MaxCalls directive should be placed immediately after the declaration of
the function or procedure.
The purpose of this directive is to eliminate convergence problems that can otherwise occur due
to control decisions made using the logic statements that can be employed within a function or
procedure. In some problems, these logic statements will lead to repeated on/off decisions that
never terminate. The $MaxCalls directive eliminates this issue; if the number of calls to the
function or procedure exceeds the value set by the $MaxCalls directive then the values returned
510 Chapter 14: Directives
will be the same as were returned for the last valid call. If a Parametric Table is being solved,
then the parameter N establishes the maximum number of times a function or procedure can be
called for each row.
$Reference
The $Reference directive allows the reference state that is used for a built-in EES fluid that uses
the fundamental equation of state to be adjusted from its default value. This directive can also be
used to change the reference state for property data obtained with the EES_REFPROP interface.
The format for the $Reference directive is:
where Fluid is the name of the fluid (either as a string variable or a string constant) and
ReferenceID indicates the reference state. The allowable values of ReferenceID are summarized in
Table 14-4.
The $Reference directive can also be used for properties determined using the EES_REFPROP
interface. In this case, a /EESREFPROP option must follow the $Reference keyword, as shown
in the following program.
$RunMacroAfter
The $RunMacroAfter directive allows macros to be embedded within the Equations window.
The macro is run after the calculations are completed. Variables that are defined with macro
Chapter 14: Directives 511
commands are displayed in the Macro Variables tab of the Solution window. One use of the
directive is to automatically generate a plot after calculations are completed, as shown in the
example. These features are available in the Professional version.
StopCriteria
The $StopCriteria allows the user to specify the stop criteria that control the iterative calculation
process used by EES to solve the equations. The parameters that can be set using this directive
are the same as those that can be specified from the Stop Crit tab of the Preferences dialog,
shown in Figure 14-13.
The $StopCriteria directive corresponding to the stop criteria settings shown in Figure 14-13 is:
Note that it is not necessary to provide all of the parameters; any parameter that is not specified
in the $StopCriteria directive will be set according to the default values or the values set in the
512 Chapter 14: Directives
Stop Crit tab of the Preferences dialog. Settings made using the $StopCriteria directive will
override those made in the Stop Crit tab of the Preferences dialog.
$Trace
The $Trace directive produces a table that contains the values of specified variables that occur
during the iterative solution process to the equation set. The $Trace directive allows the iterative
solution process used by EES to be examined. The $Trace directive is discussed in detail in
Section 5.4 and is primarily used for debugging. The format of the directive is:
where Variable1, Variable2, etc. are the variables in the Main EES program that are to be traced.
The parameter N_i is the maximum number of iterations that will be recorded. The variables are
placed in a Lookup Table that has the name Trace.
$UpdateGuesses
The $UpdateGuesses directive causes the guess values to be automatically updated after the
calculations are completed. The $UpdateGuesses directive normally operates only within the
scope of the program unit in which it is located in (either the main program or a subprogram).
However, $UpdateGuesses /A will cause the values for all subprograms and the main program to
be updated, regardless of where it is placed.
$VarInfo
The $VarInfo directive allows variable information (e.g., the guess value, limits, units, display
format, etc.) to be entered from the Equations window, rather than from the Variable Information
dialog. This directive is very useful when it is necessary to enter commands to EES from a
macro or from a text file, as for example, when using the internet EES_App (See Appendix G.).
It is also helpful to use the $VarInfo directive to make the setting of guess values and/or bounds
visible in the Equations window. A separate directive is normally needed for each variable.
However an array name, e.g., T[], can be specified and in this case, the directive is applied to all
variables in the array. The format of the $VarInfo directive is as follows (all on one line).
VariableName must be the first parameter. The variable name does not need to previously
defined, so the location of the $VarInfo directive is not important. However, it is best to place
the $VarInfo directive before the first equation in the main section of the Equations window.
Following VariableName, the remaining part of the directive consists of one or more keywords
followed by an equal sign and a specification. It is only necessary to provide the
keyword=specification terms that you are interested in changing and they can be provided in any
order.
V1, V2, and V3 shown as the specifications for Guess, Lower, and Upper, can be a numerical
value or the name of an EES variable. In the latter case, EES will use the current value of the
variable as the value for the specification.
Chapter 14: Directives 513
The Units specification can be a string constant (within single quotes) or a string variable. The
AltUnits specification must have the same dimensions as Units.
The Display specification consists of two characters. The first character can be A, N, F, E, G, D,
or T. A stands for Auto format. When this format option (the default) is selected, EES will
internally choose a format for displaying the value. N stands for N significant figures. The value
will be displayed with the number of significant figures in the second character of this
specification. F means Fixed Decimal format. In this case, the number in the second field
indicates the number of digits to the right of the decimal separator. E indicates exponential
format. The number that follows the E is the number of digits to the right of the decimal
separator. G indicates engineering format. Engineering format is similar to exponential format
in that the value is shown with a number followed by an exponent. However, in engineering
format, that exponent is always an integer factor of 3. The number that follows G is the number
of significant figures. D indicates date format. The second number then selects one of 10 date
formats. T indicates time format. In this case, the value in decimal hours is converted to
hour:minutes:seconds. The number in the second display column affects the number of
significant figures displayed. For F and E formats, this value will the number of digits to the
right of the decimal point. For G (Engineering) format, this number will be the number of
significant figures.
The Style specification controls the appearance of the variable in the Solutions window.
Allowable specifications are Normal, Italic, Bold and Boxed.
The Key specification indicates that the variable should be considered to be a key variable. The
comment that appears in the Key variable tab of the Solution window is provided after the equal
sign in quotes.
The following example will calculate the specific enthalpy of steam in variable h and set its units
to 'kJ/kg' and designate it to be a key variable.
The $VarInfo directive will set the units of a variable if the units are provided with the guess,
lower, or upper value. For example,
will set the lower bound for variable X to 200 and the units of the variable to K.
The Professional version will allow the guess, lower and upper value to be provided with an
equation involving EES variables. For example,
$VarInfo X Guess=A+10
514 Chapter 14: Directives
will set the guess values of variable to X to the current value of A+10.
The Professional version allows the $VarInfo directive to set the guess values and lower and
upper limists of all variables in an array to Guess, Lower and Upper values defined by other
arrays, as shown in the following example.
The $VarInfo directive can be used for variables in a Function, Procedure, Module, Subprogram
as well as the Main program. However, only the Units, Display, and Style keywords are
recognized for variables in Functions and Procedures since these variables do not have guess
values or limits and they cannot be designated as key variables.
References
Nellis, G.F. and S.A. Klein, Heat Transfer, Cambridge, New York, (2009).
515
The Professional version of EES greatly extends the capabilities of the Diagram Window by
allowing drop-down lists, radio button groups, check boxes and slider controls as alternative
input methods. Alternative output methods include live plots that update when the calculations
are completed. The Professional version allows Child Diagram windows that are activated by
“hot areas”, tabs, or link buttons. The Diagram and Child Diagram windows can also be
accessed from the Windows menu. Additional types of buttons can be placed on the Diagram
windows to load or save inputs/outputs, print, start a macro (see Chapter 19), provide a hypertext
link or start other programs. The Diagram Window is the key to the animation capabilities in
EES that are described in Chapter 16 and the Executable/Distributable programs that are
described in Chapter 17.
The Diagram Window must be in development mode in order to make any changes to it. Text
and graphic items can be placed in the Diagram Window. Existing text and graphic items can be
moved, modified, or deleted as discussed in this section. The Diagram tool bar shown in Figure
15-1 can be moved to any location by pressing the left mouse button down while the cursor is
positioned at the top of the tool bar and then moving the mouse to drag the tool bar. A status bar
is visible at the bottom of the Diagram Window when it is in development mode. The status bar
shows the cursor position, the Diagram Window identity and information about the object that is
under the mouse cursor.
In the Professional version, you will see the Paste format dialog shown in Figure 15-2 if the
graphic object is available in more than one format. In most cases, the device independent
bitmap or the enhanced metafile are the best choices.
Chapter 15: The Diagram Window 517
Selecting the Paste button will place the graphic object on the Diagram Window. As an
example, the throttle schematic shown in Figure 15-3 was created in a drawing program and
pasted into the Diagram Window. The object can then be dragged to any location on the
Diagram Window by pressing and holding the left mouse button down within a rectangle that
encloses the object while sliding the mouse to a new location.
Note: Objects pasted as a Bitmap require a large amount of memory compared to the other
alternatives and bitmaps tend not to scale well. The recommended format is Enhanced
metafile or Picture, unless there are other factors involved.
The object can be resized after it has been pasted into the Diagram Window. Clicking on the
schematic will result in the display of 8 small boxes or handles; these are visible in Figure 15-3.
Move the cursor to any of the boxes and then press and hold the left mouse button down. The
cursor will change to indicate that you are resizing the object. Now move the mouse to a new
location while holding the button down. The schematic will be resized. If the Shift key is
depressed during this process then the aspect ratio of the object will remain unchanged. The
graphic object can be deleted by selecting it and then pressing the delete key.
Figure 15-3: Throttle schematic created in a drawing program and copied into the Diagram Window.
The Professional version also provides tools for polylines ( ) and polygons ( ).
518 Chapter 15: The Diagram Window
After the line has been drawn, it can be moved to any location on the Diagram Window by
pressing and holding the left mouse button down while the cursor is positioned somewhere in the
middle of the line. Moving the mouse to a new location while holding the left button down will
move the line. The location of the starting or ending point of the line can also be changed. Once
drawn, the line can be selected by clicking the left mouse button in the middle of the line. The
selected line will have small boxes (handles) at the ends, as shown in Figure 15-5. Move the
cursor to the box at the end of the line that you wish to relocate. Now press and hold the left
mouse button down on the line handle while moving it to its new location.
Each new line that is drawn will have the characteristics of the previous line. The first line that
is drawn will be a solid thin black line. To change the characteristics of the line, either double-
click the left mouse button or click the right mouse button while the cursor is located somewhere
near the line center in order to activate a pop-up menu that contains various options, as shown in
Figure 15-6. Note that the line can be cut or copied and its position relative to other graphic
objects (i.e., backwards or forwards, corresponding to behind or in front of, respectively) can be
controlled with options in the pop-up menu. Select the Properties menu item to bring up the
Diagram Line Characteristics dialog shown in Figure 15-7.
The color, line type (thick, dotted, dashed, etc.) and other characteristics of the selected line can
be modified by changing the appropriate controls. The line can be made to appear as a single or
double-headed arrow. The precise location of the start and end of the line can be entered in pixel
coordinates. If the Locked button is selected then the position of the line cannot be altered with
the cursor.
The Name field is also visible in the Diagram Line Characteristics dialog in the Professional
version of EES. The Name field is used to provide animation effects, as described in Chapter 16.
Animation provides the ability to hide or show the line, as well as changing its end positions,
thickness or color.
To select a rectangle in development mode, click the mouse within the rectangle. The rectangle
can be moved to another location by pressing and holding the left mouse button down at a
location within the rectangle and moving the mouse while the button remains depressed. The
length and/or width of the rectangle can be changed by pressing and holding the left mouse
button down on one of the eight handles. This action will cause the cursor to change from the
pointer to a double-arrow, as shown in Figure 15-8. While holding the left mouse button down,
move the mouse to relocate the position of the handle. Note that the aspect ratio of the rectangle
will remain constant if the Shift key is held down during this process.
Chapter 15: The Diagram Window 521
The rectangle that is created will have the characteristics of the most recently created rectangle.
The first rectangle that is placed on the Diagram Window will be drawn with a thin black border
having square corners and no fill, as shown in Figure 15-8. The characteristics of the rectangle
can be changed by double-clicking the left mouse button or clicking the right mouse button
anywhere within the rectangle. Clicking the right mouse button displays a pop-up menu, shown
in Figure 15-9. The rectangle can be cut or copied and then pasted into the Diagram Window of
another instance of EES or into a Child Diagram Window (in the Professional version). The
position relative to other graphic items (in front of or behind) can be adjusted. Selecting
Properties from the pop-up menu will bring up the Diagram Object Characteristics dialog shown
in Figure 15-10.
Figure 15-9: Pop-up menu resulting from right-clicking on the rectangle border.
522 Chapter 15: The Diagram Window
Figure 1
Figure 15-10: Diagram Object Characteristics dialog.
The slider control at the upper left in the Type box controls the sharpness of the corners; sliding
the control to the right increases the rounding of the corners. The line color and line type can be
selected from the Line box at the upper right. The Fill box provides options for the manner in
which the rectangle object is filled. Select a color for the fill by clicking in the color box. Then
select the fill type. If the Transparent check box is selected then the fill will be drawn in semi-
transparent manner so that objects that are behind the rectangle can be seen. The exact location
of the top-left corner and the width and height of the rectangle can be entered. Note that if the
Fix aspect ratio check box is selected, as shown in Figure 15-10, then the width will change
when the height is changed and vice-versa. To enter the width and height independently,
uncheck the Fix aspect ratio check box.
The Angle and Name inputs are provided in the Professional version. These inputs are used for
animation and for control of the object with EES variables, as explained in Chapter 16. The
Professional version also provides a 3D option, which creates a rectangle having a 3D
appearance.
Click the Add Polyline button shown in Figure 15-1 ( ) to place a polyline or Bezier curve
on the Diagram Window. The cursor will change from a pointer to a plus sign. Move the cursor
to the desired location of the first point. The polyline object can be moved later, if desired,
so selecting the exact position of the point is not necessary. After clicking on the starting
point, move the cursor to the second point. A line will be displayed from the last point to the
current cursor location. Click to position the second point. Continue this process until all
of the segments of the polyline are drawn. Double-click (or press the Enter key) to end the
drawing process. If you wish to abort the drawing process, press the Esc key.
Once the drawing process is completed, the polyline object can be selected by clicking the left
mouse button while the cursor is positioned near the center of any line segment. The selected
polyline will include handles at each of the vertices of the polyline. The entire polyline can be
moved to a new location by pressing and holding the left mouse button near the center of any
line segment and moving the cursor. The location of individual points composing the polyline
can also be moved by selecting any one of the vertex handles of the polyline until the cursor
changes to up-down-left-right arrows, as shown in Figure 15-11. While holding the left mouse
button down, move the cursor to a new location. The position of the selected vertex will move
with the mouse.
Vertices can be added or deleted from an existing polyline by right-clicking on any vertex. The
pop-up menu shown in Figure 15-9 will appear with the Add Point and Delete Point menu items
enabled. Selecting the Add Point menu item will locate a new vertex between the vertex that
524 Chapter 15: The Diagram Window
was selected and its neighbor. The new vertex can then be moved to a new location. Selecting
the Delete Point menu item will delete the vertex that the cursor was positioned on.
The properties of the polyline can be changed when the toolbar is visible by positioning the
cursor on a line or vertex and either double-clicking the left mouse button or clicking the right
mouse button and selecting Properties from the pop-up menu. The Polyline Characteristics
dialog shown in Figure 15-12 will appear, allowing the line type and color can be changed. If
the Smooth check box is selected then the polyline will be displayed with cubic Bezier curves
using the endpoints and control points specified by the vertices. The first curve is drawn from
the first point to the fourth point, using the second and third points as control points. Each
subsequent curve in the sequence needs exactly three more points; the ending point of the
previous curve is used as the starting point, the next two points in the sequence are control
points, and the third is the ending point. Note that if the number of points in the polyline is not
evenly divisible by three then one or two points will not be represented in the Bezier curve.
When the Diagram Window toolbar is visible, dotted lines will be drawn between the vertices of
the original polyline in order to clearly indicate their positions in case you wish to move them, as
shown in Figure 15-13. These dotted lines will not be visible when the toolbar is hidden.
Figure 15-13: Polyline converted into Bezier curve by selecting the smooth option. The dotted lines will not
Chapter 15: The Diagram Window 525
Polygon objects items can be drawn on the Diagram Window by clicking the Add filled polygon
button on the Diagram Window toolbar ( ) shown in Figure 15-1. The process is identical
to the process for drawing a polyline, except that the drawing process is concluded by clicking
on the first point, which is marked with a circle. Alternatively, double-clicking the left
mouse button or pressing the Enter key will cause the cursor to move from the last entered point
to the first point in order to form an enclosed area and conclude the drawing process. The
enclosed area will, by default, be shaded in lime color.
The polygon object can be moved to another location by pressing and holding the left mouse
button while the cursor is anywhere within the polygon and then moving the mouse. The
positions of any of the vertices of the polygon can be moved by pressing and holding the left
mouse button while the cursor is positioned on a vertex. This action will cause the cursor to
change from a pointer to left-right-up-down arrows. Additional vertices can be added and
existing vertices can be deleted using the Add point and Delete point menu items in the pop-up
menu that appears when you click the right mouse button on a vertex.
The characteristics of the polygon can be changed by double-clicking the left mouse button
anywhere within the enclosed area or by clicking the right mouse button and selecting the
Properties menu item from the pop-up menu. Either action will bring up the Polygon
Characteristics dialog shown in Figure 15-14.
The line color, line type, fill color, and fill type can all be specified. These variables can be
controlled or animated with EES variables if a name is provided for the polygon, as described in
Chapter 16. If the Transparent checkbox is selected then the graphic object will be display in a
way that allows objects underneath it to be seen.
The graphic files that are included in the Diagram Window Palette are located in the EES
Userlib\Palette directory or within a subfolder in this directory. Graphic items can be provided
in files with any of the following formats: .bmp, .emf, .jpg, or .wmf. Files can be added by the
user in any of these formats to the Userlib\Palette folder or to a sub-folder within the
Userlib\Palette folder.
When the Access Palette button on the Diagram Window Toolbar is selected, EES will bring up
a dialog window that displays the files in the Userlib\Palette directory, as shown in Figure 15-15.
The drop-down list at the top of the dialog controls which graphic files are displayed. By
default, all files in the Userlib\Palette folder and all subfolders within this folder will be
displayed. Clicking on the drop-down list will display the items in the associated subfolders in
the Userlib\Palette folder. If a subfolder is selected, then only the files in the selected subfolder
will be displayed.
The contents of the graphic files in the selected directory are shown, one at a time, in the white
rectangle. Click the scroll bar to display other graphic files in the selected folder. Note that the
graphic is scaled to fit in the rectangle. The actual size may be larger or smaller than the
displayed size.
Click the Paste button to Paste the graphic item into the Diagram Window. Once it is placed on
the Diagram Window, the graphic item can be moved to a different location, stretched, or scaled.
To move the item to different location, press and hold the left mouse button down on the item
while sliding the item to a new location. To change the size of the item, click on one of the eight
handles (small boxes) that surround the item when it is selected, as shown in Figure 15-16. If
you hold the Shift key down while changing the size of the item, the aspect ratio will be
maintained.
Chapter 15: The Diagram Window 527
Figure 15-16: Item from the Palette dialog pasted into the Diagram Window.
Right-clicking on the graphic item will display the pop-up menu shown in Figure 15-17. Use the
menu to flip or rotate the selected object.
Figure 15-17: Pop-up menu that appears after clicking the right mouse button on a palette graphic item.
Select the Properties menu item to bring up a dialog that allows the attributes of the item to be
changed. The dialog allows a name to be assigned for use in animation, as described in Chapter
16. The pop-up menu also provides menu items to flip the selected graphic item horizontally or
vertically and to rotate the item 90° counterclockwise.
Graphic items in Diagram window can be moved with the arrow keys when the Diagram window
is in development mode. When an arrow key is pressed the first time, the selected items will
move 5 pixels. If the key is held down, the selected items will move quickly. Releasing and
pressing the key again (within 3 seconds) will move the selected items by 1 pixel, allowing fine
control. If the arrow key is then held down for more than 3 seconds, the speed at which the
selected items move in the designated direction will increase.
528 Chapter 15: The Diagram Window
The Professional version provides enhancements and object-linking ability for formatted text as
well as additional capabilities for entering input variables, such as slider controls, check boxes,
and radio groups.
Information on how to enter and modify these text items are presented in this section.
The text is entered in the field to the right of the word Text, below the Type group. The field
will display “new text” when a new text item is being created. Enter the text you wish to appear
on the Diagram Window. The font, size, style, orientation, and the foreground and background
colors can be specified.
Text items in the Diagram Window can be optionally used as links in the Professional version.
To enter the link, place a check in the Include Link control and enter the link address in the edit
box. The link address may be a URL or the location of a file (e.g., a .pdf file) on the computer.
In addition, the appearance of the text (excluding text with international characters) can be
enhanced with the controls in the box at the upper right of the dialog. These controls merit
further explanation. Clicking the or button will change the selected text in the text field
into a subscript or superscript, respectively. For example, to enter Tinitial, type Tinitial into the
text field. Then select initial and click the button. The text field will change to T\dinitial\.
The \d instructs EES to display the following text up to the next \ as a subscript. \u in place of \d
will result in a superscript. You can enter these codes directly, without using the buttons if you
prefer. Clicking the button will insert a line break, carriage return code in the text string
which will appear as \m in the text edit box.
Pressing the button will display a palette of lower case Greek letters, as shown in Figure
15-19(a). Sliding the cursor from the button to the palette while holding the left button down
will place the associated letter into the text field at the cursor position. The text display will use
the indicator \s to indicate symbol font followed by the character. A \ character terminates the
symbol font. The button provides the same capability for the upper case Greek letters,
shown in Figure 15-19(b). The button allows the symbols shown in Figure 15-19(c) to be
entered. However, the last three buttons on this palette differ from the others. These buttons
first require that a text be selected in the text field. Then, clicking the button will place a dot,
bar, or hat symbol above the selected text.
Clicking the OK button will place the text item in the Diagram Window and close the dialog.
Clicking the New button will also place the text item in the Diagram Window, but the dialog
window will remain open so that additional text items can be entered. The Cancel button will
close the Diagram Window without placing the text item.
When the Diagram Window is in development mode, any text item can be moved. Click on the
text item to select it. Selected text items will be displayed within a red dotted line rectangle.
Press and hold the left mouse button down while the cursor is positioned within the rectangle and
slide the mouse to move the text item to the desired location.
530 Chapter 15: The Diagram Window
The characteristics of existing text items can be viewed or changed by moving the cursor over
the text item and double-clicking the left mouse button or clicking the right mouse button and
then selecting the Properties menu item from the pop-up menu that will appear. Either action
will bring up the Diagram Text Item dialog shown in Figure 15-18 where changes can be made.
The Professional version of EES provides much more capability for formatted text items. A
paragraph can be composed directly in the Add Diagram Text item dialog when the Formatted
Text button is selected, as shown in Figure 15-20. Selecting the OK button pastes the text in this
dialog into the Diagram Window as an editable rich text item.
Figure 15-20: Formatted text entry option in the Add Diagram Text Item dialog.
Alternatively, a rich text item that has been composed in another application, such as a word
processor, can be pasted directly into the Diagram Window using the Paste command from the
Options menu. When EES detects a rich text item on the clipboard, it will display the Select
clipboard format dialog shown in Figure 15-1 after the Paste command is issued.
Chapter 15: The Diagram Window 531
Selecting the Text option will paste the contents of the clipboard into the Diagram Window in
rich text format, allowing it to be edited. Any graphic objects included with the text will be
pasted as well. As an example, the thermodynamics problem statement shown in Figure 15-22
was copied from Microsoft Word and pasted into the Diagram Window with the Text option.
Figure 15-22: Text and graphics copied from a word processor and pasted with the text option.
The text width will initially be set to the width of the Diagram Window. Clicking the left mouse
button with the cursor positioned on the text item will select it. A selected text item is displayed
with a red dotted line border with 8 handles, as shown in Figure 15-22. The text item can be
resized by positioning the cursor on any one of the handles and then pressing and holding the left
mouse button down while moving the mouse. The text can be moved when it is selected by
pressing and holding the left mouse button down while the cursor is within the text rectangle.
The text can be edited in the usual manner. Clicking the right mouse button in the text rectangle
when the text is selected will access the pop-up menu shown in Figure 15-23. Using this menu,
selected text can be cut or copied and the font, style, size and color can be changed.
532 Chapter 15: The Diagram Window
Figure 15-23: Pop-up menu for rich text item in the Diagram Window.
Selecting the Insert Variable menu item will bring up the dialog shown in Figure 15-24 which
provides a way to insert an EES variable in a ‘live’ manner so that the value displayed in the text
changes as the value of the variable changes. The dialog provides a list of all current EES
variables in the main section of the Equations Window. The check boxes allow the name, value,
and/or units of the selected variable to appear at the cursor location. For example, clicking the
OK button when the dialog is set as shown in Figure 15-24 will result in #3COP appearing at the
cursor position. When the Diagram Window is viewed in application mode (i.e., with the tool
bar hidden) the #3COP will be replaced with COP = 1.5 [-], where 1.5 is the current value of the
variable COP. If the value of the variable COP is changed then the updated value will
automatically appear in the text item.
The capability to insert the current value of an EES variable into a formatted text item allows it
act like a text output item with the additional advantage that text in the item can be selected and
copied to the clipboard. Normal output items described in the following section cannot be
selected and copied.
The text item can also be pasted as an enhanced metafile or picture. Both of these options paste
the rich text selection from the clipboard into the Diagram Window as a non-editable graphic
object that appears exactly as it did when it was copied.
Text items in Diagram window can be moved with the arrow keys when the Diagram window is
in development mode. When an arrow key is pressed the first time, the selected items will move
5 pixels. If the key is held down, the selected items will move quickly. Releasing and pressing
Chapter 15: The Diagram Window 533
the key again (within 3 seconds) will move the selected items by 1 pixel, allowing fine control. If
the arrow key is then held down for more than 3 seconds, the speed at which the selected items
move in the designated direction will increase.
R$='R134a' "refrigerant"
A=0.005 [m^2] "cross-sectional area"
T[1]=50 [C] "inlet temperature"
P[1]=700 [kPa] "inlet pressure"
Vel[1]=15 [m/s] "inlet velocity"
P[2]=300 [kPa] "outlet pressure"
The specific volume and specific enthalpy at the inlet (v1 and h1) are fixed by the temperature
and pressure. The mass flow at the inlet can be calculated according to:
V A
m 1 = 1 (15-1)
v1
m2 = m 1 (15-2)
V A
m2 = 2 (15-3)
v2
534 Chapter 15: The Diagram Window
The specific volume and specific enthalpy at the exit (v2 and h2) are fixed by the exit temperature
and pressure (T2 and P2). An energy balance on the throttle provides:
V12 V2
h1 + = h2 + 2 (15-4)
2 2
Equations (15-3) and (15-4) together with the property relations for v2(T2, P2) and h2(T2, P2)
represent four equations in the four unknowns V2 , v2, h2, and T2. They are entered in EES:
and solved, providing T2 = 42.1°C. We will now enhance this problem by providing it with a
graphical user interface that allows the inlet state to be specified in the Diagram Window.
Note that it is possible to change the display format and units for the selected input or output by
clicking on the Variable Information button below the list. (The button is just to the left of the
arrow cursor in Figure 15-25a. Clicking this button while variable P[2] is selected brings up the
dialog shown in Figure 15-25b.
Chapter 15: The Diagram Window 535
Figure 15-25: a) Specifying EES variable P[2] as an input variable and b) Modifying variable information.
An input variable will normally be displayed with the value enclosed in a rectangle. (If you do
not wish to have the rectangle displayed at all times, uncheck the Frame Input option in the Add
Diagram Text Item dialog.) This value can be edited and it acts to set the value of the associated
variable to the value entered in the box. The input variable box provides the same functionality
as entering the equation P[2] = 300 [kPa] directly in the Equations Window.
The input variable is initially placed at a default location. Select the input variable by moving
the cursor on it and pressing the left mouse button. A red dotted border will appear around a
selected text item. Press and hold the left mouse button down and then slide the input variable to
the desired location in the Diagram Window, as shown in Figure 15-27.
Figure 15-27: Diagram Window with one input and one output variable.
Place the Diagram Window into application mode and try to solve the problem by entering F2.
You should see the error message shown in Figure 15-28 indicating that variable P[2] is now
defined in both the Diagram Window and the Equations Window.
Figure 15-28: Error message indicating the P[2] is defined in both the Diagram and Equation Windows.
Chapter 15: The Diagram Window 537
Comment out the equation that sets P[2] in the Equations Window or, alternatively, use the $IfNot
directive with the conditional DiagramWindow so that the variable P[2] is only set if the
calculations are not initiated from the Diagram Window. The $IfNot directive is discussed in
Section 14.7.
$IfNot DiagramWindow
P[2]=300 [kPa] "outlet pressure"
$EndIf
When P[2] is set with the $IfNot directive as shown above, the program will operate correctly
whether or not the Diagram Window is used.
Bring the Diagram Window to the front and press F2 to solve the problem. The Diagram
Window will be updated with the current value of variable T[2] when the calculations are
completed. Change the value of P[2] to 100 kPa using the input variable in the Diagram Window
and repeat the calculations. The Diagram Window should now indicate that T[2] is 32.23°C.
Figure 15-29: Variable Information Window showing the lower bound set for the variable P[2].
If you now attempt to enter a value for P[2] in the Diagram Window that is lower than 100 kPa
you will receive the error message shown in Figure 15-30.
538 Chapter 15: The Diagram Window
Figure 15-30: Error message that appears when an entered value is not within its lower and upper bounds.
Include the mass flow rate of refrigerant and the outlet velocity as outlet variables. The inlet
pressure, inlet temperature, and inlet velocity can be placed on the Diagram Window as input
variables. Be sure that all input variables are either commented out in the Equations Window or
placed within the $IfNot DiagramWindow and $EndIf directive clause. The Diagram Window now
appears as shown in Figure 15-31.
Figure 15-31: Diagram window with all input and output variables shown.
Figure 15-32: Add Diagram Text Item showing options for string variables.
The remaining two check boxes in Figure 15-32 require additional explanation. If you uncheck
the Use string list check box and press OK, an input field for variable R$ will be placed on the
Diagram Window. However, the user will need to type in the name of the fluid that is to be
used, which does not provide any control over the name that is entered and therefore is not
particularly convenient for the user in this case. A better choice is to provide a list of allowable
fluid names. This option is accomplished by checking the Use string list check box and then
selecting the Edit button. A list box will appear, in which you can enter allowable values for the
string variable R$, as shown in Figure 15-33.
The Professional version allows the list of strings to be supplied from a text file that is specified
in the Read strings from file input box.
Click the OK button to place the input list for variable R$ onto the Diagram Window. Move the
input list to the desired location. Hide the tool bar to place the Diagram Window in application
mode. Comment out the equation that sets the string variable R$ in the Equations Window or
move it into the $IfNot DiagramWindow / $EndIf clause. The Diagram Window will now provide a
drop-down list of choices for the fluid, as shown in Figure 15-34. Note that when any input
variable is changed, the color of all of the output variables is changed to gray in order to indicate
that they are no longer correct, as shown in Figure 15-34.
Figure 15-34: Diagram window showing drop-down list of choices for variable R$.
The width of the input list is, by default, set automatically to the width of the widest string in the
list. However, if the Set width automatically control in Figure 15-33 is unchecked, the width can
be set manually by setting the number of pixels (96 pixels = 1 inch) in the Width box that will
appear to the right of the Set width automatically checkbox.
The capability of mapping string variables can be used in the throttle example to allow the user
to select from a drop-down list that is populated by industry-standard names for the refrigerants,
rather than the corresponding EES fluid names. To proceed, enter Ctrl-D to place the Diagram
Window in development mode with the tool bar visible. Select the refrigerant input list by
clicking on it and delete it by pressing the Delete key. Click the Add text button on the tool bar
and select Input variable. However, this time, scroll to the bottom of the list and click on *** New
String Variable ***. Enter a variable name for the string variable, e.g., RInput$, as shown in Figure
15-35. Note that the variable name must end with $ to indicate that it is a string variable. EES
will append $ if it is not provided.
Chapter 15: The Diagram Window 541
Next, select the new variable, RInput$, from the list. Uncheck the Include variable name check
box and check the Use String list and Format display check boxes, if they are not already
checked. Click the Edit button and enter the information shown in Figure 15-36.
Click OK to close the list of strings and OK in the Add Diagram text dialog to place the string
input list. Hide the Diagram Window toolbar to go into application mode. The list of industry-
standard refrigerant names will now appear in the Diagram Window, as shown in Figure 15-37.
Figure 15-36: List of strings for variable RInput$ with appended specification for variable R$.
Because the Format Display check box was checked, the text beginning with // for each entry
will not be displayed. In addition, when a selection is made for variable RInput$ from the list, the
information to the right of the // will be executed as EES equations. Note the multiple equations
542 Chapter 15: The Diagram Window
can be placed on one line provided a line separator, semi-colon (US) or colon (European), is
provided between the equations.
When a selection is made containing EES instructions to the right of the // characters, it may be
necessary to update the Diagram window display. If the Execute EES commands when the
selected item is changed checkbox is checked, EES will compile the equations in the Diagram
Window objects and in the Equations window and redisplay the Diagram Window. For some
very large programs, this process can result in delays. Unchecking the option will cause EES to
not update the Diagram Window until calculations are initiated. See Section 16.2 for other
methods to improve the response time of the Diagram Window.
Figure 15-37: Diagram Window showing drop-down list for string variable RInput$.
The strings can be read from a file in the Professional version. The Professional version also
provides additional input methods as described in Section 15.6.
Figure 15-39: Diagram Window with the input variable P[1] highlighted by the Find command.
When one or more objects are selected, the Copy menu command will appear as Copy Items.
Selecting this command will copy the objects in an internal form that maintains the information
needed for their display in the Diagram Window. The objects can then be pasted into the
Diagram Window to create duplicate instances or into a Child Diagram Window (see Section
15.6). The objects can also be pasted into a Diagram or Child Diagram Window in another
instance of EES. However, in general Input/Output text items should not be copied into another
instance of EES since they contain specific pointers to EES variables that may not be appropriate
in a different EES program.
Figure 15-40. Selecting multiple objects in the Diagram Window with a selection rectangle.
In the Professional version, the dialog window shown in Figure 15-42 will appear, offering a
choice between a Calculate button, an Animation Control bar and a Update Diagram button. The
animation capabilities provided in the Professional version are described in Chapter 16.
546 Chapter 15: The Diagram Window
Figure 15-42: Select Type dialog provides a selection of calculate buttons in the Professional version.
The button caption and button type can be changed with the controls at the top of the dialog. The
Commercial version provides the options of a plain button or a button with a standard icon.
The Professional version offers the option of having a user-provided picture displayed on the
button. The button location and size can be specified. The option for providing a name for the
button is available in the Professional version. Naming the button is used for animation, as
described in Chapter 16.
The action that the Calculate button initiates when it is pressed in application mode is specified
by selecting one of the radio button options. Normally, EES displays a dialog before it starts or
after it ends any type of calculations, such as solving a Parametric table or doing an optimization.
Checking the Skip confirmation button will suppress the appearance of the dialog.
The graphic user interface developed for the throttle in Section 15.2 will benefit from a Calculate
button, as shown in Figure 15-44. Use the default options shown in Figure 15-43, but select the
Skip confirmation check box. When the Calculate button is clicked while the Diagram window
is in application mode, the calculations will be initiated and the Diagram Window will be
updated without displaying the confirmation dialog after the calculations are completed.
548 Chapter 15: The Diagram Window
The Professional version provides the option for an Update Diagram button. Clicking the
Update Diagram button in application mode compiles the equations in the Diagram and
Equations window and updates the Diagram Window display without solving. This button is
useful in some large EES programs to improve the response time when changing control values.
The Professional version provides an option to have the button Reset the problem. Resetting the
problem causes all random number seeds to be reset, as if the problem were just opened. It also
sets any equations that have been entered for Diagram input variables to 1. Then it Updates the
Diagram window.
Figure 15-46: Property Plot Information dialog for a P-h plot for R1234yf.
Next, select the Overlay Plot menu command from the Plots menu. Select h[i] for the X-Axis
variable and P[i] for the Y-Axis variable, as shown in Figure 15-47. Select the Automatic update
and Show array indices check boxes so that the plot will identify states 1 and 2 and automatically
change when the values of pressure or specific enthalpy are changed. Click the OK button.
550 Chapter 15: The Diagram Window
Figure 15-47: Overlay Plot dialog to overlay the pressure and enthalpy on the property plot.
Now, return the Diagram Window and press Ctrl-D to enter development mode. Select the Add
plot access button ( ) to access the Show Plot Window Button dialog shown in Figure
15- 48(a). The plot that will be displayed when the button is clicked is selected from the drop-
down list at the top of the dialog. The Add button to link to Plot window check box is
selected by default. (The option to Show plot in Diagram window is only available in the
Professional version.) Click the OK button and a Plot Window access button will appear on
the Diagram window. The button can be moved or resized in the same manner as described for
the Calculate button. Double-click the left mouse button or click the right mouse button when
the cursor is on the button to bring up the dialog in Figure 15-48(a) where characteristics
such as the button caption and size can be changed.
Chapter 15: The Diagram Window 551
(a) (b)
Figure 15-48: Plot window access dialog with (a) plot access via a button and (b) plot shown on the Diagram
Window.
Hide the Diagram tool bar (or press Ctrl-D) to enter application mode. Clicking the Show Plot
button will bring the selected plot window to the front of all other windows and update its
contents. A small arrow button ( ) will be visible at the lower right corner of the plot
window,
as shown in Figure 15-49. Clicking this button will hide the plot window and bring the Diagram
Window back to the front.
Figure 15-49: Property plot accessed from a button on the Diagram Window.
552 Chapter 15: The Diagram Window
The button caption, type, location, and size can be specified, in the same way as for the other
buttons described in this section. The Help button will display a file when it is clicked in
application mode. The file that it will display must be entered in the Help File Name field.
Click the Browse button to bring up a standard file open dialog that will assist you in finding the
proper file. EES expects the help file to have a file name extension of .chm, .pdf, .htm, or .txt.
Click OK to place the button on the Diagram Window. It can be moved in the usual manner.
Double-clicking the left button or clicking the right button when the cursor is positioned on the
button in development mode will bring up the dialog window shown in Figure 15-51, where
additional changes can be made.
Figure 15-53: Creating a “hot area” by pressing the Shift and Ctrl keys while dragging a rectangular area.
When you release the mouse button, a small dialog window will appear as shown in Figure 15-
54 where you must enter a name for the hot area. Click the OK button and an empty Child
Diagram Window having the name that you entered in the dialog will appear. Note that each
Child Diagram Window has its own tool bar and all of the capabilities of the main Diagram
Window. You can enter any information or objects you wish in this window, including graphics,
text, and EES variable inputs and outputs.
Figure 15-54: The name of the Child Diagram Window is entered into this dialog.
Figure 15-55: Popup menu that appears when right-clicking a Child Diagram window in development mode
556 Chapter 15: The Diagram Window
An alternative way to display this dialog is to press and hold the Ctrl and Shift keys down while
in development mode will display a red outline around all defined hot areas. Double-clicking the
left mouse button when the Ctrl and Shift keys are pressed and the cursor is positioned in the hot
area rectangle will access the Modify Hot Area Information dialog shown in Figure 15-56.
This dialog allows the name of the Child Diagram Window (that appears in the title bar) and the
parent Diagram window to be viewed or changed. The Location and Size refer to the 'hot' area in
the parent Diagram window that provides access to this Child Diagram window. If you do not
wish to provide access to the Child Diagram Window by mouse clicks in the parent Diagram
Window, then you can make the width and height small or zero and/or move the hot spot to an
obscure location. Alternatively, uncheck the Enabled check box.
The Include navigation buttons check box will, if checked, place optional navigation buttons at
the lower right corner of the window. A small “go home” navigation button ( ) is
initially placed in the lower right corner of the Child Diagram window. Clicking this button
will close the Child Diagram Window and bring up the main Diagram Window. If the
parent of the Diagram Window is not the main Diagram window but rather another Child
Diagram Window then a second button with a blue left arrow will also be displayed in the
lower right corner of the window. Clicking this button will close the Child Diagram Window
and open its parent Diagram Window. The location and size of these navigation buttons can
be changed using the arrow and Ctrl-arrow keys, respectively. A caption can be added to
either button by right- clicking on the button while it is in development mode.
Show tab for access from the Main Diagram window will provide a tab in all Diagram windows
that are designated to have tab controls. The tabs appear at the top of the Diagram window, as
shown in Figure 15-57. Include access tabs in this window will provide tabs to access other
Diagram windows in this Child Diagram window. Note that when tabs are used in a Diagram
window, they occupy the top 24 pts of space in the window. It may be necessary to move the
content in the window down if it was originally created without tabs.
Chapter 15: The Diagram Window 557
Figure 15-57: Main Diagram Window with tabs for access to Child Diagram Windows
4. A Link button can be placed on any Diagram window that will open a specified Child
Diagram window. See the following section for information on Link buttons.
558 Chapter 15: The Diagram Window
To ungroup a previously defined group, click on the grouped item and then click the Ungroup
button ( ) on the toolbar or right click on the grouped item and select the Ungroup
menu command from the pop-up menu. The ungrouped items remain selected. To add a new
item to a group, select the group and ungroup it. Then, hold the Shift key down and select the
items that you wish to include in the group. Regroup all selected items.
There are several advantages to groups. Grouped items act like a single item; clicking on any
item in the group selects all of the items. The group can be moved, copied and pasted. Group
information is saved with other file information when the Save command is issued.
Groups have several attributes that may be useful. To access the group attributes, select the
group and right-click. Select the Properties menu item from the pop-up menu that appears. The
Group Attributes dialog will appear as shown in
Checking the Locked check box will lock all items in the group, so that they cannot be moved.
This attributed prevents accidental movement of the group once it is positioned in the desired
location. Checking the Hide check box will cause all of the items in the group to be hidden in
Chapter 15: The Diagram Window 559
Application mode. The items are always visible in Development mode. The Hide attribute can
be controlled programmatically using the Group Name. If a legal EES variable name is provided
in the Group Name edit box, EES will create a variable with name 'NAME.hide', where NAME
is the variable name provided in the Group Name edit box. In this case, an equation of the form
NAME.hide=true# will cause all members in the group to be hidden when the equation is
executed. NAME.hide=false# will cause all of the group members to be visible. The equation
can appear in the main body of the Equations window or in a Diagram window control, such as a
Drop-down list, Check box, or Radio Group. Note that, as a shorthand, EES will also except
NAME.hide and NAME.show in place of NAME.hide=true# and NAME.hide=false#. Setting
the hide attribute with a Name overrides the setting in the Hide check box. The programatic
control of the hide attribute is useful for animated Diagram windows in which it is necessary to
hide several Diagram window items depending on a choice made by the user in a Diagram
window control. Using a group, it is not necessary to specifically hide or show each group
member.
Creating Links
Link buttons can be placed on a Diagram Window or a Child Diagram Window by selecting the
Add Link button ( ) in the tool bar. The Link Button Properties dialog shown in Figure 15-
62 will appear after clicking the Add Link button on the tool bar. The caption and link
properties can be specified and assigned to a button that will appear on the foremost Diagram
Window. In the pull-down window that lists the types of link buttons there is an option for a
transparent button that can be placed anywhere in the Diagram or Child Diagram windows. The
transparent button allows part or all of existing graphic objects or text to serve as a button. The
caption and properties can be changed at any time when the Diagram Window is in
development mode by either double-clicking the left mouse button or clicking the right
mouse when the cursor is positioned over the button.
For example, this capability can be used in the throttle example presented in this chapter to
prepare a property plot that is specific to the fluid that is selected by the user from the drop-down
menu. To do this, create a macro file with a text processing program such as Notepad in the
same directory as the EES file for the turbine example. The name of the macro file should be
doPropPlot.emf and it should contain the following two lines:
Again, the macro commands will become more understandable after reading Chapter 19. Next,
create a link button with the Play Macro link information shown in Figure 15-63.
Figure 15-63: Configuring a link button to show a property plot for the selected fluid.
EES will replace %%1 in the macro file with the value of the EES string variable R$. The
parameters %%2 and %%3 in the macro file will be replaced with the values T[1] and T[2],
respectively. Solve the problem by clicking the Calculate button. Then click the Show Plot
button, which will display a P-h plot for the selected fluid with a superimposed line connecting
states 1 and 2.
Chapter 15: The Diagram Window 563
Clicking OK in the Link Properties dialog will create the link button. The button can be dragged
to any location while the Diagram Window is in development mode or moved with the arrow
keys. Right-clicking on the link button while in development mode will bring up the Link
Properties dialog so that link properties can be changed or the button can be deleted. In this
dialog, the Link button can be given a name. The name is used to dynamically control the button
attribute for animation, as explained in Chapter 16.
The Browse button facilitates selection of the audio-visual file. If a movie file is selected, EES
will automatically fill in the Width and Height of the movie. These fields can be changed. If the
Lock aspect ratio button is selected, changing either width or height will result in an automatic
change in the height or width to ensure that the original aspect ratio remains unchanged.
564 Chapter 15: The Diagram Window
Clicking the Add Save Inputs button on the tool bar will bring up the Save Button Information
dialog shown in Figure 15-65. The Add Load Inputs button will display a similar dialog. The
button caption, location, and size can be specified in the usual manner. The Name field is used
for animation, as described in Chapter 16. The FileName$ fields shows the current value of the
variable SaveButton.FileName$, which is automatically set by EES to the name of the file to
which the inputs were last saved. This EES string variable can be display on the Diagram
Window as a text item in the same way as any other EES variables. The name can also be
shortened by removing the path information using the ShortFileName$ EES function.
Clicking OK will place the Save Inputs or Load Inputs button on the Diagram Window in a
default location. The button can be moved to another location using the arrow keys or with the
mouse in the usual manner.
Chapter 15: The Diagram Window 565
The Save and Load buttons can only be used in application mode. The Save button is disabled
until calculations have been successfully completed. In this way, it is not possible to write a set
of input information that will not successfully calculate. Both the Save and Load buttons will be
disabled if the Diagram Window does not contain any input variables.
When the user clicks the Save button in application mode after calculations have been
successfully completed, a standard file save dialog will appear in which the name of a file can be
entered. The default name is the same name as the EES file with a filename extension of .var.
The filename and directory information can be changed but the filename extension must be .var
in order for EES to recognize the file. If confirmed, a file containing the current values of all
EES variables in the main program, including the current values of the inputs, is written to the
disk. The .var file for the throttle example considered in this chapter is shown in Figure 15-66.
A .var file is a text file that can be viewed and edited in any text editor. The information
contained in this file includes the variable name, guess value, lower and upper limits, display
format, highlight indicator and units for every variable in the main EES program.
Figure 15-66: Contents of the .var file for the Throttle example.
This .var file can later be loaded with a Load button that has been placed on the Diagram
Window. (The .var file can also be read in the Variable Information dialog by clicking the Open
Variable Info file icon that is located at the upper right of the Variable Information window.) A
standard file open dialog will appear in which a .var file can be selected. The Diagram Windows
will be updated with the values of the variables found in this file.
As an example, we will add a check box to the Diagram Window shown in Figure 15-50 that will
allow us to include or exclude the kinetic energy effects in the throttle calculation. Place the
566 Chapter 15: The Diagram Window
Diagram Window into development mode by pressing Ctrl-D if necessary. Select the Add Check
Box button on the toolbar. A Check Box Characteristics dialog will appear that allows the
caption text, location on the Diagram Window, and font to be specified. In our example, the
caption should read Include kinetic energy effects. Next we need to enter the equations that EES
will solve (together with the all of the other equations in the Equations Window) when the check
box is unchecked and when it is checked. In our case, we need to enter the energy balance for
the throttle without kinetic energy effects when the button is unchecked and with kinetic energy
effects when it is checked, as shown in Figure 15-67. Note that one or more equations can be
entered for each check box condition including comments. If "Execute EES commands when
check status is changed" is selected, EES will attempt to execute the commands in the unchecked
or checked window, depending on the setting of the check box, directly after the change is made
to the check box in application mode. This capability is useful when the check box setting
affects the display in the Diagram Window in some way, but it is not needed in this example.
Figure 15-67: Check Box Characteristics dialog with information entered in order to selectively consider
kinetic energy effects.
Click OK. Drag the check box to the desired location. Changes to the check box characteristics
can be made later by either double-clicking the left mouse button or clicking the right mouse
button on the check box in development mode after selecting the check box. Alternatively, click
the check box to select it and then click the Add Check Box item button on the Diagram tool bar
to edit the check box.
Chapter 15: The Diagram Window 567
The height and width of the check box control are set to default values relating to the height and
width of the text. These dimensions can be modified if desired by selecting the check box
control and using the arrow key while holding the Ctrl key down.
Hide the tool bar. It is next necessary to comment out the energy balance that was entered in the
Equations Window, or alternatively, surround it with $IfNot DiagramWindow / $EndIf directives.
$IfNot DiagramWindow
h[1]+Vel[1]^2/2=h[2]+Vel[2]^2/2 "steady-state energy balance"
$EndIf
Return to the Diagram Window and test the interface with the check box control. Figure 15-68
shows the Diagram Window after calculations are completed without including kinetic energy
effects. Note that the specific enthalpy of the refrigerant is constant in this case. Compare this
result to the result shown in Figure 15-50 which considered kinetic energy effects.
568 Chapter 15: The Diagram Window
Figure 15-68: Diagram Window with results that exclude kinetic energy effects. Compare this result to the
result shown in Figure 15-50.
The number of radio buttons is set with the spin control in the upper left corner of the dialog, or
by entering the value. The number of buttons can be between 2 and 8. The number of columns
controls how the buttons are positioned on the Diagram window. The number of columns can be
between 1 and 4. An optional group caption can be entered for the radio button group. The
background color, width, height, location, and font characteristics can also be specified.
Changing any of these controls will cause the radio button in the dialog window to be redrawn as
it will appear in the Diagram Window.
A radio button group operates in a manner that is similar to a check box. Each button is
associated with EES equations. The caption and EES equations for the currently selected button
appear at the bottom of the dialog. Both the caption and the EES equation for this button can be
modified. For example, we could have implemented the selective consideration of kinetic
energy using a Radio Group instead of a check box. To do so, we would first select the number
of radio buttons to be 2. Next we need to change the caption for Button 1 to be Exclude kinetic
energy effects and enter the energy balance without kinetic energy terms in the edit box below
the caption. Click on Button 2 and change its caption to be Include kinetic energy terms and
enter the energy balance with kinetic energy terms in the edit box below the caption. The result
should be as shown in Figure 15-70.
570 Chapter 15: The Diagram Window
Figure 15-70: Diagram Window with results that exclude kinetic energy effects.
If "Execute EES commands when check status is changed" is selected in the dialog then EES
will attempt to execute the commands associated with the selected button immediately after it is
selected. This capability is most useful when the check box setting affects the display in the
Diagram Windows in some way. For example, a graphic or text item button can be hidden by
setting the EES variable, Name.Hide=true# where Name is the name given to the object. This type
of animation capability is discussed in Chapter 16.
After clicking the OK button, the radio button group will appear in the Diagram Window. In
development mode, the radio button group can be dragged to a new position by pressing and
holding the mouse on the group border while moving the group to a new location. If the left
mouse button is pressed when the cursor is on the lower right corner of the radio button group
then the cursor will change to a resize arrow. Dragging the mouse at this point will allow the
width and height to be changed. (The width and height can also be changed with the arrow keys
Chapter 15: The Diagram Window 571
while holding the Ctrl key down.) Right-clicking (or double-clicking the left mouse button) on
the border of the radio button group while in development mode will brings up the Radio Button
Characteristics dialog so that changes can be made to the item. Alternatively, click the radio
button group to select it and then click the Add Radio Group button on the Diagram tool bar.
For example, we can use a slider to enter the value of the variable P[2], the downstream pressure
for the throttle, in place of the input edit box shown in Figure 15-68. Put the Diagram Window
into development mode by pressing Ctrl-D. Select the input box for P[2] and double-click within
the selection (or click the Add Text button in the Diagram tool bar with the input box selected) in
order to access the Modify Diagram Text dialog shown in Figure 15-71. Click the Slider input
check box. The dialog window will expand to display the parameters for the slider control at the
bottom of the dialog. In this example, we need to restrict the downstream pressure between 100
kPa and the inlet pressure. Enter 100 kPa for the lower limit and P[1] for the upper limit on the
pressure. Note that the limits entered for a variable in this dialog are the lower and upper bounds
that are normally entered with the Variable Information Window.
With the slider set up as shown in Figure 15-71, only integer values will be provided for P[2].
The slider control width will be 100 pixels (approximately 1 inch). The width can be varied
from 60 to 200 pixels. Also, the value that the slider control provides, along with the name of
the variable and its units will be displayed directly above the slider control. Click OK to exit the
dialog. The Diagram Window with the slider control is shown in Figure 15-72.
The slider operates just like other Diagram Window objects. It can be dragged to a new position
by pressing and holding the left mouse button down on the control while sliding the control to
the desired location while the Diagram window is in development mode. The characteristics of
the slider control can later be changed while in development mode by double-clicking the left
mouse button (or by clicking the right mouse button) while the cursor is positioned on the slider
control. Sliding the control from its left position to its right position linearly changes the value
of the variable from its minimum to its maximum value. The changes in the variable value occur
immediately.
572 Chapter 15: The Diagram Window
Figure 15-72: Diagram window with a slider control used to input the downstream pressure.
Bring up the Diagram window in Development mode. i.e., with the tool bar showing. Using the
add/edit text button on upper left of the Diagram tool bar, specify D and L, as output variables.
Next use the add/edit text tool to specify A as an input. Be sure to check the Allow equation box
as shown in Figure 15-75. When this option is checked, the input can be entered as an equation;
otherwise, only numerical values are accepted.
Chapter 15: The Diagram Window 575
Add a Calculate button on the Diagram window using the Add Calculate button at the upper right
of the Diagram tool bar. Right click on the Calculate button to bring up its properties. Rename
the button caption to Submit. Next use the text button on the Diagram window to enter a text
item with instructions for the user. The Diagram window should now appear as seen in Figure
15-76.
To make this problem more interesting, let's use the Random function so that the values of D and
L change each time the answer is submitted. Also, let's add a little function to score the input
and provide feedback. The complete EES code is as follows.
576 Chapter 15: The Diagram Window
Function Checkinput(A,A_c)
If (abs((A-A_c)/A_c)<0.01) Then
Call warning('Got it!')
CheckInput=100
Else
beep 5
Call warning('Your submission is not correct. Try again.')
CheckInput=0
Endif
End D=Random(0.01,0.1,-
1)
L=Random(0.2,1,-1)
A_c=pi*D*L
Score=checkinput(A,A_c)
$HideWindow Equations
$HIdeWindow Solution
The input for A in the Diagram window will accept a value or a numerical expression. Symbols
such as pi, D, and L are also accepted, as shown in Figure 15-77.
Note that, once generated, the values of D and L remain unchanged. This behavior results from
using a negative number (-1) as the third parameter for the Random functions. Each time the
program is opened, new values of D and L are provided but they remain unchanged thereafter.
To have the option of having new values of D and L, enter a New Problem button that resets the
random number generator. To do this, return the Diagram Window to Development mode and
select the Add Calculate button. Select Calculate button. Right click on the Calculate button to
bring up its properties. Entery New Problem for the caption and Reset for the action. Click OK
and position the button on the Diagram window.
Chapter 15: The Diagram Window 577
Hide the tool bar and click the New Problem button. New values for D and L will be generated
and displayed and the input for A will be set to 1. With these capabilities, it is possible to use
EES to generate quizzes.
Figure 15-79: Diagram window after clicking the New Problem button
578 Chapter 15: The Diagram Window
Clicking in the input field for the string variable when the Diagram window is in application
mode will bring up an Open File dialog. The selected file name will be entered in the input field
for the string variable. The string variable cannot be edited as clicking in the input field will
again bring up the Open File dialog.
A simple example will be used to demonstrate how the unit conversions can be accomplished.
This example accepts temperature, pressure, and the name of a selected fluid as inputs. It
outputs the density, specific enthalpy, specific entropy, thermal conductivity, viscosity and phase
of the fluid A listing of the EES program that does the necessary calculations follows
$ifnot DiagramWindow
Chapter 15: The Diagram Window 579
Note the use of the $ifnot DiagramWindow directive in the above example. If the Diagram
window is not open, the unit system, temperature and pressure will be set as shown. Otherwise,
these inputs and the unit system will be set in the Diagram window.
This program can be run as is. However, we want to enhance it by allowing the temperature,
pressure and fluid to be selected from the Diagram window and also allow the user to chose the
unit system. Open the Diagram Window and select Show Diagram Tool Bar from the Options
menu if the tool bar is not already visible. Place a Radio Group control on the Diagram window
by selecting it from the tool bar. Specify two radio buttons and name them SI Units and English
Units. Click the check box to "Execute EES commands when check status is changed". Next
enter the $UnitSystem directive and string variables assigned to the expected units for each of
the inputs and outputs. Figure 15-81 shows the necessary input or the SI Units button. Click the
English Units button and enter the information for the English Units button (Figure 15-82).
580 Chapter 15: The Diagram Window
Figure 15-81: Radio Group showing equations for the SI Units button.
Click OK to finalize the setting of the Radio Group. We next need to specify the inputs and
outputs. Select the text button (abc) from the tool bar and choose T as an input with variable
name and units included as shown in Figure 15-83. Click OK. (Note that it may be necessary to
move the Radio Group to see the temperature input.) Repeat the process for P. Click OK.
Chapter 15: The Diagram Window 581
Repeat the process for R$, but select the string list option, as shown in Figure 15-84. Click the
Edit button to enter the names of the fluids you wish to allow in this example. A suggested list
appears in Figure 15-84. (Note that only real fluids should be selected in this example as ideal
gases do not allow pressure as an input.)
582 Chapter 15: The Diagram Window
Next repeat use the text control to specify output h, s, k, vis, and Q$. Figure 15-86 shows the
dialog for variable h. You may want the outputs to have a different color or font. Repeat the
process for all of the outputs.
Chapter 15: The Diagram Window 583
The last step is to place a Calculate button on the Diagram window using the button at the top
right of the tool bar. The completed Diagram window should now look something like the one
shown in Figure 15-87.
The final step is to assign the string variables to be the units of their respective variables. For
example, TU$ will be set to the units for variable T. This can all be done in one step in the
Variable Information dialog, as shown in Figure 15-88.
584 Chapter 15: The Diagram Window
Click OK. Test the Diagram window by choosing SI and English units. You should see the
units of the inputs and outputs change when a different button is selected.
There are other ways to convert and display the appropriate units for input and output variables.
This example used a Radio Group. A check box or drop-down control would have worked
equally well. Also, in this example, EES was configured to operate in the selected unit system
using the $UnitSystem directive. This is not necessary. The alternative is to always do the
calculations in one set of units, e.g., standard SI, and convert the inputs and outputs to the desired
unit system using the ConvertTemp and Convert functions. For example, the following equation
can be used to convert the input temperature to K
TK=convertTemp(TU$,K,T)
where TU$ is a string variable assigned to the units of variable T. Variable TK will always be in
K. The convert function can be used to convert specific enthalpy and other outputs to the user's
unit system choice, e.g.,
h=hSI*convert(J/kg,HU$)
The Name edit box located in the lower right corner of the dialog allows you to enter the name of
this object. Enter a name in this field, such as Rect1. Note that, as soon as you enter the name,
many of the attribute labels in the dialog are redisplayed with an underline, as shown in Figure
16-1. The underlined labels are associated with those attributes that can be assigned to EES
variables. A list of the programmable attributes associated with the rectangle object is provided
in Table 16-1. (The attributes for an object created with the Add ellipse or circle button on
the tool bar are the same as those of the rectangle object.)
586 Chapter 17: Diagram Window Animation
1. The parameter Name indicates the name of the rectangle or ellipse object.
The programmable attributes have a compound name, with the first part being the name entered
in the Name field for the object (shown as Name in Table 16-1) and the second part, separated by
a decimal point, being the attribute descriptor. Note that these attribute names are EES variables.
The name you provide in the Name field must conform to the EES variable convention which
requires that the name begin with a letter and not include any spaces. Also, the total length of
the compound variable name must be less than 30 characters; therefore, the names that you enter
in the Name field be relatively short. Click OK to close the dialog. Note that array variables can
be used; in this case, the array index must be placed at the end of the variable name so that EES
recognizes the variable name as an array variable. If, for example, you enter a name for the
object to be Rect[1] then the line color attribute would accessed using EES variable
Rect.lineColor[1].
The LineColor and FillColor attributes are color variables corresponding to the RGB color standard.
Many common colors are provided as EES constants, e.g., Black#, Blue#, Green#, Red#, White#,
Chapter 16: Diagram Window Animation 587
and Yellow#. Note that all constants have a # character as the last character in their name. Colors
can also be assigned using the RGB function. The RGB function returns the value of color
formed by providing the red, green, and blue color component values. The component values
can range from 0 to 255. For example, RGB(255,0,0) returns pure red, RBG(0,255,0) returns pure
green, and RGB(0,0,255) returns pure blue. The RGB function allows combinations of red,
green, and blue so that any color can be described.
The LineType attribute is an integer ranging between 1 and 4 corresponding to the line types
defined in Table 16-2.
The FillType attribute is an integer ranging between 0 and 7 corresponding to the fill patterns
defined in Table 16-3.
The hide attribute is a Boolean value that should be either 0 (for false) or 1 (for true). Note that
any value that is non-zero will be assumed to imply true. It is convenient and more readable to
use the EES constants True# and False# when setting the hide attribute.
The position of the rectangle in the Diagram Window is specified with its left and top attributes.
These attributes are expressed in pixels. Most computer systems are configured so there are 96
or 120 pixels per inch. A left position of zero corresponds to the left side of the Diagram
Window and increases moving to the right. A top position of zero corresponds to the top of the
Diagram Window and increases moving downwards. The Width and Height attributes determine
the size of the rectangle and are also specified in pixels. EES provides the functions
DiagramHeight# and DiagramWidth# that return the height and width of the specified Diagram or
Child Diagram Window. The PixelsperInch# function allows the position and size to be computed
in other units and converted to the pixel values needed in the Diagram Window.
588 Chapter 17: Diagram Window Animation
Specifying the angle attribute rotates the object about its center. The angle is specified in
degrees, regardless of the degree-radian setting in the Unit System settings. The object turns
counter-clockwise as the angle is increased.
The attributes of a rectangle object can be set directly in the Equations Window. First, hide the
tool bar so that the Diagram Window is in application mode. Then arrange the positions and
sizes of the Diagram and Equations Windows so that you can see both windows on your screen,
as shown in Figure 16-2. Enter one or more of the equations shown in Figure 16-2 and press F2
to initiate the calculations. You should see the Diagram Window instantly update so that its
attributes are as specified in the Equations Window. This capability provides the basis of the
animation capabilities in EES.
1. The parameter Name indicates the name of the polyline or polygon object.
A text object provides some of the same attributes as the graphic objects, e.g., Left, Top, Color and
Hide. In addition, the text itself can be programmatically specified using the Text$ attribute. This
capability can be used to display customized messages in the Diagram Window.
A very simple program will be used to illustrate this capability. Open EES and enter:
X=1
in the Equations Window. Now, move to the Diagram Window and place it in development
mode by entering Ctrl-D so that the tool bar is visible. We will add two text items by selecting
the Add Text button on the tool bar. The first text item is an input variable text object for the
variable X. The second item is a text object that displays a customized message depending on the
value of X. In this example, one message will be displayed if the variable X is less 0 and a
different message will be displayed if X > 100. Name the text object Message, as shown in
Figure 16-3
Figure 16-3: Add Diagram Text Item dialog showing entry for a text item named Message.
Hide the tool bar to enter application mode and return to the Equations Window. Delete the
equation that sets X = 1 and enter the following Procedure and Call statement. Note that the
Chapter 16: Diagram Window Animation 591
procedure SetMessage has inputs X and sets the values of two outputs, Message$ and Color. The
string variable Message$ is assigned a string corresponding to the message to be displayed and
the numerical variable Color is assigned a value corresponding to the color of that message.
Calling the procedure SetMessage with Message.Text$ and Message.Color as the outputs sets their
values and therefore changes the attributes of this text item in the Diagram Window.
Procedure SetMessage(X:Message$,Color)
Message$=' '
Color = Black#
If (X > 100) Then
Color = Red#
Message$ = 'X must be less than or equal to 100'
Else
If (X < 0) Then
Color = Blue#
Message$ = 'X must be greater than or equal to 0'
EndIf
EndIf
End
{X=1}
Call SetMessage(X: Message.Text$,Message.Color)
Return to the Diagram Window and place it in application mode in order to test the program.
Enter a value of 200 for X and press F2 to solve. You should see a red message in the diagram
window, as shown in Figure 16-4. A blue message will appear when you press F2 if a value of X
less than zero is entered. There will not be a message is X is between 0 and 100.
Table 16-8: Programmable attributes for buttons, radio groups and check box objects.
1. The parameter Name indicates the name of the button, radio group, or check box object.
Table 16-9: Additional programmable attributes for radio groups and check box objects
2. The color can be specified with the RGB function or with defined values, e.g., Red#
ABC.Hide=true#
You can alternatively enter:
ABC.Hide
The alternative .Show and .Hide formats are particularly convenient when used within the
Diagram window, as described in the following section.
Internally, EES converts ABC.Hide into ABC.Hide=1 and ABC.Show into ABC.Hide=0. Note
that ABC.Hide is an EES variable in the main section of the Equations Window. The variable
ABC.Hide will be recognized in the main block of code in the Equations window and anywhere
in the Diagram windows. However, it will not be recognized within a function, procedure,
module or subprogram. It is often necessary to use a function to conditionally control the
visibility of an object. This can be easily done by having the function return a 0 (for false#) or 1
for true#) and assigning this return value to the object's hide attribute, e.g.,
function ShoworHide(X,Y)
if (X>Y) then ShoworHide=True# else ShoworHide=False#
end
Chapter 16: Diagram Window Animation 593
...{Set X and Y}
...
ABC.Hide=ShoworHide(X,Y)
Note that, you can hide or show multiple Diagram objects with one command if they are
grouped, as described in Section 15.6.
Start EES and enter the following equation into the Equations window.
Y=X^2
Of course, this equation can not be solved without more information. One way to provide this
information is with a Parametric Table. Select the New Parametric Table command from the
Tables menu and create a Parametric Table with 10 rows containing columns for the variables X
and Y. Enter values for X in the table that range from 1 to 10. Select the Solve Table command
from the Calculate menu (or press F3) in order to solve the table, as shown in Figure 16-5.
594 Chapter 17: Diagram Window Animation
Select the Diagram Window command from the Windows menu (or enter Ctrl-D). Make sure
that the Diagram Window is in development mode. We are going to place five objects on the
Diagram Window. First, add a Calculate button by clicking the Add Calculate button on the tool
bar. Set the Caption to be Solve and also name the button SolveButton, as shown in Figure 16-
6(a). Note that the left position of the button is set to 35 pixels and the top is set to 44 pixels.
Add a second calculate button with the caption Solve Table and give it the name
SolveTableButton, as shown in Figure 16-6(b). Set its top position to 44 pixels. Select the Skip
confirmations check box for both buttons.
(a) (b)
Figure 16-6: Calculate Button dialog for the (a) Solve button and (b) Solve Table button.
Use the Add Text button to make the variable X an input variable. Give the input text item a
name, e.g. Xinput as shown in Figure 16-7(a). Use the Add Text button and add an output text
item that displays Y; give this output text item a name, e.g., Youtput as shown in Figure 16-7(b).
Chapter 16: Diagram Window Animation 595
Select the Add Text button one more time and click the Input variable button. Select *** New
String Variable *** from the list and enter DD$ as the name for the string in the box that appears, as
shown in Figure 16-8. Click the OK button and the variable DD$ will be displayed in the list.
The Include units check box will change to Use string list with and Edit button, as shown in
Figure 16-10. Click the Edit button and enter the strings, as shown in Figure 16-9.
(a) (b)
Figure 16-7: Modify Diagram Text Item dialog for (a) the input variable X and (b) the output variable Y.
Figure 16-8: Add a new string variable that will be used for drop-down text.
596 Chapter 17: Diagram Window Animation
Figure 16-9: Drop-down strings for string variable DD$ which control objects in the Diagram Window.
There is one more change to make. Because the drop-down list is providing control information
for other text items on the Diagram Window (Xinput and Youtput), it is preferable for the drop-
down list to be the first object that is processed. This is accomplished by setting its Tab order to
1, as shown in Figure 16-10.
Figure 16-10: Dialog window for the DD$ variable with the Tab order highlighted.
Click OK and hide the Diagram Window tool bar. The Diagram Window that we have created
can now be tested. When you select Solve from the drop-down control, it will immediately
execute the EES commands to the right of the // characters in Figure 16-9 (which are not visible
in the drop-down list). In this case, the Solve Table button will be hidden and the X variable
input and Y variable output will be made visible so that you can enter a value for X. The
Parametric Table is not used with the Solve command, so it can be hidden using the $HideWindow
directive, discussed in Chapter 14. Clicking the Solve button will solve the equations in the
Equations Window and display the corresponding value of Y, as shown in Figure 16-11(a).
Chapter 16: Diagram Window Animation 597
Selecting Solve Table from the drop-down list will hide the Solve button as well as the text input
for X and text output for Y. The Solve Table button will become visible. The left position of the
Solve Table button is set to 35 pixels, which puts it exactly at the same position as the Solve
button. The $ShowWindow Parametric directive displays the Parametric Table.
(a) (b)
Figure 16-11: Diagram Window appearance when the (a) the Solve and b) the Solve Table options are
selected from the drop-down menu.
Set the Diagram window into development mode by pressing Ctrl-D until the tool bar appears.
Next, click on the left edge of the drop-down group to select it and the press the Delete key.
Click the Add Check Box button on the tool bar. The Check Box Characteristics dialog will
appear. Set the caption to be Use the Parametric Table. The check box control will execute the
equations in the upper edit box when its state is changed to unchecked. The equations in the
lower edit box will be executed when its state is changed to checked. Enter the equations shown
in Figure 16-12, which are the same as those used in the drop-down menu example. Hide the
toolbar and test the operation of the check box control.
click the second button and enter its information, including the command RadioButtonGroup.Color
= Green#.
.
Figure 16-13: Radio Button Characteristics dialog showing information for the Solve button.
Chapter 16: Diagram Window Animation 599
Hide the tool bar and test the radio button control. It should operate just as the check box
control, except that the radio group will be yellow when the Solve command is selected and
green when the Solve Table command is selected, as shown in Figure 16-14.
(a) (b)
Figure 16-14: Diagram window appearance for a) the Solve and b) the Solve Table radio button options.
Controlling the Equations Window with Check Boxes and Radio Button Groups
The check boxes and radio button groups can provide much more control over an EES program
than is initially evident. On way to apply this control is to have the check box or radio group set
a string variable that is used with a $If directive to include or exclude code in the Equations
window. The following very simple example demonstrates this capability.
Start a new instance of EES and enter the short program shown in Figure 16-15. The program
will not run because string variable DoThis$ is not set.
Figure 16-15: Equations Window using the $IF directive to include or exclude equations.
In this example, string variable DoThis$ will be set in a radio button group. Bring the Diagram
Window to the front and put it into development mode by entering Ctrl-D if necessary. Select
the radio group button from the Diagram Window toolbar and then configure a radio button
group with two buttons, Add and Subtract. Only one line of code is needed for each button and
that line sets DoThis$ to 'Add' or 'Subtract', as shown in Figure 16-16a. For convenience, also
place a Calculate button on the Diagram window, so that the Diagram window appears as seen in
Figure 16-16b. The $If directive is a compile-time instruction. However, the objects in the
Diagram window, such as the radio button group, are evaluated before compilation is initiated.
Consequently, the setting of the radio button can control what equations are included or
excluded, as demonstrated in this example.
600 Chapter 17: Diagram Window Animation
(a) (b)
Figure 16-16: a) Radio button group that sets DoThis$ and b) Diagram window with Radio Group.
$DiagramUpdate Off and On directives can be placed around Functions, Procedures, Modules,
and/or Subprograms in the Equations window that do not need to be recompiled during the
Diagram window updating process. $DiagramUpdate Off will cause all following equations to
be ignored until a $DiagramUpdate On directive is found. Skipping compilation of the code
enclosed within the $DiagramUpdate Off and $DiagramUpdate On directives can result in a
significant speedup in the response time to changes in the Diagram window controls.
Note that the $DiagramUpdate directive should not normally be placed in the Main program as
this will likely generate compilation errors. Also a $DiagramUpdate Off must be provided after
a $DiagramUpdate On directive or an error will occur. The $DiagramUpdate directives are
ignored if there is no Diagram window or if the Diagram window not being changed.
Chapter 16: Diagram Window Animation 601
A very simple model will be used to illustrate two methods to designate inputs and outputs. The
model is the simple equation
A+B+C=0
This model consists of one equation with three variables and therefore it has two degrees of
freedom, i.e., the values of two of three variables must be specified to calculate the value of the
third variables. However, there known variables could be A and B, A and C, or B and C. We
want the user to select which set of variables are to be specified.
Figure 16-17: Using the Text button to add input (left) and output (right) controls for variable A
Repeat this process for variables B and C. At this point, the Diagram window may appear as
shown in Figure 16-18.
Figure 16-18: Diagram Window with input and output controls for variables A. B. and C.
Next, right click on each of the input and output controls and select Properties from the popup
menu. The Modify Diagram Text Item dialog will appear. All the is needed is the provide a
name for the text control. Figure 16-19 shows that the input and output text items for variable A
are named A_input and A_output, respectively. Repeat for variables B and C.
Chapter 16: Diagram Window Animation 603
Figure 16-19: Setting names for the input (left) and output (right) text items.
The next step is to add a Diagram control that allows selection of which inputs and outputs are
active. The simplest control is a Radio Button group. Select the Radio Button group by clicking
the lower right button on the Diagram tool bar. Specify 3 radio buttons with 1 column. Set the
captions of the buttons to Enter A and B, Enter A and C, and Enter B and C, as shown in Figure
16-20. Enter equations for each button that will hide two of the inputs and one of the outputs and
show the remaining text items. The necessary equations for the Enter A and B button are shown
in Figure 16-20. Be sure to check the "Execute EES commands when status is changed" button
located above the OK button. This will result in immediate changes when the radio button
control is changed.
604 Chapter 17: Diagram Window Animation
Figure 16-20: Radio button characteristics showing the equations for the first button.
The final step is to move the text controls so that the input and output controls are located exactly
on top of each other for A, B, and C. Add a Calculate button for convenience. The completed
Diagram window should appear as shown in Figure 16-21. Clicking the Radio button control
opens two inputs boxes in which values can be entered. Clicking OK displays the result of the
third variable.
Figure 16-21: Completed Diagram window that allows two inputs and one output.
Chapter 16: Diagram Window Animation 605
Open EES and enter A+B+C=0 into the Equations window. Open the Diagram window and set
it into Development mode so that the Diagram tool bar is showing. Click the Text (abc) button
in the toolbar. Click Output variable and select variable A. Click OK. Repeat for B and C.
Click the Text button again and click Input variable. Select *** New String Variable *** from
the variable list shown on the left in Figure 16-22. EES will prompt you to enter a string
variable name (Figure 16-22, right). Enter A$ (or any string variable name. It must end with a
?).
Figure 16-22: Creating string variable A$ and setting it to be input from a string list.
Uncheck the Include Variable Name option. Check the Use string list and Format Display
buttons, as in F Click the Edit button and enter the following information:
Input A //A=?
Output A
Repeat this process two more times, defining string variables B$ and C$.
606 Chapter 17: Diagram Window Animation
Figure 16-23. Setting string variable A$ to be input from a drop-down string list.
This process sets up a drop-down string list to define string variable A$. A$ can be set to Input
A or to Output A. Note the //A=? following Input A. When the Format display check box is
selected, //A=? is not displayed in the drop down list. Rather it is interpreted as an instruction to
EES. EES recognizes A=? to mean that variable A should be considered an input. When Output
A is selected, the //A=? is not provided and A reverts to an output. The completed Diagram
window with a Calculate button added appears in Figure 16-24. The user can choose which two
variables are to be inputs. An error will result if less or more than two inputs are selected.
Creating an animation with EES is simple. The first step is to draw the object in the Diagram
Window using either the drawing tools provided in EES or an external drawing program such as
Power Point, as described in Section 15.1. The object must be given a name in the name field of
the object properties dialog so that its attributes become active, as described in Section 16.1.
Equations must be entered into the Equations Window to specify the attributes as needed. The
Diagram Window display is continuously updated as the attributes change. Therefore, attributes
that are changed within a Parametric or Integral Table will cause objects to become animated, as
demonstrated with the examples provided in this section. The final step is to add an animation
control bar to the Diagram Window. This is done by selecting the Add Calculate button in the
Diagram Window tool bar when the Diagram Window is in development mode. The dialog
shown in Figure 16-25 will appear.
.
Click the Animation Control Bar button to place an animation control bar on the Diagram
Window. The animation control bar can be dragged to the desired location on the window by
pressing and holding the left mouse button while the cursor is positioned anywhere on the first
four buttons by sliding the mouse to a new location. The functions of the controls on the
animation bar are identified in Figure 16-26.
608 Chapter 17: Diagram Window Animation
$UnitSystem Degree
Ball.Left=X
Ball.Top=150 + 100*sin(X)
Create a Parametric Table with 361 rows that has columns for the variables X, Ball.Left, and
Ball.Top. Enter values for X that range from 0 and 360. Return to the Diagram Window. Click
the Add Calculate button on the tool bar and select the Animation Control Bar from the dialog
that is shown in Figure 16-25. Right-click on one of the buttons in the animation control bar to
bring up the Animation Characteristics dialog in Figure 16-28. Select the Solve Table button.
Since there is only one Parametric Table, the table choice should already be set to Table 1.
Chapter 16: Diagram Window Animation 609
Hide the Diagram Window toolbar so that the Diagram Window is in application mode. You
may also want to hide the Parametric Table. Click the Start button ( ) on the animation
control bar and watch the show. As each row of the Parametric table is solved, new values are
assigned to the variable Ball.Left and Ball.Top. The position of the object Ball will change as its
attributes change. The slider in the animation control bar controls the speed at which animation
proceeds. Click the Pause button ( ) to pause the animation. The Stop button ( )
halts the animation. When paused or stopped, clicking the step button ( ) will move the
animation forward by one step, which in this case means that the next row in the Parametric
Table will be solved and the Diagram Window updated accordingly. Note that the current row
in the Parametric Table is displayed as Run# in the animation control bar. If you click the
Loop button ( ) then the animation will restart when it reaches the end of the Parametric
Table. The number of times that the animation has been restarted is displayed to the right of
the Loop button in the animation control bar. All graphic and text items in the Diagram
Window can be animated in this same way.
The animation can also be coupled to one or more plots. To demonstrate this capability, create a
new plot in which the X-axis is set to the variable Ball.Left and the Y-axis is set to the variable
Ball.Top. Right click on the plot and select the Automatic Update checkbox. Start the animation
with it set to loop and watch the plot. Notice the red circle that shows the current point in the
simulation as the animation progresses, as shown in Figure 16-29.
610 Chapter 17: Diagram Window Animation
Figure 16-29: Plot window for the animation of the graphic object Ball.
Each animation file that is saved will have the file name Frame_XX.yyy where XX is a
sequential number that starts at 1 and ends with the last frame saved. The extension yyy
corresponds to the file type extension which can be .emf, .jpg, or .bmp, as selected from the File
Type drop-down control in Figure 16-30. It is best to place these files in a separate directory.
Enter the directory name in the edit box field or use the Browse button to locate an existing
directory. If the Save every control is set to 1 then a file will be saved for every frame in the
animation. If it is set to 2 then a file will be saved for every second frame, and so on. Click OK
to generate the files. Once the files are created in the specified folder, they can be used to create
a movie file using Microsoft Movie Maker or other software, as described in Section 9.2.
velocity of the cannon ball is Vin = 100 m/s. The cannon ball experiences standard gravity and
i
air resistance during its flight. The drag coefficient is Cd = 0.6.
Let's solve this problem and then animate the solution. The inputs are entered in EES.
$UnitSystem Degree
$TabStops 3.5 in
The density of iron (ball) is obtained using the rho_ function which accesses the properties of
incompressible substances and the density of air (a) is obtained using the Density function which
accesses the properties of compressible substances. The use of property functions in EES is
discussed in Chapter 4. The volume and projected area of the cannon ball (Vball and Aball) are
obtained from:
=
4 D 3 (16-1)
V
ball
3 2
Aball = D
2
(16-2)
4
ini cos ( )
Vx ,ini = V (16-4)
ini sin ( )
Vy ,ini = V (16-5)
We are going to solve this problem by animating the results of a simulation carried out using the
numerical integration capability in EES that is associated with the Integral command, discussed in
612 Chapter 17: Diagram Window Animation
Chapter 7. The first step in this process is to set the state variables and integration variables to
some arbitrary values and then verify that it is possible to calculate the derivatives of the state
variables. For this problem the state variables are the x- and y-positions of the cannon ball and
the velocity of the cannon ball in the x- and y-directions. The integration variable is time (t).
The derivatives of x and y position with respect to time are simply the velocity components of
the ball.
dx
= V (16-6)
x
dt
dy
= V (16-7)
y
dt
dx = C A Vx2 (16-8)
m d a ball
ball 2
dt
m
dy
= g C A Vy2 (16-9)
ball d a ball
dt 2
m_ball*dVel_xdt=-C_d*A_ball*rho_a*Vel_x^2/2 "calculate dVel_xdt"
m_ball*dVel_ydt=-m_ball*g#-C_d*A_ball*rho_a*Vel_y^2/2 "calculate dVel_ydt"
With the state equations implemented it is possible to comment out the values of the state
variables
and use the Integral command to numerically carry out the integrations:
tsim
x= +dx dt (16-10)
0 dt
Chapter 16: Diagram Window Animation 613
tsim
y= +dy dt (16-11)
0 dt
The result of the integration is stored in an Integral Table using the $IntegralTable directive.
$IntegralTable time,Vel_x,Vel_y, x, y
A circle and rectangle are drawn and placed on the Diagram Window to form an object that
looks like a cannon, as shown in Figure 16-31. These two objects are selected and grouped by
right-clicking and selecting the Group option from the pop-up menu. The group is given the
name Cannon by double-clicking on the object and entering Cannon in the name field, as shown
in Figure 16-32(a) and (b). Input text items are placed on the Diagram Window for the variables
theta and Vel_ini, as shown in Figure 16-31, and the equations specifying these variables are
commented out:
The Angle attribute of the object Cannon (Cannon.Angle) is specified according to the value of the
variable theta that is set by the user:
Cannon.angle=theta
The Left and Top attributes of the object Ball (Ball.Left and Ball.Top) are specified according to the
values of the variables x and y:
Ball.left=113+x Ball.top=524-
y
614 Chapter 17: Diagram Window Animation
(a) (b)
Figure 16-32: Diagram Object Characteristics dialog for (a) the cannon and (b) the ball.
The final step is to place an animation control bar on the Diagram Window. Click the Add
Calculate button and select Animation Control bar from the dialog shown in Figure 16-25. The
default action for the animation control bar is to Solve the equations (rather than Solve Table), so
no changes are necessary. You can ensure that the control bar is set to Solve by right-clicking on
it.
Chapter 16: Diagram Window Animation 615
Hide the Diagram tool bar so the Diagram window is in application mode. Enter 30° for the
variable theta and 100 m/s for the variable Vel_ini. Click the green arrow in the animation control
bar to start the animation and select the loop button so that it continuously replays, shooting
cannon ball after cannon ball. Note that the value of the integration variable (which is time in
this example) is displayed in the animation control bar.
A little imagination can be applied to improve this program. For example, we could find a
picture of a cannon on a website, copy it, and replace the circle/rectangle approximation of a
cannon. We could also add a moving target that the cannonball is intended to hit.
There are many interesting animation examples in the Examples folder, which can be accessed
from the Examples menu at the right of the menu bar in EES. Select the Animation menu item.
You can look at the EES code associated with these examples to see how they work. The
information in this chapter should provide you with the background to understand these
examples and the ability to create your own animations.
17 DISTRIBUTABLE PROGRAMS
Chapter 15 describes how graphic and text objects can be placed on the Diagram Window.
These capabilities allow a graphic user interface to an EES program to be created so that inputs
can be entered and used to calculate results without requiring the user to view or understand the
equations that are used to carry out the analysis. Chapter 16 describes further capabilities of this
graphic user interface including the ability to modify the interface based on user input and
display animated output. This chapter describes a very powerful capability provided in the
Professional version in which one or more (up to 100) EES programs can be packaged into a
Distributable Program. The Distributable Program can be provided to users who do not have
EES installed on their computer. A license to use EES is not required. Distributable Programs
provide an ideal method for distributing EES programs to a wide variety of users. This chapter
will show how these Distributable Programs are made.
617 Chapter 17: Distributable Programs
As an example, we will convert the EES program that carries out the throttle analysis developed
in Chapter 15 into a Distributable Program. This file is named Throttle.ees (or Throttle.ees64 in
the 64-bit version) and it is provided with the EES program. You will find this file in the
UserLib\Examples folder within the folder that EES has been installed. You can navigate to this
file more quickly using the Examples menu at the right of the menu bar. Select the Professional
Version and then open the file identified as Distributable example – Throttle.
Select Diagram Window from the Windows menu or enter Ctrl-D to bring the Diagram Window
to the front in application mode, as shown in Figure 17-1. Note that Save and Load buttons have
been added to the Diagram Window to allow the user to save and load inputs. It would be wise
to save an input file named Throttle_Defaults.var that can be used to restore the default values
for this problem.
618 Chapter 17: Distributable Programs
This EES program has many of the characteristics that are appropriate for a distributable
program:
1. The program provides useful information that can be understood by persons other than the
developer of the program.
2. All of the inputs can be entered in the Diagram (or Child Diagram) Window.
3. Outputs from the analysis are displayed in the Diagram Window. They may also be
displayed in other windows as plots or tables, but it is usually more convenient for the user to
see the important results in the Diagram Window.
A limitation of this program is that it is written in EES, which (in theory) would mean that only
users who have a license to use EES can benefit from running the program. However, this
program can be converted into a special purpose Distributable Program that can operate
independent of the EES software. The license agreement in EES requires that Distributable
Programs cannot be sold by the Developer; they must be provided to users at no cost.
Once the program has been developed, tested, and provided with a graphical user interface using
the Diagram Window, it is ready to be converted into a Distributable Program. To do this, select
the Make Distributable Program menu item from the File menu. The message shown in Figure
17-2 will appear the first time that this command is used.
Chapter 18: Macros 619
Figure 17-2: Confirmation that Distributable Programs cannot be sold by the developer.
Click the I agree button to proceed. The Distributable Program Setup dialog shown in Figure 17-
3 will appear. This dialog allows all of the information concerning the Distributable Program to
be entered. This information should be entered with some care because it will not be possible to
change the information after the Distributable Program is released.
One consideration in creating a Distributable Program is which version of EES to use. The EES
setup program provided two versions, one having 3-D plotting capability. The 3-D plotting
routines that are used by EES employ graphic software that may not be compatible with all video
cards. Unless your Distributable Program uses 3-D plotting, it would be best to create the
Distributable using the version of EES that does not provide 3-D plotting capability.
The distributable program must have a .exe file name extension. The default name that will
initially appear in the EXE Name edit field is the complete name (with the directory) of the EES
file that was open when the Make Distributable command was issued, but with the .ees
(or.ees64) extension changed to .exe. Edit this field so that the distributable program is saved
appropriately. It is recommended that you do not save the distributable file in the same directory
as the EES.exe file since it will then load the Userlib (or Userlib64) folder that is included with
EES. Note that if the directory that you enter does not exist then it will be created when you
click OK.
A splash screen will appear each time that the Distributable Program is started. The text that
appears on the splash screen can be entered on the three lines in the splash screen message box.
You can enter whatever you wish here, but you should enter something.
EES can use either a decimal point (U.S. setting) or a comma for the decimal separator character.
This choice is made when EES is started and controlled by the Regional setting choices made in
the Control Panel of the operating system. However, if the US setting check box is selected in
Figure 17-3 then the Distributable Program will use the U.S. setting (i.e., a decimal point
separator) regardless of the regional settings associated with the computer that it is run on. This
option avoids some compatibility problems that may occur if a Distributable Program is made
and run with different regional settings.
EES provides several methods to restrict the use of the distributable file. The first is password
protection. If the Passwd: check box is selected then a space for a password will appear and
users will be required to provide this password in order to use the Distributable Program. When
the user starts the Distributable Program, they will be challenged to enter a password in the
dialog shown in Figure 17-4. Note that the password is case sensitive and there is no way to
recover the password if you lose it, so be careful.
Use of the distributable file can also be controlled using an expiration date. If the Expires check
box is selected then the date field will become enabled and an edit control will become visible
where you can enter the message that will be displayed if the Distributable Program is started
after the expiration date, as shown in Figure 17-5. Providing an expiration date for the
Distributable Program is recommended, as you may not wish to have the Distributable Program
available for use years in the future when newer and improved versions are available.
Figure 17-5: Information that can be entered if the Expires check box is selected.
Chapter 18: Macros 621
As described above, a message consisting of three short lines of text can be placed in the splash
screen that appears when the program is started. A more extensive message that appears after
the splash screen is dismissed can also be shown by clicking either the Display figure in file or
Show following message button in Figure 17-3. If the Display figure in file is selected then an
edit box will appear where you can enter the name of a .bmp, .jpg or .wmf file. The Browse
button will be enabled to help locate the file. The figure could provide any graphics and/or
information that you wish to display. If the Show following message button is selected then an
edit box will appear where you can enter a message with up to 1024 characters, as shown in
Figure 17-6.
Figure 17-6: Entering a message that appears when the distributable program is started.
The message that is entered can also be accessed by the user while running the Distributable
Program by selecting the View startup message menu item in the Help menu, as shown in Figure
17-7.
Figure 17-7: Access to the startup message is provided in the Help menu of the Distributable Program.
A Distributable Program file can provide access to one or more (up to 100) different programs.
The method for entering the program information is provided in Section 17.2. If more than one
program is included then a menu will be provided in the main menu bar when the Distributable
Program is running, as shown in Figure 17-8. The menu will list the names of each of the
programs that are included in the distributable file. Selecting the program from this menu closes
the current program and opens the selected program. The default name of the menu is
Distributable Files (as shown in Figure 17-8). However, you can enter a more descriptive name
for this menu in the edit field at the bottom of the distributable startup dialog shown in Figure
17-3.
Figure 17-8: Menu provided when the Distributable Program includes more than one file.
Two small buttons are provided just below the Cancel button in the Make Distributable dialog
shown in Figure 17-3. These buttons allow saving and loading of scripting files that simplify the
process of creating Distributable Programs. The save button ( ) saves all of the information
622 Chapter 17: Distributable Programs
contained in the Make Distributable dialog (including the file information that is described
Section 17.2) into a file having an .mdi (Make Distributable Information) filename extension.
Click this button after you have entered all of the information needed to create the distributable
file and before you click the OK button. The load button ( ) will open an .mdi file and use
the stored information in order to fill in all of the fields in the Make Distributable dialog. You
will likely need several attempts to set up your distributable file so that it looks and behaves
exactly as you want. Using these buttons assures that you will not have to repeatedly enter
the same information each time.
Figure 17-9: File Information tab of the Distributable Program Setup dialog; note that one of these must be
filled out for each EES program that is included.
The first time that you display the File Information tab, it will show information for the first EES
file that is to be included; by default this is the EES file that was open when the Make
Distributable menu command was issued. The first edit box contains the name of the EES file
Chapter 18: Macros 623
that will be integrated with the Distributable Program. Use the Browse button to help locate the
file if the file name shown in the edit box is not the file that you wish to include.
The next edit box provides an (optional) opportunity to enter a help file for this program. The
help file can provide instructions for using the program, background information, credits, or
whatever you wish. The help file can be an .htm, .pdf, .txt, or .chm file. Use the Browse button
to locate the file. Note that the Browse button will insert the Help file with ..\ in front of the file
name. The ..\ refers to the directory that the distributable program is started in. The help file
will need to be placed in the same directory as the distributable file so that it can be opened as
needed. Unlike the EES file, the Help file is not built into the distributable file and therefore it
must be included as a separate file and installed in the correct directory with the distributable
file.
Perhaps the easiest way to create a help file is to enter the information that you wish to be
included into a Microsoft Word document and use the ‘Save as web page’ menu item from the
File menu in order to save tit as a .htm file. This type of file can provide links to other files on
the web, if you wish. The help file included for each program will be accessible in the Help
menu in the menu bar and labeled using the text provided in the Menu text field in Figure 17-9.
The result is shown in Figure 17-10 for the Throttle program. You can also provide a Help
button on the Diagram Window that will directly access this file by clicking on the Add Help
button ( ) on the Diagram Window tool bar.
Figure 17-10: Help menu showing access to the help file for the Throttle distributable program.
The remaining file information is provided using check boxes. These selections are, for the most
part, self-explanatory. By default, the equations in the EES code are built into the distributable
file in a manner such that they can be viewed by the user. However, if you uncheck the
Equations Window visible and Formatted Equations window visible check boxes then users will
not be able to see your equations. This capability may be important if these equations contain
proprietary information. The Equations Window can also be set so that it is read only. However,
even if this option is not selected and the user is allowed to change the equations, the modified
program cannot be saved as it is an executable file.
A Distributable Program is normally designed around the Diagram Window. Therefore, you will
usually want to have the Diagram Window foremost at startup. If the Maximize windows check
box is selected then the Diagram Window will fill the screen and you can then select the Adjust
Diagram Windows to Fix Screen check box in order to increase or decrease the size of the
objects in the Diagram Window so that they fit the adjusted size of the Diagram Window. The
remaining check boxes control access to other EES windows.
624 Chapter 17: Distributable Programs
All of the information in the File Information tab of the Distributable Program Setup dialog
refers only to the specific EES program entered in the File name field. Additional EES programs
can be included in the distributable file by incrementing the file number at the top of the file
information dialog shown in Figure 17-9. The up and down arrows can be used to change the
file number. For example, if you change the file number to 2 then the file name field will be
blank. You can use the Browse button to select another EES file, e.g., the Ball animation file
that was created in Chapter 16, to include in the distributable program. Click the save button
( ) to save all of the file information.
The View and Reorder Files tab in the Distributable Program Setup dialog provides an overview
of the programs that will be included in the distributable file. This dialog is only useful when the
distributable file will include more than one EES program. All of the programs that will be
included are displayed in a list, as shown in Figure 17-11. As shown, the menu names of the
program are listed. Click the Show file names button to display the complete EES file name
(including directory information) in the list. Click the Show menu names button to display the
names of the files as they will appear in the Distributable Files menu that will appear to the right
of the Help menu in the EES menu bar. It is possible to change the order of the files in this
directory. For example, to make the Ball program the first program in the Distributable file,
press and hold the left mouse down while the cursor is on the Ball entry and move the mouse so
that the mouse cursor is above the Throttle entry. Up to 100 files can be placed in the
distributable file, so this view can be helpful to ensure that the desired files have been selected
and properly ordered.
When the distributable program is started, the first program will automatically be loaded by
default. However, any one of the files can be selected as the file that appears at startup by
Chapter 18: Macros 625
providing /# as a parameter where # is an integer between 1 and 100. For example, entering
MyPrg.exe /2 in the Windows Run dialog will open the distributable file named MyPrg.exe and
start program 2.
Figure 17-12: Dialog to allow selection to files to include in the ..\Userlib folder for the distributable file.
The Notice! dialog requires some explanation. The .exe file that is created includes most of the
files needed to run the program in the distributable file, but it may not include all of the
information that is needed. The files that are not automatically built into the .exe are:
1) the optional help files for each EES program;
2) any .var files that are created when you click the Save button on the Diagram window; and
3) any external library files that are used by the EES programs in the distributable file.
As noted in Section 17.2, it is best not to refer to a specific directory in the File Information
dialog because a user may wish to install the distributable file in a different directory than you
expected. Help files are usually placed in the same directory as the .exe file. The Help file name
that begins with ..\ tells the distributable program to look for the file in the same directory as the
executable file. Therefore, all of the help files that will be needed by the distributable program
must be placed into the directory that the executable file will be saved in.
626 Chapter 17: Distributable Programs
The only way for users to save input data entered in the Diagram Window is with a Save button
placed on the Diagram window. The Save button saves a .var file that includes all current
variable information. A Load button allows the user to read a selected .var file. If the
distributable file provides a Save button then it is a good idea to provide a default .var file with
the program that contains default data in case the user enters incorrect data and cannot run the
distributable program. You may wish to make the default .var file read only so that it cannot be
accidently modified. Copy all of the .var files that you wish to distribute with the executable into
the directory that the .exe file will be saved in.
One or more of the EES files that you have included in the distributable file may require an
external library file. These files are normally provided in the Userlib (or Userlib64 for the 64-bit
version) folder of the EES program. For example, perhaps one of your EES programs uses the
functions that are included with the Heat Transfer library discussed in Chapter 12. If so, that
particular external library must be provided in a Userlib (or Userlib64) folder that is installed in
the same directory as the executable file. The dialog shown in Figure 17-12 lists all of the
external library files that are installed with your version of EES. If any of the EES files in the
distributable program uses one of these library files, click on the library name so that it appears
with a check. After creating the .exe file, EES will create a Userlib (or Userlib64) folder in the
same directory as the .exe file and copy all of the library files that you have checked into the
Userlib (or Userlib64) folder. (This is another very good reason for saving your .exe file in a
different directory than the directory that the EES.exe file is located in.) Click the Include button
to navigate to and select any additional external files that are not displayed in the list. These
additional files will also be placed in the Userlib (or Userlib64) folder in the directory with the
.exe file.
The complete distributable package that should be provided to users must include the .exe file,
any help files and .var files that you wish to include and the Userlib (or Userlib64) folder
containing all external library file that are used by the EES programs in the distributable file.
These external files in the Userlib (or Userlib64) folder will automatically load when the .exe is
started.
It is convenient to provide a single file to users. This can be accomplished by using WinZip® or
other program to compress all of the files located in the directory that the .exe file is located,
including all help files, .var files and all files in the Userlib (or Userlib64) directory, into one .zip
file. You should copy this .zip file to another directory, unzip it and test that it operates as
expected. This one file can then be distributed to users. The user can unzip this compressed file
to restore the directory with all of the necessary files, ready to use.
In some cases, you may with to customize the icon associated with the Distributable program.
The easiest way to do this is to create a short-cut to program. Right-click on the short-cut and
select Properties from the pop-up menu. Click the Change Icon button and supply a file name
containing an alternative icon.
Chapter 18: Macros 627
18 MACROS
A macro is a set of instructions to EES that is read from an ASCII file or from the EES Macro
Window. If you are familiar with MATLAB, the macro capability is similar in many respects to
a MATLAB script. Macro commands can instruct EES to automatically open a file, solve the
equations, create and solve a table, store calculated results in a file, print, plot, etc. In fact all of
the capabilities that are provided with the menu commands and directives in EES can also be
implemented using macro commands. In addition, macros can apply additional commands, such
as for communicating with external programs (e.g., MATLAB or EXCEL) or the serial port.
Macros can also work with the operating system commands to change directories, delete files,
and pick out and open all of the files of a particular type from a folder. There are many
advantages to using macros. First, macros allow a set of repetitive tasks to be scripted so that
they can be re-executed with a single click. They allow two or more EES programs to be run in
series where the following program can used results determined by the previous program. Also,
macros provide a way in which EES can interact automatically with other programs. Macros can
also be used to control EES from another program, either by running EES with the macro file
name, as described in Section 18.3, or by using dynamic data exchange (DDE) within the calling
program, as described in Section 18.4.
Note the control buttons that are located in the palette at the right of the Macro Window. The
functions of these buttons are identified in Figure 18-2.
The Play button also appears at the right in the button ribbon below the main menu bar (see
Figure 18-3) in the EES program whenever the Macro Window is open. Right-clicking this
button will dock the Macro window to the bottom of the Equations window.
Figure 18-3: EES button ribbon showing the macro Play button.
As a simple example, solve the equations in the BasicEqn.ees file by pressing the shortcut key
F2. The macro command Solve will appear in the EES Macro Window, as shown in Figure 18-5.
Chapter 18: Macros 629
Most of the EES menu commands will produce a macro instruction that will appear in the Macro
Window. If you do not wish to have the commands appear in the Macro Window, then click the
lock button in the Macro Window toolbar. The text in the locked Macro window will be shown
in a gray font.
The Macro Window is editable when the lock button is not in effect; you can modify the
commands that appear in this window or delete them if you wish. A detailed list of all macro
commands and their options is provided in Section 18.2. You can comment or uncomment one
or more lines in the Macro Window by selecting the lines, clicking the right mouse button and
selecting the Comment or Uncomment menu item from the pop-up menu that appears as shown
in Figure 18-6. Note that this same popup menu allows tabs to be set and specific editing and
printing for text in the Macro window. For example, if the EES file is already open and you do
not wish to have the macro command open it again then select the first line in the Macro
Window shown in Figure 18-4, right-click and comment it out; the result is shown in Figure 18-
7. Note that a commented line is indicated with the characters // placed at the front of the line.
You could alternatively just enter // at the start of the line to comment out a macro command.
Figure 18-6: Popup menu that appears after right-clicking in the Macro window.
630 Chapter 18: Macros
Figure 18-7: Macro Window with the first macro command commented out.
Uncomment the first line and select the Save button in the Macro Window palette. You will be
asked to supply a file name to save the macro file, with the default being the name you originally
provided. Now we can test this macro. Lock the Macro Window by selecting the lock button.
Then select New from the File menu in order to reset EES. Click the play button (the green
arrow) that appears in the EES Macro Window palette or at the right side of the button ribbon.
EES will respond by opening the specified file and solving the equations, as instructed in the
macro command set.
x^2+y^3=77
sqrt(x/(y^2+1))=2
alpha+x=1.234
x^2+y^3=z
The resulting equation set cannot be solved as there are more unknowns than equations. We can
set the value of the variable z to a value within the Macro Window and solve the equations. To
do this, click the Open New Macro button on the Macro Window palette if the Macro Window is
open or select the Open or Create Macro command in the File menu. Enter a file name for the
macro when prompted to do so. Set the value of the variable z in the Macro Window and enter
the macro command Solve so that the Macro Window appears as in Figure 18-8:
z=77
Solve
The first line of the macro sets the value of EES variable z in the equation set and the second line
solves the equations. Click the Play button to verify that the Macro solves the equation set.
Chapter 18: Macros 631
A Repeat..Until construct can be used to create a loop within a macro. The commands below
create a macro that contains a loop in which the value of the variable z is incremented by 11 each
time it executes. The loop is terminated when the value of variable z is greater than 99. Figure
18-9 shows the macro commands. Click the Save button and save the macro file as
aMacro1.emf. Note that the name of the macro is shown in the Macro Window tab.
Figure 18-9: A macro that solves the equations three times for different values of z.
Now, when you click the Play button, the equation set will be solved three times for values of z
that are equal to 77, 88, and 99. Note that we were able to set (and reset) the value of z in the
macro file and its current value in the macro is used in the solution of the equations. Of course,
the equations are solved so quickly that you cannot see the results and only the last solution will
be displayed in the Solution Window. There are several remedies for this problem. We could
pause between each calculation, so that there is time to see the result or we could save the results
in a file. The modifications to the macro command that implement both of these alternatives are
shown in Figure 18-10.
Figure 18-10: Modification to pause and save the solution for each value of z.
632 Chapter 18: Macros
The macro command Pause 2 waits 2 seconds before continuing. The SaveSolution macro
command saves the Solution Window in the specified file. The /A option appends the results to
the existing file. In this case, the result is that the Solution Window for all three runs will appear
in the file solution.txt, as shown in Figure 18-11. It would also be possible to save the results in
separate files using the string handling capability in the macro commands to compose the file
names.
Figure 18-11: Contents of the solution.txt file that contains the solution windows for all values of z.
Right-clicking on a tab brings up a pop-up menu that offers the options of saving the macro file,
closing the macro file (and removing the tab from the Macro window, or clearing the Log file.
Chapter 18: Macros 633
Figure 18-13: Macro window showing a macro that will be saved with the .EES file
Figure 18-14: EES macro log file written for the execution of the macro in Figure 18-10.
The EES Macro log file can also be viewed directly at the bottom of the Macro window by
sliding the splitter bar up to enlarge the macro log section, as shown in Figure 18-15.
Figure 18-15: EES Macro window showing the log file and the log file toggle control.
If you do not wish to see the log file, pull the splitter bar to the bottom of the screen or, more
simply click the small log window size control shown at the cursor location in Figure 18-15. If
you want to restore the log window to its last position, again click the log window size control.
Note that logging and displaying the log window require computer time that may affect the
operation of a macro in time-sensitive operations, such as reading and writing to the serial port.
Chapter 18: Macros 635
It may be necessary to close the log window and turn off logging with a Log Off macro
command when doing time-sensitive operations.
The most general calling protocol is displayed in bold font for each macro command in this
section. Note that parameters that are enclosed in curly brackets are optional. The purpose of
each macro command and the calling details are provided below the general protocol. An
example is provided after each command. The example macro command(s) can be entered
directly in the Macro Window or in a text file with a text editor such as Notepad. Multiple
macro commands can be placed on one line, provided that a line separator character (; in the U.S.
format, : for the European format) is placed between the commands.
Comments may appear in the macro file. A comment begins with characters // and continues for
the remainder of the line. Comments are displayed in blue font. The macro command file must
be saved with a file name extension of .emf. Note that macro commands are not extensively
checked for syntax. An incorrectly formulated macro command may not execute and halt the
execution of the remaining macro commands. The log file provides the best source of
information relating to the execution of a macro command set.
Normally, if an error of any kind occurs during execution of macro commands, execution will
stop and an error message will be posted to the log file and to the display. The OnError GoTo
macro command described below provides a way for this default behavior to be modified.
Assign EESVariable=Value
The Assign macro command assigns the value Value to the variable EESVariable. The variable
remains assigned to this value until it is reassigned. A variable assigned with a macro
command cannot be reassigned in the Equations Window, Parametric Table or Diagram
Window. The Assign command can also be used to assign a string variable (identified with a
$ as the last character in the name) to a string constant or string variable. The keyword
Assign is optional.
Chapter 18: Macros 637
Example:
Assign X=10
Y=10 //note that the Assign keyword is optional;
Assign TB$=’Table 1’ //Assign can be used for string variables as well.
Beep {Type}
The Beep macro of this command will result in an audible sound. The optional Type
parameter is an integer between 1 and 5 that can optionally follow the Beep keyword in order
to specify the type of sound; the choices are defined in the Sound tab of the Preferences
dialog and listed in Table 18-2. If the Type parameter is not provided then the default sound
will be played.
Table 18-2: Sound types.
Example:
Beep 1
Check
The Check macro command provides the same function as selecting the Check/Format
command from the Calculate menu. The equations in the Equations Window are recompiled
and checked. A summary statement is not issued. This command is useful only in rare
situations in which it is necessary to have EES review the existing equations before
processing subsequent macro commands.
ClearClipboard
ClearClipboard will clear the contents of the Clipboard.
638 Chapter 18: Macros
The range of values to copy can optionally be specified using the nomenclature RX CY : RXX
CYY. If these parameters are not provided then the entire table will be copied. The key
letters R and C indicate row and column, respectively. The parameters X and Y indicate the
number of the row and column, respectively, corresponding to the upper left cell in the range
of cells to be copied and the parameters XX and YY indicate the row and column of the lower
right cell in the range to be copied. For example, specifying R1 C1 : R10 C4 will copy the
Arrays Table values starting in row 1, column 1 through row 10 column 4. It is possible to
specify the selection range with string variables. For example, R1$ and C1$ can be defined in
the macro commands or within the EES program as 'R1' and 'C1', respectively. String
variables R2$ and C2$ can be defined as 'R10' and 'C4', respectively. Note that the strings
must include the leading 'R' or 'C' characters and they can be generated using the Concat$ and
String$ functions. For example, the statement X=10; R2$ = concat$('R',string$(X)) will set
R2$=’R10’. Note that the || operator can be used in place of the concat$ function, e.g., R2$ =
'R' || string$(X)
Example:
Copy /H ArraysTable //copy the main Arrays Table with headers
Copy Diagram
The Copy Diagram macro command copies the Diagram Window to the clipboard in Windows
metafile format. Note that only the Main Diagram Window is copied. Child Diagram
Windows cannot be copied with this macro command.
Copy {/H} IntegralTable {RX CY : RXX CYY}
The Copy IntegralTable macro command copies the contents of the Integral Table to the
clipboard. The optional /H parameter will copy the column names and units, in addition to the
values in the table. The optional parameters RX CY : RXX CYY allows the user to specify the
range of cells to be copied. If these parameters are not included then the entire Integral Table
Chapter 18: Macros 639
is copied. The range specification and copy format are explained in the Copy ArraysTable
macro command.
Example:
Copy /H IntegralTable //copy the Integral Table with headers
Example:
Table$=’Table 1’
Copy /H ParametricTable Table$
//copy the entire contents of Table 1 to the clipboard, including the header and units
Example:
Plot$=’Plot 1’
Copy PlotWindow Plot$
Copy SolutionWindow
The Copy SolutionWindow macro command copies the entire contents of the Solution Window
for the Main Equations Window to the clipboard in text format.
DefVarinfo Letter {Lower=LowerValue} {Upper=UpperValue} {Guess=GuessValue}{Units=Units}
{Display=DisplayCode}
The DefVarInfo macro command sets the default variable information for all variables
beginning with letter following the DefVarInfo keyword. The defaults for the guess value,
lower and upper bounds, display format and units can all be set in this manner. The display
code is set with two characters, the first indicating the type of format and the second
indicating the number of significant figures.
Example:
DefVarinfo T guess=300 units='K' Display=F2
Delay(100)
The Delay macro command suspends execution for the specified number of microseconds.
The parentheses around the time interval are optional. (Also, see the Pause command).
Delete File$
The Delete macro command deletes the file File$. The parameter File$ can either be a string
variable or a filename enclosed in single quotes. If the directory information is not provided
then EES will look for the specified file in all of the directories that have been opened during
the EES session and delete the file in the first directory that it finds that contains a file with
the name File$.
DeleteLookup Table$ {TableNumber}
The DeleteLookup macro command deletes the Lookup Table with name Table$. The
parameter Table$ can either be a string variable or
the table name enclosed in single quotes.
Alternatively, the Lookup Table can be indicated by the integer TableNumber which specifies
the number of the Lookup Table tab to be deleted.
Example:
Table$=’Lookup 1’
DeleteLookup Table$
string variable containing the name of the table. The column that is to be deleted may be
indicated by providing a string constant or string variable containing the name of the column
in the header cell. Alternatively, an integer may be provided that indicates the column
number displayed in the upper left corner of the column header.
A range of columns may be deleted by placing the DeleteLookupColumn macro command
within a Repeat..Until loop using the LookupColName$ function to determine the name of
each column, as demonstrated in the following example. The units assigned to the values in
the column can be accessed with the LookupColUnits$ function. Note that the column
numbers change after each execution of the DeleteLookupColumn macro, so it is necessary
to delete the columns from right to left. If a column is deleted from a table that only has one
column, the Lookup table will be deleted.
Example:
i=10 //Delete columns 5-10 from Lookup 2
TN$='Lookup 2'
repeat
C$=LookupColName$(TN$,i)
DeleteLookupColumn TN$ C$
i=i-1
until (i<5)
Example:
Table$='Table 1’
DeleteParametric Table$
DeleteParametricRows or DeleteParametricRuns
Deletes one or more rows in the existing Parametric table that has name (showing on the tab
in the window). TableName may be a string variable containing the name of the table.
StartRow is the first row in the table to be deleted. It may be a number or an EES variable
that is set to the value of the first row. NRows is the number of rows to be deleted. If
NRows is not provided, it is assumed to be 1. If all of the rows in the table are deleted, the
entire table is deleted.
DeletePlot Plot$ {PlotNumber}
The DeletePlot macro command deletes the Plot Window Plot$. The parameter Plot$ can
either be a string variable or the plot name enclosed in single quotes. Alternatively, the Plot
Window can be indicated by the integer PlotNumber which specifies the number of the Plot
Window tab to be deleted.
Example:
Plot$=’Plot 1’
DeletePlot Plot$
Excel.Cell(C$,V)
The Excel.Cell macro command writes a text item or value to a specified cell in a previously
opened Excel worksheet. The command requires two parameters separated by a list separator
(, for the U.S. configuration and ; for the European configuration). The parameter C$
indicates the cell location and should include a letter that designates the column and a
number that designates the row. For example C$ = 'B3' corresponds to column B and row 3 in
Excel. The parameter V can be text (within single quotes) or an EES variable name. The
EES variable can be a numerical or string variable. If a numerical EES variable is provided,
the value will be formatted using the format specification associated with the variable and the
text representing the formatted value will be copied to the cell. If a string variable name is
provided, the string associated with the variable will be copied to the cell.
Example:
Excel.FileNew
Excel.Show
C$='B3'
Excel.Cell(C$,'Test')
V=34.5
EXCEL.Cell('B4',V)
W$='It works'
EXCEL.Cell('B5',W$)
PAUSE 5
EXCEL.Quit
string(Range)
The Excel.Copy macro command copies the contents of the cells in the specified cell range in
the current Excel worksheet to the Clipboard. The Excel.Range below for information on
setting the range. Note that the range can be set to a single cell, e.g., ‘C1:C1’. Once copied,
the information on the Clipboard can be moved into EES variables using the IMPORT macro
command or into a table using the Paste Parametric or Paste Lookup macro commands. The
example copies two values from Sheet 1 in an existing Excel file. The values are added in
the macro, but they could also have been used in an EES file and which is started with the
SOLVE macro command. The result is exported back to cell C6 in Excel.
Example:
F$='c:\temp\importexport.xls'
EXCEL.OPEN(F$)
EXCEL.Sheet('Sheet1')
// import data from cells C10 and C11
EXCEL.Copy('C3:C4')
IMPORT 'Clipboard' x1,x2
y=x1+x2
// export of the results to Excel file
EXCEL.cell('C6',y)
EXCEL.FileSaveAs(F$)
EXCEL.Quit
Excel.FileNew
The Excel.FileNew macro command starts Excel if it is not already open and creates a new,
empty worksheet.
644 Chapter 18: Macros
Excel.FileOpen(File$)
The Excel.FileOpen macro command starts Excel and opens the Excel file specified by File$.
It is necessary to provide the complete file name, including the directory. You can use the
EESFileDir$ function to return the directory name of the currently open EES file.
Example:
File$=Concat$(EESFileDir$,'Book1.xls')
Excel.FileOpen(File$)
Excel.Show
Excel.FileSaveAs(File$)
The Excel.FileSaveAs macro command saves the currently active Excel file. It is necessary to
provide the complete filename including the directory information and extension. Note that
Excel files can be saved with file extensions .csv, or .xlsx.
Example:
Excel.FileNew
Excel.Cell('B3','Test')
File$=Concat$(EESFileDir$,'Excel_Test.csv')
Excel.FileSaveAs(File$)
Excel.Quit
Excel.Hide
The Excel.Hide macro command hides the currently open Excel application.
Excel.Paste
The Excel.Paste macro command pastes the contents of the clipboard into Excel at the
selection point defined by the macro command Excel.Range.
Excel.Range(Range)
The Excel.Range macro command sets the selection point within the currently open Excel
worksheet. The parameter Range must consist of a column (letter) and row (number) that
defines the upper left corner of the range and a column and row that defines the lower right
corner of the range, separated by a colon (e.g., A1:C10). The range can also be provided with
an EES string variable. The Excel.Paste macro command will paste the contents of the
clipboard into Excel at the selection point. To specify the insertion point for a paste
operation, set the upper left and lower right corners to be the same cell, corresponding to the
desired upper left cell of the paste operation (e.g., 'A1:A1').
Example:
Excel.FileNew
Excel.Show
Copy ParametricTable 'Table 1' //need to have a Parametric Table made
Excel.Range(B1:B1)
Excel.Paste
Excel.Quit
The Excel.Quit macro command closes the currently Excel application.
Excel.Sheet(Sheet$)
The Excel.Sheet macro command activates the Excel worksheet with name Sheet$ in the
currently open Excel application. If the sheet does not exist, it is created and activated.
Chapter 18: Macros 645
Example:
Excel.FileNew
Excel.Show
Excel.Sheet('Sheet2')
Excel.Cell(A1, 'Test')
Excel.Show
The Excel.Show macro command makes the currently open Excel worksheet visible.
Export {/A} File$ X, Y, Z, ...
The Export macro command opens the file File$ and writes the values of the EES variables in
the list X, Y, Z, ... to the file. If the value of File$ is 'clipboard', then the variables are written to
the clipboard. The optional parameter /A appends the data to the file if it already exists. If
the file does not exist then a new file with this name is created. Note that if File$ is a text file
(.txt) then the format is consistent with a Lookup Table. If File$ is a .csv or .dat file then the
data will be saved as a delimited text file. The Export macro has the same options as the
$Export directive.
Example:
X=1; A$ = 'Test'
Export 'clipboard' X, A$
GetDirectory
The GetDirectory macro command returns the current Windows directory, which can be
assigned to a string variable. Note that the GetDirectory macro does not provide \ as its last
character.
Example:
D$=GetDirectory
F$=Concat$(D$,'\MyFile.ees')
Solve
Goto Line
The Goto macro command transfers execution to the macro line having label Line. The value
of Line must be an integer between 1 and 30000 corresponding to a line label that has been
assigned using the Label macro command. Goto and Label macro commands are usually used
within If Then Else macro commands.
Example:
Solve //the value of X must be set in the Equations Window
If (X<5) Then Goto 10 Else Goto 20
Label 10: Beep 1
Pause 1
Label 20: Beep 2
HideWindow WindowName
The HideWindow macro command hides the window specified by the parameter WindowName.
The parameter WindowName can be any of the keywords: EES, Equations, Formatted, Solution,
Residuals, Arrays, Parametric, Lookup, Integral, Plot, or Diagram. If the keyword is EES, the
main EES window and all of the windows contained within it are hidden. Visibility can be
restored with the ShowWindow macro.
646 Chapter 18: Macros
Example:
Solve
HideWindow Equations
Include File$
The Include Macro command will process the file that is provided after the Include keyword. Files
have the file name extension of .dlf, .dll, .dlp, .fdl, .fld, .prf, and .var can be processed with this macro
command.
Example.
// load the C11.fld fluid property information file from REFPROP. and then prepare a Temperature-
//Entropy property plot for this fluid
Include c:\Program Files (x86)\REFPROP\Fluids\C11.FLD
PropPlot C11_rp TS 6 1000 700 300 90 20 3 6 0.0068 0.095 0.35 1.31 4.88 18.1 DoQLines
Input /U /D X, Y, R$
The Input macro command will display a dialog prompting the user to enter the values of 1
to 5 EES or macro variables. Both numerical and string variables can be enter this way. The
variable can then be used in subsequent macro commands or within the main program while
solving. /U and /D are optional. If /U is present, the units of the variables) will be displayed
in the input dialog. If /D is present, the previous value of the variable(s) will appear as a
default. See Section 18.8 for a macro that makes use of the Input command.
Chapter 18: Macros 647
Example:
P=100 [kPa] //default value
T=15 [C] //default value
R$=’R515A’ //default value
Input /U /D T, P, R$
h-enthalpy(R$,T=T,P=P)
Solve
Example:
InsertLookupRows 'Lookup 1' 999 5 //inserts 5 rows at the end of the Lookup Table 'Lookup 1'
Label Line#
The Label macro command creates a line with the label provided by the parameter Line. The
parameter Line# must be a number between 1 and 30000. If a colon follows the parameter
Line then a macro command can follow the line label on the same line. See GoTo for an
example.
Example:
{Placing this directive in an EES file will automatically create a .pdf document having the same
parent name as the EES file containing all of the EES file information except the Lookup Tables.}
$RunMacroAfter
F$=changefileext$(EESFileName$,'.pdf')
LatexPDF F$ -L
$endmacro
Load #N
The Load macro is useful only for macro files that control the execution of a distributable file
(discussed in Chapter 17). Distributable files can contain up to 100 separate programs. The
Load command clears the memory space and then loads program N where N is an integer
between 1 and the number of programs provided with the distributable.
Example:
Load #2
LoadLibrary DirectoryName
The LoadLibrary macro loads all external files in the DirectoryName, which can be either a
string or string variable. Library files that reside in subdirectories are also loaded. External
library files must have a file name extension of .lib, .dll, .dlf, .dlp, or .fdl. The 64-version
uses these file types with a 64 at the end of the file name extension. Library files with the .lib
or .lib64 file name extension are developed in EES, as discussed in Chapter 11. All of the
others must be developed in a compiled language such as C or FORTRAN, as discussed in
Chapter 19. Note that all library files that are placed in the Userlib (or Userlib64 for the 64-
bit version) directory within the EES folder are automatically loaded.
650 Chapter 18: Macros
Example:
LoadLibrary 'C:\EES\myLibraryFolder '
LogFileName File$
EES writes a log file showing each of the macro commands that it executes. The log file is
named, by default, EESMacro.log, and it is placed in the same directory as the macro file.
However, you can change the file name to File$ using the LogFileName macro. The file name
will typically have a .log extension, but any extension representing a text file is appropriate.
The directory information can also be contained in File$; if none is specified then the log file
is placed in the same directory as the macro file. Note that File$ cannot be represented with
an EES string variable. If a filename is not provided after the LogFileName macro command
(i.e., if the file name is blank) then a log file will not be written.
Lookup[Table$, Row, Column] = Value
The Lookup macro places Value into Lookup Table Table$ at position Row and Column. Note
that brackets rather than parentheses are required. Column must either be an integer,
referring to the column number or a string constant or string variable that contains the name
of the column in the Lookup table. Mathematical operations cannot be used in place of Value
(e.g., Lookup['Lookup 1', 1, 1] = i^2 will not work).
Example:
R=4
Lookup['Lookup 1', R, 2]=20 //Sets the value of row 4, column 2 in 'Lookup 1' to be 20
MATLAB.Execute(Command$)
The MATLAB.Execute command executes the MATLAB command in the string Command$.
The command is executed in the MATLAB command window. Note that the MATLAB
command is case-sensitive and must be entered exactly as it would be entered in the
command window. The result of the command is displayed in the EESMacro.log file. Note
that the MATLAB.Open command must be used before the MATLAB.Execute macro is issued.
Example:
Command$='X=1'
MATLAB.Open
MATLAB.Execute(Command$)
//Note that the variable X should be set to 1 in the MATLAB command window.
EESVarName=MATLAB.GetVariable(MLVarName)
Retrieve an existing MATLAB variable defined in the MATLAB 'base' workspace. The
MATLAB variable may be a single real value, a single string variable, a 1-D MATLAB
vector or a 2-D MATLAB array. Note that MATLAB.Open command must be used before
this command can be issued. If a vector or array is used, the dimensions provided in
EESVarName must be the same size as those for the MATLAB variable.
Example 1:
MATLAB.Execute(HW='Hello World!')
HW$=MATLAB.GetVariable(HW)
Example 2:
MATLAB.Execute(x=sqrt(36))
x=MATLAB.GetVariable(x)
Example 3:
{assumes vector b is defined in MATLAB}
b[1..3]=MATLAB.GetVariable(b).
Example 4:
MATLAB.Execute(A=[1 2 3; 4 5 6; 7 8 9])
N=3
A[1..N,1..N]=MATLAB.GetVariable(A)
MATLAB.Open
The MATLAB.Open command starts MATLAB and opens the MATLAB command window.
This command is ignored if MATLAB has previously been opened in this session and not
closed with the MATLAB.Quit command.
MATLAB.Quit
The MATLAB.Quit command closes the instance of MATLAB that was opened with the
MATLAB.Open macro command. MATLAB will need to be reopened after this command is
issued. Note that opening MATLAB is time-consuming. Do not issue this command until
you are done with MATAB.
652 Chapter 18: Macros
MATLAB.SetVariable(MLVarName, EESVarName)
The MATLAB.SetVariable command sets the value of MATLAB variable, MLVarName, to
the value of an existing and defined EES variable, EESVarName. MLVarName may be a
single real value, a single string variable, a 1-D MATLAB vector or a 2-D MATLAB array.
The EESVarName must be of the same type (real or string). If EESVarName is a vector or
array, the dimensions must be explictly defined.
Example 1:
S$='Hello! Welcome to EES and MATLAB'
MATLAB.SetVariable(aStr,S$)
Example 2:
brow[1,1..3]=[1,2,3] {Set a row vector}
MATLAB.SetVariable(brow,brow[1,1..3])
bcol[1..3,1]=[1,2,3] {Set a column vector}
MATLAB.SetVariable(bcol,bcol[1..3,1])
b[1..3]=[1,2,3]
MATLAB.SetVariable(bcol,b[1..3]) {This also sets a column vector}
Example 3:
N=3
a[1,1..N] = [2, 3, 1]
a[2,1..N] = [8, 5, 1]
a[3,1..N] = [7, 1, 2]
MATLAB.SetVariable(A,A[1..N,1..N])
Maximize G a b c {/Method=MethodKeyword}
The Maximize macro command maximizes the dependent variable G with respect to the
independent variables in the list a b c. Note that all variables must be defined in the
Equations Window and the dependent variables must have non-infinite upper and lower
limits; the VarInfo macro command can be used to set these limits. The optimization method
can optionally be specified by the /Method=MethodKeyword parameter. The value of
MethodKeyword can be Golden or Quadratic for single degree of freedom optimization
problems. For problems involving multiple independent variables, the value of
MethodKeyword can be Conjugate, Variable, Nelder, Genetic, or Direct. If the
/Method=MethodKeyword parameter is not provided then EES will use the optimization method
that was used for the last optimization.
Example 1:
Open EESProgramDir$||'USERLIB\Examples\MaxPower.ees
Maximize W_dot T_1 /Method=Golden
//maximize W_dot by varying T_w using the Golden Section method
Example 2:
FN$=EESProgramDir$||'USERLIB\EXAMPLES\REGEN_MINMAX.EES'
OPEN FN$ //Open existing example
MAXIMIZE /METHOD=CONJUGATE Eff P[2] P[4] //maximize Eff using the Conjugate method
Minimize G a b c {/Method=MethodKeyword}
The Minimize macro command operates in the same way as the Maximize macro command
except that the objective function is minimized.
Example:
ModifyAxis X Name='Plot 1' Min=0 Max=2 Linear Int=0.2 Grids=On Format=E3 Color=Red
New
The New macro command clears the work space and brings up an empty Equations Window.
Note that the New macro will not display a dialog asking you to save an existing file; rather,
the existing file will be closed without saving.
NewContourPlot Table=Table$ (or TableType#) X=XColumn Y=YColumn Z=ZColumn
Type=TypeValue {Legend=yes (or no)} {Resolution=Res} {Xmin=XminValue} {Xmax=XmaxValue}
{Xint=XintValue} {Ymin=YminValue} {Ymax=YmaxValue} {Yint=YintValue} {Zmin = ZminValue}
{Zmax = ZmaxValue} {Zint=ZintValue} {Name=Plot$}
The NewContourPlot macro command creates a new contour plot. The table containing the
data used for the plot is provided by the string Table$. If Table$ is the name of both a
Parametric Table and a Lookup Table then the data will be plotted from the Parametric
Table. (The search order is Parametric Table, Lookup Table, and then Arrays Table.)
Alternatively, the table can be identified by specifying an identifier for the type of table (PAR
for Parametric, LOOK for Lookup, ARR for Array and INT for Integral) followed by a number
that indicates its position; e.g., LOOK1 is the first Lookup Table. The columns in the table
that are used for the x, y, and z data are indicated by the XColumn, YColumn, and ZColumn
parameters, respectively. The TypeValue parameter indicates the type of contour plot:
Isometric, Colorbands, or Gradient. The remaining keywords are optional and summarized in
Table 18-5. If these parameters are not specified then default values are used.
Example:
Open C:\EES_CAE\USERLIB\Examples\LinearRegression.ees
NewContourPlot Table=LOOK1 X=T_cond Y=T_evap Z=m_dot Type=ColorBands Name='MyPlot'
Example:
Open C:\EES32\Userlib\Examples\capvst.ees
NewPlot Name='My Plot' Table=PAR1 X=Q_H Y=T_amb Line=1 Symbol=1 Color=Red
ONERROR GOTO XX
Normally, if an error of any kind occurs during execution of macro commands, execution
will stop and an error message will be posted. The ONERROR macro command provides a
way for this default behavior to be modified. After this command has been executed, an error
will result in a jump to the macro command having label XX. A line with this label must
appear in the macro file. Labels must be numerical values ranging between 1 and 30000
followed by a colon (:). This command can appear as many times as desired. The control will
transfer to the macro command with the label for the most recently executed ONERROR
command. To return to default behavior, enter ONERROR GOTO 0.
658 Chapter 18: Macros
Open File$
The Open macro command opens the file File$.
Example:
T$ = ‘C:\EES32\USERLIB\Examples\CapvsT.ees’
Open T$
Example:
Table$='MyLookupTable'
NewLookup Table$ Rows=10 Cols=2 //create a new Lookup Table
Show LookupTable Table$ //bring the Lookup Table to the front
//make sure that the clipboard contains one or more numbers
Paste Lookup Table$ R1 C1 //paste the contents of the clipboard into the table
Pause Time
The Pause macro command pauses execution for the number of seconds specified by the
Time parameter. The Pause macro is useful when an EES macro file is being repeated and
EES is periodically reading a file using the Import macro that has been written by another
application (e.g., a data acquisition program). (Also see the Delay command.)
Print Window
The Print macro command prints the window specified by the Window parameter to the default
printer. The default printer can be specified using the PrintSetup command. The recognized
values of the Window parameter are summarized in Table 18-8. Note that multiple windows
can be printed using a single Print macro command.
Table 18-8: Recognized values of the Window parameter for the Print macro.
Example:
Open C:\EES_CAE\USERLIB\Examples\CapvsT.ees
SolveTable 'Table 1' Rows=1..7
Print Equ Plot1 Plot2
660 Chapter 18: Macros
PropPlot Fluid$ Type NProp1 Val1Prop1 Val2Prop1 ... NProp2 Val1Prop2 Val2Prop2 ... {DoQLines}
The PropPlot macro command generates a property plot of the type indicated by the Type
parameter for the fluid Fluid$ which can be any fluid in EES other than AirH2O (see the macro
command PropPlot AirH2O Psy to generate a psychrometric plot). The recognized values of the
Type parameter are summarized in Table 18-9. The NProp1 parameter specifies the number
of lines of constant property 1 (see Table 18-9) that will be shown on the plot and the
subsequent list (Val1Prop1 Val2Prop1 ...) specifies their values. The NProp2 parameter
specifies the number of lines of constant property 2 that will be shown on the plot and the
subsequent list (Val1Prop2 Val2Prop2 ...) specifies their values. The optional DoQLines
keyword indicates that the plot should contain lines of constant quality within the vapor
dome.
Table 18-9: Recognized values of the Type parameter and associated constant property lines.
Example:
PropPlot ‘Steam’ Ts 4 10e6 5E+06 2E+06 0.5e6 6 0.007 0.2 1 7 40 200 DoQLines
PropPlot AirH2O Psy Nwb Twb1 Twb2 ... Nv v1 v2 ... P=Pval {Mollier}
The PropPlot AirH2O Psy macro command generates a psychrometric plot for the fluid AirH2O.
The Nwb parameter specifies the number of lines of constant wet bulb temperature to place
on the plot and the list Twb1 Twb2 ... specifies their values. The Nv parameter specifies the
number of lines of constant specific volume to place on the plot and the list v1 v2 ... specifies
their values. The value of Pval is the pressure to be used to generate the plot. The optional
keyword Mollier specifies that the psychrometric chart should be in Mollier format.
Example:
PropPlot AirH2O Psy 5 285 290 295 300 305 4 0.825 0.85 0.875 0.9 P=101300.0 Mollier
Chapter 18: Macros 661
Quit
The Quit macro command closes the EES application. The Quit macro command is not
needed (or desired) when the macro is run from the Macro Command Window. However,
the Quit macro command is useful when the macro is started from another program, as
described in Section 18.3.
Repeat
Command(s)
Until (Conditional)
The Repeat-Until macro command executes the commands in the macro file between the
Repeat and Until keywords (which must be on separate lines) until the conditional test
Conditional is true. Note that any legal expression involving existing variables that are
defined in the main section of the Equations Window or the Macro Command Window can
be used in the expression. If the expression Conditional is never true then the macro
commands in the Repeat-Until loop will be repeated indefinitely or until the Escape key or
Macro Window stop button is pressed.
Example:
//Put the equation Y=X^2 in the Equations Window
X=0
Repeat
X=X+1
Solve
Pause 2
662 Chapter 18: Macros
Until (X>5)
Reset X, Y ...
The Reset macro command will reset the status of the variables in the list X, Y ... to
unassigned. This command is useful if a variable has previously been used in a macro
command and is now to be used in a different manner in the same macro command file.
ResetGuesses
The ResetGuesses macro command resets the guess values for the variables in the Equations
Window to their default values.
RetrievePametric FileName
Retrieve a previously saved Parametric table for which the name is provided in parameter
Filename. The file name must have a .par or .txt filename extension. (For the 64-bit version,
the .par64 filename extension is used in place of .par.) This macro command provides the
same function as the Retrieve Parametric command in the Tables menu.
Run Statement
The Run macro command acts as if Statement were entered into the Windows Start menu.
For example, to start Excel use the macro command Run Excel. (Note that there are separate
macro commands that allow specific interactions with Excel, e.g., Excel.Hide). You can also
start Excel and open a specific file. For example, the macro Run C:\temp\Test.xls will start
Excel and open the file Test.xls. EES knows that the .xls file name extension is an Excel file,
provided that Excel is installed properly. Using the Run command, it is possible to start
external programs that read data exported by EES and then have EES import the data that is
output by that program.
Example:
Run Excel
Run MATLAB
Save {File$}
The Save macro command saves the existing file. If the optional parameter File$ is included
then the file will be saved with the name File$. Otherwise, the file will be saved with its
existing file name.
Example:
Save 'C:\temp\temp.ees'
Example:
//Put the equation A[1..5]=[1,2,3,4,5] in the Equations Window
Solve
File$='C:\Temp\Arrays.txt'
SaveArrays 'Main' File$
Example:
SavePlot 'Plot 1' 'C:\temp\temp.jpg'
SaveVarInfo VarInfoFIleName$ /A
Save the variable information for the current EES file which includes the name, guess values,
limits, display format, units and comments assigned for each variable. The filename should
have a .VAR file name extension. If no extension is provided or if the file name extension is
something other than .VAR, it will be changed to .VAR. The variable information file name
can be a string constant (enclosed in single quotes) or a string variable (ending with a $
character) as shown. If no file name is provided, the file name will be created using the
name of the EES file with a .VAR file name extension. By default, variable information is
saved only for the main program. If the /A option is provided, variable information will also
be saved for functions, procedures, subprograms, and modules that are in use.
Example:
SaveVarInfo //Save variable information for current .EES file.
Serial.Close(COM1)
Close serial port COM1. The port name, COM1 in this example, can be a string variable,
e.g., C$, that has been previously set to the port name. If the specified serial port is not open,
this command will do nothing. Parentheses around the port name are optional.
Serial.Open (Port=COM1 Baud=9600 Parity=n Stop=1 BufferSize=2048 TimeOut=200)
Opens the specified serial port for reading and/or writing. The port name can be a string variable,
e.g., C$, that has been previously set to the port name. The baud rate is the number of bits per
second that data is transferred in serial communication. Parity and Stop specify framing bits for the
asynchronous communication. The baud rate, parity, and stop bits must match the parameters of the
device that EES is attempting to communicate with. The defaults for Baud, Parity, and Stop are
Chapter 18: Macros 665
9600, n, and 1. If these parameters are not provided, the defaults are used. Buffersize is the number
of bytes used for the internal buffers for reading and writing. The maximum buffer size is 8192. If
butfersize is set to zero or if this parameter is not provided, the default buffer size of 1024 is used.
TimeOut is the number of milliseconds that EES will wait before giving up while trying to read data
from the serial port with the Serial.ReadChar, Serial.ReadString, Serial. ReadNumber or
Serial.ReadtoLookup serial macro commands. Timeout can be specified with a number or with an
EES variable that has previously been set to value. The choice for Timeout depends on the rate at
which the serial device is sending data. The Pause macro can also be used within a Repeat-Until
loop to control the timing. Note that the parentheses are optional and the keyword clauses can be
separated with a space or a comma (US system) or semi-colon (EU system). (See Section 18.4 for
examples using serial port communications.)
Serial.ReadChar COM1 H$
Reads a single ASCII character from the specified serial port. The first parameter is the port name
and it can be a string variable, e.g., C$, that has been previously set to the port name. The specified
port must have been previously opened with the Serial.Open command. An EES string variable, e.g.,
H$, must be provided. The string variable will be set to the character read from the serial port. The
ReadChar command will continue to look for a character on the serial port until the Timeout interval
specified in the Serial.Open command is exceeded.
Example
C$='COM1'
Serial.Open(Port=C$, Baud=9600m Parity=n, Stop=1, BufferSize=1024, TimeOut=100)
Serial.ReadChar(C$, H$) //H$ is set to the character
Serial.Close(C$)
Serial.ReadNumber COM1 V
Reads a numerical value (integer or real) from the specified serial port. The first parameter is the port
name and it can be a string variable, e.g., C$, that has been previously set to the port name. The
specified port must have been previously opened with the Serial.Open command. An EES variable,
e.g., V, must be provided. The value of the variable will be set to the numerical value read from the
serial port. Note that the numerical value must be provided to the serial port by the external program
as a string of numerical characters terminated by CRLF, i.e., carriage return (ASCII13) and line feed
(ASCII 10) characters. The ReadNumber macro command will continue to look for the number on the
serial port until it reads a CRLF or the Timeout interval specified in the Serial.Open command is
exceeded.
Serial.ReadString COM1 S$
Reads a string consisting a one or more ASCII characters from the specified serial port. The first
parameter is the port name, COM1 in this example, and it can be a string variable, e.g., C$, that has
been previously set to the port name. The specified port must have been previously opened with the
Serial.Open command. An EES string variable, e.g., S$, must be provided. The string variable will
be set to the character string read from the serial port. Note that string provided to the serial port by
the external program must be terminated by CRLF, i.e., carriage return (ASCII13) and line feed
(ASCII 10) characters. The ReadString macro command will continue to look for the string on the
serial port until it reads a CRLF or the Timeout interval specified in the Serial.Open command is
exceeded.
The Lookup table must exist. It can be created using the New Lookup Table menu or the NewLookup
macro command. Row and Col are, respectively, the row and column in which the numerical value
will be placed after the read operation is completed. Row and Col can be provided as numerical
values or as EES variables that have been previously set to numerical values. The column can also
be indicated by providing the name of the column as a string constant. If Row is greater than the
number of rows in the table, the number of rows in the Lookup table will be increased. However, this
operation takes time and may result in lost data. It is better to use the InserLookupRows macro
command to ensure that there are sufficient rows in the designated lookup table. If Col is greater
than the number of columns in the table, the value will be ignored. Note that the numerical value
must be provided to the serial port by the external program as a string of numerical characters
forming a single numerical value terminated by CRLF, i.e., carriage return (ASCII13) and line feed
(ASCII 10) characters. The ReadtoLookup macro command will continue to look for the number on
the serial port until it reads a CRLF or the Timeout interval specified in the Serial.Open command is
exceeded.
Example
T$='Lookup 1'
Row=5
Col=1
C$='COM1'
Serial.Open(Port=C$, Baud=9600m Parity=n, Stop=1, BufferSize=1024, TimeOut=100)
Serial.ReadtoLookup(C$,T$, Row, Col) //value is placed in the Lookup table
Serial.Close(C$)
Serial.WriteChar COM1 'H'
Writes one or more ASCII characters to the specified serial port. The first parameter is the port name
and it can be a string variable, e.g., C$, that has been previously set to the port name. The specified
port must have been previously opened with the Serial.Open command. The second parameter is a
string constant (enclosed within single quotes) or an EES string variable containing the character(s)
that are to be written. Note that this command differs from the Serial.WriteString command in that
CRLF (carriage return line feed characters) are not written to the serial port.
Serial.WriteNumber COM1 V
Writes the ASCII characters representing a number to the specified serial port. The first parameter is
the port name and it can be a string variable, e.g., C$, that has been previously set to the port name.
The specified port must have been previously opened with the Serial.Open command. The second
parameter is either the numerical value or an EES variable, e.g., V, containing the numerical value
that is to be written. CRLF (carriage return line feed characters) are appended to the number that is
written to the serial port.
Serial.WriteString COM1 S$
Writes one or more ASCII characters to the specified serial port. The first parameter is the port name
and it can be a string variable, e.g., C$, that has been previously set to the port name. The specified
port must have been previously opened with the Serial.Open command. The second parameter is a
numerical value or an EES string containing the character(s) that are to be written. Note that this
command differs from the Serial.WriteChar command in that CRLF (carriage return line feed
characters) are appended to the characters that are written to the serial port.
Example
C$='COM1'
Serial.Open(Port=C$, Baud=9600m Parity=n, Stop=1, BufferSize=1024, TimeOut=100)
H$='Hello World!'
Serial.WriteString C$ H$
Serial.Close C$
Chapter 18: Macros 667
SetDirectory(Directory$)
The SetDirectory macro command sets the current Windows directory to Directory$. Note that
the EESFileDir$ and EESProgramDir$ functions may be useful as they return the current
directories for the EES file and EES program file, respectively.
Example:
Directory$=EESFileDir$ //Get the directory for the current file
SetDirectory(Directory$) //set the directory to be that of the current file
ShowWindow Arrays
The ShowWindow Arrays macro command shows the Arrays Window and places it in front of
all other windows. This command is ignored if an Arrays Table does not exist.
ShowWindow Diagram {Name$}
The ShowWindow Diagram macro command shows the Diagram Window and places it in front
of all other windows. The name of a Child Diagram Window can optionally be provided as
the parameter Name$; if this parameter is not provided then the Main Diagram Window will
be shown.
ShowWindow EES
The ShowWindow EES macro command will change the visibility of the EES application from
a minimized state to its normal viewing state.
ShowWindow Equations
The ShowWindow Equations macro command shows the Equations Window and places it in
front of all other windows.
ShowWindow ErrorMessages
Normally, error message (including those generated by the Call Error procedure) are quietly
written to the Macro log file rather than shown on the screen. However, this macro
command will cause the error messages to be displayed in the same way they would appear if
they were run as a normal EES program.
ShowWindow Format
The ShowWindow Format macro command shows the Formatted Equations Window and places
it in front of all other windows.
ShowWindow Integrals
The ShowWindow Integrals macro command shows the Integral Table and places it in front of
all other windows. This command is ignored if an Integral Table does not exist.
ShowWindow Lookup {Table$}
The ShowWindow Lookup macro command shows the Lookup Table Window and places it in
front of all other windows. The name of a Lookup Table can optionally be provided as the
parameter Table$ in which case the table named Table$ will be selected.
ShowWindow Parametric {Table$}
The ShowWindow Parametric macro command shows the Parametric Table Window and places
it in front of all other windows. The name of a Parametric Table can optionally be provided
as the parameter Table$ in which case the table named Table$ will be selected.
668 Chapter 18: Macros
Solve
The Solve macro command initiates the solution process in the same manner as if the Solve
command were selected from the Calculate menu.
SolveTable /U /R /S Table$ {Rows = RowStart ... RowEnd}
The SolveTable macro command initiates the solution process for Parametric Table Table$ in
the same manner as if the Solve Table command were selected from the Calculate menu.
The table can be designated with a predefined string variable, e.g., Table$, or with a string
constant enclosed in single quotes, e.g., ‘Table 1’. The range of rows to be solved can
optionally be provided using the Rows = keyword with RowStart and RowEnd values
indicating the first and last rows, respectively. RowStart and RowEnd can be integer
variables or EES variables set to specified values in the Macro window or in the EES main
program. If /U is provided, the guess values will be updated after each row of the table
successfully completes calculations. If /R is provided the calculations will be start on the last
row and proceed to the first row of the specified range. If /S is provided the calculations will
stop if an error is encountered and remaining rows of the table will not be processed.
Example:
RowStart=1
RowEnd=7
SolveTable /U 'Table 1' Rows=RowStart..RowEnd
Stop
The Stop macro command halts the execution of the macro.
StopCrit {It=ItValue} {Time=TimeValue} {Res=ResValue} {Var=VarValue}
Chapter 18: Macros 669
The StopCrit macro command sets the stop criteria properties used by EES in the solution
process. These are the same properties that can be set within the Stop Crit tab in the
Preference dialog or by using the $StopCriteria directive. The keywords It, Time, Res, and Var
must each be followed by an equal sign and then a numerical value. These keywords may be
in any order and do not all need to be specified. The value of ItValue is the maximum number
of iterations. The value of TimeValue is the maximum value of elapsed time. The value of
ResValue is the criteria on the relative residual. The value of VarValue is the stop criterion for
the change in variables.
Example:
StopCrit It=200 //sets the maximum number of iterations to 200
Units SI Mass (or Mole) Deg (or Rad) kPa (or Pa, bar, MPa) J (or kJ) C (or K)
670 Chapter 18: Macros
Units Eng Mass (or Mole) Deg (or Rad) psia (or atm) F (or R)
The Units macro command sets the unit system in EES. The macro command works in the
same manner that the $UnitSystem directive works, as discussed in Section 14.3. All of the
specifications that could be set in the Unit System tab of the Preferences dialog can also be
set using the Units macro command. Note that it is not possible to specify a mixed unit
system. For example, if SI is used then specifying F for the temperature units will result in
temperature units of C, not F.
Example:
Units SI Mass J K Pa Rad
UpdateGuesses
The UpdateGuesses macro command sets all variable guess values to their last set of
calculated values.
UpdatePlot [optional plot window]
Plot windows can be set to display the most recent calculated data by checking the
Automatic update control in the Modify Plot dialog. However, the display is updated only
when the plot window is the active window, i.e., the one that has control. A window can be
activated by clicking the mouse button anywhere within the window. In some cases, a plot
window may be fully visible, but it is not the active window. In this case, the display can be
made to update with the UpdatePlot macro command. The optional plot window may be a
numerical value indicating the position of the plot tab or a string constant or string variable
that provides the name of the plot window seen on the tab. If an plot window designation is
not provided then all of the plot windows in the file will be updated.
VarInfo Variable {Lower=LowerValue} {Upper=UpperValue} {Guess=GuessValue}
The VarInfo macro command sets the bounds and guess value for the variable Variable in the
same way as if these characteristics were specified within the Variable Information Window.
The lower and upper bounds are set to the values LowerValue and UpperValue, respectively.
The guess value is set to GuessValue. Not all of these parameters must be specified. The
numerical values LowerValue, UpperValue, and GuessValue can be variables that have been set
in either the Macro Window or the Equations Window.
Example:
GuessValue=-1
VarInfo x Upper=0 Guess=GuessValue
Word.FileNew
The Word.FileNew macro command starts Microsoft Word and creates a new empty
document.
Word.FileOpen(File$)
The Word.FileOpen macro command starts Microsoft Word and opens the file File$. It is
necessary to provide the complete file name with directory information. The file name
should have an extension of either .doc or .docx.
Example:
File$='C:\temp\temp.doc'
Word.FileOpen(File$)
Word.FileSaveAs(File$)
Chapter 18: Macros 671
The Word.FileSaveAs macro command saves the current Microsoft Word document with the
file name File$. It is necessary to provide the complete file name with directory information.
The file name should have an extension of either .doc or .docx.
Example:
File$='C:\temp\temp.doc'
Word.FileOpen(File$)
Word.FileSaveAs('C:\temp\temp2.doc')
Word.Hide
The Word.Hide macro command hides the current Microsoft Word document.
Word.Insert(Text$)
The Word.Insert macro command inserts the text Text$ into the current Microsoft Word
document at the current position.
Example:
File$='C:\temp\temp.doc'
Word.FileOpen(File$)
Word.Insert('Hello')
Word.Paste
The Word.Pastemacro command pastes the current contents of the clipboard into the current
Microsoft Word document.
Word.PasteSpecial(FormatType)
The Word.PasteSpecial macrocommand pastes the current contents of the clipboard into the
current Microsoft Word document using the format specified by the parameter FormatType.
The parameter FormatType can be either Text, Picture, Bitmap, Device Independent Bitmap, or
Enhanced Metafile.
Example:
Open C:\EES32\USERLIB\Examples\CapvsT.ees
Word.FileNew
Copy PlotWindow 'P-h: R134a'
Word.Show
Word.PasteSpecial(Enhanced Metafile)
Word.Quit
The Word.Quit macro command closes the current Microsoft Word document.
Word.Show
The Word.Show macro command makes the current Microsoft Word document visible.
Start EES and enter the following equations into the Equations Window:
These equations cannot be solved unless values are provided for the variables T (in °C) and P (in
kPa). In this example, values of T and P will be obtained from Excel and the calculated values of
specific enthalpy, specific entropy and specific volume will be exported back to Excel.
Create a Parametric Table using the New Parametric Table command in the Tables menu.
Specify 10 rows (the default) and provide columns for variables T, P, h, s, and v (in that order) as
shown in Figure 18-16.
Select the Variable Information command in the Options menu and enter the units for all
variables, as shown in Figure 18-17:
Chapter 18: Macros 673
Save the EES file as C:\Temp\TestExcelMacro.ees. Next, open Microsoft Excel and enter the
information shown in Figure 18-18 into Sheet 1. Note that the Excel sheet provides values of
temperature and pressure that will be copied into the Parametric Table in EES. It also has empty
columns for specific enthalpy, specific entropy and specific volume. Save the Excel file. In this
example, the file name is C:\Temp\Excel_ws1.xlsx. You can of course use any directory or file
name, but it is necessary to use the complete file name in the EES Macro file that we will
develop next. Close the Excel file.
Figure 18-18: Excel worksheet with values set for T and P and columns for h, s, and v.
Return to EES. Next, select the Open or Create Macro command from the File menu and enter a
file name. The file name used in this example is C:\Temp\Excel1.emf. The macro will open the
Excel file, copy the temperature and pressure data to the Parametric Table, run the Parametric
Table, and finally copy the properties calculated in EES back to Excel. The Excel file name is
assigned to the string File$. The Excel.Open macro command is used to open the file and the
Excel.Show macro command is used to bring the Excel file to the front.
The Excel.Copy macro command is used to copy the values in the Excel file in the range A2:B11
to the clipboard. The Paste Parametric macro command is used to paste the values in the
clipboard into the Parametric Table starting at row 1 and column 1 (R1 C1).
The Parametric Table is solved using the SolveTable macro command and the Copy
ParametricTable macro command is used to copy the values in the table from row 1 column 3 to
row 10 column 5 (R1 C3 R10 C5) to the clipboard.
The insertion point in Excel is set to cell C2 using the Excel.Range macro command and the
contents of the clipboard are pasted into Excel using the Excel.Paste macro command.
The Excel file is saved using the Excel.FileSaveAs macro command. Execution is paused for 2
seconds using the Pause macro command and finally the Excel file is closed using the Excel.Quit
macro command.
Type the macro commands listed above into the Macro Window, as shown in Figure 18-19. If
you saved the Excel file with a different name or in a different directory, then change the file
name accordingly. When you are sure that all of the macro commands have been correctly
entered, click the Save button ( ) in the Macro Window tool bar and then click the lock
button so that no additional changes can be made to the Macro window. Click the Play
button to start the calculations.
Figure 18-19: EES Macro Window with macro commands to interact with Excel.
Chapter 18: Macros 675
The macro will open the Excel file that you created previously and display it. It will then copy
the values of T and P from the first two columns of the Excel sheet to the EES Parametric Table.
The Solve Table macro command will fill the Parametric Table with values of calculated specific
enthalpy, specific entropy and specific volume that are copied to the clipboard and pasted back
into Excel. The modified Excel file is saved with the same file name. The Pause 2 macro allows
you to see the modified file before Excel is closed.
Example 1: Use MATLAB to compute the Airy function for an array of numbers.
The array is generated in the EES Equations Window:
$TabStops 0.25 in
Duplicate i=1,10
X[i]=i/10
End
The macro starts by solving the Equations Window and then exporting the X array values to the
file C:\Temp\Input.dat that can subsequently be opened by MATLAB.
Solve
Export 'C:\Temp\Input.dat' X[1..10] //export the array to a file
An application of MATLAB is opened using the MATLAB.Open macro command.
MATLAB.Execute macro commands are used to open the file, execute the Airy command in
MATLAB and finally save the results to the file C:\Temp\Output.txt.
MATLAB.Open //open MATLAB
MATLAB.Execute('A=importdata('C:\Temp\Input.dat')')
MATLAB.Execute('B=airy(A)')
MATLAB.Execute('save('C:\Temp\Output.txt','B','-ascii')')
The Import macro command is used to read the data in the file C:\Temp\Output.txt into the array
Y. The Solve macro command is executed in order to have EES rebuild the Arrays Table. Then
arrays X and Y are used to create a plot using the NewPlot macro command.
Import 'C:\Temp\Output.txt' Y[1..10]
Solve
NewPlot Name='Plot 1' Table=ARR1 X=X[i] Y=Y[i] Rows=1..10 Line=1 Symbol=0 Color=0
The result of running the macro should be the plot of the Airy function shown in Figure 18-20.
676 Chapter 18: Macros
N=3
A[1,1..N]=[2, 3, 1] {define the array}
A[2,1..N]=[1, 5, 1]
A[3,1..N]=[7, 1, 2]
b[1..N]=[1, 2, 5] {define the vector}
Select Open or Create Macro from the File menu. Provide a name for the macro and enter the
commands shown in Figure 18-22.
Figure 18-22: Macro Window showing commands to solve a linear system of equations.
Click the green Play button to start the macro. The Arrays window will show the x vector.
Figure 18-23: Arrays window showing the vector x returned from MATLAB.
678 Chapter 18: Macros
Serial.Open
Serial.ReadChar
Serial.ReadNumber
Serial.ReadString
Serial.ReadtoLookup
Serial.WriteChar
Serial.WriteNumber
Serial.WriteString
Serial.Close
This section will provide several examples of serial communication. The examples presented
here demonstrate how these commands can be used to allow EES to communicate with the
Arduino UNO board. However, these commands would work to create an interface between
EES and any device that communicates with the serial port.
https://www.arduino.cc/en/Main/Software.
/*
Turns on an LED on or off according to a signal sent through the serial port.
The Arduino acknowledges the action by writing a string to the serial port.
*/
char C;
void setup() {
pinMode(13, OUTPUT); // initialize digital pin 13 as an output.
Serial.begin(9600);
}
Chapter 18: Macros 679
void loop() {
delay(1000); // wait for a second
if (Serial.available() >0) {
C=Serial.read();
if (C=='H') {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("Bulb is on");
}
if (C=='L') {
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
Serial.println("Bulb is off");
}
}
}
#include <dht.h>
#define dht_dpin A0 //Set equal to channel sensor is on
dht DHT;
char C;
int Start,Time;
void setup(){
Serial.begin(9600);
delay(1000);//Wait 1000ms recommended delay before accessing sensor
Start=millis();
}//end "setup()"
void loop(){
if (Serial.available()>0) {
C=Serial.read();
DHT.read11(dht_dpin);
Time=float(millis()-Start)/1000;
Serial.println(Time);
Serial.println(DHT.humidity);
Serial.println(DHT.temperature);
}
}// end loop()
The EES macro is programmed to loop continuously (actually, 20000 times). Within each loop,
the macro collects 20 samples of the time, humidity and temperature and saves them in a Lookup
table named 'Lookup 1'. The Lookup table, with three columns named 'Time', Humidity, and
'Temperature', should be created before playing this macro, as shown in Figure 18-24. Initially,
you should fill the table with reasonable values and prepare a plot of temperature and humidity
Chapter 18: Macros 681
versus time. This will allow you to generate the plot and select appropriate scale ranges for
temperature and humidity. The time scale should be set to automatically scale. The plot should
be set to automatically update for both temperature and humidity.
Figure 18-24: Create this Lookup table and plot before playing the macro.
Now the macro shown in Figure 18-25 can be played. This macro is designed to collect 20
values of elapsed time, temperature and humidity and place them in the Lookup table using the
Serial.ReadtoLookup macro command. The data are collected at 2 second intervals, initiated by
the macro writing character C to the serial port. After 20 values are collected, the Plot window is
shown and the most recent 20 values of temperature and humidity are displayed. The data are
also continuously written to a disk file. Note the use of the OnError macro command. If the
Arduino board fails to provide data on the serial port as expected, an error is thrown. However,
with the OnError command, control is passed to label 10: in the macro file, which effectively
skips to the next data point without displaying an error.
This macro will run for a long time, but it can be interrupted by pressing the Esc key or clicking
the Stop button in the Macro window.
682 Chapter 18: Macros
Figure 18-25: EES Macro to log, plot and store the temperature and humidity data.
The Arduino program is shown in Figure 18-26. Note that it waits for a character to be available
on the serial port. If the character is an R, the bulb displays red. G displays green and B displays
blue. If the character is not one of these three letters, nothing is done.
Chapter 18: Macros 683
The color character will be sent to the Arduino from the Diagram window. There are several
steps to creating the Diagram window and macro.
Start EES. If EES is already open then use the New command from the File menu to start a new
session. Select the Open or Create Macro from the File menu. When prompted for a name, enter
RGB.emf. Then enter the macro file shown in Figure 18-27. This macro will not interact with
the Arduino board in this form. If you wish to test the connection to the Arduino board, change
the C=%%1 line to C=1 and click the Play button. The LED should have changed to red. Try C=2
and C=3. When you are satisfied that the program works, change the line back to C=%%1. Click
the Save button in the Macro window tool bar to save this macro file and close the macro
window using the Close macro command in the File menu.
.
684 Chapter 18: Macros
COLOR$='RED'
Open the Diagram window and configure it to be in Development mode with the Diagram
toolbar displayed. Select the Text tool in the Diagram window tool bar. We are going to create
a drop-down control to select the color. Click the Input Variable button and select COLOR$ as
the input variable. Uncheck the Include variable name control. Check the Use string list and
Format display controls and click the Edit button. Enter RED//Color=1, GREEN//Color=2, and
BLUE//Color=3 on separate lines, as shown in Figure 18-28. The click the OK button in both
dialogs.
A drop-down input control should now be visible in the Diagram window and it will be used to
set the color. Delete the COLOR$='RED' equation from the Equations window since COLOR$ will
not be set by the drop-down control.
The final step is to create a Link button by clicking on the Link button in the tool bar. Set the
caption to be OK. Select the Play Macro (adapted) and use the Browse button to locate the
RGB.emf macro that you just saved. Enter variable Color to the right of the macro file name, as
shown in Figure 18-29. Click the OK button to dismiss the dialog.
Figure 18-29: Link button dialog showing parameters for linking to macro file RGB.emf.
Hide the Diagram window tool bar so that the Diagram window is in Application mode. The
Diagram window should now appear as seen in Figure 18-30. Clicking the arrow on the right of
the drop-down control will display the RED, GREEN, and BLUE options, but the information to
beginning with // is hidden.
Figure 18-30: Diagram window showing drop-down control and link button.
686 Chapter 18: Macros
When a color selection is made from the drop-down list, EES string variable COLOR$ is set to
the name of the color and the scalar variable Color is set to 1, 2, or 3 by the hidden code to the
right of the // characters. When you click the OK button, macro file RGB is opened and %%1 is
replaced by the value of Color. The macro is then executed. Selecting Red and clicking the OK
button should now cause the LED to show red
Changing the color of an LED bulb may not be exciting, but with this technique, any type of
hardware control can be implemented in EES and that is exciting.
Chapter 18: Macros 687
We will use a very simple set of macro commands to illustrate how EES can be controlled from
external programs. In this example, we will use EES to return property information for a
specified fluid. The EES program that will be executed contains the following equations.
v=volume(R$,T=T,P=P)
h=enthalpy(R$, T=T,P=P)
s=entropy(R$, T=T,P=P)
Enter these equations into EES and save the file as C:\Temp\TestMacro.ees. (Change the path
name throughout this example as needed to operate on your computer system.) Next, we'll create
a macro file that opens the EES file, imports the fluid, temperature and pressure of interest from
a file, calculates the properties, exports the results to a file, and closes EES. The macro can be
created in the EES Macro Window or using any text editor.
Open 'C:\Temp\TestMacro.ees'
Units SI C kPa J Mass
Import 'C:\Temp\Input.dat' R$ T P
Solve
Export 'C:\Temp\Output.dat' R$ T P v h s
Quit
Save the macro file as C:\Temp\aMacro.emf. Note that the file name extension must be .emf to
indicate an EES Macro File.
'R134a' 50 200
Next, enter EES C:\Temp\TestMacro.emf into the edit space of the Run dialog, as shown in Figure
18-31, and click the OK button.
688 Chapter 18: Macros
Figure 18-31: Starting EES and a macro command list from the Windows Run dialog.
Note that EES accepts the name of the macro file (in this case C:\Temp\aMacro.emf) as an input
parameter as well as an EES file name. When EES is provided with the name of a macro file, it
will start EES in a hidden state and execute the macro commands quietly. The only indication
that EES is running is the appearance of the EES icon in the application tray at the bottom of the
screen. The macro command set opens the EES file that calculates properties and then writes the
results to the file C:\Temp\Output.dat. After the command has completed, you should find the
Output.dat file in the C:\Temp\ directory. Open the Output.dat file to see the computed
properties:
The MATLAB function is called EESProperty and the header is given below:
function[v, h, s] = EESProperty(R, T, P)
%[v,h,s]=EESProperty(R,T,P)
%
% Inputs
% R = an EES recognized fluid
% T = temperature (C)
% P = pressure (kPa)
%
% Outputs
% v = specific volume (m^3/kg)
% h = specific enthalpy (J/kg)
% s = specific entropy (J/kg-K)
end
Chapter 18: Macros 689
The file C:\Temp\Input.dat is opened using the fopen command in MATLAB. The 'w' flag
indicates that the file is available to write to and any existing contents are flushed. The fprintf
command is used to write the inputs R, T, and P to the file. Notice the formatting required to put
single quotes around the string R so that it is read appropriately as a string in EES. The file is
closed using the fclose command.
The system command in MATLAB executes a command in the operating system as if it were
entered into the Run Window. We will use the system command to open EES with the macro
file name as an input parameter.
EES will open and automatically execute the commands in the macro C:\Temp\aMacro.emf.
This causes EES to open the file C:\Temp\Input.dat and assign the contents to the variables R$,
T, and P in the EES file. The file is solved and the properties v, h, and s are written to the file
C:\Temp\Output.dat. Finally, EES is closed. It is necessary to pause within MATLAB while
this process occurs in order to allow EES time to finish these operations. The pause command in
MATLAB is used for this purpose. The duration of the pause that is required will be different
for different machines; it is dependent on the time required to read and write the data files. The
code below waits for 2 seconds. See the example in Section 18.8 for a faster method that uses
the clipboard.
All that remains is to open the file C:\Temp\Output.dat and assign the values to the output
parameters v, h, and s in the MATLAB function EESProperty. This is done using the importdata
command in MATLAB.
The MATLAB function EESProperty can now be run like any other MATLAB function in order
to provide access to EES' internal property routines. To calculate the properties of R134a at
50ºC and 200 kPa, enter the following lines in the MATLAB Command Window:
>> R='R134a';T=50;P=200;
>> [v,h,s]=EESProperty(R,T,P)
v=
0.1277
h=
2.9670e+005
s=
690 Chapter 18: Macros
1.1164e+003
which leads to v = 0.1277 m3/kg, h = 2.9670x105 J/kg, and s = 1.1164 J/kg-K. Notice that there
is no visual indication that EES has started and executed the macro command list. However, you
see that the C:\Temp\EESMacro.log file appears in the directory. A disadvantage of this
example is that EES must be opened each time it is called and it closes after the calculations are
completed. See section 18.8 for a modification of this example that does not require EES to be
repeatedly opened.
Select Visual Basic from the Developer tab in order to access Visual Basic, as shown in Figure
18-33.
Select Module from the Insert menu in order to create a new module. The module will contain a
function Volume that returns the specific volume given the fluid name, temperature, and pressure.
Declare the function with three arguments (R, T, and P) as shown below. Notice that the type of
each argument as well as the type of the value returned by the function are declared.
End Function
In order to write the string to a file in a name that is recognized by EES it must be surrounded by
single quotes. A temporary string, RR is declared and formed.
Dim RR As String
RR = "'" + R + "'"
Note that the single quote is surrounded by double quotes. The file C:\Temp\Input.dat is opened
for output using the Open command in Visual Basic. The quantities RR, T, and P are written to
the file and it is closed. The macro aMacro.emf is modified so that only specific volume is
returned using the Notepad program, as shown in Figure 18-34.
Figure 18-34: Modified macro aMacro.emf that returns only specific volume.
The Shell command in Visual Basic is used to execute system commands. The EES program is
opened with the macro name provided as the parameter. The EES program TestMacro.ees is
opened and the inputs R$, T, and P are read from the file C:\Temp\Input.dat. The program is
solved and the value of the calculated specific volume, v, is written to the file
C:\Temp\Output.dat.
Next it is necessary to pause for a sufficient amount of time to allow EES to complete its
calculations and write the output file. This may be different for different machines; the code
below pauses for 2 seconds.
PauseTime = 2
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
The file C:\Temp\Output.dat is opened by Excel and the value of Volume is read using the Input
command.
692 Chapter 18: Macros
The function Volume can be used like any other Excel function. For example, enter the fluid
name, temperature, and pressure into sequential cells and then call the function Volume referring
to these cells as inputs, as shown in Figure 18-36(a). The value returned by Volume is shown in
Figure 18-36(b). Figure 18-36(c) illustrates a range of values filled in using the Volume function.
(a)
(b)
Chapter 18: Macros 693
(c)
Figure 18-36: (a) Calling the function Volume from the Worksheet, (b) the value returned, and (c) a range of
values returned.
We can write an interface between LabView and EES using this technique. Open EES and write
a simple program that computes the specific volume given the fluid, temperature, and pressure.
$UnitSystem SI Mass J K Pa
v=volume(R$,T=T,P=P)
Save the EES program as TestMacro.ees in a temporary directory. Select Open or Create Macro
from the File menu and save the macro file as monitor.emf. The macro file first deactivates
writing to the log file using the LogFileName macro command; this is necessary in order to avoid
creating an endlessly growing log file as the loop executes continuously.
Next, the input file name is assigned to the string variable File$. The timestamp for this file is
obtained using the TimeStamp macro command.
10:
Pause 0.2 //pause 0.2 seconds between loops
new = TimeStamp(File$) //get the new timestamp of the file
If (new>old) Then Goto 20 //if the timestamp has changed then execute commands
694 Chapter 18: Macros
Goto 10
The first line is a label that can be used with Goto statements. The next line pauses 0.2 seconds
between each execution of the loop in order to avoid eating up all of the computer resources.
The third line obtains the new timestamp of the input file. If the timestamp changes then
execution is directed to line 20 where any commands that are to be executed upon detecting a
new input file will be placed. Finally, the loop is repeated using the Goto 20 statement.
20:
Beep 2 //make a noise
old=new //reset the time stamp
Goto 10 //return to the loop
In this case, each time the timestamp of the input file changes, EES will make a noise and then
reset the timestamp and re-enter the loop. Using NotePad, prepare a simple input file as shown
in Figure 18-37.
Save the Input.dat file and then start the EES macro. Each time you save the Input.dat file you
should hear a beep, indicating that EES has detected that the timestamp of the file changed at
which time the commands between 20: and Goto 10 are executed.
We can use this macro as the basis of an interface between EES and any other program. In this
example, we will write a LabView Virtual Instrument (VI) that allows the user to enter the fluid,
temperature, and pressure and then interact with EES in order to return the specific volume.
When the timestamp of the file Input.dat changes, the EES macro will import the parameters R$,
T, and P from the file, solve the equations, and export the resulting value of specific volume to
the file Output.dat. The resulting macro is shown below:
20:
Chapter 18: Macros 695
In LabView, start a new VI and place two numeric controls (for temperature and pressure) and
one string control (for fluid) on the front panel. Place a numeric indicator (for specific volume)
on the front panel. The result is shown in Figure 18-38.
On the block diagram, place a flat sequence structure, as shown in Figure 18-39. In the first
frame, obtain the current time stamp of the file Output.dat using the File/Directory Info subvi which
can be found in the Programming>File I/O>Advanced File Functions> palette. In the second
frame, open the file Input.dat, write the inputs to the file, and close the file. The input string is
formed by concatenating the strings corresponding to the individual inputs. Note that single
quotes were added around the fluid name and spaces were added between inputs. The subvi
Number to Fractional String is used to convert the numerical inputs to strings. In the third frame
place a while loop that continuously reads the time stamp of the file Output.dat and terminates
when the time stamp changes relative to the value read in the first frame. Finally, the fourth
frame opens the file Output.dat and reads the specific volume. The string is converted to a
number using the Fract/Exp String to Number subvi and displayed using the indicator for specific
volume.
696 Chapter 18: Macros
To run the program, start the EES macro and then enter some reasonable inputs into the controls
on the LabView VI front panel. Run the VI and you should hear a beep (corresponding to EES
running) and then the value of specific volume should be displayed, as shown in Figure 18-40.
Start DELPHI XE2 and select VCL Forms Application – DELPHI from the New menu item in
the File menu. Place a button and an edit box on Form1, as shown in Figure 18-41.
Chapter 18: Macros 697
Double click on the Start button and enter the code shown in Figure 18-42. This code picks up
the name of the file entered in the edit box and concatenates it to the string C:\EES32\EES.exe
with an intervening space. The code then calls the Windows CreateProcess routine to start the
specified program. Run the program and enter C:\EES32\TestMacro\aMacro.emf in the edit box.
Then click the Start button. A message will appear to indicate whether or not the process was
successful.
Figure 18-42: DELPHI code to start EES with a specified file name.
698 Chapter 18: Macros
The Excel macro can be implemented on a form in Excel with 5 buttons, as shown in Figure 18-
43. (See the Excel Visual Basic instructions for creating a form.) The Visual Basic code that
accompanies each of these buttons is shown in Figure 18-44.
Figure 18-44: Visual Basic code for implementation of DDE with EES.
The code begins by defining ChannelNumber as a global variable. The Start EES & DDE button
runs the StartEES_click subroutine. The subroutine first starts EES in the manner described in
Section 18.3 using the Shell command. The location of the EES program is assumed to be in the
directory C:\EES32\. You will need to change this path if your version of EES is installed
elsewhere. After starting EES, the Excel macro executes the DDEInitiate command which
broadcasts a message to all open applications. Any application that can recognize EES and DDE
codes responds and Excel stores its address within the variable ChannelNumber.
Clicking the Calculate button runs the Sub_cmdDDE_Click subroutine. The Excel macro begins
by copying two columns of numbers that provide values of temperature and pressure. Then it
issues a series of macro commands to EES using the DDEExecute command. The macro
command is placed inside of square brackets, as shown in Figure 18-44. Any of the macro
commands listed in Section 18.2 can be sent to EES in this manner. In this case, EES is
instructed to open the file EXCEL_EES.ees, paste the temperature and pressure data from the
Excel sheet in the EES Parametric table, run the table, copy the third, fourth and fifth columns to
the clipboard and paste them back into Excel. The macro is run each time the Calculate button is
clicked. EES remains loaded and it does not have to be restarted each time the calculations are
initiated. The Excel sheet should appear as shown in Figure 18-45 after calculations are
completed.
700 Chapter 18: Macros
Figure 18-45: Excel Sheet after the macro has been run.
Clicking the Run button will execute the DDE RUN command in EES. EES must be running with
DDE initiated before this button is clicked. When it receives this command, EES will close any
open file and open and solve the specified file, which in this case is the CH1EX.ees example
problem in the UserLib examples folder. After solving the file, EES will write the contents of
the Solution Window to a file having the same name as the EES file, but with a .txt file name
extension. Note that the Run command is not an EES macro command and therefore is not
enclosed in square brackets.
Clicking the Play button will play the specified macro file. Note that, as with Run command, the
Play command is not an EES macro command and therefore it is not enclosed in square brackets.
The Run and Play commands do not restart EES, so they execute relatively fast.
The Quit EES & DDE button quits EES and disconnects the DDE channel.
Write the simple EES program shown below. The program reads the values of T and P from the
clipboard, uses the Volume command to compute the specific volume, and then writes the
parameter v to the clipboard.
$UnitSystem SI Mass J K Pa
Chapter 18: Macros 701
$Import 'ClipBoard' T, P
v=volume('R134a',T=T,P=P)
$Export /C 'ClipBoard' v
We will write a script in MATLAB that communicates with EES via DDE. The temperature and
pressure of interest are assigned.
The ddeinit command is used to initiate a DDE conversation with EES. The service is 'EES' and
the topic is 'DDE'.
The clipboard command is used to copy the values of T and P to the clipboard. Note that these
values are converted to strings using the num2str command and the strings are separated by a
comma.
The ddeexec command is used to execute a macro command in EES. In this case, the equations
are solved which causes T and P to be read from the clipboard, v to be calculated, and finally v to
be written to the clipboard.
The value of v is read from the clipboard and converted from a string to a number using the
str2num command.
v=str2num(clipboard('paste')); %copy the output from the clipboard & convert to number
Start EES and click the minimize button. Run the script and you should see that the variable v is
assigned in the Command Window. This approach can be expanded to create a sophisticated
interface between MATLAB and EES. Note that MATLAB can send any of the macro
commands listed in Section 18.2 to EES in this manner. The communication between MATLAB
and EES using DDE is must faster than with the macros presented in Section 18.5.
702 Chapter 18: Macros
C:\EES32\EES.exe /Hide
After receiving this command, EES will start in a minimized mode. Its icon will be visible in
the Windows task bar, but the program will otherwise not be visible on the screen.
The calling program must next send EES a series of messages according to the DDE message
protocol. The first message that must be sent is the wm_DDE_initiate message. This message is
normally sent using the Windows SendMessage command. The SendMessage command requires
four parameters. The first should be a broadcast message to all running applications. The
second must be wm_DDE_initiate. The third is the handle of the calling application. EES will
use this handle to send a message back to the calling application. The final parameter is a
global atom referring to 'EES', so that EES knows to act on this initiate message. Shown below
is a code fragment in Delphi XE2 that sends the wm_DDE_initiate message to EES.
EES will respond to the wm_DDE_initiate message by sending the application a wm_DDE_ack
message. Included in this message is the handle to the EES application, here called
EESWindowHandle, that the calling program must provide in following messages. A code
segment that receives the wm_DDE_ack message may appear as shown below.
procedure TForm1.GetACK(var theMessage:TMessage);
Type charString:array[0..255] of char;
var AppName,TopicName:charString;
S:shortString;
ReturnCode:smallInt;
begin
inherited;
EESWindowHandle:=theMessage.wParam;
ReturnCode:=LoWord(theMessage.lParam);
S:='Acknowledgement received.';// with result code = '+inttoStr(ReturnCode);
MessageDlg(S, mtInformation, [mbOk], 0);
Chapter 18: Macros 703
end;
After the wm_DDE_initiate message has been received by EES, the calling application can next
send a wm_DDE_execute message with an EES Macro command enclosed in square braces. The
code fragment below shows how the macro Solve command can be sent. Any macro command
listed in Section 18-2 can be initiated in this manner. The macro commands must be enclosed
with in square brackets, as shown for the Solve command.
The Quit command terminates EES. The code below shows how it can be sent:
MacroName is the name on the tab in the Macro Window that contains a set of macro
commands. The inputs are separated from the outputs by a colon (:) as in the Call statement for
internal and external Procedures. The CallMacro statement may only be used in the Main
program and so the inputs and outputs can only be variables in the Main program.
One difference between the CallMacro and Call statements is in the manner that the input and
output variables are transferred. In a Call statement, a copy of the inputs variables is made for
use in the internal or external Procedure. The Procedure calculates outputs and a copy of these
704 Chapter 18: Macros
outputs is transferred back to the program that called the Procedure. The names of the inputs
and outputs that appear in the Call statement can be different from the variable names in the
Procedure. Copies of the input and output variables are not made when using a CallMacro
statement. The input and output variables are appearing the CallMacro statement are variables
that already exist in the Main program. The macro that is called expects the input variables to
have been set before the macro starts execution. The purpose of the macro is to determine the
values of the outputs identified in the CallMacro statement. These values are set in the macro
itself using appropriate macro commands. The only purpose for providing the list of inputs and
outputs is to allow EES to properly block the equations so that it can call the macro at the
appropriate point in the calculations.
We will illustrate the CallMacro statement with a simple example that uses MATLAB to
determine the vector X that satisfies AX=b, where A is a 3x3 matrix and X and b are vectors
with dimension N=3. This macro will also use MATLAB to determine the inverse of the matrix
and the macro will place this inverse in a Lookup table. First, we need to create the macro.
Start EES and select Open or Create Macro from the File menu. Provide a name to save the
macro, e.g., CMTest.emf. Enter the commands shown below into the CMTest macro window.
Lock the macro window (click the macro lock button) so it won't be changed as you prepare the
EES file. Click the macro save button to save a final copy of this macro. The MATLAB macro
commands may be new to you. You can review them in section 18.2.
Next, bring the Equations window to the front. It should be empty. Enter the following
equations.
$Include C:\temp\CMTest.emf
N=3
A[1,1..N]=[2, 3, 1] {Matrix values in row 1}
A[2,1..N]=[1, 5, 1] {Matrix values in row 2}
A[3,1..N]=[7, 1, 2] {Matrix values in row 3}
b[1]+b[2]+b[3]=8 {Solve these equations to determine the b vector}
b[1]+b[2]=3
b[1]+b[3]=6
CallMacro CMtest(N, A[1..N,1..N], b[1..N]: X[1..N])
Xsum=sum(X[1..N])
Chapter 18: Macros 705
The $Include directive automatically loads the macro file from storage and places it in the
Macro Window. The A matrix is defined, row by row, followed by the b vector. The
CallMacro equation starts the macro, which determines the values of the X vector. It may take a
a minute or so to start MATLAB the first time it is called. After that, it should execute quickly.
The Arrays window should appear as seen in Figure 18-46 after the calculations are completed.
Figure 18-47: The inverse of the A matrix is placed in Lookup table Ainv
Note that the equation for Xsum is not executed until the CallMacro statement is completed. It
does not matter where in the Equations window the CallMacro statement appears. EES figures
out the order in which to solve the equations and it knows that the X vector must be defined in
order to solve for Xsum. You can see the blocking order and number of calls for each equation
in the Residuals window.
706 Chapter 18: Macros
After playing this macro file, a Lookup table named 'Factorial Design' will be created, as shown
in Figure 18-48. It would be possible to fill the Parametric table instead of the Lookup table
using the Parametric[...] macro command. It would also be easy to modify this macro so that it
fills the table with desired low and high values for each factor, rather than 0 and 1.
Chapter 18: Macros 707
Figure 18-48: Lookup table created for use in a factorial design analysis
To illustrate, consider the following simple EES file, which reads a temperature (in K) from the
first column and pressure (in kPa) from the second column of a Lookup file whose name is
stored in the string variable F$. The specific volume is found from the temperature and pressure
using the function volume (the fluid is carbon dioxide). In this example the data are read from
the first row in the table, but if the data files contained more than one row, all of the rows in a
table could be used by employing a Parametric table with the variable Row incremented each
run.
Finally, enter the following macro into the Macro window, as described in section 18.1.
Play this Macro file. It will successively find each of the .csv files, solve the EES file, and save
the results. Note that it was not necessary to open a Lookup table in order to run this macro as
EES is able to read the data directly from the file using the Lookup command. A listing of the
solution file is shown in Figure 18-50.
Figure 18-50: Listing of the file created by the macro while solving with the GetFirstFile$ and GetNextFile$
commands.
Admittedly, this is a very simple example. However, it clearly illustrates the capability of the
GetFirstFile$ and GetNextFile$ commands. These commands can be used for other purposes as
well, for example, to solve all .ees/.ees64 files in a directory, or update all .lkt/.lkt64 files.
{This example illustrates the ability to automatically create a property plot for a refrigeration cycle and
superimpose state property data using the $RunMacroAfter Directive.}
R$='R134a' "refrigerant"
T[1]=-5 [C] "evaporation temperature"
Q_dot_evap=(h[1]-h[4]) "energy balance on evaporator"
x[1]=1 "saturated vapor at compressor inlet"
P[1]=pressure(R$,T=T[1],x=x[1]) "properties for state 1"
h[1]=ENTHALPY(R$,T=T[1],x=x[1])
s[1]=entropy(R$,T=T[1],x=x[1])
s_ID[2]=s[1] "ideal compressor is isentropic"
P[2]=pressure(R$,T=T[3],x=1) "properties for ideal state 2"
h_ID[2]=enthalpy(R$,P=P[2],s=s_ID[2])
W_c_ID=-(h_ID[2]-h[1]) "specific power for ideal compressor"
ComEff=0.60 "Isentropic efficiency"
W_c=W_c_ID/ComEff "power requirement for actual compressor"
h[2]=h[1]-W_c "energy balance on adiabatic compressor"
T[2]=temperature(R$,h=h[2],P=P[2]) "compressor exit temperature"
s[2]=entropy(R$,h=h[2],P=P[2]) "and specific entropy"
Q_dot_cond=(h[2]-h[4]) "energy balance on condenser"
T[3]=40 [C] "condensing temperature"
s[3]=entropy(R$,T=T[3],x=1) "saturated vapor for plot "
T[4]=T[3] "condenser outlet temperature"
h[4]=ENTHALPY(R$,T=T[3],x=0) "saturated liquid at condenser outlet"
s[4]=entropy(R$,T=T[3],x=0)
P[4]=P[2] "neglect pressure loss in condenser"
h[5]=h[4] "valve is isenthalpic"
P[5]=P[1] "properties at valve outlet"
x[5]=quality(R$,h=h[5],P=P[4])
T[5]=T[1]
s[5]=entropy(R$,h=h[5],P=P[5])
T[6]=T[1]; s[6]=s[1] "to complete cycle in plot"
$RunMacroAfter
DeletePlot 1
PropPlot R$ TS 2 P[1] P[2] 0 DoQLines
OverlayPlot Name=1 Table=ARR1 X=s[i] Y=T[i] Rows=1..6 Line=1 Symbol=9 Color=Red PointLabels
$endMacro
The plot that results when the EES file is solved appears in Figure 18-51.
710 Chapter 18: Macros
4.Automatically open all .EES files in a directory and copy the equations into a .doc file.
The following macro commands will open each .EES file in directory 'C:\Temp'. It will then
copy the contents of the Equations window and paste it into a Word .doc file with the same
parent file name. One use of this capability is to compare the equations in different files using
the Word compare file capability.
SetDirectory('C:\Temp')
F$=GetFirstFile$('*.EES')
if (F$='') then quit
repeat
W$=ChangeFileExt$(F$,'.doc')
Open F$
Copy EquationWindow
Word.FileNew
Word.Paste
Word.FileSaveAs(W$)
Word.Quit
F$=GetNextFile$
Until (F$='')
Chapter 18: Macros 711
5.Repeatedly call EES from MATLAB without having to open and close EES each time. A
disadvantage of the example of Executing an EES Macro File from MATLAB presented in
Section 18.5 is that EES must be opened each time it is called. The process of opening EES is
slow since EES needed to open and read its library files. In addition, the example passes
information between MATLAB and EES using text files that are written to disk files. An
alternative that eliminates the need to open and close EES and write files to disk is provided in
this example.
Start EES and (as in the MATLAB example in Section 18.5) enter the following simple EES
program.
v=volume(R$,T=T,P=P)
h=enthalpy(R$, T=T,P=P)
s=entropy(R$, T=T,P=P)
Save the file as C:\Temp\TestMacro.ees. (Change the path name throughout this example as
needed to operate on your computer system.) Next, select the Open or Create Macro command
in the File menu. Enter the macro instructions shown in Figure 18-52 into the Macro Window
and save the macro file by clicking the Save icon on the tool bar. Click the green Play button to
start the macro. The EES application can now be minimized so it is not showing on the monitor.
Note that the OnError goto 10 line prevents the program from stopping if the clipboard is empty.
The first line in the macro file turns off the logging of each macro command to a file. As in the
example in Section 18.5, the macro next opens TestMacro.EES and sets the unit system. At this
point, it enters into a loop as it waits for a data to appear on the clipboard. The data on the
clipboard is assigned to string S$. New information is on the clipboard if S$ differs from the
previous value. In this case, the new information is imported into variables R$, T, and P and the
equations in TestMacro are solved. The values of v, h, and S are placed on the clipboard for use
712 Chapter 18: Macros
by MATLAB. The /C option ensures that the file is cleared before each export. The EES macro
will run continuously until the Escape key is pressed or the red stop button is clicked.
The MATLAB function EESProperty shown in Section 18.5 needs to be modified to use the
clipboard. A listing of the modified function named EESPropertyClip.m is shown below.
The function accepts the string R and values T, and P as inputs. It then places these values in a
string variables named Str and places the string on the clipboard. Next the function enters a loop
that continuously checks the clipboard waiting for the contents to change. When this occurs, the
function extracts the values of v, h, and s (placed on the clipboard by EES) and returns. There is
a time delay as information is placed on the clipboard, but it smaller than that for writing files.
To demonstrate this macro, the MATLAB script provided below calls the function in a loop,
providing new input conditions for each call the to EESPropertyClip function.
Chapter 18: Macros 713
6.Use of the Input dialog and Saving Macro files with the .EES file
The capabilities of the Diagram window are enhanced by using macros, which can be activated
with Link buttons in the Diagram window. This example will describe the operation of the
ViewFactors.EES program, located in the Examples folder, which provides the value of radiation
view factors for 12 different geometries.
The purpose of this program is provide an easy way for a user to select a geometry and enter the
dimensions to obtain the radiation view factor. Each of 12 pictures in Figure 18-53 is a link
button. Right-clicking on the picture at the upper left of the Diagram window while in
Development mode will bring up the Link button Properties shown in Figure 18-54.
Figure 18-54: Link Button Properties dialog for the upper left button
Note that the link button is set to be a button with picture and the picture file is provided at the
upper left of Figure 18-54. The button is programmed to play macro F3D1. The fact that the
macro does not have an .emf file name extension indicates that it is to be saved with the EES file.
The macro is shown in Figure 18-54. A similar macro is provided for each of the button.
Figure 18-55: Macros for each of the 12 buttons in the Diagram window.
Return the Diagram window to Application mode by hiding the tool bar. Clicking on the upper
left button will initiate macro F3D1. The macro includes an Input command which will display
the prompt in Figure 18-56.
Chapter 18: Macros 715
Figure 18-56: Input macro command puts up a prompt to enter values for a, b, and c.
The macro will then solve for the view factor and display the results using the entered values.
Figure 18-57: Calculated view factor for a=1 [m], b=2 [m] and c=3 [m]
Note the blue text at the bottom of Figure 18-53. This is a hypertext link to the view factor
library. This link is created by placing a transparent button over the text. The link button
characterics are shown in Figure 18-58.
A very powerful feature of EES is that functions and procedures can be written in any compiled
language, such as Pascal, C, C++ or Fortran or in a scripted language, such as Python. These
code segments, referred to as external functions and procedures, are used in exactly the same
manner as internal EES functions and procedures that have been saved in library (.lib) files, as
described in Chapter 11. They can even be coded so that the units of the input and output
variables will be checked by EES, in the same manner as for internal functions and procedures.
Warning and error messages can be returned from the external routines and displayed by EES.
External functions and procedures will be automatically loaded when EES starts if they are
placed in the Userlib directory. (The 64-bit version uses the Userlib64 directory.) Alternatively,
they can be manually loaded using the Load Library command from File menu or the $INCLUDE
directive. Help files can be provided for documenting external functions and procedures in the
same manner as described in Chapter 11 for library files. External functions and procedures
offer some significant advantages. External routines that are written in a compiled language and
provided to EES as dynamic link libraries will execute much faster (~10x) than their internal
counterparts and the equations that are employed can not be seen by the user. External
procedures that are written in Python allow this popular and easy to use scripting language to be
integrated with EES, eliminating the need to translate code.
where the parameter S is a 256 ANSI character string, Mode is a 4-byte integer, and Inputs is a
pointer to the head of a linked list of input values. The linked list structure consists of a double
precision value and a pointer to the next input. The last input points to nil. Fortran 77 does not
support pointers, therefore .dlf external functions cannot be written in Fortran 77. Pointers and
linked lists are possible with Fortran 95 and newer Fortran compilers, so external functions can
be written with newer Fortran compilers. However, doing so requires conversion from Fortran
pointers to C pointers. It is easier to write Fortran external procedures using the .fdl format that
does not require use of pointers, as described in Section 19.3.
Chapter 19: External Functions and Procedures 717
An external function must be written to accept one or more input arguments and use them to
calculate a result that is assigned to the function name. An external function should also
internally provide an example of it how it is to be used, the units of the inputs and function
output, and check that the number of inputs supplied in the linked list is equal to the number of
inputs that the function expects. To demonstrate the process, a simple function will be written in
Pascal and C++. The function will be called RMS and it will return the root mean square of up to
200 values that are supplied to it as arguments. The root mean square is defined in Eq. (19-14)
library MyFunc;
{$E .DLF}
type
charstring=array[0..255] of ansichar;
ParamRecPtr = ^ParamRec;
ParamRec = record { defines structure of the linked list of inputs }
Value: double;
next: ParamRecPtr;
end;
begin
end.
Figure 19-1: Skeleton listing of an external function for EES written in Delphi 2010.
The code begins with the Delphi keyword ‘library’, which instructs the compiler to compile the
code as a dynamic link library (.dll) file. The project file name (MyFunc in Figure 19-1) follows
the library keyword; the project has a .dproj file name extension. The {$E .DLF) directive
instructs the compiler to save the compiler library file with the project file name and a .dlf file
name extension, i.e., MyFunc.DLF. This is the name that EES will use to access the function
A string type (charstring) is defined as an array of 256 ANSI characters. The string can be used
for input or output. The string is used to output an example of the proper use of the function and
any error messages. A pointer to a data structure called ParamRec is defined. This pointer
provides the linked list of inputs that are passed to the external function from EES when it is
called. Each item in the linked list consists of a double precision value and a pointer to the next
link. The last link must point to a null record (nil). EES will automatically construct this linked
list when the function is called and pass it as the argument to the function.
718 Chapter 19: External Functions and Procedures
The function (named F in Figure 19-1) must have the three arguments, as shown, and it must
return a double precision value. The ‘export’ keyword directs the Delphi linker to make the
function accessible to other programs. The ‘stdcall’ keyword is required to ensure that the
arguments are passed to and from EES in the order that EES expects. Note that the exported
function is renamed from F to ‘MyFunc’ using the ‘exports’ keyword. This renaming is necessary
as Delphi does not allow a function to have the same name as the project, and it is the project
name that is assigned to the compiled function.
The parameter S is a 256-character ANSI C string terminated with an ASCII 0 (null character).
S can be used for both input and output. If the first parameter provided in the EES function is a
string constant (within single quotes) or a string variable then EES will pass this string to the
external routine. If an error is encountered, S should be set in the external routine to an
appropriate error message. If the length of S is not zero, EES will terminate calculations and
display S in an error message.
The parameter Mode is an integer set by EES. If Mode = –1, then EES is requesting that the
function return in S an example of the function call. If Mode = –2, EES is requesting that the
function return in S the units of the input variable(s), separated with commas. Mode = –3, EES is
requesting that the function return in S the units of the function return value. If Mode >= 0, then
the function should simply return the function value. Currently, EES does not use the return
value of Mode.
A method to register external functions and procedures is implemented in EES versions 10.011
and newer. Before calling the external program the first time, EES will call it with Mode = –1
and with the character string S set to '['+EESIDNo+']', e.g., [0001]. EESIDNo is the EES
registration number that appears on the EES start-up screen. The external program can ignore
this information or it can internally use it to set a flag if this EES license is not intended to use
the external program. This capability allows control of specialized libraries developed by users.
The parameter Inputs is a pointer to the head of a linked list of input values supplied by EES. The
function should count the inputs to ensure that the number provided is as expected and issue an
error message in S if this is not the case.
Figure 19-2 provides a complete listing of an external function named RMS written in Delphi
XE4 that returns the root mean square of an array of values. Unit checking is not provided in
this example program, since it is a general utility that could have any units. To avoid having
EES check units, the value of S returned when Mode=-2 or-3 should be the null string. Use the
Build command from the Project menu in Delphi XE2 to create the file RMS.dlf. Copy this file
into the EES Userlib folder and start EES to test it. (Use .DLF64 for the file name extension and
place the compiled program in the EES Userlib64 folder for the 64-bit version.)
library RMS;
{$E .DLF}
OutputUnits = -3;
type
CharString = array[0..255] of ansichar;
ParamRecPtr=^ParamRec;
ParamRec=record {structure of linked list}
Value:double;
next:ParamRecPtr;
end;
begin
RMS_p:=1;
if (Mode = doExample) then begin
S := 'RMS(X[1..N])';
exit;
end;
if (Mode = InputUnits) or (Mode = OutputUnits) then begin
S := '';
exit;
end;
if (Mode < 0) then
exit;
N:=CountValues(Inputs);
if (N<1) or (N>200) then
S := 'The number of values must be between 1 and 200.'
else
RMS_p:=RMSCalc;
720 Chapter 19: External Functions and Procedures
end; {RMS_p}
exports
RMS_p name 'RMS';
begin
{no initiation code needed}
end.
Figure 19-2: Complete listing of the RMS function written in Delphi XE2.
The function RMS will automatically load when EES is started, provided that it is found in the
Userlib directory. You can confirm that it has been loaded using the Function Information dialog
(Options menu) by clicking the External routines button, as shown in Figure 19-3. Select the
RMS item that should appear in the list. EES will call the function with the request to return an
example of how the function should be used, which is displayed in the Example box at the
bottom of the dialog.
Figure 19-3: Function Information dialog showing RMS function and an example call.
Figure 19-4 provides a listing of an EES program that calls the RMS function.
Chapter 19: External Functions and Procedures 721
Figure 19-4: EES Equations window showing an example use of the RMS function.
The function returns 581.7. If you try to set N to be greater than 200 then the function should
return an error message in string S that EES will display.
#include <windows.h>
#include <stdlib.h>
#include <math.h>
extern "C" // Use the "C" style calling convention to avoid C++ mangled names
The project file starts by including the required libraries and then defining the constant
doExample and the linked list ParamRec structure that will be used to pass values from EES. The
structure consists of a value and a pointer to the next value. The last value is the null pointer, or
0.
The extern "C" statement is required for every function declaration having a C header in
order to ensure that the function header is not “mangled”, i.e., modified by the compiler. The
722 Chapter 19: External Functions and Procedures
declspec(dllexport) keyword instructs the compiler to export the function with the
required STDCALL protocol and eliminates the need for a .def file. Note that the function must
accept three arguments. The first argument (S) is a 256 array of ANSI characters that will be
primarily used to output an example of the function call or for warning and error messages. The
second argument (mode) is an integer which is used both for input and output. If mode = -1 then
the function is expected to return a string with an example call. If mode = -2, the function should
return a string containing the units of each input, separated by a comma. If mode = -3, the
function should return a string providing the units of the function. All other values of mode
indicate that the function should return a calculated result. The third argument, Inputs, is a
pointer to the first link of the linked list of inputs. On return, mode should be set to 0 for normal
operation. If mode > 0, the string (S) will be displayed as an error message and EES will halt. If
mode < 0, the string (S) will be displayed as a warning and calculations will proceed.
A complete listing of the RMS function written in Microsoft Visual C++ with Visual Studio 2010
is shown in Figure 19-6. This function should be compiled and linked as a Win32 Dynamic-
Link Library with name RMS.dlf.
Chapter 19: External Functions and Procedures 723
#include <windows.h>
#include <stdlib.h>
#include <math.h>
extern "C"// Use the "C" style calling convention to avoid C++ mangled names
int CountInputs(struct ParamRec *Inputs)
{
int NInputs=0;
ParamRec *anInput=Inputs;
while (anInput != 0) //Count Inputs
{
anInput=anInput-
>next; NInputs++;
};
return NInputs;
}
extern "C"
{ declspec(dllexport) double RMS(char s[256], int& mode, struct ParamRec *Inputs)
{double Result;
int NInputs;
ParamRec * anInput;
if (mode==doExample) {
strcpy(s,"RMS(X[1..N])");
return 0;
}
if (mode==InputUnits || mode==OutputUnits) {
s="";
return 0;
}
if (mode<0) {
return 0;
}
NInputs= CountInputs(Inputs);
if (NInputs<1 || NInputs>200) {
strcpy(s,"The number of values provided to RMS must be between 1 and 200");
return 0;}
anInput = Inputs;
Result=0;
while (anInput!= 0)
{
Result = Result+(anInput->value)*(anInput->value);
anInput = anInput->next;
};
Result=sqrt(Result)
; return Result;}
};
Figure 19-6: Complete listing of the RMS function written in Microsoft Visual C++.
Copy the file RMS.dlf file into the EES Userlib folder and start EES. The RMS function should
automatically load. You can confirm that the function has been loaded by using the Function
Information command from the Options menu and clicking on the External Routines button.
You should see RMS in the list of routines, as shown in Figure 19-3. Click on RMS and the
example of the call to the function should appear in the Example box at the bottom of the dialog.
The function is called from EES as shown in Figure 19-4.
724 Chapter 19: External Functions and Procedures
where ProcName is the name of the procedure, ‘text’ is an (optional) text string that will be passed
to the procedure. This text can either be a string constant enclosed in single quote marks or a
string variable. The input text is the only string input allowed in an external procedure. The
input list A, B, ... can consist of one or more numerical inputs separated by a list separator
(comma for the U.S. system, semicolon for the European system) appearing to the left of the
colon. Inputs may be numerical constants, EES variable names, or algebraic expressions. The
output list X, Y, ... are outputs determined by the procedure. There should be one or more outputs
to the right of the colon, separated by list separators. Outputs must be EES numerical variable
names. String variables are not allowed. Note that the Call statement used to access external
procedures is identical in format to the Call statement used for internal EES procedures, which
are described in Chapter 3. Also note that it is not necessary to supply variables for all of the
outputs. Only the variables that are to be determined need to be supplied, provided the
appropriate number of list separators is included in the Call statement.
There are two formats for external procedures, referred to as Type 1 and Type2. The Type 1
format is recognized by having a .dlp file name extension. It uses a linked list for the input
arguments and a second linked list for calculated outputs with the following format.
where S is a 256 ANSI character string, Mode is a 4-byte integer that is used for both input and
output, as described below. The parameter Inputs is a pointer to the head of a linked list of input
values and the parameter Outputs is a pointer to the head of a linked list of output values.
The linked lists are most conveniently programmed in Pascal, C++, and in any compiled
language that supports pointers. The Type 2 format, identified with a .fdl file name extension,
uses arrays rather than linked lists and therefore it can be written in Fortran, Pascal, C++, or any
compiled language that can write a dynamic linked library file. This section describes the Type
1 procedure format and shows examples in Pascal and C++. Section 19.3 describes the Type 2
procedure format.
An external procedure must be written so that it accepts one or more input arguments that are
used to calculate one or more output arguments. The parameters are passed by reference with
the STDCALL protocol in the Windows Operating System. An external procedure should also
internally provide an example of it how it is to be called, the units of the inputs and outputs, and
check that the number of inputs and outputs supplied in the linked lists are equal to the number
that the procedure expects. It can output a warning or error message as needed. To demonstrate
Chapter 19: External Functions and Procedures 725
the process, a simple procedure will be written in Pascal and C++. This procedure will be called
MDAS (for Multiply-Divide-Add-Subtract). The procedure will accept two inputs (X and Y) and
it will return four outputs (M = X*Y, D = X/Y, A = X+Y, and S = X-Y). To illustrate the unit checking
capability, it will be assumed that variables X and Y are both expect to have units of m (meters).
library MyProc;
{$E .DLP}
type
charstring=array[0..255] of ansichar;
ParamRecPtr = ^ParamRec;
ParamRec = record { defines structure of the linked list of inputs }
Value: double;
next: ParamRecPtr;
end;
begin
end.
Figure 19-7: Skeleton listing of an external procedure for EES written in Delphi XE4.
The code begins with the Delphi keyword ‘library’, which instructs the compiler to compile the
code as a dynamic link library (DLL) file. The project file name (MyProc in Figure 19-7) follows
the library keyword; the project has a .dproj file name extension. The {$E .DLP} directive instructs
the compiler to save the compiler library file with the project file name and a .dlp file name
extension, i.e., MyProc.dlp. This is the name that EES will use to access the function
A pointer to a data structure called ParamRec is defined. This structure provides the linked list of
inputs and outputs that are passed between the external procedure and EES. Each item in the
linked list consists of a double precision value and a pointer to the next link. The last link must
point to a null record (nil). EES will construct linked lists for the inputs and outputs when the
procedure is called and pass the addresses of the pointers.
The procedure (named P in Figure 19-7) must have the four arguments provided in the order that
is shown. The ‘export’ keyword directs the Delphi linker to make the function accessible to other
programs. The ‘stdcall’ keyword is required to ensure that the arguments are passed to and from
EES in the order that EES expects. Note that the exported procedure is renamed to be ‘MyProc’
using the ‘exports’ keyword. This renaming is necessary as Delphi does not allow a procedure to
726 Chapter 19: External Functions and Procedures
have the same name as the project, and it is the project name that is assigned to the compiled
function.
The parameter S is a 256-character ANSI C string terminated with an ASCII 0; the parameter S
can be used for both input and output. If the first parameter provided in the EES function is a
string (within single quotes), EES will pass this string to the external routine. The parameter
Mode is an integer set by EES for input and it is set by the procedure for output. If Mode = –1,
during input, then EES is requesting that the procedure return in S an example of the function
call. If Mode = –2, EES is requesting that the function return in S the units of the input
variable(s), separated with commas. Mode = –3, EES is requesting that the function return in S
the units of the function return value. If Mode >= 0, the function should return the calculated
output values. For output, the procedure should return Mode = 0 for normal operation. If an
error is encountered, Mode should be set to a positive integer and S should be set in the external
routine to an appropriate error message, which EES will display and terminate. If Mode is set to
a negative integer, EES will display S as a warning message.
Before calling the external program the first time, EES will call it with Mode = –1 (EES 10.011
and newer) and with the character string S set to '['+EESIDNo+']', e.g., [0001]. EESIDNo is the
EES registration number that appears on the EES start-up screen. The external program can
ignore this information or it can use it to set a flag if this EES license is not intended to use the
external program. This capability allows control of specialized libraries developed by users.
The parameter Inputs is a pointer to the head of a linked list of input values supplied by EES. The
procedure should count the inputs to be sure that the number supplied is as expected and issue an
error message in S if this is not the case. Outputs is a pointer to the head of linked list of output
values that are calculated and returned by the procedure.
Figure 19-8 provides a complete listing of a external procedure named MDAS written in Delphi
XE2 that implements the MDAS (Multiply-Divide-Add-Subtract) procedure. Use the Build
command from the Project menu in Delphi XE2 to create file MDAS.dlp. Copy this file into the
EES Userlib folder and start EES to test it. Alternatively you can load the external procedure
using the Load Library command from the File menu. (In the 64-bit version use file name
extension .dlp64 and copy the file to the EES Userlib64 folder.)
library MDAS;
uses SysUtils, Classes;
{$E .DLP}
begin
N := 0;
while (P <> nil) do begin
N := N + 1;
P := P^.next
end;
CountValues := N;
end; {CountValues}
exports
MDAS_p name 'MDAS';
begin
{no initiation code needed}
end.
Figure 19-8: Complete listing of the MDAS procedure written in Delphi XE4.
728 Chapter 19: External Functions and Procedures
Figure 19-9 shows a short EES program that calls the procedure MDAS and the resulting Solution
Window. Note that the solution shows that there are 3 possible unit errors. This warning
appears because the units of variables M, A, and S were not set in the main program and it
illustrates that EES is checking units in the call to the external program. The units of variable D
are ''.
Figure 19-9: Example EES program that calls external procedure MDAS and the resulting Solution Window.
Set the units of M, A, and S in the main program by, for example, using the Variable Information
dialog or by right-clicking on each variable in the Solution window. After the units are set, the
Solution window will show that there are no unit problems (Figure 19-10).
#include <windows.h>
#include <stdlib.h>
#include <math.h>
extern "C" // Use the "C" style calling convention to avoid C++ mangled names
The project file starts by including the required libraries. The APIENTRY system call is needed to
specify the entry point for the dynamic link library file. The constant doExample is set and the
linked list ParamRec structure that will be used to pass inputs and outputs between EES and the
library file is defined. The structure consists of a value and a pointer to the next value. The last
value is the null pointer, or 0.
The extern "C" statement is required for every function declaration having a C header to
ensure that the function header is not “mangled”, i.e., modified by the compiler. The
declspec(dllexport) keyword instructs the compiler to export the procedure with the
required STDCALL protocol and eliminates the need for a .def file. Note that the procedure
must have four arguments. The first argument (S) is a 256 array of ANSI characters that can be
used for input or output. On output, it will be used for output of a example format or warning or
error messages. The second argument (mode) is an integer. If mode = -1, the procedure is
expected to return a string with an example call. If mode = -2, the function should return a string
containing the units of each input, separated by a comma. If mode = -3, the function should
return a string providing the units of the each output, separated by a comma. All other values of
mode indicate that the procedure should return calculated output values. The third argument,
Inputs, is a pointer to the first link of the linked list of inputs. The procedure is responsible for
calculating outputs, which are placed in the Outputs linked list.
730 Chapter 19: External Functions and Procedures
On return, mode should be set to 0 for normal operation. If mode > 0, the string (s) will be
displayed as an error message and EES will halt. If mode < 0, the string (s) will be displayed as
a warning and calculations will proceed.
A complete listing of the MDAS procedure written in Microsoft Visual C++ is shown in Figure
19-12. This program should be compiled and linked as a Win32 Dynamic-Link Library with
name MDAS.dlp.
Figure 19-9 shows a short EES program that calls procedure MDAS and the resulting Solution
Window. Note the unit checking that takes place based on the unit strings the external procedure
returns. Figure 19-10 shows the SolutionWindow after the units have been set in the main
program to the units expected by the external procedures.
Chapter 19: External Functions and Procedures 731
#include <windows.h>
#include <stdlib.h>
// Defines a stdcall entry point for the dll
BOOL WINAPI DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{ return TRUE; }
const int doExample=-1; int InputUnits=-2; int OutputUnits=-3;
struct ParamRec { // Structure for handling EES calling syntax
double value;
struct ParamRec *next;};
extern "C"// Use the "C" style calling convention to avoid C++ mangled names
int Count(struct ParamRec *Inputs)
{
int N=0;
ParamRec *P=Inputs;
while (P! = 0) //Count Inputs
{
P=P->next;
N++;
};
return N;
}
extern "C"
{ declspec(dllexport) void MDAS(char s[256], int& mode, struct ParamRec *Inputs,
struct ParamRec *Outputs)
{double X,Y;
int NInputs, NOutputs;
ParamRec *P;
if (mode==doExample) {
strcpy(s,"Call MDAS(X, Y : M, D, A, S)");
return;
}
if (mode==InputUnits) {
strcpy(s,"m,m");
return;
}
if (mode==OutputUnits) {
strcpy(s,"m^2,,m,m");
return;
}
if (mode<0) {
return;
}
NInputs= Count(Inputs);
if (NInputs =2) {
strcpy(s,"The number of inputs provided to MDAS must be 2");
return;}
P = Inputs;
X=P->value; P=P->next;
Y=P->value;
NOutputs= Count(Outputs);
if (NOutputs =4) {
strcpy(s,"The number of outputs provided to MDAS must be 4");
return;}
P = Outputs;
mode=0;
P->value=X*Y; P=P->next;
P->value=X/Y; P=P->next;
P->value=X+Y; P=P->next;
P->value=X-Y;
}
};
Figure 19-12: Complete listing of the MDAS procedure written in Microsoft Visual C++.
732 Chapter 19: External Functions and Procedures
Type 2 procedures can be written with any compiler that can write a dynamic link library for the
Windows Operating System with the STDCALL protocol, including Fortran 77 (or later).
However, because the procedure is called from a program (EES) that is written in a different
language, it is necessary to provide the compiler and linker with instructions about how to pass
the arguments of the procedure. The required instructions vary depending on the Fortran
compiler that is used. Instructions are provided here for the Intel Visual Fortran and the MinGW
Fortran compilers.
SUBROUTINE MDAS(S,MODE,NINPUTS,INPUTS,NOUTPUTS,OUTPUTS)
DEC$ATTRIBUTES ALIAS:'MDAS' :: MDAS
DEC$ATTRIBUTES DLLEXPORT :: MDAS
IMPLICIT NONE
INTEGER(4) MODE, NINPUTS, NOUTPUTS
REAL(8) INPUTS(50), OUTPUTS(50), X, Y
CHARACTER(255) S
IF (MODE.EQ.-1) THEN
S='CALL MDAS(X,Y:A,B,C,D)'C
RETURN
ENDIF
IF (MODE.EQ.-2) THEN
S='m,m'C
RETURN
ENDIF
IF (MODE.EQ.-3) THEN
S='m^2,,m,m'C
RETURN
ENDIF
IF (MODE.LT.0) THEN
S=''C
RETURN
ENDIF
IF (NINPUTS.NE.2) THEN
S='MDAS requires two input.'C
RETURN
ENDIF
IF (NOUTPUTS.NE.4) THEN
S='MDAS EXPECTS TO PROVIDE 4 OUTPUTS'C
RETURN
ENDIF
X=INPUTS(1)
Y=INPUTS(2)
IF (ABS(Y).LE.1E-9) THEN
S='DIVISION BY ZERO IN MDAS'C
RETURN
ENDIF
Chapter 19: External Functions and Procedures 733
OUTPUTS(1)=X*Y
OUTPUTS(2)=X/Y
OUTPUTS(3)=X+Y
OUTPUTS(4)=X-Y
S=''C
RETURN
END
Figure 19-13: Listing of the MDAS procedure written with the Intel Visual Fortran compiler.
The Subroutine header statement must have the six arguments shown in Figure 19-13. Parameter
S is a null-terminated C-style ANSI character string containing 255 characters. If the first
parameter in the EES Call statement is a text constant (within single quotes) or text variable
(ending with a $) then EES will pass this string to the external program in the parameter S. Any
error messages generated by the procedure are returned to EES in the parameter S. Note the use
of the terminating character C in the error message strings shown in Figure 19-13, which ensures
that the strings are terminated by an ANSI null character. The parameter S should be set to ‘’C
for normal operation.
The parameter Mode is a 4-byte integer. When EES calls the subroutine with Mode = -1, it is
instructing the external procedure to place an example of the calling sequence for this procedure
in the parameter S so that it can be displayed in the Function Info Dialog window. When EES
calls the subroutine with Mode = -2, it is instructing the external procedure to return a string
containing the units of the input variables, separated by commas or semicolons. When EES calls
the subroutine with Mode = -3 it is instructing the external procedure to return a string containing
the units of the output variables, separated by commas or semicolons. The parameter S is also
used to return a user-supplied warning or error message, if necessary. If an error is detected in
the subroutine, then Mode should be set to a value that is greater than 0 to signal that EES should
terminate calculations. If S is defined, it will be displayed in the EES error message. To display
a warning in EES, set Mode to a negative integer. During normal operation, Mode should be 0.
The parameters NINPUTS and NOUTPUTS are 4-byte integers that hold the number of inputs and
outputs, respectively. Values for the inputs are provided by EES based on information in the Call
statement issued from EES. The procedure should check to see if NINPUTS and NOUTPUTS agree
with the expected number of inputs and outputs and return an error condition, if needed, by
setting Mode > 0 or by setting S to an error message, as shown in Figure 19-13. If Mode > 0 or if
S is not the null string then EES will display an error message and then terminate.
The parameters INPUTS and OUTPUTS are arrays of double precision (REAL(8)) values. EES will
allocate memory for these arrays as needed. Up to 1000 inputs and 1000 outputs can be passed
in the argument list of external functions and procedures using array element notation, i.e.,
X[1..1000]. EES will supply the values in the INPUTS array. Results calculated by the external
procedure are placed in the parameter OUTPUTS and returned to EES.
The external program must be compiled and linked as a Dynamic Link Library (DLL) routine.
The compiling procedure differs for different languages and compilers. It is essential to set the
compiler and linker options properly in order for EES and the operating system to recognize and
use the library file. The Intel Visual Fortran compiler requires the /iface:mixed_str_len_arg and
/iface:cvf compiler options, as shown in Figure 19-14. The /iface:mixed_str_len_arg compiler
734 Chapter 19: External Functions and Procedures
option instructs the compiler to include the string length (for string S) as a hidden argument
directly after the string argument. The /iface:cvf option instructs the compiler to use the
STDCALL format and to pass the arguments by reference (rather than by value); it further
instructs the Fortran compiler to export the name of the subroutine in uppercase letters. On a 32-
bit system, this option also results in @N being appended to the procedure name, where N = 32 is
the number of bytes for the pointers to the arguments. EES will not be able to identify the
procedure with the @N appended. Consequently, the first compiler directive beginning with
DEC$ in Figure 19-13 is required to force the compiler to rename the procedure according to the
name provided in quotes, which will not have the @N appended. The second compiler directive
in Figure 19-13 instructs the compiler to make the procedure visible as a dynamic link library.
Figure 19-14: External Procedures Properties for the Intel Visual Fortran Compiler.
It is also necessary to specify the runtime library that will be included with the compiled library
file. Even though the compiler is creating a DLL, you should not select the Multithread DLL
runtime library. Instead, select the Multithreaded Runtime library, as shown in Figure 19-15.
The Multithread DLL library will not work on some systems and it is not needed for the DLLs
that are built for use with EES.
Chapter 19: External Functions and Procedures 735
Figure 19-15: Runtime Library Properties for the Intel Visual Fortran Compiler.
By default, the file name extension of a dynamic link library is .dll. This extension must be
changed to .fdl in order for EES to recognize the Type 2 procedure format. The change can be
made by changing the output file name template provided for the linker.
Figure 19- 16: Linker Properties showing the output file name extension set to .fdl.
736 Chapter 19: External Functions and Procedures
Type 2 (.fdl procedure) with the MinGW Open Source GCC Fortran Compiler
MinGW is a development environment for Microsoft Windows applications that provides an
Open Source programming tool set, including the GNU Compiler Collection (GCC). This
compiler collection includes a Fortran compiler that can be used to generate Type 2 (.fdl)
external procedures. This section provides summary data for downloading, installing and using
the GCC Fortran compiler for creating .fdl external procedures. For more information please
visit http://www.mingw.org.
To install MinGW (Minimalist GNU for Windows), download the latest version by clicking on
Installer link from http://sourceforge.net/projects/mingw/files/. In the next window, click the
Download mingw-get-setup.exe link. This will download the installer program. Then run
mingw-get-setup.exe. You will see a screen similar to that shown in Figure 19-17. Select the
files shown in this figure for installation. Then select Apply Changes menu item from the
Installation menu, as shown in Figure 19-18. By default the compiler files will be installed in
directory C:\MinGW.
Figure 19-17: Screen shot from the MinGW Installation program showing selected options.
Figure 19-18: Selecting the option to install the MinGW compiler form the Installation menu.
The compiler should now be installed. It is next necessary to prepare the Fortran source file,
which for this example, will be named MDASF.F90. This program will multiply, divide, add
and subtract two input values, just as we did in previous examples in this section.
Chapter 19: External Functions and Procedures 737
A few changes must be made compared to the source code shown in Figure 19-13. It is
necessary to tell the compiler and linker to create the dynamic library using the STDCALL
convention. This is accomplished by entering the following line to the source code.
The MinGW Fortran compiler handles strings differently than the Intel Visual Fortran compiler,
and this difference requires an additional minor change in the Fortran source code compared to
that used in Figure 19-13. Specifically, an additional integer variable (LS) must be added after
the string argument (S) in the Subroutine statement so that the Subroutine statement appears as
In addition, all strings must be terminated with the C_null_char, which is defined in the
iso_c_binding library. A Use command is required to access this library.
That is all of the required changes. A complete listing of the source code for the MDASF.F90
file follows in Figure 19-19.
SUBROUTINE MDASF(S,LS,MODE,NINPUTS,INPUTS,NOUTPUTS,OUTPUTS)
USE iso_c_binding, only: c_null_char !necessary to append a null character
IMPLICIT NONE
INTEGER(4) MODE, NINPUTS, NOUTPUTS, LS
REAL(8) INPUTS(50), OUTPUTS(50), X, Y
CHARACTER(255) S
!GCC$ ATTRIBUTES STDCALL :: MDASF ! STDCALL calling convention for FDL
IF (MODE.EQ.-1) THEN
S='CALL MDAS(X,Y:A,B,C,D)'//C_null_char
RETURN
ENDIF
IF (MODE.EQ.-2) THEN
S='m,m'//C_null_char
RETURN
ENDIF
IF (MODE.EQ.-3) THEN
S='m^2,,m,m'//C_null_char
RETURN
ENDIF
IF (MODE.LT.0) THEN
S=''//C_null_char
RETURN
ENDIF
IF (NINPUTS.NE.2) THEN
S='MDAS requires two input.'//C_null_char
RETURN
ENDIF
IF (NOUTPUTS.NE.4) THEN
S='MDAS EXPECTS TO PROVIDE 4 OUTPUTS'//C_null_char
RETURN
ENDIF
MODE=0
738 Chapter 19: External Functions and Procedures
X=INPUTS(1)
Y=INPUTS(2)
IF (ABS(Y).LE.1E-9) THEN
S='DIVISION BY ZERO IN MDAS'//C_null_char
RETURN
ENDIF
OUTPUTS(1)=X*Y
OUTPUTS(2)=X/Y
OUTPUTS(3)=X+Y
OUTPUTS(4)=X-Y
S=''//C_null_char
RETURN
END
Figure 19-19: MDASF Fortran source code (MDASF.f90) for the MinGW Fortran compiler.
A definition file (here called mdasf.def) is required by the linker in order for EES and the
compiled .FDL procedure to communicate successfully. The contents of the definition file are:
EXPORTS
mdasf_@32 @ 1
MDASF = mdasf_@32
The .def file should be placed in the same directory as the .f90 source code. Note that mdasf on
the second and third lines of the .def file is the name of the subroutine that appears in the source
code; however, the name should be all lower case in the .def file. If the subroutine name is
changed then these lines should be changed accordingly. (The _@32 characters that are
appended to the subroutine name are used by the compiler to provide information relating to the
type and number of parameters.)
Now that the source file (MDASF.f90) and the definition file (MDASF.def) are created, it is
necessary to use the MinGW compiler to create the libarry file. The compiler can be accessed
from the Windows Commands Prompt window. One way to open this window is to enter
Command.com in the edit box above the Start button that appears in the lower left of the screen.
The Command Prompt window is shown in Figure 19-20.
.
Chapter 19: External Functions and Procedures 739
In the Command Prompt window, first set the path to the compiler by entering
SET PATH=C:\MinGW\bin;%PATH%
Then change the directory using the CD command to the directory where the .f90 and .def files
reside, e.g.,
cd c:\ees32\mdasf
Finally enter the following command to create the .fdl library file.
The file produced here is MDASF.fdl. Note that you will need to change MDASF to the name of
your external procedure name. Copy the MDASF.fdl file into the USERLIB directory within the
EES Folder. EES will automatically load the MDAS.FDL external procedure if it is located in
the USERLIB folder in EES. The Solution window that appears after calling the MDASF
procedure is shown in Figure 19-21. The unit errors that are indicated in this figure can be
eliminated by setting the units for variables M, A, and S.
Only one external function or procedure will be recognized by EES in these file types. The
filename extension (.dlf, .dlp, or .fdl) identifies the type of externally compiled file and the name
of the external routine must be the same name as filename (without the extension).
Note that that 64-bit version of EES uses similar 64-bit files that are indentified with a 64 at the
end of the file name extension, e.g., .dlf64 or .fdl64. The 64-bit version cannot read .dlf, .dlp,
.fld, or .dll files and the 32-bit version cannot read .dlf64, .dlp64, .fld64, or .dll64 files.
However, it is also possible to place one or more external routines in a single file and this single
file can contain one or more external programs of all three types of external routines. The
external file can have any name but it must have a .dll filename extension. If this file is placed in
the UserLib (or Userlib64) subdirectory then EES will automatically load all the external
routines in the file at startup, provided that the Library Manager (See Chapter 11) does not direct
otherwise.
EES must know the names of all of the external routines in the .dll file and their type (.dlf, .dlp,
or .fdl) because the calling arguments differ for each type. The mechanism for telling EES the
names and types of the external routines is to provide three short routines in the DLL file with
names DLFNames, DLPNames, and FDLNames. These routines do nothing but return the
calling names of each routine type in the DLL file. DLFName, DLPNames, and FDLNames
must be exported in the DLL. They have one argument, which is a character string. The
character string is filled with the names of the routines of each type that are contained in the .dll
file. A comma separates each file name. A zero length string is used to indicate that there are no
files of that type. A skeleton example is provided in Figure 19-22 for DELPHI XE4 code and in
Figure 19-23 for Visual C++ code.
library MYEXTRNLS {This DLL file contains two DLF functions and one DLP procedure}
uses SysUtils;
const doExample = -1;
{***********************************************************************}
type
CharString = array[0..255] of ansichar;
ParamRecPtr = ^ParamRec;
ParamRec = record
Value : Double;
Next : ParamRecPtr;
end;
{***********************************************************************}
{There are two .DLF functions; names are separated with commas}
end;
{***********************************************************************}
{There is one .DLP procedure}
procedure DLPNames(Names : PAnsiChar); export; stdcall;
begin
StrCopy(Names,'myDLP');
end;
{***********************************************************************}
{no FDL procedures so return a null string}
procedure FDLNames(Names : PAnsiChar); export; stdcall;
begin
StrCopy(Names,'');
end;
{***********************************************************************}
function myFunc1 (var S: CharString; var Mode: integer;
Inputs: ParamRecPtr): double; export; stdCall;
begin
{Code for myFunc1}
...
end; {myFunc1}
{***********************************************************************}
function myFunc2 (var S: CharString; var Mode: integer;
Inputs: ParamRecPtr): double; export; stdCall;
begin
{Code for myFunc2}
...
end; {myFunc2}
{***********************************************************************}
exports
DLFNames,
DLPNames,
FDLNames,
myFunc1,
myFunc2,
myDLP;
begin
end.
Figure 19-22: Skeleton listing of a .DLL file in Delphi XE4 code that holds several EES external library files.
742 Chapter 19: External Functions and Procedures
#include <windows.h>
#include <math.h>
// Tell EES which functions and procedures are exported in the library :
// List of DLF format functions
declspec(dllexport) void DLFNames(char* Names)
{ strcpy(Names,"myFunc1,myFunc2"); }
Note that the automatic loading of both external and internal library files can be controlled in the
Professional version using the Library Manager, which is discussed in Section 11.6.
Library files can be manually loaded using the Load Library command from the File menu or by
placing a $INCLUDE “FileName” directive in the EES equations window. The filename should be
enclosed within quotes, as shown, and it must include the file name extension. It is not normally
necessary to include the directory name with the file name, as EES will look in the directory that
the EES file was loaded from as well as the EES directory if directory information is not
provided. The filename can also be provided in a string variable that has previously been
defined.
Installing PYTHON
It is necessary to install the Python interpreter on your computer in order to use Python scripts.
The Python interpreter can be downloaded at not cost from https://www.python.org/downloads/.
There are many versions of Python available at this site. It is recommended that you download
the latest version, which is Python 3.5.1 at the time of this writing. It is necessary for EES to
locate the Python interpreter (PythonW.exe). This task is made easier if you select the option to
Add Python to Path.
Also, Click on Customize Installer and select the option to install py laucher.
Chapter 19: External Functions and Procedures 745
EES looks for the PythonW.exe program at startup and it should find it if Python is installed as
described above. If EES is unable to find Python or if you have several versions of Python
installed and want to specify a particular version, you can specify the location with the
$PYTHON directive, e.g.,
$PYTHON C:\Users\username\AppData\Local\Programs\Python\Python35\pythonw.exe
Call Python('filename.pyw', 'optional string', In1, In2, ... : Out1, Out2, ....)
The first argument in the parameter list is the file name of the Python script that is to be run.
Note that the file name must have a .pyw file name extension. Python scripts should normally be
placed in the EES Userlib\Python directory. In this case, the script information and associated
help files can be viewed in the Function Information dialog after selecting the External routines
button. In addition, when the script is located in the Userlib\Python folder, the file name used in
the Call statement does not need to include directory information. It is possible to run script in
any other directory by providing the complete path and file name. The Python script name can
provided with a string constant as shown above, or with a string variable that has been set to the
file name.
An optional string can follow the file name in the Call statement. This string is passed as the
first input which is read by the Python script. If this string is not provided, EES will
automatically supply a blank string.
Numerical input values (In1, In2, ...) follow the file name or optional string in the argument list.
The values can be EES variables or numerical constants. The Python script must be designed to
read the number of inputs that are provided, each on a separate line from standard input. Note
746 Chapter 19: External Functions and Procedures
that the input values can be provided using an array using array range notation, e.g.,
Inputs[1..10].
The Python script must return one or more numerical outputs, which are assigned to the EES
variables that are placed to the right of the colon in the argument list (e.g., Out1, Out2, ...).
Array range notation can also be used for the outputs, e.g., Outputs[1..10]. There is no explicit
limit on the number of inputs and outputs, other than each variable counts against the total
variable limit in EES, which is 6000 for the Commercial version, 12,000 for the Professional
version and 24,000 for the 64-bit version.
The Python script in Figure 19-24 demonstrates how any Python script must be designed to
works with EES. The script reads inputs from the stdIn and outputs to stdout. It can be tested
before calling it from EES using normal console input and output. When called from EES, the
inputs and outputs will be piped to EES and they will not appear on the console.
The first input to the Python script is a string (SR). (Note that Python scripts are case-sensitive.)
This string provides the information in the optional string in the EES Call Python statement.
Normally, this will be a blank string, but it is possible to provide string information in the Call
statement that will be provided in this way to the script.
The next input is an integer called mode. Mode is used for both input and output. On input,
mode=-1 indicates that the script should return (i.e., print) a string indicating its calling format.
This string is displayed in the Function Information dialog when the script name is selected.
Mode=-2 indicates that the script should return a string with the units of the inputs, separated by
commas. Mode=-3 indicates that the script should return a string with the units of the outputs
separated by commas. It is not necessary to provide the example calling parameters or
input/output units. However, the script should be designed to return without doing calculations if
mode<0. Unit checking will be disabled if the script returns a blank string for mode=-2 and
mode=-3.
Chapter 19: External Functions and Procedures 747
if (y==0):
mode=2
SR='Attempted division by zero in MDAS Python program'
print(SR)
print(mode)
sys.exit(0) #return
try:
m=x*y #do the calculations
d=x/y
a=x+y
s=x-y
SR=''
mode=0 #return mode=0 if there are no errors
except:
SR='Unexpected error occurred in the MDAS Python program.'
mode=1
m=-999
d=-999
a=-999
s=-999
print(SR) # print a string. Normally blank unless error
print(mode) # print the mode.Normally, mode=0, but it can be
set to a value >0 to indicate an error
print('{}\n{}\n{}\n{}'.format(m, d, a, s)) # print the outputs,
each on a separate line.
Figure 19-24. Listing of an example Python Script.
748 Chapter 19: External Functions and Procedures
When mode>=0, the script is expected to read the numerical inputs, one per line and then initiate
the calculations. The number and order of inputs and outputs in the script must be exactly the
same as in the EES CALL statement. The script should use the inputs to calculate the outputs.
Return information is provided to EES by the print command directed to sys.stdout. If there are
no errors, the script should return (print) an empty string (SR='') and mode=0 and along with the
outputs, each on a separate line. If an error occurs in the script, mode should be set to a value >0
to indicate the error number and the string (SR) can optionally provide an error message, as
shown in the example when input y is zero.
Figure 19-26: Solution window in EES after executing the Call Python statement showing unit errors.
Note the unit errors in Figure 19-26. These unit errors occur because the Python script expects X
and Y to have units of m. The outputs (M, D, A, and S) should have units of m^2, blank (or -),
m, and m. Set the units of the EES variables in the Solution window or in the Variable
Information dialog and run the EES program again. Now it will indicate that there are no unit
errors.
Chapter 19: External Functions and Procedures 749
Figure 19-27: Solution window after units of EES variables have been set
A very important capability that EES provides to Python scripts is the exchanging of inputs and
outputs. The Python expects to receive inputs and it returns outputs. However, the equation-
solving capability built into EES may allow one or more of the outputs to be specified in order to
determine an input. For example, in the following EES program, outputs A and D are provided.
Figure 19- 28: Calling the Python script with specified outputs to determine the inputs
EES will iteratively call Python until it finds the inputs that produce these outputs.
Figure 19-29: Solution window after determining the inputs that provide the specified outputs
750 Chapter 19: External Functions and Procedures
NOTE: In order to speed up the staring process, the Component Library is not automatically
loaded, even though it resides in the ..\USERLIB folder. Include the following directive:
$LOAD 'Component Library'
at the top of the Equations file to load this library as needed. The library, once loaded, remains
loaded for the remainder of the EES session.
The Component Library is accessed from the Function Information command in the Options
menu, as shown in Figure 21-1. Click the Component Library button and select the category of
interest from the dropdown menu to the right of this button. A second dropdown menu to the
right of the picture (hidden in Figure 21-1) allows the category to be refined in some cases. A
small picture of the component is displayed in the dialog. The scrollbar below the picture allows
the user to select from related component models in the chosen category. Click the Info button
to display detailed information concerning the selected model. These models are written as EES
Procedures or Subprograms. You can view the EES code by clicking the View button.
Click the Index button to see an index of the component models, as shown in Figure 21-2.
Clicking on a component picture will bring up information about that component.
752 Chapter 20: The Component Library
Chapter 20: The Component Library 753
Although the capability to create component models has been part of EES since its inception, the
Component Library represents the next logical step in the development of EES. It provides the
ability to carry out detailed design and analysis of systems by connecting existing component
models together. These component models rely on the existing thermophysical property library
as well as the heat transfer and fluid flow libraries. Since the Component Library models are
written in EES, you can copy the EES code and modify it, if necessary, to suit your specific
situation. The use of the Component Library is illustrated by the following example.
throttle valve
evaporator
4 1
Wc
compressor
Figure 21-3: Schematic of the heat pump system
"Operating Conditions"
R$='R134a' "refrigerant"
T_amb=5 [C] "outdoor temperature"
P_amb=101.3 [kPa] "atmospheric pressure"
T_indoor=25 [C] "temperature of air in the building"
DELTAT_sh=5 [DELTAC] "superheating at compressor inlet"
DELTAT_sc=5 [DELTAC] "subcooling at the compressor exit"
At design conditions we will specify the cooling capacity as well as a 10°C temperature
difference between the entering air and the saturation temperatures in the evaporator and
condenser. For these operating conditions this specification corresponds to an evaporating
temperature of Tsat,evap = -5°C and a condensing temperature of Tsat,cond = 35°C. The air
temperature is specified to drop by 5°C as it passes through the evaporator and increase by 5°C
as it passes through the condenser. These design conditions are entered in EES and will be used
to size the equipment for the cycle.
"Design Point"
Q_dot=10 [kW] "heating capacity"
T_sat_evap= -5 [C] "design saturation temperature in evaporator "
T_sat_cond=35[C] "design saturation temperature in condenser"
T_air_out_evap=T_amb-5 [C] "temperature of air leaving evaporator"
T_air_out_cond=T_indoor+5 [C] "exit temperature of the air at design conditions"
The evaporating temperature sets the pressure at state 2 and the superheat sets the temperature.
Together, the pressure and temperature set the enthalpy at state 2.
The condensing temperature sets the pressure at state 4 and the subcooling sets the temperature.
Together, the pressure and temperature set the enthalpy at state 4.
There is assumed to be no pressure loss on the refrigerant sides of the evaporator and condenser.
The valve is assumed to be isenthalpic. The specific enthalpy and pressure at state 1 set the
quality and temperature.
Now that the state points have been set it is necessary to determine the compressor and heat
exchangers required. An energy balance on the condenser sets the required mass flow rate of the
refrigerant. Typical values of the clearance ratio, normalized valve pressure loss, and
compressor efficiency are assumed and the component library procedure Compressor3_CL is used
to determine the required displacement rate for the reciprocating compressor. The procedure
also provides the exit enthalpy of the refrigerant which can be used to determine the temperature
at state 3.
"Design compressor"
Q_dot=m_dot*(h[3]-h[4]) "energy balance on condenser"
C=0.025 [-] "clearance ratio"
dP_evap=0.1 "normalized pressure loss in inlet valves"
eta_cm=0.55 "combined compressor-motor efficiency"
Call Compressor3_CL(R$, DR, C, T_sat_evap, DELTAT_sh, T_sat_cond, dP_evap, eta_cm: &
eta_vol, m_dot, W_dot, h[3]) "determine displacement rate for compressor"
T[3]=Temperature(R$,h=h[3],P=P[3]) "temperature leaving compressor"
Solving at this point indicates that the required compressor power is 2.60 kW, the design
refrigerant flow rate is 0.0467 kg/s and this is driven by a compressor having a displacement rate
of 0.00476 m3/s with a 83% volumetric efficiency. This is a good time to update guess values.
The component library procedure Evaporator3_CL is used to determineboth the length of the
evaporator in the flow direction (Levap) and volumetric flow rate of air (Vair ,evap ). Note that it will
be necessary to set reasonable values of guess values for these quantities in order for EES to
converge.
Figure 21-4: Selection of a heat exchanger core from the Compact HX library
"Design evaporator"
HXg_evap$='fc_tubes_sCF-70-58J' "selected heat exchanger geometry"
W_evap=0.7 [m] "width of frontal area"
H_evap=0.7 [m] "height of frontal area"
th_tb_evap=0.0009 [m] "tube wall thickness"
N_circuits_evap=2 "number of parallel circuits for refrigerant"
Call Evaporator3_CL(R$, m_dot, h[1], P[1], DELTAT_sh, V_dot_air_evap, T_amb, P_amb, &
HXg_evap$, W_evap, H_evap, th_tb_evap, N_circuits_evap : L_evap, A_R_evap, &
UA_evap, Q_dot_evap, h_R_out_evap, T_air_out_evap, DELTAP_air_evap, f_sh_evap)
Solving shows that the required volumetric air flow rate is about 1.16 m3/s and the required
surface area (refrigerant side) for the evaporator is about 3.0 m2. The required evaporator length
in the flow direction is 0.14 m and the design air pressure drop across the evaporator is 52 Pa.
Note that Evaporator3_CL determines the heat transfer coefficients for air and refrigerant using
the heat transfer library. Separate heat transfer coefficients are determined for the saturated and
superheated sections. About 6.6% of the evaporator surface area is needed to provide the
specified 5°C superheat at the evaporator exit.
A similar process is carried out for the condenser using the procedure Condenser3_CL. The
condenser length and volumetric flow rate of air (Lcond and Vair ,cond ) are determined. Note that
Condenser3_CL returns the rate of heat transfer in the condenser, but this variable has already be
758 Chapter 20: The Component Library
specified. In order to avoid over-defining the problem, this output parameter is named
Q_dot_cond.
"Design condenser"
HXg_cond$='fc_tubes_sCF-70-58J' "selected heat exchanger geometry"
W_cond=0.7 [m] "width of frontal area"
H_cond=0.7 [m] "height of frontal area"
th_tb_cond=0.0009 [m] "tube wall thickness"
N_circuits_cond=2 "number of parallel circuits for refrigerant"
Call Condenser3_CL(R$, m_dot, h[3], DELTAT_sc, P[3], V_dot_air_cond, T_indoor, P_amb, &
HXg_cond$, W_cond, H_cond, th_tb_cond, N_circuits_cond : L_cond, A_R_cond, &
UA_cond, Q_dot_cond, h_R_out_cond, T_air_out_cond, DELTAP_air_cond, f_sh_cond, f_sc_cond)
Note that it would also be possible to adjust the frontal area (W and H) for both heat exchangers
in order to satisfy a design point air-side pressure drop. The required air flow rate is 1.68 m3/s
and the required length of the condenser in the flow direction is 0.13 m. The fraction of the
condenser in the superheat region is 14.4% and 8.7% is used for the subcooled section. We can
calculate the COP and the fan power, assuming a fan efficiency of 0.60.
At this point, we could easily investigate a number of design parameters. For example, different
heat exchanger surfaces could be used with different frontal areas. The effect of the air flow rate
on performance on fan power could be determined. The importance of compressor clearance
volume could be investigated. However, the focus will now be changed to determining the
performance of this system with fixed hardware at different outdoor conditions.
A new EES program that accomplished the simulation is developed. Because of the iterative
nature of the heat pump simulation program, it is necessary to provide reasonable guess values
for the saturation temperatures in the evaporator and condenser as well as for other states. In this
example, the guess values are provided using a $IF directive. A string variable, Mode$ is used to
determine whether the guess values are to be initialized. Mode$ is initially set to 'initialize'.
After entering and running the complete simulation program, the guess values are updated and
Mode$ is set to something other then 'initialize' to conduct the simulation.
Mode$='Initialize'
Chapter 20: The Component Library 759
This program begins by specifying the operating condition and then importing the hardware
parameters using the $Import directive.
R$='R134a' "refrigerant"
T_amb=5 [C] "outdoor temperature"
P_amb=101.3 [kPa] "atmospheric pressure"
T_indoor=25 [C] "temperature of air in the building"
DELTAT_sc=5 [DELTAC] "subcooling at the compressor exit"
DELTAT_sh=5 [DELTAC] "superheating at compressor inlet"
If Mode$ is set to 'initialize', reasonable guess values are provided for the evaporating and
condensing temperatures. After the program has been fully entered and checked, we will change
Mode$ to some other string, effectively removing these guess values and replacing them with
other equations that allow these temperatures to float according to the performance of the
evaporator and condenser. Note that the $UpdateGuesses directive is included in the $If clause
so that the guess values will be updated to provide a start for the simulation.
$if Mode$='Initialize'
T_sat_evap=-5 [C] "guess for evaporating temperature"
T_sat_cond=35 [C] "guess for condensing temperature"
$UpdateGuesses
$endif
The temperatures and pressures at states 2 and 4 are fixed by the assumed saturation
temperatures together with the superheat and subcool.
The enthalpy at state 2 is fixed by the temperature and pressure. The Compressor3_CL procedure
is used to compute the mass flow rate (note that the displacement rate of the device is now fixed)
and compressor exit enthalpy. There is no pressure loss on the refrigerant side of the condenser
and therefore the pressure and enthalpy at state 3 fix the temperature.
The condenser parameters are fixed, including the flow length and the air flow rate. Therefore, it
is best to use the procedure Condenser4_CL to simulate the condenser. Condenser3_CL was
developed to determine the required surface area (or flow length) given the outlet state.
Condenser4_CL uses the specified flow length to determine the outlet state, which is more
consistent with the simulation that we are doing here. In this case EES could solve the equations
in either way, but we will use Condenser4_CL, as it provides better convergence when the
outdoor temperature is changed.
The condenser exit enthalpy and pressure together specify the temperature at state 4. Calculating
T4 at this point would over-constrain the problem since T4 was already computed based on the
assumed value of the condensing temperature. We only want to calculate T4 when we are not
setting the saturation temperature. This can be accomplished by using a $Ifnot directive testing
string variable Mode$.
$ifnot Mode$='Initialize'
T[4]=Temperature(R$,h=h[4],P=P[4]) "temperature leaving condenser to achieve proper subcooling"
$endif
Your EES code should solve and you should find that Tsat,cond = 35°C because we are simulating
the system at exactly the design point. Changing the operating conditions will cause the
condensing temperature to float as necessary given the fixed size of the condenser and the
condenser fan.
The valve is isenthalpic and there is no pressure drop across the evaporator. The enthalpy and
pressure at state 1 fix the quality and temperature.
h[1]=h[4] "valve"
P[1]=P[2] "no pressure loss in evaporator"
x[1]=quality(R$,h=h[1],P=P[1]) "quality at evaporator inlet"
T[1]=Temperature(R$,h=h[1],P=P[1]) "temperature at evaporator inlet"
The evaporator geometry and size and the evaporator fan is fixed. As with the condenser, the
procedure Evaporator4_CL is more robust than Evaporator3_CL for this type of simulation where
the size is known and the outlet state is being predicted. The output of Evaporator4_CL is the
enthalpy leaving the evaporator (state 2). However, h2 has already been set based on the
assumed evaporating temperature is Mode$ is set to 'initialize'. Therefore, we will only call the
Evaporator4_CL procedure to compute h4 and the remainder of the code that computes the
capacity and COP if Mode$ is not set to 'initialize.
Chapter 20: The Component Library 761
$ifnot Mode$='Initialize'
Call Evaporator4_CL(R$, m_dot, h[1], P[1], V_dot_air_evap, T_amb, P_amb, HXg_evap$, &
W_evap, H_evap, L_evap, th_tb_evap, N_circuits_evap : Q_dot_evap, h[2], &
T_air_out_evap, DELTAP_air_evap) "simulate evaporator - adjust T_sat_evap "
Run the program with Mode$ set to 'initialize'. It should run without errors and then set the
guess values. Now, set Mode$ to something other than 'initialize'.
Mode$='dontInitialize'
Your EES code should solve and you should find that Tsat,evap is about -5°C; again, this is because
we are simulating the system at the design point. The heating capacity, fan power, and total
COP are computed.
Solving leads to a heating capacity of 10 kW and a COP of 3.38; this performance is identical to
the performance at the design condition. Now we can investigate the effect of outdoor
temperature on the performance of this heat pump system. Set up a Parametric table to include
variables Tamb, Q, and COP. Fill the Tamb column in with values between 15 and -15°C. It will
be necessary to either comment out the equation that sets the variable T_amb in the Equations
window or use a $IFNOT ParametricTable directive, as shown here.
$IfNot ParametricTable
T_amb=20 [C] "outdoor temperature"
$Endif
Solve the table. (It may be necessary to solve from rows 7 to 10 and then from rows 1 to 7 in
reverse in order to use the guess values for already determined for row 7. The results are shown
in Figure 21-6. You may also want to use the Property Plot command in the Plots menu to create
a P-h plot for the refrigerant and then overlay a plot the pressure-enthalpy values for states 1
through 4, as shown in Figure 21-5.
762 Chapter 20: The Component Library
4
5x10
R134a
4
10
16°C
1 2
2 -21°C
10
1
10
-100 0 100 200 300 400 500
h [kJ/kg]
Figure 21-5: Pressure Enthalpy plot for the heat pump at the design point.
The plot of the heating capacity and COP versus outdoor air temperature in Figure 21-7 shows
that both are significantly reduced as the outdoor temperature is reduced.
Chapter 20: The Component Library 763
Figure 21-7: Plot of heating capacity and COP versus outdoor air temperature.
764 Chapter 20
CoolingCoil2_CL This model predicts the performance of a heat exchanger designed to cool humid air
in which the air is cooled by heat exchange with a brine solution. Other than using
brine instead of pure water, this model is the same as CoolingCoil1_Cl.
CoolingTower1_CL This model determines the performance of a counterflow cooling tower using the
analogy method. An enthalpy effectiveness is determined as a function of the heat
transfer coefficient between the air and the water. Fan power is not calculated and
its effect on the tower capacity is not included. Drift or water spray carryover is
neglected. The effect of makeup water temperature is also neglected.
Heat Exchangers
HeatExchanger1_CL Model of a heat exchanger in which a fluid is interacting with a reservoir (i.e., a
source or sink that has infinite capacitance). The approach temperature difference is
specified. This function works with real fluids, ideal gas, incompressible, or brines.
HeatExchanger2_CL Models a heat exchanger in which two fluids interact with one another. The
approach temperature difference is specified. In this model, the pinch point must
occur at either the hot or cold end. The procedure supports real fluids, ideal gas,
incompressible, or brines on either side.
HeatExchanger3_CL Models a circular finned tube heat exchanger in which a single phase liquid or brine
(on the tube side) interacts with a single phase gas (on the fin side). The procedure
works with any type of fluid on the liquid side (including brines) and any type of
fluid on the gas side except brines. The procedure determines the heat transfer and
pressure drop characteristics on both sides. Properties are assumed to be constant
and are computed at the inlet temperatures. Effectiveness is calculated assuming
that heat exchanger behaves as an unmixed-unmixed cross-flow heat exchanger.
Nozzles & Diffusers
Nozzle1_CL Adiabatic nozzle with a specified efficiency.
Diffuser1_CL Adiabatic diffuser with a specified efficiency.
Pumps
GearPump1_CL A simple model of a gear pump. The volumetric flow rate is determined from
displacement rate less leakage flow. Power is determined from overall efficiency
applied to displacement flow rate.
GearPump2_CL Calls GearPump1_CL using performance parameters that are based on specific
models of gear pump.
Turbines
Turbine1_CL Model of a low reaction, single-stage radial turbine operating outside of the vapor
dome. Mass flow rate is determined from the nozzle area and spouting velocity
assuming that all of the pressure drop is across the nozzle. Isentropic efficiency is
determined from a generic efficiency vs velocity ratio curve. The standard curve
can be shifted vertically and horizontally.
Turbine2_CL A model of a turbine with a specified isentropic or polytropic efficiency.
Appendix A 767
Integral(F,X) arguments Start, Stop, and Step are not provided, the Integral function can only be
used in conjunction with a Parametric Table. In this case, X must be a variable that
has values defined in one of the columns of the Parametric Table. F is a variable
Integral(F,X,Start,Stop,Step) or algebraic expression involving X and other variables or values. If Start, Stop,
and (optionally) Step are provided, EES will repeatedly solve all equations
involving variable X, setting the value of X to values between Start and Stop as
appropriate. If Step is not provided, EES will internally choose a step size using
an automatic stepsize adjustment algorithm. The Integral function can be used to
solve initial value differential equations. See Chapter 7 for additional information.
Returns a value from the Integral Table that is created using the $IntegralTable
directive. t is the value of the independent integration variable for which the value
of variable X is to be returned. X is a string constant indicating the name of a
IntegralValue(t,X)
variable that has been included in the Integral Table. (The single quotes around
the string constant are optional.) The value provided for t must be less than or
equal to the current value of the independent integration variable.
+t e t dt © k , X
k /2 1
=
2 2
Chi_Square(X,k) F (X,k) = 0
k
+t k /2
2
1 t
e dt
0
where © is the lower incomplete Gamma function and is the Gamma function.
Returns the complementary error function defined as
2
Erfc( X ) = 1 Erf ( X ) =
2
Erfc(X) e t dt
X +
Returns the function for the argument value X, defined as
Gamma(X)
( X ) = +t
X 1
e t dt
0
Returns the largest argument value. The number of arguments must be between 1 and
2000 . An array or subset of an array can be provided in the argument list by using array
Max(X)
range notation, e.g., Max(X[1..50]). (See also MaxLookup and MaxParametric in Table A-
9.)
Returns the smallest value. The number of arguments must be between 1 and 2000. An
Min(X) array or subset of an array can be provided in the argument list by using array range
notation, e.g., Min(X[1..50]). (See also MinLookup and MinParametric in Table A-9.)
Returns the standard deviation of the arguments. The number of arguments must be
StdDev(X1, X2, …XN) between 2 and 2000. An array or subset of an array can be provided as an argument list
by using array range notation, e.g., StdDev(X[1..50]).
772 Chapter 20
where z = 1 and z = 2
1
2
Returns the product of a series of terms. Arg can be any algebraic expression.
Series_info provides the name of the product index variable and the lower and upper
limits, which must be integers or variables which have been previously set to integer
Product(Arg, Series_Info) values. Product(j, j=1,4) will return 1*2*3*4 or 24, which is 4 factorial. The Product
function is most useful when used with array variables, e.g., X[]. For example, the
product of the squares of all 10 elements in the array X[] can be obtained as Product
(X[j]*X[j], j=1,10).
Returns a uniformly distributed number in the range between A and B. C is optional. It
controls the seed for the random number generator. If C is 0, the Random function will
produce a new result each time it is called.. If C is a positive value, the Random function
Random(A, B, C)
will produce the same random number each time it is called. If C is a negative number ,
the Random function will produce a new random number when an EES file is opened but
thereafter, calls to the Random function will produce the same random number.
RandG operates just like the Random function but it selects a random number from a
RandG(A, B, C)
Gaussian (rather than uniform) distribution.
StdDev(X[1..N]) Returns the standard deviation of a series of numbers. The numbers can be input with
array name notation, as shown in the first option or as individual EES variable names as
Sum(X1, X2, … XN) shown in the second options.
There are two forms for the Sum function. EES determines which format is in use by
context. The first form returns the sum of a series of terms. Arg can be any algebraic
expression. Series_info provides the name of the summation index variable and the lower
and upper limits. These limits must be integers or variables that have been previously set
Sum(Arg, Series_Info) to integer values. For example, Sum(j, j=1,4) will return 1+2+3+4 or 10. The Sum
function is most useful when used with array variables, e.g., X[]. For example, the scalar
product of two vectors, X[] and Y[], each with 10 elements can be obtained as
Sum(X1, X2, … XN) Sum(X[j]*Y[j], j=1,10).
The second form returns the sum of the arguments. Array range notation is particularly
convenient for this form. For example, Sum(X[1..100]) returns the sum of the 100
elements in the array X[].
Appendix A 773
contains fewer than N points, N is set to the number of points in the table. If N is
set to be less than 8, EES will reset it to 8 and issue a warning message. If N is not
provided, a value of -16 is assumed so that the default case is a bi-quadratic
method with 16 points. See Section 2.4 for more information.
Interpolate2DM provides two-dimensional linear interpolation for data in a Lookup
Table or Lookup file that are arranged in a row and column matrix format. T$ is a
string constant or string variable that provides the name of the Lookup Table or
the name of an existing Lookup file stored on disk. X is the value of the
Interpolate2DM(T$, X, Y) independent variable whose values appear in the first row of the table. The
columns used to determine the interpolated value will be identified by this value.
Y is the value of the independent variable whose values appear in the first column
of the table. The rows used to determine the interpolated value will be identified
by this value. See Section 2.4 for more information.
Returns the value in Lookup Table T$ at the specified row and column. T$ is a
string constant or string variable that provides the name of the Lookup Table. Row
is the row in the table, but it does not need to be an integer value and linear
interpolation will be used to determine values between rows. C$ indicates the
column in the table. C$ is an integer, string constant, or string variable indicating
Lookup(T$, Row, C$)
the column. If an integer is provided, it is taken to be the column number.
Otherwise, the string constant or variable must contain the name of one of the
columns. The Lookup function can also be used to set the value of a cell in the
Lookup Table window when it is used on the left-hand side of an equation in an
internal function or procedure. Also see Lookup$ in Appendix B.
The function requires the same arguments as the Lookup function. It returns either
a 0 (if the specified cell is empty) or 1 if it contains a value. The function can be
LookupCellEmpty(T$,Row,C$) used with logic statement such as If-Then-Else and Repeat-Until in internal
functions and procedures to ensure that a cell in the Lookup Table or file contains
a value.
The LookupCol function scans a specified Row in Lookup Table T$ and returns the
column in this table at which the value is equal to V. The return value may not be
LookupCol(T$, Row, V) an integer. A bisection method is used in finding the column, using all of the
columns of data in the specified row. The data in the specified row of the table
LookupCol1(T$, Row, V) must be monotonic, either increasing or decreasing. LookupCol1 operates in
exactly the same manner except that it ignores the data in the first column of the
table.
The LookupRow function scans a specified column in Lookup Table T$ and returns
the row in this table at which the value is equal to V. C$ is an integer, string
constant, or string variable indicating the column. If an integer is provided, it is
taken to be the column number. Otherwise, the string constant or variable must
LookupRow(T$, C$, V)
contain the name of one of the columns. The return value may not be an integer.
LookupRow1(T$, C$, V) A bisection method is used in finding the row, using all of the rows of data in the
specified column. The data in the specified column of the table must be
monotonic, either increasing or decreasing. LookupRow1 operates in exactly the
same manner except that it ignores the data in the first row of the table. (Also see
Lookup$Row in Appendix B.)
Returns the maximum of all or selected cells in a specified column of the Lookup
Table or Lookup file on disk having name T$. T$ can be a string constant or string
variable. C$ is an integer, string constant, or string variable indicating the column.
MaxLookup(T$, C$, R1, R2)
If an integer is provided, it is taken to be the column number. R1 and R2 are
optional arguments that provide the starting and stopping rows for which the
maximum will be found.
Returns the maximum of all or selected cells in a specified column of the
Parametric Table having name T$. T$ can be a string constant or string variable.
MaxParametric(T$,C$,R1,R2)
C$ is an integer, string constant, or string variable indicating the column. If an
integer is provided, it is taken to be the column number. R1 and R2 are optional
Appendix A 775
arguments that provide the starting and stopping rows for which the maximum will
be found.
Returns the number of columns in the Arrays Window having name T$. The
NArrayColumns(T$) Arrays Window for the main program is named ‘Main’. If the Arrays Table does
not exist, the function call will return 0.
Returns the number of rows in the Arrays Window having name T$. The Arrays
NArrayRows(T$) window for the main program is named ‘Main’. If the Arrays table does not exist,
the function call will return 0.
Returns the number of rows in a text file that is stored on disk. T$ is a string
NFileRows(T$) constant or a string variable that contains the name of the file. If the file does not
exist or it cannot be read, the function returns 0.
Returns the number of columns in the specified Lookup Table or a Lookup file
that is stored on disk. T$ is a string constant or a string variable that contains the
NLookupColumns(T$)
name of the Lookup Table or file. The function will return 0 if the table or file are
not found.
Returns the number of rows in the specified Lookup Table or a Lookup file that is
stored on disk. T$ is a string constant or a string variable that contains the name of
NLookupRows(T$)
the Lookup Table or file. The function will return 0 if the table or file are not
found.
Returns the number of columns in the specified Parametric Table. T$ is a string
NParametricColumns(T$) constant or a string variable that contains the name of the Parametric Table. The
function will return 0 if the table is not found.
Returns the number of rows in the specified Parametric Table. T$ is a string
NParametricRows(T$) constant or a string variable that contains the name of the Parametric Table. The
function will return 0 if the table is not found.
Returns the standard deviation of all or selected cells in a specified column of a
Lookup Table or Lookup file on disk. T$ is a string constant or a string variable
that contains the name of the Lookup Table or file. C$ is a integer value, string
constant or string variable the identifies the column. If an integer value is
provided, it is taken to be the column number. If a string constant is provided, it is
StdDevLookup(T$,C$,R1,R2)
assumed to be the name of the variable for the column. The single quotes that
normally identify a string constant are not required. If a string variable is
provided, it must contain the name of one of the columns in the Lookup Table. R1
and R2 are integers or EES variables specifying the starting and stopping rows for
which the operation will be performed. These parameters are optional.
Returns the standard deviation of all or selected cells in a specified column of
Parametric Table T$. C$ is a integer value, string constant or string variable the
identifies the column. If an integer value is provided, it is taken to be the column
number. If a string constant is provided, it is assumed to be the name of the
StdDevParametric(T$, C$, R1,
R2)
variable for the column. The single quotes that normally identify a string constant
are not required. If a string variable is provided, it must contain the name of one
of the columns in the Parametric Table. R1 and R2 are integers or EES variables
specifying the starting and stopping rows for which the operation will be
performed. These parameters are optional.
Returns the sum of all or selected cells in a specified column of a Lookup Table or
Lookup file on disk. T$ is a string constant or a string variable that contains the
name of the Lookup Table or file. C$ is a integer value, string constant or string
variable the identifies the column. If an integer value is provided, it is taken to be
the column number. If a string constant is provided, it is assumed to be the name
SumLookup(T$, C$, R1, R2)
of the variable for the column. The single quotes that normally identify a string
constant are not required. If a string variable is provided, it must contain the name
of one of the columns in the Lookup Table. R1 and R2 are integers or EES
variables specifying the starting and stopping rows for which the sum will be
performed. These parameters are optional.
776 Chapter 20
Function Description
Returns the sum of all or selected cells in a specified column of a ParametricTable.
T$ is a string constant or a string variable that contains the name of the Parametric
Table. C$ is a integer value, string constant or string variable the identifies the
column. If an integer value is provided, it is taken to be the column number. If a
SumParametric(T$,C$,R1,R2) string constant is provided, it is assumed to be the name of the variable for the
column. The single quotes that normally identify a string constant are not required.
If a string variable is provided, it must contain the name of one of the column. R1
and R2 are integers or EES variables specifying the starting and stopping rows for
which the sum will be performed. These parameters are optional.
Returns the Parametric Table run number for which calculations are currently in
progress. This function has no arguments and it should only be used only when
TableRun# calculations are initiated with the Solve Table or Min/Max Table command in the
Calculate menu. The name of the Parametric Table that is currently being used is
accessed with the TableName$ function.
Returns the value stored in the row and column of the specified Parametric Table
identified by T$, which can either be a string variable or a string constant. C$ is
the column, which may be either entered directly as an integer number or by
TableValue(T$, Row, C$) supplying the variable name for the desired column within single-quotes.
Alternatively a string variable may be used to provide the name of the column.
The function is useful in the solution of some marching-solution type problems in
which the current value of a variable depends on its value in previous calculations.
Returns an integer coded representation of the date and time that disk file T$ was
last modified. The larger this number is, the more recent the file. If the specified
TimeStamp(T$)
file is not found, the function returns -1. T$, which can either be a string variable
or a string constant. (See also TimeStamp$)
column is not found, the function will return '??'. The name of an existing column in a
Lookup Table can only be changed within an internal function or procedure. To change
the column name, place the LookupColName$ function call on the left hand side of an
equation in an internal function or procedure and set it equal to a string containing the
column name and units, separated by the \ character.
Returns the units of a specified column in a Lookup table. T$ is the name of a Lookup
table or a Lookup file. It may be a string constant or string variable. C can be a number
LookupColUnits$(T$,C)
or expression that evaluates to the column number in the table. If the column is not
found, the function will return '??'
Returns the row in column C$ of Lookup Table T$ in which this string N$ exists. T$ and
Lookup$Row(T$, C$, N$) N$ can be string constants or string variables. C$ can be an integer, a string constant or a
string variable that indicates the column in the Lookup Table.
Returns the name of the Lookup Table with tab number Tab. If no such tab exists then
LookupTabName$(Tab)
the function returns an empty string.
corresponding to the keyword. Possible return strings for each of the arguments are as
follows:
Appendix C: Directives
A complete list of the directives implemented at the time of publication is provided in Table C-1.
See Chapter 14 for more information and examples relating to the use of directives.
Related to Units
Directive Description
Activates or deactivates EES’ ability to automatically set the units
$AutoSetUnits On/Off
for each variable.
Turns off unit checking for a specified subset of the equations or
$CheckUnits On/Off and AutoOn/AutoOff
the entire set of equations.
This directive is only applicable when the EES_REFPROP
interface is used. If present (an not followed by keyword Off, it
will convert all inputs to and outputs from the EES_REFPROP
$ConvertEESREFPROPUnits
interface so units that are consistent the units set in the EES
program If /mass is provided, the specific properties will be
converted to a mass basis..
$UnitSystem Specifies the unit system used by EES.
Appendix C 781
See Chapter 18 for more information and examples relating to the use of macro commands.
Copy SolutionWindow Copies the contents of the Main Solution Window to the clipboard.
Sets the default information for every variable that begins with the
DefVarIno {Letter, Guess=Guess,
Units='Units', Display=Display}
specified letter. The default information can consist of the guess, lower
bound, upper bound, display format and units.
Delay (time) Pause execution for time in microseconds. See also Pause.
Transfers execution to the macro command line labeled Line. Lines are
Goto Line labeled using the Label command. Line must be an integer between 1
and 29999.
Open or process the file, which may have a file name extension of .dlf,
.dll, .dlp, .fdl .fld, .prf, or.var. (For the 64-bit version, the file name
Include F$
extensions are .dlf64, dll64, .dlp64, and .fdl64, .fld, and .var). F$ may
be a string constant or string variable containing the name of the file.
LatexPDF 'Filename' Create a .tex or .pdf document and save it in Filename This macro
command has many options. (See Table 18-3).
Changes the name of the macro log file to File$. Note that if File$ is
LogFileName File$
not included then no log file is written.
MinimizeTable /R /U /S G a b c Minimizes the variable G with respect to the variables in the list a b c
{Method=MethodKeyword /Table=Table$ for each of the rows in a Parametric Table. The optional
/Rows=RowStart..RowEnd} MethodKeyword can be used to specify the optimization technique.
The optional Table$ can be used to specify the Parametric Table. The
Appendix D 785
Clears the work space and brings up an empty Equations Window. The
New
existing file will be closed without saving.
OnError GoTo XX Transfer control to the command after label XX if an error occurs.
Pause Time Pauses execution for the number of seconds specified by Time.
Print Window Prints the window specified by the Window parameter (see Table 18-7).
PrintSetup Printer=Printer$ Sets the default printer to Printer$. The orientation and number of
{Orientation=Portrait (or Landscape) copies can be optionally specified.
Copies=NCopies}
Repeat Executes the commands in the list Command(s) until the conditional
Command(s) test Conditional is true.
Until(Conditional)
Reset X, Y, ... Resets the status of the variables in the list X, Y, ... to unassigned.
Resets the guess values for the variables in the Equations Window to
ResetGuesses
their default values.
Shows the Plot Window. The optional parameter Plot$ specifies the
ShowWindow Plot {Plot$ (or Plot#)} particular plot by name. The integer parameter Plot# specifies the plot
by tab number.
Stop Execution of the Stop macro command immediately stops the macro.
Specifies the stop criteria for the solution process. The number of
StopCrit {It=ItValue Time=TimeValue
Res=ResValue Var=VarValue}
iterations (ItValue), elapsed time (TimeValue), relative residual
(ResValue), and change in variables (VarValue) can be specified.
Units SI Mass (or Mole) Deg (or Rad) kPa Sets the unit system to SI and specifies the unit values.
(or Pa, bar, MPa) J (or kJ) C (or K)
Units Eng Mass (or Mole) Deg (or Rad) psia Sets the unit system to SI and specifies the unit values.
(or atm) F (or R)
Update Guesses Sets all variable guess values to their last set of calculated values.
VarInfo Variable {Lower=LowerValue Sets the bounds (LowerValue and UpperValue) and guess value
Upper=UpperValue Guess=GuessValue} (GuessValue) for the variable Variable.
Appendix D 787
Table D-3: Macro commands to communicate with external devices through the serial port.
Macro Command Description
Close serial port C$. If the specified serial port is not open, this command will do
Serial.Close(C$)
nothing. Parentheses around the port name are optional.
Opens the specified serial port for reading and/or writing. The baud rate, parity,
and stop bits must match the parameters of the device that EES is attempting to
communicate with. The defaults for Baud, Parity, and Stop are 9600, n, and 1. If
Serial.Open(Port=C$, these parameters are not provided, the defaults are used. Buffersize is the number
Baud=9600 Parity=n Stop=1 of bytes used for the internal read/write buffers. The maximum buffer size is 8192
BufferSize=2048 TimeOut=200) and the default is 1024. TimeOut is the number of milliseconds that EES will wait
before giving up while trying to read data from the serial port. The keyword
clauses can be separated with a space or a comma (US system) or semi-colon (EU
system).
Reads a single ASCII character from the serial port C$ into EES string variable
Serial.ReadChar(C$ H$)
H$.
Serial.ReadNumber(C$ V) Reads a numerical value into EES variable V from serial port C$.
Reads a string (terminated by CRLF) from the serial port C$ into EES string
Serial.ReadNumber(C$ S$)
variable S$.
Reads a numerical value from serial port C$ directly into the cell at row R and
Serial.ReadtoLookup(C$,T$,R,C) column C of Lookup table T$. R and C can be numerical values or EES variables
that have been previously set to numerical values.
Writes the character(s) in EES string variable H$ to serial port C$. No CRLF is
Serial.WriteChar(C$ H$)
appended.
Writes the characters forming the number EES variable V (or a numerical
Serial.WriteNumber(C$ V)
constant) to serial port C$.
Writes the string contained in EES string variable S$ to serial port C$. A CRLF is
Serial.WriteString(C$ S$)
appended to the string.
Appendix D 789
Inserts a row in Lookup Table Table$ at position After. The optional NRows
InsertLookupRows Table$ After
{NRows}
parameter specifies the number of rows to insert. If NRows<0, rows will be
deleted.
Inserts a run in Parametric Table Table$ at position After. The optional NRows
InsertParametricRuns Table$ After
{NRows}
parameter specifies the number of runs to insert. If NRows<0, rows will be
deleted.
Sets the cell Row, Column in Lookup Table Table$ to Value. Column must
either by an integer (referring to the column number) or a string constant or
Lookup[Table$, Row, string variable that provides the name of the column. Note that Value cannot be
Column]=Value an arithmetic expression. Lookup$ is also excepted and in this case, Value is
expected to be string variable. The column that Value is placed into must be
designated as a string column.
Sets the name of column Column in Lookup Table Table$ to Name$.
LookupColInfo Table$ Column Optionally, the units are set to Units$.
Name$ {Units$}
Maximizes the variable G with respect to the variables in the list a b c for each
of the rows in a Parametric Table. The optional MethodKeyword can be used to
specify the optimization technique. The optional Table$ can be used to specify
MaximizeTable /R /U /S G a b c the Parametric Table. The optional RowStart..RowEnd parameters can be used
{Method=MethodKeyword
/Table=Table$
to specify the rows within the table. If /U is provided, the guess values will be
/Rows=RowStart..RowEnd} updated after each row of the table successfully completes calculations. If /R is
provided the calculations will be start on the last row and proceed to the first
row of the specified range. If /S is provided the calculations will stop if an error
is encountered and remaining rows of the table will not be processed
Minimizes the variable G with respect to the variables in the list a b c for each
of the rows in a Parametric Table. The optional MethodKeyword can be used to
specify the optimization technique. The optional Table$ can be used to specify
MinimizeTable /R /U /S G a b c the Parametric Table. The optional RowStart..RowEnd parameters can be used
{Method=MethodKeyword
/Table=Table$
to specify the rows within the table. If /U is provided, the guess values will be
/Rows=RowStart..RowEnd} updated after each row of the table successfully completes calculations. If /R is
provided the calculations will be start on the last row and proceed to the first
row of the specified range. If /S is provided the calculations will stop if an error
is encountered and remaining rows of the table will not be processed
NewLookup Table$ Rows=NRows Creates a new Lookup Table with name Table$. The number of rows is NRows
Cols=NCols and the number of columns is NCols.
NewTable Table$ Rows=NRow X Creates a new Parametric Table with name Table$ and NRow rows with
Y Z ... columns for variables in the list X Y Z ...
Opens the lookup file LookupFile$. If ? is provided then a dialog will appear to
OpenLookup LookupFile$
{/Format FormatFile$}
allow the file to be selected. The optional FormatFile$ can be used to specify
the format that should be used to read the file.
Parametric[Table$, Row, Col (or Sets the cell in row number Row and column number Col in table Table$ to
Col$)]=Value Value. The column can also be specified by the name of the column Col$.
Pastes the contents of the clipboard in the Lookup Table Table$ at the position
specified by the parameters Row and Col. The /A is optional. If /A is provided
Paste Lookup Table$ /A Row Col
additional rows will be added to the table if needed to complete the Paste
operation. Without the /A operation, no additional rows will be added.
Pastes the contents of the clipboard in the Parametric Table Table$ at the
position specified by the parameters Row and Col. The /A is optional. If /A is
Paste Parametric Table$ /A R1 C1
provided additional rows will be added to the table if needed to complete the
Paste operation. Without the /A operation, no additional rows will be added.
Appendix D 793
Retrieve an existing Parametric table that has been stored in a file with a .txt or
RetrieveParametric Table$ .par (.par64 for the 64-bit version). Table$ can be a string variable containing
the table name or a string constant.
Initiates the Solve Table solution process using Parametric Table Table$. The
optional parameters RowStart ... RowEnd specifies the rows in the table. If /U
SolveTable /R /U /S Table$ is provided, the guess values will be updated after each row of the table
{Rows=RowStart...RowEnd} successfully completes calculations. If /R is provided the calculations will be
start on the last row and proceed to the first row of the specified range. If /S is
provided the calculations will stop if an error is encountered.
Initiate the UncertaintyTable calculations for rows 1 through 10 in Parametric
Table ‘Table 1’ to determine the uncertainty in variables X1and X2 as a result of
uncertainties in variables Y1, Y2, and Y3. Measured variables are identified
with =A or =R following their names. A indicates absolute uncertainty and R
UncertaintyTable /S /U /R 'Table 1' indicates relative uncertainty. The absolute or relative uncertainty is indicated
Rows=1..10 X1, X2 with a numerical value or with a variable name following the A or R. If /U is
Y1=A1,Y2=R0.01 Y3=Au_Tinf provided, the guess values will be updated after each row of the table
successfully completes calculations. If /R is provided the calculations will be
start on the last row and proceed to the first row of the specified range. If /S is
provided the calculations will stop if an error is encountered and remaining rows
of the table will not be processed.
794 Appendix F
Table E-1:
Keys Held Down Description
File Operations
EES normally loads all of the library files in the ..\USERLIB (or ..\USERLIB64)
Ctrl Key + Shift Key directory when it is started. To override, hold the Ctrl and Shift keys down while starting
EES. You should notice that is loads much faster, but the library files will not be loaded.
EES normally compiles and formats an EES file and then solves some of the simpler
equations when you open the file, either by double-clicking on the file icon or selecting it
Ctrl Key from the File Open command. However, if you hold the Ctrl Key down as the file is
opened, these operations will not occur. The ability to override the compiling is useful is
some circumstances, such as when a compile-time error occurs when the file is opened.
If the Ctrl and Shift keys are both depressed while a file is opened from the File menu,
only the equations, variable information and tables will be read. Plots, Diagram window
Ctrl Key + Shift Key controls, uncertainty data, variable information for Suprograms, Modules, Procedures and
Functions and key variable comments will not be read. It is usually possible to open a
corrupted EES file by pressing the Ctrl and Shift keys to recover the equations.
Parametric, Lookup and Arrays Tables
The column width of the Parametric, Lookup and Arrays tables are 90 pixels, by default.
The column widths can be changed by right-clicking in the column header and setting the
column width or more simply, by dragging the column border. The column widths are
Ctrl Key
saved along with other problem information. However, if the Ctrl key is depressed while
a file is opened, the column widths will be reset to their default values. The Professional
version provides a column width control (a double-headed arrow) in the upper left cell.
When a Parametric, Lookup, Arrays or Integral table is resized, the window size is
Ctrl Key adjusted so that an integral number of columns and rows are displayed. Holding the Ctrl
key down while resizing overrides this behavior so that the window can be set to any size.
Diagram Window
Pressing the Ctrl and Shift keys while a Diagram window is displayed in Construction
Ctrl Key + Shift Key mode (tool bar showing) will highlight the hot area of all child Diagram windows with a
red dotted line.
Clicking on a text or graphic item in the Diagram window while it is displayed in
Ctrl Key or Shift Key Construction mode normally selects that item and unselects all other items. However, if
the Ctrl key or Shift key is depressed, the current item is selected without deselecting any
items. This capability allows multiple items to be selected and then reformatted all at
Appendix F 795
once.
A new child Diagram window can be created in an existing Diagram or child Diagram
window by holding the Ctrl and Shift keys down while dragging a rectangle around the
Ctrl Key + Shift Key
area that will effectively become the button that transfers control to the child Diagram
window.
When resizing an object in the Diagram window, holding the Shift key down during the
Shift Key
operation forces the aspect ratio to remain fixed.
When adding a new line to a Diagram window or editing an existing line, holding the
Shift Key Shift key down will force the line to align to the nearest 45° angle. This is the easiest
way to draw a horizontal or vertical line.
Equations, Solution, and Variable Information
Double-clicking on a variable in the Equations window will select that variable unless the
Ctrl Key
Ctrl key is depressed.
When EES compiles the equations in the Equations window, it will attempt to solve
Ctrl Key equations that have one unknown. If the Ctrl key is depressed, EES will skip the solving
process while compiling.
EES displays a Progress dialog that shows which the Subprogram and iteration properties
such as the maximum residual, number of iterations etc.) for that Subprogram. The
Ctrl Key display is updated every 1/2 second. If the Ctrl key is depressed while EES is solving,
the Progress dialog will display the iteration properties for the Main program, rather than
that for the Subprogram that is executing.
If you apply the Copy command to the Solution window, EES will copy the Solution to
the Clipboard as both a text object and as a picture. The choice as to which format will
Ctrl Key appear is made with the Paste Special command in the application that is receiving the
copy. If the Ctrl key is depressed during execution of the Copy command, only the text
version of the Solution window will be placed on the Clipboard.
Plot and Diagram Windows
When adding a new line to a Plot or Diagram window or editing an existing line, holding
Shift Key the Shift key down will force the line to align to the nearest 45° angle. This is the easiest
way to draw a horizontal or vertical line.
When resizing an object in the Plot or Diagram windows, holding the Shift key down
Shift Key
during the operation forces the aspect ratio to remain fixed.
Moving the mouse with the left button depressed on a 3D plot causes the plot object to
rotate. Override this behavior by pressing the Shift or Ctrl key. Overriding may be
Ctrl Key or Shift Key
necessary when you wish to move a text or graphic object, but leave the 3D plot
undisturbed.
Pressing the Ctrl and Shift keys on a Plot window causes cursor to be a cross-hairs. The
coordinates of the cross-hairs are displayed in the status bar at the bottom of the window.
Ctrl Key + Shift Key
The cross-hairs can also be made to appear by selecting the cross-hairs button from the
Plot window tool bar.
The position of the left and top borders of a plot can be changed by holding the Ctrl key
down after moving the cursor to a location within the plot rectangle and moving the
Ctrl Key
mouse with the left button depressed. This operation can also be accomplished by
selecting the Move Plot button in the Plot window toolbar.
EES plots allow for a second Y-axis scale, which by default is positioned on the right side
Ctrl Key of a plot. A second X-axis scale is by default positioned at the top of the plot. The
position of either scale can be changed by holding the Ctrl key down. The left and right
796 Appendix F
arrows control the position of the second Y-axis and the up and down arrows control the
position of the second X-axis.
When a large object is pasted into the Plot window, EES will by default scale the size of
Ctrl Key the object so that it fits within the window. Press the Ctrl key during the paste operation
to override this behavior.
When you select a variable to plot in the Plot Setup dialog, EES normally sets the
Ctrl Key minimum and maximum values for the variable. Override this behavior by pressing the
Ctrl key while selecting the variable that is to be plotted.
The font size of text items in a plot window is normally scaled with the plot when the plot
Ctrl Key is resized. Hold the Ctrl key down if you do not wish the font size to change when you
resize the plot.
Text and graphic items in the Plot window can be moved left, right, up or down with the
arrow keys. Holding the arrow key down causes the item to move in an accelerated
Ctrl Key
manner. Holding the Ctrl key down allows the item to continue to move, but a slower rate
so it can be more easily controlled.
Printing
If the Alt key is depressed while printing, the header that appears on the top of each
Alt Key
printed page will be suppressed.
Macro Files
Normally, if an error of any kind occurs during execution of macro commands, execution
will stop and an error message will be posted. The OnError GoTo macro command
provides a way for this default behavior to be modified. After this command has been
executed, an error will result in a jump to the macro command having label XX. A line
OnError GoTo XX with this label must appear in the macro file. Labels must be numerical values ranging
between 1 and 30000 followed by a colon (:). This command can appear as many times as
desired. The control will transfer to the macro command with the label for the most
recently executed OnError GoTo command. To return to default behavior, enter OnError
GoTo 0.
Appendix F 797
Dynamically linked Function (.dlf or .dlf64) files are a special file type recognized only by EES that
can be written in C, C++, Pascal, and other high level compiled languages that support linked lists and
.dlf and
.dlf64
dynamic linked library files. These files provide external functions that can be called by EES. See
Section 19.1 for details. Note that the 32-bit versions read .dlf files compiled by 32-bit compilers and
the .64-bit version of EES reads .dlf64 files that are compiled by a 64-bit compiler.
EES can access one or more external programs that are compiled in a particular format as dynamic
link library (.dll or .dll64) files. External programs can also be provided as .fdl, .dlf, and .dlp file
.dll and
.dll64
formats for the 32-bit versions and .fld64, .dlf64, and dlp64 for the 64-bit version. The advantage of
the .dll/.dll64 format over the other types is that more than one external procedure can be provided in
a .dll/dll64 file. See Section 19.4.
Dynamically linked Procedure (.dlp and .dlp64) files are compiled files that are written in C, C++,
Pascal, or other high level compiled languages that support linked lists and dynamic linked library
.dlp and
files. These files can be provide external procedures that can be called by EES. See Section 19.2.
.dlf64
Note that the 32-bit versions read .dlp files compiled by 32-bit compilers and the .64-bit version of
EES reads .dlp64 files that are compiled by a 64-bit compiler.
Default Variable Information (.dvi and .dvi64) files are binary files containing default information for
the guess value, bounds and format as a function of the first letter of the variable name. A .dvi file is
.dvi and created with the Store button in the Default Variable Information dialog (Options menu) and read
.dvi64 when the Load button in that dialog is clicked. File EES.DFLT.dvi is provided in the EES setup
program. Because of numerical formatting differences, the 32-bit version can only use the .dvi files
and the 64-bit version can only use .dvi64 files.
EES Macro Files (.emf) store macro commands in an ASCII (text) file that can be replayed. The
instructions in the macro file can be executed by opening the file with the Open or Create Macro
command and clicking the Play button. This command also allows new macro files to be created or
.emf
existing macro files to be edited. A macro file can also be played from another program using DDE
(Dynamic Data Exchange) commands. EES macro files can only be created with the Professional
version. See Section 18.1 for more information.
EES Plot Template (.ept) files store plot window characteristics. It is convenient to save the
characteristics of a plot window in an .ept file and then later apply those characteristics to other plots.
.ept
This action assures that all plots have the same size, fonts, and other characteristics. See Plot
Templates in Section 9.1 for more information.
EES saves all problem information including tables, plots, equations, variables and diagrams, in an
.ees .ees file, which is a binary file that can only be read by the 32-bit Commercial and Professional
versions of EES.
The 64-bit version saves all problem information in an .ees64 file, which is the 64-bit equivalent of
.ees64 the .ees file. The 64-bit version can read and write both .ees and .ees64 file types, but the 32-bit
versions can only read and write .ees files.
EES_ files are used by the EES Android application (See Appendix G). EES can read and write files
.ees_
in this format.
An EES file can be automatically compressed to a smaller size and saved as an .eez/.eez64file. All
.eez and versions of EES after version 7.659 can read .eez files and automatically uncompress them. The files
.eez64 can be opened by WinZip. The Professional version of EES can write .eez files. The 64-bit version
uses .eez64 files, but it can read .eez files as well.
An .fdl file provides an externally compiled procedure that can be called by EES. The filename
originally was intended for refer to FORTRAN Dynamic library, but the external program can be
.fdl and written and compiled in any language that supports Windows dynamic link library files. .dlp and .dll
.fdl64 files also provide external procedures in dynamic link library format. The .fdl file format differs from
the .dlp file in the manner in which the arguments are provided. In particular, the .fdl file format uses
arrays, rather than linked lists, to transfer data. See Section 19.3 for details. Note that the 32-bit
versions read .fdl files compiled by 32-bit compilers and the .64-bit version of EES reads .fdl64 files
Appendix F 799
to a distributable file. This capability is provided only for the Professional version.
An EES.nwm file may (or may not) exist in the EES main folder. This file is created by EES when
the user selects the ‘Do not show this dialog next time’ check box. This check box appears in two
situations. It will appear if a second EES application is started and the user checks the 'do not show
this dialog next time' check box when the warning for multiple copies of EES is presented. It will
also appear when the dialog to determine if a file should be saved in a backward compatible manner is
.nwm shown. The EES.nwm file is a standard text file that can be opened with Notepad or any other file
editor. The file contains two characters, each on a separate line. If the first character is N, the dialog
to warn for multiple copies will not be displayed. If the second character is N, the dialog that asks if
the file should be saved in backward compatible format will not be shown. You can change either of
these characters from N to Y to alter behavior. To return to the default behavior, simply delete the
EES.nwm file.
Parametric (.par) files are created by the Store Parametric Table command in the Tables menu in the
32-bit versions. A .par file stores information for a selected Parametric Table to a binary disk file.
All information related to the parametric table is saved. The file can later be read to recreate the table
.par with the Retrieve Parametric Table command. The original purpose of .par files was to get around the
EES implementation limit of one Parametric Table in older versions of EES. EES now allows an
unlimited number of Parametric Tables which eliminates the need for .par files. The 64-bit version
does not have a Store or Retrieve Parametric Table command and does not use .par files
Portable Document Interface (.pdf) files are created by the Create LaTeX/PDF Report command in
the Files menu if the Create PDF document option is selected. In the case the PDFLaTeX.exe
.pdf
program is used to compile the .TEX file into a .PDF file which can be viewed with Abode Acrobat.
.pdf files can also be used to provide help or documentation for the Diagram window and library files.
EES Preference files (.prf) hold default values of units settings selected in the Unit System dialog,
stop criteria and integration tolerances specified in the Tolerances dialog, default variable
information, and all of the information in the Preferences dialog. In addition, the .prf file holds
recently accessed file names and default directory information. A .prf/.ref64 file is created when the
.prf and
prf64
Store button in clicked in the Unit System, Tolerances, and Preferences dialogs. EES will
automatically load the .prf file when it is started if it is found in the same directory as the EES
application. An existing .prf file in any directory can be loaded with the Load button in the
Preferences dialog or with a $INCLUDE directive. The .prf64 file is the 64-bit equivalent of the .prf
file and used only in the 64-bit version.
Data exported to a .tab file with the $Export directive are separated with a tab character, rather than
.tab
with a space, comma or semicolon list separator
TeX (.tex) files are created by the Create LaTeX/PDF Report command. These files can be
.tex
automatically converted to .pdf output files.
Table of Contents (.toc) files are used to provide access to application libraries that appear in the
.toc
Function Information dialog. See Section 11.4
Textbook (.txb) files hold information that can be used to create a user menu at the right of the menu
bar. Originally, the user menu was used to provide information to coordinate with textbooks that used
.txb EES, but any user menu can be created. .txb files can be loaded manually with the Load Textbook
command (File menu) or automatically, by placing the file in the EES\USERLIB or \USERLIB64)
folder. The format of a .txb file is described in Section 11.5.
Text (.TXT) files are used in several ways by EES. .TXT files that contain equations, perhaps
functions, procedures, or modules, can be merged into an EES program using the $INCLUDE
directive. Table files having a .TXT extension can be saved using the Save Table command or
.txt $SaveTable directive. .TXT files can be opened using the Open Lookup Table command or
$OpenLookup directive. See Lookup file formats for more information. The .TXT format can be used
to read and write files with the $IMPORT and $EXPORT directives. The Store and Retrieve
Parametric table commands in the Tables menu can work with .TXT files. Text files can also be used
to provide help information for internal or external functions and procedures. The
Appendix F 801
LibraryManager.text file is written by the EES Library Manager which controls loading of library
files at startup. If a HELLO.TXT file is placed in the EES application directory, that file will be
automatically opened into the Equations window when EES is started.
.unc files save uncertainty information. These file types are used in the Uncertainty Propagation and
Uncertainty Propagation table dialogs in the Professional version. These dialogs provide Load and
.unc Save uncertainty buttons (located to the left and right of the Set Uncertainties button, respectively) to
open and save these file types. Saving .unc file types allows several different uncertainty calculations
to be conducted with the same .ees/.ees64 file.
Units List (.unt) files hold unit strings facilitating the entering of units information for EES variables.
.unt .unt files can be created with a text editor or more simply using the Units List dialog. See Section 1.5
for more information.
Variable (.var/.var64) files save the name, guess, lower bound, upper bound, and format for all EES
variables in the main program or a module. The 64-bit version uses the .var64 format. .var/.var64
files can be read and saved in the Variable Information dialog or using the Load/Save buttons in the
Diagram window. The Professional version is required for using .var/.var64 files. .var/.var64 files
.var and
.var64
are particularly useful with the Diagram window in that user inputs can be saved and later re-loaded.
The $SaveVarFile directive automatically saves a .var/.var64 file when the program is successfully
solved. Other application for .var/var64 files are to provide multiple sets of guesses and to automate
setting information for commonly used variable names. See Variable Information Files in Section 5.4
for details.
A binary format used by Excel for saving spreadsheet data. Parametric, Lookup, Arrays and Integral
.xlsx tables can all be saved in .xlsx format. The Save Table and Open Lookup table menu commands
work with .xlsx files in the Professional version.
Export files (.xpt) were originally developed to transfer EES files between the Windows, Macintosh,
.xpt and DOS versions of EES. However, there no longer is a Macintosh version and there is no reason to
ever use this file format.
802 Appendix G
The 64-bit version (EES64.exe) requires a 64-bit Windows operating system, e.g, Windows
7/8 64 bit. It will not work on any 32-bit operating system.
There is only a 64-bit Professional version. A Commercial license will not be able to run the
64-bit version.
An extra-cost license (EES.DFT64) file is required to run the 64-bit version. This file must
be purchased from http://fchartsoftware.com/ees/order.php.
The 32-bit versions of EES do all floating point calculations using extended floating point
numbers having 80 bits of numerical precision. The 64-bit version uses doubles, which are
floating point numbers having 64 bits of precision. As a result, the 32-bit version provides
greater precision and allows larger numerical values than the 64-bit version. The largest
number that the 64-bit version can handle is approximately 1.7E308. The use of 64-bit
doubles is the major reason that the 64-bit version calculates faster than the 32-bit version.
Because numerical values are stored with different precision, the files saved by the 64-bit
version necessarily differ from the 32-bit versions. The 64-bit version saves EES files with
the .EES64 file name extension. EES64 files are identified by the file name extension and
the yellow EES 64 icon. Double-clicking on an EES64 file will start the 64-bit version of
EES. The 32-bit version of EES cannot read or write .EES64 files.
Library files in the 64-bit version are saved with the .LIB64 file name extension. Similarly,
EES Lookup files, external functions and procedures are identified with a 64 in the file name
extension, e.g., .LKT64, .PRF64, .FDL64, .DLF64, .DLP64, and .DLL64. None of these
files can be read by the 32-bit version due to the different format of the floating point
numbers.
The 64-bit version of EES can read and write any 32-bit or 64-bit EES or library file.
However, it is necessary to convert the information in the 32-bit file to equivalent 64-bit
information and this conversion process is slow. After reading a 32-bit file, it is best to save
it as 64-bit file so that is will be read quickly the next time it is opened.
It is possible for the 64-bit version to save EES and library files in an older format that can be
read by the 32-bit version. EES is programmed to save files in the older format if the file
name extension is .EES or .LIB instead of .EES64 or .LIB64. The Open and Save As dialogs
provide a dropdown control to select various file types, including the older 32-bit format.
Appendix G 803
The 64-bit version can not read external library files (.FDL, .DLP, .DLF, .DLL) that were
created for the 32-bit version. It is necessary to use 64-bit versions of these files, which are
identified as .FDL64, .DLP64, .DLF64, and .DLL64.
804 Index
Index
$Arrays On directive, 123, 126, 404, 419, $UnitSystem directive, 119, 134, 137, 160,
480 471, 489
$AutoSetUnits directive, 54, 488 $UpdateGuesses directive, 258, 512
$Bookmark directive, 481 $VarInfo directive, 512
$CheckUnits directive, 52, 98, 488 $Warnings On directive, 129, 487
$ClearLookup, 501 %% character, 562
$ClearParametric, 501 *** New String Variable ***, 540
$Common directive, 104, 109, 122, 404, .lkt/.lkt64 format, 77
489 3-D plotting, 619
$Complex On directive, 419, 469, 491 3-D points plot, 397 3-
$Constant directive, 83, 123, 490 D surface plot, 391
$ConvertEESREFPROPUnits directive, 207, 64-bit Professional version, 802
488, 780 absolute uncertainty, 336
$CopyToLookup directive, 491 acentric factor, 137
$DefaultArraySize, 121, 501 acquiring EES, 1
$DiagramUpdate On/Off directive, 600 adaptive step-size, 298, 309, 313
$DoLast directive, 501 adding constants, 82
$Export directive, 493 adding fluid properties, 151, 212, 216
$ExportPlot directive, 495 adding ideal gas properties, 152, 213
$HideWindow directive, 483, 596 adding incompressible property data, 188
$If directive, 502, 599 adding units, 59
$IfNot directive, 502, 537 adiabatic saturation temperature, 161
$Import directive, 495 Adobe Reader, 64
$INCLUDE directive, 57, 87, 429, 507, 540 Air, 152, 159
$Input directive, 508 Air_ha, 152, 159
$IntegralAutoStep directive, 313, 509 AirH2O, 161
$IntegralTable directive, 311, 317, 509 aligning items, 559
$Load directive, 509 alignment tool, 45
$MaxCalls directive, 509 Allow equations in Diagram inputs, 573
$OpenLookup directive, 498 Alter Values command, 74
$Private directive, 483 alternate units
$Real directive, 478, 491 entering in the Variable Information
$Reference directive, 151, 510 dialog, 12
$RunMacro directive, 510 entering uncertainty, 336
$SaveLookup directive, 499, 500 ammonia-water mixtures, 192
$SaveTable directive, 499 ammonia-water properties, 201
$ShowWindow directive, 485, 597 ampersand, 12
$StopCriteria directive, 229, 511 and, 112
$SumRow directive, 486 angle attribute, 588, 613
$Syntax directive, 486 angular frequency, 476
$TabStops directive, 16, 487 animating plots, 380
$Trace directive, 264, 512 animation, 585, 607
animation control bar, 607
Index 805
animation with Integral Table, 610 aspect ratio, maintaining constant value of,
annotation, 13 44
append to file, 494 assignment operator, 103
application library files, 433 assignments, 1, 6, 70, 102, 225
application mode, 515 attributes of objects, 585
apply pattern option, 387 audio-visual object, 563
argument list, 404 auto format, 11
arguments, 104, 108 automatic unit checking, 52
array editor, 68 automatic update, 41, 174, 372, 609
array editor, 68 automatically setting units, 53
array range notation, 67, 92, 495 axial conduction, 457
arrays, 66, 148 axis limits, 371
$Arrays On directive, 123, 404, 419 bar plots, 356, 359
$Common directive, 122 Beep, 128
$Constant directive, 491 Bessel function, 371
$Constant directive to set limits, 123 Bessel functions, 769
$SaveTable directive, 499 Bezier curve, 523
arguments in functions & procedures, 120 binned data, 356
array editor, 68 bi-quadratic interpolation, 99
Arrays Table Window, 66, 123 bi-quadratic polynomials, 388
assigning array variables, 66 bitmap file, 373, 516
assigning units to, 71 Black# constant, 586
collapsing, 71, 249 blackbody emissive power, 484
Duplicate command, 69 Blackbody library, 484
functions for, 773 blocking equations, 234, 417
guess values for, 72 blocks, 236
in functions and procedures, 120 blue to red color scheme, 389
modules, 404 Blue# constant, 586
nested Duplicate statements, 70 bmp file, 373, 516, 610
plotting data in, 379 boiling, 438
purging unused array variables, 72 bookmarks, 481
range notation, 67 bounds for optimization, 272
subprograms, 404 brine properties, 176
subscripts, 66 BrineProp2 procedure, 178
thermodynamic states in, 66, 148 brines, 177
two-dimensional, 67 BrineProp2 procedure, 178
units for, 250 concentration of, 178
used for guess values, 251 freezing point of, 176
used for limits, 251 properties, list of, 176
Variable Information dialog, 71 viscosity of, 176
Variable Information Dialoog, 249 building materials, 182
Arrays Table Window, 66, 123 button objects, 591
arrows, 390, 518 C, 716
ASCII file, 493, 627 C procedure, 111
ASHRAE Standard reference state, 151 C++, 702, 721, 729
Calculate, 545
806 Index
Function Information dialog, 135 number of arguments for ideal gas, 152
function list, 137 Peng-Robinson equation of state, 205
fundamental equation of state, 149 phase rule, 136
GENEOS library, 205 plots, 165
heating value, 160 Property Plot dialog, 165
ice, 150 psychrometric, 161
ideal gas, 151, 213 Pv_ function, 182
ideal gas model, 151 quality, 145
ideal gas reference state, 153, 159 Real Fluids, 136
ideal gas, adding user-defined, 152 Real Fluids, list of, 141
ideal gas, list of, 152 Redlich-Kwong equation of state, 205
IIR reference state, 150 redundant equations, 263
importance of units, 135 reference state, 150, 153
incompressible, 149, 179 REFPROP, 202, 206
Incompressible property tables, 185 REFPROP .fld file, 508
incompressible substances, 182 REFPROP .fld files, 221
Incompressible, adding, 185 saturation pressure, 143
Incompressible, list of, 180 saturation temperature, 143
Incompressible, using functions, 184 sea water, 203
indicators, 137 Seawater_EES library, 203
indicators, list of, 143 secondary refrigerants, 176
insulation, 182 SI unit system, 133, 134
internal, 135 solutions, 203
internal energy, 152 specific, 133
library, 135 standardized specific enthalpy, 159
LiClH2O library, 204 state, 136
liquid metals, 182 status bar, units in, 135
lithium bromide-water, 203 steam, 142
lithium chloride-water, 203 Steam_IAPWS, 142, 150
Lookup Tables for, 213 stoichiometric, 159
lower heating value, 160 strings for fluid names, 143
Martin-Hou equation of state, 142, 149, subcooled liquid, 149
151, 216 temperature, 158
mass specific, 133 Temperature function, 264
metals, 182 thermal conductivity of brines, 176
mixtures, list of, 177 thermodynamic state, 136
molar specific, 133 Third Law of Thermodynamics, 159 two-
molten salts, 182 phase states, 144, 264
NASA database, list of functions for, 157 unit system, 133
NASA Ideal Gas Database, 156 unit system dialog, 133
NASA library, 199 universal gas constant, 151
NASA procedure, 199 vapor pressure, 182
NH3H2O library, 202 viscosity, 176
Nitrogen vs N2, 152 water, 150
normal boiling point, 144 property indicators, list of, 143
Normal Boiling Point reference state, 151 Property Plot dialog, 165
Index 825