www.mooseframework.org
Executioner.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // Moose includes
16 #include "Executioner.h"
17 
18 #include "FEProblem.h"
19 #include "MooseApp.h"
20 #include "MooseMesh.h"
21 #include "NonlinearSystem.h"
22 #include "SlepcSupport.h"
23 
24 // C++ includes
25 #include <vector>
26 #include <limits>
27 
28 template <>
31 {
33  params.addDeprecatedParam<FileNameNoExtension>(
34  "restart_file_base",
35  "",
36  "File base name used for restart",
37  "Please use \"Problem/restart_file_base\" instead");
38 
39  params.registerBase("Executioner");
40 
41  params.addParamNamesToGroup("restart_file_base", "Restart");
42 
43  params.addParam<std::vector<std::string>>("splitting",
44  "Top-level splitting defining a "
45  "hierarchical decomposition into "
46  "subsystems to help the solver.");
47 
48 // Default Solver Behavior
49 #ifdef LIBMESH_HAVE_PETSC
51 #endif // LIBMESH_HAVE_PETSC
52  params.addParam<Real>("l_tol", 1.0e-5, "Linear Tolerance");
53  params.addParam<Real>("l_abs_step_tol", -1, "Linear Absolute Step Tolerance");
54  params.addParam<unsigned int>("l_max_its", 10000, "Max Linear Iterations");
55  params.addParam<unsigned int>("nl_max_its", 50, "Max Nonlinear Iterations");
56  params.addParam<unsigned int>("nl_max_funcs", 10000, "Max Nonlinear solver function evaluations");
57  params.addParam<Real>("nl_abs_tol", 1.0e-50, "Nonlinear Absolute Tolerance");
58  params.addParam<Real>("nl_rel_tol", 1.0e-8, "Nonlinear Relative Tolerance");
59  params.addParam<Real>("nl_abs_step_tol", 1.0e-50, "Nonlinear Absolute step Tolerance");
60  params.addParam<Real>("nl_rel_step_tol", 1.0e-50, "Nonlinear Relative step Tolerance");
61  params.addParam<bool>("no_fe_reinit", false, "Specifies whether or not to reinitialize FEs");
62  params.addParam<bool>("compute_initial_residual_before_preset_bcs",
63  false,
64  "Use the residual norm computed *before* PresetBCs are imposed in relative "
65  "convergence check");
66 
67  params.addParamNamesToGroup("l_tol l_abs_step_tol l_max_its nl_max_its nl_max_funcs "
68  "nl_abs_tol nl_rel_tol nl_abs_step_tol nl_rel_step_tol "
69  "compute_initial_residual_before_preset_bcs",
70  "Solver");
71  params.addParamNamesToGroup("no_fe_reinit", "Advanced");
72 
73  return params;
74 }
75 
77  : MooseObject(parameters),
78  UserObjectInterface(this),
80  Restartable(parameters, "Executioners"),
81  _fe_problem(*parameters.getCheckedPointerParam<FEProblemBase *>(
82  "_fe_problem_base", "This might happen if you don't have a mesh")),
83  _initial_residual_norm(std::numeric_limits<Real>::max()),
84  _old_initial_residual_norm(std::numeric_limits<Real>::max()),
85  _restart_file_base(getParam<FileNameNoExtension>("restart_file_base")),
86  _splitting(getParam<std::vector<std::string>>("splitting"))
87 {
88 // Extract and store PETSc related settings on FEProblemBase
89 #ifdef LIBMESH_HAVE_PETSC
91 #endif // LIBMESH_HAVE_PETSC
92 
93  // solver params
94  EquationSystems & es = _fe_problem.es();
95  es.parameters.set<Real>("linear solver tolerance") = getParam<Real>("l_tol");
96 
97  es.parameters.set<Real>("linear solver absolute step tolerance") =
98  getParam<Real>("l_abs_step_tol");
99 
100  es.parameters.set<unsigned int>("linear solver maximum iterations") =
101  getParam<unsigned int>("l_max_its");
102 
103  es.parameters.set<unsigned int>("nonlinear solver maximum iterations") =
104  getParam<unsigned int>("nl_max_its");
105 
106  es.parameters.set<unsigned int>("nonlinear solver maximum function evaluations") =
107  getParam<unsigned int>("nl_max_funcs");
108 
109  es.parameters.set<Real>("nonlinear solver absolute residual tolerance") =
110  getParam<Real>("nl_abs_tol");
111 
112  es.parameters.set<Real>("nonlinear solver relative residual tolerance") =
113  getParam<Real>("nl_rel_tol");
114 
115  es.parameters.set<Real>("nonlinear solver absolute step tolerance") =
116  getParam<Real>("nl_abs_step_tol");
117 
118  es.parameters.set<Real>("nonlinear solver relative step tolerance") =
119  getParam<Real>("nl_rel_step_tol");
120 
122  getParam<bool>("compute_initial_residual_before_preset_bcs");
123 
124  _fe_problem.getNonlinearSystemBase()._l_abs_step_tol = getParam<Real>("l_abs_step_tol");
125 }
126 
128 
129 void
131 {
132 }
133 
134 void
136 {
137 }
138 
139 void
141 {
142 }
143 
144 void
146 {
147 }
148 
149 void
151 {
152 }
153 
154 Problem &
156 {
157  mooseDoOnce(mooseWarning("This method is deprecated, use feProblem() instead"));
158  return _fe_problem;
159 }
160 
163 {
164  return _fe_problem;
165 }
166 
167 std::string
169 {
170  return std::string();
171 }
172 
173 bool
175 {
176  return _fe_problem.converged();
177 }
178 
179 void
181  Real & attribute,
182  const std::string execute_on)
183 {
185  "_fe_problem_base",
186  "Failed to retrieve FEProblemBase when adding a attribute reporter in Executioner");
187  InputParameters params = _app.getFactory().getValidParams("ExecutionerAttributeReporter");
188  params.set<Real *>("value") = &attribute;
189  if (!execute_on.empty())
190  params.set<MultiMooseEnum>("execute_on") = execute_on;
191  problem->addPostprocessor("ExecutionerAttributeReporter", name, params);
192 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
void storePetscOptions(FEProblemBase &fe_problem, const InputParameters &params)
Stores the PETSc options supplied from the InputParameters with MOOSE.
Definition: PetscSupport.C:598
void mooseWarning(Args &&...args) const
Definition: MooseObject.h:89
A class for creating restricted objects.
Definition: Restartable.h:31
virtual void addAttributeReporter(const std::string &name, Real &attribute, const std::string execute_on="")
Adds a postprocessor to report a Real class attribute.
Definition: Executioner.C:180
virtual std::string getTimeStepperName()
The name of the TimeStepper This is an empty string for non-Transient executioners.
Definition: Executioner.C:168
Executioner(const InputParameters &parameters)
Constructor.
Definition: Executioner.C:76
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
NonlinearSystemBase & getNonlinearSystemBase()
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:26
virtual void postExecute()
Override this for actions that should take place after execution.
Definition: Executioner.C:140
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Class that hold the whole problem being solved.
Definition: Problem.h:29
InputParameters validParams< Executioner >()
Definition: Executioner.C:30
FEProblemBase & feProblem()
Return a reference to this Executioner&#39;s FEProblemBase instance.
Definition: Executioner.C:162
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Factory & getFactory()
Retrieve the Factory associated with this App.
Definition: MooseApp.h:253
virtual EquationSystems & es() override
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual bool converged() override
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
virtual Problem & problem()
Deprecated: Return a reference to this Executioner&#39;s Problem instance.
Definition: Executioner.C:155
Interface for objects that need to use UserObjects.
virtual ~Executioner()
Definition: Executioner.C:127
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:111
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.C:135
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
virtual bool lastSolveConverged()
Whether or not the last solve converged.
Definition: Executioner.C:174
virtual void init()
Initialize the executioner.
Definition: Executioner.C:130
bool _compute_initial_residual_before_preset_bcs
virtual void preSolve()
Override this for actions that should take place before execution.
Definition: Executioner.C:145
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
Definition: PetscSupport.C:738
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
virtual void postSolve()
Override this for actions that should take place after execution.
Definition: Executioner.C:150
virtual void addPostprocessor(std::string pp_name, const std::string &name, InputParameters parameters)
Interface class for classes which interact with Postprocessors.
FEProblemBase & _fe_problem
Definition: Executioner.h:126
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...