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