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 UserObjectBasegetUserObjectBase (const std::string &param_name, bool is_dependency=true) const
 Get an user object with a given parameter param_name. More...
 
const UserObjectBasegetUserObjectBaseByName (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 UserObjectBase &) const
 Helper for deriving classes to override to add dependencies when a UserObject is requested. More...
 

Private Member Functions

const UserObjectBasegetUserObjectFromFEProblem (const UserObjectName &object_name, const THREAD_ID tid=0) const
 Go directly to the FEProblem for the requested object_name for thread ID tid. More...
 
template<class T >
const T & castUserObject (const UserObjectBase &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 UserObjectBase &uo) const
 Gets a UserObject's type; avoids including UserObject.h in the UserObjectInterface. More...
 
const std::string & userObjectName (const UserObjectBase &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:237

◆ 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 UserObjectBase ) const
inlineprotectedvirtual

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

Reimplemented in UserObjectBase, AuxKernelBase, and InitialConditionBase.

Definition at line 111 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().

111 {}

◆ castUserObject()

template<class T >
const T & UserObjectInterface::castUserObject ( const UserObjectBase 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 151 of file UserObjectInterface.h.

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

173 {
174  return castUserObject<T>(getUserObjectBase(param_name, is_dependency), param_name);
175 }
const UserObjectBase & getUserObjectBase(const std::string &param_name, bool is_dependency=true) const
Get an user object with a given parameter param_name.

◆ getUserObjectBase()

const UserObjectBase & 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 115 of file UserObjectInterface.C.

Referenced by getUserObject().

117 {
118  const auto object_name = getUserObjectName(param_name);
119  if (!hasUserObjectByName(object_name))
121  param_name, "The requested UserObject with the name \"", object_name, "\" was not found.");
122 
123  return getUserObjectBaseByName(object_name, is_dependency);
124 }
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:467
const MooseObject & _uoi_moose_object
Moose object using the interface.
const UserObjectBase & 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 UserObjectBase & 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 127 of file UserObjectInterface.C.

Referenced by AuxKernelBase::addPostprocessorDependencyHelper(), AuxKernelBase::addVectorPostprocessorDependencyHelper(), FunctorAux::FunctorAux(), UserObjectBase::getDependObjects(), getUserObjectBase(), and getUserObjectByName().

129 {
130  if (!hasUserObjectByName(object_name))
132  "The requested UserObject with the name \"", object_name, "\" was not found.");
133 
134  const auto & uo_base_tid0 = getUserObjectFromFEProblem(object_name);
135  if (is_dependency)
136  addUserObjectDependencyHelper(uo_base_tid0);
137 
138  const THREAD_ID tid = uo_base_tid0.needThreadedCopy() ? _uoi_tid : 0;
139  return getUserObjectFromFEProblem(object_name, tid);
140 }
const MooseObject & _uoi_moose_object
Moose object using the interface.
virtual void addUserObjectDependencyHelper(const UserObjectBase &) const
Helper for deriving classes to override to add dependencies when a UserObject is requested.
const THREAD_ID _uoi_tid
Thread ID.
const UserObjectBase & getUserObjectFromFEProblem(const UserObjectName &object_name, const THREAD_ID tid=0) const
Go directly to the FEProblem for the requested object_name for thread ID tid.
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:281
bool hasUserObjectByName(const UserObjectName &object_name) const
unsigned int THREAD_ID
Definition: MooseTypes.h:237

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

181 {
182  return castUserObject<T>(getUserObjectBaseByName(object_name, is_dependency));
183 }
const UserObjectBase & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.

◆ getUserObjectFromFEProblem()

const UserObjectBase & UserObjectInterface::getUserObjectFromFEProblem ( const UserObjectName &  object_name,
const THREAD_ID  tid = 0 
) const
private

Go directly to the FEProblem for the requested object_name for thread ID tid.

Definition at line 96 of file UserObjectInterface.C.

Referenced by getUserObjectBaseByName(), and hasUserObjectByName().

98 {
99  const UserObjectBase * uo = nullptr;
100 
101  if (_uoi_feproblem.hasUserObject(object_name))
102  uo = &_uoi_feproblem.getUserObjectBase(object_name, tid);
103 
104 #ifdef MOOSE_KOKKOS_ENABLED
105  if (_uoi_feproblem.hasKokkosUserObject(object_name))
107 #endif
108 
109  mooseAssert(uo, "getUserObjectFromFEProblem() could not find user object");
110 
111  return *uo;
112 }
bool hasKokkosUserObject(const std::string &name) const
Check if there if a Kokkos user object of given name.
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.
const T & getKokkosUserObject(const std::string &name) const
Get the Kokkos user object by its name.
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:467
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:281

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

188 {
189  return hasUserObjectByName<T>(getUserObjectName(param_name));
190 }
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 FunctorAux::FunctorAux(), getUserObjectBase(), getUserObjectBaseByName(), hasUserObject(), and hasUserObjectByName().

85 {
86  bool flag = _uoi_feproblem.hasUserObject(object_name);
87 
88 #ifdef MOOSE_KOKKOS_ENABLED
89  flag = flag || _uoi_feproblem.hasKokkosUserObject(object_name);
90 #endif
91 
92  return flag;
93 }
bool hasKokkosUserObject(const std::string &name) const
Check if there if a Kokkos user object of given name.
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 194 of file UserObjectInterface.h.

195 {
196  if (!hasUserObjectByName(object_name))
197  return false;
198  return dynamic_cast<const T *>(&getUserObjectFromFEProblem(object_name));
199 }
const UserObjectBase & getUserObjectFromFEProblem(const UserObjectName &object_name, const THREAD_ID tid=0) const
Go directly to the FEProblem for the requested object_name for thread ID tid.
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 155 of file UserObjectInterface.C.

Referenced by castUserObject().

156 {
157  if (_uoi_moose_object.parameters().isParamValid(param_name))
158  _uoi_moose_object.paramError(param_name, oss.str());
159  else
160  _uoi_moose_object.mooseError(oss.str());
161 }
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:467
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:281
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 UserObjectBase uo) const
private

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

Definition at line 149 of file UserObjectInterface.C.

Referenced by castUserObject().

150 {
151  return uo.name();
152 }
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103

◆ userObjectType()

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

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

Definition at line 143 of file UserObjectInterface.C.

Referenced by castUserObject().

144 {
145  return uo.type();
146 }
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 143 of file UserObjectInterface.h.

Referenced by getUserObjectFromFEProblem(), and hasUserObjectByName().

◆ _uoi_moose_object

const MooseObject& UserObjectInterface::_uoi_moose_object
private

Moose object using the interface.

Definition at line 140 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 146 of file UserObjectInterface.h.

Referenced by getUserObjectBaseByName().


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