MP Example Files

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs ➔ Model Procedures ➔ MP Example Files

Model Procedures MP Example Files

Related Links: Example PGM Files, Example Model Procedure Files, Evaluation Blocks

Example projects using MP file: Demo Nickel Copper Project, Model Procedure Example


Model Procedure Example: Tank Volume

EXAMPLE MP FILE SysCAD ACCESS WINDOW
;EXAMPLE MODEL PROCEDURE FUNCTION
PageLabel "TankVolume" 
  TextBreak
  real ResidenceTimeReqd*("Time", "h")<<1>>, ActualResidenceTime@("Time", "h")
  real Feed_Flowrate@("Qv", "m^3/h"){Comment("Slurry Only")}
  real Prod_Flowrate@("Qv", "m^3/h"){Comment("Slurry Only")}
  Checkbox UseDesignVol*
  Real DesignFactor*<<1.2>>
  real VolumeReqd@("Vol", "m^3"), Design_Volume@("Vol", "m^3")
  Long RoundupDecimalPlaces*<<0>>{Comment("0 : to whole number")}<-2, 0>
; ------------------------------------------------------------
Sub Calc()
	Feed_Flowrate = ["QFeed.SLQv (m^3/h)"]
	Prod_Flowrate = ["QProd.SLQv (m^3/h)"]
	VolumeReqd = Max(Feed_Flowrate, Prod_Flowrate) * ResidenceTimeReqd
	Design_Volume = Roundup(VolumeReqd*DesignFactor, RoundupDecimalPlaces)
	["ResTime.Volume (m^3)"] = iif(UseDesignVol, Design_Volume, VolumeReqd)
	ActualResidenceTime = ["ResTime.Slurry (h)"]
EndSub

Sub MP_InitialiseSolution()
	Calc()	
EndSub

Sub MP_TerminateSolution()
	Calc()
EndSub

; ------------------------------------------------------------
$ ; --- end of file ---

MP EXAMPLE TankVol.png

Model Procedure Example: Set Demand Flow as Volume Flow

EXAMPLE MP FILE SysCAD ACCESS WINDOW
;EXAMPLE MODEL PROCEDURE SUBROUTINE
PageLabel "VolFlow" 
  TextLabel ""
  real VolFlowReqd*("Qv", "m^3/h")
  real MassFlowReqd@("Qm", "t/h")
  real Density@("Rho", "t/m^3")
; ------------------------------------------------------------
Sub MP_Eval_Before()
  ;--Convert volume flow to mass flow
  Density = Max(0.9, ["Qo.Rho (t/m^3)"])
  MassFlowReqd = VolFlowReqd * Density
  ["Qm_Demand.Reqd (t/h)"] = MassFlowReqd
EndSub
; ------------------------------------------------------------
$ ; --- end of file ---

MP EXAMPLE VolDemandFlow.png

Model Procedure Example: Agitator Power

EXAMPLE MP FILE SysCAD ACCESS WINDOW
PageLabel "AgitatorPower" 
TextLabel ,, " --- Power = Po * N^3 * D^5 * Density -- ", ""
memo AgDesc*
TextLabel ""
real   Po{i, comment("dimensionless power number")} <<1>>
real   N{i, comment("Rotation per second")}<<0.3>>
real   D{i, ("L", "m"), comment("ImpellerDiameter")}<<1>>
real   Density@("Rho", "kg/m^3")
real   Power@("Pwr", "kW")

Sub MP_TerminateSolution()
  Density = ["QProd.SLRho (kg/m^3)"]
  Power = Po * N^3 * D^5 * Density
EndSub
; ------------------------------------------------------------
$ ; --- end of file ---

MP EXAMPLE AgitatorPower.png

Model Procedure Example: Crusher Power

EXAMPLE MP FILE SysCAD ACCESS WINDOW
; --- variable declarations ---
PageLabel "BondIndex and Power"
TextBreak 
TextLabel "  Power = 10.0 * Solid Mass Flowrate * BondWI * (1.0/Sqrt(P80) - 1.0/Sqrt(F80))"
TextBreak 
Real 	BondWI*("WI", "kWs/kg")<<14>>
Real 	SolidsMassFlow@("Qm", "kg/s")
Real	Feed_P80*("PartSize", "um")<<20000>>, Prod_P80*("PartSize", "um")<<1000>>
Real 	Power@("Pwr", "kW")

; --- procedure declarations ---
Sub MP_TerminateSolution()
	SolidsMassFlow = ["QFeed.SQm (kg/s)"]
	Power = 10.0 * SolidsMassFlow * BondWI * (1.0/Sqrt(Prod_P80) - 1.0/Sqrt(Feed_P80))
EndSub

$ ; --- end of file ---

MP EXAMPLE CrusherPower.png

Model Procedure Example: Pipe Sizing

The following example shows the use of Global User Defined Variables, located on the Plant Model access window, Project Tab. To make use of these variables, user can use the Predefined Plant Model Class to read in the values.

EXAMPLE MP FILE SysCAD ACCESS WINDOW
;EXAMPLE MODEL PROCEDURE SUBROUTINE

;--- Define Subroutine ---
PageLabel "Pipe Sizing" 
Textbreak
REAL	Vol_Flow@("Qv", "m^3/s")
Textbreak
TextLabel "----User Defined Global Values - PlantModel - Project Tab" 
REAL	VapourDesign_Vel*("Ldt", "m/s")
REAL	LiquidDesign_Vel*("Ldt", "m/s")
REAL	SlurryDesign_Vel*("Ldt", "m/s")
Textbreak
TextLabel "----For intermittent flows, Vol_Flow is",
          "    the normalised flow over 24 hours.",  
          "    to calculate the instantaneous flowrate,", 
          "    state the operating hours per day----"
Textbreak
REAL	OperatingHoursPerDay*("Time", "h")
REAL	Intermittent_Factor@
REAL	DesignFlow@("Qv", "m^3/s")
Textbreak
STRING	Pipe_Type@
Textbreak
REAL	Design_Vel@("Ldt", "m/s")
REAL	Diameter@("L", "mm")
REAL	Design_Diameter@("L", "mm")

;Local Variables
Real	Pipe_Vf, Pipe_Lf

Sub MP_TerminateSolution()
   ;Getting design velocities from the Plant Model Class - User Defined Global Values. 
	VapourDesign_Vel = PM.PUV(4)
	LiquidDesign_Vel = PM.PUV(5)
	SlurryDesign_Vel = PM.PUV(6)

	Pipe_Vf = Get("Qo.Vf (%)")
	Pipe_Lf = Get("Qo.Lf (%)")
		
	If Pipe_Vf > 50
		Design_Vel = VapourDesign_Vel
		Pipe_Type = "Vapour Line"
	Elseif	Pipe_Lf > 90
		Design_Vel = LiquidDesign_Vel
		Pipe_Type = "Liquid Line"
	Else
		Design_Vel = SlurryDesign_Vel
		Pipe_Type = "Slurry Line"
	Endif	

	intermittent_Factor = 24/OperatingHoursPerDay  		
	Vol_Flow = Get("Qv (m^3/s)")
	DesignFlow = Vol_Flow * intermittent_Factor
	Diameter = sqrt(4 / PI * DesignFlow / Design_Vel) * 1000
	Design_Diameter = Roundup(Diameter, -1)
EndSub		

$ ; --- end of file ---

MP EXAMPLE 2.png

Model Procedure Example: Thickener

;EXAMPLE MODEL PROCEDURE SUBROUTINE
PageLabel "UserDefinedThickener" 
TextLabel , "Requirements"
REAL RqdUFSolids*("Frac", "Frac")<0.001, 0.99>
REAL RqdOFSolids*("Frac", "Frac")<0, 0.5>
REAL SolidsFeed, LiquidsFeed
REAL SolidstoUF, LiquidstoUF, SolidstoOF, LiquidstoOF
REAL FracSolidstoUF, FracLiquidstoUF
TextLabel , "Results"
REAL UFSolids@("Frac", "Frac")
REAL OFSolids@("Frac", "Frac")
REAL UFSolRec@("Frac", "Frac")
 
; --- procedure declarations ---
Sub MP_Eval_AfterEB()
; calculate the massfrac split of solids and liquids to underflow
   SolidsFeed = Get("QFeed.SQm (kg/s)")
   LiquidsFeed = Get("QFeed.LQm (kg/s)")
   SolidstoUF = 0.0
   if (SolidsFeed > 0.001)
     SolidstoUF = Range(0.0, (SolidsFeed*(1.0-RqdOFSolids) - RqdOFSolids*LiquidsFeed)/(1.0-RqdOFSolids - RqdOFSolids/RqdUFSolids*(1.0-RqdUFSolids)), SolidsFeed)
   endif
   LiquidstoUF = Range(0.0, SolidstoUF * (1.0-RqdUFSolids)/RqdUFSolids, LiquidsFeed)
   FracSolidstoUF = iif(SolidstoUF > 0.001, SolidstoUF/SolidsFeed, 0.0)
   FracLiquidstoUF = iif(LiquidstoUF > 0.001, LiquidstoUF/LiquidsFeed, 0.0)
 	
; Split to UF:
   Set("GM.IOs.[P_003].Splt.Solids (%)", FracSolidstoUF * 100)
   Set("GM.IOs.[P_003].Splt.Liquids (%)", FracLiquidstoUF * 100)
; send all gases to overflow
   Set("GM.IOs.[P_003].Splt.Gasses (%)", 0)
EndSub	
; ------------------------------------------------------------

Sub MP_Eval_After()
; calculate some results
   SolidstoOF = SolidsFeed - SolidstoUF
   LiquidstoOF = LiquidsFeed - LiquidstoUF
   UFSolids = iif((SolidstoUF + LiquidstoUF) > 0.001, SolidstoUF / (SolidstoUF + LiquidstoUF), 0)
   OFSolids = iif((SolidstoOF + LiquidstoOF) > 0.001, SolidstoOF / (SolidstoOF + LiquidstoOF), 0)
   UFSolRec = FracSolidstoUF
EndSub		
 
$ ; --- end of file ---