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