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 9474094 : MooseObject::validParams() 26 : { 27 9474094 : InputParameters params = ParallelParamObject::validParams(); 28 37896376 : params.addParam<bool>("enable", true, "Set the enabled status of the MooseObject."); 29 37896376 : params.addParam<std::vector<std::string>>( 30 : "control_tags", 31 : "Adds user-defined labels for accessing object parameters via control logic."); 32 28422282 : params.addParamNamesToGroup("enable control_tags", "Advanced"); 33 18948188 : params.addPrivateParam<FEProblem *>("_fe_problem", nullptr); 34 18948188 : params.addPrivateParam<FEProblemBase *>("_fe_problem_base", nullptr); 35 18948188 : params.addPrivateParam<EigenProblem *>("_eigen_problem", nullptr); 36 18948188 : params.addPrivateParam<SubProblem *>("_subproblem", nullptr); 37 18948188 : params.addPrivateParam<SystemBase *>("_sys", nullptr); 38 18948188 : params.addPrivateParam<SystemBase *>("_nl_sys", nullptr); 39 28422282 : params.addPrivateParam<TransientBase *>("_executioner", nullptr); 40 9474094 : params.addPrivateParam<THREAD_ID>("_tid"); 41 18948188 : params.addPrivateParam<bool>("_residual_object", false); 42 9474094 : return params; 43 0 : } 44 : 45 2371456 : MooseObject::MooseObject(const InputParameters & parameters) 46 : : ParallelParamObject(parameters), 47 : SolutionInvalidInterface(this, parameters), 48 4742912 : _enabled(getParam<bool>("enable")) 49 : { 50 2371456 : 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 2371456 : } 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 534450 : MooseObject::MooseObject(const MooseObject & object, const Moose::Kokkos::FunctorCopy & key) 64 534450 : : ParallelParamObject(object), SolutionInvalidInterface(object, key), _enabled(object._enabled) 65 : { 66 534450 : } 67 : #endif 68 : 69 : std::shared_ptr<MooseObject> 70 1576 : MooseObject::getSharedPtr() 71 : { 72 : try 73 : { 74 3148 : 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 : }