Skip to content

Commit 934b995

Browse files
local variables
Co-authored-by: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com>
1 parent 5cb3a3c commit 934b995

2 files changed

Lines changed: 42 additions & 48 deletions

File tree

SU2_CFD/src/output/CFlowOutput.cpp

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -793,19 +793,15 @@ void CFlowOutput::Add_NearfieldInverseDesignOutput(){
793793
void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *geometry, const CConfig *config){
794794

795795
ofstream EquivArea_file, FuncGrad_file;
796-
unsigned short iMarker = 0;
797-
su2double auxXCoord, auxYCoord, auxZCoord, InverseDesign = 0.0, DeltaX,
796+
su2double auxXCoord, auxYCoord, auxZCoord, InverseDesign, DeltaX,
798797
Coord_i, Coord_j, jp1Coord, *Coord = nullptr, MeanFunction,
799798
*Face_Normal = nullptr, auxArea, auxPress, jFunction, jp1Function;
800-
unsigned long jVertex, iVertex, iPoint, nVertex_NearField = 0, auxPoint,
801-
auxDomain;
802-
unsigned short iPhiAngle;
799+
unsigned long iPoint, auxPoint, auxDomain;
803800
ofstream NearFieldEA_file; ifstream TargetEA_file;
804801

805802
su2double XCoordBegin_OF = config->GetEA_IntLimit(0);
806803
su2double XCoordEnd_OF = config->GetEA_IntLimit(1);
807804

808-
unsigned short nDim = geometry->GetnDim();
809805
su2double AoA = -(config->GetAoA()*PI_NUMBER/180.0);
810806
su2double EAScaleFactor = config->GetEA_ScaleFactor(); // The EA Obj. Func. should be ~ force based Obj. Func.
811807

@@ -819,20 +815,17 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
819815

820816
if (rank == MASTER_NODE) cout << "Writing Equivalent Area files." << endl ;
821817

822-
unsigned long nLocalVertex_NearField = 0, MaxLocalVertex_NearField = 0;
823-
int iProcessor;
824-
825818
vector<unsigned long> Buffer_Receive_nVertex;
826819
if (rank == MASTER_NODE) {
827820
Buffer_Receive_nVertex.resize(size);
828821
}
829822

830823
/*--- Compute the total number of points of the near-field ghost nodes ---*/
831824

832-
nLocalVertex_NearField = 0;
833-
for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++)
825+
unsigned long nLocalVertex_NearField = 0;
826+
for (unsignde short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++)
834827
if (config->GetMarker_All_KindBC(iMarker) == NEARFIELD_BOUNDARY)
835-
for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) {
828+
for (unsigned long iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) {
836829
iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
837830
Face_Normal = geometry->vertex[iMarker][iVertex]->GetNormal();
838831
Coord = geometry->nodes->GetCoord(iPoint);
@@ -843,6 +836,7 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
843836
}
844837

845838
/*--- Send Near-Field vertex information --*/
839+
unsigned long MaxLocalVertex_NearField, nVertex_NearField;
846840

847841
SU2_MPI::Allreduce(&nLocalVertex_NearField, &nVertex_NearField, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
848842
SU2_MPI::Allreduce(&nLocalVertex_NearField, &MaxLocalVertex_NearField, 1, MPI_UNSIGNED_LONG, MPI_MAX, SU2_MPI::GetComm());
@@ -882,9 +876,9 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
882876
/*--- Copy coordinates, index points, and pressures to the auxiliar vector --*/
883877

884878
nLocalVertex_NearField = 0;
885-
for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++)
879+
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++)
886880
if (config->GetMarker_All_KindBC(iMarker) == NEARFIELD_BOUNDARY)
887-
for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) {
881+
for (unsigned long iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) {
888882
iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
889883
Face_Normal = geometry->vertex[iMarker][iVertex]->GetNormal();
890884
Coord = geometry->nodes->GetCoord(iPoint);
@@ -926,8 +920,8 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
926920
vector<su2double> Weight(nVertex_NearField);
927921

928922
nVertex_NearField = 0;
929-
for (iProcessor = 0; iProcessor < size; iProcessor++)
930-
for (iVertex = 0; iVertex < Buffer_Receive_nVertex[iProcessor]; iVertex++) {
923+
for (int iProcessor = 0; iProcessor < size; iProcessor++)
924+
for (unsigned long iVertex = 0; iVertex < Buffer_Receive_nVertex[iProcessor]; iVertex++) {
931925
Xcoord[nVertex_NearField] = Buffer_Receive_Xcoord[iProcessor*MaxLocalVertex_NearField+iVertex];
932926
Ycoord[nVertex_NearField] = Buffer_Receive_Ycoord[iProcessor*MaxLocalVertex_NearField+iVertex];
933927

@@ -975,7 +969,7 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
975969
vector<short> PhiAngleList;
976970
vector<short>::iterator IterPhiAngleList;
977971

978-
for (iVertex = 0; iVertex < nVertex_NearField; iVertex++)
972+
for (unsigned long iVertex = 0; iVertex < nVertex_NearField; iVertex++)
979973
PhiAngleList.push_back(AzimuthalAngle[iVertex]);
980974

981975
sort( PhiAngleList.begin(), PhiAngleList.end());
@@ -998,8 +992,8 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
998992

999993
/*--- Distribute the values among the different PhiAngles ---*/
1000994

1001-
for (iVertex = 0; iVertex < nVertex_NearField; iVertex++)
1002-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
995+
for (unsigned long iVertex = 0; iVertex < nVertex_NearField; iVertex++)
996+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1003997
if (AzimuthalAngle[iVertex] == PhiAngleList[iPhiAngle]) {
1004998
Xcoord_PhiAngle[iPhiAngle].push_back(Xcoord[iVertex]);
1005999
Ycoord_PhiAngle[iPhiAngle].push_back(Ycoord[iVertex]);
@@ -1016,9 +1010,9 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
10161010

10171011
/*--- Order the arrays (x Coordinate, Pressure, Point, and Domain) ---*/
10181012

1019-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1020-
for (iVertex = 0; iVertex < Xcoord_PhiAngle[iPhiAngle].size(); iVertex++)
1021-
for (jVertex = 0; jVertex < Xcoord_PhiAngle[iPhiAngle].size() - 1 - iVertex; jVertex++)
1013+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1014+
for (unsigned long iVertex = 0; iVertex < Xcoord_PhiAngle[iPhiAngle].size(); iVertex++)
1015+
for (unsigned long jVertex = 0; jVertex < Xcoord_PhiAngle[iPhiAngle].size() - 1 - iVertex; jVertex++)
10221016
if (Xcoord_PhiAngle[iPhiAngle][jVertex] > Xcoord_PhiAngle[iPhiAngle][jVertex+1]) {
10231017
auxXCoord = Xcoord_PhiAngle[iPhiAngle][jVertex]; Xcoord_PhiAngle[iPhiAngle][jVertex] = Xcoord_PhiAngle[iPhiAngle][jVertex+1]; Xcoord_PhiAngle[iPhiAngle][jVertex+1] = auxXCoord;
10241018
auxYCoord = Ycoord_PhiAngle[iPhiAngle][jVertex]; Ycoord_PhiAngle[iPhiAngle][jVertex] = Ycoord_PhiAngle[iPhiAngle][jVertex+1]; Ycoord_PhiAngle[iPhiAngle][jVertex+1] = auxYCoord;
@@ -1032,23 +1026,23 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
10321026

10331027
/*--- Check that all the azimuth lists have the same size ---*/
10341028

1035-
unsigned short nVertex = Xcoord_PhiAngle[0].size();
1036-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1037-
unsigned short nVertex_aux = Xcoord_PhiAngle[iPhiAngle].size();
1038-
if (nVertex_aux != nVertex) cout <<"Be careful!!! one azimuth list is shorter than the other"<< endl;
1029+
auto nVertex = Xcoord_PhiAngle[0].size();
1030+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1031+
auto nVertex_aux = Xcoord_PhiAngle[iPhiAngle].size();
1032+
if (nVertex_aux != nVertex) cout <<"Be careful! One azimuth list is shorter than the other.\n";
10391033
nVertex = min(nVertex, nVertex_aux);
10401034
}
10411035

10421036
/*--- Compute equivalent area distribution at each azimuth angle ---*/
10431037

1044-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1038+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
10451039
EquivArea_PhiAngle[iPhiAngle][0] = 0.0;
1046-
for (iVertex = 1; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
1040+
for (unsigned long iVertex = 1; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
10471041
EquivArea_PhiAngle[iPhiAngle][iVertex] = 0.0;
10481042

10491043
Coord_i = Xcoord_PhiAngle[iPhiAngle][iVertex]*cos(AoA) - Zcoord_PhiAngle[iPhiAngle][iVertex]*sin(AoA);
10501044

1051-
for (jVertex = 0; jVertex < iVertex-1; jVertex++) {
1045+
for (unsigned long jVertex = 0; jVertex < iVertex-1; jVertex++) {
10521046

10531047
Coord_j = Xcoord_PhiAngle[iPhiAngle][jVertex]*cos(AoA) - Zcoord_PhiAngle[iPhiAngle][jVertex]*sin(AoA);
10541048
jp1Coord = Xcoord_PhiAngle[iPhiAngle][jVertex+1]*cos(AoA) - Zcoord_PhiAngle[iPhiAngle][jVertex+1]*sin(AoA);
@@ -1075,15 +1069,15 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
10751069
else
10761070
NearFieldEA_file << "VARIABLES = \"Height (m) at r="<< R_Plane << " m. (cylindrical coordinate system)\"";
10771071

1078-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1072+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
10791073
if (config->GetSystemMeasurements() == US)
10801074
NearFieldEA_file << ", \"Equivalent Area (ft<sup>2</sup>), <greek>F</greek>= " << PhiAngleList[iPhiAngle] << " deg.\"";
10811075
else
10821076
NearFieldEA_file << ", \"Equivalent Area (m<sup>2</sup>), <greek>F</greek>= " << PhiAngleList[iPhiAngle] << " deg.\"";
10831077
}
10841078

10851079
NearFieldEA_file << "\n";
1086-
for (iVertex = 0; iVertex < EquivArea_PhiAngle[0].size(); iVertex++) {
1080+
for (unsigned long iVertex = 0; iVertex < EquivArea_PhiAngle[0].size(); iVertex++) {
10871081

10881082
su2double XcoordRot = Xcoord_PhiAngle[0][iVertex]*cos(AoA) - Zcoord_PhiAngle[0][iVertex]*sin(AoA);
10891083
su2double XcoordRot_init = Xcoord_PhiAngle[0][0]*cos(AoA) - Zcoord_PhiAngle[0][0]*sin(AoA);
@@ -1093,7 +1087,7 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
10931087
else
10941088
NearFieldEA_file << scientific << (XcoordRot - XcoordRot_init);
10951089

1096-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1090+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
10971091
NearFieldEA_file << scientific << ", " << EquivArea_PhiAngle[iPhiAngle][iVertex];
10981092
}
10991093

@@ -1112,8 +1106,8 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
11121106

11131107
if (TargetEA_file.fail()) {
11141108
/*--- Set the table to 0 ---*/
1115-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1116-
for (iVertex = 0; iVertex < TargetArea_PhiAngle[iPhiAngle].size(); iVertex++)
1109+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1110+
for (unsigned long iVertex = 0; iVertex < TargetArea_PhiAngle[iPhiAngle].size(); iVertex++)
11171111
TargetArea_PhiAngle[iPhiAngle][iVertex] = 0.0;
11181112
}
11191113
else {
@@ -1150,8 +1144,8 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
11501144
TargetArea_PhiAngle_Trans.push_back(row);
11511145
}
11521146

1153-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1154-
for (iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++)
1147+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1148+
for (unsigned long iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++)
11551149
TargetArea_PhiAngle[iPhiAngle][iVertex] = TargetArea_PhiAngle_Trans[iVertex][iPhiAngle];
11561150

11571151
}
@@ -1163,8 +1157,8 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
11631157
/*--- Evaluate the objective function ---*/
11641158

11651159
InverseDesign = 0;
1166-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1167-
for (iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
1160+
for (unsigned short iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1161+
for (unsigned long iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
11681162
Weight_PhiAngle[iPhiAngle][iVertex] = 1.0;
11691163
Coord_i = Xcoord_PhiAngle[iPhiAngle][iVertex];
11701164

@@ -1178,11 +1172,11 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
11781172

11791173
/*--- Evaluate the weight of the nearfield pressure (adjoint input) ---*/
11801174

1181-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1182-
for (iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
1175+
for (unsigned long iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1176+
for (unsigned long iVertex = 0; iVertex < EquivArea_PhiAngle[iPhiAngle].size(); iVertex++) {
11831177
Coord_i = Xcoord_PhiAngle[iPhiAngle][iVertex];
11841178
NearFieldWeight_PhiAngle[iPhiAngle][iVertex] = 0.0;
1185-
for (jVertex = iVertex; jVertex < EquivArea_PhiAngle[iPhiAngle].size(); jVertex++) {
1179+
for (unsigned long jVertex = iVertex; jVertex < EquivArea_PhiAngle[iPhiAngle].size(); jVertex++) {
11861180
Coord_j = Xcoord_PhiAngle[iPhiAngle][jVertex];
11871181
Weight_PhiAngle[iPhiAngle][iVertex] = 1.0;
11881182

@@ -1207,9 +1201,9 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
12071201
else
12081202
EquivArea_file << "VARIABLES = \"Height (m) at r="<< R_Plane << " m. (cylindrical coordinate system)\",\"Equivalent Area (m<sup>2</sup>)\",\"Target Equivalent Area (m<sup>2</sup>)\",\"Cp\"" << "\n";
12091203

1210-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
1204+
for (unsigned long iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++) {
12111205
EquivArea_file << fixed << "ZONE T= \"<greek>F</greek>=" << PhiAngleList[iPhiAngle] << " deg.\"" << "\n";
1212-
for (iVertex = 0; iVertex < Xcoord_PhiAngle[iPhiAngle].size(); iVertex++) {
1206+
for (unsigned long iVertex = 0; iVertex < Xcoord_PhiAngle[iPhiAngle].size(); iVertex++) {
12131207

12141208
su2double XcoordRot = Xcoord_PhiAngle[0][iVertex]*cos(AoA) - Zcoord_PhiAngle[0][iVertex]*sin(AoA);
12151209
su2double XcoordRot_init = Xcoord_PhiAngle[0][0]*cos(AoA) - Zcoord_PhiAngle[0][0]*sin(AoA);
@@ -1235,14 +1229,14 @@ void CFlowOutput::Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *g
12351229
FuncGrad_file.open("WeightNF.dat", ios::out);
12361230

12371231
FuncGrad_file << scientific << "-1.0";
1238-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1232+
for (unsigned long iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
12391233
FuncGrad_file << scientific << "\t" << PhiAngleList[iPhiAngle];
12401234
FuncGrad_file << "\n";
12411235

1242-
for (iVertex = 0; iVertex < NearFieldWeight_PhiAngle[0].size(); iVertex++) {
1236+
for (unsigned long iVertex = 0; iVertex < NearFieldWeight_PhiAngle[0].size(); iVertex++) {
12431237
su2double XcoordRot = Xcoord_PhiAngle[0][iVertex]*cos(AoA) - Zcoord_PhiAngle[0][iVertex]*sin(AoA);
12441238
FuncGrad_file << scientific << XcoordRot;
1245-
for (iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
1239+
for (unsigned long iPhiAngle = 0; iPhiAngle < PhiAngleList.size(); iPhiAngle++)
12461240
FuncGrad_file << scientific << "\t" << NearFieldWeight_PhiAngle[iPhiAngle][iVertex];
12471241
FuncGrad_file << "\n";
12481242
}

TestCases/optimization_euler/equivalentarea_naca64206/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Introduction
44
The purpose of this test case is to confirm equivalent area distribution and its adjoint can be calculated by SU2. Equivalent area is a distribution calculated from pressure along a line parallel to the aircraft axis. It can be used to supersonic aircraft design. See the paper below for an example of use of SU2 for supersonic aircraft design using equivalent area distribution.
55

6-
Palacios, F., Alonso, J. J., Colonno, M., Hicken, J., and Lukaczyk, T., "Adjoint-based method for supersonic aircraft design using equivalent area distribution," AIAA 2012-0269, 2012. DOI: 10.2514/6.2012-269
6+
Palacios, F., Alonso, J. J., Colonno, M., Hicken, J., and Lukaczyk, T., "Adjoint-based method for supersonic aircraft design using equivalent area distribution," AIAA 2012-0269, 2012. DOI: [10.2514/6.2012-269](https://arc.aiaa.org/doi/10.2514/6.2012-269)
77

88
## Expected outcome
99
- Direct solver
@@ -36,4 +36,4 @@ A mesh has to have a circumferential boundary around the aircraft axis within th
3636
TargetEA.dat is required for shape optimization using equivalent area. After running direct solver, Equivalent_Area.dat is output, which can be used to define a target since it has the same format as TargetEA.dat. Equivalent area is calculated at each node on a surface with MARKER_NEARFIELD. Difference from target is calculated by sum of squared difference at each node.
3737

3838
## Implementation on SU2
39-
Equivalent area calculation function was temporarily unavailable after introduction of ver. 7.0.0. See PR1329 on Github for recovery.
39+
Equivalent area calculation function was temporarily unavailable after introduction of ver. 7.0.0. See [PR1329](https://github.com/su2code/SU2/pull/1329) on Github for recovery.

0 commit comments

Comments
 (0)