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 "KokkosArray.h" 13 : 14 : #define usingKokkosMaterialPropertyValueBaseMembers(T, dimension) \ 15 : using MaterialPropertyValueBase<T, dimension>::_idx; \ 16 : using MaterialPropertyValueBase<T, dimension>::_data; \ 17 : using MaterialPropertyValueBase<T, dimension>::_value 18 : 19 : namespace Moose::Kokkos 20 : { 21 : 22 : template <typename T, unsigned int dimension> 23 : class MaterialProperty; 24 : 25 : class Datum; 26 : 27 : /** 28 : * The Kokkos wrapper class for accessing the material property values of a single quadrature 29 : * point. The instances of this class are expected to be only created by the Kokkos material 30 : * properties as temporary objects. 31 : */ 32 : ///@{ 33 : template <typename T, unsigned int dimension> 34 : class MaterialPropertyValueBase 35 : { 36 : public: 37 : /** 38 : * Constructor 39 : * @param property The material property constructing this object 40 : * @param datum The Datum object of the current thread 41 : * @param qp The local quadrature point index 42 : */ 43 : KOKKOS_FUNCTION MaterialPropertyValueBase(const MaterialProperty<T, dimension> & property, 44 : const Datum & datum, 45 : const unsigned int qp); 46 : 47 : /** 48 : * Get the size of a dimension 49 : * @param dim The dimension index 50 : * @returns The size of the dimension 51 : */ 52 : KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const { return _data->n(dim); } 53 : 54 : protected: 55 : /** 56 : * Index into the property data storage 57 : */ 58 : const dof_id_type _idx; 59 : /** 60 : * Pointer to the property data storage 61 : */ 62 : Array<T, dimension + 1> const * _data; 63 : /** 64 : * Default value 65 : */ 66 : const T & _value; 67 : }; 68 : 69 : template <typename T, unsigned int dimension> 70 : class MaterialPropertyValue : public MaterialPropertyValueBase<T, dimension> 71 : { 72 : usingKokkosMaterialPropertyValueBaseMembers(T, dimension); 73 : 74 : public: 75 : /** 76 : * Constructor 77 : * @param property The material property constructing this object 78 : * @param datum The Datum object of the current thread 79 : * @param qp The local quadrature point index 80 : */ 81 : KOKKOS_FUNCTION MaterialPropertyValue(const MaterialProperty<T, dimension> & property, 82 : const Datum & datum, 83 : const unsigned int qp); 84 : 85 : /** 86 : * Get the writeable reference of a property value 87 : * @param i The index of each dimension 88 : * @returns The writeable reference of the property value 89 : */ 90 : template <typename... index_type> 91 : KOKKOS_FUNCTION T & operator()(index_type... i) 92 : { 93 : static_assert(sizeof...(i) == dimension, 94 : "Number of arguments should match material property dimension"); 95 : 96 : return (*_data)(i..., _idx); 97 : } 98 : /** 99 : * Get the const reference of a property value 100 : * @param i The index of each dimension 101 : * @returns The const reference of the property value 102 : */ 103 : template <typename... index_type> 104 : KOKKOS_FUNCTION const T & operator()(index_type... i) const 105 : { 106 : static_assert(sizeof...(i) == dimension, 107 : "Number of arguments should match material property dimension"); 108 : 109 : return _data ? (*_data)(i..., _idx) : _value; 110 : } 111 : }; 112 : 113 : template <typename T> 114 : class MaterialPropertyValue<T, 0> : public MaterialPropertyValueBase<T, 0> 115 : { 116 : usingKokkosMaterialPropertyValueBaseMembers(T, 0); 117 : 118 : public: 119 : /** 120 : * Constructor 121 : * @param property The material property constructing this object 122 : * @param datum The Datum object of the current thread 123 : * @param qp The local quadrature point index 124 : */ 125 : KOKKOS_FUNCTION 126 : MaterialPropertyValue(const MaterialProperty<T, 0> & property, 127 : const Datum & datum, 128 : const unsigned int qp); 129 : 130 : /** 131 : * Get the const reference of a property value 132 : * @returns The const reference of the property value 133 : */ 134 33368404 : KOKKOS_FUNCTION operator const T &() const { return _data ? (*_data)(_idx) : _value; } 135 : /** 136 : * Assign a value to the underlying property 137 : * @param value The value to assign 138 : */ 139 : KOKKOS_FUNCTION auto & operator=(const T & value); 140 : /** 141 : * Copy a value from another property 142 : * @param value The property to copy 143 : */ 144 : KOKKOS_FUNCTION auto & operator=(const MaterialPropertyValue<T, 0> & value); 145 : }; 146 : ///@} 147 : 148 : } // namespace Moose::Kokkos