Skip to content

Commit 931f367

Browse files
authored
Merge pull request #2019 from afshawnlotfi/develop
Allow selecting the zone used by the python wrapper (for multizone drivers)
2 parents 3278ea9 + d0ac499 commit 931f367

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

SU2_CFD/include/drivers/CDriverBase.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CDriverBase {
5454
UsedTime; /*!< \brief Elapsed time between Start and Stop point of the timer. */
5555

5656
unsigned long TimeIter;
57-
57+
unsigned short selected_iZone = ZONE_0; /*!< \brief Selected zone for the driver. Defaults to ZONE_0 */
5858
unsigned short iMesh, /*!< \brief Iterator on mesh levels. */
5959
iZone, /*!< \brief Iterator on zones. */
6060
nZone, /*!< \brief Total number of zones in the problem. */
@@ -227,7 +227,7 @@ class CDriverBase {
227227
SU2_MPI::Error("Initial coordinates are only available with DEFORM_MESH= YES", CURRENT_FUNCTION);
228228
}
229229
auto* coords =
230-
const_cast<su2activematrix*>(solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
230+
const_cast<su2activematrix*>(solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
231231
return CPyWrapperMatrixView(*coords, "InitialCoordinates", true);
232232
}
233233

@@ -241,7 +241,7 @@ class CDriverBase {
241241
if (iMarker >= GetNumberMarkers()) SU2_MPI::Error("Marker index exceeds size.", CURRENT_FUNCTION);
242242

243243
auto* coords =
244-
const_cast<su2activematrix*>(solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
244+
const_cast<su2activematrix*>(solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
245245
return CPyWrapperMarkerMatrixView(*coords, main_geometry->vertex[iMarker], main_geometry->GetnVertex(iMarker),
246246
"MarkerInitialCoordinates", true);
247247
}
@@ -549,6 +549,17 @@ class CDriverBase {
549549
main_geometry->SetCustomBoundaryHeatFlux(iMarker, iVertex, WallHeatFlux);
550550
}
551551

552+
/*!
553+
* \brief Selects zone to be used for Driver operation
554+
* \param[in] iZone - Zone identifier.
555+
*/
556+
inline void SelectZone(unsigned short iZone) {
557+
if (iZone >= nZone) SU2_MPI::Error("Zone index out of range", CURRENT_FUNCTION);
558+
selected_iZone = iZone;
559+
main_geometry = geometry_container[selected_iZone][INST_0][MESH_0];
560+
main_config = config_container[selected_iZone];
561+
}
562+
552563
/*!
553564
* \brief Get the wall normal heat flux at a vertex on a specified marker of the flow or heat solver.
554565
* \note This can be the output of a heat or flow solver in a CHT setting.
@@ -696,7 +707,7 @@ class CDriverBase {
696707
if (iMarker < std::numeric_limits<unsigned short>::max() && iMarker > GetNumberMarkers()) {
697708
SU2_MPI::Error("Marker index exceeds size.", CURRENT_FUNCTION);
698709
}
699-
auto* solver = solver_container[ZONE_0][INST_0][MESH_0][iSolver];
710+
auto* solver = solver_container[selected_iZone][INST_0][MESH_0][iSolver];
700711
if (solver == nullptr) SU2_MPI::Error("The selected solver does not exist.", CURRENT_FUNCTION);
701712
return solver;
702713
}

SU2_CFD/src/drivers/CDriverBase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ vector<passivedouble> CDriverBase::GetMarkerVertexNormals(unsigned short iMarker
391391
}
392392

393393
void CDriverBase::CommunicateMeshDisplacements() {
394-
solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->InitiateComms(main_geometry, main_config, MESH_DISPLACEMENTS);
395-
solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->CompleteComms(main_geometry, main_config, MESH_DISPLACEMENTS);
394+
solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->InitiateComms(main_geometry, main_config, MESH_DISPLACEMENTS);
395+
solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->CompleteComms(main_geometry, main_config, MESH_DISPLACEMENTS);
396396
}
397397

398398
map<string, unsigned short> CDriverBase::GetSolverIndices() const {
399399
map<string, unsigned short> indexMap;
400400
for (auto iSol = 0u; iSol < MAX_SOLS; iSol++) {
401-
const auto* solver = solver_container[ZONE_0][INST_0][MESH_0][iSol];
401+
const auto* solver = solver_container[selected_iZone][INST_0][MESH_0][iSol];
402402
if (solver != nullptr) {
403403
if (solver->GetSolverName().empty()) SU2_MPI::Error("Solver name was not defined.", CURRENT_FUNCTION);
404404
indexMap[solver->GetSolverName()] = iSol;
@@ -408,7 +408,7 @@ map<string, unsigned short> CDriverBase::GetSolverIndices() const {
408408
}
409409

410410
std::map<string, unsigned short> CDriverBase::GetFEASolutionIndices() const {
411-
if (solver_container[ZONE_0][INST_0][MESH_0][FEA_SOL] == nullptr) {
411+
if (solver_container[selected_iZone][INST_0][MESH_0][FEA_SOL] == nullptr) {
412412
SU2_MPI::Error("The FEA solver does not exist.", CURRENT_FUNCTION);
413413
}
414414
const auto nDim = main_geometry->GetnDim();
@@ -429,7 +429,7 @@ std::map<string, unsigned short> CDriverBase::GetFEASolutionIndices() const {
429429
}
430430

431431
map<string, unsigned short> CDriverBase::GetPrimitiveIndices() const {
432-
if (solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL] == nullptr) {
432+
if (solver_container[selected_iZone][INST_0][MESH_0][FLOW_SOL] == nullptr) {
433433
SU2_MPI::Error("The flow solver does not exist.", CURRENT_FUNCTION);
434434
}
435435
return PrimitiveNameToIndexMap(CPrimitiveIndices<unsigned short>(

SU2_CFD/src/python_wrapper_structure.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,38 @@ void CDriver::PreprocessPythonInterface(CConfig** config, CGeometry**** geometry
6262
/* Functions to obtain global parameters from SU2 (time steps, delta t, etc.) */
6363
//////////////////////////////////////////////////////////////////////////////////
6464

65-
unsigned long CDriver::GetNumberTimeIter() const { return config_container[ZONE_0]->GetnTime_Iter(); }
65+
unsigned long CDriver::GetNumberTimeIter() const { return config_container[selected_iZone]->GetnTime_Iter(); }
6666

6767
unsigned long CDriver::GetTimeIter() const { return TimeIter; }
6868

6969
passivedouble CDriver::GetUnsteadyTimeStep() const {
70-
return SU2_TYPE::GetValue(config_container[ZONE_0]->GetTime_Step());
70+
return SU2_TYPE::GetValue(config_container[selected_iZone]->GetTime_Step());
7171
}
7272

73-
string CDriver::GetSurfaceFileName() const { return config_container[ZONE_0]->GetSurfCoeff_FileName(); }
73+
string CDriver::GetSurfaceFileName() const { return config_container[selected_iZone]->GetSurfCoeff_FileName(); }
7474

7575
////////////////////////////////////////////////////////////////////////////////
7676
/* Functions related to the management of markers */
7777
////////////////////////////////////////////////////////////////////////////////
7878

7979
void CDriver::SetHeatSourcePosition(passivedouble alpha, passivedouble pos_x, passivedouble pos_y,
8080
passivedouble pos_z) {
81-
CSolver* solver = solver_container[ZONE_0][INST_0][MESH_0][RAD_SOL];
81+
CSolver* solver = solver_container[selected_iZone][INST_0][MESH_0][RAD_SOL];
8282

83-
config_container[ZONE_0]->SetHeatSource_Rot_Z(alpha);
84-
config_container[ZONE_0]->SetHeatSource_Center(pos_x, pos_y, pos_z);
83+
config_container[selected_iZone]->SetHeatSource_Rot_Z(alpha);
84+
config_container[selected_iZone]->SetHeatSource_Center(pos_x, pos_y, pos_z);
8585

86-
solver->SetVolumetricHeatSource(geometry_container[ZONE_0][INST_0][MESH_0], config_container[ZONE_0]);
86+
solver->SetVolumetricHeatSource(geometry_container[selected_iZone][INST_0][MESH_0], config_container[selected_iZone]);
8787
}
8888

8989
void CDriver::SetInletAngle(unsigned short iMarker, passivedouble alpha) {
9090
su2double alpha_rad = alpha * PI_NUMBER / 180.0;
9191

9292
unsigned long iVertex;
9393

94-
for (iVertex = 0; iVertex < geometry_container[ZONE_0][INST_0][MESH_0]->nVertex[iMarker]; iVertex++) {
95-
solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL]->SetInlet_FlowDir(iMarker, iVertex, 0, cos(alpha_rad));
96-
solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL]->SetInlet_FlowDir(iMarker, iVertex, 1, sin(alpha_rad));
94+
for (iVertex = 0; iVertex < geometry_container[selected_iZone][INST_0][MESH_0]->nVertex[iMarker]; iVertex++) {
95+
solver_container[selected_iZone][INST_0][MESH_0][FLOW_SOL]->SetInlet_FlowDir(iMarker, iVertex, 0, cos(alpha_rad));
96+
solver_container[selected_iZone][INST_0][MESH_0][FLOW_SOL]->SetInlet_FlowDir(iMarker, iVertex, 1, sin(alpha_rad));
9797
}
9898
}
9999

@@ -116,22 +116,22 @@ void CSinglezoneDriver::SetInitialMesh() {
116116

117117
SU2_OMP_PARALLEL {
118118
for (iMesh = 0u; iMesh <= main_config->GetnMGLevels(); iMesh++) {
119-
SU2_OMP_FOR_STAT(roundUpDiv(geometry_container[ZONE_0][INST_0][iMesh]->GetnPoint(), omp_get_max_threads()))
120-
for (auto iPoint = 0ul; iPoint < geometry_container[ZONE_0][INST_0][iMesh]->GetnPoint(); iPoint++) {
119+
SU2_OMP_FOR_STAT(roundUpDiv(geometry_container[selected_iZone][INST_0][iMesh]->GetnPoint(), omp_get_max_threads()))
120+
for (auto iPoint = 0ul; iPoint < geometry_container[selected_iZone][INST_0][iMesh]->GetnPoint(); iPoint++) {
121121
/*--- Overwrite fictitious velocities. ---*/
122122
su2double Grid_Vel[3] = {0.0, 0.0, 0.0};
123123

124124
/*--- Set the grid velocity for this coarse node. ---*/
125-
geometry_container[ZONE_0][INST_0][iMesh]->nodes->SetGridVel(iPoint, Grid_Vel);
125+
geometry_container[selected_iZone][INST_0][iMesh]->nodes->SetGridVel(iPoint, Grid_Vel);
126126
}
127127
END_SU2_OMP_FOR
128128
/*--- Push back the volume. ---*/
129-
geometry_container[ZONE_0][INST_0][iMesh]->nodes->SetVolume_n();
130-
geometry_container[ZONE_0][INST_0][iMesh]->nodes->SetVolume_nM1();
129+
geometry_container[selected_iZone][INST_0][iMesh]->nodes->SetVolume_n();
130+
geometry_container[selected_iZone][INST_0][iMesh]->nodes->SetVolume_nM1();
131131
}
132132
/*--- Push back the solution so that there is no fictitious velocity at the next step. ---*/
133-
solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->GetNodes()->Set_Solution_time_n();
134-
solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->GetNodes()->Set_Solution_time_n1();
133+
solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->GetNodes()->Set_Solution_time_n();
134+
solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->GetNodes()->Set_Solution_time_n1();
135135
}
136136
END_SU2_OMP_PARALLEL
137137
}

0 commit comments

Comments
 (0)