Example PGM - Species Check

From SysCAD Documentation
Jump to navigation Jump to search
Warning! Page you're reading is outdated or was archived and very likely is referring to older version of the software.

Navigation: PGMs ➔ Example PGM Files ➔ Species Check


General Notes

  1. From Build 139, the used/unused species list are listed in the Plant Model - Species tab. The examples below are for Build 138 or earlier.
  2. The PGM can be added to any project, the check is performed at the end of project solve. If the project is very large (with thousands of pipes and hundreds of species), user may need to change the PlantModel - FlwSolve - PGM_ExecuteTimeout value to allow SysCAD more time to finish the calculations.
  3. The species list display length may need to be adjusted if the number of species with flow or with no flow is greater than 100.
  4. The following PGM examples demonstrate the use of the many pre-defined classes and functions:
    • Species Database Class - how to fetch species data information
    • TagSelect - apply a search criteria to select relevant models. In the examples below, it will search for models that belong to the stream unit group only, that is, Pipes and makeup streams.
    • String Array - how to store a list a string variables (e.g.: species flow list, species no flow list)
    • Array - how to used array to store value and apply array summation. (see Example 2)
    • String Functions - how to apply string comparison (See Example 3)

Example 1 - Species with Flow List

Available from Build 139., the used species list can be found in Plant Model - Species tab.
For build138 and earlier, the following PGM can be used to check if a certain species is used by the project (has flow) :

  • The PGM will search through each species in the project, if the species has flow it will be added to the "Species_With_Flow" list.
  • The "Species With Flow" list can be used to create stream reports, as it will help shorten the list of species.
  • See General Notes
PageLabel("CheckSpecies")
    TextLabel(, "  --Time out value may need to be adjusted for large projects--" )
    Real  PGM_time_out*("Time", "s")<<300>>
    TextLabel(, "   -----------Species-----------",)
    TagSelect SpeciesListWithFlow
    StrArray  SpeciesFlowList
    integer   speciesCount@,  HasFlowCount, speciesWithFlowCount@, i, j
    Checkbox  CriteriaOK
    string    Criteria, SpeciesName
    ; The follow watch function is used to set the species list display length.  User can adjust the value as needed.
    Watch SpeciesFlowList[All,100]@
  
Sub InitialisePreStart() 
    ["PlantModel.PGM_ExecuteTimeout (s)"] = PGM_time_out
EndSub 
	
Sub CheckSpecies()
     While i < speciesCount
          SpeciesName = SDB.SpSymbol(i)
          Criteria = Concatenate("[UnitGroup]=='Stream' AND [Qo.QM.", SpeciesName, " (g/h)]>1 ")
          CriteriaOK = SpeciesListWithFlow.Exec(Criteria, false, false)
          HasFlowCount= SpeciesListWithFlow.GetLen()
          If HasFlowCount > 0
              SpeciesFlowList.SetAt(j,SpeciesName)
              j = j + 1
          Endif	
          i = i + 1
     EndWhile
     speciesWithFlowCount = j
EndSub

Sub TerminateSolution() 
     speciesCount = SDB.SpeciesCount()
     SpeciesFlowList.SetLen(speciesCount)
     i = 0
     j = 0
     CheckSpecies()
     Lognote("Finished Species Check")
EndSub

$ ; --- end of file ---

Example 2 - Species with NO Flow List

Available from Build 139., the unused species list can be found in Plant Model - Species tab.
For build138 and earlier, the following PGM can be used to check if a certain species is not used by the project (has no flow):

  • The PGM will search through the project, streams with total flow > specified flow will be analysed.
  • For each species, the species flow for each pipe meeting the search criteria will be temporarily stored in an array.
  • If the sum of the array equals 0, then the species has no flow in the project, it will be added to the NO flow list.
  • See General Notes
PageLabel("CheckNoFlowSpecies")
    TextLabel(, "  --Time out value may need to be adjusted for large projects--" )
    Real  PGM_time_out*("Time", "s")<<300>>
    TextLabel(, "   -----------Species-----------",)
    Array     SpeciesFlow
    Real      SpeciesFlow_Sum
    TagSelect SpeciesListFlowCheck
    StrArray  SpeciesNoFlowList
    integer   speciesCount@,  speciesNoFlowCount@, i, j
    Checkbox  CriteriaOK
    string    SpeciesFlowTag, SpeciesName
    ; The follow watch function is used to set the species list display length.  User can adjust the value as needed.
    Watch SpeciesNoFlowList[All,100]@

Sub InitialisePreStart() 
    ["PlantModel.PGM_ExecuteTimeout (s)"] = PGM_time_out
EndSub 	
	
Sub CheckSpecies()
     While i < speciesCount
          SpeciesName = SDB.SpSymbol(i)
          CriteriaOK = speciesListFlowCheck.Exec("[UnitGroup]=='Stream' AND [Qo.Qm (g/h)]>1 ", false, false)
          SpeciesFlowTag = Concatenate(".Qo.QM.", SpeciesName, " (t/h)")
          speciesListFlowCheck.GetValues(SpeciesFlowTag, SpeciesFlow)
          SpeciesFlow_Sum = SpeciesFlow.Sum()
          If SpeciesFlow_Sum == 0
              SpeciesNoFlowList.SetAt(j,SpeciesName)
              j = j + 1
          Endif	
          i = i + 1
     EndWhile
     speciesNoFlowCount = j
EndSub

Sub TerminateSolution() 
     speciesCount = SDB.SpeciesCount()
     SpeciesNoFlowList.SetLen(speciesCount)
     i = 0
     j = 0
     CheckSpecies()
     Lognote("Finished Species Check")
EndSub

$ ; --- end of file ---

Example 3 - Comparing Lists

Available from Build 139., the used/unused species list can be found in Plant Model - Species tab.
For build138 and earlier, the following PGM can be used to check if a certain species is used (has flow) or not used (with no flow) by the project:

  • The PGM will search through each species in the project, if the species has flow it will be added to the "Species_With_Flow" list.
  • The "Species With Flow" list is then compared to the full species list, thus creating a "Species No Flow" list by difference.
  • The "Species With Flow" list can be used to create stream reports, as it will help shorten the list of species.
  • See General Notes
PageLabel("CheckSpecies")
    TextLabel(, "  --Time out value may need to be adjusted for large projects--" )
    Real  PGM_time_out*("Time", "s")<<300>>
    TextLabel(, "   -----------Species-----------",)
    TagSelect SpeciesListWithFlow
    StrArray  SpeciesFlowList,SpeciesNoFlowList
    integer   speciesCount@,  HasFlowCount, speciesWithFlowCount@,  speciesNoFlowCount@, i, j, k
    Checkbox  CriteriaOK
    string    Criteria, SpeciesName
    ; The follow watch function is used to set the species list display length.  User can adjust the value as needed.
    Watch SpeciesFlowList[All,100]@, SpeciesNoFlowList[All,100]@
 
Sub InitialisePreStart() 
    ["PlantModel.PGM_ExecuteTimeout (s)"] = PGM_time_out
EndSub 
	
Sub CheckSpecies()
     While i < speciesCount
          SpeciesName = SDB.SpSymbol(i)
          Criteria = Concatenate("[UnitGroup]=='Stream' AND [Qo.QM.", SpeciesName, " (g/h)]>1 ")
          CriteriaOK = SpeciesListWithFlow.Exec(Criteria, false, false)
          HasFlowCount= SpeciesListWithFlow.GetLen()
          If HasFlowCount > 0
              SpeciesFlowList.SetAt(j,SpeciesName)
              j = j + 1
          Endif	
          i = i + 1
     EndWhile
     speciesWithFlowCount = j
EndSub

Sub NoFlowList()
     While i < speciesCount
          SpeciesName = SDB.SpSymbol(i)
          if (StrCmp(SpeciesName,SpeciesFlowList.GetAt(j)) == 0)
          ; species has flow, check next species
               j = j + 1
          else
          ; species has no flow, add to no flow list
               SpeciesNoFlowList.SetAt(k,SpeciesName)
               k = k + 1
          endif
          i = i + 1
     EndWhile
EndSub

Sub TerminateSolution() 
     speciesCount = SDB.SpeciesCount()
     SpeciesFlowList.SetLen(speciesCount)
     i = 0
     j = 0
     CheckSpecies()
     speciesNoFlowCount = speciesCount - speciesWithFlowCount
     if speciesNoFlowCount > 0
          SpeciesNoFlowList.SetLen(speciesNoFlowCount)
          i = 0
          j = 0
          k = 0
          NoFlowList()
     endif
     Lognote("Finished Species Check")
EndSub

$ ; --- end of file ---