https://mooseframework.inl.gov
KokkosKernelValue.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 "KokkosKernel.h"
13 
14 namespace Moose::Kokkos
15 {
16 
41 class KernelValue : public Kernel
42 {
43 public:
45 
47  static constexpr bool use_precompute_hooks = true;
48 
53 
58 
68  template <typename Derived>
69  KOKKOS_FUNCTION Real precomputeQpJacobian(const unsigned int /* j */,
70  const unsigned int /* qp */,
71  AssemblyDatum & /* datum */) const
72  {
73  ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
74  "redefined this method in your class without typos.");
75 
76  return 0;
77  }
88  template <typename Derived>
89  KOKKOS_FUNCTION Real precomputeQpOffDiagJacobian(const unsigned int /* j */,
90  const unsigned int /* jvar */,
91  const unsigned int /* qp */,
92  AssemblyDatum & /* datum */) const
93  {
94  ::Kokkos::abort(
95  "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
96  "redefined this method in your class without typos.");
97 
98  return 0;
99  }
101 
107  template <typename Derived>
109  static auto defaultJacobian()
110  {
111  return &KernelValue::precomputeQpJacobian<Derived>;
112  }
113  template <typename Derived>
115  {
116  return &KernelValue::precomputeQpOffDiagJacobian<Derived>;
117  }
119 
124  template <typename Derived>
126  KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
127  template <typename Derived>
128  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
129  template <typename Derived>
130  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
131  AssemblyDatum & datum) const;
133 };
134 
135 template <typename Derived>
136 KOKKOS_FUNCTION void
137 KernelValue::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
138 {
140  datum,
141  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
142  {
143  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
144  {
145  Real value = datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum);
146 
147  for (unsigned int i = ib; i < ie; ++i)
148  local_re[i] += value * _test(datum, i, qp);
149  }
150  });
151 }
152 
153 template <typename Derived>
154 KOKKOS_FUNCTION void
155 KernelValue::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
156 {
158  datum,
159  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
160  {
161  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
162  {
163  Real value = datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum);
164 
165  for (unsigned int i = ib; i < ie; ++i)
166  local_ke[i] += value * _test(datum, i, qp);
167  }
168  });
169 }
170 
171 template <typename Derived>
172 KOKKOS_FUNCTION void
173 KernelValue::computeOffDiagJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
174 {
176  datum,
177  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
178  {
179  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
180  {
181  Real value = datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
182  j, datum.jvar(), qp, datum);
183 
184  for (unsigned int i = ib; i < ie; ++i)
185  local_ke[i] += value * _test(datum, i, qp);
186  }
187  });
188 }
189 
190 } // namespace Moose::Kokkos
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
KOKKOS_FUNCTION void computeResidualInternal(const Derived &kernel, AssemblyDatum &datum) const
The parallel computation bodies that hide the base class methods to optimize for factoring out the te...
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
KOKKOS_FUNCTION Real precomputeQpJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
const VariableTestValue _test
Current test function.
Definition: KokkosKernel.h:173
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
Definition: KokkosDatum.h:651
The base class for a user to derive their own Kokkos kernels where the residual is of the form...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
KOKKOS_FUNCTION Real precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:303
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KernelValue(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:559
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:506
The base class for a user to derive their own Kokkos kernels.
Definition: KokkosKernel.h:39
static constexpr bool use_precompute_hooks
KernelValue hooks factor out the test function.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
static InputParameters validParams()