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 29484191 : MooseObject::validParams() 26 : { 27 29484191 : InputParameters params = ParallelParamObject::validParams(); 28 117936764 : params.addParam<bool>("enable", true, "Set the enabled status of the MooseObject."); 29 117936764 : params.addParam<std::vector<std::string>>( 30 : "control_tags", 31 : "Adds user-defined labels for accessing object parameters via control logic."); 32 88452573 : params.addParamNamesToGroup("enable control_tags", "Advanced"); 33 58968382 : params.addPrivateParam<FEProblem *>("_fe_problem", nullptr); 34 58968382 : params.addPrivateParam<FEProblemBase *>("_fe_problem_base", nullptr); 35 58968382 : params.addPrivateParam<EigenProblem *>("_eigen_problem", nullptr); 36 58968382 : params.addPrivateParam<SubProblem *>("_subproblem", nullptr); 37 58968382 : params.addPrivateParam<SystemBase *>("_sys", nullptr); 38 58968382 : params.addPrivateParam<SystemBase *>("_nl_sys", nullptr); 39 88452573 : params.addPrivateParam<TransientBase *>("_executioner", nullptr); 40 29484191 : params.addPrivateParam<THREAD_ID>("_tid"); 41 58968382 : params.addPrivateParam<bool>("_residual_object", false); 42 29484191 : return params; 43 0 : } 44 : 45 2438473 : MooseObject::MooseObject(const InputParameters & parameters) 46 4876946 : : ParallelParamObject(parameters), _enabled(getParam<bool>("enable")) 47 : { 48 2438473 : if (Registry::isRegisteredObj(type()) && _app.getFactory().currentlyConstructing() != ¶meters) 49 0 : mooseError( 50 : "This registered object was not constructed using the Factory, which is not supported."); 51 2438473 : } 52 : 53 : namespace 54 : { 55 : const std::string not_shared_error = 56 : "MooseObject::getSharedPtr() must only be called for objects that are managed by a " 57 : "shared pointer. Make sure this object is build using Factory::create(...)."; 58 : } 59 : 60 : std::shared_ptr<MooseObject> 61 1179 : MooseObject::getSharedPtr() 62 : { 63 : try 64 : { 65 2356 : return shared_from_this(); 66 : } 67 2 : catch (std::bad_weak_ptr &) 68 : { 69 2 : mooseError(not_shared_error); 70 2 : } 71 : } 72 : 73 : std::shared_ptr<const MooseObject> 74 0 : MooseObject::getSharedPtr() const 75 : { 76 : try 77 : { 78 0 : return shared_from_this(); 79 : } 80 0 : catch (std::bad_weak_ptr &) 81 : { 82 0 : mooseError(not_shared_error); 83 0 : } 84 : }