https://mooseframework.inl.gov
KokkosKernelGrad.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 
42 class KernelGrad : public Kernel
43 {
44 public:
46 
48  static constexpr bool use_precompute_hooks = true;
49 
54 
59 
69  template <typename Derived>
70  KOKKOS_FUNCTION Real3 precomputeQpJacobian(const unsigned int /* j */,
71  const unsigned int /* qp */,
72  AssemblyDatum & /* datum */) const
73  {
74  ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
75  "redefined this method in your class without typos.");
76 
77  return Real3(0);
78  }
89  template <typename Derived>
90  KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int /* j */,
91  const unsigned int /* jvar */,
92  const unsigned int /* qp */,
93  AssemblyDatum & /* datum */) const
94  {
95  ::Kokkos::abort(
96  "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
97  "redefined this method in your class without typos.");
98 
99  return Real3(0);
100  }
102 
108  template <typename Derived>
110  static auto defaultJacobian()
111  {
112  return &KernelGrad::precomputeQpJacobian<Derived>;
113  }
114  template <typename Derived>
116  {
117  return &KernelGrad::precomputeQpOffDiagJacobian<Derived>;
118  }
120 
125  template <typename Derived>
127  KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
128  template <typename Derived>
129  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
130  template <typename Derived>
131  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
132  AssemblyDatum & datum) const;
134 };
135 
136 template <typename Derived>
137 KOKKOS_FUNCTION void
138 KernelGrad::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
139 {
141  datum,
142  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
143  {
144  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
145  {
146  Real3 value = datum.J(qp).transpose() *
147  (datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum));
148 
149  for (unsigned int i = ib; i < ie; ++i)
150  local_re[i] += value * _grad_test.reference(datum, i, qp);
151  }
152  });
153 }
154 
155 template <typename Derived>
156 KOKKOS_FUNCTION void
157 KernelGrad::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
158 {
160  datum,
161  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
162  {
163  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
164  {
165  Real3 value =
166  datum.J(qp).transpose() *
167  (datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum));
168 
169  for (unsigned int i = ib; i < ie; ++i)
170  local_ke[i] += value * _grad_test.reference(datum, i, qp);
171  }
172  });
173 }
174 
175 template <typename Derived>
176 KOKKOS_FUNCTION void
177 KernelGrad::computeOffDiagJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
178 {
180  datum,
181  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
182  {
183  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
184  {
185  Real3 value = datum.J(qp).transpose() *
186  (datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
187  j, datum.jvar(), qp, datum));
188 
189  for (unsigned int i = ib; i < ie; ++i)
190  local_ke[i] += value * _grad_test.reference(datum, i, qp);
191  }
192  });
193 }
194 
195 } // namespace Moose::Kokkos
Vector3< Real > Real3
Definition: KokkosTypes.h:32
static constexpr bool use_precompute_hooks
KernelGrad hooks factor out the test-function gradient.
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
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...
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
Definition: KokkosDatum.h:651
KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
Get the inverse of Jacobian matrix | dxi/dx deta/dx dzeta/dx | | dxi/dy deta/dy dzeta/dy | | dxi/dz d...
Definition: KokkosDatum.h:495
static auto defaultOffDiagJacobian()
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KOKKOS_FUNCTION const Real3 & reference(AssemblyDatum &datum, unsigned int i, unsigned int qp) const
Get the gradient of the current shape function in reference space.
KernelGrad(const InputParameters &parameters)
Constructor.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:303
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 gr...
KOKKOS_INLINE_FUNCTION Real33 transpose() const
Definition: KokkosTypes.h:448
static InputParameters validParams()
KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableTestGradient _grad_test
Gradient of the current test function.
Definition: KokkosKernel.h:177
KOKKOS_FUNCTION Real3 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...
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
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
The base class for a user to derive their own Kokkos kernels.
Definition: KokkosKernel.h:39
The base class for a user to derive their own Kokkos kernels where the residual is of the form...
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.