Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
reichardt_kernel.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#ifndef __WALL_MODELS_REICHARDT_KERNEL_H__
36#define __WALL_MODELS_REICHARDT_KERNEL_H__
37
38#include <cfloat>
39#include <cmath>
40
49template<typename T>
50__device__ T reichardt_up(const T yp, const T kappa, const T C,
51 const T B1, const T B2) {
52 const T one = static_cast<T>(1.0);
53
54 return log(one + kappa * yp) / kappa +
55 C * (one - exp(-yp / B1) - yp / B1 * exp(-yp / B2));
56}
57
66template<typename T>
67__device__ T reichardt_dup(const T yp, const T kappa, const T C,
68 const T B1, const T B2) {
69 const T one = static_cast<T>(1.0);
70
71 return one / (one + kappa * yp) +
72 C / B1 * (exp(-yp / B1) - (one - yp / B2) * exp(-yp / B2));
73}
74
87template<typename T>
88__device__ T reichardt_solve(const T u, const T y, const T guess,
89 const T nu, const T kappa, const T C,
90 const T B1, const T B2, const T tol) {
91 T utau = guess;
92 const int maxiter = 100;
93
94 for (int k = 0; k < maxiter; ++k) {
95 const T old = utau;
96 const T yp = y * utau / nu;
97 const T up = reichardt_up(yp, kappa, C, B1, B2);
98
99 // Evaluate function and its derivative
100 const T f = utau * up - u;
101 const T df = up + yp * reichardt_dup(yp, kappa, C, B1, B2);
102
103 // Update solution, keeping utau positive
104 utau -= f / df;
105 if (utau <= static_cast<T>(0.0)) {
106 utau = static_cast<T>(0.5) * old;
107 }
108
109 if (fabs((old - utau) / old) < tol) {
110 break;
111 }
112 }
113
114 return utau;
115}
116
138template<typename T>
139__global__ void reichardt_compute(const T * __restrict__ u_d,
140 const T * __restrict__ v_d,
141 const T * __restrict__ w_d,
142 const T * __restrict__ n_x_d,
143 const T * __restrict__ n_y_d,
144 const T * __restrict__ n_z_d,
145 const T * __restrict__ nu_d,
146 const T * __restrict__ rho_w_d,
147 const T * __restrict__ h_d,
148 T * __restrict__ tau_x_d,
149 T * __restrict__ tau_y_d,
150 T * __restrict__ tau_z_d,
151 const int n_nodes,
152 const T kappa,
153 const T C,
154 const T B1,
155 const T B2,
156 const int tstep) {
157 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
158 const int str = blockDim.x * gridDim.x;
159 const T eps = (sizeof(T) == sizeof(float)) ?
160 static_cast<T>(FLT_EPSILON) :
161 static_cast<T>(DBL_EPSILON);
162 const T tol = (sizeof(T) == sizeof(float)) ?
163 static_cast<T>(10.0 * FLT_EPSILON) :
164 static_cast<T>(1e-8);
165
166 for (int i = idx; i < n_nodes; i += str) {
167 T ui = u_d[i];
168 T vi = v_d[i];
169 T wi = w_d[i];
170 const T rho = rho_w_d[i];
171 const T nx = n_x_d[i];
172 const T ny = n_y_d[i];
173 const T nz = n_z_d[i];
174 const T h = h_d[i];
175 const T nu = nu_d[i];
176
177 // Project on tangential direction
178 const T normu = ui * nx + vi * ny + wi * nz;
179 ui -= normu * nx;
180 vi -= normu * ny;
181 wi -= normu * nz;
182
183 const T magu = sqrt(ui * ui + vi * vi + wi * wi);
184
185 // No tangential velocity, no shear stress
186 if (magu <= eps) {
187 tau_x_d[i] = static_cast<T>(0.0);
188 tau_y_d[i] = static_cast<T>(0.0);
189 tau_z_d[i] = static_cast<T>(0.0);
190 continue;
191 }
192
193 // Get initial guess for the Newton solver
194 T guess = tau_x_d[i] * tau_x_d[i] +
195 tau_y_d[i] * tau_y_d[i] +
196 tau_z_d[i] * tau_z_d[i];
197 if (tstep == 1 || guess <= static_cast<T>(0.0)) {
198 guess = sqrt(magu * nu / h);
199 } else {
200 guess = sqrt(sqrt(guess) / rho);
201 }
202
203 const T utau = reichardt_solve(magu, h, guess, nu, kappa, C, B1, B2,
204 tol);
205
206 // Distribute according to the velocity vector
207 tau_x_d[i] = -rho * utau * utau * ui / magu;
208 tau_y_d[i] = -rho * utau * utau * vi / magu;
209 tau_z_d[i] = -rho * utau * utau * wi / magu;
210 }
211}
212
213#endif // __WALL_MODELS_REICHARDT_KERNEL_H__
const int i
__global__ void const T *__restrict__ u
const int e
__device__ T reichardt_up(const T yp, const T kappa, const T C, const T B1, const T B2)
__device__ T reichardt_solve(const T u, const T y, const T guess, const T nu, const T kappa, const T C, const T B1, const T B2, const T tol)
__device__ T reichardt_dup(const T yp, const T kappa, const T C, const T B1, const T B2)
__global__ void reichardt_compute(const T *__restrict__ u_d, const T *__restrict__ v_d, const T *__restrict__ w_d, const T *__restrict__ n_x_d, const T *__restrict__ n_y_d, const T *__restrict__ n_z_d, const T *__restrict__ nu_d, const T *__restrict__ rho_w_d, const T *__restrict__ h_d, T *__restrict__ tau_x_d, T *__restrict__ tau_y_d, T *__restrict__ tau_z_d, const int n_nodes, const T kappa, const T C, const T B1, const T B2, const int tstep)