22 const std::set<std::string> &
33 params.
addParam<
unsigned int>(
"nl_max_its", 50,
"Max Nonlinear Iterations");
34 params.
addParam<
unsigned int>(
"nl_forced_its", 0,
"The Number of Forced Nonlinear Iterations");
35 params.
addParam<
unsigned int>(
"nl_max_funcs", 10000,
"Max Nonlinear solver function evaluations");
36 params.
addParam<
Real>(
"nl_abs_tol", 1.0e-50,
"Nonlinear Absolute Tolerance");
37 params.
addParam<
Real>(
"nl_rel_tol", 1.0e-8,
"Nonlinear Relative Tolerance");
41 "Nonlinear Relative Divergence Tolerance. A negative value disables this check.");
45 "Nonlinear Absolute Divergence Tolerance. A negative value disables this check.");
46 params.
addParam<
Real>(
"nl_abs_step_tol", 0.,
"Nonlinear Absolute step Tolerance");
47 params.
addParam<
Real>(
"nl_rel_step_tol", 0.,
"Nonlinear Relative step Tolerance");
48 params.
addParam<
unsigned int>(
"n_max_nonlinear_pingpong",
50 "The maximum number of times the nonlinear residual can ping pong " 51 "before requesting halting the current evaluation and requesting " 52 "timestep cut for transient simulations");
55 "nl_max_its nl_forced_its nl_max_funcs nl_abs_tol nl_rel_tol " 56 "nl_rel_step_tol nl_abs_step_tol nl_div_tol nl_abs_div_tol n_max_nonlinear_pingpong",
70 std::set<std::string> alias_line_searches = {
"default",
"none",
"basic"};
71 line_searches.insert(alias_line_searches.begin(), alias_line_searches.end());
73 line_searches.insert(petsc_line_searches.begin(), petsc_line_searches.end());
75 MooseEnum line_search(line_search_string,
"default");
76 std::string addtl_doc_str(
" (Note: none = basic)");
78 "line_search", line_search,
"Specifies the line search type" + addtl_doc_str);
79 MooseEnum line_search_package(
"petsc moose",
"petsc");
82 "The solver package to use to conduct the line-search");
84 params.
addParam<
unsigned>(
"contact_line_search_allowed_lambda_cuts",
86 "The number of times lambda is allowed to be cut in half in the " 87 "contact line search. We recommend this number be roughly bounded by 0 " 88 "<= allowed_lambda_cuts <= 3");
90 "The linear relative tolerance to be used while the contact state is " 91 "changing between non-linear iterations. We recommend that this tolerance " 92 "be looser than the standard linear tolerance");
95 params.addParam<
Real>(
"l_tol", 1.0e-5,
"Linear Relative Tolerance");
96 params.addParam<
Real>(
"l_abs_tol", 1.0e-50,
"Linear Absolute Tolerance");
97 params.addParam<
unsigned int>(
"l_max_its", 10000,
"Max Linear Iterations");
98 params.addParam<std::vector<ConvergenceName>>(
99 "nonlinear_convergence",
100 "Name of the Convergence object(s) to use to assess convergence of the " 101 "nonlinear system(s) solve. If not provided, the default Convergence " 102 "associated with the Problem will be constructed internally.");
103 params.addParam<std::vector<ConvergenceName>>(
104 "linear_convergence",
105 "Name of the Convergence object(s) to use to assess convergence of the " 106 "linear system(s) solve. If not provided, the linear solver tolerance parameters are used");
107 params.addParam<
bool>(
110 "Specifies whether or not to reuse the base vector for matrix-free calculation");
111 params.addParam<
bool>(
112 "skip_exception_check",
false,
"Specifies whether or not to skip exception check");
113 params.addParam<
bool>(
114 "use_pre_SMO_residual",
116 "Compute the pre-SMO residual norm and use it in the relative convergence check. The " 117 "pre-SMO residual is computed at the begining of the time step before solution-modifying " 118 "objects are executed. Solution-modifying objects include preset BCs, constraints, " 120 params.addParam<
bool>(
"automatic_scaling",
"Whether to use automatic scaling for the variables.");
121 params.addParam<std::vector<bool>>(
122 "compute_scaling_once",
124 "Whether the scaling factors should only be computed once at the beginning of the simulation " 125 "through an extra Jacobian evaluation. If this is set to false, then the scaling factors " 126 "will be computed during an extra Jacobian evaluation at the beginning of every time step. " 127 "Vector entries correspond to each nonlinear system.");
128 params.addParam<std::vector<bool>>(
129 "off_diagonals_in_auto_scaling",
131 "Whether to consider off-diagonals when determining automatic scaling factors. Vector " 132 "entries correspond to each nonlinear system.");
133 params.addRangeCheckedParam<std::vector<Real>>(
134 "resid_vs_jac_scaling_param",
136 "0<=resid_vs_jac_scaling_param<=1",
137 "A parameter that indicates the weighting of the residual vs the Jacobian in determining " 138 "variable scaling parameters. A value of 1 indicates pure residual-based scaling. A value of " 139 "0 indicates pure Jacobian-based scaling. Vector entries correspond to each nonlinear " 141 params.addParam<std::vector<std::vector<std::vector<std::string>>>>(
142 "scaling_group_variables",
143 "Name of variables that are grouped together for determining scale factors. (Multiple " 144 "groups can be provided, separated by semicolon). Vector entries correspond to each " 145 "nonlinear system.");
146 params.addParam<std::vector<std::vector<std::string>>>(
147 "ignore_variables_for_autoscaling",
148 "List of variables that do not participate in autoscaling. Vector entries correspond to each " 149 "nonlinear system.");
150 params.addRangeCheckedParam<
unsigned int>(
154 "The number of grids to use for a grid sequencing algorithm. This includes the final grid, " 155 "so num_grids = 1 indicates just one solve in a time-step");
156 params.addParam<std::vector<bool>>(
"residual_and_jacobian_together",
158 "Whether to compute the residual and Jacobian together. " 159 "Vector entries correspond to each nonlinear system.");
161 params.addParam<
bool>(
"reuse_preconditioner",
163 "If true reuse the previously calculated " 164 "preconditioner for the linearized " 165 "system across multiple solves " 166 "spanning nonlinear iterations and time steps. " 167 "The preconditioner resets as controlled by " 168 "reuse_preconditioner_max_linear_its");
169 params.addParam<
unsigned int>(
"reuse_preconditioner_max_linear_its",
171 "Reuse the previously calculated " 172 "preconditioner for the linear system " 173 "until the number of linear iterations " 174 "exceeds this number");
179 params.addParam<
bool>(
180 "multi_system_fixed_point",
182 "Whether to perform fixed point (Picard) iterations between the nonlinear systems.");
183 params.addRangeCheckedParam<std::vector<Real>>(
184 "multi_system_fixed_point_relaxation_factor",
186 "multi_system_fixed_point_relaxation_factor>0 & multi_system_fixed_point_relaxation_factor<2",
187 "Relaxation factor(s) applied to system solution updates during multi-system fixed point " 188 "iterations; 1 disables relaxation. If one value is provided it is applied to every system; " 189 "otherwise the vector must match the number/order of systems being solved.");
190 params.addParam<ConvergenceName>(
191 "multi_system_fixed_point_convergence",
192 "Convergence object to determine the convergence of the multi-system fixed point iteration.");
194 params.addParamNamesToGroup(
"l_tol l_abs_tol l_max_its reuse_preconditioner " 195 "reuse_preconditioner_max_linear_its",
197 params.addParamNamesToGroup(
198 "solve_type snesmf_reuse_base use_pre_SMO_residual " 199 "num_grids residual_and_jacobian_together nonlinear_convergence linear_convergence",
201 params.addParamNamesToGroup(
202 "automatic_scaling compute_scaling_once off_diagonals_in_auto_scaling " 203 "scaling_group_variables resid_vs_jac_scaling_param ignore_variables_for_autoscaling",
204 "Solver variable scaling");
205 params.addParamNamesToGroup(
"line_search line_search_package contact_line_search_ltol " 206 "contact_line_search_allowed_lambda_cuts",
207 "Solver line search");
208 params.addParamNamesToGroup(
"multi_system_fixed_point multi_system_fixed_point_convergence " 209 "multi_system_fixed_point_relaxation_factor",
210 "Multiple solver system");
211 params.addParamNamesToGroup(
"skip_exception_check",
"Advanced");
218 _num_grid_steps(
cast_int<unsigned
int>(getParam<unsigned
int>(
"num_grids") - 1)),
219 _using_multi_sys_fp_iterations(getParam<bool>(
"multi_system_fixed_point")),
220 _multi_sys_fp_convergence(nullptr)
224 paramError(
"Can't use relaxation factors because multisystem fixed point iteration hasn't been " 233 auto set_solver_params = [
this, &ex](
const SolverSystem & sys)
235 const auto prefix = sys.prefix();
236 if (dynamic_cast<const LinearSystem *>(&sys))
243 solver_params.
_prefix = prefix;
244 solver_params._solver_sys_num = sys.number();
248 for (
const auto *
const sys :
_systems)
249 set_solver_params(*sys);
255 es.parameters.set<
Real>(
"linear solver absolute tolerance") = getParam<Real>(
"l_abs_tol");
256 es.parameters.set<
unsigned int>(
"linear solver maximum iterations") =
257 getParam<unsigned int>(
"l_max_its");
258 es.parameters.set<
bool>(
"reuse preconditioner") = getParam<bool>(
"reuse_preconditioner");
259 es.parameters.set<
unsigned int>(
"reuse preconditioner maximum linear iterations") =
260 getParam<unsigned int>(
"reuse_preconditioner_max_linear_its");
270 mooseError(
"The selected problem does not allow 'nonlinear_convergence' to be set.");
272 getParam<std::vector<ConvergenceName>>(
"nonlinear_convergence"));
280 "linear_convergence",
281 "Setting 'linear_convergence' is currently only possible for solving linear systems");
283 getParam<std::vector<ConvergenceName>>(
"linear_convergence"));
291 [
this](
const auto & solver_sys)
295 "Automatic scaling isn't implemented for the case where you do not have a " 296 "preconditioning matrix. No scaling will be applied");
304 ? getParam<bool>(
"automatic_scaling")
308 [
this](
const auto & solver_sys)
315 paramError(
"multi_system_fixed_point_convergence",
316 "Cannot set a convergence object for multi-system fixed point iterations if " 317 "'multi_system_fixed_point' is set to false");
319 paramError(
"multi_system_fixed_point_convergence",
320 "Must set a convergence object for multi-system fixed point iterations if using " 321 "multi-system fixed point iterations");
336 const auto res_and_jac =
337 getParamFromNonlinearSystemVectorParam<bool>(
"residual_and_jacobian_together", i_nl_sys);
339 nl.residualAndJacobianTogether();
342 nl.computeScalingOnce(
343 getParamFromNonlinearSystemVectorParam<bool>(
"compute_scaling_once", i_nl_sys));
345 getParamFromNonlinearSystemVectorParam<Real>(
"resid_vs_jac_scaling_param", i_nl_sys));
346 nl.offDiagonalsInAutoScaling(
347 getParamFromNonlinearSystemVectorParam<bool>(
"off_diagonals_in_auto_scaling", i_nl_sys));
349 nl.scalingGroupVariables(
351 "scaling_group_variables", i_nl_sys));
358 const auto & ignore_variables_for_autoscaling =
359 getParamFromNonlinearSystemVectorParam<std::vector<std::string>>(
360 "ignore_variables_for_autoscaling", i_nl_sys);
361 const auto & scaling_group_variables =
362 getParamFromNonlinearSystemVectorParam<std::vector<std::vector<std::string>>>(
363 "scaling_group_variables", i_nl_sys);
364 for (
const auto & group : scaling_group_variables)
365 for (
const auto & var_name : group)
366 if (
std::find(ignore_variables_for_autoscaling.begin(),
367 ignore_variables_for_autoscaling.end(),
368 var_name) != ignore_variables_for_autoscaling.end())
369 paramError(
"ignore_variables_for_autoscaling",
370 "Variables cannot be in a scaling grouping and also be ignored");
372 nl.ignoreVariablesForAutoscaling(
374 "ignore_variables_for_autoscaling", i_nl_sys));
382 template <
typename T>
385 unsigned int index)
const 387 const auto & param_vec = getParam<std::vector<T>>(param_name);
390 "Vector parameter is requested at index (" + std::to_string(index) +
391 ") which is larger than number of nonlinear systems (" +
393 if (param_vec.size() == 0)
396 "This parameter was passed to a routine which cannot handle empty vector parameters");
399 "Vector parameter size (" + std::to_string(param_vec.size()) +
400 ") is different than the number of nonlinear systems (" +
404 if (param_vec.size() == 1)
407 return param_vec[index];
430 for (
const auto & conv_name : conv_names)
439 const auto conv_names = getParam<std::vector<ConvergenceName>>(
"linear_convergence");
440 for (
const auto & conv_name : conv_names)
448 if (
isParamValid(
"multi_system_fixed_point_convergence"))
461 getParam<std::vector<Real>>(
"multi_system_fixed_point_relaxation_factor");
465 paramError(
"multi_system_fixed_point_relaxation_factor",
467 " values (one per system in the solve order).");
474 bool converged =
false;
475 unsigned int num_fp_multisys_iters = 0;
480 num_fp_multisys_iters = 0;
485 _console << COLOR_MAGENTA <<
"Multi-system fixed point iteration " << num_fp_multisys_iters
486 <<
":" << COLOR_DEFAULT <<
"\n" 494 const Real fp_relax =
496 const bool apply_fp_relax =
500 sys->setFixedPointRelaxationFactor(fp_relax);
501 sys->saveOldSolutionForFixedPointRelaxation();
509 const auto linear_sys_number =
515 const auto solve_name =
516 _systems.size() == 1 ?
" Solve" :
"System " + sys->name() +
": Solve";
522 sys->applyFixedPointRelaxation();
523 _console << COLOR_GREEN << solve_name <<
" Converged!" << COLOR_DEFAULT <<
"\n" 528 _console << COLOR_RED << solve_name <<
" Did NOT Converge!" << COLOR_DEFAULT <<
"\n" 531 sys->clearFixedPointRelaxation();
536 _console << COLOR_GREEN << solve_name <<
" Skipped!" << COLOR_DEFAULT <<
"\n" 541 const auto linear_sys_number =
552 sys->clearFixedPointRelaxation();
562 const auto convergence_status =
568 num_fp_multisys_iters++;
const ExecFlagType EXEC_MULTISYSTEM_FIXED_POINT_CONVERGENCE
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)
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
void accumulateTimeStepIntoTotalOccurences(const unsigned int timestep_index)
Pass the number of solution invalid occurrences from current timestep to cumulative timestep counter ...
const InputParameters & _pars
The object's parameters.
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 ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
virtual std::size_t numNonlinearSystems() const override
std::set< std::string > getPetscValidLineSearches()
Returns the valid petsc line search options as a set of strings.
void accumulateIterationIntoTimeStepOccurences()
Pass the number of solution invalid occurrences from current iteration to cumulative counters...
virtual MooseConvergenceStatus checkConvergence(unsigned int iter)=0
Returns convergence status.
static std::set< std::string > const _moose_line_searches
Moose provided line searches.
std::vector< Real > _multi_sys_fp_relax_factors
Per-system relaxation factors for multi-system fixed point iterations (expanded to match the number/o...
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.
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
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 setConvergedReasonFlags(FEProblemBase &fe_problem, std::string prefix)
Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspectiv...
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
void uniformRefine()
uniformly refine the problem mesh(es).
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.
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
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()
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.
MooseApp & _app
The MOOSE application this is associated with.
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 dontAddCommonSNESOptions(FEProblemBase &fe_problem)
Function to ensure that common SNES options are not added to the PetscOptions storage object to be la...
void setupMultiSystemFixedPointRelaxationFactors()
Initializes/expands the multi-system fixed point relaxation factors.
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 and optionally a file path to the top-level block p...
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
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
void automaticScaling(bool automatic_scaling) override
Automatic scaling setter.
void paramWarning(const std::string ¶m, Args... args) const
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.
bool isRecovering() const
Whether or not this is a "recover" calculation.
void ErrorVector unsigned int
auto index_range(const T &sizable)
const std::string & _type
The type of this class.
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.