www.mooseframework.org
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

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 reqested type. 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 22 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 23 of file UserObjectInterface.C.

24  : _uoi_moose_object(*moose_object),
26  "_fe_problem_base")),
29  : 0)
30 {
31 }
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:198

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 108 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().

108 {}

◆ 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 reqested 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 136 of file UserObjectInterface.h.

138 {
139  const T * uo = dynamic_cast<const T *>(&uo_base);
140 
141  if (!uo)
142  {
143  std::stringstream oss;
144  oss << "The provided UserObject \"" << userObjectName(uo_base) << "\" of type "
145  << userObjectType(uo_base)
146  << " is not derived from the required type.\n\nThe UserObject must derive from "
147  << MooseUtils::prettyCppType<T>() << ".";
148 
149  if (_uoi_moose_object.parameters().isParamValid(param_name))
150  _uoi_moose_object.paramError(param_name, oss.str());
151  else
152  _uoi_moose_object.mooseError(oss.str());
153  }
154 
155  return *uo;
156 }
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 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 std::string & userObjectName(const UserObject &uo) const
Gets a UserObject&#39;s name; avoids including UserObject.h in the UserObjectInterface.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ 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 160 of file UserObjectInterface.h.

161 {
162  return castUserObject<T>(getUserObjectBase(param_name, is_dependency), param_name);
163 }
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 79 of file UserObjectInterface.C.

Referenced by getUserObject().

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 }
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 91 of file UserObjectInterface.C.

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

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 }
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:198

◆ 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 167 of file UserObjectInterface.h.

169 {
170  return castUserObject<T>(getUserObjectBaseByName(object_name, is_dependency));
171 }
const UserObject & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_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 34 of file UserObjectInterface.C.

Referenced by getUserObjectBase(), and hasUserObject().

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 }
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 67 of file UserObjectInterface.C.

68 {
69  return hasUserObjectByName(getUserObjectName(param_name));
70 }
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 175 of file UserObjectInterface.h.

176 {
177  return hasUserObjectByName<T>(getUserObjectName(param_name));
178 }
UserObjectName getUserObjectName(const std::string &param_name) const

◆ hasUserObjectByName() [1/2]

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

Definition at line 73 of file UserObjectInterface.C.

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

74 {
75  return _uoi_feproblem.hasUserObject(object_name);
76 }
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 182 of file UserObjectInterface.h.

183 {
184  if (!hasUserObjectByName(object_name))
185  return false;
186  return dynamic_cast<const T *>(&_uoi_feproblem.getUserObjectBase(object_name));
187 }
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.
bool hasUserObjectByName(const UserObjectName &object_name) const

◆ 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 113 of file UserObjectInterface.C.

Referenced by castUserObject().

114 {
115  return uo.name();
116 }
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56

◆ 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 107 of file UserObjectInterface.C.

Referenced by castUserObject().

108 {
109  return uo.type();
110 }
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:50

◆ validParams()

InputParameters UserObjectInterface::validParams ( )
static

Definition at line 18 of file UserObjectInterface.C.

Referenced by FVInterfaceKernel::validParams().

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

Member Data Documentation

◆ _uoi_feproblem

const FEProblemBase& UserObjectInterface::_uoi_feproblem
private

Reference to the FEProblemBase instance.

Definition at line 128 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName(), and hasUserObjectByName().

◆ _uoi_moose_object

const MooseObject& UserObjectInterface::_uoi_moose_object
private

Moose object using the interface.

Definition at line 125 of file UserObjectInterface.h.

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

◆ _uoi_tid

const THREAD_ID UserObjectInterface::_uoi_tid
private

Thread ID.

Definition at line 131 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().


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