17#include "libmesh/system.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),
48 _nl_max_its(getSharedExecutionerParam<unsigned
int>(
"nl_max_its")),
49 _nl_abs_tol(getSharedExecutionerParam<Real>(
"nl_abs_tol")),
50 _nl_rel_tol(getSharedExecutionerParam<Real>(
"nl_rel_tol"))
73 mooseError(
"DefaultNonlinearConvergence can only be used with nonlinear solves.");
90 params.
set<
unsigned int>(
"nonlinear solver maximum iterations") =
_nl_max_its;
91 params.set<
unsigned int>(
"nonlinear solver maximum function evaluations") =
92 getSharedExecutionerParam<unsigned int>(
"nl_max_funcs");
93 params.set<Real>(
"nonlinear solver absolute residual tolerance") =
_nl_abs_tol;
94 params.set<Real>(
"nonlinear solver relative residual tolerance") =
_nl_rel_tol;
95 params.set<Real>(
"nonlinear solver divergence tolerance") =
96 getSharedExecutionerParam<Real>(
"nl_div_tol");
97 params.set<Real>(
"nonlinear solver absolute step tolerance") =
98 getSharedExecutionerParam<Real>(
"nl_abs_step_tol");
99 params.set<Real>(
"nonlinear solver relative step tolerance") =
100 getSharedExecutionerParam<Real>(
"nl_rel_step_tol");
115 std::ostringstream & oss)
119 oss <<
"Converged due to absolute residual " << fnorm <<
" < absolute tolerance (" << abs_tol
123 else if (n_iter && fnorm <= ref_norm * rel_tol)
125 oss <<
"Converged due to relative/normalized residual norm " << fnorm / ref_norm
126 <<
" < relative tolerance (" << rel_tol <<
")\n";
157 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetNumberFunctionEvals(snes, &nfuncs));
160 PetscReal abs_tol, rel_tol, rel_step_tol;
161 PetscInt max_its, max_funcs;
164 SNESGetTolerances(snes, &abs_tol, &rel_tol, &rel_step_tol, &max_its, &max_funcs));
166#if !PETSC_VERSION_LESS_THAN(3, 8, 4)
167 PetscBool force_iteration = PETSC_FALSE;
168 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetForceIteration(snes, &force_iteration));
184#if PETSC_VERSION_LESS_THAN(3, 25, 0)
185 PetscBool domainerror;
186 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetFunctionDomainError(snes, &domainerror));
190 SNESConvergedReason reason;
192 if (reason == SNES_DIVERGED_FUNCTION_DOMAIN)
221 std::ostringstream oss;
223 oss <<
"Number of forced iterations not yet reached: " << n_iter <<
" < " <<
_nl_forced_its
225 else if (fnorm != fnorm)
227 oss <<
"Failed to converge, residual norm is NaN\n";
232 else if (nfuncs >= max_funcs)
234 oss <<
"Exceeded maximum number of residual evaluations: " << nfuncs <<
" > " << max_funcs
241 oss <<
"Nonlinear solve was blowing up!\n";
244 else if (snorm < rel_step_tol * xnorm)
246 oss <<
"Converged due to small update length: " << snorm <<
" < " << rel_step_tol <<
" * "
252 oss <<
"Diverged due to relative residual " << ref_residual <<
" > divergence tolerance "
258 oss <<
"Diverged due to residual " << fnorm <<
" > absolute divergence tolerance "
264 oss <<
"Diverged due to maximum nonlinear residual pingpong achieved" <<
'\n';
275 if (msg.length() > 0)
276#
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.
virtual void preSolve()
Method that gets called in each iteration before the solve.
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.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
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.
virtual void preSolve() override
Method that gets called in each iteration before the solve.
static InputParameters validParams()
void setNonlinearSystemParameters()
Sets the nonlinear system parameters, such as tolerances.
FEProblemBase & _fe_problem
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
unsigned int _nl_max_its
Nonlinear maximum nonlinear iterations (modifiable by setMaximumIterations)
unsigned int _nl_forced_its
Number of iterations to force.
void setMaximumIterations(const unsigned int max_iter)
Sets the maximum nonlinear iterations.
Real _nl_rel_tol
Nonlinear relative tolerance (modifiable by setRelativeTolerance)
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.
void setRelativeTolerance(const Real rel_tol)
Sets the relative nonlinear tolerance.
void setAbsoluteTolerance(const Real abs_tol)
Sets the absolute nonlinear tolerance.
const unsigned int _nl_max_pingpong
Maximum number of nonlinear ping-pong iterations for a solve.
virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter) override
Returns convergence status.
Real _nl_abs_tol
Nonlinear absolute tolerance (modifiable by setAbsoluteTolerance)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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)
virtual libMesh::System & system() override
Get the reference to the libMesh system.
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)