Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
vreman_nut_kernel.h
Go to the documentation of this file.
1#ifndef __COMMON_VREMAN_NUT_KERNEL_H__
2#define __COMMON_VREMAN_NUT_KERNEL_H__
3/*
4 Copyright (c) 2024, 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>
44 const T * __restrict__ a12,
45 const T * __restrict__ a13,
46 const T * __restrict__ a21,
47 const T * __restrict__ a22,
48 const T * __restrict__ a23,
49 const T * __restrict__ a31,
50 const T * __restrict__ a32,
51 const T * __restrict__ a33,
52 const T * __restrict__ delta,
53 T * __restrict__ nut,
54 const T * __restrict__ mult,
55 const T c,
56 const T eps,
57 const int n){
58
59 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
60 const int str = blockDim.x * gridDim.x;
61
65
66 for (int i = idx; i < n; i += str) {
67
68 const T a11_r = a11[i];
69 const T a12_r = a12[i];
70 const T a13_r = a13[i];
71 const T a21_r = a21[i];
72 const T a22_r = a22[i];
73 const T a23_r = a23[i];
74 const T a31_r = a31[i];
75 const T a32_r = a32[i];
76 const T a33_r = a33[i];
77 const T delta_r = delta[i];
78
85
89
90 b_beta = max(0.0, b_beta);
91
93
94 nut[i] = c * delta_r * delta_r
95 * sqrt(b_beta / (aijaij + eps)) * mult[i];
96 }
97}
98
99template<typename T>
101 const T * __restrict__ a12,
102 const T * __restrict__ a13,
103 const T * __restrict__ a21,
104 const T * __restrict__ a22,
105 const T * __restrict__ a23,
106 const T * __restrict__ a31,
107 const T * __restrict__ a32,
108 const T * __restrict__ a33,
109 const T * __restrict__ delta,
110 T * __restrict__ nut,
111 const T * __restrict__ mult,
112 const T c,
113 const T eps,
114 const int n,
115 const T * __restrict__ dTdx,
116 const T * __restrict__ dTdy,
117 const T * __restrict__ dTdz,
118 const T n1, const T n2, const T n3,
119 const T g1, const T g2, const T g3,
120 const T ri_c, const T ref_temp){
121 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
122 const int str = blockDim.x * gridDim.x;
123
126 T b_beta, aijaij;
127 T nut0;
128
129 for (int i = idx; i < n; i += str) {
130
131 const T a11_r = a11[i];
132 const T a12_r = a12[i];
133 const T a13_r = a13[i];
134 const T a21_r = a21[i];
135 const T a22_r = a22[i];
136 const T a23_r = a23[i];
137 const T a31_r = a31[i];
138 const T a32_r = a32[i];
139 const T a33_r = a33[i];
140 const T delta_r = delta[i];
141
148
152
153 b_beta = max(0.0, b_beta);
154
156
157 nut0 = c * delta_r * delta_r
158 * sqrt(b_beta / (aijaij + eps)) * mult[i];
159
160 // Scalar gradient for buoyancy
161 T buoyancy = (g1*dTdx[i] + g2*dTdy[i] + g3*dTdz[i]) / ref_temp;
162
163 // Directional derivative along n
164 T du_n1 = a11_r*n1 + a12_r*n2 + a13_r*n3;
165 T du_n2 = a21_r*n1 + a22_r*n2 + a23_r*n3;
166 T du_n3 = a31_r*n1 + a32_r*n2 + a33_r*n3;
167
168 T du_parallel = du_n1*n1 + du_n2*n2 + du_n3*n3;
169
170 T sh1 = du_n1 - du_parallel*n1;
171 T sh2 = du_n2 - du_parallel*n2;
172 T sh3 = du_n3 - du_parallel*n3;
173
174 T shear_sq = sh1*sh1 + sh2*sh2 + sh3*sh3;
175
176 T ri = buoyancy / (shear_sq + eps);
177
178 T out;
179 if (ri <= ri_c) {
180 T v = (T)1 - ri/ri_c;
181 if (v < (T)0) v = (T)0;
182 out = nut0 * sqrt(v);
183 } else {
184 out = eps;
185 }
186
187 nut[i] = out;
188 }
189}
190#endif // __COMMON_VREMAN_NUT_KERNEL_H__
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
__global__ void vreman_nut_compute(const T *__restrict__ a11, const T *__restrict__ a12, const T *__restrict__ a13, const T *__restrict__ a21, const T *__restrict__ a22, const T *__restrict__ a23, const T *__restrict__ a31, const T *__restrict__ a32, const T *__restrict__ a33, const T *__restrict__ delta, T *__restrict__ nut, const T *__restrict__ mult, const T c, const T eps, const int n)
__global__ void vreman_nut_compute_buoy(const T *__restrict__ a11, const T *__restrict__ a12, const T *__restrict__ a13, const T *__restrict__ a21, const T *__restrict__ a22, const T *__restrict__ a23, const T *__restrict__ a31, const T *__restrict__ a32, const T *__restrict__ a33, const T *__restrict__ delta, T *__restrict__ nut, const T *__restrict__ mult, const T c, const T eps, const int n, const T *__restrict__ dTdx, const T *__restrict__ dTdy, const T *__restrict__ dTdz, const T n1, const T n2, const T n3, const T g1, const T g2, const T g3, const T ri_c, const T ref_temp)
#define max(a, b)
Definition tensor.cu:40