# # Copyright 2003 (c) Pointwise, Inc. # All rights reserved. # # This sample Gridgen script is not supported by Pointwise, Inc. # It is provided freely for demonstration purposes only. # SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE. # gg::tkLoad set KinematicViscosity 3.5e-7 set FreestreamVelocity 0 set Density .002378 set BoundryLayerOrigin "0,0,0" set StartSurfaceEnd "0,0,0" set YplusValue 50 set endScript 1 set selected {} set allcons {} foreach i [gg::conGetAll] { if { [catch { gg::conGetPt $i 1 }]==0 } { lappend allcons "$i - Begin" lappend allcons "$i - End" } } set parent "" catch { set scriptDir [file dirname [info script]] source [file join $scriptDir pwiLogo.glf] } proc checkInputStatus { } { global YPlus if {0 == $YPlus(fsvel) || 0 == $YPlus(density) || \ 0 == $YPlus(kenvisc) || 0 == $YPlus(origin) || \ 0 == $YPlus(yplus) || 0 == [llength [$YPlus(list) curselection]]} { $YPlus(okButton) configure -state disabled $YPlus(applyButton) configure -state disabled } else { $YPlus(okButton) configure -state normal $YPlus(applyButton) configure -state normal } } proc isCoordinate { str } { global errorCode set a "?" set x "?" set y "?" set z "?" set re {^\s*([-.eE0-9]+)[, ]+([-.eE0-9]+)[, ]+([-.eE0-9]+)\s*$} catch { regexp $re $str a x y z } if {[string is double $x] == 0 || [string is double $y] == 0 || \ [string is double $z] == 0 } { set st 0 } else { set st 1 } return $st } proc checkCoordinateInput { w var text action } { global YPlus # Ignore force validations if {$action == -1} { return 1 } if {![isCoordinate $text]} { set YPlus($var) 0 $w configure -bg "#FFCCCC" } else { set YPlus($var) 1 $w configure -bg "#FFFFFF" } checkInputStatus return 1 } proc checkRealInput { w var text action } { global YPlus # Ignore force validations if {$action == -1} { return 1 } if {![string is double $text]} { set YPlus($var) 0 $w configure -bg "#FFCCCC" } else { set YPlus($var) 1 $w configure -bg "#FFFFFF" } checkInputStatus return 1 } proc Coord2List { coord } { set a "?" set x "?" set y "?" set z "?" set re {^\s*([-.eE0-9]+)[, ]+([-.eE0-9]+)[, ]+([-.eE0-9]+)\s*$} catch { regexp $re $coord a x y z } if {[string is double $x] == 0 || [string is double $y] == 0 || \ [string is double $z] == 0 } { set st [list 0 0 0] } else { set st [list $x $y $z] } return $st } proc getY { dist } { global KinematicViscosity FreestreamVelocity Density BoundryLayerOrigin YplusValue if { [catch { set Rex [expr $Density*$FreestreamVelocity*$dist/$KinematicViscosity] set cf [expr .026*pow($Rex,-1/7.)] set tao_wall [expr $cf*$Density*$FreestreamVelocity*$FreestreamVelocity/2] set friction_velocity [expr sqrt($tao_wall/$Density)] }]==1 } { global endScript; tk_dialog .err "Warning..." "One of the selected connector ends is at the boundary layer origin. Its spacing will not be updated." warning "0" "Skip"; return -1; } return [expr $YplusValue*($KinematicViscosity/$Density)/$friction_velocity] } #This is where we actually run the calculations and modify the grid proc runCalculations { } { global BoundryLayerOrigin foreach i {freestrvel density kenvisc origin yplus} { .inputs.$i.ent$i validate if { [string first "#FFCCCC" [.inputs.$i.ent$i configure -background]]!=-1 } { .inputs.$i.ent$i selection range 0 100 focus .inputs.$i.ent$i return } } foreach {ox oy oz} [Coord2List $BoundryLayerOrigin] {break} foreach connum [.selector.list curselection] { set conend [.selector.list get $connum] scan $conend "%s - %s" c p set x 0 set y 0 set z 0 if { [string compare $p Begin]==0 } { set pt 1 } else { set pt [gg::conDim $c] } foreach {x y z} [gg::conGetPt $c $pt] {break} set dist [expr sqrt(pow($ox-$x,2)+pow($oy-$y,2)+pow($oz-$z,2))] set spacing [getY $dist] if { $spacing > -1 } { setSpacing $c $p $spacing } } } proc setSpacing { con part spacing } { if { [catch { if { [string compare $part "Begin"]==0 } { gg::conBeginSpacing $con $spacing } else { gg::conEndSpacing $con $spacing } }]==1 } { tk_dialog .sfail "Error..." "Spacing, $spacing, too large on connector $con ($part). Connector will be skipped." warning 0 "Ok"} } proc select { } { global selected allcons set sel {} foreach i [.selector.list curselection] { lappend sel [lindex $allcons $i] } wm withdraw . set sel [gg::dispPick SUBCON_END -interior FALSE -message "Select Connectors to be Split" -select [formatCons $sel]] .selector.list selection clear 0 end foreach i $sel { lappend selected "[lindex $i 0] - [lindex $i 2]" .selector.list selection set [lsearch $allcons "[lindex $i 0] - [lindex $i 2]"] } if {[winfo exists .]} { wm deiconify . } checkInputStatus } proc formatCons { cns } { set ret {} foreach c $cns { set con [lindex $c 0] set side [lindex $c 2] if { $side == "Begin" } { set sc 1 } else { set sc [gg::conGetNumSubCons $con] } lappend ret "$con $sc $side" } return $ret } proc loadFromFile { file } { if { [string compare $file ""]!=0 } { if { [catch { set f [open $file r] global KinematicViscosity FreestreamVelocity Density BoundryLayerOrigin YplusValue while { [gets $f line] >= 0 } { catch { eval $line } } close $f }]==1 } { tk_dialog .d "Error: Loading File..." "Could not access file $file. Load Parameters Failed!" warning 0 "Cancel" } } } proc saveToFile { file } { if { [string compare $file ""]!=0 } { set f 0 if { [catch { set f [open $file w] global KinematicViscosity FreestreamVelocity Density BoundryLayerOrigin YplusValue foreach i {KinematicViscosity FreestreamVelocity Density YplusValue} { puts $f "set $i [eval expr $$i+0]" } puts $f "set BoundryLayerOrigin $BoundryLayerOrigin" puts $f ".selector.list selection clear 0 end" foreach i [.selector.list curselection] { puts $f ".selector.list selection set $i" } flush $f close $f }]==1 } { tk_dialog .d "Error: Saving File..." "Could not access file $file. Save failed" warning 0 "Cancel" } } } proc makeInputField { parent name title variable {width 7} {valid ""} } { frame $parent.$name label $parent.$name.lbl$name -text $title entry $parent.$name.ent$name -textvariable $variable -width $width if { [string compare $valid ""]!=0 } { $parent.$name.ent$name configure -validate all $parent.$name.ent$name configure -validatecommand $valid } pack "$parent.$name.ent$name" -side right -padx 3 -pady 1 pack "$parent.$name.lbl$name" -side right -padx 3 -pady 1 return $parent.$name } proc makeWindow {} { global KinematicViscosity FreestreamVelocity Density BoundryLayerOrigin YplusMin YplusMax global YPlus #Begin Menu Section frame .mbar -bd 0 menubutton .mbar.file -text "File" -menu .mbar.file.menu menu .mbar.file.menu -tearoff 0 .mbar.file.menu add command -label "Load Parameters..." -command { loadFromFile [tk_getOpenFile -parent .] } .mbar.file.menu add command -label "Save Parameters..." -command { saveToFile [tk_getSaveFile -parent .] } pack .mbar.file -side left pack .mbar -side top -fill x frame .hr0 -bd 1 -height 2 -relief sunken pack .hr0 -side top -fill x -expand 0 -pady 2 #End Menu Section #Begin Title Section label .title -text "Y+ Connector Spacing" set font [.title cget -font] .title configure -font [font create -family [font actual $font -family] -weight bold] pack .title -expand 1 -side top frame .hr1 -bd 1 -height 4 -relief flat pack .hr1 -side top -fill x -expand 0 -pady 2 label .subtitle -text "Enter flow data in units consistent with your grid's length units." pack .subtitle -side top #End Title Section #Begin Input Section frame .inputframe pack .inputframe -fill both -padx 2 -pady 2 #Begin Variable Input pack [frame .inputs] -side left -in .inputframe -fill both set YPlus(fsvel) 1 set YPlus(density) 1 set YPlus(kenvisc) 1 set YPlus(origin) 1 set YPlus(yplus) 1 pack [makeInputField .inputs freestrvel "Free Stream Velocity:" FreestreamVelocity 7 [list checkRealInput %W fsvel %P %d]] -padx 5 -pady 2 -fill x -expand y pack [makeInputField .inputs density "Density:" Density 7 [list checkRealInput %W density %P %d]] -padx 5 -pady 2 -fill x -expand y pack [makeInputField .inputs kenvisc "Kinematic Viscosity:" KinematicViscosity 7 [list checkRealInput %W kenvisc %P %d]] -padx 5 -pady 2 -fill x -expand y pack [makeInputField .inputs origin "Boundary Layer Origin:" BoundryLayerOrigin 7 [list checkCoordinateInput %W origin %P %d]] -padx 5 -pady 2 -fill x -expand y pack [makeInputField .inputs yplus "y+ Value:" YplusValue 7 [list checkRealInput %W yplus %P %d]] -padx 5 -pady 2 -fill x -expand y #End Variable Input #Begin Selector pack [frame .right] -in .inputframe -side right pack [frame .selector] -fill y -side top -in .right pack [scrollbar .selector.scroll -command ".selector.list yview" -takefocus 0] -side right -fill y pack [listbox .selector.list -yscrollcommand ".selector.scroll set" -selectmode multiple -exportselection false -takefocus 0 -listvariable allcons] -fill both -side right bind . <> [list checkInputStatus] set YPlus(list) .selector.list pack [button .sel -command select -text "Select Connector Ends"] -side bottom -in .right #End Selector #End Input Section #Begin Bottom Logo and Buttons frame .commands button .commands.ok -text "OK" -command { global endScript; runCalculations; if { $endScript } { exit } } button .commands.apply -text "Apply" -command { global endScript; runCalculations } button .commands.cancel -text "Quit" -command { exit } set YPlus(okButton) ".commands.ok" set YPlus(applyButton) ".commands.apply" frame .hr2 -bd 1 -height 2 -relief sunken pack .hr2 -side top -fill x -expand 0 -pady 2 if {![catch {pwiLogoCreate .commands.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 -fill y } pack .commands -fill x -side bottom pack .commands.cancel .commands.apply .commands.ok -padx 2 -pady 1 -side right bind .commands.ok { global endScript; runCalculations; if { $endScript } { exit } } bind .commands.apply { global endScript; runCalculations} bind .commands.cancel { exit } #End Bottom Logo and Buttons checkInputStatus } makeWindow ::tk::PlaceWindow . widget focus .inputs.freestrvel.entfreestrvel .inputs.freestrvel.entfreestrvel selection range 0 100 gg::tkLoop # # DISCLAIMER: # TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS # ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED # TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED # BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY # FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES # WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF # BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE # USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN # ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE # FAULT OR NEGLIGENCE OF POINTWISE. #