https://mooseframework.inl.gov
KokkosNodalKernel.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 "KokkosNodalKernelBase.h"
13 
14 namespace Moose
15 {
16 namespace Kokkos
17 {
18 
37 {
38 public:
40 
45 
49  virtual void computeResidual() override;
53  virtual void computeJacobian() override;
54 
59 
66  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
67  AssemblyDatum & /* datum */) const
68  {
69  return 0;
70  }
78  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
79  const unsigned int /* qp */,
80  AssemblyDatum & /* datum */) const
81  {
82  return 0;
83  }
95 
99  template <typename Derived>
101  KOKKOS_FUNCTION Real computeQpResidualShim(const Derived & kernel,
102  const unsigned int qp,
103  AssemblyDatum & datum) const
104  {
105  return kernel.computeQpResidual(qp, datum);
106  }
107  template <typename Derived>
108  KOKKOS_FUNCTION Real computeQpJacobianShim(const Derived & kernel,
109  const unsigned int qp,
110  AssemblyDatum & datum) const
111  {
112  return kernel.computeQpJacobian(qp, datum);
113  }
114  template <typename Derived>
115  KOKKOS_FUNCTION Real computeQpOffDiagJacobianShim(const Derived & kernel,
116  const unsigned int jvar,
117  const unsigned int qp,
118  AssemblyDatum & datum) const
119  {
120  return kernel.computeQpOffDiagJacobian(jvar, qp, datum);
121  }
123 
127  template <typename Derived>
129  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const;
130  template <typename Derived>
131  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const;
132  template <typename Derived>
133  KOKKOS_FUNCTION void
134  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const;
136 
137 protected:
142 
143 private:
148 };
149 
150 template <typename Derived>
151 KOKKOS_FUNCTION void
152 NodalKernel::operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const
153 {
155  auto & sys = kokkosSystem(_kokkos_var.sys());
156 
157  if (!sys.isNodalDefined(node, _kokkos_var.var()))
158  return;
159 
161 
162  Real local_re = kernel.computeQpResidualShim(kernel, 0, datum);
163 
164  accumulateTaggedNodalResidual(true, local_re, node);
165 }
166 
167 template <typename Derived>
168 KOKKOS_FUNCTION void
169 NodalKernel::operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const
170 {
172  auto & sys = kokkosSystem(_kokkos_var.sys());
173 
174  if (!sys.isNodalDefined(node, _kokkos_var.var()))
175  return;
176 
178 
179  Real local_ke = kernel.computeQpJacobianShim(kernel, 0, datum);
180 
181  accumulateTaggedNodalMatrix(true, local_ke, node, _kokkos_var.var());
182 }
183 
184 template <typename Derived>
185 KOKKOS_FUNCTION void
186 NodalKernel::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const
187 {
188  auto node = _boundary_restricted ? kokkosBoundaryNodeID(_thread(tid, 1))
189  : kokkosBlockNodeID(_thread(tid, 1));
190  auto & sys = kokkosSystem(_kokkos_var.sys());
191  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
192 
193  if (!sys.isNodalDefined(node, _kokkos_var.var()))
194  return;
195 
196  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
197 
198  Real local_ke = kernel.computeQpOffDiagJacobianShim(kernel, jvar, 0, datum);
199 
200  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
201 }
202 
203 } // namespace Kokkos
204 } // namespace Moose
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a node.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(ThreadID tid) const
Get the contiguous node ID this Kokkos thread is operating on.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION ContiguousElementID kokkosBlockNodeID(ThreadID tid) const
Get the contiguous node index this Kokkos thread is operating on.
dof_id_type ThreadID
Definition: KokkosThread.h:18
const bool _boundary_restricted
Flag whether this kernel is boundary-restricted.
static auto defaultOffDiagJacobian()
Get the function pointer of the default computeQpOffDiagJacobian()
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION void accumulateTaggedNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int comp=0) const
Accumulate or set local nodal residual contribution to tagged vectors.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
The base class for a user to derive their own Kokkos nodal kernels.
Thread _thread
Kokkos thread object.
KOKKOS_FUNCTION Real computeQpOffDiagJacobianShim(const Derived &kernel, const unsigned int jvar, const unsigned int qp, AssemblyDatum &datum) const
virtual void computeResidual() override
Dispatch residual calculation.
The base class for Kokkos nodal kernels.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &kernel) const
The parallel computation entry functions called by Kokkos.
KOKKOS_FUNCTION const System & kokkosSystem(unsigned int sys) const
Get the const reference of a Kokkos system.
Definition: KokkosSystem.h:625
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
NodalKernel(const InputParameters &parameters)
Constructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue _u
Current solution at nodes.
KOKKOS_FUNCTION Real computeQpResidualShim(const Derived &kernel, const unsigned int qp, AssemblyDatum &datum) const
Shims for hook methods that can be leveraged to implement static polymorphism.
static InputParameters validParams()
KOKKOS_FUNCTION Real computeQpJacobianShim(const Derived &kernel, const unsigned int qp, AssemblyDatum &datum) const
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:244
Variable _kokkos_var
Kokkos variable.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
The Kokkos wrapper classes for MOOSE-like variable value access.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION const auto & getCoupling(unsigned int var) const
Get the list of off-diagonal coupled variable numbers of a variable.
Definition: KokkosSystem.h:147
KOKKOS_FUNCTION void accumulateTaggedNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int jvar, const unsigned int comp=0) const
Accumulate or set local nodal Jacobian contribution to tagged matrices.
static auto defaultJacobian()
Get the function pointer of the default computeQpJacobian()
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:608