https://mooseframework.inl.gov
FunctorInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "FunctorInterface.h"
11 #include "MooseFunctor.h"
12 
15 {
16  return emptyInputParameters();
17 }
18 
20  : _fi_params(moose_object->parameters()),
21  _fi_name(_fi_params.get<std::string>("_object_name")),
22  _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
23  _fi_tid(_fi_params.get<THREAD_ID>("_tid"))
24 {
25 }
26 
27 std::string
28 FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params)
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 }
58 
59 std::string
60 FunctorInterface::deduceFunctorName(const std::string & name) const
61 {
63 }
64 
65 template <>
67 FunctorInterface::defaultFunctor(const std::string & name)
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 }
83 
84 template <>
86 FunctorInterface::defaultFunctor(const std::string & name)
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 }
102 
103 bool
104 FunctorInterface::isFunctor(const std::string & name, const SubProblem & subproblem) const
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 }
111 
112 bool
113 FunctorInterface::isFunctor(const std::string & name) const
114 {
115  mooseAssert(_fi_subproblem, "This must be non-null");
116  return isFunctor(name, *_fi_subproblem);
117 }
118 
120 FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const
121 {
122  return {elem, correct_skewness};
123 }
std::string name(const ElemQuality q)
std::vector< std::unique_ptr< Moose::Functor< ADReal > > > _default_ad_real_functors
Storage vector for Moose::Functor<ADReal> default objects.
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.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
This is a wrapper that forwards calls to the implementation, which can be switched out at any time wi...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
FunctorInterface(const MooseObject *moose_object)
const Moose::Functor< T > * defaultFunctor(const std::string &name)
Helper function to parse default functor values.
InputParameters emptyInputParameters()
std::vector< std::unique_ptr< Moose::Functor< Real > > > _default_real_functors
Storage vector for Moose::Functor<Real> default objects.
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...
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
A structure that is used to evaluate Moose functors logically at an element/cell center.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class template for creating constant functors.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
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.
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:1270
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.
bool isFunctor(const std::string &name) const
Checks the subproblem for the given functor.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.