Nektar++
Loading...
Searching...
No Matches
PhysLiftProjectBlockOpDeviceStdMatKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysLiftProjectBlockOpDeviceStdMatKernels.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: Device StdMat kernels of the lift-and-project element
32// operator.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36/**
37 * @file PhysLiftProjectBlockOpDeviceStdMatKernels.hpp
38 * @brief Device StdMat kernels of the lift-and-project operator: the
39 * Pointwise form at width one.
40 *
41 * @details
42 * The threads stride over the points of all the elements, one point
43 * each, so that consecutive threads touch consecutive entries. The kernel
44 * has the name and arguments of its SumFac and SumFacTOP counterparts
45 * (PhysLiftProjectBlockOpDeviceSumFacKernels.hpp,
46 * PhysLiftProjectBlockOpDeviceSumFacTOPKernels.hpp), restricted to
47 * Implementation StdMat, so that the caller launches
48 * `PhysLiftProjectPointwiseKernel<Implementation, ...>`.
49 */
50
51#pragma once
52
56
57#include <type_traits>
58
60{
61
62#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
63
64/**
65 * @brief The Pointwise form at width one: `out (+)= scale / (w_q J) * in` at
66 * every point, zero on the padding elements. Grid dimension 1 is the
67 * component.
68 *
69 * @param weights The quadrature weights at every point (WeightsKey at
70 * width one).
71 * @param jac The Jacobians (JacobianKey at width one), one per
72 * element, or one per point when @p DEFORMED.
73 */
74template <typename Implementation, bool APPEND, bool DEFORMED,
75 typename TthreadBlock, typename TData,
76 std::enable_if_t<std::is_same_v<Implementation, StdMat>, bool>
77 Enable = true>
79 const size_t nelmt, const unsigned int nqTot, const TData scale,
80 const TData *NEK_RESTRICT weights, const TData *NEK_RESTRICT jac,
81 const TData *NEK_RESTRICT in, TData *NEK_RESTRICT out,
82 const TthreadBlock &threadBlock)
83{
84 const size_t nsize = nqTot * nelmt;
85 const unsigned int c = getBlockIdx<1>(threadBlock);
86 const TData *NEK_RESTRICT inptr = in + nsize * c;
87 TData *NEK_RESTRICT outptr = out + nsize * c;
88 for (size_t idx = getGlobalIdx<0>(threadBlock); idx < nsize;
89 idx += getGlobalRange<0>(threadBlock))
90 {
91 const unsigned int q = idx % nqTot;
92 TData jacobian;
93 if constexpr (DEFORMED)
94 {
95 jacobian = jac[idx];
96 }
97 else
98 {
99 jacobian = jac[idx / nqTot];
100 }
101 const TData factor = SafeDivide(scale, weights[q] * jacobian);
102 if constexpr (APPEND)
103 {
104 outptr[idx] += factor * inptr[idx];
105 }
106 else
107 {
108 outptr[idx] = factor * inptr[idx];
109 }
110 }
111}
112
113#endif
114
115} // namespace Nektar::MultiRegions::detail
#define NEK_RESTRICT
Definition Backends.hpp:254
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
Block-level base class, implementation-strategy tags and device launch helpers shared by every elemen...
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
static NEK_FORCE_INLINE void PhysLiftProjectPointwiseKernel(const unsigned int nqTot, const simd_type *pointScale, const simd_type *vol, simd_type *out)
The Pointwise form of one element group: out (+)= pointScale * vol.
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 const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT jac
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
NEK_HOSTDEVICE_INLINE TData SafeDivide(const TData &num, const TData &den)
num / den, and zero where den is zero.