Nektar++
Loading...
Searching...
No Matches
CFLVelocityCFEKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CFLVelocityCFEKernels.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: Kernel converting conserved variables to velocity and sound
32// speed.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#pragma once
37
40
41// header should appear after loop execution.hpp
43
44namespace Nektar::detail
45{
46
47/**
48 * @brief Fill @p outbase with the @p ndim velocity components followed by
49 * the speed of sound.
50 *
51 * The layout mirrors what MaxStdVelocityOp expects when its sound speed
52 * factor is one: velocity in the leading components, wave speed in the one
53 * after them.
54 */
55template <typename ExecSpace, typename EqnOfSParams, typename TData>
57 const EqnOfSParams EoS, const unsigned int npts, const unsigned int ndim,
58 const unsigned int inStride, const unsigned int outStride,
59 const TData *inbase, TData *outbase, const unsigned int streamID)
60{
61 using vec_t =
63 TData>::type;
64 constexpr unsigned int vec_width =
65 (std::is_same_v<ExecSpace, NektarSpaces::AVX>)
67 : 1;
68
69 const size_t groupsize = npts / vec_width;
70 const size_t inVecStride = inStride / vec_width;
71 const size_t outVecStride = outStride / vec_width;
72 const auto invec = reinterpret_cast<const vec_t *>(inbase);
73 auto outvec = reinterpret_cast<vec_t *>(outbase);
74
76
77 // Parallelize over point groups; each i is independent.
78 Nektar::parallel_for<ExecSpace>(
79 0u, groupsize, NEKTAR_LAMBDA(const size_t i) {
80 const vec_t rho = invec[0 * inVecStride + i];
81 const vec_t invRho = SafeDivide(vec_t(TData(1)), rho);
82
83 vec_t mom[3] = {vec_t(TData(0)), vec_t(TData(0)), vec_t(TData(0))};
84
85 for (unsigned int d = 0; d < ndim; ++d)
86 {
87 mom[d] = invec[(1u + d) * inVecStride + i]; // rho*u_d
88 outvec[d * outVecStride + i] = mom[d] * invRho;
89 }
90
91 const vec_t E = invec[(ndim + 1u) * inVecStride + i];
92 const vec_t e = GetInternalEnergy(ndim, rho, mom, E);
93
94 outvec[ndim * outVecStride + i] = GetSoundSpeed(EoS, rho, e);
95 });
96
97 // Restore the default for whatever runs next: a kernel that inherits the
98 // stream would otherwise land on this block's stream.
100}
101
102} // namespace Nektar::detail
#define NEKTAR_LAMBDA
#define NEK_FORCE_INLINE
Definition NekInline.hpp:46
NEK_HOSTDEVICE_INLINE TData GetSoundSpeed(const IdealGasEoS< TScalar > &EoS, const TData &rho, const TData &e)
static NEK_FORCE_INLINE void CFLVelocityCFEKernel(const EqnOfSParams EoS, const unsigned int npts, const unsigned int ndim, const unsigned int inStride, const unsigned int outStride, const TData *inbase, TData *outbase, const unsigned int streamID)
Fill outbase with the ndim velocity components followed by the speed of sound.
NEK_HOSTDEVICE_INLINE TData GetInternalEnergy(unsigned ndim, const TData &rho, const TData *m, const TData &E)
Compute the specific internal energy .
static void LoopExecutionSetStreamID(const unsigned int streamID)
tinysimd::simd< NekDouble > vec_t
NEK_HOSTDEVICE_INLINE TData SafeDivide(const TData &num, const TData &den)
num / den, and zero where den is zero.
typename abi< ScalarType, width >::type simd
Definition tinysimd.hpp:138