https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "KokkosFESystem.h"
15#include "KokkosVariable.h"
16
17namespace Moose::Kokkos
18{
19
25{
26public:
33 KOKKOS_FUNCTION
34 MeshDatum(ContiguousElementID elem, const unsigned int side, const Mesh & mesh);
35
40 KOKKOS_FUNCTION const Mesh & mesh() const { return _mesh; }
41
46 KOKKOS_FUNCTION const ElementInfo & elem() const { return _elem; }
47
52 KOKKOS_FUNCTION ContiguousElementID elemID() const { return _elem.id; }
53
58 KOKKOS_FUNCTION bool hasNeighbor() const;
59
67 KOKKOS_FUNCTION const ElementInfo & neighbor() const { return _neighbor; }
68
73 KOKKOS_FUNCTION ContiguousElementID neighborID() const { return _neighbor.id; }
74
79 KOKKOS_FUNCTION unsigned int side() const { return _side; }
80
85 KOKKOS_FUNCTION bool isSide() const { return _side != libMesh::invalid_uint; }
86
91 KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const { return _elem.subdomain; }
92
97 KOKKOS_FUNCTION ContiguousSubdomainID neighborSubdomain() const { return _neighbor.subdomain; }
98
99protected:
113 static KOKKOS_FUNCTION ElementInfo neighborInfo(ContiguousElementID elem,
114 const unsigned int side,
115 const Mesh & mesh);
116
120 const Mesh & _mesh;
121
126
130 const unsigned int _side = libMesh::invalid_uint;
131
136};
137
138KOKKOS_FUNCTION inline MeshDatum::MeshDatum(ContiguousElementID elem,
139 const unsigned int side,
140 const Mesh & mesh)
141 : _mesh(mesh),
142 _elem(elem != libMesh::DofObject::invalid_id ? _mesh.getElementInfo(elem) : ElementInfo{}),
143 _side(side),
144 _neighbor(neighborInfo(_elem.id, _side, _mesh))
145{
146}
147
148KOKKOS_FUNCTION inline bool
153
154KOKKOS_FUNCTION inline ElementInfo
155MeshDatum::neighborInfo(ContiguousElementID elem, const unsigned int side, const Mesh & mesh)
156{
158 return {};
159
160 const auto neighbor = mesh.getNeighbor(elem, side);
162}
163
167class FVDatum : public MeshDatum
168{
169public:
176 KOKKOS_FUNCTION
177 FVDatum(ContiguousElementID elem, const unsigned int side, const Mesh & mesh);
178
184 KOKKOS_FUNCTION Real3 faceCentroid() const { return _mesh.getSideCentroid(_elem.id, _side); }
185
191 KOKKOS_FUNCTION Real3 faceNormal() const { return _mesh.getSideNormal(_elem.id, _side); }
192
198 KOKKOS_FUNCTION Real faceDCNMag() const
199 {
201 }
202
208 KOKKOS_FUNCTION Real faceDCFMag() const
209 {
211 }
212
218 KOKKOS_FUNCTION Real faceArea() const { return _mesh.getSideArea(_elem.id, _side); }
219
225 KOKKOS_FUNCTION Real3 elementCentroid() const { return _mesh.getElementCentroid(_elem.id); }
226
232 KOKKOS_FUNCTION Real elementVolume() const { return _mesh.getElementVolume(_elem.id); }
233};
234
235KOKKOS_FUNCTION inline FVDatum::FVDatum(ContiguousElementID elem,
236 const unsigned int side,
237 const Mesh & mesh)
238 : MeshDatum(elem, side, mesh)
239{
240}
241
245class Datum : public MeshDatum
246{
247public:
255 KOKKOS_FUNCTION
257 const unsigned int side,
258 const Assembly & assembly,
259 const Array<FESystem> & systems);
260
267 KOKKOS_FUNCTION
268 Datum(const ContiguousNodeID node, const Assembly & assembly, const Array<FESystem> & systems);
269
274 KOKKOS_FUNCTION const Assembly & assembly() const { return _assembly; }
275
281 KOKKOS_FUNCTION const FESystem & system(unsigned int sys) const { return _systems[sys]; }
282
288 KOKKOS_FUNCTION dof_id_type extraElemID(unsigned int index) const
289 {
291 }
292
297 KOKKOS_FUNCTION ContiguousNodeID node() const { return _node; }
298
303 KOKKOS_FUNCTION unsigned int n_qps() const { return _n_qps; }
304
309 KOKKOS_FUNCTION dof_id_type qpOffset() const { return _qp_offset; }
310
317 KOKKOS_FUNCTION dof_id_type propertyIdx(const PropertyConstantOption constant_option,
318 const unsigned int qp) const;
319
324 KOKKOS_FUNCTION bool isNodal() const { return _node != libMesh::DofObject::invalid_id; }
325
331 KOKKOS_FUNCTION bool isNodalDefined(const Variable & var) const;
332
341 KOKKOS_FUNCTION const Real33 & J(const unsigned int qp);
342
348 KOKKOS_FUNCTION Real JxW(const unsigned int qp);
349
355 KOKKOS_FUNCTION Real3 q_point(const unsigned int qp);
356
362 KOKKOS_FUNCTION Real3 normals(const unsigned int qp);
363
369 KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id,
370 const unsigned int num_local_threads)
371 {
374 }
379 KOKKOS_FUNCTION unsigned int local_thread_id() const { return _local_thread_id; }
384 KOKKOS_FUNCTION unsigned int num_local_threads() const { return _num_local_threads; }
385
386protected:
391
396
401
405 const unsigned int _n_qps = 1;
406
411
416
417private:
422 KOKKOS_FUNCTION void reinitTransform(const unsigned int qp);
423
434 Real _JxW;
438
441 unsigned int _local_thread_id = 0;
445 unsigned int _num_local_threads = 1;
446};
447
448KOKKOS_FUNCTION inline Datum::Datum(const ContiguousElementID elem,
449 const unsigned int side,
450 const Assembly & assembly,
451 const Array<FESystem> & systems)
452 : MeshDatum(elem, side, assembly.kokkosMesh()),
453 _assembly(assembly),
454 _systems(systems),
455 _n_qps(!isSide() ? assembly.getNumQps(_elem) : assembly.getNumFaceQps(_elem, side)),
456 _qp_offset(!isSide() ? assembly.getQpOffset(_elem) : assembly.getQpFaceOffset(_elem, side)),
457 _elem_property_idx(!isSide() ? _elem.id - _mesh.getStartingContiguousElementID(_elem.subdomain)
458 : assembly.getElemFacePropertyIndex(_elem, _side))
459{
460}
461
462KOKKOS_FUNCTION inline Datum::Datum(const ContiguousNodeID node,
463 const Assembly & assembly,
464 const Array<FESystem> & systems)
465 : MeshDatum(libMesh::DofObject::invalid_id, libMesh::invalid_uint, assembly.kokkosMesh()),
466 _assembly(assembly),
467 _systems(systems),
468 _node(node)
469{
470}
471
472KOKKOS_FUNCTION inline dof_id_type
473Datum::propertyIdx(const PropertyConstantOption constant_option, const unsigned int qp) const
474{
475 dof_id_type idx = 0;
476
477 if (constant_option == PropertyConstantOption::NONE)
478 idx = _qp_offset + qp;
479 else if (constant_option == PropertyConstantOption::ELEMENT)
480 idx = _elem_property_idx;
481
482 return idx;
483}
484
485KOKKOS_FUNCTION inline bool
487{
488 if (!isNodal() || !var.nodal())
489 return false;
490
491 return _systems[var.sys()].isNodalDefined(_node, var.var());
492}
493
494KOKKOS_FUNCTION inline const Real33 &
495Datum::J(const unsigned int qp)
496{
497 if (!isNodal())
498 reinitTransform(qp);
499 else
501
502 return _J;
503}
504
505KOKKOS_FUNCTION inline Real
506Datum::JxW(const unsigned int qp)
507{
508 if (!isNodal())
509 reinitTransform(qp);
510 else
511 _JxW = 1;
512
513 return _JxW;
514}
515
516KOKKOS_FUNCTION inline Real3
517Datum::q_point(const unsigned int qp)
518{
519 if (!isNodal())
520 reinitTransform(qp);
521 else
523
524 return _xyz;
525}
526
527KOKKOS_FUNCTION inline Real3
528Datum::normals(const unsigned int qp)
529{
530 KOKKOS_ASSERT(isSide());
531
532 if (isSide())
533 reinitTransform(qp);
534
535 return _normal;
536}
537
538KOKKOS_FUNCTION inline void
539Datum::reinitTransform(const unsigned int qp)
540{
541 if (_cached_qp == qp)
542 return;
543
544 if (!isSide())
545 {
547 _JxW = _assembly.getJxW(_elem, qp);
549 }
550 else
552
553 _cached_qp = qp;
554}
555
559class AssemblyDatum : public Datum
560{
561public:
572 KOKKOS_FUNCTION
574 const unsigned int side,
575 const Assembly & assembly,
576 const Array<FESystem> & systems,
577 const Variable & ivar,
578 const unsigned int jvar,
579 const unsigned int comp = 0)
580 : Datum(elem, side, assembly, systems),
581 _tag(ivar.tag()),
582 _sys(ivar.sys(comp)),
583 _ivar(ivar.var(comp)),
584 _jvar(jvar),
585 _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
586 _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar)),
587 _n_idofs(assembly.getNumDofs(_elem.type, _ife)),
588 _n_jdofs(assembly.getNumDofs(_elem.type, _jfe))
589 {
590 }
600 KOKKOS_FUNCTION
602 const Assembly & assembly,
603 const Array<FESystem> & systems,
604 const Variable & ivar,
605 const unsigned int jvar,
606 const unsigned int comp = 0)
607 : Datum(node, assembly, systems),
608 _tag(ivar.tag()),
609 _sys(ivar.sys(comp)),
610 _ivar(ivar.var(comp)),
611 _jvar(jvar),
612 _ife(systems[ivar.sys(comp)].getFETypeID(_ivar)),
613 _jfe(systems[ivar.sys(comp)].getFETypeID(_jvar))
614 {
615 }
616
621 KOKKOS_FUNCTION unsigned int n_dofs() const { return _n_idofs; }
626 KOKKOS_FUNCTION unsigned int n_idofs() const { return _n_idofs; }
631 KOKKOS_FUNCTION unsigned int n_jdofs() const { return _n_jdofs; }
636 KOKKOS_FUNCTION unsigned int sys() const { return _sys; }
641 KOKKOS_FUNCTION unsigned int var() const { return _ivar; }
646 KOKKOS_FUNCTION unsigned int ivar() const { return _ivar; }
651 KOKKOS_FUNCTION unsigned int jvar() const { return _jvar; }
656 KOKKOS_FUNCTION unsigned int fe() const { return _ife; }
661 KOKKOS_FUNCTION unsigned int ife() const { return _ife; }
666 KOKKOS_FUNCTION unsigned int jfe() const { return _jfe; }
671 KOKKOS_FUNCTION void do_derivatives(const bool flag) { _do_derivatives = flag; }
676 KOKKOS_FUNCTION bool do_derivatives() const { return _do_derivatives; }
677
678protected:
682 const TagID _tag;
686 const unsigned int _sys;
690 const unsigned int _ivar, _jvar;
694 const unsigned int _ife, _jfe;
698 const unsigned int _n_idofs = 1, _n_jdofs = 1;
702 bool _do_derivatives = true;
703};
704
705} // namespace Moose::Kokkos
706
dof_id_type ContiguousElementID
Definition KokkosMesh.h:20
dof_id_type ContiguousNodeID
Definition KokkosMesh.h:21
unsigned int TagID
Definition MooseTypes.h:238
The Kokkos array class.
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels.
KOKKOS_FUNCTION unsigned int ivar() const
Get the variable number.
KOKKOS_FUNCTION AssemblyDatum(const ContiguousNodeID node, const Assembly &assembly, const Array< FESystem > &systems, const Variable &ivar, const unsigned int jvar, const unsigned int comp=0)
Constructor for node data.
const unsigned int _ivar
Variable numbers.
KOKKOS_FUNCTION AssemblyDatum(const ContiguousElementID elem, const unsigned int side, const Assembly &assembly, const Array< FESystem > &systems, const Variable &ivar, const unsigned int jvar, const unsigned int comp=0)
Constructor for element and side data.
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
KOKKOS_FUNCTION unsigned int jfe() const
Get the coupled variable FE type ID.
bool _do_derivatives
Whether to compute derivatives for automatic differentiation (AD)
KOKKOS_FUNCTION bool do_derivatives() const
Get whether to compute derivatives for automatic differentiation (AD)
KOKKOS_FUNCTION unsigned int n_dofs() const
Get the number of local DOFs.
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
KOKKOS_FUNCTION unsigned int n_idofs() const
Get the number of local DOFs.
const unsigned int _jfe
const unsigned int _jvar
const unsigned int _ife
FE type IDs of variables.
const unsigned int _n_idofs
Number of local DOFs.
KOKKOS_FUNCTION unsigned int ife() const
Get the variable FE type ID.
const TagID _tag
Solution tag ID.
KOKKOS_FUNCTION unsigned int n_jdofs() const
Get the number of local DOFs for the coupled variable.
const unsigned int _n_jdofs
const unsigned int _sys
System number.
KOKKOS_FUNCTION unsigned int var() const
Get the variable number.
KOKKOS_FUNCTION unsigned int fe() const
Get the variable FE type ID.
The Kokkos assembly class.
KOKKOS_FUNCTION Real getJxW(ElementInfo info, unsigned int qp) const
Get the transformed Jacobian weight of an element quadrature point.
KOKKOS_FUNCTION unsigned int getDimension() const
Get the mesh dimension.
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 Real33 getJacobian(ElementInfo info, unsigned int qp) const
Get the inverse of Jacobian matrix of an element quadrature point.
KOKKOS_FUNCTION Real3 getQPoint(ElementInfo info, unsigned int qp) const
Get the coordinate of an element quadrature point.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
Real33 _J
Cached physical transformation data.
KOKKOS_FUNCTION unsigned int num_local_threads() const
Get the number of local threads.
const Assembly & _assembly
Reference of the Kokkos assembly.
KOKKOS_FUNCTION bool isNodalDefined(const Variable &var) const
Get whether the a variable is defined on the current node.
KOKKOS_FUNCTION const FESystem & system(unsigned int sys) const
Get the Kokkos system.
unsigned int _cached_qp
Cached quadrature point index for checking whether the physical transformation data should be recompu...
unsigned int _local_thread_id
Thread ID for local parallelization.
const dof_id_type _elem_property_idx
Index for element-constant material properties.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
const Array< FESystem > & _systems
Reference of the Kokkos systems.
KOKKOS_FUNCTION unsigned int local_thread_id() const
Get the current local thread ID.
const dof_id_type _qp_offset
Starting offset into the global quadrature point index.
const ContiguousNodeID _node
Current contiguous node ID.
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...
KOKKOS_FUNCTION dof_id_type extraElemID(unsigned int index) const
Get the extra element ID.
KOKKOS_FUNCTION Real3 normals(const unsigned int qp)
Get the normal vector on surface.
KOKKOS_FUNCTION Datum(const ContiguousElementID elem, const unsigned int side, const Assembly &assembly, const Array< FESystem > &systems)
Constructor for element and side data.
KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
KOKKOS_FUNCTION ContiguousNodeID node() const
Get the contiguous node ID.
unsigned int _num_local_threads
Number of threads for local parallelization.
KOKKOS_FUNCTION Real3 q_point(const unsigned int qp)
Get the physical quadrature point coordinate.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
KOKKOS_FUNCTION dof_id_type propertyIdx(const PropertyConstantOption constant_option, const unsigned int qp) const
Get the index into the property data storage.
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
KOKKOS_FUNCTION const Assembly & assembly() const
Get the Kokkos assembly.
KOKKOS_FUNCTION void reinitTransform(const unsigned int qp)
Compute and cache the physical transformation data.
const unsigned int _n_qps
Number of local quadrature points.
KOKKOS_FUNCTION bool isNodal() const
Get whether the current datum is on a node.
The Kokkos FE system class.
Device-side geometric context for finite volume kernels and boundary conditions.
KOKKOS_FUNCTION Real elementVolume() const
Get the coordinate-weighted current element volume.
KOKKOS_FUNCTION Real3 faceCentroid() const
Get the centroid of the current element side.
KOKKOS_FUNCTION Real faceArea() const
Get the coordinate-weighted area of the current element side.
KOKKOS_FUNCTION Real3 elementCentroid() const
Get the current element centroid.
KOKKOS_FUNCTION Real faceDCNMag() const
Get the distance from the current element centroid to its neighbor centroid.
KOKKOS_FUNCTION Real3 faceNormal() const
Get the outward unit normal of the current element side.
KOKKOS_FUNCTION Real faceDCFMag() const
Get the distance from the current element centroid to the current side centroid.
KOKKOS_FUNCTION FVDatum(ContiguousElementID elem, const unsigned int side, const Mesh &mesh)
Constructor.
Generic datum class containing geometric information related to the mesh.
Definition KokkosDatum.h:25
KOKKOS_FUNCTION ContiguousElementID neighborID() const
Get the contiguous neighbor element ID.
Definition KokkosDatum.h:73
static KOKKOS_FUNCTION ElementInfo neighborInfo(ContiguousElementID elem, const unsigned int side, const Mesh &mesh)
Get the neighbor element information object for an element side.
KOKKOS_FUNCTION bool isSide() const
Get whether the current datum is on a side.
Definition KokkosDatum.h:85
const ElementInfo _neighbor
Current neighbor element information object.
KOKKOS_FUNCTION ContiguousSubdomainID neighborSubdomain() const
Get the contiguous neighbor subdomain ID.
Definition KokkosDatum.h:97
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition KokkosDatum.h:79
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition KokkosDatum.h:46
KOKKOS_FUNCTION const ElementInfo & neighbor() const
Get the neighbor element information object.
Definition KokkosDatum.h:67
KOKKOS_FUNCTION ContiguousElementID elemID() const
Get the contiguous element ID.
Definition KokkosDatum.h:52
KOKKOS_FUNCTION const Mesh & mesh() const
Get the Kokkos mesh.
Definition KokkosDatum.h:40
const Mesh & _mesh
Reference to the Kokkos mesh.
const unsigned int _side
Current side index.
KOKKOS_FUNCTION bool hasNeighbor() const
Get whether the current side has a neighbor.
KOKKOS_FUNCTION ContiguousSubdomainID subdomain() const
Get the contiguous subdomain ID.
Definition KokkosDatum.h:91
const ElementInfo _elem
Current element information object.
KOKKOS_FUNCTION MeshDatum(ContiguousElementID elem, const unsigned int side, const Mesh &mesh)
Constructor.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition KokkosMesh.h:651
The Kokkos mesh object.
Definition KokkosMesh.h:53
KOKKOS_FUNCTION Real3 getSideCentroid(ContiguousElementID elem, unsigned int side) const
Get the centroid of an element side.
Definition KokkosMesh.h:239
KOKKOS_FUNCTION dof_id_type getExtraElementID(ContiguousElementID elem, unsigned int index) const
Get the extra element ID of an element.
Definition KokkosMesh.h:383
KOKKOS_FUNCTION const auto & getElementInfo(ContiguousElementID elem) const
Get the element information object.
Definition KokkosMesh.h:206
KOKKOS_FUNCTION Real3 getNodePoint(ContiguousNodeID node) const
Get the coordinate of a node.
Definition KokkosMesh.h:428
KOKKOS_FUNCTION Real getElementCentroidToSideCentroidDistance(ContiguousElementID elem, unsigned int side) const
Get the element-centroid to side-centroid distance for an element side.
Definition KokkosMesh.h:273
KOKKOS_FUNCTION Real getElementCentroidToNeighborCentroidDistance(ContiguousElementID elem, unsigned int side) const
Get the element-centroid to neighbor-centroid distance for an element side with a neighbor.
Definition KokkosMesh.h:299
KOKKOS_FUNCTION Real getElementVolume(ContiguousElementID elem) const
Get the coordinate-weighted volume of a local element.
Definition KokkosMesh.h:319
KOKKOS_FUNCTION ContiguousElementID getNeighbor(ContiguousElementID elem, unsigned int side) const
Get the neighbor contiguous element ID.
Definition KokkosMesh.h:218
KOKKOS_FUNCTION Real3 getElementCentroid(ContiguousElementID elem) const
Get the centroid of a local element.
Definition KokkosMesh.h:330
KOKKOS_FUNCTION Real getSideArea(ContiguousElementID elem, unsigned int side) const
Get the coordinate-weighted area of an element side.
Definition KokkosMesh.h:228
KOKKOS_FUNCTION Real3 getSideNormal(ContiguousElementID elem, unsigned int side) const
Get the outward unit normal of an element side.
Definition KokkosMesh.h:250
The Kokkos variable object that carries the coupled variable and tag information.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION bool nodal() const
Get whether the variable is nodal.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
static constexpr dof_id_type invalid_id
MeshBase & mesh
PropertyConstantOption
Property constant options.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const unsigned int invalid_uint
The Kokkos object that contains the information of an element The IDs used in Kokkos are different fr...
Definition KokkosMesh.h:34
ContiguousElementID id
Contiguous element ID.
Definition KokkosMesh.h:42
ContiguousSubdomainID subdomain
Contiguous subdomain ID.
Definition KokkosMesh.h:46
KOKKOS_INLINE_FUNCTION void identity(const unsigned int dim=3)