23const std::set<std::string> &
34 params.
addParam<
unsigned int>(
"nl_max_its", 50,
"Max Nonlinear Iterations");
35 params.
addParam<
unsigned int>(
"nl_forced_its", 0,
"The Number of Forced Nonlinear Iterations");
36 params.
addParam<
unsigned int>(
"nl_max_funcs", 10000,
"Max Nonlinear solver function evaluations");
37 params.
addParam<Real>(
"nl_abs_tol", 1.0e-50,
"Nonlinear Absolute Tolerance");
38 params.
addParam<Real>(
"nl_rel_tol", 1.0e-8,
"Nonlinear Relative Tolerance");
42 "Nonlinear Relative Divergence Tolerance. A negative value disables this check.");
46 "Nonlinear Absolute Divergence Tolerance. A negative value disables this check.");
47 params.
addParam<Real>(
"nl_abs_step_tol", 0.,
"Nonlinear Absolute step Tolerance");
48 params.
addParam<Real>(
"nl_rel_step_tol", 0.,
"Nonlinear Relative step Tolerance");
49 params.
addParam<
unsigned int>(
"n_max_nonlinear_pingpong",
51 "The maximum number of times the nonlinear residual can ping pong "
52 "before requesting halting the current evaluation and requesting "
53 "timestep cut for transient simulations");
56 "nl_max_its nl_forced_its nl_max_funcs nl_abs_tol nl_rel_tol "
57 "nl_rel_step_tol nl_abs_step_tol nl_div_tol nl_abs_div_tol n_max_nonlinear_pingpong",
71 std::set<std::string> alias_line_searches = {
"default",
"none",
"basic"};
72 line_searches.insert(alias_line_searches.begin(), alias_line_searches.end());
74 line_searches.insert(petsc_line_searches.begin(), petsc_line_searches.end());
76 MooseEnum line_search(line_search_string,
"default");
77 std::string addtl_doc_str(
" (Note: none = basic)");
79 "line_search", line_search,
"Specifies the line search type" + addtl_doc_str);
80 MooseEnum line_search_package(
"petsc moose",
"petsc");
83 "The solver package to use to conduct the line-search");
85 params.
addParam<
unsigned>(
"contact_line_search_allowed_lambda_cuts",
87 "The number of times lambda is allowed to be cut in half in the "
88 "contact line search. We recommend this number be roughly bounded by 0 "
89 "<= allowed_lambda_cuts <= 3");
90 params.
addParam<Real>(
"contact_line_search_ltol",
91 "The linear relative tolerance to be used while the contact state is "
92 "changing between non-linear iterations. We recommend that this tolerance "
93 "be looser than the standard linear tolerance");
96 params.
addParam<Real>(
"l_tol", 1.0e-5,
"Linear Relative Tolerance");
97 params.
addParam<Real>(
"l_abs_tol", 1.0e-50,
"Linear Absolute Tolerance");
98 params.
addParam<
unsigned int>(
"l_max_its", 10000,
"Max Linear Iterations");
99 params.
addParam<std::vector<ConvergenceName>>(
100 "nonlinear_convergence",
101 "Name of the Convergence object(s) to use to assess convergence of the "
102 "nonlinear system(s) solve. If not provided, the default Convergence "
103 "associated with the Problem will be constructed internally.");
104 params.
addParam<std::vector<ConvergenceName>>(
105 "linear_convergence",
106 "Name of the Convergence object(s) to use to assess convergence of the "
107 "linear system(s) solve. If not provided, the linear solver tolerance parameters are used");
111 "Specifies whether or not to reuse the base vector for matrix-free calculation");
113 "skip_exception_check",
false,
"Specifies whether or not to skip exception check");
115 "use_pre_SMO_residual",
117 "Compute the pre-SMO residual norm and use it in the relative convergence check. The "
118 "pre-SMO residual is computed at the begining of the time step before solution-modifying "
119 "objects are executed. Solution-modifying objects include preset BCs, constraints, "
121 params.
addParam<
bool>(
"automatic_scaling",
"Whether to use automatic scaling for the variables.");
123 "compute_scaling_once",
125 "Whether the scaling factors should only be computed once at the beginning of the simulation "
126 "through an extra Jacobian evaluation. If this is set to false, then the scaling factors "
127 "will be computed during an extra Jacobian evaluation at the beginning of every time step. "
128 "Vector entries correspond to each nonlinear system.");
130 "off_diagonals_in_auto_scaling",
132 "Whether to consider off-diagonals when determining automatic scaling factors. Vector "
133 "entries correspond to each nonlinear system.");
135 "resid_vs_jac_scaling_param",
137 "0<=resid_vs_jac_scaling_param<=1",
138 "A parameter that indicates the weighting of the residual vs the Jacobian in determining "
139 "variable scaling parameters. A value of 1 indicates pure residual-based scaling. A value of "
140 "0 indicates pure Jacobian-based scaling. Vector entries correspond to each nonlinear "
142 params.
addParam<std::vector<std::vector<std::vector<std::string>>>>(
143 "scaling_group_variables",
144 "Name of variables that are grouped together for determining scale factors. (Multiple "
145 "groups can be provided, separated by semicolon). Vector entries correspond to each "
146 "nonlinear system.");
147 params.
addParam<std::vector<std::vector<std::string>>>(
148 "ignore_variables_for_autoscaling",
149 "List of variables that do not participate in autoscaling. Vector entries correspond to each "
150 "nonlinear system.");
155 "The number of grids to use for a grid sequencing algorithm. This includes the final grid, "
156 "so num_grids = 1 indicates just one solve in a time-step");
157 params.
addParam<std::vector<bool>>(
"residual_and_jacobian_together",
159 "Whether to compute the residual and Jacobian together. "
160 "Vector entries correspond to each nonlinear system.");
162 params.
addParam<
bool>(
"reuse_preconditioner",
164 "If true reuse the previously calculated "
165 "preconditioner for the linearized "
166 "system across multiple solves "
167 "spanning nonlinear iterations and time steps. "
168 "The preconditioner resets as controlled by "
169 "reuse_preconditioner_max_linear_its");
170 params.
addParam<
unsigned int>(
"reuse_preconditioner_max_linear_its",
172 "Reuse the previously calculated "
173 "preconditioner for the linear system "
174 "until the number of linear iterations "
175 "exceeds this number");
178 "reuse_preconditioner_max_linear_its",
181 "solve_type snesmf_reuse_base use_pre_SMO_residual "
182 "num_grids residual_and_jacobian_together nonlinear_convergence linear_convergence",
185 "automatic_scaling compute_scaling_once off_diagonals_in_auto_scaling "
186 "scaling_group_variables resid_vs_jac_scaling_param ignore_variables_for_autoscaling",
187 "Solver variable scaling");
189 "contact_line_search_allowed_lambda_cuts",
190 "Solver line search");
198 _num_grid_steps(cast_int<unsigned
int>(getParam<unsigned
int>(
"num_grids") - 1))
204 auto set_solver_params = [
this, &ex](
const SolverSystem & sys)
206 const auto prefix = sys.prefix();
214 solver_params.
_prefix = prefix;
215 solver_params._solver_sys_num = sys.number();
219 for (
const auto *
const sys :
_systems)
220 set_solver_params(*sys);
225 es.
parameters.
set<Real>(
"linear solver tolerance") = getParam<Real>(
"l_tol");
226 es.parameters.set<Real>(
"linear solver absolute tolerance") = getParam<Real>(
"l_abs_tol");
227 es.parameters.set<
unsigned int>(
"linear solver maximum iterations") =
228 getParam<unsigned int>(
"l_max_its");
229 es.parameters.set<
bool>(
"reuse preconditioner") = getParam<bool>(
"reuse_preconditioner");
230 es.parameters.set<
unsigned int>(
"reuse preconditioner maximum linear iterations") =
231 getParam<unsigned int>(
"reuse_preconditioner_max_linear_its");
241 mooseError(
"The selected problem does not allow 'nonlinear_convergence' to be set.");
243 getParam<std::vector<ConvergenceName>>(
"nonlinear_convergence"));
251 "linear_convergence",
252 "Setting 'linear_convergence' is currently only possible for solving linear systems");
254 getParam<std::vector<ConvergenceName>>(
"linear_convergence"));
262 [
this](
const auto & solver_sys)
263 { return _problem.solverParams(solver_sys->number())._type == Moose::ST_JFNK; }))
266 "Automatic scaling isn't implemented for the case where you do not have a "
267 "preconditioning matrix. No scaling will be applied");
275 ? getParam<bool>(
"automatic_scaling")
279 [
this](
const auto & solver_sys)
281 return _problem.solverParams(solver_sys->number())._type !=
286 paramError(
"multi_system_fixed_point_convergence",
287 "Cannot set a convergence object for multi-system fixed point iterations if "
288 "'multi_system_fixed_point' is set to false");
290 paramError(
"multi_system_fixed_point_convergence",
291 "Must set a convergence object for multi-system fixed point iterations if using "
292 "multi-system fixed point iterations");
296 for (
const auto i_sys : index_range(
_systems))
307 const auto res_and_jac =
308 getParamFromNonlinearSystemVectorParam<bool>(
"residual_and_jacobian_together", i_nl_sys);
310 nl.residualAndJacobianTogether();
313 nl.computeScalingOnce(
314 getParamFromNonlinearSystemVectorParam<bool>(
"compute_scaling_once", i_nl_sys));
316 getParamFromNonlinearSystemVectorParam<Real>(
"resid_vs_jac_scaling_param", i_nl_sys));
317 nl.offDiagonalsInAutoScaling(
318 getParamFromNonlinearSystemVectorParam<bool>(
"off_diagonals_in_auto_scaling", i_nl_sys));
320 nl.scalingGroupVariables(
322 "scaling_group_variables", i_nl_sys));
329 const auto & ignore_variables_for_autoscaling =
330 getParamFromNonlinearSystemVectorParam<std::vector<std::string>>(
331 "ignore_variables_for_autoscaling", i_nl_sys);
332 const auto & scaling_group_variables =
333 getParamFromNonlinearSystemVectorParam<std::vector<std::vector<std::string>>>(
334 "scaling_group_variables", i_nl_sys);
335 for (
const auto & group : scaling_group_variables)
336 for (
const auto & var_name : group)
337 if (std::find(ignore_variables_for_autoscaling.begin(),
338 ignore_variables_for_autoscaling.end(),
339 var_name) != ignore_variables_for_autoscaling.end())
340 paramError(
"ignore_variables_for_autoscaling",
341 "Variables cannot be in a scaling grouping and also be ignored");
343 nl.ignoreVariablesForAutoscaling(
345 "ignore_variables_for_autoscaling", i_nl_sys));
356 unsigned int index)
const
358 const auto & param_vec = getParam<std::vector<T>>(param_name);
361 "Vector parameter is requested at index (" + std::to_string(index) +
362 ") which is larger than number of nonlinear systems (" +
364 if (param_vec.size() == 0)
367 "This parameter was passed to a routine which cannot handle empty vector parameters");
370 "Vector parameter size (" + std::to_string(param_vec.size()) +
371 ") is different than the number of nonlinear systems (" +
375 if (param_vec.size() == 1)
378 return param_vec[index];
398 for (
const auto i : index_range(
_systems))
400 const auto sys_num =
_systems[i]->number();
424 for (
const auto & conv_name : conv_names)
433 const auto conv_names = getParam<std::vector<ConvergenceName>>(
"linear_convergence");
434 for (
const auto & conv_name : conv_names)
442 if (
isParamValid(
"multi_system_fixed_point_convergence"))
455 bool converged =
false;
456 unsigned int fp_iter = 0;
466 _console << COLOR_MAGENTA <<
"Multi-system fixed point iteration " << fp_iter <<
":"
467 << COLOR_DEFAULT <<
"\n"
475 for (
const auto sys_i : index_range(
_systems))
485 const auto linear_sys_number =
491 const auto solve_name =
492 _systems.size() == 1 ?
" Solve" :
"System " + sys->name() +
": Solve";
500 _console << COLOR_GREEN << solve_name <<
" Converged!" << COLOR_DEFAULT <<
"\n"
505 _console << COLOR_RED << solve_name <<
" Did NOT Converge!" << COLOR_DEFAULT <<
"\n"
511 _console << COLOR_GREEN << solve_name <<
" Skipped!" << COLOR_DEFAULT <<
"\n"
516 const auto linear_sys_number =
536 const auto n_fp_iter = fp_iter + 1;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
const ExecFlagType EXEC_MULTISYSTEM_FIXED_POINT_ITERATION_END
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter)=0
Returns convergence status.
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
Executioners are objects that do the actual work of solving your problem.
void numGridSteps(unsigned int num_grid_steps)
Set the number of steps in a grid sequences.
const std::vector< ConvergenceName > & getNonlinearConvergenceNames() const
Gets the nonlinear system convergence object name(s).
void setLinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the linear convergence object name(s) if there is one.
virtual std::size_t numLinearSystems() const override
void setNeedToAddDefaultNonlinearConvergence()
Sets _need_to_add_default_nonlinear_convergence to true.
virtual libMesh::EquationSystems & es() override
virtual void addLineSearch(const InputParameters &)
add a MOOSE line search
void setNonlinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the nonlinear convergence object name(s) if there is one.
virtual std::size_t numNonlinearSystems() const override
void skipExceptionCheck(bool skip_exception_check)
Set a flag that indicates if we want to skip exception and stop solve.
void needsPreviousMultiSystemFixedPointIterationAuxiliary(bool state)
Set a flag that indicates that user requires values for the previous multi-system fixed point iterate...
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
virtual void solveLinearSystem(const unsigned int linear_sys_num, const Moose::PetscSupport::PetscOptions *po=nullptr)
Build and solve a linear system.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
void setSNESMFReuseBase(bool reuse, bool set_by_user)
If or not to reuse the base vector for matrix-free calculation.
virtual void solve(const unsigned int nl_sys_num)
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
void automaticScaling(bool automatic_scaling) override
Automatic scaling setter.
virtual bool onlyAllowDefaultNonlinearConvergence() const
Returns true if an error will result if the user supplies 'nonlinear_convergence'.
void needsPreviousMultiSystemFixedPointIterationSolution(bool needed, const unsigned int solver_sys_num)
Set a flag that indicates that user requires values for the previous multi-system fixed point iterate...
virtual void outputStep(ExecFlagType type)
Output the current step.
void uniformRefine()
uniformly refine the problem mesh(es).
static InputParameters feProblemDefaultConvergenceParams()
T getParamFromNonlinearSystemVectorParam(const std::string ¶m_name, unsigned int index) const
Helper routine to get the nonlinear system parameter at the right index.
static const std::set< std::string > & mooseLineSearches()
void convergenceSetup()
Performs setup related to Convergence objects.
const unsigned int _num_grid_steps
The number of steps to perform in a grid sequencing algorithm.
static std::set< std::string > const _moose_line_searches
Moose provided line searches.
FEProblemSolve(Executioner &ex)
virtual void initialSetup() override
Method that should be executed once, before any solve calls.
virtual bool solve() override
Picard solve the FEProblem.
static InputParameters validParams()
Linear system to be solved.
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
bool isRecovering() const
Whether or not this is a "recover" calculation.
bool defaultAutomaticScaling() const
Whether to enable automatic scaling by default.
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
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 InputParameters & _pars
The object's parameters.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
MooseApp & _app
The MOOSE application this is associated with.
A solve object for use when wanting to solve multiple systems.
const bool _using_multi_sys_fp_iterations
Whether we are using fixed point iterations for multi-system.
Convergence * _multi_sys_fp_convergence
Convergence object to assess the convergence of the multi-system fixed point iteration.
std::set< SystemBase * > _systems_to_copy_back_multi_sys_fp
Systems that should save their previous multi-system fixed point solutions.
unsigned int _num_nl_systems
Number of nonlinear systems.
std::vector< Real > _multi_sys_fp_relax_factors
Per-system relaxation factors for multi-system fixed point iterations (expanded to match the number/o...
std::vector< bool > _perform_multi_sys_fp_relaxation
Whether to perform relaxation for each solve system, indexed over solve system.
static InputParameters validParams()
std::vector< SolverSystem * > _systems
Vector of pointers to the systems.
Nonlinear system to be solved.
void setPreSMOResidual(bool use)
Set whether to evaluate the pre-SMO residual and use it in the subsequent relative convergence checks...
void paramWarning(const std::string ¶m, Args... args) const
void accumulateIterationIntoTimeStepOccurences()
Pass the number of solution invalid occurrences from current iteration to cumulative counters.
void accumulateTimeStepIntoTotalOccurences(const unsigned int timestep_index)
Pass the number of solution invalid occurrences from current timestep to cumulative timestep counter ...
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
FEProblemBase & _problem
Reference to FEProblem.
virtual void initialSetup()
Method that should be executed once, before any solve calls.
AuxiliarySystem & _aux
Reference to auxiliary system for faster access.
virtual bool converged(const unsigned int sys_num)
Eventually we want to convert this virtual over to taking a solver system number argument.
virtual void needSolutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time, libMesh::ParallelType parallel_type=GHOSTED)
Registers that the solution state state is needed.
NumericVector< Number > & solution()
ParallelType type() const
T & set(const std::string &)
const auto MULTISYSTEM_FIXED_POINT
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...
void dontAddCommonSNESOptions(FEProblemBase &fe_problem)
Function to ensure that common SNES options are not added to the PetscOptions storage object to be la...
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
std::set< std::string > getPetscValidLineSearches()
Returns the valid petsc line search options as a set of strings.
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.
std::string stringify(const T &t)
conversion to string