diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp index 050be2b7787..453dca7226b 100644 --- a/SU2_CFD/include/variables/CVariable.hpp +++ b/SU2_CFD/include/variables/CVariable.hpp @@ -2170,13 +2170,19 @@ class CVariable { } inline void GetAdjointSolution_time_n(unsigned long iPoint, su2double *adj_sol) const { - for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++) - adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n(iPoint,iVar)); + int index = 0; + for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++) { + AD::SetIndex(index, Solution_time_n(iPoint, iVar)); + adj_sol[iVar] = AD::GetDerivative(index); + } } inline void GetAdjointSolution_time_n1(unsigned long iPoint, su2double *adj_sol) const { - for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++) - adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n1(iPoint,iVar)); + int index = 0; + for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++) { + AD::SetIndex(index, Solution_time_n1(iPoint, iVar)); + adj_sol[iVar] = AD::GetDerivative(index); + } } /*! diff --git a/SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp b/SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp index 7abd17805fa..baf00a826a2 100644 --- a/SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp +++ b/SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp @@ -247,11 +247,15 @@ void CDiscAdjFEASolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *co /*--- Extract and store the adjoint solution at time n (including accel. and velocity) ---*/ if (config->GetTime_Domain()) { + AD::BeginUseAdjoints(); + for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { su2double Solution[MAXNVAR] = {0.0}; direct_solver->GetNodes()->GetAdjointSolution_time_n(iPoint,Solution); nodes->Set_Solution_time_n(iPoint,Solution); } + + AD::EndUseAdjoints(); } /*--- Set the residuals ---*/ diff --git a/SU2_CFD/src/solvers/CDiscAdjSolver.cpp b/SU2_CFD/src/solvers/CDiscAdjSolver.cpp index ac9c6043097..6b8fd2a199d 100644 --- a/SU2_CFD/src/solvers/CDiscAdjSolver.cpp +++ b/SU2_CFD/src/solvers/CDiscAdjSolver.cpp @@ -359,6 +359,8 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi /*--- Extract and store the adjoint of the primal solution at time n ---*/ if (time_n_needed) { + AD::BeginUseAdjoints(); + SU2_OMP_FOR_STAT(omp_chunk_size) for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { su2double Solution[MAXNVAR] = {0.0}; @@ -366,10 +368,14 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi nodes->Set_Solution_time_n(iPoint,Solution); } END_SU2_OMP_FOR + + AD::EndUseAdjoints(); } /*--- Extract and store the adjoint of the primal solution at time n-1 ---*/ if (time_n1_needed) { + AD::BeginUseAdjoints(); + SU2_OMP_FOR_STAT(omp_chunk_size) for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) { su2double Solution[MAXNVAR] = {0.0}; @@ -377,6 +383,8 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi nodes->Set_Solution_time_n1(iPoint,Solution); } END_SU2_OMP_FOR + + AD::EndUseAdjoints(); } }