GPROMS - Developing Custom Unit Operation Models
GPROMS - Developing Custom Unit Operation Models
Module 201
Modelling prerequisites
Contents
Implementing a lumped model in gPROMS
Motivation
Creating a simple model in gPROMS
Hands-on session
Develop a gas-phase valve model
Using arrays and intrinsic functions in models
Defining a simulation with operating procedures
Hands-on session
Develop a gas-phase CSTR model for the synthesis of methanol and
simulate in steady-state and dynamic modes
Modelling support tools
Extending a model
Handling discontinuities
Hands-on session
Extend the gas-phase CSTR model for the synthesis of methanol
Physical properties (Multiflash)
Hands-on session
Including thermodynamics within gas-phase CSTR model for the
synthesis of methanol
Basic troubleshooting
Hands-on session
Handling common errors
Related gPROMS documentation
Motivation
2. Existing user library models are not suitable for each and
every application
need to customise them
Creating a model
F2in F in NoInput
Mixing tank with:
F1in
Multiple components
Multiple inlets
Component mass balance:
h
dMi NoInlet in in
MT Fj X j ,i F out X i , i 1...NoComp
Fout dt j 1
Total holdup:
NoComp
MT
i 1
Mi
Mass fractions:
Mi MT X i , i 1...NoComp
© Process Systems Enterprise Limited
Creating a model
Mixing tank example
MODEL editor
Project tree
area
PROCESS
editor
Creating a model
Mixing tank example
PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
area AS REAL
density AS ARRAY ( components ) OF REAL
outlet_flowrate_coefficient AS REAL
VARIABLE
inlet_mass_flowrate AS ARRAY ( number_of_inlets ) OF mass_flowrate_gML
inlet_mass_fraction AS ARRAY ( number_of_inlets , components ) OF mass_fraction_gML
outlet_mass_flowrate AS mass_flowrate_gML
mass_fraction AS ARRAY ( components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( components ) OF mass_gML
total_mass_holdup AS mass_gML
total_volume AS volume_gML
height AS length_gML
PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
area AS REAL
density AS ARRAY (components)OF REAL
outlet_flowrate_coefficient AS REAL
Supported types:
REAL | INTEGER | LOGICAL | FOREIGN_OBJECT | ORDERED_SET
Creating a MODEL
gPROMS language
PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
area AS REAL
density AS ARRAY ( components ) OF REAL
outlet_flowrate_coefficient AS REAL
VARIABLE
inlet_mass_flowrate AS ARRAY ( number_of_inlets ) OF mass_flowrate_gML
inlet_mass_fraction AS ARRAY ( number_of_inlets , components ) OF mass_fraction_gML
outlet_mass_flowrate AS mass_flowrate_gML
mass_fraction AS ARRAY ( components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( components ) OF mass_gML
total_mass_holdup AS mass_gML
total_volume AS volume_gML
height AS length_gML
Creating a model
VARIABLEs
Numerical definition:
Default value is used as initial guess for the initialisation calculation
Lower and Upper bounds define the valid ranges for all Variables of this
type
Units are not used in the calculation but are very important for model
readability and maintainability
A set of commonly used Variable Types is defined in the
gML Basics Interface library
based on SI units
look there first before defining your own!
© Process Systems Enterprise Limited
Creating a model
Mixing tank example
EQUATION
# Mass balance
FOR i IN components DO
$mass_holdup(i)
= SIGMA ( inlet_mass_flowrate() * inlet_mass_fraction(,i) )
- outlet_mass_flowrate * mass_fraction(i) ;
END # FOR i
Comments:
single line comments:# …
multiple line comments:{…}
can be nested
Creating a model
EQUATIONs
Arithmetic operators:
+ - / ^
Built-in functions:
SQRT(Height)
Declarative language
order of equations not important!
form of equations (usually) not important!
Defining a simulation
Degrees of freedom
𝑀𝑖 = 𝑀𝑇 ∙ 𝑋𝑖 - Nc -
𝑁𝑜𝐶𝑜𝑚𝑝 𝑀
𝑖
𝑉= 𝑉, 𝜌𝑖 1 Nc+1
𝑖=1 𝜌𝑖
𝑉 =𝐴∙ℎ h 1 1
𝐹𝑜𝑢𝑡 = 𝛼 ∙ ℎ - 1 -
Total no equations 2∙Nc+4
Total no variables 3∙Nc + Nc∙Nin + 4
Degrees of freedom Nc + Nc∙Nin
Fin(t)
h(t)?
M(t)?
Fout(t)?
Defining a simulation
Initial conditions
𝑀𝑖 (0)
Typical MODEL...
Describes physical behaviour in
EQUATIONs, PARAMETERs and
VARIABLEs
Is generic for all unit operations of that
type
Typical PROCESS...
Contains all case-specific information
needed for simulation
Input specifications
Operating procedure
Solver settings (optional)
Defining a simulation
PROCESS entity
T101
Defining a simulation
PROCESS entity
ASSIGN
WITHIN T101 DO
inlet_mass_fraction(1,) := [ 0.97 , 0.02 , 0.01 ] ;
inlet_mass_fraction(2,) := [ 0.01 , 0.96 , 0.03 ] ;
inlet_mass_fraction(3,) := [ 0.13 , 0.11 , 0.76 ] ;
inlet_mass_fraction(4,) := [ 0.64 , 0.30 , 0.06 ] ;
END
Defining a simulation
PROCESS entity
INITIAL conditions
INITIAL INITIAL conditions are
WITHIN T101 DO equations,
mass_holdup(1) = 2.1 ; not assignments
mass_holdup(2) = 2.1 ;
mass_holdup(3) = 2.1 ;
mass_holdup(4) = 2.1 ;
END
If initially at steady-state, specify:
INITIAL
T101.$mass_holdup() = 0 ;
Or:
INITIAL
STEADY_STATE
© Process Systems Enterprise Limited
Running a simulation
History of already
performed simulations
Running a simulation
The execution control dialog
Execution specifications
Case project is
created
Execution output
Running a simulation
Case project structure
Original entities: full description of the problem
Used to create a new project
Easily reproduce results
Running a simulation
Case projects
Click Add
line...
Choose 2D,
3D, XY plot or
plot Template
Choose a
variable
View/change
line properties
Hands-on session
Develop a gas-phase valve model
Creating a model
Mixing tank example
PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
area AS REAL
density AS ARRAY ( components ) OF REAL
outlet_flowrate_coefficient AS REAL
VARIABLE
inlet_mass_flowrate AS ARRAY ( number_of_inlets ) OF mass_flowrate_gML
inlet_mass_fraction AS ARRAY ( number_of_inlets , components ) OF mass_fraction_gML
outlet_mass_flowrate AS mass_flowrate_gML
mass_fraction AS ARRAY ( components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( components ) OF mass_gML
total_mass_holdup AS mass_gML
total_volume AS volume_gML
height AS length_gML
PARAMETER
components AS ORDERED_SET
density AS ARRAY ( components ) OF REAL
SET
components := ['water','oil','emulsifier'] ;
density('water') := 1000 ; # kg/m3
density('oil') := 900 ; # kg/m3
density('emulsifier') := 1100 ; # kg/m3
Creating a model
Arrays using INTEGERs
PARAMETER
number_of_inlets AS INTEGER
VARIABLE
inlet_mass_flowrate AS ARRAY ( number_of_inlets ) OF mass_flowrate_gML
SET
number_of_inlets := 4 ;
ASSIGN
inlet_mass_flowrate(1) := 9 ; # kg/s
inlet_mass_flowrate(2) := 6 ; # kg/s
inlet_mass_flowrate(3) := 1 ; # kg/s
inlet_mass_flowrate(4) := 3 ; # kg/s
PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
VARIABLE
inlet_mass_fraction AS ARRAY ( number_of_inlets , components ) OF mass_fraction_gML
SET
components := ['water','oil','emulsifier'] ;
number_of_inlets := 4 ;
ASSIGN
inlet_mass_fraction(1,) := [ 0.97 , 0.02 , 0.01 ] ;
inlet_mass_fraction(2,) := [ 0.01 , 0.96 , 0.03 ] ;
inlet_mass_fraction(3,) := [ 0.13 , 0.11 , 0.76 ] ;
inlet_mass_fraction(4,) := [ 0.64 , 0.30 , 0.06 ] ;
Creating a model
ARRAY referencing
Equivalent statements…
A
A(,) A(3:4,’S2’:’S5’)
A(1:5,ordered_set_name)
A(1:5,’S1’:’S5’)
A(2,)
A(3,’S2’)
A(2:2,ordered_set_name)
A(2:2,’S1’:’S5’)
EQUATION
# Mass balance
FOR i IN components DO
$mass_holdup(i)
= SIGMA ( inlet_mass_flowrate() * inlet_mass_fraction(,i) )
- outlet_mass_flowrate * mass_fraction(i) ;
END # FOR i
Creating a model
Arrays in EQUATIONs
Mi MT X i , i 1...NoComp
PARAMETER
components AS ORDERED_SET
VARIABLE
mass_fraction AS ARRAY ( components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( components ) OF mass_gML
total_mass_holdup AS mass_gML
Explicit Implicit
EQUATION EQUATION
FOR i IN components DO
mass_holdup(i) mass_holdup()
= total_mass_holdup = total_mass_holdup
* mass_fraction(i) ; * mass_fraction() ;
END # FOR i
© Process Systems Enterprise Limited
Mi MT X i , i 1...NoComp
PARAMETER
components AS ORDERED_SET
VARIABLE
mass_fraction AS ARRAY ( components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( components ) OF mass_gML
total_mass_holdup AS mass_gML
Explicit Implicit
EQUATION EQUATION
FOR i IN components DO
mass_holdup(i) mass_holdup()
= total_mass_holdup = total_mass_holdup
* mass_fraction(i) ; * mass_fraction() ;
END # FOR i
© Process Systems Enterprise Limited
Creating a model
Arrays in EQUATIONs
Mi MT X i , i 1...NoComp
PARAMETER
num_components AS INTEGER
VARIABLE
mass_fraction AS ARRAY ( num_components ) OF mass_fraction_gML
mass_holdup AS ARRAY ( num_components ) OF mass_gML
total_mass_holdup AS mass_gML
Explicit Implicit
EQUATION EQUATION
FOR i := 1 TO num_components DO
mass_holdup(i) mass_holdup()
= total_mass_holdup = total_mass_holdup
* mass_fraction(i) ; * mass_fraction() ;
END # FOR i
© Process Systems Enterprise Limited
Mi MT X i , i 1...NoComp
PARAMETER
num_components AS INTEGER
VARIABLE
mass_fraction AS ARRAY ( num_components ) OF mass_fraction
mass_holdup AS ARRAY ( num_components ) OF mass
total_mass_holdup AS mass
Explicit Implicit
EQUATION EQUATION
FOR i := 1 TO num_components DO
mass_holdup(i) mass_holdup()
= total_mass_holdup = total_mass_holdup
* mass_fraction(i) ; * mass_fraction() ;
END # FOR i
© Process Systems Enterprise Limited
Creating a model
Arrays in EQUATIONs
VARIABLE
c AS ARRAY ( m , n ) OF no_type_gML
Explicit Implicit
EQUATION EQUATION
FOR i := 1 TO m DO
FOR j := 1 TO n DO
a(i,j) * b(i,j) = c(i,j) ; a(,) * b(,) = c(,) ;
END # FOR j
END # FOR i
VARIABLE
B AS ARRAY ( m , p ) OF no_type_gML
Explicit
EQUATION
FOR i := 1 TO m DO
FOR j := 1 TO p DO
SIGMA ( A(i,) * X(,j)) = B(i,j) ;
END # FOR j
END # FOR i
Arrays in EQUATIONs
General rules
x y
where + - * / ^
Case x y xy
1 Scalar Scalar Scalar
2 Array Scalar Array
3 Scalar Array Array
4 Array Array Array
EQUATION
# Mass balance
FOR i IN components DO
$mass_holdup(i)
= SIGMA ( inlet_mass_flowrate() * inlet_mass_fraction(,i) )
- outlet_mass_flowrate * mass_fraction(i) ;
END # FOR i
Creating a model
Intrinsic functions
SIGMA(x,y,…),PRODUCT(x,y,…), ABS(x),SGN(x),SQRT(x),
MIN(x,y,…),MAX(x,y,…) EXP(x),LOG(x),LOG10(x),
SIN(x),COS(x),TAN(x),
ASIN(x),ACOS(x),ATAN(x),
SINH(x),COSH(x),TANH(x)
SQRT ( )
SQRT ( ) SIGMA ( , , )
SQRT ( ) SIGMA ( )
Creating a model
Operations on ORDERED_SETs
+ union
species := gases + liquids ;
- difference
solvent := liquids – reactants – products ;
components.first
Returns the first element as a string
components.last
Returns the last element as a string
components.card
Returns an the cardinality (i.e. the size) as an integer
components.element(i)
Returns the ith element as a string
components.index(element)
Returns the integer index of the element
Parameters
Modelling of
physical, chemical Variables
& biological plant MODEL
behaviour
Equations
Process
Modelling What to do?
Modelling of
operating
procedures & How to do it? TASK
control strategies
When to do it?
Defining a simulation
Simple operating procedures
© Process Systems Enterprise Limited
Defining a simulation
What to do?
Implicit Message
Defining a simulation
What to do? – replace one input variable with another
A, B
A B A B
t < t* t = t* t > t*
Defining a simulation
What to do? – change values of SELECTOR variables
P > 20 bar
INTACT BURST
R101
Defining a simulation
How to do it? – execute actions concurrently
V101
R101
V102
R102
PARALLEL ends when the last action (not necessarily the last
stated) is finished
Defining a simulation
How to do it?
Example projects
Technical webinars
© Process Systems Enterprise Limited
Pressing <CTRL+space>
produces a list of all valid completions of whatever you are
writing…
works throughout gPROMS, not just in MODELs
Extending a model
Handling discontinuities
Irreversible discontinuities
NO
PipeHeight FLOW
Height FLOW
EQUATION
IF Height < PipeHeight THEN
Fout = 0 ;
ELSE
Fout = Alpha * Density * g * (Height-PipeHeight) ;
END # IF
Extending a model
Reversible and symmetric discontinuities
Height < PipeHeight
NO
PipeHeight FLOW
Height FLOW
SELECTOR
Regime AS (Flow,NoFlow) DEFAULT Flow Height > PipeHeight
EQUATION
CASE Regime OF
WHEN Flow:
Fout = Alpha * Density * g * (Height-PipeHeight) ;
SWITCH TO NoFlow IF Height < PipeHeight ;
WHEN NoFlow:
Fout = 0 ;
SWITCH TO Flow IF Height > PipeHeight ;
END # Case
© Process Systems Enterprise Limited
P
OPEN CLOSED
PARAMETER
Popen, Pclose AS REAL
P > 10 bar
SELECTOR
ValveState AS ( Open , Closed ) DEFAULT Closed
EQUATION
CASE ValveState OF
WHEN Open :
Fout = k * SQRT(P-Pout) ;
SWITCH TO Closed IF P < Pclose ;
WHEN Closed :
Fout = 0 ;
SWITCH TO Open IF P > Popen ;
END # Case
© Process Systems Enterprise Limited
Extending a model
Irreversible discontinuities
P > 20 bar
INTACT BURST
P
PARAMETER
Pburst AS REAL
SELECTOR
DiscState AS ( Intact , Burst ) DEFAULT Intact
EQUATION
CASE DiscState OF
WHEN Intact :
Fout = 0 ;
SWITCH TO Burst IF P > Pburst ;
WHEN Burst :
Fout = k * P / SQRT(T) ;
END # Case
© Process Systems Enterprise Limited
Irreversible discontinuities
CASE equations
Handling discontinuities
Conditional equations
SELECTOR
Phase AS ( liquid , VLE , vapour ) DEFAULT vapour
P < 9 bar
@ t=0,
P=9.5 bar OPEN CLOSED
? ?
PROCESS entity:
P > 10 bar
UNIT
T101 AS VesselWithValve
INITIALSELECTOR
WITHIN T101 DO
ValveState := Open ;
END # WITHIN T101
INITIAL
T101.P = 9.5 ;
© Process Systems Enterprise Limited
Hands-on session
Foreign Objects
© Process Systems Enterprise Limited
# Energy balance
F * Hf = L * phys_prop.LiquidEnthalpy ( T , P , x )
+ V * phys_prop.VapourEnthalpy ( T , P , y )
+ Q ;
# Vapour-liquid equilibrium
x * phys_prop.LiquidFugacityCoeff ( T , P , x ) =
y * phys_prop.VapourFugacityCoeff ( T , P , y ) ;
PROCESS FlashSimulation
UNIT
F101 AS Flash
SET
F101.NoComp := 3 ;
ASSIGN
F101.F := 11.2 ; # kmol/hr
F101.z := [ 0.1 , 0.5 , 0.4 ] ;
Something missing?
Components (e.g. propane, butane,. . .)?
Thermodynamic options (e.g. RKS, NRTL,. . .)?
Databank to use (DIPPR,. . .)?
gPROMS does not need to know the information inside the data
file…
gPROMS just passes the file name to the Foreign Object code
Feed Product
PARAMETER
NoComp AS INTEGER
NoFlash AS INTEGER
phys_prop AS FOREIGN_OBJECT
UNIT
Flash AS ARRAY ( NoFlash ) OF Flash
PROCESS SimTrain
UNIT
SeparationSection AS FlashTrain
SET
SeparationSection.phys_prop := "Multiflash::methanol_water.mfl" ;
UNIT
LowTempSeparationSection AS FlashTrain
HighTempSeparationSection AS FlashTrain
PROCESS SimTrain
UNIT
Plant AS CryoPlant
SET
WITHIN Plant DO
LowTempSeparationSection.phys_prop := “Multiflash::LowT.mfl” ;
HighTempSeparationSection.phys_prop := “Multiflash::HighT.mfl” ;
END # WITHIN Plant
Chemical components
Data
Source
Component
list
Component
definition
Thermophysical models
Model Thermo
category model
Phases which
may appear
Transport
properties
Multiflash
Configuration
file
Basic troubleshooting
Motivation
Specifying distribution domains
Specifying boundary conditions
Handling partial derivatives and integrals
Hands-on session
Develop a 1D gas-phase PFR model
Defining and running a simulation
Solution methods
Choosing a discretisation method
Specifying initial conditions
Contents
Developing your own distributed model
Hands-on session
Simulating a 1D gas-phase PFR
Improving computational time
Hands-on session
Extending 1D model to 2D model
Reducing CPU time without compromising on accuracy for
a 2D gas-phase PFR
Related gPROMS documentation
Motivation
2. Library models are not suitable for each and every application
need to customise them
Tubular reactor
Assumptions:
Axial variations
Well-mixed cooling jacket
Distributed systems
Tubular reactor
C i C i 2C i No Re ac
Mass balance
t
v
z
D
z 2
j 1
ij R j ,
i 1..NoComp , z (0, L )
T T 2T 2U
C p C pv k 2 (T T w )
Energy balance t z z R
No Re ac
j 1
R j ( H j ) , z (0, L )
E j NoComp
Reaction rate
R j A je RT C iOij , j 1..No Re ac , z [0, L ]
i 1
At z = 0:
C i
D vC i vC i ,in , i 1..NoComp
z
T
-k C pvT C pvT in
z
At z = L:
C i
0 , i 1..NoComp
z
T
0
z
Distributed systems
Tubular reactor – cooling jacket
Energy balance:
dT w
wC p,wV w FwC p,w (T w ,in T w ) Q
dt
T 2T PARTIAL(PARTIAL(T,Axial),Axial)
PARTIAL(T,Axial)
or
z z 2 PARTIAL(T,Axial,Axial)
(vC ) 2 (Cv )
PARTIAL(v*C,Radial) PARTIAL(C(r)*v(r),Radial,Radial)
r r 2
T
(k ) PARTIAL(Kr*PARTIAL(T,Radial),Radial)
r r
T
$T
t
Distributed systems
Handling integrals
1
e
z 2
dz INTEGRAL(z := 0:1 ; EXP(-z^2))
0
L
0
(T (z , R ) T w )dz INTEGRAL(z := 0:ReactorLength ; T(z,ReactorRadius)-Tw)
2 L R
T
LR 2
0 0
rT (z , r )drdz
DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]
FOR XDomain := a TO b DO
...
END
Distributed systems
Specifying distribution domains
DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]
DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]
Distributed systems
Specifying distribution domains
DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]
Implicit form:
# The reactor is well-insulated
Q(0:ReactorLength) = 0 ;
# or
Q = 0 ;
Explicit form:
# The reactor is well-insulated
FOR z := 0 TO ReactorLength DO
Q(z) = 0 ;
END # For
Distributed systems
Specifying distribution domains
DISTRIBUTION_DOMAIN
Axial AS [ 0 : ReactorLength ]
VARIABLE
# Concentrations
C AS DISTRIBUTION(NoComp,Axial) OF molar_concentration_gML
# Reactor temperature
T AS DISTRIBUTION(Axial) OF temperature_gML
# Reaction rates
Rate AS DISTRIBUTION(NoReac,Axial) OF reaction_rate_kmol_per_h_kg_gML
. . .
C i
D vC i vC i ,in , i 1..NoComp
z
T
-k C pvT C pvT in
z
. . .
BOUNDARY
# @ z = 0
- DiffZ * PARTIAL(C(,0), Axial) + v * C(,0) = u * Cin() ;
- CondZ * PARTIAL(T(0),Axial) = rho * Cp * v * (Tin - T(0)) ;
C i
0 , i 1..NoComp
z
T
0
z
# @ z = L
PARTIAL(C(,ReactorLength), Axial) = 0 ;
PARTIAL(T(ReactorLength), Axial) = 0 ;
. .
© Process Systems Enterprise Limited
Distributed systems
Specifying model equations
. . . C i C i C i No Re ac 2
EQUATION
# Mass balance t
v
z
D
z 2
j 1
ij R j ,
FOR i := 1 TO NoComp DO i 1..NoComp , z (0, L )
FOR z := 0|+ TO ReactorLength|- DO
$C(i,z) = - v * PARTIAL(C(i,z), Axial) + DiffZ * PARTIAL(C(i,z), Axial, Axial)
+ SIGMA(Nu(i,) * Rate(,z)) ;
END # FOR z T T 2T 2U
END # FOR i
C p C pv k 2 (T T w )
t z z R
No Re ac
# Energy Balance
FOR z := 0|+ TO ReactorLength|- DO
j 1
R j ( H j ) , z (0, L )
rho * Cp * $T(z) = - rho * Cp * v * PARTIAL(T(z), Axial)
+ CondZ * PARTIAL(T(z), Axial, Axial) - 2*U / ReactorRadius * (T(z) - Tw)
- SIGMA(Rate(,z) * DH) ;
END # FOR z
E j NoComp
R j A je R T C iOij , j 1..No Re ac , z [0, L ]
# Reaction rate
i 1
FOR j := 1 TO NoReac DO
FOR z := 0 TO ReactorLength DO
Rate(j,z) = A(j)*EXP(-E(j)/(R*T(z)) *PRODUCT(C(,z)^Order(,j)) ;
END # FOR z
END # FOR j
. . .
Lumped
Lumped Distributed
Extending a model
Adding distribution domains
FOR i := 1 TO NoComp DO
FOR z := 0|+ TO ReactorLength|- DO
FOR r := 0|+ TO ReactorRadius|- DO
$C(i,z,r) = - v * PARTIAL(C(i,z,r),Axial)
+ DiffZ * PARTIAL(C(i,z,r),Axial,Axial)
+ (DiffR/r) * PARTIAL(r*PARTIAL(C(i,z,r),Radial),Radial)
+ SIGMA(Nu(i,) * Rate(,z,r)) ;
END
END
END
Ordinary Differential +
Algebraic Equations (DAEs)
Initialisation/
Integration
SOLUTION
Advantages:
makes use of solution methods for DAEs
allows solution of mixed lumped/distributed systems
Distributed Unit
Lumped Unit
DAEs IPDAEs
DAE system
𝜗𝑥 𝑥𝑘 −𝑥𝑘−1
Backward finite differences: 𝑧𝑘 =
𝜗𝑧 ℎ
𝜗𝑥 𝑥𝑘+1 −𝑥𝑘
Forward finite differences: 𝑧𝑘 =
𝜗𝑧 ℎ
𝜗𝑥 𝑥𝑘+1 −𝑥𝑘−1
Centered finite differences: 𝑧𝑘 =
𝜗𝑧 2ℎ
© Process Systems Enterprise Limited
z=0 z=L
DISTRIBUTION_DOMAIN
UpAxial, DownAxial AS (0:Length)
z=L
VARIABLE
X AS DISTRIBUTION(NoComp,DownAxial) OF molar_fraction_gML
Y AS DISTRIBUTION(NoComp,UpAxial) OF molar_fraction_gML
. . .
z=0
SET
UpAxial := [ BFDM, 1, 20 ] ;
DownAxial := [ FFDM, 1, 20 ] ;
Defining a simulation
Specifying initial conditions
# Mass balance
FOR i := 1 TO NoComp DO
FOR z := 0|+ TO ReactorLength|- DO
$C(i,z) = - v * PARTIAL(C(i,z), Axial) + DiffZ * PARTIAL(C(i,z), Axial, Axial)
+ SIGMA(Nu(i),) * Rate(,z)) ;
END # FOR z
END # FOR i
INITIAL
FOR i := 1 TO NoComp DO
FOR z := 0|+ TO ReactorLength|- DO
C(i,z) = Cin(i) ;
END
END
Hands-on session
Simulating a 1D gas-phase PFR
manually specified
Axial := [ CFDM, 2,(0.356, 0.524, 0.635,
0.719, 0.807, 0.851,
0.902, 0.945, 0.979 )] ;
LOGarithmic transformation
Axial := [CFDM, 2, 10, TRANSFORM( LOG, alpha)] ;
ln( z 1)
Increasing concentrates the zˆ
points at the lower bound ln( 1)
636
634
temperature alpha=2
632
630
628
626
624
0 1 2 3
Axial
EXPonential transformation
Axial := [CFDM, 2, 10, TRANSFORM( EXP, alpha)] ;
2.0
T
1.5
1.0
0.5
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
X Dom
alpha = 6 alpha = 4
alpha = 2
© Process Systems Enterprise Limited
Recommended procedure:
1. start with a uniform grid
2. identify the regions with strong gradients
3. set-up the appropriate non-uniform grid
Motivation
How to construct abstract composite models
Declare UNITs in higher-level model
Define connections in higher-level model
Parameter propagation
Hands-on session
Interacting a cooling jacket and valve model with a gas-
phase CSTR for synthesis of methanol
Visibility of
variables in lower-level models
Related gPROMS documentation
Reaction kinetics
Reactor train Reactor
kinetic
mechanism 1
Plant Reaction Section
kinetic
mechanism 2
kinetic
mechanism 3
…
Tray
Distillation hydraulics
column tray
hydraulics 1
tray
Separation Section hydraulics 2
tray
hydraulics 3
…
#MODEL Reactor
PARAMETER
. . .
UNIT
kinetics AS reaction_kinetics
VARIABLE
. . .
Reactor EQUATION
. . .
Reaction kinetics
EQUATION
# Reaction rate
NC + NR + 1 new FOR j := 1 TO number_of_reactions DO
variables molar_reaction_rate(j)
= reaction_pre_exponential_factor(j)
* EXP ( -reaction_activation_energy(j) / (
ideal_gas_constant * temperature ) )
* PRODUCT ( molar_fraction() ^ reaction_order(,j);
NR new equations END # FOR j
Reactor
# MODEL Reactor
PARAMETER
. . .
Reaction kinetics
Xi UNIT
Xi kinetics AS reaction_kinetics
VARIABLE
. . .
T
T
Note: no
computational impact
© Process Systems Enterprise Limited
VARIABLE
. . .
# molar_reaction_rate AS ARRAY (number_of_reactions ) OF reaction_rate
EQUATION
# Molar balance
FOR i IN component_list DO
$holdup_moles(i)
= inlet_molar_flowrate * inlet_molar_fraction(i)
- outlet_molar_flowrate * molar_fraction(i)
+ total_holdup_moles
* SIGMA ( kinetics.reaction_stoichiometry(i,)
* kinetics.molar_reaction_rate() ) ;
END # FOR i
Parameter propagation
Explicit specifications
It can never be overridden
In the model itself
In other models containing instances of the above model
In the process
MODEL reaction_kinetics
PARAMETER
NoReac AS INTEGER
A AS ARRAY ( NoReac ) OF REAL
SET
NoReac := 3 ;
A := [ 1.1E10 , 2.1E5 , 1.7E4 ] ;
alternatively. . .
PROCESS Simulation
UNIT
P AS Plant
SET
P.RxnSec.R1.kn.NoReac := 3 ;
P.RxnSec.R1.kn.A := [ 1.1E10 , 2.1E5 , 1.7E4 ] ;
Reactor
PARAMETER
NoComp, NoReac AS INTEGER
UNIT
kn AS RxnKinetic
Composite/component models
Summary
Contain one or more other instances of component (lower-
level) models as declared in the UNIT section
Component models
Should be well-parameterised to provide generality to the
composite model
variety of reaction mechanisms/tray hydraulic/heat
transfer models available
included as different options in the dialog box
specifications of the unit operation’s Public Interface
Hands-on session
kinetic
mechanism 3
…
Tray
Distillation hydraulics
column tray
hydraulics 1
tray
Separation Section hydraulics 2
tray
hydraulics 3
…
A variable defined in the Reaction kinetics model cannot be used directly in the Tray
hydraulics model. Relationships to lower-level variables need to be defined in the highest-
level model (e.g. Plant model)
© Process Systems Enterprise Limited
Contents
Making models robust
Motivation
Initialisation procedures
Introduction
Development of initialisation procedures
Hands-on session
Troubleshooting
SOLUTIONPARAMETERS
Modelling tips
Related gPROMS documentation
Motivation
Modelling trends:
Models getting bigger
Models becoming more detailed (more non-linear)
Initialisation procedures
1. Introduction
Sources of initial guesses
Initialisation procedures
2. Development of initialisation procedures
Unit-level initialisation procedures
Flowsheet-level initialisation procedures
3. Hands-on session
SAVE task
saves the current values of all variables and selectors
SEQUENCE
CONTINUE FOR 10
SAVE "10min"
RESET
TANK.InFlow := 25.3 ;
END # Reset
CONTINUE FOR 20
SAVE "30min"
. . .
END # Sequence
Created SAVEd files
are found in the
results folder
RESTORE task
Priority: PRESET explicitly > PRESET with RESTORE > Variable types
© Process Systems Enterprise Limited
Standard initialisation
general mathematical solver algorithm to go from xguess to x
xguess x
Initialisation procedure
model-specific knowledge to “guide” the solver algorithm
along the way
solve a series of sub-problems increasingly like the “real”
problem
x
x3
x2
x1
xguess
© Process Systems Enterprise Limited
Final State
Initial State
Next state … Next State (original
(as defined)
model)
General approach
INITIALISATION_PROCEDURE ip_name 1
START
#Insert list of modifications to the model here 2
END
NEXT
#Insert list of modifications to the model here
END
NEXT 3
#Insert list of modifications to the model here
END
...
JUMP_TO MOVE_TO
Advantage Faster More Robust
Disadvantage Less Robust Slower
General syntax:
Explicit change to VARIABLE/PARAMETER/SELECTOR
JUMP_TO or MOVE_TO
<variable> := <new value>;
END
General approach:
1. Decrease the size of larger non-linear blocks
Standard techniques:
Remove energy balance: specify temperature instead
Remove spatial dependencies: assume inlet conditions everywhere
Switch off reactions
Etc.
Guidelines:
Isothermal mode:
𝑑𝑇
=0
𝑑𝑡
Adiabatic mode:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗
𝑑𝑡 𝑗=1
Full mode:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1
SELECTOR
EQUATION
CASE EnergyMode OF
WHEN Isothermal:
$T = 0 ;
WHEN Adiabatic:
$U = F_in*h_in – F_out*h + V*SIGMA(rate()*DeltaH_R()) ;
WHEN Full:
$U = F_in*h_in – F_out*h + V*SIGMA(rate()*DeltaH_R()) + Q ;
END
INITIALISATION_PROCEDURE IP_SimpleEnergyBalance
START
EnergyMode := Isothermal ;
END
NEXT
MOVE_TO
EnergyMode := Adiabatic ;
END
END
NEXT
MOVE_TO
EnergyMode := Full ;
END
END
Energy balance:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1
PARAMETER
DeltaH_R AS REAL
SET
DeltaH_R := 40000 ;
(…)
INITIALISATION_PROCEDURE IP_NoHeatReaction
START
DeltaH_R := 0 ;
END
NEXT
MOVE_TO
REVERT DeltaH_R ;
END
END
Energy balance:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1
VARIABLE
F_steam AS mass_flowrate_gML
ASSIGN
F_steam := 50 ;
(…)
INITIALISATION_PROCEDURE IP_NoSteamFlow
START
F_steam := 0 ;
END
NEXT
MOVE_TO
REVERT F_steam ;
END
END
Note:
REASSIGN or RESET tasks cannot be used in IPs
© Process Systems Enterprise Limited
Fractional conversion:
𝑝𝑠𝑜𝑢𝑟𝑐𝑒1 𝑅𝑇𝑠𝑜𝑢𝑟𝑐𝑒 − 𝐶1 (𝐿)
𝜉=
𝑝𝑠𝑜𝑢𝑟𝑐𝑒1 𝑅𝑇𝑠𝑜𝑢𝑟𝑐𝑒
Common procedure:
Specify 𝐿 (length of reactor) and calculate 𝜉
Specify 𝜉 and calculate 𝐿
May present problems during initialisation
𝑧 𝑧
𝑧
𝑧=
𝐿
0 L 0 1
DISTRIBUTION_DOMAIN
VARIABLE
...
ReactorLength AS length_gML
C AS DISTRIBUTION(NoComp,Axial) OF molar_concentration_gML
Conversion AS no_type_gML
EQUATION
INITIALISATION_PROCEDURE IP_ReplaceConversion
START
REPLACE
Conversion
WITH
ReactorLength := 5 ;
END
END
NEXT
MOVE_TO
REVERT Conversion ;
END
END
Note:
Conversion must be specified in the PROCESS
ASSIGN
R101.Conversion := 0.95 ;
PROCESS entity:
at the bottom (after SOLUTIONPARAMETERS):
INITIALISATION_PROCEDURE
IP to be used
USE
unit_name : IP_name ;
END MODEL instance specified in
UNIT section
Right-click to include IP:
SVS
Solution
INITIALISATION_PROCEDURE
USE
#Insert list of Unit and Model specifications
END
START
#Insert list of modifications to the Model
END
NEXT
#Insert list of initialisation procedure actions
END
...
Full
Hands-on session
Making models robust
Troubleshooting
1. Introduction
Dynamic simulation failures
gPROMS execution output
2. Failures at initialisation
3. Failures at re-initialisation
4. Failures during integration
5. Modelling tips
Occurrences of failures:
At initialisation
At re-initialisation Frequency
During integration
Introduction
gPROMS execution output
gPROMS version
Top-level parameter
settings
Solution parameter
settings
Resolving
parameters
Initial selectors,
Jacobian expression,
Etc.
Structural
analysis
Initialisation
Integration
Introduction
gPROMS execution output
If a failure occurs:
At initialisation:
At InitialisationNLSolver (DASolver):
Set OutputLevel := 2
At the BlockSolver, set OutputLevel := 2
At re-initialisation:
At ReinitialisationNLSolver (DASolver)
Set OutputLevel := 2
At the BlockSolver, Set OutputLevel := 2
During integration:
At DASolver:
Set OutputLevel := 3
Set Diag := TRUE
Introduction
gPROMS execution output
… the equation(s) …
… the current values
of variables …
Introduction
gPROMS execution output
Block decomposition:
Sequence of smaller problems
Modes of failure:
Structural singularity
Failure in linear block
Illegal arithmetic operation
Convergence failure in non-linear block
Failures at initialisation
Structural singularity
Diagnosis:
k equations with k-1 distinct variables
Cause:
Bad modelling equations
High-index DAE system
Bad choice of degree of freedom specifications
Action:
Check reported equations
Check ASSIGNed variables
Diagnosis:
Message identifying equations and variables involved (usually
1x1 linear block)
Cause:
Bad variable bounds
Problem bad posed
Action:
Check variable reported by gPROMS
Query this variable
Name, value, lower and upper bounds
Consider adjusting variable bounds
© Process Systems Enterprise Limited
Failures at initialisation
Illegal arithmetic operation
Diagnosis:
Report of equation or derivative and the term causing the failure
Cause:
Illegal operation …
Division by zero, illegal argument for built-in function (LOG, etc.)
… when evaluating
Equation residual, equation partial derivative
Action:
Check equation involved
Consider rewriting the equation
Modify variable bounds (e.g., avoid 0 as lower bound)
If needed, introduce new variable and impose appropriate bounds
© Process Systems Enterprise Limited
Diagnosis:
Failure to converge within allowed iterations
Before failing, gPROMS may report numerical singularities or
variables hitting bounds
Cause:
a) Problem badly posed (but not structurally singular)
b) Solution does not exist for ASSIGNed variables
c) Solution does not exist within specified bounds
d) Initial guesses not good enough
e) Requested initialisation accuracy unreasonably high
f) Maximum number of iterations not sufficient
Failures at initialisation
Convergence failure in non-linear block
Action:
Assess likelihood of possible causes:
Singularity messages Problem badly posed ?
Variables hitting bounds Solution does not exist ?
Equation norm low but not decreasing Initialisation accuracy high ?
Equation norm low and decreasing No. of iterations not enough ?
Initial guesses not good enough always possible
Action:
Suspected case – Solution does not exist within bounds
Increase number of iterations in NLSolver
Suspected case – Initial guesses not good enough
Change initial guesses via explicit PRESET specification, RESTORE saved
variable sets or default value of variable types
Suspected case - Requested initialisation accuracy unreasonably
high
If equation n has the highest residual (which is a small number but greater than the
convergence tolerance) query the equation
Consider scaling/rearraging equation
Relax convergence tolerance
Suspected case - Maximum number of iterations not sufficient
Increase number of iterations in NLSolver
Failures at re-initialisation
Easier to diagnose
Modes of failure:
Trajectory attempts to go through variable bounds
Diagnosis:
Report of variable and bound involved
Cause:
Incorrect variable bounds
Insufficient integration accuracy
Incorrect model equations
Action:
Check bound reported
If too tight, relax it in Variable Type section
If correct, check if integration accuracy is
adequate
For very small quantities violating zero bounds, tighten
absolute tolerance of the DASolver
Diagnosis:
Report of type and time of failure
Cause:
Unstable system
Wrong choice of discretisation method
Numerical singularity
…
Very fast dynamics
Hidden discontinuity
Note: improper initial conditions may also result in integration step failures
Action:
Modify SCHEDULE to integrate until just before failure
Create a model report just before the failure
Inspect variables for abnormal values (use small reporting
interval)
Modelling tips
Scaling
Variable scaling
Multiplying the variable by a scaling factor
E.g. 𝑃 to 10−5𝑃 (𝑃 in Pa)
Scaling the units of the variable
E.g. J to MJ, Pa to bar
Equation scaling
Multiplying the equation by a scaling factor
Rewriting the equation
E.g. 𝑦 𝑥 = 1 to 𝑦 = 𝑥
Including additional equations
Note: to get more information, try a small number of discretisation intervals, e.g.
Axial := [CFDM,1,5]
© Process Systems Enterprise Limited
Motivation
What is required prior to a model validation exercise
Setting up an already performed experiment
Statistical variance models
Simulate a performed experiment
Hands-on session
Creating and simulating an already performed experiment
Setting upa parameter estimation
Hands-on session
Creating a parameter estimation entity
Contents
Estimating model parameters from experimental data
Motivation
Estimating model parameters from experimental data
1
Build drag-and-drop flowsheet
of experimental 3 Estimate parameters and
analyse uncertainty 5 Build & execute full-size
equipment model
equipment/process
Iterate until
sufficient
parameter accuracy
2 Execute experiment Use model to design the
optimal next experiment
4
3
Parameter estimation
Illustrative example
Batch reactor
Electrical
Heating
Element
rV H R Q
dH
dt
Reaction rate
r kC AC B
k k 0e E / R T
© Process Systems Enterprise Limited
Batch reactor
Mathematical model
Component concentrations
Mi
Ci , i A ..D
V
D
Mi
V
i A i
Energy content
D
H M h
i A
o
i i
i
hio i T T ref 2
T 2
T ref2 , i A ..D
k 0, E , H R
Batch reactor
Dynamic experiment #2
Experiments entity
Initial conditions
of the experiment
Specification must be in
terms of initial values of
Complete variable variables listed in INITIAL
pathname section of the gPROMS
PROCESS
Experiments entity
Controls tab
Variables that differ from
specifications in gPROMS
or that are changed in 3 options:
different experiments • Time-invariant
• Piecewise-constant
• Piecewise-linear
Complete variable
pathname
Tin
505
0
t
Experiments entity
Controls tab – Piecewise-constant
Tin
505
0
100 400
t
Tin
505
400
300
0
100 400
t
Experiments entity
Measured data tab
Complete variables
pathname
Specify sensor if
measurement
variances can be
grouped (optional)
Specify experiment-
specific variance
model (optional)
Experimental results
Specify time history
for each measurement
Overwrites variance
model specified in the
Estimation entity
Experiments entity
gPROMS language tab
Experiments entity
Simulating experiments
Steps:
Hands-on session
Creating and simulating an already performed experiment
Batch reactor
Experimental data vs. model predictions
E 20000 J mol 1
H R 55000 J mol 1
Concentration of A - Experiment #1
Temperature - Experiment #1
NE NV i NM ij
2
z z jk
N
2
1
ln 2 min
2 i 1 j 1 k 1 ijk
ln 2 ijk
ijk
2
Parameter estimation
Objective function
NE NV i NM ij
2
z z jk
N
2
1
ln 2 min
2 i 1 j 1 k 1
ln 2 ijk
ijk
ijk
2
N Total no. of measurements taken during all experiments
Set of parameters to be estimated, which may be
subject to given bounds, i.e. L U
NE Number of experiments performed
NVi Number of variables measured in the ith expt.
NMij No. of measurements of the jth variable in the ith expt.
2ijk Variance of the kth measurement of variable j in expt. i
z ijk kth measured value of variable j in expt. i
zijk kth (model-)predicted value of variable j in expt. i
© Process Systems Enterprise Limited
Parameter estimation
Statistical variance models
2 2 z 2
Most general type is HETEROSCEDASTIC
2 2 z 2
where 0 and 0 1
In all cases, and/or can be fixed if known or estimated
(optimised) together with parameters in physical model
NE NV i NM ij
2
z z jk
N
2
1
ln 2 min
2 i 1 j 1 k 1 ijk
ln 2 ijk
ijk
2
Information required
Relevant entities in gPROMS Project File
Process model
Definition of parameter
estimation problem
Process Model
MODEL section
Process Model
PROCESS section
Experiments to be included
in the parameter estimation
Statistical variance
model and associated
parameters for
measured variables
Complete variables
pathname
Automatically populated in
gPROMS language tab
Hands-on session
Estimating reaction parameters for synthesis of methanol
in a gas-phase CSTR
Reporting results
Summary of
information
Contents list
N E N V i N M ij
z
2
z jk
N
2
1
ln 2 min
2 i 1 j 1 k 1
ln 2
ijk
ijk
ijk
2
Understand
biggest
contributions
Ignore value
© Process Systems Enterprise Limited
Statistics
machine readable file (.stat-mr)
Summary sheet
Contributions to objective function
Model parameters marked in red have not been estimated well
or are at their bounds
Statistics
Selected spreadsheets
Statistics
Selected spreadsheets
Statistics
Statistical plots
Three types
Overlay charts
Residual charts
Confidence ellipsoids
Statistical plots
Residual charts
Weighted deviation,
z ijk
z ijk
2ijk
Statistical plots
Confidence ellipsoids
Summary of What to do