https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14namespace Moose::Kokkos
15{
16
41class KernelValue : public Kernel
42{
43public:
45
47 static constexpr bool use_precompute_hooks = true;
48
53
59
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
108 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
125 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
135template <typename Derived>
136KOKKOS_FUNCTION void
137KernelValue::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
153template <typename Derived>
154KOKKOS_FUNCTION void
155KernelValue::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
171template <typename Derived>
172KOKKOS_FUNCTION void
173KernelValue::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
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels.
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
The base class for a user to derive their own Kokkos kernels where the residual is of the form.
KernelValue(const InputParameters &parameters)
Constructor.
static InputParameters validParams()
KOKKOS_FUNCTION Real precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
static constexpr bool use_precompute_hooks
KernelValue hooks factor out the test function.
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
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...
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...
The base class for a user to derive their own Kokkos kernels.
const VariableTestValue _test
Current test function.
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.