PGM Example - Reaction Finder Classes and Functions

From SysCAD Documentation
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: 26 October 2022 - SysCAD 9.3 Build 139.31866

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       ReactionIndex@              ;the actual reaction index number in the unit
long       totalNumReactions@          ;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
;The following is an example of pgm code using the ReactionFinder class to
;call a number of reactions.

>>C:\SysCADProjects\CommonFiles\ReactionFinderClass.pgm
PageLabel("Reaction Control") 
TextLabel(,)
long        NumUnits*       ;this value should match the number of instances of ReactionFinder. 
long        iR
 
ReactionFinder Reactions[2]

Sub InitialiseSolution()
  iR = 0
  while (iR < NumUnits)
     Reactions[iR].Init()
     iR = iR + 1
  endwhile
EndSub

  iR = 0

  while (iR < NumUnits)
    Reactions[iR].SetExtent()
    iR = iR + 1
  endwhile

Endfile

ReactionFinder.png