forked from pointwise/GridCoordEnum
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpwio.glf
1921 lines (1752 loc) · 68.9 KB
/
pwio.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright 2013 (c) Pointwise, Inc.
# All rights reserved.
#
# This sample 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.
#
if { ![namespace exists pwio] } {
package require PWI_Glyph
#puts "pwio scriptdir='[file dirname [info script]]'"
namespace eval pwio {
#========================================================================
# utils namespace
#========================================================================
namespace eval utils {
proc assert { cond msg {exitVal -1} } {
if { ![expr $cond] } {
puts "assert failed: ($cond)"
puts "message : $msg"
if { 0 != $exitVal } {
exit $exitVal
}
}
}
proc entBaseType { ent {subTypeVarName ""} } {
if { "" != $subTypeVarName } {
upvar 1 $subTypeVarName subType
}
if { 0 == [regexp {\mpw::(Block|Domain|Connector|Node*)(Structured|Unstructured|Extruded)*} [$ent getType] -> baseType subType] } {
set baseType ""
set subType ""
} elseif { "" == $subType } {
set subType $baseType
}
return $baseType
}
proc getBlockFaces { blk } {
set faces [list]
for {set ii 1} {$ii <= [$blk getFaceCount]} {incr ii} {
lappend faces [$blk getFace $ii]
}
return $faces
}
proc getBlockDomains { blk } {
set doms [list]
foreach face [getBlockFaces $blk] {
set doms [concat $doms [getFaceDomains $face]]
}
return $doms
}
proc getFaceDomains { face } {
set doms [list]
for {set ii 1} {$ii <= [$face getDomainCount]} {incr ii} {
lappend doms [$face getDomain $ii]
}
return $doms
}
proc getFaceEdges { face } {
set edges [list]
for {set ii 1} {$ii <= [$face getEdgeCount]} {incr ii} {
lappend edges [$face getEdge $ii]
}
return $edges
}
proc getEdgeConnectors { edge } {
set cons [list]
for {set ii 1} {$ii <= [$edge getConnectorCount]} {incr ii} {
lappend cons [$edge getConnector $ii]
}
return $cons
}
proc getFaceEdgeConnectors { face } {
set cons [list]
foreach edge [getFaceEdges $face] {
set cons [concat $cons [getEdgeConnectors $edge]]
}
return $cons
}
proc getPerimeterPointCount { ent } {
set ret 0
switch -exact [$ent getType] {
pw::Node {
set ret 0
}
pw::Connector {
set ret 2
}
pw::DomainUnstructured {
set ret [$ent getPerimeterPointCount]
}
pw::DomainStructured {
lassign [$ent getDimensions] i j
set ret [expr {($i * 2) + ($j * 2) - 4}]
}
pw::FaceUnstructured {
foreach edge [getFaceEdges $ent] {
incr ret [expr {[$edge getPointCount] - 1}]
}
}
pw::FaceStructured {
lassign [$ent getDimensions] i j
set ret [expr {($i * 2) + ($j * 2) - 4}]
}
pw::BlockExtruded {
lassign [$ent getDimensions] numBasePts one numExtrudePts
set ret [expr {($numBasePts * 2) + (($numExtrudePts - 2) * \
[getPerimeterPointCount [$ent getFace JMinimum]])}]
}
pw::BlockUnstructured {
if { [getSupportEnts $ent supEnts] } {
foreach supEnt $supEnts {
incr ret [getOwnedPointCount $supEnt]
}
}
}
pw::BlockStructured {
lassign [$ent getDimensions] i j k
set ret [expr {(($i * $j) + ($i * ($k - 2)) + (($j - 2) * ($k - 2))) * 2}]
}
default {
assert 0 "getPerimeterPointCount: Bad Entity '[$ent getType]'"
} }
return $ret
}
proc getOwnedPointCount { ent } {
set ret 0
switch -exact [$ent getType] {
pw::Node {
set ret 1
}
pw::Connector {
set ret [expr {[$ent getPointCount] - 2}]
}
pw::DomainUnstructured {
set ret [expr {[$ent getPointCount] - [$ent getPerimeterPointCount]}]
}
pw::DomainStructured {
lassign [$ent getDimensions] i j
set ret [expr {($i - 2) * ($j - 2)}]
}
pw::BlockUnstructured {
set ret [expr {[$ent getPointCount] - [getPerimeterPointCount $ent]}]
}
pw::BlockStructured {
lassign [$ent getDimensions] i j k
set ret [expr {($i - 2) * ($j - 2) * ($k - 2)}]
}
pw::BlockExtruded {
set ret [expr {[$ent getPointCount] - [getPerimeterPointCount $ent]}]
}
}
return $ret
}
proc isBndryEnt { ent allEnts } {
# getRegisterBoundaryConditions returns a list of {{register} parentEntity} lists
# { {::pw::BlockStructured_2 ::pw::DomainStructured_283 Opposite} ::pw::BoundaryCondition_46 }
# { {::pw::BlockStructured_3 ::pw::DomainStructured_283 Same} ::pw::BoundaryCondition_46 }
set regBCs [$ent getRegisterBoundaryConditions]
set numParents [llength $regBCs]
if {1 == $numParents} {
return true ;# hard bndry ents have only one parent
} elseif { $numParents > 2 } {
# non-manifold topology!
assert 0 "$ent $numParents has NONMANIFOLD CONNECTIVITY!"
}
# ent has 2 parents and is a cnxn UNLESS BC is applied
set ret false ;# assume cnxn
foreach regBC $regBCs {
lassign $regBC reg bc
lassign $reg parentEnt cnxnEnt orient
if { -1 == [lsearch -exact $allEnts $parentEnt] } {
# reg parent ent is not part of the export. ent is a bndry
set ret true
break
}
set bcName [$bc getName]
if { $bcName != "Unspecified" } {
# cnxn ent has BCs assigned it is a bndry
set ret true
#break
}
}
return $ret
}
proc getNodeDbEnt { node dbEntVarName } {
upvar 1 $dbEntVarName dbEnt
set dbEnt [lindex [$node getPoint] 2]
if { "::pw::" != [string range $dbEnt 0 5] } {
set dbEnt ""
}
return [expr {0 != [string length $dbEnt]}]
}
proc entLockInterior { ent } {
switch -exact [$ent getType] {
pw::Node -
pw::Connector -
pw::DomainUnstructured -
pw::DomainStructured -
pw::BlockUnstructured -
pw::BlockExtruded {
# do nothing
}
pw::BlockStructured {
while { [$ent getInteriorState] == "Locked" } {
$ent unlockInterior
}
$ent lockInterior
}
}
}
proc entUnlockInterior { ent {clearAllLocks 0} } {
switch -exact [$ent getType] {
pw::Node -
pw::Connector -
pw::DomainUnstructured -
pw::DomainStructured -
pw::BlockUnstructured -
pw::BlockExtruded {
# do nothing
}
pw::BlockStructured {
$ent unlockInterior
while { $clearAllLocks && [$ent getInteriorState] == "Locked" } {
$ent unlockInterior
}
}
}
}
proc entGetName { ent } {
set baseType [entBaseType $ent]
switch -exact $baseType {
Block -
Domain -
Connector {
set name [$ent getName]
}
Node {
# ::pw::Node_195
set name [string range $ent 6 end]
} }
return $name
}
proc entGetDimensions { ent } {
switch -exact [entBaseType $ent] {
Block { set dim [$ent getDimensions] }
Domain { set dim [$ent getDimensions] ; lappend dim 1 }
Connector { set dim [list [$ent getDimension] 1 1] }
Node { set dim [list 1 1 1] }
default { assert false "Invalid Ent Type ([entBaseType $ent])" }
}
return $dim ;# returns {i j k}
}
proc entIjkToIndex { ent ijk } {
set ret 0
set baseType [entBaseType $ent subType]
switch -exact $subType {
Node -
Connector -
Unstructured {
set ret [lindex $ijk 0] ;# grab the i
}
Structured -
Extruded {
if { "Domain" == $baseType } {
set ijk [lrange $ijk 0 1] ;# convert to ij
}
set ret [$ent getLinearIndex $ijk]
}
default {
assert false "bad subType '$subType'"
}
}
return $ret
}
proc ijkToIndexStructured { ijk ijkdim } {
lappend ijk 1 1 ;# handle an i or ij value
lassign $ijk i j k
lappend ijkdim 0 0 ;# handle an i or ij dim value
lassign $ijkdim idim jdim kdim
# ijk are 1-based. Do not subtract from $i to return a 1-based index
return [expr {($k - 1) * ($idim * $jdim) + ($j - 1) * $idim + $i}]
}
proc indexToIjkStructured { ndx ijkdim } { ;# ndx must be 1-based
lappend ijkdim 1 ;# add a null kdim to pad an ij-only value
lassign $ijkdim idim jdim kdim
assert "$ndx > 0 && $ndx <= ($idim * $jdim * $kdim)" \
"indexToIjkStructured: Invalid ndx ($ndx)"
incr ndx -1 ;# convert to 0-based index
if { $kdim != 0 } { ;# ijk
set k [expr {$ndx / ($idim * $jdim)}]
incr ndx [expr {-$k * $idim * $jdim}]
} else { ;# ij
set k 0
}
set j [expr {$ndx / $idim}]
incr ndx [expr {-$j * $idim + 1}] ;# +1 makes ndx 1-based
return [list $ndx [incr j] [incr k]] ;# return 1-based ijk's
}
proc entIndexToIjk { ent entNdx1 } { ;# entNdx1 must be 1-based
assert "$entNdx1 >= 1 && $entNdx1 <= [$ent getPointCount]" \
"entIndexToIjk: Bad Index $entNdx1 for $ent"
set ret 0
set baseType [entBaseType $ent subType]
switch -exact $subType {
Node -
Connector -
Unstructured {
set ret [list $entNdx1 1 1]
}
Structured -
Extruded {
set ret [indexToIjkStructured $entNdx1 [$ent getDimensions]]
}
default {
assert false "bad subType '$subType'"
}
}
return $ret
}
proc makeCoord { ent ijk } { ;# 1-based ijk
return [lappend ijk $ent]
}
proc makeCoordFromIjkVals { ent i j k } { ;# 1-based i j k
return [makeCoord $ent [list $i $j $k]]
}
proc makeCoordFromEntIndex { ent ndx } { ;# 1-based ndx relative to ent's pt space
return [makeCoord $ent [entIndexToIjk $ent $ndx]]
}
proc sortEntsByType { ents } {
proc compareBaseTypes {type1 type2} {
array set rank {Block 0 Domain 1 Connector 2 Node 3}
return [expr {$rank([entBaseType $type1]) - $rank([entBaseType $type2])}]
}
# sort ents in Block/Domain/Connector/Node order
return [lsort -command compareBaseTypes $ents]
}
proc pointToString { pt } {
# pt == {u v ::pw::Surface_1} or {x y z}
lassign $pt xu yv zdb
set prec "%8.5f"
if { [string equal -length 6 "::pw::" $zdb] } {
set fmt "%s"
} else {
set fmt $prec
}
return [format "\{$prec $prec $fmt\}" $xu $yv $zdb]
}
proc xyzEqual { xyz1 xyz2 {tol 1.0e-8} } {
lassign $xyz1 x1 y1 z1
lassign $xyz2 x2 y2 z2
return [expr {[valEqual $x1 $x2 $tol] && [valEqual $y1 $y2 $tol] && [valEqual $z1 $z2 $tol]}]
}
proc valEqual { val1 val2 {tol 1.0e-8} } {
return [expr {abs($val1 - $val2) < $tol}]
}
proc coordToPtString { coord } {
# pt == {u v ::pw::Surface_1} or {x y z}
set pt [pw::Grid getPoint $coord]
set ret [pointToString $pt]
if { -1 != [string first "::pw::" $ret] } {
set xyz [pw::Grid getXYZ $coord]
set ret "[pointToString $xyz] @ $ret"
}
return $ret
}
proc vcToString { vc } {
set vcName [$vc getName]
if {$vcName == "Unspecified" } {
return $vcName
}
return "$vcName [$vc getId] [$vc getPhysicalType]"
}
proc labelPt { ndx pt } {
lassign $pt x y z
set noteHt 0.04
set note [pw::Note create]
$note setText "$ndx"
$note setPosition [list $x $y $z]
$note setSize $noteHt
$note setColor 0x0000FF00
$note setRenderAttribute ColorMode Entity
}
proc printEntInfo { title ents {dim 0} {allEnts {}} } {
proc compareBaseTypes {type1 type2} {
array set rank {Block 0 Domain 1 Connector 2 Node 3}
return [expr {$rank([entBaseType $type1]) - $rank([entBaseType $type2])}]
}
# sort ents in Block/Domain/Connector/Node order
set ents [lsort -command compareBaseTypes $ents]
set fmt "| %-30.30s | %-20.20s | %10.10s | %6.6s | %-13.13s | %-10.10s | %-5.5s |"
puts "$title"
puts [format $fmt "Entity" "Name" "NumPts" "DbPts" "Dim" "BaseType" "BorC"]
set tmp [string repeat "-" 50]
puts [format $fmt $tmp $tmp $tmp $tmp $tmp $tmp $tmp]
foreach ent $ents {
array set eInfo [list Name "[entGetName $ent]" NumPts "" DbPts "" Dim "" Bndry ""]
set baseType [entBaseType $ent]
switch -exact $baseType {
Block -
Domain {
#set eInfo(Name) [$ent getName]
set eInfo(NumPts) [$ent getPointCount -constrained eInfo(DbPts)]
set eInfo(Dim) [$ent getDimensions]
if { $baseType == "Domain" && $dim == 3 } {
if { [isBndryEnt $ent $allEnts] } {
set eInfo(Bndry) "Bndry"
} else {
set eInfo(Bndry) "Cnxn"
}
}
}
Connector {
#set eInfo(Name) [$ent getName]
set eInfo(NumPts) [$ent getPointCount -constrained eInfo(DbPts)]
set eInfo(Dim) [$ent getDimension]
if { $dim == 2 } {
if { [isBndryEnt $ent $allEnts] } {
set eInfo(Bndry) "Bndry"
} else {
set eInfo(Bndry) "Cnxn"
}
}
}
Node {
#set eInfo(Name) ""
set eInfo(NumPts) 1
set eInfo(DbPts) [getNodeDbEnt $ent ignore]
set eInfo(Dim) 1
} }
if { $eInfo(DbPts) == 0 } {
set eInfo(DbPts) ""
}
puts [format $fmt $ent $eInfo(Name) $eInfo(NumPts) $eInfo(DbPts) $eInfo(Dim) $baseType $eInfo(Bndry)]
}
}
proc getSelection { selType selectedVarName errMsgVarName } {
upvar 1 $selectedVarName selected
upvar 1 $errMsgVarName errMsg
array set validSelTypes { \
Connector 0 \
Domain 1 \
Block 2 \
Database 3 \
Spacing 4 \
Boundary 5 \
}
array set typeFilters { \
Connector {Dimensioned} \
Domain {Defined} \
Block {Defined} \
Database {Models Quilts} \
Spacing {Begin End} \
DatabaseBoundary {} \
}
set ret 0
set selected {}
set allEnts [pw::Grid getAll -type "pw::$selType"]
set gridCnt 0
foreach ent $allEnts {
if { [$ent getEnabled] && [pw::Display isLayerVisible [$ent getLayer]] } {
incr gridCnt
lappend selected $ent
}
}
if { "" == [array get validSelTypes $selType] } {
set errMsg "Invalid Selection Type '$selType'"
} elseif { 0 == $gridCnt } {
set errMsg "No appropriate $selType entities are available for selection!"
} elseif { 1 == $gridCnt } {
# force selection of only $selType ent available
set ret 1
} else {
set filter $typeFilters($selType)
# set selection based on current 2D/3D setting
set mask [pw::Display createSelectionMask -require$selType $filter]
if { [pw::Display selectEntities \
-description "Select $selType\s" \
-selectionmask $mask \
picks] } {
set selected $picks($selType\s)
set ret 1
} else {
set errMsg "$selType selection aborted!"
}
}
return $ret
}
# returns true/false
# support ents placed in supEntsVarName
# if addEnts is true, ents will also be added to supEntsVarName
proc getSupportEnts { ents supEntsVarName {addEnts false}} {
upvar 1 $supEntsVarName supEnts
set supEnts [list]
array set unique {} ;# empty array - used to track unique ent names
foreach ent $ents {
if { "" == [set base [entBaseType $ent]] } {
continue ; # BAD!
}
set funcName "getSupportEnts_Private::push$base\AndSupportEnts"
$funcName $ent unique $addEnts
}
# extract the list of unique entity names
set supEnts [array names unique]
return [expr {0 != [llength $supEnts]}]
}
namespace eval getSupportEnts_Private {
proc pushBlockAndSupportEnts { blk uniqueVarName {addBlk true}} {
upvar 1 $uniqueVarName unique
if { "" == [array names unique -exact $blk] } {
if { $addBlk } {
set unique($blk) 1 ;# add to array
}
set faceCnt [$blk getFaceCount]
for {set ii 1} {$ii <= $faceCnt} {incr ii} {
set face [$blk getFace $ii]
set domCnt [$face getDomainCount]
for {set jj 1} {$jj <= $domCnt} {incr jj} {
pushDomainAndSupportEnts [$face getDomain $jj] unique
}
}
}
}
proc pushDomainAndSupportEnts { dom uniqueVarName {addDom true}} {
upvar 1 $uniqueVarName unique
if { "" == [array names unique -exact $dom] } {
if { $addDom } {
set unique($dom) 1 ;# add to array
}
set edgeCnt [$dom getEdgeCount]
for {set ii 1} {$ii <= $edgeCnt} {incr ii} {
set edge [$dom getEdge $ii]
set conCnt [$edge getConnectorCount]
for {set jj 1} {$jj <= $conCnt} {incr jj} {
pushConnectorAndSupportEnts [$edge getConnector $jj] unique
}
}
}
}
proc pushConnectorAndSupportEnts { con uniqueVarName } {
upvar 1 $uniqueVarName unique
# if con is not in array, process it
if { "" == [array names unique -exact $con] } {
set unique($con) 1 ;# add to array
pushNodeAndSupportEnts [$con getNode Begin] unique
pushNodeAndSupportEnts [$con getNode End] unique
}
}
proc pushNodeAndSupportEnts { node uniqueVarName } {
upvar 1 $uniqueVarName unique
# if node is not in array, process it
if { "" == [array names unique -exact $node] } {
set unique($node) 1 ;# add to array
# nodes do NOT have support ents - all done!
}
}
} ;# namespace eval getSupportEnts_Private
}
#========================================================================
# cell namespace
#========================================================================
namespace eval cell {
# key = "dim,numCellPts"
# val = "edge1p1 edge1p2 edge2p1 edge2p2 ... edgeNp1 edgeNp2"
variable edgeMap ; array set edgeMap {
"2e3" { 0 1 1 2 2 0 } ;# tri
"2e4" { 0 1 1 2 2 3 3 0 } ;# quad
"3e4" { 0 1 1 2 2 0 0 3 1 3 2 3 } ;# tet
"3e5" { 0 1 1 2 2 3 3 0 0 4 1 4 2 4 3 4 } ;# pyramid
"3e6" { 0 1 1 2 2 0 3 4 4 5 5 3 0 3 1 4 2 5 } ;# prism
"3e8" { 0 1 1 2 2 3 3 0 4 5 5 6 6 7 7 4 0 4 1 5 2 6 3 7 } ;# hex
}
# key = "dim,numCellPts"
# val = "{face1} {face2} ... {faceN}"
variable faceMap ; array set faceMap {
"2f3" { {0 1} {1 2} {2 0} } ;# tri
"2f4" { {0 1} {1 2} {2 3} {3 0} } ;# quad
"3f4" { {0 1 2} {0 3 1} {1 3 2} {2 3 0} } ;# tet
"3f5" { {0 1 2 3} {0 4 1} {1 4 2} {2 4 3} {3 4 0} } ;# pyramid
"3f6" { {0 1 2} {3 5 4} {0 3 4 1} {1 4 5 2} {2 5 3 0} } ;# prism
"3f8" { {0 1 2 3} {4 7 6 5} {0 4 5 1} {1 5 6 2} {2 6 7 3} {3 7 4 0} } ;# hex
}
proc getEdges { cell {minFirstOrder 0} {revVarName ""} } {
if { "" != $revVarName } {
upvar 1 $revVarName rev
}
set key "$pwio::caeDim\e[llength $cell]"
variable edgeMap
pwio::utils::assert "\"\" != \"[array names edgeMap $key]\"" "Invalid cell edgeMap key: '$key'"
set ret [list]
set rev [list]
set map $edgeMap($key)
foreach {i1 i2} $map {
set v1 [lindex $cell $i1]
set v2 [lindex $cell $i2]
if { $minFirstOrder && ($v2 < $v1) } {
lappend ret [list $v2 $v1]
lappend rev 1
} else {
lappend ret [list $v1 $v2]
lappend rev 0
}
}
return $ret
}
proc getFaceEdges { face {minFirstOrder 0} {revVarName ""} } {
if { "" != $revVarName } {
upvar 1 $revVarName rev
}
set key "2\e[llength $face]"
variable edgeMap
pwio::utils::assert "\"\" != \"[array names edgeMap $key]\"" "Invalid cell edgeMap key: '$key'"
set ret [list]
set rev [list]
set map $edgeMap($key)
foreach {i1 i2} $map {
set v1 [lindex $face $i1]
set v2 [lindex $face $i2]
if { $minFirstOrder && ($v2 < $v1) } {
lappend ret [list $v2 $v1]
lappend rev 1
} else {
lappend ret [list $v1 $v2]
lappend rev 0
}
}
return $ret
}
proc getFaces { cell {minFirstOrder 0} } {
variable faceMap
set f f
set key "$pwio::caeDim$f[llength $cell]"
pwio::utils::assert "\"\" != \"[array names faceMap $key]\"" "Invalid cell faceMap key: '$key'"
set ret [list]
set map $faceMap($key)
foreach faceIndices $map { ;# faceIndices is a list of cell local indices
set face [list]
foreach ndx $faceIndices {
lappend face [lindex $cell $ndx]
}
if {$minFirstOrder} {
set minIdx 0
set minVal [lindex $face $minIdx]
for {set j 1} {$j < [llength $face]} {incr j} {
if {[set val [lindex $face $j]] < $minVal} {
set minVal $val
set minIdx $j
}
}
if {$minIdx > 0} {
set minFirstFace [concat [lrange $face $minIdx end] \
[lrange $face 0 [expr {$minIdx - 1}]]]
} else {
set minFirstFace $face
}
lappend ret $minFirstFace
} else {
lappend ret $face
}
}
return $ret
}
}
#========================================================================
# pwio variables
#========================================================================
# misc variables
variable selEnts [list]
variable caeDim [pw::Application getCAESolverDimension]
variable perimPtCountCache ;# maps an ent to its num of perim points
array set perimPtCountCache {}
# coords db variables
variable coordSingleEnt ""
variable entToCoordTotalsOffset ; array set entToCoordTotalsOffset {} ;# maps an ent to its offset into coordTotals list
variable coordTotals [list] ;# list of {entOwnedPts totalOwnedPts ent} lists
variable totalOwnedPts 0
variable ndxCoordTotals 0 ;# cached index into coordTotals list
variable offsetGlobToLocalGetCoord 0 ;# cached global to owned index offset: globNdx = ownedNdx + offsetGlobToLocalGetCoord
variable prevCoordEntName "@null" ;# cached name of previous coord entity enumerated
variable offsetGlobToLocalGetCoordIndex 0 ;# cached global to owned index offset: globNdx = ownedNdx + offsetGlobToLocalGetCoordIndex
# cells db variables
variable cellSingleEnt ""
variable totalCellCount 0
variable cellTotals [list] ;# list of {entCellCount totalEntCellCount ent} lists
variable entToCellTotalsOffset ;# maps an ent to its offset into cellTotals list
array set entToCellTotalsOffset {}
variable ndxCellTotals 0 ;# cached index into cellTotals list
variable offsetGlobToLocalGetCell 0 ;# cached global to cell index offset: globCellNdx = entCellNdx + offsetGlobToLocalGetCell
variable prevCellEntName "@null" ;# cached name of previous cell entity enumerated
variable offsetGlobToLocalGetCellIndex 0 ;# cached global to cell index offset: globNdx = cellNdx + offsetGlobToLocalGetCellIndex
#public
#========================================================================
namespace export beginIO
proc beginIO { ents } {
variable selEnts
reset
set selEnts $ents
build
foreach ent $selEnts {
utils::entLockInterior $ent
}
}
#========================================================================
namespace export endIO
proc endIO { {clearAllLocks 0} } {
variable selEnts
foreach ent $selEnts {
utils::entUnlockInterior $ent $clearAllLocks
}
}
#========================================================================
namespace export getCoordCount
proc getCoordCount {} {
variable totalOwnedPts
return $totalOwnedPts
}
#========================================================================
namespace export getCoord
proc getCoord { enumNdx } { ;# 1-based index
variable coordSingleEnt
variable entToCoordTotalsOffset
variable coordTotals
variable totalOwnedPts
variable ndxCoordTotals
variable offsetGlobToLocalGetCoord
utils::assert "$enumNdx >=1 && $enumNdx <= $totalOwnedPts" \
"Invalid global index in pwio::getCoord($enumNdx)"
set ret {} ;# GgGridCoord
if { "" != $coordSingleEnt } {
return [utils::makeCoordFromEntIndex $coordSingleEnt $enumNdx]
}
incr enumNdx -1 ;# convert to 0-based index
# indexes will typically be looped over from 0 to NumPts, so we cache
# the ndxCoordTotals index into the coordTotals list and offsetGlobToLocalGetCoord
if { $enumNdx == [lindex $coordTotals $ndxCoordTotals 1] } {
# moving to the next position in the coordTotals array
set offsetGlobToLocalGetCoord [lindex $coordTotals $ndxCoordTotals 1]
incr ndxCoordTotals
} elseif { $enumNdx < $offsetGlobToLocalGetCoord || $enumNdx >= [lindex $coordTotals $ndxCoordTotals 1] } {
# not in the cached range, so do a binary search to find the correct range
set lo 0
set hi [llength $coordTotals]
while { $lo < $hi } {
set mid [expr {($lo + $hi) / 2}]
if { [lindex $coordTotals $mid 1] <= $enumNdx } {
set lo [incr mid];
} else {
set hi $mid
}
}
set ndxCoordTotals $lo
if { $ndxCoordTotals == 0 } {
set offsetGlobToLocalGetCoord 0
} else {
set offsetGlobToLocalGetCoord [lindex $coordTotals [incr lo -1] 1]
}
}
incr enumNdx ;# convert back to 1-based index
set ent [lindex $coordTotals $ndxCoordTotals 2]
set ownedNdx [expr {$enumNdx - $offsetGlobToLocalGetCoord}]
set entIjk [entOwnedIndexToIjk $ent $ownedNdx]
return [utils::makeCoord $ent $entIjk]
}
#========================================================================
namespace export getCoordIndex
proc getCoordIndex { coord {mapCoordToOwner 1} } {
variable coordSingleEnt
variable entToCoordTotalsOffset
variable coordTotals
variable prevCoordEntName
variable offsetGlobToLocalGetCoordIndex
if { "" != $coordSingleEnt } {
if { $coordSingleEnt == [coordGetEntity $coord] } {
return [utils::entIjkToIndex $coordSingleEnt [coordGetIjk $coord]]
} elseif { [coordMapToEntity $coord $coordSingleEnt coords] > 0 } {
return [utils::entIjkToIndex $coordSingleEnt [coordGetIjk [lindex $coords 0]]]
} else {
utils::assert false "pwio::getCoordIndex: Could not map coord ($coord) to coordSingleEnt"
}
}
if { $mapCoordToOwner } {
set ownerCoord [mapToOwner $coord]
set ent [coordGetEntity $ownerCoord]
set ijk [coordGetIjk $ownerCoord]
} else {
set ent [coordGetEntity $coord]
set ijk [coordGetIjk $coord]
}
if { $ent != $prevCoordEntName } {
set match [array get entToCoordTotalsOffset $ent]
if { 2 != [llength $match] } {
utils::assert false "pwio::getCoordIndex: Entity not found ($ent) '$match'"
}
# match is {ent offset} list
lassign $match -> totalsOffset
set prevCoordEntName $ent
set offsetGlobToLocalGetCoordIndex [lindex $coordTotals [expr {$totalsOffset - 1}] 1]
}
set ret [entIjkToOwnedIndex $ent $ijk]
if { $offsetGlobToLocalGetCoordIndex > 0 } {
# owned indices after the first range must be offset to the enum's
# index space
incr ret $offsetGlobToLocalGetCoordIndex
}
return $ret
}
#========================================================================
namespace export getCellCount
proc getCellCount {} {
variable totalCellCount
return $totalCellCount
}
#========================================================================
namespace export getCell
proc getCell { enumNdx {vcVarName ""} } { ;# 1-based index
if { "" != $vcVarName } {
upvar 1 $vcVarName vc
}
variable cellSingleEnt
variable entToCellTotalsOffset
variable cellTotals
variable totalCellCount
variable ndxCellTotals
variable offsetGlobToLocalGetCell
utils::assert "$enumNdx >=1 && $enumNdx <= $totalCellCount" \
"Invalid global index in pwio::getCell($enumNdx)"
set ret [list] ;# cell indices
if { "" != $cellSingleEnt } {
set vc [$cellSingleEnt getVolumeCondition]
return [getEntityCell $cellSingleEnt $enumNdx]
}
incr enumNdx -1 ;# convert to 0-based index
# indexes will typically be looped over from 0 to NumCells, so we cache
# the prior index into the cellTotals list (ndxCellTotals) and the prior
# index offset (offsetGlobToLocalGetCell)
if { $enumNdx == [lindex $cellTotals $ndxCellTotals 1] } {
# move to the next position in the cellTotals array
set offsetGlobToLocalGetCell [lindex $cellTotals $ndxCellTotals 1]
incr ndxCellTotals
#puts "ndx=$enumNdx next block \$offsetGlobToLocalGetCell=$offsetGlobToLocalGetCell \$ndxCellTotals=$ndxCellTotals"
} elseif { $enumNdx < $offsetGlobToLocalGetCell || $enumNdx >= [lindex $cellTotals $ndxCellTotals 1] } {
# not in the cached range, so do a binary search to find the correct range
set lo 0
set hi [llength $cellTotals]
while { $lo < $hi } {
set mid [expr {($lo + $hi) / 2}]
if { [lindex $cellTotals $mid 1] <= $enumNdx } {
set lo [incr mid];
} else {
set hi $mid
}
}
set ndxCellTotals $lo
if { $ndxCellTotals == 0 } {
set offsetGlobToLocalGetCell 0
} else {
set offsetGlobToLocalGetCell [lindex $cellTotals [incr lo -1] 1]
}
#puts "ndx=$enumNdx find block \$offsetGlobToLocalGetCell=$offsetGlobToLocalGetCell \$ndxCellTotals=$ndxCellTotals"
} else {
#puts "ndx=$enumNdx using block \$offsetGlobToLocalGetCell=$offsetGlobToLocalGetCell \$ndxCellTotals=$ndxCellTotals"
}
set vc [[set ent [lindex $cellTotals $ndxCellTotals 2]] getVolumeCondition]
# +1 converts enumNdx back to 1-based index
# return [getEntityCell ent entNdx]
return [getEntityCell $ent [expr {$enumNdx + 1 - $offsetGlobToLocalGetCell}]]
}
#========================================================================
namespace export getCellIndex
proc getCellIndex { ent entNdx } { ;# 1-based index into ent's cell space
variable cellSingleEnt
variable entToCellTotalsOffset
variable cellTotals
variable prevCellEntName
variable offsetGlobToLocalGetCellIndex
if { "" != $cellSingleEnt } {
if { $cellSingleEnt == $ent } {
return $entNdx
} else {
utils::assert false "pwio::getCellIndex: Invalid entity ($ent)"
}
}
if { $ent != $prevCellEntName } {
set match [array get entToCellTotalsOffset $ent]
if { 2 != [llength $match] } {
utils::assert false "pwio::getCellIndex: Entity not found ($ent) '$match'"
}
# match is {ent offset} list
lassign $match -> totalsOffset
set prevCellEntName $ent
set offsetGlobToLocalGetCellIndex [lindex $cellTotals [expr {$totalsOffset - 1}] 1]
}
if { $offsetGlobToLocalGetCellIndex > 0 } {
# cell indices after the first range must be offset to the enum's
# index space
incr entNdx $offsetGlobToLocalGetCellIndex
}
return $entNdx
}
#========================================================================
namespace export getCellEdges
proc getCellEdges { enumNdx {cellVarName ""} {minFirstOrder 0} {revVarName ""} } {
if { "" != $cellVarName } {
upvar 1 $cellVarName cell
}
if { "" != $revVarName } {