Nektar++
Loading...
Searching...
No Matches
ReynoldsStressKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ReynoldsStressKernels.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-portable velocity-product kernel.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
39namespace Nektar::detail
40{
41
42/**
43 * @brief Add scale * u_a * u_b to product component (a,b), a <= b, at every
44 * entry of one block.
45 *
46 * The velocity and the products share the block's storage layout, so one
47 * storage index addresses the same point in both, whatever the interleave
48 * width: the kernel walks the storage as it is laid out, neighbouring threads
49 * reading and writing neighbouring entries, with no index arithmetic. The
50 * padding of the velocity is zero, so the padded entries of the products
51 * stay zero. The products are ordered (0,0), (0,1), ..., (0,d-1), (1,1), ...,
52 * (d-1,d-1). Each component holds @p nPlanes homogeneous planes of
53 * @p planeSize entries, one after the other, which the kernel walks as one.
54 */
55template <typename ExecSpace, unsigned int NDIM, typename TData>
56void ReynoldsStressKernelLauncher(const size_t planeSize,
57 const unsigned int nPlanes,
58 const unsigned int velocityComponent0,
59 const unsigned int velocityComponent1,
60 const unsigned int velocityComponent2,
61 const TData scale, const TData *velocity,
62 TData *products, const unsigned int streamID)
63{
64 static_assert(NDIM == 2 || NDIM == 3,
65 "ReynoldsStress supports only dimensions 2 and 3.");
66
67 // Offsets of the velocity components. The third is unused in 2D.
68 const size_t compSize = nPlanes * planeSize;
69 const size_t uOffset = velocityComponent0 * compSize;
70 const size_t vOffset = velocityComponent1 * compSize;
71 const size_t wOffset = velocityComponent2 * compSize;
72
74 Nektar::parallel_for<ExecSpace>(
75 0u, compSize, NEKTAR_LAMBDA(const size_t idx) {
76 const TData u[3] = {velocity[uOffset + idx],
77 velocity[vOffset + idx],
78 NDIM == 3 ? velocity[wOffset + idx] : TData{0}};
79
80 unsigned int product = 0;
81 for (unsigned int a = 0; a < NDIM; ++a)
82 {
83 for (unsigned int b = a; b < NDIM; ++b, ++product)
84 {
85 products[product * compSize + idx] += scale * u[a] * u[b];
86 }
87 }
88 });
90}
91
92} // namespace Nektar::detail
#define NEKTAR_LAMBDA
void ReynoldsStressKernelLauncher(const size_t planeSize, const unsigned int nPlanes, const unsigned int velocityComponent0, const unsigned int velocityComponent1, const unsigned int velocityComponent2, const TData scale, const TData *velocity, TData *products, const unsigned int streamID)
Add scale * u_a * u_b to product component (a,b), a <= b, at every entry of one block.
static void LoopExecutionSetStreamID(const unsigned int streamID)