LCOV - code coverage report
Current view: top level - include/kokkos/base - KokkosDatum.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 70 73 95.9 %
Date: 2025-10-29 16:49:47 Functions: 24 24 100.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 "KokkosTypes.h"
      13             : #include "KokkosAssembly.h"
      14             : #include "KokkosSystem.h"
      15             : #include "KokkosVariable.h"
      16             : 
      17             : namespace Moose
      18             : {
      19             : namespace Kokkos
      20             : {
      21             : 
      22             : /**
      23             :  * The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object
      24             :  */
      25             : class Datum
      26             : {
      27             : public:
      28             :   /**
      29             :    * Constructor for element and side data
      30             :    * @param elem The contiguous element ID of the current thread
      31             :    * @param side The side index of the current thread
      32             :    * @param assembly The Kokkos assembly
      33             :    * @param systems The Kokkos systems
      34             :    */
      35             :   KOKKOS_FUNCTION
      36     4084195 :   Datum(const ContiguousElementID elem,
      37             :         const unsigned int side,
      38             :         const Assembly & assembly,
      39             :         const Array<System> & systems)
      40     4084195 :     : _assembly(assembly),
      41     4084195 :       _systems(systems),
      42     4084195 :       _elem(assembly.kokkosMesh().getElementInfo(elem)),
      43     4084195 :       _side(side),
      44     3962405 :       _neighbor(_side == libMesh::invalid_uint ? libMesh::DofObject::invalid_id
      45      121790 :                                                : assembly.kokkosMesh().getNeighbor(_elem.id, side)),
      46     4084195 :       _n_qps(side == libMesh::invalid_uint ? assembly.getNumQps(_elem)
      47      121790 :                                            : assembly.getNumFaceQps(_elem, side)),
      48     4084195 :       _qp_offset(side == libMesh::invalid_uint ? assembly.getQpOffset(_elem)
      49     8168390 :                                                : assembly.getQpFaceOffset(_elem, side))
      50             :   {
      51     4084195 :   }
      52             :   /**
      53             :    * Constructor for node data
      54             :    * @param node The contiguous node ID of the current thread
      55             :    * @param assembly The Kokkos assembly
      56             :    * @param systems The Kokkos systems
      57             :    */
      58             :   KOKKOS_FUNCTION
      59     2612340 :   Datum(const ContiguousNodeID node, const Assembly & assembly, const Array<System> & systems)
      60     2612340 :     : _assembly(assembly), _systems(systems), _node(node)
      61             :   {
      62     2612340 :   }
      63             : 
      64             :   /**
      65             :    * Get the Kokkos assembly
      66             :    * @returns The Kokkos assembly
      67             :    */
      68   164798908 :   KOKKOS_FUNCTION const Assembly & assembly() const { return _assembly; }
      69             :   /**
      70             :    * Get the Kokkos system
      71             :    * @param sys The system number
      72             :    * @returns The Kokkos system
      73             :    */
      74    51598818 :   KOKKOS_FUNCTION const System & system(unsigned int sys) const { return _systems[sys]; }
      75             : 
      76             :   /**
      77             :    * Get the element information object
      78             :    * @returns The element information object
      79             :    */
      80   228805236 :   KOKKOS_FUNCTION const ElementInfo & elem() const { return _elem; }
      81             :   /**
      82             :    * Get the contiguous subdomain ID
      83             :    * @returns The contiguous subdomain ID
      84             :    */
      85    38098064 :   KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const { return _elem.subdomain; }
      86             :   /**
      87             :    * Get the side index
      88             :    * @returns The side index
      89             :    */
      90   212573296 :   KOKKOS_FUNCTION unsigned int side() const { return _side; }
      91             :   /**
      92             :    * Get the contiguous node ID
      93             :    * @returns The contiguous node ID
      94             :    */
      95     4733920 :   KOKKOS_FUNCTION ContiguousNodeID node() const { return _node; }
      96             :   /**
      97             :    * Get the number of local quadrature points
      98             :    * @returns The number of local quadrature points
      99             :    */
     100    25195863 :   KOKKOS_FUNCTION unsigned int n_qps() const { return _n_qps; }
     101             :   /**
     102             :    * Get the starting offset into the global quadrature point index
     103             :    * @returns The starting offset
     104             :    */
     105    85872452 :   KOKKOS_FUNCTION dof_id_type qpOffset() const { return _qp_offset; }
     106             :   /**
     107             :    * Get whether the current side has a neighbor
     108             :    * @returns Whether the current side has a neighbor
     109             :    */
     110             :   KOKKOS_FUNCTION bool hasNeighbor() const { return _neighbor != libMesh::DofObject::invalid_id; }
     111             :   /**
     112             :    * Get whether the current datum is on a node
     113             :    * @returns Whether the current datum is on a node
     114             :    */
     115   151887722 :   KOKKOS_FUNCTION bool isNodal() const { return _node != libMesh::DofObject::invalid_id; }
     116             : 
     117             :   /**
     118             :    * Get the inverse of Jacobian matrix
     119             :    * | dxi/dx deta/dx dzeta/dx |
     120             :    * | dxi/dy deta/dy dzeta/dy |
     121             :    * | dxi/dz deta/dz dzeta/dz |
     122             :    * @param qp The local quadrature point index
     123             :    * @returns The Jacobian matrix
     124             :    */
     125    59819184 :   KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
     126             :   {
     127    59819184 :     if (!isNodal())
     128    59819184 :       reinitTransform(qp);
     129             :     else
     130           0 :       _J.identity(_assembly.getDimension());
     131             : 
     132    59819184 :     return _J;
     133             :   }
     134             :   /**
     135             :    * Get the transformed Jacobian weight
     136             :    * @param qp The local quadrature point index
     137             :    * @returns The transformed Jacobian weights
     138             :    */
     139    88096300 :   KOKKOS_FUNCTION Real JxW(const unsigned int qp)
     140             :   {
     141    88096300 :     if (!isNodal())
     142    88096300 :       reinitTransform(qp);
     143             :     else
     144           0 :       _JxW = 1;
     145             : 
     146    88096300 :     return _JxW;
     147             :   }
     148             :   /**
     149             :    * Get the physical quadrature point coordinate
     150             :    * @param qp The local quadrature point index
     151             :    * @returns The physical quadrature point coordinate
     152             :    */
     153      147808 :   KOKKOS_FUNCTION Real3 q_point(const unsigned int qp)
     154             :   {
     155      147808 :     if (!isNodal())
     156      147808 :       reinitTransform(qp);
     157             :     else
     158           0 :       _xyz = _assembly.kokkosMesh().getNodePoint(_node);
     159             : 
     160      147808 :     return _xyz;
     161             :   }
     162             : 
     163             :   /**
     164             :    * Reset the reinit flag
     165             :    */
     166    21064652 :   KOKKOS_FUNCTION void reinit() { _transform_reinit = false; }
     167             : 
     168             : protected:
     169             :   /**
     170             :    * Reference of the Kokkos assembly
     171             :    */
     172             :   const Assembly & _assembly;
     173             :   /**
     174             :    * Reference of the Kokkos systems
     175             :    */
     176             :   const Array<System> & _systems;
     177             :   /**
     178             :    * Current element information object
     179             :    */
     180             :   const ElementInfo _elem;
     181             :   /**
     182             :    * Current side index
     183             :    */
     184             :   const unsigned int _side = libMesh::invalid_uint;
     185             :   /**
     186             :    * Current contiguous node ID
     187             :    */
     188             :   const ContiguousNodeID _node = libMesh::DofObject::invalid_id;
     189             :   /**
     190             :    * Current contiguous element ID of neighbor
     191             :    */
     192             :   const ContiguousElementID _neighbor = libMesh::DofObject::invalid_id;
     193             :   /**
     194             :    * Number of local quadrature points
     195             :    */
     196             :   const unsigned int _n_qps = 1;
     197             :   /**
     198             :    * Starting offset into the global quadrature point index
     199             :    */
     200             :   const dof_id_type _qp_offset = libMesh::DofObject::invalid_id;
     201             : 
     202             : private:
     203             :   /**
     204             :    * Compute and cache the physical transformation data
     205             :    * @param qp The local quadrature point index
     206             :    */
     207             :   KOKKOS_FUNCTION void reinitTransform(const unsigned int qp);
     208             : 
     209             :   /**
     210             :    * Flag whether the physical transformation data was cached
     211             :    */
     212             :   bool _transform_reinit = false;
     213             :   /**
     214             :    * Cached physical transformation data
     215             :    */
     216             :   ///@{
     217             :   Real33 _J;
     218             :   Real _JxW;
     219             :   Real3 _xyz;
     220             :   ///@}
     221             : };
     222             : 
     223             : KOKKOS_FUNCTION inline void
     224   148063292 : Datum::reinitTransform(const unsigned int qp)
     225             : {
     226   148063292 :   if (_transform_reinit)
     227   132852488 :     return;
     228             : 
     229    15210804 :   if (_side == libMesh::invalid_uint)
     230             :   {
     231    15104840 :     _J = _assembly.getJacobian(_elem, qp);
     232    15104840 :     _JxW = _assembly.getJxW(_elem, qp);
     233    15104840 :     _xyz = _assembly.getQPoint(_elem, qp);
     234             :   }
     235             :   else
     236      105964 :     _assembly.computePhysicalMap(_elem, _side, qp, &_J, &_JxW, &_xyz);
     237             : 
     238    15210804 :   _transform_reinit = true;
     239             : }
     240             : 
     241             : /**
     242             :  * The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels
     243             :  */
     244             : class AssemblyDatum : public Datum
     245             : {
     246             : public:
     247             :   /**
     248             :    * Constructor for element and side data
     249             :    * @param elem The contiguous element ID of the current thread
     250             :    * @param side The side index of the current thread
     251             :    * @param assembly The Kokkos assembly
     252             :    * @param systems The Kokkos systems
     253             :    * @param ivar The Kokkos variable
     254             :    * @param jvar The coupled variable number
     255             :    * @param comp The variable component
     256             :    */
     257             :   KOKKOS_FUNCTION
     258     3127259 :   AssemblyDatum(const ContiguousElementID elem,
     259             :                 const unsigned int side,
     260             :                 const Assembly & assembly,
     261             :                 const Array<System> & systems,
     262             :                 const Variable & ivar,
     263             :                 const unsigned int jvar,
     264             :                 const unsigned int comp = 0)
     265     3127259 :     : Datum(elem, side, assembly, systems),
     266     3127259 :       _tag(ivar.tag()),
     267     3127259 :       _ivar(ivar.var(comp)),
     268     3127259 :       _jvar(jvar),
     269     3127259 :       _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
     270     3127259 :       _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar)),
     271     3127259 :       _n_idofs(assembly.getNumDofs(_elem.type, _ife)),
     272     6254518 :       _n_jdofs(assembly.getNumDofs(_elem.type, _jfe))
     273             :   {
     274     3127259 :   }
     275             :   /**
     276             :    * Constructor for node data
     277             :    * @param elem The contiguous element ID of the current thread
     278             :    * @param assembly The Kokkos assembly
     279             :    * @param systems The Kokkos systems
     280             :    * @param ivar The Kokkos variable
     281             :    * @param jvar The coupled variable number
     282             :    * @param comp The variable component
     283             :    */
     284             :   KOKKOS_FUNCTION
     285     2612340 :   AssemblyDatum(const ContiguousNodeID node,
     286             :                 const Assembly & assembly,
     287             :                 const Array<System> & systems,
     288             :                 const Variable & ivar,
     289             :                 const unsigned int jvar,
     290             :                 const unsigned int comp = 0)
     291     2612340 :     : Datum(node, assembly, systems),
     292     2612340 :       _tag(ivar.tag()),
     293     2612340 :       _ivar(ivar.var(comp)),
     294     2612340 :       _jvar(jvar),
     295     2612340 :       _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
     296     5224680 :       _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar))
     297             :   {
     298     2612340 :   }
     299             : 
     300             :   /**
     301             :    * Get the number of local DOFs
     302             :    * @returns The number of local DOFs
     303             :    */
     304   128646122 :   KOKKOS_FUNCTION unsigned int n_dofs() const { return _n_idofs; }
     305             :   /**
     306             :    * Get the number of local DOFs
     307             :    * @returns The number of local DOFs
     308             :    */
     309     1320591 :   KOKKOS_FUNCTION unsigned int n_idofs() const { return _n_idofs; }
     310             :   /**
     311             :    * Get the number of local DOFs for the coupled variable
     312             :    * @returns The number of local DOFs
     313             :    */
     314    77041039 :   KOKKOS_FUNCTION unsigned int n_jdofs() const { return _n_jdofs; }
     315             :   /**
     316             :    * Get the variable number
     317             :    * @returns The variable number
     318             :    */
     319             :   KOKKOS_FUNCTION unsigned int var() const { return _ivar; }
     320             :   /**
     321             :    * Get the variable number
     322             :    * @returns The variable number
     323             :    */
     324             :   KOKKOS_FUNCTION unsigned int ivar() const { return _ivar; }
     325             :   /**
     326             :    * Get the coupled variable number
     327             :    * @returns The variable number
     328             :    */
     329     6208608 :   KOKKOS_FUNCTION unsigned int jvar() const { return _jvar; }
     330             :   /**
     331             :    * Get the variable FE type ID
     332             :    * @returns The variable FE type ID
     333             :    */
     334             :   KOKKOS_FUNCTION unsigned int fe() const { return _ife; }
     335             :   /**
     336             :    * Get the variable FE type ID
     337             :    * @returns The variable FE type ID
     338             :    */
     339   133069516 :   KOKKOS_FUNCTION unsigned int ife() const { return _ife; }
     340             :   /**
     341             :    * Get the coupled variable FE type ID
     342             :    * @returns The variable FE type ID
     343             :    */
     344    31729392 :   KOKKOS_FUNCTION unsigned int jfe() const { return _jfe; }
     345             : 
     346             : protected:
     347             :   /**
     348             :    * Solution tag ID
     349             :    */
     350             :   const TagID _tag;
     351             :   /**
     352             :    * Variable numbers
     353             :    */
     354             :   const unsigned int _ivar, _jvar;
     355             :   /**
     356             :    * FE type IDs of variables
     357             :    */
     358             :   const unsigned int _ife, _jfe;
     359             :   /**
     360             :    * Number of local DOFs
     361             :    */
     362             :   const unsigned int _n_idofs = 1, _n_jdofs = 1;
     363             : };
     364             : 
     365             : } // namespace Kokkos
     366             : } // namespace Moose
     367             : 
     368             : using Datum = Moose::Kokkos::Datum;
     369             : using AssemblyDatum = Moose::Kokkos::AssemblyDatum;

Generated by: LCOV version 1.14