Nektar++
Loading...
Searching...
No Matches
DivergenceBlockOpDeviceStdMatKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: DivergenceBlockOpDeviceStdMatKernels.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// Description: Chain-rule kernel of the device StdMat divergence.
31///////////////////////////////////////////////////////////////////////////////
32
33/**
34 * @file DivergenceBlockOpDeviceStdMatKernels.hpp
35 * @brief Chain-rule kernel of the device StdMat divergence: contract the
36 * standard-region derivatives of every component with the element's
37 * derivative factors and sum them, one work item per point of the block.
38 *
39 * @details
40 * The derivative factors are laid out transposed (DerivFactorKey with
41 * `transpose = true`, see GeometricDataWarehouse.hpp): per element the
42 * `ndf = coordDim * dimension` factors form contiguous planes, of one value
43 * each for a regular element and of nqTot values each for a deformed one.
44 * The deformed branch reaches factor `c * dimension + d` of element @em e at
45 * `ndf * nqTot * e + nqTot * (c * dimension + d) + i`, written as
46 * `(ndf - 1) * nqTot * e + ...` because the within-plane flat index added
47 * last, `idx`, already carries one `nqTot * e`.
48 */
49
50#pragma once
51
53
55{
56
57#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
58/**
59 * @brief Form the divergence of a whole block from the standard-region
60 * derivatives of its components, writing every point once.
61 *
62 * Each work item sums
63 * \f$\sum_c \sum_d \partial\xi_d/\partial x_c\,
64 * \partial u_c/\partial\xi_d\f$ at its point in a register and stores it.
65 * The second grid dimension picks the homogeneous plane, `nqTot * nelmt`
66 * values apart in both @p in and @p out; the same geometry serves every
67 * plane.
68 *
69 * @tparam DEFORMED Derivative factors vary point by point.
70 * @tparam TthreadBlock Back-end thread-block handle type.
71 * @tparam TData Floating-point type of the field data.
72 *
73 * @param nqTot Quadrature points per element.
74 * @param ncoord Cartesian components the factor array holds
75 * (coordDim); sets the per-element factor stride.
76 * @param dimension Components of the vector field, and standard
77 * directions to contract over.
78 * @param nelmt Elements in the block, including padding.
79 * @param compoffset Stride between the components of @p in.
80 * @param diroffset Stride between the standard directions of @p in.
81 * @param dfptr Derivative factors of the block, transposed layout.
82 * @param in Standard-direction derivatives, direction @em d of
83 * component @em c at `c * compoffset + d * diroffset`.
84 * @param out Divergence of the block.
85 * @param threadBlock Thread-block handle supplied by the launcher macro.
86 */
87template <bool DEFORMED, typename TthreadBlock, typename TData>
88NEK_DEVICE_KERNEL static void DivergenceDerivFactorKernel(
89 const unsigned nqTot, const unsigned ncoord, const unsigned dimension,
90 const size_t nelmt, const size_t compoffset, const size_t diroffset,
91 const TData *dfptr, const TData *in, TData *out,
92 const TthreadBlock &threadBlock)
93{
94 const auto ndf = ncoord * dimension;
95 const size_t nsize = nqTot * nelmt;
96
97 size_t idx = getGlobalIdx<0>(threadBlock);
98 const unsigned int p = getBlockIdx<1>(threadBlock);
99 const TData *inptr = in + nsize * p;
100 TData *outptr = out + nsize * p;
101 while (idx < nsize)
102 {
103 const size_t e = idx / nqTot;
104
105 TData div = 0.0;
106 for (unsigned int c = 0; c < dimension; c++)
107 {
108 for (unsigned int d = 0; d < dimension; d++)
109 {
110 const TData df = DEFORMED
111 ? dfptr[(ndf - 1) * nqTot * e +
112 nqTot * (c * dimension + d) + idx]
113 : dfptr[ndf * e + c * dimension + d];
114 div += df * inptr[c * compoffset + d * diroffset + idx];
115 }
116 }
117
118 outptr[idx] = div;
119
120 idx += getGlobalRange<0>(threadBlock);
121 }
122}
123#endif
124
125} // namespace Nektar::MultiRegions::detail
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
void div(const TData alpha, LibUtilities::MemoryRegion< TData > &x, LibUtilities::MemoryRegion< TData > &y)
Definition Math.hpp:988
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
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 > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)