Examples

advertisement
Summary EES Manual
General commands
F1: help file
The Options menu provides commands for setting the guess values and bounds of variables, the unit
system, default information, and program preferences. A command is also provided for displaying
information on built-in and user-supplied functions.
The Calculate menu contains the commands to check, format and solve the equation set.
The Tables menu contains commands to set up and alter the contents of the Parametric and Lookup
Tables and to do linear regression on the data in these tables. The Parametric Table, similar to a
spreadsheet, allows the equation set to be solved repeatedly while varying the values of one or more
variables. The Lookup table holds user-supplied data which can be interpolated and used in the
solution of the equation set.
The Plot menu provides commands to modify an existing plot or prepare a new plot of data in the
Parametric, Lookup, or Array tables. Curve-fitting capability is also provided.
Options menu  Unit system
Unit conversion capabilities with the CONVERT function

Note the use of the Convert function in this example to convert the units of the specific
kinetic energy [m^2/s^2] to the units used for specific enthalpy [kJ/kg]
The Convert function has the following format: Convert(’From’, ’To’) where From and To are
character strings identifying the unit type such as ’Btu/hr-ft2-R’ or ’mph’.
“Comments”
Array variables  X[5,3]
A Lookup file = 2-dimensional matrix
String Variables  $ at the end
Raising to a power  ^ or **
Underscore character is used to indicate a subscript  lb_m will appear as lbm
Multiple equations may be entered on one line if they are separated by a semi-colon “;”
The order in which the equations are entered does not matter.
The position of knowns and unknowns in the equation does not matter.
Thermodynamic property functions:
General:
variable=thermodynamic property function(substance name, Independent variables e.g. T, P,
H, U, S, V, and X, corresponding to temperature, pressure, specific enthalpy, specific internal
energy, specific entropy, specific volume, and quality)
Or via Options  Function Information
For example:
Specific volume  v1=volume(R134a,T=T1,P=P1)
Before solving the equation:
 Set guess values and (possibly) the lower and upper bounds for the variables
 Options  Variable Information
Equation Window:
 Checking the syntax using the Check/Format command in the Calculate menu
Solving the equation:

Calculate Menu  Solve
Number of iterations and residual:
 Options Menu  Stop Criteria
 If the maximum residual is larger than the value set for the stopping criteria, the equations
were not correctly solved, possibly because the bounds on one or more variables constrained
the solution.
Parametric studies: to see how one variable varies with another.
 Table Menu  New Parametric Table
 Add the variables in the table (“Add”), also the one that will be used for the sensitivity
analysis


The first column is the one which will vary (type in or enter automatically by the clicking on
the arrow of the first column)
In the equation window the variable should be added with some code to prevent fixing the
variable to a certain defined value
$ifnot Parameter Table
P2 = 300
$ endif
Solve

Calculate Menu  Solve Table
Plot the Table

Plot Menu  New Plot Window
o Choose x and y axis
Plots of the thermodynamic properties can be generated using the Property Plot command
Example:
 Type: T-s diagram – R245fa
 Reference: DFT (IIR, if you work with REFprop for mixtures; REFprop must be imported via
package)
Optimization
 Min/Max: to find the minimum or maximum of an undetermined variable in an equation set for
which there is one or more (limited to 10) degrees of freedom.
 Methods: The recursive Quadratic Approximations method is usually faster, but the Golden
Section method is more reliable. Multi-dimensional optimization may be done using either Direct
Search or a Variable Metric algorithm. The Variable Metric method, which uses numerical
derivatives, usually performs much better than the Direct Search method, but it may be confounded
if the optimum is constrained to be on a bound.
 Careful selection of the bounds and the guess value(s) of the independent variables will improve
the likelihood of finding an optimum.
 Min/Max Table provides the same capability as the Min/Max command, except that the
calculations will be repeated for each row in the Parametric Table.
 Update Guesses replaces the guess value of each variable in the Equations window with the value
determined in the last calculation. This command is accessible after calculations have been
successfully completed.
Built-in functions
Mathematical functions
From page 91 in Manual
if (A, B, X, Y, Z)
 allows conditional assignment statements.
 If A<B; the function will return a value equal to the value supplied for X;
 If A=B, the function will return the value of Y;
 If A>B, the function will return the value of Z.
lookup(‘Filename’, Row, Column)
 Returns the value in the Lookup Table or Lookup file at the specified row and column.
Thermophysical property functions
From page 104 in Manual
EES Functions, Procedures and Modules


A function is a subprogram that accepts one or more inputs and returns a single result.
A procedure can return one or more results.

A module is similar to a procedure in that it can return one or more results. However, it
differs from a procedure in that it employs equalities rather than assignment statements.
Functions
 At the top of the Equations Window
 An assignment statement sets the variable identified on the left of the statement to the
numerical value on the right.
 FUNCTION function name(argument1, argument2,…)
X:=X+1 “is a valid assignment statement but it obviously cannot be an equality”
END
 If then else, repeat until and goto statements may be used
Example
The specific availability of a flowing stream, often called , is
= (h - ho) - To (s - so) + V2/2 + g z
Once the temperature and pressure of the dead state are selected, ho and so are constants. A user
function for the availability of steam, with To=530 R and Po=1 atm, could be implemented by placing
the following statements at the top of the Equations window. A reference to psi(T1, P1, V1, Z1) from
an equation would return the specific availability of steam in Btu/lbm for the chosen ‘dead’ state.
FUNCTION psi(T, P, V, Z)
To := 530
“R dead state temperature”
ho := 38.05
“Btu/lbm specific enthalpy at dead state conditions”
so := 0.0745
“Btu/lbm-R specific entropy at dead state conditions”
h := enthalpy(STEAM, T=T, P=P)
s := entropy(STEAM, T=T, P=P)
g = 32.17 “ft/s^2 gravitational acceleration”
psi := (h-ho)- To * (s – so) + (V^2 / 2 + g * Z) * Convert(ft^2/s^2, Btu/lbm)
END
Procedures
 EES procedures are very much like EES functions, except that they allow multiple outputs.
 At the top of the Equations Window
 The format of a Procedure is:
PROCEDURE procedure name(input1, input2,… : output1, output2,…)
...
...
X :=...
Y :=...
END
 To use the procedure, place a CALL statement anywhere within your equations. The CALL
statement appears as
...
CALL test(1,2,3 : X,Y)
...
 If then else, repeat until and goto statements may be used
Single-Line If Then Else Statements




Only in functions and procedures (not in modules and in the main body text).
Recognized operators are =, <, >, <=, >=, and <> (for not equal).
The AND and OR logical operators can also be used in the conditional test.
The single-line format has the following form:
If (Conditional Test ) Then Statement 1 Else Statement 2
Example:
Function MIN3(x,y,z) { returns smallest of the three values}
If (x<y) Then m:=x Else m:=y
If (m>z) Then m:=z
MIN3:=m
End
Y = MIN3(5,4,6) { Y will be set to 4 when this statement executes}
Multiple-Line If Then Else Statements
 The format is as follows:
If (Conditional Test) Then
Statement
Statement
...
Else
Statement
Statement
...
EndIf
Example:
Function IFTest(X, Y)
If (X<Y) and (Y<>0) Then
A:=X/Y
B:=X*Y
If (X<0) Then
A:=-A; B:=-B
EndIf
Else
A:=X*Y
B:=X/Y
EndIf
IFTest:=A+B
End
{nested If statement}
G=IFTest(-3,4) { G will be set to 12.75 when this statement executes}
GoTo Statements
 EES will normally process the assignment statements in a function or procedure in the order
they appear starting with the first statement. However, the flow control can be altered using
GoTo statements.
 The format of a GoTo statement is simply GoTo # where # is a statement label number which
must be an integer number between 1 and 30000.
 Statement labels precede an assignment statement separated with a colon (:).
Example:
Function FACTORIAL(N)
F:=1
i:=1
10: i:=i+1
F:=F*i
If (i<N) Then GoTo 10
FACTORIAL:=F
End
Y= FACTORIAL(5) { Y will be set to 120 when this statement executes}
Repeat Until Statements
 Can only be used in functions and procedures.
 Format:
Repeat
Statement
Statement
...
Until (Conditional Test)
Example:
Function Factorial(N)
F:=1
Repeat
F:=F*N
N:=N-1;
Until (N=1)
Factorial:=F
End
Y= FACTORIAL(5) { Y will be set to 120 when this statement executes}
Modules
Example:
Library Files
 EES allows files containing one or more functions, procedures or modules (subprograms) to
be saved as Library files. A Library file has a .LIB filename extension.
Advanced Features
String Variables
Examples:
A$=’carbon dioxide’
B$=A$
h=enthalpy(R$,T=T,P=P)
 String variables may be used with the Parametric table.
The DUPLICATE Command
 The DUPLICATE command provides a shorthand way of entering equations into EES. The
equations which are to be duplicated are enclosed between the DUPLICATE and END
command words.
 DUPLICATE is useful only when used with array variables.
For example, the following statements:
N=5
X[1]=1
DUPLICATE j=2,N
X[j]=X[j–1]+j
END
are equivalent to:
X[1]=1
X[2]=X[1]+2
X[3]=X[2]+3
X[4]=X[3]+4
X[5]=X[4]+5
Download