-
Notifications
You must be signed in to change notification settings - Fork 977
Expand file tree
/
Copy pathCSolver.cpp
More file actions
4374 lines (3264 loc) · 157 KB
/
CSolver.cpp
File metadata and controls
4374 lines (3264 loc) · 157 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 CSolver.cpp
* \brief Main subroutines for CSolver class.
* \author F. Palacios, T. Economon
* \version 8.4.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/solvers/CSolver.hpp"
#include "../../include/gradients/computeGradientsGreenGauss.hpp"
#include "../../include/gradients/computeGradientsLeastSquares.hpp"
#include "../../include/limiters/computeLimiters.hpp"
#include "../../../Common/include/toolboxes/MMS/CIncTGVSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CInviscidVortexSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSIncEulerSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSIncNSSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSNSTwoHalfCirclesSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSNSTwoHalfSpheresSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSNSUnitQuadSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CMMSNSUnitQuadSolutionWallBC.hpp"
#include "../../../Common/include/toolboxes/MMS/CNSUnitQuadSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CRinglebSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CTGVSolution.hpp"
#include "../../../Common/include/toolboxes/MMS/CUserDefinedSolution.hpp"
#include "../../../Common/include/toolboxes/printing_toolbox.hpp"
#include "../../../Common/include/toolboxes/C1DInterpolation.hpp"
#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
#include "../../../Common/include/toolboxes/CLinearPartitioner.hpp"
#include "../../../Common/include/adt/CADTPointsOnlyClass.hpp"
#include "../../include/CMarkerProfileReaderFVM.hpp"
CSolver::CSolver(LINEAR_SOLVER_MODE linear_solver_mode) : System(linear_solver_mode) {
rank = SU2_MPI::GetRank();
size = SU2_MPI::GetSize();
adjoint = false;
/*--- Set the multigrid level to the finest grid. This can be
overwritten in the constructors of the derived classes. ---*/
MGLevel = MESH_0;
/*--- Array initialization ---*/
OutputHeadingNames = nullptr;
Residual = nullptr;
Residual_i = nullptr;
Residual_j = nullptr;
Solution = nullptr;
Solution_i = nullptr;
Solution_j = nullptr;
Vector = nullptr;
Vector_i = nullptr;
Vector_j = nullptr;
Res_Conv = nullptr;
Res_Visc = nullptr;
Res_Sour = nullptr;
Res_Conv_i = nullptr;
Res_Visc_i = nullptr;
Res_Conv_j = nullptr;
Res_Visc_j = nullptr;
Jacobian_i = nullptr;
Jacobian_j = nullptr;
Jacobian_ii = nullptr;
Jacobian_ij = nullptr;
Jacobian_ji = nullptr;
Jacobian_jj = nullptr;
base_nodes = nullptr;
nOutputVariables = 0;
ResLinSolver = 0.0;
/*--- Variable initialization to avoid valgrid warnings when not used. ---*/
IterLinSolver = 0;
/*--- Initialize pointer for any verification solution. ---*/
VerificationSolution = nullptr;
/*--- Flags for the periodic BC communications. ---*/
rotate_periodic = false;
implicit_periodic = false;
/*--- Containers to store the markers. ---*/
nMarker = 0;
/*--- Flags for the dynamic grid (rigid movement or unsteady deformation). ---*/
dynamic_grid = false;
/*--- Auxiliary data needed for CFL adaption. ---*/
Old_Func = 0;
New_Func = 0;
NonLinRes_Counter = 0;
nPrimVarGrad = 0;
nPrimVar = 0;
}
CSolver::~CSolver() {
unsigned short iVar;
/*--- Public variables, may be accessible outside ---*/
delete [] OutputHeadingNames;
/*--- Private ---*/
delete [] Residual;
delete [] Residual_i;
delete [] Residual_j;
delete [] Solution;
delete [] Solution_i;
delete [] Solution_j;
delete [] Vector;
delete [] Vector_i;
delete [] Vector_j;
delete [] Res_Conv;
delete [] Res_Visc;
delete [] Res_Sour;
delete [] Res_Conv_i;
delete [] Res_Conv_j;
delete [] Res_Visc_i;
delete [] Res_Visc_j;
if (Jacobian_i != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_i[iVar];
delete [] Jacobian_i;
}
if (Jacobian_j != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_j[iVar];
delete [] Jacobian_j;
}
if (Jacobian_ii != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_ii[iVar];
delete [] Jacobian_ii;
}
if (Jacobian_ij != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_ij[iVar];
delete [] Jacobian_ij;
}
if (Jacobian_ji != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_ji[iVar];
delete [] Jacobian_ji;
}
if (Jacobian_jj != nullptr) {
for (iVar = 0; iVar < nVar; iVar++)
delete [] Jacobian_jj[iVar];
delete [] Jacobian_jj;
}
Restart_Vars = decltype(Restart_Vars){};
Restart_Data = decltype(Restart_Data){};
delete VerificationSolution;
}
vector<int> CSolver::FindFieldIndices(const vector<string>& target_fields) const {
/*--- Search for field names in the fields vector.
Fields are stored with quotes, e.g., "Temperature", so we need to check
both with and without quotes. ---*/
vector<int> indices;
indices.reserve(target_fields.size());
for (const auto& search : target_fields) {
/*--- Prepare both quoted and unquoted versions ---*/
string fieldNameWithQuotes = "\"" + search + "\"";
/*--- Search for the field (try both with and without quotes) ---*/
auto it = std::find(fields.begin(), fields.end(), fieldNameWithQuotes);
if (it == fields.end()) {
it = std::find(fields.begin(), fields.end(), search);
}
/*--- Store the index or -1 if not found ---*/
indices.push_back(it != fields.end() ? std::distance(fields.begin(), it) : -1);
}
return indices;
}
void CSolver::GetPeriodicCommCountAndType(const CConfig* config,
unsigned short commType,
unsigned short &COUNT_PER_POINT,
unsigned short &MPI_TYPE,
unsigned short &ICOUNT,
unsigned short &JCOUNT) const {
switch (commType) {
case PERIODIC_VOLUME:
COUNT_PER_POINT = 1;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_NEIGHBORS:
COUNT_PER_POINT = 1;
MPI_TYPE = COMM_TYPE_UNSIGNED_SHORT;
break;
case PERIODIC_RESIDUAL:
COUNT_PER_POINT = nVar + nVar*nVar + 1;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_IMPLICIT:
COUNT_PER_POINT = nVar;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_LAPLACIAN:
COUNT_PER_POINT = nVar;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_MAX_EIG:
COUNT_PER_POINT = 1;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_SENSOR:
COUNT_PER_POINT = 2;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case PERIODIC_SOL_GG:
case PERIODIC_SOL_GG_R:
COUNT_PER_POINT = nVar*nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nVar;
JCOUNT = nDim;
break;
case PERIODIC_PRIM_GG:
case PERIODIC_PRIM_GG_R:
COUNT_PER_POINT = nPrimVarGrad*nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nPrimVarGrad;
JCOUNT = nDim;
break;
case PERIODIC_SOL_LS:
case PERIODIC_SOL_ULS:
case PERIODIC_SOL_LS_R:
case PERIODIC_SOL_ULS_R:
COUNT_PER_POINT = nDim*nDim + nVar*nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nVar;
JCOUNT = nDim;
break;
case PERIODIC_PRIM_LS:
case PERIODIC_PRIM_ULS:
case PERIODIC_PRIM_LS_R:
case PERIODIC_PRIM_ULS_R:
COUNT_PER_POINT = nDim*nDim + nPrimVarGrad*nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nPrimVarGrad;
JCOUNT = nDim;
break;
case PERIODIC_LIM_PRIM_1:
COUNT_PER_POINT = nPrimVarGrad*2;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nPrimVarGrad;
break;
case PERIODIC_LIM_PRIM_2:
COUNT_PER_POINT = nPrimVarGrad;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nPrimVarGrad;
break;
case PERIODIC_LIM_SOL_1:
COUNT_PER_POINT = nVar*2;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nVar;
break;
case PERIODIC_LIM_SOL_2:
COUNT_PER_POINT = nVar;
MPI_TYPE = COMM_TYPE_DOUBLE;
ICOUNT = nVar;
break;
default:
SU2_MPI::Error("Unrecognized quantity for periodic communication.",
CURRENT_FUNCTION);
break;
}
}
namespace PeriodicCommHelpers {
CVectorOfMatrix& selectGradient(CVariable* nodes, unsigned short commType) {
switch(commType) {
case PERIODIC_PRIM_GG:
case PERIODIC_PRIM_LS:
case PERIODIC_PRIM_ULS:
return nodes->GetGradient_Primitive();
break;
case PERIODIC_SOL_GG:
case PERIODIC_SOL_LS:
case PERIODIC_SOL_ULS:
return nodes->GetGradient();
break;
default:
return nodes->GetGradient_Reconstruction();
break;
}
}
const su2activematrix& selectField(CVariable* nodes, unsigned short commType) {
switch(commType) {
case PERIODIC_PRIM_GG:
case PERIODIC_PRIM_LS:
case PERIODIC_PRIM_ULS:
case PERIODIC_PRIM_GG_R:
case PERIODIC_PRIM_LS_R:
case PERIODIC_PRIM_ULS_R:
case PERIODIC_LIM_PRIM_1:
case PERIODIC_LIM_PRIM_2:
return nodes->GetPrimitive();
break;
default:
return nodes->GetSolution();
break;
}
}
su2activematrix& selectLimiter(CVariable* nodes, unsigned short commType) {
switch(commType) {
case PERIODIC_LIM_PRIM_1:
case PERIODIC_LIM_PRIM_2:
return nodes->GetLimiter_Primitive();
break;
default:
return nodes->GetLimiter();
break;
}
}
}
void CSolver::InitiatePeriodicComms(CGeometry *geometry,
const CConfig *config,
unsigned short val_periodic_index,
unsigned short commType) {
/*--- Check for dummy communication. ---*/
if (commType == PERIODIC_NONE) return;
if (rotate_periodic && config->GetNEMOProblem()) {
SU2_MPI::Error("The NEMO solvers do not support rotational periodicity yet.", CURRENT_FUNCTION);
}
/*--- Local variables ---*/
bool boundary_i, boundary_j;
bool weighted = true;
unsigned short iVar, jVar, iDim;
unsigned short nNeighbor = 0;
unsigned short COUNT_PER_POINT = 0;
unsigned short MPI_TYPE = 0;
unsigned short ICOUNT = nVar;
unsigned short JCOUNT = nVar;
int iMessage, iSend, nSend;
unsigned long iPoint, msg_offset, buf_offset, iPeriodic;
auto *Diff = new su2double[nVar];
auto *Und_Lapl = new su2double[nVar];
auto *Sol_Min = new su2double[nPrimVarGrad];
auto *Sol_Max = new su2double[nPrimVarGrad];
auto *rotPrim_i = new su2double[nPrimVar];
auto *rotPrim_j = new su2double[nPrimVar];
su2double Sensor_i = 0.0, Sensor_j = 0.0, Pressure_i, Pressure_j;
const su2double *Coord_i, *Coord_j;
su2double r11, r12, r13, r22, r23_a, r23_b, r33, weight;
const su2double *center, *angles, *trans;
su2double rotMatrix2D[2][2] = {{1.0,0.0},{0.0,1.0}};
su2double rotMatrix3D[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
su2double rotCoord_i[3] = {0.0}, rotCoord_j[3] = {0.0};
su2double translation[3] = {0.0}, distance[3] = {0.0};
const su2double zeros[3] = {0.0};
su2activematrix Cvector;
auto Rotate = [&](const su2double* origin, const su2double* direction, su2double* rotated) {
if(nDim==2) GeometryToolbox::Rotate(rotMatrix2D, origin, direction, rotated);
else GeometryToolbox::Rotate(rotMatrix3D, origin, direction, rotated);
};
string Marker_Tag;
/*--- Set the size of the data packet and type depending on quantity. ---*/
GetPeriodicCommCountAndType(config, commType, COUNT_PER_POINT, MPI_TYPE, ICOUNT, JCOUNT);
/*--- Allocate buffers for matrices that need rotation. ---*/
su2activematrix jacBlock(ICOUNT,JCOUNT);
su2activematrix rotBlock(ICOUNT,JCOUNT);
/*--- Check to make sure we have created a large enough buffer
for these comms during preprocessing. It will be reallocated whenever
we find a larger count per point than currently exists. After the
first cycle of comms, this should be inactive. ---*/
geometry->AllocatePeriodicComms(COUNT_PER_POINT);
/*--- Set some local pointers to make access simpler. ---*/
su2double *bufDSend = geometry->bufD_PeriodicSend;
unsigned short *bufSSend = geometry->bufS_PeriodicSend;
/*--- Handle the different types of gradient and limiter. ---*/
auto& gradient = PeriodicCommHelpers::selectGradient(base_nodes, commType);
auto& limiter = PeriodicCommHelpers::selectLimiter(base_nodes, commType);
auto& field = PeriodicCommHelpers::selectField(base_nodes, commType);
/*--- Load the specified quantity from the solver into the generic
communication buffer in the geometry class. ---*/
if (geometry->nPeriodicSend > 0) {
/*--- Post all non-blocking recvs first before sends. ---*/
geometry->PostPeriodicRecvs(geometry, config, MPI_TYPE, COUNT_PER_POINT);
for (iMessage = 0; iMessage < geometry->nPeriodicSend; iMessage++) {
/*--- Get the offset in the buffer for the start of this message. ---*/
msg_offset = geometry->nPoint_PeriodicSend[iMessage];
/*--- Get the number of periodic points we need to
communicate on the current periodic marker. ---*/
nSend = (geometry->nPoint_PeriodicSend[iMessage+1] -
geometry->nPoint_PeriodicSend[iMessage]);
SU2_OMP_FOR_STAT(OMP_MIN_SIZE)
for (iSend = 0; iSend < nSend; iSend++) {
/*--- Get the local index for this communicated data. We need
both the node and periodic face index (for rotations). ---*/
iPoint = geometry->Local_Point_PeriodicSend[msg_offset + iSend];
iPeriodic = geometry->Local_Marker_PeriodicSend[msg_offset + iSend];
/*--- Retrieve the supplied periodic information. ---*/
Marker_Tag = config->GetMarker_All_TagBound(iPeriodic);
center = config->GetPeriodicRotCenter(Marker_Tag);
angles = config->GetPeriodicRotAngles(Marker_Tag);
trans = config->GetPeriodicTranslation(Marker_Tag);
/*--- Store (center+trans) as it is constant and will be added. ---*/
translation[0] = center[0] + trans[0];
translation[1] = center[1] + trans[1];
translation[2] = center[2] + trans[2];
/*--- Store angles separately for clarity. Compute sines/cosines. ---*/
su2double Theta = angles[0];
su2double Phi = angles[1];
su2double Psi = angles[2];
/*--- Compute the rotation matrix. Note that the implicit
ordering is rotation about the x-axis, y-axis, then z-axis. ---*/
if (nDim==2) {
GeometryToolbox::RotationMatrix(Psi, rotMatrix2D);
} else {
GeometryToolbox::RotationMatrix(Theta, Phi, Psi, rotMatrix3D);
}
/*--- Compute the offset in the recv buffer for this point. ---*/
buf_offset = (msg_offset + iSend)*COUNT_PER_POINT;
/*--- Load the send buffers depending on the particular value
that has been requested for communication. ---*/
switch (commType) {
case PERIODIC_VOLUME:
/*--- Load the volume of the current periodic CV so that
we can accumulate the total control volume size on all
periodic faces. ---*/
bufDSend[buf_offset] = geometry->nodes->GetVolume(iPoint) +
geometry->nodes->GetPeriodicVolume(iPoint);
break;
case PERIODIC_NEIGHBORS:
nNeighbor = 0;
for (auto jPoint : geometry->nodes->GetPoints(iPoint)) {
/*--- Check if this neighbor lies on the periodic face so
that we avoid double counting neighbors on both sides. If
not, increment the count of neighbors for the donor. ---*/
if (!geometry->nodes->GetPeriodicBoundary(jPoint))
nNeighbor++;
}
/*--- Store the number of neighbors in bufffer. ---*/
bufSSend[buf_offset] = nNeighbor;
break;
case PERIODIC_RESIDUAL:
/*--- Communicate the residual from our partial control
volume to the other side of the periodic face. ---*/
for (iVar = 0; iVar < nVar; iVar++) {
bufDSend[buf_offset+iVar] = LinSysRes(iPoint, iVar);
}
/*--- Rotate the momentum components of the residual array. ---*/
if (rotate_periodic) {
Rotate(zeros, &LinSysRes(iPoint,1), &bufDSend[buf_offset+1]);
}
buf_offset += nVar;
/*--- Load the time step for the current point. ---*/
bufDSend[buf_offset] = base_nodes->GetDelta_Time(iPoint);
buf_offset++;
/*--- For implicit calculations, we will communicate the
contributions to the Jacobian block diagonal, i.e., the
impact of the point upon itself, J_ii. ---*/
if (implicit_periodic) {
for (iVar = 0; iVar < nVar; iVar++) {
for (jVar = 0; jVar < nVar; jVar++) {
jacBlock[iVar][jVar] = Jacobian.GetBlock(iPoint, iPoint, iVar, jVar);
}
}
/*--- Rotate the momentum columns of the Jacobian. ---*/
if (rotate_periodic) {
for (iVar = 0; iVar < nVar; iVar++) {
if (nDim == 2) {
jacBlock[1][iVar] = (rotMatrix2D[0][0]*Jacobian.GetBlock(iPoint, iPoint, 1, iVar) +
rotMatrix2D[0][1]*Jacobian.GetBlock(iPoint, iPoint, 2, iVar));
jacBlock[2][iVar] = (rotMatrix2D[1][0]*Jacobian.GetBlock(iPoint, iPoint, 1, iVar) +
rotMatrix2D[1][1]*Jacobian.GetBlock(iPoint, iPoint, 2, iVar));
} else {
jacBlock[1][iVar] = (rotMatrix3D[0][0]*Jacobian.GetBlock(iPoint, iPoint, 1, iVar) +
rotMatrix3D[0][1]*Jacobian.GetBlock(iPoint, iPoint, 2, iVar) +
rotMatrix3D[0][2]*Jacobian.GetBlock(iPoint, iPoint, 3, iVar));
jacBlock[2][iVar] = (rotMatrix3D[1][0]*Jacobian.GetBlock(iPoint, iPoint, 1, iVar) +
rotMatrix3D[1][1]*Jacobian.GetBlock(iPoint, iPoint, 2, iVar) +
rotMatrix3D[1][2]*Jacobian.GetBlock(iPoint, iPoint, 3, iVar));
jacBlock[3][iVar] = (rotMatrix3D[2][0]*Jacobian.GetBlock(iPoint, iPoint, 1, iVar) +
rotMatrix3D[2][1]*Jacobian.GetBlock(iPoint, iPoint, 2, iVar) +
rotMatrix3D[2][2]*Jacobian.GetBlock(iPoint, iPoint, 3, iVar));
}
}
}
/*--- Load the Jacobian terms into the buffer for sending. ---*/
for (iVar = 0; iVar < nVar; iVar++) {
for (jVar = 0; jVar < nVar; jVar++) {
bufDSend[buf_offset] = jacBlock[iVar][jVar];
buf_offset++;
}
}
}
break;
case PERIODIC_IMPLICIT:
/*--- Communicate the solution from our master set of periodic
nodes (from the linear solver perspective) to the passive
periodic nodes on the matching face. This is done at the
end of the iteration to synchronize the solution after the
linear solve. ---*/
for (iVar = 0; iVar < nVar; iVar++) {
bufDSend[buf_offset+iVar] = base_nodes->GetSolution(iPoint, iVar);
}
/*--- Rotate the momentum components of the solution array. ---*/
if (rotate_periodic) {
Rotate(zeros, &base_nodes->GetSolution(iPoint)[1], &bufDSend[buf_offset+1]);
}
break;
case PERIODIC_LAPLACIAN:
/*--- For JST, the undivided Laplacian must be computed
consistently by using the complete control volume info
from both sides of the periodic face. ---*/
for (iVar = 0; iVar < nVar; iVar++)
Und_Lapl[iVar] = 0.0;
for (auto jPoint : geometry->nodes->GetPoints(iPoint)) {
/*--- Avoid periodic boundary points so that we do not
duplicate edges on both sides of the periodic BC. ---*/
if (!geometry->nodes->GetPeriodicBoundary(jPoint)) {
/*--- Solution differences ---*/
for (iVar = 0; iVar < nVar; iVar++)
Diff[iVar] = (base_nodes->GetSolution(iPoint, iVar) -
base_nodes->GetSolution(jPoint,iVar));
/*--- Correction for compressible flows (use enthalpy) ---*/
if (!(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE)) {
Pressure_i = base_nodes->GetPressure(iPoint);
Pressure_j = base_nodes->GetPressure(jPoint);
Diff[nVar-1] = ((base_nodes->GetSolution(iPoint,nVar-1) + Pressure_i) -
(base_nodes->GetSolution(jPoint,nVar-1) + Pressure_j));
}
boundary_i = geometry->nodes->GetPhysicalBoundary(iPoint);
boundary_j = geometry->nodes->GetPhysicalBoundary(jPoint);
/*--- Both points inside the domain, or both in the boundary ---*/
/*--- iPoint inside the domain, jPoint on the boundary ---*/
if (!boundary_i || boundary_j) {
if (geometry->nodes->GetDomain(iPoint)){
for (iVar = 0; iVar< nVar; iVar++)
Und_Lapl[iVar] -= Diff[iVar];
}
}
}
}
/*--- Store the components to be communicated in the buffer. ---*/
for (iVar = 0; iVar < nVar; iVar++)
bufDSend[buf_offset+iVar] = Und_Lapl[iVar];
/*--- Rotate the momentum components of the Laplacian. ---*/
if (rotate_periodic) {
Rotate(zeros, &Und_Lapl[1], &bufDSend[buf_offset+1]);
}
break;
case PERIODIC_MAX_EIG:
/*--- Simple summation of eig calc on both periodic faces. ---*/
bufDSend[buf_offset] = base_nodes->GetLambda(iPoint);
break;
case PERIODIC_SENSOR:
/*--- For the centered schemes, the sensor must be computed
consistently using info from the entire control volume
on both sides of the periodic face. ---*/
Sensor_i = 0.0; Sensor_j = 0.0;
for (auto jPoint : geometry->nodes->GetPoints(iPoint)) {
/*--- Avoid halos and boundary points so that we don't
duplicate edges on both sides of the periodic BC. ---*/
if (!geometry->nodes->GetPeriodicBoundary(jPoint)) {
/*--- Use density instead of pressure for incomp. flows. ---*/
if ((config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE)) {
Pressure_i = base_nodes->GetDensity(iPoint);
Pressure_j = base_nodes->GetDensity(jPoint);
} else {
Pressure_i = base_nodes->GetPressure(iPoint);
Pressure_j = base_nodes->GetPressure(jPoint);
}
boundary_i = geometry->nodes->GetPhysicalBoundary(iPoint);
boundary_j = geometry->nodes->GetPhysicalBoundary(jPoint);
/*--- Both points inside domain, or both on boundary ---*/
/*--- iPoint inside the domain, jPoint on the boundary ---*/
if (!boundary_i || boundary_j) {
if (geometry->nodes->GetDomain(iPoint)) {
Sensor_i += (Pressure_j - Pressure_i);
Sensor_j += (Pressure_i + Pressure_j);
}
}
}
}
/*--- Store the sensor increments to buffer. After summing
all contributions, these will be divided. ---*/
bufDSend[buf_offset] = Sensor_i;
buf_offset++;
bufDSend[buf_offset] = Sensor_j;
break;
case PERIODIC_SOL_GG:
case PERIODIC_SOL_GG_R:
case PERIODIC_PRIM_GG:
case PERIODIC_PRIM_GG_R:
/*--- Access and rotate the partial G-G gradient. These will be
summed on both sides of the periodic faces before dividing
by the volume to complete the Green-Gauss gradient calc. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++) {
for (iDim = 0; iDim < nDim; iDim++) {
jacBlock[iVar][iDim] = gradient(iPoint, iVar, iDim);
}
}
/*--- Rotate the gradients in x,y,z space for all variables. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++) {
Rotate(zeros, jacBlock[iVar], rotBlock[iVar]);
}
/*--- Rotate the vector components of the solution. ---*/
if (rotate_periodic) {
for (iDim = 0; iDim < nDim; iDim++) {
su2double d_diDim[3] = {0.0};
for (iVar = 1; iVar < 1+nDim; ++iVar) {
d_diDim[iVar-1] = rotBlock(iVar, iDim);
}
su2double rotated[3] = {0.0};
Rotate(zeros, d_diDim, rotated);
for (iVar = 1; iVar < 1+nDim; ++iVar) {
rotBlock(iVar, iDim) = rotated[iVar-1];
}
}
}
/*--- Store the partial gradient in the buffer. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++) {
for (iDim = 0; iDim < nDim; iDim++) {
bufDSend[buf_offset+iVar*nDim+iDim] = rotBlock[iVar][iDim];
}
}
break;
case PERIODIC_SOL_LS: case PERIODIC_SOL_ULS:
case PERIODIC_SOL_LS_R: case PERIODIC_SOL_ULS_R:
case PERIODIC_PRIM_LS: case PERIODIC_PRIM_ULS:
case PERIODIC_PRIM_LS_R: case PERIODIC_PRIM_ULS_R:
/*--- For L-S gradient calculations with rotational periodicity,
we will need to rotate the x,y,z components. To make the process
easier, we choose to rotate the initial periodic point and their
neighbor points into their location on the donor marker before
computing the terms that we need to communicate. ---*/
/*--- Set a flag for unweighted or weighted least-squares. ---*/
switch(commType) {
case PERIODIC_SOL_ULS:
case PERIODIC_SOL_ULS_R:
case PERIODIC_PRIM_ULS:
case PERIODIC_PRIM_ULS_R:
weighted = false;
break;
default:
weighted = true;
break;
}
/*--- Get coordinates for the current point. ---*/
Coord_i = geometry->nodes->GetCoord(iPoint);
/*--- Get the position vector from rotation center to point. ---*/
GeometryToolbox::Distance(nDim, Coord_i, center, distance);
/*--- Compute transformed point coordinates. ---*/
Rotate(translation, distance, rotCoord_i);
/*--- Get conservative solution and rotate if necessary. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++)
rotPrim_i[iVar] = field(iPoint, iVar);
if (rotate_periodic) {
Rotate(zeros, &field(iPoint,1), &rotPrim_i[1]);
}
/*--- Inizialization of variables ---*/
Cvector.resize(ICOUNT,nDim) = su2double(0.0);
r11 = 0.0; r12 = 0.0; r22 = 0.0;
r13 = 0.0; r23_a = 0.0; r23_b = 0.0; r33 = 0.0;
for (auto jPoint : geometry->nodes->GetPoints(iPoint)) {
/*--- Avoid periodic boundary points so that we do not
duplicate edges on both sides of the periodic BC. ---*/
if (!geometry->nodes->GetPeriodicBoundary(jPoint)) {
/*--- Get coordinates for the neighbor point. ---*/
Coord_j = geometry->nodes->GetCoord(jPoint);
/*--- Get the position vector from rotation center. ---*/
GeometryToolbox::Distance(nDim, Coord_j, center, distance);
/*--- Compute transformed point coordinates. ---*/
Rotate(translation, distance, rotCoord_j);
/*--- Get conservative solution and rotate if necessary. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++)
rotPrim_j[iVar] = field(jPoint,iVar);
if (rotate_periodic) {
Rotate(zeros, &field(jPoint,1), &rotPrim_j[1]);
}
if (weighted) {
weight = GeometryToolbox::SquaredDistance(nDim, rotCoord_j, rotCoord_i);
} else {
weight = 1.0;
}
/*--- Sumations for entries of upper triangular matrix R ---*/
if (weight != 0.0) {
r11 += ((rotCoord_j[0]-rotCoord_i[0])*
(rotCoord_j[0]-rotCoord_i[0])/weight);
r12 += ((rotCoord_j[0]-rotCoord_i[0])*
(rotCoord_j[1]-rotCoord_i[1])/weight);
r22 += ((rotCoord_j[1]-rotCoord_i[1])*
(rotCoord_j[1]-rotCoord_i[1])/weight);
if (nDim == 3) {
r13 += ((rotCoord_j[0]-rotCoord_i[0])*
(rotCoord_j[2]-rotCoord_i[2])/weight);
r23_a += ((rotCoord_j[1]-rotCoord_i[1])*
(rotCoord_j[2]-rotCoord_i[2])/weight);
r23_b += ((rotCoord_j[0]-rotCoord_i[0])*
(rotCoord_j[2]-rotCoord_i[2])/weight);
r33 += ((rotCoord_j[2]-rotCoord_i[2])*
(rotCoord_j[2]-rotCoord_i[2])/weight);
}
/*--- Entries of c:= transpose(A)*b ---*/
for (iVar = 0; iVar < ICOUNT; iVar++)
for (iDim = 0; iDim < nDim; iDim++)
Cvector(iVar,iDim) += ((rotCoord_j[iDim]-rotCoord_i[iDim])*
(rotPrim_j[iVar]-rotPrim_i[iVar])/weight);
}
}
}
/*--- We store and communicate the increments for the matching
upper triangular matrix (weights) and the r.h.s. vector.
These will be accumulated before completing the L-S gradient
calculation for each periodic point. ---*/
if (nDim == 2) {
bufDSend[buf_offset] = r11; buf_offset++;
bufDSend[buf_offset] = r12; buf_offset++;
bufDSend[buf_offset] = 0.0; buf_offset++;
bufDSend[buf_offset] = r22; buf_offset++;
}
if (nDim == 3) {
bufDSend[buf_offset] = r11; buf_offset++;
bufDSend[buf_offset] = r12; buf_offset++;
bufDSend[buf_offset] = r13; buf_offset++;
bufDSend[buf_offset] = 0.0; buf_offset++;
bufDSend[buf_offset] = r22; buf_offset++;
bufDSend[buf_offset] = r23_a; buf_offset++;
bufDSend[buf_offset] = 0.0; buf_offset++;
bufDSend[buf_offset] = r23_b; buf_offset++;
bufDSend[buf_offset] = r33; buf_offset++;
}
for (iVar = 0; iVar < ICOUNT; iVar++) {
for (iDim = 0; iDim < nDim; iDim++) {
bufDSend[buf_offset] = Cvector(iVar,iDim);
buf_offset++;
}
}
break;
case PERIODIC_LIM_PRIM_1:
case PERIODIC_LIM_SOL_1:
/*--- The first phase of the periodic limiter calculation
ensures that the proper min and max of the solution are found
among all nodes adjacent to periodic faces. ---*/
/*--- We send the min and max over "our" neighbours. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++) {
Sol_Min[iVar] = base_nodes->GetSolution_Min()(iPoint, iVar);
Sol_Max[iVar] = base_nodes->GetSolution_Max()(iPoint, iVar);
}
for (auto jPoint : geometry->nodes->GetPoints(iPoint)) {
for (iVar = 0; iVar < ICOUNT; iVar++) {
Sol_Min[iVar] = min(Sol_Min[iVar], field(jPoint, iVar));
Sol_Max[iVar] = max(Sol_Max[iVar], field(jPoint, iVar));
}
}
for (iVar = 0; iVar < ICOUNT; iVar++) {
bufDSend[buf_offset+iVar] = Sol_Min[iVar];
bufDSend[buf_offset+ICOUNT+iVar] = Sol_Max[iVar];
}
/*--- Rotate the momentum components of the min/max. ---*/
if (rotate_periodic) {
Rotate(zeros, &Sol_Min[1], &bufDSend[buf_offset+1]);
Rotate(zeros, &Sol_Max[1], &bufDSend[buf_offset+ICOUNT+1]);
}
break;
case PERIODIC_LIM_PRIM_2:
case PERIODIC_LIM_SOL_2:
/*--- The second phase of the periodic limiter calculation
ensures that the correct minimum value of the limiter is
found for a node on a periodic face and stores it. ---*/
for (iVar = 0; iVar < ICOUNT; iVar++) {
bufDSend[buf_offset+iVar] = limiter(iPoint, iVar);
}
if (rotate_periodic) {
Rotate(zeros, &limiter(iPoint,1), &bufDSend[buf_offset+1]);
}
break;
default:
SU2_MPI::Error("Unrecognized quantity for periodic communication.",
CURRENT_FUNCTION);