Trigger Subroutines
Navigation: PGM SITEMAP
Defining a Class | Defining a Function | Mathematical Functions | Defining a Subroutine | Tag Functions |
---|---|---|---|---|
Predefined Classes | Predefined Functions | String Functions | Trigger Subroutines | Example PGM Files |
Related Topics: Predefined Special Constants, Model Procedures
Contents
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.
The trigger subroutines can be used as an alternative to the predefined constants OnInitialise and OnTerminate which are used in older versions. To use the Trigger subroutines, the Old135Format option in the General Controller must be deselected.
When starting a new PGM file 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 or later 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 |
Making multi-step configuration changes using trigger subroutines
Where multiple steps are required to re-configure a unit operation, the steps may need to be broken up between the different trigger subroutines so that they are executed in series.
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 |