Skip to content

Commit b9b34ba

Browse files
committed
Changes to the tape debug mode, improving the detection of errors when recording wrt mesh coordinates.
The tape debug mode code is currently also reworked in #2721. The changes in this commit could already be useful for the current turbo discrete adjoint development.
1 parent 136daa7 commit b9b34ba

4 files changed

Lines changed: 28 additions & 38 deletions

File tree

Common/include/option_structure.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,19 +2624,15 @@ enum class CHECK_TAPE_VARIABLES {
26242624
};
26252625
static const MapType<std::string, CHECK_TAPE_VARIABLES> CheckTapeVariables_Map = {
26262626
MakePair("SOLVER_VARIABLES", CHECK_TAPE_VARIABLES::SOLVER_VARIABLES)
2627-
MakePair("SOLVER_VARIABLES_AND_MESH_COORDINATES", CHECK_TAPE_VARIABLES::MESH_COORDINATES)
2627+
MakePair("MESH_COORDINATES", CHECK_TAPE_VARIABLES::MESH_COORDINATES)
26282628
};
26292629

26302630
enum class RECORDING {
26312631
CLEAR_INDICES,
26322632
SOLUTION_VARIABLES,
26332633
MESH_COORDS,
26342634
MESH_DEFORM,
2635-
SOLUTION_AND_MESH,
2636-
TAG_INIT_SOLVER_VARIABLES,
2637-
TAG_CHECK_SOLVER_VARIABLES,
2638-
TAG_INIT_SOLVER_AND_MESH,
2639-
TAG_CHECK_SOLVER_AND_MESH
2635+
SOLUTION_AND_MESH
26402636
};
26412637

26422638
/*!

SU2_CFD/include/output/CFlowOutput.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CFlowOutput : public CFVMOutput{
4444
*/
4545
CFlowOutput(const CConfig *config, unsigned short nDim, bool femOutput);
4646

47-
/*
47+
/*!
4848
* \brief Add turboperformance outputs as history field
4949
* \param[in] nZone - Number of zones in problem
5050
*/

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,26 @@ void CDiscAdjMultizoneDriver::TapeTest() {
246246

247247
/*--- This recording will assign the initial (same) tag to each registered variable.
248248
* During the recording, each dependent variable will be assigned the same tag. ---*/
249+
AD::SetTag(1);
249250

250251
if(driver_config->GetAD_CheckTapeType() == CHECK_TAPE_TYPE::OBJECTIVE_FUNCTION) {
251252
if(driver_config->GetAD_CheckTapeVariables() == CHECK_TAPE_VARIABLES::MESH_COORDINATES) {
252-
if (rank == MASTER_NODE) cout << "\nChecking OBJECTIVE_FUNCTION_TAPE for SOLVER_VARIABLES_AND_MESH_COORDINATES." << endl;
253-
SetRecording(RECORDING::TAG_INIT_SOLVER_AND_MESH, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
253+
if (rank == MASTER_NODE) cout << "\nChecking OBJECTIVE_FUNCTION_TAPE for MESH_COORDINATES." << endl;
254+
SetRecording(RECORDING::MESH_COORDS, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
254255
}
255256
else {
256-
if (rank == MASTER_NODE) cout << "\nChecking OBJECTIVE_FUNCTION_TAPE for SOLVER_VARIABLES." << endl;
257-
SetRecording(RECORDING::TAG_INIT_SOLVER_VARIABLES, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
257+
if (rank == MASTER_NODE) cout << "\nChecking OBJECTIVE_FUNCTION_TAPE for SOLUTION_VARIABLES." << endl;
258+
SetRecording(RECORDING::SOLUTION_VARIABLES, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
258259
}
259260
}
260261
else {
261262
if(driver_config->GetAD_CheckTapeVariables() == CHECK_TAPE_VARIABLES::MESH_COORDINATES) {
262-
if (rank == MASTER_NODE) cout << "\nChecking FULL_SOLVER_TAPE for SOLVER_VARIABLES_AND_MESH_COORDINATES." << endl;
263-
SetRecording(RECORDING::TAG_INIT_SOLVER_AND_MESH, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
263+
if (rank == MASTER_NODE) cout << "\nChecking FULL_SOLVER_TAPE for MESH_COORDINATES." << endl;
264+
SetRecording(RECORDING::MESH_COORDS, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
264265
}
265266
else {
266-
if (rank == MASTER_NODE) cout << "\nChecking FULL_SOLVER_TAPE for SOLVER_VARIABLES." << endl;
267-
SetRecording(RECORDING::TAG_INIT_SOLVER_VARIABLES, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
267+
if (rank == MASTER_NODE) cout << "\nChecking FULL_SOLVER_TAPE for SOLUTION_VARIABLES." << endl;
268+
SetRecording(RECORDING::SOLUTION_VARIABLES, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
268269
}
269270
}
270271
total_errors = TapeTestGatherErrors(error_report);
@@ -277,18 +278,19 @@ void CDiscAdjMultizoneDriver::TapeTest() {
277278
* from the initial recording and a mismatch with the "check" recording tag will throw an error.
278279
* In such a case, a possible reason could be that such a variable is set by a post-processing routine while
279280
* for a mathematically correct recording this dependency must be included earlier. ---*/
281+
AD::SetTag(2);
280282

281283
if(driver_config->GetAD_CheckTapeType() == CHECK_TAPE_TYPE::OBJECTIVE_FUNCTION) {
282284
if(driver_config->GetAD_CheckTapeVariables() == CHECK_TAPE_VARIABLES::MESH_COORDINATES)
283-
SetRecording(RECORDING::TAG_CHECK_SOLVER_AND_MESH, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
285+
SetRecording(RECORDING::MESH_COORDS, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
284286
else
285-
SetRecording(RECORDING::TAG_CHECK_SOLVER_VARIABLES, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
287+
SetRecording(RECORDING::SOLUTION_VARIABLES, Kind_Tape::OBJECTIVE_FUNCTION_TAPE, ZONE_0);
286288
}
287289
else {
288290
if(driver_config->GetAD_CheckTapeVariables() == CHECK_TAPE_VARIABLES::MESH_COORDINATES)
289-
SetRecording(RECORDING::TAG_CHECK_SOLVER_AND_MESH, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
291+
SetRecording(RECORDING::MESH_COORDS, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
290292
else
291-
SetRecording(RECORDING::TAG_CHECK_SOLVER_VARIABLES, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
293+
SetRecording(RECORDING::SOLUTION_VARIABLES, Kind_Tape::FULL_SOLVER_TAPE, ZONE_0);
292294
}
293295
total_errors += TapeTestGatherErrors(error_report);
294296

@@ -706,10 +708,6 @@ void CDiscAdjMultizoneDriver::SetRecording(RECORDING kind_recording, Kind_Tape t
706708
case RECORDING::CLEAR_INDICES: cout << "Clearing the computational graph." << endl; break;
707709
case RECORDING::MESH_COORDS: cout << "Storing computational graph wrt MESH COORDINATES." << endl; break;
708710
case RECORDING::SOLUTION_VARIABLES: cout << "Storing computational graph wrt CONSERVATIVE VARIABLES." << endl; break;
709-
case RECORDING::TAG_INIT_SOLVER_VARIABLES: cout << "Simulating recording with tag 1 on conservative variables." << endl; AD::SetTag(1); break;
710-
case RECORDING::TAG_CHECK_SOLVER_VARIABLES: cout << "Checking first recording with tag 2 on conservative variables." << endl; AD::SetTag(2); break;
711-
case RECORDING::TAG_INIT_SOLVER_AND_MESH: cout << "Simulating recording with tag 1 on conservative variables and mesh coordinates." << endl; AD::SetTag(1); break;
712-
case RECORDING::TAG_CHECK_SOLVER_AND_MESH: cout << "Checking first recording with tag 2 on conservative variables and mesh coordinates." << endl; AD::SetTag(2); break;
713711
default: break;
714712
}
715713
}
@@ -872,10 +870,7 @@ void CDiscAdjMultizoneDriver::SetObjFunction(RECORDING kind_recording) {
872870
AD::RegisterOutput(ObjFunc);
873871
AD::SetIndex(ObjFunc_Index, ObjFunc);
874872
if (kind_recording == RECORDING::SOLUTION_VARIABLES ||
875-
kind_recording == RECORDING::TAG_INIT_SOLVER_VARIABLES ||
876-
kind_recording == RECORDING::TAG_CHECK_SOLVER_VARIABLES ||
877-
kind_recording == RECORDING::TAG_INIT_SOLVER_AND_MESH ||
878-
kind_recording == RECORDING::TAG_CHECK_SOLVER_AND_MESH) {
873+
kind_recording == RECORDING::MESH_COORDS) {
879874
cout << " Objective function : " << ObjFunc << endl;
880875
}
881876
}

SU2_CFD/src/iteration/CDiscAdjFluidIteration.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,15 @@ void CDiscAdjFluidIteration::RegisterInput(CSolver***** solver, CGeometry**** ge
405405

406406
SU2_OMP_PARALLEL_(if(solvers0[ADJFLOW_SOL]->GetHasHybridParallel())) {
407407

408+
bool AD_debug_mesh_coordinates = false;
409+
if (config[iZone]->GetAD_CheckTapeVariables() == CHECK_TAPE_VARIABLES::MESH_COORDINATES) {
410+
cout << "Register additional SOLUTION VARIABLES for tag debug mode (zone " << iZone << ")." << endl;
411+
AD_debug_mesh_coordinates = true;
412+
}
413+
408414
if (kind_recording == RECORDING::SOLUTION_VARIABLES ||
409-
kind_recording == RECORDING::TAG_INIT_SOLVER_VARIABLES ||
410-
kind_recording == RECORDING::TAG_CHECK_SOLVER_VARIABLES ||
411-
kind_recording == RECORDING::TAG_INIT_SOLVER_AND_MESH ||
412-
kind_recording == RECORDING::TAG_CHECK_SOLVER_AND_MESH ||
413-
kind_recording == RECORDING::SOLUTION_AND_MESH) {
415+
kind_recording == RECORDING::SOLUTION_AND_MESH ||
416+
AD_debug_mesh_coordinates) {
414417

415418
/*--- Register flow and turbulent variables as input ---*/
416419

@@ -441,9 +444,7 @@ void CDiscAdjFluidIteration::RegisterInput(CSolver***** solver, CGeometry**** ge
441444
}
442445

443446
if (kind_recording == RECORDING::MESH_COORDS ||
444-
kind_recording == RECORDING::SOLUTION_AND_MESH ||
445-
kind_recording == RECORDING::TAG_INIT_SOLVER_AND_MESH ||
446-
kind_recording == RECORDING::TAG_CHECK_SOLVER_AND_MESH) {
447+
kind_recording == RECORDING::SOLUTION_AND_MESH) {
447448

448449
/*--- Register node coordinates as input ---*/
449450
geometry0->RegisterCoordinates();
@@ -469,9 +470,7 @@ void CDiscAdjFluidIteration::SetDependencies(CSolver***** solver, CGeometry****
469470

470471
if ((kind_recording == RECORDING::MESH_COORDS) ||
471472
(kind_recording == RECORDING::CLEAR_INDICES) ||
472-
(kind_recording == RECORDING::SOLUTION_AND_MESH) ||
473-
(kind_recording == RECORDING::TAG_INIT_SOLVER_AND_MESH) ||
474-
(kind_recording == RECORDING::TAG_CHECK_SOLVER_AND_MESH)) {
473+
(kind_recording == RECORDING::SOLUTION_AND_MESH)) {
475474
/*--- Update geometry to get the influence on other geometry variables (normals, volume etc) ---*/
476475

477476
SU2_OMP_PARALLEL

0 commit comments

Comments
 (0)