Skip to content

Commit 00f9f14

Browse files
authored
Merge branch 'develop' into py_wrapper_moving_wall
2 parents dfd8dab + 5e82645 commit 00f9f14

7 files changed

Lines changed: 47 additions & 7 deletions

File tree

Common/include/basic_types/ad_structure.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ FORCEINLINE void SetIndex(int& index, const su2double& data) { index = data.getI
396396

397397
// WARNING: For performance reasons, this method does not perform bounds checking.
398398
// When using it, please ensure sufficient adjoint vector size by a call to AD::ResizeAdjoints().
399+
// This method does not perform locking either.
400+
// It should be safeguarded by calls to AD::BeginUseAdjoints() and AD::EndUseAdjoints().
399401
FORCEINLINE void SetDerivative(int index, const double val) {
400402
if (index == 0) // Allow multiple threads to "set the derivative" of passive variables without causing data races.
401403
return;
@@ -406,6 +408,8 @@ FORCEINLINE void SetDerivative(int index, const double val) {
406408
// WARNING: For performance reasons, this method does not perform bounds checking.
407409
// If called after tape evaluations, the adjoints should exist.
408410
// Otherwise, please ensure sufficient adjoint vector size by a call to AD::ResizeAdjoints().
411+
// This method does not perform locking either.
412+
// It should be safeguarded by calls to AD::BeginUseAdjoints() and AD::EndUseAdjoints().
409413
FORCEINLINE double GetDerivative(int index) {
410414
return AD::getTape().getGradient(index, codi::AdjointsManagement::Manual);
411415
}

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,13 +2170,19 @@ class CVariable {
21702170
}
21712171

21722172
inline void GetAdjointSolution_time_n(unsigned long iPoint, su2double *adj_sol) const {
2173-
for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++)
2174-
adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n(iPoint,iVar));
2173+
int index = 0;
2174+
for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++) {
2175+
AD::SetIndex(index, Solution_time_n(iPoint, iVar));
2176+
adj_sol[iVar] = AD::GetDerivative(index);
2177+
}
21752178
}
21762179

21772180
inline void GetAdjointSolution_time_n1(unsigned long iPoint, su2double *adj_sol) const {
2178-
for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++)
2179-
adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n1(iPoint,iVar));
2181+
int index = 0;
2182+
for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++) {
2183+
AD::SetIndex(index, Solution_time_n1(iPoint, iVar));
2184+
adj_sol[iVar] = AD::GetDerivative(index);
2185+
}
21802186
}
21812187

21822188
/*!

SU2_CFD/src/drivers/CDriver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ CDriverBase(confFile, val_nZone, MPICommunicator), StopCalc(false), fsi(false),
248248
cout << endl <<"---------------------- Turbomachinery Preprocessing ---------------------" << endl;
249249

250250
PreprocessTurbomachinery(config_container, geometry_container, solver_container, interface_container);
251+
} else {
252+
mixingplane = false;
251253
}
252254

253255

SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,30 @@ void CDiscAdjFEASolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *co
232232

233233
/*--- Extract and store the adjoint solution ---*/
234234

235+
AD::BeginUseAdjoints();
236+
235237
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
236238
su2double Solution[MAXNVAR] = {0.0};
237239
direct_solver->GetNodes()->GetAdjointSolution(iPoint,Solution);
238240
nodes->SetSolution(iPoint,Solution);
239241
}
240242

243+
AD::EndUseAdjoints();
244+
241245
if (CrossTerm) return;
242246

243247
/*--- Extract and store the adjoint solution at time n (including accel. and velocity) ---*/
244248

245249
if (config->GetTime_Domain()) {
250+
AD::BeginUseAdjoints();
251+
246252
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
247253
su2double Solution[MAXNVAR] = {0.0};
248254
direct_solver->GetNodes()->GetAdjointSolution_time_n(iPoint,Solution);
249255
nodes->Set_Solution_time_n(iPoint,Solution);
250256
}
257+
258+
AD::EndUseAdjoints();
251259
}
252260

253261
/*--- Set the residuals ---*/
@@ -358,6 +366,8 @@ void CDiscAdjFEASolver::SetSensitivity(CGeometry *geometry, CConfig *config, CSo
358366

359367
/*--- Extract the geometric sensitivities ---*/
360368

369+
AD::BeginUseAdjoints();
370+
361371
for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) {
362372

363373
auto Coord = geometry->nodes->GetCoord(iPoint);
@@ -375,6 +385,8 @@ void CDiscAdjFEASolver::SetSensitivity(CGeometry *geometry, CConfig *config, CSo
375385
}
376386
}
377387

388+
AD::EndUseAdjoints();
389+
378390
}
379391

380392
void CDiscAdjFEASolver::ReadDV(const CConfig *config) {

SU2_CFD/src/solvers/CDiscAdjSolver.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi
317317

318318
if (!config->GetMultizone_Problem()) nodes->Set_OldSolution();
319319

320+
AD::BeginUseAdjoints();
321+
320322
SU2_OMP_FOR_STAT(omp_chunk_size)
321323
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
322324

@@ -339,6 +341,8 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi
339341
}
340342
END_SU2_OMP_FOR
341343

344+
AD::EndUseAdjoints();
345+
342346
direct_solver->ExtractAdjoint_SolutionExtra(nodes->GetSolutionExtra(), config);
343347

344348
/*--- Residuals and time_n terms are not needed when evaluating multizone cross terms. ---*/
@@ -355,24 +359,32 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi
355359

356360
/*--- Extract and store the adjoint of the primal solution at time n ---*/
357361
if (time_n_needed) {
362+
AD::BeginUseAdjoints();
363+
358364
SU2_OMP_FOR_STAT(omp_chunk_size)
359365
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
360366
su2double Solution[MAXNVAR] = {0.0};
361367
direct_solver->GetNodes()->GetAdjointSolution_time_n(iPoint,Solution);
362368
nodes->Set_Solution_time_n(iPoint,Solution);
363369
}
364370
END_SU2_OMP_FOR
371+
372+
AD::EndUseAdjoints();
365373
}
366374

367375
/*--- Extract and store the adjoint of the primal solution at time n-1 ---*/
368376
if (time_n1_needed) {
377+
AD::BeginUseAdjoints();
378+
369379
SU2_OMP_FOR_STAT(omp_chunk_size)
370380
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
371381
su2double Solution[MAXNVAR] = {0.0};
372382
direct_solver->GetNodes()->GetAdjointSolution_time_n1(iPoint,Solution);
373383
nodes->Set_Solution_time_n1(iPoint,Solution);
374384
}
375385
END_SU2_OMP_FOR
386+
387+
AD::EndUseAdjoints();
376388
}
377389

378390
}
@@ -477,6 +489,8 @@ void CDiscAdjSolver::SetAdjoint_Output(CGeometry *geometry, CConfig *config) {
477489

478490
void CDiscAdjSolver::SetSensitivity(CGeometry *geometry, CConfig *config, CSolver*) {
479491

492+
AD::BeginUseAdjoints();
493+
480494
SU2_OMP_PARALLEL {
481495

482496
const bool time_stepping = (config->GetTime_Marching() != TIME_MARCHING::STEADY);
@@ -510,6 +524,8 @@ void CDiscAdjSolver::SetSensitivity(CGeometry *geometry, CConfig *config, CSolve
510524

511525
}
512526
END_SU2_OMP_PARALLEL
527+
528+
AD::EndUseAdjoints();
513529
}
514530

515531
void CDiscAdjSolver::SetSurface_Sensitivity(CGeometry *geometry, CConfig *config) {

TestCases/hybrid_regression_AD.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def main():
242242
pywrapper_FEA_AD_FlowLoad.test_vals_aarch64 = [-0.131745, -0.553214, -0.000364, -0.003101]
243243
pywrapper_FEA_AD_FlowLoad.command = TestCase.Command(exec = "python", param = "run_adjoint.py --parallel -f")
244244
pywrapper_FEA_AD_FlowLoad.timeout = 1600
245-
pywrapper_FEA_AD_FlowLoad.tol = 1e-4
245+
pywrapper_FEA_AD_FlowLoad.tol = 1e-3
246246
pywrapper_FEA_AD_FlowLoad.new_output = False
247247
pywrapper_FEA_AD_FlowLoad.enabled_with_tsan = False
248248
test_list.append(pywrapper_FEA_AD_FlowLoad)
@@ -257,7 +257,7 @@ def main():
257257
pywrapper_CFD_AD_MeshDisp.test_vals_aarch64 = [30.000000, -2.516536, 1.386443, 0.000000]
258258
pywrapper_CFD_AD_MeshDisp.command = TestCase.Command(exec = "python", param = "run_adjoint.py --parallel -f")
259259
pywrapper_CFD_AD_MeshDisp.timeout = 1600
260-
pywrapper_CFD_AD_MeshDisp.tol = 1e-4
260+
pywrapper_CFD_AD_MeshDisp.tol = 1e-3
261261
pywrapper_CFD_AD_MeshDisp.new_output = False
262262
pywrapper_CFD_AD_MeshDisp.enabled_with_tsan = False
263263
test_list.append(pywrapper_CFD_AD_MeshDisp)

TestCases/serial_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ def main():
10661066
airfoilRBF.cfg_dir = "fea_fsi/Airfoil_RBF"
10671067
airfoilRBF.cfg_file = "config.cfg"
10681068
airfoilRBF.test_iter = 1
1069-
airfoilRBF.test_vals = [ 1.000000, -2.786186, -4.977944]
1069+
airfoilRBF.test_vals = [1.000000, -2.786186, -4.977944]
10701070
airfoilRBF.multizone = True
10711071
test_list.append(airfoilRBF)
10721072

0 commit comments

Comments
 (0)