Neko 1.99.2
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 for (int s = blockDim.x / 2; s > 0; s >>= 1) {
110 if (tid < s) {
111 sdata[tid] = max(sdata[tid], sdata[tid + s]);
112 }
114 }
115
116 max_val = sdata[0];
118
119 for (int i = tid; i < lx3; i += blockDim.x) {
120 reg_coeff[offset + i] = max_val;
121 }
122}
123
127template<typename T>
129 const T * __restrict__ h,
130 const T * __restrict__ max_wave_speed,
131 const T c_avisc_low,
132 const int n) {
133 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
134 const int str = blockDim.x * gridDim.x;
135
136 for (int i = idx; i < n; i += str) {
137 T low_order_visc = c_avisc_low * h[i] * max_wave_speed[i];
138 reg_coeff[i] = min(reg_coeff[i], low_order_visc);
139 }
140}
141
145template<typename T>
147 const T * __restrict__ temp_field,
148 const T * __restrict__ mult_field,
149 const int n) {
150 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
151 const int str = blockDim.x * gridDim.x;
152
153 for (int i = idx; i < n; i += str) {
154 reg_coeff[i] = temp_field[i] / mult_field[i];
155 }
156}
157
158#endif // __FLUID_ENTROPY_VISCOSITY_KERNEL_H__
159
const int i
__syncthreads()
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
__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