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://mooseframework.inl.gov
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 auto getLocalConstraints(dof_id_type dof) const
57 {
58 return _local_constraints.size() ? _local_constraints[dof]
59 : decltype(_local_constraints[dof])(nullptr, {});
60 }
61
67 KOKKOS_FUNCTION const Array<unsigned int> & getFieldCoupling(unsigned int var) const
68 {
69 return _field_coupling[var];
70 }
71
77 KOKKOS_FUNCTION const Array<unsigned int> & getScalarCoupling(unsigned int var) const
78 {
79 return _scalar_coupling[var];
80 }
81
88 KOKKOS_FUNCTION bool hasNodalBCMatrixTag(dof_id_type dof, TagID tag) const
89 {
90 return _nbc_matrix_tag_dof[tag].isAlloc() && _nbc_matrix_tag_dof[tag][dof];
91 }
92
98 KOKKOS_FUNCTION unsigned int getFETypeID(unsigned int var) const { return _var_fe_types[var]; }
99
107 KOKKOS_FUNCTION dof_id_type getNodeLocalDofIndex(ContiguousNodeID node,
108 unsigned int i,
109 unsigned int var) const
110 {
111 return _local_node_dof_index[var][node] + i;
112 }
113
121 KOKKOS_FUNCTION dof_id_type getNodeGlobalDofIndex(ContiguousNodeID node,
122 unsigned int i,
123 unsigned int var) const
124 {
126 }
127
134 KOKKOS_FUNCTION bool isNodalDefined(ContiguousNodeID node, unsigned int var) const
135 {
137 }
138
146 KOKKOS_FUNCTION ADReal getVectorDofADValue(const dof_id_type dof,
147 const TagID tag,
148 const Real seed) const;
157 KOKKOS_FUNCTION Real & getVectorQpValue(const ElementInfo info,
158 const dof_id_type qp,
159 const unsigned int var,
160 const TagID tag) const
161 {
162 return _qp_solutions[tag](info.subdomain, var)[qp];
163 }
175 KOKKOS_FUNCTION ADReal getVectorQpADValue(const ElementInfo info,
176 const dof_id_type offset,
177 const dof_id_type qp,
178 const unsigned int var,
179 const TagID tag,
180 const Real seed) const;
189 KOKKOS_FUNCTION Real3 & getVectorQpGrad(const ElementInfo info,
190 const dof_id_type qp,
191 const unsigned int var,
192 const TagID tag) const
193 {
194 return _qp_solutions_grad[tag](info.subdomain, var)[qp];
195 }
204 KOKKOS_FUNCTION Real3 & getVectorQpVectorValue(const ElementInfo info,
205 const dof_id_type qp,
206 const unsigned int var,
207 const TagID tag) const
208 {
209 return _qp_vector_solutions[tag](info.subdomain, var)[qp];
210 }
219 KOKKOS_FUNCTION Real33 & getVectorQpVectorGrad(const ElementInfo info,
220 const dof_id_type qp,
221 const unsigned int var,
222 const TagID tag) const
223 {
224 return _qp_vector_solutions_grad[tag](info.subdomain, var)[qp];
225 }
234 KOKKOS_FUNCTION Real3 & getVectorQpVectorCurl(const ElementInfo info,
235 const dof_id_type qp,
236 const unsigned int var,
237 const TagID tag) const
238 {
239 return _qp_vector_solutions_curl[tag](info.subdomain, var)[qp];
240 }
253 KOKKOS_FUNCTION ADReal3 getVectorQpADGrad(const ElementInfo info,
254 const Real33 jacobian,
255 const dof_id_type offset,
256 const dof_id_type qp,
257 const unsigned int var,
258 const TagID tag,
259 const Real seed) const;
269 KOKKOS_FUNCTION Real getVectorQpValueFace(const ElementInfo info,
270 const unsigned int side,
271 const unsigned int qp,
272 const unsigned int var,
273 const TagID tag) const;
283 KOKKOS_FUNCTION Real3 getVectorQpVectorValueFace(const ElementInfo info,
284 const unsigned int side,
285 const unsigned int qp,
286 const unsigned int var,
287 const TagID tag) const;
299 KOKKOS_FUNCTION ADReal getVectorQpADValueFace(const ElementInfo info,
300 const unsigned int side,
301 const unsigned int qp,
302 const unsigned int var,
303 const TagID tag,
304 const Real seed) const;
315 KOKKOS_FUNCTION Real3 getVectorQpGradFace(const ElementInfo info,
316 const unsigned int side,
317 const Real33 jacobian,
318 const unsigned int qp,
319 const unsigned int var,
320 const TagID tag) const;
331 KOKKOS_FUNCTION Real33 getVectorQpVectorGradFace(const ElementInfo info,
332 const unsigned int side,
333 const Real33 jacobian,
334 const unsigned int qp,
335 const unsigned int var,
336 const TagID tag) const;
337
350 KOKKOS_FUNCTION ADReal3 getVectorQpADGradFace(const ElementInfo info,
351 const unsigned int side,
352 const Real33 jacobian,
353 const unsigned int qp,
354 const unsigned int var,
355 const TagID tag,
356 const Real seed) const;
357
361 KOKKOS_FUNCTION void operator()(const ThreadID tid) const;
362#endif
363
364private:
369
373 void setupDofs();
374
379
384
390 void getNodalBCDofs(const NodalBCBase * nbc, Array<bool> & dofs);
391
396
407
412
417
422
430
435
440};
441
442#ifdef MOOSE_KOKKOS_SCOPE
443
444KOKKOS_FUNCTION inline ADReal
445FESystem::getVectorDofADValue(const dof_id_type dof, TagID tag, const Real seed) const
446{
447 ADReal value = _vectors[tag][dof];
448
449 if (seed != 0)
450 value.derivatives().insert(dof) = seed;
451
452 return value;
453}
454
455KOKKOS_FUNCTION inline ADReal
457 const dof_id_type offset,
458 const dof_id_type qp,
459 const unsigned int var,
460 const TagID tag,
461 const Real seed) const
462{
463 ADReal value = 0;
464
465 if (seed == 0)
466 value = getVectorQpValue(info, offset + qp, var, tag);
467 else
468 {
469 auto fe = _var_fe_types[var];
470 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
471 auto & phi = kokkosAssembly().getPhi(info.subdomain, info.type, fe);
472
473 for (unsigned int i = 0; i < n_dofs; ++i)
474 value += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * phi(i, qp);
475 }
476
477 return value;
478}
479
480KOKKOS_FUNCTION inline ADReal3
482 const Real33 jacobian,
483 const dof_id_type offset,
484 const dof_id_type qp,
485 const unsigned int var,
486 const TagID tag,
487 const Real seed) const
488{
489 ADReal3 grad;
490
491 if (seed == 0)
492 grad = getVectorQpGrad(info, offset + qp, var, tag);
493 else
494 {
495 auto fe = _var_fe_types[var];
496 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
497 auto & grad_phi = kokkosAssembly().getGradPhi(info.subdomain, info.type, fe);
498
499 for (unsigned int i = 0; i < n_dofs; ++i)
500 grad +=
501 getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * grad_phi(i, qp);
502
503 grad = jacobian * grad;
504 }
505
506 return grad;
507}
508
509KOKKOS_FUNCTION inline Real
511 const unsigned int side,
512 const unsigned int qp,
513 const unsigned int var,
514 const TagID tag) const
515{
516 auto fe = _var_fe_types[var];
517 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
518 auto & phi = kokkosAssembly().getPhiFace(info.subdomain, info.type, fe)(side);
519
520 Real value = 0;
521
522 for (unsigned int i = 0; i < n_dofs; ++i)
523 value += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * phi(i, qp);
524
525 return value;
526}
527
528KOKKOS_FUNCTION inline Real3
530 const unsigned int side,
531 const unsigned int qp,
532 const unsigned int var,
533 const TagID tag) const
534{
535 auto fe = _var_fe_types[var];
536 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
537 auto & phi = kokkosAssembly().getVectorPhiFace(info.subdomain, info.type, fe)(side);
538
539 Real3 value = 0;
540
541 for (unsigned int i = 0; i < n_dofs; ++i)
542 value += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * phi(i, qp);
543
544 return value;
545}
546
547KOKKOS_FUNCTION inline ADReal
549 const unsigned int side,
550 const unsigned int qp,
551 const unsigned int var,
552 const TagID tag,
553 const Real seed) const
554{
555 auto fe = _var_fe_types[var];
556 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
557 auto & phi = kokkosAssembly().getPhiFace(info.subdomain, info.type, fe)(side);
558
559 ADReal value = 0;
560
561 for (unsigned int i = 0; i < n_dofs; ++i)
562 value += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * phi(i, qp);
563
564 return value;
565}
566
567KOKKOS_FUNCTION inline Real3
569 const unsigned int side,
570 const Real33 jacobian,
571 const unsigned int qp,
572 const unsigned int var,
573 const TagID tag) const
574{
575 auto fe = _var_fe_types[var];
576 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
577 auto & grad_phi = kokkosAssembly().getGradPhiFace(info.subdomain, info.type, fe)(side);
578
579 Real3 grad = 0;
580
581 for (unsigned int i = 0; i < n_dofs; ++i)
582 grad += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * grad_phi(i, qp);
583
584 grad = jacobian * grad;
585
586 return grad;
587}
588
589KOKKOS_FUNCTION inline Real33
591 const unsigned int side,
592 const Real33 jacobian,
593 const unsigned int qp,
594 const unsigned int var,
595 const TagID tag) const
596{
597 auto fe = _var_fe_types[var];
598 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
599 auto & grad_phi = kokkosAssembly().getVectorGradPhiFace(info.subdomain, info.type, fe)(side);
600
601 Real33 grad = 0;
602
603 for (unsigned int i = 0; i < n_dofs; ++i)
604 grad += getVectorDofValue(getElemLocalDofIndex(info.id, i, var), tag) * grad_phi(i, qp);
605
606 grad = grad * jacobian.transpose();
607
608 return grad;
609}
610
611KOKKOS_FUNCTION inline ADReal3
613 const unsigned int side,
614 const Real33 jacobian,
615 const unsigned int qp,
616 const unsigned int var,
617 const TagID tag,
618 const Real seed) const
619{
620 auto fe = _var_fe_types[var];
621 auto n_dofs = kokkosAssembly().getNumDofs(info.type, fe);
622 auto & grad_phi = kokkosAssembly().getGradPhiFace(info.subdomain, info.type, fe)(side);
623
624 ADReal3 grad = ADReal(0);
625
626 for (unsigned int i = 0; i < n_dofs; ++i)
627 grad += getVectorDofADValue(getElemLocalDofIndex(info.id, i, var), tag, seed) * grad_phi(i, qp);
628
629 grad = jacobian * grad;
630
631 return grad;
632}
633#endif
634
636} // 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 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.
JaggedArray< Pair< dof_id_type, Real >, 1, 1 > _local_constraints
Constraining DOFs and weights of each constrained local or ghost DOF.
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
KOKKOS_FUNCTION auto getLocalConstraints(dof_id_type dof) const
Get the local-indexed constraint of a local DOF.
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 Kokkos jagged array class.
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