LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosVectorKernelGrad.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 329044 Lines: 22 35 62.9 %
Date: 2026-08-03 21:12:22 Functions: 6 10 60.0 %
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, \nabla\psi_i)$
      21             :  *
      22             :  * i.e. the gradient of the vector test function $(\nabla\psi_i)$ can be factored out for
      23             :  * optimization.
      24             :  */
      25             : class VectorKernelGrad : public VectorKernel
      26             : {
      27             : public:
      28             :   static InputParameters validParams();
      29             : 
      30             :   /// VectorKernelGrad hooks factor out the test-function gradient
      31             :   static constexpr bool use_precompute_hooks = true;
      32             : 
      33             :   /**
      34             :    * Constructor
      35             :    */
      36             :   VectorKernelGrad(const InputParameters & parameters);
      37             : 
      38             :   /**
      39             :    * Default methods to prevent compile errors even when these methods were not defined in the
      40             :    * derived class
      41             :    */
      42             :   ///@{
      43             :   template <typename Derived>
      44           0 :   KOKKOS_FUNCTION Real33 precomputeQpJacobian(const unsigned int /* j */,
      45             :                                               const unsigned int /* qp */,
      46             :                                               AssemblyDatum & /* datum */) const
      47             :   {
      48           0 :     ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
      49             :                     "redefined this method in your class without typos.");
      50             : 
      51             :     return Real33(0);
      52             :   }
      53             :   template <typename Derived>
      54           0 :   KOKKOS_FUNCTION Real33 precomputeQpOffDiagJacobian(const unsigned int /* j */,
      55             :                                                      const unsigned int /* jvar */,
      56             :                                                      const unsigned int /* qp */,
      57             :                                                      AssemblyDatum & /* datum */) const
      58             :   {
      59           0 :     ::Kokkos::abort(
      60             :         "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
      61             :         "redefined this method in your class without typos.");
      62             : 
      63             :     return Real33(0);
      64             :   }
      65             :   ///@}
      66             : 
      67             :   /**
      68             :    * Functions used to check if users have overriden the hook methods, whose calculations can be
      69             :    * skipped when not overriden
      70             :    */
      71             :   ///@{
      72             :   template <typename Derived>
      73       41416 :   static auto defaultJacobian()
      74             :   {
      75       41416 :     return &VectorKernelGrad::precomputeQpJacobian<Derived>;
      76             :   }
      77             :   template <typename Derived>
      78       41416 :   static auto defaultOffDiagJacobian()
      79             :   {
      80       41416 :     return &VectorKernelGrad::precomputeQpOffDiagJacobian<Derived>;
      81             :   }
      82             :   ///@}
      83             : 
      84             :   /**
      85             :    * Optimized computation bodies that factor out the vector test-function gradient
      86             :    */
      87             :   ///@{
      88             :   template <typename Derived>
      89             :   KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
      90             :   template <typename Derived>
      91             :   KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
      92             :   template <typename Derived>
      93             :   KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
      94             :                                                       AssemblyDatum & datum) const;
      95             :   ///@}
      96             : };
      97             : 
      98             : template <typename Derived>
      99             : KOKKOS_FUNCTION void
     100      168921 : VectorKernelGrad::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
     101             : {
     102      168921 :   ResidualObject::computeResidualInternal(
     103             :       datum,
     104      168921 :       [&](Real * local_re, const unsigned int ib, const unsigned int ie)
     105             :       {
     106     1288578 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     107             :         {
     108             :           Real33 value =
     109     1119657 :               (datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum)) *
     110     1119657 :               datum.J(qp);
     111             : 
     112    18069633 :           for (unsigned int i = ib; i < ie; ++i)
     113    16949976 :             local_re[i] += value.contract(_grad_test.reference(datum, i, qp));
     114             :         }
     115             :       });
     116      168921 : }
     117             : 
     118             : template <typename Derived>
     119             : KOKKOS_FUNCTION void
     120       42676 : VectorKernelGrad::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
     121             : {
     122       42676 :   ResidualObject::computeJacobianInternal(
     123             :       datum,
     124      367448 :       [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
     125             :       {
     126     2079664 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     127             :         {
     128             :           Real33 value =
     129     1712216 :               (datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum)) *
     130     1712216 :               datum.J(qp);
     131             : 
     132    19775304 :           for (unsigned int i = ib; i < ie; ++i)
     133    18063088 :             local_ke[i] += value.contract(_grad_test.reference(datum, i, qp));
     134             :         }
     135             :       });
     136       42676 : }
     137             : 
     138             : template <typename Derived>
     139             : KOKKOS_FUNCTION void
     140           0 : VectorKernelGrad::computeOffDiagJacobianInternal(const Derived & kernel,
     141             :                                                  AssemblyDatum & datum) const
     142             : {
     143           0 :   ResidualObject::computeJacobianInternal(
     144             :       datum,
     145           0 :       [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
     146             :       {
     147           0 :         for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
     148             :         {
     149             :           Real33 value = (datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
     150           0 :                                               j, datum.jvar(), qp, datum)) *
     151           0 :                          datum.J(qp);
     152             : 
     153           0 :           for (unsigned int i = ib; i < ie; ++i)
     154           0 :             local_ke[i] += value.contract(_grad_test.reference(datum, i, qp));
     155             :         }
     156             :       });
     157           0 : }
     158             : 
     159             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14