https://mooseframework.inl.gov
KokkosVectorNodalBC.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 "KokkosNodalBCBase.h"
13 
14 namespace Moose::Kokkos
15 {
16 
21 class VectorNodalBC : public NodalBCBase
22 {
23 public:
25 
30 
34  virtual void computeResidual() override;
38  virtual void computeJacobian() override;
39 
44  template <typename Derived>
46  KOKKOS_FUNCTION Real3 computeQpJacobian(const unsigned int /* qp */,
47  AssemblyDatum & /* datum */) const
48  {
49  return Real3(1);
50  }
51  template <typename Derived>
52  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
53  const unsigned int /* qp */,
54  AssemblyDatum & /* datum */) const
55  {
56  ::Kokkos::abort(
57  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
58  "redefined this method in your class without typos.");
59 
60  return 0;
61  }
63 
68  template <typename Derived>
70  static auto defaultJacobian()
71  {
72  return &VectorNodalBC::computeQpJacobian<Derived>;
73  }
74  template <typename Derived>
75  static auto defaultOffDiagJacobian()
76  {
77  return &VectorNodalBC::computeQpOffDiagJacobian<Derived>;
78  }
80 
84  template <typename Derived>
86  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
87  template <typename Derived>
88  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
89  template <typename Derived>
90  KOKKOS_FUNCTION void
91  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
93 
94 protected:
99 };
100 
101 template <typename Derived>
102 KOKKOS_FUNCTION void
103 VectorNodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
104 {
105  auto node = kokkosBoundaryNodeID(tid);
106  auto & sys = kokkosSystem(_kokkos_var.sys());
107 
108  if (!sys.isNodalDefined(node, _kokkos_var.var()))
109  return;
110 
111  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
112 
113  Real3 local_re = bc.template computeQpResidual<Derived>(0, datum);
114 
115  for (unsigned int comp = 0; comp < _dimension; ++comp)
116  accumulateTaggedVectorNodalResidual(false, local_re(comp), node, comp);
117 }
118 
119 template <typename Derived>
120 KOKKOS_FUNCTION void
121 VectorNodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
122 {
123  auto node = kokkosBoundaryNodeID(tid);
124  auto & sys = kokkosSystem(_kokkos_var.sys());
125 
126  if (!sys.isNodalDefined(node, _kokkos_var.var()))
127  return;
128 
129  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
130 
131  Real3 local_ke = bc.template computeQpJacobian<Derived>(0, datum);
132 
133  for (unsigned int comp = 0; comp < _dimension; ++comp)
134  accumulateTaggedVectorNodalMatrix(false, local_ke(comp), node, comp, comp, _kokkos_var.var());
135 }
136 
137 template <typename Derived>
138 KOKKOS_FUNCTION void
139 VectorNodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
140 {
141  auto node = kokkosBoundaryNodeID(_thread(tid, 1));
142  auto & sys = kokkosSystem(_kokkos_var.sys());
143  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
144 
145  if (!sys.isNodalDefined(node, _kokkos_var.var()))
146  return;
147 
148  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
149 
150  Real3 local_ke = bc.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
151 
152  for (unsigned int comp = 0; comp < _dimension; ++comp)
153  accumulateTaggedVectorNodalMatrix(true, local_ke(comp), node, comp, 0, jvar);
154 }
155 
156 } // namespace Moose::Kokkos
Vector3< Real > Real3
Definition: KokkosTypes.h:32
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node ID this Kokkos thread is operating on.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Thread _thread
Kokkos thread object.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
virtual void computeResidual() override
Dispatch residual calculation.
The base class for a user to derive their own Kokkos nodal boundary conditions on vector variables...
const VectorVariableValue _u
Current vector solution at nodes.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
KOKKOS_FUNCTION void accumulateTaggedVectorNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int i) const
Accumulate or set local nodal residual contribution to tagged vectors for vector FE variables...
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
VectorNodalBC(const InputParameters &parameters)
Constructor.
The base class for Kokkos nodal boundary conditions.
KOKKOS_FUNCTION void accumulateTaggedVectorNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int i, const unsigned int j, const unsigned int jvar) const
Accumulate or set local nodal Jacobian contribution to tagged matrices for vector FE variables...
KOKKOS_FUNCTION Real3 computeQpJacobian(const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:559
static InputParameters validParams()
Variable _kokkos_var
Kokkos variable.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
const unsigned int _dimension
Mesh dimension.