Trigger Subroutines

From SysCAD Documentation
Jump to: navigation, search

Navigation: PGM SITEMAP

PGM Main Page Defining a Class Defining a Function Tag Functions Mathematical Functions Defining a Subroutine
Example PGM Files Predefined Classes Predefined Functions Tag Functions (9.3) String Functions Trigger Subroutines

Related Topics: Predefined Special Constants, Model Procedures

NOTE this page is only valid for SysCAD 9.3 or later versions.

Introduction

Trigger subroutines contain commands which are executed by SysCAD at different stages of the evaluation of the model. All subroutines are optional.

These are similar to the trigger functions used in Model Procedures.

In SysCAD 9.3 the trigger subroutines can be used as an alternative to the predefined constants OnInitialise and OnTerminate which are used in SysCAD 9.2 and earlier versions. To use the Trigger subroutines, the Old135Format option in the General Controller must be deselected.

When starting a new PGM file in SysCAD 9.3, the trigger subroutines are contained in the standard PGM template.

Initialise PreStart

The InitialisePreStart subroutine is for logic which is to be executed very early before the first iteration. Deactivation of flowsheets can only be performed within this subroutine. Other items which might be performed within this subroutine are turning controllers or units on or off. See examples below.

Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration
 
EndSub

PreStart

The PreStart subroutine is for logic which is to be executed early before the first iteration. This is similar to the setting of tags in the Plant Model SetTagList. Items which may be performed within this subroutine include turning controllers or units on or off and the setting of options or methods.

Sub PreStart()
 ;--- Logic executed early before first iteration
 
EndSub

Initialise Solution

The InitialiseSolution subroutine is for logic which is to be executed during initialisation of the model, before the first iteration. This is similar to the use of the OnInitialise special constant in SysCAD 9.2 or earlier versions. It is also similar to the MP_InitialiseSolution function used in Model Procedures. Items which may be performed within this subroutine include setting of initial values or constant values in units.

Sub InitialiseSolution()
 ;--- Logic executed during initialisation before first iteration
 
EndSub

Terminate Solution

The TerminateSolution subroutine is for logic which is to be executed after the last iteration, when the solver is stopped. This is similar to the use of the OnTerminate special constant in SysCAD 9.2 or earlier versions. It is also similar to the MP_TerminateSolution function used in Model Procedures.

Sub TerminateSolution()
 ;--- Logic executed after last iteration (when solver is stopped)
 
EndSub

Initialise PreStart Examples

Reset Actions

Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration

 ; Perform complete reset of project
 ["$Solver.Cmd.CompleteReset"] = 1  

EndSub

Activate/deactivate flowsheets

SysCAD 9.3 Build 137 Format
Separate variables for Activate or Deactivate
Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration

 ; Activate flowsheet 05_Flowsheet
 ["PlantModel.Page[05_Flowsheet].Activate"] = 1  

 ; Deactivate flowsheet 10_Flowsheet
 ["PlantModel.Page[10_Flowsheet].DeActivate"] = 1

EndSub
SysCAD 9.3 Build 136 Format
Same variable for Activate or Deactivate
Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration

 ; Activate flowsheet 05_Flowsheet
 ["PlantModel.Page[05_Flowsheet].Active"] = 1  

 ; Deactivate flowsheet 10_Flowsheet
 ["PlantModel.Page[10_Flowsheet].Active"] = 0

EndSub

Cross-page connections

Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration

 ; Turn on cross-page connection in Feeder XPG_001
 ["XPG_001.ConnectionOn"] = 1

 ; Turn off cross-page connection in Feeder XPG_002
 ["XPG_002.ConnectionOn"] = 0

 ; Set cross-page connection in Feeder XPG_001 to XPG_002
 [str "XPG_001.Conn_To"] = "XPG_002"

EndSub

Multiple Subroutine Example

Where multiple steps are required, this may need to be broken up between the different trigger subroutines.

In this example, a Filter Press model is required to be turned on, the method changed and a parameter set. Since the parameter may not be available until the method selection is made, these will be performed in different subroutines.

Sub InitialisePreStart()
 ;--- Logic executed very early before first iteration

 ; Turn on filter press FP_001
 ["FP_001.On"] = 1

EndSub
 
Sub PreStart()
 ;--- Logic executed early before first iteration

 ; Set method in filter press FP_001 to FiltrateConcAt25C
 ["FP_001.Method"] = 1

EndSub

Sub InitialiseSolution()
 ;--- Logic executed during initialisation before first iteration

 ; Set required filtrate solid concentration in filter press FP_001
 ["FP_001.FiltrateSolidConc25Reqd (g/L)"] = 2

EndSub