Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
entropy_viscosity_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_ENTROPY_VISCOSITY_KERNEL_H__
36#define __FLUID_ENTROPY_VISCOSITY_KERNEL_H__
37
39
43template<typename T>
45 const T * __restrict__ S,
46 const T * __restrict__ S_lag1,
47 const T * __restrict__ S_lag2,
48 const T * __restrict__ S_lag3,
49 const T bdf1,
50 const T bdf2,
51 const T bdf3,
52 const T bdf4,
53 const T dt,
54 const int n) {
55 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
56 const int str = blockDim.x * gridDim.x;
57
58 for (int i = idx; i < n; i += str) {
59 entropy_residual[i] = (bdf1 * S[i]
60 - bdf2 * S_lag1[i]
61 - bdf3 * S_lag2[i]
62 - bdf4 * S_lag3[i]) / dt;
63 }
64}
65
69template<typename T>
71 const T * __restrict__ entropy_residual,
72 const T * __restrict__ h,
73 const T c_avisc_entropy,
74 const T n_S,
75 const int n) {
76 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
77 const int str = blockDim.x * gridDim.x;
78
79 for (int i = idx; i < n; i += str) {
80 reg_coeff[i] = c_avisc_entropy * h[i] * h[i] * entropy_residual[i] / n_S;
81 }
82}
83
88template<typename T>
90 const int lx3,
91 const int nelv) {
92 __shared__ T sdata[1024];
93
94 const int el = blockIdx.x;
95 const int tid = threadIdx.x;
96
97 if (el >= nelv) return;
98
99 const int offset = el * lx3;
100
101 T max_val = -1e30;
102 for (int i = tid; i < lx3; i += blockDim.x) {
103 max_val = max(max_val, reg_coeff[offset + i]);
104 }
105
106 sdata[tid] = max_val;
108
109 const int nthreads = blockDim.x;
110 int s = 1;
111 while (s < nthreads) s <<= 1;
112 for (s >>= 1; s > 0; s >>= 1) {
113 if (tid < s && tid + s < nthreads) {
114 sdata[tid] = max(sdata[tid], sdata[tid + s]);
115 }
117 }
118
119 max_val = sdata[0];
121
122 for (int i = tid; i < lx3; i += blockDim.x) {
123 reg_coeff[offset + i] = max_val;
124 }
125}
126
130template<typename T>
132 const T * __restrict__ h,
133 const T * __restrict__ max_wave_speed,
134 const T c_avisc_low,
135 const int n) {
136 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
137 const int str = blockDim.x * gridDim.x;
138
139 for (int i = idx; i < n; i += str) {
140 T low_order_visc = c_avisc_low * h[i] * max_wave_speed[i];
141 reg_coeff[i] = min(reg_coeff[i], low_order_visc);
142 }
143}
144
148template<typename T>
150 const T * __restrict__ temp_field,
151 const T * __restrict__ mult_field,
152 const int n) {
153 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
154 const int str = blockDim.x * gridDim.x;
155
156 for (int i = idx; i < n; i += str) {
157 reg_coeff[i] = temp_field[i] / mult_field[i];
158 }
159}
160
161#endif // __FLUID_ENTROPY_VISCOSITY_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 const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const int *__restrict__ const int nelv
const int i
__syncthreads()
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__global__ void entropy_visc_clamp_to_low_order_kernel(T *__restrict__ reg_coeff, const T *__restrict__ h, const T *__restrict__ max_wave_speed, const T c_avisc_low, const int n)
__global__ void entropy_visc_compute_viscosity_kernel(T *__restrict__ reg_coeff, const T *__restrict__ entropy_residual, const T *__restrict__ h, const T c_avisc_entropy, const T n_S, const int n)
__global__ void entropy_visc_compute_residual_kernel(T *__restrict__ entropy_residual, const T *__restrict__ S, const T *__restrict__ S_lag1, const T *__restrict__ S_lag2, const T *__restrict__ S_lag3, const T bdf1, const T bdf2, const T bdf3, const T bdf4, const T dt, const int n)
__global__ void entropy_visc_apply_element_max_kernel(T *__restrict__ reg_coeff, const int lx3, const int nelv)
__global__ void entropy_visc_smooth_divide_kernel(T *__restrict__ reg_coeff, const T *__restrict__ temp_field, const T *__restrict__ mult_field, const int n)
#define max(a, b)
Definition tensor.cu:40