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

Generated by: LCOV version 1.14