Skip to content

Commit 1f63ebf

Browse files
Cleaned up the PreprocessAverage function
1 parent d1879dc commit 1f63ebf

1 file changed

Lines changed: 38 additions & 66 deletions

File tree

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 38 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8795,74 +8795,55 @@ void CEulerSolver::SetFreeStream_TurboSolution(CConfig *config) {
87958795

87968796
void CEulerSolver::PreprocessAverage(CSolver **solver, CGeometry *geometry, CConfig *config, unsigned short marker_flag) {
87978797

8798-
unsigned long iVertex, iPoint;
8799-
unsigned short iDim, iMarker, iMarkerTP, iSpan;
8800-
su2double Pressure = 0.0, Density = 0.0, *Velocity = nullptr, *TurboVelocity,
8801-
Area, TotalArea, TotalAreaPressure, TotalAreaDensity, *TotalAreaVelocity, *UnitNormal, *TurboNormal;
8802-
string Marker_Tag, Monitoring_Tag;
8803-
unsigned short iZone = config->GetiZone();
8804-
const su2double *AverageTurboNormal;
8805-
su2double VelSq;
8806-
8807-
/*-- Variables declaration and allocation ---*/
8808-
Velocity = new su2double[nDim];
8809-
UnitNormal = new su2double[nDim];
8810-
TurboNormal = new su2double[nDim];
8811-
TurboVelocity = new su2double[nDim];
8812-
TotalAreaVelocity = new su2double[nDim];
8813-
88148798
const auto nSpanWiseSections = config->GetnSpanWiseSections();
8815-
8816-
for (iSpan= 0; iSpan < nSpanWiseSections; iSpan++){
8817-
8818-
for (iDim=0; iDim<nDim; iDim++) {
8819-
TotalAreaVelocity[iDim] = 0.0;
8820-
}
8821-
8822-
TotalAreaPressure = 0.0;
8823-
TotalAreaDensity = 0.0;
8824-
8825-
for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++){
8826-
for (iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
8799+
const auto iZone = config->GetiZone();
8800+
8801+
for (auto iSpan= 0u; iSpan < nSpanWiseSections; iSpan++){
8802+
su2double TotalAreaVelocity[MAXNDIM]={0.0},
8803+
TotalAreaPressure{0},
8804+
TotalAreaDensity{0};
8805+
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++){
8806+
for (auto iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
88278807
if (config->GetMarker_All_Turbomachinery(iMarker) == iMarkerTP){
88288808
if (config->GetMarker_All_TurbomachineryFlag(iMarker) == marker_flag){
88298809

88308810
/*--- Retrieve Old Solution ---*/
88318811

88328812
/*--- Loop over the vertices to sum all the quantities pithc-wise ---*/
8833-
for (iVertex = 0; iVertex < geometry->GetnVertexSpan(iMarker,iSpan); iVertex++) {
8834-
iPoint = geometry->turbovertex[iMarker][iSpan][iVertex]->GetNode();
8813+
for (auto iVertex = 0u; iVertex < geometry->GetnVertexSpan(iMarker,iSpan); iVertex++) {
8814+
auto iPoint = geometry->turbovertex[iMarker][iSpan][iVertex]->GetNode();
88358815
if (geometry->nodes->GetDomain(iPoint)){
88368816
/*--- Compute the integral fluxes for the boundaries ---*/
88378817

8838-
Pressure = nodes->GetPressure(iPoint);
8839-
Density = nodes->GetDensity(iPoint);
8818+
auto Pressure = nodes->GetPressure(iPoint);
8819+
auto Density = nodes->GetDensity(iPoint);
88408820

8821+
su2double UnitNormal[MAXNDIM]={0},
8822+
TurboNormal[MAXNDIM]={0},
8823+
TurboVelocity[MAXNDIM],
8824+
Area;
88418825
/*--- Normal vector for this vertex (negate for outward convention) ---*/
88428826
geometry->turbovertex[iMarker][iSpan][iVertex]->GetNormal(UnitNormal);
88438827
geometry->turbovertex[iMarker][iSpan][iVertex]->GetTurboNormal(TurboNormal);
88448828
Area = geometry->turbovertex[iMarker][iSpan][iVertex]->GetArea();
88458829

8846-
VelSq = 0.0;
8847-
for (iDim = 0; iDim < nDim; iDim++) {
8848-
Velocity[iDim] = nodes->GetVelocity(iPoint,iDim);
8849-
VelSq += Velocity[iDim]*Velocity[iDim];
8850-
}
8830+
su2double Velocity[MAXNDIM]={0};
8831+
for (auto iDim=0u; iDim<nDim;iDim++) Velocity[iDim] = nodes->GetVelocity(iPoint, iDim);
88518832

88528833
ComputeTurboVelocity(Velocity, TurboNormal , TurboVelocity, marker_flag, config->GetKind_TurboMachinery(iZone));
88538834

88548835
/*--- Compute different integral quantities for the boundary of interest ---*/
88558836

88568837
TotalAreaPressure += Area*Pressure;
88578838
TotalAreaDensity += Area*Density;
8858-
for (iDim = 0; iDim < nDim; iDim++)
8839+
for (auto iDim = 0u; iDim < nDim; iDim++)
88598840
TotalAreaVelocity[iDim] += Area*Velocity[iDim];
88608841
}
88618842
}
88628843
}
88638844
}
8864-
}
8865-
}
8845+
} // iMarkerTP
8846+
} // iMarker
88668847

88678848
#ifdef HAVE_MPI
88688849

@@ -8876,7 +8857,7 @@ void CEulerSolver::PreprocessAverage(CSolver **solver, CGeometry *geometry, CCon
88768857

88778858
auto* MyTotalAreaVelocity = new su2double[nDim];
88788859

8879-
for (iDim = 0; iDim < nDim; iDim++) {
8860+
for (auto iDim = 0u; iDim < nDim; iDim++) {
88808861
MyTotalAreaVelocity[iDim] = TotalAreaVelocity[iDim];
88818862
}
88828863

@@ -8889,72 +8870,63 @@ void CEulerSolver::PreprocessAverage(CSolver **solver, CGeometry *geometry, CCon
88898870
/*--- initialize spanwise average quantities ---*/
88908871

88918872

8892-
for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++){
8893-
for (iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
8873+
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++){
8874+
for (auto iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
88948875
if (config->GetMarker_All_Turbomachinery(iMarker) == iMarkerTP){
88958876
if (config->GetMarker_All_TurbomachineryFlag(iMarker) == marker_flag){
88968877

8897-
TotalArea = geometry->GetSpanArea(iMarker,iSpan);
8898-
AverageTurboNormal = geometry->GetAverageTurboNormal(iMarker,iSpan);
8878+
auto TotalArea = geometry->GetSpanArea(iMarker,iSpan);
8879+
auto AverageTurboNormal = geometry->GetAverageTurboNormal(iMarker,iSpan);
88998880

89008881
/*--- Compute the averaged value for the boundary of interest for the span of interest ---*/
89018882

89028883
AverageDensity[iMarker][iSpan] = TotalAreaDensity / TotalArea;
89038884
AveragePressure[iMarker][iSpan] = TotalAreaPressure / TotalArea;
8904-
for (iDim = 0; iDim < nDim; iDim++)
8885+
for (auto iDim = 0u; iDim < nDim; iDim++)
89058886
AverageVelocity[iMarker][iSpan][iDim] = TotalAreaVelocity[iDim] / TotalArea;
89068887

89078888
/* --- compute static averaged quantities ---*/
89088889
ComputeTurboVelocity(AverageVelocity[iMarker][iSpan], AverageTurboNormal , AverageTurboVelocity[iMarker][iSpan], marker_flag, config->GetKind_TurboMachinery(iZone));
89098890

89108891
OldAverageDensity[iMarker][iSpan] = AverageDensity[iMarker][iSpan];
89118892
OldAveragePressure[iMarker][iSpan] = AveragePressure[iMarker][iSpan];
8912-
for(iDim = 0; iDim < nDim;iDim++)
8893+
for(auto iDim = 0u; iDim < nDim;iDim++)
89138894
OldAverageTurboVelocity[iMarker][iSpan][iDim] = AverageTurboVelocity[iMarker][iSpan][iDim];
89148895

89158896
}
89168897
}
8917-
}
8918-
}
8919-
}
8898+
} // iMarkerTP
8899+
} // iMarker
8900+
} // iSpan
89208901

89218902
/*--- initialize 1D average quantities ---*/
89228903

8923-
for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++){
8924-
for (iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
8904+
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++){
8905+
for (auto iMarkerTP=1; iMarkerTP < config->GetnMarker_Turbomachinery()+1; iMarkerTP++){
89258906
if (config->GetMarker_All_Turbomachinery(iMarker) == iMarkerTP){
89268907
if (config->GetMarker_All_TurbomachineryFlag(iMarker) == marker_flag){
89278908

8928-
AverageTurboNormal = geometry->GetAverageTurboNormal(iMarker,nSpanWiseSections);
8909+
auto AverageTurboNormal = geometry->GetAverageTurboNormal(iMarker,nSpanWiseSections);
89298910

89308911
/*--- Compute the averaged value for the boundary of interest for the span of interest ---*/
89318912

89328913
AverageDensity[iMarker][nSpanWiseSections] = AverageDensity[iMarker][nSpanWiseSections/2];
89338914
AveragePressure[iMarker][nSpanWiseSections] = AveragePressure[iMarker][nSpanWiseSections/2];
8934-
for (iDim = 0; iDim < nDim; iDim++)
8915+
for (auto iDim = 0u; iDim < nDim; iDim++)
89358916
AverageVelocity[iMarker][nSpanWiseSections][iDim] = AverageVelocity[iMarker][nSpanWiseSections/2][iDim];
89368917

89378918
/* --- compute static averaged quantities ---*/
89388919
ComputeTurboVelocity(AverageVelocity[iMarker][nSpanWiseSections], AverageTurboNormal , AverageTurboVelocity[iMarker][nSpanWiseSections], marker_flag, config->GetKind_TurboMachinery(iZone));
89398920

89408921
OldAverageDensity[iMarker][nSpanWiseSections] = AverageDensity[iMarker][nSpanWiseSections];
89418922
OldAveragePressure[iMarker][nSpanWiseSections] = AveragePressure[iMarker][nSpanWiseSections];
8942-
for(iDim = 0; iDim < nDim;iDim++)
8923+
for(auto iDim = 0u; iDim < nDim;iDim++)
89438924
OldAverageTurboVelocity[iMarker][nSpanWiseSections][iDim] = AverageTurboVelocity[iMarker][nSpanWiseSections][iDim];
89448925

89458926
}
89468927
}
8947-
}
8948-
}
8949-
8950-
8951-
/*--- Free locally allocated memory ---*/
8952-
delete [] Velocity;
8953-
delete [] UnitNormal;
8954-
delete [] TurboNormal;
8955-
delete [] TurboVelocity;
8956-
delete [] TotalAreaVelocity;
8957-
8928+
} // iMarkerTP
8929+
} // iMarker
89588930
}
89598931

89608932

0 commit comments

Comments
 (0)