LCOV - code coverage report
Current view: top level - include/kokkos/functions - KokkosFunction.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 1 17 5.9 %
Date: 2026-05-29 20:35:17 Functions: 1 9 11.1 %
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 "KokkosTypes.h"
      13             : #include "KokkosFunctionWrapper.h"
      14             : #include "KokkosFunctorRegistry.h"
      15             : 
      16             : #include "FunctionBase.h"
      17             : 
      18             : namespace Moose::Kokkos
      19             : {
      20             : 
      21             : /**
      22             :  * The base class for a user to derive their own Kokkos functions.
      23             :  *
      24             :  * The user should define the hook methods in their derived class as inlined public methods (not
      25             :  * virtual override) with the same signature. If they are defined in the derived class, they will
      26             :  * hide the default definitions in the base class. However, the default definitions are not to be
      27             :  * actually called. If a hook method was not defined in the derived class, it should not be called.
      28             :  */
      29             : class FunctionBase : public Moose::FunctionBase
      30             : {
      31             : public:
      32             :   static InputParameters validParams();
      33             : 
      34             :   /**
      35             :    * Constructor
      36             :    */
      37             :   FunctionBase(const InputParameters & parameters);
      38             :   /**
      39             :    * Copy constructor for parallel dispatch
      40             :    */
      41             :   FunctionBase(const FunctionBase & object);
      42             : 
      43             :   /**
      44             :    * Evaluate a scalar value at point (t,x,y,z)
      45             :    * @param t The time
      46             :    * @param p The location in space (x,y,z)
      47             :    * @returns The scalar value evaluated at the time and location
      48             :    */
      49             :   KOKKOS_FUNCTION Real value(Real /* t */, Real3 /* p */) const
      50             :   {
      51             :     KOKKOS_ASSERT(false);
      52             :     return 0;
      53             :   }
      54             :   /**
      55             :    * Evaluate a vector value at point (t,x,y,z)
      56             :    * @param t The time
      57             :    * @param p The location in space (x,y,z)
      58             :    * @returns The vector value evaluated at the time and location
      59             :    */
      60           0 :   KOKKOS_FUNCTION Real3 vectorValue(Real /* t */, Real3 /* p */) const
      61             :   {
      62             :     KOKKOS_ASSERT(false);
      63           0 :     return Real3(0);
      64             :   }
      65             :   /**
      66             :    * Evaluate a gradient at point (t,x,y,z)
      67             :    * @param t The time
      68             :    * @param p The location in space (x,y,z)
      69             :    * @returns The gradient evaluated at the time and location
      70             :    */
      71           0 :   KOKKOS_FUNCTION Real3 gradient(Real /* t */, Real3 /* p */) const
      72             :   {
      73             :     KOKKOS_ASSERT(false);
      74           0 :     return Real3(0);
      75             :   }
      76             :   /**
      77             :    * Evaluate a curl at point (t,x,y,z)
      78             :    * @param t The time
      79             :    * @param p The location in space (x,y,z)
      80             :    * @returns The curl evaluated at the time and location
      81             :    */
      82           0 :   KOKKOS_FUNCTION Real3 curl(Real /* t */, Real3 /* p */) const
      83             :   {
      84             :     KOKKOS_ASSERT(false);
      85           0 :     return Real3(0);
      86             :   }
      87             :   /**
      88             :    * Evaluate a divergence at point (t,x,y,z)
      89             :    * @param t The time
      90             :    * @param p The location in space (x,y,z)
      91             :    * @returns The divergence evaluated at the time and location
      92             :    */
      93           0 :   KOKKOS_FUNCTION Real div(Real /* t */, Real3 /* p */) const
      94             :   {
      95             :     KOKKOS_ASSERT(false);
      96           0 :     return 0;
      97             :   }
      98             :   /**
      99             :    * Evaluate a time derivative at point (t,x,y,z)
     100             :    * @param t The time
     101             :    * @param p The location in space (x,y,z)
     102             :    * @returns The time derivative evaluated at the time and location
     103             :    */
     104           0 :   KOKKOS_FUNCTION Real timeDerivative(Real /* t */, Real3 /* p */) const
     105             :   {
     106             :     KOKKOS_ASSERT(false);
     107           0 :     return 0;
     108             :   }
     109             :   /**
     110             :    * Evaluate a time integral at point (x,y,z) between time \p t1 and \p t2
     111             :    * @param t1 The beginning time
     112             :    * @param t2 The end time
     113             :    * @param p The location in space (x,y,z)
     114             :    * @returns The time integral evaluated at the location between the times
     115             :    */
     116           0 :   KOKKOS_FUNCTION Real timeIntegral(Real /* t1 */, Real /* t2 */, Real3 /* p */) const
     117             :   {
     118             :     KOKKOS_ASSERT(false);
     119           0 :     return 0;
     120             :   }
     121             :   /**
     122             :    * Evaluate the integral over the domain
     123             :    * @returns The integral over the domain
     124             :    */
     125           0 :   KOKKOS_FUNCTION Real integral() const
     126             :   {
     127             :     KOKKOS_ASSERT(false);
     128           0 :     return 0;
     129             :   }
     130             :   /**
     131             :    * Evaluate the average over the domain
     132             :    * @returns The average over the domain
     133             :    */
     134           0 :   KOKKOS_FUNCTION Real average() const
     135             :   {
     136             :     KOKKOS_ASSERT(false);
     137           0 :     return 0;
     138             :   }
     139             : };
     140             : 
     141             : /**
     142             :  * The abstract class that provides polymorphic interfaces for a function.
     143             :  *
     144             :  * NOTE: This class is not the base class for a Kokkos function derivation. The user should derive
     145             :  * their own function from Moose::Kokkos::FunctionBase.
     146             :  */
     147             : class Function final
     148             : {
     149             : public:
     150             :   /**
     151             :    * Constructor
     152             :    * @param wrapper The host function wrapper
     153             :    */
     154             :   Function(std::shared_ptr<FunctionWrapperHostBase> wrapper);
     155             :   /**
     156             :    * Copy constructor for parallel dispatch
     157             :    */
     158             :   Function(const Function & function);
     159             :   /**
     160             :    * Destructor
     161             :    */
     162             :   ~Function();
     163             : 
     164    13123379 :   KOKKOS_FUNCTION Real value(Real t, Real3 p) const { return _wrapper_device->value(t, p); }
     165             :   KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
     166             :   {
     167             :     return _wrapper_device->vectorValue(t, p);
     168             :   }
     169             :   KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const { return _wrapper_device->gradient(t, p); }
     170             :   KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const { return _wrapper_device->curl(t, p); }
     171             :   KOKKOS_FUNCTION Real div(Real t, Real3 p) const { return _wrapper_device->div(t, p); }
     172             :   KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
     173             :   {
     174             :     return _wrapper_device->timeDerivative(t, p);
     175             :   }
     176             :   KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
     177             :   {
     178             :     return _wrapper_device->timeIntegral(t1, t2, p);
     179             :   }
     180             :   KOKKOS_FUNCTION Real integral() const { return _wrapper_device->integral(); }
     181             :   KOKKOS_FUNCTION Real average() const { return _wrapper_device->average(); }
     182             : 
     183             : private:
     184             :   /**
     185             :    * Pointer to the host function wrapper
     186             :    */
     187             :   std::shared_ptr<FunctionWrapperHostBase> _wrapper_host;
     188             :   /**
     189             :    * Pointer to the device function wrapper
     190             :    */
     191             :   FunctionWrapperDeviceBase * _wrapper_device = nullptr;
     192             : };
     193             : 
     194             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14