This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvec_mom_cuda_kernels.cu
316 lines (280 loc) · 10.8 KB
/
advec_mom_cuda_kernels.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*Crown Copyright 2012 AWE.
*
* This file is part of CloverLeaf.
*
* CloverLeaf is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* CloverLeaf is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* CloverLeaf. If not, see http://www.gnu.org/licenses/.
*/
/*
* @brief CUDA momentum advection kernel
* @author Michael Boulton
* @details Performs a second order advective remap on the vertex momentum
* using van-Leer limiting and directional splitting.
* Note that although pre_vol is only set and not used in the update, please
* leave it in the method.
*/
#include "cuda_common.cu"
__global__ void device_advec_mom_vol_kernel_cuda
(int x_min,int x_max,int y_min,int y_max, int mom_sweep,
double* __restrict const post_vol,
double* __restrict const pre_vol,
const double* __restrict const volume,
const double* __restrict const vol_flux_x,
const double* __restrict const vol_flux_y)
{
__kernel_indexes;
if(row >= (y_min + 1) - 2 && row <= (y_max + 1) + 2
&& column >= (x_min + 1) - 2 && column <= (x_max + 1) + 2)
{
if(mom_sweep == 1)
{
post_vol[THARR2D(0, 0, 1)] = volume[THARR2D(0, 0, 0)]
+ vol_flux_y[THARR2D(0, 1, 0)] - vol_flux_y[THARR2D(0, 0, 0)];
pre_vol[THARR2D(0, 0, 1)] = post_vol[THARR2D(0, 0, 1)]
+ vol_flux_x[THARR2D(1, 0, 1)] - vol_flux_x[THARR2D(0, 0, 1)];
}
else if(mom_sweep == 2)
{
post_vol[THARR2D(0, 0, 1)] = volume[THARR2D(0, 0, 0)]
+ vol_flux_x[THARR2D(1, 0, 1)] - vol_flux_x[THARR2D(0, 0, 1)];
pre_vol[THARR2D(0, 0, 1)] = post_vol[THARR2D(0, 0, 1)]
+ vol_flux_y[THARR2D(0, 1, 0)] - vol_flux_y[THARR2D(0, 0, 0)];
}
else if(mom_sweep == 3)
{
post_vol[THARR2D(0, 0, 1)] = volume[THARR2D(0, 0, 0)];
pre_vol[THARR2D(0, 0, 1)] = post_vol[THARR2D(0, 0, 1)]
+ vol_flux_y[THARR2D(0, 1, 0)] - vol_flux_y[THARR2D(0, 0, 0)];
}
else if(mom_sweep == 4)
{
post_vol[THARR2D(0, 0, 1)] = volume[THARR2D(0, 0, 0)];
pre_vol[THARR2D(0, 0, 1)] = post_vol[THARR2D(0, 0, 1)]
+ vol_flux_x[THARR2D(1, 0, 1)] - vol_flux_x[THARR2D(0, 0, 1)];
}
}
}
////////////////////////////////////////////////////////////
//x kernels
__global__ void device_advec_mom_node_flux_post_x_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
double* __restrict const node_flux,
double* __restrict const node_mass_post,
const double* __restrict const mass_flux_x,
const double* __restrict const post_vol,
const double* __restrict const density1)
{
__kernel_indexes;
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) - 2 && column <= (x_max + 1) + 2)
{
node_flux[THARR2D(0, 0, 1)] = 0.25
* (mass_flux_x[THARR2D(0, -1, 1)] + mass_flux_x[THARR2D(0, 0, 1)]
+ mass_flux_x[THARR2D(1, -1, 1)] + mass_flux_x[THARR2D(1, 0, 1)]);
}
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) - 1 && column <= (x_max + 1) + 2)
{
node_mass_post[THARR2D(0, 0, 1)] = 0.25
*(density1[THARR2D(0, -1, 0)] * post_vol[THARR2D(0, -1, 1)]
+ density1[THARR2D(0, 0, 0)] * post_vol[THARR2D(0, 0, 1)]
+ density1[THARR2D(-1, -1, 0)] * post_vol[THARR2D(-1, -1, 1)]
+ density1[THARR2D(-1, 0, 0)] * post_vol[THARR2D(-1, 0, 1)]);
}
}
__global__ void device_advec_mom_node_pre_x_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_flux,
const double* __restrict const node_mass_post,
double* __restrict const node_mass_pre)
{
__kernel_indexes;
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) - 1 && column <= (x_max + 1) + 2)
{
node_mass_pre[THARR2D(0, 0, 1)] = node_mass_post[THARR2D(0, 0, 1)]
- node_flux[THARR2D(-1, 0, 1)] + node_flux[THARR2D(0, 0, 1)];
}
}
__global__ void device_advec_mom_flux_x_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_flux,
const double* __restrict const node_mass_post,
const double* __restrict const node_mass_pre,
const double* __restrict const xvel1,
const double* __restrict const celldx,
double* __restrict const mom_flux)
{
__kernel_indexes;
int upwind, donor, downwind, dif;
double advec_vel;
double sigma, width, vdiffuw, vdiffdw, limiter;
double auw, adw, wind;
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) - 1 && column <= (x_max + 1) + 1)
{
if(node_flux[THARR2D(0, 0, 1)] < 0.0)
{
upwind = 2;
donor = 1;
downwind = 0;
dif = donor;
}
else
{
upwind = -1;
donor = 0;
downwind = 1;
dif = upwind;
}
sigma = fabs(node_flux[THARR2D(0, 0, 1)]) / node_mass_pre[THARR2D(donor, 0, 1)];
vdiffuw = xvel1[THARR2D(donor, 0, 1)] - xvel1[THARR2D(upwind, 0, 1)];
vdiffdw = xvel1[THARR2D(downwind, 0, 1)] - xvel1[THARR2D(donor, 0, 1)];
limiter = 0.0;
if(vdiffdw * vdiffuw > 0.0)
{
auw = fabs(vdiffuw);
adw = fabs(vdiffdw);
wind = (vdiffdw <= 0.0) ? -1.0 : 1.0;
width = celldx[column];
limiter = wind * MIN(width * ((2.0 - sigma) * adw / width
+ (1.0 + sigma) * auw / celldx[column + dif]) / 6.0,
MIN(auw, adw));
}
advec_vel = xvel1[THARR2D(donor, 0, 1)] + (1.0 - sigma) * limiter;
mom_flux[THARR2D(0, 0, 1)] = advec_vel * node_flux[THARR2D(0, 0, 1)];
}
}
__global__ void device_advec_mom_xvel_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_mass_post,
const double* __restrict const node_mass_pre,
const double* __restrict const mom_flux,
double* __restrict const xvel1)
{
__kernel_indexes;
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
xvel1[THARR2D(0, 0, 1)] = (xvel1[THARR2D(0, 0, 1)]
* node_mass_pre[THARR2D(0, 0, 1)] + mom_flux[THARR2D(-1, 0, 1)]
- mom_flux[THARR2D(0, 0, 1)]) / node_mass_post[THARR2D(0, 0, 1)];
}
}
////////////////////////////////////////////////////////////
//y kernels
__global__ void device_advec_mom_node_flux_post_y_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
double* __restrict const node_flux,
double* __restrict const node_mass_post,
const double* __restrict const mass_flux_y,
const double* __restrict const post_vol,
const double* __restrict const density1)
{
__kernel_indexes;
if(row >= (y_min + 1) - 2 && row <= (y_max + 1) + 2
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
node_flux[THARR2D(0, 0, 1)] = 0.25
* (mass_flux_y[THARR2D(-1, 0, 0)] + mass_flux_y[THARR2D(0, 0, 0)]
+ mass_flux_y[THARR2D(-1, 1, 0)] + mass_flux_y[THARR2D(0, 1, 0)]);
}
if(row >= (y_min + 1) - 1 && row <= (y_max + 1) + 2
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
node_mass_post[THARR2D(0, 0, 1)] = 0.25
* (density1[THARR2D(0, -1, 0)] * post_vol[THARR2D(0, -1, 1)]
+ density1[THARR2D(0, 0, 0)] * post_vol[THARR2D(0, 0, 1)]
+ density1[THARR2D(-1, -1, 0)] * post_vol[THARR2D(-1, -1, 1)]
+ density1[THARR2D(-1, 0, 0)] * post_vol[THARR2D(-1, 0, 1)]);
}
}
__global__ void device_advec_mom_node_pre_y_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_flux,
const double* __restrict const node_mass_post,
double* __restrict const node_mass_pre)
{
__kernel_indexes;
if(row >= (y_min + 1) - 1 && row <= (y_max + 1) + 2
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
node_mass_pre[THARR2D(0, 0, 1)] = node_mass_post[THARR2D(0, 0, 1)]
- node_flux[THARR2D(0, -1, 1)] + node_flux[THARR2D(0, 0, 1)];
}
}
__global__ void device_advec_mom_flux_y_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_flux,
const double* __restrict const node_mass_post,
const double* __restrict const node_mass_pre,
const double* __restrict const yvel1,
const double* __restrict const celldy,
double* __restrict const mom_flux)
{
__kernel_indexes;
int upwind, donor, downwind, dif;
double advec_vel;
double sigma, width, vdiffuw, vdiffdw, limiter;
double auw, adw, wind;
if(row >= (y_min + 1) - 1 && row <= (y_max + 1) + 1
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
if(node_flux[THARR2D(0, 0, 1)] < 0.0)
{
upwind = 2;
donor = 1;
downwind = 0;
dif = donor;
}
else
{
upwind = -1;
donor = 0;
downwind = 1;
dif = upwind;
}
sigma = fabs(node_flux[THARR2D(0, 0, 1)]) / node_mass_pre[THARR2D(0, donor, 1)];
vdiffuw = yvel1[THARR2D(0, donor, 1)] - yvel1[THARR2D(0, upwind, 1)];
vdiffdw = yvel1[THARR2D(0, downwind, 1)] - yvel1[THARR2D(0, donor, 1)];
limiter = 0.0;
if(vdiffdw * vdiffuw > 0.0)
{
auw = fabs(vdiffuw);
adw = fabs(vdiffdw);
wind = (vdiffdw <= 0.0) ? -1.0 : 1.0;
width = celldy[row];
limiter = wind * MIN(width * ((2.0 - sigma) * adw / width
+ (1.0 + sigma) * auw / celldy[row + dif]) / 6.0,
MIN(auw, adw));
}
advec_vel = yvel1[THARR2D(0, donor, 1)] + (1.0 - sigma) * limiter;
mom_flux[THARR2D(0, 0, 1)] = advec_vel * node_flux[THARR2D(0, 0, 1)];
}
}
__global__ void device_advec_mom_yvel_kernel_cuda
(int x_min,int x_max,int y_min,int y_max,
const double* __restrict const node_mass_post,
const double* __restrict const node_mass_pre,
const double* __restrict const mom_flux,
double* __restrict const yvel1)
{
__kernel_indexes;
if(row >= (y_min + 1) && row <= (y_max + 1) + 1
&& column >= (x_min + 1) && column <= (x_max + 1) + 1)
{
yvel1[THARR2D(0, 0, 1)] = (yvel1[THARR2D(0, 0, 1)]
* node_mass_pre[THARR2D(0, 0, 1)] + mom_flux[THARR2D(0, -1, 1)]
- mom_flux[THARR2D(0, 0, 1)]) / node_mass_post[THARR2D(0, 0, 1)];
}
}