https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14namespace Moose::Kokkos
15{
16
25{
26public:
28
30 static constexpr bool use_precompute_hooks = true;
31
36
42 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
71 template <typename Derived>
72 static auto defaultJacobian()
73 {
74 return &VectorKernelValue::precomputeQpJacobian<Derived>;
75 }
76 template <typename Derived>
78 {
79 return &VectorKernelValue::precomputeQpOffDiagJacobian<Derived>;
80 }
82
87 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
97template <typename Derived>
98KOKKOS_FUNCTION void
99VectorKernelValue::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
115template <typename Derived>
116KOKKOS_FUNCTION void
117VectorKernelValue::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
133template <typename Derived>
134KOKKOS_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
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.
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.
The base class for Kokkos vector kernels where the residual is of the form.
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...
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
KOKKOS_FUNCTION void computeResidualInternal(const Derived &kernel, AssemblyDatum &datum) const
Optimized computation bodies that factor out the vector test function.
VectorKernelValue(const InputParameters &parameters)
Constructor.
static constexpr bool use_precompute_hooks
VectorKernelValue hooks factor out the test function.
static InputParameters validParams()
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
KOKKOS_FUNCTION Real3 precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
The base class for a user to derive their own Kokkos vector kernels on vector variables.
const VectorVariableTestValue _test
Current vector test function.
Vector3< Real > Real3
Definition KokkosTypes.h:32