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

An interface for accessing Moose::Functors. More...

#include <FunctorInterface.h>

Inheritance diagram for FunctorInterface:
[legend]

Public Member Functions

 FunctorInterface (const MooseObject *moose_object)
 

Static Public Member Functions

static InputParameters validParams ()
 
static std::string deduceFunctorName (const std::string &name, const InputParameters &params)
 Helper to look up a functor name through the input parameter keys. More...
 

Protected Member Functions

template<typename T >
const Moose::Functor< T > & getFunctor (const std::string &name)
 Retrieves a functor from the subproblem. More...
 
template<typename T >
const Moose::Functor< T > & getFunctor (const std::string &name, THREAD_ID tid)
 Retrieves a functor from the subproblem. More...
 
template<typename T >
const Moose::Functor< T > & getFunctor (const std::string &name, SubProblem &subproblem)
 Retrieves a functor from the passed-in subproblem. More...
 
template<typename T >
const Moose::Functor< T > & getFunctor (const std::string &name, SubProblem &subproblem, THREAD_ID tid)
 Retrieves a functor from the passed-in subproblem. More...
 
bool isFunctor (const std::string &name) const
 Checks the subproblem for the given functor. More...
 
bool isFunctor (const std::string &name, const SubProblem &subproblem) const
 Checks the passed-in subproblem for the given functor. More...
 
std::string deduceFunctorName (const std::string &name) const
 Small helper to look up a functor name through the input parameter keys. More...
 
Moose::ElemArg makeElemArg (const Elem *elem, bool correct_skewnewss=false) const
 Helper method to create an elemental argument for a functor that includes whether to perform skewness corrections. More...
 
template<typename T >
void checkFunctorSupportsSideIntegration (const std::string &name, bool qp_integration)
 Throws error if the functor does not support the requested side integration. More...
 

Private Member Functions

template<typename T >
const Moose::Functor< T > & getFunctorByName (const std::string &name, SubProblem &subproblem, THREAD_ID tid)
 Retrieves a functor from the passed-in subproblem. More...
 
virtual bool isADObject () const =0
 Whether this interface is for an AD object. More...
 
template<typename T >
const Moose::Functor< T > * defaultFunctor (const std::string &name)
 Helper function to parse default functor values. More...
 
template<>
const Moose::Functor< Real > * defaultFunctor (const std::string &name)
 
template<>
const Moose::Functor< ADReal > * defaultFunctor (const std::string &name)
 

Private Attributes

const InputParameters_fi_params
 Parameters of the object with this interface. More...
 
const std::string _fi_name
 The name of the object that this interface belongs to. More...
 
SubProblem *const _fi_subproblem
 Pointer to subproblem if the subproblem pointer parameter was set. More...
 
const THREAD_ID _fi_tid
 Current threaded it. More...
 
std::vector< std::unique_ptr< Moose::Functor< Real > > > _default_real_functors
 Storage vector for Moose::Functor<Real> default objects. More...
 
std::vector< std::unique_ptr< Moose::Functor< ADReal > > > _default_ad_real_functors
 Storage vector for Moose::Functor<ADReal> default objects. More...
 

Detailed Description

An interface for accessing Moose::Functors.

Definition at line 28 of file FunctorInterface.h.

Constructor & Destructor Documentation

◆ FunctorInterface()

FunctorInterface::FunctorInterface ( const MooseObject moose_object)

Definition at line 19 of file FunctorInterface.C.

20  : _fi_params(moose_object->parameters()),
21  _fi_name(_fi_params.get<std::string>("_object_name")),
22  _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
24 {
25 }
const std::string _fi_name
The name of the object that this interface belongs to.
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.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
const InputParameters & parameters() const
Get the parameters of the object.
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.
const InputParameters & _fi_params
Parameters of the object with this interface.
const THREAD_ID _fi_tid
Current threaded it.
unsigned int THREAD_ID
Definition: MooseTypes.h:209

Member Function Documentation

◆ checkFunctorSupportsSideIntegration()

template<typename T >
void FunctorInterface::checkFunctorSupportsSideIntegration ( const std::string &  name,
bool  qp_integration 
)
protected

Throws error if the functor does not support the requested side integration.

Parameters
[in]nameName of functor or functor parameter
[in]qp_integrationTrue if performing qp integration, false if face info

Definition at line 236 of file FunctorInterface.h.

237 {
238  const std::string functor_name = deduceFunctorName(name);
239  const auto & functor = getFunctor<T>(name);
240  if (qp_integration)
241  {
242  if (!functor.supportsElemSideQpArg())
243  mooseError("Quadrature point integration was requested, but the functor '",
244  functor_name,
245  "' does not support this.");
246  }
247  else
248  {
249  if (!functor.supportsFaceArg())
250  mooseError("Face info integration was requested, but the functor '",
251  functor_name,
252  "' does not support this.");
253  }
254 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
static std::string deduceFunctorName(const std::string &name, const InputParameters &params)
Helper to look up a functor name through the input parameter keys.

◆ deduceFunctorName() [1/2]

std::string FunctorInterface::deduceFunctorName ( const std::string &  name,
const InputParameters params 
)
static

Helper to look up a functor name through the input parameter keys.

Parameters
nameThe input parameter name that we are trying to deduce the functor name for
paramsThe input parameters object that we will be checking for parameters named name
Returns
The functor name

Definition at line 28 of file FunctorInterface.C.

Referenced by checkFunctorSupportsSideIntegration(), deduceFunctorName(), getFunctor(), and isFunctor().

29 {
30  if (params.isParamValid(name))
31  {
32  if (params.have_parameter<MooseFunctorName>(name))
33  return params.get<MooseFunctorName>(name);
34  // variables, functor material properties, functions, and post-processors are also functors
35  else if (params.have_parameter<MaterialPropertyName>(name))
36  return params.get<MaterialPropertyName>(name);
37  else if (params.have_parameter<VariableName>(name))
38  return params.get<VariableName>(name);
39  else if (params.have_parameter<std::vector<VariableName>>(name))
40  {
41  const auto & var_names = params.get<std::vector<VariableName>>(name);
42  if (var_names.size() != 1)
43  mooseError("We only support a single variable name for retrieving a functor");
44  return var_names[0];
45  }
46  else if (params.have_parameter<NonlinearVariableName>(name))
47  return params.get<NonlinearVariableName>(name);
48  else if (params.have_parameter<FunctionName>(name))
49  return params.get<FunctionName>(name);
50  else if (params.have_parameter<PostprocessorName>(name))
51  return params.get<PostprocessorName>(name);
52  else
53  mooseError("Invalid parameter type for retrieving a functor");
54  }
55  else
56  return name;
57 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ deduceFunctorName() [2/2]

std::string FunctorInterface::deduceFunctorName ( const std::string &  name) const
protected

Small helper to look up a functor name through the input parameter keys.

Definition at line 60 of file FunctorInterface.C.

61 {
62  return deduceFunctorName(name, _fi_params);
63 }
const InputParameters & _fi_params
Parameters of the object with this interface.
static std::string deduceFunctorName(const std::string &name, const InputParameters &params)
Helper to look up a functor name through the input parameter keys.

◆ defaultFunctor() [1/3]

template<typename T >
const Moose::Functor< T > * FunctorInterface::defaultFunctor ( const std::string &  name)
private

Helper function to parse default functor values.

This is implemented as a specialization for supported types and returns NULL in all other cases.

Definition at line 229 of file FunctorInterface.h.

230 {
231  return nullptr;
232 }

◆ defaultFunctor() [2/3]

const Moose::Functor< Real > * FunctorInterface::defaultFunctor ( const std::string &  name)
private

Definition at line 67 of file FunctorInterface.C.

68 {
69  std::istringstream ss(name);
70  Real real_value;
71 
72  // check if the string parsed cleanly into a Real number
73  if (ss >> real_value && ss.eof())
74  {
75  _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>(
76  std::make_unique<Moose::ConstantFunctor<Real>>(real_value)));
77  auto & default_property = _default_real_functors.back();
78  return default_property.get();
79  }
80 
81  return nullptr;
82 }
This is a wrapper that forwards calls to the implementation, which can be switched out at any time wi...
std::vector< std::unique_ptr< Moose::Functor< Real > > > _default_real_functors
Storage vector for Moose::Functor<Real> default objects.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class template for creating constant functors.

◆ defaultFunctor() [3/3]

const Moose::Functor< ADReal > * FunctorInterface::defaultFunctor ( const std::string &  name)
private

Definition at line 86 of file FunctorInterface.C.

87 {
88  std::istringstream ss(name);
89  Real real_value;
90 
91  // check if the string parsed cleanly into a Real number
92  if (ss >> real_value && ss.eof())
93  {
94  _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>(
95  std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value)));
96  auto & default_property = _default_ad_real_functors.back();
97  return default_property.get();
98  }
99 
100  return nullptr;
101 }
std::vector< std::unique_ptr< Moose::Functor< ADReal > > > _default_ad_real_functors
Storage vector for Moose::Functor<ADReal> default objects.
This is a wrapper that forwards calls to the implementation, which can be switched out at any time wi...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class template for creating constant functors.

◆ getFunctor() [1/4]

template<typename T >
const Moose::Functor< T > & FunctorInterface::getFunctor ( const std::string &  name)
protected

Retrieves a functor from the subproblem.

This method also leverages the ability to create default functors if the user passed an integer or real in the input file

Parameters
nameThe name of the functor to retrieve. This should match the functor parameter name, not the actual name of the functor created in the input file
Returns
The functor

Definition at line 200 of file FunctorInterface.h.

Referenced by MaterialFunctorConverterTempl< T >::MaterialFunctorConverterTempl().

201 {
202  mooseAssert(_fi_subproblem, "This must be non-null");
203  return getFunctor<T>(name, *_fi_subproblem, _fi_tid);
204 }
std::string name(const ElemQuality q)
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.
const THREAD_ID _fi_tid
Current threaded it.

◆ getFunctor() [2/4]

template<typename T >
const Moose::Functor< T > & FunctorInterface::getFunctor ( const std::string &  name,
THREAD_ID  tid 
)
protected

Retrieves a functor from the subproblem.

This method also leverages the ability to create default functors if the user passed an integer or real in the input file

Parameters
nameThe name of the functor to retrieve. This should match the functor parameter name, not the actual name of the functor created in the input file
tidThe thread ID used to retrieve the functor from this interface's subproblem
Returns
The functor

Definition at line 192 of file FunctorInterface.h.

193 {
194  mooseAssert(_fi_subproblem, "This must be non-null");
195  return getFunctor<T>(name, *_fi_subproblem, tid);
196 }
std::string name(const ElemQuality q)
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.

◆ getFunctor() [3/4]

template<typename T >
const Moose::Functor< T > & FunctorInterface::getFunctor ( const std::string &  name,
SubProblem subproblem 
)
protected

Retrieves a functor from the passed-in subproblem.

This method also leverages the ability to create default functors if the user passed an integer or real in the input file

Parameters
nameThe name of the functor to retrieve. This should match the functor parameter name, not the actual name of the functor created in the input file
subproblemThe subproblem to query for the functor
Returns
The functor

Definition at line 185 of file FunctorInterface.h.

186 {
187  return getFunctor<T>(name, subproblem, _fi_tid);
188 }
std::string name(const ElemQuality q)
const THREAD_ID _fi_tid
Current threaded it.

◆ getFunctor() [4/4]

template<typename T >
const Moose::Functor< T > & FunctorInterface::getFunctor ( const std::string &  name,
SubProblem subproblem,
THREAD_ID  tid 
)
protected

Retrieves a functor from the passed-in subproblem.

This method also leverages the ability to create default functors if the user passed an integer or real in the input file

Parameters
nameThe name of the functor to retrieve. This should match the functor parameter name, not the actual name of the functor created in the input file
subproblemThe subproblem to query for the functor
tidThe thread ID used to retrieve the functor from the subproblem
Returns
The functor

Definition at line 176 of file FunctorInterface.h.

177 {
178  // Check if the supplied parameter is a valid input parameter key
179  std::string functor_name = deduceFunctorName(name);
180  return getFunctorByName<T>(functor_name, subproblem, tid);
181 }
static std::string deduceFunctorName(const std::string &name, const InputParameters &params)
Helper to look up a functor name through the input parameter keys.

◆ getFunctorByName()

template<typename T >
const Moose::Functor< T > & FunctorInterface::getFunctorByName ( const std::string &  name,
SubProblem subproblem,
THREAD_ID  tid 
)
private

Retrieves a functor from the passed-in subproblem.

This method also leverages the ability to create default functors if the user passed an integer or real in the input file

Parameters
nameThe actual name of the functor to retrieve instead of the parameter name
subproblemThe subproblem to query for the functor
tidThe thread ID used to retrieve the functor from the subproblem
Returns
The functor

Definition at line 208 of file FunctorInterface.h.

211 {
212  // Check if it's just a constant
213  const auto * const default_functor = defaultFunctor<T>(name);
214  if (default_functor)
215  return *default_functor;
216 
217  return subproblem.getFunctor<T>(name, tid, _fi_name, isADObject());
218 }
std::string name(const ElemQuality q)
const std::string _fi_name
The name of the object that this interface belongs to.
const Moose::Functor< T > & getFunctor(const std::string &name, const THREAD_ID tid, const std::string &requestor_name, bool requestor_is_ad)
Definition: SubProblem.h:1214
virtual bool isADObject() const =0
Whether this interface is for an AD object.

◆ isADObject()

virtual bool FunctorInterface::isADObject ( ) const
privatepure virtual

Whether this interface is for an AD object.

Implemented in ADFunctorInterface, and NonADFunctorInterface.

Referenced by getFunctorByName().

◆ isFunctor() [1/2]

bool FunctorInterface::isFunctor ( const std::string &  name) const
protected

Checks the subproblem for the given functor.

This will not query default functors potentially stored in this object, e.g. this method will return false if the user passed an int or real to the functor param in the input file

Parameters
nameThe name of the functor to check. This should match the functor parameter name, not the actual name of the functor created in the input file
Returns
Whether the subproblem has the specified functor

Definition at line 113 of file FunctorInterface.C.

114 {
115  mooseAssert(_fi_subproblem, "This must be non-null");
116  return isFunctor(name, *_fi_subproblem);
117 }
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.
bool isFunctor(const std::string &name) const
Checks the subproblem for the given functor.

◆ isFunctor() [2/2]

bool FunctorInterface::isFunctor ( const std::string &  name,
const SubProblem subproblem 
) const
protected

Checks the passed-in subproblem for the given functor.

This will not query default functors potentially stored in this object, e.g. this method will return false if the user passed an int or real to the functor param in the input file

Parameters
nameThe name of the functor to check. This should match the functor parameter name, not the actual name of the functor created in the input file
subproblemThe subproblem to query for the functor
Returns
Whether the subproblem has the specified functor

Definition at line 104 of file FunctorInterface.C.

105 {
106  // Check if the supplied parameter is a valid input parameter key
107  std::string functor_name = deduceFunctorName(name);
108 
109  return subproblem.hasFunctor(functor_name, _fi_tid);
110 }
bool hasFunctor(const std::string &name, const THREAD_ID tid) const
checks whether we have a functor corresponding to name on the thread id tid
Definition: SubProblem.C:1264
const THREAD_ID _fi_tid
Current threaded it.
static std::string deduceFunctorName(const std::string &name, const InputParameters &params)
Helper to look up a functor name through the input parameter keys.

◆ makeElemArg()

Moose::ElemArg FunctorInterface::makeElemArg ( const Elem *  elem,
bool  correct_skewnewss = false 
) const
protected

◆ validParams()

InputParameters FunctorInterface::validParams ( )
static

Definition at line 14 of file FunctorInterface.C.

Referenced by ADFunctorInterface::validParams(), NonADFunctorInterface::validParams(), and AuxKernelTempl< Real >::validParams().

15 {
16  return emptyInputParameters();
17 }
InputParameters emptyInputParameters()

Member Data Documentation

◆ _default_ad_real_functors

std::vector<std::unique_ptr<Moose::Functor<ADReal> > > FunctorInterface::_default_ad_real_functors
private

Storage vector for Moose::Functor<ADReal> default objects.

Definition at line 171 of file FunctorInterface.h.

Referenced by defaultFunctor().

◆ _default_real_functors

std::vector<std::unique_ptr<Moose::Functor<Real> > > FunctorInterface::_default_real_functors
private

Storage vector for Moose::Functor<Real> default objects.

Definition at line 168 of file FunctorInterface.h.

Referenced by defaultFunctor().

◆ _fi_name

const std::string FunctorInterface::_fi_name
private

The name of the object that this interface belongs to.

Definition at line 159 of file FunctorInterface.h.

Referenced by getFunctorByName().

◆ _fi_params

const InputParameters& FunctorInterface::_fi_params
private

Parameters of the object with this interface.

Definition at line 156 of file FunctorInterface.h.

Referenced by deduceFunctorName().

◆ _fi_subproblem

SubProblem* const FunctorInterface::_fi_subproblem
private

Pointer to subproblem if the subproblem pointer parameter was set.

Definition at line 162 of file FunctorInterface.h.

Referenced by getFunctor(), and isFunctor().

◆ _fi_tid

const THREAD_ID FunctorInterface::_fi_tid
private

Current threaded it.

Definition at line 165 of file FunctorInterface.h.

Referenced by getFunctor(), and isFunctor().


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