Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 
41  static std::string deduceFunctorName(const std::string & name, const InputParameters & params);
42 
43 protected:
51  template <typename T>
52  const Moose::Functor<T> & getFunctor(const std::string & name);
53 
62  template <typename T>
63  const Moose::Functor<T> & getFunctor(const std::string & name, THREAD_ID tid);
64 
73  template <typename T>
74  const Moose::Functor<T> & getFunctor(const std::string & name, SubProblem & subproblem);
75 
85  template <typename T>
86  const Moose::Functor<T> &
87  getFunctor(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
88 
97  bool isFunctor(const std::string & name) const;
98 
108  bool isFunctor(const std::string & name, const SubProblem & subproblem) const;
109 
113  std::string deduceFunctorName(const std::string & name) const;
114 
119  Moose::ElemArg makeElemArg(const Elem * elem, bool correct_skewnewss = false) const;
120 
127  template <typename T>
128  void checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration);
129 
130 private:
139  template <typename T>
140  const Moose::Functor<T> &
141  getFunctorByName(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
142 
146  virtual bool isADObject() const = 0;
147 
152  template <typename T>
153  const Moose::Functor<T> * defaultFunctor(const std::string & name);
154 
157 
159  const std::string _fi_name;
160 
163 
166 
168  std::vector<std::unique_ptr<Moose::Functor<Real>>> _default_real_functors;
169 
171  std::vector<std::unique_ptr<Moose::Functor<ADReal>>> _default_ad_real_functors;
172 };
173 
174 template <typename T>
175 const Moose::Functor<T> &
176 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem, const THREAD_ID tid)
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 }
182 
183 template <typename T>
184 const Moose::Functor<T> &
185 FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem)
186 {
187  return getFunctor<T>(name, subproblem, _fi_tid);
188 }
189 
190 template <typename T>
191 const Moose::Functor<T> &
192 FunctorInterface::getFunctor(const std::string & name, const THREAD_ID tid)
193 {
194  mooseAssert(_fi_subproblem, "This must be non-null");
195  return getFunctor<T>(name, *_fi_subproblem, tid);
196 }
197 
198 template <typename T>
199 const Moose::Functor<T> &
200 FunctorInterface::getFunctor(const std::string & name)
201 {
202  mooseAssert(_fi_subproblem, "This must be non-null");
203  return getFunctor<T>(name, *_fi_subproblem, _fi_tid);
204 }
205 
206 template <typename T>
207 const Moose::Functor<T> &
208 FunctorInterface::getFunctorByName(const std::string & name,
209  SubProblem & subproblem,
210  const THREAD_ID tid)
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 }
219 
220 template <>
221 const Moose::Functor<Real> * FunctorInterface::defaultFunctor<Real>(const std::string & name);
222 
223 template <>
224 const Moose::Functor<ADReal> * FunctorInterface::defaultFunctor<ADReal>(const std::string & name);
225 
226 // General version for types that do not accept default values
227 template <typename T>
228 const Moose::Functor<T> *
229 FunctorInterface::defaultFunctor(const std::string & /*name*/)
230 {
231  return nullptr;
232 }
233 
234 template <typename T>
235 void
236 FunctorInterface::checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration)
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)
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:1219
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:302
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 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:205