Professional Documents
Culture Documents
Modeling Language
Reference
Version 11.1
September 2001
Copyright 2001 by Aspen Technology, Inc. All rights reserved.
AspenTech product names that are mentioned in this manual, e.g., Aspen Custom Modeler™, Aspen Dynamics™,
Plantelligence and Enterprise Optimization and the aspen leaf logo are trademarks or registered trademarks of Aspen
Technology, Inc., Cambridge, MA.
All other brand and product names are trademarks or registered trademarks of their respective companies.
This manual is intended as a guide to using AspenTech's software. This documentation contains AspenTech
proprietary and confidential information and may not be disclosed, used, or copied without the prior consent of
AspenTech or as set forth in the applicable license agreement. Users are solely responsible for the proper use of the
software and the application of the results obtained.
Although AspenTech has tested the software and reviewed the documentation, the sole warranty for the software may
be found in the applicable license agreement between AspenTech and the user. ASPENTECH MAKES NO
WARRANTY OR REPRESENTATION, EITHER EXPRESSED OR IMPLIED, WITH RESPECT TO THIS
DOCUMENTATION, ITS QUALITY, PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR A
PARTICULAR PURPOSE.
Corporate
Aspen Technology, Inc.
Ten Canal Park
Cambridge, MA 02141-2201
USA
Phone: (1) (617) 949-1000
Toll Free: (1) (888) 996-7001
Fax: (1) (617) 949-1030
URL: http://www.aspentech.com/
Division
Design, Simulation and Optimization
AspenTech Ltd.
Sheraton House
Castle Park
Cambridge CB3 0AX
United Kingdom
Phone: +44 (0) 1223 819700
Fax: +44 (0) 1223 366980
URL: http://www.aspentech.com/
Contents
Introduction v
About This Manual.............................................................................................................. v
What You Need To Use This Manual ................................................................................. v
Associated Manuals............................................................................................................ vi
For More Information........................................................................................................ vii
Online Help ........................................................................................................... vii
Printing Portable Document Format Files (PDFs) ................................................ vii
World Wide Web .................................................................................................viii
Technical Support ................................................................................................viii
Index
Phone Numbers
: Value assignments
= Equation assignments
AS Declaration assignments
CONNECT AND Connection assignments
LINK AND Link assignments
Statement Examples
All the following examples are statements and must end with ;
(semi-colon), as shown.
The following example assigns a value to the message output level:
PRINTLEVEL: 2 ;
The following example assigns a value to a variable and states that
the variable is known:
Feed.Temperature: 75.0, Fixed ;
The following example equates two variables in a model:
FlowIn = FlowOut ;
The following example creates an instance of a model in a
flowsheet, or in a model description:
FeedValve AS Valve ;
The following example makes a connection of an input to a
flowsheet terminator:
CONNECT FeedValve.Input1 ;
The following example makes a connection between the input and
output of two blocks:
CONNECT Pump1.Output1 AND Valve2.Input1 ;
The following example makes a connection between the port of a
sub-model and the port of the containing model:
LINK Tank5.Output1 AND MultiOutput1 ;
TypeKeyword Identifier
CLASS ClassString
USES TypeName
ROLE RoleString
DefinitionBody
END
VARIABLE Temperature
Value : 1.0 ;
Upper : 300.0 ;
Lower : -40.0 ;
Spec : Free;
Scale : 10.0 ;
Description : "Temperature in Celsius";
PhysicalQuantity : "Temperature";
END
Declaration Statements
A declaration introduces a property by giving it a name and
describing its type. The syntax for all declarations has the
following form:
MODEL Heater
T AS Temperature;
T.Value : 100.0;
END
The line T as Temperature; is called a declaration. A declaration
is used to add properties to types. In this example a variable T is
added to the model type Heater. The variable T has the properties
of the variable type Temperature, for example, Value, Upper,
Lower, and so on. These properties can then be modified. The
property value has the real number 100.0 assigned to it in this
example.
Assignments
Assignments that involve expressions are treated as constraints by
the compiler. This means that if an expression occurs on the right
side of an assignment then that expression is re-evaluated
whenever the value of any term within it changes. The result is
then assigned to the property on the left side.
Assignment Syntax
The modeling language uses : (a colon) as its assignment operator:
Object.Property : PropertyValue;...
x : 5.0;
The following examples specify the numerical values for the
properties Lower and Upper, for the variable, x:
x.Lower : -10;
x.Upper : 20;
The following example specifies that the string "Cylinder" is
assigned to the property, Value, of the parameter Geometry:
Geometry : "Cylinder";
The following example specifies that the logical True is assigned to
the property, Value, of the parameter, PressureDriven:
PressureDriven : True;
The following example assigns to the property, Value, an
expression, 5/60, for the variable, Lag:
Lag : 5/60;
For further examples of assignments, see Defining Specifications
in Models Examples and Defining Specifications in Flowsheets
Examples.
ArrayVariable(Index) : Value ;
Components AS
StringSet(["H2O","H2+","Zn++","Ca++"]);
mw(Components) AS MoleWeight;
mw("H2O"):18;
mw("Ca++"):40.1;
Note The name Components is defined as a set. Therefore, when
you use this name, you do not need to use the [ ] characters to
define the set. Also, when you want to refer to individual elements
of the set, you do not need to use the [ ] characters.
You need to use [ ] to define a set only when you use a list of set
elements.
For example, the array variable mw in the above example could
have been defined:
mw(["H2O","H2+","Zn++","Ca++"]) AS MoleWeight;
WITHIN BlockName.VariableName
PropertyAssignmentList
ENDWITH
WITHIN Tank.Q
Value : 25.0 ;
Spec : FIXED ;
Lower : 0.0 ;
Upper : 100.0;
ENDWITH
Alternatively, you can type each specification explicitly:
Tank.Q.Value : 25.0 ;
Tank.Q.Spec : FIXED ;
Tank.Q.Lower : 0.0 ;
Tank.Q.Upper : 100.0;
Naming Conventions
You use names when you:
• Define a type
• Add a property to a type
Important Do not create a type which has the same name as a
built-in type. This can have undesirable results.
Because you use names to identify objects from external programs
such as Microsoft® Visual Basic® or Microsoft Excel, you should
apply the naming rules for Visual Basic.
Make sure that the names you choose:
• Conform to the rules imposed by the external programs
• Are unique, because each name identifies a particular object
• Include only characters from a restricted set. The set is all
the alphanumeric characters plus the _ (underscore)
character.
• Start with an alphabetic character, not a numeric one
• Do not begin with am_
BLOCKS("BlockName").VariableName
STREAM Syntax
STREAMS("StreamName").VariableName
Blocks("B1") AS Heater;
Streams("B1") AS MaterialStream;
BLOCKS("B1").Temperature =
STREAMS("B1").Temperature;
BLOCK and STREAM are reserved words and cannot be used to
name definitions.
Parameters Syntax
Parameters Remarks
The distinction between variables and parameters is that variables
are solved for by the solution routines, whereas parameters control
which variables and equations define a particular instance of a
model. Like variables, parameters are declared within types and
they can be treated as properties of instances of types in the same
way as variables.
Parameters may be of type INTEGERPARAMETER,
STRINGPARAMETER, LOGICALPARAMETER,
REALPARAMETER. These four types are built in to the language.
In addition, you can refine these parameter types by defining new
parameter types that inherit properties from these built-in
parameter types. To define new parameter types, use the
PARAMETER keyword. Use inheritance to ensure that the new
type is derived from one of the built-in parameter types.
You can test parameters in the condition part of IF ... ENDIF
statements to define structural variations within models.
MODEL Column
NStages AS IntegerParameter(10);
Stages([1:NStages]) AS Tray;
.
.
.
END
FLOWSHEET
C101 AS Column(NStages:20);
END
Sets
You can define sets to create array variables, control the operation
of FOR loops, define component lists, and build flexible models. A
set is a collection of objects that has no duplicate values and is not
in any specific order. Aspen Custom Modeler™ uses sets in the
same way as a mathematical set. To manipulate sets in Aspen
Custom Modeler, you use set functions, such as union, intersection,
and difference.
Arrays are indexed by the contents of a set. For information on
arrays, see Arrays.
Sets Syntax
Sets Examples
In the following example, the set MySet is defined as containing
objects that are of integer values. The contents of the set are not yet
defined.
MySet AS IntegerSet;
In the second example, MySet is defined as containing integer
objects. However, the set is immediately defined as an empty set.
This set has no contents:
MySet AS IntegerSet( [] ) ;
In the third example, MySet contains four integer objects of the
value 1, 2, 3, and 4:
MySet AS IntegerSet( [ 1, 2, 3, 4 ] ) ;
The fourth example shows the same definition of MySet as the
previous example, but uses : (a colon) to define the contents as all
integers from 1 to 4:
MySet AS IntegerSet( [1:4] ) ;
In the fifth example, MySet contains the same values as the
previous example, but not in the same order:
MySet AS IntegerSet( [ 1, 3, 2, 4 ] ) ;
In the last example, MySet is defined as a set containing the strings
"Yes" and "No":
MySet AS StringSet( [ "Yes", "No" ] ) ;
DIFFERENCE Note
The DIFFERENCE of two sets is the set of elements in the first set
but not in the second set.
INTERSECTION Note
The INTERSECTION of two s~ets is the set of elements that are
common to both s~ets.
SYMDIFF Note
The SYMDIFF of two s~ets is the set of the elements that are in
one set but not in the other. This can be defined as the difference
between the union and the intersection of the two s~ets.
Arrays Remarks
Because an array is defined by a set, the index of the array may not
take consecutive integer values. You can define an array that is
indexed by an integer set that has some of the integer numbers
“missing”. This is useful for modeling trays in a distillation
column, where you may want to use a different model for a feed
tray, for example.
As arrays can be indexed by a string of text, you can define an
array indexed by component names. For more information, see
Chapter 3, Using the ComponentList Property.
Arrays Examples
The following line defines an array variable. The variable
SectionTemp is indexed explicitly as having integer elements from
1 to 10:
SectionTemp( [1:10] ) AS Temperature ;
The variable FeedMolFrac is indexed to the set called
Components, which contains three string elements:
Components AS StringSet(["N2", "O2", "CO2"])
FeedMolFrac( Components ) AS MolFraction ;
The variable SectionMolFrac is defined as a two dimensional
array. The first dimension is defined as the set Components and the
second dimension is explicitly stated as integer elements from
1 to 10:
SectionMolFrac ( Components,[ 1: 10 ] ) AS
MolFraction ;
MODEL Column
NTrays AS IntegerParameter(10);
NFeedTray AS IntegerParameter(5);
task MyTask
s2 as StringParameter;
s2 : CONVERTTO(string, v); // where V is a
variable accessible to the task
print "variable v is "+s2;
//print CONVERTTO(string, v); // Note that
CONVERTTO cannot be used directly in a print
statement.
end
Inheritance Remarks
Inheritance enables you to extend a type definition by adding extra
properties to the type definition. Inheritance enables you to refine
the definition only by changing the default values of existing
properties. However, you cannot change the types of inherited
properties in a derived type.
All types are defined by inheritance. If you define a type using
inheritance, the type inherits all the properties of the type from
which it inherits. If you define a type without using inheritance, the
compiler defines a default inheritance relationship for that type.
For each type that you can define, you inherit properties from a
built-in type.
Note Icons are not inherited between models.
Inheritance Example
In the following example, the variable definition ColdTemp
inherits all the properties and defaults from the variable definition
Temperature, but it overrides the default value for the property
UPPER. Because UPPER is not declared within the ColdTemp, it
must have been declared within Temperature or within a definition
from which Temperature is derived.
Type Relatives
The inheritance relationship enables you to define a family of
related types that can be substituted for each other.
For example, in a procedure definition, you list the types of the
input and output variables expected in a procedure call. Using
inheritance, you can define new variables that inherit properties
from the type you have named in the procedure call argument list.
You can use these new variable types in the same procedure,
because they are recognized as descendants of the variable types
you named in the procedure call list.
You can use related types to determine which ports can be
connected, using custom streams. You cannot connect instances of
different port types, unless the two port types are related types. One
of the port types must be related to the other port type through
inheritance. If you use the built-in Connection stream, any two
ports can be connected. In this case, variables in the ports being
connected are matched by name.
PORT Material
Flow AS Flow_Vol_Liq;
END
PORT NewMaterial USES Material
Temp AS Temperature;
END
MODEL Tank1
.
Out1 AS OUTPUT NewMaterial;
.
END
MODEL Tank2
.
In1 AS INPUT Material;
.
END
STREAM MaterialStream;
In1 AS InputMaterial;
Out AS OutputMaterial;
In1.Flow = Out.Flow;
END
FLOWSHEET
S1 AS MaterialStream;
T1 AS Tank1;
T2 AS Tank2;
CONNECT T1.Out1 AND T2.In1 WITH s1;
END
The port Material carries flow rate, and the port NewMaterial
carries flow rate and temperature values. The two ports can be
connected, as they are related by inheritance. However, the
temperature value carried from the first tank T1 is not passed to the
second tank T2.
PROCEDURE TotalMassCalc
.
.
INPUTS : Area, Length, LiquidDensity;
OUTPUTS : Mass;
END
MODEL Tank
TankArea AS Area ;
TankHeight AS Length ;
RhoLiq AS LiquidDensity ;
RhoVap AS VaporDensity ;
TotalMass AS Mass ;
Phase AS PhaseParameter("Liquid");
END
PARAMETER StringParameter
Description AS String("");
Value AS String("");
END
PARAMETER IntegerParameter
Description AS String("");
Value AS Integer(0);
Upper AS Integer(32767);
Lower AS Integer(-32767);
END
PARAMETER RealParameter
Description AS String("");
Value AS Real(0.0);
Upper AS Real(1.0e37);
Lower AS Real(-1.0e37);
PhysicalQuantity AS String("");
Tag AS String;
END
PARAMETER LogicalParameter
Description AS String("");
Value AS Logical("TRUE");
END
VARIABLE RealVariable
Value AS Real(1.0);
Upper AS Real(1.0e37);
Lower AS Real(-1.0e37);
Scale AS Real(1.0);
Derivative AS Real;
IsConnected AS Logical("FALSE");
IsMatched AS Boolean;
Description AS String("");
PhysicalQuantity AS String("");
Units AS String;
ULagrange AS Real;
LLagrange AS Real;
Spec AS SpecType("FREE");
Tag AS String;
Record AS Boolean;
END
MODEL GenericModel
Description AS String("");
Default_Form AS String("");
Current_Icon AS String("");
InputSignal AS INPUT ControlPort;
OutputSignal AS OUTPUT ControlPort;
ComponentList AS ComponentListName("Default");
END
STREAM GenericStream
Description AS String("");
Default_Form AS String("AllVariables");
Current_Icon AS String("System");
InputSignal AS INPUT ControlPort;
OutputSignal AS OUTPUT ControlPort;
ComponentList AS ComponentListName("Default");
END
STREAM GenericConnection
Description AS String("");
Default_Form AS String("AllVariables");
Current_Icon AS String("System");
Source AS INPUT ConnectionPort;
Dest AS OUTPUT ConnnectionPort;
END
PORT GenericPort
Description as String("");
IsConnected AS LogicalParameter("FALSE");
ComponentList AS ComponentListName("Default");
END
PORT ControlPort
Description AS String("");
IsConnected AS LogicalParameter("FALSE");
END
PORT ConnectionPort
Description AS String("");
IsConnected AS LogicalParameter("FALSE");
Direction AS Integer(0);
END
SlackVariable Type
The built-in type SlackVariable represents variables that can be
applied as constraints to other variables and expressions. The lower
bound of SlackVariable is zero and so slack values in an
expression can never become negative.
The syntax for the built-in slack variable type is:
VARIABLE SlackVariable
Value AS Real(1.0);
Description AS String("");
LLagrange AS Real;
Tag AS String;
END
PhysicalQuantity : "PhysQuanName";
The following example shows how the physical quantity for the
variable type Temperature is assigned "Temperature".
DIM xUom
SET xUom = ActiveDocument.uom
xUom ................................ A Visual Basic variable. You can choose to call this
variable whatever you want.
ActiveDocument .............. The current simulation path in the automation
interface
ActiveDocument is equivalent to the path Application.Simulation,
so alternatively you could write:
DIM xUom
SET xUom = Application.Simulation.uom
AnyVar = xUom.AddPhysicalQuantity("PhysicalQuantityName",
"BaseUnitSymbol", AspenPlusQuantity, AspenPlusUnit)
AnyVar = xUom.DefineConversion("PhysicalQuantityName",
"UomSymbol", Multiplier, Offset)
xUom.SelectUomSet("UomSetName")
OPTIONS
CurrentUomSet : "UomSetName";
.
END
and
MODEL
VariableName1 AS VariableType1;
VariableName2 AS VariableType2 (..., UseUOMOf
:"VariableName1");
END
MODEL PI_Controller
.
Pv AS INPUT Control_Signal;
PvMin AS Control_Signal (Fixed, UseUOMOf : "Pv");
PvMax AS Control_Signal (Fixed, UseUOMOf : "Pv");
.
END
In this example, if a variable of type Temperature is connected to
the input control variable Pv with the built-in ControlSignal stream
type, the variables Pv, PvMin and PvMax are all displayed with the
same units as the variable of type Temperature.
BlockName.VariableName.Value("UOMName")
VariableName.Value("UOMName")
Application.PrintToMessageWindow "Temperature in
base units is " + B1.Out1.Temp("BaseUnits")
Application.PrintToMessageWindow "Temperature in
current units is " + B1.Out1.Temp("CurrentUnits")
Application.PrintToMessageWindow "Temperature in
Celsius is " + B1.Out1.Temp("C")
Application.PrintToMessageWindow "Temperature in
Fahrenheit is " + B1.Out1.Temp("F")
If the BaseUOMSet is metric and the CurrentUOMSet is US units,
the output from the script is:
ratio*input2 = input1;
prod = input1*input2;
End
Notes
• Input1 is declared as using the UOM of input2, and vice
versa. This is allowed so that whichever of input1 or input2
is connected the appropriate units will come from that
connection.
• The 'ratio' variable is declared as using the UOM of input1
divided by input2. If, for example, input1 is connected to a
temperature variable displaying in Fahrenheit and input2 to
a length variable displaying in feet, the display units of
measurement will be Fahrenheit/ft. Note that in this case the
conversion for display units to base units (Centigrade/meter)
will not include the offset between Fahrenheit and
Centigrade: only the scaling is applied.
• The 'prod' variable is handled in a similar way to the ratio
variable except in this case a "*" is used to reflect the
multiplication operation.
Model RatioBlock
input1 as input RealVariable(fixed);
input2 as input RealVariable(fixed);
End
In this example, if the 'diff' variable was simply declared to use the
UOM of input1 then when converting to display units, the
conversion offset would be inappropriately applied (for example, a
zero Centigrade temperature difference would be converted to 32.0
in Fahrenheit). To ensure that only the scale is applied, this
example uses the "ScaleOf:" qualifier before the name of the
variable.
Event Example
The allowable comparison operators are >=, >, ==, <, <=, <>.
For time expressions you can use only >=, > or = =.
<> means not equal to.
In the second example, the inlet flow is set to 3.0 when the level is
below 0.01. This can happen at any time in the simulation. In the
first example, the inlet flow can only be set to 3.0 after the time
conditional has been met.
TASK test2A RUNS WHEN TIME == 5.0
Input1.Flow : 0.0;
END
TASK test2B RUNS WHEN Level <= 0.01
Input1.Flow : 3.0;
END
TaskName ........................ The name of the task. The name must be unique in
the scope in which the task is defined.
ParameterList .................. An optional list of the parameters passed to this
task from the expression that calls the task.
TaskStatements............... The task statements that are executed when the
task is run.
Use a CALL statement to call another task.
TASK SubTaskA
Input1.Flow : 4.0;
END
TASK SubTaskB
Input1.Flow : 1.0;
END
TASK Test RUNS WHEN Time == 1.0
Input1.Flow : 5.0;
WAIT FOR Level >= 3.0;
CALL SubTaskB;
WAIT FOR Level <= 0.4;
CALL SubTaskA;
END
Flowin.flow: 10.0;
Flowin.temp: 50.0;
END
Suspending and You can suspend the execution of a task until a particular condition
Restarting a Task is met. You can use the following statements to suspend a task:
Statement Use
WAIT real-expression;
real-expression................ The number of time units for which to wait (that is, a
relative time)
SnapshotName ................ The name of the snapshot that appears with the
automatically generated snapshot contained in the
snapshot file
PARALLEL
CALL Task1;
CALL Task2;
.
.
CALL Taskn;
ENDPARALLEL;
TASK P1
RAMP(Input1.Flow, 2.5, 4.0);
END
TASK P2
RAMP(Input2.Flow, 0.5, 5.0);
END
TASK P3
RAMP(Input3.Flow, 5.5, 3.0);
END
TASK Task1 RUNS WHEN TIME == 1.25
PARALLEL
CALL P1;
CALL P2;
CALL P3;
ENDPARALLEL;
Input4.Flow : 0.0;
END
All three Ramps start at time 1.25. The last task to finish is Task
P2, which completes at 6.25, at which time the flow rate of input4
changes to 0.0 instantaneously.
PRINT Statements in You can print a message from a task to the Simulation Messages
Tasks window.
PRINT Syntax
task MyTask
s2 as StringParameter;
s2 : CONVERTTO(string, v); // where V is a
variable accessible to the task
print "variable v is "+s2;
//print CONVERTTO(string, v);// Note that
CONVERTTO cannot be used directly in a print
statement.
end
Pausing a Simulation You can use a PAUSE statements to suspend a simulation.
from a Task PAUSE Syntax
The syntax for suspending a simulation is:
PAUSE;
invoke ScriptName;
This searches for the script in the Scripts folder under Custom
Modeling.
This searches for the script in the Scripts folder in the library called
MyLibrary. This library must be Open (attached) for the current
simulation.
Application.Simulation.AddEstimateVariable
“BlockName.VariableName”
BlockName....................... The name of the block containing the variable you are
estimating
VariableName .................. The name of the variable you are estimating
You can define a number of different variables to estimate in an
estimation simulation.
Note Estimated variables can be Fixed or Initial.
Application.Simulation.AddEstimateVariable
"Reactor1.RK1"
Application.Simulation.AddEstimateVariable
"Reactor1.RK2"
Defining Steady-State For information on how to use the Estimation dialog box to define
Estimation steady-state Estimation experiments (which is the recommended
Experiments method), see the online Help on running Estimation simulations.
You can also use Microsoft® Visual Basic® automation methods
to define steady-state experiments for an estimation simulation. For
each experiment you must give an experiment name and define the
experiment as steady-state. You must also add measurement points
for the experiment, using the following syntax. You can also make
changes to the value of fixed variables for each experiment.
DIM ThisExp
SET ThisExp = Application.Simulation.NewExperiment (
"ExperimentName", "Steady State" )
ThisExp.AddSSMeasurePoint "BlockName.VariableName",
MeasuredValue, MeasurementWeight
.
ThisExp.AddFixedPoint "BlockName.VariableName", FixedValue
.
ThisExp.SetWeight ExperimentWeight
Application.Simulation.AddExperiment(ThisExp)
SET SSExpt1 =
Application.Simulation.NewExperiment("Experiment1
","Steady State")
SSExpt1.AddFixedPoint
"Reactor1.In1.Flow(""ReagentA"")", 1.0
SSExpt1.AddFixedPoint
"Reactor1.In1.Flow(""ReagentB"")", 9.0
SSExpt1.AddSSMeasurePoint
"Reactor1.Out1.x(""ReagentA"")", 0.092, 1.0
SSExpt1.AddSSMeasurePoint
"Reactor1.Out1.x(""ReagentB"")", 0.904, 1.0
SSExpt1.SetWeight 1.0
SET SSExpt2 =
Application.Simulation.NewExperiment("Experiment2
","Steady State")
SSExpt2.AddFixedPoint
"Reactor1.In1.Flow(""ReagentA"")", 2.0
SSExpt2.AddFixedPoint
"Reactor1.In1.Flow(""ReagentB"")", 8.0
SSExpt2.AddSSMeasurePoint
"Reactor1.Out1.x(""ReagentA"")", 0.179, 1.0
SSExpt2.AddSSMeasurePoint
"Reactor1.Out1.x(""ReagentB"")", 0.808, 1.0
SSExpt2.SetWeight 1.0
Application.Simulation.AddExperiment(SSExpt1)
Application.Simulation.AddExperiment(SSExpt2)
Defining Dynamic For information on how to use the Estimation dialog box to define
Estimation dynamic Estimation experiments (which is the recommended
Experiments method), see the online Help on running Estimation simulations.
You can also use Microsoft® Visual Basic® automation methods
to define dynamic experiments for an estimation simulation. For
each experiment, you must give an experiment name and define the
experiment as dynamic. You must also add measurement values for
the experiment at time points during the experiment. You can add
initial conditions for the derivatives or state variables, and change
the value of fixed variables for each experiment.
DIM ThisExp
SET ThisExp = Application.Simulation.NewExperiment (
"ExperimentName", "Dynamic" )
ThisExp.AddDynMeasurePoint "BlockName.VariableName",
MeasurementTime, MeasuredValue, MeasurementWeight
.
ThisExp.AddFixedPoint "BlockName.VariableName", FixedValue
.
ThisExp.AddInitialPoint "BlockName.VariableName", InitialValue
.
ThisExp.AddRateInitialPoint "BlockName.VariableName",
RateInitialValue
.
ThisExp.SetWeight ExperimentWeight
Application.Simulation.AddExperiment(ThisExp)
SET DynExpt2 =
Application.Simulation.NewExperiment("DynamicExpe
riment1","Dynamic")
DynExpt2.AddInitialPoint
"Reactor1.x(""CH3OH"")", 0.009
DynExpt2.AddFixedPoint "Reactor1.Temp", 200.0
DynExpt2.AddFixedPoint "Reactor1.Press", 12.5
DynExpt2.AddDynMeasurePoint "Reactor1.
x(""CH3OH"")", 0.1667, 0.008, 1.0
DynExpt2.AddDynMeasurePoint "Reactor1.
x(""CH3OH"")", 0.3333, 0.015, 1.0
DynExpt2.AddDynMeasurePoint "Reactor1.
x(""CH3OH"")", 0.5000, 0.029, 1.0
Application.Simulation.AddExperiment(DynExpt1)
Application.Simulation.AddExperiment(DynExpt2)
Application.Simulation.ResetEstimation
Application.Simulation.ResetEstimation
Application.Simulation.AddExperiment(SSExpt1)
EstimatedValue("EstVar1")
Deviation ("EstVar1")
DeviationArrayPresent
Application.Simulation.Correlation("EstVar1", "EstVar2")
Dim Corr
SET Corr =
Application.Simulation.Correlation("Reactor.K1",
"Reactor.K2")
Application.PrintToMessageWindow "Correlation
between K1 and K2 is " & Cstr(Corr)
Application.Simulation.CorrelationMatrix
CorrelationMatrixPresent
Dim Corr
IF Application.Simulation.CorrelationMatrix Present = True THEN
Corr = Application.Simulation.Correlation Matrix
ELSE
Application.PrintToMessageWindow "WARNING : Correlation Matrix
Not Present"
END IF
OPTIMIZATION
IsDynamic : TRUE|FALSE;
ElementSizeBoundsAutomatic : TRUE|FALSE;
TimeBoundsAutomatic : TRUE|FALSE;
EndTime : TimeValue;
VariableName : Objective;
VariableName : Control;
VariableName : Initial;
VariableName : Design;
Control.FinalTime_Upper : double value;
Control.FinalTime_Lower : double value;
Control.FinalTime_IsFixed : TRUE | FALSE;
Control.FinalTime_IsObjective : TRUE | FALSE;
Control.Elements : int value;
Control.FixedInterval : TRUE | FALSE;
Control.PiecewiseLinear : TRUE | FALSE;
Control.MaxInterval : double value;
Control.MinInterval : double value;
Control(index) : double value;
.
.
Control(index).VariableName : double disvalue ;.
Control.MaxMove.VariableName : double maxvalue, TRUE |
FALSE ;
End
Optimization
IsDynamic : TRUE;
ElementSizeBoundsAutomatic : TRUE;
TimeBoundsAutomatic : TRUE;
EndTime : 1;
Control.FinalTime_Upper : 2;
Control.FinalTime_Lower : 0.5;
Control.FinalTime_IsFixed : TRUE;
Control.FinalTime_IsObjective : FALSE;
Control.Elements : 10;
Control.FixedInterval : TRUE;
Control.PiecewiseLinear : FALSE;
Control.MaxInterval : 0.2;
Control.MinInterval : 0.001;
Control(0) : 0.1 ;
Control(1) : 0.1 ;
Control(2) : 0.1 ;
Control(3) : 0.1 ;
Control(4) : 0.1 ;
Control(5) : 0.1 ;
Control(6) : 0.1 ;
Control(7) : 0.1 ;
Control(8) : 0.1 ;
Control(9) : 0.1 ;
b1.u : control;
Control(0).b1.u : 1;
Control(1).b1.u : 1;
Control(2).b1.u : 1;
Control(3).b1.u : 1;
Control(4).b1.u : 1;
Control(5).b1.u : 1;
Control(6).b1.u : 1;
Control(7).b1.u : 1;
Control(8).b1.u : 1;
Control(9).b1.u : 1;
b1.y2 : objective;
Control.MaxMove.b1.u : 0,FALSE;
End
A AS RealVariable;
B AS RealVariable;
Slack1 AS SlackVariable;
Slack1 + A = B;
PURGE.X1("Methanol") <=
MAX_EFFLUENT_CONCENTRATION;
MEREACTOR.TEMP >= MIN_TEMPERATURE;
MEREACTOR.TEMP <= MAX_TEMPERATURE;
MEREACTOR.PRESSURE >= MIN_PRESSURE;
MEREACTOR.PRESSURE <= MAX_PRESSURE;
Homotopy
BlockName.VariableName: TargetValue;
.
.
Enabled: TRUE|FALSE;
End
Homotopy
FEEDERMB.TOTAL: 12000;
MEREACTOR.PRESSURE: 130;
MEREACTOR.TEMP: 480;
Enabled: FALSE;
End
VARIABLE Syntax
If you do not specify a parent variable type, as shown in the
following syntax, the built-in variable type RealVariable is used.
For information on RealVariable, see Chapter 1.
VARIABLE VariableName
Property : PropertyValue;...
END
PORT Syntax
PORT Remarks
You can make the port type inherit the properties of a previously
defined port with the keyword USES. You can then add additional
variable types to the existing definition so that more information is
passed by the new port.
If you do not specify a parent port type, the built-in port type,
GenericPort, is used. For information on GenericPort, see
Chapter 1.
PORT Examples
The following examples show definitions of port type, including
inheritance. The first example defines a Port called Material, which
contains an empty variable type list, and so has limited usage:
PORT Material END
The second example definition is equivalent to the previous
example:
PORT Material USES GenericPort END
The following example shows the port type Material defined to
communicate a molar flow rate and a temperature:
PORT Material
Flow AS MolFlow;
Temp AS Temperature;
END
MODEL Syntax
MODEL Remarks
You can include statements in the model description to define
different aspects of the model. Models do not need to contain
specific elements. For example, you can define a model with no
ports and use inheritance to define different models with different
port configurations.
You can add the following statements to your model definition:
• Parameters
• Sets
• Variables
• Ports
• Equations
• Procedure calls
• Sub-models (instances of other models)
• Sub-model connections
• Forms and icons associated with this model
MODEL Example
The following example shows a complete description of a gravity
flow tank:
MODEL TANK
/* Define variables for this model’s equations */
Vol AS Volume;
K AS Constant;
H AS Length;
XSArea AS Area;
/* Set up an inlet and an outlet port of port type Fluid */
In1 AS INPUT Fluid;
Out1 AS OUTPUT Fluid;
/* Equations using internal and port variables */
/* Input - Output = Accumulation */
$Vol = In1.Flow - Out1.Flow ;
/* Flow out proportional to the square root of the fluid
height */
Out1.flow * Out1.flow = K^2 * H ;
/* Cylindrical geometry tank */
Vol = H * XSArea;
/* The tank is fully described */
END
STREAM Syntax
The syntax for a stream type is exactly the same as a model type:
STREAM Remarks
There are some restrictions to the STREAM syntax compared to
the MODEL syntax:
• You must define at least one port, but not more than two
ports. Most streams connect two blocks together, and
therefore need two ports.
• The two ports must be INPUT or OUTPUT. The direction of
the stream depends on the direction values of the stream
ports and the block ports to which the streams are
connected.
• If the stream definition has one port only, this port must be a
feed or product stream. Again, the direction of the stream
ports or the block ports to which the stream is attached
determines the stream orientation.
Stream types are optional. You can make connections between
blocks using a built-in stream type called Connection.
You can mark the stream as PRIVATE. This means that if the
stream is used in a library, the user of the library cannot:
• Display the stream in the Simulation Explorer view
• Export the stream with a Save
• See the stream equations and variable names in a Diagnostic
view
MODEL Heater
Input AS myVBheaterform;
.
.
END
A type called myVBHeaterForm is defined. An external type has a
class and a role. The class tells the compiler the object that
implements this type. The role tells the compiler the role that an
instance of the type plays in the problem. The compiler uses this
information to build the external object into the system and to
create instances of it.
If any text is associated with the external type, it appears between
the TEXT and ENDTEXT keywords. This text may contain data
that needs to be loaded when the compiler creates the type.
In the model Heater, a declaration gives the model a form. In this
example, the form is called Input.
PROPERTIES
WorkingDirectory : "value"
RunID : "value"
ComponentListDeclarations
Assignments
END
The
Name as ComponentList;
The
Name................................. The name of the component list
Assignments.................... A list of assignments to the declared component lists
and to the built-in properties of the Properties type
RunID................................ The file containing the physical properties information
WorkingDirectory ............ The full path to the RunID file
Caution If the path includes a specific drive letter,
ensure that any mapped drives are consistent with the
path. If you share properties files between many servers,
it is advisable always to map the the same drive letter on
all servers.
PROPERTIES
ComponentListDeclarations (IsComponentSet : value);
Assignments
END
ComponentList
Declarations..................... A list of declarations of component lists of the form:
The
Name as ComponentList;
Name................................. The name of the component list
The
Utility.components : ["Water"];
Process.components :
["Methanol","Ethanol","Water"];
Process.option("OPSET") : "Sysop12";
Process.option("KBASE") : "1";
end
In this example, the Utility component list has a single component,
water. No options are specified so the defaults defined by the
implementation of the physical properties system interface will be
used. The second component list, Process, has three components:
methanol, ethanol, and water. The default values for the calculation
options OPSET and KBASE are overridden for this list.
Validating When you open an input file, the component names, option names,
Component Lists and option values are validated against the physical properties
system you have specified. To specify the physical properties
system to be used, you supply values for the WorkingDirectory and
RunID properties in the properties definition.
If the validation fails, the load operation continues using the valid
data. Invalid data is ignored but warnings are given.
If the location of the files used to perform the validation is invalid,
the component list data is loaded, but it will be validated when
physical property data is next successfully loaded. If any data is
invalid at this point, invalid data is deleted and warnings are
generated.
Using the A block, stream or port has a built-in property called
ComponentList ComponentList. You can use ComponentList to define arrays
Property indexed over the set of components defined in a component list.
ComponentList Remarks
You can globally assign a value to the property ComponentList in
the LocalVariables table for the flowsheet. This value will be a
component list you have defined yourself in a properties definition.
For information on defining physical properties types, see Defining
Physical Properties Types on page 3-11.
ComponentList Example
The following is an example of a model that uses the process
component list declared in the Properties definition given in the
Defining Properties Example on page 3-13.
PROCEDURE pEnth_Mol
WORKSPACE : 10;
CALL : "gpi2ex";
LIBRARY : "sai";
IMPLEMENTATION : "SUBROUTINE";
LANGUAGE : "FORTRAN";
OPTIONS : PROPERTIES;
INPUTS:
Temperature,
Pressure,
Molefraction(*);
OUTPUTS:
/* returns molar enthalpy for non-specified-phase stream
*/
Enth_Mol;
END
MODEL FeederPP
Description:"Feed stream material balance calculation.";
ComponentList : "Process";
Z(ComponentList) AS Molefraction;
T_out AS Temperature;
P AS Pressure;
H AS Enth_Mol;
$T_out = 10 ;
CALL ( H ) = pEnth_Mol (T_out, P, Z);
SIGMA(Z) = 1.0;
END
OPTIONS
SolverProperty : Value ;
.
END
PROCEDURE ProcedureName
LIBRARY : "dll library filename" ;
CALL : "ExternalName";
IMPLEMENTATION: SUBROUTINE | FUNCTION "Fortran, C or C++
file pathname"|
TEXT
code
ENDTEXT;
LANGUAGE: "FORTRAN | C |C++";
COMPATIBILITY: "SPEEDUP" ;
OPTIONS: ListOfOptions ;
WORKSPACE: WorkspaceExpression ;
ProcedureName .............. The name you give to this procedure definition. This name is used by
call statements in the modeling language
Dll library filename.......... The file name, including the path on the machine you are using, as a
string of text. Do not include the extension .dll or .so if you want the
name to be platform-independent.
Note If the client and server are running on the same machine, you do
not need to specify the full path name if DLLs are located:
– on the PATH;
– in the Simulation Working Directory, or;
– in the same directory as the Input language text file.
ExternalName.................. The name of the routine in the external code. If the ExternalName is the
same as the ProcedureName, the CALL statement is not required
Keyword Meaning
Folder Syntax
You can create lists of types under named folders. The syntax is:
FOLDER FolderName
Description: "Descriptive text string";
TYPES: ["Type1", "Type2", ..., "TypeN"];
FOLDER NestedFolderName
Description: "Descriptive text string";
TYPES: ["TypeX", "TypeY", "TypeZ"];
END
END
FolderName ..................... Name you give to the folder. This name is displayed in
the Custom Modeling library folder
Type1, Type2, TypeN
TypeX, TypeY, TypeZ....... Lists of previously defined types
Descriptive text string .... Description of the folder
NestedFolderName ......... Name you give to a nested folder (if applicable)
Folder Remarks
You can create any number of levels of model folder by using the
Add Model Folder object within each model folder.
You must define folders after you have defined the types you want
to list in the folders. You should define folders in a suitable place,
for example, immediately before the flowsheet definition.
Folder Example
In this example, a number of previously defined models are
organized into different folders for more efficient access in the
Custom Modeling library.
FOLDER HeatExchangers
Types: ["HeatEx1", "HeaterCooler", "HeatEx2",
"HeatExShellInTube", "HeatExFanAssisted"];
END
FOLDER Mixers
Types: ["GeneralMixer", "TwoPhaseMixer",
"ThreePhaseMixer"];
END
Property Description
MODEL ddd
inp as input multiport of FlowPort;
out as output FlowPort;
for s in inp.connectionset do
for c in inp.connection(s).componentlist do
if( NOT inp.connection(s).F(c).IsMatched ) then
inp.connection(s).F(c) = 0.0;
endif
endfor
endfor
END
Multiport Syntax
The syntax for defining a multiport in a model is:
Connection Syntax
The variables in the port are accessed using the following syntax:
PortName.Connection.PortVariable
Sum = SIGMA(PortName.Connection.ArrayVariable);
FOR i IN ArrayIndexSet DO
Sum(i) = SIGMA(PortName.Connection.ArrayVariable(i));
ENDFOR
FOR i IN PortName.ConnectionSet DO
Sum(i) = SIGMA(PortName.Connection(i).ArrayVariable);
ENDFOR
Variable(ConnectionSet) AS VariableType;
Multiport Example
The following model represents a multi-mixer where only one inlet
port is defined. This mixer model can then be used to mix any
number of inlet streams between MAX_CONNECTIONS and
MIN_CONNECTIONS.
PORT Main
Flow AS Flowrate;
Z(ComponentList) AS Fraction;
END
MODEL MULTIMIX
Input 1 as INPUT MULTIPORT OF
Main(MIN_CONNECTIONS:1,MAX_CONNECTIONS:10);
Output1 AS OUTPUT Main;
Output1.Flow = SIGMA(Input1.Connection.Flow) ;
FOR i IN ComponentList DO
Output1.z(i)*Output1.Flow =
SIGMA(Input1.Connection.z(i)*Input1.Connection.Flow) ;
ENDFOR
/*Connection is an array of size ConnectionSet,
so the SIGMA function sums the values over the
elements in this array for each of the components
in ConponentList*/
END
Equation Syntax
Equation Remarks
You can have any number of variables on either side of the equality
sign. You should re-arrange equations to improve the numerical
solution of the simulation for robustness and speed.
The equations and variables in a model must completely describe
the process. You must ensure that the simulation can be solved,
given the number of known values in your simulation. The number
of equations must equal the number of unknowns in your
simulation.
Equation Example
The following is a simple flow continuity equation. FlowIn and
FlowOut are variable defined for the model. The name
MaterialBalance is optional.
MaterialBalance : FlowIn = FlowOut ;
Input1.Flow and Output1.Flow are port variables. AdditionalFlow
is a variable defined in the model. Both types of variable can be
freely mixed.
Input1.Flow + AdditionalFlow = Output1.Flow ;
ArrayVariable
ArrayVariable(Element)
ArrayVariable( [ElementA, ElementB, ...] )
ArrayVariable( [ElementA : ElementB ] )
ArrayVariable ( SetName )
IF ConditionalExpression THEN
Equation1A;
Equation2A;
.
Assignment1A;
Assignment1B;
.
ELSE
Equation1B;
Equation2B;
.
Assignment2A;
Assignment2B;
.
ENDIF
Operator Meaning
Notes
• The three logical functions are evaluated in the priority
order: NOT, AND, OR.
• Two logical functions may not appear in sequence unless the
second one is the NOT operator.
• To avoid ambiguities in your logical expressions, use
parentheses to define the expression.
FOR Loops
FOR loops enable you to simplify repetitive statements. FOR loops
are useful for handling arrays with large numbers of elements, or
more than one dimension.
statements;
ENDFOR
ForEach Operator
The ForEach operator is the equivalent of the For operator, but is
used only with list operators, that is:
• SIGMA
• PRODUCT
• MIN
• MAX
• UNION
• INTERSECTION
• DIFFERENCE
• SYMDIFF
ListOperator(expression1, expression2, …)
ForEach Examples
The following is a simple matrix multiplication example:
Index([1:n]) as IntegerSet;
A(Index, Index), B(Index, Index), C(Index, Index) as RealVariable;
For i in Index DO
For j in Index DO
C(i,j) = Sigma(ForEach (k in Index) A(i,k)*B(k,j) );
EndFor
EndFor
The result of the above for n = 2 would be the following equations
C(1,1) = sigma(A(1,1)*B(1,1), A(1,2)*B(2,1)); // i=1, j=1
C(1,2) = sigma(A(1,1)*B(1,2), A(1,2)*B(2,2)); // i=1, j=2
C(2,1) = sigma(A(2,1)*B(1,1), A(2,2)*B(2,1)); // i=2, j=1
C(2,2) = sigma(A(2,1)*B(1,2), A(2,2)*B(2,2)); // i=2, j=2
The following example is a legal statement using ForEach with
sigma:
sigma(foreach (i in set) x(i)) = 0;
Result when set = [1:3]:
sigma(x(1), x(2), x(3)) = 0;
The second example is also a legal statement:
sigma(foreach(i in set1, j in submodel(i).set) model(i).x(j) ) = 0;
Result when set1 = ["a", "b"], submodel("a").set = [1,2],
submodel("b").set = [3,4]:
Sigma(model("a").x(1),model("a").x(2),model("b").x(3),model("b").x(4
)) = 0;
The third example is also a legal statement:
sigma(foreach(i in set1) x(i), foreach(i in set2) y(i) ) = 0;
Result when set1 = ["a", "b"] and set2 = [1,2]:
PortName.PortVariableName
CONNECT Keyword
You use connection statements to connect ports and variables in a
flowsheet. You have the option of connecting ports with a stream.
Use the CONNECT keyword to connect ports of compatible
directions in the flowsheet. You can use CONNECT in model
definitions and in flowsheet definitions.
For information on when to use CONNECT, and how to connect
ports and variables, see Connectivity Rules.
or
CONNECT Remarks
The following table shows the results of specifying port names:
One port name only The first port becomes either a feed or a product
port, depending on the direction of the port
Two port names One port must be an inlet and the other an outlet.
a([1:nStage]) as ModelType1;
b([1:nStage]) as ModelType2;
connect a.outlet and b.inlet; // Illegal implicit loop
nStage as IntegerParameter;
a([1:nStage]) as ModelType1;
b([1:nStage]) as ModelType2;
FOR i IN (1:a.nStage] DO
FOR j IN [1:a(i).nArraySize] DO
// j is dependent upon i the outer
loop index variable
connect a(i).x(j) and b(i).y;
// nested FOR loop too complex for
CONNECT statement
ENDFOR
ENDFOR
CONNECT Examples
The following examples show the different options available for
the CONNECT keyword.
The first example shows the port Valve.Outlet is not connected to
another port. On the flowsheet the unconnected end of the stream is
shown as a product.
CONNECT Valve.Outlet ;
Then the ports Valve.Outlet and Tank.Inlet are connected with a
universal stream:
CONNECT Valve.Outlet AND Tank.Inlet ;
In the following example, the ports Valve.Outlet and Tank.Inlet are
connected with the stream called Stream1. Stream1 is defined
before this statement as using a defined Stream Type:
CONNECT Valve.Outlet AND Tank.Inlet WITH Stream1 ;
The next example shows the connection named as S1. This name
overrides the default connection name in the flowsheet display:
S1 : CONNECT Valve.Outlet AND Tank.Inlet ;
The next example shows the connection named S1 using the
stream named Stream1:
S1 : CONNECT Valve.Outlet AND Tank.Inlet WITH
Stream1 ;
LINK Keyword
Use the LINK keyword to define a connection to a containing
model's ports from the ports of sub-models within the containing
model. Use LINK to connect ports of the same direction. If the
ports are of different directions, use CONNECT.
For information on when to use LINK, and how to connect ports,
see Connectivity Rules.
LINK Syntax
LINK Remarks
Use the LINK keyword when you have a list of sub-models within
a containing model. Use the CONNECT keyword for connections
within the containing model. LINK enables you to attach an
internal connection to one of the containing model’s ports.
You can connect two ports of the same direction with the LINK
keyword.
You must specify two port names in a LINK statement, one of
which is the port name for the containing model.
You cannot use LINK in the flowsheet definition. You must use
LINK only in a model definition.
LINK Restrictions The following restrictions apply when using LINK:
• You cannot use a LINK statement to connect arrays of
variables or ports. The following example is therefore
illegal:
Connectivity Rules
Connect ports in models as shown in the following table:
INPUT OUTPUT
OUTPUT INPUT
INPUT INPUT
OUTPUT OUTPUT
SIGMA Syntax
The syntax for using SIGMA is:
SIGMA ( Expression );
SIGMA Remarks
The SIGMA function is normally applied to expressions containing
arrays. You can sum the whole array or a defined slice of an array.
If you use an array variable in sigma without any qualification, all
the values in the array are summed.
You can apply SIGMA to multidimensional arrays. To control the
way SIGMA works, you define the extent of the arrays to be
summed. You can also use SIGMA to sum the variables in
multiports.
SIGMA Examples
The most basic use of the SIGMA function is to sum non-array
variables or values:
A1, A2, A3, B1 AS RealVariable;
B1 = SIGMA (A1, A2, A3, 2.0 );
The SIGMA command is interpreted as:
B1 = A1 + A2 + A3 + 2.0
More typically, SIGMA is used to sum elements of arrays:
ComponentList AS StringSet(["N2", "O2", CO2"]);
x(ComponentList) AS Fraction;
SIGMA(x) = 1.0;
In this example, x is an array, so SIGMA(x) calculates the sum of
the values in the array. The SIGMA command is interpreted as:
x("N2") + x("O2") + x("CO2") = 1.0
Temp(Sections) AS Temperature;
x, y AS RealVariable;
x = SIGMA(Temp);
y = SIGMA(Temp([2:Nsect]));
You can remove an element of a set from the calculation in the
SIGMA expression:
NonWaterFraction AS Fraction;
x(ComponentList) AS Fraction;
SIGMA(x(ComponentList - ["WATER"])) =
NonWaterFraction;
In this example, SIGMA is used to sum the fractions of all the
components in a component list except for water.
Using SIGMA for You can use SIGMA to sum arrays that contain more than one
Multidimensional dimension.
Arrays and Multiports
SIGMA( Variable(Dim1, Dim2, ..., Dimn) )
or
SIZE Syntax
SIZE ( SetName )
SIZE Example
In the following example SIZE is used to determine the number of
components used in a model, and calculates some default values
for the molefractions of the components.
MODEL Feed
x(ComponentList) AS Molefraction(fixed);
.
x(ComponentList) : 1 / SIZE(ComponentList) ;
.
END
The SIZE function calculates the size of the ComponentList Set. A
value of one over the number of components is used as an default
value for the fixed molefraction array variable.
VariableName.Spec : Fixed|Free|Initial|RateInitial ;
– or –
– or –
ParameterName.ParameterProperty : PropertyValue;
– or–
ParameterName : PropertyValue ;
SubModelName.VariableName
SubModelName AS
ModelName( SubModelVariable = ModelVariable, ...,
SubModelParameter : ModelParameter, ... ) ;
SubModelName ([1:(condition)]) AS
ModelName( SubModelVariable = ModelVariable, ...,
SubModelParameter : ModelParameter, ... )
To use this sub-model, the containing model must equate its local
variables with the variables in the sub-model, for example:
Model Simple
TotalFlow as flow_mol;
Flow(componentlist) as flow_mol;
X(componentlist) as fraction;
//Include submodel for conversion from
fractions to flows
convert as FractionToFlow(TotalFlow=TotalFlow,
X=X, Flow=Flow);
// Rest of models equations
End
This has introduced duplicates of each Flow and X variable and the
TotalFlow variable. To reduce the duplication of variables, you can
use the EXTERNAL declaration qualifier in the sub-model, for
example:
Model FractionToFlow
TotalFlow as EXTERNAL moleflow;
Flow(componentlist) as EXTERNAL flow;
X (componentlist) as EXTERNAL fraction;
Flow = TotalFlow * X;
End
Now there is only one copy of the variables TotalFlow, Flow, and
X.
Using SWITCH
You can use the SWITCH keyword to define any number of
different modes of operation directly in the model definition.
A switch definition always applies to the model during simulation.
SWITCH operates with all run modes.
You can use SWITCH to change between different equations in a
model. You can define conditions that determine how the model
switches between different sets of equations.
SwitchName: SWITCH
INITIAL STATE StateName
SwitchStatements;
IF Condition STATE : StateName;
ENDSTATE
.
.
ENDSWITCH
SWITCH Remarks
You can use SWITCH to change the way a model works depending
on the condition of a process variable during run-time. SWITCH
provides a quick and easy way for you to describe reversible and
non-reversible changes in your process.
You cannot change the structure of the simulation between states.
Each state definition in a switch must maintain a square and
complete simulation status. This means that you must have the
same number of equations in each state within a SWITCH
definition.
Domain Syntax
Domain, Domain, … AS
DomainModel of RealParameterType(Property :
PropertyValue, ... );
Notes
• The default spacing preference for each section in a domain
is the spacing preference specified for the domain.
• The information on spacing preference vs. spacing used for
a domain also applies to element spacing for individual
sections.
Section Remarks
• You can change the number of domain sections and their
location and element spacing in the declaration of your
domain or by using the domain configuration form.
• The locations of contiguous sections in a given domain must
be in increasing order. A section location value must not
exceed Section(1).Location plus Length.
• Uniform element spacing is used in a given section. Element
spacing can vary between sections, therefore, non-uniform
spacing can be applied using multiple sections, each with a
different spacing. The latter is particularly useful for
modeling PDE systems with sharp fronts.
In the above example, the domain declaration sets the default order
for all distributed variables to 2. This means that both ddx and
d2dx2 are calculated for the distributed variable T. However, for
TWall the default is overridden and set to zero. In this case the ddx
and d2dx2 arrays are empty and no partial derivatives are
calculated.
Alternatively you can simply index TWall over the same range as
the domain:
Model Pipe
XDomain as Domain(HighestOrderDerivative: 2);
T as Distribution1D of Temperature;
TWall([0:XDomain.EndNode]) as Temperature;
End
Referring to Domains Distributed variables can refer only to domains that you have
in Distributed declared previously in your model. For instance this sequence of
Variable Declarations declarations is legal:
Model Pipe
// Declare distributed domain
Axis as Domain of LengthParameter;
// Declare array of concentration variables
distributed over a 1D domain
Conc(ComponentList) as Distribution1D(XDomain
is
Axis) of Conc_Mole (Value: 0.0);
End
whereas the following declarations are illegal because the Axis
domain is used before it is declared:
Notes
• The declaration of the distributed array called Conc
illustrates the convention for separating declaration
qualifiers (for example, XDomain is Axis), which appear
before the value type (for example, Concentration), and
assignments (for example, Value:0.0), which are put after
the value type.
• To refer to the concentration of a particular component (for
example, "A") at a specific location (for example, node iX),
use Conc("A").value(iX) or Conc("A")(iX) for short.
Referencing Domains You can declare a domain and/or distribution in a model and then
and Distributions in use this in a submodel of that model. To do this you should declare
Sub-Models the domain and/or distribution as External in the sub-model, and
pass the name of the domain and/or distribution to be used when
you instance the sub-model. For example to use the Domain X and
distribution T in a sub-model called Conductivity, the main model
Advection Equation
∂T ∂T
= −V
∂t ∂x
// Modeling Language
$Temp = -V *
Temp(Axis.Interior+Axis.EndNode).ddx;
For example, Fourier’s second law for heat conduction in one-
dimensional Cartesian coordinates:
// Modeling Language
u(X.Interior,Y.Interior).d2dx2 +
u(X.Interior,Y.Interior).d2dy2 = 0.0;
Poisson’s Equation
∂2u ∂2 u
+ 2 = sinh( π 2 + 1 x ) sin(πy )
∂x 2
∂y
// Modeling Language
for ix in x.interior do
for iy in y.interior do
u(iX, iY).d2dx2 + u(iX, iY).d2dy2 =
sinh(sqrt(sqr(PI)+1.0)*X(iX)) * sin(PI*Y(iY));
endfor
endfor
Helmholtz’s Equation
∂2u ∂2u
+ =u
∂x 2 ∂y 2
// Modeling Language
u(X.Interior,Y.Interior).d2dx2 +
u(X.Interior,Y.Interior).d2dy2 = u(X.Interior,
Y.Interior);
Open Domains for The proper declaration of models of distributed parameter systems
PDE Modeling requires the accurate specification of the domain of applicability of
each equation and boundary condition. You can easily distinguish
between the interior of the domain and the different parts of the
boundaries. The built-in domain model provides an integer set
called Interior that can be used to facilitate the efficient writing of
partial differential equations in your model.
An open domain is a domain without its boundaries. You can
define an open domain in your model equations using the Interior
set declared in the domain model. As its name implies, the Interior
set does not include the left-hand domain boundary [0] and right-
hand [EndNode] domain boundary.
Closed Domains for A closed domain is a domain with its boundaries included. The
PDE Modeling left-hand and right-hand domain boundaries are represented by
nodes 0 and EndNode, respectively. You will often need to define a
closed domain when writing your boundary conditions:
// Boundary condition for Heat transfer to solid
$TS([0:X.EndNode]) = SCon * (TG([0:X.EndNode]) -
TS([0:X.EndNode]));
Important Do not use the Interior set for writing boundary
conditions, especially when using OCFE discretization methods
and finite difference methods with multiple domain sections. You
should always index boundary conditions explicitly using integer
elements.
Using Domain Slices The boundary condition equations in a model may involve just a
for PDE Modeling sub-domain of an entire domain distribution. To define such sub-
domains, you can make use of the built-in support for set
operations. For example, in the case of the variable Temp which is
distributed over both axial and radial domains:
PDE Order LHB Section1 Section1 Section1 Sbound Section2 Section2 Section2
RHB
Node 0 Node 1 Node 2 Node 3 Node 4 Node 5 Node 6 Node 7 EndNode
1-ddx FFD1 BFD1 BFD1 BFD1 BFD1 BFD1 BFD1 BFD1 BFD1
2-d2dx2 None CFD2 CFD2 CFD2 ddx Cont CFD2 CFD2 CFD2 None
PDE LHB Section1 Section1 Section1 Section1 Sbound Section2 Section2 Section2
Section2 RHB
Order Node 0 Node 1 Node 2 Node 3 Node 4 Node 5 Node 6 Node 7 Node 8 Node 9 EndNode
1-ddx FFD4 DBFD4 CFD4 CFD4 UBFD4 BFD4 DBFD4 CFD4 CFD4 UBFD4 BFD4
2-d2dx2 None DBFD4 CFD4 CFD4 UBFD4 ddx Cont DBFD4 CFD4 CFD4 UBFD4 None
1-ddx FFD4 DBFD4 CFD4 UBFD4 UBFD4 BFD4 DBFD4 CFD4 UBFD4 UBFD4 BFD4
2-d2dx2 None DBFD4 CFD4 UBFD4 UBFD4 ddx Cont DBFD4 CFD4 UBFD4 UBFD4 None
Discretization The finite element family of methods divides the domain into many
Methods: Finite smaller elements and applies weighted residual methods within
Element Methods each element. The weighted residual methods assume that the
solution can be represented as a weighted combination of known
polynomial approximations of order n with unknown weighting
coefficients. The latter are determined to satisfy boundary
conditions and the system of equations at a finite set of points,
called collocation or polynomial points. The precise criterion used
to choose the weighting coefficients determines the method.
The weighted residual method that is combined with the finite
element concept is the method of orthogonal collocation (OCFE).
Second- and fourth-order OCFE methods are provided as shown in
the following table. You can specify that you want to use an OCFE
method using the DiscretizationMethod property assignment when
declaring a domain.
OCFE2
PDE LHB Node 0 Element1 ElemBoundNode 2 Element2 Coll 1 RHB EndNode 4
Order Coll 1
OCFE4
PDE LHB Element1 Element1 Element1 ElemBound Element2 Element2 Element2 RHB
Order Node 0 Coll 1 Coll 2 Coll 3 Node 4 Coll 1 Coll 2 Coll 3 EndNode 8
1 ddx ddx ddx ddx ddx Elem1 ddx ddx ddx ddx
2 None d2dx2 d2dx2 d2dx2 ddx Cont d2dx2 d2dx2 d2dx2 None
Distribution
A distribution is a variable distributed over one or more domains.
Domain
A domain is a region over which a distributed parameter system is
discretized.
Method of Lines
The Method of Lines is an approach to solving time-dependent
PDAE systems by discretizing in space, but leaving the time
variable continuous
Neumann
Neumann is a type of boundary condition that specifies the values
of the first-order spatial derivatives on the boundary.
Flowsheet Syntax
FLOWSHEET
FlowsheetStatements
CONSTRAINTS
Variable and Equation definitions
END
END
Flowsheet Remarks
The flowsheet describes instances of models and streams, and the
connections between them. Models and streams describe the
equations and variables that will be solved.
You usually define the flowsheet using the GUI. However, you
may sometimes prefer to define the flowsheet in a text editor,
where cutting and pasting lines of text is more efficient than
placing blocks on a flowsheet. For example, you may want to
create a large, repetitive flowsheet, where the same model is used
many times.
Caution If you want to use a text editor to modify an existing
flowsheet in a saved language file by either adding or deleting
blocks, you must delete the existing text flagged in the file as
SYSTEM SECTION. Before deleting the System section, you are
strongly advised to make a backup copy of your work. The System
section usually contains graphical or other data in a strict format
associated with the last saved flowsheet. Normally, you should
avoid editing the System section, but in this case, you must delete
the System section to be able to open the modified language file.
You can declare variables local to the flowsheet that are used in
flowsheet equations. All variables and equations in a flowsheet
must be declared between the keywords CONSTRAINT and END.
Constraint equations can include variables in the flowsheet blocks.
This syntax does not apply to hierarchy flowsheets. These should
only be created and editing using the GUI.
BlockName AS ModelName ;
or
BlockName.ParameterName : ParameterValue ;
BlockName.VariableName.PropertyName : PropertyValue ;
Symbol Effect
*/
General Modeling The modeling language is free format. This means that you can
Language write syntax over several lines and insert spaces for clarity.
Conventions The modeling language is not case sensitive.
L P
LINK keyword 4-29 PARALLEL keyword 2-26–2-27
Logical operators 4-12, 4-15 PARAMETER keyword 1-12, 1-25
LogicalParameter built-in parameter type 1- Parameters
25 built-in types 1-25
defined 1-12
M modeling language for 3-4
relating to variables 4-11
Matching port variables 4-7
Path names, assignment lists for 1-9
Mathematical operators 4-12
Pausing a simulation 2-28
MAX operator 4-12, 4-21
PDAE models 5-23
Method of Lines 5-36
PDE models 5-1
MIN operator 4-12, 4-21
Physical properties
MODEL keyword 3-6
modeling language for 3-11
Modeling language
Physical quantities 2-3, 2-4
conventions for writing 7-2
PhysicalQuantity property 2-3
Models
PORT keyword 3-5
built-in type for 1-28
Ports
connecting 4-25, 4-29
built-in type 1-30
modeling language for blocks 6-4
collections of 4-8
modeling language for model types 3-6
connecting 4-5
specifications in 4-37
modeling language for 3-5, 4-5, 4-25, 4-29
variables in 4-2
properties for 4-6
Modes of operation 4-46
restrictions in streams 3-8
U
UNION operator 1-15, 4-21
Units of measurement
automation 2-4
modeling language for 2-2
UOM
modeling language for 2-2
USES keyword 1-20, 3-2, 3-5
UseUOMof qualifier 4-2
V
Validating component lists 3-13