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  ResidualDatum & /* datum */) const
68  {
69  return 0;
70  }
78  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
79  const unsigned int /* qp */,
80  ResidualDatum & /* datum */) const
81  {
82  return 0;
83  }
95 
99  template <typename Derived>
101  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const;
102  template <typename Derived>
103  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const;
104  template <typename Derived>
105  KOKKOS_FUNCTION void
106  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const;
108 
109 protected:
114 
115 private:
120 };
121 
122 template <typename Derived>
123 KOKKOS_FUNCTION void
124 NodalKernel::operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const
125 {
127  auto & sys = kokkosSystem(_kokkos_var.sys());
128 
129  if (!sys.isNodalDefined(node, _kokkos_var.var()))
130  return;
131 
133 
134  Real local_re = kernel.computeQpResidual(0, datum);
135 
136  accumulateTaggedNodalResidual(true, local_re, node);
137 }
138 
139 template <typename Derived>
140 KOKKOS_FUNCTION void
141 NodalKernel::operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const
142 {
144  auto & sys = kokkosSystem(_kokkos_var.sys());
145 
146  if (!sys.isNodalDefined(node, _kokkos_var.var()))
147  return;
148 
150 
151  Real local_ke = kernel.computeQpJacobian(0, datum);
152 
153  accumulateTaggedNodalMatrix(true, local_ke, node, _kokkos_var.var());
154 }
155 
156 template <typename Derived>
157 KOKKOS_FUNCTION void
158 NodalKernel::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const
159 {
160  auto node = _boundary_restricted ? kokkosBoundaryNodeID(_thread(tid, 1))
161  : kokkosBlockNodeID(_thread(tid, 1));
162  auto & sys = kokkosSystem(_kokkos_var.sys());
163  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
164 
165  if (!sys.isNodalDefined(node, _kokkos_var.var()))
166  return;
167 
168  ResidualDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
169 
170  Real local_ke = kernel.computeQpOffDiagJacobian(jvar, 0, datum);
171 
172  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
173 }
174 
175 } // namespace Kokkos
176 } // namespace Moose
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.
virtual void computeResidual() override
Dispatch residual calculation.
The base class for Kokkos nodal kernels.
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int, ResidualDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
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:615
NodalKernel(const InputParameters &parameters)
Constructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue _u
Current solution at nodes.
static InputParameters validParams()
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 Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, ResidualDatum &) const
Compute off-diagonal Jacobian contribution on a node.
KOKKOS_FUNCTION const auto & getCoupling(unsigned int var) const
Get the list of off-diagonal coupled variable numbers of a variable.
Definition: KokkosSystem.h:140
The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual object...
Definition: KokkosDatum.h:245
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:598