-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgridRefine.glf
More file actions
1009 lines (851 loc) · 29.7 KB
/
gridRefine.glf
File metadata and controls
1009 lines (851 loc) · 29.7 KB
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
#############################################################################
#
# (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
#
# This 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.
#
#############################################################################
# ==========================================================================
# GRID REFINEMENT SCRIPT - POINTWISE
# ==========================================================================
# Written by Travis Carrigan & Claudio Pita
#
#
# --------------------------------------------------------------------------
# User Defined Parameters
# --------------------------------------------------------------------------
# Refinement factor
set refinementFactor 2
# Pointwise file name, please include .pw file extension
set pwFile "TestGrid.pw"
# Whether to create volume mesh, YES or NO
set volMesh "YES"
# --------------------------------------------------------------------------
# Load Pointwise Glyph package
package require PWI_Glyph
# --------------------------------------------------------------------------
# Unstructure solver attribute names
set unsSolverAttsNames { BoundaryDecay EdgeMaximumLength EdgeMinimumLength \
PyramidMaximumHeight PyramidMinimumHeight PyramidAspectRatio \
InitialMemorySize IterationCount TRexMaximumLayers TRexFullLayers \
TRexGrowthRate TRexPushAttributes TRexSpacingSmoothing \
TRexSpacingRelaxationFactor TRexIsotropicSeedLayers TRexCollisionBuffer \
TRexAnisotropicIsotropicBlend TRexSkewCriteriaDelayLayers \
TRexSkewCriteriaMaximumAngle TRexSkewCriteriaEquivolume \
TRexSkewCriteriaEquiangle TRexSkewCriteriaCentroid \
TRexCheckCombinedElementQuality TRexVolumeFunction TetMesher }
# --------------------------------------------------------------------------
# Remove element from list
proc removeFromList { list values } {
foreach val $values {
set idx [lsearch $list $val]
set list [lreplace $list $idx $idx]
}
return $list
}
# --------------------------------------------------------------------------
# Compare lists
proc compareLists { a b } {
set la [llength $a]
set lb [llength $b]
if {$la != $lb} {
return 0
} else {
set i 0
foreach ae $a be $b {
if {![string equal $ae $be]} {
return 0
}
incr i
}
}
return 1
}
# --------------------------------------------------------------------------
# Get connectors used by a domain
proc getConnectors { domain } {
set conns [list]
set edgeCount [$domain getEdgeCount]
for {set i 1} {$i <= $edgeCount} {incr i} {
set edge [$domain getEdge $i]
set connectorCount [$edge getConnectorCount]
for {set j 1} {$j <= $connectorCount} {incr j} {
lappend conns [$edge getConnector $j]
}
}
return $conns
}
# --------------------------------------------------------------------------
# Get domains used by a block
proc getDomains { block } {
set doms [list]
set faceCount [$block getFaceCount]
for {set i 1} {$i <= $faceCount} {incr i} {
set face [$block getFace $i]
set domainCount [$face getDomainCount]
for {set j 1} {$j <= $domainCount} {incr j} {
lappend doms [$face getDomain $j]
}
}
return $doms
}
# --------------------------------------------------------------------------
# Get boundary conditions
proc getBoundaryConditions {} {
global boundaryConditions
# Get list of boundary condition names
set condsNames [pw::BoundaryCondition getNames]
# Loop through all the condition names
foreach name $condsNames {
# Getcondition object from its name
set condition [pw::BoundaryCondition getByName $name]
# If condition exist, cache it
if { $condition ne "" && [$condition getPhysicalType] ne "Unspecified"} {
set boundaryConditions($name) $condition
}
}
}
# --------------------------------------------------------------------------
# Get and redimension TRex conditions
proc getAndRedimensionTRexConditions {} {
global refinementFactor
global trexConditions
# Get list of TRex condition names
set condsNames [pw::TRexCondition getNames]
# Loop through all the condition names
foreach name $condsNames {
# Get condition object from its name
set condition [pw::TRexCondition getByName $name]
# If condition exist, adjust spacing (if necessary) and cache it
if { $condition ne "" && [$condition getConditionType] ne "Off" } {
if { [$condition getConditionType] eq "Wall" } {
# Get spacing
set spc [$condition getSpacing]
# Refine spacing
set newSpc [expr (1.0 / $refinementFactor) * $spc]
# Set new spacing
$condition setSpacing $newSpc
}
# Cache it
set trexConditions($name) $condition
}
}
}
# --------------------------------------------------------------------------
# Get volume conditions
proc getVolumeConditions {} {
global volumeConditions
# Get list of volume condition names
set condsNames [pw::VolumeCondition getNames]
# Loop through all the condition names
foreach name $condsNames {
# Get condition object from its name
set condition [pw::VolumeCondition getByName $name]
# If condition exist, cache it
if { $condition ne "" && [$condition getPhysicalType] ne "Unspecified"} {
set volumeConditions($name) $condition
}
}
}
# --------------------------------------------------------------------------
# Get and redimension unstructured solver attributes for the block
proc getAndRedimensionUnstructuredSolverAttributes { blk } {
global refinementFactor
global unsSolverAttsNames
set attributes [dict create]
foreach name $unsSolverAttsNames {
set value [$blk getUnstructuredSolverAttribute $name]
# Redimension certain attributes
switch $name {
EdgeMinimumLength -
EdgeMaximumLength {
if { $value ne "Boundary" } {
set value [expr {$value / $refinementFactor}]
}
}
PyramidMinimumHeight -
PyramidMaximumHeight {
if { $value > 0 } {
set value [expr {$value / $refinementFactor}]
}
}
}
dict set attributes $name $value
}
return $attributes
}
# --------------------------------------------------------------------------
# Match diagonalized domains with their structured counterpart
proc findMatchedOrigDiagDomains { } {
global strDomList
global blksRegenData
global diagDomNameToOrigDom
set blksRegenData(names) ""
array set diagDomNameToOrigDom {}
# Loop through all structured domains to find their diagonalized counterpart
if { [llength $strDomList] > 0 } {
foreach dom $strDomList {
# Get list of connectors used by this domain
set conList [getConnectors $dom]
# Get list of domains adjacent to this domain
set adjDomList [pw::Domain getAdjacentDomains $dom]
foreach adjDom $adjDomList {
# The diagonalized domain is unstructured
if { [$adjDom isOfType "pw::DomainUnstructured"] } {
# Get list of connectors used by this domain
set adjConList [getConnectors $adjDom]
# If the lists of connectos match then adjDom is the diagonalized
# version of dom.
if { [compareLists $conList $adjConList] } {
# Add matching pair to the map
set diagDomNameToOrigDom([$adjDom getName]) $dom
# Cache data to regenerate unstructured blocks using the diagonalized
# domain
set blkList [pw::Block getBlocksFromDomains $adjDom]
foreach blk $blkList {
if { [$blk isOfType "pw::BlockUnstructured"] } {
set domList [getDomains $blk]
cacheBlockRegenerationData $adjDom $domList $blk
}
}
}
}
}
}
}
}
# --------------------------------------------------------------------------
# Cache data necessary for block regeneration
proc cacheBlockRegenerationData { domRegenerate domList blk } {
global blksRegenData
global boundaryConditions
global trexConditions
set domName [$domRegenerate getName]
set blkName [$blk getName]
if { [lsearch -exact $blksRegenData(names) $blkName] == -1 } {
# Name
lappend blksRegenData(names) $blkName
# Layer
lappend blksRegenData($blkName,layer) [$blk getLayer]
# Domain list (this list does not contain the diagonalized domain to be
# regenerated)
set domList [removeFromList $domList $domRegenerate]
set blksRegenData($blkName,domains,keep) $domList
# Domain names list (diagonalized domains to be regenerated)
set blksRegenData($blkName,domains,regenerate) $domName
# Attributes
set blksRegenData($blkName,attributes) \
[getAndRedimensionUnstructuredSolverAttributes $blk]
# Boundary conditions
cacheBoundaryConditions "boundary" $blk
# TRex conditions
cacheBoundaryConditions "trex" $blk
# Volume conditions
cacheVolumeConditions "volume" $blk
} else {
# Domain names list (diagonalized domains to be regenerated)
if { [lsearch -exact $blksRegenData($blkName,domains,regenerate) \
$domName] == -1 } {
set domList $blksRegenData($blkName,domains,keep)
set domList [removeFromList $domList $domRegenerate]
set blksRegenData($blkName,domains,keep) $domList
lappend blksRegenData($blkName,domains,regenerate) $domName
}
}
}
# --------------------------------------------------------------------------
# Cache boundary conditions (boundary, TRex)
proc cacheBoundaryConditions { type blk } {
global blksRegenData
global boundaryConditions
global trexConditions
switch $type {
boundary { array set conditions [array get boundaryConditions] }
trex { array set conditions [array get trexConditions] }
}
if { [array size conditions] > 0 } {
foreach {name condition} [array get conditions] {
set add 0
set registers [$condition getRegisters]
set blkName [$blk getName]
foreach reg $registers {
set highLevelEntity [lindex $reg 0]
if { $highLevelEntity eq $blk } {
# Boundary condition applied to this block, cache it
set add 1
set data [list [[lindex $reg 1] getName] [lindex $reg 2]]
lappend blksRegenData($blkName,${type}Conditions,$name) $data
}
}
if { $add == 1 } {
lappend blksRegenData($blkName,${type}Conditions,names) $name
}
}
}
}
# --------------------------------------------------------------------------
# Apply boundary conditions (boundary, TRex)
proc applyBoundaryConditions { type blk } {
global blksRegenData
global boundaryConditions
global trexConditions
set blkName [$blk getName]
if {$type eq "boundary"} {
array set conditions [array get boundaryConditions]
} elseif {$type eq "trex"} {
array set conditions [array get trexConditions]
}
set argument "$blkName,${type}Conditions"
if { [array names blksRegenData -exact $argument,names] ne "" } {
foreach condName $blksRegenData($argument,names) {
# Get BC
set condition $conditions($condName)
set bcData $blksRegenData($argument,$condName)
# Build register
foreach data $bcData {
set orient [lindex $data 1]
set domName [lindex $data 0]
set dom [pw::GridEntity getByName [lindex $data 0]]
set register [list $blk $dom $orient]
$condition apply $register
}
}
}
}
# --------------------------------------------------------------------------
# Cache volume conditions
proc cacheVolumeConditions { type blk } {
global blksRegenData
global volumeConditions
if { [array size volumeConditions] > 0 } {
foreach {name condition} [array get volumeConditions] {
set entities [$condition getEntities]
foreach entity $entities {
if { $entity eq $blk } {
set blkName [$blk getName]
set blksRegenData($blkName,volumeCondition) $name
}
}
}
}
}
# --------------------------------------------------------------------------
# Apply volume conditions
proc applyVolumeConditions { blk } {
global blksRegenData
global volumeConditions
set blkName [$blk getName]
set argument "$blkName,volumeCondition"
if { [array names blksRegenData -exact $argument] ne "" } {
set condName $blksRegenData($argument)
# Get VC
set condition $volumeConditions($condName)
$condition apply $blk
}
}
# --------------------------------------------------------------------------
# Redimension balanced connectors
proc redimensionBalancedConnectors {} {
global refinementFactor
global strDomList
global conList
set refinedConList ""
# Loop over structured domains, redimension connectors, and check for edge
# dimension balance
foreach domain $strDomList {
set edgeDims {0 0}
for {set i 1} {$i <= 4} {incr i} {
set tmpConList ""
set edge [$domain getEdge $i]
set connectorCount [$edge getConnectorCount]
for {set j 1} {$j <= $connectorCount} {incr j} {
set connector [$edge getConnector $j]
if { [lsearch -exact $refinedConList $connector] == -1 } {
# Add connector to a temporary list of connectors to be refined now
lappend tmpConList $connector
}
}
# Refine connectors in this edge
redimensionConnectors $tmpConList
# Append to the list of refined connectors
lappend refinedConList $tmpConList
set refinedConList [join $refinedConList]
# Remove from the list of connectors that still need to be refined
set conList [removeFromList $conList $tmpConList]
# A balanced structured domain requires edge_1 to be balanced with edge_3
# and edge_2 to be balanced with edge_4. If edge is not balanced with its
# opposing edge, attempt to balance them
set idx [expr $i - 1]
set edgeDim [$edge getDimension]
if { $i <= 2 } {
set edgeDims [lreplace $edgeDims $idx $idx $edgeDim]
} elseif { $edgeDim != [lindex $edgeDims [expr $idx - 2]] } {
balanceEdge [lindex $edgeDims [expr $idx - 2]] $edgeDim $tmpConList \
$domain
}
}
}
}
# --------------------------------------------------------------------------
# Redimension connectors
proc redimensionConnectors { conList } {
global refinementFactor
global numCons
global conCnt
set conMode [pw::Application begin Modify $conList]
foreach con $conList {
# Progress information
incr conCnt
puts ""
puts "Refining connector $conCnt of $numCons..."
puts " ...connector [$con getName]"
puts ""
# Get connector distribution type
set conDist [$con getDistribution 1]
# Check if distribution is of type growth
if { [$conDist isOfType "pw::DistributionGrowth"] } {
# Decrease grid point spacing
$conDist setBeginSpacing [expr {(1.0 / $refinementFactor) * \
[[$conDist getBeginSpacing] getValue]}]
$conDist setEndSpacing [expr {(1.0 / $refinementFactor) * \
[[$conDist getEndSpacing] getValue]}]
# Set optimal connector dimension
$con setDimensionFromDistribution
} else {
# Increase connector dimension in 3 steps ...
# 1) Store refined subconnector dimensions
set totalDim 0
set subConnCount [$con getSubConnectorCount]
for {set i 1} {$i <= $subConnCount} {incr i} {
set dim [expr {round($refinementFactor * \
[$con getSubConnectorDimension $i] - 1)}]
lappend conSubDim $dim
incr totalDim $dim
}
# 2) Redimension connector
$con setDimension [expr {$totalDim - ($subConnCount - 1)}]
# 3) Adjust subconnector dimension
if { $subConnCount > 1 } {
$con setSubConnectorDimension $conSubDim
}
catch {unset conSubDim}
# Decrease grid point spacing
for {set i 1} {$i <= $subConnCount} {incr i} {
set conDist [$con getDistribution $i]
$conDist setBeginSpacing [expr (1.0 / $refinementFactor)* \
[[$conDist getBeginSpacing] getValue]]
$conDist setEndSpacing [expr (1.0 / $refinementFactor)* \
[[$conDist getEndSpacing] getValue]]
}
}
}
$conMode end
catch {unset conMode}
}
# --------------------------------------------------------------------------
# Balance the edges of free standing structured domains.
# Note: this function balnces free-standing structured domains only (basically
# structured domains used to create diagonalized unstructured domains
# that are not being used by any block)
proc balanceEdge { edgeBalancedDimension edgeDimension conList domain } {
if { [llength [pw::Block getBlocksFromDomains $domain]] == 0 } {
# How many points do we need to add/remove?
set deltaPoints [expr abs($edgeBalancedDimension - $edgeDimension)]
# Sort connectors according to their dimension
set dimensionData [dict create]
foreach con $conList {
dict lappend dimensionData [$con getDimension] $con
}
set sortedDims [lsort -integer -decreasing [dict keys $dimensionData]]
# Modify dimension
# Note: The grid points are added to or removed from connectors with the
# larger dimension first.
foreach dim $sortedDims {
# Get list of connectors with this dimension
set conSubList [dict get $dimensionData $dim]
# Set new dimension
if { $edgeBalancedDimension > $edgeDimension } {
incr dim 1
} else {
incr dim -1
}
# Redimension connectors
foreach con $conSubList {
$con setDimension $dim
incr deltaPoints -1
if { $deltaPoints == 0 } {
# No more points need to be added/removed, return
return
}
}
}
}
}
# --------------------------------------------------------------------------
# Redimension unstructured domains
proc redimensionDomains {} {
global refinementFactor
global domList
global numDoms
global domCnt
foreach dom $domList {
# Progress information
incr domCnt
puts ""
puts "Refining domain $domCnt of $numDoms..."
puts " ...domain [$dom getName]"
puts ""
# Refine interior triangles of unstructured domains if necessary. Do not refine
# diagonalized domains, they will be regenerated
if { [$dom isOfType "pw::DomainUnstructured"] &&
[array get diagDomNameToOrigDom $dom] eq "" } {
set domMinEdgeLen [$dom getUnstructuredSolverAttribute EdgeMinimumLength]
set domMaxEdgeLen [$dom getUnstructuredSolverAttribute EdgeMaximumLength]
# Refine min. and max. edge length (if necessary)
if { $domMinEdgeLen ne "Boundary" } {
$dom setUnstructuredSolverAttribute EdgeMinimumLength \
[expr {$domMinEdgeLen / $refinementFactor}]
}
if { $domMaxEdgeLen ne "Boundary" } {
$dom setUnstructuredSolverAttribute EdgeMaximumLength \
[expr {$domMaxEdgeLen / $refinementFactor}]
}
# Refine
set unsSolver [pw::Application begin UnstructuredSolver $dom]
if [catch {$unsSolver run Refine}] {
lappend domError [$dom getName]
$unsSolver end
continue
}
$unsSolver end
}
}
catch {unset unsSolver}
# Write out unstructured domains that could not be refined due to solver error
if { [info exists domError] } {
set errMsg "Error refining [llength $domError] domain"
printErrorInformation $domError $errMsg
}
}
# --------------------------------------------------------------------------
# Regenerate diagonalized domains
proc regenerateDiagDomains {} {
global diagDomNameToOrigDom
global diagDomNameToDiagDom
# Generate new diagonalized domains and delete old ones
foreach {diagDomName origDom} [array get diagDomNameToOrigDom] {
if { [catch {set newDiagDom [$origDom triangulate Aligned]}] } {
if { [catch {set newDiagDom [$origDom triangulate]}] } {
# Error during triangularization
lappend domError $diagDomName
continue
}
}
set oldDiagDom [pw::GridEntity getByName $diagDomName]
set oldDiagDomLayer [$oldDiagDom getLayer]
$oldDiagDom delete -force
$newDiagDom setName $diagDomName
$newDiagDom setLayer $oldDiagDomLayer
set diagDomNameToDiagDom($diagDomName) $newDiagDom
}
# Write out unstructured domains that could not be re-diagonalized
if { [info exists domError] } {
set errMsg "Error re-diagonalizing [llength $domError] domain"
printErrorInformation $domError $errMsg
}
}
# --------------------------------------------------------------------------
# Regenerate unstructured blocks
proc regenerateUnstructuredBlocks {} {
global blksRegenData
global diagDomNameToDiagDom
global unsSolverAttsNames
global trexConditions
if { [array get blksRegenData names] ne "" } {
set blkNameList $blksRegenData(names)
foreach blkName $blkNameList {
set domList $blksRegenData($blkName,domains,keep)
# Add regenerated domains to the list. If there was an error
# re-diagonalizing the domain, the old domain is already in
# the list, no need to add it again
foreach name $blksRegenData($blkName,domains,regenerate) {
set dom [pw::GridEntity getByName $name]
if { [lsearch -exact $domList $dom] == -1 } {
# The domain was re-diagonalized
lappend domList $dom
}
}
# Create block
if { [catch {set blk [pw::BlockUnstructured createFromDomains -reject \
unused $domList]}] || [llength $unused] > 0 } {
# Error during block generation
lappend blkError $blkName
} else {
# Name
if { [$blk getName] ne $blkName } {
$blk setName $blkName
}
# Attributes
set attributes $blksRegenData($blkName,attributes)
foreach name [dict keys $attributes] {
set value [dict get $attributes $name]
if { $name ne "" && $value ne "" } {
$blk setUnstructuredSolverAttribute $name $value
}
}
# Boundary conditions
applyBoundaryConditions "boundary" $blk
# TRex conditions
applyBoundaryConditions "trex" $blk
# Volume conditions
applyVolumeConditions $blk
# Layer
$blk setLayer $blksRegenData($blkName,layer)
}
}
# Write out unstructured blocks that could not be regenerated
if { [info exists blkError] } {
set errMsg "Error re-generating [llength $blkError] block"
printErrorInformation $blkError $errMsg
}
}
}
# --------------------------------------------------------------------------
# Initialize unstructured blocks
proc initializeUnstructuredBlocks {} {
global refinementFactor
global unsBlkList
foreach unsBlk $unsBlkList {
set unsSolver [pw::Application begin UnstructuredSolver $unsBlk]
if [catch {$unsSolver run Initialize}] {
lappend blkError [$unsBlk getName]
$unsSolver end
continue
}
$unsSolver end
unset unsSolver
}
# Write out unstructured blocks that could not be initialized due to solver error
if { [info exists blkError] } {
set errMsg "Error initializing [llength $blkError] block"
printErrorInformation $blkError $errMsg
}
}
# --------------------------------------------------------------------------
# Print error information
proc printErrorInformation { entityList errMsg } {
if { [ llength $entityList] > 0 } {
# Print out error information
if { [llength $entityList] == 1 } {
set errMsg "${errMsg}:"
} else {
set errMsg "${errMsg}s:"
}
puts $errMsg
foreach entity $entityList {
puts "$entity"
}
}
}
# --------------------------------------------------------------------------
# Print block information
proc printBlockInformation {} {
global blkList
foreach blk $blkList {
if { [$blk isOfType "pw::BlockStructured"] } {
puts ""
puts "Block [$blk getName]"
puts "--------------------"
puts "Block Type: Structured"
puts "Total Cell Count: [$blk getCellCount]"
puts ""
} elseif {[$blk isOfType "pw::BlockUnstructured"]} {
puts ""
puts "Block [$blk getName]"
puts "--------------------"
puts "Block Type: Unstructured"
if {[$blk getTRexCellCount]>0} {
puts "Full TRex Layers: [$blk getTRexFullLayerCount]"
puts "Total TRex Layers: [$blk getTRexTotalLayerCount]"
puts "Total TRex Cells: [$blk getTRexCellCount]"
puts "Total Cell Count: [$blk getCellCount]"
puts ""
} else {
puts "Total Cell Count: [$blk getCellCount]"
}
} elseif {[$blk isOfType "pw::BlockExtruded"]} {
puts ""
puts "Block [$blk getName]"
puts "--------------------"
puts "Block Type: Extruded"
puts "Total Cell Count: [$blk getCellCount]"
puts ""
} else {
puts ""
puts "Block [$blk getName] type not supported by this script."
puts ""
}
}
}
# --------------------------------------------------------------------------
# Save volume mesh
proc saveVolumeMesh { volStartTime volEndTime } {
global refinementFactor
global cwd
global fileRoot
set fileExport "$fileRoot-Volume-$refinementFactor.pw"
puts ""
puts "Writing $fileExport file..."
puts "Volume initialization completed in [expr {$volEndTime-$volStartTime}] \
seconds"
puts ""
pw::Application save [file join $cwd $fileExport]
}
# --------------------------------------------------------------------------
# Main script body
# Start timer
set startTime [clock seconds]
# Setup Pointwise and define working directory
pw::Application reset
pw::Application clearModified
set cwd [file dirname [info script]]
# File root
set fileRoot [file rootname $pwFile]
# Output Pointwise version information
puts ""
puts "[pw::Application getVersion]"
puts ""
puts "Refinement factor is set to $refinementFactor"
puts ""
# Check if refinement factor is lower or equal than 1
if { $refinementFactor <= 1 } {
if { $volMesh eq "YES" } {
# Load Pointwise file
pw::Application load [file join $cwd $pwFile]
# Save surface mesh
set fileExport "$fileRoot-Surface-$refinementFactor.pw"
puts ""
puts "Writing $fileExport file..."
puts ""
pw::Application save [file join $cwd $fileExport]
puts ""
puts "Initializing volume mesh..."
puts ""
# Start timer
set volStartTime [clock seconds]
# Gather all blocks
set blkList [pw::Grid getAll -type pw::Block]
# Gather all unstructured blocks
set unsBlkList [pw::Grid getAll -type pw::BlockUnstructured]
# Initialize unstructured blocks
initializeUnstructuredBlocks
# End timer
set volEndTime [clock seconds]
# Print block information
printBlockInformation
# Save volume mesh
saveVolumeMesh $volStartTime $volEndTime
# End timer
set endTime [clock seconds]
puts ""
puts "Pointwise script executed in [expr $endTime-$startTime] seconds"
puts ""
exit
} else {
puts ""
puts "Refinement factor is 1 or lower, nothing to do..."
puts ""
exit
}
}
# Load Pointwise file
pw::Application load [file join $cwd $pwFile]
# Start timer
set surfStartTime [clock seconds]
# Get current layer
set currentLayer [pw::Display getCurrentLayer]
# Gather all connectors
set conList [pw::Grid getAll -type pw::Connector]
set numCons [llength $conList]
set conCnt 0
# Gather all domains
set domList [pw::Grid getAll -type pw::Domain]
set numDoms [llength $domList]
set domCnt 0
# Gather all structured domains
set strDomList [pw::Grid getAll -type pw::DomainStructured]
# Gather all blocks
set blkList [pw::Grid getAll -type pw::Block]
# Gather all unstructured blocks
set unsBlkList [pw::Grid getAll -type pw::BlockUnstructured]
# Get boundary conditions
getBoundaryConditions
# Get and redimension TRex conditions
getAndRedimensionTRexConditions
# Get volume conditions
getVolumeConditions
# Match diagonalized domains with their structured counterpart
findMatchedOrigDiagDomains
# Redimension balanced connectors
redimensionBalancedConnectors
# Redimension connectors
redimensionConnectors $conList
# Redimension domains
redimensionDomains
# Regenerate diagonalized domains
regenerateDiagDomains
# Save surface mesh
set fileExport "$fileRoot-Surface-$refinementFactor.pw"
# End timer
set surfEndTime [clock seconds]
# Regenerate unstructured blocks
regenerateUnstructuredBlocks
puts ""
puts "Writing $fileExport file..."
puts "Surface refinement completed in [expr {$surfEndTime-$surfStartTime}]\
seconds"
puts ""
pw::Application save [file join $cwd $fileExport]
# Initialize volume mesh if required
if { $volMesh eq "YES" } {
puts ""
puts "Initializing volume mesh..."
puts ""
# Start timer
set volStartTime [clock seconds]
# Unstructured blocks could have been regenerated, gather all blocks (again)
set blkList [pw::Grid getAll -type pw::Block]
# Unstructured blocks could have been regenerated, gather all unstructured \
# blocks (again)
set unsBlkList [pw::Grid getAll -type pw::BlockUnstructured]
# Initialize unstructured blocks
initializeUnstructuredBlocks
# End timer
set volEndTime [clock seconds]
# Print block information
printBlockInformation
# Save volume mesh
saveVolumeMesh $volStartTime $volEndTime
}
# Restore current layer
pw::Display setCurrentLayer $currentLayer
# End timer
set endTime [clock seconds]
puts ""
puts "Pointwise script executed in [expr $endTime-$startTime] seconds"
puts ""
#
# END SCRIPT
#
#############################################################################
#