PGM Examples - Check Version, Error and Convergence

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs ➔ Example PGM Files ➔ Checking Project

Simple Examples Subroutines Examples Dynamic Examples Steady State Overall Mass Balance Array and Matrix Examples
Basic
Layout
Simple
Calculations
Initialise
PreStart
Multi-Step Trigger Checking
Project
Counter, While
and Random
Belt Filter
Wash Loss
Startup
Actions
Mass
Balance
Mass
Balance
Species
Balance
Elemental
Balance
Lookup
Value
Set
Values
Tridiagonal
System

Related Links: Trigger Subroutines


Example PGM Subroutine to Check for Error and Pause Simulation

Checkbox  CheckErrors*

Sub SanityCheck(BIT Wrong, STR Message)
  if (CheckErrors AND Wrong)
    logerror(strcat("Ohoh:",Message))
    pausesimulation = true
  Endif
EndSub
Checkbox BuildOK@

Sub CheckVersion()
  BuildOK = PM.Version(0)>=9 AND PM.Version(1)>=3 AND PM.Version(2)>=139 AND PM.Version(3)>=31866
  ; Needs to be SysCAD9.3 Build139.31866 or higher to use the new PGM function.
  If NOT BuildOK
     LogError("Incorrect version of SysCAD, needs SysCAD9.3 Build139.31866 or later.")
     Beep(1)
     StopSimulation = true
  Endif
EndSub

Example: Check the Status of Project Convergence at the end of Project Solve

PageLabel("CheckConvergence")
    TextLabel(, )
    CheckBox Project_Converged@, Project_Has_Errors@, Project_Has_Warnings@
    Long     NumberOf_Errors@, NumberOf_Cond_Warning@

Sub TerminateSolution() 
    Project_Converged     = ["$Solver.Convergence.Converged"] == True
    Project_Has_Errors    = ["PlantModel.Status.Total.Error.Count"] > 0
    Project_Has_Warnings  = ["PlantModel.Status.Cnds.Warning.Count"] > 0  ; Getting solve condition errors only
    NumberOf_Errors 	  = ["PlantModel.Status.Total.Error.Count"]
    NumberOf_Cond_Warning = ["PlantModel.Status.Cnds.Warning.Count"]

  If Not Project_Converged OR Project_Has_Errors OR Project_Has_Warnings
      Lognote("Project may not be fully solved, please check results")	
      Sound(3000, 100)
  Else
      Lognote("Project Solved")	
      Sound(2000, 100)
  Endif	
 
EndSub
	
$ ; --- end of file ---