Example PGM Files - Using Counter, While and Random functions

From SysCAD Documentation
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)

;===================================================================================
; This is a sample PGM file.  
; The aim is to show how to set up the PGM file when counters are being used.
;===================================================================================

;---- 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...
     MsgBox(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 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

PrecipAttrition.png

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

Breakagefunction.png

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!
PageLabel("TestFeedCondition")
 TextLabel()
 Real  Variation*("Frac", "%"){Comment("Set this to 0 to return to base value")}
 TextLabel()
 Real  FeedTempBaseValue*("T", "C")<<50>>, FeedTemp@("T", "C")
 Real  FeedFlowBaseValue*("Qm", "t/h")<<200>>, FeedFlow@("Qm", "t/h")	
 Real  FeedSolidsBaseValue*("Frac", "%")<<85>>, FeedSolids@("Frac", "%")	
 	
 Function RandVariation(Real baseValue)
   Return baseValue*(1.0 + Variation/100. * (random(2) - 1))
 Endfunct
 
 
 Sub InitialiseSolution()
     FeedTemp   = RandVariation(FeedTempBaseValue)    
     FeedFlow   = RandVariation(FeedFlowBaseValue)   
     FeedSolids = RandVariation(FeedSolidsBaseValue)     
     ["Feed.T_Reqd (C)"]   = FeedTemp
     ["Feed.QmReqd (t/h)"] = FeedFlow
     ["Feed.Content.MF.Solids (%)"] = FeedSolids
 EndSub

$

PGMExample4.png