https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CreateExecutionerAction.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11#include "Factory.h"
12#include "PetscSupport.h"
13#include "MooseApp.h"
14#include "Executioner.h"
15#include "FEProblem.h"
16#include "EigenProblem.h"
17#include "EigenProblemSolve.h"
19
20registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner");
21
24{
26 params.addClassDescription("Add an Executioner object to the simulation.");
27 params.addParam<bool>(
28 "auto_preconditioning",
29 true,
30 "When true, the application will attempt to use the correct preconditioning given the "
31 "Executioner settings for the nonlinear systems that do not have a preconditioner in the "
32 "[Preconditioning] block.");
33 return params;
34}
35
37 : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning"))
38{
39}
40
41void
43{
44 std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem);
45 if (eigen_problem)
46 _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get();
47 _moose_object_pars.set<SubProblem *>("_subproblem") = cast_ptr<SubProblem *>(_problem.get());
48
49 std::shared_ptr<Executioner> executioner =
51
52 if ((eigen_problem != nullptr) != executioner->hasSolveObject<EigenProblemSolve>())
53 mooseError("Executioner is not consistent with each other; EigenExecutioner needs an "
54 "EigenProblem, and Steady and Transient need a FEProblem");
55
56 // If enabled, automatically create a Preconditioner for the nonlinear systems that do not have
57 // one in the [Preconditioning] block
60
61 _app.setExecutioner(std::move(executioner));
62}
63
64void
66{
67 // Nonlinear systems that already have a preconditioner from the [Preconditioning] block. Other
68 // actions on the preconditioning task (e.g. Physics) are not tied to a nonlinear system, so
69 // their presence disables the automatic preconditioner entirely.
70 std::set<unsigned int> preconditioned_nl_sys;
71 for (const auto action : _awh.getActionListByName("add_preconditioning"))
72 {
73 const auto pc_action = dynamic_cast<const SetupPreconditionerAction *>(action);
74 if (!pc_action)
75 return;
76 const auto & pc_params = pc_action->getObjectParams();
77 preconditioned_nl_sys.insert(
78 pc_params.isParamValid("nl_sys")
79 ? _problem->nlSysNum(pc_params.get<NonlinearSystemName>("nl_sys"))
80 : 0);
81 }
82
83 // Without a [Preconditioning] block, only NEWTON and LINEAR solves need a preconditioner, which
84 // then uses the full coupling. A user preconditioner sets a custom coupling matrix, so every
85 // other nonlinear system then needs a preconditioner to set its coupling matrix, whatever the
86 // solve type. Its coupling follows the effective solve type, which a user preconditioner can
87 // override.
88 if (preconditioned_nl_sys.empty())
89 {
90 // Compare as a string because the eigenvalue solve type enumeration has no LINEAR item
91 const std::string & solve_type = _moose_object_pars.get<MooseEnum>("solve_type");
92 if (solve_type != "NEWTON" && solve_type != "LINEAR")
93 return;
94 }
95
96 for (const auto & nl_sys_name : _problem->getNonlinearSystemNames())
97 {
98 if (preconditioned_nl_sys.count(_problem->nlSysNum(nl_sys_name)))
99 continue;
100
101 // Action Parameters
102 InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction");
103 params.set<std::string>("type") = "SMP";
104
105 // Associate errors with "solve_type"
106 associateWithParameter(_moose_object_pars, "solve_type", params);
107
108 // Create the Action that will build the Preconditioner object
109 std::shared_ptr<Action> ptr = _action_factory.create(
110 "SetupPreconditionerAction",
111 MooseUtils::join(
112 std::vector<std::string>({"_moose_auto", static_cast<std::string>(nl_sys_name)}), "_"),
113 params);
114
115 // The SingleMatrixPreconditioner defaults to the full coupling for NEWTON and LINEAR solves
116 std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr);
117 InputParameters & mo_params = moa_ptr->getObjectParams();
118 mo_params.set<NonlinearSystemName>("nl_sys") = nl_sys_name;
119
120 _awh.addActionBlock(ptr);
121 }
122}
registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner")
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name)
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
void associateWithParameter(const std::string &param_name, InputParameters &params) const
Associates the object's parameters params with the input location from this Action's parameter with t...
Definition Action.C:170
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition Action.h:169
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
CreateExecutionerAction(const InputParameters &params)
static InputParameters validParams()
EigenProblemSolve is used to solve an eigenvalue problem interfacing SLEPc.
Problem for solving eigenvalue problems.
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition Factory.C:142
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
void setExecutioner(std::shared_ptr< Executioner > &&executioner)
Set the Executioner for this App.
Definition MooseApp.h:346
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...
Definition MooseBase.h:271
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
InputParameters _moose_object_pars
The parameters for the object to be created.
static InputParameters validParams()
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
std::string _type
The Object type that is being created.
ActionFactory & _action_factory
Builds Actions.
Factory & _factory
The Factory associated with the MooseApp.
Set the preconditioner up.
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
void insert(const std::string &)