Example PGM Files - Using Counter, While and Random functions
Jump to navigation
Jump to search
Navigation: PGMs ➔ Example PGM Files ➔ Counter, While, Random
Simple Examples | Subroutines Examples | Dynamic Examples | Steady State Overall Mass Balance | Array and Matrix Examples | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic Layout | Simple Calculations | Initialise PreStart | Multi-Step Trigger | Checking Project | Counter, While and Random | Belt Filter Wash Loss | Startup Actions | Mass Balance | Mass Balance | Species Balance | Elemental Balance | Lookup Value | Set Values | Tridiagonal System |
Related Links: Trigger Subroutines, Predefined Functions
Sample PGM File (File layout when using counters)
Example 1 ;--- SysCAD General Controller (PGM) program logic file ---
; Basic file structure for utilising counters.
;---- Define Variables ------------------------
long Counter@
Checkbox ControlOn*
bit Error1@
String AssessmentMessage1@
;--- Logic ------------------------------------
Sub InitialiseSolution()
["PID_2.Cfg.[1].On"] = ControlOn
EndSub
Sub TerminateSolution()
Error1 = ;place any solution checking logic here
if (Error1)
AssessmentMessage1 = "Run not successful, do this..." ;message as required...
LogWarning(AssessmentMessage1)
endif
EndSub
;NOTE counter must be placed in this section to count the iterations as the project solves.
Counter = Counter + 1
$ ;END OF FILE
|
Example 2 ;--- SysCAD General Controller (PGM) program logic file ---
; How to use a counter to assign different values to a variable.
;--- variable declarations ---
CheckBox UseInitFeed* ;trigger for using initial feed
integer IterationCount@ ;counter
Integer FeedOffCount*<<1>> ;sets flow to 0 when it reaches this value
Sub InitialiseSolution()
;--- Logic executed during initialisation before first iteration
;For example to set initial values, or set values in units
If UseInitFeed
["XPG_001.QmReqd (t/h)"] = 20
IterationCount = 0
Endif
EndSub
;--- Logic - executed at EVERY step ---
If UseInitFeed AND (IterationCount < FeedOffCount)
IterationCount = IterationCount + 1
If (IterationCount >= FeedOffCount)
["XPG_001.QmReqd (t/h)"] = 0
Endif
Endif
$
|
Example PGM File - Using While loop to set user defined value to multiple equipment
Long i, NumberofTanks*<<14>>
Real AggRateCorrection*<<0.35>>
Sub InitialiseSolution()
i = 1
While i <= NumberofTanks
[Concatenate("PC_", IntStr0(i, 3), ".Agglom.Rate.Correction")] = AggRateCorrection
i = i + 1
EndWhile
EndSub
;Inside the while loop, tags PC_001 to PC_014.Agglom.Rate.Correction will be set to the user defined value.
;The function IntStr0 will convert integers "1 to 14" to 3-character length strings, padding with 0 (zeros).
Example PGM File - Using While loop to set Selection/Breakage Function Table values
Example 1
This example sets fines into the crusher to represent Attrition Control for Alumina Precipitation circuit:
Real Breakage*
Long k, n
Sub InitialiseSolution()
n = 27
While n > 1
k = n
While (k > 1)
[Concatenate("CR_001.Al[OH]3(s).BRK[", IntToStr(k), "][", IntToStr(n), "] (%)")] = 0
[Concatenate("CR_001.Al[OH]3(s).BRK[1][", IntToStr(n), "] (%)")] = Breakage
[Concatenate("CR_001.Al[OH]3(s).BRK[0][", IntToStr(n), "] (%)")] = 100 - Breakage
k = k - 1
EndWhile
n = n - 1
EndWhile
EndSub
Example 2
This example initialises Crusher2 Breakage function table values to 0:
String OreTag1*
Long k, n
Sub InitialiseSolution()
OreTag1 = "CR001.Ore1(s)"
n = 24
While n > 1
k = n
While (k > 1)
[Concatenate(OreTag1, ".BRK[", IntToStr(k), "][", IntToStr(n), "] (%)")] = 0
[Concatenate(OreTag1, ".BRK[1][", IntToStr(n), "] (%)")] = 0
[Concatenate(OreTag1, ".BRK[0][", IntToStr(n), "] (%)")] = 0
k = k - 1
EndWhile
n = n - 1
endwhile
EndSub
Example: Using random for testing plant models
The following is an example of a PGM file that can be used to "drive" a plant model around nameplate or design condition by introducing small variations in each of the key parameters.
- Each time the model is run, the base values are subject to a small random variation, controlled by the variable Variation.
- When you are done testing, just set Variation to zero and nameplate conditions will be reset!