Sunteți pe pagina 1din 24

Computer Aided

Engineering

Advanced EES

(Engineering Equation Solver)

Lecture 6

Advanced Features

Dr Hannes van der Walt

Swinburne Uni, Melbourne, Australia

Contents
EES advanced tutorial

(2 Lectures)

Min/Max analysis
(Lect 5)
Uncertainty analysis
Coding conventions
(Lect 6)
String functions, constants
Diagram window
Functions, procedures, modules & subprograms
Loops
Curvefitting
TableRun#, TableValue, Lookup
Disk input and output, formatted output
Other important features

Coding Conventions
Capitalisation:
Use capitals or mixed case for directives such as
$UnitSystem, $IfDef (or if you really insist use
$IFDEF)
Use lowercase (mostly) for variable names
Use mixed case for user defined function names and
logical statements such as If, Do, Repeat-Until,
Duplicate
Most importantly however, be consistent!

Spaces:
Use spaces liberally either side of operators +, -, /,
*, =
Indent and align lines inside If, Do, Duplicate and
inside functions

String Functions
See the Help file for String Functions:

Concat$
Date$
EesFileDir$
LowerCase$
String$
StringLen
StringPos
StringVal
Time$
UpperCase$

Strings
EES handles strings quite elegantly:

Strings are defined between single quotes


Names can be defined for strings and the
names can be used in functions that need
them
Strings can be manipulated through the
string functions listed before

Check out the following example file:


Lecture 6.1 StringHandling.ees

Note how strings can be supplied from a


parametric table and thus vary with each
run.
0:15

Strings
String usage example:

"String constants can be created. There are also several


string handling functions"
title$ = 'EES'
secondTitle$ = ' is very cool!'
combinedTitle1$ = Concat$(title$, ' is cool')
combinedTitle2$ = Concat$(title$, secondTitle$)
"Strings are also used in several property functions"
density_water_1 = Density('water', T=100, P = 100)
T1 = 100 [C]
P1 = 95 [kPa]
fluid$ = 'water'
density_water_2 = Density(fluid$, T=T1, P = P1)
0:20

Diagram Window
The Diagram Window (Ctrl+D) provided EES
with a Graphical User Interface that can
contain:

input fields
output fields
radio buttons
drop down boxes

Graphic images can by copied from any


other graphical package into the EES
diagram window
Lets reopen the projectile movement
example of just before.

Diagram Window

Add input and output fields as


shown.
Add buttons as shown
Of course, when input values are
provided in the diagram window,
they cannot be provided in the
equations window or the
parametric table!
See Lecture 5.1 - SimpleMinMax.EES
"Define initial velocity"
$IfNot (ParametricTable or MinMax) Apparently one can only have 2 statements in an $If
$IfNot DiagramWindow
theta = 45 [deg]
Disabled when running Table 1 or Table 2 or the Diagram Window"
$EndIf
$EndIf
$IfNot ParametricTable = 'Table 2 - Min/Max Table'
$IfNot DiagramWindow
u = 30 [m/s]
Disabled when running Table 2 or the Diagram Window"
$EndIf
See diagram window examples in the Examples
$EndIf

menu

Functions
EES solves the main body of the program as
a simultaneous set of equations, and not
sequential. That implies that logic cannot be
accommodated in the main body and has to
be added to a function.
For the same reason, loops (apart from
Duplicate) cannot be added to the main
body and has to be implemented in a
function.
Functions that the user defines are no
different from those chosen from the
Options > Function Info menu:
a = cos(theta)
b = sqrt(value)

Lecture 6.2a - Functions.EES


Lecture 6.2b - Procedures.EES

Functions
Functions must be declared before (above)
the main body of an EES program:
$TabStops 0.5 cm
Function Minimum(x, y)
if (x < y) then
Minimum = x
else
Minimum = y
endif
End
a = 12
The main body of the EES program starts here
b = -10
x_min = Minimum(a, b)

Functions
Logic can be nested to provide more complex
behaviour, for example:
$TabStops 0.5 cm

Function Smallest(x, y, z)

if ((x < y) and (x < z)) then


s=x
We can assign the result to a temporary variable for now
else
if ((y < x) and (y < z)) then
s=y
else
s=z
endif
endif
Smallest = s; But eventually the value is to be returned here!

End

a = 12
b = -12
c = 22
x_smallest = Smallest(a, b, c)

Procedures
EES Procedures are very much like EES Functions,
except that they allow multiple inputs and outputs.
The format of a Procedure is:
$TabStops 0.5 cm
Procedure CalcSquareOfTwo(x, y: x_sq, y_sq)
x_sq = x * x
y_sq = y * y
End
a = 12
b = -12
Call CalcSquareOfTwo(a, b: a_sq, b_sq)

Modules & Subprograms


Modules and Subprograms can be
considered to be stand-alone EES programs
that can be called from the main EES
program. The format of a Module /
Subprogram is similar to that for an
internal Procedure.
See the Help file as well the Examples.
See eesysol15.pdf (www.fchart.com)

Loops
Loops are implemented in a function or a procedure
as follows: (Lecture 6.3 - Loops.EES)
$TabStops 0.5 cm
Function SumOfArray(n, x[1..n])
sum = 0
i=1
Repeat
sum = sum + x[i]
i=i+1
Until (i > n)
SumOfArray = sum
End
c[1] = 12
c[2] = 5
c[3] = 27
c[4] = 9
c[5] = 16
size = 5
sum = SumOfArray(size, c[1..size])

See the Help file for:


Repeat-Until
Logical operators
If(a, b, c, d)
If$(a, b, c, d)

Note the shorthand


array notation!
Logical Operators:
<
(less than)
>
(greater than)
=
(equal)
<=
(less than or equal)
>=
(greater than or equal)
<>
(not equal)
and
(logical and)
or
(logical or)

Curve Fitting Examples


Following is an example on using the programatical curve fitting function
(See CURVEFIT1D in the Help file): (Lecture 6.4b - Curve Fitting Function.EES)
$TabStops 0.5 cm
n = 100 n is the number of data points
m is other order of the polynomial from the table
F$ = Concat$('POLY', String$(m))
call CurveFit1D(F$, X[1..n], Y[1..n] : a[0..m], rms, bias, R|2, a_err[0..m])
Duplicate i = 1, n
X[i] = i
fake data for the example
Y[i] = i + 2.5*X[i]^2 + 0.002*X[i]^4 + random(0,1)*X[i]
predicted value of Y from the polynomial fits
Yp[i]=a[0] + Sum(a[j]*X[i]^j, j = 1, m)
End

Data Output to Disk


$Export
The $Export directive provides a simple way
of writing selected variables to an ASCII
file. This file can then be read by a $Import
directive, the Open Lookup Table command in
EES or by another application, such as a
spreadsheet program. If the filename
extension is .CSV (comma-separated values),
the data will be written as a CSV ASCII text
file that is easily recognized by spreadsheet
applications and by the $Import directive.

Data Output to Disk


In this format, each value is separated
by a list separator character. If the
filename extension is .TXT, EES will
assume that the data should be written
with header information in the EES
Lookup file format that can be read
directly by the Open Lookup Table
command. The header information will
include the name of the variable, its
units, and its display format.

Data Output to Disk


The format of the $Export Directive is
$Export /A /F /C 'FileName', Var1,
Var2, X[1..5], ...
The /A /F /C are options see the Help
system for details

Data Input from Disk


$Import
The $Import directive provides a
simple way of reading selected variables
from an ASCII file. The data could be
provided from a file written using the
$Export directive or another
application. The combination of $Export
and $Import directives provides a
convenient way to transfer information
from one EES program to another or to
itself.

Data Input from Disk


The format of the $Import Directive
is:
$Import 'FileName', Var1, Var2,
X[1..5], S$...
See the Help system for details. Also
see the Examples > Directives >
$Import and $Export demonstration
Also see $SaveTable, $OpenLookup,
$SaveLookup

Formatted Data Output


The Print command can be used with the
assignment statements in Internal
Functions and Procedures to output
intermediate results. The format of the
Print command is
Print "filename" x, y, z

Formatted Data Output


Example
Function Test(x, y)
t=x+y
F$ = 'text.txt'
i=0
Repeat
i=i+1
print F$, i, x+i, y+i
Until (i >= t)
Test = t
End
result = Test(2, 3)

Listing of file Text.txt after


running the above program.
1
2
3
4
5

3
4
5
6
7

4
5
6
7
8

Other Important Features


Advanced Features

2D & 3D interpolation
Lookup files (instead of lookup tables!)
3D Plots
Create LaTeX/PDF Report (MikTex http://miktex.org)
ERROR & WARNING procedures
EES File Types
Distributable programs
Library Manager
Animation (Also plot animation)
$TRACE, Residual Window, $SAVETABLE

End of Lecture 6

0:05

S-ar putea să vă placă și