21 const std::set<std::string> &
32 params.
addParam<
unsigned int>(
"nl_max_its", 50,
"Max Nonlinear Iterations");
33 params.
addParam<
unsigned int>(
"nl_forced_its", 0,
"The Number of Forced Nonlinear Iterations");
34 params.
addParam<
unsigned int>(
"nl_max_funcs", 10000,
"Max Nonlinear solver function evaluations");
35 params.
addParam<
Real>(
"nl_abs_tol", 1.0e-50,
"Nonlinear Absolute Tolerance");
36 params.
addParam<
Real>(
"nl_rel_tol", 1.0e-8,
"Nonlinear Relative Tolerance");
40 "Nonlinear Relative Divergence Tolerance. A negative value disables this check.");
44 "Nonlinear Absolute Divergence Tolerance. A negative value disables this check.");
45 params.
addParam<
Real>(
"nl_abs_step_tol", 0.,
"Nonlinear Absolute step Tolerance");
46 params.
addParam<
Real>(
"nl_rel_step_tol", 0.,
"Nonlinear Relative step Tolerance");
47 params.
addParam<
unsigned int>(
"n_max_nonlinear_pingpong",
49 "The maximum number of times the nonlinear residual can ping pong " 50 "before requesting halting the current evaluation and requesting " 51 "timestep cut for transient simulations");
54 "nl_max_its nl_forced_its nl_max_funcs nl_abs_tol nl_rel_tol " 55 "nl_rel_step_tol nl_abs_step_tol nl_div_tol nl_abs_div_tol n_max_nonlinear_pingpong",
67 params.
addParam<std::vector<std::vector<std::string>>>(
70 "Top-level splitting defining a hierarchical decomposition into " 71 "subsystems to help the solver. Outer-vector of this vector-of-vector parameter correspond " 72 "to each nonlinear system.");
76 std::set<std::string> alias_line_searches = {
"default",
"none",
"basic"};
77 line_searches.insert(alias_line_searches.begin(), alias_line_searches.end());
79 line_searches.insert(petsc_line_searches.begin(), petsc_line_searches.end());
81 MooseEnum line_search(line_search_string,
"default");
82 std::string addtl_doc_str(
" (Note: none = basic)");
84 "line_search", line_search,
"Specifies the line search type" + addtl_doc_str);
85 MooseEnum line_search_package(
"petsc moose",
"petsc");
88 "The solver package to use to conduct the line-search");
90 params.
addParam<
unsigned>(
"contact_line_search_allowed_lambda_cuts",
92 "The number of times lambda is allowed to be cut in half in the " 93 "contact line search. We recommend this number be roughly bounded by 0 " 94 "<= allowed_lambda_cuts <= 3");
96 "The linear relative tolerance to be used while the contact state is " 97 "changing between non-linear iterations. We recommend that this tolerance " 98 "be looser than the standard linear tolerance");
101 params.addParam<
Real>(
"l_tol", 1.0e-5,
"Linear Relative Tolerance");
102 params.addParam<
Real>(
"l_abs_tol", 1.0e-50,
"Linear Absolute Tolerance");
103 params.addParam<
unsigned int>(
"l_max_its", 10000,
"Max Linear Iterations");
104 params.addParam<std::vector<ConvergenceName>>(
105 "nonlinear_convergence",
106 "Name of the Convergence object(s) to use to assess convergence of the " 107 "nonlinear system(s) solve. If not provided, the default Convergence " 108 "associated with the Problem will be constructed internally.");
109 params.addParam<std::vector<ConvergenceName>>(
110 "linear_convergence",
111 "Name of the Convergence object(s) to use to assess convergence of the " 112 "linear system(s) solve. If not provided, the linear solver tolerance parameters are used");
113 params.addParam<
bool>(
116 "Specifies whether or not to reuse the base vector for matrix-free calculation");
117 params.addParam<
bool>(
118 "skip_exception_check",
false,
"Specifies whether or not to skip exception check");
119 params.addParam<
bool>(
"compute_initial_residual_before_preset_bcs",
121 "Use the residual norm computed *before* solution modifying objects like " 122 "preset BCs are imposed in relative convergence check.");
123 params.deprecateParam(
124 "compute_initial_residual_before_preset_bcs",
"use_pre_SMO_residual",
"12/31/2024");
125 params.addParam<
bool>(
126 "use_pre_SMO_residual",
128 "Compute the pre-SMO residual norm and use it in the relative convergence check. The " 129 "pre-SMO residual is computed at the begining of the time step before solution-modifying " 130 "objects are executed. Solution-modifying objects include preset BCs, constraints, " 132 params.addParam<
bool>(
"automatic_scaling",
"Whether to use automatic scaling for the variables.");
133 params.addParam<std::vector<bool>>(
134 "compute_scaling_once",
136 "Whether the scaling factors should only be computed once at the beginning of the simulation " 137 "through an extra Jacobian evaluation. If this is set to false, then the scaling factors " 138 "will be computed during an extra Jacobian evaluation at the beginning of every time step. " 139 "Vector entries correspond to each nonlinear system.");
140 params.addParam<std::vector<bool>>(
141 "off_diagonals_in_auto_scaling",
143 "Whether to consider off-diagonals when determining automatic scaling factors. Vector " 144 "entries correspond to each nonlinear system.");
145 params.addRangeCheckedParam<std::vector<Real>>(
146 "resid_vs_jac_scaling_param",
148 "0<=resid_vs_jac_scaling_param<=1",
149 "A parameter that indicates the weighting of the residual vs the Jacobian in determining " 150 "variable scaling parameters. A value of 1 indicates pure residual-based scaling. A value of " 151 "0 indicates pure Jacobian-based scaling. Vector entries correspond to each nonlinear " 153 params.addParam<std::vector<std::vector<std::vector<std::string>>>>(
154 "scaling_group_variables",
155 "Name of variables that are grouped together for determining scale factors. (Multiple " 156 "groups can be provided, separated by semicolon). Vector entries correspond to each " 157 "nonlinear system.");
158 params.addParam<std::vector<std::vector<std::string>>>(
159 "ignore_variables_for_autoscaling",
160 "List of variables that do not participate in autoscaling. Vector entries correspond to each " 161 "nonlinear system.");
162 params.addRangeCheckedParam<
unsigned int>(
166 "The number of grids to use for a grid sequencing algorithm. This includes the final grid, " 167 "so num_grids = 1 indicates just one solve in a time-step");
168 params.addParam<std::vector<bool>>(
"residual_and_jacobian_together",
170 "Whether to compute the residual and Jacobian together. " 171 "Vector entries correspond to each nonlinear system.");
173 params.addParam<
bool>(
"reuse_preconditioner",
175 "If true reuse the previously calculated " 176 "preconditioner for the linearized " 177 "system across multiple solves " 178 "spanning nonlinear iterations and time steps. " 179 "The preconditioner resets as controlled by " 180 "reuse_preconditioner_max_linear_its");
181 params.addParam<
unsigned int>(
"reuse_preconditioner_max_linear_its",
183 "Reuse the previously calculated " 184 "preconditioner for the linear system " 185 "until the number of linear iterations " 186 "exceeds this number");
191 params.addParam<
bool>(
192 "multi_system_fixed_point",
194 "Whether to perform fixed point (Picard) iterations between the nonlinear systems.");
195 params.addParam<ConvergenceName>(
196 "multi_system_fixed_point_convergence",
197 "Convergence object to determine the convergence of the multi-system fixed point iteration. " 198 "If unspecified, defaults to checking that every system is converged (based on their own " 199 "convergence criterion)");
201 params.addParamNamesToGroup(
"l_tol l_abs_tol l_max_its reuse_preconditioner " 202 "reuse_preconditioner_max_linear_its",
204 params.addParamNamesToGroup(
205 "solve_type snesmf_reuse_base use_pre_SMO_residual " 206 "num_grids residual_and_jacobian_together splitting nonlinear_convergence linear_convergence",
208 params.addParamNamesToGroup(
209 "automatic_scaling compute_scaling_once off_diagonals_in_auto_scaling " 210 "scaling_group_variables resid_vs_jac_scaling_param ignore_variables_for_autoscaling",
211 "Solver variable scaling");
212 params.addParamNamesToGroup(
"line_search line_search_package contact_line_search_ltol " 213 "contact_line_search_allowed_lambda_cuts",
214 "Solver line search");
215 params.addParamNamesToGroup(
"multi_system_fixed_point multi_system_fixed_point_convergence",
216 "Multiple solver system");
217 params.addParamNamesToGroup(
"skip_exception_check",
"Advanced");
224 _num_grid_steps(
cast_int<unsigned
int>(getParam<unsigned
int>(
"num_grids") - 1)),
225 _using_multi_sys_fp_iterations(getParam<bool>(
"multi_system_fixed_point")),
226 _multi_sys_fp_convergence(nullptr)
232 auto set_solver_params = [
this, &ex](
const SolverSystem & sys)
234 const auto prefix = sys.prefix();
240 solver_params.
_prefix = prefix;
241 solver_params._solver_sys_num = sys.number();
245 for (
const auto *
const sys :
_systems)
246 set_solver_params(*sys);
252 es.parameters.set<
Real>(
"linear solver absolute tolerance") = getParam<Real>(
"l_abs_tol");
253 es.parameters.set<
unsigned int>(
"linear solver maximum iterations") =
254 getParam<unsigned int>(
"l_max_its");
255 es.parameters.set<
bool>(
"reuse preconditioner") = getParam<bool>(
"reuse_preconditioner");
256 es.parameters.set<
unsigned int>(
"reuse preconditioner maximum linear iterations") =
257 getParam<unsigned int>(
"reuse_preconditioner_max_linear_its");
267 mooseError(
"The selected problem does not allow 'nonlinear_convergence' to be set.");
269 getParam<std::vector<ConvergenceName>>(
"nonlinear_convergence"));
277 "linear_convergence",
278 "Setting 'linear_convergence' is currently only possible for solving linear systems");
280 getParam<std::vector<ConvergenceName>>(
"linear_convergence"));
288 [
this](
const auto & solver_sys)
292 "Automatic scaling isn't implemented for the case where you do not have a " 293 "preconditioning matrix. No scaling will be applied");
301 ? getParam<bool>(
"automatic_scaling")
305 [
this](
const auto & solver_sys) {
311 paramError(
"multi_system_fixed_point_convergence",
312 "Cannot set a convergence object for multi-system fixed point iterations if " 313 "'multi_system_fixed_point' is set to false");
315 paramError(
"multi_system_fixed_point_convergence",
316 "Must set a convergence object for multi-system fixed point iterations if using " 317 "multi-system fixed point iterations");
332 const auto & all_splittings = getParam<std::vector<std::vector<std::string>>>(
"splitting");
333 if (all_splittings.size())
337 nl.setDecomposition({});
339 const auto res_and_jac =
340 getParamFromNonlinearSystemVectorParam<bool>(
"residual_and_jacobian_together", i_nl_sys);
342 nl.residualAndJacobianTogether();
345 nl.computeScalingOnce(
346 getParamFromNonlinearSystemVectorParam<bool>(
"compute_scaling_once", i_nl_sys));
348 getParamFromNonlinearSystemVectorParam<Real>(
"resid_vs_jac_scaling_param", i_nl_sys));
349 nl.offDiagonalsInAutoScaling(
350 getParamFromNonlinearSystemVectorParam<bool>(
"off_diagonals_in_auto_scaling", i_nl_sys));
352 nl.scalingGroupVariables(
354 "scaling_group_variables", i_nl_sys));
361 const auto & ignore_variables_for_autoscaling =
362 getParamFromNonlinearSystemVectorParam<std::vector<std::string>>(
363 "ignore_variables_for_autoscaling", i_nl_sys);
364 const auto & scaling_group_variables =
365 getParamFromNonlinearSystemVectorParam<std::vector<std::vector<std::string>>>(
366 "scaling_group_variables", i_nl_sys);
367 for (
const auto & group : scaling_group_variables)
368 for (
const auto & var_name : group)
369 if (std::find(ignore_variables_for_autoscaling.begin(),
370 ignore_variables_for_autoscaling.end(),
371 var_name) != ignore_variables_for_autoscaling.end())
372 paramError(
"ignore_variables_for_autoscaling",
373 "Variables cannot be in a scaling grouping and also be ignored");
375 nl.ignoreVariablesForAutoscaling(
377 "ignore_variables_for_autoscaling", i_nl_sys));
385 template <
typename T>
388 unsigned int index)
const 390 const auto & param_vec = getParam<std::vector<T>>(param_name);
393 "Vector parameter is requested at index (" + std::to_string(index) +
394 ") which is larger than number of nonlinear systems (" +
396 if (param_vec.size() == 0)
399 "This parameter was passed to a routine which cannot handle empty vector parameters");
402 "Vector parameter size (" + std::to_string(param_vec.size()) +
403 ") is different than the number of nonlinear systems (" +
407 if (param_vec.size() == 1)
410 return param_vec[index];
425 for (
const auto & conv_name : conv_names)
434 const auto conv_names = getParam<std::vector<ConvergenceName>>(
"linear_convergence");
435 for (
const auto & conv_name : conv_names)
443 if (
isParamValid(
"multi_system_fixed_point_convergence"))
456 bool converged =
false;
457 unsigned int num_fp_multisys_iters = 0;
463 num_fp_multisys_iters = 0;
477 const auto linear_sys_number =
489 const auto solve_name =
490 _systems.size() == 1 ?
" Solve" :
"System " + sys->name() +
": Solve";
494 _console << COLOR_GREEN << solve_name <<
" Converged!" << COLOR_DEFAULT << std::endl;
497 _console << COLOR_RED << solve_name <<
" Did NOT Converge!" << COLOR_DEFAULT
503 _console << COLOR_GREEN << solve_name <<
" Skipped!" << COLOR_DEFAULT << std::endl;
517 num_fp_multisys_iters++;
static InputParameters validParams()
const std::vector< ConvergenceName > & getNonlinearConvergenceNames() const
Gets the nonlinear system convergence object name(s).
FEProblemBase & _problem
Reference to FEProblem.
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
void computeGradients()
Compute the Green-Gauss gradients.
virtual std::size_t numNonlinearSystems() const override
std::set< std::string > getPetscValidLineSearches()
Returns the valid petsc line search options as a set of strings.
virtual MooseConvergenceStatus checkConvergence(unsigned int iter)=0
Returns convergence status.
static std::set< std::string > const _moose_line_searches
Moose provided line searches.
virtual bool onlyAllowDefaultNonlinearConvergence() const
Returns true if an error will result if the user supplies 'nonlinear_convergence'.
virtual bool solve() override
Picard solve the FEProblem.
const auto MULTISYSTEM_FIXED_POINT
FEProblemSolve(Executioner &ex)
virtual void initialSetup()
Method that should be executed once, before any solve calls.
const unsigned int _num_grid_steps
The number of steps to perform in a grid sequencing algorithm.
virtual void solve(const unsigned int nl_sys_num)
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Nonlinear system to be solved.
void skipExceptionCheck(bool skip_exception_check)
Set a flag that indicates if we want to skip exception and stop solve.
virtual void addLineSearch(const InputParameters &)
add a MOOSE line search
void uniformRefine()
uniformly refine the problem mesh(es).
const std::string _type
The type of this class.
void numGridSteps(unsigned int num_grid_steps)
Set the number of steps in a grid sequences.
Convergence * _multi_sys_fp_convergence
Convergence object to assess the convergence of the multi-system fixed point iteration.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
Jacobian-Free Newton Krylov.
virtual libMesh::EquationSystems & es() override
virtual bool converged(const unsigned int sys_num)
Eventually we want to convert this virtual over to taking a solver system number argument.
static InputParameters feProblemDefaultConvergenceParams()
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void setLinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the linear convergence object name(s) if there is one.
Executioners are objects that do the actual work of solving your problem.
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
void setNonlinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the nonlinear convergence object name(s) if there is one.
static InputParameters validParams()
std::string stringify(const T &t)
conversion to string
void setNeedToAddDefaultNonlinearConvergence()
Sets _need_to_add_default_nonlinear_convergence to true.
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
void setConvergedReasonFlags(FEProblemBase &fe_problem, const std::string &prefix)
Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspectiv...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
T getParamFromNonlinearSystemVectorParam(const std::string ¶m_name, unsigned int index) const
Helper routine to get the nonlinear system parameter at the right index.
T & set(const std::string &)
unsigned int _num_nl_systems
Number of nonlinear systems.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
const bool _using_multi_sys_fp_iterations
Whether we are using fixed point iterations for multi-system.
void convergenceSetup()
Performs setup related to Convergence objects.
virtual std::size_t numLinearSystems() const override
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
void paramWarning(const std::string ¶m, Args... args) const
Emits a warning prefixed with the file and line number of the given param (from the input file) along...
void automaticScaling(bool automatic_scaling) override
Automatic scaling setter.
void storePetscOptions(FEProblemBase &fe_problem, const std::string &prefix, const ParallelParamObject ¶m_object)
Stores the PETSc options supplied from the parameter object on the problem.
void setSNESMFReuseBase(bool reuse, bool set_by_user)
If or not to reuse the base vector for matrix-free calculation.
virtual void solveLinearSystem(const unsigned int linear_sys_num, const Moose::PetscSupport::PetscOptions *po=nullptr)
Build and solve a linear system.
void ErrorVector unsigned int
auto index_range(const T &sizable)
std::vector< SolverSystem * > _systems
Vector of pointers to the systems.
virtual void initialSetup() override
Method that should be executed once, before any solve calls.
void setPreSMOResidual(bool use)
Set whether to evaluate the pre-SMO residual and use it in the subsequent relative convergence checks...
Tnew cast_int(Told oldvar)
static const std::set< std::string > & mooseLineSearches()
A solve object for use when wanting to solve multiple systems.