-
Notifications
You must be signed in to change notification settings - Fork 975
Expand file tree
/
Copy pathCFlowOutput.cpp
More file actions
4113 lines (3493 loc) · 196 KB
/
CFlowOutput.cpp
File metadata and controls
4113 lines (3493 loc) · 196 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 CFlowOutput.cpp
* \brief Common functions for flow output.
* \author R. Sanchez
* \version 8.3.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2025, 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 <sstream>
#include <string>
#include <sstream>
#include <iomanip>
#include "../../include/output/CFlowOutput.hpp"
#include "../../../Common/include/geometry/CGeometry.hpp"
#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
#include "../../include/solvers/CSolver.hpp"
#include "../../include/variables/CPrimitiveIndices.hpp"
#include "../../include/fluid/CCoolProp.hpp"
CFlowOutput::CFlowOutput(const CConfig *config, unsigned short nDim, bool fem_output) :
CFVMOutput(config, nDim, fem_output),
lastInnerIter(curInnerIter) {
}
// The "AddHistoryOutput(" must not be split over multiple lines to ensure proper python parsing
// clang-format off
void CFlowOutput::AddAnalyzeSurfaceOutput(const CConfig *config){
/// DESCRIPTION: Average mass flow
AddHistoryOutput("SURFACE_MASSFLOW", "Avg_Massflow", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average mass flow on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Mach number
AddHistoryOutput("SURFACE_MACH", "Avg_Mach", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average mach number on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Temperature
AddHistoryOutput("SURFACE_STATIC_TEMPERATURE","Avg_Temp", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average temperature on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Pressure
AddHistoryOutput("SURFACE_STATIC_PRESSURE", "Avg_Press", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average pressure on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Density
AddHistoryOutput("AVG_DENSITY", "Avg_Density", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average density on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Enthalpy
AddHistoryOutput("AVG_ENTHALPY", "Avg_Enthalpy", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average enthalpy on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average velocity in normal direction of the surface
AddHistoryOutput("AVG_NORMALVEL", "Avg_NormalVel", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average normal velocity on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Flow uniformity
AddHistoryOutput("SURFACE_UNIFORMITY", "Uniformity", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total flow uniformity on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Secondary strength
AddHistoryOutput("SURFACE_SECONDARY", "Secondary_Strength", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total secondary strength on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Momentum distortion
AddHistoryOutput("SURFACE_MOM_DISTORTION", "Momentum_Distortion", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total momentum distortion on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Secondary over uniformity
AddHistoryOutput("SURFACE_SECOND_OVER_UNIFORM","Secondary_Over_Uniformity",ScreenOutputFormat::SCIENTIFIC,"FLOW_COEFF", "Total secondary over uniformity on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average total temperature
AddHistoryOutput("SURFACE_TOTAL_TEMPERATURE","Avg_TotalTemp", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average total temperature all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average total pressure
AddHistoryOutput("SURFACE_TOTAL_PRESSURE", "Avg_TotalPress", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total average total pressure on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Pressure drop
if (config->GetnMarker_Analyze() >= 2) {
AddHistoryOutput("SURFACE_PRESSURE_DROP", "Pressure_Drop", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF", "Total pressure drop on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
} else if (rank == MASTER_NODE) {
cout << "\nWARNING: SURFACE_PRESSURE_DROP can only be computed for at least 2 surfaces (outlet, inlet, ...)\n" << endl;
}
if (config->GetKind_Species_Model() == SPECIES_MODEL::SPECIES_TRANSPORT) {
/// DESCRIPTION: Average Species
for (unsigned short iVar = 0; iVar < config->GetnSpecies(); iVar++) {
AddHistoryOutput("SURFACE_SPECIES_" + std::to_string(iVar), "Avg_Species_" + std::to_string(iVar), ScreenOutputFormat::FIXED, "SPECIES_COEFF", "Total average species " + std::to_string(iVar) + " on all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
}
/// DESCRIPTION: Species Variance
AddHistoryOutput("SURFACE_SPECIES_VARIANCE", "Species_Variance", ScreenOutputFormat::SCIENTIFIC, "SPECIES_COEFF", "Total species variance, measure for mixing quality. On all markers set in MARKER_ANALYZE", HistoryFieldType::COEFFICIENT);
}
/// END_GROUP
/// BEGIN_GROUP: AERO_COEFF_SURF, DESCRIPTION: Surface values on non-solid markers.
vector<string> Marker_Analyze;
for (unsigned short iMarker_Analyze = 0; iMarker_Analyze < config->GetnMarker_Analyze(); iMarker_Analyze++){
Marker_Analyze.push_back(config->GetMarker_Analyze_TagBound(iMarker_Analyze));
}
/// DESCRIPTION: Average mass flow
AddHistoryOutputPerSurface("SURFACE_MASSFLOW", "Avg_Massflow", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Mach number
AddHistoryOutputPerSurface("SURFACE_MACH", "Avg_Mach", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Temperature
AddHistoryOutputPerSurface("SURFACE_STATIC_TEMPERATURE","Avg_Temp", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Pressure
AddHistoryOutputPerSurface("SURFACE_STATIC_PRESSURE", "Avg_Press", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Density
AddHistoryOutputPerSurface("AVG_DENSITY", "Avg_Density", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average Enthalpy
AddHistoryOutputPerSurface("AVG_ENTHALPY", "Avg_Enthalpy", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average velocity in normal direction of the surface
AddHistoryOutputPerSurface("AVG_NORMALVEL", "Avg_NormalVel", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Flow uniformity
AddHistoryOutputPerSurface("SURFACE_UNIFORMITY", "Uniformity", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Secondary strength
AddHistoryOutputPerSurface("SURFACE_SECONDARY", "Secondary_Strength", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Momentum distortion
AddHistoryOutputPerSurface("SURFACE_MOM_DISTORTION", "Momentum_Distortion", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Secondary over uniformity
AddHistoryOutputPerSurface("SURFACE_SECOND_OVER_UNIFORM","Secondary_Over_Uniformity",ScreenOutputFormat::SCIENTIFIC,"FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average total temperature
AddHistoryOutputPerSurface("SURFACE_TOTAL_TEMPERATURE","Avg_TotalTemp", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
/// DESCRIPTION: Average total pressure
AddHistoryOutputPerSurface("SURFACE_TOTAL_PRESSURE", "Avg_TotalPress", ScreenOutputFormat::SCIENTIFIC, "FLOW_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
if (config->GetKind_Species_Model() == SPECIES_MODEL::SPECIES_TRANSPORT) {
/// DESCRIPTION: Average Species
for (unsigned short iVar = 0; iVar < config->GetnSpecies(); iVar++) {
AddHistoryOutputPerSurface("SURFACE_SPECIES_" + std::to_string(iVar), "Avg_Species_" + std::to_string(iVar), ScreenOutputFormat::FIXED, "SPECIES_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
}
/// DESCRIPTION: Species Variance
AddHistoryOutputPerSurface("SURFACE_SPECIES_VARIANCE", "Species_Variance", ScreenOutputFormat::SCIENTIFIC, "SPECIES_COEFF_SURF", Marker_Analyze, HistoryFieldType::COEFFICIENT);
}
}
// clang-format on
void CFlowOutput::SetAnalyzeSurface(const CSolver* const*solver, const CGeometry *geometry, CConfig *config, bool output){
unsigned short iDim, iMarker, iMarker_Analyze;
unsigned long iVertex, iPoint;
su2double Mach = 0.0, Pressure, Temperature = 0.0, TotalPressure = 0.0, TotalTemperature = 0.0,
Enthalpy, Velocity[3] = {0.0}, TangVel[3], Vector[3], Velocity2, MassFlow, Density, Area,
SoundSpeed, Vn, Vn2, Vtang2, Weight = 1.0;
const su2double Gas_Constant = config->GetGas_ConstantND();
const su2double Gamma = config->GetGamma();
const unsigned short nMarker = config->GetnMarker_All();
const unsigned short nDim = geometry->GetnDim();
const unsigned short Kind_Average = config->GetKind_Average();
const bool compressible = config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE;
const bool incompressible = config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE;
const bool energy = config->GetEnergy_Equation();
const bool streamwisePeriodic = (config->GetKind_Streamwise_Periodic() != ENUM_STREAMWISE_PERIODIC::NONE);
const bool species = config->GetKind_Species_Model() == SPECIES_MODEL::SPECIES_TRANSPORT;
const auto nSpecies = config->GetnSpecies();
const bool axisymmetric = config->GetAxisymmetric();
const unsigned short nMarker_Analyze = config->GetnMarker_Analyze();
const auto flow_nodes = solver[FLOW_SOL]->GetNodes();
const CVariable* species_nodes = species ? solver[SPECIES_SOL]->GetNodes() : nullptr;
vector<su2double> Surface_MassFlow (nMarker,0.0);
vector<su2double> Surface_Mach (nMarker,0.0);
vector<su2double> Surface_Temperature (nMarker,0.0);
vector<su2double> Surface_Density (nMarker,0.0);
vector<su2double> Surface_Enthalpy (nMarker,0.0);
vector<su2double> Surface_NormalVelocity (nMarker,0.0);
vector<su2double> Surface_StreamVelocity2 (nMarker,0.0);
vector<su2double> Surface_TransvVelocity2 (nMarker,0.0);
vector<su2double> Surface_Pressure (nMarker,0.0);
vector<su2double> Surface_TotalTemperature (nMarker,0.0);
vector<su2double> Surface_TotalPressure (nMarker,0.0);
vector<su2double> Surface_VelocityIdeal (nMarker,0.0);
vector<su2double> Surface_Area (nMarker,0.0);
vector<su2double> Surface_MassFlow_Abs (nMarker,0.0);
su2activematrix Surface_Species(nMarker, nSpecies);
Surface_Species = su2double(0.0);
su2double Tot_Surface_MassFlow = 0.0;
su2double Tot_Surface_Mach = 0.0;
su2double Tot_Surface_Temperature = 0.0;
su2double Tot_Surface_Density = 0.0;
su2double Tot_Surface_Enthalpy = 0.0;
su2double Tot_Surface_NormalVelocity = 0.0;
su2double Tot_Surface_StreamVelocity2 = 0.0;
su2double Tot_Surface_TransvVelocity2 = 0.0;
su2double Tot_Surface_Pressure = 0.0;
su2double Tot_Surface_TotalTemperature = 0.0;
su2double Tot_Surface_TotalPressure = 0.0;
su2double Tot_Momentum_Distortion = 0.0;
su2double Tot_SecondOverUniformity = 0.0;
vector<su2double> Tot_Surface_Species(nSpecies,0.0);
/*--- Compute the numerical fan face Mach number, and the total area of the inflow ---*/
for (iMarker = 0; iMarker < nMarker; iMarker++) {
if (config->GetMarker_All_Analyze(iMarker) == YES) {
for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) {
iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
if (geometry->nodes->GetDomain(iPoint)) {
geometry->vertex[iMarker][iVertex]->GetNormal(Vector);
const su2double AxiFactor = GetAxiFactor(axisymmetric, *geometry->nodes, iPoint, iMarker);
Density = flow_nodes->GetDensity(iPoint);
Velocity2 = 0.0; Area = 0.0; MassFlow = 0.0; Vn = 0.0; Vtang2 = 0.0;
for (iDim = 0; iDim < nDim; iDim++) {
Area += (Vector[iDim] * AxiFactor) * (Vector[iDim] * AxiFactor);
Velocity[iDim] = flow_nodes->GetVelocity(iPoint,iDim);
Velocity2 += Velocity[iDim] * Velocity[iDim];
Vn += Velocity[iDim] * Vector[iDim] * AxiFactor;
MassFlow += Vector[iDim] * AxiFactor * Density * Velocity[iDim];
}
Area = sqrt (Area);
if (AxiFactor == 0.0) Vn = 0.0; else Vn /= Area;
Vn2 = Vn * Vn;
Pressure = flow_nodes->GetPressure(iPoint);
/*--- Use recovered pressure here as pressure difference between in and outlet is zero otherwise ---*/
if(streamwisePeriodic) Pressure = flow_nodes->GetStreamwise_Periodic_RecoveredPressure(iPoint);
SoundSpeed = flow_nodes->GetSoundSpeed(iPoint);
for (iDim = 0; iDim < nDim; iDim++) {
TangVel[iDim] = Velocity[iDim] - Vn*Vector[iDim]*AxiFactor/Area;
Vtang2 += TangVel[iDim]*TangVel[iDim];
}
if (incompressible){
if (config->GetVariable_Density_Model()) {
Mach = sqrt(flow_nodes->GetVelocity2(iPoint))/
sqrt(flow_nodes->GetSpecificHeatCp(iPoint)*config->GetPressure_ThermodynamicND()/(flow_nodes->GetSpecificHeatCv(iPoint)*flow_nodes->GetDensity(iPoint)));
} else {
Mach = sqrt(flow_nodes->GetVelocity2(iPoint))/
sqrt(config->GetBulk_Modulus()/(flow_nodes->GetDensity(iPoint)));
}
Temperature = flow_nodes->GetTemperature(iPoint);
Enthalpy = flow_nodes->GetSpecificHeatCp(iPoint)*Temperature;
TotalTemperature = Temperature + 0.5*Velocity2/flow_nodes->GetSpecificHeatCp(iPoint);
TotalPressure = Pressure + 0.5*Density*Velocity2;
}
else{
Mach = sqrt(Velocity2)/SoundSpeed;
Temperature = Pressure / (Gas_Constant * Density);
Enthalpy = flow_nodes->GetEnthalpy(iPoint);
TotalTemperature = Temperature * (1.0 + Mach * Mach * 0.5 * (Gamma - 1.0));
TotalPressure = Pressure * pow( 1.0 + Mach * Mach * 0.5 * (Gamma - 1.0), Gamma / (Gamma - 1.0));
}
/*--- Compute the mass Surface_MassFlow ---*/
Surface_Area[iMarker] += Area;
Surface_MassFlow[iMarker] += MassFlow;
Surface_MassFlow_Abs[iMarker] += abs(MassFlow);
if (Kind_Average == AVERAGE_MASSFLUX) Weight = abs(MassFlow);
else if (Kind_Average == AVERAGE_AREA) Weight = abs(Area);
else Weight = 1.0;
Surface_Mach[iMarker] += Mach*Weight;
Surface_Temperature[iMarker] += Temperature*Weight;
Surface_Density[iMarker] += Density*Weight;
Surface_Enthalpy[iMarker] += Enthalpy*Weight;
Surface_NormalVelocity[iMarker] += Vn*Weight;
Surface_Pressure[iMarker] += Pressure*Weight;
Surface_TotalTemperature[iMarker] += TotalTemperature*Weight;
Surface_TotalPressure[iMarker] += TotalPressure*Weight;
if (species)
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
Surface_Species(iMarker, iVar) += species_nodes->GetSolution(iPoint, iVar)*Weight;
/*--- For now, always used the area to weight the uniformities. ---*/
Weight = abs(Area);
Surface_StreamVelocity2[iMarker] += Vn2*Weight;
Surface_TransvVelocity2[iMarker] += Vtang2*Weight;
}
}
}
}
/*--- Copy to the appropriate structure ---*/
vector<su2double> Surface_MassFlow_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Mach_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Temperature_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Density_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Enthalpy_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_NormalVelocity_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_StreamVelocity2_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_TransvVelocity2_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Pressure_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_TotalTemperature_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_TotalPressure_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_Area_Local (nMarker_Analyze,0.0);
vector<su2double> Surface_MassFlow_Abs_Local (nMarker_Analyze,0.0);
su2activematrix Surface_Species_Local(nMarker_Analyze,nSpecies);
Surface_Species_Local = su2double(0.0);
vector<su2double> Surface_MassFlow_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Mach_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Temperature_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Density_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Enthalpy_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_NormalVelocity_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_StreamVelocity2_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_TransvVelocity2_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Pressure_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_TotalTemperature_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_TotalPressure_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_Area_Total (nMarker_Analyze,0.0);
vector<su2double> Surface_MassFlow_Abs_Total (nMarker_Analyze,0.0);
su2activematrix Surface_Species_Total(nMarker_Analyze,nSpecies);
Surface_Species_Total = su2double(0.0);
vector<su2double> Surface_MomentumDistortion_Total (nMarker_Analyze,0.0);
/*--- Compute the numerical fan face Mach number, mach number, temperature and the total area ---*/
for (iMarker = 0; iMarker < nMarker; iMarker++) {
if (config->GetMarker_All_Analyze(iMarker) == YES) {
for (iMarker_Analyze= 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
/*--- Add the Surface_MassFlow, and Surface_Area to the particular boundary ---*/
if (config->GetMarker_All_TagBound(iMarker) == config->GetMarker_Analyze_TagBound(iMarker_Analyze)) {
Surface_MassFlow_Local[iMarker_Analyze] += Surface_MassFlow[iMarker];
Surface_Mach_Local[iMarker_Analyze] += Surface_Mach[iMarker];
Surface_Temperature_Local[iMarker_Analyze] += Surface_Temperature[iMarker];
Surface_Density_Local[iMarker_Analyze] += Surface_Density[iMarker];
Surface_Enthalpy_Local[iMarker_Analyze] += Surface_Enthalpy[iMarker];
Surface_NormalVelocity_Local[iMarker_Analyze] += Surface_NormalVelocity[iMarker];
Surface_StreamVelocity2_Local[iMarker_Analyze] += Surface_StreamVelocity2[iMarker];
Surface_TransvVelocity2_Local[iMarker_Analyze] += Surface_TransvVelocity2[iMarker];
Surface_Pressure_Local[iMarker_Analyze] += Surface_Pressure[iMarker];
Surface_TotalTemperature_Local[iMarker_Analyze] += Surface_TotalTemperature[iMarker];
Surface_TotalPressure_Local[iMarker_Analyze] += Surface_TotalPressure[iMarker];
Surface_Area_Local[iMarker_Analyze] += Surface_Area[iMarker];
Surface_MassFlow_Abs_Local[iMarker_Analyze] += Surface_MassFlow_Abs[iMarker];
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
Surface_Species_Local(iMarker_Analyze, iVar) += Surface_Species(iMarker, iVar);
}
}
}
}
auto Allreduce = [](const vector<su2double>& src, vector<su2double>& dst) {
SU2_MPI::Allreduce(src.data(), dst.data(), src.size(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
};
auto Allreduce_su2activematrix = [](const su2activematrix& src, su2activematrix& dst) {
SU2_MPI::Allreduce(src.data(), dst.data(), src.size(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
};
Allreduce(Surface_MassFlow_Local, Surface_MassFlow_Total);
Allreduce(Surface_Mach_Local, Surface_Mach_Total);
Allreduce(Surface_Temperature_Local, Surface_Temperature_Total);
Allreduce(Surface_Density_Local, Surface_Density_Total);
Allreduce(Surface_Enthalpy_Local, Surface_Enthalpy_Total);
Allreduce(Surface_NormalVelocity_Local, Surface_NormalVelocity_Total);
Allreduce(Surface_StreamVelocity2_Local, Surface_StreamVelocity2_Total);
Allreduce(Surface_TransvVelocity2_Local, Surface_TransvVelocity2_Total);
Allreduce(Surface_Pressure_Local, Surface_Pressure_Total);
Allreduce(Surface_TotalTemperature_Local, Surface_TotalTemperature_Total);
Allreduce(Surface_TotalPressure_Local, Surface_TotalPressure_Total);
Allreduce(Surface_Area_Local, Surface_Area_Total);
Allreduce(Surface_MassFlow_Abs_Local, Surface_MassFlow_Abs_Total);
Allreduce_su2activematrix(Surface_Species_Local, Surface_Species_Total);
/*--- Compute the value of Surface_Area_Total, and Surface_Pressure_Total, and
set the value in the config structure for future use ---*/
for (iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
if (Kind_Average == AVERAGE_MASSFLUX) Weight = Surface_MassFlow_Abs_Total[iMarker_Analyze];
else if (Kind_Average == AVERAGE_AREA) Weight = abs(Surface_Area_Total[iMarker_Analyze]);
else Weight = 1.0;
if (Weight != 0.0) {
Surface_Mach_Total[iMarker_Analyze] /= Weight;
Surface_Temperature_Total[iMarker_Analyze] /= Weight;
Surface_Density_Total[iMarker_Analyze] /= Weight;
Surface_Enthalpy_Total[iMarker_Analyze] /= Weight;
Surface_NormalVelocity_Total[iMarker_Analyze] /= Weight;
Surface_Pressure_Total[iMarker_Analyze] /= Weight;
Surface_TotalTemperature_Total[iMarker_Analyze] /= Weight;
Surface_TotalPressure_Total[iMarker_Analyze] /= Weight;
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
Surface_Species_Total(iMarker_Analyze, iVar) /= Weight;
}
else {
Surface_Mach_Total[iMarker_Analyze] = 0.0;
Surface_Temperature_Total[iMarker_Analyze] = 0.0;
Surface_Density_Total[iMarker_Analyze] = 0.0;
Surface_Enthalpy_Total[iMarker_Analyze] = 0.0;
Surface_NormalVelocity_Total[iMarker_Analyze] = 0.0;
Surface_Pressure_Total[iMarker_Analyze] = 0.0;
Surface_TotalTemperature_Total[iMarker_Analyze] = 0.0;
Surface_TotalPressure_Total[iMarker_Analyze] = 0.0;
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
Surface_Species_Total(iMarker_Analyze, iVar) = 0.0;
}
/*--- Compute flow uniformity parameters separately (always area for now). ---*/
Area = fabs(Surface_Area_Total[iMarker_Analyze]);
/*--- The definitions for Distortion and Uniformity Parameters are taken as defined by Banko, Andrew J., et al. in section 3.2 of
https://www.sciencedirect.com/science/article/pii/S0142727X16301412 ------*/
if (Area != 0.0) {
Surface_MomentumDistortion_Total[iMarker_Analyze] = Surface_StreamVelocity2_Total[iMarker_Analyze]/(Surface_NormalVelocity_Total[iMarker_Analyze]*Surface_NormalVelocity_Total[iMarker_Analyze]*Area) - 1.0;
Surface_StreamVelocity2_Total[iMarker_Analyze] /= Area;
Surface_TransvVelocity2_Total[iMarker_Analyze] /= Area;
}
else {
Surface_MomentumDistortion_Total[iMarker_Analyze] = 0.0;
Surface_StreamVelocity2_Total[iMarker_Analyze] = 0.0;
Surface_TransvVelocity2_Total[iMarker_Analyze] = 0.0;
}
}
for (iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
su2double MassFlow = Surface_MassFlow_Total[iMarker_Analyze] * config->GetDensity_Ref() * config->GetVelocity_Ref();
if (us_units) MassFlow *= 32.174;
SetHistoryOutputPerSurfaceValue("SURFACE_MASSFLOW", MassFlow, iMarker_Analyze);
Tot_Surface_MassFlow += MassFlow;
config->SetSurface_MassFlow(iMarker_Analyze, MassFlow);
su2double Mach = Surface_Mach_Total[iMarker_Analyze];
SetHistoryOutputPerSurfaceValue("SURFACE_MACH", Mach, iMarker_Analyze);
Tot_Surface_Mach += Mach;
config->SetSurface_Mach(iMarker_Analyze, Mach);
su2double Temperature = Surface_Temperature_Total[iMarker_Analyze] * config->GetTemperature_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_STATIC_TEMPERATURE", Temperature, iMarker_Analyze);
Tot_Surface_Temperature += Temperature;
config->SetSurface_Temperature(iMarker_Analyze, Temperature);
su2double Pressure = Surface_Pressure_Total[iMarker_Analyze] * config->GetPressure_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_STATIC_PRESSURE", Pressure, iMarker_Analyze);
Tot_Surface_Pressure += Pressure;
config->SetSurface_Pressure(iMarker_Analyze, Pressure);
su2double Density = Surface_Density_Total[iMarker_Analyze] * config->GetDensity_Ref();
SetHistoryOutputPerSurfaceValue("AVG_DENSITY", Density, iMarker_Analyze);
Tot_Surface_Density += Density;
config->SetSurface_Density(iMarker_Analyze, Density);
su2double Enthalpy = Surface_Enthalpy_Total[iMarker_Analyze];
SetHistoryOutputPerSurfaceValue("AVG_ENTHALPY", Enthalpy, iMarker_Analyze);
Tot_Surface_Enthalpy += Enthalpy;
config->SetSurface_Enthalpy(iMarker_Analyze, Enthalpy);
su2double NormalVelocity = Surface_NormalVelocity_Total[iMarker_Analyze] * config->GetVelocity_Ref();
SetHistoryOutputPerSurfaceValue("AVG_NORMALVEL", NormalVelocity, iMarker_Analyze);
Tot_Surface_NormalVelocity += NormalVelocity;
config->SetSurface_NormalVelocity(iMarker_Analyze, NormalVelocity);
su2double Uniformity = sqrt(Surface_StreamVelocity2_Total[iMarker_Analyze]) * config->GetVelocity_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_UNIFORMITY", Uniformity, iMarker_Analyze);
Tot_Surface_StreamVelocity2 += Uniformity;
config->SetSurface_Uniformity(iMarker_Analyze, Uniformity);
su2double SecondaryStrength = sqrt(Surface_TransvVelocity2_Total[iMarker_Analyze]) * config->GetVelocity_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_SECONDARY", SecondaryStrength, iMarker_Analyze);
Tot_Surface_TransvVelocity2 += SecondaryStrength;
config->SetSurface_SecondaryStrength(iMarker_Analyze, SecondaryStrength);
su2double MomentumDistortion = Surface_MomentumDistortion_Total[iMarker_Analyze];
SetHistoryOutputPerSurfaceValue("SURFACE_MOM_DISTORTION", MomentumDistortion, iMarker_Analyze);
Tot_Momentum_Distortion += MomentumDistortion;
config->SetSurface_MomentumDistortion(iMarker_Analyze, MomentumDistortion);
su2double SecondOverUniform = SecondaryStrength/Uniformity;
SetHistoryOutputPerSurfaceValue("SURFACE_SECOND_OVER_UNIFORM", SecondOverUniform, iMarker_Analyze);
Tot_SecondOverUniformity += SecondOverUniform;
config->SetSurface_SecondOverUniform(iMarker_Analyze, SecondOverUniform);
su2double TotalTemperature = Surface_TotalTemperature_Total[iMarker_Analyze] * config->GetTemperature_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_TOTAL_TEMPERATURE", TotalTemperature, iMarker_Analyze);
Tot_Surface_TotalTemperature += TotalTemperature;
config->SetSurface_TotalTemperature(iMarker_Analyze, TotalTemperature);
su2double TotalPressure = Surface_TotalPressure_Total[iMarker_Analyze] * config->GetPressure_Ref();
SetHistoryOutputPerSurfaceValue("SURFACE_TOTAL_PRESSURE", TotalPressure, iMarker_Analyze);
Tot_Surface_TotalPressure += TotalPressure;
config->SetSurface_TotalPressure(iMarker_Analyze, TotalPressure);
if (species) {
for (unsigned short iVar = 0; iVar < nSpecies; iVar++) {
su2double Species = Surface_Species_Total(iMarker_Analyze, iVar);
SetHistoryOutputPerSurfaceValue("SURFACE_SPECIES_" + std::to_string(iVar), Species, iMarker_Analyze);
Tot_Surface_Species[iVar] += Species;
if (iVar == 0)
config->SetSurface_Species_0(iMarker_Analyze, Species);
}
}
}
/*--- Compute the average static pressure drop between two surfaces. Note
that this assumes we have two surfaces being analyzed and that the outlet
is first followed by the inlet. This is because we may also want to choose
outlet values (temperature, uniformity, etc.) for our design problems,
which require the outlet to be listed first. This is a simple first version
that could be generalized to a different orders/lists/etc. ---*/
if (nMarker_Analyze >= 2) {
su2double PressureDrop = (Surface_Pressure_Total[1] - Surface_Pressure_Total[0]) * config->GetPressure_Ref();
for (iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
config->SetSurface_PressureDrop(iMarker_Analyze, PressureDrop);
}
SetHistoryOutputValue("SURFACE_PRESSURE_DROP", PressureDrop);
}
SetHistoryOutputValue("SURFACE_MASSFLOW", Tot_Surface_MassFlow);
SetHistoryOutputValue("SURFACE_MACH", Tot_Surface_Mach);
SetHistoryOutputValue("SURFACE_STATIC_TEMPERATURE", Tot_Surface_Temperature);
SetHistoryOutputValue("SURFACE_STATIC_PRESSURE", Tot_Surface_Pressure);
SetHistoryOutputValue("AVG_DENSITY", Tot_Surface_Density);
SetHistoryOutputValue("AVG_ENTHALPY", Tot_Surface_Enthalpy);
SetHistoryOutputValue("AVG_NORMALVEL", Tot_Surface_NormalVelocity);
SetHistoryOutputValue("SURFACE_UNIFORMITY", Tot_Surface_StreamVelocity2);
SetHistoryOutputValue("SURFACE_SECONDARY", Tot_Surface_TransvVelocity2);
SetHistoryOutputValue("SURFACE_MOM_DISTORTION", Tot_Momentum_Distortion);
SetHistoryOutputValue("SURFACE_SECOND_OVER_UNIFORM", Tot_SecondOverUniformity);
SetHistoryOutputValue("SURFACE_TOTAL_TEMPERATURE", Tot_Surface_TotalTemperature);
SetHistoryOutputValue("SURFACE_TOTAL_PRESSURE", Tot_Surface_TotalPressure);
if (species) {
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
SetHistoryOutputValue("SURFACE_SPECIES_" + std::to_string(iVar), Tot_Surface_Species[iVar]);
SetAnalyzeSurfaceSpeciesVariance(solver, geometry, config, Surface_Species_Total, Surface_MassFlow_Abs_Total,
Surface_Area_Total);
}
if ((rank == MASTER_NODE) && !config->GetDiscrete_Adjoint() && output) {
cout.precision(6);
cout.setf(ios::scientific, ios::floatfield);
cout << endl << "Computing surface mean values." << endl << endl;
for (iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
cout << "Surface "<< config->GetMarker_Analyze_TagBound(iMarker_Analyze) << ":" << endl;
if (nDim == 3) { if (si_units) cout << setw(20) << "Area (m^2): "; else cout << setw(20) << "Area (ft^2): "; }
else { if (si_units) cout << setw(20) << "Area (m): "; else cout << setw(20) << "Area (ft): "; }
if (si_units) cout << setw(15) << fabs(Surface_Area_Total[iMarker_Analyze]);
else if (us_units) cout << setw(15) << fabs(Surface_Area_Total[iMarker_Analyze])*12.0*12.0;
cout << endl;
su2double MassFlow = config->GetSurface_MassFlow(iMarker_Analyze);
if (si_units) cout << setw(20) << "Mf (kg/s): " << setw(15) << MassFlow;
else if (us_units) cout << setw(20) << "Mf (lbs/s): " << setw(15) << MassFlow;
su2double NormalVelocity = config->GetSurface_NormalVelocity(iMarker_Analyze);
if (si_units) cout << setw(20) << "Vn (m/s): " << setw(15) << NormalVelocity;
else if (us_units) cout << setw(20) << "Vn (ft/s): " << setw(15) << NormalVelocity;
cout << endl;
su2double Uniformity = config->GetSurface_Uniformity(iMarker_Analyze);
if (si_units) cout << setw(20) << "Uniformity (m/s): " << setw(15) << Uniformity;
else if (us_units) cout << setw(20) << "Uniformity (ft/s): " << setw(15) << Uniformity;
su2double SecondaryStrength = config->GetSurface_SecondaryStrength(iMarker_Analyze);
if (si_units) cout << setw(20) << "Secondary (m/s): " << setw(15) << SecondaryStrength;
else if (us_units) cout << setw(20) << "Secondary (ft/s): " << setw(15) << SecondaryStrength;
cout << endl;
su2double MomentumDistortion = config->GetSurface_MomentumDistortion(iMarker_Analyze);
cout << setw(20) << "Mom. Distortion: " << setw(15) << MomentumDistortion;
su2double SecondOverUniform = config->GetSurface_SecondOverUniform(iMarker_Analyze);
cout << setw(20) << "Second/Uniform: " << setw(15) << SecondOverUniform;
cout << endl;
su2double Pressure = config->GetSurface_Pressure(iMarker_Analyze);
if (si_units) cout << setw(20) << "P (Pa): " << setw(15) << Pressure;
else if (us_units) cout << setw(20) << "P (psf): " << setw(15) << Pressure;
su2double TotalPressure = config->GetSurface_TotalPressure(iMarker_Analyze);
if (si_units) cout << setw(20) << "PT (Pa): " << setw(15) <<TotalPressure;
else if (us_units) cout << setw(20) << "PT (psf): " << setw(15) <<TotalPressure;
cout << endl;
su2double Mach = config->GetSurface_Mach(iMarker_Analyze);
cout << setw(20) << "Mach: " << setw(15) << Mach;
su2double Density = config->GetSurface_Density(iMarker_Analyze);
if (si_units) cout << setw(20) << "Rho (kg/m^3): " << setw(15) << Density;
else if (us_units) cout << setw(20) << "Rho (lb/ft^3): " << setw(15) << Density*32.174;
cout << endl;
if (compressible || energy) {
su2double Temperature = config->GetSurface_Temperature(iMarker_Analyze);
if (si_units) cout << setw(20) << "T (K): " << setw(15) << Temperature;
else if (us_units) cout << setw(20) << "T (R): " << setw(15) << Temperature;
su2double TotalTemperature = config->GetSurface_TotalTemperature(iMarker_Analyze);
if (si_units) cout << setw(20) << "TT (K): " << setw(15) << TotalTemperature;
else if (us_units) cout << setw(20) << "TT (R): " << setw(15) << TotalTemperature;
cout << endl;
}
}
cout.unsetf(ios_base::floatfield);
}
std::cout << std::resetiosflags(std::cout.flags());
}
void CFlowOutput::SetAnalyzeSurfaceSpeciesVariance(const CSolver* const*solver, const CGeometry *geometry,
CConfig *config, const su2activematrix& Surface_Species_Total,
const vector<su2double>& Surface_MassFlow_Abs_Total,
const vector<su2double>& Surface_Area_Total) {
const unsigned short nMarker = config->GetnMarker_All();
const unsigned short Kind_Average = config->GetKind_Average();
const bool species = config->GetKind_Species_Model() == SPECIES_MODEL::SPECIES_TRANSPORT;
const auto nSpecies = config->GetnSpecies();
const bool axisymmetric = config->GetAxisymmetric();
const unsigned short nMarker_Analyze = config->GetnMarker_Analyze();
const auto flow_nodes = solver[FLOW_SOL]->GetNodes();
const CVariable* species_nodes = species ? solver[SPECIES_SOL]->GetNodes() : nullptr;
/*--- Compute Variance of species on the analyze markers. This is done after the rest as the average species value is
* necessary. The variance is computed for all species together and not for each species alone. ---*/
vector<su2double> Surface_SpeciesVariance(nMarker,0.0);
su2double Tot_Surface_SpeciesVariance = 0.0;
/*--- sum += (Yj_i - mu_Yj)^2 * weight_i with i representing the node and j the species. ---*/
for (unsigned short iMarker = 0; iMarker < nMarker; iMarker++) {
if (config->GetMarker_All_Analyze(iMarker) == YES) {
/*--- Find iMarkerAnalyze to iMarker. As SpeciesAvg is accessed via iMarkerAnalyze. ---*/
unsigned short iMarker_Analyze_Stored = std::numeric_limits<unsigned short>::max();
for (unsigned short iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++)
if (config->GetMarker_All_TagBound(iMarker) == config->GetMarker_Analyze_TagBound(iMarker_Analyze))
iMarker_Analyze_Stored = iMarker_Analyze;
for (unsigned long iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++) {
const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
if (geometry->nodes->GetDomain(iPoint)) {
const su2double AxiFactor = GetAxiFactor(axisymmetric, *geometry->nodes, iPoint, iMarker);
su2double Vector[3];
geometry->vertex[iMarker][iVertex]->GetNormal(Vector);
const su2double Density = flow_nodes->GetDensity(iPoint);
su2double Area = 0.0;
su2double MassFlow = 0.0;
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
Area += (Vector[iDim] * AxiFactor) * (Vector[iDim] * AxiFactor);
MassFlow += Vector[iDim] * AxiFactor * Density * flow_nodes->GetVelocity(iPoint,iDim);
}
Area= sqrt(Area);
su2double Weight;
if (Kind_Average == AVERAGE_MASSFLUX) Weight = abs(MassFlow);
else if (Kind_Average == AVERAGE_AREA) Weight = abs(Area);
else Weight = 1.0;
for (unsigned short iVar = 0; iVar < nSpecies; iVar++)
Surface_SpeciesVariance[iMarker] += pow(species_nodes->GetSolution(iPoint, iVar) - Surface_Species_Total(iMarker_Analyze_Stored, iVar), 2) * Weight;
}
}
}
}
/*--- MPI Communication ---*/
vector<su2double> Surface_SpeciesVariance_Local(nMarker_Analyze,0.0);
vector<su2double> Surface_SpeciesVariance_Total(nMarker_Analyze,0.0);
for (unsigned short iMarker = 0; iMarker < nMarker; iMarker++) {
if (config->GetMarker_All_Analyze(iMarker) == YES) {
for (unsigned short iMarker_Analyze= 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
/*--- Add the Surface_MassFlow, and Surface_Area to the particular boundary ---*/
if (config->GetMarker_All_TagBound(iMarker) == config->GetMarker_Analyze_TagBound(iMarker_Analyze)) {
Surface_SpeciesVariance_Local[iMarker_Analyze] += Surface_SpeciesVariance[iMarker];
}
}
}
}
auto Allreduce = [](const vector<su2double>& src, vector<su2double>& dst) {
SU2_MPI::Allreduce(src.data(), dst.data(), src.size(), MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
};
Allreduce(Surface_SpeciesVariance_Local, Surface_SpeciesVariance_Total);
/*--- Divide quantity by weight. ---*/
for (unsigned short iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
su2double Weight;
if (Kind_Average == AVERAGE_MASSFLUX) Weight = Surface_MassFlow_Abs_Total[iMarker_Analyze];
else if (Kind_Average == AVERAGE_AREA) Weight = abs(Surface_Area_Total[iMarker_Analyze]);
else Weight = 1.0;
if (Weight != 0.0) {
Surface_SpeciesVariance_Total[iMarker_Analyze] /= Weight;
}
else {
Surface_SpeciesVariance[iMarker_Analyze] = 0.0;
}
}
/*--- Set values on markers ---*/
for (unsigned short iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
su2double SpeciesVariance = Surface_SpeciesVariance_Total[iMarker_Analyze];
SetHistoryOutputPerSurfaceValue("SURFACE_SPECIES_VARIANCE", SpeciesVariance, iMarker_Analyze);
config->SetSurface_Species_Variance(iMarker_Analyze, SpeciesVariance);
Tot_Surface_SpeciesVariance += SpeciesVariance;
}
SetHistoryOutputValue("SURFACE_SPECIES_VARIANCE", Tot_Surface_SpeciesVariance);
}
void CFlowOutput::ConvertVariableSymbolsToIndices(const CPrimitiveIndices<unsigned long>& idx, const bool allowSkip,
CustomOutput& output) const {
const auto nameToIndex = PrimitiveNameToIndexMap(idx);
std::stringstream knownVariables;
for (const auto& items : nameToIndex) {
knownVariables << items.first + '\n';
}
knownVariables << "TURB[0,1,...]\nRAD[0,1,...]\nSPECIES[0,1,...]\nSCALAR[0,1,...]\n";
auto IndexOfVariable = [](const map<std::string, unsigned long>& nameToIndex, const std::string& var) {
/*--- Primitives of the flow solver. ---*/
const auto flowOffset = FLOW_SOL * CustomOutput::MAX_VARS_PER_SOLVER;
const auto it = nameToIndex.find(var);
if (it != nameToIndex.end()) return flowOffset + it->second;
/*--- Index-based (no name) access to variables of other solvers. ---*/
auto GetIndex = [](const std::string& s, int nameLen) {
/*--- Extract an int from "name[int]", nameLen is the length of "name". ---*/
return std::stoi(std::string(s.begin() + nameLen + 1, s.end() - 1));
};
if (var.rfind("SPECIES", 0) == 0) return SPECIES_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 7);
if (var.rfind("SCALAR", 0) == 0) return SPECIES_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 6);
if (var.rfind("TURB", 0) == 0) return TURB_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 4);
if (var.rfind("RAD", 0) == 0) return RAD_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 3);
return CustomOutput::NOT_A_VARIABLE;
};
output.otherOutputs.clear();
output.varIndices.clear();
output.varIndices.reserve(output.varSymbols.size());
for (const auto& var : output.varSymbols) {
output.varIndices.push_back(IndexOfVariable(nameToIndex, var));
if (output.type == OperationType::FUNCTION && output.varIndices.back() != CustomOutput::NOT_A_VARIABLE) {
SU2_MPI::Error("Custom outputs of type 'Function' cannot reference solver variables.", CURRENT_FUNCTION);
}
/*--- Symbol is a valid solver variable. ---*/
if (output.varIndices.back() < CustomOutput::NOT_A_VARIABLE) continue;
/*--- An index above NOT_A_VARIABLE is not valid with current solver settings. ---*/
if (output.varIndices.back() > CustomOutput::NOT_A_VARIABLE) {
SU2_MPI::Error("Inactive solver variable (" + var + ") used in function " + output.name + "\n"
"E.g. this may only be a variable of the compressible solver.", CURRENT_FUNCTION);
}
/*--- An index equal to NOT_A_VARIABLE may refer to a history output. ---*/
output.varIndices.back() += output.otherOutputs.size();
output.otherOutputs.push_back(GetPtrToHistoryOutput(var));
if (output.otherOutputs.back() == nullptr) {
if (!allowSkip) {
SU2_MPI::Error("Invalid history output or solver variable (" + var + ") used in function " + output.name +
"\nValid solvers variables:\n" + knownVariables.str(), CURRENT_FUNCTION);
} else {
if (rank == MASTER_NODE) {
std::cout << "Info: Ignoring function " + output.name + " because it may be used by the primal/adjoint "
"solver.\n If the function is ignored twice it is invalid." << std::endl;
}
output.skip = true;
break;
}
}
}
}
void CFlowOutput::SetCustomOutputs(const CSolver* const* solver, const CGeometry *geometry, const CConfig *config) {
const bool adjoint = config->GetDiscrete_Adjoint();
const bool axisymmetric = config->GetAxisymmetric();
const auto* flowNodes = su2staticcast_p<const CFlowVariable*>(solver[FLOW_SOL]->GetNodes());
for (auto& output : customOutputs) {
if (output.skip) continue;
if (output.varIndices.empty()) {
const bool allowSkip = adjoint && (output.type == OperationType::FUNCTION);
/*--- Setup indices for the symbols in the expression. ---*/
const auto primIdx = CPrimitiveIndices<unsigned long>(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE,
config->GetNEMOProblem(), nDim, config->GetnSpecies());
ConvertVariableSymbolsToIndices(primIdx, allowSkip, output);
if (output.skip) continue;
/*--- Convert marker names to their index (if any) in this rank. Or probe locations to nearest points. ---*/
if (output.type != OperationType::PROBE) {
output.markerIndices.clear();
for (const auto& marker : output.markers) {
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); ++iMarker) {
if (config->GetMarker_All_TagBound(iMarker) == marker) {
output.markerIndices.push_back(iMarker);
continue;
}
}
}
} else {
if (output.markers.size() != nDim) {
SU2_MPI::Error("Wrong number of coordinates to specify probe " + output.name, CURRENT_FUNCTION);
}
su2double coord[3] = {};
for (auto iDim = 0u; iDim < nDim; ++iDim) coord[iDim] = std::stod(output.markers[iDim]);
su2double minDist = std::numeric_limits<su2double>::max();
unsigned long minPoint = 0;
for (auto iPoint = 0ul; iPoint < geometry->GetnPointDomain(); ++iPoint) {
const su2double dist = GeometryToolbox::SquaredDistance(nDim, coord, geometry->nodes->GetCoord(iPoint));
if (dist < minDist) {
minDist = dist;
minPoint = iPoint;
}
}
/*--- Decide which rank owns the probe. ---*/
su2double globMinDist;
SU2_MPI::Allreduce(&minDist, &globMinDist, 1, MPI_DOUBLE, MPI_MIN, SU2_MPI::GetComm());
output.iPoint = fabs(minDist - globMinDist) < EPS ? minPoint : CustomOutput::PROBE_NOT_OWNED;
if (output.iPoint != CustomOutput::PROBE_NOT_OWNED) {
std::cout << "Probe " << output.name << " is using global point "
<< geometry->nodes->GetGlobalIndex(output.iPoint)
<< ", distance from target location is " << sqrt(minDist) << std::endl;
}
}
}
if (output.type == OperationType::FUNCTION) {
auto Functor = [&](unsigned long i) {
/*--- Functions only reference other history outputs. ---*/
return *output.otherOutputs[i - CustomOutput::NOT_A_VARIABLE];
};
SetHistoryOutputValue(output.name, output.Eval(Functor));
continue;
}
/*--- Prepares the functor that maps symbol indices to values at a given point
* (see ConvertVariableSymbolsToIndices). ---*/
auto MakeFunctor = [&](unsigned long iPoint) {
/*--- This returns another lambda that captures iPoint by value. ---*/
return [&, iPoint](unsigned long i) {
if (i < CustomOutput::NOT_A_VARIABLE) {
const auto solIdx = i / CustomOutput::MAX_VARS_PER_SOLVER;
const auto varIdx = i % CustomOutput::MAX_VARS_PER_SOLVER;
if (solIdx == FLOW_SOL) {
return flowNodes->GetPrimitive(iPoint, varIdx);
}
return solver[solIdx]->GetNodes()->GetSolution(iPoint, varIdx);
} else {
return *output.otherOutputs[i - CustomOutput::NOT_A_VARIABLE];
}
};
};
if (output.type == OperationType::PROBE) {
su2double value = std::numeric_limits<su2double>::max();
if (output.iPoint != CustomOutput::PROBE_NOT_OWNED) {
value = output.Eval(MakeFunctor(output.iPoint));
}
su2double tmp = value;
SU2_MPI::Allreduce(&tmp, &value, 1, MPI_DOUBLE, MPI_MIN, SU2_MPI::GetComm());
SetHistoryOutputValue(output.name, value);
continue;
}
/*--- Surface integral of the expression. ---*/
std::array<su2double, 2> integral = {0.0, 0.0};
SU2_OMP_PARALLEL {
std::array<su2double, 2> local_integral = {0.0, 0.0};
for (const auto iMarker : output.markerIndices) {
SU2_OMP_FOR_(schedule(static) SU2_NOWAIT)
for (auto iVertex = 0ul; iVertex < geometry->nVertex[iMarker]; ++iVertex) {
const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
if (!geometry->nodes->GetDomain(iPoint)) continue;
const auto* normal = geometry->vertex[iMarker][iVertex]->GetNormal();
su2double weight = 1.0;
if (output.type == OperationType::MASSFLOW_AVG || output.type == OperationType::MASSFLOW_INT) {
weight = flowNodes->GetDensity(iPoint) * flowNodes->GetProjVel(iPoint, normal);
} else {
weight = GeometryToolbox::Norm(nDim, normal);
}
weight *= GetAxiFactor(axisymmetric, *geometry->nodes, iPoint, iMarker);
local_integral[1] += weight;
local_integral[0] += weight * output.Eval(MakeFunctor(iPoint));
}
END_SU2_OMP_FOR
}
SU2_OMP_CRITICAL {
integral[0] += local_integral[0];
integral[1] += local_integral[1];
}
END_SU2_OMP_CRITICAL
}
END_SU2_OMP_PARALLEL
const auto local = integral;
SU2_MPI::Allreduce(local.data(), integral.data(), 2, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
if (output.type == OperationType::AREA_AVG || output.type == OperationType::MASSFLOW_AVG) {
integral[0] /= integral[1];
}
SetHistoryOutputValue(output.name, integral[0]);
}
}
// The "AddHistoryOutput(" must not be split over multiple lines to ensure proper python parsing
// clang-format off
void CFlowOutput::AddHistoryOutputFields_ScalarRMS_RES(const CConfig* config) {
switch (TurbModelFamily(config->GetKind_Turb_Model())) {
case TURB_FAMILY::SA:
/// DESCRIPTION: Root-mean square residual of nu tilde (SA model).
AddHistoryOutput("RMS_NU_TILDE", "rms[nu]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of nu tilde (SA model).", HistoryFieldType::RESIDUAL);
break;
case TURB_FAMILY::KW:
/// DESCRIPTION: Root-mean square residual of kinetic energy (SST model).
AddHistoryOutput("RMS_TKE", "rms[k]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of kinetic energy (SST model).", HistoryFieldType::RESIDUAL);
/// DESCRIPTION: Root-mean square residual of the dissipation (SST model).
AddHistoryOutput("RMS_DISSIPATION", "rms[w]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of dissipation (SST model).", HistoryFieldType::RESIDUAL);
break;
case TURB_FAMILY::NONE: break;
}
switch (config->GetKind_Trans_Model()) {
case TURB_TRANS_MODEL::LM:
/// DESCRIPTION: Root-mean square residual of the intermittency (LM model).
AddHistoryOutput("RMS_INTERMITTENCY", "rms[LM_1]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of intermittency (LM model).", HistoryFieldType::RESIDUAL);
/// DESCRIPTION: Root-mean square residual of the momentum thickness Reynolds number (LM model).
AddHistoryOutput("RMS_RE_THETA_T", "rms[LM_2]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of momentum thickness Reynolds number (LM model).", HistoryFieldType::RESIDUAL);
break;
case TURB_TRANS_MODEL::NONE: break;
}
switch (config->GetKind_Species_Model()) {
case SPECIES_MODEL::SPECIES_TRANSPORT: {
for (unsigned short iVar = 0; iVar < config->GetnSpecies(); iVar++) {
AddHistoryOutput("RMS_SPECIES_" + std::to_string(iVar), "rms[rho*Y_" + std::to_string(iVar)+"]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of transported species.", HistoryFieldType::RESIDUAL);
}
break;
}
case SPECIES_MODEL::FLAMELET: {
const auto& flamelet_config_options = config->GetFlameletParsedOptions();
/*--- Controlling variable transport. ---*/
for (auto iCV = 0u; iCV < flamelet_config_options.n_control_vars; iCV++){