LCOV - code coverage report
Current view: top level - include/functions - Function.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: d8769b Lines: 8 10 80.0 %
Date: 2025-11-07 20:01:30 Functions: 4 6 66.7 %
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 "FunctionBase.h"
      13             : #include "MooseFunctor.h"
      14             : #include "ChainedReal.h"
      15             : 
      16             : // libMesh
      17             : #include "libmesh/vector_value.h"
      18             : 
      19             : // libMesh forward declarations
      20             : namespace libMesh
      21             : {
      22             : class Point;
      23             : }
      24             : 
      25             : /**
      26             :  * Base class for function objects.  Functions override value to supply a
      27             :  * value at a point.
      28             :  */
      29             : class Function : public Moose::FunctionBase, public Moose::FunctorBase<Real>
      30             : {
      31             : public:
      32             :   /**
      33             :    * Class constructor
      34             :    * \param parameters The input parameters for the function
      35             :    */
      36             :   static InputParameters validParams();
      37             : 
      38             :   Function(const InputParameters & parameters);
      39             : 
      40             :   /**
      41             :    * Function destructor
      42             :    */
      43             :   virtual ~Function();
      44             : 
      45             :   /**
      46             :    * Override this to evaluate the scalar function at point (t,x,y,z), by default
      47             :    * this returns zero, you must override it.
      48             :    * \param t The time
      49             :    * \param p The Point in space (x,y,z)
      50             :    * \return A scalar of the function evaluated at the time and location
      51             :    */
      52             :   virtual Real value(Real t, const Point & p) const;
      53             : 
      54             :   /**
      55             :    * Override this to evaluate the scalar function at point (t,x,y,z), using dual numbers by default
      56             :    * this uses value, gradient, and timeDerivative to assemble a dual number, although the function
      57             :    * can be overridden with a custom computation using dual numbers.
      58             :    * \param t The time
      59             :    * \param p The Point in space (x,y,z)
      60             :    * \return A scalar of the function evaluated at the time and location
      61             :    */
      62             :   virtual ADReal value(const ADReal & t, const ADPoint & p) const;
      63             : 
      64             :   ///@{ Helpers to call value(t,x,y,z)
      65             :   ChainedReal value(const ChainedReal & t) const;
      66             :   template <typename U>
      67             :   auto value(const U & t) const;
      68             :   template <typename U>
      69          40 :   auto value(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
      70             :   ///@}
      71             : 
      72             :   /**
      73             :    * Override this to evaluate the vector function at a point (t,x,y,z), by default
      74             :    * this returns a zero vector, you must override it.
      75             :    * \param t The time
      76             :    * \param p The Point in space (x,y,z)
      77             :    * \return A vector of the function evaluated at the time and location
      78             :    */
      79             :   virtual RealVectorValue vectorValue(Real t, const Point & p) const;
      80             : 
      81             :   /**
      82             :    * Override this to evaluate the curl of the vector function at a point (t,x,y,z),
      83             :    * by default this returns a zero vector, you must override it.
      84             :    * \param t The time
      85             :    * \param p The Point in space (x,y,z)
      86             :    * \return A vector of the curl of the function evaluated at the time and location
      87             :    */
      88             :   virtual RealVectorValue curl(Real t, const Point & p) const;
      89             : 
      90             :   /**
      91             :    * Override this to evaluate the divergence of the vector function at a point (t,x,y,z),
      92             :    * by default this returns zero, you must override it.
      93             :    * \param t The time
      94             :    * \param p The Point in space (x,y,z)
      95             :    * \return A scalar of the divergence of the function evaluated at the time and location
      96             :    */
      97             :   virtual Real div(Real t, const Point & p) const;
      98             : 
      99             :   using Moose::FunctorBase<Real>::gradient;
     100             :   /**
     101             :    * Function objects can optionally provide a gradient at a point. By default
     102             :    * this returns 0, you must override it.
     103             :    * \param t The time
     104             :    * \param p The Point in space (x,y,z)
     105             :    * \return A gradient of the function evaluated at the time and location
     106             :    */
     107             :   virtual RealGradient gradient(Real t, const Point & p) const;
     108             : 
     109             :   /**
     110             :    * Get the time derivative of the function
     111             :    * \param t The time
     112             :    * \param p The point in space (x,y,z)
     113             :    * \return The time derivative of the function at the specified time and location
     114             :    */
     115             :   virtual Real timeDerivative(Real t, const Point & p) const;
     116             : 
     117             :   ///@{ Helpers to call timeDerivative(t,x,y,z)
     118             :   template <typename U>
     119             :   auto timeDerivative(const U & t) const;
     120             :   template <typename U>
     121             :   auto timeDerivative(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
     122             :   ///@}
     123             : 
     124             :   /// Returns the integral of the function over its domain
     125             :   virtual Real integral() const;
     126             : 
     127             :   /// Returns the average of the function over its domain
     128             :   virtual Real average() const;
     129             : 
     130             :   /**
     131             :    * Computes the time integral at a spatial point between two time values
     132             :    *
     133             :    * @param[in] t1  Beginning time value
     134             :    * @param[in] t2  End time value
     135             :    * @param[in] p   Spatial point
     136             :    */
     137             :   virtual Real timeIntegral(Real t1, Real t2, const Point & p) const;
     138             : 
     139             :   void timestepSetup() override;
     140             :   // We will only allow initialSetup() and timestepSetup() to be overriden
     141             :   void residualSetup() override final;
     142             :   void jacobianSetup() override final;
     143             :   void customSetup(const ExecFlagType & exec_type) override final;
     144             : 
     145       22006 :   bool hasBlocks(SubdomainID) const override { return true; }
     146             : 
     147           0 :   bool supportsFaceArg() const override final { return true; }
     148           0 :   bool supportsElemSideQpArg() const override final { return true; }
     149             : 
     150             : private:
     151             :   using typename Moose::FunctorBase<Real>::ValueType;
     152             :   using typename Moose::FunctorBase<Real>::GradientType;
     153             :   using typename Moose::FunctorBase<Real>::DotType;
     154             : 
     155             :   using ElemArg = Moose::ElemArg;
     156             :   using ElemQpArg = Moose::ElemQpArg;
     157             :   using ElemSideQpArg = Moose::ElemSideQpArg;
     158             :   using FaceArg = Moose::FaceArg;
     159             :   using ElemPointArg = Moose::ElemPointArg;
     160             :   using NodeArg = Moose::NodeArg;
     161             : 
     162             :   template <typename R>
     163             :   ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const;
     164             : 
     165             :   ValueType evaluate(const ElemArg & elem, const Moose::StateArg & state) const override final;
     166             :   ValueType evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
     167             :   ValueType evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
     168             :   ValueType evaluate(const ElemSideQpArg & elem_side_qp,
     169             :                      const Moose::StateArg & state) const override final;
     170             :   ValueType evaluate(const ElemPointArg & elem_point,
     171             :                      const Moose::StateArg & state) const override final;
     172             :   ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
     173             : 
     174             :   template <typename R>
     175             :   GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const;
     176             : 
     177             :   GradientType evaluateGradient(const ElemArg & elem,
     178             :                                 const Moose::StateArg & state) const override final;
     179             :   GradientType evaluateGradient(const FaceArg & face,
     180             :                                 const Moose::StateArg & state) const override final;
     181             :   GradientType evaluateGradient(const ElemQpArg & qp,
     182             :                                 const Moose::StateArg & state) const override final;
     183             :   GradientType evaluateGradient(const ElemSideQpArg & elem_side_qp,
     184             :                                 const Moose::StateArg & state) const override final;
     185             :   GradientType evaluateGradient(const ElemPointArg & elem_point,
     186             :                                 const Moose::StateArg & state) const override final;
     187             :   GradientType evaluateGradient(const NodeArg & node,
     188             :                                 const Moose::StateArg & state) const override final;
     189             : 
     190             :   template <typename R>
     191             :   DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const;
     192             :   DotType evaluateDot(const ElemArg & elem, const Moose::StateArg & state) const override final;
     193             :   DotType evaluateDot(const FaceArg & face, const Moose::StateArg & state) const override final;
     194             :   DotType evaluateDot(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
     195             :   DotType evaluateDot(const ElemSideQpArg & elem_side_qp,
     196             :                       const Moose::StateArg & state) const override final;
     197             :   DotType evaluateDot(const ElemPointArg & elem_point,
     198             :                       const Moose::StateArg & state) const override final;
     199             :   DotType evaluateDot(const NodeArg & node, const Moose::StateArg & state) const override final;
     200             : };
     201             : 
     202             : template <typename U>
     203             : auto
     204       19877 : Function::value(const U & t) const
     205             : {
     206       19877 :   static const Moose::GenericType<Point, Moose::IsADType<U>::value> p;
     207       19877 :   return value(t, p);
     208             : }
     209             : 
     210             : template <typename U>
     211             : auto
     212         394 : Function::value(const U & t, const U & x, const U & y, const U & z) const
     213             : {
     214         394 :   Moose::GenericType<Point, Moose::IsADType<U>::value> p(x, y, z);
     215         788 :   return value(t, p);
     216             : }
     217             : 
     218             : template <typename U>
     219             : auto
     220             : Function::timeDerivative(const U & t) const
     221             : {
     222             :   static const Moose::GenericType<Point, Moose::IsADType<U>::value> p;
     223             :   return timeDerivative(t, p);
     224             : }
     225             : 
     226             : template <typename U>
     227             : auto
     228             : Function::timeDerivative(const U & t, const U & x, const U & y, const U & z) const
     229             : {
     230             :   Moose::GenericType<Point, Moose::IsADType<U>::value> p(x, y, z);
     231             :   return timeDerivative(t, p);
     232             : }

Generated by: LCOV version 1.14