Skip to content

Commit 575c157

Browse files
authored
Merge pull request #1036 from su2code/fix_cfl_adapt
Update adaptive CFL
2 parents ce6f487 + b5e8420 commit 575c157

25 files changed

Lines changed: 172 additions & 179 deletions

Common/include/CConfig.hpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ class CConfig {
735735
unsigned short Tab_FileFormat; /*!< \brief Format of the output files. */
736736
unsigned short ActDisk_Jump; /*!< \brief Format of the output files. */
737737
unsigned long StartWindowIteration; /*!< \brief Starting Iteration for long time Windowing apporach . */
738-
bool CFL_Adapt; /*!< \brief Adaptive CFL number. */
738+
unsigned short nCFL_AdaptParam; /*!< \brief Number of CFL parameters provided in config. */
739+
bool CFL_Adapt; /*!< \brief Use adaptive CFL number. */
739740
bool HB_Precondition; /*!< \brief Flag to turn on harmonic balance source term preconditioning */
740741
su2double RefArea, /*!< \brief Reference area for coefficient computation. */
741742
RefElemLength, /*!< \brief Reference element length for computing the slope limiting epsilon. */
@@ -758,12 +759,10 @@ class CConfig {
758759
su2double* Mesh_Box_Length; /*!< \brief Array containing the length in the x-, y-, and z-directions for the analytic RECTANGLE and BOX grid formats. */
759760
su2double* Mesh_Box_Offset; /*!< \brief Array containing the offset from 0.0 in the x-, y-, and z-directions for the analytic RECTANGLE and BOX grid formats. */
760761
string Mesh_FileName, /*!< \brief Mesh input file. */
761-
Target_Mesh_FileName, /*!< \brief Mesh name to be adapted. */
762762
Mesh_Out_FileName, /*!< \brief Mesh output file. */
763763
Solution_FileName, /*!< \brief Flow solution input file. */
764764
Solution_AdjFileName, /*!< \brief Adjoint solution input file for drag functional. */
765765
Volume_FileName, /*!< \brief Flow variables output file. */
766-
Residual_FileName, /*!< \brief Residual variables output file. */
767766
Conv_FileName, /*!< \brief Convergence history output file. */
768767
Breakdown_FileName, /*!< \brief Breakdown output file. */
769768
Restart_FileName, /*!< \brief Restart file for flow variables. */
@@ -1057,10 +1056,10 @@ class CConfig {
10571056
bool Radiation; /*!< \brief Determines if a radiation model is incorporated. */
10581057
su2double CFL_Rad; /*!< \brief CFL Number for the radiation solver. */
10591058

1059+
array<su2double,5> default_cfl_adapt; /*!< \brief Default CFL adapt param array for the COption class. */
10601060
su2double default_vel_inf[3], /*!< \brief Default freestream velocity array for the COption class. */
10611061
default_eng_cyl[7], /*!< \brief Default engine box array for the COption class. */
10621062
default_eng_val[5], /*!< \brief Default engine box array values for the COption class. */
1063-
default_cfl_adapt[4], /*!< \brief Default CFL adapt param array for the COption class. */
10641063
default_jst_coeff[2], /*!< \brief Default artificial dissipation (flow) array for the COption class. */
10651064
default_ffd_coeff[3], /*!< \brief Default artificial dissipation (flow) array for the COption class. */
10661065
default_mixedout_coeff[3], /*!< \brief Default default mixedout algorithm coefficients for the COption class. */
@@ -1157,7 +1156,7 @@ class CConfig {
11571156
monoatomic; /*!< \brief Flag for monoatomic mixture. */
11581157
string GasModel, /*!< \brief Gas Model. */
11591158
*Wall_Catalytic; /*!< \brief Pointer to catalytic walls. */
1160-
1159+
11611160
/*!
11621161
* \brief Set the default values of config options not set in the config file using another config object.
11631162
* \param config - Config object to use the default values from.
@@ -1539,13 +1538,6 @@ class CConfig {
15391538
*/
15401539
su2double GetCFL_AdaptParam(unsigned short val_index) const { return CFL_AdaptParam[val_index]; }
15411540

1542-
/*!
1543-
* \brief Set the values of the CFL adaption parameters.
1544-
* \param[in] val_index - Index of the particular CFL adaption parameter
1545-
* \param[in] val_cfl_param - Value of the CFL adaption parameter
1546-
*/
1547-
void SetCFL_AdaptParam(unsigned short val_index, su2double val_cfl_param) { CFL_AdaptParam[val_index] = val_cfl_param; }
1548-
15491541
/*!
15501542
* \brief Get the value of the CFL adaption flag.
15511543
* \return <code>TRUE</code> if CFL adaption is active; otherwise <code>FALSE</code>.
@@ -5112,11 +5104,6 @@ class CConfig {
51125104
*/
51135105
bool GetRestart(void) const { return Restart; }
51145106

5115-
/*!
5116-
* \brief Sets the restart information.
5117-
*/
5118-
void SetRestart(bool val_restart) { Restart = val_restart; }
5119-
51205107
/*!
51215108
* \brief Flag for whether binary SU2 native restart files are read.
51225109
* \return Flag for whether binary SU2 native restart files are read, if <code>TRUE</code> then the code will load binary restart files.
@@ -5214,12 +5201,6 @@ class CConfig {
52145201
*/
52155202
string GetSolution_AdjFileName(void) const { return Solution_AdjFileName; }
52165203

5217-
/*!
5218-
* \brief Get the name of the file with the residual of the problem.
5219-
* \return Name of the file with the residual of the problem.
5220-
*/
5221-
string GetResidual_FileName(void);
5222-
52235204
/*!
52245205
* \brief Get the format of the input/output grid.
52255206
* \return Format of the input/output grid.

Common/include/option_structure.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const unsigned int INST_0 = 0; /*!< \brief Definition of the first instance per
9494

9595
const su2double STANDARD_GRAVITY = 9.80665; /*!< \brief Acceleration due to gravity at surface of earth. */
9696
const su2double UNIVERSAL_GAS_CONSTANT = 8.3144598; /*!< \brief Universal gas constant in J/(mol*K) */
97-
const su2double BOLTZMANN_CONSTANT = 1.3806503E-23; /*! \brief Boltzmann's constant [J K^-1] */
97+
const su2double BOLTZMANN_CONSTANT = 1.3806503E-23; /*! \brief Boltzmann's constant [J K^-1] */
9898
const su2double AVOGAD_CONSTANT = 6.0221415E26; /*!< \brief Avogardro's constant, number of particles in one kmole. */
9999

100100
const su2double EPS = 1.0E-16; /*!< \brief Error scale. */
@@ -541,9 +541,9 @@ enum ENUM_FLUIDMODEL {
541541
PR_GAS = 3, /*!< \brief Perfect Real gas model. */
542542
CONSTANT_DENSITY = 4, /*!< \brief Constant density gas model. */
543543
INC_IDEAL_GAS = 5, /*!< \brief Incompressible ideal gas model. */
544-
INC_IDEAL_GAS_POLY = 6, /*!< \brief Inc. ideal gas, polynomial gas model. */
544+
INC_IDEAL_GAS_POLY = 6, /*!< \brief Inc. ideal gas, polynomial gas model. */
545545
MUTATIONPP = 7, /*!< \brief Mutation++ gas model for nonequilibrium flow. */
546-
SU2_NONEQ = 8 /*!< \brief User defined gas model for nonequilibrium flow. */
546+
SU2_NONEQ = 8 /*!< \brief User defined gas model for nonequilibrium flow. */
547547
};
548548
static const MapType<string, ENUM_FLUIDMODEL> FluidModel_Map = {
549549
MakePair("STANDARD_AIR", STANDARD_AIR)

Common/src/CConfig.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,11 +1618,12 @@ void CConfig::SetConfig_Options() {
16181618
/* DESCRIPTION: Activate The adaptive CFL number. */
16191619
addBoolOption("CFL_ADAPT", CFL_Adapt, false);
16201620
/* !\brief CFL_ADAPT_PARAM
1621-
* DESCRIPTION: Parameters of the adaptive CFL number (factor down, factor up, CFL limit (min and max) )
1621+
* DESCRIPTION: Parameters of the adaptive CFL number (factor down, factor up, CFL limit (min and max), acceptable linear residual )
16221622
* Factor down generally <1.0, factor up generally > 1.0 to cause the CFL to increase when the under-relaxation parameter is 1.0
16231623
* and to decrease when the under-relaxation parameter is less than 0.1. Factor is multiplicative. \ingroup Config*/
16241624
default_cfl_adapt[0] = 1.0; default_cfl_adapt[1] = 1.0; default_cfl_adapt[2] = 10.0; default_cfl_adapt[3] = 100.0;
1625-
addDoubleArrayOption("CFL_ADAPT_PARAM", 4, CFL_AdaptParam, default_cfl_adapt);
1625+
default_cfl_adapt[4] = 0.001;
1626+
addDoubleListOption("CFL_ADAPT_PARAM", nCFL_AdaptParam, CFL_AdaptParam);
16261627
/* DESCRIPTION: Reduction factor of the CFL coefficient in the adjoint problem */
16271628
addDoubleOption("CFL_REDUCTION_ADJFLOW", CFLRedCoeff_AdjFlow, 0.8);
16281629
/* DESCRIPTION: Reduction factor of the CFL coefficient in the level set problem */
@@ -4143,6 +4144,19 @@ void CConfig::SetPostprocessing(unsigned short val_software, unsigned short val_
41434144
CFL = new su2double[nCFL];
41444145
CFL[0] = CFLFineGrid;
41454146

4147+
/*--- Handle optional CFL adapt parameter values ---*/
4148+
4149+
if (nCFL_AdaptParam < default_cfl_adapt.size()) {
4150+
auto newParam = new su2double [default_cfl_adapt.size()];
4151+
for (iCFL = 0; iCFL < default_cfl_adapt.size(); ++iCFL) {
4152+
if (iCFL < nCFL_AdaptParam) newParam[iCFL] = CFL_AdaptParam[iCFL];
4153+
else newParam[iCFL] = default_cfl_adapt[iCFL];
4154+
}
4155+
swap(newParam, CFL_AdaptParam);
4156+
delete [] newParam;
4157+
nCFL_AdaptParam = default_cfl_adapt.size();
4158+
}
4159+
41464160
/*--- Evaluate when the Cl should be evaluated ---*/
41474161

41484162
Iter_Fixed_CM = SU2_TYPE::Int(nInnerIter / (su2double(Update_iH)+1));
@@ -6540,7 +6554,8 @@ void CConfig::SetOutput(unsigned short val_software, unsigned short val_izone) {
65406554

65416555
if (!CFL_Adapt) cout << "No CFL adaptation." << endl;
65426556
else cout << "CFL adaptation. Factor down: "<< CFL_AdaptParam[0] <<", factor up: "<< CFL_AdaptParam[1]
6543-
<<",\n lower limit: "<< CFL_AdaptParam[2] <<", upper limit: " << CFL_AdaptParam[3] <<"."<< endl;
6557+
<<",\n lower limit: "<< CFL_AdaptParam[2] <<", upper limit: " << CFL_AdaptParam[3]
6558+
<<",\n acceptable linear residual: "<< CFL_AdaptParam[4] << "." << endl;
65446559

65456560
if (nMGLevels !=0) {
65466561
PrintingToolbox::CTablePrinter MGTable(&std::cout);

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,13 +2026,11 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
20262026
unsigned long iVertex, iPoint, iPointNormal;
20272027
unsigned short iMarker, iMarker_Monitoring, iDim, jDim;
20282028
unsigned short T_INDEX = 0, TVE_INDEX = 0, VEL_INDEX = 0;
2029-
su2double Viscosity = 0.0, WallDist[3] = {0.0}, Area, TauNormal, RefTemp, RefVel2 = 0.0,
2029+
su2double Viscosity = 0.0, WallDist[3] = {0.0}, Area, TauNormal, RefTemp, RefVel2 = 0.0, dTn, dTven,
20302030
RefDensity = 0.0, GradTemperature, Density = 0.0, WallDistMod, FrictionVel, Mach2Vel, Mach_Motion,
20312031
UnitNormal[3] = {0.0}, TauElem[3] = {0.0}, TauTangent[3] = {0.0}, Tau[3][3] = {{0.0}}, Cp,
2032-
thermal_conductivity, thermal_conductivity_tr, thermal_conductivity_ve = 0.0,
2033-
MaxNorm = 8.0, Grad_Vel[3][3] = {{0.0}}, Grad_Temp[3] = {0.0}, AxiFactor;
2032+
thermal_conductivity, MaxNorm = 8.0, Grad_Vel[3][3] = {{0.0}}, Grad_Temp[3] = {0.0}, AxiFactor;
20342033
const su2double *Coord = nullptr, *Coord_Normal = nullptr, *Normal = nullptr;
2035-
su2double **Grad_PrimVar = nullptr, dTn, dTven;
20362034

20372035
string Marker_Tag, Monitoring_Tag;
20382036

@@ -2170,12 +2168,6 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
21702168
}
21712169
Density = nodes->GetDensity(iPoint);
21722170

2173-
if (nemo) {
2174-
thermal_conductivity_tr = nodes->GetThermalConductivity(iPoint);
2175-
thermal_conductivity_ve = nodes->GetThermalConductivity_ve(iPoint);
2176-
Grad_PrimVar = nodes->GetGradient_Primitive(iPoint);
2177-
}
2178-
21792171
Area = GeometryToolbox::Norm(nDim, Normal);
21802172
for (iDim = 0; iDim < nDim; iDim++) {
21812173
UnitNormal[iDim] = Normal[iDim] / Area;
@@ -2247,6 +2239,10 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
22472239

22482240
} else {
22492241

2242+
const auto thermal_conductivity_tr = nodes->GetThermalConductivity(iPoint);
2243+
const auto thermal_conductivity_ve = nodes->GetThermalConductivity_ve(iPoint);
2244+
const auto Grad_PrimVar = nodes->GetGradient_Primitive(iPoint);
2245+
22502246
dTn = 0.0; dTven = 0.0;
22512247
for (iDim = 0; iDim < nDim; iDim++) {
22522248
dTn += Grad_PrimVar[T_INDEX][iDim]*UnitNormal[iDim];

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class CSolver {
6969
unsigned short MGLevel; /*!< \brief Multigrid level of this solver object. */
7070
unsigned short IterLinSolver; /*!< \brief Linear solver iterations. */
7171
su2double ResLinSolver; /*!< \brief Final linear solver residual. */
72-
su2double NonLinRes_Value, /*!< \brief Summed value of the nonlinear residual indicator. */
73-
NonLinRes_Func; /*!< \brief Current value of the nonlinear residual indicator at one iteration. */
7472
unsigned short NonLinRes_Counter; /*!< \brief Number of elements of the nonlinear residual indicator series. */
7573
vector<su2double> NonLinRes_Series; /*!< \brief Vector holding the nonlinear residual indicator series. */
7674
su2double Old_Func, /*!< \brief Old value of the nonlinear residual indicator. */

SU2_CFD/src/iteration/CFluidIteration.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ void CFluidIteration::Iterate(COutput* output, CIntegration**** integration, CGe
5858
CFreeFormDefBox*** FFDBox, unsigned short val_iZone, unsigned short val_iInst) {
5959
unsigned long InnerIter, TimeIter;
6060

61-
bool unsteady = (config[val_iZone]->GetTime_Marching() == DT_STEPPING_1ST) ||
62-
(config[val_iZone]->GetTime_Marching() == DT_STEPPING_2ND);
63-
bool frozen_visc = (config[val_iZone]->GetContinuous_Adjoint() && config[val_iZone]->GetFrozen_Visc_Cont()) ||
64-
(config[val_iZone]->GetDiscrete_Adjoint() && config[val_iZone]->GetFrozen_Visc_Disc());
61+
const bool unsteady = (config[val_iZone]->GetTime_Marching() == DT_STEPPING_1ST) ||
62+
(config[val_iZone]->GetTime_Marching() == DT_STEPPING_2ND);
63+
const bool frozen_visc = (config[val_iZone]->GetContinuous_Adjoint() && config[val_iZone]->GetFrozen_Visc_Cont()) ||
64+
(config[val_iZone]->GetDiscrete_Adjoint() && config[val_iZone]->GetFrozen_Visc_Disc());
65+
const bool disc_adj = (config[val_iZone]->GetDiscrete_Adjoint());
6566
TimeIter = config[val_iZone]->GetTimeIter();
6667

6768
/* --- Setting up iteration values depending on if this is a
@@ -134,7 +135,7 @@ void CFluidIteration::Iterate(COutput* output, CIntegration**** integration, CGe
134135

135136
/*--- Adapt the CFL number using an exponential progression with under-relaxation approach. ---*/
136137

137-
if (config[val_iZone]->GetCFL_Adapt() == YES) {
138+
if ((config[val_iZone]->GetCFL_Adapt() == YES) && (!disc_adj)) {
138139
SU2_OMP_PARALLEL
139140
solver[val_iZone][val_iInst][MESH_0][FLOW_SOL]->AdaptCFLNumber(geometry[val_iZone][val_iInst],
140141
solver[val_iZone][val_iInst], config[val_iZone]);

SU2_CFD/src/numerics/NEMO/NEMO_sources.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ CNumerics::ResidualType<> CSource_NEMO::ComputeChemistry(const CConfig *config)
102102

103103
ws = fluidmodel->ComputeNetProductionRates();
104104

105-
for (iSpecies = 0; iSpecies < nSpecies; iSpecies++)
105+
for (iSpecies = 0; iSpecies < nSpecies; iSpecies++)
106106
residual[iSpecies] = ws[iSpecies] *Volume;
107107

108108
//if (implicit) {
@@ -230,7 +230,7 @@ CNumerics::ResidualType<> CSource_NEMO::ComputeChemistry(const CConfig *config)
230230
// } // implicit
231231

232232
return ResidualType<>(residual, nullptr, nullptr);
233-
233+
234234
}
235235

236236
CNumerics::ResidualType<> CSource_NEMO::ComputeVibRelaxation(const CConfig *config) {
@@ -286,19 +286,19 @@ CNumerics::ResidualType<> CSource_NEMO::ComputeVibRelaxation(const CConfig *conf
286286
// }
287287

288288
if(config->GetVTTransferResidualLimiting()){
289-
if(residual[nSpecies+nDim+1]>res_max) residual[nSpecies+nDim+1]=res_max;
289+
if(residual[nSpecies+nDim+1]>res_max) residual[nSpecies+nDim+1]=res_max;
290290
if(residual[nSpecies+nDim+1]<res_min) residual[nSpecies+nDim+1]=res_min;
291-
}
291+
}
292292

293293
return ResidualType<>(residual, nullptr, nullptr);
294294
}
295295

296296
CNumerics::ResidualType<> CSource_NEMO::ComputeAxisymmetric(const CConfig *config) {
297297

298298
unsigned short iDim, iSpecies, iVar;
299-
su2double rho, rhov, vel2, H, yinv, T, Tve, qy_ve, Ru, RuSI;
299+
su2double rho, rhov, vel2, H, yinv, T, Tve, Ru, RuSI;
300300
su2double *Ds, **GV, ktr, kve;
301-
301+
302302
/*--- Rename for convenience ---*/
303303
Ds = Diffusion_Coeff_i;
304304
ktr = Thermal_Conductivity_i;
@@ -311,7 +311,7 @@ CNumerics::ResidualType<> CSource_NEMO::ComputeAxisymmetric(const CConfig *confi
311311
Ru = 1000.0*RuSI;
312312

313313
auto& Ms = fluidmodel->GetSpeciesMolarMass();
314-
314+
315315
bool viscous = config->GetViscous();
316316
bool rans = (config->GetKind_Turb_Model() != NONE);
317317
hs = fluidmodel->ComputeSpeciesEnthalpy(T, Tve, eve_i);
@@ -352,23 +352,23 @@ CNumerics::ResidualType<> CSource_NEMO::ComputeAxisymmetric(const CConfig *confi
352352

353353
for (iSpecies=0; iSpecies<nSpecies; iSpecies++)
354354
Mass += V_i[iSpecies]*Ms[iSpecies];
355-
355+
356356
su2double heat_capacity_cp_i = V_i[RHOCVTR_INDEX]+Ru/Mass;
357357
su2double total_viscosity_i = Laminar_Viscosity_i + Eddy_Viscosity_i;
358-
su2double total_conductivity_i = ktr + kve + heat_capacity_cp_i*Eddy_Viscosity_i/Prandtl_Turb;
358+
su2double total_conductivity_i = ktr + kve + heat_capacity_cp_i*Eddy_Viscosity_i/Prandtl_Turb;
359359
su2double u = V_i[VEL_INDEX];
360360
su2double v = V_i[VEL_INDEX+1];
361361
su2double qy_ve = kve*GV[TVE_INDEX][1];
362362

363363
/*--- Enthalpy and vib-el energy transport due to y-direction diffusion---*/
364-
for (iSpecies = 0; iSpecies < nHeavy; iSpecies++) {
364+
for (iSpecies = 0; iSpecies < nHeavy; iSpecies++) {
365365
sumJhs_y += (rho*Ds[iSpecies]*GV[RHOS_INDEX+iSpecies][1] - V_i[RHOS_INDEX+iSpecies]*Vector[1]) * hs[iSpecies];
366366
sumJeve_y += (rho*Ds[iSpecies]*GV[RHOS_INDEX+iSpecies][1] - V_i[RHOS_INDEX+iSpecies]*Vector[1]) * eve_i[iSpecies];
367367
}
368368

369369
for (iSpecies = 0; iSpecies < nSpecies; iSpecies++)
370370
residual[iSpecies] -= 0.0;
371-
residual[nSpecies] -= Volume*(yinv*total_viscosity_i*(PrimVar_Grad_i[nSpecies+2][1]+PrimVar_Grad_i[nSpecies+3][0])
371+
residual[nSpecies] -= Volume*(yinv*total_viscosity_i*(PrimVar_Grad_i[nSpecies+2][1]+PrimVar_Grad_i[nSpecies+3][0])
372372
-TWO3*AuxVar_Grad_i[0][0]);
373373
residual[nSpecies+1] -= Volume*(yinv*total_viscosity_i*2*(PrimVar_Grad_i[nSpecies+3][1]-v*yinv)
374374
-TWO3*AuxVar_Grad_i[0][1]);

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3854,12 +3854,12 @@ void CEulerSolver::GetPower_Properties(CGeometry *geometry, CConfig *config, uns
38543854
MassFlow -= Vector[iDim]*Velocity[iDim]*Density;
38553855
}
38563856

3857+
Area = GeometryToolbox::Norm(nDim, Vector);
38573858
Vn = 0.0; ReverseFlow = false;
38583859
for (iDim = 0; iDim < nDim; iDim++) { Vn -= Velocity[iDim]*Vector[iDim]/Area; }
38593860
if (Vn < 0.0) { ReverseFlow = true; }
38603861

38613862
Vel_Infty = sqrt (Vel_Infty2);
3862-
Area = GeometryToolbox::Norm(nDim, Vector);
38633863
Mach = sqrt(Velocity2)/SoundSpeed;
38643864
TotalPressure = Pressure * pow( 1.0 + Mach * Mach * 0.5 * (Gamma - 1.0), Gamma / (Gamma - 1.0));
38653865
TotalTemperature = Temperature * (1.0 + Mach * Mach * 0.5 * (Gamma - 1.0));

0 commit comments

Comments
 (0)