https://mooseframework.inl.gov
FunctorInterface.h
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 #pragma once
11 
12 #include "ADReal.h"
13 #include "MooseTypes.h"
14 #include "SubProblem.h"
15 #include "MooseFunctorForward.h"
16 
17 #include <vector>
18 #include <memory>
19 #include <string>
20 
21 class InputParameters;
22 class MooseObject;
23 
29 {
30 public:
32 
33  FunctorInterface(const MooseObject * moose_object);
34 
35 #ifdef MOOSE_KOKKOS_ENABLED
36 
40 #endif
41 
48  static std::string deduceFunctorName(const std::string & name, const InputParameters & params);
49 
50 protected:
58  template <typename T>
59  const Moose::Functor<T> & getFunctor(const std::string & name);
60 
69  template <typename T>
70  const Moose::Functor<T> & getFunctor(const std::string & name, THREAD_ID tid);
71 
80  template <typename T>
81  const Moose::Functor<T> & getFunctor(const std::string & name, SubProblem & subproblem);
82 
92  template <typename T>
93  const Moose::Functor<T> &
94  getFunctor(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
95 
104  bool isFunctor(const std::string & name) const;
105 
115  bool isFunctor(const std::string & name, const SubProblem & subproblem) const;
116 
120  std::string deduceFunctorName(const std::string & name) const;
121 
126  Moose::ElemArg makeElemArg(const Elem * elem, bool correct_skewnewss = false) const;
127 
134  template <typename T>
135  void checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration);
136 
137 private:
146  template <typename T>
147  const Moose::Functor<T> &
148  getFunctorByName(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
149 
153  virtual bool isADObject() const = 0;
154 
159  template <typename T>
160  const Moose::Functor<T> * defaultFunctor(const std::string & name);
161 
164 
166  const std::string _fi_name;
167 
170 
173 
175  std::vector<std::unique_ptr<Moose::Functor<Real>>> _default_real_functors;
176 
178  std::vector<std::unique_ptr<Moose::Functor<ADReal>>> _default_ad_real_functors;
179 };
180 
181 template <typename T>
182 const Moose::Functor<T> &
183 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem, const THREAD_ID tid)
184 {
185  // Check if the supplied parameter is a valid input parameter key
186  std::string functor_name = deduceFunctorName(name);
187  return getFunctorByName<T>(functor_name, subproblem, tid);
188 }
189 
190 template <typename T>
191 const Moose::Functor<T> &
192 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem)
193 {
194  return getFunctor<T>(name, subproblem, _fi_tid);
195 }
196 
197 template <typename T>
198 const Moose::Functor<T> &
199 FunctorInterface::getFunctor(const std::string & name, const THREAD_ID tid)
200 {
201  mooseAssert(_fi_subproblem, "This must be non-null");
202  return getFunctor<T>(name, *_fi_subproblem, tid);
203 }
204 
205 template <typename T>
206 const Moose::Functor<T> &
207 FunctorInterface::getFunctor(const std::string & name)
208 {
209  mooseAssert(_fi_subproblem, "This must be non-null");
210  return getFunctor<T>(name, *_fi_subproblem, _fi_tid);
211 }
212 
213 template <typename T>
214 const Moose::Functor<T> &
215 FunctorInterface::getFunctorByName(const std::string & name,
216  SubProblem & subproblem,
217  const THREAD_ID tid)
218 {
219  // Check if it's just a constant
220  const auto * const default_functor = defaultFunctor<T>(name);
221  if (default_functor)
222  return *default_functor;
223 
224  return subproblem.getFunctor<T>(name, tid, _fi_name, isADObject());
225 }
226 
227 template <>
228 const Moose::Functor<Real> * FunctorInterface::defaultFunctor<Real>(const std::string & name);
229 
230 template <>
231 const Moose::Functor<ADReal> * FunctorInterface::defaultFunctor<ADReal>(const std::string & name);
232 
233 // General version for types that do not accept default values
234 template <typename T>
235 const Moose::Functor<T> *
236 FunctorInterface::defaultFunctor(const std::string & /*name*/)
237 {
238  return nullptr;
239 }
240 
241 template <typename T>
242 void
243 FunctorInterface::checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration)
244 {
245  const std::string functor_name = deduceFunctorName(name);
246  const auto & functor = getFunctor<T>(name);
247  if (qp_integration)
248  {
249  if (!functor.supportsElemSideQpArg())
250  mooseError("Quadrature point integration was requested, but the functor '",
251  functor_name,
252  "' does not support this.");
253  }
254  else
255  {
256  if (!functor.supportsFaceArg())
257  mooseError("Face info integration was requested, but the functor '",
258  functor_name,
259  "' does not support this.");
260  }
261 }
std::string name(const ElemQuality q)
An interface for accessing Moose::Functors.
std::vector< std::unique_ptr< Moose::Functor< ADReal > > > _default_ad_real_functors
Storage vector for Moose::Functor<ADReal> default objects.
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.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
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.
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:27
A structure that is used to evaluate Moose functors logically at an element/cell center.
const Moose::Functor< T > & getFunctor(const std::string &name)
Retrieves a functor from the subproblem.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
void checkFunctorSupportsSideIntegration(const std::string &name, bool qp_integration)
Throws error if the functor does not support the requested side integration.
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.
const Moose::Functor< T > & getFunctorByName(const std::string &name, SubProblem &subproblem, THREAD_ID tid)
Retrieves a functor from the passed-in subproblem.
const InputParameters & _fi_params
Parameters of the object with this interface.
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