Defining a Class
From SysCAD Documentation
Navigation: PGMs
Related Topics: Defining a Function, Access Class Members
Predefined Classes: Specie Database Class, Array Class, Matrix Class, Noise, TimeClass, PID Controller, Profiler
Contents |
Syntax
Class className Variable declaration(s) Function(s) EndClass
- className : is an unique name of the class, used to refer to the class.
- The class declaration must begin with the Class keyword and end with the EndClass keyword. See Class Declaration.
- Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class.
- While declaring variables in a class, the normal variable declaration rules will apply. Thus, the user can define units, append * to add the variable to the access window and/or append @ to make the variable read only. For more information, refer to Variable declaration.
- Function, StrFunction can be declared, within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.
- Classes cannot be nested. (ie classes cannot be defined within classes)
For a working example of how to define and uses Classes and functions, see Example PGM with Classes and Functions
Class Example
Class TimeConversions Double minutes, hours Function GetMinutes() minutes = Time()/60 Return minutes EndFunct Function CalcAll() minutes = Time()/60 hours = minutes/60 Return 0 EndFunct EndClass
Using Class
TimeConversions FirstTime, CurTime double NoOfHours if (OnStart) FirstTime.CalcAll() endif CurTime.CalcAll() NoOfHours = CurTime.Hours - FirstTime.Hours WatchInfo(CurTime.minutes,0,1440,"Current number of minutes elapsed")
Note:
- The data members of the class can be used within the member functions.
- Once an instance is declared, the data members and member functions of the instance can then be accessed using Dot Notation.
Declare arrays of User Classes
This can only be done in the global scope.
Use square braces "[" and "]" to index array elements. First element is at index 0.
Example of declaration would be "MyClass C[5]".
Examples to access a class member: "C[0].a = 5"; "C[i].Exec()"; "x = C[i].a + C[i].GetResult(g)"
Exclude Watch of User Class Tags
ExcludeWatch UserClass[index]
This is used to make the variables of a class not visible in the access window. eg "ExcludeWatch C[0]"
Predefined Classes in SysCAD
Useful classes include: Specie Database Class, Array Class, Matrix Class, TimeClass
Some Old but still usable classes include: Noise, PID Controller, Profiler. NOTE these three classes have been converted into SysCAD models, users can use the Insert Unit operations to insert them onto the flowsheet.
Use of Classes in Example Projects
- 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.
