LCOV - code coverage report
Current view: top level - include/utils - ADWrapperFunctor.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 54 62 87.1 %
Date: 2025-07-17 01:28:37 Functions: 39 155 25.2 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : {
      16             : /**
      17             :  * Wraps non-AD functors such that they can be used in objects that have requested the functor as AD
      18             :  */
      19             : template <typename T>
      20             : class ADWrapperFunctor : public FunctorBase<T>
      21             : {
      22             : public:
      23             :   using typename Moose::FunctorBase<T>::ValueType;
      24             :   using typename Moose::FunctorBase<T>::GradientType;
      25             :   using typename Moose::FunctorBase<T>::DotType;
      26             : 
      27      118014 :   ADWrapperFunctor(const FunctorBase<typename MetaPhysicL::RawType<T>::value_type> & non_ad_functor)
      28      118014 :     : FunctorBase<T>(non_ad_functor.functorName() + "_ad_ified", {EXEC_ALWAYS}),
      29      354042 :       _non_ad_functor(non_ad_functor)
      30             :   {
      31      236028 :   }
      32             : 
      33           0 :   virtual bool isExtrapolatedBoundaryFace(const FaceInfo & fi,
      34             :                                           const Elem * const elem,
      35             :                                           const Moose::StateArg & state) const override
      36             :   {
      37           0 :     return _non_ad_functor.isExtrapolatedBoundaryFace(fi, elem, state);
      38             :   }
      39           0 :   virtual bool isConstant() const override { return _non_ad_functor.isConstant(); }
      40        6304 :   virtual bool hasBlocks(const SubdomainID id) const override
      41             :   {
      42        6304 :     return _non_ad_functor.hasBlocks(id);
      43             :   }
      44           0 :   virtual bool hasFaceSide(const FaceInfo & fi, const bool fi_elem_side) const override
      45             :   {
      46           0 :     return _non_ad_functor.hasFaceSide(fi, fi_elem_side);
      47             :   }
      48             : 
      49           0 :   bool supportsFaceArg() const override final { return _non_ad_functor.supportsFaceArg(); }
      50           0 :   bool supportsElemSideQpArg() const override final
      51             :   {
      52           0 :     return _non_ad_functor.supportsElemSideQpArg();
      53             :   }
      54             : 
      55             : protected:
      56             :   ///@{
      57             :   /**
      58             :    * Forward calls to wrapped object
      59             :    */
      60        2306 :   ValueType evaluate(const ElemArg & elem, const StateArg & state) const override
      61             :   {
      62        4612 :     return _non_ad_functor(elem, state);
      63             :   }
      64       16540 :   ValueType evaluate(const FaceArg & face, const StateArg & state) const override
      65             :   {
      66       33080 :     return _non_ad_functor(face, state);
      67             :   }
      68        1922 :   ValueType evaluate(const ElemQpArg & qp, const StateArg & state) const override
      69             :   {
      70        3844 :     return _non_ad_functor(qp, state);
      71             :   }
      72        1474 :   ValueType evaluate(const ElemSideQpArg & qp, const StateArg & state) const override
      73             :   {
      74        2948 :     return _non_ad_functor(qp, state);
      75             :   }
      76           2 :   ValueType evaluate(const ElemPointArg & elem_point, const StateArg & state) const override
      77             :   {
      78           4 :     return _non_ad_functor(elem_point, state);
      79             :   }
      80      151019 :   ValueType evaluate(const NodeArg & node, const StateArg & state) const override
      81             :   {
      82      302038 :     return _non_ad_functor(node, state);
      83             :   }
      84             : 
      85           2 :   GradientType evaluateGradient(const ElemArg & elem, const StateArg & state) const override
      86             :   {
      87           4 :     return _non_ad_functor.gradient(elem, state);
      88             :   }
      89           2 :   GradientType evaluateGradient(const FaceArg & face, const StateArg & state) const override
      90             :   {
      91           4 :     return _non_ad_functor.gradient(face, state);
      92             :   }
      93           2 :   GradientType evaluateGradient(const ElemQpArg & qp, const StateArg & state) const override
      94             :   {
      95           4 :     return _non_ad_functor.gradient(qp, state);
      96             :   }
      97           2 :   GradientType evaluateGradient(const ElemSideQpArg & qp, const StateArg & state) const override
      98             :   {
      99           4 :     return _non_ad_functor.gradient(qp, state);
     100             :   }
     101           2 :   GradientType evaluateGradient(const ElemPointArg & elem_point,
     102             :                                 const StateArg & state) const override
     103             :   {
     104           4 :     return _non_ad_functor.gradient(elem_point, state);
     105             :   }
     106           2 :   GradientType evaluateGradient(const NodeArg & node, const StateArg & state) const override
     107             :   {
     108           4 :     return _non_ad_functor.gradient(node, state);
     109             :   }
     110             : 
     111         258 :   DotType evaluateDot(const ElemArg & elem, const StateArg & state) const override
     112             :   {
     113         516 :     return _non_ad_functor.dot(elem, state);
     114             :   }
     115           2 :   DotType evaluateDot(const FaceArg & face, const StateArg & state) const override
     116             :   {
     117           4 :     return _non_ad_functor.dot(face, state);
     118             :   }
     119           2 :   DotType evaluateDot(const ElemQpArg & qp, const StateArg & state) const override
     120             :   {
     121           4 :     return _non_ad_functor.dot(qp, state);
     122             :   }
     123           2 :   DotType evaluateDot(const ElemSideQpArg & qp, const StateArg & state) const override
     124             :   {
     125           4 :     return _non_ad_functor.dot(qp, state);
     126             :   }
     127           2 :   DotType evaluateDot(const ElemPointArg & elem_point, const StateArg & state) const override
     128             :   {
     129           4 :     return _non_ad_functor.dot(elem_point, state);
     130             :   }
     131           2 :   DotType evaluateDot(const NodeArg & node, const StateArg & state) const override
     132             :   {
     133           4 :     return _non_ad_functor.dot(node, state);
     134             :   }
     135             : 
     136           2 :   GradientType evaluateGradDot(const ElemArg & elem, const StateArg & state) const override
     137             :   {
     138           4 :     return _non_ad_functor.gradDot(elem, state);
     139             :   }
     140           2 :   GradientType evaluateGradDot(const FaceArg & face, const StateArg & state) const override
     141             :   {
     142           4 :     return _non_ad_functor.gradDot(face, state);
     143             :   }
     144           2 :   GradientType evaluateGradDot(const ElemQpArg & qp, const StateArg & state) const override
     145             :   {
     146           4 :     return _non_ad_functor.gradDot(qp, state);
     147             :   }
     148           2 :   GradientType evaluateGradDot(const ElemSideQpArg & qp, const StateArg & state) const override
     149             :   {
     150           4 :     return _non_ad_functor.gradDot(qp, state);
     151             :   }
     152           2 :   GradientType evaluateGradDot(const ElemPointArg & elem_point,
     153             :                                const StateArg & state) const override
     154             :   {
     155           4 :     return _non_ad_functor.gradDot(elem_point, state);
     156             :   }
     157           2 :   GradientType evaluateGradDot(const NodeArg & node, const StateArg & state) const override
     158             :   {
     159           4 :     return _non_ad_functor.gradDot(node, state);
     160             :   }
     161             :   ///@}
     162             : 
     163             : private:
     164             :   /// Our wrapped AD object
     165             :   const FunctorBase<typename MetaPhysicL::RawType<T>::value_type> & _non_ad_functor;
     166             : };
     167             : }

Generated by: LCOV version 1.14