17 #include "libmesh/equation_systems.h" 22 #include <petscsnes.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.");
82 std::ostringstream & oss)
84 if (fnorm <= ref_norm * rel_tol)
86 oss <<
"Converged due to relative/normalized residual norm " << fnorm / ref_norm
87 <<
" < relative tolerance (" << rel_tol <<
")\n";
121 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetNumberFunctionEvals(snes, &nfuncs));
124 PetscReal abs_tol, rel_tol, rel_step_tol;
125 PetscInt max_its, max_funcs;
128 SNESGetTolerances(snes, &abs_tol, &rel_tol, &rel_step_tol, &max_its, &max_funcs));
130 #if !PETSC_VERSION_LESS_THAN(3, 8, 4) 131 PetscBool force_iteration = PETSC_FALSE;
132 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetForceIteration(snes, &force_iteration));
148 PetscBool domainerror;
149 LibmeshPetscCallA(
_fe_problem.
comm().
get(), SNESGetFunctionDomainError(snes, &domainerror));
174 std::ostringstream oss;
177 oss <<
"Failed to converge, residual norm is NaN\n";
182 oss <<
"Converged due to residual norm " << fnorm <<
" < " << abs_tol <<
'\n';
185 else if (nfuncs >= max_funcs)
187 oss <<
"Exceeded maximum number of residual evaluations: " << nfuncs <<
" > " << max_funcs
194 oss <<
"Nonlinear solve was blowing up!\n";
202 else if (snorm < rel_step_tol * xnorm)
204 oss <<
"Converged due to small update length: " << snorm <<
" < " << rel_step_tol <<
" * " 210 oss <<
"Diverged due to relative residual " << ref_residual <<
" > divergence tolerance " 216 oss <<
"Diverged due to residual " << fnorm <<
" > absolute divergence tolerance " 222 oss <<
"Diverged due to maximum nonlinear residual pingpong achieved" <<
'\n';
234 if (msg.length() > 0)
235 #
if !PETSC_VERSION_LESS_THAN(3, 17, 0)
registerMooseObject("MooseApp", DefaultNonlinearConvergence)
virtual void nonlinearConvergenceSetup()
Performs setup necessary for each call to checkConvergence.
const Real _nl_rel_div_tol
Nonlinear relative divergence tolerance.
Base class for default convergence criteria.
DefaultNonlinearConvergence(const InputParameters ¶meters)
unsigned int multiAppLevel() const
The MultiApp Level.
void verboseOutput(std::ostringstream &oss)
Outputs the stream to the console if verbose output is enabled.
const Parallel::Communicator & comm() const
virtual bool checkRelativeConvergence(const unsigned int it, const Real fnorm, const Real ref_norm, const Real rel_tol, const Real abs_tol, std::ostringstream &oss)
Check the relative convergence of the nonlinear solution.
virtual MooseConvergenceStatus checkConvergence(unsigned int iter) override
Returns convergence status.
const Real _nl_abs_div_tol
Nonlinear absolute divergence tolerance.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
auto max(const L &left, const R &right)
const unsigned int _nl_max_pingpong
Maximum number of nonlinear ping-pong iterations for a solve.
Nonlinear system to be solved.
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN, bool dont_indent_first_line=true, const std::string &post_prefix=": ")
Indents the supplied message given the prefix and color.
unsigned int _current_nl_its
Real referenceResidual() const
The reference residual used in relative convergence check.
NonlinearSystemBase & currentNonlinearSystem()
virtual libMesh::EquationSystems & es() override
static InputParameters feProblemDefaultConvergenceParams()
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
MooseApp & _app
The MOOSE application this is associated with.
MooseConvergenceStatus
Status returned by calls to checkConvergence.
PerfID _perfid_check_convergence
Performance ID for checkConvergence.
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _nl_current_pingpong
Current number of nonlinear ping-pong iterations for the current solve.
Class for containing MooseEnum item information.
T & set(const std::string &)
void setInitialResidual(Real r)
Record the initial residual (for later relative convergence check)
unsigned int _nl_forced_its
Number of iterations to force.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const Real _div_threshold
Divergence threshold value.
FEProblemBase & _fe_problem
Default nonlinear convergence criteria for FEProblem.
void ErrorVector unsigned int
static InputParameters validParams()
virtual void checkIterationType(IterationType it_type) const override
Perform checks related to the iteration type.