Skip to content

Commit 3ff9650

Browse files
authored
Merge pull request #1105 from su2code/nan_checks_better_defaults
Nan checks and better discrete adjoint default options
2 parents 3da85dd + e9ac8a5 commit 3ff9650

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

Common/src/CConfig.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,13 @@ void CConfig::SetConfig_Options() {
10871087
addBoolOption("MULTIZONE", Multizone_Problem, NO);
10881088
/*!\brief PHYSICAL_PROBLEM \n DESCRIPTION: Physical governing equations \n Options: see \link Solver_Map \endlink \n DEFAULT: NO_SOLVER \ingroup Config*/
10891089
addEnumOption("MULTIZONE_SOLVER", Kind_MZSolver, Multizone_Map, MZ_BLOCK_GAUSS_SEIDEL);
1090+
#ifdef CODI_REVERSE_TYPE
1091+
const bool discAdjDefault = true;
1092+
#else
1093+
const bool discAdjDefault = false;
1094+
#endif
10901095
/*!\brief MATH_PROBLEM \n DESCRIPTION: Mathematical problem \n Options: DIRECT, ADJOINT \ingroup Config*/
1091-
addMathProblemOption("MATH_PROBLEM", ContinuousAdjoint, false, DiscreteAdjoint, false, Restart_Flow, false);
1096+
addMathProblemOption("MATH_PROBLEM", ContinuousAdjoint, false, DiscreteAdjoint, discAdjDefault, Restart_Flow, discAdjDefault);
10921097
/*!\brief KIND_TURB_MODEL \n DESCRIPTION: Specify turbulence model \n Options: see \link Turb_Model_Map \endlink \n DEFAULT: NO_TURB_MODEL \ingroup Config*/
10931098
addEnumOption("KIND_TURB_MODEL", Kind_Turb_Model, Turb_Model_Map, NO_TURB_MODEL);
10941099
/*!\brief KIND_TRANS_MODEL \n DESCRIPTION: Specify transition model OPTIONS: see \link Trans_Model_Map \endlink \n DEFAULT: NO_TRANS_MODEL \ingroup Config*/
@@ -4856,6 +4861,10 @@ void CConfig::SetPostprocessing(unsigned short val_software, unsigned short val_
48564861
}
48574862
#endif
48584863

4864+
/*--- Use the same linear solver on the primal as the one used in the adjoint. ---*/
4865+
Kind_Linear_Solver = Kind_DiscAdj_Linear_Solver;
4866+
Kind_Linear_Solver_Prec = Kind_DiscAdj_Linear_Prec;
4867+
48594868
/*--- Disable writing of limiters if enabled ---*/
48604869
Wrt_Limiters = false;
48614870

SU2_CFD/src/output/COutput.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ bool COutput::Convergence_Monitoring(CConfig *config, unsigned long Iteration) {
839839
if (historyOutput_Map.count(convField) > 0){
840840
su2double monitor = historyOutput_Map.at(convField).value;
841841

842+
/*--- Stop the simulation in case a nan appears, do not save the solution ---*/
843+
if (isnan(SU2_TYPE::GetValue(monitor))) {
844+
SU2_MPI::Error("SU2 has diverged (NaN detected).", CURRENT_FUNCTION);
845+
}
846+
842847
/*--- Cauchy based convergence criteria ---*/
843848

844849
if (historyOutput_Map.at(convField).fieldType == HistoryFieldType::COEFFICIENT) {
@@ -962,6 +967,11 @@ bool COutput::MonitorTimeConvergence(CConfig *config, unsigned long TimeIteratio
962967
if (historyOutput_Map.count(WndConv_Field) > 0){
963968
su2double monitor = historyOutput_Map[WndConv_Field].value;
964969

970+
/*--- Stop the simulation in case a nan appears, do not save the solution ---*/
971+
if (isnan(SU2_TYPE::GetValue(monitor))) {
972+
SU2_MPI::Error("SU2 has diverged (NaN detected).", CURRENT_FUNCTION);
973+
}
974+
965975
/*--- Cauchy based convergence criteria ---*/
966976

967977
if (historyOutput_Map[WndConv_Field].fieldType == HistoryFieldType::AUTO_COEFFICIENT) { //TAVG values are AUTO_COEFF
@@ -996,11 +1006,6 @@ bool COutput::MonitorTimeConvergence(CConfig *config, unsigned long TimeIteratio
9961006
SetHistoryOutputValue("CAUCHY_" + WndConv_Field, WndCauchy_Value);
9971007
}
9981008
TimeConvergence = fieldConverged && TimeConvergence;
999-
1000-
/*--- Stop the simulation in case a nan appears, do not save the solution ---*/
1001-
1002-
if (monitor != monitor){
1003-
SU2_MPI::Error("SU2 has diverged (NaN detected).", CURRENT_FUNCTION);}
10041009
}
10051010
}
10061011

config_template.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ KIND_SGS_MODEL= NONE
3333
KIND_VERIFICATION_SOLUTION= NO_VERIFICATION_SOLUTION
3434
%
3535
% Mathematical problem (DIRECT, CONTINUOUS_ADJOINT, DISCRETE_ADJOINT)
36+
% Defaults to DISCRETE_ADJOINT for the SU2_*_AD codes, and to DIRECT otherwise.
3637
MATH_PROBLEM= DIRECT
3738
%
3839
% Axisymmetric simulation, only compressible flows (NO, YES)
@@ -976,13 +977,13 @@ ADJ_JST_SENSOR_COEFF= ( 0.5, 0.02 )
976977
% BCGSTAB, FGMRES, RESTARTED_FGMRES, CONJUGATE_GRADIENT (self-adjoint problems only), SMOOTHER.
977978
LINEAR_SOLVER= FGMRES
978979
%
979-
% Same for discrete adjoint (smoothers not supported)
980+
% Same for discrete adjoint (smoothers not supported), replaces LINEAR_SOLVER in SU2_*_AD codes.
980981
DISCADJ_LIN_SOLVER= FGMRES
981982
%
982983
% Preconditioner of the Krylov linear solver or type of smoother (ILU, LU_SGS, LINELET, JACOBI)
983984
LINEAR_SOLVER_PREC= ILU
984985
%
985-
% Same for discrete adjoint (JACOBI or ILU)
986+
% Same for discrete adjoint (JACOBI or ILU), replaces LINEAR_SOLVER_PREC in SU2_*_AD codes.
986987
DISCADJ_LIN_PREC= ILU
987988
%
988989
% Linael solver ILU preconditioner fill-in level (0 by default)

0 commit comments

Comments
 (0)