https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CreateProblemDefaultAction.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
12#include "Factory.h"
13#include "FEProblem.h"
14#include "EigenProblem.h"
15#include "MooseApp.h"
17#include "CreateProblemAction.h"
18
19registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default");
20registerMooseAction("MooseApp", CreateProblemDefaultAction, "determine_system_type");
21
24{
26 params.addPrivateParam<bool>("_solve");
27 return params;
28}
29
34
35void
37{
38 if (_current_task == "determine_system_type")
39 {
40 // Determine whether the Executioner is derived from EigenExecutionerBase and
41 // set a flag on MooseApp that can be used during problem construction.
42 bool use_nonlinear = true;
43 bool use_eigenvalue = false;
44 auto p = _awh.getActionByTask<CreateExecutionerAction>("setup_executioner");
45 if (p)
46 {
47 auto & exparams = p->getObjectParams();
48 use_nonlinear = !(exparams.isParamValid("_eigen") && exparams.get<bool>("_eigen"));
49 use_eigenvalue =
50 (exparams.isParamValid("_use_eigen_value") && exparams.get<bool>("_use_eigen_value"));
51 }
52
53 _app.useNonlinear() = use_nonlinear;
54 _app.useEigenvalue() = use_eigenvalue;
55 return;
56 }
57
58 // act only if we have mesh
59 if (_mesh.get() != NULL)
60 {
61 // Make sure the problem hasn't already been created elsewhere
62 if (!_problem)
63 {
64 std::string type;
65 if (_app.useEigenvalue())
66 type = "EigenProblem";
67 else
68 type = "FEProblem";
69 auto params = _factory.getValidParams(type);
70
71 // apply global parameters
72 _app.builder().extractParams("Problem", params);
73
74 // apply common parameters of the object held by CreateProblemAction to honor user inputs in
75 // [Problem]
76 auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
77 if (p)
78 params.applyParameters(p->getObjectParams());
79
80 params.set<MooseMesh *>("mesh") = _mesh.get();
81 params.set<bool>("use_nonlinear") = _app.useNonlinear();
82 if (_pars.isParamValid("_solve"))
83 params.set<bool>("solve") = getParam<bool>("_solve");
84
85 _problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
86 }
87 else
88 {
89 // otherwise perform necessary sanity checks
90 if (_app.useEigenvalue() && !(std::dynamic_pointer_cast<EigenProblem>(_problem)))
91 mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
92 "eigen executioner");
93 }
94 }
95}
registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default")
const T * getActionByTask(const std::string &task)
Retrieve the action on a specific task with its type.
Base class for actions.
Definition Action.h:38
std::shared_ptr< MooseMesh > & _mesh
Definition Action.h:174
static InputParameters validParams()
Definition Action.C:26
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
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
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.
static InputParameters validParams()
CreateProblemDefaultAction(const InputParameters &parameters)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
bool & useNonlinear()
Returns a writable Boolean indicating whether this app will use a Nonlinear or Eigen System.
Definition MooseApp.h:397
Moose::Builder & builder()
Returns a writable reference to the builder.
Definition MooseApp.h:226
bool & useEigenvalue()
Returns a writable Boolean indicating whether this app will use an eigenvalue executioner.
Definition MooseApp.h:402
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
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
const InputParameters & _pars
The object's parameters.
Definition MooseBase.h:384
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
void extractParams(const hit::Node *const section_node, InputParameters &p)
Attempt to extract values from input starting with the section in input in section_node based on the ...
Definition Builder.C:664
Factory & _factory
The Factory associated with the MooseApp.