Example Class - Check Elemental Balance of a Process Unit Operation
Jump to navigation
Jump to search
Navigation: PGMs ➔ Example PGM Files ➔ Check Elemental Balance
Related Links: Defining a Class, Defining a Function
Example Class to Check Elemental Balance of a Process Unit Operation
Class Class_UnitElemMB
Textbreak
String UnitName@{Tag}
String Element*{Comment("If unspecified, defalut to 'O' for Oxygen")}
String Stream, FlowTag
Real FlowIn@("Qm", "kg/h"), FlowOut@("Qm", "kg/h")
Real MassDiff@@("Qm", "kg/h"), TotFlow
integer Count, inCount@@, outCount@@, i
Checkbox ElemBal_OK@
Sub Init()
UnitName = ClassTag()
if IsEmpty(Element)
element = "O"
Endif
EndSub
Sub Init2()
if IsEmpty(Element)
element = "O"
Endif
EndSub
StrFunction GetStreamName(integer i, String InOrOut)
return [Concatenate(UnitName,".Links.",InOrOut,".[",IntToStr(i),"].ConnTag")]
EndFunct
Function GetFlow(String InOrOut)
Count = [Concatenate(UnitName,".Links.Summary.",InOrOut,".Count")]
TotFlow = 0.0
i = 1
while (i <= Count)
Stream = GetStreamName(i,InOrOut)
FlowTag = Concatenate(Stream,".Qo.QEl.",Element," (kg/h)")
TotFlow = TotFlow + [FlowTag]
i = i + 1
EndWhile
return TotFlow
EndFunct
Sub CalculateBalance()
FlowIn = GetFlow("In")
inCount = Count
FlowOut = GetFlow("Out")
outCount = Count
MassDiff = FlowOut - FlowIn
ElemBal_OK = iif(Abs(MassDiff) < 0.00001, 1, 0)
EndSub
EndClass
; ---- Using the Class ----
PageLabel "ElemBal"
; Define the required number of Elemental Balance Calculations
Class_UnitElemMB Cementation, AutoclaveLeach_FeedTank, Ni_Co_Filter
Class_UnitElemMB # CCD[4]{ez}
Sub InitialiseSolution()
ForEachClass(Class_UnitElemMB, init())
CCD[1].UnitName = "CCD_1"
CCD[2].UnitName = "CCD_2"
CCD[3].UnitName = "CCD_3"
ForEachClass(CCD, init2())
EndSub
; Perform the Elemental Balance Calculations at the end of project solve
Sub TerminateSolution()
ForEachClass(Class_UnitElemMB, CalculateBalance())
ForEachClass(CCD, CalculateBalance())
EndSub
EndFile
NOTES:
- Example General Controller results for the Nickel Copper Demo Project.
- User may obtain an elemental balance for each unit model by turning on the Audit.On and ElemAudit.On options.
- The example above shows both the class definition and the use of Class in the same PGM file.
- In general, if the Class is useful for multiple PGM file or can be re-used, it is best to store the class definition in a separate file (e.g.: Gerenal_Class.pgm). The class definition can then be inserted into a PGM file using the include file syntax. (e.g.: >>General_Class.pgm)
- Please see Sharing Classes between Projects for more information on how to include the class definition into a pgm file.