https://mooseframework.inl.gov
ADWrapperFunctor.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 "MooseFunctor.h"
13 
14 namespace Moose
15 {
19 template <typename T>
20 class ADWrapperFunctor : public FunctorBase<T>
21 {
22 public:
23  using typename Moose::FunctorBase<T>::ValueType;
25  using typename Moose::FunctorBase<T>::DotType;
26 
27  ADWrapperFunctor(const FunctorBase<typename MetaPhysicL::RawType<T>::value_type> & non_ad_functor)
28  : FunctorBase<T>(non_ad_functor.functorName() + "_ad_ified", {EXEC_ALWAYS}),
29  _non_ad_functor(non_ad_functor)
30  {
31  }
32 
33  virtual bool isExtrapolatedBoundaryFace(const FaceInfo & fi,
34  const Elem * const elem,
35  const Moose::StateArg & state) const override
36  {
37  return _non_ad_functor.isExtrapolatedBoundaryFace(fi, elem, state);
38  }
39  virtual bool isConstant() const override { return _non_ad_functor.isConstant(); }
40  virtual bool hasBlocks(const SubdomainID id) const override
41  {
42  return _non_ad_functor.hasBlocks(id);
43  }
44  virtual bool hasFaceSide(const FaceInfo & fi, const bool fi_elem_side) const override
45  {
46  return _non_ad_functor.hasFaceSide(fi, fi_elem_side);
47  }
48 
49  bool supportsFaceArg() const override final { return _non_ad_functor.supportsFaceArg(); }
50  bool supportsElemSideQpArg() const override final
51  {
53  }
54 
55 protected:
57 
60  ValueType evaluate(const ElemArg & elem, const StateArg & state) const override
61  {
62  return _non_ad_functor(elem, state);
63  }
64  ValueType evaluate(const FaceArg & face, const StateArg & state) const override
65  {
66  return _non_ad_functor(face, state);
67  }
68  ValueType evaluate(const ElemQpArg & qp, const StateArg & state) const override
69  {
70  return _non_ad_functor(qp, state);
71  }
72  ValueType evaluate(const ElemSideQpArg & qp, const StateArg & state) const override
73  {
74  return _non_ad_functor(qp, state);
75  }
76  ValueType evaluate(const ElemPointArg & elem_point, const StateArg & state) const override
77  {
78  return _non_ad_functor(elem_point, state);
79  }
80  ValueType evaluate(const NodeArg & node, const StateArg & state) const override
81  {
82  return _non_ad_functor(node, state);
83  }
84 
85  GradientType evaluateGradient(const ElemArg & elem, const StateArg & state) const override
86  {
87  return _non_ad_functor.gradient(elem, state);
88  }
89  GradientType evaluateGradient(const FaceArg & face, const StateArg & state) const override
90  {
91  return _non_ad_functor.gradient(face, state);
92  }
93  GradientType evaluateGradient(const ElemQpArg & qp, const StateArg & state) const override
94  {
95  return _non_ad_functor.gradient(qp, state);
96  }
97  GradientType evaluateGradient(const ElemSideQpArg & qp, const StateArg & state) const override
98  {
99  return _non_ad_functor.gradient(qp, state);
100  }
102  const StateArg & state) const override
103  {
104  return _non_ad_functor.gradient(elem_point, state);
105  }
106  GradientType evaluateGradient(const NodeArg & node, const StateArg & state) const override
107  {
108  return _non_ad_functor.gradient(node, state);
109  }
110 
111  DotType evaluateDot(const ElemArg & elem, const StateArg & state) const override
112  {
113  return _non_ad_functor.dot(elem, state);
114  }
115  DotType evaluateDot(const FaceArg & face, const StateArg & state) const override
116  {
117  return _non_ad_functor.dot(face, state);
118  }
119  DotType evaluateDot(const ElemQpArg & qp, const StateArg & state) const override
120  {
121  return _non_ad_functor.dot(qp, state);
122  }
123  DotType evaluateDot(const ElemSideQpArg & qp, const StateArg & state) const override
124  {
125  return _non_ad_functor.dot(qp, state);
126  }
127  DotType evaluateDot(const ElemPointArg & elem_point, const StateArg & state) const override
128  {
129  return _non_ad_functor.dot(elem_point, state);
130  }
131  DotType evaluateDot(const NodeArg & node, const StateArg & state) const override
132  {
133  return _non_ad_functor.dot(node, state);
134  }
135 
136  GradientType evaluateGradDot(const ElemArg & elem, const StateArg & state) const override
137  {
138  return _non_ad_functor.gradDot(elem, state);
139  }
140  GradientType evaluateGradDot(const FaceArg & face, const StateArg & state) const override
141  {
142  return _non_ad_functor.gradDot(face, state);
143  }
144  GradientType evaluateGradDot(const ElemQpArg & qp, const StateArg & state) const override
145  {
146  return _non_ad_functor.gradDot(qp, state);
147  }
148  GradientType evaluateGradDot(const ElemSideQpArg & qp, const StateArg & state) const override
149  {
150  return _non_ad_functor.gradDot(qp, state);
151  }
153  const StateArg & state) const override
154  {
155  return _non_ad_functor.gradDot(elem_point, state);
156  }
157  GradientType evaluateGradDot(const NodeArg & node, const StateArg & state) const override
158  {
159  return _non_ad_functor.gradDot(node, state);
160  }
162 
163 private:
166 };
167 }
virtual bool hasBlocks(SubdomainID) const
Returns whether the functor is defined on this block.
Definition: MooseFunctor.h:237
virtual bool isConstant() const override
Returns true if this functor is a constant.
GradientType evaluateGradDot(const ElemQpArg &qp, const StateArg &state) const override
Base class template for functor objects.
Definition: MooseFunctor.h:137
ValueType evaluate(const ElemSideQpArg &qp, const StateArg &state) const override
DotType evaluateDot(const NodeArg &node, const StateArg &state) const override
virtual bool isExtrapolatedBoundaryFace(const FaceInfo &, const Elem *, const StateArg &) const
Returns whether this (sided) face is an extrapolated boundary face for this functor.
Definition: MooseFunctor.h:247
Wraps non-AD functors such that they can be used in objects that have requested the functor as AD...
GradientType evaluateGradDot(const ElemPointArg &elem_point, const StateArg &state) const override
Evaluate the functor gradient-dot with a given element and point.
GradientType evaluateGradient(const ElemQpArg &qp, const StateArg &state) const override
virtual bool isExtrapolatedBoundaryFace(const FaceInfo &fi, const Elem *const elem, const Moose::StateArg &state) const override
Returns whether this (sided) face is an extrapolated boundary face for this functor.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:47
typename FunctorReturnType< T, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector...
Definition: MooseFunctor.h:149
GradientType evaluateGradient(const ElemPointArg &elem_point, const StateArg &state) const override
Evaluate the functor gradient with a given element and point.
const FunctorBase< typename MetaPhysicL::RawType< T >::value_type > & _non_ad_functor
Our wrapped AD object.
GradientType gradDot(const ElemArg &elem, const StateArg &state) const
Same as their evaluateGradDot overloads with the same arguments but allows for caching implementation...
Definition: MooseFunctor.h:933
bool supportsElemSideQpArg() const override final
Whether this functor supports evaluation with ElemSideQpArg.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:36
virtual bool supportsElemSideQpArg() const =0
Whether this functor supports evaluation with ElemSideQpArg.
A structure defining a "face" evaluation calling argument for Moose functors.
DotType evaluateDot(const ElemArg &elem, const StateArg &state) const override
Evaluate the functor time derivative with a given element.
GradientType evaluateGradient(const FaceArg &face, const StateArg &state) const override
GradientType evaluateGradDot(const FaceArg &face, const StateArg &state) const override
virtual bool hasFaceSide(const FaceInfo &fi, const bool fi_elem_side) const override
ValueType evaluate(const ElemArg &elem, const StateArg &state) const override
Forward calls to wrapped object.
ValueType evaluate(const NodeArg &node, const StateArg &state) const override
A structure that is used to evaluate Moose functors logically at an element/cell center.
GradientType evaluateGradDot(const ElemArg &elem, const StateArg &state) const override
Evaluate the functor gradient-dot with a given element.
Argument for requesting functor evaluation at a quadrature point location in an element.
GradientType evaluateGradDot(const NodeArg &node, const StateArg &state) const override
ValueType evaluate(const FaceArg &face, const StateArg &state) const override
const MooseFunctorName & functorName() const
Return the functor name.
Definition: MooseFunctor.h:170
GradientType evaluateGradient(const ElemSideQpArg &qp, const StateArg &state) const override
virtual bool hasBlocks(const SubdomainID id) const override
Returns whether the functor is defined on this block.
virtual bool supportsFaceArg() const =0
Whether this functor supports evaluation with FaceArg.
ADWrapperFunctor(const FunctorBase< typename MetaPhysicL::RawType< T >::value_type > &non_ad_functor)
DotType dot(const ElemArg &elem, const StateArg &state) const
Same as their evaluateDot overloads with the same arguments but allows for caching implementation...
Definition: MooseFunctor.h:890
DotType evaluateDot(const ElemQpArg &qp, const StateArg &state) const override
GradientType gradient(const ElemArg &elem, const StateArg &state) const
Same as their evaluateGradient overloads with the same arguments but allows for caching implementatio...
Definition: MooseFunctor.h:847
ValueType evaluate(const ElemQpArg &qp, const StateArg &state) const override
ValueType evaluate(const ElemPointArg &elem_point, const StateArg &state) const override
Evaluate the functor with a given element and point.
State argument for evaluating functors.
GradientType evaluateGradient(const ElemArg &elem, const StateArg &state) const override
Evaluate the functor gradient with a given element.
GradientType evaluateGradient(const NodeArg &node, const StateArg &state) const override
DotType evaluateDot(const FaceArg &face, const StateArg &state) const override
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
GradientType evaluateGradDot(const ElemSideQpArg &qp, const StateArg &state) const override
DotType evaluateDot(const ElemSideQpArg &qp, const StateArg &state) const override
virtual bool isConstant() const
Returns true if this functor is a constant.
Definition: MooseFunctor.h:260
bool supportsFaceArg() const override final
Whether this functor supports evaluation with FaceArg.
Argument for requesting functor evaluation at quadrature point locations on an element side...
DotType evaluateDot(const ElemPointArg &elem_point, const StateArg &state) const override
Evaluate the functor time derivative with a given element and point.
virtual bool hasFaceSide(const FaceInfo &fi, const bool fi_elem_side) const override
Definition: MooseFunctor.h:976