-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathCFVMFlowSolverBase.inl
More file actions
2974 lines (2333 loc) · 120 KB
/
CFVMFlowSolverBase.inl
File metadata and controls
2974 lines (2333 loc) · 120 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 CFVMFlowSolverBase.inl
* \brief Base class template for all FVM flow solvers.
* \version 8.1.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2024, 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/>.
*/
#pragma once
#include "../gradients/computeGradientsGreenGauss.hpp"
#include "../gradients/computeGradientsLeastSquares.hpp"
#include "../limiters/computeLimiters.hpp"
#include "../numerics_simd/CNumericsSIMD.hpp"
#include "CFVMFlowSolverBase.hpp"
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::AeroCoeffsArray::allocate(int size) {
_size = size;
CD = new su2double[size];
CL = new su2double[size];
CSF = new su2double[size];
CEff = new su2double[size];
CFx = new su2double[size];
CFy = new su2double[size];
CFz = new su2double[size];
CMx = new su2double[size];
CMy = new su2double[size];
CMz = new su2double[size];
CoPx = new su2double[size];
CoPy = new su2double[size];
CoPz = new su2double[size];
CT = new su2double[size];
CQ = new su2double[size];
CMerit = new su2double[size];
setZero();
}
template <class V, ENUM_REGIME R>
CFVMFlowSolverBase<V, R>::AeroCoeffsArray::~AeroCoeffsArray() {
delete[] CD;
delete[] CL;
delete[] CSF;
delete[] CEff;
delete[] CFx;
delete[] CFy;
delete[] CFz;
delete[] CMx;
delete[] CMy;
delete[] CMz;
delete[] CoPx;
delete[] CoPy;
delete[] CoPz;
delete[] CT;
delete[] CQ;
delete[] CMerit;
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::AeroCoeffsArray::setZero(int i) {
CD[i] = CL[i] = CSF[i] = CEff[i] = 0.0;
CFx[i] = CFy[i] = CFz[i] = CMx[i] = 0.0;
CMy[i] = CMz[i] = CoPx[i] = CoPy[i] = 0.0;
CoPz[i] = CT[i] = CQ[i] = CMerit[i] = 0.0;
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
/*--- Define some auxiliar vector related with the residual ---*/
Residual_RMS.resize(nVar,0.0);
Residual_Max.resize(nVar,0.0);
Point_Max.resize(nVar,0);
Point_Max_Coord.resize(nVar,nDim) = su2double(0.0);
/*--- Define some auxiliar vector related with the undivided lapalacian computation ---*/
if ((config.GetKind_ConvNumScheme_Flow() == SPACE_CENTERED) && (MGLevel == MESH_0)) {
iPoint_UndLapl.resize(nPointDomain);
jPoint_UndLapl.resize(nPointDomain);
}
/*--- Initialize the solution and right hand side vectors for storing
the residuals and updating the solution (always needed even for
explicit schemes). ---*/
LinSysSol.Initialize(nPoint, nPointDomain, nVar, 0.0);
LinSysRes.Initialize(nPoint, nPointDomain, nVar, 0.0);
/*--- LinSysSol will always be init to 0. ---*/
System.SetxIsZero(true);
/*--- Store the value of the characteristic primitive variables at the boundaries ---*/
AllocVectorOfMatrices(nVertex, nPrimVar, CharacPrimVar);
/*--- Store the value of the Total Pressure at the inlet BC ---*/
AllocVectorOfVectors(nVertex, Inlet_Ttotal);
/*--- Store the value of the Total Temperature at the inlet BC ---*/
AllocVectorOfVectors(nVertex, Inlet_Ptotal);
/*--- Store the value of the Flow direction at the inlet BC ---*/
AllocVectorOfMatrices(nVertex, nDim, Inlet_FlowDir);
/*--- Force definition and coefficient arrays for all of the markers ---*/
AllocVectorOfVectors(nVertex, CPressure);
AllocVectorOfVectors(nVertex, CPressureTarget);
/*--- Non dimensional aerodynamic coefficients ---*/
InvCoeff.allocate(nMarker);
MntCoeff.allocate(nMarker);
ViscCoeff.allocate(nMarker);
SurfaceInvCoeff.allocate(config.GetnMarker_Monitoring());
SurfaceMntCoeff.allocate(config.GetnMarker_Monitoring());
SurfaceViscCoeff.allocate(config.GetnMarker_Monitoring());
SurfaceCoeff.allocate(config.GetnMarker_Monitoring());
/*--- Heat flux coefficients. ---*/
HF_Visc.resize(nMarker,0.0);
MaxHF_Visc.resize(nMarker,0.0);
Surface_HF_Visc.resize(config.GetnMarker_Monitoring());
Surface_MaxHF_Visc.resize(config.GetnMarker_Monitoring());
/*--- Supersonic coefficients ---*/
CNearFieldOF_Inv.resize(nMarker,0.0);
/*--- Initializate quantities for SlidingMesh Interface ---*/
SlidingState.resize(nMarker);
SlidingStateNodes.resize(nMarker);
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) {
if (config.GetMarker_All_KindBC(iMarker) == FLUID_INTERFACE) {
SlidingState[iMarker].resize(nVertex[iMarker], nPrimVar+1) = nullptr;
SlidingStateNodes[iMarker].resize(nVertex[iMarker],0);
}
}
/*--- Heat flux in all the markers ---*/
AllocVectorOfVectors(nVertex, HeatFlux);
AllocVectorOfVectors(nVertex, HeatFluxTarget);
/*--- Y plus in all the markers ---*/
AllocVectorOfVectors(nVertex, YPlus);
/*--- U Tau in all the markers ---*/
AllocVectorOfVectors(nVertex, UTau);
/*--- wall eddy viscosity in all the markers ---*/
AllocVectorOfVectors(nVertex, EddyViscWall);
/*--- Skin friction in all the markers ---*/
AllocVectorOfMatrices(nVertex, nDim, CSkinFriction);
/*--- Wall Shear Stress in all the markers ---*/
AllocVectorOfVectors(nVertex, WallShearStress);
/*--- Store the values of the temperature and the heat flux density at the boundaries,
used for coupling with a solid donor cell ---*/
constexpr auto nHeatConjugateVar = 4u;
AllocVectorOfMatrices(nVertex, nHeatConjugateVar, HeatConjugateVar, config.GetTemperature_FreeStreamND());
if (MGLevel == MESH_0) {
auto nSolidVertex = nVertex;
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++)
if (!config.GetSolid_Wall(iMarker))
nSolidVertex[iMarker] = 0;
AllocVectorOfMatrices(nSolidVertex, nDim, VertexTraction);
if (config.GetDiscrete_Adjoint()) AllocVectorOfMatrices(nSolidVertex, nDim, VertexTractionAdjoint);
}
/*--- Initialize the BGS residuals in FSI problems. ---*/
if (config.GetMultizone_Residual()) {
Residual_BGS.resize(nVar,1.0);
Residual_Max_BGS.resize(nVar,1.0);
Point_Max_BGS.resize(nVar,0);
Point_Max_Coord_BGS.resize(nVar,nDim) = su2double(0.0);
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::AllocateTerribleLegacyTemporaryVariables() {
/*--- Define some auxiliary vectors related to the residual ---*/
Residual = new su2double[nVar]();
Res_Conv = new su2double[nVar]();
Res_Visc = new su2double[nVar]();
Res_Sour = new su2double[nVar]();
/*--- Define some auxiliary vectors related to the solution ---*/
Solution = new su2double[nVar]();
Solution_i = new su2double[nVar]();
Solution_j = new su2double[nVar]();
/*--- Define some auxiliary vectors related to the geometry ---*/
Vector = new su2double[nDim]();
Vector_i = new su2double[nDim]();
Vector_j = new su2double[nDim]();
/*--- Jacobian temporaries. ---*/
Jacobian_i = new su2double*[nVar];
Jacobian_j = new su2double*[nVar];
for (auto iVar = 0u; iVar < nVar; iVar++) {
Jacobian_i[iVar] = new su2double[nVar];
Jacobian_j[iVar] = new su2double[nVar];
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::CommunicateInitialState(CGeometry* geometry, const CConfig* config) {
/*--- Define solver parameters needed for execution of destructor ---*/
space_centered = (config->GetKind_ConvNumScheme_Flow() == SPACE_CENTERED);
euler_implicit = (config->GetKind_TimeIntScheme_Flow() == EULER_IMPLICIT);
least_squares = (config->GetKind_Gradient_Method() == WEIGHTED_LEAST_SQUARES);
/*--- Communicate and store volume and the number of neighbors for
any dual CVs that lie on on periodic markers. ---*/
for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic() / 2; iPeriodic++) {
InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_VOLUME);
CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_VOLUME);
InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_NEIGHBORS);
CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_NEIGHBORS);
}
SetImplicitPeriodic(euler_implicit);
if (MGLevel == MESH_0) SetRotatePeriodic(true);
/*--- Perform the MPI communication of the solution ---*/
InitiateComms(geometry, config, MPI_QUANTITIES::SOLUTION);
CompleteComms(geometry, config, MPI_QUANTITIES::SOLUTION);
/*--- Store the initial CFL number for all grid points. ---*/
const auto CFL = config->GetCFL(MGLevel);
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
nodes->SetLocalCFL(iPoint, CFL);
}
Min_CFL_Local = CFL;
Max_CFL_Local = CFL;
Avg_CFL_Local = CFL;
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::HybridParallelInitialization(const CConfig& config, CGeometry& geometry) {
#ifdef HAVE_OMP
/*--- Get the edge coloring. If the expected parallel efficiency becomes too low setup the
* reducer strategy. Where one loop is performed over edges followed by a point loop to
* sum the fluxes for each cell and set the diagonal of the system matrix. ---*/
su2double parallelEff = 1.0;
#ifdef CODI_REVERSE_TYPE
/*--- For the discrete adjoint, the reducer strategy is costly. Prefer coloring, possibly with reduced edge color
* group size. Find the maximum edge color group size that yields an efficient coloring. Also, allow larger numbers
* of colors. ---*/
const bool relax = config.GetEdgeColoringRelaxDiscAdj();
const auto& coloring = geometry.GetEdgeColoring(¶llelEff, relax);
#else
const auto& coloring = geometry.GetEdgeColoring(¶llelEff);
#endif
/*--- The decision to use the strategy is local to each rank. ---*/
ReducerStrategy = parallelEff < COLORING_EFF_THRESH;
/*--- When using the reducer force a single color to reduce the color loop overhead. ---*/
if (ReducerStrategy && (coloring.getOuterSize() > 1)) geometry.SetNaturalEdgeColoring();
if (!coloring.empty()) {
/*--- If the reducer strategy is used we are not constrained by group
* size as we have no other edge loops in the Euler/NS solvers. ---*/
auto groupSize = ReducerStrategy ? 1ul : geometry.GetEdgeColorGroupSize();
auto nColor = coloring.getOuterSize();
EdgeColoring.reserve(nColor);
for (auto iColor = 0ul; iColor < nColor; ++iColor)
EdgeColoring.emplace_back(coloring.innerIdx(iColor), coloring.getNumNonZeros(iColor), groupSize);
}
/*--- If the reducer strategy is not being forced (by EDGE_COLORING_GROUP_SIZE=0) print some messages. ---*/
if (config.GetEdgeColoringGroupSize() != 1 << 30) {
su2double minEff = 1.0;
SU2_MPI::Reduce(¶llelEff, &minEff, 1, MPI_DOUBLE, MPI_MIN, MASTER_NODE, SU2_MPI::GetComm());
int tmp = ReducerStrategy, numRanksUsingReducer = 0;
SU2_MPI::Reduce(&tmp, &numRanksUsingReducer, 1, MPI_INT, MPI_SUM, MASTER_NODE, SU2_MPI::GetComm());
if (minEff < COLORING_EFF_THRESH) {
cout << "WARNING: On " << numRanksUsingReducer << " MPI ranks the coloring efficiency was less than "
<< COLORING_EFF_THRESH << " (min value was " << minEff << ").\n"
<< " Those ranks will now use a fallback strategy, better performance may be possible\n"
<< " with a different value of config option EDGE_COLORING_GROUP_SIZE (default 512)."
#ifdef HAVE_OPDI
<< "\n The memory usage of the discrete adjoint solver is higher when using the fallback."
#endif
<< endl;
} else {
if (SU2_MPI::GetRank() == MASTER_NODE) {
cout << "All ranks use edge coloring." << endl;
}
}
const su2double coloredParallelEff = ReducerStrategy ? 1.0 : parallelEff;
su2double minColoredParallelEff = 1.0;
SU2_MPI::Reduce(&coloredParallelEff, &minColoredParallelEff, 1, MPI_DOUBLE, MPI_MIN, MASTER_NODE, SU2_MPI::GetComm());
const unsigned long coloredNumColors = ReducerStrategy ? 0 : coloring.getOuterSize();
unsigned long maxColoredNumColors = 0;
SU2_MPI::Reduce(&coloredNumColors, &maxColoredNumColors, 1, MPI_UNSIGNED_LONG, MPI_MAX, MASTER_NODE, SU2_MPI::GetComm());
const unsigned long coloredEdgeColorGroupSize = ReducerStrategy ? 1 << 30 : geometry.GetEdgeColorGroupSize();
unsigned long minColoredEdgeColorGroupSize = 1 << 30;
SU2_MPI::Reduce(&coloredEdgeColorGroupSize, &minColoredEdgeColorGroupSize, 1, MPI_UNSIGNED_LONG, MPI_MIN, MASTER_NODE, SU2_MPI::GetComm());
if (SU2_MPI::GetRank() == MASTER_NODE && numRanksUsingReducer != SU2_MPI::GetSize()) {
cout << "Among the ranks that use edge coloring,\n"
<< " the minimum efficiency is " << minColoredParallelEff << ",\n"
<< " the maximum number of colors is " << maxColoredNumColors << ",\n"
<< " the minimum edge color group size is " << minColoredEdgeColorGroupSize << "." << endl;
}
}
if (ReducerStrategy) EdgeFluxes.Initialize(geometry.GetnEdge(), geometry.GetnEdge(), nVar, nullptr);
omp_chunk_size = computeStaticChunkSize(nPoint, omp_get_max_threads(), OMP_MAX_SIZE);
#else
EdgeColoring[0] = DummyGridColor<>(geometry.GetnEdge());
#endif
}
template <class V, ENUM_REGIME R>
CFVMFlowSolverBase<V, R>::~CFVMFlowSolverBase() {
for (auto& mat : SlidingState) {
for (auto ptr : mat) delete [] ptr;
}
delete nodes;
delete edgeNumerics;
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::SetPrimitive_Gradient_GG(CGeometry* geometry, const CConfig* config,
bool reconstruction) {
const auto& primitives = nodes->GetPrimitive();
auto& gradient = reconstruction ? nodes->GetGradient_Reconstruction() : nodes->GetGradient_Primitive();
const auto comm = reconstruction? MPI_QUANTITIES::PRIMITIVE_GRAD_REC : MPI_QUANTITIES::PRIMITIVE_GRADIENT;
const auto commPer = reconstruction? PERIODIC_PRIM_GG_R : PERIODIC_PRIM_GG;
computeGradientsGreenGauss(this, comm, commPer, *geometry, *config, primitives, 0, nPrimVarGrad, prim_idx.Velocity(), gradient);
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::SetPrimitive_Gradient_LS(CGeometry* geometry, const CConfig* config,
bool reconstruction) {
/*--- Set a flag for unweighted or weighted least-squares. ---*/
bool weighted;
PERIODIC_QUANTITIES commPer;
if (reconstruction) {
weighted = (config->GetKind_Gradient_Method_Recon() == WEIGHTED_LEAST_SQUARES);
commPer = weighted? PERIODIC_PRIM_LS_R : PERIODIC_PRIM_ULS_R;
}
else {
weighted = (config->GetKind_Gradient_Method() == WEIGHTED_LEAST_SQUARES);
commPer = weighted? PERIODIC_PRIM_LS : PERIODIC_PRIM_ULS;
}
const auto& primitives = nodes->GetPrimitive();
auto& rmatrix = nodes->GetRmatrix();
auto& gradient = reconstruction ? nodes->GetGradient_Reconstruction() : nodes->GetGradient_Primitive();
const auto comm = reconstruction? MPI_QUANTITIES::PRIMITIVE_GRAD_REC : MPI_QUANTITIES::PRIMITIVE_GRADIENT;
computeGradientsLeastSquares(this, comm, commPer, *geometry, *config, weighted,
primitives, 0, nPrimVarGrad, prim_idx.Velocity(), gradient, rmatrix);
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::SetPrimitive_Limiter(CGeometry* geometry, const CConfig* config) {
const auto kindLimiter = config->GetKind_SlopeLimit_Flow();
const auto& primitives = nodes->GetPrimitive();
const auto& gradient = nodes->GetGradient_Reconstruction();
auto& primMin = nodes->GetSolution_Min();
auto& primMax = nodes->GetSolution_Max();
auto& limiter = nodes->GetLimiter_Primitive();
computeLimiters(kindLimiter, this, MPI_QUANTITIES::PRIMITIVE_LIMITER, PERIODIC_LIM_PRIM_1, PERIODIC_LIM_PRIM_2, *geometry, *config, 0,
nPrimVarGrad, primitives, gradient, primMin, primMax, limiter);
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::Viscous_Residual_impl(unsigned long iEdge, CGeometry *geometry, CSolver **solver_container,
CNumerics *numerics, CConfig *config) {
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
const bool tkeNeeded = (config->GetKind_Turb_Model() == TURB_MODEL::SST);
CVariable* turbNodes = nullptr;
if (tkeNeeded) turbNodes = solver_container[TURB_SOL]->GetNodes();
/*--- Points, coordinates and normal vector in edge ---*/
auto iPoint = geometry->edges->GetNode(iEdge,0);
auto jPoint = geometry->edges->GetNode(iEdge,1);
numerics->SetCoord(geometry->nodes->GetCoord(iPoint),
geometry->nodes->GetCoord(jPoint));
numerics->SetNormal(geometry->edges->GetNormal(iEdge));
/*--- Primitive and secondary variables. ---*/
numerics->SetPrimitive(nodes->GetPrimitive(iPoint),
nodes->GetPrimitive(jPoint));
numerics->SetSecondary(nodes->GetSecondary(iPoint),
nodes->GetSecondary(jPoint));
/*--- Gradients. ---*/
numerics->SetPrimVarGradient(nodes->GetGradient_Primitive(iPoint),
nodes->GetGradient_Primitive(jPoint));
/*--- Turbulent kinetic energy. ---*/
if (tkeNeeded)
numerics->SetTurbKineticEnergy(turbNodes->GetSolution(iPoint,0),
turbNodes->GetSolution(jPoint,0));
/*--- Wall shear stress values (wall functions) ---*/
numerics->SetTau_Wall(nodes->GetTau_Wall(iPoint),
nodes->GetTau_Wall(jPoint));
/*--- Compute and update residual ---*/
auto residual = numerics->ComputeResidual(config);
if (ReducerStrategy) {
EdgeFluxes.SubtractBlock(iEdge, residual);
if (implicit)
Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j);
}
else {
LinSysRes.SubtractBlock(iPoint, residual);
LinSysRes.AddBlock(jPoint, residual);
if (implicit)
Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j);
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::ComputeVerificationError(CGeometry* geometry, CConfig* config) {
/*--- The errors only need to be computed on the finest grid. ---*/
if (MGLevel != MESH_0) return;
/*--- If this is a verification case, we can compute the global
error metrics by using the difference between the local error
and the known solution at each DOF. This is then collected into
RMS (L2) and maximum (Linf) global error norms. From these
global measures, one can compute the order of accuracy. ---*/
bool write_heads =
((((config->GetInnerIter() % (config->GetScreen_Wrt_Freq(2) * 40)) == 0) && (config->GetInnerIter() != 0)) ||
(config->GetInnerIter() == 1));
if (!write_heads) return;
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
/*--- Check if there actually is an exact solution for this
verification case, if computed at all. ---*/
if (VerificationSolution && VerificationSolution->ExactSolutionKnown()) {
/*--- Get the physical time if necessary. ---*/
su2double time = 0.0;
if (config->GetTime_Marching() != TIME_MARCHING::STEADY) time = config->GetPhysicalTime();
/*--- Reset the global error measures to zero. ---*/
for (unsigned short iVar = 0; iVar < nVar; iVar++) {
VerificationSolution->SetError_RMS(iVar, 0.0);
VerificationSolution->SetError_Max(iVar, 0.0, 0);
}
/*--- Loop over all owned points. ---*/
for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) {
/* Set the pointers to the coordinates and solution of this DOF. */
const su2double* coor = geometry->nodes->GetCoord(iPoint);
su2double* solDOF = nodes->GetSolution(iPoint);
/* Get local error from the verification solution class. */
vector<su2double> error(nVar, 0.0);
VerificationSolution->GetLocalError(coor, time, solDOF, error.data());
/* Increment the global error measures */
for (unsigned short iVar = 0; iVar < nVar; iVar++) {
VerificationSolution->AddError_RMS(iVar, error[iVar] * error[iVar]);
VerificationSolution->AddError_Max(iVar, fabs(error[iVar]), geometry->nodes->GetGlobalIndex(iPoint),
geometry->nodes->GetCoord(iPoint));
}
}
/* Finalize the calculation of the global error measures. */
VerificationSolution->SetVerificationError(geometry->GetGlobal_nPointDomain(), config);
/*--- Screen output of the error metrics. This can be improved
once the new output classes are in place. ---*/
PrintVerificationError(config);
}
}
END_SU2_OMP_SAFE_GLOBAL_ACCESS
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::ComputeUnderRelaxationFactor(const CConfig* config) {
/* Loop over the solution update given by relaxing the linear
system for this nonlinear iteration. */
const su2double allowableRatio = 0.2;
SU2_OMP_FOR_STAT(omp_chunk_size)
for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) {
su2double localUnderRelaxation = 1.0;
for (unsigned short iVar = 0; iVar < nVar; iVar++) {
/* We impose a limit on the maximum percentage that the
density and energy can change over a nonlinear iteration. */
if ((iVar == 0) || (iVar == nVar - 1)) {
const unsigned long index = iPoint * nVar + iVar;
su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS);
if (ratio > allowableRatio) {
localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation);
}
}
}
/* Threshold the relaxation factor in the event that there is
a very small value. This helps avoid catastrophic crashes due
to non-realizable states by canceling the update. */
if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0;
/* Store the under-relaxation factor for this point. */
nodes->SetUnderRelaxation(iPoint, localUnderRelaxation);
}
END_SU2_OMP_FOR
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::ImplicitEuler_Iteration(CGeometry *geometry, CSolver**, CConfig *config) {
PrepareImplicitIteration(geometry, nullptr, config);
/*--- Solve or smooth the linear system. ---*/
SU2_OMP_FOR_(schedule(static,OMP_MIN_SIZE) SU2_NOWAIT)
for (unsigned long iPoint = nPointDomain; iPoint < nPoint; iPoint++) {
LinSysRes.SetBlock_Zero(iPoint);
LinSysSol.SetBlock_Zero(iPoint);
}
END_SU2_OMP_FOR
auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config);
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
SetIterLinSolver(iter);
SetResLinSolver(System.GetResidual());
}
END_SU2_OMP_SAFE_GLOBAL_ACCESS
CompleteImplicitIteration(geometry, nullptr, config);
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::ComputeVorticityAndStrainMag(const CConfig& config, const CGeometry *geometry, unsigned short iMesh) {
auto& StrainMag = nodes->GetStrainMag();
ompMasterAssignBarrier(StrainMag_Max,0.0, Omega_Max,0.0);
su2double strainMax = 0.0, omegaMax = 0.0;
SU2_OMP_FOR_STAT(omp_chunk_size)
for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) {
const auto VelocityGradient = nodes->GetVelocityGradient(iPoint);
auto Vorticity = nodes->GetVorticity(iPoint);
/*--- Vorticity ---*/
Vorticity[0] = 0.0;
Vorticity[1] = 0.0;
Vorticity[2] = VelocityGradient(1,0)-VelocityGradient(0,1);
if (nDim == 3) {
Vorticity[0] = VelocityGradient(2,1)-VelocityGradient(1,2);
Vorticity[1] = -(VelocityGradient(2,0)-VelocityGradient(0,2));
}
/*--- Strain Magnitude ---*/
const su2double vy = nodes->GetVelocity(iPoint, 1);
const su2double y = geometry->nodes->GetCoord(iPoint, 1);
AD::StartPreacc();
AD::SetPreaccIn(VelocityGradient, nDim, nDim);
AD::SetPreaccIn(vy, y);
StrainMag(iPoint) = 0.0;
/*--- Add diagonal part ---*/
for (unsigned long iDim = 0; iDim < nDim; iDim++) {
StrainMag(iPoint) += pow(VelocityGradient(iDim, iDim), 2);
}
if (config.GetAxisymmetric() && y > EPS) {
StrainMag(iPoint) += pow(vy / y, 2);
}
/*--- Add off diagonals ---*/
StrainMag(iPoint) += 2.0*pow(0.5*(VelocityGradient(0,1) + VelocityGradient(1,0)), 2);
if (nDim == 3) {
StrainMag(iPoint) += 2.0*pow(0.5*(VelocityGradient(0,2) + VelocityGradient(2,0)), 2);
StrainMag(iPoint) += 2.0*pow(0.5*(VelocityGradient(1,2) + VelocityGradient(2,1)), 2);
}
StrainMag(iPoint) = sqrt(2.0*StrainMag(iPoint));
AD::SetPreaccOut(StrainMag(iPoint));
/*--- Max is not differentiable, so we not register them for preacc. ---*/
strainMax = max(strainMax, StrainMag(iPoint));
omegaMax = max(omegaMax, GeometryToolbox::Norm(3, Vorticity));
AD::EndPreacc();
}
END_SU2_OMP_FOR
if ((iMesh == MESH_0) && (config.GetComm_Level() == COMM_FULL)) {
SU2_OMP_CRITICAL {
StrainMag_Max = max(StrainMag_Max, strainMax);
Omega_Max = max(Omega_Max, omegaMax);
}
END_SU2_OMP_CRITICAL
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
{
su2double MyOmega_Max = Omega_Max;
su2double MyStrainMag_Max = StrainMag_Max;
SU2_MPI::Allreduce(&MyStrainMag_Max, &StrainMag_Max, 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm());
SU2_MPI::Allreduce(&MyOmega_Max, &Omega_Max, 1, MPI_DOUBLE, MPI_MAX, SU2_MPI::GetComm());
}
END_SU2_OMP_SAFE_GLOBAL_ACCESS
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::SetInletAtVertex(const su2double* val_inlet, unsigned short iMarker,
unsigned long iVertex) {
/*--- Alias positions within inlet file for readability ---*/
unsigned short T_position = nDim;
unsigned short P_position = nDim + 1;
unsigned short FlowDir_position = nDim + 2;
/*--- Note that it is not necessary anymore to use normalized normals for the inlet velocity ---*/
/*--- Store the values in our inlet data structures. ---*/
Inlet_Ttotal[iMarker][iVertex] = val_inlet[T_position];
Inlet_Ptotal[iMarker][iVertex] = val_inlet[P_position];
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
Inlet_FlowDir[iMarker][iVertex][iDim] = val_inlet[FlowDir_position + iDim];
}
}
template <class V, ENUM_REGIME R>
su2double CFVMFlowSolverBase<V, R>::GetInletAtVertex(unsigned short iMarker, unsigned long iVertex,
const CGeometry* geometry, su2double* val_inlet) const {
const auto T_position = nDim;
const auto P_position = nDim + 1;
const auto FlowDir_position = nDim + 2;
val_inlet[T_position] = Inlet_Ttotal[iMarker][iVertex];
val_inlet[P_position] = Inlet_Ptotal[iMarker][iVertex];
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
val_inlet[FlowDir_position + iDim] = Inlet_FlowDir[iMarker][iVertex][iDim];
}
/*--- Compute boundary face area for this vertex. ---*/
su2double Normal[MAXNDIM] = {0.0};
geometry->vertex[iMarker][iVertex]->GetNormal(Normal);
return GeometryToolbox::Norm(nDim, Normal);
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::SetUniformInlet(const CConfig* config, unsigned short iMarker) {
if (config->GetMarker_All_KindBC(iMarker) == INLET_FLOW) {
const string Marker_Tag = config->GetMarker_All_TagBound(iMarker);
const su2double p_total = config->GetInletPtotal(Marker_Tag);
const su2double t_total = config->GetInletTtotal(Marker_Tag);
const su2double* flow_dir = config->GetInletFlowDir(Marker_Tag);
for (unsigned long iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) {
Inlet_Ttotal[iMarker][iVertex] = t_total;
Inlet_Ptotal[iMarker][iVertex] = p_total;
for (unsigned short iDim = 0; iDim < nDim; iDim++) Inlet_FlowDir[iMarker][iVertex][iDim] = flow_dir[iDim];
}
} else if (config->GetMarker_All_KindBC(iMarker) == SUPERSONIC_INLET) {
const string Marker_Tag = config->GetMarker_All_TagBound(iMarker);
const su2double p = config->GetInlet_Pressure(Marker_Tag);
const su2double t = config->GetInlet_Temperature(Marker_Tag);
const su2double* vel = config->GetInlet_Velocity(Marker_Tag);
for (unsigned long iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) {
Inlet_Ttotal[iMarker][iVertex] = t;
Inlet_Ptotal[iMarker][iVertex] = p;
for (unsigned short iDim = 0; iDim < nDim; iDim++) Inlet_FlowDir[iMarker][iVertex][iDim] = vel[iDim];
}
} else {
/*--- For now, non-inlets just get set to zero. In the future, we
can do more customization for other boundary types here. ---*/
for (unsigned long iVertex = 0; iVertex < nVertex[iMarker]; iVertex++) {
Inlet_Ttotal[iMarker][iVertex] = 0.0;
Inlet_Ptotal[iMarker][iVertex] = 0.0;
for (unsigned short iDim = 0; iDim < nDim; iDim++) Inlet_FlowDir[iMarker][iVertex][iDim] = 0.0;
}
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::UpdateCustomBoundaryConditions(
CGeometry** geometry_container, CSolver*** solver_container, CConfig *config) {
struct {
const CSolver* fine_solver{nullptr};
CSolver* coarse_solver{nullptr};
unsigned short marker{0};
unsigned short var{0};
su2double Get(unsigned long vertex) const {
if (var == 0) {
return fine_solver->GetInletTtotal(marker, vertex);
} else if (var == 1) {
return fine_solver->GetInletPtotal(marker, vertex);
}
return fine_solver->GetInletFlowDir(marker, vertex, var - 2);
}
void Set(unsigned long vertex, const su2double& val) const {
if (var == 0) {
coarse_solver->SetInletTtotal(marker, vertex, val);
} else if (var == 1) {
coarse_solver->SetInletPtotal(marker, vertex, val);
}
coarse_solver->SetInletFlowDir(marker, vertex, var - 2, val);
}
} inlet_values;
for (auto mg_coarse = 1u; mg_coarse <= config->GetnMGLevels(); ++mg_coarse) {
const auto mg_fine = mg_coarse - 1;
inlet_values.fine_solver = solver_container[mg_fine][FLOW_SOL];
inlet_values.coarse_solver = solver_container[mg_coarse][FLOW_SOL];
for (auto marker = 0u; marker < config->GetnMarker_All(); ++marker) {
if (config->GetMarker_All_KindBC(marker) != INLET_FLOW) continue;
inlet_values.marker = marker;
for (inlet_values.var = 0; inlet_values.var < 2 + nDim; ++inlet_values.var) {
geometry_container[mg_coarse]->SetMultiGridMarkerQuantity(geometry_container[mg_fine], marker, inlet_values);
}
}
}
}
template <class V, ENUM_REGIME R>
void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver ***solver, CConfig *config, int iter,
bool update_geo, su2double* SolutionRestart,
unsigned short nVar_Restart) {
/*--- Restart the solution from file information ---*/
const string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", iter);
const bool static_fsi = ((config->GetTime_Marching() == TIME_MARCHING::STEADY) && config->GetFSI_Simulation());
/*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
if (nVar_Restart == 0) nVar_Restart = nVar;
/*--- Skip coordinates ---*/
unsigned short skipVars = nDim;
/*--- Read the restart data from either an ASCII or binary SU2 file. ---*/
if (config->GetRead_Binary_Restart()) {
Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename);
} else {
Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename);
}
bool steady_restart = config->GetSteadyRestart();
if (update_geo && dynamic_grid) {
auto notFound = fields.end();
if (find(fields.begin(), notFound, string("\"Grid_Velocity_x\"")) == notFound) {
if (rank == MASTER_NODE)
cout << "\nWARNING: The restart file does not contain grid velocities, these will be set to zero.\n" << endl;
steady_restart = true;
}
}
/*--- Load data from the restart into correct containers. ---*/
unsigned long counter = 0;
for (auto iPoint_Global = 0ul; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) {
/*--- Retrieve local index. If this node from the restart file lives
on the current processor, we will load and instantiate the vars. ---*/
const auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global);
if (iPoint_Local > -1) {
/*--- We need to store this point's data, so jump to the correct
offset in the buffer of data from the restart file and load it. ---*/
auto index = counter * Restart_Vars[1] + skipVars;
if (SolutionRestart == nullptr) {
for (auto iVar = 0u; iVar < nVar_Restart; iVar++)
nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]);
}
else {
/*--- Used as buffer, allows defaults for nVar > nVar_Restart. ---*/
for (auto iVar = 0u; iVar < nVar_Restart; iVar++)
SolutionRestart[iVar] = Restart_Data[index + iVar];
nodes->SetSolution(iPoint_Local, SolutionRestart);
}
/*--- For dynamic meshes, read in and store the
grid coordinates and grid velocities for each node. ---*/
if (dynamic_grid && update_geo) {
/*--- Read in the next 2 or 3 variables which are the grid velocities ---*/
/*--- If we are restarting the solution from a previously computed static calculation (no grid movement) ---*/
/*--- the grid velocities are set to 0. This is useful for FSI computations ---*/
/*--- Rewind the index to retrieve the Coords. ---*/
index = counter * Restart_Vars[1];
const auto* Coord = &Restart_Data[index];
su2double GridVel[MAXNDIM] = {0.0};
if (!steady_restart) {
/*--- Move the index forward to get the grid velocities. ---*/
index += skipVars + nVar_Restart + config->GetnTurbVar();
for (auto iDim = 0u; iDim < nDim; iDim++) { GridVel[iDim] = Restart_Data[index+iDim]; }
}
for (auto iDim = 0u; iDim < nDim; iDim++) {
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
geometry[MESH_0]->nodes->SetGridVel(iPoint_Local, iDim, GridVel[iDim]);
}
}
/*--- For static FSI problems, grid_movement is 0 but we need to read in and store the
grid coordinates for each node (but not the grid velocities, as there are none). ---*/
if (static_fsi && update_geo) {
/*--- Rewind the index to retrieve the Coords. ---*/
index = counter*Restart_Vars[1];
const auto* Coord = &Restart_Data[index];
for (auto iDim = 0u; iDim < nDim; iDim++) {
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
}
}
/*--- Increment the overall counter for how many points have been loaded. ---*/
counter++;
}
}
/*--- Detect a wrong solution file ---*/
if (counter != nPointDomain) {
SU2_MPI::Error(string("The solution file ") + restart_filename + string(" does not match with the mesh file.\n") +
string("This can be caused by empty lines at the end of the file."), CURRENT_FUNCTION);
}
}
END_SU2_OMP_SAFE_GLOBAL_ACCESS
/*--- Update the geometry for flows on deforming meshes. ---*/
if ((dynamic_grid || static_fsi) && update_geo) {
CGeometry::UpdateGeometry(geometry, config);
if (dynamic_grid) {
for (auto iMesh = 0u; iMesh <= config->GetnMGLevels(); iMesh++) {
/*--- Compute the grid velocities on the coarser levels. ---*/
if (iMesh) geometry[iMesh]->SetRestricted_GridVelocity(geometry[iMesh - 1]);
else {
geometry[MESH_0]->InitiateComms(geometry[MESH_0], config, MPI_QUANTITIES::GRID_VELOCITY);
geometry[MESH_0]->CompleteComms(geometry[MESH_0], config, MPI_QUANTITIES::GRID_VELOCITY);
}
}
}
}
/*--- Communicate the loaded solution on the fine grid before we transfer
it down to the coarse levels. We also call the preprocessing routine
on the fine level in order to have all necessary quantities updated,
especially if this is a turbulent simulation (eddy viscosity). ---*/
solver[MESH_0][FLOW_SOL]->InitiateComms(geometry[MESH_0], config, MPI_QUANTITIES::SOLUTION);
solver[MESH_0][FLOW_SOL]->CompleteComms(geometry[MESH_0], config, MPI_QUANTITIES::SOLUTION);
/*--- For turbulent/species simulations the flow preprocessing is done by the turbulence/species solver
* after it loads its variables (they are needed to compute flow primitives). In case turbulence and species, the
* species solver does all the Pre-/Postprocessing. ---*/
if (config->GetKind_Turb_Model() == TURB_MODEL::NONE &&
config->GetKind_Species_Model() == SPECIES_MODEL::NONE) {
solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, RUNTIME_FLOW_SYS, false);
}
/*--- Interpolate the solution down to the coarse multigrid levels ---*/
for (auto iMesh = 1u; iMesh <= config->GetnMGLevels(); iMesh++) {
MultigridRestriction(*geometry[iMesh - 1], solver[iMesh - 1][FLOW_SOL]->GetNodes()->GetSolution(),
*geometry[iMesh], solver[iMesh][FLOW_SOL]->GetNodes()->GetSolution());
solver[iMesh][FLOW_SOL]->InitiateComms(geometry[iMesh], config, MPI_QUANTITIES::SOLUTION);
solver[iMesh][FLOW_SOL]->CompleteComms(geometry[iMesh], config, MPI_QUANTITIES::SOLUTION);
if (config->GetKind_Turb_Model() == TURB_MODEL::NONE &&
config->GetKind_Species_Model() == SPECIES_MODEL::NONE) {
solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, false);
}
}
/*--- Update the old geometry (coordinates n and n-1) in dual time-stepping strategy. ---*/
const bool dual_time = ((config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST) ||
(config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND));
if (dual_time && config->GetGrid_Movement() && !config->GetDeform_Mesh() &&
(config->GetKind_GridMovement() != RIGID_MOTION)) {
Restart_OldGeometry(geometry[MESH_0], config);
}
/*--- Go back to single threaded execution. ---*/
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
{
/*--- Delete the class memory that is used to load the restart. ---*/
Restart_Vars = decltype(Restart_Vars){};