# # How this works: # - checks what solver has been set (CAE / Select-Solver and CAE/Set-Dimension) # - looks for a file named solver-name+dimension.pwg in your home folder # eg. cfd++_2D.pwg if your solver is set to CFD++ in 2D # cfd++_3D.pwg if your solver is set to CFD++ in 3D # Note that spaces are removed from the config file names ("Ansys Fluent" becomes "AnsysFluent") # # - if the file isn't found, prints a mesage and exits # - if the file is found, opens it and scans for metric-name / value / min-max specs, and forms a list # the list need not be complete: you may well choose to check for only 1 metric # use the supplied example PWG file (a "#" in the first column indicates the line should be ignored) # - prompts the user to select items (domains or blocks, depending on the dimension) # - runs the examine and prints results # package require PWI_Glyph 2.3 # procedure to get Solver name + dimension # returns name of config file to look for proc getPwgName { } { set mySolver [pw::Application getCAESolver] # strip spaces regsub -all { } $mySolver "" mySolver set myDimension [pw::Application getCAESolverDimension] append myPwgName $mySolver "_" $myDimension "D" ".pwg" return $myPwgName } # open the file, extract metric name/cutoff/min-max flag and saves in list # return this list to the caller proc parsePwgFile { fileName } { # get list of supported metrics set mySupportedMetrics [pw::Examine getFunctionNames] puts [ format " Opening %s ..." $fileName ] set pwgFile [ open $fileName r ] set lineNumber 0 set myErrorFlag1 0 set myErrorFlag2 0 set metricList [] # Read till file ends while { [gets $pwgFile fileLineString] >= 0 } { incr lineNumber set myFirstChar [string index $fileLineString 0] set myIsComment [string equal $myFirstChar "#"] if { !$myIsComment } { set numTokens [llength $fileLineString] # if metric is in mySupportedMetrics, add it - else ignore it if { $numTokens != 3} { puts [ format " Ignoring line %d: expected 3 items, found %d (%s)" $lineNumber $numTokens $fileLineString ] } else { set myTokens [ scan $fileLineString "%s %s %s" myToken1 myToken2 myToken3] # if token 1 is in mySupportedMetrics AND token2 = MIN or MAX, add them, # else flash warning and ignore set myFirstCheck [regexp $myToken1 $mySupportedMetrics ] set mySecondCheck [ string equal $myToken2 "MIN" ] set myThirdCheck [ string equal $myToken2 "MAX" ] #set myErrorFlag1 0 #set myErrorFlag2 0 if { !$myFirstCheck } { puts [ format " Error on line %d: first word is not a valid metric! (%s) " $lineNumber $myToken1 ] set myErrorFlag1 1 } if { !$mySecondCheck && !$myThirdCheck } { puts [ format " Error on line %d: second word must be either MAX or MIN! (%s) " $lineNumber $myToken2 ] set myErrorFlag2 1 } if { !$myErrorFlag1 && !$myErrorFlag2 } { puts [format " Success reading line %d (%s)" $lineNumber $fileLineString ] lappend metricList $myToken1 lappend metricList $myToken2 lappend metricList $myToken3 } } } } if { $myErrorFlag1 > 0 } { set myNumSupportedMetrics [ llength $mySupportedMetrics ] #puts [ format " Valid metric names are any of the following: " ] if { [pw::Application getCAESolverDimension] == 3 } { # list Block Metrics puts " Current solver is 3D, so only Block related metrics are valid" for {set myCounter 0} {$myCounter < $myNumSupportedMetrics } {incr myCounter} { set myKeyWord [lindex $mySupportedMetrics $myCounter] if { [regexp "Block" $myKeyWord ] } { puts [ format " %s" $myKeyWord ] } } } else { # list Domain Metrics puts " Current solver is 2D, so only Domain related metrics are valid" for {set myCounter 0} {$myCounter < $myNumSupportedMetrics } {incr myCounter} { set myKeyWord [lindex $mySupportedMetrics $myCounter] if { [regexp "Domain" $myKeyWord ] } { puts [ format " %s" $myKeyWord ] } } } } if { $myErrorFlag2 > 0 } { puts " Second key word must either be MAX or MIN" } close $pwgFile return $metricList } # # Given the list of metrics, the min/max flag and cutoff for each, AND the entities to examine, # this procedure runs the PW Examiner and reports the results # proc checkMetrics { mySpecs mySelectedEntities } { set numSpecs [ llength $mySpecs ] set mySpecList [ split $mySpecs " " ] for {set myCounter 0} {$myCounter < $numSpecs } {set myCounter [expr $myCounter + 3] } { set myMetricName [lindex $mySpecList $myCounter] set myMetricType [lindex $mySpecList [ expr $myCounter+1] ] set myMetricCutoff [lindex $mySpecList [ expr $myCounter+2] ] set isMin [string equal $myMetricType "MIN"] puts [ format " Checking %s against %s of %f ..." $myMetricName $myMetricType $myMetricCutoff ] foreach thisEntity $mySelectedEntities { set myExam [pw::Examine create $myMetricName] $myExam addEntity [list $thisEntity] $myExam examine if { $isMin } { set thisMinVal [$myExam getMinimum -entity thisMinVar -location thisMinLoc] set thisMinName [$thisMinVar getName] if { $thisMinVal <= $myMetricCutoff } { puts [format " %s fails ( = %s )" $thisMinName $thisMinVal ] } else { puts [format " %s passes ( = %s )" $thisMinName $thisMinVal ] } } else { set thisMaxVal [$myExam getMaximum -entity thisMaxVar -location thisMaxLoc] set thisMaxName [$thisMaxVar getName] if { $thisMaxVal >= $myMetricCutoff } { puts [format " %s fails ( = %s )" $thisMaxName $thisMaxVal ] } else { puts [format " %s passes ( = %s )" $thisMaxName $thisMaxVal ] } } $myExam delete unset myExam } } } #================================Start processing============================== set startTime [clock seconds] puts [ format "Start time: [clock format $startTime -format %H:%M:%S] " startTime ] puts [ format " Executing %s" [ file normalize [ info script ] ] ] set myPwgName [getPwgName] if { [file exists $myPwgName] == 1} { puts [ format " Reading specs from %s in the folder %s" $myPwgName [pwd]] #open the file and parse the list set myMetrics [ parsePwgFile $myPwgName ] # prompt user to select relevant items: Blocks if 3D, Doms if 2D (exit with comment if canceled) set myEntities [] if { [pw::Application getCAESolverDimension] == 3 } { set myMask [pw::Display createSelectionMask -requireBlock [list] ] pw::Display selectEntities \ -description "Select the Blocks to be examined" \ -selectionmask $myMask selection set myEntities $selection(Blocks) set myEntityString "Block" } else { set myMask [pw::Display createSelectionMask -requireDomain [list] ] pw::Display selectEntities \ -description "Select the Domains to be examined" \ -selectionmask $myMask selection set myEntities $selection(Domains) set myEntityString "Domain" } set numSelected [ llength $myEntities ] if {$numSelected < 1 } { puts "Nothing selected, script aborted." } else { if { $numSelected > 1 } { append myEntityString "s" } puts [ format " Examining %d %s" $numSelected $myEntityString ] set myResult [ checkMetrics $myMetrics $myEntities ] } } else { puts [ format " Unable to locate config file %s in %s" $myPwgName [pwd] ] } # End timer set endTime [clock seconds] puts [ format "End time: [clock format $startTime -format %H:%M:%S] " endTime ] puts "Script executed in [expr $endTime-$startTime] seconds, on [clock format $startTime -format %D] "