https://mooseframework.inl.gov
KokkosVectorKernelValue.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 "KokkosVectorKernel.h"
13 
14 namespace Moose::Kokkos
15 {
16 
25 {
26 public:
28 
30  static constexpr bool use_precompute_hooks = true;
31 
36 
41  template <typename Derived>
43  KOKKOS_FUNCTION Real3 precomputeQpJacobian(const unsigned int /* j */,
44  const unsigned int /* qp */,
45  AssemblyDatum & /* datum */) const
46  {
47  ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
48  "redefined this method in your class without typos.");
49 
50  return Real3(0);
51  }
52  template <typename Derived>
53  KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int /* j */,
54  const unsigned int /* jvar */,
55  const unsigned int /* qp */,
56  AssemblyDatum & /* datum */) const
57  {
58  ::Kokkos::abort(
59  "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
60  "redefined this method in your class without typos.");
61 
62  return Real3(0);
63  }
65 
70  template <typename Derived>
72  static auto defaultJacobian()
73  {
74  return &VectorKernelValue::precomputeQpJacobian<Derived>;
75  }
76  template <typename Derived>
77  static auto defaultOffDiagJacobian()
78  {
79  return &VectorKernelValue::precomputeQpOffDiagJacobian<Derived>;
80  }
82 
86  template <typename Derived>
88  KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
89  template <typename Derived>
90  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
91  template <typename Derived>
92  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
93  AssemblyDatum & datum) const;
95 };
96 
97 template <typename Derived>
98 KOKKOS_FUNCTION void
99 VectorKernelValue::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
100 {
102  datum,
103  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
104  {
105  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
106  {
107  Real3 value = datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum);
108 
109  for (unsigned int i = ib; i < ie; ++i)
110  local_re[i] += value * _test(datum, i, qp);
111  }
112  });
113 }
114 
115 template <typename Derived>
116 KOKKOS_FUNCTION void
117 VectorKernelValue::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
118 {
120  datum,
121  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
122  {
123  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
124  {
125  Real3 value = datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum);
126 
127  for (unsigned int i = ib; i < ie; ++i)
128  local_ke[i] += value * _test(datum, i, qp);
129  }
130  });
131 }
132 
133 template <typename Derived>
134 KOKKOS_FUNCTION void
136  AssemblyDatum & datum) const
137 {
139  datum,
140  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
141  {
142  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
143  {
144  Real3 value = datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
145  j, datum.jvar(), qp, datum);
146 
147  for (unsigned int i = ib; i < ie; ++i)
148  local_ke[i] += value * _test(datum, i, qp);
149  }
150  });
151 }
152 
153 } // namespace Moose::Kokkos
Vector3< Real > Real3
Definition: KokkosTypes.h:32
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
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 vector kernels on vector variables.
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 void computeResidualInternal(const Derived &kernel, AssemblyDatum &datum) const
Optimized computation bodies that factor out the vector test function.
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...
VectorKernelValue(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
The base class for Kokkos vector kernels where the residual is of the form.
const VectorVariableTestValue _test
Current vector test function.
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
static constexpr bool use_precompute_hooks
VectorKernelValue hooks factor out the test function.
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) 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
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.