LCOV - code coverage report
Current view: top level - include/kokkos/materials - KokkosMaterialBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 23 27 85.2 %
Date: 2025-11-03 17:23:24 Functions: 13 27 48.1 %
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 "KokkosMaterialPropertyValue.h"
      14             : #include "KokkosDispatcher.h"
      15             : 
      16             : #include "MaterialBase.h"
      17             : 
      18             : namespace Moose
      19             : {
      20             : namespace Kokkos
      21             : {
      22             : 
      23             : /**
      24             :  * The base class for Kokkos materials
      25             :  */
      26             : class MaterialBase : public ::MaterialBase,
      27             :                      public MeshHolder,
      28             :                      public AssemblyHolder,
      29             :                      public SystemHolder
      30             : {
      31             : public:
      32             :   static InputParameters validParams();
      33             : 
      34             :   /**
      35             :    * Constructor
      36             :    */
      37             :   MaterialBase(const InputParameters & parameters);
      38             :   /**
      39             :    * Copy constructor for parallel dispatch
      40             :    */
      41             :   MaterialBase(const MaterialBase & object);
      42             : 
      43             :   /**
      44             :    * Setup block and boundary restrictions
      45             :    */
      46             :   virtual void initialSetup() override;
      47             : 
      48             :   // Unused for Kokkos materials because all elements are computed in parallel
      49        2245 :   virtual void subdomainSetup() override final {}
      50             : 
      51             :   /**
      52             :    * Kokkos function tags
      53             :    */
      54             :   ///@{
      55             :   struct ElementInit
      56             :   {
      57             :   };
      58             :   struct SideInit
      59             :   {
      60             :   };
      61             :   struct NeighborInit
      62             :   {
      63             :   };
      64             :   struct ElementCompute
      65             :   {
      66             :   };
      67             :   struct SideCompute
      68             :   {
      69             :   };
      70             :   struct NeighborCompute
      71             :   {
      72             :   };
      73             :   ///@}
      74             : 
      75             : protected:
      76             :   /**
      77             :    * Declare a material property
      78             :    * @tparam T The property data type
      79             :    * @tparam dimension The property dimension
      80             :    * @param name The property name or the parameter name containing the property name
      81             :    * @param dims The vector containing the size of each dimension
      82             :    * @returns The material property
      83             :    */
      84             :   template <typename T, unsigned int dimension = 0>
      85        1027 :   MaterialProperty<T, dimension> declareKokkosProperty(const std::string & name,
      86             :                                                        const std::vector<unsigned int> & dims = {})
      87             :   {
      88        1027 :     std::string prop_name = name;
      89        1027 :     if (_pars.have_parameter<MaterialPropertyName>(name))
      90         267 :       prop_name = _pars.get<MaterialPropertyName>(name);
      91             : 
      92        2048 :     return declareKokkosPropertyByName<T, dimension>(prop_name, dims);
      93        1021 :   }
      94             :   /**
      95             :    * Declare a material property by property name
      96             :    * @tparam T The property data type
      97             :    * @tparam dimension The property dimension
      98             :    * @param prop_name The property name
      99             :    * @param dims The vector containing the size of each dimension
     100             :    * @returns The material property
     101             :    */
     102             :   template <typename T, unsigned int dimension = 0>
     103             :   MaterialProperty<T, dimension>
     104             :   declareKokkosPropertyByName(const std::string & prop_name,
     105             :                               const std::vector<unsigned int> & dims = {});
     106             : 
     107             :   /**
     108             :    * Get the number of elements this material operates on for element material property evaluation
     109             :    * @returns The number of elements
     110             :    */
     111       16006 :   KOKKOS_FUNCTION dof_id_type numKokkosElements() const { return _element_ids.size(); }
     112             :   /**
     113             :    * Get the number of sides this material is operating on for face material property evaluation
     114             :    * @returns The number of sides
     115             :    */
     116       32903 :   KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const { return _element_side_ids.size(); }
     117             :   /**
     118             :    * Get the contiguous element ID for a thread
     119             :    * @param tid The thread ID
     120             :    * @returns The contiguous element ID
     121             :    */
     122      879756 :   KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
     123             :   {
     124      879756 :     return _element_ids[tid];
     125             :   }
     126             :   /**
     127             :    * Get the contiguous element ID - side index pair for a thread
     128             :    * @param tid The thread ID
     129             :    * @returns The contiguous element ID - side index pair
     130             :    */
     131       77180 :   KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const { return _element_side_ids[tid]; }
     132             : 
     133             :   /**
     134             :    * Kokkos functor dispatchers
     135             :    */
     136             :   ///@{
     137             :   std::unique_ptr<DispatcherBase> _init_dispatcher;
     138             :   std::unique_ptr<DispatcherBase> _compute_dispatcher;
     139             :   ///@}
     140             : 
     141             :   /**
     142             :    * TODO: Move to TransientInterface
     143             :    */
     144             :   ///@{
     145             :   /**
     146             :    * Time
     147             :    */
     148             :   Scalar<Real> _t;
     149             :   /**
     150             :    * Old time
     151             :    */
     152             :   Scalar<const Real> _t_old;
     153             :   /**
     154             :    * The number of the time step
     155             :    */
     156             :   Scalar<int> _t_step;
     157             :   /**
     158             :    * Time step size
     159             :    */
     160             :   Scalar<Real> _dt;
     161             :   /**
     162             :    * Size of the old time step
     163             :    */
     164             :   Scalar<Real> _dt_old;
     165             :   ///@}
     166             : 
     167             : private:
     168             :   // Unused for Kokkos materials because they are hidden by Kokkos functions
     169           0 :   virtual void initQpStatefulProperties() override final {}
     170           0 :   virtual void computeQpProperties() override final {}
     171             : 
     172             :   /**
     173             :    * Contiguous element IDs this material operates on for element material property evaluation
     174             :    */
     175             :   Array<ContiguousElementID> _element_ids;
     176             :   /**
     177             :    * Contiguous element ID - side index pairs this material operates on for face material property
     178             :    * evaluation
     179             :    */
     180             :   Array<Pair<ContiguousElementID, unsigned int>> _element_side_ids;
     181             : };
     182             : 
     183             : template <typename T, unsigned int dimension>
     184             : MaterialProperty<T, dimension>
     185        1027 : MaterialBase::declareKokkosPropertyByName(const std::string & prop_name,
     186             :                                           const std::vector<unsigned int> & dims)
     187             : {
     188             :   static_assert(dimension <= 4, "Up to four-dimensional Kokkos material properties are allowed.");
     189             : 
     190        1027 :   if (dims.size() != dimension)
     191           0 :     mooseError("The declared Kokkos material property '",
     192             :                prop_name,
     193             :                "'\nhas a different dimension (",
     194             :                dimension,
     195             :                ") with the provided dimension (",
     196           0 :                dims.size(),
     197             :                ").");
     198             : 
     199        1859 :   const auto prop_name_modified =
     200         832 :       _declare_suffix.empty()
     201         832 :           ? prop_name
     202         832 :           : MooseUtils::join(std::vector<std::string>({prop_name, _declare_suffix}), "_");
     203             : 
     204        1027 :   auto prop = materialData().declareKokkosProperty<T, dimension>(
     205         832 :       prop_name_modified, dims, this, isBoundaryMaterial());
     206             : 
     207        1021 :   registerPropName(prop_name_modified, false, 0);
     208             : 
     209        2042 :   return prop;
     210        1021 : }
     211             : 
     212             : } // namespace Kokkos
     213             : } // namespace Moose

Generated by: LCOV version 1.14