LCOV - code coverage report
Current view: top level - include/kokkos/base - KokkosVariableValue.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 59 68 86.8 %
Date: 2025-09-22 20:01:15 Functions: 13 14 92.9 %
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 "KokkosDatum.h"
      13             : 
      14             : #include "MooseVariableBase.h"
      15             : 
      16             : namespace Moose
      17             : {
      18             : namespace Kokkos
      19             : {
      20             : 
      21             : /**
      22             :  * The Kokkos wrapper classes for MOOSE-like shape function access
      23             :  */
      24             : ///@{
      25             : class VariablePhiValue
      26             : {
      27             : public:
      28             :   /**
      29             :    * Get the current shape function
      30             :    * @param datum The ResidualDatum object of the current thread
      31             :    * @param i The element-local DOF index
      32             :    * @param qp The local quadrature point index
      33             :    * @returns The shape function
      34             :    */
      35    13613424 :   KOKKOS_FUNCTION Real operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
      36             :   {
      37    13613424 :     auto & elem = datum.elem();
      38    13613424 :     auto side = datum.side();
      39    13613424 :     auto fe = datum.jfe();
      40             : 
      41           0 :     return side == libMesh::invalid_uint
      42    13613424 :                ? datum.assembly().getPhi(elem.subdomain, elem.type, fe)(i, qp)
      43    13613424 :                : datum.assembly().getPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp);
      44             :   }
      45             : };
      46             : 
      47             : class VariablePhiGradient
      48             : {
      49             : public:
      50             :   /**
      51             :    * Get the gradient of the current shape function
      52             :    * @param datum The ResidualDatum object of the current thread
      53             :    * @param i The element-local DOF index
      54             :    * @param qp The local quadrature point index
      55             :    * @returns The gradient of the shape function
      56             :    */
      57    15746752 :   KOKKOS_FUNCTION Real3 operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
      58             :   {
      59    15746752 :     auto & elem = datum.elem();
      60    15746752 :     auto side = datum.side();
      61    15746752 :     auto fe = datum.jfe();
      62             : 
      63           0 :     return datum.J(qp) *
      64             :            (side == libMesh::invalid_uint
      65    15746752 :                 ? datum.assembly().getGradPhi(elem.subdomain, elem.type, fe)(i, qp)
      66    31493504 :                 : datum.assembly().getGradPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp));
      67             :   }
      68             : };
      69             : 
      70             : class VariableTestValue
      71             : {
      72             : public:
      73             :   /**
      74             :    * Get the current test function
      75             :    * @param datum The ResidualDatum object of the current thread
      76             :    * @param i The element-local DOF index
      77             :    * @param qp The local quadrature point index
      78             :    * @returns The test function
      79             :    */
      80    32925524 :   KOKKOS_FUNCTION Real operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
      81             :   {
      82    32925524 :     auto & elem = datum.elem();
      83    32925524 :     auto side = datum.side();
      84    32925524 :     auto fe = datum.ife();
      85             : 
      86           0 :     return side == libMesh::invalid_uint
      87    32925524 :                ? datum.assembly().getPhi(elem.subdomain, elem.type, fe)(i, qp)
      88    32925524 :                : datum.assembly().getPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp);
      89             :   }
      90             : };
      91             : 
      92             : class VariableTestGradient
      93             : {
      94             : public:
      95             :   /**
      96             :    * Get the gradient of the current test function
      97             :    * @param datum The ResidualDatum object of the current thread
      98             :    * @param i The element-local DOF index
      99             :    * @param qp The local quadrature point index
     100             :    * @returns The gradient of the test function
     101             :    */
     102    38643232 :   KOKKOS_FUNCTION Real3 operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
     103             :   {
     104    38643232 :     auto & elem = datum.elem();
     105    38643232 :     auto side = datum.side();
     106    38643232 :     auto fe = datum.ife();
     107             : 
     108           0 :     return datum.J(qp) *
     109             :            (side == libMesh::invalid_uint
     110    38643232 :                 ? datum.assembly().getGradPhi(elem.subdomain, elem.type, fe)(i, qp)
     111    77286464 :                 : datum.assembly().getGradPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp));
     112             :   }
     113             : };
     114             : ///@}
     115             : 
     116             : /**
     117             :  * The Kokkos wrapper classes for MOOSE-like variable value access
     118             :  */
     119             : ///@{
     120             : class VariableValue
     121             : {
     122             : public:
     123             :   /**
     124             :    * Constructor
     125             :    * @param var The Kokkos variable
     126             :    */
     127         501 :   VariableValue(Variable var) : _var(var) {}
     128             :   /**
     129             :    * Constructor
     130             :    * @param var The MOOSE variable
     131             :    * @param tag The vector tag name
     132             :    */
     133        1772 :   VariableValue(const MooseVariableBase & var, const TagName & tag = Moose::SOLUTION_TAG)
     134        1358 :     : _var(var, tag)
     135             :   {
     136        1772 :   }
     137             : 
     138             :   /**
     139             :    * Get whether the variable was coupled
     140             :    * @returns Whether the variable was coupled
     141             :    */
     142       14016 :   KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
     143             : 
     144             :   /**
     145             :    * Get the current variable value
     146             :    * @param datum The Datum object of the current thread
     147             :    * @param qp The local quadrature-point index
     148             :    * @param comp The variable component
     149             :    * @returns The variable value
     150             :    */
     151    18767176 :   KOKKOS_FUNCTION Real operator()(Datum & datum, unsigned int qp, unsigned int comp = 0) const
     152             :   {
     153    18767176 :     if (_var.coupled())
     154             :     {
     155    18751940 :       auto & elem = datum.elem();
     156    18751940 :       auto side = datum.side();
     157    18751940 :       auto qp_offset = datum.qpOffset();
     158             : 
     159           0 :       return side == libMesh::invalid_uint
     160    18751940 :                  ? datum.system(_var.sys(comp))
     161    18575744 :                        .getVectorQpValue(elem, qp_offset + qp, _var.var(comp), _var.tag())
     162      176196 :                  : datum.system(_var.sys(comp))
     163    18751940 :                        .getVectorQpValueFace(elem, side, qp, _var.var(comp), _var.tag());
     164             :     }
     165             :     else
     166       15236 :       return _var.value(comp);
     167             :   }
     168             : 
     169             : private:
     170             :   /**
     171             :    * Coupled Kokkos variable
     172             :    */
     173             :   Variable _var;
     174             : };
     175             : 
     176             : class VariableNodalValue : public SystemHolder
     177             : {
     178             : public:
     179             :   /**
     180             :    * Constructor
     181             :    * @param systems The Kokkos systems
     182             :    * @param var The Kokkos variable
     183             :    */
     184         184 :   VariableNodalValue(Array<System> & systems, Variable var) : SystemHolder(systems), _var(var) {}
     185             :   /**
     186             :    * Constructor
     187             :    * @param systems The Kokkos systems
     188             :    * @param var The MOOSE variable
     189             :    * @param tag The vector tag name
     190             :    */
     191        1509 :   VariableNodalValue(Array<System> & systems,
     192             :                      const MooseVariableBase & var,
     193         352 :                      const TagName & tag = Moose::SOLUTION_TAG)
     194        1157 :     : SystemHolder(systems), _var(var, tag)
     195             :   {
     196        1509 :   }
     197             : 
     198             :   /**
     199             :    * Get whether the variable was coupled
     200             :    * @returns Whether the variable was coupled
     201             :    */
     202             :   KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
     203             : 
     204             :   /**
     205             :    * Get the current variable nodal value
     206             :    * @param node The current contiguous node ID
     207             :    * @param comp The variable component
     208             :    * @returns The variable nodal value
     209             :    */
     210     1721259 :   KOKKOS_FUNCTION Real operator()(ContiguousNodeID node, unsigned int comp = 0) const
     211             :   {
     212     1721259 :     if (_var.coupled())
     213             :     {
     214     1721259 :       auto dof = kokkosSystem(_var.sys(comp)).getNodeLocalDofIndex(node, _var.var(comp));
     215             : 
     216     1721259 :       return kokkosSystem(_var.sys(comp)).getVectorDofValue(dof, _var.tag());
     217             :     }
     218             :     else
     219           0 :       return _var.value(comp);
     220             :   }
     221             : 
     222             : private:
     223             :   /**
     224             :    * Coupled Kokkos variable
     225             :    */
     226             :   Variable _var;
     227             : };
     228             : 
     229             : class VariableGradient
     230             : {
     231             : public:
     232             :   /**
     233             :    * Constructor
     234             :    * @param var The Kokkos variable
     235             :    */
     236           0 :   VariableGradient(Variable var) : _var(var) {}
     237             :   /**
     238             :    * Constructor
     239             :    * @param var The MOOSE variable
     240             :    * @param tag The vector tag name
     241             :    */
     242        1500 :   VariableGradient(const MooseVariableBase & var, const TagName & tag = Moose::SOLUTION_TAG)
     243        1148 :     : _var(var, tag)
     244             :   {
     245        1500 :   }
     246             : 
     247             :   /**
     248             :    * Get whether the variable was coupled
     249             :    * @returns Whether the variable was coupled
     250             :    */
     251             :   KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
     252             : 
     253             :   /**
     254             :    * Get the current variable gradient
     255             :    * @param datum The Datum object of the current thread
     256             :    * @param qp The local quadrature-point index
     257             :    * @param comp The variable component
     258             :    * @returns The variable gradient
     259             :    */
     260    22894944 :   KOKKOS_FUNCTION Real3 operator()(Datum & datum, unsigned int qp, unsigned int comp = 0) const
     261             :   {
     262    22894944 :     if (_var.coupled())
     263             :     {
     264    22894944 :       auto & elem = datum.elem();
     265    22894944 :       auto side = datum.side();
     266    22894944 :       auto qp_offset = datum.qpOffset();
     267             : 
     268             :       return side == libMesh::invalid_uint
     269    22894944 :                  ? datum.system(_var.sys(comp))
     270    22894944 :                        .getVectorQpGrad(elem, qp_offset + qp, _var.var(comp), _var.tag())
     271           0 :                  : datum.system(_var.sys(comp))
     272             :                        .getVectorQpGradFace(
     273    22894944 :                            elem, side, datum.J(qp), qp, _var.var(comp), _var.tag());
     274             :     }
     275             :     else
     276           0 :       return Real3(0);
     277             :   }
     278             : 
     279             : private:
     280             :   /**
     281             :    * Coupled Kokkos variable
     282             :    */
     283             :   Variable _var;
     284             : };
     285             : ///@}
     286             : 
     287             : } // namespace Kokkos
     288             : } // namespace Moose

Generated by: LCOV version 1.14