Skip to content

Commit 68cdd8d

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into feature_update_mpp
2 parents f5160b2 + da0c951 commit 68cdd8d

File tree

9 files changed

+78
-45
lines changed

9 files changed

+78
-45
lines changed

Common/include/code_config.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,30 @@ FORCEINLINE Out su2staticcast_p(In ptr) {
9898
#if defined(HAVE_OMP)
9999
using su2double = codi::RealReverseIndexOpenMPGen<double, double>;
100100
#else
101-
#if defined(CODI_INDEX_TAPE)
101+
#if defined(CODI_JACOBIAN_LINEAR_TAPE)
102+
using su2double = codi::RealReverse;
103+
#elif defined(CODI_JACOBIAN_REUSE_TAPE)
104+
using su2double = codi::RealReverseIndexGen<double, double, codi::ReuseIndexManager<int> >;
105+
#elif defined(CODI_JACOBIAN_MULTIUSE_TAPE)
102106
using su2double = codi::RealReverseIndex;
103-
// #elif defined(CODI_PRIMAL_TAPE)
104-
// using su2double = codi::RealReversePrimal;
105-
// #elif defined(CODI_PRIMAL_INDEX_TAPE)
106-
// using su2double = codi::RealReversePrimalIndex;
107+
#elif defined(CODI_PRIMAL_LINEAR_TAPE)
108+
using su2double = codi::RealReversePrimal;
109+
#elif defined(CODI_PRIMAL_REUSE_TAPE)
110+
using su2double = codi::RealReversePrimalIndexGen<double, double, codi::ReuseIndexManager<int> >;
111+
#elif defined(CODI_PRIMAL_MULTIUSE_TAPE)
112+
using su2double = codi::RealReversePrimalIndex;
107113
#else
108-
using su2double = codi::RealReverse;
114+
#error "Please define a CoDiPack tape."
109115
#endif
110116
#endif
117+
118+
#if defined(HAVE_OMP) || defined(CODI_JACOBIAN_REUSE_TAPE) || defined(CODI_JACOBIAN_MULTIUSE_TAPE) || \
119+
defined(CODI_PRIMAL_REUSE_TAPE) || defined(CODI_PRIMAL_MULTIUSE_TAPE)
120+
#define CODI_INDEX_REUSE
121+
#endif
111122
#elif defined(CODI_FORWARD_TYPE) // forward mode AD
112123
#include "codi.hpp"
113124
using su2double = codi::RealForward;
114-
115125
#else // primal / direct / no AD
116126
using su2double = double;
117127
#endif

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/CDiscAdjMultizoneDriver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,9 @@ void CDiscAdjMultizoneDriver::SetAdjObjFunction() {
786786

787787
void CDiscAdjMultizoneDriver::ComputeAdjoints(unsigned short iZone, bool eval_transfer) {
788788

789-
#if defined(CODI_INDEX_TAPE) || defined(HAVE_OPDI)
789+
#if defined(CODI_INDEX_REUSE)
790790
if (nZone > 1 && rank == MASTER_NODE) {
791-
std::cout << "WARNING: Index AD types do not support multiple zones." << std::endl;
791+
std::cout << "WARNING: AD types that reuse indices do not support multiple zones." << std::endl;
792792
}
793793
#endif
794794

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
}

meson.build

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,25 @@ if get_option('enable-autodiff') or get_option('enable-directdiff')
7777
codi_for_args = ['-DCODI_FORWARD_TYPE']
7878
endif
7979

80-
if get_option('enable-autodiff')
81-
if get_option('codi-tape') == 'JacobianIndex'
82-
codi_rev_args += '-DCODI_INDEX_TAPE'
83-
#elif get_option('codi-tape') == 'PrimalLinear'
84-
# codi_rev_args += '-DCODI_PRIMAL_TAPE'
85-
#elif get_option('codi-tape') == 'PrimalIndex'
86-
# codi_rev_args += '-DCODI_PRIMAL_INDEX_TAPE'
80+
if get_option('enable-autodiff') and not omp
81+
if get_option('codi-tape') == 'JacobianLinear'
82+
codi_rev_args += '-DCODI_JACOBIAN_LINEAR_TAPE'
83+
elif get_option('codi-tape') == 'JacobianReuse'
84+
codi_rev_args += '-DCODI_JACOBIAN_REUSE_TAPE'
85+
elif get_option('codi-tape') == 'JacobianMultiUse'
86+
codi_rev_args += '-DCODI_JACOBIAN_MULTIUSE_TAPE'
87+
elif get_option('codi-tape') == 'PrimalLinear'
88+
codi_rev_args += '-DCODI_PRIMAL_LINEAR_TAPE'
89+
elif get_option('codi-tape') == 'PrimalReuse'
90+
codi_rev_args += '-DCODI_PRIMAL_REUSE_TAPE'
91+
elif get_option('codi-tape') == 'PrimalMultiUse'
92+
codi_rev_args += '-DCODI_PRIMAL_MULTIUSE_TAPE'
93+
else
94+
message('Invalid CoDiPack tape choice @1@'.format(get_option('codi-tape')))
95+
endif
96+
97+
if get_option('codi-tape') != 'JacobianLinear'
98+
warning('The tape choice @1@ is not tested regularly in SU2'.format(get_option('codi-tape')))
8799
endif
88100
endif
89101

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ option('install-mpp', type : 'boolean', value : false, description: 'install Mut
2222
option('enable-coolprop', type : 'boolean', value : false, description: 'enable CoolProp support')
2323
option('enable-mlpcpp', type : 'boolean', value : false, description: 'enable MLPCpp support')
2424
option('opdi-backend', type : 'combo', choices : ['auto', 'macro', 'ompt'], value : 'auto', description: 'OpDiLib backend choice')
25-
option('codi-tape', type : 'combo', choices : ['JacobianLinear', 'JacobianIndex'], value : 'JacobianLinear', description: 'CoDiPack tape choice')
25+
option('codi-tape', type : 'combo', choices : ['JacobianLinear', 'JacobianReuse', 'JacobianMultiUse', 'PrimalLinear', 'PrimalReuse', 'PrimalMultiUse'], value : 'JacobianLinear', description: 'CoDiPack tape choice')
2626
option('opdi-shared-read-opt', type : 'boolean', value : true, description : 'OpDiLib shared reading optimization')
2727
option('librom_root', type : 'string', value : '', description: 'libROM base directory')
2828
option('enable-librom', type : 'boolean', value : false, description: 'enable LLNL libROM support')

meson_scripts/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def init_submodules(
5555

5656
# This information of the modules is used if projects was not cloned using git
5757
# The sha tag must be maintained manually to point to the correct commit
58-
sha_version_codi = "17232fed05245dbb8f04a31e274a02d53458c75c"
58+
sha_version_codi = "c30f195eb9d772cadc75e9dbf4c88cb351ee34bb"
5959
github_repo_codi = "https://github.com/scicompkl/CoDiPack"
6060
sha_version_medi = "aafc2d1966ba1233640af737e71c77c1a86183fd"
6161
github_repo_medi = "https://github.com/SciCompKL/MeDiPack"

0 commit comments

Comments
 (0)