https://mooseframework.inl.gov
MooseObject.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 
10 // MOOSE includes
11 #include "MooseObject.h"
12 #include "MooseApp.h"
13 #include "MooseUtils.h"
14 #include "Factory.h"
15 
16 class FEProblem;
17 class FEProblemBase;
18 class EigenProblem;
19 class SubProblem;
20 class SystemBase;
21 class AuxiliarySystem;
22 class TransientBase;
23 
26 {
28  params.addParam<bool>("enable", true, "Set the enabled status of the MooseObject.");
29  params.addParam<std::vector<std::string>>(
30  "control_tags",
31  "Adds user-defined labels for accessing object parameters via control logic.");
32  params.addParamNamesToGroup("enable control_tags", "Advanced");
33  params.addPrivateParam<std::string>("_type"); // The name of the class being built
34  params.addPrivateParam<std::string>("_object_name"); // The name passed to Factory::create
35  params.addPrivateParam<std::string>("_unique_name"); // The unique name generated in the warehouse
36  params.addPrivateParam<FEProblem *>("_fe_problem", nullptr);
37  params.addPrivateParam<FEProblemBase *>("_fe_problem_base", nullptr);
38  params.addPrivateParam<EigenProblem *>("_eigen_problem", nullptr);
39  params.addPrivateParam<SubProblem *>("_subproblem", nullptr);
40  params.addPrivateParam<SystemBase *>("_sys", nullptr);
41  params.addPrivateParam<SystemBase *>("_nl_sys", nullptr);
42  params.addPrivateParam<TransientBase *>("_executioner", nullptr);
43  params.addPrivateParam<THREAD_ID>("_tid");
44  params.addPrivateParam<bool>("_residual_object", false);
45  return params;
46 }
47 
49  : ParallelParamObject(parameters.get<std::string>("_type"),
50  parameters.get<std::string>("_object_name"),
51  *parameters.getCheckedPointerParam<MooseApp *>("_moose_app"),
52  parameters),
53  _enabled(getParam<bool>("enable"))
54 {
56  mooseError(
57  "This registered object was not constructed using the Factory, which is not supported.");
58 }
59 
60 namespace
61 {
62 const std::string not_shared_error =
63  "MooseObject::getSharedPtr() must only be called for objects that are managed by a "
64  "shared pointer. Make sure this object is build using Factory::create(...).";
65 }
66 
67 std::shared_ptr<MooseObject>
69 {
70  try
71  {
72  return shared_from_this();
73  }
74  catch (std::bad_weak_ptr &)
75  {
76  mooseError(not_shared_error);
77  }
78 }
79 
80 std::shared_ptr<const MooseObject>
82 {
83  try
84  {
85  return shared_from_this();
86  }
87  catch (std::bad_weak_ptr &)
88  {
89  mooseError(not_shared_error);
90  }
91 }
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...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:20
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
MooseObject(const InputParameters &parameters)
Definition: MooseObject.C:48
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< MooseObject > getSharedPtr()
Get another shared pointer to this object that has the same ownership group.
Definition: MooseObject.C:68
Base class for a system (of equations)
Definition: SystemBase.h:84
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
InputParameters emptyInputParameters()
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:434
const bool & _enabled
Reference to the "enable" InputParameters, used by Controls for toggling on/off MooseObjects.
Definition: MooseObject.h:51
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Definition: TransientBase.h:26
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
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...
static bool isRegisteredObj(const std::string &name)
Definition: Registry.h:237
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
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...
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
static InputParameters validParams()
Definition: MooseObject.C:25
Base class shared by both Action and MooseObject.
A system that holds auxiliary variables.
const InputParameters * currentlyConstructing() const
Definition: Factory.C:254
unsigned int THREAD_ID
Definition: MooseTypes.h:209
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...