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)
    ;use the next line for latest versions of SysCAD, Build 139.32346 or later.
    PauseSolver("Ohoh:", Message)
    ;OR use the next two lines for older versions of SysCAD, Build 139.32346 or earlier.    
    ;logerror("Ohoh:",Message)
    ;pausesimulation = true
  Endif
EndSub
Sub CheckVersion()
    Bit BuildOK
    Const long VersionNumber = 32346
    BuildOK = PM.Version(0)>=9 AND PM.Version(1)>=3 AND PM.Version(2)>=139 AND PM.Version(3)>=VersionNumber
    If NOT BuildOK
        ;use the next line for latest versions of SysCAD, Build 139.32346 or later.
        StopSolver("Incorrect version of SysCAD, needs SysCAD9.3 Build139.", IntToStr(VersionNumber)," or later.")
        ;OR use the next two lines for older versions of SysCAD, Build 139.32346 or earlier.
        ;LogError("Incorrect version of SysCAD, needs SysCAD9.3 Build139.", IntToStr(VersionNumber)," or later.")
        ;StopSimulation = true  
    Endif
EndSub

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

PageLabel "CheckConvergence" 
    Textbreak 
    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 ---