Class - Introduction

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs ➔ Classes

Functions Subroutines Classes
Defining a Function Predefined Functions Tag Functions Mathematical Functions String Functions Defining a Subroutine Trigger Subroutines Defining a Class

Related Links: User Defined Class and Functions, Example PGM Files

Class - Introduction Class - Defining a Class Class - Using a Class Class - Macros Class - Examples

Global Predefined Class Instances: Species Database Class, Particle Size Definition Class, Plant Model Class
Predefined Classes: Array Class, StrArray Class, Matrix Class, TagSelect Class, Noise Class, TimeClass


Understanding when to use Class

Adding class control into PGM code can help a user simplify the handling of multiple related variables or objects. Class control can be used in most scenarios where the PGM code carries out a similar/identical control or calculations multiple times in the same iteration. This has applications both in ProBal and Dynamic modelling. Classes are used to define multiple instances of the same object. The two main scenarios when a class should be used in process simulation is either when the object is a repeating variable or repeating procedure that needs calculation.

Examples of when to use Class

There are two main instances when a class should be used:

  1. Repeating Variable Calculations
    • Multiple units require the same residence time calculations
    • Multiple units require an agitator power calculation
    • Setting multiple species splits
  2. Repeating Procedure Calculations
    • Batch unit operations for a set of units (eg. multiple ion exchange columns, filtration units, reaction tanks, vacuum pans, etc.)
    • Repeating the same control calculation on a set of units?

Understanding “Class” and Its Usage

  1. Define a Class: Start by defining a class, which is a way to group variables and functions or subroutines together. This definition acts as a “class template”.
  2. Create Instances: Use this class definition to create any number of “instances” or “objects”.
  3. Example Scenario: Imagine you need to calculate the tank slurry volume based on a defined residence time. Without a class, you would have to write and repeat the same code each time you perform this calculation. This repetition could become extensive, especially with a large number of tanks in your project. Moreover, any change in logic would require updates in all instances of the repeated code, making it hard to maintain.
  4. Use a Class for Efficiency: To avoid this, write your code in the form of a class. Define all necessary variables and functions in a template, for instance, “Class_Tank”.
  5. Implement the Class: Instruct SysCAD to use this template to create as many “instances” or “objects” of type Class_Tank as needed. You can then perform the volume calculations multiple times without repeating the code.
  6. Example Class: A simple example is provide below, showing how this can be implemented in SysCAD.
  7. For further understanding, please refer to one of the following topics:

Simple Example

EXAMPLE PGM FILE USING CLASS SysCAD ACCESS WINDOW
;--- Define the Class ---
Class Class_Tank
	TextLabel ,"Inputs"
	String UnitTag{Tag}@
	String FeedTag, ProdTag, VolTag
	real ResidenceTimeReqd*("Time", "h")<<1>>
	Real DesignFactor*<<1.2>>
	integer RoundupDemcimalPlaces*<<-1>>
	TextLabel ,"Results"
	real Feed_Flowrate@("Qv", "m^3/h"){Comment("Slurry Only")}
	real Prod_Flowrate@("Qv", "m^3/h"){Comment("Slurry Only")}
	real VolumeReqd@("Vol", "m^3")
	Real Design_Volume@("Vol", "m^3"){Comment("using Roundup")}

	Sub Init()
		UnitTag = ClassTag()
		FeedTag = Concatenate(UnitTag, ".QFeed.SLQv (m^3/h)")
		ProdTag = Concatenate(UnitTag, ".QProd.SLQv (m^3/h)")
		VolTag  = Concatenate(UnitTag, ".ResTime.Volume (m^3)")
	EndSub

	Sub Exec()
		Feed_Flowrate = [FeedTag]
		Prod_Flowrate = [ProdTag]
		VolumeReqd    = Max(Feed_Flowrate, Prod_Flowrate) * ResidenceTimeReqd
		Design_Volume = Roundup(VolumeReqd * DesignFactor, RoundupDemcimalPlaces)
		[VolTag]      = VolumeReqd 
	EndSub	
EndClass

;Variable Declaration
;--- Using the Class --- 
PageLabel "Tanks"
Class_Tank {ClassGrid} FEED_TANK, AUTOCLAVE

Sub InitialiseSolution()
  ;--- Logic executed during initialisation before first iteration
  ;For example to set initial values, or set values in units
  ForEachSub(Class_Tank, init())
EndSub

  ForEachSub(Class_Tank, Exec())
$ ; --- end of file ---

EXAMPLE TankVol.png

NOTE: A variation of this file can be found in the Demo Nickel Copper Project from Build 139.37023.

Predefined Classes in SysCAD

Predefined Class Brief Description
Useful class instances include:
SDB - Species Database Class The SDB class instance gives access to information about species and phases within a project. For example, users can obtain species Density, Saturated Temperature or Pressure, number of solid species in a project, etc.
PSD - Particle Size Definition Class The PSD class instance gives access to information about the Particle Size Definition (PSD) within a project. For example, users can find the number of Size Intervals in a PSD, the Top and bottom Size, etc.
PM - Plant Model Class The PM class instance provides a function to retrieve a list of global tags available in the Plant Model (PM), can be used in PGM or MP files.
Useful classes include:
Array Class This Class lets user define an array to read or store numeric values.
StrArray Class This Class lets user define an array to read or store (in memory) string values.
Matrix Class This Class lets user define an matrix to read or store values.
TagSelect Class This Class provides a function to retrieve a list of model tags meeting a SQL type select query, similar to the Excel Tag Select Reports.
Time Class This Class contains some function to manipulate the time readings.
Some Old but still usable classes include:
Noise Class This has been implemented into SysCAD as the Noise Process unit.

Example User Defined Classes

  1. Demo Nickel Copper Project - Various PGM files utilising Class. These include calculations for tank volume, elemental balance, species balance, process block (BFD) mass balance checks and Optimise Controller.
  2. Gold Project - demonstrates the use of Classes in the CSTR pgm file. This is used to calculate the gold and copper leaching and adsorption values in a number of individual tanks.
  3. Lime Preparation (Makeup) Example - demonstrates the use of two user defined Classes: Set Species Splits and Optimise Controller.
  4. Milling and Flotation Project - demonstrate the use of Classes to display flotation recoveries at the end of project solve.
  5. Milling and Magnetic Separation Project - demonstrate the use of Classes to display cyclone splits and magnetic separator recoveries.
  6. Size Distribution Project - demonstrate the use of Classes to display some cyclone split information.
  7. Digestion with Direct Heating - demonstrates the use of Classes to calculate user defined properties.
  8. Demo Ammonia Project - demonstrates the use of Classes to calculate water shift.
  9. SOP Example Project - demonstrate the use of Classes to add rainfall and evaporation to the tank model (emulating a pond).
  10. FerroManganese Furnace Example Project - demonstrates use of Classes to set flow in feeders, perform heat loss calculations, and to calculate and set reactions extents.
  11. See Example Class Files for more examples of user defined class definitions.