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 "KokkosAssembly.h"
14 : #include "KokkosSystem.h"
15 : #include "KokkosVariable.h"
16 :
17 : namespace Moose
18 : {
19 : namespace Kokkos
20 : {
21 :
22 : /**
23 : * The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object
24 : */
25 : class Datum
26 : {
27 : public:
28 : /**
29 : * Constructor for element and side data
30 : * @param elem The contiguous element ID of the current thread
31 : * @param side The side index of the current thread
32 : * @param assembly The Kokkos assembly
33 : * @param systems The Kokkos systems
34 : */
35 : KOKKOS_FUNCTION
36 5413565 : Datum(const ContiguousElementID elem,
37 : const unsigned int side,
38 : const Assembly & assembly,
39 : const Array<System> & systems)
40 5413565 : : _assembly(assembly),
41 5413565 : _systems(systems),
42 5413565 : _elem(assembly.kokkosMesh().getElementInfo(elem)),
43 5413565 : _side(side),
44 5236605 : _neighbor(_side == libMesh::invalid_uint ? libMesh::DofObject::invalid_id
45 176960 : : assembly.kokkosMesh().getNeighbor(_elem.id, side)),
46 5413565 : _n_qps(side == libMesh::invalid_uint ? assembly.getNumQps(_elem)
47 176960 : : assembly.getNumFaceQps(_elem, side)),
48 5413565 : _qp_offset(side == libMesh::invalid_uint ? assembly.getQpOffset(_elem)
49 10827130 : : assembly.getQpFaceOffset(_elem, side))
50 : {
51 5413565 : }
52 : /**
53 : * Constructor for node data
54 : * @param node The contiguous node ID of the current thread
55 : * @param assembly The Kokkos assembly
56 : * @param systems The Kokkos systems
57 : */
58 : KOKKOS_FUNCTION
59 3100454 : Datum(const ContiguousNodeID node, const Assembly & assembly, const Array<System> & systems)
60 3100454 : : _assembly(assembly), _systems(systems), _node(node)
61 : {
62 3100454 : }
63 :
64 : /**
65 : * Get the Kokkos assembly
66 : * @returns The Kokkos assembly
67 : */
68 204757068 : KOKKOS_FUNCTION const Assembly & assembly() const { return _assembly; }
69 : /**
70 : * Get the Kokkos system
71 : * @param sys The system number
72 : * @returns The Kokkos system
73 : */
74 69313905 : KOKKOS_FUNCTION const System & system(unsigned int sys) const { return _systems[sys]; }
75 :
76 : /**
77 : * Get the element information object
78 : * @returns The element information object
79 : */
80 293784876 : KOKKOS_FUNCTION const ElementInfo & elem() const { return _elem; }
81 : /**
82 : * Get the contiguous subdomain ID
83 : * @returns The contiguous subdomain ID
84 : */
85 38098064 : KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const { return _elem.subdomain; }
86 : /**
87 : * Get the side index
88 : * @returns The side index
89 : */
90 270185856 : KOKKOS_FUNCTION unsigned int side() const { return _side; }
91 : /**
92 : * Get the contiguous node ID
93 : * @returns The contiguous node ID
94 : */
95 5207943 : KOKKOS_FUNCTION ContiguousNodeID node() const { return _node; }
96 : /**
97 : * Get the number of local quadrature points
98 : * @returns The number of local quadrature points
99 : */
100 31732373 : KOKKOS_FUNCTION unsigned int n_qps() const { return _n_qps; }
101 : /**
102 : * Get the starting offset into the global quadrature point index
103 : * @returns The starting offset
104 : */
105 103526852 : KOKKOS_FUNCTION dof_id_type qpOffset() const { return _qp_offset; }
106 : /**
107 : * Get whether the current side has a neighbor
108 : * @returns Whether the current side has a neighbor
109 : */
110 : KOKKOS_FUNCTION bool hasNeighbor() const { return _neighbor != libMesh::DofObject::invalid_id; }
111 : /**
112 : * Get whether the current datum is on a node
113 : * @returns Whether the current datum is on a node
114 : */
115 215439905 : KOKKOS_FUNCTION bool isNodal() const { return _node != libMesh::DofObject::invalid_id; }
116 :
117 : /**
118 : * Get the inverse of Jacobian matrix
119 : * | dxi/dx deta/dx dzeta/dx |
120 : * | dxi/dy deta/dy dzeta/dy |
121 : * | dxi/dz deta/dz dzeta/dz |
122 : * @param qp The local quadrature point index
123 : * @returns The Jacobian matrix
124 : */
125 79577584 : KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
126 : {
127 79577584 : if (!isNodal())
128 79577584 : reinitTransform(qp);
129 : else
130 0 : _J.identity(_assembly.getDimension());
131 :
132 79577584 : return _J;
133 : }
134 : /**
135 : * Get the transformed Jacobian weight
136 : * @param qp The local quadrature point index
137 : * @returns The transformed Jacobian weights
138 : */
139 117123260 : KOKKOS_FUNCTION Real JxW(const unsigned int qp)
140 : {
141 117123260 : if (!isNodal())
142 117123260 : reinitTransform(qp);
143 : else
144 0 : _JxW = 1;
145 :
146 117123260 : return _JxW;
147 : }
148 : /**
149 : * Get the physical quadrature point coordinate
150 : * @param qp The local quadrature point index
151 : * @returns The physical quadrature point coordinate
152 : */
153 14853944 : KOKKOS_FUNCTION Real3 q_point(const unsigned int qp)
154 : {
155 14853944 : if (!isNodal())
156 14440608 : reinitTransform(qp);
157 : else
158 413336 : _xyz = _assembly.kokkosMesh().getNodePoint(_node);
159 :
160 14853944 : return _xyz;
161 : }
162 :
163 : /**
164 : * Reset the reinit flag
165 : */
166 26271792 : KOKKOS_FUNCTION void reinit() { _transform_reinit = false; }
167 :
168 : protected:
169 : /**
170 : * Reference of the Kokkos assembly
171 : */
172 : const Assembly & _assembly;
173 : /**
174 : * Reference of the Kokkos systems
175 : */
176 : const Array<System> & _systems;
177 : /**
178 : * Current element information object
179 : */
180 : const ElementInfo _elem;
181 : /**
182 : * Current side index
183 : */
184 : const unsigned int _side = libMesh::invalid_uint;
185 : /**
186 : * Current contiguous node ID
187 : */
188 : const ContiguousNodeID _node = libMesh::DofObject::invalid_id;
189 : /**
190 : * Current contiguous element ID of neighbor
191 : */
192 : const ContiguousElementID _neighbor = libMesh::DofObject::invalid_id;
193 : /**
194 : * Number of local quadrature points
195 : */
196 : const unsigned int _n_qps = 1;
197 : /**
198 : * Starting offset into the global quadrature point index
199 : */
200 : const dof_id_type _qp_offset = libMesh::DofObject::invalid_id;
201 :
202 : private:
203 : /**
204 : * Compute and cache the physical transformation data
205 : * @param qp The local quadrature point index
206 : */
207 : KOKKOS_FUNCTION void reinitTransform(const unsigned int qp);
208 :
209 : /**
210 : * Flag whether the physical transformation data was cached
211 : */
212 : bool _transform_reinit = false;
213 : /**
214 : * Cached physical transformation data
215 : */
216 : ///@{
217 : Real33 _J;
218 : Real _JxW;
219 : Real3 _xyz;
220 : ///@}
221 : };
222 :
223 : KOKKOS_FUNCTION inline void
224 211141452 : Datum::reinitTransform(const unsigned int qp)
225 : {
226 211141452 : if (_transform_reinit)
227 190723508 : return;
228 :
229 20417944 : if (_side == libMesh::invalid_uint)
230 : {
231 20201640 : _J = _assembly.getJacobian(_elem, qp);
232 20201640 : _JxW = _assembly.getJxW(_elem, qp);
233 20201640 : _xyz = _assembly.getQPoint(_elem, qp);
234 : }
235 : else
236 216304 : _assembly.computePhysicalMap(_elem, _side, qp, &_J, &_JxW, &_xyz);
237 :
238 20417944 : _transform_reinit = true;
239 : }
240 :
241 : /**
242 : * The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels
243 : */
244 : class AssemblyDatum : public Datum
245 : {
246 : public:
247 : /**
248 : * Constructor for element and side data
249 : * @param elem The contiguous element ID of the current thread
250 : * @param side The side index of the current thread
251 : * @param assembly The Kokkos assembly
252 : * @param systems The Kokkos systems
253 : * @param ivar The Kokkos variable
254 : * @param jvar The coupled variable number
255 : * @param comp The variable component
256 : */
257 : KOKKOS_FUNCTION
258 4456629 : AssemblyDatum(const ContiguousElementID elem,
259 : const unsigned int side,
260 : const Assembly & assembly,
261 : const Array<System> & systems,
262 : const Variable & ivar,
263 : const unsigned int jvar,
264 : const unsigned int comp = 0)
265 4456629 : : Datum(elem, side, assembly, systems),
266 4456629 : _tag(ivar.tag()),
267 4456629 : _ivar(ivar.var(comp)),
268 4456629 : _jvar(jvar),
269 4456629 : _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
270 4456629 : _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar)),
271 4456629 : _n_idofs(assembly.getNumDofs(_elem.type, _ife)),
272 8913258 : _n_jdofs(assembly.getNumDofs(_elem.type, _jfe))
273 : {
274 4456629 : }
275 : /**
276 : * Constructor for node data
277 : * @param elem The contiguous element ID of the current thread
278 : * @param assembly The Kokkos assembly
279 : * @param systems The Kokkos systems
280 : * @param ivar The Kokkos variable
281 : * @param jvar The coupled variable number
282 : * @param comp The variable component
283 : */
284 : KOKKOS_FUNCTION
285 3100454 : AssemblyDatum(const ContiguousNodeID node,
286 : const Assembly & assembly,
287 : const Array<System> & systems,
288 : const Variable & ivar,
289 : const unsigned int jvar,
290 : const unsigned int comp = 0)
291 3100454 : : Datum(node, assembly, systems),
292 3100454 : _tag(ivar.tag()),
293 3100454 : _ivar(ivar.var(comp)),
294 3100454 : _jvar(jvar),
295 3100454 : _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
296 6200908 : _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar))
297 : {
298 3100454 : }
299 :
300 : /**
301 : * Get the number of local DOFs
302 : * @returns The number of local DOFs
303 : */
304 132121832 : KOKKOS_FUNCTION unsigned int n_dofs() const { return _n_idofs; }
305 : /**
306 : * Get the number of local DOFs
307 : * @returns The number of local DOFs
308 : */
309 1832991 : KOKKOS_FUNCTION unsigned int n_idofs() const { return _n_idofs; }
310 : /**
311 : * Get the number of local DOFs for the coupled variable
312 : * @returns The number of local DOFs
313 : */
314 104881439 : KOKKOS_FUNCTION unsigned int n_jdofs() const { return _n_jdofs; }
315 : /**
316 : * Get the variable number
317 : * @returns The variable number
318 : */
319 : KOKKOS_FUNCTION unsigned int var() const { return _ivar; }
320 : /**
321 : * Get the variable number
322 : * @returns The variable number
323 : */
324 : KOKKOS_FUNCTION unsigned int ivar() const { return _ivar; }
325 : /**
326 : * Get the coupled variable number
327 : * @returns The variable number
328 : */
329 8941408 : KOKKOS_FUNCTION unsigned int jvar() const { return _jvar; }
330 : /**
331 : * Get the variable FE type ID
332 : * @returns The variable FE type ID
333 : */
334 : KOKKOS_FUNCTION unsigned int fe() const { return _ife; }
335 : /**
336 : * Get the variable FE type ID
337 : * @returns The variable FE type ID
338 : */
339 162096476 : KOKKOS_FUNCTION unsigned int ife() const { return _ife; }
340 : /**
341 : * Get the coupled variable FE type ID
342 : * @returns The variable FE type ID
343 : */
344 42660592 : KOKKOS_FUNCTION unsigned int jfe() const { return _jfe; }
345 :
346 : protected:
347 : /**
348 : * Solution tag ID
349 : */
350 : const TagID _tag;
351 : /**
352 : * Variable numbers
353 : */
354 : const unsigned int _ivar, _jvar;
355 : /**
356 : * FE type IDs of variables
357 : */
358 : const unsigned int _ife, _jfe;
359 : /**
360 : * Number of local DOFs
361 : */
362 : const unsigned int _n_idofs = 1, _n_jdofs = 1;
363 : };
364 :
365 : } // namespace Kokkos
366 : } // namespace Moose
367 :
368 : using Datum = Moose::Kokkos::Datum;
369 : using AssemblyDatum = Moose::Kokkos::AssemblyDatum;
|