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 
144  template <typename T>
145  const Moose::Functor<T> & getFunctorByName(const std::string & name);
146 
147 private:
156  template <typename T>
157  const Moose::Functor<T> &
158  getFunctorByName(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
159 
163  virtual bool isADObject() const = 0;
164 
169  template <typename T>
170  const Moose::Functor<T> * defaultFunctor(const std::string & name);
171 
174 
176  const std::string _fi_name;
177 
180 
183 
185  std::vector<std::unique_ptr<Moose::Functor<Real>>> _default_real_functors;
186 
188  std::vector<std::unique_ptr<Moose::Functor<ADReal>>> _default_ad_real_functors;
189 };
190 
191 template <typename T>
192 const Moose::Functor<T> &
193 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem, const THREAD_ID tid)
194 {
195  // Check if the supplied parameter is a valid input parameter key
196  std::string functor_name = deduceFunctorName(name);
197  return getFunctorByName<T>(functor_name, subproblem, tid);
198 }
199 
200 template <typename T>
201 const Moose::Functor<T> &
202 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem)
203 {
204  return getFunctor<T>(name, subproblem, _fi_tid);
205 }
206 
207 template <typename T>
208 const Moose::Functor<T> &
209 FunctorInterface::getFunctor(const std::string & name, const THREAD_ID tid)
210 {
211  mooseAssert(_fi_subproblem, "This must be non-null");
212  return getFunctor<T>(name, *_fi_subproblem, tid);
213 }
214 
215 template <typename T>
216 const Moose::Functor<T> &
217 FunctorInterface::getFunctor(const std::string & name)
218 {
219  mooseAssert(_fi_subproblem, "This must be non-null");
220  return getFunctor<T>(name, *_fi_subproblem, _fi_tid);
221 }
222 
223 template <typename T>
224 const Moose::Functor<T> &
225 FunctorInterface::getFunctorByName(const std::string & name)
226 {
227  mooseAssert(_fi_subproblem, "This must be non-null");
228  return getFunctorByName<T>(name, *_fi_subproblem, _fi_tid);
229 }
230 
231 template <typename T>
232 const Moose::Functor<T> &
233 FunctorInterface::getFunctorByName(const std::string & name,
234  SubProblem & subproblem,
235  const THREAD_ID tid)
236 {
237  // Check if it's just a constant
238  const auto * const default_functor = defaultFunctor<T>(name);
239  if (default_functor)
240  return *default_functor;
241 
242  return subproblem.getFunctor<T>(name, tid, _fi_name, isADObject());
243 }
244 
245 template <>
246 const Moose::Functor<Real> * FunctorInterface::defaultFunctor<Real>(const std::string & name);
247 
248 template <>
249 const Moose::Functor<ADReal> * FunctorInterface::defaultFunctor<ADReal>(const std::string & name);
250 
251 // General version for types that do not accept default values
252 template <typename T>
253 const Moose::Functor<T> *
254 FunctorInterface::defaultFunctor(const std::string & /*name*/)
255 {
256  return nullptr;
257 }
258 
259 template <typename T>
260 void
261 FunctorInterface::checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration)
262 {
263  const std::string functor_name = deduceFunctorName(name);
264  const auto & functor = getFunctor<T>(name);
265  if (qp_integration)
266  {
267  if (!functor.supportsElemSideQpArg())
268  mooseError("Quadrature point integration was requested, but the functor '",
269  functor_name,
270  "' does not support this.");
271  }
272  else
273  {
274  if (!functor.supportsFaceArg())
275  mooseError("Face info integration was requested, but the functor '",
276  functor_name,
277  "' does not support this.");
278  }
279 }
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:1224
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:311
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:28
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 InputParameters & _fi_params
Parameters of the object with this interface.
const Moose::Functor< T > & getFunctorByName(const std::string &name)
Retrieves a functor from the subproblem.
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:237