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 
41 class KernelGrad : public Kernel
42 {
43 public:
45 
50 
55 
65  template <typename Derived>
66  KOKKOS_FUNCTION Real3 computeQpJacobian(const unsigned int /* j */,
67  const unsigned int /* qp */,
68  AssemblyDatum & /* datum */) const
69  {
70  ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
71  "redefined this method in your class without typos.");
72 
73  return Real3(0);
74  }
85  template <typename Derived>
86  KOKKOS_FUNCTION Real3 computeQpOffDiagJacobian(const unsigned int /* j */,
87  const unsigned int /* jvar */,
88  const unsigned int /* qp */,
89  AssemblyDatum & /* datum */) const
90  {
91  ::Kokkos::abort(
92  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
93  "redefined this method in your class without typos.");
94 
95  return Real3(0);
96  }
98 
104  template <typename Derived>
106  static auto defaultJacobian()
107  {
108  return &KernelGrad::computeQpJacobian<Derived>;
109  }
110  template <typename Derived>
112  {
113  return &KernelGrad::computeQpOffDiagJacobian<Derived>;
114  }
116 
121  template <typename Derived>
123  KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
124  template <typename Derived>
125  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
126  template <typename Derived>
127  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
128  AssemblyDatum & datum) const;
130 };
131 
132 template <typename Derived>
133 KOKKOS_FUNCTION void
134 KernelGrad::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
135 {
137  datum,
138  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
139  {
140  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
141  {
142  Real3 value = datum.JxW(qp) * kernel.template computeQpResidual<Derived>(qp, datum);
143 
144  for (unsigned int i = ib; i < ie; ++i)
145  local_re[i] += value * _grad_test(datum, i, qp);
146  }
147  });
148 }
149 
150 template <typename Derived>
151 KOKKOS_FUNCTION void
152 KernelGrad::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
153 {
155  datum,
156  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
157  {
158  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
159  {
160  Real3 value = datum.JxW(qp) * kernel.template computeQpJacobian<Derived>(j, qp, datum);
161 
162  for (unsigned int i = ib; i < ie; ++i)
163  local_ke[i] += value * _grad_test(datum, i, qp);
164  }
165  });
166 }
167 
168 template <typename Derived>
169 KOKKOS_FUNCTION void
170 KernelGrad::computeOffDiagJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
171 {
173  datum,
174  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
175  {
176  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
177  {
178  Real3 value = datum.JxW(qp) * kernel.template computeQpOffDiagJacobian<Derived>(
179  j, datum.jvar(), qp, datum);
180 
181  for (unsigned int i = ib; i < ie; ++i)
182  local_ke[i] += value * _grad_test(datum, i, qp);
183  }
184  });
185 }
186 
187 } // namespace Moose::Kokkos
Vector3< Real > Real3
Definition: KokkosTypes.h:31
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:456
static auto defaultOffDiagJacobian()
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
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:118
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...
static InputParameters validParams()
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
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:311
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
KOKKOS_FUNCTION Real3 computeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
The base class for a user to derive their own Kokkos kernels where the residual is of the form...
KOKKOS_FUNCTION Real3 computeQpJacobian(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...
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.