-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDomAreaBlkVol.glf
306 lines (269 loc) · 11.2 KB
/
DomAreaBlkVol.glf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#############################################################################
#
# (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
#
# This sample script is not supported by Cadence Design Systems, Inc.
# It is provided freely for demonstration purposes only.
# SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE.
#
#############################################################################
package require PWI_Glyph 2
pw::Script loadTk
wm withdraw .
set BlockCount [llength [pw::Grid getAll -type pw::Block]]
set DomainCount [llength [pw::Grid getAll -type pw::Domain]]
if {0 == $DomainCount} {
tk_messageBox -icon error -title "No Grid Entities" -message \
"There are no suitable grid entities defined." -type ok
exit
}
set Selection {}
set MaxNameLength 0
set Mode 0
set Label(Total,0) "TOTAL AREA"
set Label(Total,1) "TOTAL VOLUME"
set Label(Entity,0) "Domain"
set Label(Entity,1) "Block"
set Label(Metric,0) "Area"
set Label(Metric,1) "Volume"
set Type(0) "Domains"
set Type(1) "Blocks"
############################################################################
# beginTable: start generating a rich-text (HTML) report table
############################################################################
proc beginTable {} {
global Selection Mode MaxNameLength Label Type
set MaxNameLength [string length $Label(Total,$Mode)]
foreach ent $Selection($Type($Mode)) {
set nlen [string length [$ent getName]]
if {$nlen > $MaxNameLength} {
set MaxNameLength $nlen
}
}
set table [format "\n%-${MaxNameLength}s %15s" $Label(Entity,$Mode) \
$Label(Metric,$Mode)]
set lines [format "%${MaxNameLength}.${MaxNameLength}s ---------------" \
"--------------------------------------------------"]
if {1 == $Mode} {
append lines " -----------"
append table " Orientation"
}
puts $table
puts $lines
}
############################################################################
# tableRow: add a report row
############################################################################
proc tableRow {name value} {
global MaxNameLength
set row [format "%-${MaxNameLength}s %15.6f" $name $value]
if {$value < 0.0} {
append row " LEFT-HANDED"
}
puts $row
}
############################################################################
# endTable: finish the report table and write it out
############################################################################
proc endTable {total} {
global Mode MaxNameLength Label
puts [format "%${MaxNameLength}.${MaxNameLength}s ---------------" \
"--------------------------------------------------"]
puts [format "%-${MaxNameLength}s %15.6f" $Label(Total,$Mode) $total]
}
############################################################################
# select: pick domains or blocks to calculate area or volume
############################################################################
proc select {} {
global Mode Selection
wm withdraw .
switch $Mode {
1 {
set mask [pw::Display createSelectionMask -requireBlock {Defined}]
set prompt "Select blocks for volume calculation"
set type Blocks
}
0 {
set mask [pw::Display createSelectionMask -requireDomain {Defined}]
set prompt "Select domains for area calculation"
set type Domains
}
}
pw::Display selectEntities -selectionmask $mask -description $prompt Selection
if {0 == [llength $Selection($type)]} {
wm deiconify .
} else {
report
exit
}
}
############################################################################
# report: generate the area/volume report for selected entities
############################################################################
proc report {} {
global Selection Mode
beginTable
set total 0.0
switch $Mode {
0 {
if { 0 < [llength $Selection(Domains)] } {
foreach dom $Selection(Domains) {
set exam [pw::Examine create DomainArea]
$exam addEntity $dom
$exam examine
set area 0.0
if [$dom isOfType pw::DomainUnstructured] {
set count [$dom getCellCount]
for { set i 1 } { $i <= $count } { incr i } {
set area [expr $area + [$exam getValue $dom $i]]
}
} else {
set dims [$dom getDimensions]
set imax [lindex $dims 0]
set jmax [lindex $dims 1]
for { set i 1 } { $i < $imax } { incr i } {
for { set j 1 } { $j < $jmax } { incr j } {
set area [expr $area + [$exam getValue $dom "$i $j"]]
}
}
}
tableRow [$dom getName] $area
set total [expr $total + $area]
$exam delete
}
}
}
1 {
if {0 < [llength $Selection(Blocks)]} {
foreach blk $Selection(Blocks) {
set exam [pw::Examine create BlockVolume]
$exam addEntity $blk
$exam examine
set volume 0.0
if [$blk isOfType pw::BlockExtruded] {
# unstructured: prism
set imax [[$blk getFace 1] getCellCount]
set kmax [lindex [$blk getDimensions] 2]
for { set i 1 } { $i <= $imax } { incr i } {
for { set k 1 } { $k < $kmax } { incr k } {
set volume [expr $volume + [$exam getValue $blk "$i 1 $k"]]
}
}
} elseif [$blk isOfType pw::BlockUnstructured] {
# unstructured: tetrahedra and pyramid
set imax [$blk getCellCount]
for { set i 1 } { $i <= $imax } { incr i } {
set volume [expr $volume + [$exam getValue $blk "$i 1 1"]]
}
} else {
# structured
set dims [$blk getDimensions]
set imax [lindex $dims 0]
set jmax [lindex $dims 1]
set kmax [lindex $dims 2]
for { set i 1 } { $i < $imax } { incr i } {
for { set j 1 } { $j < $jmax } { incr j } {
for { set k 1 } { $k < $kmax } { incr k } {
set volume [expr $volume + [$exam getValue $blk "$i $j $k"]]
}
}
}
}
tableRow [$blk getName] $volume
if {$volume > 0.0} {
set total [expr $total + $volume]
} else {
set total [expr $total - $volume]
}
$exam delete
}
}
}
}
endTable $total
}
############################################################################
# makeWindow: create the Tk interface
############################################################################
proc makeWindow {} {
global BlockCount
label .title -text "Calculate Domain Area/Block Volume" -width 35
set font [.title cget -font]
.title configure -font [font create -family [font actual $font -family] \
-weight bold]
pack .title -expand 1 -side top
frame .select -bd 1 -height 2 -relief sunken
radiobutton .select.r0 -text Domains -variable Mode -value 0
radiobutton .select.r1 -text Blocks -variable Mode -value 1
if {0 == $BlockCount} {
.select.r1 configure -state disabled
}
grid [label .select.l1] .select.r0 .select.r1 [label .select.l2]
grid columnconfigure .select "0 3" -weight 1
pack .select -fill x
frame .buttons
button .buttons.ok -text "Select" -command { select }
button .buttons.cancel -text "Cancel" -command { exit }
pack .buttons.ok .buttons.cancel -padx 2 -pady 1 -side right
pack .buttons -fill x -side bottom -pady 4
pack [label .buttons.logo -image [cadenceLogo] -bd 0 -relief flat] \
-side left -padx 5
bind . <KeyPress-Escape> { .buttons.cancel invoke }
bind . <Control-KeyPress-Return> { .buttons.ok invoke }
wm deiconify .
}
proc cadenceLogo {} {
set logoData "
R0lGODlhgAAYAPQfAI6MjDEtLlFOT8jHx7e2tv39/RYSE/Pz8+Tj46qoqHl3d+vq62ZjY/n4+NT
T0+gXJ/BhbN3d3fzk5vrJzR4aG3Fubz88PVxZWp2cnIOBgiIeH769vtjX2MLBwSMfIP///yH5BA
EAAB8AIf8LeG1wIGRhdGF4bXD/P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIe
nJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtdGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1w
dGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1Nzo
wMSAgICAgICAgIj48cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudy5vcmcvMTk5OS8wMi
8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmY6YWJvdXQ9IiIg/3htbG5zO
nhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0
cDovL25zLmFkb2JlLm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Sk7BghQAQMeqMmkY20amA+zHtDiEwl10dRiBcPoacJr0qjx7Ai+yTjQvk31aws92JZ
Q1070mGsSQsS1uYWiJeDrCkGy+CZvnjFEUME7VaFaQAcXCCDyyBYA3NQGIY8ssgU7vqAxjB4EwA
DEIyxggQAsjxDBzRagKtbGaBXclAMMvNNuBaiGAAA7"
return [image create photo -format GIF -data $logoData]
}
makeWindow
tkwait window .
#############################################################################
#
# This file is licensed under the Cadence Public License Version 1.0 (the
# "License"), a copy of which is found in the included file named "LICENSE",
# and is distributed "AS IS." TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE
# LAW, CADENCE DISCLAIMS ALL WARRANTIES AND IN NO EVENT SHALL BE LIABLE TO
# ANY PARTY FOR ANY DAMAGES ARISING OUT OF OR RELATING TO USE OF THIS FILE.
# Please see the License for the full text of applicable terms.
#
#############################################################################