Nektar++
Loading...
Searching...
No Matches
BndCondRiemannInvariantCFEKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: BndCondRiemannInvariantCFEKernels.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: Block kernels of the Riemann invariant farfield boundary
32// condition.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#pragma once
37
38#include <cmath>
39
41
42namespace Nektar::detail
43{
44
45/**
46 * @brief Project the freestream velocity onto a block's outward normals.
47 */
48template <typename ExecSpace, typename TData>
50 const size_t stride, const unsigned coordDim, const TData *velInfHost,
51 const TData *norms, TData *VnInf, const unsigned int streamID = 0)
52{
54
55 // A host array of coordDim entries, copied into a fixed-size local so
56 // that the kernel captures the values rather than a host address.
57 TData velInf[3] = {TData(0.0), TData(0.0), TData(0.0)};
58 for (unsigned d = 0; d < coordDim; ++d)
59 {
60 velInf[d] = velInfHost[d];
61 }
62
63 Nektar::parallel_for<ExecSpace>(
64 0u, stride, NEKTAR_LAMBDA(const size_t i) {
65 TData vn = TData(0.0);
66 for (unsigned d = 0; d < coordDim; ++d)
67 {
68 vn += velInf[d] * norms[d * stride + i];
69 }
70 VnInf[i] = vn;
71 });
72
74}
75
76/**
77 * @brief Reconstruct the boundary state on a block from the Riemann invariants,
78 * each taken from the side that carries it.
79 */
80template <typename ExecSpace, typename TData>
82 const size_t stride, const unsigned coordDim, const size_t eng,
83 const TData gamma, const TData rhoInf, const TData pInf,
84 const TData *velInfHost, const TData *VnInf, const TData *norms,
85 TData *bndPtr, const unsigned int streamID = 0)
86{
88
89 const TData gamM1 = gamma - TData(1.0);
90 const TData twoOverGamM1 = TData(2.0) / gamM1;
91
92 // A host array of coordDim entries, copied into a fixed-size local so
93 // that the kernel captures the values rather than a host address.
94 TData velInf[3] = {TData(0.0), TData(0.0), TData(0.0)};
95 for (unsigned d = 0; d < coordDim; ++d)
96 {
97 velInf[d] = velInfHost[d];
98 }
99
100 Nektar::parallel_for<ExecSpace>(
101 0u, stride, NEKTAR_LAMBDA(const size_t i) {
102#if defined(__SYCL_DEVICE_ONLY__)
103 using sycl::pow;
104 using sycl::sqrt;
105#else
106 using std::pow;
107 using std::sqrt;
108#endif
109
110 // The storage holds the interior state.
111 const TData rhoInt = bndPtr[i];
112
113 TData momSq = TData(0.0);
114 TData vn = TData(0.0);
115 for (unsigned d = 0; d < coordDim; ++d)
116 {
117 const TData mom = bndPtr[(d + 1) * stride + i];
118 momSq += mom * mom;
119 vn += mom * norms[d * stride + i];
120 }
121 vn /= rhoInt;
122
123 const TData pInt = gamM1 * (bndPtr[eng * stride + i] -
124 TData(0.5) * momSq / rhoInt);
125 const TData cInt = sqrt(gamma * pInt / rhoInt);
126 const TData cInf = sqrt(gamma * pInf / rhoInf);
127
128 const bool inflow = (vn <= TData(0.0));
129 const bool sonic = (std::abs(vn) / cInt >= TData(1.0));
130
131 // Each invariant comes from the side it is carried from.
132 // Supersonic takes both from the upstream side, which
133 // makes the reconstruction below return that side's state
134 // unchanged - no special case needed.
135 const bool plusFromInterior = !(inflow && sonic);
136 const bool minusFromInterior = (!inflow && sonic);
137
138 const TData rPlus = plusFromInterior
139 ? vn + cInt * twoOverGamM1
140 : VnInf[i] + cInf * twoOverGamM1;
141 const TData rMinus = minusFromInterior
142 ? vn - cInt * twoOverGamM1
143 : VnInf[i] - cInf * twoOverGamM1;
144
145 const TData vnBC = TData(0.5) * (rPlus + rMinus);
146 const TData cBC = TData(0.25) * gamM1 * (rPlus - rMinus);
147
148 // The entropy comes from upstream, and with it the
149 // velocity vector whose normal component is corrected.
150 const TData sBC =
151 inflow ? pInf / pow(rhoInf, gamma) : pInt / pow(rhoInt, gamma);
152 const TData vnUp = inflow ? VnInf[i] : vn;
153
154 const TData rhoBC =
155 pow(cBC * cBC / (gamma * sBC), TData(1.0) / gamM1);
156 const TData pBC = rhoBC * cBC * cBC / gamma;
157
158 const TData vDiff = vnBC - vnUp;
159
160 TData EkBC = TData(0.0);
161 for (unsigned d = 0; d < coordDim; ++d)
162 {
163 const TData n = norms[d * stride + i];
164 const TData up =
165 inflow ? velInf[d] : bndPtr[(d + 1) * stride + i] / rhoInt;
166 const TData v = up + vDiff * n;
167
168 bndPtr[(d + 1) * stride + i] = rhoBC * v;
169 EkBC += TData(0.5) * rhoBC * v * v;
170 }
171
172 bndPtr[i] = rhoBC;
173 bndPtr[eng * stride + i] = pBC / gamM1 + EkBC;
174 });
175
177}
178
179} // namespace Nektar::detail
#define NEKTAR_LAMBDA
#define NEK_FORCE_INLINE
Definition NekInline.hpp:46
static NEK_FORCE_INLINE void ApplyRiemannInvariantBlock(const size_t stride, const unsigned coordDim, const size_t eng, const TData gamma, const TData rhoInf, const TData pInf, const TData *velInfHost, const TData *VnInf, const TData *norms, TData *bndPtr, const unsigned int streamID=0)
Reconstruct the boundary state on a block from the Riemann invariants, each taken from the side that ...
static NEK_FORCE_INLINE void ProjectFreestreamVelocityBlock(const size_t stride, const unsigned coordDim, const TData *velInfHost, const TData *norms, TData *VnInf, const unsigned int streamID=0)
Project the freestream velocity onto a block's outward normals.
static void LoopExecutionSetStreamID(const unsigned int streamID)
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289