Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
spalding_kernel.h
Go to the documentation of this file.
1#ifndef __COMMON_SPALDING_KERNEL_H__
2#define __COMMON_SPALDING_KERNEL_H__
3/*
4 Copyright (c) 2025, The Neko Authors
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following
16 disclaimer in the documentation and/or other materials provided
17 with the distribution.
18
19 * Neither the name of the authors nor the names of its
20 contributors may be used to endorse or promote products derived
21 from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35*/
36
40#include <cmath>
41#include <algorithm>
42template<typename T>
43__device__ T solve(const T u, const T y, const T guess, const T nu,
44 const T kappa, const T B);
45
49template<typename T>
51 const T * __restrict__ v_d,
52 const T * __restrict__ w_d,
53 const T * __restrict__ n_x_d,
54 const T * __restrict__ n_y_d,
55 const T * __restrict__ n_z_d,
56 const T * __restrict__ nu_d,
57 const T * __restrict__ rho_w_d,
58 const T * __restrict__ h_d,
62 const int n_nodes,
63 const T kappa,
64 const T B,
65 const int tstep) {
66
67 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
68 const int str = blockDim.x * gridDim.x;
69 for (int i = idx; i < n_nodes; i += str) {
70 T ui = u_d[i];
71 T vi = v_d[i];
72 T wi = w_d[i];
73 T rho = rho_w_d[i];
74
75 // Load normal vectors and wall shear stress values once
76 T nx = n_x_d[i];
77 T ny = n_y_d[i];
78 T nz = n_z_d[i];
79 T h = h_d[i];
80
81 // Project on tangential direction
82 T normu = ui * nx + vi * ny + wi * nz;
83
84 ui -= normu * nx;
85 vi -= normu * ny;
86 wi -= normu * nz;
87
88 T magu = sqrt(ui * ui + vi * vi + wi * wi);
89
90 // Get initial guess for Newton solver
91 T guess;
92 if (tstep == 1) {
93 guess = sqrt(magu * nu_d[i] / h);
94 } else {
95 guess = tau_x_d[i] * tau_x_d[i] +
96 tau_y_d[i] * tau_y_d[i] +
97 tau_z_d[i] * tau_z_d[i];
98 guess = sqrt(sqrt(guess));
99 }
100
101 // Solve for utau using Newton's method
102 T utau = solve(magu, h, guess, nu_d[i], kappa, B);
103
104 // Distribute according to the velocity vector
105 tau_x_d[i] = -rho * utau * utau * ui / magu;
106 tau_y_d[i] = -rho * utau * utau * vi / magu;
107 tau_z_d[i] = -rho * utau * utau * wi / magu;
108 }
109}
110
114template<typename T>
115__device__ T solve(const T u, const T y, const T guess, const T nu,
116 const T kappa, const T B) {
117 T utau = guess;
118 T yp, up, f, df, old, error;
119 const int maxiter = 100;
120
121 for (int k = 0; k < maxiter; ++k) {
122 up = u / utau;
123 yp = y * utau / nu;
124 old = utau;
125
126 // Evaluate function and its derivative
127 f = (up + exp(-kappa * B) *
128 (exp(kappa * up) - 1.0 - kappa * up -
129 0.5 * (kappa * up) * (kappa * up) -
130 (1.0 / 6.0) * (kappa * up) * (kappa * up) * (kappa * up)) -
131 yp);
132
133 df = (-y / nu - u / (utau * utau) -
134 kappa * up / utau * exp(-kappa * B) *
135 (exp(kappa * up) - 1.0 - kappa * up -
136 0.5 * (kappa * up) * (kappa * up)));
137
138 // Update solution
139 utau -= f / df;
140
141 error = fabs((old - utau) / old);
142
143 if (error < 1e-3) {
144 break;
145 }
146 }
147
148 return utau;
149}
150
151#endif // __COMMON_SPALDING_KERNEL_H__
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
const int e
__global__ void spalding_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 B, const int tstep)
solve(case_descr)
Definition intf.py:323