https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosFESystem.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 "KokkosSystem.h"
13#include "KokkosAssembly.h"
14
15class MooseMesh;
16class SystemBase;
17
18namespace Moose::Kokkos
19{
20
21class NodalBCBase;
22
27class FESystem : public System, public AssemblyHolder
28{
29public:
35
41 FESystem(System & base, SystemBase & system);
42
43#ifdef MOOSE_KOKKOS_SCOPE
45
49 void reinit();
50
56 KOKKOS_FUNCTION const Array<unsigned int> & getFieldCoupling(unsigned int var) const
57 {
58 return _field_coupling[var];
59 }
60
66 KOKKOS_FUNCTION const Array<unsigned int> & getScalarCoupling(unsigned int var) const
67 {
68 return _scalar_coupling[var];
69 }
70
77 KOKKOS_FUNCTION bool hasNodalBCMatrixTag(dof_id_type dof, TagID tag) const
78 {
79 return _nbc_matrix_tag_dof[tag].isAlloc() && _nbc_matrix_tag_dof[tag][dof];
80 }
81
87 KOKKOS_FUNCTION unsigned int getFETypeID(unsigned int var) const { return _var_fe_types[var]; }
88
96 KOKKOS_FUNCTION dof_id_type getNodeLocalDofIndex(ContiguousNodeID node,
97 unsigned int i,
98 unsigned int var) const
99 {
100 return _local_node_dof_index[var][node] + i;
101 }
102
110 KOKKOS_FUNCTION dof_id_type getNodeGlobalDofIndex(ContiguousNodeID node,
111 unsigned int i,
112 unsigned int var) const
113 {
115 }
116
123 KOKKOS_FUNCTION bool isNodalDefined(ContiguousNodeID node, unsigned int var) const
124 {
126 }
127
135 KOKKOS_FUNCTION ADReal getVectorDofADValue(const dof_id_type dof,
136 const TagID tag,
137 const Real seed) const;
146 KOKKOS_FUNCTION Real & getVectorQpValue(const ElementInfo info,
147 const dof_id_type qp,
148 const unsigned int var,
149 const TagID tag) const
150 {
151 return _qp_solutions[tag](info.subdomain, var)[qp];
152 }
164 KOKKOS_FUNCTION ADReal getVectorQpADValue(const ElementInfo info,
165 const dof_id_type offset,
166 const dof_id_type qp,
167 const unsigned int var,
168 const TagID tag,
169 const Real seed) const;
178 KOKKOS_FUNCTION Real3 & getVectorQpGrad(const ElementInfo info,
179 const dof_id_type qp,
180 const unsigned int var,
181 const TagID tag) const
182 {
183 return _qp_solutions_grad[tag](info.subdomain, var)[qp];
184 }
193 KOKKOS_FUNCTION Real3 & getVectorQpVectorValue(const ElementInfo info,
194 const dof_id_type qp,
195 const unsigned int var,
196 const TagID tag) const
197 {
198 return _qp_vector_solutions[tag](info.subdomain, var)[qp];
199 }
208 KOKKOS_FUNCTION Real33 & getVectorQpVectorGrad(const ElementInfo info,
209 const dof_id_type qp,
210 const unsigned int var,
211 const TagID tag) const
212 {
213 return _qp_vector_solutions_grad[tag](info.subdomain, var)[qp];
214 }
223 KOKKOS_FUNCTION Real3 & getVectorQpVectorCurl(const ElementInfo info,
224 const dof_id_type qp,
225 const unsigned int var,
226 const TagID tag) const
227 {
228 return _qp_vector_solutions_curl[tag](info.subdomain, var)[qp];
229 }
242 KOKKOS_FUNCTION ADReal3 getVectorQpADGrad(const ElementInfo info,
243 const Real33 jacobian,
244 const dof_id_type offset,
245 const dof_id_type qp,
246 const unsigned int var,
247 const TagID tag,
248 const Real seed) const;
258 KOKKOS_FUNCTION Real getVectorQpValueFace(const ElementInfo info,
259 const unsigned int side,
260 const unsigned int qp,
261 const unsigned int var,
262 const TagID tag) const;
272 KOKKOS_FUNCTION Real3 getVectorQpVectorValueFace(const ElementInfo info,
273 const unsigned int side,
274 const unsigned int qp,
275 const unsigned int var,
276 const TagID tag) const;
288 KOKKOS_FUNCTION ADReal getVectorQpADValueFace(const ElementInfo info,
289 const unsigned int side,
290 const unsigned int qp,
291 const unsigned int var,
292 const TagID tag,
293 const Real seed) const;
304 KOKKOS_FUNCTION Real3 getVectorQpGradFace(const ElementInfo info,
305 const unsigned int side,
306 const Real33 jacobian,
307 const unsigned int qp,
308 const unsigned int var,
309 const TagID tag) const;
320 KOKKOS_FUNCTION Real33 getVectorQpVectorGradFace(const ElementInfo info,
321 const unsigned int side,
322 const Real33 jacobian,
323 const unsigned int qp,
324 const unsigned int var,
325 const TagID tag) const;
326
339 KOKKOS_FUNCTION ADReal3 getVectorQpADGradFace(const ElementInfo info,
340 const unsigned int side,
341 const Real33 jacobian,
342 const unsigned int qp,
343 const unsigned int var,
344 const TagID tag,
345 const Real seed) const;
346
350 KOKKOS_FUNCTION void operator()(const ThreadID tid) const;
351#endif
352
353private:
358
362 void setupDofs();
363
368
373
379 void getNodalBCDofs(const NodalBCBase * nbc, Array<bool> & dofs);
380
385
396
401
406
411
419
424};
425
426#ifdef MOOSE_KOKKOS_SCOPE
427
428KOKKOS_FUNCTION inline ADReal
429FESystem::getVectorDofADValue(const dof_id_type dof, TagID tag, const Real seed) const
430{
431 ADReal value = _vectors[tag][dof];
432
433 if (seed != 0)
434 value.derivatives().insert(_local_to_global_dof_index[dof]) = seed;
435
436 return value;
437}
438
439KOKKOS_FUNCTION inline ADReal
441 const dof_id_type offset,
442 const dof_id_type qp,
443 const unsigned int var,
444 const TagID tag,
445 const Real seed) const
446{
447 ADReal value = 0;
448
449 if (seed == 0)
450 value = getVectorQpValue(info, offset + qp, var, tag);
451 else
452 {
453 auto fe = _var_fe_types[var];
454 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
455 auto & phi = kokkosAssembly().getPhi(info.subdomain, info.type, fe);
456
457 for (unsigned int i = 0; i < n_dofs; ++i)
458 value += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * phi(i, qp);
459 }
460
461 return value;
462}
463
464KOKKOS_FUNCTION inline ADReal3
466 const Real33 jacobian,
467 const dof_id_type offset,
468 const dof_id_type qp,
469 const unsigned int var,
470 const TagID tag,
471 const Real seed) const
472{
473 ADReal3 grad;
474
475 if (seed == 0)
476 grad = getVectorQpGrad(info, offset + qp, var, tag);
477 else
478 {
479 auto fe = _var_fe_types[var];
480 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
481 auto & grad_phi = kokkosAssembly().getGradPhi(info.subdomain, info.type, fe);
482
483 for (unsigned int i = 0; i < n_dofs; ++i)
484 grad +=
485 getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * grad_phi(i, qp);
486
487 grad = jacobian * grad;
488 }
489
490 return grad;
491}
492
493KOKKOS_FUNCTION inline Real
495 const unsigned int side,
496 const unsigned int qp,
497 const unsigned int var,
498 const TagID tag) const
499{
500 auto fe = _var_fe_types[var];
501 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
502 auto & phi = kokkosAssembly().getPhiFace(info.subdomain, info.type, fe)(side);
503
504 Real value = 0;
505
506 for (unsigned int i = 0; i < n_dofs; ++i)
507 value += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * phi(i, qp);
508
509 return value;
510}
511
512KOKKOS_FUNCTION inline Real3
514 const unsigned int side,
515 const unsigned int qp,
516 const unsigned int var,
517 const TagID tag) const
518{
519 auto fe = _var_fe_types[var];
520 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
521 auto & phi = kokkosAssembly().getVectorPhiFace(info.subdomain, info.type, fe)(side);
522
523 Real3 value = 0;
524
525 for (unsigned int i = 0; i < n_dofs; ++i)
526 value += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * phi(i, qp);
527
528 return value;
529}
530
531KOKKOS_FUNCTION inline ADReal
533 const unsigned int side,
534 const unsigned int qp,
535 const unsigned int var,
536 const TagID tag,
537 const Real seed) const
538{
539 auto fe = _var_fe_types[var];
540 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
541 auto & phi = kokkosAssembly().getPhiFace(info.subdomain, info.type, fe)(side);
542
543 ADReal value = 0;
544
545 for (unsigned int i = 0; i < n_dofs; ++i)
546 value += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * phi(i, qp);
547
548 return value;
549}
550
551KOKKOS_FUNCTION inline Real3
553 const unsigned int side,
554 const Real33 jacobian,
555 const unsigned int qp,
556 const unsigned int var,
557 const TagID tag) const
558{
559 auto fe = _var_fe_types[var];
560 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
561 auto & grad_phi = kokkosAssembly().getGradPhiFace(info.subdomain, info.type, fe)(side);
562
563 Real3 grad = 0;
564
565 for (unsigned int i = 0; i < n_dofs; ++i)
566 grad += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * grad_phi(i, qp);
567
568 grad = jacobian * grad;
569
570 return grad;
571}
572
573KOKKOS_FUNCTION inline Real33
575 const unsigned int side,
576 const Real33 jacobian,
577 const unsigned int qp,
578 const unsigned int var,
579 const TagID tag) const
580{
581 auto fe = _var_fe_types[var];
582 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
583 auto & grad_phi = kokkosAssembly().getVectorGradPhiFace(info.subdomain, info.type, fe)(side);
584
585 Real33 grad = 0;
586
587 for (unsigned int i = 0; i < n_dofs; ++i)
588 grad += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * grad_phi(i, qp);
589
590 grad = grad * jacobian.transpose();
591
592 return grad;
593}
594
595KOKKOS_FUNCTION inline ADReal3
597 const unsigned int side,
598 const Real33 jacobian,
599 const unsigned int qp,
600 const unsigned int var,
601 const TagID tag,
602 const Real seed) const
603{
604 auto fe = _var_fe_types[var];
605 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
606 auto & grad_phi = kokkosAssembly().getGradPhiFace(info.subdomain, info.type, fe)(side);
607
608 ADReal3 grad = ADReal(0);
609
610 for (unsigned int i = 0; i < n_dofs; ++i)
611 grad += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * grad_phi(i, qp);
612
613 grad = jacobian * grad;
614
615 return grad;
616}
617#endif
618
620} // namespace Moose::Kokkos
dof_id_type ContiguousNodeID
Definition KokkosMesh.h:21
unsigned int TagID
Definition MooseTypes.h:238
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
The Kokkos array class.
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION const auto & getVectorPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the face vector shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION const auto & getPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the face shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION unsigned int getNumDofs(unsigned int elem_type, unsigned int fe_type) const
Get the number of DOFs of a FE type for an element type.
KOKKOS_FUNCTION const auto & getGradPhi(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the gradient of shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION const auto & getGradPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the gradient of face shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION const auto & getVectorGradPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the gradient of face vector shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION const auto & getPhi(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the shape functions of a FE type for an element type and subdomain.
The Kokkos FE system class.
KOKKOS_FUNCTION Real getVectorQpValueFace(const ElementInfo info, const unsigned int side, const unsigned int qp, const unsigned int var, const TagID tag) const
Get the face quadrature point value of a variable from a tagged vector.
Array< Array2D< Array< Real > > > _qp_solutions
Cached elemental quadrature values and gradients.
void setupNodalBCDofs()
Mark the DOFs covered by nodal BCs.
void setupVariables()
Setup variable data.
KOKKOS_FUNCTION ADReal getVectorQpADValueFace(const ElementInfo info, const unsigned int side, const unsigned int qp, const unsigned int var, const TagID tag, const Real seed) const
Get the face quadrature point value of a variable from a tagged vector for automatic differentiation ...
KOKKOS_FUNCTION Real3 getVectorQpVectorValueFace(const ElementInfo info, const unsigned int side, const unsigned int qp, const unsigned int var, const TagID tag) const
Get the face quadrature point value of a vector variable from a tagged vector.
Array< bool > _var_is_vector
Whether each variable is vector-valued.
KOKKOS_FUNCTION ADReal3 getVectorQpADGrad(const ElementInfo info, const Real33 jacobian, const dof_id_type offset, const dof_id_type qp, const unsigned int var, const TagID tag, const Real seed) const
Get the quadrature point gradient of a variable from a tagged vector for automatic differentiation (A...
Array< Array< dof_id_type > > _local_node_dof_index
Local nodal DOF indices of each variable.
KOKKOS_FUNCTION const Array< unsigned int > & getFieldCoupling(unsigned int var) const
Get the list of off-diagonal coupled field variable numbers of a variable.
FESystem(System &base, SystemBase &system)
Constructor for mixed FE+FV simulations, sharing device memory with an existing System.
void getNodalBCDofs(const NodalBCBase *nbc, Array< bool > &dofs)
Get the list of DOFs covered by a nodal BC.
Thread _thread
Kokkos thread object.
KOKKOS_FUNCTION Real3 getVectorQpGradFace(const ElementInfo info, const unsigned int side, const Real33 jacobian, const unsigned int qp, const unsigned int var, const TagID tag) const
Get the face quadrature point gradient of a variable from a tagged vector.
KOKKOS_FUNCTION Real3 & getVectorQpVectorCurl(const ElementInfo info, const dof_id_type qp, const unsigned int var, const TagID tag) const
Get the quadrature point curl of a vector variable from a tagged vector.
KOKKOS_FUNCTION Real33 & getVectorQpVectorGrad(const ElementInfo info, const dof_id_type qp, const unsigned int var, const TagID tag) const
Get the quadrature point gradient of a vector variable from a tagged vector.
KOKKOS_FUNCTION Real33 getVectorQpVectorGradFace(const ElementInfo info, const unsigned int side, const Real33 jacobian, const unsigned int qp, const unsigned int var, const TagID tag) const
Get the face quadrature point gradient of a vector variable from a tagged vector.
Array< Array2D< Array< Real33 > > > _qp_vector_solutions_grad
void setupCoupling()
Setup coupling data between variables.
Array< Array< bool > > _nbc_matrix_tag_dof
Per-matrix-tag local-plus-ghost DOF masks for nodal BC coverage.
KOKKOS_FUNCTION bool isNodalDefined(ContiguousNodeID node, unsigned int var) const
Get whether a variable is defined on a node.
Array< Array< unsigned int > > _field_coupling
Off-diagonal coupled field and scalar variable numbers of each variable.
Array< Array2D< Array< Real3 > > > _qp_vector_solutions_curl
Array< Array2D< Array< Real3 > > > _qp_vector_solutions
void setupDofs()
Setup DOF data.
KOKKOS_FUNCTION ADReal getVectorDofADValue(const dof_id_type dof, const TagID tag, const Real seed) const
Get the DOF value of a tagged vector for automatic differentiation (AD)
Array< unsigned int > _var_fe_types
FE type ID of each variable.
FESystem(SystemBase &system)
Constructor for standalone use (pure FE simulations)
KOKKOS_FUNCTION ADReal3 getVectorQpADGradFace(const ElementInfo info, const unsigned int side, const Real33 jacobian, const unsigned int qp, const unsigned int var, const TagID tag, const Real seed) const
Get the face quadrature point gradient of a variable from a tagged vector for automatic differentiati...
KOKKOS_FUNCTION dof_id_type getNodeGlobalDofIndex(ContiguousNodeID node, unsigned int i, unsigned int var) const
Get the global DOF index of a variable for a node.
KOKKOS_FUNCTION dof_id_type getNodeLocalDofIndex(ContiguousNodeID node, unsigned int i, unsigned int var) const
Get the local DOF index of a variable for a node.
KOKKOS_FUNCTION bool hasNodalBCMatrixTag(dof_id_type dof, TagID tag) const
Check whether a local DOF index is associated with a nodal BC for an extra matrix tag.
KOKKOS_FUNCTION Real3 & getVectorQpGrad(const ElementInfo info, const dof_id_type qp, const unsigned int var, const TagID tag) const
Get the quadrature point gradient of a variable from a tagged vector.
KOKKOS_FUNCTION unsigned int getFETypeID(unsigned int var) const
Get the FE type ID of a variable.
Array< Array2D< Array< Real3 > > > _qp_solutions_grad
void reinit()
Allocate the quadrature point vectors for active variable and tags and cache quadrature point values.
Array< Array< unsigned int > > _scalar_coupling
KOKKOS_FUNCTION void operator()(const ThreadID tid) const
Kokkos function for caching variable values on element quadrature points.
KOKKOS_FUNCTION const Array< unsigned int > & getScalarCoupling(unsigned int var) const
Get the list of off-diagonal coupled scalar variable numbers of a variable.
KOKKOS_FUNCTION Real3 & getVectorQpVectorValue(const ElementInfo info, const dof_id_type qp, const unsigned int var, const TagID tag) const
Get the quadrature point value of a vector variable from a tagged vector.
KOKKOS_FUNCTION ADReal getVectorQpADValue(const ElementInfo info, const dof_id_type offset, const dof_id_type qp, const unsigned int var, const TagID tag, const Real seed) const
Get the quadrature point value of a variable from a tagged vector for automatic differentiation (AD)
KOKKOS_FUNCTION Real & getVectorQpValue(const ElementInfo info, const dof_id_type qp, const unsigned int var, const TagID tag) const
Get the quadrature point value of a variable from a tagged vector.
The base class for Kokkos nodal boundary conditions.
The Kokkos base system class.
KOKKOS_FUNCTION dof_id_type getElemLocalDofIndex(ContiguousElementID elem, unsigned int i, unsigned int var) const
Get the local DOF index of a variable for an element.
KOKKOS_FUNCTION Real & getVectorDofValue(const dof_id_type dof, const TagID tag) const
Get the DOF value of a tagged vector.
Array< dof_id_type > _local_to_global_dof_index
Map from local DOF index to global DOF index.
Array< Vector > _vectors
Kokkos vectors and matrices on device.
The Kokkos thread object that aids in converting the one-dimensional thread index into multi-dimensio...
Base class for deriving any boundary condition that works at nodes.
Definition NodalBCBase.h:28
Base class for a system (of equations)
Definition SystemBase.h:87
static constexpr dof_id_type invalid_id
MakeSystemHolder(FESystem)
MOOSE_KOKKOS_INDEX_TYPE ThreadID
DualNumber< Real, DNDerivativeType, false > ADReal
The Kokkos object that contains the information of an element The IDs used in Kokkos are different fr...
Definition KokkosMesh.h:34
KOKKOS_INLINE_FUNCTION Real33 transpose() const