0% found this document useful (0 votes)
1K views164 pages

GPROMS - Developing Custom Unit Operation Models

Uploaded by

Bamrung Sungnoen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views164 pages

GPROMS - Developing Custom Unit Operation Models

Uploaded by

Bamrung Sungnoen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 164

Modelling prerequisites

Module 201

© Process Systems Enterprise Limited

Modelling prerequisites

 Before implementation, decide on the model’s


 system boundaries
 relevant phenomena and assumptions
 degrees of freedom and calculation mode: design, rating, ...
 A model formulation table can help provide structure

Model formulation table for a buffer tank

© Process Systems Enterprise Limited

Page 1 © Process Systems Enterprise Ltd


Implementing a lumped model in gPROMS
Module 202

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 2 © Process Systems Enterprise Ltd


Contents
Implementing a lumped model in gPROMS

 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

© Process Systems Enterprise Limited

Motivation

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 3 © Process Systems Enterprise Ltd


Motivation

1. New applications/non-standard unit operations


 need to develop first-principle models from scratch

2. Existing user library models are not suitable for each and
every application
 need to customise them

3. Input for user-defined areas of flowsheets


 need to identify proprietary as well as process specific reaction
mechanisms, separation isotherms, heat transfer correlations, etc.

Keep in mind: combination with other models


 need to comply to a standard: gPROMS Model Libraries (gML)

© Process Systems Enterprise Limited

Creating a model

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 4 © Process Systems Enterprise Ltd


Creating a model
Mixing tank example

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

F1in F2in F in NoInput  Calculation of liquid level in the tank:


NoComp
Mi
V  
i 1 i
V  Ah
h
MT
Fout  Characterisation of the outlet flowrate:
Fout   h

© Process Systems Enterprise Limited

Page 5 © Process Systems Enterprise Ltd


gPROMS ProcessBuilder environment

MODEL editor
Project tree
area

PROCESS
editor

© Process Systems Enterprise Limited

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

PARAMETERs can be used to define array dimensions


1. INTEGER refer to array elements with an index
2. ORDERED_SET refer to array elements with a string
© Process Systems Enterprise Limited

Page 6 © Process Systems Enterprise Ltd


Creating a MODEL
PARAMETERs

PARAMETER
components AS ORDERED_SET
number_of_inlets AS INTEGER
area AS REAL
density AS ARRAY (components)OF REAL
outlet_flowrate_coefficient AS REAL

 PARAMETERs must be given fixed values before a simulation begins

 Supported types:
 REAL | INTEGER | LOGICAL | FOREIGN_OBJECT | ORDERED_SET

© Process Systems Enterprise Limited

Creating a MODEL
gPROMS language

 gPROMS language is case-insensitive


but...
 Convention used by PSE:
 all gPROMS keywords in CAPITALS
 user-defined identifiers in MixedCase or by separating
words with an underscore “_”
 E.g. ExternalHeatInput or external_heat_input
 Use descriptive names!
 Valid names must:
 contain only letters, numbers and underscores
 not begin with a number

© Process Systems Enterprise Limited

Page 7 © Process Systems Enterprise Ltd


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

© Process Systems Enterprise Limited

Creating a model
VARIABLEs

 VARIABLEs may vary with time


 Can be either specified by user or calculated by the
simulation
 Associated with a variable type
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

© Process Systems Enterprise Limited

Page 8 © Process Systems Enterprise Ltd


Creating a model
Variable types

 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

# Relation of mass fraction to component holdup


FOR i IN components DO
mass_holdup(i) = total_mass_holdup * mass_fraction(i) ;
END # FOR i

# Total holdup should equal sum of component holdups


total_mass_holdup = SIGMA ( mass_holdup() ) ;

# Relation between total volume and component holdups


total_volume = SIGMA ( mass_holdup() / density() ) ;

# Relation between volume and liquid level


total_volume = area * height ;

# Relation of outlet mass flowrate to liquid level


outlet_mass_flowrate = outlet_flowrate_coefficient * SQRT ( ABS ( height ) )
* SGN ( height ) ;
© Process Systems Enterprise Limited

Page 9 © Process Systems Enterprise Ltd


Creating a model
EQUATIONs

 EQUATIONs can be partial, differential and algebraic


 Time derivatives: $HoldUp
 Use CTRL+space while typing to obtain list of valid
completions

 Comments:
 single line comments:# …
 multiple line comments:{…}
 can be nested

© Process Systems Enterprise Limited

Creating a model
EQUATIONs

 Arithmetic operators:
+ -  / ^

 Built-in functions:
SQRT(Height)

 Declarative language
 order of equations not important!
 form of equations (usually) not important!

© Process Systems Enterprise Limited

Page 10 © Process Systems Enterprise Ltd


Defining a simulation

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Defining a simulation
Degrees of freedom

New calculated No of new


Equation No equations
Variables calculated variable
𝑑𝑀𝑖 𝑁𝑜𝐼𝑛𝑙𝑒𝑡
𝑀𝑖 , 𝐹𝑗,𝑖𝑛 , 𝑋𝑖𝑗,𝑖𝑛 ,𝐹𝑜𝑢𝑡 ,
= 𝐹𝑗,𝑖𝑛 ∙ 𝑋𝑖𝑗,𝑖𝑛 −𝐹𝑜𝑢𝑡 ∙ 𝑋𝑖 Nc 2∙Nc+ Nc∙Nin+1
𝑑𝑡 𝑗=1 𝑋𝑖
𝑁𝑜𝐶𝑜𝑚𝑝
𝑀𝑇 = 𝑀𝑖 𝑀𝑇 1 1
𝑖=1

𝑀𝑖 = 𝑀𝑇 ∙ 𝑋𝑖 - 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

Extra specifications, e.g. 𝐹𝑗,𝑖𝑛 , 𝑋𝑖𝑗,𝑖𝑛


© Process Systems Enterprise Limited

Page 11 © Process Systems Enterprise Ltd


Defining a simulation
Degrees of freedom

Fin(t)

h(t)?
M(t)?
Fout(t)?

© Process Systems Enterprise Limited

Defining a simulation
Initial conditions

 At t = 0, determine 4 + 3𝑁𝑐 variables:

𝑀𝑖 0 , 𝑀𝑖 (0), 𝐹 𝑜𝑢𝑡 (0), 𝑋𝑖 (0), 𝑀𝑇 (0), 𝑉(0), ℎ(0)

 Must satisfy 4 + 2𝑁𝑐 equations at t = 0

 Need 𝑁𝑐 extra equations at t = 0 (“initial condition"), e.g.:

𝑀𝑖 (0)

Number of initial conditions = Number of differential variables in the model

© Process Systems Enterprise Limited

Page 12 © Process Systems Enterprise Ltd


Defining a simulation
MODEL vs. PROCESS entities

 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)

© Process Systems Enterprise Limited

Defining a simulation
PROCESS entity

 Create a new PROCESS

© Process Systems Enterprise Limited

Page 13 © Process Systems Enterprise Ltd


Defining a simulation
PROCESS entity

 What MODEL(s) to simulate?


UNIT
T101 AS Tank

T101

 Simultaneous simulation with multiple instances of the


same model :
UNIT
T101 AS Tank
T102 AS Tank
T103 AS Tank

T101 T102 T103

© Process Systems Enterprise Limited

Defining a simulation
PROCESS entity

 SET values of PARAMETERs:


Assignment
symbol in
SET gPROMS
WITHIN T101 DO
components := ['water','oil','emulsifier'] ;
number_of_inlets := 4 ;
density := [ 1000 , 900 , 1100 ] ;
area := 1 ; # m2
outlet_flowrate_coefficient := 10 ; # kg/s/m0.5
END

 Always need to refer to which model instance (e.g. T101)

 Use WITHIN for more compact notation

© Process Systems Enterprise Limited

Page 14 © Process Systems Enterprise Ltd


Defining a simulation
PROCESS entity

 ASSIGN degrees of freedom:

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 ] ;

inlet_mass_flowrate := [ 20, 20, 20, 20 ] ; # kg/s

END

© Process Systems Enterprise Limited

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

Page 15 © Process Systems Enterprise Ltd


Defining a simulation
PROCESS entity

 Specify the SCHEDULE of the operating procedure to be


simulated:

SCHEDULE # Operating procedure


CONTINUE FOR 1800

© Process Systems Enterprise Limited

Running a simulation

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 16 © Process Systems Enterprise Ltd


Running a simulation
Press the “Simulate…” button to start
the simulation (or press F5)

History of already
performed simulations

Select the appropriate


PROCESS entity

© Process Systems Enterprise Limited

Running a simulation
The execution control dialog

A Case project is automatically created at the start of the execution

 Execution specifications

 Configuration of Case content

 Miscellaneous execution controls

© Process Systems Enterprise Limited

Page 17 © Process Systems Enterprise Ltd


Running a simulation
Executing…

Stop execution button


The gPROMS Results Management System
(gRMS) is loaded (if selected)

Case project is
created
Execution output

© Process Systems Enterprise Limited

Running a simulation
Case project structure
 Original entities: full description of the problem
 Used to create a new project
 Easily reproduce results

 Trajectories: simulation results


 Tables, graphs, stream tables, model reports

 Problem description: complete definition of the


activity in the gPROMS language
 Used for debugging in relation to the execution output

 Execution output: displays all the messages relating


to the solution of the Model-based activity

© Process Systems Enterprise Limited

Page 18 © Process Systems Enterprise Ltd


Running a simulation
Viewing the results

 View results in Case


 time variation of individual variables

 gRMS: more powerful environment for configuring graphs

© Process Systems Enterprise Limited

Running a simulation
Case projects

© Process Systems Enterprise Limited

Page 19 © Process Systems Enterprise Ltd


Running a simulation
Constructing a plot in gRMS

Click Add
line...

Choose 2D,
3D, XY plot or
plot Template

Choose a
variable

View/change
line properties

© Process Systems Enterprise Limited

Hands-on session
Develop a gas-phase valve model

© Process Systems Enterprise Limited

Page 20 © Process Systems Enterprise Ltd


Using arrays and intrinsic functions in models

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 21 © Process Systems Enterprise Ltd


Creating a model
Arrays using ORDERED_SETs

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

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 22 © Process Systems Enterprise Ltd


Creating a model
Arrays using ORDERED_SETs and INTEGERs

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 ] ;

Any number of dimensions!

© Process Systems Enterprise Limited

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’)

© Process Systems Enterprise Limited

Page 23 © Process Systems Enterprise Ltd


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

# Relation of mass fraction to component holdup


Arrays in EQUATIONs
FOR i IN components DO
mass_holdup(i) = total_mass_holdup * mass_fraction(i) ;
END # FOR i

# Total holdup should equal sum of component holdups


total_mass_holdup = SIGMA ( mass_holdup() ) ;

# Relation between total volume and component holdups


total_volume = SIGMA ( mass_holdup() / density() ) ;

# Relation between volume and liquid level


total_volume = area * height ;

# Relation of outlet mass flowrate to liquid level


outlet_mass_flowrate = outlet_flowrate_coefficient * SQRT ( ABS ( height ) )
* SGN ( height ) ;
© Process Systems Enterprise Limited

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

Page 24 © Process Systems Enterprise Ltd


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

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

Page 25 © Process Systems Enterprise Ltd


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
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

aij bij  cij


PARAMETER
m,n AS INTEGER
a AS ARRAY ( m , n ) OF REAL
b AS ARRAY ( m , n ) OF REAL

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

© Process Systems Enterprise Limited

Page 26 © Process Systems Enterprise Ltd


Creating a model
Arrays in EQUATIONs
n
AX  B  A
k 1
ik X kj  Bij
PARAMETER
m,n,p AS INTEGER
A AS ARRAY ( m , n ) OF REAL
X AS ARRAY ( n , p ) OF REAL

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

© Process Systems Enterprise Limited

Arrays in EQUATIONs
General rules

x  y
where   + - * / ^

Case x y xy
1 Scalar Scalar Scalar
2 Array Scalar Array
3 Scalar Array Array
4 Array Array Array

Case 4 is valid only if x and y are of the same shape and


size !
© Process Systems Enterprise Limited

Page 27 © Process Systems Enterprise Ltd


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

# Relation of mass fraction to component holdup


FOR i IN components DO
mass_holdup(i) = total_mass_holdup * mass_fraction(i) ;
END # FOR i
Intrinsic functions
# Total holdup should equal sum of component holdups
total_mass_holdup = SIGMA ( mass_holdup() ) ;

# Relation between total volume and component holdups


total_volume = SIGMA ( mass_holdup() / density() ) ;

# Relation between volume and liquid level


total_volume = area * height ;

# Relation of outlet mass flowrate to liquid level


outlet_mass_flowrate = outlet_flowrate_coefficient * SQRT ( ABS ( height ) )
* SGN ( height ) ;
© Process Systems Enterprise Limited

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)

 Any number of arguments  One argument only

 Arguments may be:  Argument may be:


 scalar  scalar
 array  array
 array slice  array slice

 Result is always a scalar !  Result has the same dimensionality as


argument
© Process Systems Enterprise Limited

Page 28 © Process Systems Enterprise Ltd


Creating a model
Intrinsic functions

SQRT ( )

SQRT ( ) SIGMA ( , , )

SQRT ( ) BUT SIGMA ( )

SQRT ( ) SIGMA ( )

© Process Systems Enterprise Limited

Creating a model
Operations on ORDERED_SETs

+ union
species := gases + liquids ;

- difference
solvent := liquids – reactants – products ;

Operations are non-commutative


gases + liquids ≠ liquids + gases

© Process Systems Enterprise Limited

Page 29 © Process Systems Enterprise Ltd


Creating a model
ORDERED_SET intrinsic functions

 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

© Process Systems Enterprise Limited

Defining a simulation with operating procedures

© Process Systems Enterprise Limited

Page 30 © Process Systems Enterprise Ltd


Defining a simulation
Simple operating procedures

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?

© Process Systems Enterprise Limited

Defining a simulation
Simple operating procedures

 Elementary tasks (What)  Composite tasks (How/when)

© Process Systems Enterprise Limited

Page 31 © Process Systems Enterprise Ltd


Defining a simulation
Simple operating procedures

 Turn on input streams 1 and 2


 Wait until the volume in the tank is 3.5 m3
 Turn off input stream 1
 Increase flowrate of input stream 2 by 50%
 Wait until the volume in the tank is 5 m3
 Turn off input stream 2
 Wait for 5 min as mixing takes place
 Open outlet valve
 Wait until tank has drained
 Close outlet valve


© Process Systems Enterprise Limited

Defining a simulation
What to do?

 CONTINUE until when?  When to STOP?


 Explicit  Stop operation now!

 Implicit  Message

© Process Systems Enterprise Limited

Page 32 © Process Systems Enterprise Ltd


Defining a simulation
What to do? – Change values of input variables

1. CONTINUE FOR 0.8


2. Increase flowrate in tank T101 by 50%
3. Change T102 inlet temperature to 20oC, rising at +0.1 K/min

Reminder: Input variables are ASSIGNed in PROCESSes

© Process Systems Enterprise Limited

Defining a simulation
What to do? – replace one input variable with another

 Simple algebraic model: 𝑎 + 𝑏 = 10

1. At start a is known and b needs to be calculated


2. Later b is known and a needs to be calculated

© Process Systems Enterprise Limited

Page 33 © Process Systems Enterprise Ltd


Defining a simulation
What to do? – impulsive changes to differential variables

A, B

A B A B

t < t* t = t* t > t*

© Process Systems Enterprise Limited

Defining a simulation
What to do? – change values of SELECTOR variables

P > 20 bar

INTACT BURST

© Process Systems Enterprise Limited

Page 34 © Process Systems Enterprise Ltd


Defining a simulation
How to do it? – execute actions sequentially

R101

© Process Systems Enterprise Limited

Defining a simulation
How to do it? – execute actions concurrently

V101

R101

V102

R102

© Process Systems Enterprise Limited

Page 35 © Process Systems Enterprise Ltd


Defining a simulation
PARALLEL and SEQUENCE

 SEQUENCE ends when the last stated action is finished

 PARALLEL ends when the last action (not necessarily the last
stated) is finished

 PARALLEL and SEQUENCE may be nested

© Process Systems Enterprise Limited

Defining a simulation
How to do it?

© Process Systems Enterprise Limited

Page 36 © Process Systems Enterprise Ltd


Hands-on session
Develop a gas-phase CSTR model for the synthesis of methanol and
simulate in steady-state and dynamic modes

© Process Systems Enterprise Limited

Modelling support tools

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 37 © Process Systems Enterprise Ltd


Modelling support tools

 Assisted pathname completion

 Global search-and-replace tool

 Project and entity comparison tool

 On-line help system

 Example projects

 Technical webinars
© Process Systems Enterprise Limited

Modelling support tools


Assisted pathname completion

 Pressing <CTRL+space>
 produces a list of all valid completions of whatever you are
writing…
 works throughout gPROMS, not just in MODELs

© Process Systems Enterprise Limited

Page 38 © Process Systems Enterprise Ltd


Modelling support tools
Global search-and-replace tool

 Available in the Tools menu

 Allows to search and/or replace text strings within selected


entities/projects

 Advanced options and tools

© Process Systems Enterprise Limited

Modelling support tools


Comparing entities

 Select two entities in the project tree using <ctrl> or <shift>


keys Click to go to next/
 Lines that are different are highlighted with colour previous difference

 Compare configuration options available

© Process Systems Enterprise Limited

Page 39 © Process Systems Enterprise Ltd


Modelling support tools
Comparing projects

 Find entities which occur only in one project


 Find entities which occur in both projects but are different
 Double click on each entity to view differences
 Similar features when comparing entity groups

© Process Systems Enterprise Limited

Modelling support tools


On-line help system

 Accessed from Help > Documentation

© Process Systems Enterprise Limited

Page 40 © Process Systems Enterprise Ltd


Modelling support tools
Example projects

© Process Systems Enterprise Limited

Modelling support tools


Technical webinars

• The webinar series is free of charge


• Each webinar video is available on-demand on our website
• Each module includes an optional 10-question quiz
• Modules can be completed in any order
Topics
• Model Development I - Lumped Models
• Model Development II - Distributed Models
• Initialisation Procedures
• Debugging your Models
• Parameter Estimation I
• Parameter Estimation II
• Optimisation - NLP
• Optimisation - MINLP
• Numerical Solutions I
• Numerical Solutions II
• Library Development I

© Process Systems Enterprise Limited

Page 41 © Process Systems Enterprise Ltd


Extending a model

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Extending a model
Handling discontinuities

 Reversible and symmetric discontinuities

 Reversible and asymmetric discontinuities

 Irreversible discontinuities

© Process Systems Enterprise Limited

Page 42 © Process Systems Enterprise Ltd


Extending a model
Reversible and symmetric discontinuities
Height < PipeHeight

NO
PipeHeight FLOW
Height FLOW

Height > PipeHeight

EQUATION
IF Height < PipeHeight THEN
Fout = 0 ;
ELSE
Fout = Alpha * Density * g * (Height-PipeHeight) ;
END # IF

© Process Systems Enterprise Limited

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

Page 43 © Process Systems Enterprise Ltd


Extending a model
Reversible and asymmetric discontinuities
P < 9 bar

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

Page 44 © Process Systems Enterprise Ltd


Handling discontinuities
Conditional equations

 Reversible & symmetric discontinuities


 IF – THEN – ELSE equations
 CASE equations

 Reversible & asymmetric discontinuities


 CASE equations

 Irreversible discontinuities
 CASE equations

© Process Systems Enterprise Limited

Handling discontinuities
Conditional equations

 Any number and type of equations in each clause


 Number of equations in each clause must be the
same
 FOR, IF and CASE may be nested to any number of
levels

 CASE may have more than two branches, e.g.:

SELECTOR
Phase AS ( liquid , VLE , vapour ) DEFAULT vapour

© Process Systems Enterprise Limited

Page 45 © Process Systems Enterprise Ltd


Handling discontinuities

 Initial values of selector variables must be specified

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

Handling discontinuities in a gas-phase CSTR model for


the synthesis of methanol

© Process Systems Enterprise Limited

Page 46 © Process Systems Enterprise Ltd


Physical properties

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Physical properties in gPROMS

 Code physical property equations in gPROMS


 need to provide
 equations
 data for pure components and their interactions
 really feasible only in very simple cases

 Use external physical property package interfaced to gPROMS


as a Foreign Object (FO)
 IPPFO
 Multiflash
 gSAFT
 CAPE-OPEN physical properties
 OLI
 proprietary physical property packages
© Process Systems Enterprise Limited

Page 47 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Interaction between gPROMS and FOs

gPROMS MODEL  Each FO provides one or more


Need physical methods
properties?
 LiquidEnthalpy, VapourEnthalpy,
BoilingPoint, …
 Each method may have zero, one or
more inputs (scalar or arrays)
 CriticalTemperature,
VapourPressure(T),
Methods: LiquidEnthalpy(T,p,n), …
LiquidEnthalpy (T,P,x)
VapourEnthalpy (T,p,y)  Each method has a single output
etc. which may be a scalar or an array

Foreign Objects
© Process Systems Enterprise Limited

Physical properties in gPROMS


Use of external physical property packages
PARAMETER
phys_prop AS FOREIGN_OBJECT
New type of PARAMETER
components AS ORDERED_SET
VARIABLE
F, L, V AS reaction_rate_kmol_per_h_kg_gML
z, x, y AS ARRAY ( components ) OF molar_fraction_gML
T AS temperature_gML
P AS ressure_bar_gML
EQUATION
# Component molar balance
F * z = L * x + V * y ;

# 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 ) ;

# Molar fractions must add up to one


SIGMA(x) = SIGMA(y) = 1 ;
© Process Systems Enterprise Limited

Page 48 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Foreign object methods

 Method inputs may be scalar (e.g. T) or arrays (e.g. x)

 Method inputs may be algebraic expressions:


phys_prop.LiquidEnthalpy ((Tin+Tout)/2 , (Pin+Pout)/2 , x)

 Each method has a single output which may be a scalar or an


array:
 method LiquidEnthalpy returns a scalar;
 method LiquidFugacityCoeff returns an array

 Note: Full list of physical property methods:


 Menu: Help  Documentation
 Physical Properties Guide Using Physical Properties for Simple Materials
The set of physical properties supported by gPROMS
© Process Systems Enterprise Limited

Physical properties in gPROMS


Flash example

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 ] ;

END # PROCESS FlashSimulation

Something missing?
 Components (e.g. propane, butane,. . .)?
 Thermodynamic options (e.g. RKS, NRTL,. . .)?
 Databank to use (DIPPR,. . .)?

© Process Systems Enterprise Limited

Page 49 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Giving a value to a foreign object

 Foreign objects are PARAMETERs. . .


 must be given values (SET) before simulation may be executed

 "Value" of a FO is a unique string

 . . . often the identifier of a file with data defining the behaviour


of this FO instance

 gPROMS does not need to know the information inside the data
file…
 gPROMS just passes the file name to the Foreign Object code

© Process Systems Enterprise Limited

Physical properties in gPROMS


Giving a value to a foreign object
PARAMETER
phys_prop AS FOREIGN_OBJECT Name of the configuration file
Name of physical property package, e.g. for physical property package,
SET “Multiflash”
phys_prop := "Multiflash::methanol_water.mfl" ;

…or… By default, Multiflash performs molar-based calculations.


Optionally, specify “mass” to perform mass-based calculations.
SET
phys_prop := “Multiflash::mass:methanol_water.mfl” ;

gSAFT: Statistical Associating Fluid


…or… Theory specify components to be used from
database file
SET
phys_prop := “gSAFT::VR_SW_databank.dtb<methanol,water>”
;
Database file
© Process Systems Enterprise Limited

Page 50 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Flash train example

Feed Product

Flash(1) Flash(2) Flash(NoFlash)

© Process Systems Enterprise Limited

Physical properties in gPROMS


Flash train example I
MODEL FlashTrain

PARAMETER
NoComp AS INTEGER
NoFlash AS INTEGER
phys_prop AS FOREIGN_OBJECT

UNIT
Flash AS ARRAY ( NoFlash ) OF Flash

END # MODEL FlashTrain

PROCESS SimTrain

UNIT
SeparationSection AS FlashTrain

SET
SeparationSection.phys_prop := "Multiflash::methanol_water.mfl" ;

END # PROCESS SimTrain

© Process Systems Enterprise Limited

Page 51 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Flash train example II
MODEL CryoPlant

UNIT
LowTempSeparationSection AS FlashTrain
HighTempSeparationSection AS FlashTrain

END # Model CryoPlant

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

END # PROCESS SimTrain

© Process Systems Enterprise Limited

Physical properties in gPROMS


Configuring materials using the Multiflash GUI

 Physical property package


developed and marketed by
Infochem Computer Services Ltd.

 Available through standard


gPROMS installation

 Export material definition to gPROMS ProcessBuilder via .mfl


data file

© Process Systems Enterprise Limited

Page 52 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Configuring materials using the Multiflash GUI

 Chemical components

Data
Source

Component
list

Component
definition

© Process Systems Enterprise Limited

Physical properties in gPROMS


Configuring materials using the Multiflash GUI

 Thermophysical models
Model Thermo
category model

Phases which
may appear

Transport
properties

© Process Systems Enterprise Limited

Page 53 © Process Systems Enterprise Ltd


Physical properties in gPROMS
Configuring materials using the Multiflash GUI

 Saving material definition

Multiflash
Configuration
file

© Process Systems Enterprise Limited

Physical properties in gPROMS


Importing a material definition into a gPROMS project

© Process Systems Enterprise Limited

Page 54 © Process Systems Enterprise Ltd


Hands-on session
Including thermodynamics within gas-phase CSTR model for the
synthesis of methanol

© Process Systems Enterprise Limited

Basic troubleshooting

Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 55 © Process Systems Enterprise Ltd


Hands-on session
Handling common errors

© Process Systems Enterprise Limited

Related gPROMS documentation


Implementing a lumped model in gPROMS

© Process Systems Enterprise Limited

Page 56 © Process Systems Enterprise Ltd


Related gPROMS documentation

 Menu: Help  Documentation


 Custom Modelling
 Declaring Variable and Connection types
 Defining Models and Processes
 Arrays
 Intrinsic gPROMS functions
 Conditional equations
 Ordered Sets
 Defining Schedules
 Physical Properties Guide

© Process Systems Enterprise Limited

Developing your own distributed model


Module 203

© Process Systems Enterprise Limited

Page 57 © Process Systems Enterprise Ltd


Contents
Developing your own distributed model

 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

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 58 © Process Systems Enterprise Ltd


Motivation
Developing your own distributed model

© Process Systems Enterprise Limited

Motivation

1. New applications/non-standard unit operations


 need to develop first-principle models from scratch

2. Library models are not suitable for each and every application
 need to customise them

 Keep in mind: combination with other models


 need to comply to some standard: model libraries

 gPROMS: an advanced and flexible environment for


 custom model development
 custom model use
 mix & match with library models

© Process Systems Enterprise Limited

Page 59 © Process Systems Enterprise Ltd


Distributed systems

 Tubular reactor

 Assumptions:
 Axial variations
 Well-mixed cooling jacket

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 60 © Process Systems Enterprise Ltd


Distributed systems
Tubular reactor

 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

© Process Systems Enterprise Limited

Distributed systems
Tubular reactor – cooling jacket

 Energy balance:

dT w
wC p,wV w  FwC p,w (T w ,in  T w )  Q
dt

 Thermal coupling with tube:


L
Q  U 2 R  [T (z )  T w ]dz
0

© Process Systems Enterprise Limited

Page 61 © Process Systems Enterprise Ltd


Distributed systems
Handling partial derivatives

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

© Process Systems Enterprise Limited

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

# Multiple integral notation


Tave = 2 / (ReactorLength * ReactorRadius^2) *
INTEGRAL(z := 0:ReactorLength ,
r := 0:ReactorRadius ; r*T(z,r)) ;

© Process Systems Enterprise Limited

Page 62 © Process Systems Enterprise Ltd


Distributed systems
Specifying distribution domains

DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]

Mathematical domain gPROMS notation


[ a, b ] a: b
(a , b ] a|+: b
[a,b) a : b|–
( a , b) a|+: b|–

FOR XDomain := a TO b DO
...
END

© Process Systems Enterprise Limited

Distributed systems
Specifying distribution domains

DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]

Mathematical domain gPROMS notation


[ a, b ] a: b
(a , b ] a|+: b
[a,b) a : b|–
( a , b) a|+: b|–

FOR XDomain := a|+ TO b DO


...
END

© Process Systems Enterprise Limited

Page 63 © Process Systems Enterprise Ltd


Distributed systems
Specifying distribution domains

DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]

Mathematical domain gPROMS notation


[ a, b ] a: b
(a , b ] a|+: b
[a,b) a : b|–
( a , b) a|+: b|–

FOR XDomain := a TO b|- DO


...
END

© Process Systems Enterprise Limited

Distributed systems
Specifying distribution domains

DISTRIBUTION_DOMAIN
XDomain AS [ a : b ]

Mathematical domain gPROMS notation


[ a, b ] a: b
(a , b ] a|+: b
[a,b) a : b|–
( a , b) a|+: b|–

FOR XDomain := a|+ TO b|- DO


...
END

© Process Systems Enterprise Limited

Page 64 © Process Systems Enterprise Ltd


Distributed systems
Specifying distribution domains

 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

© Process Systems Enterprise Limited

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
. . .

© Process Systems Enterprise Limited

Page 65 © Process Systems Enterprise Ltd


Distributed systems
Specifying boundary conditions

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
. . .

© Process Systems Enterprise Limited

Page 66 © Process Systems Enterprise Ltd


Overview

 Same as lumped MODELs:


 may involve discontinuities
 can have PORTs
 may be combined in composite models
 …

 Lumped

Lumped Distributed

© Process Systems Enterprise Limited

Extending a model
Adding distribution domains

 Axial and radial variations


C i C i  2C i Dr  C i No Re ac
 v  Dz  (r )   ij R j ,
t z z 2
r r r j 1

i  1..NoComp , z  (0, L ) , r  (0, R )

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

© Process Systems Enterprise Limited

Page 67 © Process Systems Enterprise Ltd


Hands-on session
Develop a 1D gas-phase PFR model for the
synthesis of methanol

© Process Systems Enterprise Limited

Defining and running a simulation


Method of Lines

Integral + Partial Differential +


Algebraic Equations (IPDAEs) +
Discretisation of Boundary Conditions
NON-temporal
variations

Ordinary Differential +
Algebraic Equations (DAEs)
Initialisation/
Integration

SOLUTION

© Process Systems Enterprise Limited

Page 68 © Process Systems Enterprise Ltd


Defining and running a simulation
Method of Lines

 Advantages:
 makes use of solution methods for DAEs
 allows solution of mixed lumped/distributed systems

Distributed Unit
Lumped Unit

DAEs IPDAEs

DAE system

 Discretisation methods in gPROMS:


 finite difference methods
 orthogonal collocation on finite elements

© Process Systems Enterprise Limited

Defining and running a simulation


Solution methods

 Distribution domains are discretized

 Discretization methods are user-specified parameters


 SET before simulation is executed

Numerical method Orders


Backward Finite Difference Method 1, 2
Upwind
Forward Finite Difference Method 1, 2
Centered Finite Difference Method 2, 4, 6
Central
Orthogonal Collocation on Finite Elements Method 2, 3, 4

© Process Systems Enterprise Limited

Page 69 © Process Systems Enterprise Ltd


Defining and running a simulation
Solution methods – Finite difference

 Discretise spatial domain into N intervals (equal or non-uniform


intervals):
z=0 z=L

0 1 2 k-1 k k+1 N-1 N

 Approximate partial derivatives at each node:

𝜗𝑥 𝑥𝑘 −𝑥𝑘−1
 Backward finite differences: 𝑧𝑘 =
𝜗𝑧 ℎ
𝜗𝑥 𝑥𝑘+1 −𝑥𝑘
 Forward finite differences: 𝑧𝑘 =
𝜗𝑧 ℎ
𝜗𝑥 𝑥𝑘+1 −𝑥𝑘−1
 Centered finite differences: 𝑧𝑘 =
𝜗𝑧 2ℎ
© Process Systems Enterprise Limited

Defining and running a simulation


Solution methods – Orthogonal collocation on finite elements

 Discretise spatial domain into N intervals (finite elements):

z=0 z=L

0 1 2 k-1 k k+1 N-1 N

 Assume a polynomial spatial variation for each variable in each


element:
 Polynomial of degree M (M = 2, 3, 4).
 Continuity of variable value and gradient at element boundaries

Element 1 Element 2 Element 3


© Process Systems Enterprise Limited

Page 70 © Process Systems Enterprise Ltd


Defining and running a simulation
Choosing the appropriate discretisation method

 Best choice depends on the form of the equations:



 Convective terms:  (vci )
z
 c
 Diffusive/dispersive terms: ( Di i )
z z
 Purely convective problems (hyperbolic PDEs)
 Use finite difference method
 General rule: discretisation method opposite to direction of flow
 Backward finite differences
z=0 z=L

 Forward finite differences


z=0 z=L
© Process Systems Enterprise Limited

Defining and running a simulation


Choosing the appropriate discretisation method

 Purely convective problems


 May need to used two axial domains in same MODEL

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 ] ;

© Process Systems Enterprise Limited

Page 71 © Process Systems Enterprise Ltd


Defining and running a simulation
Choosing the appropriate discretisation method

 Mixed convective/dispersive problems (parabolic PDEs)


 Use either CFDM or OCFEM
 Prefer CFDM for strongly convective problems

 Purely dispersive problems (parabolic PDEs)


 Use OCFEM
 Usually prefer high-order with small number of elements
(e.g. [OCFEM, 4, 5])

 Problems with flow reversal


 Use OCFEM
 For strongly convective problems may need low-order and large
number of elements

© Process Systems Enterprise Limited

Defining a simulation
Specifying initial conditions

 Initial conditions are general distributed equations

 Domain of initial conditions must match domain of


differential variables
 i.e. variables appearing with $ in MODEL

 STEADY_STATE is still a valid initial condition

© Process Systems Enterprise Limited

Page 72 © Process Systems Enterprise Ltd


Defining a simulation
Specifying initial conditions – Tubular reactor

# 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

 Differential variables: Ci(z,t)

INITIAL
FOR i := 1 TO NoComp DO
FOR z := 0|+ TO ReactorLength|- DO
C(i,z) = Cin(i) ;
END
END

© Process Systems Enterprise Limited

Hands-on session
Simulating a 1D gas-phase PFR

© Process Systems Enterprise Limited

Page 73 © Process Systems Enterprise Ltd


Improving computational time
Specifying grid type

 Different type of grids:


 uniform
Axial := [ CFDM, 2, 40] ;

 manually specified
Axial := [ CFDM, 2,(0.356, 0.524, 0.635,
0.719, 0.807, 0.851,
0.902, 0.945, 0.979 )] ;

 non-uniform through a transformation


Axial := [ CFDM, 2, 10, TRANSFORM( LOG, 4.0) ] ;
Axial := [ CFDM, 2, 10, TRANSFORM( EXP, 4.0) ] ;

© Process Systems Enterprise Limited

Improving computational time


Non-uniform grid transformation

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

temperature alpha=2 temperature alpha=10


© Process Systems Enterprise Limited

Page 74 © Process Systems Enterprise Ltd


Improving computational time
Non-uniform grid transformation

EXPonential transformation
Axial := [CFDM, 2, 10, TRANSFORM( EXP, alpha)] ;

Increasing  concentrates the points exp  z   1


at3.0the upper bound zˆ 
exp   1
2.5

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

Improving computational time


Non-uniform grid recommendations

 Recommended procedure:
1. start with a uniform grid
2. identify the regions with strong gradients
3. set-up the appropriate non-uniform grid

 Equivalent solution can be found with a smaller number of


grid points using non-uniform grid

 For transient problem, the region with strong gradients may


change with time  non-uniform grid may be inappropriate

© Process Systems Enterprise Limited

Page 75 © Process Systems Enterprise Ltd


Hands-on session
 Extending 1D model to 2D model
 Reducing CPU time without compromising on
accuracy for a 2D gas-phase PFR

© Process Systems Enterprise Limited

Related gPROMS documentation


Developing your own distributed model

© Process Systems Enterprise Limited

Page 76 © Process Systems Enterprise Ltd


Related gPROMS documentation

 Menu: Help  Documentation


 Custom Modelling
 Distributed Models

© Process Systems Enterprise Limited

Combining models in a hierarchy


Module 204

© Process Systems Enterprise Limited

Page 77 © Process Systems Enterprise Ltd


Contents
Combining models in a hierarchy

 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

© Process Systems Enterprise Limited

Combining models in hierarchy


Motivation

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

© Process Systems Enterprise Limited

Page 78 © Process Systems Enterprise Ltd


How to construct abstract composite models

© Process Systems Enterprise Limited

Constructing composite models


example: reaction kinetics
 Step 1: declare UNIT in higher-level model

#MODEL Reactor

PARAMETER
. . .
UNIT
kinetics AS reaction_kinetics

VARIABLE
. . .

Reactor EQUATION
. . .

Reaction kinetics

New model equations & variables added to problem!


© Process Systems Enterprise Limited

Page 79 © Process Systems Enterprise Ltd


Constructing composite models
example: reaction kinetics
New model equations & variables added to problem
Reactor
# MODEL Reaction_kinetics
PARAMETER
. . .
Reaction
VARIABLE
kinetics
molar_fraction AS ARRAY ( component_list ) OF ...
temperature AS OF ...
molar_reaction_rate AS ARRAY ( no_reactions ) OF ...

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

Need additional NC+1 equations


 These are the degrees of freedom of the sub-model.
 Resolve by adding equations in higher-level model

© Process Systems Enterprise Limited

Constructing composite models


example: reaction kinetics

 Step 2: define connecting equations in higher-level model


 NC+1 equations required
 Link new variables to existing model variables

Reactor
# MODEL Reactor

PARAMETER
. . .
Reaction kinetics
Xi UNIT
Xi kinetics AS reaction_kinetics

VARIABLE
. . .
T
T

Note: no
computational impact
© Process Systems Enterprise Limited

Page 80 © Process Systems Enterprise Ltd


Constructing composite models
example: reaction kinetics

 Step 3: can use lower-level model variables directly in


composite model equations
# MODEL Reactor

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

Assisted pathname completion: pressing


<Ctrl+space> produces a list of valid
completions of whatever you are writing
© Process Systems Enterprise Limited

Parameter propagation

© Process Systems Enterprise Limited

Page 81 © Process Systems Enterprise Ltd


Specification of PARAMETER values

3 ways of specifying PARAMETERs:

It may be overridden using an explicit or


 Default specifications implicit specification
PARAMETER
ideal_gas_constant AS REAL DEFAULT 8.314

 Explicit specifications
It can never be overridden
 In the model itself
 In other models containing instances of the above model
 In the process

 Implicit specifications (parameter propagation)

© Process Systems Enterprise Limited

Specification of PARAMETER values


examples of explicit specifications - I

MODEL reaction_kinetics

PARAMETER
NoReac AS INTEGER
A AS ARRAY ( NoReac ) OF REAL

SET
NoReac := 3 ;
A := [ 1.1E10 , 2.1E5 , 1.7E4 ] ;

END # MODEL reaction_kinetics

This option limits


generality of MODEL!

© Process Systems Enterprise Limited

Page 82 © Process Systems Enterprise Ltd


Specification of PARAMETER values
examples of explicit specifications-II

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 ] ;

END # PROCESS Simulation


More general option

© Process Systems Enterprise Limited

Specification of PARAMETER values


implicit specifications

 Any specification of a PARAMETER that appears in a


composite MODEL is inherited by other PARAMETERs which:
 appear in MODEL instances which occur directly within the
composite MODEL
 have exactly the same name, type and size as the specified
PARAMETER
 have not been specified explicitly

 The above rule is recursive


 Automatic "parameter propagation" through gPROMS MODEL
hierarchies !

© Process Systems Enterprise Limited

Page 83 © Process Systems Enterprise Ltd


Example of parameter propagation

Reactor train PARAMETER


NoComp, NoReac AS INTEGER
A,E AS ARRAY(NoReac) OF REAL
UNIT
RRR AS ARRAY(10) OF Reactor
SET
NoReac := 3 ;
A := [1.1E10. 2.1E5, 1.7E4] ;

Reactor
PARAMETER
NoComp, NoReac AS INTEGER

UNIT
kn AS RxnKinetic

Reaction kinetics PARAMETER


NoComp, NoReac AS INTEGER
A, E AS ARRAY(NoReac) OF REAL
R AS REAL DEFAULT 8.314
VARIABLE
. . . . . . . . . . . .
EQUATION
. . . . . . . . . . . .

© Process Systems Enterprise Limited

Composite/component models
Summary
 Contain one or more other instances of component (lower-
level) models as declared in the UNIT section

 Construction of a composite model can be done


 using the gPROMS language
 graphically on the topology tab (flowsheeting)
 through a combination of the above

 A composite model contains connectivity equations


 With only lower-level model variables
 Combining lower-level and higher-level model variables

© Process Systems Enterprise Limited

Page 84 © Process Systems Enterprise Ltd


Composite/component models
Summary
 Component models may be stored:
 in the same project as the composite (higher-level) model
 in cross-referenced libraries or projects

 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

© Process Systems Enterprise Limited

Hands-on session

Combining models in a hierarchy

© Process Systems Enterprise Limited

Page 85 © Process Systems Enterprise Ltd


Visibility of variables in lower-level models

© Process Systems Enterprise Limited

Visibility of variables in lower-level models


Reaction kinetics
Reactor train Reactor
kinetic
mechanism 1
Plant Reaction Section
kinetic
mechanism 2 Variable α

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

Page 86 © Process Systems Enterprise Ltd


Related gPROMS documentation

Combining models in a hierarchy

© Process Systems Enterprise Limited

Related gPROMS documentation

 Menu: Help  Documentation


 Composite models

© Process Systems Enterprise Limited

Page 87 © Process Systems Enterprise Ltd


Making models robust
Module 205

© 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

© Process Systems Enterprise Limited

Page 88 © Process Systems Enterprise Ltd


Motivation
Making your models robust

© Process Systems Enterprise Limited

Motivation

 Modelling trends:
 Models getting bigger
 Models becoming more detailed (more non-linear)

 gPROMS is based on Newton solver


 Need initial guesses for all variables

 Initialisation procedures aid in the initialisation of a


model from a poor initial guess
 Up to 50% of modelling effort
 Necessary for non-expert users to initialise complex models

© Process Systems Enterprise Limited

Page 89 © Process Systems Enterprise Ltd


Initialisation procedures
Making models robust

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 90 © Process Systems Enterprise Ltd


Introduction

© Process Systems Enterprise Limited

Sources of initial guesses

 Default value in Variable Type

 PRESET section in PROCESS and MODEL

© Process Systems Enterprise Limited

Page 91 © Process Systems Enterprise Ltd


Sources of initial guesses
PRESET section

 Specify guesses for variables


PRESET
Plant.Column.Condenser.T := 357 ;
Plant.Column.Reboiler.T := 390 ;

 Restore guesses from previously SAVEd files (Saved Variable


Sets)
 Does NOT restore selector values (set in INITIALSELECTOR
section)
PRESET
RESTORE “10min"

 Combination of the above


PRESET
RESTORE “10min"
Plant.Column.Condenser.T := 357 ;
Plant.Column.Reboiler.T := 390 ;

© Process Systems Enterprise Limited

Sources of initial guesses


Saved Variable Sets

 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

© Process Systems Enterprise Limited

Page 92 © Process Systems Enterprise Ltd


Sources of initial guesses
Saved Variable Sets

 Copy the SAVEd file into the working project

 Stored in Saved Variable Sets folder

© Process Systems Enterprise Limited

Sources of initial guesses


Saved Variable Sets

 RESTORE task

 Restores previously SAVEd variable values


 When used in PRESET, it is executed before initialisation to
provide initial guesses

PROCESS # Facilitate initialisation


...
PRESET
RESTORE “10min”
...

© Process Systems Enterprise Limited

Page 93 © Process Systems Enterprise Ltd


Sources of initial guesses

 Default value in Variable Type

 PRESET section in PROCESS and MODEL

 Priority: PRESET explicitly > PRESET with RESTORE > Variable types
© Process Systems Enterprise Limited

What is an initialisation procedure?

 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

Page 94 © Process Systems Enterprise Ltd


What is an initialisation procedure?

 State of a model defined by:


 EQUATIONs in MODEL
 SET values of PARAMETERs
 Choice and ASSIGNed values of degrees of freedom
 Initialisation procedure (IP) is…
 … a sequence of model states…
 … and a way of moving from one state to the next

Final State
Initial State
Next state … Next State (original
(as defined)
model)

JUMP_TO Or… MOVE_TO


instantaneously in a smooth path

© Process Systems Enterprise Limited

General approach

1. Use an IP to solve initially a simplified form of unit


operation models
2. Add complexity to the unit models in steps until the
“real” unit model is solved
UNIT-LEVEL

3. Use an IP to modify flowsheets so that units are not


solved simultaneously
4. Revert all units and the flowsheet back to the original
problem
FLOWSHEET-LEVEL

© Process Systems Enterprise Limited

Page 95 © Process Systems Enterprise Ltd


Development of initialisation procedures

© Process Systems Enterprise Limited

Unit-level initialisation procedures

1. Add the INITIALISATION_PROCEDURE keyword to


the bottom (after EQUATIONs) of the MODEL entity (and
name it)

2. Define list of modifications/simplifications with which


the IP is started

3. Define sequence of steps to increase complexity

4. If any simplifications from step 2 are not reverted,


gPROMS will (implicitly) automatically revert them

© Process Systems Enterprise Limited

Page 96 © Process Systems Enterprise Ltd


Unit-level initialisation procedures

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
...

{IMPLICIT REVERT OF ALL REMAINING CHANGES IN START SECTION


BY gPROMS} 4

© Process Systems Enterprise Limited

Unit-level initialisation procedures

 The model can be changed in two ways:


 Instantaneous change
JUMP_TO
#Insert list of modifications to the model here
END
 Smooth change
MOVE_TO
#Insert list of modifications to the model here
END

JUMP_TO MOVE_TO
Advantage Faster More Robust
Disadvantage Less Robust Slower

© Process Systems Enterprise Limited

Page 97 © Process Systems Enterprise Ltd


Unit-level initialisation procedures

 General syntax:
 Explicit change to VARIABLE/PARAMETER/SELECTOR
JUMP_TO or MOVE_TO
<variable> := <new value>;
END

 Revert to originally specified value in


SET/ASSIGN/INITIALSELECTOR
JUMP_TO / MOVE_TO
REVERT <variable>;
END

© Process Systems Enterprise Limited

Unit-level initialisation procedures

 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.

2. Make complex relations explicit in the variable for which they


solve
 E.g.: 𝑦 = 𝑓 𝑇, 𝑃, 𝑥
3. Ensure complex relations are not “out of range”
 Model input variables may take “unrealistic” values

© Process Systems Enterprise Limited

Page 98 © Process Systems Enterprise Ltd


Unit-level initialisation procedures

 Guidelines:

1. Ensure first step works for variety of input conditions

2. Avoid problem specific information

3. When using MOVE_TO, ensure it represents a realistic and


continuous physical path

© Process Systems Enterprise Limited

Unit-level initialisation procedures

 Techniques associated with IPs:

 Using simplified equations

 Change the value of a PARAMETER

 Change the value of a degree of freedom

 Change the choice of a degree of freedom

© Process Systems Enterprise Limited

Page 99 © Process Systems Enterprise Ltd


Unit-level initialisation procedures
Using simplified equations – CSTR example

 Isothermal mode:
𝑑𝑇
=0
𝑑𝑡

 Adiabatic mode:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗
𝑑𝑡 𝑗=1

 Full mode:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1

© Process Systems Enterprise Limited

Unit-level initialisation procedures


Using simplified equations – CSTR example

SELECTOR

EnergyMode AS (Isothermal, Adiabatic, Full) DEFAULT Full

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

© Process Systems Enterprise Limited

Page 100 © Process Systems Enterprise Ltd


Unit-level initialisation procedures
Using simplified equations – CSTR example

INITIALISATION_PROCEDURE IP_SimpleEnergyBalance
START
EnergyMode := Isothermal ;
END

NEXT
MOVE_TO
EnergyMode := Adiabatic ;
END
END

NEXT
MOVE_TO
EnergyMode := Full ;
END
END

© Process Systems Enterprise Limited

Unit-level initialisation procedures


Changing the value of a PARAMETER – CSTR example

 Energy balance:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1

May cause failure during initialisation IF highly


exothermic reaction is considered
© Process Systems Enterprise Limited

Page 101 © Process Systems Enterprise Ltd


Unit-level initialisation procedures
Changing the value of a PARAMETER – CSTR example

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

© Process Systems Enterprise Limited

Unit-level initialisation procedures


Changing the value of a degree of freedom – CSTR example

 Energy balance:
𝑑𝑈 𝑁𝑟
= 𝐹𝑖𝑛 ℎ𝑖𝑛 − 𝐹𝑜𝑢𝑡 ℎ + 𝑉 𝑟𝑗 ∆𝐻𝑅𝑗 + 𝑄
𝑑𝑡 𝑗=1

Depends on steam flowrate through vessel


jacket or coil
© Process Systems Enterprise Limited

Page 102 © Process Systems Enterprise Ltd


Unit-level initialisation procedures
Changing the value of a degree of freedom – CSTR example

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

Unit-level initialisation procedures


Changing the choice of a degree of freedom – PFR example

 Fractional conversion:
𝑝𝑠𝑜𝑢𝑟𝑐𝑒1 𝑅𝑇𝑠𝑜𝑢𝑟𝑐𝑒 − 𝐶1 (𝐿)
𝜉=
𝑝𝑠𝑜𝑢𝑟𝑐𝑒1 𝑅𝑇𝑠𝑜𝑢𝑟𝑐𝑒

 Common procedure:
 Specify 𝐿 (length of reactor) and calculate 𝜉
 Specify 𝜉 and calculate 𝐿
 May present problems during initialisation

© Process Systems Enterprise Limited

Page 103 © Process Systems Enterprise Ltd


Unit-level initialisation procedures
Changing the choice of a degree of freedom – PFR example

𝑧 𝑧
𝑧
𝑧=
𝐿
0 L 0 1
DISTRIBUTION_DOMAIN

Axial AS [0:1] # normalised

VARIABLE

...
ReactorLength AS length_gML
C AS DISTRIBUTION(NoComp,Axial) OF molar_concentration_gML
Conversion AS no_type_gML

EQUATION

Conversion = (Psource(1) / (Rg * Tsource) – C(1,1)) /


(Psource(1) / (Rg * Tsource)) ;
© Process Systems Enterprise Limited

Unit-level initialisation procedures


Changing the choice of a degree of freedom – PFR example

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 Systems Enterprise Limited

Page 104 © Process Systems Enterprise Ltd


Unit-level initialisation procedure
Executing initialisation procedures

 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:

© Process Systems Enterprise Limited

Unit-level initialisation procedure


Executing initialisation procedures

 IPs controlled from the Simulation activity dialog


 Run only the IP, then stop
 Execute IP, then continue with main
simulation activity
 Ignore IP (use of Saved Variable Sets)

SVS

Initial State Final


… … Solution
(as defined) State

Solution

© Process Systems Enterprise Limited

Page 105 © Process Systems Enterprise Ltd


Flowsheet-level initialisation procedures

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
...

{IMPLICIT REVERT OF ALL REMAINING CHANGES IN START SECTION


BY gPROMS}

© Process Systems Enterprise Limited

Flowsheet-level initialisation procedures

 Allows the user to:

 Determine the order in which models initialise


NEXT
COMPLETE Unit_1 Run the IP for a certain unit
END
NEXT
COMPLETE Unit_2
END

 Control individual steps in each unit IP


ADVANCE Unit_1 Execute a single step of a
unit IP

© Process Systems Enterprise Limited

Page 106 © Process Systems Enterprise Ltd


Flowsheet-level initialisation procedures

 Use of COMPLETE and ADVANCE to control execution of


lower-level IPs
INITIALISATION_PROCEDURE

START CSTR example – energy balance


#Step 1
END Isothermal
NEXT
ADVANCE Isothermal
#Step 2
END
NEXT Adiabatic COMPLETE
ADVANCE
#Step 3
END
... ADVANCE Full
<IMPLICIT REVERT>

Full

© Process Systems Enterprise Limited

Hands-on session
Making models robust

© Process Systems Enterprise Limited

Page 107 © Process Systems Enterprise Ltd


Related gPROMS documentation
Initialisation procedures

© Process Systems Enterprise Limited

Related gPROMS documentation

 Menu: Help  Documentation


 Custom Modelling
 Initialisation Procedures

© Process Systems Enterprise Limited

Page 108 © Process Systems Enterprise Ltd


Troubleshooting
Making models robust

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 109 © Process Systems Enterprise Ltd


Introduction
Dynamic simulation failures

 Typical dynamic simulation


Integrate Integrate

Initialise Re-initialise Re-initialise

 Occurrences of failures:
 At initialisation
 At re-initialisation Frequency
 During integration

© Process Systems Enterprise Limited

Introduction
gPROMS execution output

gPROMS version

Top-level parameter
settings

Solution parameter
settings

Resolving
parameters

Initial selectors,
Jacobian expression,
Etc.

© Process Systems Enterprise Limited

Page 110 © Process Systems Enterprise Ltd


Introduction
gPROMS execution output

Structural
analysis

Model pruning Re-initialisation

Initialisation

Integration

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 111 © Process Systems Enterprise Ltd


Introduction
gPROMS execution output

 Retain license after execution


 Access diagnostics

© Process Systems Enterprise Limited

Introduction
gPROMS execution output

Click on the block


link to query the
equations of the block

 Note: The license for running a simulation is held


© Process Systems Enterprise Limited

Page 112 © Process Systems Enterprise Ltd


Introduction
gPROMS execution output
The output provides
the list of variables and
equation numbers …

… the equation(s) …
… the current values
of variables …

… and the block where


the value is calculated

© Process Systems Enterprise Limited

Introduction
gPROMS execution output

 To release license: right-click case file


© Process Systems Enterprise Limited

Page 113 © Process Systems Enterprise Ltd


Failures at initialisation

 Problem being solved:


𝐹 𝑥 0 ,𝑥 0 ,𝑦 0 =0

 Block decomposition:
 Sequence of smaller problems

 Modes of failure:
 Structural singularity
 Failure in linear block
 Illegal arithmetic operation
 Convergence failure in non-linear block

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 114 © Process Systems Enterprise Ltd


Failures at initialisation
Failure in linear block

 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

Page 115 © Process Systems Enterprise Ltd


Failures at initialisation
Convergence failure in non-linear block

 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

© Process Systems Enterprise Limited

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

 Suspected case – Problem badly posed


 Query variable and equation
 Consider scaling/rewriting equation

 Suspected case – Solution does not exist for ASSIGNed variables


 Check input values of ASSIGNed variables: are they in the model application
range?

© Process Systems Enterprise Limited

Page 116 © Process Systems Enterprise Ltd


Failures at initialisation
Convergence failure in non-linear block

 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

© Process Systems Enterprise Limited

Failures at re-initialisation

 Causes similar to initialisation

 Easier to diagnose

 Re-initialisation following RESET may detect a high-index


DAE that was not diagnosed at initialisation

© Process Systems Enterprise Limited

Page 117 © Process Systems Enterprise Ltd


Failures during integration

 gPROMS is unable to take a successful step in time

 Modes of failure:
 Trajectory attempts to go through variable bounds

 Repeated corrector or error test failure

© Process Systems Enterprise Limited

Failures during integration


Trajectory attempts to go through variable bounds

 Diagnosis:
 Report of variable and bound involved

 Cause:
 Incorrect variable bounds
 Insufficient integration accuracy
 Incorrect model equations

© Process Systems Enterprise Limited

Page 118 © Process Systems Enterprise Ltd


Failures during integration
Trajectory attempts to go through variable bounds

 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

 Check equations/parameters related to the


variable going through bound
 e.g. if temperature too high, check energy
balance

© Process Systems Enterprise Limited

Failures during integration


Repeated corrector or error test failures

 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

© Process Systems Enterprise Limited

Page 119 © Process Systems Enterprise Ltd


Failures during integration
Repeated corrector or error test 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)

 Consider simplifying model and gradually increase complexity

© Process Systems Enterprise Limited

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: Use “sendmathinfo” in SCHEDULE and check variables/equations causing


the problem
© Process Systems Enterprise Limited

Page 120 © Process Systems Enterprise Ltd


Modelling tips
Distributed models

 Appropriate discretisation method

 Mixed convective/dispersive problems: CFDM or OCFEM


 Purely dispersive problems: OCFEM (prefer high-order with small
number of elements)
 Flow reversal problems: OCFEM (prefer large number of
elements)

 Note: to get more information, try a small number of discretisation intervals, e.g.
Axial := [CFDM,1,5]
© Process Systems Enterprise Limited

Related gPROMS documentation


Troubleshooting

© Process Systems Enterprise Limited

Page 121 © Process Systems Enterprise Ltd


Related gPROMS documentation

 Menu: Help  Documentation


 Custom Modelling
 Controlling the Execution of Model-based Activities
 Model Analysis and Diagnosis

© Process Systems Enterprise Limited

Estimating model parameters from


experimental data
Module 206

© Process Systems Enterprise Limited

Page 122 © Process Systems Enterprise Ltd


Contents
Estimating model parameters from experimental data

 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

© Process Systems Enterprise Limited

Contents
Estimating model parameters from experimental data

 Executing aparameter estimation


 Hands-on session
 Estimating reaction parameters for synthesis of methanol
in a gas-phase CSTR
 Analysing the results from parameter estimation
 Methods to improve an estimation
 Statistical analysis within MS Excel
 Hands-on session
 Re-parameterisation of the model of kinetic reaction
scheme
 Related gPROMS documentation

© Process Systems Enterprise Limited

Page 123 © Process Systems Enterprise Ltd


Motivation
Estimating model parameters from experimental data

© Process Systems Enterprise Limited

Motivation
Estimating model parameters from experimental data

 Process models usually involve parameters that can be


adjusted to make the model predictions match
observed reality
 Examples: reaction kinetic constants, heat transfer
coefficients, distillation stage efficiencies, constants within
physical property correlations, etc.

 The more accurate these parameters are, the closer


the model response is to reality

© Process Systems Enterprise Limited

Page 124 © Process Systems Enterprise Ltd


Motivation
Estimating model parameters from experimental data

 Parameter estimation is usually achieved by


 manually ‘tweaking’ parameters
 performing dozens/hundreds of simulations

 gPROMS contains powerful, state-of-the art Parameter


Estimation capabilities :
 Multiple parameters occurring in dynamic or steady-state
models may be estimated simultaneously.
 Data from both dynamic and steady-state experiments may be
used.
 Results of the estimation are subjected to extensive statistical
analysis.
© Process Systems Enterprise Limited

What is required prior to a model validation


exercise

© Process Systems Enterprise Limited

Page 125 © Process Systems Enterprise Ltd


The Model-based Engineering cycle

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

© Process Systems Enterprise Limited

Parameter estimation
Illustrative example

 Batch reactor

A+B C+D  Endothermic reaction


A+BC+D

Electrical
Heating
Element

© Process Systems Enterprise Limited

Page 126 © Process Systems Enterprise Ltd


Batch reactor
Mathematical model

 Component mass balance


dM i
 vi rV , i  A ..D
dt
 Energy balance

 rV  H R   Q
dH
dt
 Reaction rate
r  kC AC B

 Arrhenius temperature dependence

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

© Process Systems Enterprise Limited

Page 127 © Process Systems Enterprise Ltd


Batch reactor
Estimation problem

 Values of kinetic parameters are uncertain

 Objective: to estimate the following kinetic parameters from


experimental data

k 0, E , H R

© Process Systems Enterprise Limited

What is required prior to a model validation exercise?

 Experiments that provide required information for model at


different conditions (e.g. T, P, x)

 Each experiment i = 1 ,…, NE is characterised by:


 Specifications:
 Overall duration
 Initial conditions, v
 Variation of control variables, u(t)
 Values of time-invariant parameters, p

 Results: data pairs 𝑡𝑖𝑗𝑘 , 𝑧𝑖𝑗𝑘 collected during each experiment,


where 𝑧𝑖𝑗𝑘 is the kth value measured for the jth variable and can
be either a differential variable x or an algebraic variable y

© Process Systems Enterprise Limited

Page 128 © Process Systems Enterprise Ltd


Batch reactor
Dynamic experiment #1

Initial conditions Heating policy


MA = 100 mol
MB = 100 mol Q = 505kW , 0 < t <100
MC = MD = 1 mol Q = 0 , 100 < t<400
T = 293K
Reactant and product
Reactor Temperature
concentrations
t(s) T(K) CA (mol/m3) CC (mol/m3)
10 412.5 3746.9 898.6
20 504.2 2518.6 2358.9
30 603.5 1504.1 3634.9
40 715.3 883.8 4407.9
50 837.8 548.1 4849.8
… … … …

© Process Systems Enterprise Limited

Batch reactor
Dynamic experiment #2

Initial conditions Heating policy


MA = 100 mol
MB = 100 mol Q = 505kW , 0 < t <100
MC = MD = 1 mol Q = 0 , 100 < t<400
T = 293K
Reactant and product
Reactor Temperature
concentrations
t(s) T(K) CA (mol/m3) CC (mol/m3)
10 412.5 3700.8 898.2
20 504.2 2520.9 2380.4
30 603.5 1502.4 3626.6
40 715.3 894.4 4388.9
50 837.8 545.1 4828.0
… … … …

...and so on for the other experiments.


© Process Systems Enterprise Limited

Page 129 © Process Systems Enterprise Ltd


Setting up an already performed experiment

© Process Systems Enterprise Limited

Experiments entity

 Each experiment entity contains the


description and results of a different
experiment

Entity name: EXPNAME, where EXPNAME


is the name used to identify the experiment
in the Estimation entity

© Process Systems Enterprise Limited

Page 130 © Process Systems Enterprise Ltd


Experiments entity
General tab
PROCESS to be used
for specifications
Saved variable set (if any) to be
used to aid in initialisation

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

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 131 © Process Systems Enterprise Ltd


Experiments entity
Controls tab - Time-invariant

 Identify time-invariant parameters and specify value

Tin

505

0
t

© Process Systems Enterprise Limited

Experiments entity
Controls tab – Piecewise-constant

 Identify piecewise constant parameters and specify value for


each interval

Tin

505

0
100 400
t

© Process Systems Enterprise Limited

Page 132 © Process Systems Enterprise Ltd


Experiments entity
Controls tab – Piecewise-linear

 Identify piecewise linear parameters and give value at


start and end of each interval

Tin

505
400
300

0
100 400
t

© Process Systems Enterprise Limited

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

© Process Systems Enterprise Limited

Page 133 © Process Systems Enterprise Ltd


Experiments entity
Measured data tab – Variance model

Overwrites variance
model specified in the
Estimation entity

 Sensors are discussed in estimation section

© Process Systems Enterprise Limited

Experiments entity
gPROMS language tab

 Automatically generated by the dialogs in the other tabs


© Process Systems Enterprise Limited

Page 134 © Process Systems Enterprise Ltd


Simulate a performed experiment

© Process Systems Enterprise Limited

Experiments entity
Simulating experiments

 Before running the parameter estimation, ensure that model


runs robustly for control schemes of each experiment

 Experiments can be simulated directly


 Using assigned values in PROCESS for parameters to be
estimated
 Using control strategy in experiment (time-invariant, piecewise-
constant, piecewise-linear)
 Duration of experiment simulation – either final interval of
control strategy or time of final measurement (whichever is last)
 Process automatically created containing all this information

© Process Systems Enterprise Limited

Page 135 © Process Systems Enterprise Ltd


Experiments entity
Simulating experiments

 Steps:

1. Ensure PROCESS is specified on


the General tab of Performed
Experiment

2. Select Experiment entity in


Project Tree

3. From the Activities menu, select


Simulate... (or click the short-cut
button on the tool bar)

© Process Systems Enterprise Limited

Hands-on session
Creating and simulating an already performed experiment

© Process Systems Enterprise Limited

Page 136 © Process Systems Enterprise Ltd


Parameter estimation

© Process Systems Enterprise Limited

Batch reactor
Experimental data vs. model predictions

 Estimating parameter values manually:


e.g. k  6.5  104 m 3mol 1s 1
0

E  20000 J mol 1
H R  55000 J mol 1

Concentration of A - Experiment #1

Temperature - Experiment #1

© Process Systems Enterprise Limited

Page 137 © Process Systems Enterprise Ltd


Parameter estimation
Theory

 As with optimisation, one could do hundreds of manual


simulations trying to fit the model

 Better to use formal, mathematically-based methods


 provided as standard within gPROMS

 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


   

Choose  to maximise the probability that the model predictions will


match the experimental results (maximum likelihood goal1).

1Aldrich J.(1997),Statistical Science 12 (3): 162–176

© Process Systems Enterprise Limited

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

Page 138 © Process Systems Enterprise Ltd


Parameter estimation
Statistical variance models

 Relate measurement errors to magnitudes of measured


variables

 Different types of variance models


 CONSTANT_VARIANCE
 CONSTANT_RELATIVE_VARIANCE
 HETEROSCEDASTIC
 LINEAR_VARIANCE

© Process Systems Enterprise Limited

Parameter estimation
Statistical variance models

 If errors do not depend on magnitude of measurements


 CONSTANT_VARIANCE model
 2  2
 If errors are directly proportional to magnitude of measurements
 CONSTANT_RELATIVE_VARIANCE model

 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

© Process Systems Enterprise Limited

Page 139 © Process Systems Enterprise Ltd


Relations

 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


   

 Sum of squares optimisation:


 Same number of experiments for each measurement
 Same constant variance for all experiments and measurements

 Weighted sum of squared residuals:


 Same number of experiments for each measurement
 Different variance for each measurements

© Process Systems Enterprise Limited

Setting up a parameter estimation

© Process Systems Enterprise Limited

Page 140 © Process Systems Enterprise Ltd


Information required

 Process model (MODEL, PROCESS)

 Information relating to the overall parameter estimation


problem
 Parameters to be estimated
 Variance models
 Experiments

 Information on individual experiments


 Initial conditions
 Time-invariant parameters
 Time-varying controls
 Measurements
© Process Systems Enterprise Limited

Information required
Relevant entities in gPROMS Project File

Process model

Information on individual experiments


used for parameter estimation

Definition of parameter
estimation problem

© Process Systems Enterprise Limited

Page 141 © Process Systems Enterprise Ltd


Process Model

 Same as for dynamic simulation!

 Minimum structure required


that describes the experiment

© Process Systems Enterprise Limited

Process Model
MODEL section

 Must be robust over entire range of values of parameters 


 “Parameters” to be estimated must be VARIABLEs (not
PARAMETERs !) in the MODEL

Simulation Parameter estimation

© Process Systems Enterprise Limited

Page 142 © Process Systems Enterprise Ltd


Process Model
PROCESS section

 The following must be ASSIGNed:


 Time-varying controls for experiments, u(t)
 Time-invariant “parameters” for experiments, p
 Unknown “parameters” to be estimated, 

 The variables that will be used to specify the initial conditions


in each experiment must be INITIALised:
 Same subset of variables for all experiments
 Values specified are ignored !

 PRESET may be used to provide initial guesses

 SCHEDULE is ignored - represented through experiments

© Process Systems Enterprise Limited

Process Model
PROCESS section

 “Parameters” to be estimated must be now ASSIGNED (not SET!) in


the PROCESS

Simulation Parameter estimation

© Process Systems Enterprise Limited

Page 143 © Process Systems Enterprise Ltd


Parameter estimation entity
Experiments & measurements

Experiments to be included
in the parameter estimation

Statistical variance
model and associated
parameters for
measured variables

© Process Systems Enterprise Limited

Parameter estimation editor


Experiments & measurements

© Process Systems Enterprise Limited

Page 144 © Process Systems Enterprise Ltd


Parameter estimation entity
Variance models

 Variance models may already have been specified in experiment


entity or they can specified in the parameter estimation entity
Priority: Estimation > Experiment

 If you have information on the measurement errors, use it! Fix 


and/or  whenever possible
 If a measured variable is to have different variance models
and/or different sets of parameter values in different
experiments, it can be specified in either the parameter
estimation or the experiment entities
 Similar measurements can be grouped into sensors with same
variance models

© Process Systems Enterprise Limited

Parameter estimation entity


Specifying Variance model

© Process Systems Enterprise Limited

Page 145 © Process Systems Enterprise Ltd


Parameter estimation entity
Grouping sensors

© Process Systems Enterprise Limited

Parameter estimation entity


Parameters to be estimated

Initial guess for each parameter to be If fixed, selected parameter no longer


estimated estimated

Complete variables
pathname

Lower and upper bounds


for each parameter to be
estimated

© Process Systems Enterprise Limited

Page 146 © Process Systems Enterprise Ltd


Parameter estimation entity

 Summary and completeness check


 At bottom of “Parameters to be estimated” and “Experiments &
measurements” tabs
 Number of parameters to be estimated
 Physical model parameters
 Variance model parameters

 Warning if not all measurements have been given a variance model

© Process Systems Enterprise Limited

Parameter estimation editor


gPROMS language

Automatically populated in
gPROMS language tab

© Process Systems Enterprise Limited

Page 147 © Process Systems Enterprise Ltd


Executing a parameter estimation

© Process Systems Enterprise Limited

Running parameter estimation

1. Prepare MODEL entity and PROCESS entity YYY

2. Prepare one or more Experiment entities with experiment


results

3. Prepare Estimation entity YYY

4. Execute parameter estimation run ...

© Process Systems Enterprise Limited

Page 148 © Process Systems Enterprise Ltd


Running parameter estimation

2. Run Parameter estimation from


Activities menu or by
selecting the estimation icon

1. Select Parameter Estimation entity

© Process Systems Enterprise Limited

Running parameter estimation

Tick to include results trajectory in Case

Tick to send results to gRMS

Select stages of the optimisation that the values


are recorded into the results trajectory

 Final results: no values recorded until an


optimal solution found
 Major iterations (slow): values recorded at
every major iteration
 Every step (very slow): as above, plus values
recorded during line-search steps of the
optimisation (useful for diagnosing problems)

© Process Systems Enterprise Limited

Page 149 © Process Systems Enterprise Ltd


Running parameter estimation

 It is possible to stop the


parameter estimation activity
while it is running

 Accept results of most recent


iteration
 If activity runs for a long time
and only small improvement is
made with iterations
 Results reported show sufficient
improvement over original

© Process Systems Enterprise Limited

Hands-on session
Estimating reaction parameters for synthesis of methanol
in a gas-phase CSTR

© Process Systems Enterprise Limited

Page 150 © Process Systems Enterprise Ltd


Analysing the results from parameter estimation

© Process Systems Enterprise Limited

Reporting results

 What if somebody told us the result of a parameter estimation


is:
p1  100.4563

Is this a good result?

 We need statistical information, at least standard deviation:

p1  100.4563  0.0005 Good accuracy


p1  100.4563  1105 Very bad result

Better: more statistical information (e.g. confidence intervals,


correlation matrices, etc.)

© Process Systems Enterprise Limited

Page 151 © Process Systems Enterprise Ltd


Results files

 Parameter estimation results


 Estimation results report
(YYY): html interactive file
 Estimation output file
(YYY.out)
Parameter
estimation  Parameters file
results files (YYY.params)
 Statistics - Machine readable
file(YYY.stat-mr)
Experiment  Experiment results
results files
 Variable trajectories

© Process Systems Enterprise Limited

Parameter estimation report


Summary

Summary of
information

Contents list

© Process Systems Enterprise Limited

Page 152 © Process Systems Enterprise Ltd


Parameter estimation report
Objective function

 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

Parameter estimation report


Estimated parameters

Percentage accuracy of the estimated Standard deviation << final


parameters, with respect to 95% value indicates a good
confidence intervals estimation

Interval 95% t-value << reference t-value indicates that


the available data from these experiments may not
be sufficient to estimate the parameter precisely.
© Process Systems Enterprise Limited

Page 153 © Process Systems Enterprise Ltd


Parameter estimation report
Statistical significance

 If the confidence intervals are << respective estimated


parameter value and the 95% t-value is << 95% reference t-
value, all the estimated parameters are likely to be fine
 If not and the 95% t-value is highlighted, this indicates that too
many parameters are being estimated for the amount of data.
In that case we need to:
 Add more experimental data or
 Re-parameterise model or
 Fix some parameters

© Process Systems Enterprise Limited

Parameter estimation report


Correlation matrix

Off-diagonal elements close to 1 or -1 indicate strong correlation between two


parameters. Ideally want a matrix with elements close to 0.
k  k 0e E / R T

May need decoupling through different experimental conditions or through model


 E 1 1 
changes, e.g. k  A  exp    
T T
  (this decouples A and E to some extent and

 R  ref 
focuses the results to be optimal around Tref)

© Process Systems Enterprise Limited

Page 154 © Process Systems Enterprise Ltd


Parameter estimation report
Lack of fit

 Compare weighted residual with c2-value


 Good fit: weighted residual < c2-value
 Bad fit: weighted residual > c2-value
(model may be inadequate representation of physical system)

© Process Systems Enterprise Limited

Parameter estimation report


Measurements

 Ability to plot measured variables in report file


 Predicted values and measured values for each experiment with
standard deviation

© Process Systems Enterprise Limited

Page 155 © Process Systems Enterprise Ltd


Analysing the results from parameter estimation

Statistical analysis within MS Excel

© Process Systems Enterprise Limited

Statistics
machine readable file (.stat-mr)

 Used by MS ExcelTM for enhanced statistical analysis


Steps required to analyse results
 Double click the file in the case results. This automatically loads
it into Excel
 Alternatively
 Export file YYY.stat-mr from the Activity case (with file extension
.stat-mr)
 From the start menu in Windows, click on Process Systems
Enterprise and then Parameter Estimation Results
(Excel)
 Click on the Enable Macros button
 Click on Parameter Estimation on the Excel toolbar
 Click on Import File, navigate to the YYY.star-mr file and open it

creates various statistical spreadsheets and plots
© Process Systems Enterprise Limited

Page 156 © Process Systems Enterprise Ltd


Statistics
Selected spreadsheets

 Summary sheet
 Contributions to objective function
 Model parameters marked in red have not been estimated well
or are at their bounds

© Process Systems Enterprise Limited

Statistics
Selected spreadsheets

 Parameter Estimates sheet


 Estimated values of process model and variance models’
parameters together with respective bounds

© Process Systems Enterprise Limited

Page 157 © Process Systems Enterprise Ltd


Statistics
Selected spreadsheets

 Measured Summary sheet


 Compares experimental data with model predictions
 Prints residuals for each measurement
 Enables potential outliers to be spotted

© Process Systems Enterprise Limited

Statistics
Selected spreadsheets

 Statistical Significance sheet


 Most important spreadsheet
 Check confidence intervals and individual 95% t-values

© Process Systems Enterprise Limited

Page 158 © Process Systems Enterprise Ltd


Statistics
Selected spreadsheets

 Correlation Matrix sheet


 High correlation if off-diagonal elements are close to 1 or -1

© Process Systems Enterprise Limited

Statistics
Statistical plots

 These are an alternative to the spreadsheets


(for those who think pictorially)

 Three types
 Overlay charts
 Residual charts
 Confidence ellipsoids

 To create, choose the plot option from the Add-ins→


Parameter Estimation menu on the top toolbar

© Process Systems Enterprise Limited

Page 159 © Process Systems Enterprise Ltd


Statistical plots
Overlay charts

 Overlay measured and predicted variables for each variable in


each experiment

© Process Systems Enterprise Limited

Statistical plots
Residual charts

 Plot residuals for each variable. Three types:

 Absolute deviation, z ijk


 z ijk 
 z 
100%   1  ijk 
 Relative deviation,  z ijk
 

 Weighted deviation,
z ijk
 z ijk 
 2ijk

 Want values close to zero

© Process Systems Enterprise Limited

Page 160 © Process Systems Enterprise Ltd


Statistical plots
Residual charts

© Process Systems Enterprise Limited

Statistical plots
Confidence ellipsoids

 Plot for pairs of parameters


 Want small region around the estimated point
 This indicates that if another identical experiment was carried out and
parameter estimation re-done, the estimates would be almost the same

© Process Systems Enterprise Limited

Page 161 © Process Systems Enterprise Ltd


Statistical plots
Confidence ellipsoids

© Process Systems Enterprise Limited

Summary of What to do

1. Create Estimation and Experiment entities;

2. Run Estimation problem;

3. Look at YYY, YYY.out and YYY.stat-mr in the activity Case file

4. If on Windows, in addition to reports file, use enhanced statistical


analysis in MS ExcelTM
 Look at Summary, Parameter Estimates and Measured Summary sheets for
residuals
 Check t-values in Statistical Significance sheet and Correlation Matrix for
correlated parameters
 View overlay charts, residual charts and confidence ellipsoids

© Process Systems Enterprise Limited

Page 162 © Process Systems Enterprise Ltd


Hands-on session
Re-parameterisation of the model of kinetic reaction scheme

© Process Systems Enterprise Limited

Related gPROMS documentation

 Menu: Help  Documentation


 Parameter Estimation in gPROMS
 Estimating model parameters from experimental data
 Model validation guide: Experiment design in gPROMS

© Process Systems Enterprise Limited

Page 163 © Process Systems Enterprise Ltd


Thank you

© Process Systems Enterprise Limited

Page 164 © Process Systems Enterprise Ltd

You might also like