https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosVectorKernelGrad.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
26{
27public:
29
31 static constexpr bool use_precompute_hooks = true;
32
37
43 template <typename Derived>
44 KOKKOS_FUNCTION Real33 precomputeQpJacobian(const unsigned int /* j */,
45 const unsigned int /* qp */,
46 AssemblyDatum & /* datum */) const
47 {
48 ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly "
49 "redefined this method in your class without typos.");
50
51 return Real33(0);
52 }
53 template <typename Derived>
54 KOKKOS_FUNCTION Real33 precomputeQpOffDiagJacobian(const unsigned int /* j */,
55 const unsigned int /* jvar */,
56 const unsigned int /* qp */,
57 AssemblyDatum & /* datum */) const
58 {
59 ::Kokkos::abort(
60 "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly "
61 "redefined this method in your class without typos.");
62
63 return Real33(0);
64 }
66
72 template <typename Derived>
73 static auto defaultJacobian()
74 {
75 return &VectorKernelGrad::precomputeQpJacobian<Derived>;
76 }
77 template <typename Derived>
79 {
80 return &VectorKernelGrad::precomputeQpOffDiagJacobian<Derived>;
81 }
83
88 template <typename Derived>
89 KOKKOS_FUNCTION void computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const;
90 template <typename Derived>
91 KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
92 template <typename Derived>
93 KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & kernel,
94 AssemblyDatum & datum) const;
96};
97
98template <typename Derived>
99KOKKOS_FUNCTION void
100VectorKernelGrad::computeResidualInternal(const Derived & kernel, AssemblyDatum & datum) const
101{
103 datum,
104 [&](Real * local_re, const unsigned int ib, const unsigned int ie)
105 {
106 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
107 {
108 Real33 value =
109 (datum.JxW(qp) * kernel.template precomputeQpResidual<Derived>(qp, datum)) *
110 datum.J(qp);
111
112 for (unsigned int i = ib; i < ie; ++i)
113 local_re[i] += value.contract(_grad_test.reference(datum, i, qp));
114 }
115 });
116}
117
118template <typename Derived>
119KOKKOS_FUNCTION void
120VectorKernelGrad::computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const
121{
123 datum,
124 [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
125 {
126 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
127 {
128 Real33 value =
129 (datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum)) *
130 datum.J(qp);
131
132 for (unsigned int i = ib; i < ie; ++i)
133 local_ke[i] += value.contract(_grad_test.reference(datum, i, qp));
134 }
135 });
136}
137
138template <typename Derived>
139KOKKOS_FUNCTION void
141 AssemblyDatum & datum) const
142{
144 datum,
145 [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
146 {
147 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
148 {
149 Real33 value = (datum.JxW(qp) * kernel.template precomputeQpOffDiagJacobian<Derived>(
150 j, datum.jvar(), qp, datum)) *
151 datum.J(qp);
152
153 for (unsigned int i = ib; i < ie; ++i)
154 local_ke[i] += value.contract(_grad_test.reference(datum, i, qp));
155 }
156 });
157}
158
159} // 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 const Real33 & J(const unsigned int qp)
Get the inverse of Jacobian matrix | dxi/dx deta/dx dzeta/dx | | dxi/dy deta/dy dzeta/dy | | dxi/dz d...
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 void computeResidualInternal(const Derived &kernel, AssemblyDatum &datum) const
Optimized computation bodies that factor out the vector test-function gradient.
static constexpr bool use_precompute_hooks
VectorKernelGrad hooks factor out the test-function gradient.
KOKKOS_FUNCTION Real33 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...
VectorKernelGrad(const InputParameters &parameters)
Constructor.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
static InputParameters validParams()
KOKKOS_FUNCTION Real33 precomputeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
The base class for a user to derive their own Kokkos vector kernels on vector variables.
const VectorVariableTestGradient _grad_test
Gradient of the current vector test function.
KOKKOS_FUNCTION const Real33 & reference(AssemblyDatum &datum, unsigned int i, unsigned int qp) const
Get the gradient of the current vector shape function in reference space.