LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosTimeDerivative.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 33 35 94.3 %
Date: 2026-05-29 20:35:17 Functions: 6 7 85.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 "KokkosTimeKernel.h"
      13             : 
      14             : class KokkosTimeDerivative : public Moose::Kokkos::TimeKernel
      15             : {
      16             : public:
      17             :   static InputParameters validParams();
      18             : 
      19             :   KokkosTimeDerivative(const InputParameters & parameters);
      20             : 
      21             :   template <typename Derived>
      22             :   KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
      23             :   template <typename Derived>
      24             :   KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
      25             : 
      26             :   template <typename Derived>
      27             :   KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
      28             :   template <typename Derived>
      29             :   KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int j,
      30             :                                          const unsigned int qp,
      31             :                                          AssemblyDatum & datum) const;
      32             :   template <typename Derived>
      33           0 :   KOKKOS_FUNCTION Real computeQpJacobianDummy(const unsigned int,
      34             :                                               const unsigned int,
      35             :                                               AssemblyDatum &) const
      36             :   {
      37           0 :     return 0;
      38             :   }
      39             : 
      40             :   // The computeQpJacobian() of this class has the same signature with that of KernelValue (without
      41             :   // test function index), but this class itself derives from TimeKernel whose base class is Kernel
      42             :   // (with test function index). Therefore, their function pointers cannot be compared. Instead, we
      43             :   // provide the function pointer of a dummy function to the dispatcher registry to make it think
      44             :   // that non-default computeQpJacobian() was implemented.
      45             :   template <typename Derived>
      46       40355 :   static auto defaultJacobian()
      47             :   {
      48       40355 :     return &KokkosTimeDerivative::computeQpJacobianDummy<Derived>;
      49             :   }
      50             : 
      51             : protected:
      52             :   const bool _lumping;
      53             : };
      54             : 
      55             : template <typename Derived>
      56             : KOKKOS_FUNCTION void
      57     6864592 : KokkosTimeDerivative::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
      58             : {
      59     6864592 :   ResidualObject::computeResidualInternal(
      60             :       datum,
      61    13729184 :       [&](Real * local_re, const unsigned int ib, const unsigned int ie)
      62             :       {
      63    37660752 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
      64             :         {
      65    30796160 :           Real value = datum.JxW(qp) * kernel.template computeQpResidual<Derived>(qp, datum);
      66             : 
      67    63312544 :           for (unsigned int i = ib; i < ie; ++i)
      68    32516384 :             local_re[i] += value * _test(datum, i, qp);
      69             :         }
      70             :       });
      71     6864592 : }
      72             : 
      73             : template <typename Derived>
      74             : KOKKOS_FUNCTION void
      75     1207476 : KokkosTimeDerivative::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
      76             : {
      77             :   using Moose::Kokkos::MAX_CACHED_DOF;
      78             : 
      79             :   Real local_ke[MAX_CACHED_DOF];
      80             : 
      81     2313328 :   for (unsigned int j = datum.local_thread_id(); j < datum.n_jdofs();
      82     1105852 :        j += datum.num_local_threads())
      83             :   {
      84     1105852 :     unsigned int num_batches = datum.n_idofs() / MAX_CACHED_DOF;
      85             : 
      86     1105852 :     if (datum.n_idofs() % MAX_CACHED_DOF)
      87     1105852 :       ++num_batches;
      88             : 
      89     2211704 :     for (unsigned int batch = 0; batch < num_batches; ++batch)
      90             :     {
      91     1105852 :       unsigned int ib = batch * MAX_CACHED_DOF;
      92     1105852 :       unsigned int ie = ::Kokkos::min(ib + MAX_CACHED_DOF, datum.n_idofs());
      93             : 
      94     5611708 :       for (unsigned int i = ib; i < ie; ++i)
      95     4505856 :         local_ke[i - ib] = 0;
      96             : 
      97     5907708 :       for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
      98             :       {
      99     4801856 :         Real value = datum.JxW(qp) * kernel.template computeQpJacobian<Derived>(j, qp, datum);
     100             : 
     101    26459744 :         for (unsigned int i = ib; i < ie; ++i)
     102    21657888 :           local_ke[i - ib] += value * _test(datum, i, qp);
     103             :       }
     104             : 
     105     5611708 :       for (unsigned int i = ib; i < ie; ++i)
     106     9011712 :         accumulateTaggedElementalMatrix(
     107     9011712 :             local_ke[i - ib], datum.elem().id, i, _lumping ? i : j, datum.jvar());
     108             :     }
     109             :   }
     110     1207476 : }
     111             : 
     112             : template <typename Derived>
     113             : KOKKOS_FUNCTION Real
     114    30796160 : KokkosTimeDerivative::computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const
     115             : {
     116    30796160 :   return _u_dot(datum, qp);
     117             : }
     118             : 
     119             : template <typename Derived>
     120             : KOKKOS_FUNCTION Real
     121     4801856 : KokkosTimeDerivative::computeQpJacobian(const unsigned int j,
     122             :                                         const unsigned int qp,
     123             :                                         AssemblyDatum & datum) const
     124             : {
     125     4801856 :   return _phi(datum, j, qp) * _du_dot_du;
     126             : }

Generated by: LCOV version 1.14