Repository navigation
Expand file tree
/
Copy pathCMultiGridGeometry.cpp
More file actions
2429 lines (2049 loc) · 106 KB
/
Copy pathCMultiGridGeometry.cpp
File metadata and controls
2429 lines (2049 loc) · 106 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
/*!
* \file CMultiGridGeometry.cpp
* \brief Implementation of the multigrid geometry class.
* \author F. Palacios, T. Economon
* \version 8.6.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../include/geometry/CMultiGridGeometry.hpp"
#include "../../include/geometry/CMultiGridQueue.hpp"
#include "../../include/toolboxes/printing_toolbox.hpp"
#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
#include <algorithm>
#include <array>
#include <limits>
#include <map>
#include <sstream>
#include <utility>
namespace {
/*--- Euler wall nodes are not agglomerated where the surface turns by more than this, in
* degrees. ---*/
constexpr passivedouble EULER_WALL_MAX_CURVATURE = 45.0;
/*--- Fine points one coarse CV may hold: a quadrilateral in 2D, a hexahedron in 3D. ---*/
constexpr short int MaxAgglomSize(unsigned short nDim) { return (nDim == 2) ? 4 : 8; }
/*--- Equivalence-class id per entity for the set of physical markers it lies on: entities with the
* same set share an id, 0 means no marker. The pairs are consumed. ---*/
vector<unsigned long> MarkerSetClasses(unsigned long nEntity, vector<std::pair<unsigned long, unsigned short>>& pairs) {
vector<unsigned long> classOfEntity(nEntity, 0);
std::sort(pairs.begin(), pairs.end());
pairs.erase(std::unique(pairs.begin(), pairs.end()), pairs.end());
map<vector<unsigned short>, unsigned long> classOf;
unsigned long nClass = 0;
for (size_t i = 0; i < pairs.size();) {
size_t j = i;
vector<unsigned short> markerSet;
while ((j < pairs.size()) && (pairs[j].first == pairs[i].first)) markerSet.push_back(pairs[j++].second);
const auto res = classOf.emplace(std::move(markerSet), nClass + 1);
if (res.second) nClass++;
classOfEntity[pairs[i].first] = res.first->second;
i = j;
}
return classOfEntity;
}
} // namespace
CMultiGridGeometry::CMultiGridGeometry(CGeometry* fine_grid, CConfig* config, unsigned short iMesh) : CGeometry() {
nDim = fine_grid->GetnDim(); // Write the number of dimensions of the coarse grid.
const short int maxAgglomSize = MaxAgglomSize(nDim);
/*--- Inherit boundary properties from fine grid ---*/
boundIsStraight = fine_grid->boundIsStraight;
/*--- Agglomeration Scheme II (Nishikawa, Diskin, Thomas)
Create a queue system to do the agglomeration
1st) More than two markers ---> Vertices (never agglomerate)
2nd) Two markers ---> Edges (agglomerate if same BC, never agglomerate if different BC)
3rd) One marker ---> Surface (always agglomerate)
4th) No marker ---> Internal Volume (always agglomerate) ---*/
/*--- Set a marker to indicate indirect agglomeration, for quads and hexs,
i.e. consider up to neighbors of neighbors.
For other levels this information is propagated down during their construction. ---*/
if (iMesh == MESH_1) {
for (auto iPoint = 0ul; iPoint < fine_grid->GetnPoint(); iPoint++)
fine_grid->nodes->SetAgglomerate_Indirect(iPoint, false);
for (auto iElem = 0ul; iElem < fine_grid->GetnElem(); iElem++) {
if ((fine_grid->elem[iElem]->GetVTK_Type() == HEXAHEDRON) ||
(fine_grid->elem[iElem]->GetVTK_Type() == QUADRILATERAL)) {
for (auto iNode = 0u; iNode < fine_grid->elem[iElem]->GetnNodes(); iNode++) {
const auto iPoint = fine_grid->elem[iElem]->GetNode(iNode);
fine_grid->nodes->SetAgglomerate_Indirect(iPoint, true);
}
}
}
}
/*--- Index of a coarse CV that does not exist, and of a fine point with no parent yet. ---*/
constexpr auto NO_CV = std::numeric_limits<unsigned long>::max();
/*--- Clear the parents the halo points were given when this fine grid was itself agglomerated.
* Everything below reads NO_CV as "not agglomerated on this rank". ---*/
for (auto iPoint = fine_grid->GetnPointDomain(); iPoint < fine_grid->GetnPoint(); iPoint++)
fine_grid->nodes->SetParent_CV(iPoint, NO_CV);
/*--- Create the coarse grid structure using as baseline the fine grid ---*/
CMultiGridQueue MGQueue_InnerCV(fine_grid->GetnPoint());
vector<unsigned long> Suitable_Indirect_Neighbors;
nodes = new CPoint(fine_grid->GetnPoint(), nDim, iMesh, config);
unsigned long Index_CoarseCV = 0;
/*--- Euler wall seeds taken and refused, per config file marker so the counts reduce over the
* ranks. A local marker index names a different boundary on each rank. ---*/
vector<unsigned long> eulerTaken(config->GetnMarker_CfgFile(), 0);
vector<unsigned long> eulerRefused(config->GetnMarker_CfgFile(), 0);
vector<unsigned short> cfgMarker(fine_grid->GetnMarker(), 0);
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++)
if (config->GetMarker_All_KindBC(iMarker) == EULER_WALL)
cfgMarker[iMarker] = config->GetMarker_CfgFile_TagBound(config->GetMarker_All_TagBound(iMarker));
/*--- Points carrying a physical boundary condition. This does not include SEND_RECEIVE. ---*/
vector<char> onPhysBoundary(fine_grid->GetnPoint(), 0);
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue;
for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++)
onPhysBoundary[fine_grid->vertex[iMarker][iVertex]->GetNode()] = 1;
}
/*--- Nodes on a periodic marker. Periodic donor matching is rebuilt per level and pairs one
* coarse vertex per marker, so a coarse CV holding two of these would receive twice. ---*/
vector<char> onPeriodic(fine_grid->GetnPoint(), 0);
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
if (config->GetMarker_All_KindBC(iMarker) != PERIODIC_BOUNDARY) continue;
for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++)
onPeriodic[fine_grid->vertex[iMarker][iVertex]->GetNode()] = 1;
}
/*--- Nodes where two different boundary conditions meet. ---*/
const auto mixedBC = FindMixedBoundaryNodes(fine_grid, config);
/*--- STEP 0: pave the domain with advancing fronts rising from the boundaries. The coarse CVs it
* creates occupy [firstLineCV, endLineCV). ---*/
const auto firstLineCV = Index_CoarseCV;
vector<unsigned long> neverGrewCV;
if (config->GetMGOptions().MG_Implicit_Lines) {
levelReport =
PaveAdvancingFronts(Index_CoarseCV, fine_grid, config, iMesh, mixedBC, onPhysBoundary, onPeriodic, neverGrewCV);
}
const auto endLineCV = Index_CoarseCV;
/*--- STEP 1: The first step is the boundary agglomeration. ---*/
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
/*--- Skip periodic boundaries: do not agglomerate on periodic markers. ---*/
if (config->GetMarker_All_KindBC(iMarker) == PERIODIC_BOUNDARY) continue;
/*--- Skip SEND_RECEIVE markers, those points are left to the domain pass. ---*/
if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue;
for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++) {
const auto iPoint = fine_grid->vertex[iMarker][iVertex]->GetNode();
/*--- If the element has not been previously agglomerated and it
belongs to this physical domain, and it meets the geometrical
criteria, the agglomeration is studied. ---*/
vector<short> marker_seed;
if ((!fine_grid->nodes->GetAgglomerate(iPoint)) && (fine_grid->nodes->GetDomain(iPoint)) &&
(GeometricalCheck(iPoint, fine_grid, config))) {
unsigned short nChildren = 1;
/*--- We set an index for the parent control volume, this
also marks it as agglomerated. ---*/
fine_grid->nodes->SetParent_CV(iPoint, Index_CoarseCV);
/*--- We add the seed point (child) to the parent control volume ---*/
nodes->SetChildren_CV(Index_CoarseCV, 0, iPoint);
bool agglomerate_seed = false;
auto counter = 0;
unsigned short copy_marker[2] = {};
marker_seed.push_back(iMarker);
/*--- For a particular point in the fine grid we save all the physical markers that are in
that point. ---*/
for (auto jMarker = 0u; jMarker < fine_grid->GetnMarker(); jMarker++) {
if (config->GetMarker_All_KindBC(jMarker) == SEND_RECEIVE) continue;
if (fine_grid->nodes->GetVertex(iPoint, jMarker) != -1) {
/*--- Count every physical marker, only the first two are read back. ---*/
if (counter < 2) copy_marker[counter] = jMarker;
counter++;
if (jMarker != iMarker) {
marker_seed.push_back(jMarker);
}
}
}
/*--- To agglomerate a vertex it must have only one physical bc.
This can be improved. If there is only one marker, it is a good
candidate for agglomeration ---*/
/*--- 1 BC, so either an edge in 2D or the interior of a plane in 3D ---*/
/*--- Valley -> Valley : conditionally allowed when both points are on the same marker. ---*/
/*--- ! Note that in the case of MPI SEND_RECEIVE markers, we might need other conditions ---*/
if (counter == 1) {
// The seed/parent is one valley, so we set this part to true
// if the child is on the same valley, we set it to true as well.
agglomerate_seed = true;
/*--- Euler walls: check curvature-based agglomeration criterion ---*/
if (config->GetMarker_All_KindBC(marker_seed[0]) == EULER_WALL) {
/*--- Allow agglomeration if marker is straight OR local curvature is small ---*/
if (!boundIsStraight[marker_seed[0]]) {
/*--- Compute local curvature at this point ---*/
su2double local_curvature = ComputeLocalCurvature(fine_grid, iPoint, marker_seed[0]);
if (local_curvature >= EULER_WALL_MAX_CURVATURE) {
agglomerate_seed = false; // High curvature: do not agglomerate
eulerRefused[cfgMarker[marker_seed[0]]]++;
} else {
eulerTaken[cfgMarker[marker_seed[0]]]++;
}
} else {
/*--- Straight wall: agglomerate ---*/
eulerTaken[cfgMarker[marker_seed[0]]]++;
}
}
}
/*--- Two physical markers meet here. ---*/
if (counter == 2) {
/*--- In 2D that is a corner in the geometry, which is never agglomerated. ---*/
if (nDim == 2) agglomerate_seed = false;
/*--- In 3D, this is a ridge point (an edge where two surface markers meet). ---*/
if (nDim == 3) agglomerate_seed = true;
/*--- Euler walls: check curvature-based agglomeration criterion for both markers ---*/
// only in 3d because in 2d it's a corner
bool euler_wall_rejected_here = false;
for (unsigned short i = 0; i < 2; i++) {
if ((nDim == 3) && (config->GetMarker_All_KindBC(copy_marker[i]) == EULER_WALL)) {
if (!boundIsStraight[copy_marker[i]]) {
/*--- Compute local curvature at this point ---*/
su2double local_curvature = ComputeLocalCurvature(fine_grid, iPoint, copy_marker[i]);
if (local_curvature >= EULER_WALL_MAX_CURVATURE) {
agglomerate_seed = false; // High curvature: do not agglomerate
eulerRefused[cfgMarker[copy_marker[i]]]++;
euler_wall_rejected_here = true;
}
}
/*--- Track agglomeration if not rejected ---*/
if (agglomerate_seed && !euler_wall_rejected_here) {
eulerTaken[cfgMarker[copy_marker[i]]]++;
}
}
}
}
/*--- If there are more than 2 markers, the aglomeration will be discarded ---*/
if (counter > 2) agglomerate_seed = false;
/*--- ...and so is a node where two markers of different type meet, in any dimension. ---*/
if (mixedBC[iPoint]) agglomerate_seed = false;
/*--- If the seed (parent) can be agglomerated, we try to agglomerate connected childs to the parent ---*/
/*--- Note that in 2D we allow a maximum of 4 nodes to be agglomerated ---*/
if (agglomerate_seed) {
/*--- Now we do a sweep over all the nodes that surround the seed point ---*/
for (auto CVPoint : fine_grid->nodes->GetPoints(iPoint)) {
/*--- The new point can be agglomerated ---*/
if (SetBoundAgglomeration(CVPoint, marker_seed, fine_grid, config, mixedBC)) {
/*--- We set the value of the parent ---*/
fine_grid->nodes->SetParent_CV(CVPoint, Index_CoarseCV);
/*--- We set the value of the child ---*/
nodes->SetChildren_CV(Index_CoarseCV, nChildren, CVPoint);
nChildren++;
/*--- In 2D, we agglomerate exactly 2 nodes if the nodes are on the line edge. ---*/
if ((nDim == 2) && (counter == 1)) break;
/*--- In 3D, we agglomerate exactly 2 nodes if the nodes are on the surface edge. ---*/
if ((nDim == 3) && (counter == 2)) break;
/*--- Apply maxAgglomSize limit for 3D internal boundary face nodes (counter==1 in 3D). ---*/
if (nChildren >= maxAgglomSize) break;
}
}
/*--- Indirect neighbors only for 3D faces. ---*/
if ((nDim == 3) && (nChildren < maxAgglomSize)) {
Suitable_Indirect_Neighbors.clear();
if (fine_grid->nodes->GetAgglomerate_Indirect(iPoint))
SetSuitableNeighbors(Suitable_Indirect_Neighbors, iPoint, fine_grid);
/*--- Now we do a sweep over all the indirect nodes that can be added ---*/
for (auto CVPoint : Suitable_Indirect_Neighbors) {
/*--- The new point can be agglomerated ---*/
if (SetBoundAgglomeration(CVPoint, marker_seed, fine_grid, config, mixedBC)) {
/*--- We set the value of the parent ---*/
fine_grid->nodes->SetParent_CV(CVPoint, Index_CoarseCV);
/*--- We set the indirect agglomeration information of the corse point
based on its children in the fine grid. ---*/
if (fine_grid->nodes->GetAgglomerate_Indirect(CVPoint))
nodes->SetAgglomerate_Indirect(Index_CoarseCV, true);
/*--- We set the value of the child ---*/
nodes->SetChildren_CV(Index_CoarseCV, nChildren, CVPoint);
nChildren++;
/*--- Apply maxAgglomSize limit for 3D internal boundary face nodes. ---*/
if (nChildren >= maxAgglomSize) break;
}
}
}
}
/*--- Update the number of children of the coarse control volume. ---*/
nodes->SetnChildren_CV(Index_CoarseCV, nChildren);
Index_CoarseCV++;
}
}
}
/*--- Do not agglomerate any leftover node with more than one physical boundary condition,
i.e. make one coarse CV with a single child. ---*/
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
/*--- As in STEP 1, a SEND_RECEIVE marker does not make a point a boundary point. ---*/
if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue;
for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++) {
const auto iPoint = fine_grid->vertex[iMarker][iVertex]->GetNode();
if ((!fine_grid->nodes->GetAgglomerate(iPoint)) && (fine_grid->nodes->GetDomain(iPoint))) {
fine_grid->nodes->SetParent_CV(iPoint, Index_CoarseCV);
nodes->SetChildren_CV(Index_CoarseCV, 0, iPoint);
nodes->SetnChildren_CV(Index_CoarseCV, 1);
Index_CoarseCV++;
}
}
}
/*--- Update the queue with the results from the boundary agglomeration ---*/
for (auto iPoint = 0ul; iPoint < fine_grid->GetnPoint(); iPoint++) {
if (fine_grid->nodes->GetAgglomerate(iPoint)) {
MGQueue_InnerCV.RemoveCV(iPoint);
} else {
/*--- Count the number of agglomerated neighbors, and modify the queue,
Points with more agglomerated neighbors are processed first. ---*/
short priority = 0;
for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) {
priority += fine_grid->nodes->GetAgglomerate(jPoint);
}
MGQueue_InnerCV.MoveCV(iPoint, priority);
}
}
/*--- STEP 2: Agglomerate the domain points. A seed grows one node at a time, taking the candidate
* that shares the most edges with the current members. ---*/
vector<char> inCV(fine_grid->GetnPoint(), 0);
vector<char> isCandidate(fine_grid->GetnPoint(), 0);
vector<unsigned long> members, candidates;
members.reserve(maxAgglomSize);
/*--- A local frame at the seed: up to nDim of its incident edges, as mutually orthogonal as
* possible, each with its own length. ---*/
vector<std::array<su2double, MAXNDIM>> frameDir, edgeDir;
vector<su2double> frameLen, edgeLen;
vector<char> edgeUsed;
auto iteration = 0ul;
while (!MGQueue_InnerCV.EmptyQueue() && (iteration < fine_grid->GetnPoint())) {
const auto iPoint = MGQueue_InnerCV.NextCV();
iteration++;
/*--- If the element has not been previously agglomerated, belongs to the physical domain,
and satisfies several geometrical criteria then the seed CV is accepted for agglomeration. ---*/
if ((!fine_grid->nodes->GetAgglomerate(iPoint)) && (fine_grid->nodes->GetDomain(iPoint)) &&
(GeometricalCheck(iPoint, fine_grid, config))) {
members.clear();
candidates.clear();
unsigned short nChildren = 0;
/*--- Take a node into the CV and let the frontier grow with it. ---*/
auto addMember = [&](unsigned long CVPoint) {
fine_grid->nodes->SetParent_CV(CVPoint, Index_CoarseCV);
nodes->SetChildren_CV(Index_CoarseCV, nChildren, CVPoint);
nChildren++;
if (fine_grid->nodes->GetAgglomerate_Indirect(CVPoint)) nodes->SetAgglomerate_Indirect(Index_CoarseCV, true);
/*--- Remove it from the queue and raise the priority of its neighbours. ---*/
MGQueue_InnerCV.Update(CVPoint, fine_grid);
members.push_back(CVPoint);
inCV[CVPoint] = 1;
for (auto jPoint : fine_grid->nodes->GetPoints(CVPoint)) {
if (inCV[jPoint] || isCandidate[jPoint]) continue;
if (fine_grid->nodes->GetAgglomerate(jPoint) || !fine_grid->nodes->GetDomain(jPoint)) continue;
if (!GeometricalCheck(jPoint, fine_grid, config)) continue;
isCandidate[jPoint] = 1;
candidates.push_back(jPoint);
}
};
addMember(iPoint);
edgeDir.clear();
edgeLen.clear();
su2double seedShortest = std::numeric_limits<su2double>::max();
for (auto jPoint : fine_grid->nodes->GetPoints(iPoint)) {
su2double e[MAXNDIM] = {0.0};
GeometryToolbox::Distance(nDim, fine_grid->nodes->GetCoord(jPoint), fine_grid->nodes->GetCoord(iPoint), e);
const su2double len = GeometryToolbox::Norm(nDim, e);
if (len <= 0.0) continue;
std::array<su2double, MAXNDIM> u{};
for (unsigned short d = 0; d < nDim; ++d) u[d] = e[d] / len;
edgeDir.push_back(u);
edgeLen.push_back(len);
seedShortest = std::min(seedShortest, len);
}
/*--- A seed with no usable edge cannot be measured against anything, leave the scale at one. ---*/
if (seedShortest == std::numeric_limits<su2double>::max()) seedShortest = 1.0;
/*--- The shortest edge goes in first, the rest in order of how orthogonal they are to what is
* already in the frame. ---*/
frameDir.clear();
frameLen.clear();
edgeUsed.assign(edgeDir.size(), 0);
while (frameDir.size() < nDim) {
long pick = -1;
su2double bestScore = -1.0;
for (size_t i = 0; i < edgeDir.size(); ++i) {
if (edgeUsed[i]) continue;
su2double score;
if (frameDir.empty()) {
score = 1.0 / edgeLen[i];
} else {
score = 2.0;
for (const auto& f : frameDir) {
su2double a = 0.0;
for (unsigned short d = 0; d < nDim; ++d) a += f[d] * edgeDir[i][d];
score = std::min(score, 1.0 - fabs(a));
}
}
if (score > bestScore) {
bestScore = score;
pick = static_cast<long>(i);
}
}
if (pick < 0) break;
edgeUsed[pick] = 1;
frameDir.push_back(edgeDir[pick]);
frameLen.push_back(edgeLen[pick]);
}
/*--- Without a full frame the offset cannot be resolved, fall back to one isotropic scale. ---*/
const bool haveFrame = (frameDir.size() == nDim);
while (nChildren < maxAgglomSize) {
/*--- Centroid of what the CV holds so far, used only to break ties. ---*/
su2double centroid[MAXNDIM] = {0.0};
for (auto jPoint : members) {
const auto* coord = fine_grid->nodes->GetCoord(jPoint);
for (auto iDim = 0u; iDim < nDim; iDim++) centroid[iDim] += coord[iDim] / su2double(members.size());
}
unsigned long best = NO_CV;
unsigned short best_shared = 0;
su2double best_dist = std::numeric_limits<su2double>::max();
for (auto CVPoint : candidates) {
if (inCV[CVPoint]) continue;
unsigned short shared = 0;
for (auto jPoint : fine_grid->nodes->GetPoints(CVPoint)) shared += inCV[jPoint];
/*--- Distance to the centroid in cells: the offset is scaled by the seed edge pointing
* most nearly along it. ---*/
su2double off[MAXNDIM] = {0.0};
for (unsigned short d = 0; d < nDim; ++d) off[d] = fine_grid->nodes->GetCoord(CVPoint)[d] - centroid[d];
const su2double offLen = GeometryToolbox::Norm(nDim, off);
su2double dist = 0.0;
if (haveFrame) {
for (size_t k = 0; k < frameDir.size(); ++k) {
su2double p = 0.0;
for (unsigned short d = 0; d < nDim; ++d) p += off[d] * frameDir[k][d];
const su2double q = p / frameLen[k];
dist += q * q;
}
} else {
const su2double r = offLen / seedShortest;
dist = r * r;
}
if ((shared > best_shared) || ((shared == best_shared) && (dist < best_dist))) {
best = CVPoint;
best_shared = shared;
best_dist = dist;
}
}
if (best == NO_CV) break;
addMember(best);
}
for (auto jPoint : members) inCV[jPoint] = 0;
for (auto jPoint : candidates) isCandidate[jPoint] = 0;
/*--- Update the number of control of childrens ---*/
nodes->SetnChildren_CV(Index_CoarseCV, nChildren);
Index_CoarseCV++;
} else {
/*--- The seed point can not be agglomerated because of size, domain, streching, etc.
move the point to the lowest priority ---*/
MGQueue_InnerCV.MoveCV(iPoint, -1);
}
}
/*--- Convert any point that was not agglomerated into a coarse point. ---*/
for (auto iPoint = 0ul; iPoint < fine_grid->GetnPoint(); iPoint++) {
if ((!fine_grid->nodes->GetAgglomerate(iPoint)) && (fine_grid->nodes->GetDomain(iPoint))) {
fine_grid->nodes->SetParent_CV(iPoint, Index_CoarseCV);
if (fine_grid->nodes->GetAgglomerate_Indirect(iPoint)) nodes->SetAgglomerate_Indirect(Index_CoarseCV, true);
nodes->SetChildren_CV(Index_CoarseCV, 0, iPoint);
nodes->SetnChildren_CV(Index_CoarseCV, 1);
Index_CoarseCV++;
}
}
nPointDomain = Index_CoarseCV;
nPoint = nPointDomain;
/*--- Coarse neighbours, so the repair passes below can find a CV a merge can go to. ---*/
SetPoint_Connectivity(fine_grid);
/*--- Coarse CVs the repair passes must leave exactly as the agglomeration made them, and those
* holding a boundary node at all. ---*/
vector<bool> mustStayAlone(nPointDomain, false);
vector<bool> cvOnBoundary(nPointDomain, false);
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++)
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(iCoarsePoint); iChildren++) {
const auto iFinePoint = nodes->GetChildren_CV(iCoarsePoint, iChildren);
if (mixedBC[iFinePoint] || onPeriodic[iFinePoint]) mustStayAlone[iCoarsePoint] = true;
if (onPhysBoundary[iFinePoint]) cvOnBoundary[iCoarsePoint] = true;
}
/*--- Which physical boundaries each coarse CV sits on, as a marker-set class. Comparing classes
* keeps a merge inside one boundary. Halo points hold the parent sentinel and drop out. ---*/
vector<std::pair<unsigned long, unsigned short>> cvMarker;
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue;
for (auto iVertex = 0ul; iVertex < fine_grid->nVertex[iMarker]; iVertex++) {
const auto iParent = fine_grid->nodes->GetParent_CV(fine_grid->vertex[iMarker][iVertex]->GetNode());
if (iParent < nPointDomain) cvMarker.push_back({iParent, static_cast<unsigned short>(iMarker)});
}
}
const auto cvMarkerClass = MarkerSetClasses(nPointDomain, cvMarker);
/*--- Columns that never advanced past their seed layer, which are not stacks. ---*/
vector<bool> neverGrew(nPointDomain, false);
for (auto iCV : neverGrewCV)
if (iCV < nPointDomain) neverGrew[iCV] = true;
/*--- A boundary CV the paving built is the base of a stack and keeps its footprint. ---*/
auto isStackBase = [&](unsigned long iCoarsePoint) {
return cvOnBoundary[iCoarsePoint] && (iCoarsePoint >= firstLineCV) && (iCoarsePoint < endLineCV) &&
!neverGrew[iCoarsePoint];
};
/*--- The coarse connectivity only knows about CVs of this rank, so a CV reaching over a partition
* boundary can look isolated. ---*/
vector<bool> touchesPartition(nPointDomain, false);
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) {
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(iCoarsePoint); iChildren++) {
const auto iFinePoint = nodes->GetChildren_CV(iCoarsePoint, iChildren);
for (auto iFinePoint_Neighbor : fine_grid->nodes->GetPoints(iFinePoint)) {
if (fine_grid->nodes->GetParent_CV(iFinePoint_Neighbor) == NO_CV) {
touchesPartition[iCoarsePoint] = true;
break;
}
}
if (touchesPartition[iCoarsePoint]) break;
}
}
/*--- Whether jCV may take children from iCV: the agglomeration has not pinned it, and it sits on
* the same boundaries. ---*/
auto mayMerge = [&](unsigned long iCV, unsigned long jCV) {
return !mustStayAlone[jCV] && !isStackBase(jCV) && (cvMarkerClass[jCV] == cvMarkerClass[iCV]);
};
/*--- Append one fine point to a coarse CV. ---*/
auto giveChild = [&](unsigned long iFinePoint, unsigned long toCV) {
const auto nChildren = nodes->GetnChildren_CV(toCV);
nodes->SetChildren_CV(toCV, nChildren, iFinePoint);
nodes->SetnChildren_CV(toCV, nChildren + 1);
fine_grid->nodes->SetParent_CV(iFinePoint, toCV);
};
/*--- Empty one coarse CV into another. ---*/
auto mergeInto = [&](unsigned long fromCV, unsigned long toCV) {
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(fromCV); iChildren++)
giveChild(nodes->GetChildren_CV(fromCV, iChildren), toCV);
nodes->SetnChildren_CV(fromCV, 0);
};
/*--- Neighbour with the fewest children that may take this CV, NO_CV if there is none. Neighbours
* an earlier merge in the same pass emptied are not revived. ---*/
auto smallestPartner = [&](unsigned long iCV, unsigned short maxPartnerSize, bool keepOffPartition) {
auto best = NO_CV;
auto best_nChildren = std::numeric_limits<unsigned short>::max();
for (auto jCV : nodes->GetPoints(iCV)) {
const auto nChildren = nodes->GetnChildren_CV(jCV);
if ((nChildren == 0) || (nChildren > maxPartnerSize) || (nChildren >= best_nChildren)) continue;
if (keepOffPartition && touchesPartition[jCV]) continue;
if (!mayMerge(iCV, jCV)) continue;
best_nChildren = nChildren;
best = jCV;
}
return best;
};
/*--- A CV with a single coarse neighbour is merged into it. ---*/
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) {
if (mustStayAlone[iCoarsePoint] || touchesPartition[iCoarsePoint]) continue;
if (nodes->GetnPoint(iCoarsePoint) != 1) continue;
const auto iTarget = nodes->GetPoint(iCoarsePoint, 0);
if (isStackBase(iCoarsePoint) || !mayMerge(iCoarsePoint, iTarget)) continue;
/*--- Two boundary rows that already hold more than one node each must never fuse into one
* oversized CV. A genuine singleton leftover may still be absorbed. ---*/
if (cvOnBoundary[iCoarsePoint] && cvOnBoundary[iTarget] && (nodes->GetnChildren_CV(iCoarsePoint) > 1)) continue;
/*--- Make room in the target by handing its last children to its other neighbours. The merge
* runs whether or not that succeeds, so the size limit can still be exceeded. ---*/
int nAfterMerge = nodes->GetnChildren_CV(iTarget) + nodes->GetnChildren_CV(iCoarsePoint);
for (auto jCoarsePoint : nodes->GetPoints(iTarget)) {
if (nAfterMerge <= maxAgglomSize) break;
/*--- The isolated CV hands anything it takes straight back below. ---*/
if ((jCoarsePoint == iCoarsePoint) || !mayMerge(iTarget, jCoarsePoint)) continue;
while ((nAfterMerge > maxAgglomSize) && (nodes->GetnChildren_CV(jCoarsePoint) < maxAgglomSize)) {
const auto nChildren = nodes->GetnChildren_CV(iTarget);
if (nChildren == 0) break;
giveChild(nodes->GetChildren_CV(iTarget, nChildren - 1), jCoarsePoint);
nodes->SetnChildren_CV(iTarget, nChildren - 1);
nAfterMerge--;
}
}
mergeInto(iCoarsePoint, iTarget);
}
/*--- A CV left holding a single child joins the neighbour with the fewest, even where that takes
the neighbour one past maxAgglomSize. ---*/
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) {
if (nodes->GetnChildren_CV(iCoarsePoint) != 1) continue;
if (mustStayAlone[iCoarsePoint] || isStackBase(iCoarsePoint)) continue;
/*--- Already handled above, or truly islanded. ---*/
if (nodes->GetnPoint(iCoarsePoint) <= 1) continue;
const auto iTarget = smallestPartner(iCoarsePoint, std::numeric_limits<unsigned short>::max(), false);
if (iTarget != NO_CV) mergeInto(iCoarsePoint, iTarget);
}
/*--- Merge a paved CV of at most SMALL_STACK_CV children into an equally small neighbour, which
the two passes above do not reach. Two of them can never exceed maxAgglomSize together. ---*/
constexpr unsigned short SMALL_STACK_CV = 2; /*!< \brief The block size a narrow stack emits
between flushes; see BlockFor. */
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) {
const auto nChildren = nodes->GetnChildren_CV(iCoarsePoint);
if ((nChildren == 0) || (nChildren > SMALL_STACK_CV)) continue;
if (mustStayAlone[iCoarsePoint] || isStackBase(iCoarsePoint) || touchesPartition[iCoarsePoint]) continue;
/*--- Interior stack fragments only, a boundary row keeps its footprint. ---*/
if (cvOnBoundary[iCoarsePoint]) continue;
const auto iTarget = smallestPartner(iCoarsePoint, SMALL_STACK_CV, true);
if (iTarget != NO_CV) mergeInto(iCoarsePoint, iTarget);
}
/*--- Compact the coarse numbering, squeezing out the indices the repair passes emptied. The
children lists, indirect-agglomeration flags and owned parent indices are remapped. ---*/
{
vector<unsigned long> newIndex(nPointDomain, NO_CV);
unsigned long nKept = 0;
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++)
if (nodes->GetnChildren_CV(iCoarsePoint) > 0) newIndex[iCoarsePoint] = nKept++;
if (nKept < nPointDomain) {
/*--- Move the survivors down. newIndex[i] <= i, so a forward sweep never lands on a CV that has
not been moved yet. ---*/
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPointDomain; iCoarsePoint++) {
const auto iNew = newIndex[iCoarsePoint];
if ((iNew == NO_CV) || (iNew == iCoarsePoint)) continue;
nodes->SetChildren_CV(iNew, nodes->GetChildren_CV(iCoarsePoint));
nodes->SetnChildren_CV(iNew, nodes->GetnChildren_CV(iCoarsePoint));
nodes->SetAgglomerate_Indirect(iNew, nodes->GetAgglomerate_Indirect(iCoarsePoint));
}
for (auto iCoarsePoint = nKept; iCoarsePoint < nPointDomain; iCoarsePoint++)
nodes->SetnChildren_CV(iCoarsePoint, 0);
for (auto iFinePoint = 0ul; iFinePoint < fine_grid->GetnPointDomain(); iFinePoint++) {
const auto iParent = fine_grid->nodes->GetParent_CV(iFinePoint);
if (iParent == NO_CV) continue;
/*--- A fine point may only reference a CV the compaction kept. ---*/
if ((iParent >= nPointDomain) || (newIndex[iParent] == NO_CV))
SU2_MPI::Error("Multigrid compaction: a fine point still references an emptied coarse CV.", CURRENT_FUNCTION);
fine_grid->nodes->SetParent_CV(iFinePoint, newIndex[iParent]);
}
nPointDomain = nKept;
nPoint = nKept;
Index_CoarseCV = nKept;
}
}
/*--- Reset the neighbor information. ---*/
nodes->ResetPoints();
#ifdef HAVE_MPI
/*--- Dealing with MPI parallelization, the objective is that the received nodes must be agglomerated
in the same way as the donor (send) nodes. Send the node agglomeration information of the donor
(parent and children). The agglomerated halos of this rank are set according to the rank where
they are domain points. ---*/
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) {
if ((config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) && (config->GetMarker_All_SendRecv(iMarker) > 0)) {
const auto MarkerS = iMarker; // sending marker
const auto MarkerR = iMarker + 1; // receiving marker
const auto send_to = config->GetMarker_All_SendRecv(MarkerS) - 1;
const auto receive_from = abs(config->GetMarker_All_SendRecv(MarkerR)) - 1;
const auto nVertexS = fine_grid->nVertex[MarkerS];
const auto nVertexR = fine_grid->nVertex[MarkerR];
/*--- Allocate Receive and Send buffers ---*/
vector<unsigned long> Buffer_Receive_Children(nVertexR);
vector<unsigned long> Buffer_Send_Children(nVertexS);
vector<unsigned long> Buffer_Receive_Parent(nVertexR);
vector<unsigned long> Buffer_Send_Parent(nVertexS);
/*--- Copy the information that should be sent, child and parent indices. ---*/
for (auto iVertex = 0ul; iVertex < nVertexS; iVertex++) {
const auto iPoint = fine_grid->vertex[MarkerS][iVertex]->GetNode();
Buffer_Send_Children[iVertex] = iPoint;
Buffer_Send_Parent[iVertex] = fine_grid->nodes->GetParent_CV(iPoint);
}
/*--- Send/Receive information. ---*/
SU2_MPI::Sendrecv(Buffer_Send_Children.data(), nVertexS, MPI_UNSIGNED_LONG, send_to, 0,
Buffer_Receive_Children.data(), nVertexR, MPI_UNSIGNED_LONG, receive_from, 0,
SU2_MPI::GetComm(), MPI_STATUS_IGNORE);
SU2_MPI::Sendrecv(Buffer_Send_Parent.data(), nVertexS, MPI_UNSIGNED_LONG, send_to, 1,
Buffer_Receive_Parent.data(), nVertexR, MPI_UNSIGNED_LONG, receive_from, 1, SU2_MPI::GetComm(),
MPI_STATUS_IGNORE);
/*--- Create a list of the parent nodes without duplicates. ---*/
auto Aux_Parent = Buffer_Receive_Parent;
sort(Aux_Parent.begin(), Aux_Parent.end());
auto it1 = unique(Aux_Parent.begin(), Aux_Parent.end());
Aux_Parent.resize(it1 - Aux_Parent.begin());
/*--- Create the local and remote vector for the parents and children CVs. ---*/
const auto& Parent_Remote = Buffer_Receive_Parent;
vector<unsigned long> Parent_Local(nVertexR);
vector<unsigned long> Children_Local(nVertexR);
/*--- First pass: determine which parents will actually be used, i.e. have non-skipped
children. ---*/
vector<bool> parent_used(Aux_Parent.size(), false);
vector<unsigned long> parent_local_index(Aux_Parent.size(), NO_CV);
for (auto iVertex = 0ul; iVertex < nVertexR; iVertex++) {
const auto iPoint_Fine = fine_grid->vertex[MarkerR][iVertex]->GetNode();
auto existing_parent = fine_grid->nodes->GetParent_CV(iPoint_Fine);
/*--- Skip if already agglomerated (first-wins policy) ---*/
if (existing_parent != NO_CV) continue;
/*--- Skip if received parent is invalid (sending rank didn't agglomerate this point) ---*/
if (Parent_Remote[iVertex] == NO_CV) continue;
/*--- Find which parent this vertex maps to ---*/
for (auto jVertex = 0ul; jVertex < Aux_Parent.size(); jVertex++) {
if (Parent_Remote[iVertex] == Aux_Parent[jVertex]) {
parent_used[jVertex] = true;
break;
}
}
}
/*--- Assign local indices only to used parents ---*/
unsigned long nUsedParents = 0;
for (auto jVertex = 0ul; jVertex < Aux_Parent.size(); jVertex++) {
if (parent_used[jVertex]) {
parent_local_index[jVertex] = Index_CoarseCV + nUsedParents;
nUsedParents++;
}
}
/*--- Now map each received vertex to its local parent ---*/
for (auto iVertex = 0ul; iVertex < nVertexR; iVertex++) {
Parent_Local[iVertex] = NO_CV;
for (auto jVertex = 0ul; jVertex < Aux_Parent.size(); jVertex++) {
if (Parent_Remote[iVertex] == Aux_Parent[jVertex]) {
Parent_Local[iVertex] = parent_local_index[jVertex];
break;
}
}
Children_Local[iVertex] = fine_grid->vertex[MarkerR][iVertex]->GetNode();
}
/*--- Only increment by the number of parents that will actually be used ---*/
Index_CoarseCV += nUsedParents;
/*--- Create the final structure ---*/
for (auto iVertex = 0ul; iVertex < nVertexR; iVertex++) {
const auto iPoint_Fine = Children_Local[iVertex];
/*--- Skip if this halo point was already agglomerated (first-wins policy) ---*/
auto existing_parent = fine_grid->nodes->GetParent_CV(iPoint_Fine);
if (existing_parent != NO_CV) continue;
/*--- Skip if parent mapping is invalid (sender didn't agglomerate) ---*/
const auto iPoint_Coarse = Parent_Local[iVertex];
if (iPoint_Coarse == NO_CV) continue;
/*--- Append to existing children, don't overwrite ---*/
auto existing_children_count = nodes->GetnChildren_CV(iPoint_Coarse);
fine_grid->nodes->SetParent_CV(iPoint_Fine, iPoint_Coarse);
nodes->SetChildren_CV(iPoint_Coarse, existing_children_count, iPoint_Fine);
nodes->SetnChildren_CV(iPoint_Coarse, existing_children_count + 1);
nodes->SetDomain(iPoint_Coarse, false);
}
}
}
#endif // HAVE_MPI
/*--- Update the number of points after the MPI agglomeration ---*/
nPoint = Index_CoarseCV;
/*--- Name each coarse point, halos too, by the smallest global index it holds, so every level
* carries a name its owner and the ranks that only see it agree on. ---*/
for (auto iCoarsePoint = 0ul; iCoarsePoint < nPoint; iCoarsePoint++) {
auto globalIndex = NO_CV;
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(iCoarsePoint); iChildren++)
globalIndex =
std::min(globalIndex, fine_grid->nodes->GetGlobalIndex(nodes->GetChildren_CV(iCoarsePoint, iChildren)));
if (globalIndex != NO_CV) nodes->SetGlobalIndex(iCoarsePoint, globalIndex);
}
/*--- Console output with the summary of the agglomeration ---*/
unsigned long nPointFine = fine_grid->GetnPointDomain();
unsigned long Global_nPointCoarse, Global_nPointFine;
SU2_MPI::Allreduce(&nPointDomain, &Global_nPointCoarse, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
SU2_MPI::Allreduce(&nPointFine, &Global_nPointFine, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
SetGlobal_nPointDomain(Global_nPointCoarse);
if (iMesh != MESH_0) {
/*--- Seed the coarse-level CFL with the same per-level reduction CMultiGridIntegration
applies after every cycle. ---*/
const su2double scale = max(su2double(1e-6), min(su2double(1.0), config->GetMGOptions().MG_CflScaling[iMesh - 1]));
config->SetCFL(iMesh, config->GetCFL(iMesh - 1) * scale);
}
const su2double ratio = su2double(Global_nPointFine) / su2double(Global_nPointCoarse);
/*--- Stop coarsening on the size of the whole level, so the hierarchy a case gets does not
depend on how many ranks it happens to run on. ---*/
if (Global_nPointCoarse < config->GetMGOptions().MG_Min_MeshSize) {
if (rank == MASTER_NODE)
cout << "MG level " << iMesh << " has only " << Global_nPointCoarse
<< " CVs (< MG_MIN_MESHSIZE=" << config->GetMGOptions().MG_Min_MeshSize << "). Reducing MG levels to "
<< iMesh - 1 << "." << endl;
config->SetMGLevels(iMesh - 1);
} else if (rank == MASTER_NODE) {
PrintingToolbox::CTablePrinter MGTable(&std::cout);
MGTable.AddColumn("MG Level", 10);
MGTable.AddColumn("CVs", 10);
MGTable.AddColumn("Aggl. Rate", 10);
MGTable.AddColumn("CFL", 10);
MGTable.SetAlign(PrintingToolbox::CTablePrinter::RIGHT);
if (iMesh == MESH_1) {
MGTable.PrintHeader();
MGTable << iMesh - 1 << Global_nPointFine << "1/1.00" << config->GetCFL(iMesh - 1);
}
stringstream ss;
ss << "1/" << std::setprecision(3) << ratio;
MGTable << iMesh << Global_nPointCoarse << ss.str() << config->GetCFL(iMesh);
if (iMesh == config->GetnMGLevels()) {
MGTable.PrintFooter();
}
}
/*--- Euler wall seeds this level took, one line per marker. Every rank reaches the reduction. ---*/
vector<unsigned long> eulerTakenGlobal(eulerTaken.size()), eulerRefusedGlobal(eulerRefused.size());
SU2_MPI::Allreduce(eulerTaken.data(), eulerTakenGlobal.data(), eulerTaken.size(), MPI_UNSIGNED_LONG, MPI_SUM,
SU2_MPI::GetComm());
SU2_MPI::Allreduce(eulerRefused.data(), eulerRefusedGlobal.data(), eulerRefused.size(), MPI_UNSIGNED_LONG, MPI_SUM,
SU2_MPI::GetComm());
if (rank == MASTER_NODE) {
stringstream euler;
euler << std::fixed << std::setprecision(1);
for (auto iMarker = 0u; iMarker < eulerTakenGlobal.size(); iMarker++) {
const auto total = eulerTakenGlobal[iMarker] + eulerRefusedGlobal[iMarker];
if (total == 0) continue;
euler << " MG level " << iMesh << " Euler wall " << config->GetMarker_CfgFile_TagBound(iMarker) << ": "
<< eulerTakenGlobal[iMarker] << " seeds agglomerated, " << eulerRefusedGlobal[iMarker] << " refused above "
<< EULER_WALL_MAX_CURVATURE << " degrees of curvature ("
<< 100.0 * passivedouble(eulerRefusedGlobal[iMarker]) / passivedouble(total) << "%)\n";
}
levelReport += euler.str();
}
edgeColorGroupSize = config->GetEdgeColoringGroupSize();
}
bool CMultiGridGeometry::GeometricalCheck(unsigned long iPoint, const CGeometry* fine_grid,
const CConfig* config) const {
/*--- A control volume whose edge exceeds MAX_DIMENSION times the domain's is not agglomerated.
* Raising both sides to the power nDim gives the same test on volumes, without the roots. ---*/
constexpr passivedouble MAX_DIMENSION = 1.2;
su2double scale = MAX_DIMENSION * MAX_DIMENSION;
if (nDim == 3) scale *= MAX_DIMENSION;
return fine_grid->nodes->GetVolume(iPoint) * scale <= config->GetDomainVolume();
}
vector<char> CMultiGridGeometry::FindMixedBoundaryNodes(const CGeometry* fine_grid, const CConfig* config) const {
vector<char> mixed(fine_grid->GetnPoint(), 0);
/*--- The first physical condition seen at each node, -1 until one is. A second one of a different
* kind is what makes the node mixed. ---*/
vector<short> firstBC(fine_grid->GetnPoint(), -1);
for (auto iMarker = 0u; iMarker < fine_grid->GetnMarker(); iMarker++) {
if (config->GetMarker_All_KindBC(iMarker) == SEND_RECEIVE) continue;
const auto bc = static_cast<short>(config->GetMarker_All_KindBC(iMarker));
for (auto iVertex = 0ul; iVertex < fine_grid->GetnVertex(iMarker); iVertex++) {
const auto iPoint = fine_grid->vertex[iMarker][iVertex]->GetNode();
if (firstBC[iPoint] < 0)
firstBC[iPoint] = bc;