Nektar++
Loading...
Searching...
No Matches
EulerVolumeFluxKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: EulerVolumeFluxKernels.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: Euler volume flux kernels.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
39// header should appear after loop execution.hpp
42
43namespace Nektar::detail
44{
45template <typename ExecSpace, unsigned int NDIM, bool APPEND,
46 typename EqnOfSParams, typename TData>
48 const EqnOfSParams EoS, const unsigned int npts,
49 const unsigned int inStride, const unsigned int outStride,
50 const TData *inbase, TData *outbase, const TData scale,
51 const unsigned int streamID)
52{
53 using vec_t =
55 TData>::type;
56 constexpr unsigned int vec_width =
57 (std::is_same_v<ExecSpace, NektarSpaces::AVX>)
59 : 1;
60
61 const size_t groupsize = npts / vec_width;
62 const size_t inVecStride = inStride / vec_width;
63 const size_t outVecStride = outStride / vec_width;
64 const auto invec = reinterpret_cast<const vec_t *>(inbase);
65 auto outvec = reinterpret_cast<vec_t *>(outbase);
66
68
69 // Parallelize over point groups; each i is independent.
70 Nektar::parallel_for<ExecSpace>(
71 0u, groupsize, NEKTAR_LAMBDA(const size_t i) {
72 // ---- Load conservative variables U at point i ----
73 // Zero on the zero padding, and with it every flux below.
74 const vec_t rho = invec[0 * inVecStride + i];
75 const vec_t invRho = SafeDivide(vec_t(TData(1)), rho);
76
77 vec_t mom[NDIM];
78 vec_t vel[NDIM];
79
80 for (unsigned int d = 0; d < NDIM; ++d)
81 {
82 mom[d] = invec[(1u + d) * inVecStride + i]; // rho*u_d
83 vel[d] = mom[d] * invRho; // u_d
84 }
85
86 const vec_t E = invec[(NDIM + 1u) * inVecStride + i];
87
88 // ---- Pressure via EoS, explicitly vectorized over lanes ----
89 // From the same inverse density, so that e, and with it p, is
90 // zero on the padding too.
91 const vec_t e =
92 GetInternalEnergyFromInvDensity(NDIM, invRho, mom, E);
93 const vec_t p = GetPressure(EoS, rho, e);
94 const vec_t ePlusP = E + p;
95
96 // ---- Fluxes ----
97 // rho equation: F_rho,d = rho*u_d = mom[d]
98 //
99 // Plain if, not if constexpr: nvcc refuses an extended lambda
100 // whose first capture of a variable (outvec, scale) sits inside
101 // an if-constexpr branch. APPEND is a template constant either
102 // way, so the dead branch still folds.
103 if (APPEND)
104 {
105 for (unsigned int d = 0; d < NDIM; ++d)
106 {
107 outvec[(0u * NDIM + d) * outVecStride + i] +=
108 mom[d] * scale;
109 }
110
111 // momentum equations:
112 // F_{mom_a,d} = (rho*u_a)*u_d + p*delta_{a,d}
113 for (unsigned a = 0; a < NDIM; ++a)
114 {
115 for (unsigned d = 0; d < NDIM; ++d)
116 {
117 vec_t val = mom[a] * vel[d];
118 if (a == d)
119 {
120 val += p;
121 }
122 outvec[((1u + a) * NDIM + d) * outVecStride + i] +=
123 val * scale;
124 }
125 }
126
127 // energy equation: F_E,d = (E+p)*u_d
128 for (unsigned d = 0; d < NDIM; ++d)
129 {
130 outvec[((NDIM + 1u) * NDIM + d) * outVecStride + i] +=
131 ePlusP * vel[d] * scale;
132 }
133 }
134 else
135 {
136 for (unsigned int d = 0; d < NDIM; ++d)
137 {
138 outvec[(0u * NDIM + d) * outVecStride + i] = mom[d] * scale;
139 }
140
141 // momentum equations:
142 // F_{mom_a,d} = (rho*u_a)*u_d + p*delta_{a,d}
143 for (unsigned a = 0; a < NDIM; ++a)
144 {
145 for (unsigned d = 0; d < NDIM; ++d)
146 {
147 vec_t val = mom[a] * vel[d];
148 if (a == d)
149 {
150 val += p;
151 }
152 outvec[((1u + a) * NDIM + d) * outVecStride + i] =
153 val * scale;
154 }
155 }
156
157 // energy equation: F_E,d = (E+p)*u_d
158 for (unsigned d = 0; d < NDIM; ++d)
159 {
160 outvec[((NDIM + 1u) * NDIM + d) * outVecStride + i] =
161 ePlusP * vel[d] * scale;
162 }
163 }
164 });
165
167}
168
169} // namespace Nektar::detail
#define NEKTAR_LAMBDA
#define NEK_FORCE_INLINE
Definition NekInline.hpp:46
static NEK_FORCE_INLINE void EulerVolumeFluxKernelLauncher(const EqnOfSParams EoS, const unsigned int npts, const unsigned int inStride, const unsigned int outStride, const TData *inbase, TData *outbase, const TData scale, const unsigned int streamID)
NEK_HOSTDEVICE_INLINE TData GetInternalEnergyFromInvDensity(unsigned ndim, const TData &invRho, const TData *m, const TData &E)
Compute the specific internal energy from the inverse density invRho, for a kernel that has it alrea...
NEK_HOSTDEVICE_INLINE TData GetPressure(const IdealGasEoS< TScalar > &EoS, const TData &rho, const TData &e)
Ideal gas equation of state Helper function p = rho * R * T.
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