Nektar++
Loading...
Searching...
No Matches
AdvectionBlockOpDeviceStdMatKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: AdvectionBlockOpDeviceStdMatKernels.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Pointwise derivative-factor and velocity kernel of the Device
32// StdMat advection block operator.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36/**
37 * @file AdvectionBlockOpDeviceStdMatKernels.hpp
38 * @brief Pointwise derivative-factor/velocity kernel of the Device StdMat
39 * advection block operator (see AdvectionBlockOpDeviceStdMat.hpp).
40 *
41 * @details
42 * The kernel runs over all quadrature points of the block, launched by the
43 * block operator on its device stream; each variable and homogeneous plane
44 * of the block rides the second grid dimension of that one launch.
45 */
46
47#pragma once
48
50
52{
53
54#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
55/**
56 * @brief From reference-space derivatives, form the Cartesian gradient and
57 * contract it with the advection velocity:
58 * out = scale * sum_k V_k sum_d df(k,d) du/dxi_d, evaluated at every
59 * quadrature point of every element of one variable and plane.
60 *
61 * The derivative-factor entry k * dimension + d maps the
62 * reference-direction-d derivative into the Cartesian-k gradient
63 * component. The factors are read in the layout produced by
64 * DerivFactorKey with the transpose flag set: for regular geometry one set
65 * of ncoord * dimension values per element, for deformed geometry one such
66 * set per element in which each factor component is contiguous over the
67 * element's nqTot points.
68 *
69 * Work items run over the quadrature points of every element on the first
70 * grid dimension; the second grid dimension picks the variable and plane,
71 * @p nelmt * @p nqTot values apart in @p in and @p out. The velocity is
72 * taken from the plane, that grid index modulo @p nhomo, and the same
73 * geometric factors serve every plane.
74 *
75 * @tparam APPEND Accumulate onto @p out instead of overwriting it.
76 * @tparam DEFORMED Read per-point rather than per-element derivative
77 * factors.
78 * @tparam TthreadBlock Back-end thread-block handle type.
79 *
80 * @param nqTot Quadrature points per element.
81 * @param ncoord Cartesian gradient/velocity components.
82 * @param dimension Reference directions covered by @p in.
83 * @param nelmt Elements in the block, including padding.
84 * @param inoffset Stride between the reference-direction planes of
85 * @p in.
86 * @param dfptr Derivative factors of the block, laid out as
87 * described above.
88 * @param advVel Velocity data; component k starts at
89 * k * advelsize.
90 * @param advelsize Stride between velocity components.
91 * @param nhomo Homogeneous planes per variable.
92 * @param in Reference-space derivatives, one plane of
93 * @p inoffset values per direction.
94 * @param out Output values, one per work item.
95 * @param scale Scalar factor applied to the result.
96 * @param threadBlock Thread-block handle supplied by the launcher macro.
97 */
98template <bool APPEND, bool DEFORMED, typename TthreadBlock, typename TData>
100 const unsigned int nqTot, const unsigned int ncoord,
101 const unsigned int dimension, const size_t nelmt, const size_t inoffset,
102 const TData *dfptr, const TData *advVel, const size_t advelsize,
103 const unsigned int nhomo, const TData *in, TData *out, const TData scale,
104 const TthreadBlock &threadBlock)
105{
106 const auto ndf = ncoord * dimension;
107 const size_t nsize = nqTot * nelmt;
108
109 size_t idx = getGlobalIdx<0>(threadBlock);
110 const unsigned int c = getBlockIdx<1>(threadBlock);
111 const TData *inptr = in + nsize * c;
112 TData *outptr = out + nsize * c;
113 const TData *advVelPtr = advVel + nsize * (c % nhomo);
114 while (idx < nsize)
115 {
116 const size_t e = idx / nqTot;
117
118 TData tmp[3], tmp0 = 0;
119 if constexpr (DEFORMED)
120 {
121 const size_t i = idx - e * nqTot;
122 for (unsigned int k = 0; k < ncoord; k++)
123 {
124 tmp[k] = dfptr[ndf * nqTot * e + (k * dimension) * nqTot + i] *
125 inptr[idx];
126 for (unsigned int d = 1; d < dimension; d++)
127 {
128 tmp[k] += dfptr[ndf * nqTot * e +
129 (k * dimension + d) * nqTot + i] *
130 inptr[idx + d * inoffset];
131 }
132 tmp0 += advVelPtr[k * advelsize + idx] * tmp[k];
133 }
134 }
135 else
136 {
137 for (unsigned int k = 0; k < ncoord; k++)
138 {
139 tmp[k] = dfptr[(ndf * e + k * dimension)] * inptr[idx];
140 for (unsigned int d = 1; d < dimension; d++)
141 {
142 tmp[k] += dfptr[(ndf * e + k * dimension + d)] *
143 inptr[idx + d * inoffset];
144 }
145 tmp0 += advVelPtr[k * advelsize + idx] * tmp[k];
146 }
147 }
148
149 if constexpr (APPEND)
150 {
151 outptr[idx] += scale * tmp0;
152 }
153 else
154 {
155 outptr[idx] = scale * tmp0;
156 }
157
158 idx += getGlobalRange<0>(threadBlock);
159 }
160}
161#endif
162
163} // namespace Nektar::MultiRegions::detail
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char const TthreadBlock & threadBlock
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT in
static NEK_FORCE_INLINE void MultiplyByDerivFactorAndAdvecVelKernel(const unsigned int nqTot, const unsigned int ncoord, const unsigned int dimension, const size_t nelmt, const size_t inoffset, const TData *dfptr, const TData *advVel, const size_t advelsize, const TData *inptr, TData *outptr, const TScalar scale)
From reference-space derivatives, form the Cartesian gradient and contract it with the advection velo...
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
std::vector< double > d(NPUPPER *NPUPPER)