20 const std::set<std::string> &
31 params.
addParam<
unsigned int>(
"nl_max_its", 50,
"Max Nonlinear Iterations");
32 params.
addParam<
unsigned int>(
"nl_forced_its", 0,
"The Number of Forced Nonlinear Iterations");
33 params.
addParam<
unsigned int>(
"nl_max_funcs", 10000,
"Max Nonlinear solver function evaluations");
34 params.
addParam<
Real>(
"nl_abs_tol", 1.0e-50,
"Nonlinear Absolute Tolerance");
35 params.
addParam<
Real>(
"nl_rel_tol", 1.0e-8,
"Nonlinear Relative Tolerance");
39 "Nonlinear Relative Divergence Tolerance. A negative value disables this check.");
43 "Nonlinear Absolute Divergence Tolerance. A negative value disables this check.");
44 params.
addParam<
Real>(
"nl_abs_step_tol", 0.,
"Nonlinear Absolute step Tolerance");
45 params.
addParam<
Real>(
"nl_rel_step_tol", 0.,
"Nonlinear Relative step Tolerance");
46 params.
addParam<
unsigned int>(
"n_max_nonlinear_pingpong",
48 "The maximum number of times the nonlinear residual can ping pong " 49 "before requesting halting the current evaluation and requesting " 50 "timestep cut for transient simulations");
53 "nl_max_its nl_forced_its nl_max_funcs nl_abs_tol nl_rel_tol " 54 "nl_rel_step_tol nl_abs_step_tol nl_div_tol nl_abs_div_tol n_max_nonlinear_pingpong",
66 params.
addParam<std::vector<std::vector<std::string>>>(
69 "Top-level splitting defining a hierarchical decomposition into " 70 "subsystems to help the solver. Outer-vector of this vector-of-vector parameter correspond " 71 "to each nonlinear system.");
75 std::set<std::string> alias_line_searches = {
"default",
"none",
"basic"};
76 line_searches.insert(alias_line_searches.begin(), alias_line_searches.end());
78 line_searches.insert(petsc_line_searches.begin(), petsc_line_searches.end());
80 MooseEnum line_search(line_search_string,
"default");
81 std::string addtl_doc_str(
" (Note: none = basic)");
83 "line_search", line_search,
"Specifies the line search type" + addtl_doc_str);
84 MooseEnum line_search_package(
"petsc moose",
"petsc");
87 "The solver package to use to conduct the line-search");
89 params.
addParam<
unsigned>(
"contact_line_search_allowed_lambda_cuts",
91 "The number of times lambda is allowed to be cut in half in the " 92 "contact line search. We recommend this number be roughly bounded by 0 " 93 "<= allowed_lambda_cuts <= 3");
95 "The linear relative tolerance to be used while the contact state is " 96 "changing between non-linear iterations. We recommend that this tolerance " 97 "be looser than the standard linear tolerance");
100 params.addParam<
Real>(
"l_tol", 1.0e-5,
"Linear Relative Tolerance");
101 params.addParam<
Real>(
"l_abs_tol", 1.0e-50,
"Linear Absolute Tolerance");
102 params.addParam<
unsigned int>(
"l_max_its", 10000,
"Max Linear Iterations");
103 params.addParam<std::vector<ConvergenceName>>(
104 "nonlinear_convergence",
105 "Name of the Convergence object(s) to use to assess convergence of the " 106 "nonlinear system(s) solve. If not provided, the default Convergence " 107 "associated with the Problem will be constructed internally.");
108 params.addParam<std::vector<ConvergenceName>>(
109 "linear_convergence",
110 "Name of the Convergence object(s) to use to assess convergence of the " 111 "linear system(s) solve. If not provided, the linear solver tolerance parameters are used");
112 params.addParam<
bool>(
115 "Specifies whether or not to reuse the base vector for matrix-free calculation");
116 params.addParam<
bool>(
117 "skip_exception_check",
false,
"Specifies whether or not to skip exception check");
118 params.addParam<
bool>(
"compute_initial_residual_before_preset_bcs",
120 "Use the residual norm computed *before* solution modifying objects like " 121 "preset BCs are imposed in relative convergence check.");
122 params.deprecateParam(
123 "compute_initial_residual_before_preset_bcs",
"use_pre_SMO_residual",
"12/31/2024");
124 params.addParam<
bool>(
125 "use_pre_SMO_residual",
127 "Compute the pre-SMO residual norm and use it in the relative convergence check. The " 128 "pre-SMO residual is computed at the begining of the time step before solution-modifying " 129 "objects are executed. Solution-modifying objects include preset BCs, constraints, " 131 params.addParam<
bool>(
"automatic_scaling",
"Whether to use automatic scaling for the variables.");
132 params.addParam<std::vector<bool>>(
133 "compute_scaling_once",
135 "Whether the scaling factors should only be computed once at the beginning of the simulation " 136 "through an extra Jacobian evaluation. If this is set to false, then the scaling factors " 137 "will be computed during an extra Jacobian evaluation at the beginning of every time step. " 138 "Vector entries correspond to each nonlinear system.");
139 params.addParam<std::vector<bool>>(
140 "off_diagonals_in_auto_scaling",
142 "Whether to consider off-diagonals when determining automatic scaling factors. Vector " 143 "entries correspond to each nonlinear system.");
144 params.addRangeCheckedParam<std::vector<Real>>(
145 "resid_vs_jac_scaling_param",
147 "0<=resid_vs_jac_scaling_param<=1",
148 "A parameter that indicates the weighting of the residual vs the Jacobian in determining " 149 "variable scaling parameters. A value of 1 indicates pure residual-based scaling. A value of " 150 "0 indicates pure Jacobian-based scaling. Vector entries correspond to each nonlinear " 152 params.addParam<std::vector<std::vector<std::vector<std::string>>>>(
153 "scaling_group_variables",
154 "Name of variables that are grouped together for determining scale factors. (Multiple " 155 "groups can be provided, separated by semicolon). Vector entries correspond to each " 156 "nonlinear system.");
157 params.addParam<std::vector<std::vector<std::string>>>(
158 "ignore_variables_for_autoscaling",
159 "List of variables that do not participate in autoscaling. Vector entries correspond to each " 160 "nonlinear system.");
161 params.addRangeCheckedParam<
unsigned int>(
165 "The number of grids to use for a grid sequencing algorithm. This includes the final grid, " 166 "so num_grids = 1 indicates just one solve in a time-step");
167 params.addParam<std::vector<bool>>(
"residual_and_jacobian_together",
169 "Whether to compute the residual and Jacobian together. " 170 "Vector entries correspond to each nonlinear system.");
172 params.addParam<
bool>(
"reuse_preconditioner",
174 "If true reuse the previously calculated " 175 "preconditioner for the linearized " 176 "system across multiple solves " 177 "spanning nonlinear iterations and time steps. " 178 "The preconditioner resets as controlled by " 179 "reuse_preconditioner_max_linear_its");
180 params.addParam<
unsigned int>(
"reuse_preconditioner_max_linear_its",
182 "Reuse the previously calculated " 183 "preconditioner for the linear system " 184 "until the number of linear iterations " 185 "exceeds this number");
190 params.addParam<
bool>(
191 "multi_system_fixed_point",
193 "Whether to perform fixed point (Picard) iterations between the nonlinear systems.");
194 params.addParam<ConvergenceName>(
195 "multi_system_fixed_point_convergence",
196 "Convergence object to determine the convergence of the multi-system fixed point iteration. " 197 "If unspecified, defaults to checking that every system is converged (based on their own " 198 "convergence criterion)");
200 params.addParamNamesToGroup(
"l_tol l_abs_tol l_max_its reuse_preconditioner " 201 "reuse_preconditioner_max_linear_its",
203 params.addParamNamesToGroup(
204 "solve_type snesmf_reuse_base use_pre_SMO_residual " 205 "num_grids residual_and_jacobian_together splitting nonlinear_convergence linear_convergence",
207 params.addParamNamesToGroup(
208 "automatic_scaling compute_scaling_once off_diagonals_in_auto_scaling " 209 "scaling_group_variables resid_vs_jac_scaling_param ignore_variables_for_autoscaling",
210 "Solver variable scaling");
211 params.addParamNamesToGroup(
"line_search line_search_package contact_line_search_ltol " 212 "contact_line_search_allowed_lambda_cuts",
213 "Solver line search");
214 params.addParamNamesToGroup(
"multi_system_fixed_point multi_system_fixed_point_convergence",
215 "Multiple solver system");
216 params.addParamNamesToGroup(
"skip_exception_check",
"Advanced");
223 _num_grid_steps(
cast_int<unsigned
int>(getParam<unsigned
int>(
"num_grids") - 1)),
224 _using_multi_sys_fp_iterations(getParam<bool>(
"multi_system_fixed_point")),
225 _multi_sys_fp_convergence(nullptr)
231 auto set_solver_params = [
this, &ex](
const SolverSystem & sys)
233 const auto prefix = sys.prefix();
239 solver_params.
_prefix = prefix;
240 solver_params._solver_sys_num = sys.number();
244 for (
const auto *
const sys :
_systems)
245 set_solver_params(*sys);
251 es.parameters.set<
Real>(
"linear solver absolute tolerance") = getParam<Real>(
"l_abs_tol");
252 es.parameters.set<
unsigned int>(
"linear solver maximum iterations") =
253 getParam<unsigned int>(
"l_max_its");
254 es.parameters.set<
bool>(
"reuse preconditioner") = getParam<bool>(
"reuse_preconditioner");
255 es.parameters.set<
unsigned int>(
"reuse preconditioner maximum linear iterations") =
256 getParam<unsigned int>(
"reuse_preconditioner_max_linear_its");
266 mooseError(
"The selected problem does not allow 'nonlinear_convergence' to be set.");
268 getParam<std::vector<ConvergenceName>>(
"nonlinear_convergence"));
276 "linear_convergence",
277 "Setting 'linear_convergence' is currently only possible for solving linear systems");
279 getParam<std::vector<ConvergenceName>>(
"linear_convergence"));
287 [
this](
const auto & solver_sys)
291 "Automatic scaling isn't implemented for the case where you do not have a " 292 "preconditioning matrix. No scaling will be applied");
300 ? getParam<bool>(
"automatic_scaling")
304 [
this](
const auto & solver_sys) {
310 paramError(
"multi_system_fixed_point_convergence",
311 "Cannot set a convergence object for multi-system fixed point iterations if " 312 "'multi_system_fixed_point' is set to false");
314 paramError(
"multi_system_fixed_point_convergence",
315 "Must set a convergence object for multi-system fixed point iterations if using " 316 "multi-system fixed point iterations");
331 const auto & all_splittings = getParam<std::vector<std::vector<std::string>>>(
"splitting");
332 if (all_splittings.size())
336 nl.setDecomposition({});
338 const auto res_and_jac =
339 getParamFromNonlinearSystemVectorParam<bool>(
"residual_and_jacobian_together", i_nl_sys);
341 nl.residualAndJacobianTogether();
344 nl.computeScalingOnce(
345 getParamFromNonlinearSystemVectorParam<bool>(
"compute_scaling_once", i_nl_sys));
347 getParamFromNonlinearSystemVectorParam<Real>(
"resid_vs_jac_scaling_param", i_nl_sys));
348 nl.offDiagonalsInAutoScaling(
349 getParamFromNonlinearSystemVectorParam<bool>(
"off_diagonals_in_auto_scaling", i_nl_sys));
351 nl.scalingGroupVariables(
353 "scaling_group_variables", i_nl_sys));
360 const auto & ignore_variables_for_autoscaling =
361 getParamFromNonlinearSystemVectorParam<std::vector<std::string>>(
362 "ignore_variables_for_autoscaling", i_nl_sys);
363 const auto & scaling_group_variables =
364 getParamFromNonlinearSystemVectorParam<std::vector<std::vector<std::string>>>(
365 "scaling_group_variables", i_nl_sys);
366 for (
const auto & group : scaling_group_variables)
367 for (
const auto & var_name : group)
368 if (std::find(ignore_variables_for_autoscaling.begin(),
369 ignore_variables_for_autoscaling.end(),
370 var_name) != ignore_variables_for_autoscaling.end())
371 paramError(
"ignore_variables_for_autoscaling",
372 "Variables cannot be in a scaling grouping and also be ignored");
374 nl.ignoreVariablesForAutoscaling(
376 "ignore_variables_for_autoscaling", i_nl_sys));
384 template <
typename T>
387 unsigned int index)
const 389 const auto & param_vec = getParam<std::vector<T>>(param_name);
392 "Vector parameter is requested at index (" + std::to_string(index) +
393 ") which is larger than number of nonlinear systems (" +
395 if (param_vec.size() == 0)
398 "This parameter was passed to a routine which cannot handle empty vector parameters");
401 "Vector parameter size (" + std::to_string(param_vec.size()) +
402 ") is different than the number of nonlinear systems (" +
406 if (param_vec.size() == 1)
409 return param_vec[index];
417 if (
isParamValid(
"multi_system_fixed_point_convergence"))
422 bool converged =
false;
423 unsigned int num_fp_multisys_iters = 0;
429 num_fp_multisys_iters = 0;
443 const auto linear_sys_number =
455 const auto solve_name =
456 _systems.size() == 1 ?
" Solve" :
"System " + sys->name() +
": Solve";
460 _console << COLOR_GREEN << solve_name <<
" Converged!" << COLOR_DEFAULT << std::endl;
463 _console << COLOR_RED << solve_name <<
" Did NOT Converge!" << COLOR_DEFAULT
469 _console << COLOR_GREEN << solve_name <<
" Skipped!" << COLOR_DEFAULT << std::endl;
483 num_fp_multisys_iters++;
static InputParameters validParams()
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.
FEProblemSolve(Executioner &ex)
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.
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.
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.
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.