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>::_qp; \
16 : using MaterialPropertyValueBase<T, dimension>::_data; \
17 : using MaterialPropertyValueBase<T, dimension>::_value
18 :
19 : namespace Moose
20 : {
21 : namespace Kokkos
22 : {
23 :
24 : template <typename T, unsigned int dimension>
25 : class MaterialProperty;
26 :
27 : class Datum;
28 :
29 : /**
30 : * The Kokkos wrapper class for accessing the material property values of a single quadrature
31 : * point. The instances of this class are expected to be only created by the Kokkos material
32 : * properties as temporary objects.
33 : */
34 : ///@{
35 : template <typename T, unsigned int dimension>
36 : class MaterialPropertyValueBase
37 : {
38 : public:
39 : /**
40 : * Constructor
41 : * @param property The material property constructing this object
42 : * @param datum The Datum object of the current thread
43 : * @param qp The local quadrature point index
44 : */
45 : KOKKOS_FUNCTION MaterialPropertyValueBase(const MaterialProperty<T, dimension> & property,
46 : const Datum & datum,
47 : const unsigned int qp);
48 :
49 : /**
50 : * Get the size of a dimension
51 : * @param dim The dimension index
52 : * @returns The size of the dimension
53 : */
54 : KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const { return _data->n(dim); }
55 :
56 : protected:
57 : /**
58 : * Global quadrature point index
59 : */
60 : const dof_id_type _qp;
61 : /**
62 : * Pointer to the property data storage
63 : */
64 : Array<T, dimension + 1> const * _data;
65 : /**
66 : * Default value
67 : */
68 : const T & _value;
69 : };
70 :
71 : template <typename T, unsigned int dimension>
72 : class MaterialPropertyValue;
73 :
74 : template <typename T>
75 : class MaterialPropertyValue<T, 0> : public MaterialPropertyValueBase<T, 0>
76 : {
77 : usingKokkosMaterialPropertyValueBaseMembers(T, 0);
78 :
79 : public:
80 : /**
81 : * Constructor
82 : * @param property The material property constructing this object
83 : * @param datum The Datum object of the current thread
84 : * @param qp The local quadrature point index
85 : */
86 : KOKKOS_FUNCTION
87 : MaterialPropertyValue(const MaterialProperty<T, 0> & property,
88 : const Datum & datum,
89 : unsigned int qp);
90 :
91 : /**
92 : * Get the const reference of a property value
93 : * @returns The const reference of the property value
94 : */
95 22738672 : KOKKOS_FUNCTION operator const T &() const { return _data ? (*_data)(_qp) : _value; }
96 : /**
97 : * Assign a value to the underlying property
98 : * @param value The value to assign
99 : */
100 : KOKKOS_FUNCTION auto & operator=(const T & value);
101 : /**
102 : * Copy a value from another property
103 : * @param value The property to copy
104 : */
105 : KOKKOS_FUNCTION auto & operator=(const MaterialPropertyValue<T, 0> & value);
106 : };
107 :
108 : template <typename T>
109 : class MaterialPropertyValue<T, 1> : public MaterialPropertyValueBase<T, 1>
110 : {
111 : usingKokkosMaterialPropertyValueBaseMembers(T, 1);
112 :
113 : public:
114 : /**
115 : * Constructor
116 : * @param property The material property constructing this object
117 : * @param datum The Datum object of the current thread
118 : * @param qp The local quadrature point index
119 : */
120 : KOKKOS_FUNCTION
121 : MaterialPropertyValue(const MaterialProperty<T, 1> & property,
122 : const Datum & datum,
123 : unsigned int qp);
124 :
125 : /**
126 : * Get the writeable reference of a property value
127 : * @param i0 The first dimension index
128 : * @returns The writeable reference of the property value
129 : */
130 : KOKKOS_FUNCTION T & operator()(unsigned int i0) { return (*_data)(i0, _qp); }
131 : /**
132 : * Get the const reference of a property value
133 : * @param i0 The first dimension index
134 : * @returns The const reference of the property value
135 : */
136 : KOKKOS_FUNCTION const T & operator()(unsigned int i0) const
137 : {
138 : return _data ? (*_data)(i0, _qp) : _value;
139 : }
140 : };
141 :
142 : template <typename T>
143 : class MaterialPropertyValue<T, 2> : public MaterialPropertyValueBase<T, 2>
144 : {
145 : usingKokkosMaterialPropertyValueBaseMembers(T, 2);
146 :
147 : public:
148 : /**
149 : * Constructor
150 : * @param property The material property constructing this object
151 : * @param datum The Datum object of the current thread
152 : * @param qp The local quadrature point index
153 : */
154 : KOKKOS_FUNCTION
155 : MaterialPropertyValue(const MaterialProperty<T, 2> & property,
156 : const Datum & datum,
157 : unsigned int qp);
158 :
159 : /**
160 : * Get the writeable reference of a property value
161 : * @param i0 The first dimension index
162 : * @param i1 The second dimension index
163 : * @returns The writeable reference of the property value
164 : */
165 : KOKKOS_FUNCTION T & operator()(unsigned int i0, unsigned int i1) { return (*_data)(i0, i1, _qp); }
166 : /**
167 : * Get the const reference of a property value
168 : * @param i0 The first dimension index
169 : * @param i1 The second dimension index
170 : * @returns The const reference of the property value
171 : */
172 : KOKKOS_FUNCTION const T & operator()(unsigned int i0, unsigned int i1) const
173 : {
174 : return _data ? (*_data)(i0, i1, _qp) : _value;
175 : }
176 : };
177 :
178 : template <typename T>
179 : class MaterialPropertyValue<T, 3> : public MaterialPropertyValueBase<T, 3>
180 : {
181 : usingKokkosMaterialPropertyValueBaseMembers(T, 3);
182 :
183 : public:
184 : /**
185 : * Constructor
186 : * @param property The material property constructing this object
187 : * @param datum The Datum object of the current thread
188 : * @param qp The local quadrature point index
189 : */
190 : KOKKOS_FUNCTION
191 : MaterialPropertyValue(const MaterialProperty<T, 3> & property,
192 : const Datum & datum,
193 : unsigned int qp);
194 :
195 : /**
196 : * Get the writeable reference of a property value
197 : * @param i0 The first dimension index
198 : * @param i1 The second dimension index
199 : * @param i2 The third dimension index
200 : * @returns The writeable reference of the property value
201 : */
202 : KOKKOS_FUNCTION T & operator()(unsigned int i0, unsigned int i1, unsigned int i2)
203 : {
204 : return (*_data)(i0, i1, i2, _qp);
205 : }
206 : /**
207 : * Get the const reference of a property value
208 : * @param i0 The first dimension index
209 : * @param i1 The second dimension index
210 : * @param i2 The third dimension index
211 : * @returns The const reference of the property value
212 : */
213 : KOKKOS_FUNCTION const T & operator()(unsigned int i0, unsigned int i1, unsigned int i2) const
214 : {
215 : return _data ? (*_data)(i0, i1, i2, _qp) : _value;
216 : }
217 : };
218 :
219 : template <typename T>
220 : class MaterialPropertyValue<T, 4> : public MaterialPropertyValueBase<T, 4>
221 : {
222 : usingKokkosMaterialPropertyValueBaseMembers(T, 4);
223 :
224 : public:
225 : /**
226 : * Constructor
227 : * @param property The material property constructing this object
228 : * @param datum The Datum object of the current thread
229 : * @param qp The local quadrature point index
230 : */
231 : KOKKOS_FUNCTION
232 : MaterialPropertyValue(const MaterialProperty<T, 4> & property,
233 : const Datum & datum,
234 : unsigned int qp);
235 :
236 : /**
237 : * Get the writeable reference of a property value
238 : * @param i0 The first dimension index
239 : * @param i1 The second dimension index
240 : * @param i2 The third dimension index
241 : * @param i3 The fourth dimension index
242 : * @returns The writeable reference of the property value
243 : */
244 : KOKKOS_FUNCTION T & operator()(unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3)
245 : {
246 : return (*_data)(i0, i1, i2, i3, _qp);
247 : }
248 : /**
249 : * Get the const reference of a property value
250 : * @param i0 The first dimension index
251 : * @param i1 The second dimension index
252 : * @param i2 The third dimension index
253 : * @param i3 The fourth dimension index
254 : * @returns The const reference of the property value
255 : */
256 : KOKKOS_FUNCTION const T &
257 : operator()(unsigned int i0, unsigned int i1, unsigned int i2, unsigned int i3) const
258 : {
259 : return _data ? (*_data)(i0, i1, i2, i3, _qp) : _value;
260 : }
261 : };
262 : ///@}
263 :
264 : } // namespace Kokkos
265 : } // namespace Moose
|