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 : #include "UserObjectInterface.h" 11 : 12 : // MOOSE includes 13 : #include "FEProblemBase.h" 14 : #include "DiscreteElementUserObject.h" 15 : #include "ThreadedGeneralUserObject.h" 16 : #include "MooseObject.h" 17 : 18 : InputParameters 19 57690 : UserObjectInterface::validParams() 20 : { 21 57690 : return emptyInputParameters(); 22 : } 23 : 24 512410 : UserObjectInterface::UserObjectInterface(const MooseObject * moose_object) 25 512410 : : _uoi_moose_object(*moose_object), 26 512410 : _uoi_feproblem(*_uoi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>( 27 : "_fe_problem_base")), 28 512410 : _uoi_tid(_uoi_moose_object.parameters().have_parameter<THREAD_ID>("_tid") 29 512410 : ? _uoi_moose_object.parameters().get<THREAD_ID>("_tid") 30 512410 : : 0) 31 : { 32 512410 : } 33 : 34 : UserObjectName 35 6668 : UserObjectInterface::getUserObjectName(const std::string & param_name) const 36 : { 37 6668 : const auto & params = _uoi_moose_object.parameters(); 38 : 39 6668 : if (!params.isParamValid(param_name)) 40 4 : _uoi_moose_object.mooseError("Failed to get a parameter with the name \"", 41 : param_name, 42 : "\" when getting a UserObjectName.", 43 : "\n\nKnown parameters:\n", 44 4 : _uoi_moose_object.parameters()); 45 : 46 : // Other interfaces will use this interface (PostprocessorInterface, VectorPostprocessorInterface) 47 : // to grab UOs with a specialized name, so we need to check them all 48 6664 : UserObjectName name; 49 6664 : if (params.isType<UserObjectName>(param_name)) 50 6660 : name = params.get<UserObjectName>(param_name); 51 4 : else if (params.isType<PostprocessorName>(param_name)) 52 0 : name = params.get<PostprocessorName>(param_name); 53 4 : else if (params.isType<VectorPostprocessorName>(param_name)) 54 0 : name = params.get<VectorPostprocessorName>(param_name); 55 4 : else if (params.isType<std::string>(param_name)) 56 0 : name = params.get<std::string>(param_name); 57 : else 58 4 : _uoi_moose_object.paramError( 59 : param_name, 60 : "Parameter of type \"", 61 4 : params.type(param_name), 62 : "\" is not an expected type for getting the name of a UserObject."); 63 : 64 6660 : return name; 65 0 : } 66 : 67 : bool 68 20 : UserObjectInterface::hasUserObject(const std::string & param_name) const 69 : { 70 20 : return hasUserObjectByName(getUserObjectName(param_name)); 71 : } 72 : 73 : bool 74 13911 : UserObjectInterface::hasUserObjectByName(const UserObjectName & object_name) const 75 : { 76 13911 : return _uoi_feproblem.hasUserObject(object_name); 77 : } 78 : 79 : const UserObject & 80 74 : UserObjectInterface::getUserObjectFromFEProblem(const UserObjectName & object_name) const 81 : { 82 74 : return _uoi_feproblem.getUserObjectBase(object_name); 83 : } 84 : 85 : const UserObject & 86 6618 : UserObjectInterface::getUserObjectBase(const std::string & param_name, 87 : const bool is_dependency) const 88 : { 89 6618 : const auto object_name = getUserObjectName(param_name); 90 6610 : if (!hasUserObjectByName(object_name)) 91 4 : _uoi_moose_object.paramError( 92 : param_name, "The requested UserObject with the name \"", object_name, "\" was not found."); 93 : 94 13212 : return getUserObjectBaseByName(object_name, is_dependency); 95 6606 : } 96 : 97 : const UserObject & 98 7187 : UserObjectInterface::getUserObjectBaseByName(const UserObjectName & object_name, 99 : const bool is_dependency) const 100 : { 101 7187 : if (!hasUserObjectByName(object_name)) 102 4 : _uoi_moose_object.mooseError( 103 : "The requested UserObject with the name \"", object_name, "\" was not found."); 104 : 105 7183 : const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0); 106 7183 : if (is_dependency) 107 7146 : addUserObjectDependencyHelper(uo_base_tid0); 108 : 109 7183 : const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0; 110 7183 : return _uoi_feproblem.getUserObjectBase(object_name, tid); 111 : } 112 : 113 : const std::string & 114 8 : UserObjectInterface::userObjectType(const UserObject & uo) const 115 : { 116 8 : return uo.type(); 117 : } 118 : 119 : const std::string & 120 8 : UserObjectInterface::userObjectName(const UserObject & uo) const 121 : { 122 8 : return uo.name(); 123 : } 124 : 125 : void 126 8 : UserObjectInterface::mooseObjectError(const std::string & param_name, std::stringstream & oss) const 127 : { 128 8 : if (_uoi_moose_object.parameters().isParamValid(param_name)) 129 4 : _uoi_moose_object.paramError(param_name, oss.str()); 130 : else 131 4 : _uoi_moose_object.mooseError(oss.str()); 132 : }