www.mooseframework.org
UserObjectInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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"
16 
19 {
20  return emptyInputParameters();
21 }
22 
24  : _uoi_moose_object(*moose_object),
25  _uoi_feproblem(*_uoi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
26  "_fe_problem_base")),
27  _uoi_tid(_uoi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
28  ? _uoi_moose_object.parameters().get<THREAD_ID>("_tid")
29  : 0)
30 {
31 }
32 
33 UserObjectName
34 UserObjectInterface::getUserObjectName(const std::string & param_name) const
35 {
36  const auto & params = _uoi_moose_object.parameters();
37 
38  if (!params.isParamValid(param_name))
39  _uoi_moose_object.mooseError("Failed to get a parameter with the name \"",
40  param_name,
41  "\" when getting a UserObjectName.",
42  "\n\nKnown parameters:\n",
44 
45  // Other interfaces will use this interface (PostprocessorInterface, VectorPostprocessorInterface)
46  // to grab UOs with a specialized name, so we need to check them all
47  UserObjectName name;
48  if (params.isType<UserObjectName>(param_name))
49  name = params.get<UserObjectName>(param_name);
50  else if (params.isType<PostprocessorName>(param_name))
51  name = params.get<PostprocessorName>(param_name);
52  else if (params.isType<VectorPostprocessorName>(param_name))
53  name = params.get<VectorPostprocessorName>(param_name);
54  else if (params.isType<std::string>(param_name))
55  name = params.get<std::string>(param_name);
56  else
58  param_name,
59  "Parameter of type \"",
60  params.type(param_name),
61  "\" is not an expected type for getting the name of a UserObject.");
62 
63  return name;
64 }
65 
66 bool
67 UserObjectInterface::hasUserObject(const std::string & param_name) const
68 {
69  return hasUserObjectByName(getUserObjectName(param_name));
70 }
71 
72 bool
73 UserObjectInterface::hasUserObjectByName(const UserObjectName & object_name) const
74 {
75  return _uoi_feproblem.hasUserObject(object_name);
76 }
77 
78 const UserObject &
79 UserObjectInterface::getUserObjectBase(const std::string & param_name,
80  const bool is_dependency) const
81 {
82  const auto object_name = getUserObjectName(param_name);
83  if (!hasUserObjectByName(object_name))
85  param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
86 
87  return getUserObjectBaseByName(object_name, is_dependency);
88 }
89 
90 const UserObject &
91 UserObjectInterface::getUserObjectBaseByName(const UserObjectName & object_name,
92  const bool is_dependency) const
93 {
94  if (!hasUserObjectByName(object_name))
96  "The requested UserObject with the name \"", object_name, "\" was not found.");
97 
98  const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0);
99  if (is_dependency)
100  addUserObjectDependencyHelper(uo_base_tid0);
101 
102  const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
103  return _uoi_feproblem.getUserObjectBase(object_name, tid);
104 }
105 
106 const std::string &
108 {
109  return uo.type();
110 }
111 
112 const std::string &
114 {
115  return uo.name();
116 }
std::string name(const ElemQuality q)
UserObjectName getUserObjectName(const std::string &param_name) const
const MooseObject & _uoi_moose_object
Moose object using the interface.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
static InputParameters validParams()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
InputParameters emptyInputParameters()
const FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:50
const THREAD_ID _uoi_tid
Thread ID.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const UserObject & getUserObjectBase(const std::string &param_name, bool is_dependency=true) const
Get an user object with a given parameter param_name.
const std::string & userObjectType(const UserObject &uo) const
Gets a UserObject&#39;s type; avoids including UserObject.h in the UserObjectInterface.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
const UserObject & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
virtual void addUserObjectDependencyHelper(const UserObject &) const
Helper for deriving classes to override to add dependencies when a UserObject is requested.
bool hasUserObjectByName(const UserObjectName &object_name) const
bool hasUserObject(const std::string &param_name) const
Base class for user-specific data.
Definition: UserObject.h:39
const std::string & userObjectName(const UserObject &uo) const
Gets a UserObject&#39;s name; avoids including UserObject.h in the UserObjectInterface.
unsigned int THREAD_ID
Definition: MooseTypes.h:198
UserObjectInterface(const MooseObject *moose_object)