FAQ - PGM Frequently Asked Questions

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: User Guide ➔ Frequently Asked Questions ➔ PGM Questions

Frequently Asked Questions (FAQ) and Troubleshooting
General Questions Installation
Related
License
Related
Project
Related
Species
Related
Modelling
Related
TCE
Related
Graphics
Related
Access/Trend
Related
Reactions
Related
Mass & Energy
Balance
Flashing /
Flash Train
PGM
Related
Dynamic
Related

Latest SysCAD Version: 19 March 2024 - SysCAD 9.3 Build 139.35102

Related Links: Getting Started, PGMs


What are PGM files?

PGM files are programmable files that allow the user to extend the functionality of the SysCAD models. It is used extensively in SysCAD Dynamic modelling. In Steady-State (ProBal) mode, the user can use the PGM files to put in simple ratio controls or calculate user-defined variables and so on. See PGM Introduction.

For Example use of PGM files, please see Example PGM Files.

How can I fetch the values for Saturated Steam in a PGM?

The Species Database Class, SDB, will allow a user to obtain the saturated values for steam at a user defined temperature or pressure.

The required syntax is:

  • steam saturated vapour pressure - SDB.SpVapourP(SteamIndex, Temperature). Temperature is in Kelvin.
  • steam saturated temperature - SDB.SpVapourT(SteamIndex, Pressure). Pressure is in kPa (absolute).

Note: SteamIndex is defined by the user and is the species index of steam. Example: SteamIndex = SpI("H2O(g)")

Please see Species Database Class for more examples.

What is the difference between GetTag(), SetTag() and GetDynTag() and SetDynTag() and when do you use them?

NOTE: These are old PGM Syntax. The current syntax no longer requires different tag functions to be used in the situations described below. Please see Tag Functions for the latest syntax.

The difference between GetTag() and GetDynTag(); SetTag and SetDynTag is subtle. It is NOT related to dynamic mode.

  • The GetDynTag() and SetDynTag() functions "dynamically" build the Tag, when required. This can also be a string based on logic using strcat that you want to set/get.
  • At start-up, when you press solve, SysCAD has a list of all tags used in SetTag() and GetTag() which it checks to see if they can ALWAYS be legally set/read.
  • For SetDynTag() and GetDynTag() the checking of the tag is done at runtime when the command is called.

I am getting a runtime error for unknown tag in Model Procedure (MP), how do I fix it?

When using [string] for the value of the variable, user may get "Unknown tag "GM.IOs.[P_002].Splt.H2O(l) (%)'", this is because the [] function expects a full tag instead of partial tag.

Please see troubleshooting MP for the correct syntax.

How do I enter an equation of the form y = -x?

The pgm syntax does not allow users to enter the negative form of a function. To convert to negative, multiply by -1, as shown in the examples below:

Required Equation Equation in pgm
y = -x y = -1 * x
y = exp(-x) y = exp(-1 * x)

How do I avoid a 'Divide by Zero' error?

At times a user may get a 'Divide by Zero' error in their general controller or model procedure. This can be caused in a number of ways, when the denominator in a division:

  • uses a variable that has been read in from the SysCAD model, using a GetTag function, and the measured variable is unexpectedly zero; or
  • uses a User defined input variable and the user types in zero; or
  • is the result of a previous calculation which produces a zero value.

It is good practice to ALWAYS ensure that the denominator is not zero when doing a division. The following example shows methods of avoiding a zero denominator when using a measured SysCAD variable as the denominator, but these methods can be used for all of the above cases.

Example: The following two variables are measured in a PGM:

SolidMassFlow = ["P_001.Qo.SQm (t/h)"]
SlurryMassFlow = ["P_001.Qo.SLQm (t/h)"]
The user wishes to find the fraction of solids in the slurry, and therefore wants to divide the solids mass by the mass of slurry. However, if for some unexpected reason there is zero flow in stream P_001, this will produce a 'Divide by Zero' error. You can avoid this in PGM code in a number of ways:
  • Check that the denominator is greater than some small number before carrying out the calculation (You may check that it is greater than zero, but rather choose a reasonable small number, because otherwise you may end up dividing by a number such as 1e-7 and still get silly results)):
if (SlurryMassFlow > 0.001)
   SolidInSlurryMF = SolidMassFlow / SlurryMassFlow
else
   SolidInSlurryMF = 0
endif
  • The above code can also be written as follows (it is exactly the same, just a shorter way of putting it in the code. See IIf Command for a description of the use of the 'iif' command):
SolidInSlurryMF = iif (SlurryMassFlow > 0.001, SolidMassFlow / SlurryMassFlow, 0)
  • Use the 'Max' command to ensure that you never divide by a very small number:
SolidInSlurryMF = SolidMassFlow / MAX(SlurryMassFlow, 0.001)
This command will compare the value of 'SlurryMassFlow' and 0.001 and use whichever is the greater value of the two. Therefore, if 'SlurryMassFlow' is zero, or less than 0.001, it will use 0.001 and you will not have an error in your code.

Notes:

  1. The user could make use of the 'min' or 'range' functions to avoid silly results, but this would not prevent the divide by zero error message. Refer to Maths Functions for more details on these functions.
  2. For the case of the User defined input variable being the problem, the user can set a range on an input variable when first declaring it to prevent the user from entering a zero. Refer to Declaring Variables for more details.

How do I set values in CheckBoxes and DropDown lists?

SysCAD access windows have other items apart from numerical values, such as dropdown lists (where you select from a number of items) and checkboxes (which can be on or off). Some examples are listed below:

Checkbox.png

Checkbox2.png

Dropdowns4.png

Dropdowns.png

PGM code can be used to adjust or query these values in the same way as numerical variables are set. Note: Some choices can only be made during the initialisation stage of the project run. These selections need to be made within a Trigger Subroutine such as InitialiseSolution.

The values for the items in a dropdown list can be seen to the right of the string description. If the value to be set needs to be a variable, then it is convenient to use the Bit type for Checkboxes and the Integer type for dropdown lists.

Bit       Sol_On{i,Comment("0 - Off,1 - On")}          ; A boolean (0 or 1) input
Integer   VLE_Type{i,<0,12>}                           ; Integer input with valid range 0 - 12

Sub InitialiseSolution()
   ["XPG_001.Demand.On"] = 1                ; Set the Demand function in Feeder XPG_001 to 1 (On)
   ["X_001.OperatingP.Method"] = 2          ; Set the OperatingP Method in Tie X_001 to 2 (Atmospheric)
   ["X_001.EB.Solubility.On"] = Sol_On      ; Set the Solubility functionality in Tie X_001 equal to the Sol_On variable
   ["XPG_001.VLEquilibrium"] = VLE_Type     ; Set the VLE option in Feeder XPG_001 equal to the VLE_Type variable
EndSub

Dropdowns5.png

Adding a comment to the variable declaration can make the user choices a bit more obvious!

The user can also create their own checkboxes and dropdown lists. See next FAQ question for more information.

How do I create CheckBoxes and DropDown lists?

SysCAD access windows have other items apart from numerical values, such as dropdown lists (where you select from a number of items) and checkboxes (which can be on or off). Some examples are listed below:

Checkbox.png

Dropdowns.png

The user can use PGM code to create their own checkboxes and dropdown lists. These variables can then be used to set other values and/or used in If statements.

Use the Checkbox type for Checkboxes and the EnumDropList type for dropdown lists.

Checkbox       Online*                          ; True or False                    
EnumDropList   Options{Acid,Basic,Neutral}      ; Define the EnumDropList options
Options        OperatingMode*                   ; Set the variable to use the EnumDropList

Sub InitialiseSolution()
   ["XPG_001.Demand.On"]  = Online              ; Set the Demand function in Feeder XPG_001 equal to the Online variable
   ["pH_Controller.Mode"] = OperatingMode       ; Set the user defined variable "Mode" in General Controller "pH_Controller" equal to the chosen Operating Mode
EndSub

If Online
   ; Logic for when Online is enabled
EndIf

If (OperatingMode == Basic)
   ; Logic for when Operating Mode is set to Basic (1)
EndIf

Dropdowns3.png

The values for the items in a dropdown list can be seen to the right of the string description.

Adding a comment to the variable declaration can make the user choices a bit more obvious!

See Data Types for more information and examples.

How do I assign a value range to a defined variables?

When you define a new writeable variable in the PGM file, the starting default value is 0 (no value assigned). If this value is used in a calculation without being assigned a value, it is possible to run into the division by zero problem or cause upset to the model. You can limit the value to a valid range to avoid this problem.

REAL  ReactionFeedTempReqd*("T", "C")<40,120>

See Declaring variables with ranges for more information.

How do I assign a starting value to newly defined variables?

When you define a new writeable variable in the PGM file, the starting default value is 0 (no value assigned). If this value is used in a calculation without being assigned a value, it is possible to run into the division by zero problem or cause upset to the model.

REAL  ReactionFeedTempReqd*("T", "C")<<80>>

;The following line will also add a valid range.
REAL  ReactionFeedTempReqd*("T", "C")<<80>><40,120>

See Declaring variables with an Initial Value for more information.

Why are Notepad++ Syntax Colours Not Visible?

Please see Using Notepad++.