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)
 
 UserObjectInterface (const UserObjectInterface &object, const Moose::Kokkos::FunctorCopy &key)
 Special constructor used for Kokkos functor copy during parallel dispatch. More...
 
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() [1/2]

UserObjectInterface::UserObjectInterface ( const MooseObject moose_object)

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.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
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.
unsigned int THREAD_ID
Definition: MooseTypes.h:209

◆ UserObjectInterface() [2/2]

UserObjectInterface::UserObjectInterface ( const UserObjectInterface object,
const Moose::Kokkos::FunctorCopy key 
)

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 35 of file UserObjectInterface.C.

39  _uoi_tid(object._uoi_tid)
40 {
41 }
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.

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

Referenced by getUserObjectBaseByName().

111 {}

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

151 {
152  const T * uo = dynamic_cast<const T *>(&uo_base);
153 
154  if (!uo)
155  {
156  std::stringstream oss;
157  oss << "The provided UserObject \"" << userObjectName(uo_base) << "\" of type "
158  << userObjectType(uo_base)
159  << " is not derived from the required type.\n\nThe UserObject must derive from "
160  << MooseUtils::prettyCppType<T>() << ".";
161 
162  mooseObjectError(param_name, oss);
163  }
164 
165  return *uo;
166 }
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 170 of file UserObjectInterface.h.

171 {
172  return castUserObject<T>(getUserObjectBase(param_name, is_dependency), param_name);
173 }
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 96 of file UserObjectInterface.C.

Referenced by getUserObject().

98 {
99  const auto object_name = getUserObjectName(param_name);
100  if (!hasUserObjectByName(object_name))
102  param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
103 
104  return getUserObjectBaseByName(object_name, is_dependency);
105 }
UserObjectName getUserObjectName(const std::string &param_name) const
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 ...
Definition: MooseBase.h:439
const MooseObject & _uoi_moose_object
Moose object using the interface.
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 108 of file UserObjectInterface.C.

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

110 {
111  if (!hasUserObjectByName(object_name))
113  "The requested UserObject with the name \"", object_name, "\" was not found.");
114 
115  const auto & uo_base_tid0 = _uoi_feproblem.getUserObjectBase(object_name, /* tid = */ 0);
116  if (is_dependency)
117  addUserObjectDependencyHelper(uo_base_tid0);
118 
119  const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
120  return _uoi_feproblem.getUserObjectBase(object_name, tid);
121 }
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 and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
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 177 of file UserObjectInterface.h.

179 {
180  return castUserObject<T>(getUserObjectBaseByName(object_name, is_dependency));
181 }
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 90 of file UserObjectInterface.C.

Referenced by hasUserObjectByName().

91 {
92  return _uoi_feproblem.getUserObjectBase(object_name);
93 }
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 45 of file UserObjectInterface.C.

Referenced by getUserObjectBase(), and hasUserObject().

46 {
47  const auto & params = _uoi_moose_object.parameters();
48 
49  if (!params.isParamValid(param_name))
50  _uoi_moose_object.mooseError("Failed to get a parameter with the name \"",
51  param_name,
52  "\" when getting a UserObjectName.",
53  "\n\nKnown parameters:\n",
55 
56  // Other interfaces will use this interface (PostprocessorInterface, VectorPostprocessorInterface)
57  // to grab UOs with a specialized name, so we need to check them all
58  UserObjectName name;
59  if (params.isType<UserObjectName>(param_name))
60  name = params.get<UserObjectName>(param_name);
61  else if (params.isType<PostprocessorName>(param_name))
62  name = params.get<PostprocessorName>(param_name);
63  else if (params.isType<VectorPostprocessorName>(param_name))
64  name = params.get<VectorPostprocessorName>(param_name);
65  else if (params.isType<std::string>(param_name))
66  name = params.get<std::string>(param_name);
67  else
69  param_name,
70  "Parameter of type \"",
71  params.type(param_name),
72  "\" is not an expected type for getting the name of a UserObject.");
73 
74  return name;
75 }
std::string name(const ElemQuality q)
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 ...
Definition: MooseBase.h:439
const MooseObject & _uoi_moose_object
Moose object using the interface.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271

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

79 {
80  return hasUserObjectByName(getUserObjectName(param_name));
81 }
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 185 of file UserObjectInterface.h.

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

◆ hasUserObjectByName() [1/2]

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

Definition at line 84 of file UserObjectInterface.C.

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

85 {
86  return _uoi_feproblem.hasUserObject(object_name);
87 }
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 192 of file UserObjectInterface.h.

193 {
194  if (!hasUserObjectByName(object_name))
195  return false;
196  return dynamic_cast<const T *>(&getUserObjectFromFEProblem(object_name));
197 }
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 136 of file UserObjectInterface.C.

Referenced by castUserObject().

137 {
138  if (_uoi_moose_object.parameters().isParamValid(param_name))
139  _uoi_moose_object.paramError(param_name, oss.str());
140  else
141  _uoi_moose_object.mooseError(oss.str());
142 }
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 ...
Definition: MooseBase.h:439
const MooseObject & _uoi_moose_object
Moose object using the interface.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
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 130 of file UserObjectInterface.C.

Referenced by castUserObject().

131 {
132  return uo.name();
133 }
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103

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

Referenced by castUserObject().

125 {
126  return uo.type();
127 }
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93

◆ 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 141 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 138 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 144 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().


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