Skip to content

Commit

Permalink
added compatibility for multizone driver selection
Browse files Browse the repository at this point in the history
  • Loading branch information
afshawnlotfi committed Apr 29, 2023
1 parent 2bb4550 commit df5838c
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 109 deletions.
19 changes: 15 additions & 4 deletions SU2_CFD/include/drivers/CDriverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CDriverBase {
UsedTime; /*!< \brief Elapsed time between Start and Stop point of the timer. */

unsigned long TimeIter;

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

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

auto* coords =
const_cast<su2activematrix*>(solver_container[ZONE_0][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
const_cast<su2activematrix*>(solver_container[selected_iZone][INST_0][MESH_0][MESH_SOL]->GetNodes()->GetMesh_Coord());
return CPyWrapperMarkerMatrixView(*coords, main_geometry->vertex[iMarker], main_geometry->GetnVertex(iMarker),
"MarkerInitialCoordinates", true);
}
Expand Down Expand Up @@ -530,6 +530,17 @@ class CDriverBase {
main_geometry->SetCustomBoundaryHeatFlux(iMarker, iVertex, WallHeatFlux);
}


/*!
* \brief Selects zone to be used for Driver operation
* \param[in] iZone - Zone identifier.
*/
inline void SelectZone(unsigned long iZone) {
selected_iZone = iZone;
main_geometry = geometry_container[selected_iZone][INST_0][MESH_0];
main_config = config_container[selected_iZone];
}

/*!
* \brief Get the wall normal heat flux at a vertex on a specified marker of the flow or heat solver.
* \note This can be the output of a heat or flow solver in a CHT setting.
Expand Down Expand Up @@ -677,7 +688,7 @@ class CDriverBase {
if (iMarker < std::numeric_limits<unsigned short>::max() && iMarker > GetNumberMarkers()) {
SU2_MPI::Error("Marker index exceeds size.", CURRENT_FUNCTION);
}
auto* solver = solver_container[ZONE_0][INST_0][MESH_0][iSolver];
auto* solver = solver_container[selected_iZone][INST_0][MESH_0][iSolver];
if (solver == nullptr) SU2_MPI::Error("The selected solver does not exist.", CURRENT_FUNCTION);
return solver;
}
Expand Down
8 changes: 4 additions & 4 deletions SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void CDiscAdjMultizoneDriver::Run() {
/*--- Check for convergence. ---*/

StopCalc = driver_output->GetConvergence() || (iOuterIter == nOuterIter-1) ||
((nZone==1) && output_container[ZONE_0]->GetConvergence());
((nZone==1) && output_container[selected_iZone]->GetConvergence());

/*--- Clear the stored adjoint information to be ready for a new evaluation. ---*/

Expand Down Expand Up @@ -765,13 +765,13 @@ void CDiscAdjMultizoneDriver::SetObjFunction(RECORDING kind_recording) {
void CDiscAdjMultizoneDriver::SetAdjObjFunction() {
su2double seeding = 1.0;

if (config_container[ZONE_0]->GetTime_Domain()) {
const auto IterAvg_Obj = config_container[ZONE_0]->GetIter_Avg_Objective();
if (config_container[selected_iZone]->GetTime_Domain()) {
const auto IterAvg_Obj = config_container[selected_iZone]->GetIter_Avg_Objective();
if (TimeIter < IterAvg_Obj) {
/*--- Default behavior when no window is chosen is to use Square-Windowing, i.e. the numerator equals 1.0 ---*/
auto windowEvaluator = CWindowingTools();
const su2double weight =
windowEvaluator.GetWndWeight(config_container[ZONE_0]->GetKindWindow(), TimeIter, IterAvg_Obj - 1);
windowEvaluator.GetWndWeight(config_container[selected_iZone]->GetKindWindow(), TimeIter, IterAvg_Obj - 1);
seeding = weight / IterAvg_Obj;
}
else {
Expand Down
Loading

0 comments on commit df5838c

Please sign in to comment.