Beruflich Dokumente
Kultur Dokumente
Manual
Contents
Users Guide
1 Introduction
1
2
1.1
1.2
1.2.1
1.2.2
1.2.3
1.2.4
1.2.5
Multi-Platform system . . . . . . . . . . .
1.2.6
1.2.7
Solution Power . . . . . . . . . . . . . . .
1.2.8
1.2.9
1.2.10 Optimization . . . . . . . . . . . . . . . .
Installation . . . . . . . . . . . . . . . . . . . . .
1.3.1
1.3.2
1.3
2 Overview
2.1
EMSO Basics
. . . . . . . . . . . . . . . . . . .
2.2
Running EMSO . . . . . . . . . . . . . . . . . .
2.2.1
2.2.2
2.3
2.4
Tutorials . . . . . . . . . . . . . . . . . . . . . . 11
2.4.1
3.2
3.3
3.4
18
Modeling basics . . . . . . . . . . . . . . . . . . 19
3.1.1
3.1.2
3.1.3
3.1.4
Types . . . . . . . . . . . . . . . . . . . . 21
3.1.5
Using files . . . . . . . . . . . . . . . . . 22
Model . . . . . . . . . . . . . . . . . . . . . . . 23
3.2.1
Parameters . . . . . . . . . . . . . . . . . 24
3.2.2
Variables . . . . . . . . . . . . . . . . . . 25
3.2.3
Composition in Models . . . . . . . . . . 26
3.2.4
Equations . . . . . . . . . . . . . . . . . 27
3.2.5
Initial Conditions . . . . . . . . . . . . . . 28
3.2.6
Abstract Models . . . . . . . . . . . . . 28
FlowSheet . . . . . . . . . . . . . . . . . . . . 28
3.3.1
Devices
. . . . . . . . . . . . . . . . . 29
3.3.2
Connections . . . . . . . . . . . . . . . . 29
3.3.3
Specifications . . . . . . . . . . . . . . . 30
3.3.4
Options . . . . . . . . . . . . . . . . . . . 30
Optimization . . . . . . . . . . . . . . . . . . . . 30
3.4.1
Simple Optimizations . . . . . . . . . . . 32
3.4.2
Large-Scale Optimization . . . . . . . . . 33
3.5
3.6
3.7
3.8
3.9
3.4.3
3.4.4
Options . . . . . . . . . . . . . . . . . . . 34
3.4.5
Dynamic Optimization . . . . . . . . . . . 34
Parameter Estimation . . . . . . . . . . . . . . . 35
3.5.1
Experiments . . . . . . . . . . . . . . . . 36
3.5.2
Estimate . . . . . . . . . . . . . . . . . . 37
3.5.3
Options . . . . . . . . . . . . . . . . . . . 37
Data Reconciliation . . . . . . . . . . . . . . . . 39
3.6.1
Experiments . . . . . . . . . . . . . . . . 40
3.6.2
Reconcile . . . . . . . . . . . . . . . . . . 41
3.6.3
Free . . . . . . . . . . . . . . . . . . . . 42
3.6.4
Options . . . . . . . . . . . . . . . . . . . 42
Case Study . . . . . . . . . . . . . . . . . . . . . 45
3.7.1
Vary . . . . . . . . . . . . . . . . . . . . 46
3.7.2
Response . . . . . . . . . . . . . . . . . . 46
3.7.3
Results . . . . . . . . . . . . . . . . . . . 46
Sensitivity Analysis . . . . . . . . . . . . . . . . . 48
3.8.1
Vary . . . . . . . . . . . . . . . . . . . . 50
3.8.2
Response . . . . . . . . . . . . . . . . . . 50
3.8.3
Results . . . . . . . . . . . . . . . . . . . 51
Built-in Functions . . . . . . . . . . . . . . . . . 53
66
Arrays . . . . . . . . . . . . . . . . . . . . . . . 67
4.1.1
Vectors . . . . . . . . . . . . . . . . . . . 67
4.1.2
Multidimensional Arrays . . . . . . . . . . 68
4.1.3
Equation Expansion . . . . . . . . . . . . 68
4.2
4.1.4
Array Functions . . . . . . . . . . . . . . 69
4.1.5
Loop For . . . . . . . . . . . . . . . . . . 70
Conditional Modeling . . . . . . . . . . . . . . . 70
5.2
71
Introduction . . . . . . . . . . . . . . . . . . . . 72
5.1.1
What is Plugin? . . . . . . . . . . . . . 72
5.1.2
5.1.3
Using Plugins . . . . . . . . . . . . . . . . . . 73
5.2.1
76
6.1
EMSO Basics
. . . . . . . . . . . . . . . . . . . 77
6.2
Installation . . . . . . . . . . . . . . . . . . . . . 77
6.2.1
Requisites . . . . . . . . . . . . . . . . . 77
6.2.2
Matlab Install . . . . . . . . . . . . . . . 77
6.2.3
Scilab Installation . . . . . . . . . . . . . 79
6.2.4
Scilab Uninstall . . . . . . . . . . . . . . 82
6.3
6.4
c communication . . . . . . . . 87
Matlab/Simulink
6.5
c communication . . . . . . . . . . 90
Scilab/Scicos
97
7.1
7.2
7.3
7.2.1
7.2.2
II
Programming Guide
8.2
8.3
9.2
9.3
9.4
105
8.1.2
8.1.3
8.1.4
8.2.2
8.2.3
104
115
9.1.2
Jacobian . . . . . . . . . . . . . . . . . . 117
9.1.3
9.1.4
9.1.5
9.2.2
9.3.2
9.3.3
License
at GIMSCOPa UFRGS.
Group of Integration, Modeling, Simulation, Control, and Optimization of Processes - Chemical Engineering
Department - Federal University of Rio Grande do Sul (UFRGS)
Acknowledgments
Model tank
# body of the model
end
Tip: a tip for the user, for instance: always check EML for a
model before develop a new one.
Linux note: note specific for POSIX systems (Linux and Unix),
for instance: EMSO can be available for any POSIX compliant
system upon request.
I. Users Guide
Introduction
Go any further in reading this manual or using EMSO without read, understand and accept
the EMSO license, found on page vii.
In this chapter we will learn what is EMSO and why use it.
Contents
1.1
1.2
1.3
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1
1.2
1.2.1
1.2.2
1.2.3
1.2.4
1 Introduction
addition, the language is fully object-oriented, allowing the user to
develop complex models by composing them with existent small
models or develop specific models by deriving standard ones.
All EML models are written in the EMSO modeling language and
are stored in plain text .mso files which can be edited or extended
by the user.
1.2.5
Multi-Platform system
EMSO is available for win32, POSIX (Linux and Unix) platforms.
Models developed in one platform can be freely interchanged between others.
1.2.6
1.2.7
Solution Power
EMSO provides solvers for dynamic and steady-state systems
which are efficient in solving both small and large scale systems.
The solvers can make use of the dense or sparse linear algebra.
Actually there is no limit regarding problem size other than the
machine memory. In addition, new solvers can be interfaced to
EMSO and used in a seamless manner.
State of art techniques as automatic and symbolic differentiation
algorithms are built-in in EMSO. Furthermore, it has proved to
be one of the most time efficient tools when solving large scale
dynamic problems.
1.2.8
1.2.10
Optimization
Besides dynamic and steady simulation EMSO can be used to
find optimal solutions with respect to given criteria. The user
just need to formulate the optimization objective (lower cost,
maximum production, etc) and choose the optimization variables
(manipulated variables) in the Optimization environment and
let the system to find the best solution. See examples in the
ammonia opt.mso and flash opt.mso in the folder
<EMSO>/mso/sample/optimization.
1.2.11
Parameter Estimation
EMSO can perform parameter estimation of dynamic and steadystate models using the Estimation environment. See examples
in the BatchReactor.mso and sample est.mso files in
the <EMSO>/mso/sample/estimation folder.
1.2.12
Data Reconciliation
EMSO can perform data reconciliation of steady-state models using the Reconciliation environment. See examples in the
heatEx.mso in the <EMSO>/mso/sample/reconciliation
folder.
1.2.13
Case Study
EMSO can perform case studies of variables of dynamic and
steady-state models using the CaseStudy environment. See examples in the CaseStudy ss.mso and CaseStudy dyn.mso
files in the <EMSO>/mso/sample/casestudy folder.
1.2.14
Sensitivity Analysis
EMSO can perform sensitivity analysis of dynamic and steadystate models using the Sensitivity environment. See examples in the Sensitivity ss.mso and Sensitivity dyn.mso
files in the <EMSO>/mso/sample/sensitivity folder.
1 Introduction
1.2.15
Open Interfaces
EMSO has a set of open interfaces that allow the user to load
at run-time third-party software encapsulated in dynamic link libraries. (See Part II).
In addition, there are standard interfaces for implementing new
differential-algebraic equations (DAE), nonlinear algebraic equations (NLA), and nonlinear optimization problem (NLP) solvers.
1.2.16
1.3
EMSO is composed by two major softwares: the graphical interface and the engine. The EMSO power in solving complex
large-scale dynamic problems is available to be embedded in third
party software through the EMSO engine open Application Program Interface (API). Using this technology, EMSO installation
already provides an engine to build bifurcation diagrams using
AUTO2000 adapted to work with differential-algebraic equations
(DAE), and also SFunctions for simulating dynamic models
R
built with EMSO modeling language inside Matlab/Simulink
with continuous and discrete-time simulation. See the installation
procedure.
Installation
EMSO is available for two main platform groups: win32 and
POSIX. Installation instructions for these platforms can be found
in subsection 1.3.1 and subsection 1.3.2 respectively.
1.3.1
1.3 Installation
7
There are some examples to test the installation in the directory /usr/local/auto/2000 dae/demos/DAE. Copy the
file auto emso.exe from <EMSO>/bin in the same location
of the examples and execute the command @r-emso ab dae,
where ab dae is the name of the example to run, or put the
directory <EMSO>/bin in the PATH environment variable.
In order to use the EMSO-Matlab/Simulink interface, just copy
the files emso sf.dll and emsod sf.dll from the location
<EMSO>/interface/matlab to the working directory. In
the original location there are some MDL files to run some examples in the Simulink.
1.3.2
Overview
This chapter provides an overview about EMSO. First some basics are presented followed by
some tutorials. These tutorials teaches how to:
build a FlowSheet composed by a set of predefine Models;
check the consistency of a FlowSheet
run a dynamic simulations and plot results;
customize FlowSheet options.
Further, the EMSO modeling language for development of new models is introduced.
Contents
2.1
EMSO Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2
Running EMSO
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3
2.4
Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
2.1
EMSO Basics
EMSO is a software tool for modeling, simulation and optimization of dynamic or steady-state general processes. The referred
processes are called FlowSheets.
A FlowSheet is composed by a set of components, named
Devices. Each Device has a mathematical description, called
Model. These are the three main EMSO entities and all of them
are described in plain text files which are usually stored in .mso
files. Each .mso file can have any number of any of these entities and the EMSO graphical user interface can open an unlimited
number of .mso files simultaneously.
2.2
Running EMSO
EMSO is available in a variety of platforms:
Windows 95 or above and
Windows NT 4 or above.
2.2.1
win32 platforms;
POSIX platforms: Linux and Unix.
2.2.2
2.3
10
2 Overview
2.4 Tutorials
11
(a) Explorer
2.4
Tutorials
In the last section we have presented how to start EMSO and its
graphical interface. Now we give some tutorials introducing the
key concepts of EMSO and its modeling language. The directory
12
2 Overview
2.4 Tutorials
13
14
2 Overview
using "stage_separators/tank";
FlowSheet ThreeTank
VARIABLES
Feed
as flow_vol;
4
5
DEVICES
Tank1 as tank_simplified;
Tank2 as tank_simplified;
Tank3 as tank_simplified;
7
8
9
10
CONNECTIONS
Feed
to
Tank1.Fout to
Tank2.Fout to
12
13
14
15
16
Tank1.Fin;
Tank2.Fin;
Tank3.Fin;
end
2.4 Tutorials
15
The number of variables and equations does not match
!
System is not consistent!
At this point the Problems window will also show the consistency problems. This error was expected, once we have neither
specified the input flow of the first tank nor the initial level of the
tanks.
Therefore, in order to get a consistent system the user should add
the following commands:
SPECIFY
Feed = 10
INITIAL
Tank1.h =
Tank2.h =
Tank3.h =
* m3/h;
1 * m;
2 * m;
1 * m;
The user can choose between to add this code into its FlowSheet
or use the already made file ThreeTank2.mso found in the
tutorial directory.
Note: EMSO is not a sequential tool, therefore the user could
specify a variable other than the input flow of the first tank.
Now, if the user checks the ThreeTank consistency no errors
will be reported and some interesting messages will be sent to the
Console:
Checking the consistency for ThreeTank in file
ThreeTank2.mso...
Number of variables: 10
Number of equations: 10
Degrees of freedom: 0
Structural differential index: 1
Dynamic degrees of freedom: 3
Number of initial Conditions: 3
System is consistent.
Running a Simulation
Once we have a consistent FlowSheet we can run a simulation.
To do this the user has to select the desired FlowSheet in the
file explorer and then left click in the
button.
Simulation of ThreeTank started ...
Simulation of ThreeTank finished succesifuly in
0.02 seconds.
16
2 Overview
Tip: In order to get more detailed output when running a simulation just change the output level on the Console window and
run again the simulation.
Visualizing Simulation Results
For each task ride by the user a new result is added to the results
explorer. The user can see the available results by left clicking in
the results explorer tab (Figure 2.2 (b)).
If a result is selected on the top list of the results, the bottom
side will show the variables available for plotting. The user can
plot a variable profile by double clicking in it.
If not specified the integration
interval is the interval ranging from
0 to 100 seconds.
We have not configured the simulation time vector for our simulation and the default integration interval is not suitable for the
dynamics of our system. We can modify the integration interval
by adding, for instance, the following commands:
OPTIONS
TimeStep = 0.1;
TimeEnd = 2;
TimeUnit = h;
Now we can run the simulation again and compare the results
with the previous solution.
2.4 Tutorials
17
At this point our code should look like Code 2.2 found in the
tutorial directory.
Code 2.2: File ThreeTank3.mso.
1
using "stage_separators/tank";
FlowSheet ThreeTank
VARIABLES
Feed
as flow_vol;
4
5
DEVICES
Tank1 as tank_simplified;
Tank2 as tank_simplified;
Tank3 as tank_simplified;
7
8
9
10
CONNECTIONS
Feed
to
Tank1.Fout to
Tank2.Fout to
12
13
14
15
SPECIFY
Feed = 10 * m3/h;
17
18
INITIAL
Tank1.Level = 1 * m;
Tank2.Level = 2 * m;
Tank3.Level = 1 * m;
20
21
22
23
SET
Tank2.k = 8 * m2.5/h;
Tank2.A = 4 * m2;
25
26
27
OPTIONS
TimeStep = 0.1;
TimeEnd = 2;
TimeUnit = h;
29
30
31
32
33
Tank1.Fin;
Tank2.Fin;
Tank3.Fin;
end
In this chapter, we describe in detail how one can write a Model or FlowSheet using the
EMSO modeling language.
The EMSO modeling language is a case sensitive textual language. In such language the
entities are written in plain text files stored, by default, in .mso files.
Contents
3.1
Modeling basics . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
3.2
Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
3.3
FlowSheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
3.4
Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
3.5
Parameter Estimation . . . . . . . . . . . . . . . . . . . . . . . . .
35
3.6
Data Reconciliation . . . . . . . . . . . . . . . . . . . . . . . . . .
39
3.7
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
3.8
Sensitivity Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
3.9
Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
54
58
3.1
19
Modeling basics
As mentioned before, in EMSO a FlowSheet is the problem
in study. But, a FlowSheet is composed by a set of connected Devices, each one having a mathematical description
called Model.
In chapter 2 the Model and FlowSheet entities were introduced. The description of these entities share several basic concepts particular to the EMSO modeling language, which follows.
3.1.1
Composition
Every process can be considered as set of sub-processes and so
on, this depends only on the modeling level. Composition is the
ability to create a new model which is composed by a set of
components, its sub-models.
The EMSO modeling language provides unlimited modeling levels,
once one model can have sub-models which can have sub-models
themselves. This section aims at introducing the composition
concept, the application of this concept in the EMSO is shown in
subsection 3.2.3.
Inheritance
When modeling complex systems, set of models with a lot in
common usually arises. If this is the case, an advisable modeling
method is to create a basic model which holds all the common
information and derive it to generate more specific models reusing
already developed models.
In OO modeling this is achieved by inheritance, the ability to create a new model based on a preexistent one and add derivations
to it. For this reason, inheriting is also known as deriving. When
a model uses more than one base model it is said to use multiple
inheritance.
The EMSO modeling language provides unlimited levels of inheritance or multiple inheritance for Models and FlowSheets.
The following sections and EML are a good sources of examples
of inheritances.
20
3.1.2
21
$Log: streams.mso,v $
Revision 1.1.1.1 2003/06/26 16:40:37 rafael
--------------------------------------------------*#
# A line comment extends until the end of line.
3.1.4
Types
As already mentioned in chapter 2, the declaration of variables
and parameters can make use of a base type. A type can be one
of the built-in types or types derived from the built-in ones. The
list of built-in types are shown in Table 3.1.
Description
Type for continuous variables or parameters, with attributes:
Brief: textual brief description
Default: default value for parameters and initial guess for variables
Lower: lower limit
Upper: upper limit
Unit: textual unit of measurement
Integer
Boolean
Plugin
Object for loading third party pieces of software providing special calculation
services, see chapter 5.
22
# Pressure
pressure as Real (Brief = "Pressure", Default=1,
Lower=1e-30, Upper=5e7, final Unit = atm);
press_delta as pressure (Brief = "Pressure
Difference", Default=0.01, Lower=-5e6);
head_mass as Real (Brief = "Head", Default=50, Lower
=-1e6, Upper=1e6, final Unit = kJ/kg);
Using files
Code reuse is one of the key concepts behind EMSO. To achieve
this the user can be able to use code written in another files
without have to touch such files. A .mso file can make use of
all entities declared in another files with the using command.
This command has the following form:
using "file name";
where "file name" is a textual file name. Therefore, commands matching this pattern could be:
1
2
3
using "types";
using "streams";
using "tanks";
3.2 Model
23
Note: As shown in the sample code, if the user suppress the file
extension when using files EMSO will automatically add the
mso extension.
Whenever possible the user should prefer the using command
instead of copy and paste code.
Windows note: The EMSO language is case sensitive but the
windows file system is not. Therefore, when using files in windows, the language became case insensitive to the file names.
3.2
Model
The basic form of a Model was introduced in subsection 3.1.2,
here we describe how the Model body is written.
In Code 3.2 the syntax for writing Models in the EMSO modeling
language is presented.
Code 3.2: Syntax for writing Models.
1
2
3
5
6
EQUATIONS
["equation name"] expression = expression;
8
9
INITIAL
["equation name"] expression = expression;
11
12
SET
name = expression;
14
15
16
end
24
3.2.1
Parameters
3.2 Model
25
Outer Parameters
As can be seen in line 3 of Code 3.2 a parameter declaration
can use the outer prefix. When a parameter is declared with
this prefix, the parameter is only a reference to a parameter with
same name but declared in an outer context, for instance in a
FlowSheet. Because of this, parameters declared with the
outer prefix are known as outer parameters, while parameters
without the prefix are known as concrete parameters.
The purpose of outer parameters is to share the value of a parameter between several Devices of a FlowSheet. Note that the
value of an outer parameter comes from a parameter with same
name but declared in some outer context. When the source of an
outer parameter is a FlowSheet its value is specified only in
the FlowSheet and then all models can use that value directly.
3.2.2
Variables
Every mathematical model has a set of variables once the variable
values describe the behavior of the system being modeled. These
values are the result of a simulation in opposition to parameters,
which need to be known prior to the simulation.
In the EMSO modeling language, variables are declared in a manner very close to parameters. The VARIABLES identifier starts
the section where the variables are declared, following the form
presented in line 5 of Code 3.2. Examples of variable declarations
follows:
VARIABLES
T as Real(Brief="Temperature", Lower=200,
Upper = 6000);
in Fin as FlowRate;
out Fout as FlowRate;
26
3.2.3
Composition in Models
In subsection 3.1.1 the composition concept was introduced. In
the EMSO modeling language, to built composed Models is
nothing more than declare parameters or variables but using Models
as base instead of types.
If a Model is used as base for a variable such variable actually is
a sub-model and the Model where this variable was declared is
called a composed Model.
A variable deriving from a Model contains all the variables, parameters even equations of the base. In order to access the the
internal entities of a sub-model, for instance in equations or for
setting parameters, a path should be used, as exemplified in line 4
of the code below:
1
2
3
4
VARIABLES
controller as PID;
SET
controller.K = 10;
3.2 Model
3.2.4
27
Equations
Equations are needed to describe the behavior of the variables of
a Model. A Model can have any number of equations, including
no equations. In EMSO an equation is an equality relation between two expressions, it is not an attributive relation. Therefore,
the order in which the equations are declared does not matter.
Warning: A Model with more equations than variables is useless, once there is no way to remove equations from a model.
An equation is declared using the form presented in line 7 of
Code 3.2, where expression is a expression involving any of
preciously declared variables, parameters, operators, built-in functions and constants. A constant can be a number or the text of
a unit of measurement. Details about the available operators,
functions and their meaning can be found in section 3.9.
Examples of equation follows:
EQUATIONS
"Total mass balance" diff(Mt) = Feed.F - (L.F
+ V.F);
"Vapor pressure" ln(P/atm) = A*ln(T/K) + B
/T + C + D*T2;
Units of measurement
Note that atm and K, in the code above, are not comments,
such texts are recognized as units of measurement (UOM) constants and effectively are part of the expression. In such example
the UOMs are required to assure units dimension correctness, because the ln function expects a UOM dimensionless argument.
The UOM of a variable or parameter comes from its type or
declaration, for example:
temperature as Real(final Unit=K, Lower = 100,
Upper = 5000);
pressure as Real(final Unit=atm, Lower = 1e-6,
Upper = 1000);
VARIABLES
T1 as temperature;
T2 as Real(Unit = K);
P1 as pressure;
P2 as pressure(Unit = kPa); # error because
Unit was declared as final in pressure
P2 as pressure(DisplayUnit = kPa);
28
3.2.5
Initial Conditions
EMSO can execute dynamic and steady state simulations, see
subsection 3.3.4. Most dynamic systems requires a set of initial
conditions in order to obtain its solution. These initial conditions
are stated exactly as equations (subsection 3.2.4 but within the
INITIAL section identifier, for instance:
INITIAL
"Initial total mass" Mt = 2000 * kg;
Note that the equations given in the INITIAL section are used
only in the initialization procedure of dynamic simulations.
3.2.6
Abstract Models
If a Model has less equations than variables it is known as a rectangular or abstract Model, because specifications, connections
or extra equations are required in order to obtain its solution. If
a Model has no equation it is known as a pure abstract Model,
once it holds no information about the behavior of its variables.
Most models of a library are abstract or pure abstract where the
pure abstract models are derived to generate a family of abstract
models and so on. Note that is very uncommon to have a pure
abstract model used directly in a FlowSheets as well as to use
a model which is not abstract.
3.3
FlowSheet
In section 3.2 the Model body was described. When writing
FlowSheets the user can freely make use of all description
commands of a Model body, exactly as stated in section 3.2.
Additionally, in the case of FlowSheets, the sections presented
in in Code 3.3 could be used.
3.3 FlowSheet
29
Code 3.3: Syntax for writing FlowSheets.
1
2
3
5
6
SPECIFY
name = expression;
8
9
OPTIONS
name = value;
11
12
13
end
Code 3.3 uses the same code conventions explained in section 3.2.
It follows below the details of the sections of this code.
3.3.1
Devices
In line 2 of the Code 3.3 the DEVICES section can be seen. In
this section the user can declare any number of Devices of a
FlowSheet, in OO modeling these Devices are known as the
components, see subsection 3.1.1.
The DEVICES section in a FlowSheet is a substitute of the
VARIABLES section of a Model but no prefix is allowed.
Note: There is no sense in using the in or out prefix in
FlowSheets, because these supposed inputs or outputs could
not be connected once the FlowSheet is the top level model.
Exactly as variables of a Model, the base (line 3 of Code 3.3)
can be any a type, or Model.
Examples of Device declarations follows:
DEVICES
feed as MaterialStream;
pump1 as Pump;
pump2 as Pump;
3.3.2
Connections
In subsection 3.2.2 was described how to declare an input or output variable. However, was not specified how to connect an output variable to an input one. This can be done with the form
presented in line 6 of Code 3.3, where a output variable is connected to an input.
30
3.3.3
Specifications
In subsection 3.2.6 the term abstract model was defined, basically
it means models with missing equations. Most useful models
are abstract, because of their flexibility. This flexibility comes
from the possibility of specify or connect the models in several
different fashions.
In order to simulate a FlowSheet it must have the number of
variables equal number of equations. FlowSheets using abstract Models requires specifications for variables in the form
presented in line 9 of Code 3.3. In a specification expression
can be any expression valid for an equation (see subsection 3.2.4)
and name is the name or path name of the specified variable.
3.3.4
Options
In order to adjust the simulation parameters of a FlowSheet
the user can make use of the OPTIONS section. The following
piece of code shows how to set simulation options of a FlowSheet:
OPTIONS
TimeStart = 1;
TimeStep = 0.1;
TimeEnd = 10;
TimeUnit = h;
DAESolver( File = "dasslc");
3.4
Optimization
Optimization differ from simulation in several aspects. In simulation problems the solvers will try to find the solution. In optimization problems the solvers try to find the best solution with
3.4 Optimization
31
DAESolver
Type
real
real
real
boolean
text
real
real
real
boolean
text
text
text
text
Description
The reporting integration time start: 0;
The reporting integration time step: 10;
The reporting integration time end: 100;
Execute dynamic or static simulation: true or false;
The system to be used in integration: "original",
"index1" or "index0";
The relative accuracy: 1e-3;
The absolute accuracy: 1e-6;
The independent variable accuracy when detecting state
events: 1e-2;
To use sparse linear algebra or dense: true or false;
Load the initial condition from result file
Load the an initial guess from result file
The NLA solver library file name to be used:
"sundials", "nlasolver", or the name the file
of some solver developed by the user as described in
chapter 9;
The DAE solver library file name to be used:
"dasslc", "sundials", "dassl", "mebdf", or
the name the file of some solver developed by the user
as described in chapter 9;
32
6
7
8
EQUATIONS
expression5 < expression6;
expression7 > expression8;
10
11
12
FREE
variable1;
variable2;
14
15
16
17
end
Code 3.4 uses the same code conventions explained in section 3.2.
It follows below the details of the sections of this code.
3.4.1
Simple Optimizations
An example of simple optimization problem follows:
Optimization hs71
VARIABLES
x(4) as Real(Default=1, Lower=1, Upper=5);
MINIMIZE
x(1)*x(4)*(x(1)+x(2)+x(3))+x(3);
EQUATIONS
x(1)*x(2)*x(3)*x(4) > 25;
x(1)*x(1) + x(2)*x(2) + x(3)*x(3) + x(4)*x(4)
= 40;
OPTIONS
Dynamic = false;
end
3.4 Optimization
33
As can be seen in the code above, optimization problems support
inequality constraints which are not supported in Models or
FlowSheets.
In the example above, the optimization is self-contained. The
variables, optimization objectives and constraints are all declared
in the optimization problem body.
Tip: Optimization problems are solved exactly as FlowSheets,
with the run button.
3.4.2
Large-Scale Optimization
In subsection 3.4.1 we described how to write a simple optimization problem. The same approach can be used to describe largescale problems but this form is barely convenient.
As a convenience for the user, EMSO supports the directly optimization of already running FlowSheets. As an example,
consider that the user has an already developed and running
FlowSheet for a process of ammonia synthesis called Ammonia.
Now lets consider that the user want to find the recycle fraction
which yields to the minimun lost of product on the purge. For
this case the following code could be used:
Optimization AmmoniaOptimization as Ammonia
MINIMIZE
productLoose;
FREE
Splitter102.fraction;
OPTIONS
Dynamic = false;
end
34
3.4.4
Options
In subsection 3.3.4 all options supported by FlowSheets were
presented. Optimization problems support additional options as
listed in Table 3.3.
3.4.5
Dynamic Optimization
Under construction: As of this time, EMSO only supports static
optimization, dynamic optimization will be available soon.
35
3.5
Description
Flag if the simulation solution should be used as start
value for the optimization problem: true or false;
The file name of the NLP solver library:
"ipopt emso", or the name the file of some
solver developed by the user as described in chapter 9;
text
Parameter Estimation
EMSO can be used to solve steady state and dynamic parameter
estimation problems using already running FlowSheets.1 In order to create a new environment for parameter estimation problem
writing, the user should inform the name of the new environment
and the name of the base FlowSheet. This should be done
by using the keyword Estimation, as presented in Code 3.5,
which uses the same code conventions explained in section 3.2.
Code 3.5: Syntax for writing Estimation.
1
2
3
4
6
7
8
9
OPTIONS
11
12
TYPE
"fit";
"test";
end
Warning: Before running a estimation problem, it must be assured that the base FlowSheet can run (it should be consistent
and the simulation should succeed).
Into the Estimation environment, the parameter estimation
problem can be written using the commands presented in Code 3.5.
It is important to remark that only this specific commands showed
in Code 3.5 can be used for writing a parameter problem. The
other way round Optimization, the user can not use other
1
The parameter estimation section of this manual was written by Eng. Msc.
Tiago Fiorenzano Finkler.
36
3.5.1
The user will have to provide a set of measurements for the variables of the base FlowSheet and inform what parameters of the
base FlowSheet should be estimated. After properly written, a
parameter estimation problem is solved exactly as FlowSheets,
with the run button. So, by using the weighted least squares
criterion, EMSO will seek a set of new values for the measured
variables which minimizes the differences between the model predictions and the measurements of the variables.
When the problem is being solved, relevant information is reported in the Console window. The final results are reported
in the Results window. In addition to the results that are
reported when solving FlowSheets, the following informations
regarding the parameter estimation problem are provided: the
measurements of the variables, the absolute deviation between
the model predictions and the measurements, the relative deviation between the model predictions and the measurements, and
the standardized deviation between the model predictions and the
measurements.
Experiments
In the experiment section, the names of the data files containing
measures of base FlowSheet variables must be informed as
showed in Code 3.5. The name of the data file should informed
as a string and the file should be in the same folder of the .mso
file of the parameter estimation problem that is being solved. The
data files are expected to be text files with the following structure:
MEASURE
VARIANCE
DATA
variable1
value
value
value
value
value
variable2
value
value
value
value
value
37
As it can be seen in Code 3.5, the user may use multiple data files
containing measures of base FlowSheet variables. If it is the
case, two optional informations can be provided. The first is a
weight which should be a real number between 0 and 1 that can
be freely used to value or to devalue the particular experiments.
The second is the type of the experiment which can be equal
to fit or test. Experiments marked with the fit flag are
took into account for estimate the parameters while experiments
marked with the test flag are reserved for model validation.
More details about using experiments marked with the test
flag are provided in subsection 3.5.3.
Warning: When more than one experiment is informed at the
experiment section, it must be assured that all experiments have
exactly the same set of measured variables.
3.5.2
Estimate
In the estimate section, the parameters to be estimated must be
informed as showed in Code 3.5. EMSO will vary this parameters
until it finds a solution which minimizes the differences between
the model predictions and the fit data.
3.5.3
Options
RunTests
38
Significance
The statistical tests presented before are performed considering a
specific significance level. By default, the significance level is set
as 0.95, but the user can change it using the Significance
option. The syntax for using this option is showed in Code 3.8.
When using this code, the user can change the significance level
by setting it as any real number between 0 and 1.
Code 3.8: Syntax for using Significance
Significance = value;
39
BiLateral
This is an specific option for the significance of the estimated
parameter computation. By default, this statistic is computed
using a unilateral test, which is a conservative one. But this
statistic can also be computed using a bilateral test. This can
be done by changing thee BiLateral option. The syntax for
using this option is showed in Code 3.9. When using this code,
the user can set the BiLateral as true or false.
Code 3.9: Syntax for using BiLateral
BiLateral = true;
3.6
Data Reconciliation
Data reconciliation is a technique that was developed to improve
the accuracy of process measurements by reducing the effect of
random errors in the data. Basically, data reconciliation consists on adjusting variables measurements in such a way that the
obtained adjusted values obey some known process constrains,
which are described by the process model.
EMSO can be used to solve steady state data reconciliation problems using already running FlowSheets.2 In order to create a
new environment for data reconciliation problem writing, the user
should inform the name of the new environment and the name of
the base FlowSheet. This should be done by using the keyword
Reconciliation, as presented in Code 3.10, which uses the
same code conventions explained in section 3.2.
Code 3.10: Syntax for writing Reconciliation.
1
2
3
5
6
EXPERIMENTS
"data file one" [weight];
"data file two" [weight];
8
9
10
OPTIONS
12
13
end
2
The data reconciliation section of this manual was written by Eng. Msc.
Tiago Fiorenzano Finkler.
40
3.6.1
Experiments
In the experiment section, the names of the data files containing the measures to reconciled must be informed as showed in
Code 3.10. The name of the data file should informed as a string
and the file should be in the same folder of the .mso file of the
data reconciliation problem that is being solved. The data files
are expected to be text files with the following structure:
MEASURE
VARIANCE
DATA
variable1
value
value
variable2
value
value
41
be entered and the name of the variable is exactly the same as
it is in the base FlowSheet. After the keyword VARIANCE,
the value of the variance of the measurements of each one of
the previously informed measured variables should be informed.
Finally, after the keyword DATA, the values of the steady state
measurements of the measured variables must be informed.
Measurements replicates can be informed as additional entries after the keyword DATA. When replications are informed, the reconciliation problem take into account some representative value
of the informed measures for each variable. By default, this representative value is the arithmetic mean. But it can be set as the
median by using the Filter option, as it will be showed further in
subsection 3.6.4.
Another way of taking replicates of the measurements into account is informing them as additional experiments. Using the
format showed in Code 3.10, it can be informed as many experiments the user wants. When multiple experiments are informed,
a weight which should be a real number between 0 and 1 that
can be freely used to value or to devalue the particular data files.
Note: The weight of a experiment is took into account in the
computation of the filtered value for each measure. Actually it is
only considered when the chosen filtered measure is the weighted
arithmetic mean. When the filtered measure is chosen as the
median it is not considered. See subsection 3.6.4 for details about
choosing the Filter option.)
3.6.2
Reconcile
In the reconcile section, the variables to be reconciled must be
informed as showed in Code 3.10. Any of the variables informed
at the experiment section can be reconciled.
EMSO will use the variables entered in the reconcile section to
compute the objective function of the data reconciliation problem.
By default, the weighted least squares criterion is used. Another
objective functions can be used by changing the ObjectiveFunction option, as it will be explained further in subsection 3.6.4.
42
3.6.3
Free
In this section, the degrees of freedom of the data reconciliation
problem, which are also variables of the base FlowSheet, should
be informed. The variables chosen as degrees of freedom must
be specifications in the base FlowSheet that can be measured
or not.
3.6.4
Options
Internally, EMSO treats a data reconciliation problem as a optimization problem with a predefined objective function. So, the
options supported into the Optimization environment are also
supported into the Reconciliation environment. Additionally, the options Filter, GrossErrorTests, Significance,
and ObjectiveFunction are also supported. Details about
how to use each one of this options are given in the following.
Note: The Dynamic option must always be set as false in order
to run data reconciliation problems.
Filter
The Filter option allows the user to choose how EMSO will
deal with measurements replicates. The user can decide if the
representative values of the measurements of each variable will
be computed as the weighted arithmetic mean or as the median
of the individual measurements. The syntax for using this option
is showed in Code 3.11, in which Filter must be set as mean
or median.
Code 3.11: Syntax for using Filter
Filter = "mean";
GrossErrorTest
In order for data reconciliation to be effective, it is important to
assure that only random errors are present in the measurements.
43
The presence of gross errors caused by nonrandom events such
as instrument malfunctioning, miscalibration, wear corrosion of
sensors, or solid deposits, can highly damage the adjustments
evaluation. For this reason, it is important to check reconciliation results using statistical tests for gross error detection. When
a gross error is detected, the necessary actions to eliminate it
must be taken, e.g. instrument recalibration, and measurements
free from gross errors should be provided in order to the data
reconciliation problem be properly solved.
EMSO provides three statistical tests for gross error detection:
the global test, the nodal test and the measurement test. The
global test is applied over the objective function value and only
indicates if the probability of a gross error exists between the considered measurements can be neglected or not. The nodal test
is applied over each one of the model equations and indicates if
the probability of a gross error exists between the measured variables of the respective equations can be neglected or not. Finally,
the measurements test is applied over each one of the reconciled
variables and indicates directly if the probability of a gross error
exists in every particular measurement can be neglected or not.
The user can decide which of those tests will be performed by
using the GrossErrorTests option. The syntax for using
this option is showed in Code 3.12. When using this code, the
user can decide which of the tests will be performed by setting the
respective boolean values as true or false. The results of
all tests are reported at the Console window. Additionally, the
results of the measurement test are also reported at the Results
window.
Code 3.12: Syntax for using GrossErrorTests
GrossErrorTests([Global=true], [Nodal=true], [
Measurements=true]);
Significance
The statistical tests presented before are performed considering a
specific significance level. By default, the significance level is set
as 0.95, but the user can change it using the Significance
option. The syntax for using this option is showed in Code 3.13.
When using this code, the user can change the significance level
by setting it as any real number between 0 and 1.
Code 3.13: Syntax for using Significance
Significance = value;
44
ObjectiveFunction
As it was mentioned in subsection 3.6.2, by default, EMSO uses
the weighted least squares criterion to build the objective function
of the data reconciliation problem. The weight least squares criterion results from the assumption that the random measurement
errors follow a normal distribution around the true measurement
value to be estimated. This is generally a good hypothesis which
can be assumed in most of cases.
However, as this criterion states a quadratic dependence between
the measurements adjustments and its individual contributions to
the objective function, measurements with gross errors will tend
to have a high influence on the overall least squares value. In the
final solution it will inevitably be compensated by changing the
adjustments of other measured variables. This means that the
least squares criterion is highly prone to gross error propagation.
In order to minimize this ill effect, EMSO provides a set of alternative objective functions to solve data reconciliation problems
which are based on different assumptions about the way the errors are distributed around the true measurement value to be
estimated. All those different objective functions exhibit almost
the same behavior that the least squares function in a certain
range around the central point but, outside this range, they stop
growing quadratically as error increases, which results in much
smaller contributions when the error is large. This feature may
help to reduce the gross error propagation effect.
The user can choose the between the different objective functions
provided by EMSO by changing the ObjetctiveFunction
option. The syntax for using this option is showed in Code 3.14, in
which ObjectiveFunction must be set as: Normal, ContaminatedNormal, Cauchy, Logistic, Lorenzian, Fair,
or Hampel.
Code 3.14: Syntax for using ObjectiveFunction
ObjectiveFunction = "Normal";
Note: Although using the available alternative objective functions may considerably reduce the gross error propagation effect,
it can not eliminate it. In fact, as the objective functions grows
monotonically as the error modulus increases, measurements with
higher errors will still show important contributions to the final
objective function value. So, gross errors must be properly identified and eliminated, no matter what objective function is being
used.
3.7
45
Case Study
Case study is a research technique aimed to study the response
variables, disturbing some decision or manipulated variables.
EMSO can be used to solve case study problems in steady state
and dynamic models using already running FlowSheets.3 In
order to create a new environment for case study problem writing,
the user should inform the name of the new environment and the
name of the base FlowSheet. This should be done by using
the keyword CaseStudy, as presented in Code 3.15, which uses
the same code conventions explained in section 3.2.
Code 3.15: Syntax for writing CaseStudy.
1
2
3
4
6
7
8
9
end
The case study section of this manual was written by Eng. Marcos Vincius
Almeida Narciso.
46
3.7.1
Vary
In the VARY section, the variables to be varied must be informed
as showed in Code 3.15. All of the variables informed at this section will be combined in grid format. In a dynamic FlowSheet,
all points in time range are computed.
The VARY variable can have its unit of measure declared or not,
if it is not informed, the SI standard unit of measure is used.
EMSO will use the variables entered in the VARY section to compute the response variables of the case study problem. By default,
EMSO will make a combination with all elements of each variable,
simulating each one.
3.7.2
Response
In the response section, the response variables must be informed
as showed in Code 3.15. All of the variables informed at this section will be calculated by EMSO and they are showed in Results
tab.
As explained in 3.7.1, the VARY variable can have its unit of
measure declared or not, if it is not informed, the SI standard
unit of measure is used.
Warning: In RESPONSE section, the * symbol can not be
informed in unit declaration.
3.7.3
Results
If the flowsheet converged, an OK symbol will be displayed in
the cell corresponding to the response, in the case that the flowsheet did not converged, the result will not be displayed. In the
case of success, in the Results tab, the CaseStudy results
will be exhibited in a table. As showed in Figure 3.1, variables,
with its unit, will be disposed in lines, and the time will be disposed in columns.
47
48
3.8
Sensitivity Analysis
Sensitivity analysis, is similar as CaseStudy, it reports how the
variation of a disturb affects a response variable. The main difference is that this response is a derivative of a response variable
in respect to a input or disturb variable:
y
x
6
7
8
9
end
The sensitivity analysis section of this manual was written by Eng. Marcos
Vincius Almeida Narciso.
49
After properly written, a sensitivity analysis is solved exactly as
FlowSheets, with the run button. So, EMSO will transform
the Jacobian matrix of model (matrix with all derivatives equations related with all variables present in model) to obtain a Sensitivity matrix of Model between VARY and RESPONSE variables.
50
Vary
In the VARY section, the input variables must be informed as
showed in Code 3.16. All of the variables informed at this section
will be combined with the variables of RESPONSE section. These
variables can be specifications or parameters.
The VARY variable can have its unit of measure declared or not,
if it is not informed, the SI standard unit of measure is used.
EMSO will use the variables entered in the RESPONSE section
to compute the Jacobian matrix related with VARY variables of
the sensitivity analysis.
3.8.2
Response
In the response section, the response variables must be informed
as showed in Code 3.16. All of the variables informed at this section will be calculated by EMSO and they are showed in Results
tab. These variables can not be specifications or parameters.
As explained in 3.8.1, the RESPONSE variable can have its unit
of measure declared or not, if it is not informed, the SI standard
unit of measure is used.
Warning: In RESPONSE section, the * symbol can not be
informed in unit declaration.
5
Shengtai Li, Linda Petzold - Software and algorithms for sensitivity analysis of large-scale differential algebraic systems, Journal of Computational
and Applied Mathematics, 125 (2000) 131145
6
Yang Cao, Shengtai Li, Linda Petzold, Adjoint sensitivity analysis for
differential-algebraic equations: algorithms and software, Journal of Computational and Applied Mathematics 149 (2002) 171 191
51
Results
If the flowsheet converged, an OK symbol will be displayed
in the cell corresponding to the response, in the case that the
flowsheet did not converged, the result will not be displayed. In
the case of success, in the Results tab, the CaseStudy results will be exhibited in a table. As showed in Figure 3.3, the
VARY variables, with your unit, will be disposed in lines, and the
RESPONSE variables, with your unit, will be disposed in columns.
52
3.9
53
Built-in Functions
In this section the built-in functions supported by the EMSO are
listed. There are two categories of functions:
Element-by-element: if the argument of the function is a
vector or matrix, the function is applied in the same way to
all elements of the argument. The returned value of these
functions always have the same dimensions of its argument;
Matrix transformation: The functions in this category
make sense only for vector and matrix arguments. The
return value can be a scalar, vector, or matrix depending
on the function and the argument.
Examples of use of the functions are available in the folder
<EMSO>/mso/sample/miscellaneous.
Meaning
Returns the
Returns the
Returns the
Returns the
Returns the
Returns
Returns
Returns
Returns
Returns
Returns
the
the
the
the
the
the
sine of Z
cosine of Z
tangent of Z
angle whose sine is Z
angle whose cosine is Z
angle whose tangent is Z
Returns
Returns
Returns
Returns
the
the
the
the
hyperbolic
hyperbolic
hyperbolic
hyperbolic
Returns
Returns
Returns
Returns
Returns
the
the
the
the
the
sine of Z
cosine of Z
tangent of Z
cotangent of Z
54
3.10
Meaning
Returns a scalar with the sum of all elements of the vector VEC
Returns a vector with the sum of each column of the matrix MAT
Returns a vector with the sum of each row of the matrix MAT
Returns a scalar with the product of all elements of the vector
VEC
Returns a vector with the product of each column of the matrix
MAT
Returns a vector with the product of each row of the matrix MAT
Returns the transpose of a matrix MAT
3.10.1
Fundamental Units
m
kg
s
K
A
mol
cd
rad
US$
3.10.2
length in meters
mass in kilogram
time in seconds
temperature in Kelvin
eletric current in Ampere
the amount of substance in mole
the luminous intensity in Candela
angle measure in radian
money in dollar (USA)
Derived Units
Acceleration of Gravity
ga
9.80665*m/s2
Angle
arcs
4.8481368111e-6*rad
arcmin 2.90888208666e-4*rad
grad
1.57079632679e-2*rad
deg
1.74532925199e-2*rad
55
4046.87260987*m2
100*m2
10000*m2
1e-28*m2
acre
are
hectare
barn
kg*m2 /A/s2
kg/A/s2
A2 *s3 /kg/m2
A2 *s3 /kg/m2
96487*A*s
A2 *s4 /kg/m2
kg*m2 /A2 /s3
A*s
kg*m2 /A/s3
weber
tesla
siemens
mho
faraday
farad
ohm
relative current for batteries
volt
kg*m2 /s2
1e3*J
1e6*J
1e9*J
1.60217733e-19*J
1e6*eV
105506000*J
1055.05585262*J
4.1868*J
1e3*cal
1e-7*J
joule
kilojoule
megajoule
gigajoule
electronvolt
megaelectronvolt
therm
British thermal unit
calorie
kilo calorie
erg
kg*m/s2
0.138254954376*N
4.44822161526*N
4448.22161526*N
0.00980665*N
1e3*gf
0.00001*N
newton
poundal
pounds of force
kip
gram force
kilogram force
dyne
1e-2*m
0.1*cm
1e-15*m
1e-10*m
1e-6*m
centimeter
millimeter
fermi
angstrom
micro
56
2.54e-5*m
0.304800609601*m
1.82880365761*m
5.02921005842*m
20.1168402337*m
1609.34721869*m
1852*m
1609.344*m
1000*m
1.495979e11*m
9.46052840488e15*m
3.08567818585e16*m
3.08567818585e22*m
0.0254*m
0.3048*m
0.9144*m
mil
international foot
fathom
rod
chain
US statute miles
nautical mile
International Mile
Kilometer
Astronomical Unit
light year
parsec
megaparsec
inch
foot
yard
1.6605402e-27*kg
0.00006479891*kg
0.0002*kg
0.0311034768*kg
1000*kg
1016.0469088*kg
907.18474*kg
0.3732417216*kg
14.5939029372*kg
0.028349523125*kg
0.45359237*kg
kg/1000
1e3*mol
453.59237*mol
US$/3.05
kg m2 /s3
1e3*W
1e6*W
745.699871582*W
watt
Kilowatt
megawatt
horsepower
kg/m/s2 pascal
1e3*Pa
Kilopascal
57
1e3*kPa
248.84*Pa
3386.38815789*Pa
133.322368421*Pa
133.322368421*Pa
6894.75729317*Pa
1e5*Pa
101325*Pa
megapascal
inch of water column
inch of mercury
millimeter of mercury
torr
pound per square inch
bar
atmosphere
0.000258*A*s/kg
3.7e10/s
1/s
m2 /s2
0.01*m2 /s2
m2 /s2
R
curie
becquerel
sievert
rem
gray
K/1.8
degree Rankine
1/s
60*s
1/min
60*min
24*h
31556925.9744*s
hertz
minute
revolution per minute
hour
day
year
299792458*m/s
0.514444444444*m/s
0.44704*m/s
0.277777777778*m/s
light speed
knot
mile per hour
kilometer per hour
0.0001*m2 /s
0.1*kg/m/s
0.001*kg/m/s
stoke
poise
centipoise
m3
0.002359737216*m3
0.0088097675*m3
0.03523907*m3
0.158987291928*m3
4.92892159375e-6*m3
1.47867647813e-5*m3
Stere
board foot
peck
bushel
barrel
teaspoon
tablespoon
58
3.11
2.8413075e-5*m3
2.95735295625e-5*m3
2.365882365e-4*m3
1e-3*m3
1e-3*l
0.000473176473*m3
0.000946352946*m3
0.00378541178*m3
0.00454609*m3
0.004546092*m3
Solver Options
Solver specific options can be declared in the following way, they
are not case sensitive:
OPTIONS
Dynamic = false;
NLPSolveNLA = false;
NLPSolver(File = "ipopt_emso",
RelativeAccuracy = 1e-6,
limited_memory_max_history = 20);
59
Table 3.6: IPOPT optimization solver specific options, default value in bold.
Option name
MaxIter
Print level
Limited memory max history
Derivative test
Derivative test print all
Output file
Mu strategy
Print user options
Linear solver
Hessian approximation
Fixed variable treatment
RelativeAccuracy
Acceptable tol
Constr viol tol
Acceptable constr viol tol
Dual inf tol
Acceptable dual inf tol
Barrier tol factor
Compl inf tol
Bound mult init val
Bound push
Bound relax factor
Finite difference perturbation
Type Description
integer Maximum number of iterations: textbf3000
integer Output verbosity level. The valid range for this integer
option is 0 printlevel 11
integer Maximum size of the history for the limited quasiNewton Hessian approximation. The valid range for this
integer option is 0 6 < +
string Enable
derivative
checker:
first-order,
second-order, none
string Indicates whether information for all estimated derivatives should be printed: yes, no
string File name of desired output file. ipopt.out
string Update strategy for barrier parameter: "adaptive",
monotone
string Print all options set by the user: "yes", no
string Linear solver used for step computations: "ma27",
"ma57", "mumps", Default depends on compilation
options.
string Indicates what Hessian information is to be used:
"exact", "limited-memory"
string Determines how fixed variables should be handled "relax bounds", "make constraint",
"make parameter"
real
Desired convergence tolerance (relative): 1 1008
real
Acceptable convergence tolerance (relative): 1 1006
real
Desired threshold for the constraint violation(Absolute):
1 1004
real
Acceptance threshold for the constraint violation(Absolute): 1 1002
real
Desired threshold for the dual infeasibility(absolute): 1
1004
real
Acceptance threshold for the dual infeasibility(absolute): 1 1002
real
Factor for mu in barrier stop test.(absolute): 1 10+01
real
Desired threshold for the complementarity conditions:
1 1004
real
Initial value for the bound multipliers 0 1 < +
real
Desired minimum absolute distance from the initial point
to bound 0 1002 < +
real
Factor for initial relaxation of the bounds. Used together
with fixed variable treatment option. 0 1008 < +
real
Perturbation size for finite-diff Hessian Evaluation 0
1006 < +
60
In the case where the option belongs to the mixed-integer algorithm itself, it is necessary write the option preceded by the word
bonmin (pay attention to the underscore ), for example:
OPTIONS
NLPSolver(File = "minlp_emso", derivative_test = "
second-order",
bonmin_algorithm = "B-BB", print_level = 5);
Below follows the Bonmin options, more details about the options
can be found at Bonmin manual:
61
Table 3.7: MINLP ( Bonmin )optimization solver specific options, default value in bold.
Option name
algorithm
Type
string
string
string
warm start
string
sos constraints
string
string
milp subsolver
string
bb log level
integer
bb log interval
integer
bb log level
integer
bb log level
integer
oa log level
integer
oa log frequency
integer
integer
integer
integer
node limit
integer
integer
integer
Description
Bonmin algorithm: "B-BB", "B-OA", "B-QG",
B-Hyb
Print all options set by the user: "yes", no
Choose the node selection strategy. "best-bound",
"dept-first", "breadth-first", dynamic
Select the warm start method.
"optimum",
"interior point", "none"
Whether or not to activate SOS constraints branching.
"stop", "fathom"
Set the behavior when an NLP or a series of NLP are
unsolved by Ipopt "enable", "disable"
Choose the subsolver to solve MILPs sub-problems in
OAdecompositions. "Cbc D", "Cbc Par"
Specify branch-and-bounds log level: The valid range for
this integer option is 0 1 0
Interval at which node level output is printed: The valid
range for this integer option is 0 100
Set the level of output of the linear programming subsolver in B-Hyb or B-QG: The valid range for this integer
option is 0 0 4
specify MILP subsolver log level. Set the level of output
of the MILP subsolver in OA. The valid range for this
integer option is: 0 0 3
Set the level of output of OA decomposition solver. The
valid range for this integer option is: 0 1 2
Specify OA log frequency. The valid range for this integer option is: 0 100
Set the level of output of nlp solver (independent from
Ipopt print level). The valid range for this integer option
is: 0 1 2
Choose the maximum number of variables considered for
strong branching. The valid range for this integer option
is: 0 20
Set the number of branches on a variable before its
pseudo costs are to be believed in dynamic strong
branching.The valid range for this integer option is:
08
Set the maximum number of nodes explored in the
branch-andbound search.The valid range for this integer option is: 0 INT MAX
Number n of consecutive unsolved problems before
aborting a branch of the tree. The valid range for this
integer option is: 0 10
Number k of times that the algorithm tries to resolve an
unsolved NLP with a random starting point. The valid
range for this integer option is: 0 0
62
Table 3.8: MINLP ( Bonmin )optimization solver specific options, default value in bold,
continued.
Option name
max consecutive unfeasible
mir cuts
allowable gap
allowable fraction gap
cutoff
cutoff decr
time limit
integer tolerance
max random point radius
max consecutive failures
oa dec time limit
tiny element
very tiny element
Type Description
integer Number k of consecutive infeasible subproblems before
aborting a branch. The valid range for this integer option
is: 0 0
integer Number k of trials to solve the root node with different
starting points. The valid range for this integer option
is: 0 0
integer Specify the frequency (in terms of nodes) at which NLP
relaxations are solved in B-Hyb method.The valid range
for this integer option is: 0 10
integer Specify the frequency (in terms of nodes) at which NLP
relaxations are solved in B-Hyb method.The valid range
for this integer option is: 0 10
integer Number k of trials to solve a node of the tree with different starting points. The valid range for this integer
option is: 0 0
integer Sets the frequency (in terms of nodes) for generating
cuts of the given type in the branch-and-cut .The valid
range for this integer option is: 100 -5
integer (for debugging purposes only) number of iterations to
consider a problem suspect.The valid range for this integer option is: 1 -1
real
Specify the value of absolute gap under which the algorithm stops: 0
real
Specify the value of relative gap under which the algorithm stops: 0
real
Specify a cutoff value: 1 10100
real
Specify cutoff decrement: 1 105
real
Set the global maximum computation time (in seconds)
for the algorithm.: 1 1010
real
Any number within that value of an integer is considered
integer: 1 106
real
Set max value r for coordinate of a random point: 1105
real
Set max value r for coordinate of a random point: 1105
real
Specify the maximum number of seconds spent overall
in OA decomposition iterations: 120
real
Value for tiny element in OA cut: 1 108
real
Value for very tiny element in OA cut. Algorithm will
take the risk of neglecting an element lower than this:
1 1017
63
Warning: One must pay attentions that the above options are
compatible with just some algorithms,the compatibility table is
presented below:
Table 3.9: List of options and compatibility with the different algorithms.
Option
bb log level
bb log interval
lp log level
milp log level
oa log level
oa log frequency
nlp log level
print user options
time limit
allowable gap
allowable fraction gap
cutoff
cutoff decr
integer tolerance
node limit
nodeselect stra
number before trust
number strong branch
sos constraints
max random point radius
max consecutive failures
nlp failure behavior
num iterations suspect
num retry unsolved random point
type
default B-BB B-OA B-QG B-Hyb
output options
I
1
+
+
+
I
100
+
+
+
I
0
+
+
I
0
+
I
1
+
I
100
+
I
1
+
+
+
+
S
no
+
+
+
+
branch-and-bound options
F
1010
+
+
+
+
F
0
+
+
+
+
F
0
+
+
+
+
100
F
10
+
+
+
+
F
105
+
+
+
+
6
F
10
+
+
+
+
I INT MAX
+
+
+
+
S best-bound
+
+
+
+
I
8
+
+
+
I
20
+
+
+
S
enable
+
options for robustness
F
105
+
+
+
+
I
10
+
S
stop
+
+
+
+
I
1
+
+
+
+
I
0
+
+
+
+
64
Table 3.10: List of options and compatibility with the different algorithms continued.
Option
max consecutive infeasible
num resolve at node
num resolve at root
nlp solve frequency
oa dec time limit
tiny element
very tiny element
cover cuts
Gomory cuts
milp subsolver
mir cuts
probing cuts1
I
0
+
+
+
+
I
0
+
+
+
+
B-Hyb specific options
I
10
+
F
120
+
F
108
+
+
+
17
F
10
+
+
+
MILP options
I
5
+
I
5
+
S Cbc D
+
I
5
+
I
-5
Table 3.11: OPT++ optimization solver specific options, default value in bold.
Option name
MaxIterations
MaxFeval
Type Description
integer Maximum number of iterations: 100
integer Maximum number of function evaluations allowed:
1000
MaxBTIter
integer Maximum number of Back Track iterations allowed: 5
PrintDebug
integer Print debug information: 1, 0
SearchStrategy
string Search Strategy: BTLineSearch, TrustRegion,
LineSearch
MeritFun
string Search Strategy:
ArgaezTapia, NormFmu,
VanShanno ;
OutputFile
string Output file name: opt.out
RelativeAccuracy
real
set the Function tolerance: 1.49 1008
GradTol
real
set the Function tolerance: 6 1006
ConstrTol
real
set the Function tolerance: eps
StepTol
real
set the Function tolerance: 1.49 1008
MaxStep
real
set the Function tolerance: 1 10+03
MinStep
real
set the Function tolerance: 1.49 1008
LineSearchTol
real
set the Function tolerance: 1 1004
TRSize
real
set the Function tolerance: 0.1 kf (x)k
65
Table 3.12: NLASolver and Sundials specific options, default value in bold.
Option name
MaxIterations
Maxatbound
MaxDumpIter
MaxLSetupReuse
RelativeAccuracy
AbsoluteAccuracy
Type
integer
integer
integer
integer
real
real
Description
Maximum number of iterations: 100
Maximum number of iterations at bound: 20
Maximum dump iteration: 6
Maximum Jacobian reuse in the linear solving phase: 0
set the Function tolerance: 1 1003
set the Function tolerance: 1 1006
Type Description
integer Maximum number of internal steps to be taken by the
solver in its attempt to reach tout. 500
MaxOrder
integer Maximum LMM mathod order: 5
SuppressAlg
integer Suppress alg. vars. from error test 0
RelativeAccuracy
real
Set the function tolerance: 1 1003
AbsoluteAccuracy
real
Set the function tolerance: 1 1006
Hinit
real
Initial step size 0
Hmax
real
Maximum absolute value of step size allowed 1 1010
Nconfac
real
Factor in nonlinear convergence test for use during integration 1.0
Type Description
integer Maximum number of internal steps to be taken by the
solver in its attempt to reach tout. 10
MaxOrder
integer Maximum LMM mathod order: 5
Maxl
integer max. number of iterations before restart: 5
Kmp
integer number of orthogonalized vectors: 5
Istall
integer intermediate time steps : 5
RelativeAccuracy
real
Set the function tolerance: 1 1003
AbsoluteAccuracy
real
Set the function tolerance: 1 1006
Advanced Modeling
In chapter 3 the basic concepts of the EMSO modeling language were described. In this
chapter we describe more advanced concepts.
Contents
4.1
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
4.2
Conditional Modeling . . . . . . . . . . . . . . . . . . . . . . . . .
70
4.1 Arrays
4.1
67
Arrays
In EMSO we can make use of multidimensional arrays, i.e., arrays
with any number dimensions.
4.1.1
Vectors
The simplest form of an array is the one dimension array a
vector. In EMSO a vector of variables is declared as follows:
PARAMETERS
N as Integer(Default=10);
VARIABLES
vector1(100) as Real(Brief="A vector with 100
elements");
vector2(N)
as Real(Brief="Undefined length
vector");
68
4 Advanced Modeling
CONNECTIONS
s1 to mix.Inlet(1);
s2 to mix.Inlet(2);
s3 to mix.Inlet(3);
SET
mix.Ninputs = 3;
end
Multidimensional Arrays
4.1.3
Equation Expansion
4.1 Arrays
69
as Real;
Array Functions
EMSO implements some functions specially designed for handling
arrays.
Sum
The sum function sums the elements of a vector or array. For
example, if in a mixer model we want to calculate the resulting
outlet flow rate we could use:
Outlet.F =
Inleti .F
The above equation can be obtained by the last line of the following model:
Model Mixer
PARAMETERS
Ninputs as Integer(Brief="Number of inputs");
VARIABLES
Inlet(Ninputs) as stream;
Outlet
as stream;
EQUATIONS
Outlet.F = sum(Inlet.F);
70
4 Advanced Modeling
VARIABLES
var3d(x,y,z) as Real(Brief="Three dimensional
array");
var2d(x,y)
as Real(Brief="Two dimensional
array");
EQUATIONS
var2d = sum(var3d);
var3dx,y,z
Prod
The prod function returns the productory of a vector or array.
The logic of prod is exactly the same presented above for the
sum function.
4.1.5
Loop For
Most equations involving arrays are more convenient handled by
automatic equation expansion, see subsection 4.1.3. But in some
rare situations the equation expansion cannot yield the desired
result and one or more for loops are needed.
The syntax of a for loop is the following:
EQUATIONS
for i in [1:Ncomps]
Outlet.z(i) = Inlet.z(i);
end
Note: The index i used by the for loop above does not need
to be declared and is valid only in the context of the loop.
The above equation also can be written in a more compact fashion:
EQUATIONS
Outlet.z([1:Ncomps]) = Inlet.z([1:Ncomps]);
4.2
Conditional Modeling
Under construction: needs to be documented
In this chapter, we describe how the Plugin paradigm can be used to load, at run time,
third party software within EMSO entities. In chapter 8 is explained how to implement a new
Plugin service.
Contents
5.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72
5.2
Using Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
73
72
5.1
Introduction
In this section we describe what is a Plugin and what it is good
for.
5.1.1
What is Plugin?
Plugin is an interfacing mechanism which enables the user to
load calculation services provided by third party software within
EMSO. Typical cases where using Plugins is advisable are when
the following calculations are required:
Property based on correlations
Thermo-physical properties
CFD calculations for complex geometries
5.1.2
5.1.3
73
The output of a method, as each of its inputs, can be a
scalar or a vector of Real, Integer or Boolean and
have an unit of measurement (enabling EMSO to automatic
handle the required unit of measurement conversions).
Additionally, a method can provide partial derivatives of its
output with respect to all or some of its inputs.
Each Plugin service is provided by one library file which
must be compatible with the Plugin interface specification presented in section 8.1.
5.2
Using Plugins
In this section we show how to use Plugins within some EMSO
entities.
5.2.1
1
2
3
4
5
6
7
10
11
EQUATIONS
"Liquid Enthalpy"
h = PP.LiquidEnthalpy(T, P, z);
"Liquid stream"
v = 0;
13
14
15
16
17
18
end
74
In this code, the object PP will be created using the type PP. The
available Plugin types are configured with help of the Plugins
Configuration dialog, as shown in Figure 5.1. This dialog is can
be reached by the menu ConfigPlugins.
75
c and Scilab
c communication
This chapter describes how to run the EMSO Matlab
c
c
interface inside Simulink or Scicos . This communication interface was developed by
VRTech Tecnologias Industriais Ltda (www.vrtech.com.br) for the ALSOC project. Special
thanks to Ramine Nikoukhah who helped the developers with the Scicos communication
interface.
Contents
6.1
EMSO Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77
6.2
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77
6.3
82
6.4
6.5
87
90
6.1
77
EMSO Basics
EMSO has a vast library of chemical process equipments and the
main objective of this integration is to use these models integrated
c and Scilab
c in order to use their control libraries
with Matlab
such as robust, multivariate, model predictive and non-linear control that have been developed for these software. Basically, EMSO
c by a S-function in Simulink
c block.
is integrated with Matlab
c , the integration with EMSO is made by a Scicos
c
In Scilab
block. These blocks are configured by a graphical user interface,
which set-up a text file (with the .ems extension) that will be
loaded by the Simulink/Scicos block and set-up the simulation.
c and Scilab
c interface has three components:
EMSO Matlab
The configuration graphical user interface (GUI), which reads
an EMSO file and lists flowsheets and variables and also setup a projet file to be loaded by the dynamic libraries.
c
Two dynamic library for Matlab/Simulink
c
Two dynamic library for Scilab/Scicos
6.2
6.2.1
Installation
Requisites
c is availThe communication version between EMSO and Matlab
c
able only for Windows, while the version for Scilab is available
for both Windows and Linux.
c , the user must
To use the communication interface for Matlab
have installed the Microsoft Visual C++ 2008 Redistributable
Package (can be found searching at google), that can be freely
c was tested with Matdownload from Microsoft. The Matlab
lab 7.4 using Windows XP 32 bits version with Service Pack 3
installed.
Scilab communication version was tested with Scilab GTK 4.2,
which includes the lastest stable version of Scicos. This version
is available for Windows and Linux and the communication interface was tested in these platforms. Although the latest version
of Scilab is 5.0.3, the developers of Scicos does not support new
features in this new version, so the version selected for the communication interface selected was Scilab GTK 4.2.
6.2.2
Matlab Install
There are two manners of installing the EMSO Matlab interface:
Permanent install (require administrations privileges )
78
Otherwise, the temporary installation will be automatically performed and the following message will be displayed:
Warning you have no rights to permanently change
Matlab path
You will need to run EMSOMATINSTALL again next time
Matlab is started
6.2 Installation
79
Warning you have no rights to change Matlab
permanent path
6.2.3
Scilab Installation
Warning: Remember that this version of the communication
interface is only available to Scilab Gtk 4.2
Windows Installation
Open Scilab and type in prompt:
SCIHOME
This will tell where the Scilab user files were installed. Open the
following file with your favorite text editor which is located in
SCIHOME folder:
SCIHOME\scilab.ini
If the file does not exist, create a new one with the same name
on the SCIHOME folder.
Add the following line to the end of the file:
1
emdir
= EMSODIR;
80
emdir
= EMSODIR;
where EMSODIR is the complete path where EMSO was installed.Pay attention that the EMSODIR MUST be between
.
After the successfull installation the following message will be
displayed in Scilab console and every time Scilab is loaded:
link done
ans =
0.
link done
ans =
1.
Linux Installation
Copy the file emso init.sce located at EMSODIR/interface/scilab
to the folder /home/USER/.Scilab/ScilabGtk-4.2/.
where EMSODIR is the complete path where EMSO was installed
and USER is the user name.
Edit the emso init.sce that has just been copied and add
the following line as the FIRST line of the file.
6.2 Installation
81
emdir
= EMSODIR;
emdir
= EMSODIR;
82
6.2.4
Scilab Uninstall
To remove the EMSO Scilab communication interface, remove
the lines added previously to the files edited:
For Linux:
/home/user/.Scilab/ScilabGtk-4.2/.scilab
or /usr/lib/scilab-gtk-4.2/scilab.star
for Windows:
SCIHOME\Scilab.ini
or SCILAB GTK PATH\scilab.star
6.3
83
84
85
86
c communication
6.4 Matlab/Simulink
87
6.4
c communication
Matlab/Simulink
There are two versions of the communication library between
EMSO and Matlab/Simulink: In the first one, named continuous EMSO receives the inputs and calculates the states deriva-
88
c communication
6.4 Matlab/Simulink
89
90
6.5
c communication
Scilab/Scicos
In this section, the communication between Scicos and EMSO
will be presented. The communication interface is very similar of
Matlab/Simulink.
There are two versions of the communication library between
EMSO and Scilab/Scicos: In the first one, named continuous
EMSO receives the inputs and calculates the states derivatives
and returns to Scicos, which performs the integration; In the second one, named discrete, EMSO receives the inputs and the
integration interval from Scicos, integrates the system and calculates the output and send to Scicos. For both implementations
there are a template diagram which the user can start its own
work. It is important to point-out that, depending on the block diagram configuration in Scicos, the simulation may not converge,
c communication
6.5 Scilab/Scicos
91
92
c communication
6.5 Scilab/Scicos
93
Figure 6.19: Scicos block for the continuous version of the communication interface.
The project file previously configured with the GUI, delimited with .
The number of inputs.
The number of outputs.
The number of states.
If the discrete version of the library is used, only the first three
parameters will be asked. The user can also start from an empty
diagram, in this case the block can be inserted by clicking with
the mouse right button and choose the Add new block option.
A dialog will be displayed, as presented if , where the user must
fill with emso scid, for the discrete version, or emso sci c, for the
continuous version.
Warning: The user must be sure that the blocks function and
the dll were properly loaded into Scilab otherwise the adding
of the blocks and the simulation will return an error.
94
Figure 6.20: Inserting the EMSO block into a new Scicos diagram
Instead of adding a EMSO block, the user can also add a GENERIC
block, from Others block palette, and than configure it properly.
The configuration dialog of the GENERIC block is presented in
Figure 6.21, and its done as follows:
c communication
6.5 Scilab/Scicos
95
96
In this chapter, we describe how to use EMSO together with other simulation software through
CAPE-OPEN communication. EMSO implements interfaces to access third party properties
calculations and to be accessed by other simulators, as an unit-operation block.
Contents
7.1
98
7.2
99
7.3
98
7.1
99
7.2
100
7.2.1
101
102
7.3
Call
NumberOfComponents
LiquidEnthalpy(T,P,z)
VapourEnthalpy(T,P,z)
LiquidFugacityCoefficient(T,P,z)
VapourFugacityCoefficient(T,P,z)
LiquidCp(T,P,z)
VapourCp(T,P,z)
LiquidCv(T,P,z)
VapourCv(T,P,z)
LiquidCpCv(T,P,z)
VapourCpCv(T,P,z)
LiquidEntropy(T,P,z)
VapourEntropy(T,P,z)
LiquidVolume(T,P,z)
VapourVolume(T,P,z)
LiquidCompressibilityFactor(T,P,z)
VapourCompressibilityFactor(T,P,z)
LiquidGibbsFreeEnergy(T,P,z)
VapourGibbsFreeEnergy(T,P,z)
LiquidThermalConductivity(T,P,z)
VapourThermalConductivity(T,P,z)
LiquidViscosity(T,P,z)
VapourViscosity(T,P,z)
LiquidInternalEnergy(T,P,z)
VapourInternalEnergy(T,P,z)
LiquidDensity(T,P,z)
VapourDensity(T,P,z)
103
In this chapter, we describe how to develop a new Plugin service enabling to load external
software within EMSO entities. In section 5.2 the usage of the Plugin interface was described. Note that the information presented here is not a required to use Plugins but to
develop new services.
Contents
8.1
8.2
8.3
106
8.1
Interface Specification
In order to implement a Plugin service one can use any of
the most common scientific programming languages. There are
template implementations available for C, C++ and Fortran, presented in sections 8.2.1, 8.2.2 and 8.2.3 respectively. It follows
bellow the concepts behind the Plugin interface.
Note: The information presented here is not required to use
already made Plugins but to develop new services.
A Plugin provides a set of methods, each of which receive zero
or more inputs and returns one output. In order to implement
a library which provides such service, one must implement the
following functions:
create: creates a new instance of the Plugin service
check method: checks if a specific method exists and
returns the number of inputs and outputs
method details: provides detailed information about a
specific method
set parameter: function for setting a parameter of the
object
calc: provides the calculation for a given method
destroy: destroys an object instance created with the
create function
In the following subsections these functions are detailed described.
Note that, depending on the programming langued used to actually implement the service, a prefix in the function names can
be required. For instance, when implemented in C, the create
function should be eo create. In Frotran, depending the compiler it should be eo create. For more details check subsection 8.2.1, subsection 8.2.2, or subsection 8.2.3.
8.1.1
Create Function
When a new EMSO task is started, like a dynamic simulation, for
each concrete Plugin declared, EMSO creates a new instance
of such object. In this creation procedure the create function
is called in order to load the instance specific data.
The create function has the following form:
create(objectHandler, retVal, msg)
107
where the arguments are as described in Table 8.1.
retVal
msg
[out] integer
[out] text
Description
Unique identifier of the object instance created (will be used to identify the instance in subsequent calls).
Return flag, see ??.
A text space where error messages
should be copied.
EMSO does not need to known what really happens in the create
function, but the expected behavior is:
create the memory to some data structure which holds the
instance dependent data;
if some error or warning has occurred set retVal accordingly and copy a message to the msg
return the memory address of the data structure (or an
integer which unique identifies it) in the objectHandler
As EMSO Models, a Plugin can have parameters. An example
could be the required precision to be used when calculating a
method. These parameters can be set as usuall in the Model,
for instance:
PARAMETERS
PP as Plugin(Brief="Physical Properties Object",
Type = "PP", VapourModel = "PR",
LiquidModel = "PR");
For each attribute given EMSO will make a call to the set parameter
function. The prototype of the set parameter function is as
follows:
set_parameter(objectHandler,
parameterName, valueType, valueLength,
values, valuesText,
retVal, msg)
108
Type
[in] integer
parameterName
valueType
[in] text
[in] integer
valueLength
[in] integer
values
valuesText
retVal
msg
[out] integer
[out] text
Description
Identifier of the object instance coming from the create function.
The name of the parameter to be set.
The type of the parameter (1 for
Real, 2 for Integer, 3 for
Boolean and 4 for text)
The length of the value (1 if is a
scalar)
The vector of values (empty if the
type is text)
The vector of values (empty if the
type is not text)
Return flag, see ??.
A text space where error messages
should be copied.
Destroy Function
When a Plugin instance is created the create function is
called. Then, when the object is no longer used by EMSO it
is destroyed. In some point of the destruction procedure the
destroy function is called. This function has the following
form:
destroy(objectHandler, retVal, msg)
Verification Functions
A priori, EMSO does not known what are the methods supplied
by a particular Plugin nor the number or kind of its inputs
109
Type
[in] integer
[out] integer
[out] text
retVal
msg
Description
Identifier of the object instance coming from the create function.
Return flag, see ??.
A text space where error messages
should be copied.
Type
[in] integer
methodName
methodID
[in] text
[out] integer
numOfInputs
[out] integer
numOfOutputs
[out] integer
retVal
msg
[out] integer
[out] text
Description
Identifier of the object instance coming from the create function.
Name of the method being checked.
Unique identifier for the given method
name (will be used to identify the
method in subsequent calls).
The number of expected inputs of the
method.
The number of outputs of the
method.
Return flag, see ??.
A text space where error messages
should be copied.
110
Calculation Function
Given the inputs, each Plugin method calculates one or more
outputs. This calculation is provided by the calc function. This
should be implemented by the service, it has the following form:
calc(objectHandler, methodName, methodID,
outputLength, numOfInputs, inputLengths,
totalInputLenth,
methodInputs, methodOutput,
error, warning)
111
Type
[in] integer
methodName
methodID
[in] text
[in] integer
numOfInputs
inputLengths
inputTypes
inputUnits
[in] integer
[out] integer vector
[out] integer vector
[out] text vector
numOfOutputs
[in] integer
outputLengths
outputTypes
outputUnits
hasDerivatives
[out] integer
retVal
msg
[out] integer
[out] text
Description
Identifier of the object instance coming from the create function.
Name of the method being checked.
Identifier of the method coming from
the check method function.
The number of inputs of the method.
The length of each input.
The type of each input (1 for Real, 2
for Integer and 3 for Boolean).
The unit of measurement of each input.
The number of outputs of the
method.
The length of each output.
The type of each output (1 for Real,
2 for Integer and 3 for Boolean).
The unit of measurement of each output.
If the method provides analytical
derivatives calculation
Return flag, see ??.
A text space where error messages
should be copied.
112
Type
[in] integer
methodName
methodID
[in] text
[in] integer
numOfInputs
inputLengths
totalInputLength
inputValues
numOfOutputs
outputLengths
totalOutputLength
outputValues
calculeDerivatives
outputDerivatives
[in] integer
[in] integer vector
[in] integer
[in] real vector
[in] integer
[in] integer vector
[in] integer
[out] real vector
[in] integer
[out] real vector
error
[out] text
warning
[out] text
Description
Identifier of the object instance coming from the create function.
Name of the method being checked.
Unique
identifier
of
the
method name,
coming from
check method.
The number of inputs.
The length of each input.
Total input length.
Vector containing the input values.
The number of outputs.
The length of each input.
Total output length.
Vector to put the calculated output
values.
Flag if the method should calculate
the derivatives or not.
Vector to put the calculated output
derivative values.
A text space where error messages
should be copied.
A text space where warning messages
should be copied.
113
8.2
8.2.1
8.2.2
114
8.2.3
8.3
In this chapter, we describe how to develop new solver services enabling to solve the problems
coming from the FlowSheets with custom solvers. These solvers are called external solvers
because they could be freely implemented by third parties and are implemented in a very
similar way to Plugins described in chapter 8.
Contents
9.1
9.2
9.3
9.4
116
9.1
NLA Solvers
Nonlinear-algebraic (NLA) systems arise naturally from steadystate mathematical models or in the initialization of dynamic
simulations. In order to obtain the numerical solution, EMSO
automatically converts this kind of problem into the following
formulation:
F (y) = 0, yl < y < yu
(9.1)
Residuals Function
For any point yc which is not the solution of Equation 9.1 we will
have a residual:
F (yc ) = res
(9.2)
117
EMSO can calculate the residuals vector res with the ResFn
function which has the following form:
ResFn(y, res, EMSOdata, retVal)
9.1.2
Type
[in] real
[out] real
[out] integer
Description
Vector with the current point for y
Residuals vector, will be calculated as a function of y.
EMSO problem specific data (should not be
used by the solver).
Return flag, see ??.
Jacobian
Newtons like methods can solve Equation 9.1 iteratively with
some modification of the following equation:
F n
(y y n+1 ) = F (y n )
y
(9.3)
118
Type
[out] real
[in] real
[out] integer
retVal
Description
Vector with the solution of the linear system
The independent vector b
EMSO problem specific data (should not be
used by the solver)
Return flag, see ??.
The LSolve function solves the linear system using the Jacobian
of the system. But aiming at efficiency EMSO does not updates
the Jacobian matrix each time it solves the linear system. The
solver needs to explicitly tell EMSO to update the Jacobian with
the function LSetup:
LSetup(EMSOdata, retVal)
Type
[out] integer
Description
EMSO problem specific data (should not be
used by the solver)
Return flag, see ??.
As can be seen in Table 9.3 the LSetup function does not require an input argument for y. EMSO uses the y values given at
the last call to ResFn (subsection 9.1.1), this method improve
the efficiency when calculating the Jacobian using automatic differentiation.
9.1.3
Matrix Multiplication
Some modifications of the Newton method may require addition
linear algebra operations using the Jacobian matrix. For these
cases, EMSO provides a general product function, as follows:
y = Ax + y
where A is the Jacobian matrix, and are scalars, x and y are
given vectors.
119
Note: The LProd function considers that x and y are given
vectors, therefore x or y can be the current solution point or the
current vector of residuals, it is up to the designed of the solver.
Some codes may need a simplified version of the product, y =
Ax. This is easily achieved passing equal zero to the function
LProd.
The LProd function has the following prototype:
LProd(alpha, x, beta, y, EMSOdata, retVal)
9.1.4
Type
[in] real
[in] real
[in] real
[inout] real
[out] integer
Description
Given scalar
Given vector
Given scalar
Given vector, will hold the result of the operation
EMSO problem specific data (should not be
used by the solver).
Return flag, see ??.
120
Type
[out] integer
numOfEqs
resFn
[in] integer
[in] function
y0
ylb
yub
EMSOdata
iopt
ropt
retVal
msg
Description
Unique identifier of the solver instance created
(will be used to identify the instance in subsequent calls).
The number of equations of the system.
Function that calculates the residuals of the
system.
Initial values of the variables.
Lower bound for the variables.
Upper bound for the variables.
EMSO problem specific data (only to pass back
to resFn, lsetup and lsolve)
The vector of integer options, see ??.
The vector of real options, see ??.
Return flag, see ??.
A text space where error messages should be
copied.
Type
[in] integer
[out] integer
[out] text
Description
Unique identifier of the solver instance (returned by create).
Return flag, see ??.
A text space where error messages should be
copied.
Using the given solverID the solver should release any memory
associated with that solver instance.
121
Note: When using C or C++, an easy way to implement an
unique identifier for the solver is to create an structure or class
for the solver and return its address as the identifier. Then the
solver just needs to cast back the SolverId to get the address
of the structure.
9.1.5
Solve Function
Once the solver instace has been created (as described in subsection 9.1.4), EMSO will generate a call to the solve function
each time EMSO needs to solve the problem.
The solve function has the following form:
solve(solverID, numOfEqs, resFn, lsetup, lsolve,
y, ylb, yub, EMSOdata, rtol, atol,
iopt, ropt, retVal, msg)
Type
[out] integer
numOfEqs
resFn
[in] integer
[in] function
y
ylb
yub
EMSOdata
rtol
atol
iopt
ropt
retVal
msg
Description
Unique identifier of the solver instance (returned by create).
The number of equations of the system.
Function that calculates the residuals of the
system.
Initial values of the variables and the solution
at the end.
Lower bound for the variables.
Upper bound for the variables.
EMSO problem specific data (only to pass back
to resFn, lsetup and lsolve)
The relative accuracy
The absolute accuracy (optionally a vector)
The vector of integer options, see ??.
The vector of real options, see ??.
Return flag, see ??.
A text space where error messages should be
copied.
EMSO can call multiple times the solve function before destoying it. Each time EMSO asks the solver to solve the problem a
initial guess y is given and the solution should be returned on the
same vector.
122
9.2
DAE Solvers
Differential-algebraic equations (DAE) arise naturally from dynamic modeling in several engineering areas.
Prior to a dynamic simulation, EMSO internally converts in memory the given FlowSheet description to a general DAE system
in the following form:
F (t, y, y 0 ) = 0, yl < y < yu
(9.4)
123
create: creates a new instance of the DAE external solver
for a given problem structure;
step: takes one step forward in the solution or makes an
interpolation for a desired point;
destroy: destroy the solver instance created with the
create function;
9.2.1
Type
[out] integer
numOfEqs
resFn
[in] integer
[in] function
y0
[in] real vector
y0
[in] real vector
variableIndexes [in] integer vector
EMSOdata
rtol
atol
iopt
ropt
retVal
msg
[in] integer
[in] real
[in] real
[in] integer vector
[in] real vector
[out] integer
[out] text
Description
Unique identifier of the solver instance created
(will be used to identify the instance in subsequent calls).
The number of equations of the system.
Function that calculates the residuals of the
system.
Initial values of the variables y.
Initial values of the variable derivatives y 0 .
The index of each variable (only for high index
problems).
EMSO problem specific data (only to pass back
to resFn, lsetup and lsolve)
The relative accuracy
The absolute accuracy (optionally a vector)
The vector of integer options, see ??.
The vector of real options, see ??.
Return flag, see ??.
A text space where error messages should be
copied.
124
Type
[in] integer
[out] integer
[out] text
Description
Unique identifier of the solver instance (returned by create).
Return flag, see ??.
A text space where error messages should be
copied.
Step Function
After created as described in subsection 9.1.4, each time EMSO
needs to solve the problem it will call the solve function.
The solve function has the following form:
solve(solverID, numOfEqs, resFn, lsetup, lsolve,
y, ylb, yub, EMSOdata, rtol, atol,
iopt, ropt, retVal, msg)
125
Type
[out] integer
numOfEqs
resFn
[in] integer
[in] function
[inout] real vector
y
ylb
yub
EMSOdata
rtol
atol
iopt
ropt
retVal
msg
Description
Unique identifier of the solver instance (returned by create).
The number of equations of the system.
Function that calculates the residuals of the
system.
Initial values of the variables and the solution
at the end.
Lower bound for the variables.
Upper bound for the variables.
EMSO problem specific data (only to pass back
to resFn, lsetup and lsolve)
The relative accuracy
The absolute accuracy (optionally a vector)
The vector of integer options, see ??.
The vector of real options, see ??.
Return flag, see ??.
A text space where error messages should be
copied.
9.3
9.3.1
126
9.3.2
9.3.3
9.4