Line data Source code
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 : 24 : InputParameters 25 28797391 : MooseObject::validParams() 26 : { 27 28797391 : InputParameters params = emptyInputParameters(); 28 28797391 : params.addParam<bool>("enable", true, "Set the enabled status of the MooseObject."); 29 28797391 : params.addParam<std::vector<std::string>>( 30 : "control_tags", 31 : "Adds user-defined labels for accessing object parameters via control logic."); 32 28797391 : params.addParamNamesToGroup("enable control_tags", "Advanced"); 33 28797391 : params.addPrivateParam<std::string>("_type"); // The name of the class being built 34 28797391 : params.addPrivateParam<std::string>("_object_name"); // The name passed to Factory::create 35 28797391 : params.addPrivateParam<std::string>("_unique_name"); // The unique name generated in the warehouse 36 28797391 : params.addPrivateParam<FEProblem *>("_fe_problem", nullptr); 37 28797391 : params.addPrivateParam<FEProblemBase *>("_fe_problem_base", nullptr); 38 28797391 : params.addPrivateParam<EigenProblem *>("_eigen_problem", nullptr); 39 28797391 : params.addPrivateParam<SubProblem *>("_subproblem", nullptr); 40 28797391 : params.addPrivateParam<SystemBase *>("_sys", nullptr); 41 28797391 : params.addPrivateParam<SystemBase *>("_nl_sys", nullptr); 42 28797391 : params.addPrivateParam<TransientBase *>("_executioner", nullptr); 43 28797391 : params.addPrivateParam<THREAD_ID>("_tid"); 44 28797391 : params.addPrivateParam<bool>("_residual_object", false); 45 28797391 : return params; 46 0 : } 47 : 48 2204807 : MooseObject::MooseObject(const InputParameters & parameters) 49 2204807 : : ParallelParamObject(parameters.get<std::string>("_type"), 50 2204807 : parameters.get<std::string>("_object_name"), 51 4409614 : *parameters.getCheckedPointerParam<MooseApp *>("_moose_app"), 52 : parameters), 53 6614421 : _enabled(getParam<bool>("enable")) 54 : { 55 2204807 : if (Registry::isRegisteredObj(type()) && _app.getFactory().currentlyConstructing() != ¶meters) 56 0 : mooseError( 57 : "This registered object was not constructed using the Factory, which is not supported."); 58 2204807 : } 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> 68 440 : MooseObject::getSharedPtr() 69 : { 70 : try 71 : { 72 878 : return shared_from_this(); 73 : } 74 2 : catch (std::bad_weak_ptr &) 75 : { 76 2 : mooseError(not_shared_error); 77 2 : } 78 : } 79 : 80 : std::shared_ptr<const MooseObject> 81 0 : MooseObject::getSharedPtr() const 82 : { 83 : try 84 : { 85 0 : return shared_from_this(); 86 : } 87 0 : catch (std::bad_weak_ptr &) 88 : { 89 0 : mooseError(not_shared_error); 90 0 : } 91 : }