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::Kokkos
15 {
16 
37 {
38 public:
40 
45 
49  virtual void computeResidual() override;
53  virtual void computeJacobian() override;
54 
59 
67  template <typename Derived>
68  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
69  AssemblyDatum & /* datum */) const
70  {
71  ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
72  "redefined this method in your class without typos.");
73 
74  return 0;
75  }
84  template <typename Derived>
85  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
86  const unsigned int /* qp */,
87  AssemblyDatum & /* datum */) const
88  {
89  ::Kokkos::abort(
90  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
91  "redefined this method in your class without typos.");
92 
93  return 0;
94  }
96 
102  template <typename Derived>
104  static auto defaultJacobian()
105  {
106  return &NodalKernel::computeQpJacobian<Derived>;
107  }
108  template <typename Derived>
110  {
111  return &NodalKernel::computeQpOffDiagJacobian<Derived>;
112  }
114 
118  template <typename Derived>
120  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const;
121  template <typename Derived>
122  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const;
123  template <typename Derived>
124  KOKKOS_FUNCTION void
125  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const;
127 
128 protected:
133 
134 private:
139 };
140 
141 template <typename Derived>
142 KOKKOS_FUNCTION void
143 NodalKernel::operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const
144 {
146  auto & sys = kokkosSystem(_kokkos_var.sys());
147 
148  if (!sys.isNodalDefined(node, _kokkos_var.var()))
149  return;
150 
152 
153  Real local_re = kernel.template computeQpResidual<Derived>(0, datum);
154 
155  accumulateTaggedNodalResidual(true, local_re, node);
156 }
157 
158 template <typename Derived>
159 KOKKOS_FUNCTION void
160 NodalKernel::operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const
161 {
163  auto & sys = kokkosSystem(_kokkos_var.sys());
164 
165  if (!sys.isNodalDefined(node, _kokkos_var.var()))
166  return;
167 
169 
170  Real local_ke = kernel.template computeQpJacobian<Derived>(0, datum);
171 
172  accumulateTaggedNodalMatrix(true, local_ke, node, _kokkos_var.var());
173 }
174 
175 template <typename Derived>
176 KOKKOS_FUNCTION void
177 NodalKernel::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const
178 {
179  auto node = _boundary_restricted ? kokkosBoundaryNodeID(_thread(tid, 1))
180  : kokkosBlockNodeID(_thread(tid, 1));
181  auto & sys = kokkosSystem(_kokkos_var.sys());
182  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
183 
184  if (!sys.isNodalDefined(node, _kokkos_var.var()))
185  return;
186 
187  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
188 
189  Real local_ke = kernel.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
190 
191  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
192 }
193 
194 } // namespace Moose::Kokkos
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...
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 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.
const bool _boundary_restricted
Flag whether this kernel is boundary-restricted.
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.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a node.
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:792
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
The Kokkos wrapper classes for MOOSE-like variable value access.
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()
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
Variable _kokkos_var
Kokkos variable.
KOKKOS_FUNCTION ContiguousElementID kokkosBlockNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node index this Kokkos thread is operating on.
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:146
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.
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:775