17#include "libmesh/equation_systems.h"
41 _fe_problem(*getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")),
42 _nl_abs_div_tol(getSharedExecutionerParam<Real>(
"nl_abs_div_tol")),
43 _nl_rel_div_tol(getSharedExecutionerParam<Real>(
"nl_div_tol")),
44 _div_threshold(
std::numeric_limits<Real>::max()),
45 _nl_forced_its(getSharedExecutionerParam<unsigned
int>(
"nl_forced_its")),
46 _nl_max_pingpong(getSharedExecutionerParam<unsigned
int>(
"n_max_nonlinear_pingpong")),
47 _nl_current_pingpong(0)
51 es.
parameters.
set<
unsigned int>(
"nonlinear solver maximum iterations") =
52 getSharedExecutionerParam<unsigned int>(
"nl_max_its");
53 es.parameters.set<
unsigned int>(
"nonlinear solver maximum function evaluations") =
54 getSharedExecutionerParam<unsigned int>(
"nl_max_funcs");
55 es.parameters.set<Real>(
"nonlinear solver absolute residual tolerance") =
56 getSharedExecutionerParam<Real>(
"nl_abs_tol");
57 es.parameters.set<Real>(
"nonlinear solver relative residual tolerance") =
58 getSharedExecutionerParam<Real>(
"nl_rel_tol");
59 es.parameters.set<Real>(
"nonlinear solver divergence tolerance") =
60 getSharedExecutionerParam<Real>(
"nl_div_tol");
61 es.parameters.set<Real>(
"nonlinear solver absolute step tolerance") =
62 getSharedExecutionerParam<Real>(
"nl_abs_step_tol");
63 es.parameters.set<Real>(
"nonlinear solver relative step tolerance") =
64 getSharedExecutionerParam<Real>(
"nl_rel_step_tol");
73 mooseError(
"DefaultNonlinearConvergence can only be used with nonlinear solves.");
88 std::ostringstream & oss)
92 oss <<
"Converged due to absolute residual " << fnorm <<
" < absolute tolerance (" << abs_tol
96 else if (n_iter && fnorm <= ref_norm * rel_tol)
98 oss <<
"Converged due to relative/normalized residual norm " << fnorm / ref_norm
99 <<
" < relative tolerance (" << rel_tol <<
")\n";
130 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetNumberFunctionEvals(snes, &nfuncs));
133 PetscReal rel_step_tol;
134 PetscInt max_its, max_funcs;
137 SNESGetTolerances(snes, &
_abs_tol, &
_rel_tol, &rel_step_tol, &max_its, &max_funcs));
139#if !PETSC_VERSION_LESS_THAN(3, 8, 4)
140 PetscBool force_iteration = PETSC_FALSE;
141 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetForceIteration(snes, &force_iteration));
157#if PETSC_VERSION_LESS_THAN(3, 25, 0)
158 PetscBool domainerror;
159 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetFunctionDomainError(snes, &domainerror));
163 SNESConvergedReason reason;
165 if (reason == SNES_DIVERGED_FUNCTION_DOMAIN)
194 std::ostringstream oss;
196 oss <<
"Number of forced iterations not yet reached: " << n_iter <<
" < " <<
_nl_forced_its
198 else if (fnorm != fnorm)
200 oss <<
"Failed to converge, residual norm is NaN\n";
205 else if (nfuncs >= max_funcs)
207 oss <<
"Exceeded maximum number of residual evaluations: " << nfuncs <<
" > " << max_funcs
214 oss <<
"Nonlinear solve was blowing up!\n";
217 else if (snorm < rel_step_tol * xnorm)
219 oss <<
"Converged due to small update length: " << snorm <<
" < " << rel_step_tol <<
" * "
225 oss <<
"Diverged due to relative residual " << ref_residual <<
" > divergence tolerance "
231 oss <<
"Diverged due to residual " << fnorm <<
" > absolute divergence tolerance "
237 oss <<
"Diverged due to maximum nonlinear residual pingpong achieved" <<
'\n';
248 if (msg.length() > 0)
249#
if !PETSC_VERSION_LESS_THAN(3, 17, 0)
registerMooseObject("MooseApp", DefaultNonlinearConvergence)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void ErrorVector unsigned int
PerfID _perfid_check_convergence
Performance ID for checkConvergence.
void verboseOutput(std::ostringstream &oss)
Outputs the stream to the console if verbose output is enabled.
MooseConvergenceStatus
Status returned by calls to checkConvergence.
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
Base class for default convergence criteria.
static InputParameters validParams()
Default nonlinear convergence criteria for FEProblem.
const Real _nl_rel_div_tol
Nonlinear relative divergence tolerance.
unsigned int _nl_current_pingpong
Current number of nonlinear ping-pong iterations for the current solve.
const Real _nl_abs_div_tol
Nonlinear absolute divergence tolerance.
static InputParameters validParams()
FEProblemBase & _fe_problem
unsigned int _nl_forced_its
Number of iterations to force.
PetscReal _rel_tol
Nonlinear relative tolerance.
virtual NonlinearSystemBase & nonlinearSystem()
Nonlinear system whose convergence state should be checked.
virtual bool checkResidualConvergence(const unsigned int n_iter, const Real fnorm, const Real ref_norm, const Real rel_tol, const Real abs_tol, std::ostringstream &oss)
Check the absolute and relative convergence of the nonlinear solution.
DefaultNonlinearConvergence(const InputParameters ¶meters)
virtual void nonlinearConvergenceSetup()
Performs setup necessary for each call to checkConvergence.
virtual void checkIterationType(IterationType it_type) const override
Perform checks related to the iteration type.
const Real _div_threshold
Divergence threshold value.
const unsigned int _nl_max_pingpong
Maximum number of nonlinear ping-pong iterations for a solve.
PetscReal _abs_tol
Nonlinear absolute tolerance.
virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter) override
Returns convergence status.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual libMesh::EquationSystems & es() override
NonlinearSystemBase & currentNonlinearSystem()
static InputParameters feProblemDefaultConvergenceParams()
unsigned int multiAppLevel() const
The MultiApp Level.
const std::string & name() const
Get the name of the class.
Class for containing MooseEnum item information.
MooseApp & _app
The MOOSE application this is associated with.
Nonlinear system to be solved.
Real referenceResidual() const
The reference residual used in relative convergence check.
void setInitialResidual(Real r)
Record the initial residual (for later relative convergence check)
unsigned int _current_nl_its
const Parallel::Communicator & comm() const
T & set(const std::string &)
void indentMessage(const std::string &prefix, std::string &message, const char *color, bool indent_first_line, const std::string &post_prefix)