Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cai_sagaut_model_ii_kernel.h
Go to the documentation of this file.
1#ifndef CAI_SAGAUT_MODEL_II_KERNEL_H
2#define CAI_SAGAUT_MODEL_II_KERNEL_H
3
4/*
5 Copyright (c) 2026, The Neko Authors
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above
16 copyright notice, this list of conditions and the following
17 disclaimer in the documentation and/or other materials provided
18 with the distribution.
19
20 * Neither the name of the authors nor the names of its
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#include <cfloat>
39#include <algorithm>
40#include <cmath>
41
67template<typename T>
69 const T * __restrict__ v_d,
70 const T * __restrict__ w_d,
71 const int * __restrict__ ind_r_d,
72 const int * __restrict__ ind_s_d,
73 const int * __restrict__ ind_t_d,
74 const int * __restrict__ ind_e_d,
75 const T * __restrict__ n_x_d,
76 const T * __restrict__ n_y_d,
77 const T * __restrict__ n_z_d,
78 const T * __restrict__ nu_d,
79 const T * __restrict__ rho_w_d,
80 const T * __restrict__ h_d,
84 const int n_nodes,
85 const int lx,
86 const T kappa,
87 const T B,
88 const T p,
89 const T s) {
90 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
91 const int str = blockDim.x * gridDim.x;
92 const T one = static_cast<T>(1.0);
93 const T eps = (sizeof(T) == sizeof(float)) ?
94 static_cast<T>(FLT_EPSILON) :
95 static_cast<T>(DBL_EPSILON);
96 const T e_const = exp(kappa * B);
97
98 for (int i = idx; i < n_nodes; i += str) {
99 const int index = (ind_e_d[i] - 1) * lx * lx * lx +
100 (ind_t_d[i] - 1) * lx * lx +
101 (ind_s_d[i] - 1) * lx +
102 (ind_r_d[i] - 1);
103
104 T ui = u_d[index];
105 T vi = v_d[index];
106 T wi = w_d[index];
107 const T rho = rho_w_d[i];
108 const T nx = n_x_d[i];
109 const T ny = n_y_d[i];
110 const T nz = n_z_d[i];
111
112 const T normu = ui * nx + vi * ny + wi * nz;
113 ui -= normu * nx;
114 vi -= normu * ny;
115 wi -= normu * nz;
116
117 const T magu = sqrt(ui * ui + vi * vi + wi * wi);
118
119 if (magu < eps) {
120 tau_x_d[i] = static_cast<T>(0.0);
121 tau_y_d[i] = static_cast<T>(0.0);
122 tau_z_d[i] = static_cast<T>(0.0);
123 continue;
124 }
125
126 const T rey = magu * h_d[i] / nu_d[i];
127 const T blend = exp(-pow(rey / s, p));
128 const T warg = kappa * e_const * rey;
129 const T a = one /
130 (one + static_cast<T>(0.5) * log(one + warg));
131 T wlam = log(one + a * warg);
132 wlam = wlam / (one + wlam) * (one + log(warg / wlam));
133 const T up = blend * sqrt(rey) +
134 (one - blend) * wlam / kappa;
135 const T utau = magu / (up + eps);
136
137 tau_x_d[i] = -rho * utau * utau * ui / (magu + eps);
138 tau_y_d[i] = -rho * utau * utau * vi / (magu + eps);
139 tau_z_d[i] = -rho * utau * utau * wi / (magu + eps);
140 }
141}
142
143#endif
const int i
__global__ void cai_sagaut_model_ii_compute(const T *__restrict__ u_d, const T *__restrict__ v_d, const T *__restrict__ w_d, const int *__restrict__ ind_r_d, const int *__restrict__ ind_s_d, const int *__restrict__ ind_t_d, const int *__restrict__ ind_e_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 int lx, const T kappa, const T B, const T p, const T s)
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)