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 
40 class KernelValue : public Kernel
41 {
42 public:
44 
49 
54 
64  template <typename Derived>
65  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* j */,
66  const unsigned int /* qp */,
67  AssemblyDatum & /* datum */) const
68  {
69  ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
70  "redefined this method in your class without typos.");
71 
72  return 0;
73  }
84  template <typename Derived>
85  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* j */,
86  const unsigned int /* jvar */,
87  const unsigned int /* qp */,
88  AssemblyDatum & /* datum */) const
89  {
90  ::Kokkos::abort(
91  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
92  "redefined this method in your class without typos.");
93 
94  return 0;
95  }
97 
103  template <typename Derived>
105  static auto defaultJacobian()
106  {
107  return &KernelValue::computeQpJacobian<Derived>;
108  }
109  template <typename Derived>
111  {
112  return &KernelValue::computeQpOffDiagJacobian<Derived>;
113  }
115 
120  template <typename Derived>
122  KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
123  template <typename Derived>
124  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
125  template <typename Derived>
126  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
127  AssemblyDatum & datum) const;
129 };
130 
131 template <typename Derived>
132 KOKKOS_FUNCTION void
133 KernelValue::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
134 {
136  datum,
137  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
138  {
139  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
140  {
141  Real value = datum.JxW(qp) * kernel.template computeQpResidual<Derived>(qp, datum);
142 
143  for (unsigned int i = ib; i < ie; ++i)
144  local_re[i] += value * _test(datum, i, qp);
145  }
146  });
147 }
148 
149 template <typename Derived>
150 KOKKOS_FUNCTION void
151 KernelValue::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
152 {
154  datum,
155  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
156  {
157  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
158  {
159  Real value = datum.JxW(qp) * kernel.template computeQpJacobian<Derived>(j, qp, datum);
160 
161  for (unsigned int i = ib; i < ie; ++i)
162  local_ke[i] += value * _test(datum, i, qp);
163  }
164  });
165 }
166 
167 template <typename Derived>
168 KOKKOS_FUNCTION void
169 KernelValue::computeOffDiagJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
170 {
172  datum,
173  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
174  {
175  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
176  {
177  Real value = datum.JxW(qp) * kernel.template computeQpOffDiagJacobian<Derived>(
178  j, datum.jvar(), qp, datum);
179 
180  for (unsigned int i = ib; i < ie; ++i)
181  local_ke[i] += value * _test(datum, i, qp);
182  }
183  });
184 }
185 
186 } // 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...
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:456
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 unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:118
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real 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 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:364
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:311
The base class for a user to derive their own Kokkos kernels.
Definition: KokkosKernel.h:39
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
static InputParameters validParams()