ACM Modeling Language Reference
ACM Modeling Language Reference
ACM Modeling Language Reference
Modeler 2004.1
Modeling Language
Reference Guide
Who Should Read this Guide
Contents 3
Defining Tasks ....................................................................................................... 45
Event-Driven Tasks ........................................................................................... 46
Callable Tasks .................................................................................................. 48
Tasks and Opening Simulations ........................................................................... 51
Using Task Statements ........................................................................................... 51
Assigning a Value to a Variable in Tasks ............................................................... 51
UOM Conversions in Tasks.................................................................................. 52
Using the Random Function ................................................................................ 52
The IF Construct ............................................................................................... 53
Ramping the Value of a Simulation Variable in Tasks .............................................. 54
Suspending and Restarting a Task ....................................................................... 55
Creating Snapshots in Tasks ............................................................................... 57
Executing Tasks in Parallel ................................................................................. 57
PRINT Statements in Tasks................................................................................. 58
Pausing a Simulation from a Task ........................................................................ 59
Invoking a Script from a Task ............................................................................. 60
FOR Loops in Tasks ........................................................................................... 61
REPEAT Loops in Tasks ...................................................................................... 62
WHILE Loops in Tasks........................................................................................ 62
Task Language Quick Reference .......................................................................... 63
Defining Flowsheet Constraints ................................................................................ 65
Defining Optimization Constraints............................................................................. 66
Defining Steady State Constraints ............................................................................ 68
Defining Dynamic Constraints .................................................................................. 69
Path Constraints .................................................................................................... 70
Contents 4
Using Multiports ................................................................................................ 91
Writing Equations in Models ..................................................................................... 94
Mathematical Operators in Equations ................................................................... 94
Equations with Array Variables ................................................................................. 96
Conditional Equations ............................................................................................. 97
Using Sets in Conditional Expressions ......................................................................100
FOR Loops ...........................................................................................................101
ForEach Operator ..................................................................................................103
Equations that Call Procedures ................................................................................105
Equations that Refer to Port Variables ......................................................................106
CONNECT Keyword................................................................................................107
CONNECT Restrictions.......................................................................................108
LINK Keyword ......................................................................................................110
LINK Restrictions .............................................................................................110
EXTERNAL Keyword...............................................................................................112
Connectivity Rules.................................................................................................113
Using SIGMA ........................................................................................................114
Using SIGMA for Multidimensional Arrays and Multiports ........................................115
Using the SIZE Function.........................................................................................117
Assigning Specifications in Models ...........................................................................117
Referring to Sub-Models in a Model Definition ...........................................................119
Using External Properties to Write Sub-Models ..........................................................121
Example of Using External Properties to Write Sub-Models .....................................122
Changing the Default Mapping For External Properties ...........................................123
Notes and Restrictions on Writing Sub-Models ......................................................124
Using Virtual Types in Sub-Models ...........................................................................124
Example of Using Virtual Types in Sub-Models ......................................................124
Restrictions on Using Virtual Types .....................................................................126
Using SWITCH ......................................................................................................126
Contents 5
Specifying Domain Length .................................................................................138
Specifying Element Spacing Preference ...............................................................139
Using Domain Sections .....................................................................................141
Number and Location of Discretization Nodes .......................................................142
Interpolation of Existing PDE Models ...................................................................143
Using Distributions with PDE Modeling......................................................................148
Declaring Distributions for Distributed Variables ...................................................149
Declaring Distributed Variables that do not Require Partial Derivatives .....................152
Switching On Integrals in Distribution Declarations ...............................................152
Referring to Domains in Distributed Variable Declarations ......................................153
Using an Array of Distributions...........................................................................154
Referencing Domains and Distributions in Sub-Models ...........................................155
About IPDAE Models ..............................................................................................155
Partial Differential Equations (PDEs) ...................................................................156
Writing PDEs in Models ..........................................................................................157
Specifying Partial Derivatives in PDEs..................................................................157
Using the Interior Set in PDEs ............................................................................158
Open Domains for PDE Modeling.........................................................................159
Closed Domains for PDE Modeling.......................................................................160
Using Domain Slices for PDE Modeling.................................................................160
Using Boundary and Initial Conditions for PDE Modeling.........................................163
Boundary Conditions Containing Second-Order Derivatives.....................................165
Writing Integrals in PDE Models..........................................................................168
Using Method of Lines for the Solution of PDEs ..........................................................171
Finite Difference Methods: General .....................................................................172
Discretization Methods: Finite Element Methods....................................................174
Mixer-Reactor-Absorber (PDE) Example Description ...................................................176
Running the Mixer-Reactor-Absorber (PDE) Example ..................................................176
Jacketed Reactor (PDE and Integral) Example Description...........................................177
Running the Jacketed Reactor (PDE and Integral) Example .........................................178
Crystallizer (PDE and Integral) Example Description ...................................................178
Running the Crystallizer (PDE and Integral) Example..................................................179
PDE Modeling Glossary ..........................................................................................180
Contents 6
GENERAL INFORMATION..............................................................................183
Copyright.............................................................................................................183
Related Documentation..........................................................................................186
TECHNICAL SUPPORT...................................................................................187
Online Technical Support Center .............................................................................187
Phone and E-mail..................................................................................................188
INDEX ..........................................................................................................189
Contents 7
Contents 8
Introducing Aspen Custom
Modeler
Aspen Custom Modeler (ACM) is an easy-to-use tool for creating, editing and
re-using models of process units. You build simulation applications by
combining these models on a graphical flowsheet. Models can use inheritance
and hierarchy and can be re-used directly or built into libraries for distribution
and use. Dynamic, steady-state, parameter estimation and optimization
simulations are solved in an equation-based manner which provides flexibility
and power.
ACM uses an object-oriented modeling language, editors for icons and tasks,
and Microsoft Visual Basic for scripts. ACM is customizable and has extensive
automation features, making it simple to combine with other products such as
Microsoft Excel and Visual Basic. This allows you to build complete
applications for non-experts to use.
Statements
Use statements to make assignments of values, define equations, declare
items such as variables or models, and make connections.
Statements include one of the syntax elements shown in the following table.
: Value assignment
Statement Examples
Create an instance of a variable in a model:
T AS Temperature;
Assign a value to a variable and specify that the variable value is known:
FlowIn = FlowOut;
Make a connection between the port of a sub-model and the port of the
containing model:
Type Definitions
Type definitions introduce and describe new types for models, streams,
variables, structures, procedures, ports and parameters.
For further information on types, see Modeling Language for Types. Chapter
3.
DefinitionBody
VARIABLE Temperature
Value: 1.0;
Lower: -40.0;
Upper: 300.0;
Scale: 10.0;
Description: "Temperature";
PhysicalQuantity: "Temperature";
END
Declaration Statements
A declaration statement declares a property by giving it a name and defining
its type. The syntax for all declarations has the following form:
Identifier, Identifier ... AS FlagList TypeName
(AssignmentList);
Assignments
Assignments are used to change the value of a property of an object, such as
a variable or a parameter.
Assignment Syntax
The modeling language uses a : (colon) as its assignment operator:
Object.Property: ValueExpression;
Assignment Remarks
Assignments to expressions are treated as constraints by the compiler. This
means that the expression is re-evaluated whenever the value of any term
within it changes. The result is then automatically assigned to the property.
You can assign values to properties of variables or parameters in several
places, for example in models, flowsheet constraints and interactively. From
highest to lowest, the order of precedence in which variable and parameter
properties are changed is:
• Changes made in the following ways are made immediately and overwrite
any previous assignment:
− Interactive changes, for example, using a table, using the automation
interface, running a script, or applying a snapshot with Use
− Values calculated as the result of running a simulation
• Assignments written into the Flowsheet Constraints section take
precedence over assignments in models.
• If an assignment in a model uses an expression, and one of the values in
the expression changes, the expression is re-evaluated and the assigned
value is updated. However if the value has previously been changed by a
higher precedence operation, this updating is disabled to avoid overriding
this change.
• If a block uses a model that uses hierarchy, assignments made in the
parent model take precedence over those in child models in the hierarchy.
• If a block uses a model that uses inheritance, assignments in the derived
model take precedence over those in the inherited model.
• If properties are not assigned anywhere else, they will remain at the
default values defined for their variable type or parameter type.
Assignment Examples
Assign the value 5 to the Value property of the variable x:
x: 5.0;
Assign the value "Cylinder" to the Value property of the string parameter
Geometry:
Geometry: "Cylinder";
Assign the value True to the Value property of the logical parameter
PressureDriven:
PressureDriven: True;
Lag: 5/60;
Lag2: Lag/2;
Assign values for the Upper and Lower bounds of variable x:
x.Lower: -10;
x.Upper: 20;
Components AS StringSet(["H2O","H2+","Zn++","Ca++"]);
mw(Components) AS MoleWeight;
mw("H2O"): 18;
mw("Ca++"): 40.1;
mw(["H2O","H2+","Zn++","Ca++"]) AS MoleWeight;
Assignment Lists
You can use assignment lists in variable assignments to avoid repeating path
names.
Rxn1 AS PowerLawRxn;
WITHIN Rxn1
PreExp: 1.45E6;
EAct : 2374.7;
TExp : 1.2;
ENDWITH
Alternatively, you could type each specification explicitly:
Rxn1 AS PowerLawRxn;
Rxn1.PreExp: 1.45E6;
Rxn1.EAct : 2374.7;
Rxn1.TExp : 1.2;
Naming Conventions
You use names when you:
• Define a type, such as a model or a stream type.
• Add a property to a type, such as a variable.
Important Note: You cannot create a type which has the same
name as a built-in type or a keyword.
Block Syntax
BLOCKS("BlockName")
Stream Syntax
STREAMS("StreamName")
You can use the same syntax in both input files and in Microsoft Visual Basic.
BLOCKS("B1").Tin = STREAMS("B1").T;
Parameters
Use parameters to define values that are fixed for the whole simulation, such
as acceleration due to gravity, or the gas constant. You can also use
parameters for fixed physical quantities such as the number of trays in a
column. Like variables, parameters are declared within types such as models
or stream types.
Parameters Syntax
ParameterName AS ParameterType (Value);
Parameters Remarks
The key difference between variables and parameters is that variables can be
solved for during a simulation run, whereas parameters always have a known
value. Also parameters can be used in conditional statements or loops within
models to determine which variables and equations will be active for a
particular instance of a model.
Parameters may be of one of the built in types IntegerParameter,
StringParameter, LogicalParameter or RealParameter., or of a user defined
type defined using the PARAMETER keyword.
Parameters Examples
Define a parameter for the gravitational constant g:
g AS RealParameter (9.81);
In the next example the model Column has a parameter NStages which
defines the number of stages. This parameter is used to define an array of
Tray models called Stages. NSTages is given a default value of 10, but this
can be changed when the Column model is instanced as a block in the
flowsheet.
MODEL Column
NStages AS IntegerParameter(10);
Stages([1:NStages]) AS Tray;
.
.
END
Sets
Sets are most commonly used to index array variables. For information on
arrays, see Arrays.
A set is a collection of objects that has no duplicate values and is not in any
specific order. You can manipulate sets using set functions, such as union,
intersection, and difference.
Sets Syntax
SetName AS SetType (SetContents) ;
Sets Remarks
You can define sets that contain either integers (IntegerSet) or strings
(StringSet).
An IntegerSet is a set whose members are integers, for example [1,2,5].
A StringSet is a set whose members are strings, for example [“Methane”,
“Ethane”, “Propane”].
You can define the set contents at the same time as you define the set, or
you can define the set contents later. The set contents can be defined by a
list of objects enclosed between [ and ] (brackets), or by a set expression
involving previously defined sets.
Sets Examples
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;
Set Arithmetic
The following set arithmetic functions are available:
or
SetFunctionName (SetExpression1, SetExpression2, ... );
Arrays
An array is a collection of objects indexed by either one integer set or one
string set for each dimension of the array.
You can use arrays to define a collection of variables, parameters, ports,
model instances, or streams.
Arrays Remarks
Because an array is indexed by a set, it is possible for the index of the array
to 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, for example,
you may want to use a different model for a feed tray.
As arrays can be indexed by a string set, 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 over the integer set from 1 to 10:
SectionTemp([1:10]) AS Temperature;
MODEL FeedTray
.
.
END
MODEL Column
NTrays AS IntegerParameter(10);
NFeedTray AS IntegerParameter(5);
task MyTask
s2 as StringParameter;
s2: CONVERTTO(string, V); // V is a variable accessible
to the task
print "value of V is " + s2;
end
Inheritance
Inheritance enables you to create new types which build upon existing ones.
You describe an inheritance relationship between two type definitions with the
keyword USES.
Inheritance Remarks
If you define a type using inheritance, the type inherits all the properties of
the type from which it inherits. You can then extend the type definition with
statements that add extra properties to the type.
Inheritance also enables you to refine the definition by changing the default
values of existing properties. Other than this you cannot change or remove
properties that come form the inherited type.
Inheritance Example
In the following example, the variable type ColdTemp inherits all the
properties and default values from the variable type Temperature, but
overrides the default value for the property UPPER.
In the following example, the model HeatX inherits from the model Heater. It
extends Heater by adding the variable UA and an equation to calculate Q. It
also changes the default spec of Q to free, as Q is now calculated by an
equation:
MODEL HeatX USES Heater
UA as HTCoeff (1, Fixed);
Q: free;
Q=UA*DT;
END
PORT Material
Flow AS Flow_Vol_Liq;
END
MODEL Tank1
.
Out1 AS OUTPUT NewMaterial;
.
END
MODEL Tank2
.
In1 AS INPUT Material;
.
END
PROCEDURE TotalMassCalc
.
.
INPUTS : Area, Length, Density;
OUTPUTS: Mass;
MODEL Tank
TankArea AS Area;
TankHeight AS Length;
RhoLiq AS LiquidDensity;
RhoVap AS VaporDensity;
TotalMass AS Mass;
Phase AS PhaseParameter("Liquid");
END
Component Lists
A component list contains two types of information:
• A list of component names
• A list of options associated with these components. Typically this is used
to store options for calculating physical properties for mixtures of these
components
A component set is a simplified version of a component list which does not
include a list of physical property options.
In general you should use a full component list when using a physical
properties package such as Aspen Properties, and a component set if you are
not using a physical properties package.
MODEL FeederPP
:
Z(ComponentList) AS Molefraction;
:
END
MODEL HeatExchanger
HotSide, Coldside AS ComponentListName;
ColdSideInlet AS INPUT Process (ComponentList:
ColdSide);
ColdSideOutlet AS OUTPUT Process (ComponentList:
ColdSide);
HotSideInlet AS INPUT Process (ComponentList: HotSide);
HotSideOutlet AS OUTPUT Process (ComponentList: HotSide);
:
:
CALL (ColdSideOutlet.H) = pEnth_Mol (ColdSideOutlet.T,
ColdSideOutlet.P, ColdSideOutlet.z) ColdSide;
StringParameter Attributes
IntegerParameter
RealParameter Attributes
LogicalParameter Attributes
Lower The lower bound for the variable value. -1.0e37 Real
Scale The scaling factor for the variable value 1.0 Real
used by the solver
Spec A string of text that contains the “Free” Text – must be one of:-
specification for the variable
“Free”, ”Fixed”,
”Initial”, ”RateInitial”
Upper The upper bound for the variable value 1.0e37 Real
You can use the full path for the Uom object instead of defining the UOM
variable. For example:
bOK = ActiveDocument.Uom.AddPhysicalQuantity("Length", "m")
If you define UOM once, you can save typing the full path each time.
The conversion is made using the Multiplier and Offset in the following
equation:
BaseUnit = Multiplier * UomSymbolUnit + Offset
bOK = UOM.AddUomSet("SI")
bOK = UOM.AddUomSet("Metric")
bOK = UOM.AddUomSet("Eng")
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 using the ControlSignal stream type, the variables PV,
PVMin and PVMax are all displayed in the same units of measurement as the
connected variable.
Model RatioBlock
input1 as input RealVariable(fixed);
input2 as input RealVariable(fixed);
ratio*input2 = input1;
prod = input1*input2;
End
Notes:
Model RatioBlock
input1 as input RealVariable(fixed);
input2 as input RealVariable(fixed);
Defining Tasks
A task is a set of instructions that defines a sequence of actions that take
place during a dynamic simulation. For example, you can use tasks to:
• Define disturbances in feed conditions or controller set points at a pre-
defined time
• Trigger events when certain conditions are met. For example, you can use
a task to provide basic level control in a tank by closing an output valve
when the fluid level falls below a certain value.
You can define two kinds of tasks:
Event-Driven Tasks
Event-driven tasks are associated with a defined event and execute when that
event occurs.The events with which a task can be associated are:
Event Example
A specified simulation time AT 20.0
• BEFORE INITIALIZATION
• AFTER INITIALIZATION
• BEFORE STEP
• AFTER STEP
• AFTER ERROR
The associated task triggers when the system generated event occurs. That
is; before or after simulation initialization, before or after a dynamic run takes
a step, or when any error occurs.
Callable Tasks
Callable tasks are called by other tasks instead of being triggered by an
event. You can optionally define callable tasks with parameter call lists, with
the calling task passing the parameter values.
You can make calls to tasks within models, to tasks in a tasks folder, or other
tasks in your flowsheet. You cannot call a task in a model from a flowsheet
task, and you cannot call tasks in the flowsheet from a task in a model or task
folder.
TASK SubTaskA
Input1.Flow: 4.0;
END
TASK SubTaskB
Input1.Flow: 1.0;
END
HeatIn: Q + RANDOM(10,2.0,UNIFORM);
The IF Construct
Use the IF construct to control which statements are executed dependant
upon whether a conditional expression is true or false.
IF Construct Syntax
The IF construct has the following syntax:
IF Condition THEN
TaskStatements1
ELSE
TaskStatements2
ENDIF
IF Construct Remarks
The ELSE and TaskStatements2 are optional.
Note:
PARALLEL Syntax
The syntax for grouping actions in parallel is:
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 MyTask
s2 as StringParameter;
s2: CONVERTTO(string, Input1.Flow);
print "Value of Input1.Flow is " + s2;
END
Note that CONVERTTO cannot be used directly within a PRINT statement.
PAUSE Syntax
The syntax for suspending a simulation is:
PAUSE;
When a pause statement executes, the simulation is placed in a paused state,
but remains active, and can trigger again once the run is continued. If the
simulation is then run on from the paused time, the task continues execution
at the next statement.
INVOKE Syntax
INVOKE (Output1, Output2, ...) : ScriptLocation.ScriptName
(Input1, Input2, ...);
INVOKE ShowForm;
Variable.Attribute : value;
Assigns a value to variable or parameter.
IF Condition THEN
TaskStatements1
ELSE
TaskStatements2
ENDIF
Controls task statements based on a condition.
PARALLEL
CALL Task1;
CALL Task2;
:
ENDPARALLEL;
Runs tasks in parallel.
PAUSE;
Pauses the task and the simulation. The task resumes if the simulation is
continued.
WAIT RealExpression;
Suspends the execution of the task for the number of time units.
CONSTRAINT
HX1.Q = -HX2.Q;
END
The next example shows how to specify values for the ambient temperature
variables within three blocks in the flowsheet.
CONSTRAINT
C1.Tamb = 20, Fixed;
C2.Tamb = 20, Fixed;
C3.Tamb = 20, Fixed;
END
The last example shows how to declare a new flowsheet variable which
represents ambient temperature, and equates the ambient temperature to
the local values within blocks in the flowsheet.
CONSTRAINT
Tamb as Temperature;
Tamb: 20, Fixed;
C1.Tamb = Tamb;
C2.Tamb = Tamb;
C3.Tamb = Tamb;
END
Defining Optimization
Constraints
Optimization is used to manipulate decision variables to calculate the
maximum or minimum possible value of an objective function. Typically you
When using constraints you should take care to ensure that there is a feasible
solution within the constraints you specify. This is particularly important when
using equality constraints.
When performing a dynamic optimization the constraints defined in the
Flowsheets Constraints section must only be satisfied at the end of the
dynamic run. They are not applied at other times during the dynamic run. In
other words, they are end point constraints.
Notes:
• At most you can have one final time and one path constraint
active on the same variable.
Path Constraints
These are constraints on free variables at a set of finite interior points in time
over the time horizon of your dynamic optimization simulation. They can be
used to discretize constraints on variables active over all time into a series of
finite interior point constraints. For an example, refer to the Dynamic
Optimization Example.
To define Path Constraints for a dynamic optimization simulation:
1 Select “Path” in the Constraint Type column of the Dynamic Constraints
grid for the variable you wish to define a path constraint.
2 Click Edit.
3 In the Interior Points dialog, choose how many interior points per element
you want to use. This is the finite number of points per element at which
you wish to constrain the variable. The points are spread evenly through
each element, for example: if you choose 1, the constraint is at the end of
each element; if you choose 2, the constraint is at 0.5 through the
element and at the end of the element, and so on.
4 In the Interior Points dialog, specify the upper and lower bounds you want
to constrain the variable to at each interior point.
5 Use the Active switch to define which elements and interior points you
want to constrain the variable. For example, you may only wish to
constrain variable during the first few elements of the simulation.
Notes
• The default values of the upper and lower bounds are the
variables upper and lower bounds.
If you do not inherit from an existing variable type, the new variable type will
inherit its property values from the built in RealVariable variable type. For
information on RealVariable, see Chapter 1.
To change a property value from that in the inherited type, assign a value to
that property in the variable type definition.
Properties which you can change are:
You can also add properties of type Integer, Real, Logical or String to your
own variable types. These added properties can only be accessed through the
automation interface e.g. from scripts or an external Visual Basic application.
These can be useful if you need to track some additional variable property in
your external application.
VARIABLE Examples
The first example shows the definition of the variable type Temperature:
VARIABLE Temperature
PhysicalQuantity: "Temperature";
Value: 25;
Lower: -246;
Upper: 5000;
A list of valid values can only be supplied for parameter types that inherit
from IntegerParameter or StringParameter. This list is optional.
MODEL Tank
Geometry AS GeometryParameter("Cone");
:
IF Geometry == "Cone" THEN
Volume = PI/3 * Radius * Radius * Height;
ENDIF
IF Geometry == "Rectangular" THEN
Volume = Length * Length * Height;
ENDIF
END
Once the model is instanced as a block you can change the parameter
Geometry from the AllVariables Table for that block. The table will show a
drop down list of the value values.
PORT Syntax
PORT PortType USES InheritedPortType
PortVariableName1 AS VariableType1;
PortVariableName2 AS VariableType2;
:
END
PORT Remarks
You can optionally 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 type.
PORT Examples
The following example shows the definition of the port type Material. This
passes a molar flow rate and a temperature:
PORT Material
F AS Flow_mol;
T AS Temperature;
END
The next example shows that the definition of port type NewMaterial inherits
the properties of the previously defined type Material. The port variable P is
added to the list of values communicated by the port:
STREAM Syntax
PRIVATE STREAM StreamType USES InheritedStreamType
StreamStatements
END
STREAM Remarks
The statements you can use in a stream type definition are the same as those
in a model definition, except that:
• You must define at least one port, but not more than two ports. Most
streams connect two blocks together, and therefore need two ports. You
can choose to define special stream types for feeds or products that have
only one port.
• If you define two ports, one must be an INPUT port, and the other an
OUTPUT port.
If you use the optional PRIVATE keyword and create a library that includes
the stream type, the user of the library cannot:
• See the stream type in the Simulation Explorer view.
• Export the stream type with a Save.
• See the stream type equations and variable names in a Diagnostic view.
• PRIVATE can be used to protect proprietary information contained within
the stream type definition.
STREAM Example
In this example, a stream is defined as having a potential loss of fluid
through a leak. By default the leak flow is fixed and has a value of zero.
STREAM LeakyStream
FLeak AS Flow_mol (Fixed, 0);
StreamInput AS INPUT Material;
StreamOutput AS OUTPUT Material;
StreamInput.F = StreamOutput.F - FLeak;
END
Procedure Syntax
PROCEDURE ProcedureName
CALL: "RoutineName";
Keyword Meaning
PRECALL The procedure is called before the run starts, in the
following situations:
• After loading a new simulation.
• After changing the structure of a simulation.
• Re-starting a simulation after an Interrupt.
STRUCTURE Remarks
You can include statements in the structure description to define different
aspects of the structure. Structures do not need to contain specific elements.
For example, you can define a model with no equations and use inheritance to
define different structures with different sets of global data.
You can add the following statements to your structure definition:
• Parameters.
• Sets.
• Variables.
• Ports.
• Equations.
• Procedure calls.
• Sub-structures (instances of other structures).
• Forms and scripts associated with this structure type.
You can mark the structure as PRIVATE. This means that if the structure is
used in a library, the user of the library cannot:
• Display the structure type in the Simulation Explorer view.
• Export the structure type with a Save.
• See the structure type equations and variable names in a Diagnostic view.
Example
EXTERNAL qualifier.
Using EXTERNAL to reference structure instances.
You can use the EXTERNAL keyword to define a reference to an instance of a
structure type from which global data can be obtained.
e.g. Rxn1 as External Powerlaw;
where Powerlaw is the name of a structure type and Rxn1 is the reference
you will be using in this model. Having defined this reference you can use it to
access parameters and variables in the structure type.
e.g. Rxn1.HeatofReaction.
Models describe the behavior of a unit operation or other item that you wish
to include in your simulation flowsheet. This chapter describes how to define
models. The following topics are covered:
• Model Syntax.
• Declaring variables.
• Declaring ports.
• Writing equations.
• Equations with array variables.
• Conditional equations.
• Using sets in conditional expressions.
• FOR loops and the ForEach operator.
• Equations that call procedures.
• Equations that refer to port variables.
• CONNECT keyword.
• LINK keyword.
• Connectivity rules.
• Using SIGMA.
• Using the SIZE function.
• Assigning specifications.
• Referring to sub-models.
• Using SWITCH.
• Using external properties to write sub-models.
• Using virtual types in sub-models.
If you use the optional PRIVATE keyword and create a library that includes
the model, the user of the library cannot:
• See the model in the Simulation Explorer view.
• Export the model with a Save.
• See the model equations and variable names in a Diagnostic view.
PRIVATE can be used to protect proprietary information contained within the
model.
Model statements can include some or all of the following:
• Variable, Parameter and Set declarations.
• Port declarations.
• Equations.
• Procedure calls.
• Instances of other models (sub-models).
• Connections between sub-models.
• Links between sub-models and ports.
• Assignments to variable or parameter properties.
These are described in more detail in the following sections.
In the next example, no specification keyword has been used. This means the
number in brackets is assigned to the value property of the variable. The
direction keyword is included in the statement, which means the value of
TFeed can be passed to another block on the flowsheet using the built-in
stream type ControlSignal.
TFeed AS OUTPUT Temperature (373.0);
The following example shows two variables defined in one statement. Both
variables have the default value and the lower bound altered from the values
inherited from variable type Temperature.
TFeed, TProd AS Temperature (373.0, Lower:273.0);
The last example shows how to define a variable to use the units of
measurement of another variable. You can also see this feature in use in the
PID controller model in the Modeler library.
If the variable, PV, is connected to a level variable in a tank, using a
ControlSignal stream, then PV will automatically be displayed in the units of
measurement of the level variable. The UseUOMof keyword is used to also
ensure that SPRemote will be displayed in the units of measurement of the
level variable.
PV AS Input Control_Signal (Description:"Process
variable");
SPRemote AS Input Control_Signal (Fixed,
Description:"Remote
Model Heater
:
Input1 AS INPUT Material;
Output1 AS OUTPUT Material;
Input1.Flow = Output1.Flow;
:
End
Property Description
IsConnected A logical parameter that indicates whether a stream
is connected to the port.
END
The following example shows how to use two different port component lists:
PORT Process
Flow AS Flow_Mol_Liq;
x(ComponentList) AS Molefraction;
END
MODEL ComponentMixer
MODEL ddd
Inp AS INPUT MULTIPORT OF FlowPort;
Out AS OUTPUT FlowPort;
FOR c in Inp.componentlist DO
IF (NOT Inp.F(c).IsMatched) THEN
Inp.F(c) = 0.0;
ENDIF
ENDFOR
END
Using Multiports
You can define a collection of ports, which is known as a multiport. A
multiport allows multiple stream connections to be connected to it. A
multiport can use the same port types as a normal port.
Multiport Syntax
The syntax for defining a multiport in a model is:
PortName AS DirectionType MULTIPORT OF PortType
(MIN_CONNECTIONS: mincon, MAX_CONNECTIONS: maxcon);
Multiport Remarks
A multiport contains additional properties about the current connections to it.
You can use these in your model equations. The additional properties are:
Connection Syntax
The variables in the port are accessed using the following syntax:
PortName.CONNECTION(StreamName).PortVariable
As Connection is an array, you can use the SIGMA function to sum the values
of PortVariable for all connections made to that port. If the PortVariable is
also an array, you can use SIGMA in the following three ways.
The first way sums all combinations of Connection(i).ArrayVariable(j).
Sum = SIGMA(PortName.CONNECTION.ArrayVariable);
For a detailed explanation, see:
SIGMA for Multidimensional Arrays Examples.
Using SIGMA a second way, for each element of the array variable, the values
of that ArrayVariable in all connections made to the multiport are summed:
FOR i IN ArrayIndexSet DO
Sum(i) = SIGMA(PortName.CONNECTION.ArrayVariable(i));
ENDFOR
Using SIGMA a third way , for each connection made to the multiport, the
values of all the elements of the ArrayVariable are summed:
FOR i IN PortName.ConnectionSet DO
Sum(i) = SIGMA(PortName.CONNECTION(i).ArrayVariable);
ENDFOR
Multiport Example
The following model represents a stream mixer which can be used to mix up
to 10 streams into a single outlet stream. The first equation sums the values
of Flow across all connections to Input1. The FOR loop then performs a mass
balance for each component to calculate the outlet composition. The sigma
function sums the product of flow and fraction of a component across all
connections.
PORT Main
Flow AS Flowrate;
Z(ComponentList) AS Fraction;
END
MODEL MULTIMIX
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
END
Note that in this example, if there are three streams S1, S2 and S3 connected
to the port Input, and each of these carries water only, then the equations
produced by this model are:
Output1.Flow = Input1.Connection("S1").Flow +
Input1.Connection("S2").Flow +
Input1.Connection("S3").Flow;
Equation Syntax
EquationName: ExpressionA = ExpressionB;
Equation Remarks
You can have any number of variables on either side of the equality sign. You
should arrange equations to improve the numerical solution of the simulation
for robustness and speed, for example avoid dividing by a variable whose
value may go to zero during solution.
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.
- x-y Subtraction
- -x Negation
* x*y Multiplication
/ x/y Division
Conditional Equations
You can use conditionals for two purposes:
To switch between different equations during a simulation dependant upon
the values of certain variables.
To make structural changes to the equations and/or assignments used
depending upon the values of parameters or other aspects of the model
configuration.
Conditionals are defined using the following syntax:
Operator Meaning
== (two equals signs) Equal to
OR Logical OR function
Notes:
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
FlowIn(ComponentList) AS Flow_Mol;
FlowOut(ComponentList) AS Flow_Mol;
Split(ComponentList) AS Fraction;
FOR I IN ComponentList DO
FlowIn(I) = Split(I) * FlowOut(I);
Split(I): 0.33, FIXED;
ENDFOR
END
If ComponentList is defined as the set ["N2", "O2" and "CO2", ] the index
counter in the FOR loop, I, takes the value "N2", "O2" and "CO2", and three
equations and three assignments are created.
Note that for this example, it is also possible to directly write a vector
equation without using a FOR loop:
FlowIn = Split * FlowOut;
In this case, the number of equations created is based on the intersection of
the sets defining the variables in the equation. As all three array variables are
indexed by the same set, an equation is generated for each component.
The next example assigns a value of 0 to the flow rate of all components
except water:
for i in Componentlist - ["H2O"] do
F(i): 0;
endfor
The next example shows how to create a number of instances of a tray model
within a column model, and how to simplify the repetitive CONNECT
statements that connect the trays.
The loop repeats for all but the top and bottom stages in the column..
MODEL Column
NStage AS IntegerParameter(20);
StageSet AS IntegerSet([1:NStage]);
Stage(StageSet) AS Tray;
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
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));
C(1,2) = sigma(A(1,1)*B(1,2), A(1,2)*B(2,2));
C(2,1) = sigma(A(2,1)*B(1,1), A(2,2)*B(2,1));
C(2,2) = sigma(A(2,1)*B(1,2), A(2,2)*B(2,2));
The following example equates the sum of the first three values in an array to
zero:
sigma(foreach (i in set) x(i)) = 0;
When set = [1:3] this is equivalent to:
sigma(x(1), x(2), x(3)) = 0;
The second example sums array values across multiple sub-models:
sigma(foreach(i in set1, j in submodel(i).set)
model(i).x(j)) = 0;
When set1 = ["a", "b"], submodel("a").set = [1,2] and submodel("b").set =
[3,4] , this is equivalent to::
Sigma(model("a").x(1),model("a").x(2),model("b").x(3),
model("b").x(4)) = 0;
The third example sums values from two sets:
sigma(foreach(i in set1) x(i), foreach(i in set2) y(i)) =
0;
When set1 = ["a", "b"] and set2 = [1,2] the result is:
sigma(model("a").x(1),model("a").x(2),model("b").x(1),model
("b").x
(2)) = 0;
Procedure pTestArray
library: "testarray.dll";
call: testarray;
implementation: subroutine "testarray.f";
language: "fortran";
inputs: real(*);
Model TestArray
C([1:3], [1:5]) as realvariable (fixed);
x as realvariable;
x1 as realvariable;
// a column of C
call (x) = pTestArray (C(1, [1:5]));
// a row of C
call (x1) = pTestArray (C([1:3], 1));
End
MODEL SimpleValve
END
CONNECT Keyword
You use connection statements within a model to connect either ports of sub-
models, or variables of sub-models . Ports are connected through streams.
For information on when to use CONNECT, and how to connect ports and
variables, see Connectivity Rules.
CONNECT Remarks
When connecting ports, one of the ports must be an input, and one of the
ports must be an output. If you do not specify a stream, the ports are
connected with a stream of an automatically generated name using the built-
in stream type Connection. The Connection stream equates port variables of
the same name and defines them as having equal values.
This means you can have fewer equations in your simulation than you
expected, because the stream does not create an equivalence equation for all
the variables in the ports. This usually makes the flowsheet under-specified.
If you find your simulation is under-specified when you believe that the
models are correctly defined, check for port mis-matching.
If you use the CONNECT statement to connect variables in a flowsheet, you
must use the built-in stream type ControlSignal.
All input and output variables in sub-models are accessible in the containing
model. You do not need to use LINK to make these accessible from the
containing model.
CONNECT Restrictions
The following restrictions apply when using CONNECT:
a([1:nStage]) as ModelType1;
b([1:nStage]) as ModelType2;
connect a.outlet and b.inlet; // Not valid !
• However, you can use a CONNECT statement to connect arrays of
variables or ports using a FOR loop, as shown in the next example:
a([1:nStage]) as ModelType1;
b([1:nStage]) as ModelType2;
FOR i IN [1:nStage] DO
connect a(i).outlet and b(i).inlet; // Valid
ENDFOR
FOR i IN (1:a.nStage] DO
FOR j IN [1:a(i).nArraySize] DO
connect a(i).x(j) and b(i).y; // Not valid !
ENDFOR
ENDFOR
CONNECT Examples
This example connects the ports Valve.Outlet and Tank.Inlet with a stream of
type Connection, and gives this connection stream the name S1:
S1: CONNECT Valve.Outlet AND Tank.Inlet;
In the next example, the stream Stream1 is declared, and then used to
connect Valve.Outlet and Tank.Inlet:
Stream1 as Connection;
CONNECT Valve.Outlet AND Tank.Inlet WITH Stream1;
The final example shows the output variable Tank1.Temp and the Input
variable C101.PV connected with the built-in stream type ControlSignal:
CONNECT Tank1.Temp AND C101.PV;
LINK Syntax
Name: LINK PortName AND SMName.SMPortName;
LINK Remarks
Use the LINK keyword to connect ports in a sub-model to those in the
containing model. Use the CONNECT keyword for connections between sub-
models within the containing model.
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:
LINK Examples
In the following example, the LINK keyword is used to connect a port from
the model Tank to a port of the model MultiTank. A number of Tank models
are instanced within the model MultiTank. This method enables you to group
models within one containing model.
MODEL MultiTank
END
You can use LINK to connect to multiports, either where the containing model
has a multiport and/or the sub-model has a multiport.
A common situation where you might link to a multiport is where you have a
distillation column model that contains an array of stage sub-models. You can
define the feed to the column as a multiport. This allows multiple feeds to the
stages within the column.
MODEL Column
.
Feed AS INPUT MULTIPORT OF Material;
StageMap(Feed.ConnectionSet) AS IntegerParameter(1);
NStages AS IntegerParameter(20);
Stage([1:Nstages]) AS TrayModel;
FOR i IN Feed.ConnectionSet DO
FeedStage: LINK Feed.Connection(i) AND
Stage(StageMap(i)).TrayFeedPort;
ENDFOR
.
END
In this example, the key is the array StageMap. You can define the stage
numbers in StageMap for each of the connections made to the column. For
example, if you have three connections to the column's Feed port, you can
define which stage these connect to, so that StageMap is an array of three
elements indexed by the connections to the Column. For example:
StageMap("S1").Value: 5;
StageMap("S2").Value: 11;
StageMap("S3").Value: 14;
EXTERNAL Keyword
The External keyword can be used in a definition within a model. The
behaviour depends on the type being used for the definition.
If the type is a variable type then the variable definition is a reference to a
variable in the parent of this model.
If the type is a structure type then the parameter defined can contain a
reference to an instance of the structure type.
e.g. Rxn1.HeatofReaction
where HeatofReaction is a variable or parameter in the structure Powerlaw.
This could then be used wherever local parameters or variables are used.
However note you cannot assign a value to a parameter or variable in a
structure from a reference. You can only do that in the structure type itself.
See How to use structures and Defining Structure Types.
Connectivity Rules
Connect ports in models as shown in the following table:
OUTPUT INPUT
OUTPUT OUTPUT
SIGMA Syntax
The syntax for using SIGMA is:
SIGMA (Expression1, Expression2, …);
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 across ports within a multiport.
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
Another way you could write the expression is to list the array elements
explicitly:
SIGMA(x("N2"),x("O2"),x("CO2")) = 1.0;
The following statement is equivalent to the previous SIGMA expression:
SIGMA(x(ComponentList)) = 1.0;
You can use SIGMA on the whole array, or a selected slice of an array as in
the following example:
x = 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.
MODEL Tank
M, Mc(ComponentList) AS Holdup;
Total AS RealVariable;
Ntank AS IntegerParameter(10);
Tank([1:Ntank]) AS MultiMixTank;
CONNECT ...
Sum1 = SIGMA(Tank.Input1.Connection.z *
Tank.Input1.Connection.Flow)
END
In this case, the sigma expression has to evaluate the expression:
SIGMA(Tank([1:Ntank]).Input1.Connection(
ConnectionSet).z(ComponentList) *
Tank([1:Ntank]).Input1.Connection(ConnectionSet).Flow)
As in the previous example, all combinations of model array, multiport array
and component array, are calculated and summed.
Use the ForEach operator to override the default expansion of arrays within
SIGMA. For more information, see the ForEach Operator on page 4-103.
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;
:
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 a default value for the
molefraction array variable.
Assigning Specifications in
Models
You can assign a specification to a variable either when you declare it, or after
its declaration. Parameters do not have specifications, as their values are
always known. You can also specify a value for a variable or parameter when
you declare it or afterwards.
Referring to Sub-Models in a
Model Definition
You can refer to variables and parameters in sub-models directly from a
model. This is convenient when using submodels to perform common
calculations.
Vol AS Volume;
R AS Length (Fixed);
h AS Length (Initial);
PiValue AS RealParameter;
VolumeCalc: Vol = PiValue * R^2 * h;
END
MODEL Tank
k AS Constant (Fixed);
height AS Length;
Radius AS Length;
PI AS RealParameter (3.14159);
END
In the following example, the sub-model used to calculate density is
dependent on the parameter Material. If Material is given the value Alkali the
model will use the RhoAlkaliCalc submodel, otherwise it will use the
RhoAqueousCalc sub-model:
MODEL Tank
convert as FractionToFlow;
:
End
Now there is only one copy of the variables TotalFlow, Flow, and X.
TotalX as flow_mol;
TotalY as flow_mol;
FlowX(componentlist) as flow_mol;
FlowY(componentlist) as flow_mol;
X(componentlist) as fraction;
Y(componentlist) as fraction;
End
Since ValueType has not been redefined, T_Av.Average is a simple
RealVariable. This means that it will appear on tables and plots with no units
of measurement. The ValueType can be redefined by using the IS operation in
the declaration of the sub-model, for example:
Model Pipe
End
Here ValueType has been redefined to be Temperature (which is derived from
RealVariable). Consequently, T_Av.Average is created as a Temperature
variable rather than as a simple RealVariable, so it will show temperature
units of measurement on tables and plots.
Using SWITCH
Use switch to define different sets of equations that will be used dependant
upon the state of your model. You define an initial state, and the conditions
under which the state will change.
Switch is active in all run modes, but will probably be most useful in dynamic
simulations.
ENDSWITCH
Switchname .................... Optional name you can give to the Switch definition.
INITIAL........................... The state that applies at the start of the simulation
run. Use the Initial keyword on only one state
definition.
Note: One of the states you define in a SWITCH
definition must be flagged as the initial state.
StateName ...................... Unique name of a state within the current Switch
definition.
SwitchStatements ........... Equations that apply when in the state you are
defining.
Condition Condition for switching from the current state to the
new state.
NewState ........................ Name of the new state to switch to if the condition is
met.
SWITCH Remarks
SWITCH provides a quick and easy way for you to describe both reversible
and non-reversible changes in your process.
Note that 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.
SWITCH Examples
The following example shows how to model a non-reversible action using a
switch definition. The switch is non-reversible because there is a condition
that enables the state Normal to switch to Burst, but there is no condition to
reverse this switch.
SWITCH
INITIAL STATE Normal
VentFlow = 0;
IF VesselPres > 8.5 STATE: Burst;
ENDSTATE
End
Notes:
Domain Syntax
Domain, Domain, … AS
DomainModel OF RealParameterType (Property:
PropertyValue, ... );
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.
4 When changes are complete press the now active “Interpolate” button:
What is Supported?
The domain interpolation will support dependent distributions and variable
arrays of 1 to 3 dependent dimensions.
Dependent distributions and variable arrays at the same model level as the
domain and lower will only found and interpolated. If the simulation message
window print level is medium or higher, messages indicating the dependents
found will be displayed.
When creating variable arrays to represent distributed variables the array
dimensions must be explicitly declare using the either the Interior set or
EndNode parameter of the domain. For example:
//Declare domain
x As Domain;
//Valid array declarations
Valid1([0:x.EndNode]) As RealVariable;
Valid2(x.Interior) As RealVariable;
Valid3([0]+x.Interior+x.EndNode) As RealVariable;
The following type of array declaration is not supported by the interpolation
scheme:
//Declare domain
x As Domain;
//Declare set
MySet As IntegerSet([0:x.EndNode]);
Model Main
//Declare domain
x As Domain;
//Declare variables and distributions
Tdist As Distribution1D(X Is x);
Tarray([0:x.EndNode]) As RealVariable;
//Declare array of submodels
ModelArray([0:x.EndNode]) As MySub;
//Model equations
:
:
End
In the above example the interpolation scheme will correctly interpolate
distributions and arrays Tdist, Tarray, ModelArray.T1D and ModelArray.T2D.
However ModelArray.T3D will not be interpolated as it contains 4 dependent
dimensions.
The interpolation scheme will interpolate variable values, time derivatives,
spatial derivatives and integrals
Interpolate Boolean Used to execute the interpolation of the previous domain mesh
with respect to the new domain mesh configuration.
• Distribution1D
• Distribution2D
• Distribution3D
The distribution sub-models that you declare in your process model represent
distributed variables. They provide access to the values of the distributed
variable at each point of the discretized spatial domain(s). To refer to the
value of a particular distributed variable at a specific location (for example,
node i in a 1D domain), use Distribution.value(i) or Distribution(i) for short.
Using profile plotting, you can view these distributed variable values as your
Y-axis variable along the length of the discretized domain. As your X-axis
variable, use the Value array in your domain (for example,
XDomain.Value([0:XDomain.EndNode]) or XDomain([0:XDomain.EndNode])
for short).
The built-in distribution models also contain the logic for calculating partial
derivatives and integrals. More specifically, they calculate the derivatives and
integrals of the distributed variables with respect to the independent spatial
variables. First and/or second derivatives are calculated depending on the
order of the PDE problem (as defined by the highest-order derivatives in the
PDEs). Only first derivatives are considered for problems of order one. Both
first and second derivatives are considered for problems of order two. The
To compute single and double integrals for T distributed in 2D, use the
following StringSet syntax for the Integrals property:
T AS Distribution2D(Integrals:[“idx”, “idy”, “idxdy”]) of
Temperature;
Notes:
Model Conductivity
XDomain as external Domain;
T as external Distribution1D;
XDomain and T can then be used in the Conductivity model as normal.
φt = Time derivatives.
The partial derivatives with respect to the spatial variables are often written
as follows:
∂φ ( x , t ) ∂ 2φ ( x , t )
φx = , φ xx =
∂x ∂x 2
The well-known Method of Lines (MOL) is used to solve the time-dependent
PDE systems. It is a two-stage process that discretizes in space and leaves
the time domain continuous, thereby converting the IPDAE system to a DAE
system with respect to time.
φt = Time derivatives.
In general, the coefficients can be functions of all the variables and their
derivatives, for example:
a = a (t , x , φ , φ t , φ x )
The following is an example of a widely-used, linear second-order PDE:
f = aφ + bφ t + cφ x + dφ xx
Where a, b, c, and d are a function of (t,x).
To represent a distributed parameter problem fully, the model also requires
auxiliary conditions. These are of two kinds, boundary conditions and initial
conditions. The latter is used when time is one of the independent variables.
2 =1 --- [1:EndNode-1]
2 --- =1 [1:EndNode-1]
• Use the Interior set for writing (that is, indexing) your PDE model
equations and initial conditions. Failing to do so can lead to
specification problems (that is, non-square systems) for 2nd-order PDE
problems, especially when using finite difference methods with multiple
sections or OCFE methods with multiple elements. Using the Interior set
allows you to switch between finite difference and OCFE methods without
having to modify your PDEs. The underlying requirement that finite
difference and OCFE methods inherently require derivatives and model
X As Domain (NumSections:2);
C As Distribution1D (XDomain Is x);
W As Distribution1D (XDomain Is x);
For i In X.Section(1).Interior Do
W(i) = 2*C(i);
EndFor
For i In X.Section(2).Interior Do
W(i) = 3*C(i)^4;
EndFor
LaPlace’s Equation
∂2u ∂2u
+ =0
∂x 2 ∂y 2
// Modeling Language
u(X.Interior,Y.Interior).d2dx2 +
u(X.Interior,Y.Interior).d2dy2 = 0.0;
Poisson’s Equation
∂2u ∂2u
+ 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
Tip The range of each domain of every distributed variable in a PDE must be
the same as shown in the following heat transfer equation:
// Heat transfer equation: Time-dependent second order PDE.
// PDE is specified over the domain’s interior.
$T(X.Interior, Y.Interior) = D * T(X.Interior,
Y.Interior).d2dx2 + D * T(X.Interior, Y.Interior).d2dy2;
On the other hand, the following PDE example is not legal because the range
of the X domain for the $T variable is not consistent with the range of X
domain for the distributed variables on the right-hand side of the equation:
// Heat transfer equation: Time-dependent second order
partial differential
// equation. PDE is specified over the interior of the
domain.
$T([0]+X.Interior, Y.Interior) = D * T(X.Interior,
Y.Interior).d2dx2 + D * T(X.Interior, Y.Interior).d2dy2;
∂T a ∂ ∂T q
= r +
∂t r ∂r ∂r c p
where T is temperature, r is radial position, a is the thermal diffusivity, q is
the heat duty, and Cp is the heat capacity. Due to the use of the conservative
term:
∂ r∂T
∂r ∂r
it is necessary to introduce a distribution for temperature and another one for
the inner radial flux expression (for example, rdTdr). For the radial
distribution of T over r, we need first to create a Domain. So we declare:
r as LengthDomain(DiscretizationMethod:"CFD4");
For the temperature, we need a 1D distribution:
T as Distribution1D(XDomain is r) of temperature;
To handle the conservative term we need to create an additional distribution:
for i in r.Interior do
$T(i) = a/r(i)*rdTdr(i).ddx + q/cp;
endfor
Finally, we need the equation to define the additional distribution for the
conservative term:
rdTdr = r*T.ddx;
φt = Time derivatives.
// Initial conditions
T([1: X.EndNode-1]): 10.0;
// Initial specification must only be applied to 'Interior'
// points to avoid over-specification when using OCFE
methods,
// or finite difference methods with multiple sections
T(X.Interior): initial;
End
// Initial conditions
T([1: X.EndNode-1]): 10.0;
// Initial specification must only be applied to 'Interior'
// points to avoid over-specification when using OCFE
methods,
// or finite difference methods with multiple sections
T(X.Interior): initial;
End
The following syntax error message is displayed in the Simulation Messages
window when Aspen Custom Modeler compiles the PDE model shown above:
Model HeatEquation has equations that use variables which
do not exist:
HeatEquation.T.d2dx2(8) - Failed path is (8)
To avoid this error, you can replace the boundary condition involving d2dx2
with a polynomial approximation as discussed above.
Specifying Integrals
You can specify integrals in your PDEs using the id* array for single integrals,
the id*d* array for double integrals, and the idxdydz for triple integrals,
where * can be x, y, or z depending on the dimensionality of your
distribution. The following table shows valid values for integrals.
The indices of the integral arrays range from 0 to EndNode. The convention is
that the integral over element i-1 to i is stored in location i in the integral
array. By default, the integral value for node 0 is 0.0. For example, the
integral for the 1D variable T over the element i-1 to i is stored in T(i).idx. By
default, T(0)=0.0.
Since an integral is calculated over each individual element in a distribution,
you can compute the integral over the entire distribution by summing up the
individual contributions using the SIGMA operator as shown here:
Integral = SIGMA(T.idx);
Note that the summation above is done from 0:X.EndNode and not over the
Interior set since we need to sum up the integrals over all elements. If the
Interior set is used, the calculated integral is incorrect when using an OCFE
method since the Interior set is not full (i.e., does not contain all nodes).
X as LengthDomain(Length:10);
T as Distribution1D(XDomain is X, Integrals: ”idx”) of
Temperature;
Tavg as Temperature;
Tavg = SIGMA(T.idx)/X.Length;
The previous example can be extended to 2D in the following way:
X, Y as LengthDomain(Length:10);
T as Distribution2D(XDomain is X, YDomain is Y, Integrals:
”idxdy”) of Temperature;
Tavg as Temperature;
Tavg = SIGMA(T.idxdy)/(X.Length*Y.Length);
Model CylindricalTemp
Radius as lengthparameter(1);
L as lengthparameter(2);
pi as realparameter(4*atan(1));
r as lengthdomain(length:Radius);
z as lengthdomain(length:L);
∂φ 1 [ n ]]
= A φ
∂ x ah
∂ 2φ 1 [ n ]]
= B φ
∂ x 2 bh
Where:
∂φ
= Derivative vector.
∂x
φ = Dependent variable vector.
Remarks
The finite difference methods are based on the assumption of uniform grids.
PDE LHB Sectio Section Section Sbound Section Section Sectio RHB
Order Node 0 n1 1 1 Node 4 2 2 n2 EndNo
Node Node 2 Node 3 Node 5 Node 6 Node de
1 7
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 Section Section Section Sbound Section Section Section RHB
Order Node 0 1 1 1 Node 4 2 2 2 EndNode
Node 1 Node 2 Node 3 Node 5 Node 6 Node 7
1-ddx FFD2 CFD2 BFD2 BFD2 BFD2 CFD2 BFD2 BFD2 BFD2
2-d2dx2 None CFD2 BFD2 BFD2 ddx Cont CFD2 BFD2 BFD2 None
PDE LHB Section Section Section Sbound Section Section Section RHB
Order Node 0 1 1 1 Node 4 2 2 2 EndNode
Node 1 Node 2 Node 3 Node 5 Node 6 Node 7
1-ddx FFD2 CFD2 CFD2 CFD2 BFD2 CFD2 CFD2 CFD2 BFD2
2-d2dx2 None CFD2 CFD2 CFD2 ddx Cont CFD2 CFD2 CFD2 None
PDE LHB Section Section Section Section Sbound Section Section Section Section RHB
Order Node 1 1 1 1 Node 5 2 2 2 2 EndNode
0 Node Node Node Node Node Node Node Node
1 2 3 4 6 7 8 9
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
PDE LHB Section Section Section Sbound Section Section Section RHB
Order Node 1 1 1 Node 4 2 2 2 EndNode
0 Node Node Node Node 5 Node 6 Node
1 2 3 7
1-ddx FFD1 FFD1 FFD1 FFD1 BFD1 FFD1 FFD1 FFD1 BFD1
2-d2dx2 None CFD2 CFD2 CFD2 ddx Cont CFD2 CFD2 CFD2 None
PDE LHB Section Section Section Sbound Section Section Section RHB
Order Node 0 1 1 1 Node 4 2 2 2 EndNode
Node 1 Node Node 3 Node 5 Node 6 Node 7
2
1-ddx FFD2 FFD2 FFD2 CFD2 BFD2 FFD2 FFD2 CFD2 BFD2
2-d2dx2 None FFD2 FFD2 CFD2 ddx Cont FFD2 FFD2 CFD2 None
PDE LHB Section Section Section Section Sbound Section Section Section Section RHB
Order Node 1 1 1 1 Node 5 2 2 2 2 EndNode
0 Node Node Node Node Node Node Node 8 Node
1 2 3 4 6 7 9
1-ddx FFD4 DBFD4 CFD4 UBFD4 UBFD4 BFD4 DBFD4 CFD4 UBFD4 UBFD4 BFD4
2- None DBFD4 CFD4 UBFD4 UBFD4 ddx Cont DBFD4 CFD4 UBFD4 UBFD4 None
d2dx2
As shown in the following tables for OCFE2, OCFE3, and OCFE4, the domain is
divided into a number of elements and orthogonal collocation is applied within
each element. The value of EndNode is equal to the number of elements
times the order of the method, where the order is the number of collocation
points plus one.
By using the Interior set provided, the PDEs in your model are evaluated
automatically at the interior collocation points only. The correct derivatives
are also evaluated automatically.
For 1st-order PDE problems, the first derivatives at the element boundaries
are calculated using the element to the left of the boundary. For 2nd-order
PDEs, the OCFE methods are implemented using the condition that the first
derivatives are continuous between elements. This treatment of the
boundaries between elements gives a solution that is continuous, with
continuous flux, as in the exact solution.
OCFE2
OCFE3
PDE LHB Element1 Element1 Element1 ElemBound Element2 Element2 Element2 RHB
Order Node Coll 1 Coll 2 Coll 3 Node 4 Coll 1 Coll 2 Coll 3 EndNode
0 8
1 ddx ddx ddx ddx ddx Elem1 ddx ddx ddx ddx
2 None d2dx2 d2dx2 d2dx2 ddx Cont d2dx2 d2dx2 d2dx2 None
Mixer-Reactor-Absorber (PDE)
Example Description
This example demonstrates the use of PDE modeling in the dynamic
simulation of an isothermal process flowsheet consisting of a well-stirred
mixing tank, a tubular reactor, and a gas absorber.
Components A and B at a concentration ratio of 2 to 1 in the fresh feed
stream enter the mixer along with the contents of recycle stream. The mixer
outlet stream is sent to the reactor which carries out the gas-phase reaction:
A + B →2C. The reactor product enters the bottom of the countercurrent
absorber where C is partially absorbed in the liquid phase. The remaining gas
is recycled to the mixing tank.
The dynamic simulation requires the simultaneous solution of the ordinary
differential equations (ODEs) describing the mixer and the PDAEs for the
tubular reactor and gas absorber.
This example is taken from the paper by M. Oh and C.C. Pantelides, A
modeling and simulation language for combined lumped and distributed
parameter systems, Computers & Chemical Engineering, Volume 20, Issues
6/7, pp. 611-633 (1996).
Also, refer to the section: Running the Mixer-Reactor-Absorber (PDE) Example
The two 3D profile plots show the concentration profiles of component B and
the temperature profiles at the center of the tubular reactor over time. The
2D plot presents the cooling load and temperature of the cooling medium
over time.
The 3D profile plot shows the crystal population density profiles in the
crystallizer as a function of the crystal size and time. The 2D plots show the
time transients for the magma density and the liquid phase solute
concentration.
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 IPDAE 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.
Modeling Language
Conventions
This section describes the conventions you must follow when writing modeling
language.
Adding Comments
You can use two comment markers:
Symbol Effect
// Everything on the same line to the right of the // characters
is commented out. A second // on the same line has no
effect.
In the model editor, all commented out text appears highlighted in green.
However, note that the text editor does not highlight commented information
after a nested comment.
Comments Examples
The following examples show the use of the comment markers:
// This is a comment
Text Conventions
The conventions used in the documentation that describes the modeling
language are:
Copyright
Version Number: 2004.1
April 2005
Corporate
Aspen Technology, Inc. Phone: (1) (617) 949-1000
Ten Canal Park Toll Free: (1) (888) 996-7001
Cambridge, MA 02141-2201 Fax: (1) (617) 949-1030
Title Content
Aspen Custom Modeler 2004.1 Getting Started Contains basic hands-on tutorials to
Guide help you become familiar with Aspen
Custom Modeler.
Aspen Custom Modeler 2004.1 User Guide Contains a general overview of ACM
functionality and more complex and
extensive examples of using Aspen
Custom Modeler.
parameter types 34
/ solved type 36
/ used as comment symbol 190
C
A C language
ALWAYSCALL keyword 83 modeling language for external procedures
81
Arithmetic operators 99
CHANGESINPUTS keyword 83
Arrays
Comments in modeling language 190
distinguished from sets 22
Comparison operators 102
in equations 100
Compatibility with SPEEDUP 5.5 83
modeling language for 25
ComponentList property 92
values assigned to elements 17
Conditional equations
with many elements or dimensions 106
modeling language for 102
Assignments
sets in 105
array elements 17
CONNECT keyword 114
lists 18
Connection built-in stream type 114
modeling language for 15
Connection port type, built-in 36
statements for 11
Connections
values to variables in tasks 55
modeling language for streams 79
WITHIN and ENDWITH 18
ConnectionSet property 96–97, 119
available 197
ControlSignal built-in stream type 114
B Conventions
documentation 191
Base types 34
modeling language 190
BLOCK keyword 20
Converting
Blocks
strings and integers 26
passing values between 78
units of measurement 38
Built-in types
CONVERTTO operator 27
connection stream type 114
Crystallizer (PDE) Example Description 187
control signal stream type 114
modeling language for 34
Index 189
D Fortran
modeling language for external procedures
Declaration statements 14 80
Definitions, modeling language for re-using 28 Free specification, defined 125
DERIVATIVES keyword 83 Functions
DIFFERENCE operator 23, 108 in sets 23
Discontinuities modeling language for 81
modeling language for 49
Disturbances G
modeling language for 49 GLOBAL qualifier 88
documentation 195
Duplicate names, BLOCK and STREAM 20 H
HIDDEN qualifier 88
E
ENDPARALLEL keyword 61 I
ENDWITH keyword 18
IF keyword
Equations
defining conditionals in tasks 56
calling procedures 110
in conditional equations 102
conditional 102
Indexed assignments 17
logical operators 103
Inheritance
mathematical operators 98
defined 28
modeling language for 98
related types 29
referring to port variables 113
Initial specification, defined 125
switching between 134
INPUT qualifier 88
with array variables 100
IntegerParameter built-in parameter type 35
External procedures
Integers, converting to strings 26
modeling language for 80
IntegerSet 22
External programs
INTERSECTION operator 23, 108
identifying objects from 19
IS keyword 131, 134
EXTERNAL qualifier 129
IsConnected property 92–93
IsMatched attribute 94
F
Index 190
LogicalParameter built-in parameter type 35 P
M PARALLEL keyword 61
Parameters
Matching port variables 94
built-in types 34
Mathematical operators 98
defined 21
MAX operator 99, 108
modeling language for 76
Method of Lines 180
relating to variables 98
MIN operator 98, 108
Path names, assignment lists for 18
Mixer-Reactor-Absorber (PDE) Example
Description 185 Pausing a simulation 63
variables in 88 Ports
Multidimensional arrays, SIGMA for 122 modeling language for 78, 91, 114, 117
Index 191
writing sub-models 129 in models 125
PROPERTIES keyword 83 SPEEDUP
COMPATIBILITY statement 83
Q SRAMP keyword 57
Qualifiers for variables 88 Statements
repeating 106, 109
R syntax for 11
Running the Crystallizer (PDE) Example 188 Sub-models 127, 129, 132
S SystemLibrary library 34
Sets T
arithmetic for 23
Task statements
defined 22, 25
assigning values to variables 55
in conditional expressions 105
IF construct 56
SIZE function 124
modeling language for creating snapshots 60
SIGMA
overview 55
for multidimensional arrays 122
parallel 61
ForEach operator 108
pausing a simulation 63
syntax for 121
printing to Simulation Messages window 62
Simulation Messages window
ramping value of variables 57
task messages in 62
suspending 58
Simulations
Tasks
optimization 69
callable 52
SIZE function 124
modeling language for 49
Snapshots
opening simulations 54
modeling language for 60
task statements 55
Specifications
Testing
Index 192
parameters modeling language 21 W
Text conventions in documentation 191
WAIT statement 58
Types
WITHIN keyword 18
built-in 28, 34
model 87
modeling language for 13, 14
naming conventions 19
parameters 21
physical properties 32
port 78
related 29
stream 79
variable 74
virtual types in sub-models 132
Values
array elements 17
fixed 21
VARIABLE keyword 74
Variables
adding properties to 34, 76, 80
in models 88
modeling language for 74
relating to parameters 98
solved for 36
Vary specification, defined 125
Index 193