Skip to content

Commit e5b84e5

Browse files
enabling ComputeUnderRelaxationFactor
1 parent cb0de0d commit e5b84e5

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

SU2_CFD/include/solvers/CIncEulerSolver.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,11 @@ class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, ENUM_REGIME
433433
* \param[in] config - The particular config.
434434
*/
435435
void ExtractAdjoint_SolutionExtra(su2activevector& adj_sol, const CConfig* config) final;
436+
437+
/*!
438+
* \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over
439+
* a nonlinear iteration for stability.
440+
* \param[in] config - Definition of the particular problem.
441+
*/
442+
void ComputeUnderRelaxationFactor(const CConfig *config) final;
436443
};

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,45 @@ void CIncEulerSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver**, C
19211921

19221922
void CIncEulerSolver::CompleteImplicitIteration(CGeometry *geometry, CSolver**, CConfig *config) {
19231923

1924-
CompleteImplicitIteration_impl<false>(geometry, config);
1924+
CompleteImplicitIteration_impl<true>(geometry, config);
1925+
}
1926+
1927+
void CIncEulerSolver::ComputeUnderRelaxationFactor(const CConfig* config) {
1928+
/* Apply the under-relaxation to energy equation. As the energy equation
1929+
for incompressible flows can be switch-off, the under-relaxation is not
1930+
applied when the energy equation is not solved. */
1931+
1932+
if (!config->GetEnergy_Equation()) return;
1933+
1934+
/* Loop over the solution update given by relaxing the linear
1935+
system for this nonlinear iteration. */
1936+
1937+
const su2double allowableRatio = config->GetMaxUpdateFractionFlow();
1938+
1939+
SU2_OMP_FOR_STAT(omp_chunk_size)
1940+
for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) {
1941+
su2double localUnderRelaxation = 1.0;
1942+
1943+
/* We impose a limit on the maximum percentage that the
1944+
temperature can change over a nonlinear iteration. */
1945+
1946+
const unsigned long index = iPoint * nVar + nVar - 1;
1947+
su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, nVar - 1)) + EPS);
1948+
if (ratio > allowableRatio) {
1949+
localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation);
1950+
}
1951+
1952+
/* Threshold the relaxation factor in the event that there is
1953+
a very small value. This helps avoid catastrophic crashes due
1954+
to non-realizable states by canceling the update. */
1955+
1956+
if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0;
1957+
1958+
/* Store the under-relaxation factor for this point. */
1959+
1960+
nodes->SetUnderRelaxation(iPoint, localUnderRelaxation);
1961+
}
1962+
END_SU2_OMP_FOR
19251963
}
19261964

19271965
void CIncEulerSolver::SetBeta_Parameter(CGeometry *geometry, CSolver **solver_container,

0 commit comments

Comments
 (0)