Bayer Liquor Class

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs ➔ Example PGM Files ➔ Bayer Liquor Class

Example User Defined Classes
Set Species Splits Agitator
Power
Reaction
Finder
Aq Feed Conc
Calculator
Evaporation
Correlation
Bayer Liquor
Class
Check
Element Bal
Optimise Controllers
for sensitive PIDs
Relaxed Cross Page Connector

Related Links: Defining a Class, Defining a Function, Alumina 3 Bayer Species Model, Bauxite Composition Example

NOTE: This example 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.


;Class definition is saved in file called: BayerPropCalc.pgm
;=========================================================================================
Class BayerLiquor_Class
;	-----DEFINE Bayer Liquor VARIABLES--------------------------------------------
	TextLabel "  -------------------"  
	STRING UnitName{Tag}, Liquor, Water, x
	CheckBox TagExist@
	STRING NaAlOH4, Na2C2O4, Na2C5O7, Na2CO3, Na2SO4, NaCl, NaOH, Na2SiO3, Temp
	REAL   TNa, TAl2O3, TNaOH, Density_25("Rho","kg/m^3")@
	REAL   Density_T("Rho","kg/m^3")@, T("T","dC")
	REAL   A("Conc","g/L")@, C("Conc","g/L")@, S("Conc","g/L")@, A_C@, C_S@ 
	Long   i* 
;	----SUBROUTINE TO INITIALISE Tags----------------------------------------------
	Sub InitTag(Bit UseClassTag)
		If UseClassTag
			UnitName = ClassTag()
		Else 
			x = Mid(ClassTag(), 5,1)
			i = StrToInt(x) + i_Init
			UnitName = Concatenate("P_", IntStr0(i,3))
		Endif	
		TagExist = iif(DynTagExists(UnitName), 1, 0)
		if TagExist
			Liquor   = Concatenate(UnitName, ".Qo.Liquids (kg/s)")
			Water    = Concatenate(UnitName, ".Qo.QM.H2O(l) (kg/s)")
			NaAlOH4  = Concatenate(UnitName, ".Qo.QM.NaAl[OH]4(aq) (kg/s)")
			Na2C2O4  = Concatenate(UnitName, ".Qo.QM.Na2C2O4(aq) (kg/s)")
			Na2C5O7  = Concatenate(UnitName, ".Qo.QM.Na2C5O7(aq) (kg/s)")
			Na2CO3   = Concatenate(UnitName, ".Qo.QM.Na2CO3(aq) (kg/s)")
			Na2SO4   = Concatenate(UnitName, ".Qo.QM.Na2SO4(aq) (kg/s)")
			NaCl     = Concatenate(UnitName, ".Qo.QM.NaCl(aq) (kg/s)")
			NaOH     = Concatenate(UnitName, ".Qo.QM.NaOH(aq) (kg/s)")
			Na2SiO3  = Concatenate(UnitName, ".Qo.QM.Na2SiO3(aq) (kg/s)")
			Temp     = Concatenate(UnitName, ".T (dC)")
		Endif	
	EndSub
;   ----SUBROUTINE - DENSITY @ 25 dC------------------------------------------------
	Sub Density25()
	TAl2O3     = [NaAlOH4]*(MW("Al2O3(s)")/(2*MW("NaAl[OH]4(aq)")))*100/[Liquor]  
	TNaOH      = ([NaOH]*MW("Na2CO3(aq)")*0.5/MW("NaOH(aq)"))  
				+ ([NaAlOH4]*0.5*MW("Na2CO3(aq)")/MW("NaAl[OH]4(aq)"))
	TNa        = ([Na2CO3] + TNaOH + ([Na2C2O4]/MW("Na2C2O4(aq)") + [Na2C5O7]/MW("Na2C5O7(aq)")
				+ [NaCl]*0.5/MW("NaCl(aq)") + [Na2SO4]/MW("Na2SO4(aq)") + [Na2SiO3]/MW("Na2SiO3(aq)") )
				* MW("Na2CO3(aq)") ) * (100 / [Liquor])
	
	Density_25 = (0.982 + (0.01349855 * TNa) + (-0.00024948 * TNa * TNa) + 
				(0.00000273* TNa * TNa * TNa) + (0.00208035* TAl2O3)+ 
				(0.00004113* TAl2O3 * TAl2O3) + (-0.00000728* TAl2O3 * TAl2O3 * TAl2O3)+
				(0.00033367* TNa * TAl2O3))*1000
	EndSub
;	----SUBROUTINE - DENSITY @ Temp ------------------------------------------------
	Sub DensityT()
		T  = [Temp]
		Density_T  = Density_25 * (1 - (0.0005021858*0.85*(T-25))-(0.0000011881*0.85*(T-25)*(T-25)))
	EndSub
;	----SUBROUTINE - Concentration ------------------------------------------------
	Sub Conc()
		A    = [NaAlOH4]*(MW("Al2O3(s)")/(2*MW("NaAl[OH]4(aq)"))) / [Liquor] * Density_25
		C    = TNaOH / [Liquor]* Density_25
		S    = [Na2CO3] / [Liquor] * Density_25 + C
		A_C  = A/C
		C_S  = C/S
	EndSub
;	----SUBROUTINE - EXECUTE SUBROUTINES ---------------------------------------------
	Sub Exec()
		If TagExist and [Liquor]>0	
			Density25()
			DensityT()
			Conc()
		Endif	
	EndSub
EndClass

;=========================================================================================

PageLabel "Examples" 
    Textbreak
    Long i_Init*<<10>>  ;starting pipe value for array classes.
;   reading in the Class: 
	>>BayerPropCalc.pgm

; Using Class instances 
	;Example of Defining Classes individually
	 BayerLiquor_Class # P_001, P_007, P_003, P_004
	;Example of Defining Classes with an Array 
	 BayerLiquor_Class # Pipe[5]{ez}

Sub InitialiseSolution()
;------Initialise Tag Name(s)---------
   ForEachSub(BayerLiquor_Class, InitTag(True))
;  Example of calling functions from classes defined with an array.
   ForEachSub(Pipe, InitTag(False))
EndSub

;-------Executing Functions--------
   ForEachSub(BayerLiquor_Class, Exec())
;Example of calling functions from classes defined with an array.
   ForEachSub(Pipe, Exec())

ENDFILE

BayerClass1.png

NOTE:

  1. In the example above, we have used "i_init"=10 and "i = StrToInt(x) + i_init" because the pipes we wanted to calculate are from P_011 onwards. This will work for sequential tags.
  2. i_init needs to be declared in the main file before reading in the class file.