LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosVectorKernelValue.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 329044 Lines: 12 32 37.5 %
Date: 2026-08-03 21:12:22 Functions: 8 18 44.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "KokkosVectorKernel.h"
      13             : 
      14             : namespace Moose::Kokkos
      15             : {
      16             : 
      17             : /**
      18             :  * The base class for Kokkos vector kernels where the residual is of the form
      19             :  *
      20             :  * $(\dots, \psi_i)$
      21             :  *
      22             :  * i.e. the vector test function $(\psi_i)$ can be factored out for optimization.
      23             :  */
      24             : class VectorKernelValue : public VectorKernel
      25             : {
      26             : public:
      27             :   static InputParameters validParams();
      28             : 
      29             :   /// VectorKernelValue hooks factor out the test function
      30             :   static constexpr bool use_precompute_hooks = true;
      31             : 
      32             :   /**
      33             :    * Constructor
      34             :    */
      35             :   VectorKernelValue(const InputParameters & parameters);
      36             : 
      37             :   /**
      38             :    * Default methods to prevent compile errors even when these methods were not defined in the
      39             :    * derived class
      40             :    */
      41             :   ///@{
      42             :   template <typename Derived>
      43           0 :   KOKKOS_FUNCTION Real3 precomputeQpJacobian(const unsigned int /* j */,
      44             :                                              const unsigned int /* qp */,
      45             :                                              AssemblyDatum & /* datum */) const
      46             :   {
      47           0 :     ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
      48             :                     "redefined this method in your class without typos.");
      49             : 
      50             :     return Real3(0);
      51             :   }
      52             :   template <typename Derived>
      53           0 :   KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int /* j */,
      54             :                                                     const unsigned int /* jvar */,
      55             :                                                     const unsigned int /* qp */,
      56             :                                                     AssemblyDatum & /* datum */) const
      57             :   {
      58           0 :     ::Kokkos::abort(
      59             :         "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
      60             :         "redefined this method in your class without typos.");
      61             : 
      62             :     return Real3(0);
      63             :   }
      64             :   ///@}
      65             : 
      66             :   /**
      67             :    * Functions used to check if users have overriden the hook methods, whose calculations can be
      68             :    * skipped when not overriden
      69             :    */
      70             :   ///@{
      71             :   template <typename Derived>
      72       82815 :   static auto defaultJacobian()
      73             :   {
      74       82815 :     return &VectorKernelValue::precomputeQpJacobian<Derived>;
      75             :   }
      76             :   template <typename Derived>
      77       82815 :   static auto defaultOffDiagJacobian()
      78             :   {
      79       82815 :     return &VectorKernelValue::precomputeQpOffDiagJacobian<Derived>;
      80             :   }
      81             :   ///@}
      82             : 
      83             :   /**
      84             :    * Optimized computation bodies that factor out the vector test function
      85             :    */
      86             :   ///@{
      87             :   template <typename Derived>
      88             :   KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
      89             :   template <typename Derived>
      90             :   KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
      91             :   template <typename Derived>
      92             :   KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
      93             :                                                       AssemblyDatum & datum) const;
      94             :   ///@}
      95             : };
      96             : 
      97             : template <typename Derived>
      98             : KOKKOS_FUNCTION void
      99      146121 : VectorKernelValue::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
     100             : {
     101      146121 :   ResidualObject::computeResidualInternal(
     102             :       datum,
     103      146121 :       [&](Real * local_re, const unsigned int ib, const unsigned int ie)
     104             :       {
     105     1174578 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     106             :         {
     107     1028457 :           Real3 value = datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum);
     108             : 
     109    17248833 :           for (unsigned int i = ib; i < ie; ++i)
     110    16220376 :             local_re[i] += value * _test(datum, i, qp);
     111             :         }
     112             :       });
     113      146121 : }
     114             : 
     115             : template <typename Derived>
     116             : KOKKOS_FUNCTION void
     117           0 : VectorKernelValue::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
     118             : {
     119           0 :   ResidualObject::computeJacobianInternal(
     120             :       datum,
     121           0 :       [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
     122             :       {
     123           0 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     124             :         {
     125           0 :           Real3 value = datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum);
     126             : 
     127           0 :           for (unsigned int i = ib; i < ie; ++i)
     128           0 :             local_ke[i] += value * _test(datum, i, qp);
     129             :         }
     130             :       });
     131           0 : }
     132             : 
     133             : template <typename Derived>
     134             : KOKKOS_FUNCTION void
     135           0 : VectorKernelValue::computeOffDiagJacobianInternal(const Derived & kernel,
     136             :                                                   AssemblyDatum & datum) const
     137             : {
     138           0 :   ResidualObject::computeJacobianInternal(
     139             :       datum,
     140           0 :       [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
     141             :       {
     142           0 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     143             :         {
     144           0 :           Real3 value = datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
     145             :                                             j, datum.jvar(), qp, datum);
     146             : 
     147           0 :           for (unsigned int i = ib; i < ie; ++i)
     148           0 :             local_ke[i] += value * _test(datum, i, qp);
     149             :         }
     150             :       });
     151           0 : }
     152             : 
     153             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14