PGM Example - Reaction Finder Classes and Functions
Jump to navigation
Jump to search
Navigation: PGMs ➔ Example PGM Files ➔ Reaction Finder Classes and Functions
SysCAD Pre-Defined Classes and Examples | EXAMPLES: User Defined Classes | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Sp Databse Class | PSD Class | Array Class | StrArray Class | Matrix Class | Tag Select Class | Plant Model Class | Noise Class | Time Class | Agitator Power | Reaction Finder | Aq Feed Conc Calculator | Evaporation Correlation | Bayer Liquor Class | Check Element Bal |
Latest SysCAD Version: 17 May 2022 - SysCAD 9.3 Build 139.30918
Related Links: PGM Classes, PGM Functions
Example PGM with ReactionFinder Classes and Functions
;============================================================================ ; Project Used: Any with a Reaction Block. Updated September 2018 ;============================================================================ ; Description of the ReactionFinder Class function --- ; This class frees the user from the problem of the reaction index changing when a new reaction ; is added to the reaction file before the controlled reaction(s). The "Init" function should be called ; in the "InitialiseSolution" subroutine and this finds the index of the required reaction. ; The "SetExtent" function then sets the extent of the reaction as a fraction. ;============================================================================= Class ReactionFinder ;--- input variables ------ TextLabel(,) String ReqdUnit* ;the unit containing the reaction file String ReqdReaction* ;the actual reaction that will be controlled Real ReqdExtent*("Frac","%") ;the required reaction extent ;---- Output variables ------ long [email protected] ;the actual reaction index number in the unit long [email protected] ;total number of reactions in the reaction file ;--- local variables ------ String NumReactions, ReactionName, RBReact, ReactionTag, errormsg long Minlength, i, reactioncomp Function Init() if (strlen(ReqdUnit) > 0) i = 1 ReactionIndex = 0 NumReactions = Concatenate(ReqdUnit, ".RB.NoOfReactions") totalNumReactions = [NumReactions] while (i <= totalNumReactions) ReactionName = Concatenate(ReqdUnit, ".RB.R", IntToStr(i), ".Reaction") RBReact = [ReactionName] Minlength = Min(strlen(RBReact),strlen(ReqdReaction)) if (Minlength > 0) reactioncomp = StriCmp(Left(RBReact,Minlength), Left(ReqdReaction,Minlength)) if (reactioncomp == 0) ReactionTag = Concatenate(ReqdUnit, ".RB.R", IntToStr(i), ".Extent.Required (%)") ReactionIndex = i i = totalNumReactions + 1 endif endif i = i + 1 endwhile if (ReactionIndex == 0) errormsg = Concatenate("The reaction ", ReqdReaction, " not found in ", ReqdUnit) lognote(errormsg) endif endif return 0 EndFunct FUNCTION SetExtent() if (ReactionIndex > 0) [ReactionTag] = ReqdExtent endif return 0 EndFunct EndClass