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 = SI("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?

These are SysCAD 9.2 Syntax. For SysCAD 9.3 Syntax, please see 9.3 Tag Functions

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 code uses a variable that has been read in from the SysCAD model, using a GetTag() (or Get()) command, and the measured variable is unexpectedly zero; or
  • The code uses a User defined variable and the user types in zero; or
  • The denominator 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 = GetTag("P_001.Qo.SQm (t/h)")
SlurryMassFlow = GetTag("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.

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

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)

PGM code can be used to adjust or query these values in the same way as numerical variables are set.

Dropdowns.png

The values for the items in a dropdown list can be seen to the right of the string description. It is convenient to use the Bit type for Checkboxes and the Byte/Long type for dropdown lists.

Bit        isOn{i, Comment("0 - Off, 1 - On")}              ; A boolean (0 or 1)
Long       VLEType{i, <0, 9>}                               ; Valid range is 0 - 9
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()
   SetTag("XPG_001.VLEquilibrium", VLEType)
   SetTag("XPG_001.Demand.On", isOn)  
   AcidDosing = Online
   OperatingMode = 1  
endSub

Dropdowns2.png


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.

In SysCAD 9.3, we can simply do this:

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

In older versions of SysCAD, we used this method:

REAL  ReactionFeedTempReqd*("T", "C")
ReactionFeedTempReqd = Range(40, ReactionFeedTempReqd, 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.

In SysCAD 9.3, we can simply do this:

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

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

In older versions of SysCAD, we used this method:

REAL  ReactionFeedTempReqd*("T", "C")

if  ReactionFeedTempReqd < 0.000001
   ReactionFeedTempReqd = 80
Endif 

See Declaring variables with an Initial Value for more information.