https://mooseframework.inl.gov
KokkosDatum.h
Go to the documentation of this file.
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::Kokkos
18 {
19 
23 class Datum
24 {
25 public:
33  KOKKOS_FUNCTION
35  const unsigned int side,
36  const Assembly & assembly,
37  const Array<System> & systems)
39  _systems(systems),
40  _mesh(assembly.kokkosMesh()),
41  _elem(_mesh.getElementInfo(elem)),
42  _side(side),
43  _neighbor(!isSide() ? libMesh::DofObject::invalid_id : _mesh.getNeighbor(_elem.id, side)),
44  _n_qps(!isSide() ? assembly.getNumQps(_elem) : assembly.getNumFaceQps(_elem, side)),
45  _qp_offset(!isSide() ? assembly.getQpOffset(_elem) : assembly.getQpFaceOffset(_elem, side)),
47  ? _elem.id - _mesh.getStartingContiguousElementID(_elem.subdomain)
48  : assembly.getElemFacePropertyIndex(_elem, _side))
49  {
50  }
57  KOKKOS_FUNCTION
58  Datum(const ContiguousNodeID node, const Assembly & assembly, const Array<System> & systems)
59  : _assembly(assembly), _systems(systems), _mesh(assembly.kokkosMesh()), _node(node)
60  {
61  }
62 
67  KOKKOS_FUNCTION const Assembly & assembly() const { return _assembly; }
73  KOKKOS_FUNCTION const System & system(unsigned int sys) const { return _systems[sys]; }
78  KOKKOS_FUNCTION const Mesh & mesh() const { return _mesh; }
79 
84  KOKKOS_FUNCTION const ElementInfo & elem() const { return _elem; }
89  KOKKOS_FUNCTION ContiguousElementID elemID() const { return _elem.id; }
95  KOKKOS_FUNCTION dof_id_type extraElemID(unsigned int index) const
96  {
98  }
103  KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const { return _elem.subdomain; }
108  KOKKOS_FUNCTION unsigned int side() const { return _side; }
113  KOKKOS_FUNCTION ContiguousNodeID node() const { return _node; }
118  KOKKOS_FUNCTION unsigned int n_qps() const { return _n_qps; }
123  KOKKOS_FUNCTION dof_id_type qpOffset() const { return _qp_offset; }
130  KOKKOS_FUNCTION dof_id_type propertyIdx(const PropertyConstantOption constant_option,
131  const unsigned int qp) const;
136  KOKKOS_FUNCTION bool hasNeighbor() const { return _neighbor != libMesh::DofObject::invalid_id; }
141  KOKKOS_FUNCTION bool isSide() const { return _side != libMesh::invalid_uint; }
146  KOKKOS_FUNCTION bool isNodal() const { return _node != libMesh::DofObject::invalid_id; }
152  KOKKOS_FUNCTION bool isNodalDefined(const Variable & var) const;
153 
162  KOKKOS_FUNCTION const Real33 & J(const unsigned int qp);
168  KOKKOS_FUNCTION Real JxW(const unsigned int qp);
174  KOKKOS_FUNCTION Real3 q_point(const unsigned int qp);
180  KOKKOS_FUNCTION Real3 normals(const unsigned int qp);
181 
187  KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id,
188  const unsigned int num_local_threads)
189  {
192  }
197  KOKKOS_FUNCTION unsigned int local_thread_id() const { return _local_thread_id; }
202  KOKKOS_FUNCTION unsigned int num_local_threads() const { return _num_local_threads; }
203 
204 protected:
216  const Mesh & _mesh;
224  const unsigned int _side = libMesh::invalid_uint;
236  const unsigned int _n_qps = 1;
245 
246 private:
251  KOKKOS_FUNCTION void reinitTransform(const unsigned int qp);
252 
261  Real33 _J;
267 
270  unsigned int _local_thread_id = 0;
274  unsigned int _num_local_threads = 1;
275 };
276 
277 KOKKOS_FUNCTION inline dof_id_type
278 Datum::propertyIdx(const PropertyConstantOption constant_option, const unsigned int qp) const
279 {
280  dof_id_type idx = 0;
281 
282  if (constant_option == PropertyConstantOption::NONE)
283  idx = _qp_offset + qp;
284  else if (constant_option == PropertyConstantOption::ELEMENT)
286 
287  return idx;
288 }
289 
290 KOKKOS_FUNCTION inline bool
291 Datum::isNodalDefined(const Variable & var) const
292 {
293  if (!isNodal() || !var.nodal())
294  return false;
295 
296  return _systems[var.sys()].isNodalDefined(_node, var.var());
297 }
298 
299 KOKKOS_FUNCTION inline const Real33 &
300 Datum::J(const unsigned int qp)
301 {
302  if (!isNodal())
303  reinitTransform(qp);
304  else
306 
307  return _J;
308 }
309 
310 KOKKOS_FUNCTION inline Real
311 Datum::JxW(const unsigned int qp)
312 {
313  if (!isNodal())
314  reinitTransform(qp);
315  else
316  _JxW = 1;
317 
318  return _JxW;
319 }
320 
321 KOKKOS_FUNCTION inline Real3
322 Datum::q_point(const unsigned int qp)
323 {
324  if (!isNodal())
325  reinitTransform(qp);
326  else
328 
329  return _xyz;
330 }
331 
332 KOKKOS_FUNCTION inline Real3
333 Datum::normals(const unsigned int qp)
334 {
335  KOKKOS_ASSERT(isSide());
336 
337  if (isSide())
338  reinitTransform(qp);
339 
340  return _normal;
341 }
342 
343 KOKKOS_FUNCTION inline void
344 Datum::reinitTransform(const unsigned int qp)
345 {
346  if (_cached_qp == qp)
347  return;
348 
349  if (!isSide())
350  {
351  _J = _assembly.getJacobian(_elem, qp);
352  _JxW = _assembly.getJxW(_elem, qp);
353  _xyz = _assembly.getQPoint(_elem, qp);
354  }
355  else
357 
358  _cached_qp = qp;
359 }
360 
364 class AssemblyDatum : public Datum
365 {
366 public:
377  KOKKOS_FUNCTION
379  const unsigned int side,
380  const Assembly & assembly,
381  const Array<System> & systems,
382  const Variable & ivar,
383  const unsigned int jvar,
384  const unsigned int comp = 0)
385  : Datum(elem, side, assembly, systems),
386  _tag(ivar.tag()),
387  _sys(ivar.sys(comp)),
388  _ivar(ivar.var(comp)),
389  _jvar(jvar),
390  _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
391  _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar)),
392  _n_idofs(assembly.getNumDofs(_elem.type, _ife)),
393  _n_jdofs(assembly.getNumDofs(_elem.type, _jfe))
394  {
395  }
405  KOKKOS_FUNCTION
407  const Assembly & assembly,
408  const Array<System> & systems,
409  const Variable & ivar,
410  const unsigned int jvar,
411  const unsigned int comp = 0)
412  : Datum(node, assembly, systems),
413  _tag(ivar.tag()),
414  _sys(ivar.sys(comp)),
415  _ivar(ivar.var(comp)),
416  _jvar(jvar),
417  _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
418  _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar))
419  {
420  }
421 
426  KOKKOS_FUNCTION unsigned int n_dofs() const { return _n_idofs; }
431  KOKKOS_FUNCTION unsigned int n_idofs() const { return _n_idofs; }
436  KOKKOS_FUNCTION unsigned int n_jdofs() const { return _n_jdofs; }
441  KOKKOS_FUNCTION unsigned int sys() const { return _sys; }
446  KOKKOS_FUNCTION unsigned int var() const { return _ivar; }
451  KOKKOS_FUNCTION unsigned int ivar() const { return _ivar; }
456  KOKKOS_FUNCTION unsigned int jvar() const { return _jvar; }
461  KOKKOS_FUNCTION unsigned int fe() const { return _ife; }
466  KOKKOS_FUNCTION unsigned int ife() const { return _ife; }
471  KOKKOS_FUNCTION unsigned int jfe() const { return _jfe; }
476  KOKKOS_FUNCTION void do_derivatives(const bool flag) { _do_derivatives = flag; }
481  KOKKOS_FUNCTION bool do_derivatives() const { return _do_derivatives; }
482 
483 protected:
487  const TagID _tag;
491  const unsigned int _sys;
495  const unsigned int _ivar, _jvar;
499  const unsigned int _ife, _jfe;
503  const unsigned int _n_idofs = 1, _n_jdofs = 1;
507  bool _do_derivatives = true;
508 };
509 
510 } // namespace Moose::Kokkos
511 
unsigned int _local_thread_id
Thread ID for local parallelization.
Definition: KokkosDatum.h:270
const dof_id_type _elem_property_idx
Index for element-constant material properties.
Definition: KokkosDatum.h:244
The Kokkos array class.
Definition: KokkosArray.h:64
unsigned int _num_local_threads
Number of threads for local parallelization.
Definition: KokkosDatum.h:274
const unsigned int _sys
System number.
Definition: KokkosDatum.h:491
The Kokkos assembly class.
The Kokkos mesh object.
Definition: KokkosMesh.h:52
KOKKOS_FUNCTION dof_id_type extraElemID(unsigned int index) const
Get the extra element ID.
Definition: KokkosDatum.h:95
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
The Kokkos object that contains the information of an element The IDs used in Kokkos are different fr...
Definition: KokkosMesh.h:33
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
Moose::Kokkos::AssemblyDatum AssemblyDatum
Definition: KokkosDatum.h:513
KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
Definition: KokkosDatum.h:187
KOKKOS_FUNCTION bool do_derivatives() const
Get whether to compute derivatives for automatic differentiation (AD)
Definition: KokkosDatum.h:481
const unsigned int invalid_uint
const unsigned int _n_jdofs
Definition: KokkosDatum.h:503
const Assembly & _assembly
Reference of the Kokkos assembly.
Definition: KokkosDatum.h:208
unsigned int TagID
Definition: MooseTypes.h:238
KOKKOS_INLINE_FUNCTION void identity(const unsigned int dim=3)
Definition: KokkosTypes.h:352
dof_id_type ContiguousElementID
Definition: KokkosMesh.h:20
KOKKOS_FUNCTION Real3 normals(const unsigned int qp)
Get the normal vector on surface.
Definition: KokkosDatum.h:333
const unsigned int _jvar
Definition: KokkosDatum.h:495
KOKKOS_FUNCTION unsigned int num_local_threads() const
Get the number of local threads.
Definition: KokkosDatum.h:202
Moose::Kokkos::Datum Datum
Definition: KokkosDatum.h:512
KOKKOS_FUNCTION unsigned int getDimension() const
Get the mesh dimension.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
Definition: KokkosDatum.h:476
const unsigned int _side
Current side index.
Definition: KokkosDatum.h:224
KOKKOS_FUNCTION bool isNodalDefined(const Variable &var) const
Get whether the a variable is defined on the current node.
Definition: KokkosDatum.h:291
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
Definition: KokkosDatum.h:441
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
Definition: KokkosDatum.h:456
KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
Get the inverse of Jacobian matrix | dxi/dx deta/dx dzeta/dx | | dxi/dy deta/dy dzeta/dy | | dxi/dz d...
Definition: KokkosDatum.h:300
KOKKOS_FUNCTION Real3 q_point(const unsigned int qp)
Get the physical quadrature point coordinate.
Definition: KokkosDatum.h:322
const unsigned int _n_qps
Number of local quadrature points.
Definition: KokkosDatum.h:236
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
KOKKOS_FUNCTION unsigned int n_jdofs() const
Get the number of local DOFs for the coupled variable.
Definition: KokkosDatum.h:436
The Kokkos system class.
Definition: KokkosSystem.h:34
KOKKOS_FUNCTION unsigned int ivar() const
Get the variable number.
Definition: KokkosDatum.h:451
KOKKOS_FUNCTION bool isSide() const
Get whether the current datum is on a side.
Definition: KokkosDatum.h:141
const ElementInfo _elem
Current element information object.
Definition: KokkosDatum.h:220
const Mesh & _mesh
Reference of the Kokkos mesh.
Definition: KokkosDatum.h:216
KOKKOS_FUNCTION unsigned int fe() const
Get the variable FE type ID.
Definition: KokkosDatum.h:461
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition: KokkosDatum.h:108
const unsigned int _jfe
Definition: KokkosDatum.h:499
KOKKOS_FUNCTION unsigned int jfe() const
Get the coupled variable FE type ID.
Definition: KokkosDatum.h:471
PropertyConstantOption
Property constant options.
static constexpr dof_id_type invalid_id
dof_id_type ContiguousNodeID
Definition: KokkosMesh.h:21
KOKKOS_FUNCTION ContiguousElementID elemID() const
Get the contiguous element ID.
Definition: KokkosDatum.h:89
KOKKOS_FUNCTION unsigned int n_idofs() const
Get the number of local DOFs.
Definition: KokkosDatum.h:431
const unsigned int _n_idofs
Number of local DOFs.
Definition: KokkosDatum.h:503
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:118
KOKKOS_FUNCTION AssemblyDatum(const ContiguousElementID elem, const unsigned int side, const Assembly &assembly, const Array< System > &systems, const Variable &ivar, const unsigned int jvar, const unsigned int comp=0)
Constructor for element and side data.
Definition: KokkosDatum.h:378
KOKKOS_FUNCTION unsigned int local_thread_id() const
Get the current local thread ID.
Definition: KokkosDatum.h:197
KOKKOS_FUNCTION const Assembly & assembly() const
Get the Kokkos assembly.
Definition: KokkosDatum.h:67
const TagID _tag
Solution tag ID.
Definition: KokkosDatum.h:487
KOKKOS_FUNCTION dof_id_type getExtraElementID(ContiguousElementID elem, unsigned int index) const
Get the extra element ID of an element.
Definition: KokkosMesh.h:228
KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const
Get the contiguous subdomain ID.
Definition: KokkosDatum.h:103
KOKKOS_FUNCTION bool nodal() const
Get whether the variable is nodal.
KOKKOS_FUNCTION AssemblyDatum(const ContiguousNodeID node, const Assembly &assembly, const Array< System > &systems, const Variable &ivar, const unsigned int jvar, const unsigned int comp=0)
Constructor for node data.
Definition: KokkosDatum.h:406
KOKKOS_FUNCTION void reinitTransform(const unsigned int qp)
Compute and cache the physical transformation data.
Definition: KokkosDatum.h:344
KOKKOS_FUNCTION unsigned int var() const
Get the variable number.
Definition: KokkosDatum.h:446
KOKKOS_FUNCTION Real3 getNodePoint(ContiguousNodeID node) const
Get the coordinate of a node.
Definition: KokkosMesh.h:272
KOKKOS_FUNCTION Real getJxW(ElementInfo info, unsigned int qp) const
Get the transformed Jacobian weight of an element quadrature point.
bool _do_derivatives
Whether to compute derivatives for automatic differentiation (AD)
Definition: KokkosDatum.h:507
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition: KokkosMesh.h:452
ContiguousSubdomainID subdomain
Contiguous subdomain ID.
Definition: KokkosMesh.h:46
KOKKOS_FUNCTION ContiguousNodeID node() const
Get the contiguous node ID.
Definition: KokkosDatum.h:113
KOKKOS_FUNCTION dof_id_type propertyIdx(const PropertyConstantOption constant_option, const unsigned int qp) const
Get the index into the property data storage.
Definition: KokkosDatum.h:278
const dof_id_type _qp_offset
Starting offset into the global quadrature point index.
Definition: KokkosDatum.h:240
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION bool isNodal() const
Get whether the current datum is on a node.
Definition: KokkosDatum.h:146
The Kokkos variable object that carries the coupled variable and tag information. ...
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition: KokkosDatum.h:84
KOKKOS_FUNCTION unsigned int ife() const
Get the variable FE type ID.
Definition: KokkosDatum.h:466
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
KOKKOS_FUNCTION Datum(const ContiguousNodeID node, const Assembly &assembly, const Array< System > &systems)
Constructor for node data.
Definition: KokkosDatum.h:58
const ContiguousElementID _neighbor
Current contiguous element ID of neighbor.
Definition: KokkosDatum.h:232
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:311
KOKKOS_FUNCTION Datum(const ContiguousElementID elem, const unsigned int side, const Assembly &assembly, const Array< System > &systems)
Constructor for element and side data.
Definition: KokkosDatum.h:34
unsigned int _cached_qp
Cached quadrature point index for checking whether the physical transformation data should be recompu...
Definition: KokkosDatum.h:257
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION unsigned int n_dofs() const
Get the number of local DOFs.
Definition: KokkosDatum.h:426
KOKKOS_FUNCTION const System & system(unsigned int sys) const
Get the Kokkos system.
Definition: KokkosDatum.h:73
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
Definition: KokkosDatum.h:123
KOKKOS_FUNCTION const Mesh & mesh() const
Get the Kokkos mesh.
Definition: KokkosDatum.h:78
const Array< System > & _systems
Reference of the Kokkos systems.
Definition: KokkosDatum.h:212
const ContiguousNodeID _node
Current contiguous node ID.
Definition: KokkosDatum.h:228
const unsigned int _ivar
Variable numbers.
Definition: KokkosDatum.h:495
ContiguousElementID id
Contiguous element ID.
Definition: KokkosMesh.h:42
KOKKOS_FUNCTION Real33 getJacobian(ElementInfo info, unsigned int qp) const
Get the inverse of Jacobian matrix of an element quadrature point.
const unsigned int _ife
FE type IDs of variables.
Definition: KokkosDatum.h:499
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
KOKKOS_FUNCTION bool hasNeighbor() const
Get whether the current side has a neighbor.
Definition: KokkosDatum.h:136
uint8_t dof_id_type
Real33 _J
Cached physical transformation data.
Definition: KokkosDatum.h:262
KOKKOS_FUNCTION void computePhysicalMap(const ElementInfo info, const unsigned int qp, Real33 *const jacobian, Real *const JxW, Real3 *const q_points) const
Compute physical transformation data for an element.
KOKKOS_FUNCTION Real3 getQPoint(ElementInfo info, unsigned int qp) const
Get the coordinate of an element quadrature point.