1# util.tcl - CGNS utility routines 2 3array set Tools { 4 subseti i 5 subsetj j 6 subsetk k 7 cgnssol "" 8 solbase "" 9 solbase,flag 1 10 bboxpad "" 11 bboxpad,flag 1 12 maxdepth "" 13 maxdepth,flag 1 14 maxelem "" 15 maxelem,flag 1 16 extrapolate 0 17} 18 19proc interpolate_cgns {w name exe} { 20 global ProgData Tools Font 21 22 if {$ProgData(file,name) == ""} return 23 set cmd [get_executable $exe 1] 24 if {$cmd == ""} return 25 26 set Tools(cgnsinput) $ProgData(file,name) 27 if {$Tools(cgnsoutput) == ""} { 28 set Tools(cgnsoutput) $ProgData(file,name) 29 } 30 31 toplevel $w 32 wm title $w "Interpolate Solution" 33 wm transient $w . 34 wm protocol $w WM_DELETE_WINDOW {set Tools(done) 0} 35 36 set labw 13 37 38 FrameCreate $w.cgnssol -text "CGNS Solution" -font $Font(bold) 39 pack $w.cgnssol -side top -pady 2 -fill x 40 set wf [FrameGet $w.cgnssol] 41 42 set f [frame $wf.file] 43 pack $f -side top -fill x 44 label $f.lab -text Filename -width $labw -anchor w 45 pack $f.lab -side left 46 entry $f.ent -textvariable Tools(cgnssol) -width 30 47 pack $f.ent -side left -fill x -expand 1 48 button $f.but -text Browse -pady 0 -command "tools_browse $f.but cgnssol" 49 pack $f.but -side right -fill y 50 51 set f [frame $wf.basenum] 52 pack $f -side top -fill x 53 label $f.lab -text "Base Index" -width $labw -anchor w 54 pack $f.lab -side left 55 entry $f.ent -textvariable Tools(solbase) -width 10 56 pack $f.ent -side left 57 checkbutton $f.but -text default \ 58 -variable Tools(solbase,flag) -onvalue 1 -offvalue 0 \ 59 -command "tools_state solbase $f.ent" 60 pack $f.but -side left 61 62 tools_state solbase $f.ent 63 64 FrameCreate $w.cgnsinput -text "CGNS Grid" -font $Font(bold) 65 pack $w.cgnsinput -side top -pady 2 -fill x 66 set wf [FrameGet $w.cgnsinput] 67 68 set f [frame $wf.file] 69 pack $f -side top -fill x 70 label $f.lab -text Filename -width $labw -anchor w 71 pack $f.lab -side left 72 entry $f.ent -textvariable Tools(cgnsinput) -width 30 73 pack $f.ent -side left -fill x -expand 1 74 button $f.but -text Browse -pady 0 -command "tools_browse $f.but cgnsinput" 75 pack $f.but -side right -fill y 76 77 set f [frame $wf.basenum] 78 pack $f -side top -fill x 79 label $f.lab -text "Base Index" -width $labw -anchor w 80 pack $f.lab -side left 81 entry $f.ent -textvariable Tools(basenum) -width 10 82 pack $f.ent -side left 83 checkbutton $f.but -text default \ 84 -variable Tools(basenum,flag) -onvalue 1 -offvalue 0 \ 85 -command "tools_state basenum $f.ent" 86 pack $f.but -side left 87 88 tools_state basenum $f.ent 89 90 FrameCreate $w.cgnsoutput -text "CGNS Output" -font $Font(bold) 91 pack $w.cgnsoutput -side top -pady 2 -fill x 92 set wf [FrameGet $w.cgnsoutput] 93 94 set f [frame $wf.file] 95 pack $f -side top -fill x 96 label $f.lab -text Filename -width $labw -anchor w 97 pack $f.lab -side left 98 entry $f.ent -textvariable Tools(cgnsoutput) -width 30 99 pack $f.ent -side left -fill x -expand 1 100 button $f.but -text Browse -pady 0 -command "tools_browse $f.but cgnsoutput" 101 pack $f.but -side right -fill y 102 103 set f [frame $wf.basename] 104 pack $f -side top -fill x 105 label $f.lab -text "Base Name" -width $labw -anchor w 106 pack $f.lab -side left 107 entry $f.ent -textvariable Tools(basename) -width 30 108 pack $f.ent -side left -fill x -expand 1 109 checkbutton $f.but -text default \ 110 -variable Tools(basename,flag) -onvalue 1 -offvalue 0 \ 111 -command "tools_state basename $f.ent {}" 112 pack $f.but -side left 113 114 tools_state basename $f.ent "" 115 116 set f [frame $wf.solname] 117 pack $f -side top -fill x 118 label $f.lab -text "Solution Name" -width $labw -anchor w 119 pack $f.lab -side left 120 entry $f.ent -textvariable Tools(solname) -width 30 121 pack $f.ent -side left -fill x -expand 1 122 checkbutton $f.but -text default \ 123 -variable Tools(solname,flag) -onvalue 1 -offvalue 0 \ 124 -command "tools_state solname $f.ent {}" 125 pack $f.but -side left 126 127 tools_state solname $f.ent "" 128 129 tools_averaging $w 130 131 FrameCreate $w.treeopts -text "Octtree Options" -font $Font(bold) 132 pack $w.treeopts -side top -pady 2 -fill x 133 set treeopts [FrameGet $w.treeopts] 134 135 foreach opt {\ 136 {bboxpad "Bounding Box Padding" 0.01} \ 137 {maxdepth "Max Octtree Depth" 16} \ 138 {maxelem "Max Octtree Elements" 256}} { 139 set tag [lindex $opt 0] 140 set f [frame $treeopts.$tag] 141 pack $f -side top -anchor w 142 label $f.lab -text [lindex $opt 1] -width 20 -anchor w 143 entry $f.ent -textvariable Tools($tag) -width 15 144 checkbutton $f.but -text default \ 145 -variable Tools($tag,flag) -onvalue 1 -offvalue 0 \ 146 -command "tools_state $tag $f.ent [lindex $opt 2]" 147 pack $f.lab $f.ent $f.but -side left 148 tools_state $tag $f.ent [lindex $opt 2] 149 } 150 151 checkbutton $treeopts.extrap -text "Allow Extrapolation" \ 152 -variable Tools(extrapolate) -onvalue 1 -offvalue 0 153 pack $treeopts.extrap -side top -anchor w 154 155 if {![tools_interact $w check_interpolation]} return 156 157 foreach i {{c solbase} {b basenum} {B basename} {S solname} \ 158 {p bboxpad} {d maxdepth} {e maxelem}} { 159 set opt $Tools([lindex $i 1]) 160 if {$opt != ""} { 161 lappend cmd "-[lindex $i 0]$opt" 162 } 163 } 164 if {$Tools(weight) != ""} { 165 lappend cmd -w 166 } 167 if {$Tools(extrapolate)} { 168 lappend cmd -a 169 } 170 lappend cmd $Tools(cgnssol) $Tools(cgnsinput) 171 if {$Tools(cgnsoutput) != ""} { 172 lappend cmd $Tools(cgnsoutput) 173 } 174 175 tools_run "Solution Interpolation" $cmd $Tools(cgnsoutput) 176} 177 178proc check_interpolation {w} { 179 global Tools 180 if {$Tools(cgnssol) == "" || ![file exists $Tools(cgnssol)]} { 181 errormsg "CGNS solution file not specified or does not exist" $w 182 return 0 183 } 184 if {$Tools(cgnsinput) == "" || ![file exists $Tools(cgnsinput)]} { 185 errormsg "CGNS grid file not specified or does not exist" $w 186 return 0 187 } 188 if {$Tools(bboxpad) != "" && [catch {expr double($Tools(bboxpad))}]} { 189 errormsg "invalid value for bounding box padding" $w 190 return 0 191 } 192 if {$Tools(maxdepth) != "" && [catch {expr int($Tools(maxdepth))}]} { 193 errormsg "invalid value for max octtree depth" $w 194 return 0 195 } 196 if {$Tools(maxelem) != "" && [catch {expr int($Tools(maxelem))}]} { 197 errormsg "invalid value for max octtree elements" $w 198 return 0 199 } 200 return 1 201} 202 203proc extract_subset {w name exe} { 204 global ProgData Tools Font 205 206 if {$ProgData(file,name) == ""} return 207 set cmd [get_executable $exe 1] 208 if {$cmd == ""} return 209 210 set Tools(cgnsinput) $ProgData(file,name) 211 if {$Tools(cgnsoutput) == ""} { 212 set Tools(cgnsoutput) $ProgData(file,name) 213 } 214 215 toplevel $w 216 wm title $w "Extract Subset" 217 wm transient $w . 218 wm protocol $w WM_DELETE_WINDOW {set Tools(done) 0} 219 220 FrameCreate $w.loc -text Directions -font $Font(bold) 221 pack $w.loc -side top -pady 2 -fill x 222 set f [FrameGet $w.loc] 223 224 foreach n {i j k} { 225 checkbutton $f.$n -text "[string toupper $n]-subset" \ 226 -variable Tools(subset$n) -onvalue $n -offvalue "" 227 pack $f.$n -side left -expand 1 228 } 229 230 tools_cgnsinput $w 1 231 tools_cgnsoutput $w basename 232 tools_averaging $w 233 234 if {![tools_interact $w check_subset]} return 235 236 set opts $Tools(weight) 237 foreach i {i j k} { 238 if {$Tools(subset$i) != ""} { 239 append opts $Tools(subset$i) 240 } 241 } 242 lappend cmd -$opts 243 foreach i {basenum zonenum} { 244 if {$Tools($i) != ""} { 245 lappend cmd "-[string index $i 0]$Tools($i)" 246 } 247 } 248 if {$Tools(basename) != ""} { 249 lappend cmd "-B$Tools(basename)" 250 } 251 lappend cmd $Tools(cgnsinput) 252 if {$Tools(cgnsoutput) != ""} { 253 lappend cmd $Tools(cgnsoutput) 254 } 255 256 tools_run "Subset Extraction" $cmd $Tools(cgnsoutput) 257} 258 259proc check_subset {w} { 260 global Tools 261 foreach i {i j k} { 262 if {$Tools(subset$i) != ""} { 263 return [tools_check_input $w] 264 } 265 } 266 errormsg "no subset directions selected" $w 267 return 0 268} 269 270