Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
compressible_ops_kernel.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2025, 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 __FLUID_COMPRESSIBLE_OPS_KERNEL_H__
36#define __FLUID_COMPRESSIBLE_OPS_KERNEL_H__
37
39
43template< typename T>
45 const T * __restrict__ u,
46 const T * __restrict__ v,
47 const T * __restrict__ w,
48 const T gamma,
49 const T * __restrict__ p,
50 const T * __restrict__ rho,
51 const int n) {
52
53 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
54 const int str = blockDim.x * gridDim.x;
55
56 for (int i = idx; i < n; i += str) {
57 T vel_mag = sqrt(u[i]*u[i] + v[i]*v[i] + w[i]*w[i]);
58 T sound_speed = sqrt(gamma * p[i] / rho[i]);
59 max_wave_speed[i] = vel_mag + sound_speed;
60 }
61
62}
63
67template< typename T>
69 const T * __restrict__ p,
70 const T * __restrict__ rho,
71 const T gamma,
72 const int n) {
73
74 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
75 const int str = blockDim.x * gridDim.x;
76
77 for (int i = idx; i < n; i += str) {
78 // S = 1/(gamma-1) * rho * (log(p) - gamma * log(rho))
79 T log_p = log(p[i]);
80 T log_rho = log(rho[i]);
81 S[i] = (1.0 / (gamma - 1.0)) * rho[i] * (log_p - gamma * log_rho);
82 }
83
84}
85
89template< typename T>
93 const T* __restrict__ m_x,
94 const T* __restrict__ m_y,
95 const T* __restrict__ m_z,
96 const T* __restrict__ rho,
97 const int n) {
98
99
100 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
101 const int str = blockDim.x * gridDim.x;
102
103 for (int i = idx; i < n; i += str) {
104 u[i] = m_x[i] / rho[i];
105 v[i] = m_y[i] / rho[i];
106 w[i] = m_z[i] / rho[i];
107 }
108
109}
110
111
115template< typename T>
117 T* __restrict__ m_y,
118 T* __restrict__ m_z,
119 T* __restrict__ p,
121 const T* __restrict__ u,
122 const T* __restrict__ v,
123 const T* __restrict__ w,
124 const T* __restrict__ E,
125 const T* __restrict__ rho,
126 const T gamma,
127 const int n) {
128
129 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
130 const int str = blockDim.x * gridDim.x;
131
132 for (int i = idx; i < n; i += str) {
133 m_x[i] = u[i] * rho[i];
134 m_y[i] = v[i] * rho[i];
135 m_z[i] = w[i] * rho[i];
136
137 /* Update p = (gamma - 1) * (E - 0.5 * rho * (u^2 + v^2 + w^2)) */
138 const real tmp = 0.5 * rho[i] * (u[i]*u[i] + v[i]*v[i] + w[i]*w[i]);
139 p[i] = (gamma - 1.0) * (E[i] - tmp);
140 ruvw[i] = tmp;
141 }
142}
143
144#define MAX(a,b) (((a)>(b))?(a):(b))
145
149template< typename T>
151 T* __restrict__ p,
152 const T* __restrict__ ruvw,
153 const T gamma,
154 const int n) {
155
156 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
157 const int str = blockDim.x * gridDim.x;
158
159 for (int i = idx; i < n; i += str) {
160 /* Ensure pressure is positive */
161 p[i] = MAX(p[i], 1e-12);
162 /* E = p / (gamma - 1) + 0.5 * rho * (u^2 + v^2 + w^2) */
163 E[i] = p[i] * (1.0 / (gamma - 1.0)) + ruvw[i];
164 }
165}
166
170template< typename T>
172 const T* __restrict__ p,
173 const T* __restrict__ rho,
174 const T gamma,
175 const int n) {
176
177 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
178 const int str = blockDim.x * gridDim.x;
179
180 for (int i = idx; i < n; i += str) {
181 T_field[i] = p[i] / (rho[i] * (gamma - 1.0));
182 }
183}
184
188template< typename T>
192 const T* __restrict__ dudx,
193 const T* __restrict__ dudy,
194 const T* __restrict__ dudz,
195 const T* __restrict__ dvdx,
196 const T* __restrict__ dvdy,
197 const T* __restrict__ dvdz,
198 const T* __restrict__ dwdx,
199 const T* __restrict__ dwdy,
200 const T* __restrict__ dwdz,
201 const T* __restrict__ mu,
202 const int n) {
203
204 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
205 const int str = blockDim.x * gridDim.x;
206
207 for (int i = idx; i < n; i += str) {
208 const T div_u = dudx[i] + dvdy[i] + dwdz[i];
209 const T two_thirds = 2.0 / 3.0;
210 const T tau_xx = mu[i] * (2.0 * dudx[i] - two_thirds * div_u);
211 const T tau_yy = mu[i] * (2.0 * dvdy[i] - two_thirds * div_u);
212 const T tau_zz = mu[i] * (2.0 * dwdz[i] - two_thirds * div_u);
213 const T tau_xy = mu[i] * (dudy[i] + dvdx[i]);
214 const T tau_xz = mu[i] * (dudz[i] + dwdx[i]);
215 const T tau_yz = mu[i] * (dvdz[i] + dwdy[i]);
216
217 div_flux[i] = mu[i] * div_u;
218 h1[i] = mu[i];
219 dissipation[i] = tau_xx * dudx[i] +
220 tau_xy * (dudy[i] + dvdx[i]) +
221 tau_xz * (dudz[i] + dwdx[i]) +
222 tau_yy * dvdy[i] +
223 tau_yz * (dvdz[i] + dwdy[i]) +
224 tau_zz * dwdz[i];
225 }
226}
227
231template< typename T>
236 T* __restrict__ f_x,
237 T* __restrict__ f_y,
238 T* __restrict__ f_z,
239 const T* __restrict__ opgrad_x,
240 const T* __restrict__ opgrad_y,
241 const T* __restrict__ opgrad_z,
242 const T* __restrict__ u,
243 const T* __restrict__ v,
244 const T* __restrict__ w,
245 const T* __restrict__ B,
247 const int n) {
248
249 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
250 const int str = blockDim.x * gridDim.x;
251
252 for (int i = idx; i < n; i += str) {
253 f_x[i] -= (2.0 / 3.0) * opgrad_x[i];
254 f_y[i] -= (2.0 / 3.0) * opgrad_y[i];
255 f_z[i] -= (2.0 / 3.0) * opgrad_z[i];
256 visc_m_x[i] += f_x[i];
257 visc_m_y[i] += f_y[i];
258 visc_m_z[i] += f_z[i];
259 visc_E[i] += u[i] * f_x[i] + v[i] * f_y[i] + w[i] * f_z[i] -
260 B[i] * dissipation[i];
261 }
262}
263
267template< typename T>
270 const T* __restrict__ p,
271 const T* __restrict__ rho,
272 const T* __restrict__ kappa,
273 const T gamma,
274 const int n) {
275
276 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
277 const int str = blockDim.x * gridDim.x;
278
279 for (int i = idx; i < n; i += str) {
280 div_flux[i] = p[i] / (rho[i] * (gamma - 1.0));
281 h1[i] = kappa[i];
282 }
283}
284
285#endif // __FLUID_COMPRESSIBLE_OPS_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)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
const int e
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ h1
__global__ void compute_max_wave_speed_kernel(T *__restrict__ max_wave_speed, const T *__restrict__ u, const T *__restrict__ v, const T *__restrict__ w, const T gamma, const T *__restrict__ p, const T *__restrict__ rho, const int n)
__global__ void compute_entropy_kernel(T *__restrict__ S, const T *__restrict__ p, const T *__restrict__ rho, const T gamma, const int n)
__global__ void ns_flux_temperature_kernel(T *__restrict__ div_flux, T *__restrict__ h1, const T *__restrict__ p, const T *__restrict__ rho, const T *__restrict__ kappa, const T gamma, const int n)
__global__ void update_mxyz_p_ruvw_kernel(T *__restrict__ m_x, T *__restrict__ m_y, T *__restrict__ m_z, T *__restrict__ p, T *__restrict__ ruvw, const T *__restrict__ u, const T *__restrict__ v, const T *__restrict__ w, const T *__restrict__ E, const T *__restrict__ rho, const T gamma, const int n)
__global__ void update_temperature_kernel(T *__restrict__ T_field, const T *__restrict__ p, const T *__restrict__ rho, const T gamma, const int n)
__global__ void update_e_kernel(T *__restrict__ E, T *__restrict__ p, const T *__restrict__ ruvw, const T gamma, const int n)
__global__ void update_uvw_kernel(T *__restrict__ u, T *__restrict__ v, T *__restrict__ w, const T *__restrict__ m_x, const T *__restrict__ m_y, const T *__restrict__ m_z, const T *__restrict__ rho, const int n)
__global__ void ns_flux_prepare_kernel(T *__restrict__ div_flux, T *__restrict__ dissipation, T *__restrict__ h1, const T *__restrict__ dudx, const T *__restrict__ dudy, const T *__restrict__ dudz, const T *__restrict__ dvdx, const T *__restrict__ dvdy, const T *__restrict__ dvdz, const T *__restrict__ dwdx, const T *__restrict__ dwdy, const T *__restrict__ dwdz, const T *__restrict__ mu, const int n)
__global__ void ns_flux_finalize_kernel(T *__restrict__ visc_m_x, T *__restrict__ visc_m_y, T *__restrict__ visc_m_z, T *__restrict__ visc_E, T *__restrict__ f_x, T *__restrict__ f_y, T *__restrict__ f_z, const T *__restrict__ opgrad_x, const T *__restrict__ opgrad_y, const T *__restrict__ opgrad_z, const T *__restrict__ u, const T *__restrict__ v, const T *__restrict__ w, const T *__restrict__ B, const T *__restrict__ dissipation, const int n)
#define MAX(a, b)
double real