LCOV - code coverage report
Current view: top level - include/kokkos/base - KokkosDatum.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 59 59 100.0 %
Date: 2025-09-22 20:01:15 Functions: 22 22 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
      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     3628874 :   Datum(const ContiguousElementID elem,
      37             :         const unsigned int side,
      38             :         const Assembly & assembly,
      39             :         const Array<System> & systems)
      40     3628874 :     : _assembly(assembly),
      41     3628874 :       _systems(systems),
      42     3628874 :       _elem(assembly.kokkosMesh().getElementInfo(elem)),
      43     3628874 :       _side(side),
      44     3628874 :       _neighbor(_side != libMesh::invalid_uint ? assembly.kokkosMesh().getNeighbor(_elem.id, side)
      45             :                                                : libMesh::DofObject::invalid_id),
      46     3628874 :       _n_qps(side == libMesh::invalid_uint ? assembly.getNumQps(_elem)
      47       94030 :                                            : assembly.getNumFaceQps(_elem, side)),
      48     3628874 :       _qp_offset(side == libMesh::invalid_uint ? assembly.getQpOffset(_elem)
      49     3628874 :                                                : assembly.getQpFaceOffset(_elem, side))
      50             :   {
      51     3628874 :   }
      52             :   /**
      53             :    * Constructor for elemental data
      54             :    * @param elem The contiguous element ID of the current thread
      55             :    * @param assembly The Kokkos assembly
      56             :    * @param systems The Kokkos systems
      57             :    */
      58             :   KOKKOS_FUNCTION
      59      662828 :   Datum(const ContiguousElementID elem, const Assembly & assembly, const Array<System> & systems)
      60      662828 :     : Datum(elem, libMesh::invalid_uint, assembly, systems)
      61             :   {
      62      662828 :   }
      63             : 
      64             :   /**
      65             :    * Get the Kokkos assembly
      66             :    * @returns The Kokkos assembly
      67             :    */
      68   100928932 :   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    41646884 :   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   158594844 :   KOKKOS_FUNCTION const ElementInfo & elem() const { return _elem; }
      81             :   /**
      82             :    * Get the contiguous subdomain ID
      83             :    * @returns The contiguous subdomain ID
      84             :    */
      85    25810976 :   KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const { return _elem.subdomain; }
      86             :   /**
      87             :    * Get the side index
      88             :    * @returns The side index
      89             :    */
      90   142575816 :   KOKKOS_FUNCTION unsigned int side() const { return _side; }
      91             :   /**
      92             :    * Get the number of local quadrature points
      93             :    * @returns The number of local quadrature points
      94             :    */
      95    18415752 :   KOKKOS_FUNCTION unsigned int n_qps() const { return _n_qps; }
      96             :   /**
      97             :    * Get the starting offset into the global quadrature point index
      98             :    * @returns The starting offset
      99             :    */
     100    67457860 :   KOKKOS_FUNCTION dof_id_type qpOffset() const { return _qp_offset; }
     101             :   /**
     102             :    * Get whether the current side has a neighbor
     103             :    * @returns Whether the current side has a neighbor
     104             :    */
     105             :   KOKKOS_FUNCTION bool hasNeighbor() const { return _neighbor != libMesh::DofObject::invalid_id; }
     106             : 
     107             :   /**
     108             :    * Get the inverse of Jacobian matrix
     109             :    * | dxi/dx deta/dx dzeta/dx |
     110             :    * | dxi/dy deta/dy dzeta/dy |
     111             :    * | dxi/dz deta/dz dzeta/dz |
     112             :    * @param qp The local quadrature point index
     113             :    * @returns The Jacobian matrix
     114             :    */
     115    54389984 :   KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
     116             :   {
     117    54389984 :     reinitTransform(qp);
     118             : 
     119    54389984 :     return _J;
     120             :   }
     121             :   /**
     122             :    * Get the transformed Jacobian weight
     123             :    * @param qp The local quadrature point index
     124             :    * @returns The transformed Jacobian weights
     125             :    */
     126    71564148 :   KOKKOS_FUNCTION Real JxW(const unsigned int qp)
     127             :   {
     128    71564148 :     reinitTransform(qp);
     129             : 
     130    71564148 :     return _JxW;
     131             :   }
     132             :   /**
     133             :    * Get the physical quadrature point coordinate
     134             :    * @param qp The local quadrature point index
     135             :    * @returns The physical quadrature point coordinate
     136             :    */
     137      106848 :   KOKKOS_FUNCTION Real3 q_point(const unsigned int qp)
     138             :   {
     139      106848 :     reinitTransform(qp);
     140             : 
     141      106848 :     return _xyz;
     142             :   }
     143             : 
     144             :   /**
     145             :    * Reset the reinit flag
     146             :    */
     147    14739262 :   KOKKOS_FUNCTION void reinit() { _transform_reinit = false; }
     148             : 
     149             : protected:
     150             :   /**
     151             :    * Reference of the Kokkos assembly
     152             :    */
     153             :   const Assembly & _assembly;
     154             :   /**
     155             :    * Reference of the Kokkos systems
     156             :    */
     157             :   const Array<System> & _systems;
     158             :   /**
     159             :    * Current element information object
     160             :    */
     161             :   const ElementInfo _elem;
     162             :   /**
     163             :    * Current side index
     164             :    */
     165             :   const unsigned int _side;
     166             :   /**
     167             :    * Current contiguous element ID of neighbor
     168             :    */
     169             :   const ContiguousElementID _neighbor;
     170             :   /**
     171             :    * Number of local quadrature points
     172             :    */
     173             :   const unsigned int _n_qps;
     174             :   /**
     175             :    * Starting offset into the global quadrature point index
     176             :    */
     177             :   const dof_id_type _qp_offset;
     178             : 
     179             : private:
     180             :   /**
     181             :    * Compute and cache the physical transformation data
     182             :    * @param qp The local quadrature point index
     183             :    */
     184             :   KOKKOS_FUNCTION void reinitTransform(const unsigned int qp);
     185             : 
     186             :   /**
     187             :    * Flag whether the physical transformation data was cached
     188             :    */
     189             :   bool _transform_reinit = false;
     190             :   /**
     191             :    * Cached physical transformation data
     192             :    */
     193             :   ///@{
     194             :   Real33 _J;
     195             :   Real _JxW;
     196             :   Real3 _xyz;
     197             :   ///@}
     198             : };
     199             : 
     200             : KOKKOS_FUNCTION inline void
     201   126060980 : Datum::reinitTransform(const unsigned int qp)
     202             : {
     203   126060980 :   if (_transform_reinit)
     204   114378422 :     return;
     205             : 
     206    11682558 :   if (_side == libMesh::invalid_uint)
     207             :   {
     208    11593104 :     _J = _assembly.getJacobian(_elem, qp);
     209    11593104 :     _JxW = _assembly.getJxW(_elem, qp);
     210    11593104 :     _xyz = _assembly.getQPoint(_elem, qp);
     211             :   }
     212             :   else
     213       89454 :     _assembly.computePhysicalMap(_elem, _side, qp, &_J, &_JxW, &_xyz);
     214             : 
     215    11682558 :   _transform_reinit = true;
     216             : }
     217             : 
     218             : /**
     219             :  * The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual
     220             :  * objects
     221             :  */
     222             : class ResidualDatum : public Datum
     223             : {
     224             : public:
     225             :   /**
     226             :    * Constructor
     227             :    * @param elem The contiguous element ID of the current thread
     228             :    * @param side The side index of the current thread
     229             :    * @param assembly The Kokkos assembly
     230             :    * @param systems The Kokkos systems
     231             :    * @param ivar The Kokkos variable
     232             :    * @param jvar The coupled variable number
     233             :    * @param comp The variable component
     234             :    */
     235             :   KOKKOS_FUNCTION
     236     2916606 :   ResidualDatum(const ContiguousElementID elem,
     237             :                 const unsigned int side,
     238             :                 const Assembly & assembly,
     239             :                 const Array<System> & systems,
     240             :                 const Variable & ivar,
     241             :                 const unsigned int jvar,
     242             :                 const unsigned int comp = 0)
     243     2916606 :     : Datum(elem, side, assembly, systems),
     244     2916606 :       _tag(ivar.tag()),
     245     2916606 :       _ivar(ivar.var(comp)),
     246     2916606 :       _jvar(jvar),
     247     2916606 :       _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
     248     2916606 :       _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar)),
     249     2916606 :       _n_idofs(assembly.getNumDofs(_elem.type, _ife)),
     250     5833212 :       _n_jdofs(assembly.getNumDofs(_elem.type, _jfe))
     251             :   {
     252     2916606 :   }
     253             :   /**
     254             :    * Constructor for elemental data
     255             :    * @param elem The contiguous element ID of the current thread
     256             :    * @param assembly The Kokkos assembly
     257             :    * @param systems The Kokkos systems
     258             :    * @param ivar The Kokkos variable
     259             :    * @param jvar The coupled variable number
     260             :    * @param comp The variable component
     261             :    */
     262             :   KOKKOS_FUNCTION
     263     2872016 :   ResidualDatum(const ContiguousElementID elem,
     264             :                 const Assembly & assembly,
     265             :                 const Array<System> & systems,
     266             :                 const Variable & ivar,
     267             :                 const unsigned int jvar,
     268             :                 const unsigned int comp = 0)
     269     2872016 :     : ResidualDatum(elem, libMesh::invalid_uint, assembly, systems, ivar, jvar, comp)
     270             :   {
     271     2872016 :   }
     272             : 
     273             :   /**
     274             :    * Get the number of local DOFs
     275             :    * @returns The number of local DOFs
     276             :    */
     277     7476900 :   KOKKOS_FUNCTION unsigned int n_dofs() const { return _n_idofs; }
     278             :   /**
     279             :    * Get the number of local DOFs
     280             :    * @returns The number of local DOFs
     281             :    */
     282     1320534 :   KOKKOS_FUNCTION unsigned int n_idofs() const { return _n_idofs; }
     283             :   /**
     284             :    * Get the number of local DOFs for the coupled variable
     285             :    * @returns The number of local DOFs
     286             :    */
     287    72301942 :   KOKKOS_FUNCTION unsigned int n_jdofs() const { return _n_jdofs; }
     288             :   /**
     289             :    * Get the variable number
     290             :    * @returns The variable number
     291             :    */
     292             :   KOKKOS_FUNCTION unsigned int var() const { return _ivar; }
     293             :   /**
     294             :    * Get the variable number
     295             :    * @returns The variable number
     296             :    */
     297             :   KOKKOS_FUNCTION unsigned int ivar() const { return _ivar; }
     298             :   /**
     299             :    * Get the coupled variable number
     300             :    * @returns The variable number
     301             :    */
     302     6208304 :   KOKKOS_FUNCTION unsigned int jvar() const { return _jvar; }
     303             :   /**
     304             :    * Get the variable FE type ID
     305             :    * @returns The variable FE type ID
     306             :    */
     307             :   KOKKOS_FUNCTION unsigned int fe() const { return _ife; }
     308             :   /**
     309             :    * Get the variable FE type ID
     310             :    * @returns The variable FE type ID
     311             :    */
     312    71568756 :   KOKKOS_FUNCTION unsigned int ife() const { return _ife; }
     313             :   /**
     314             :    * Get the coupled variable FE type ID
     315             :    * @returns The variable FE type ID
     316             :    */
     317    29360176 :   KOKKOS_FUNCTION unsigned int jfe() const { return _jfe; }
     318             : 
     319             : protected:
     320             :   /**
     321             :    * Solution tag ID
     322             :    */
     323             :   const TagID _tag;
     324             :   /**
     325             :    * Variable numbers
     326             :    */
     327             :   const unsigned int _ivar, _jvar;
     328             :   /**
     329             :    * FE type IDs of variables
     330             :    */
     331             :   const unsigned int _ife, _jfe;
     332             :   /**
     333             :    * Number of local DOFs
     334             :    */
     335             :   const unsigned int _n_idofs, _n_jdofs;
     336             : };
     337             : 
     338             : } // namespace Kokkos
     339             : } // namespace Moose
     340             : 
     341             : using Datum = Moose::Kokkos::Datum;
     342             : using ResidualDatum = Moose::Kokkos::ResidualDatum;

Generated by: LCOV version 1.14