https://mooseframework.inl.gov
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
UserObjectInterface Class Reference

Interface for objects that need to use UserObjects. More...

#include <UserObjectInterface.h>

Inheritance diagram for UserObjectInterface:
[legend]

Public Member Functions

 UserObjectInterface (const MooseObject *moose_object)
 
UserObjectName getUserObjectName (const std::string &param_name) const
 
template<class T >
const T & getUserObject (const std::string &param_name, bool is_dependency=true) const
 Get an user object with a given parameter param_name. More...
 
template<class T >
const T & getUserObjectByName (const UserObjectName &object_name, bool is_dependency=true) const
 Get an user object with the name object_name. More...
 
const UserObjectgetUserObjectBase (const std::string &param_name, bool is_dependency=true) const
 Get an user object with a given parameter param_name. More...
 
const UserObjectgetUserObjectBaseByName (const UserObjectName &object_name, bool is_dependency=true) const
 Get an user object with the name object_name. More...
 
bool hasUserObject (const std::string &param_name) const
 
template<class T >
bool hasUserObject (const std::string &param_name) const
 
bool hasUserObjectByName (const UserObjectName &object_name) const
 
template<class T >
bool hasUserObjectByName (const UserObjectName &object_name) const
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual void addUserObjectDependencyHelper (const UserObject &) const
 Helper for deriving classes to override to add dependencies when a UserObject is requested. More...
 

Private Member Functions

const UserObjectgetUserObjectFromFEProblem (const UserObjectName &object_name) const
 Go directly to the FEProblem for the requested UserObject. More...
 
template<class T >
const T & castUserObject (const UserObject &uo_base, const std::string &param_name="") const
 Internal helper that casts the UserObject uo_base to the requested type. More...
 
void mooseObjectError (const std::string &param_name, std::stringstream &oss) const
 emit an error for the given parameter More...
 
const std::string & userObjectType (const UserObject &uo) const
 Gets a UserObject's type; avoids including UserObject.h in the UserObjectInterface. More...
 
const std::string & userObjectName (const UserObject &uo) const
 Gets a UserObject's name; avoids including UserObject.h in the UserObjectInterface. More...
 

Private Attributes

const MooseObject_uoi_moose_object
 Moose object using the interface. More...
 
const FEProblemBase_uoi_feproblem
 Reference to the FEProblemBase instance. More...
 
const THREAD_ID _uoi_tid
 Thread ID. More...
 

Detailed Description

Interface for objects that need to use UserObjects.

Definition at line 24 of file UserObjectInterface.h.

Constructor & Destructor Documentation

◆ UserObjectInterface()

UserObjectInterface::UserObjectInterface ( const MooseObject moose_object)
Parameters
paramsThe parameters used by the object being instantiated. This class needs them so it can get the user object named in the input file, but the object calling getUserObject only needs to use the name on the left hand side of the statement "user_object = user_object_name"

Definition at line 24 of file UserObjectInterface.C.

25  : _uoi_moose_object(*moose_object),
27  "_fe_problem_base")),
30  : 0)
31 {
32 }
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const MooseObject & _uoi_moose_object
Moose object using the interface.
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.
const THREAD_ID _uoi_tid
Thread ID.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
const InputParameters & parameters() const
Get the parameters of the object.
unsigned int THREAD_ID
Definition: MooseTypes.h:209

Member Function Documentation

◆ addUserObjectDependencyHelper()

virtual void UserObjectInterface::addUserObjectDependencyHelper ( const UserObject ) const
inlineprotectedvirtual

Helper for deriving classes to override to add dependencies when a UserObject is requested.

Reimplemented in AuxKernelTempl< ComputeValueType >, AuxKernelTempl< RT >, AuxKernelTempl< RealVectorValue >, AuxKernelTempl< Real >, UserObject, and InitialConditionBase.

Definition at line 110 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().

110 {}

◆ castUserObject()

template<class T >
const T & UserObjectInterface::castUserObject ( const UserObject uo_base,
const std::string &  param_name = "" 
) const
private

Internal helper that casts the UserObject uo_base to the requested type.

Exits with a useful error if the casting failed. If the parameter param_name is provided and is valid, a paramError() will be used instead.

Definition at line 148 of file UserObjectInterface.h.

150 {
151  const T * uo = dynamic_cast<const T *>(&uo_base);
152 
153  if (!uo)
154  {
155  std::stringstream oss;
156  oss << "The provided UserObject \"" << userObjectName(uo_base) << "\" of type "
157  << userObjectType(uo_base)
158  << " is not derived from the required type.\n\nThe UserObject must derive from "
159  << MooseUtils::prettyCppType<T>() << ".";
160 
161  mooseObjectError(param_name, oss);
162  }
163 
164  return *uo;
165 }
void mooseObjectError(const std::string &param_name, std::stringstream &oss) const
emit an error for the given parameter
const std::string & userObjectType(const UserObject &uo) const
Gets a UserObject&#39;s type; avoids including UserObject.h in the UserObjectInterface.
const std::string & userObjectName(const UserObject &uo) const
Gets a UserObject&#39;s name; avoids including UserObject.h in the UserObjectInterface.

◆ getUserObject()

template<class T >
const T & UserObjectInterface::getUserObject ( const std::string &  param_name,
bool  is_dependency = true 
) const

Get an user object with a given parameter param_name.

Parameters
param_nameThe name of the parameter key of the user object to retrieve
is_dependencyWhether the user object we are retrieving should be viewed as a dependency, e.g. whether the retrieved user object should be sorted and executed before this object (if we are a user object)
Returns
The user object with name associated with the parameter param_name

Definition at line 169 of file UserObjectInterface.h.

170 {
171  return castUserObject<T>(getUserObjectBase(param_name, is_dependency), param_name);
172 }
const UserObject & getUserObjectBase(const std::string &param_name, bool is_dependency=true) const
Get an user object with a given parameter param_name.

◆ getUserObjectBase()

const UserObject & UserObjectInterface::getUserObjectBase ( const std::string &  param_name,
bool  is_dependency = true 
) const

Get an user object with a given parameter param_name.

Parameters
param_nameThe name of the parameter key of the user object to retrieve
is_dependencyWhether the user object we are retrieving should be viewed as a dependency, e.g. whether the retrieved user object should be sorted and executed before this object (if we are a user object)
Returns
The user object with name associated with the parameter param_name

Definition at line 86 of file UserObjectInterface.C.

Referenced by getUserObject().

88 {
89  const auto object_name = getUserObjectName(param_name);
90  if (!hasUserObjectByName(object_name))
92  param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
93 
94  return getUserObjectBaseByName(object_name, is_dependency);
95 }
UserObjectName getUserObjectName(const std::string &param_name) const
const MooseObject & _uoi_moose_object
Moose object using the interface.
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 & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
bool hasUserObjectByName(const UserObjectName &object_name) const

◆ getUserObjectBaseByName()

const UserObject & UserObjectInterface::getUserObjectBaseByName ( const UserObjectName &  object_name,
bool  is_dependency = true 
) const

Get an user object with the name object_name.

Parameters
object_nameThe name of the user object to retrieve
is_dependencyWhether the user object we are retrieving should be viewed as a dependency, e.g. whether the retrieved user object should be sorted and executed before this object (if we are a user object)
Returns
The user object with the name object_name

Definition at line 98 of file UserObjectInterface.C.

Referenced by UserObject::getDependObjects(), getUserObjectBase(), and getUserObjectByName().

100 {
101  if (!hasUserObjectByName(object_name))
103  "The requested UserObject with the name \"", object_name, "\" was not found.");
104 
105  const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0);
106  if (is_dependency)
107  addUserObjectDependencyHelper(uo_base_tid0);
108 
109  const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
110  return _uoi_feproblem.getUserObjectBase(object_name, tid);
111 }
const MooseObject & _uoi_moose_object
Moose object using the interface.
const FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.
const THREAD_ID _uoi_tid
Thread ID.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its 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
unsigned int THREAD_ID
Definition: MooseTypes.h:209

◆ getUserObjectByName()

template<class T >
const T & UserObjectInterface::getUserObjectByName ( const UserObjectName &  object_name,
bool  is_dependency = true 
) const

Get an user object with the name object_name.

Parameters
object_nameThe name of the user object to retrieve
is_dependencyWhether the user object we are retrieving should be viewed as a dependency, e.g. whether the retrieved user object should be sorted and executed before this object (if we are a user object)
Returns
The user object with the name object_name

Definition at line 176 of file UserObjectInterface.h.

178 {
179  return castUserObject<T>(getUserObjectBaseByName(object_name, is_dependency));
180 }
const UserObject & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.

◆ getUserObjectFromFEProblem()

const UserObject & UserObjectInterface::getUserObjectFromFEProblem ( const UserObjectName &  object_name) const
private

Go directly to the FEProblem for the requested UserObject.

Definition at line 80 of file UserObjectInterface.C.

Referenced by hasUserObjectByName().

81 {
82  return _uoi_feproblem.getUserObjectBase(object_name);
83 }
const FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.

◆ getUserObjectName()

UserObjectName UserObjectInterface::getUserObjectName ( const std::string &  param_name) const
Returns
The name of the user object associated with the parameter param_name

Definition at line 35 of file UserObjectInterface.C.

Referenced by getUserObjectBase(), and hasUserObject().

36 {
37  const auto & params = _uoi_moose_object.parameters();
38 
39  if (!params.isParamValid(param_name))
40  _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",
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  UserObjectName name;
49  if (params.isType<UserObjectName>(param_name))
50  name = params.get<UserObjectName>(param_name);
51  else if (params.isType<PostprocessorName>(param_name))
52  name = params.get<PostprocessorName>(param_name);
53  else if (params.isType<VectorPostprocessorName>(param_name))
54  name = params.get<VectorPostprocessorName>(param_name);
55  else if (params.isType<std::string>(param_name))
56  name = params.get<std::string>(param_name);
57  else
59  param_name,
60  "Parameter of type \"",
61  params.type(param_name),
62  "\" is not an expected type for getting the name of a UserObject.");
63 
64  return name;
65 }
std::string name(const ElemQuality q)
const MooseObject & _uoi_moose_object
Moose object using the interface.
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 ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.

◆ hasUserObject() [1/2]

bool UserObjectInterface::hasUserObject ( const std::string &  param_name) const
Returns
Whether or not a UserObject exists with the name given by the parameter param_name.

Definition at line 68 of file UserObjectInterface.C.

69 {
70  return hasUserObjectByName(getUserObjectName(param_name));
71 }
UserObjectName getUserObjectName(const std::string &param_name) const
bool hasUserObjectByName(const UserObjectName &object_name) const

◆ hasUserObject() [2/2]

template<class T >
bool UserObjectInterface::hasUserObject ( const std::string &  param_name) const

Definition at line 184 of file UserObjectInterface.h.

185 {
186  return hasUserObjectByName<T>(getUserObjectName(param_name));
187 }
UserObjectName getUserObjectName(const std::string &param_name) const

◆ hasUserObjectByName() [1/2]

bool UserObjectInterface::hasUserObjectByName ( const UserObjectName &  object_name) const

Definition at line 74 of file UserObjectInterface.C.

Referenced by getUserObjectBase(), getUserObjectBaseByName(), hasUserObject(), and hasUserObjectByName().

75 {
76  return _uoi_feproblem.hasUserObject(object_name);
77 }
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
const FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.

◆ hasUserObjectByName() [2/2]

template<class T >
bool UserObjectInterface::hasUserObjectByName ( const UserObjectName &  object_name) const

Definition at line 191 of file UserObjectInterface.h.

192 {
193  if (!hasUserObjectByName(object_name))
194  return false;
195  return dynamic_cast<const T *>(&getUserObjectFromFEProblem(object_name));
196 }
const UserObject & getUserObjectFromFEProblem(const UserObjectName &object_name) const
Go directly to the FEProblem for the requested UserObject.
bool hasUserObjectByName(const UserObjectName &object_name) const

◆ mooseObjectError()

void UserObjectInterface::mooseObjectError ( const std::string &  param_name,
std::stringstream &  oss 
) const
private

emit an error for the given parameter

Definition at line 126 of file UserObjectInterface.C.

Referenced by castUserObject().

127 {
128  if (_uoi_moose_object.parameters().isParamValid(param_name))
129  _uoi_moose_object.paramError(param_name, oss.str());
130  else
131  _uoi_moose_object.mooseError(oss.str());
132 }
const MooseObject & _uoi_moose_object
Moose object using the interface.
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 ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ userObjectName()

const std::string & UserObjectInterface::userObjectName ( const UserObject uo) const
private

Gets a UserObject's name; avoids including UserObject.h in the UserObjectInterface.

Definition at line 120 of file UserObjectInterface.C.

Referenced by castUserObject().

121 {
122  return uo.name();
123 }
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57

◆ userObjectType()

const std::string & UserObjectInterface::userObjectType ( const UserObject uo) const
private

Gets a UserObject's type; avoids including UserObject.h in the UserObjectInterface.

Definition at line 114 of file UserObjectInterface.C.

Referenced by castUserObject().

115 {
116  return uo.type();
117 }
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51

◆ validParams()

InputParameters UserObjectInterface::validParams ( )
static

Definition at line 19 of file UserObjectInterface.C.

Referenced by FVInterfaceKernel::validParams().

20 {
21  return emptyInputParameters();
22 }
InputParameters emptyInputParameters()

Member Data Documentation

◆ _uoi_feproblem

const FEProblemBase& UserObjectInterface::_uoi_feproblem
private

Reference to the FEProblemBase instance.

Definition at line 140 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName(), getUserObjectFromFEProblem(), and hasUserObjectByName().

◆ _uoi_moose_object

const MooseObject& UserObjectInterface::_uoi_moose_object
private

Moose object using the interface.

Definition at line 137 of file UserObjectInterface.h.

Referenced by getUserObjectBase(), getUserObjectBaseByName(), getUserObjectName(), and mooseObjectError().

◆ _uoi_tid

const THREAD_ID UserObjectInterface::_uoi_tid
private

Thread ID.

Definition at line 143 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().


The documentation for this class was generated from the following files: