FAQ - PGM Frequently Asked Questions

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: User Guide -> Frequently Asked Questions


How can I find the values for Saturated Steam or Water?

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

The required syntax is:

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

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

Please see Species Database Class Example for a worked example.

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.

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:

1. 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
2. The above code can also be written as follows (it is exactly the same, just really 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)
3. 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.

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 DropList type for dropdown lists.

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

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 == 1)
   ; Logic for when Operating Mode is set to 1 (Basic)
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!

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.