-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadvec_mom.cpp
287 lines (256 loc) · 10.4 KB
/
advec_mom.cpp
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
/*
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/.
*/
#include "advec_mom.h"
// @brief Fortran momentum advection kernel
// @author Wayne Gaudin
// @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.
void advec_mom_kernel(
int x_min, int x_max, int y_min, int y_max,
Kokkos::View<double**>& vel1,
Kokkos::View<double**>& mass_flux_x,
Kokkos::View<double**>& vol_flux_x,
Kokkos::View<double**>& mass_flux_y,
Kokkos::View<double**>& vol_flux_y,
Kokkos::View<double**>& volume,
Kokkos::View<double**>& density1,
Kokkos::View<double**>& node_flux,
Kokkos::View<double**>& node_mass_post,
Kokkos::View<double**>& node_mass_pre,
Kokkos::View<double**>& mom_flux,
Kokkos::View<double**>& pre_vol,
Kokkos::View<double**>& post_vol,
Kokkos::View<double*>& celldx,
Kokkos::View<double*>& celldy,
int which_vel,
int sweep_number,
int direction) {
int mom_sweep=direction+2*(sweep_number-1);
// DO k=y_min-2,y_max+2
// DO j=x_min-2,x_max+2
Kokkos::MDRangePolicy<Kokkos::Rank<2>> policy({x_min-2+1, y_min-2+1}, {x_max+2+2, y_max+2+2});
if (mom_sweep == 1) { // x 1
Kokkos::parallel_for("advec_mom x1", policy, KOKKOS_LAMBDA(const int j, const int k) {
post_vol(j,k)= volume(j,k)+vol_flux_y(j ,k+1)-vol_flux_y(j,k);
pre_vol(j,k)=post_vol(j,k)+vol_flux_x(j+1,k )-vol_flux_x(j,k);
});
}
else if (mom_sweep == 2) { // y 1
Kokkos::parallel_for("advec_mom y1", policy, KOKKOS_LAMBDA(const int j, const int k) {
post_vol(j,k)= volume(j,k)+vol_flux_x(j+1,k )-vol_flux_x(j,k);
pre_vol(j,k)=post_vol(j,k)+vol_flux_y(j ,k+1)-vol_flux_y(j,k);
});
}
else if (mom_sweep == 3) { // x 2
Kokkos::parallel_for("advec_mom x1", policy, KOKKOS_LAMBDA(const int j, const int k) {
post_vol(j,k)=volume(j,k);
pre_vol(j,k)=post_vol(j,k)+vol_flux_y(j ,k+1)-vol_flux_y(j,k);
});
}
else if (mom_sweep == 4) { // y 2
Kokkos::parallel_for("advec_mom y1", policy, KOKKOS_LAMBDA(const int j, const int k) {
post_vol(j,k)=volume(j,k);
pre_vol(j,k)=post_vol(j,k)+vol_flux_x(j+1,k )-vol_flux_x(j,k);
});
}
if (direction == 1) {
if (which_vel == 1) {
// DO k=y_min,y_max+1
// DO j=x_min-2,x_max+2
Kokkos::parallel_for("advec_mom dir1, vel1, node_flux",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min-2+1, y_min+1}, {x_max+2+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
// Find staggered mesh mass fluxes, nodal masses and volumes.
node_flux(j,k)=0.25*(mass_flux_x(j,k-1 )+mass_flux_x(j ,k)
+mass_flux_x(j+1,k-1)+mass_flux_x(j+1,k));
});
// DO k=y_min,y_max+1
// DO j=x_min-1,x_max+2
Kokkos::parallel_for("advec_mom dir1, vel1, node_mass_pre",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min-1+1, y_min+1}, {x_max+2+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
// Staggered cell mass post advection
node_mass_post(j,k)=0.25*(density1(j ,k-1)*post_vol(j ,k-1)
+density1(j ,k )*post_vol(j ,k )
+density1(j-1,k-1)*post_vol(j-1,k-1)
+density1(j-1,k )*post_vol(j-1,k ));
node_mass_pre(j,k)=node_mass_post(j,k)-node_flux(j-1,k)+node_flux(j,k);
});
}
// DO k=y_min,y_max+1
// DO j=x_min-1,x_max+1
Kokkos::parallel_for("advec_mom dir1, mom_flux",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min-1+1, y_min+1}, {x_max+1+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
int upwind, donor, downwind, dif;
double sigma, width, limiter, vdiffuw, vdiffdw, auw, adw, wind, advec_vel_s;
if (node_flux(j,k) < 0.0) {
upwind=j+2;
donor=j+1;
downwind=j;
dif=donor;
}
else {
upwind=j-1;
donor=j;
downwind=j+1;
dif=upwind;
}
sigma=fabs(node_flux(j,k))/(node_mass_pre(donor,k));
width=celldx(j);
vdiffuw=vel1(donor,k)-vel1(upwind,k);
vdiffdw=vel1(downwind,k)-vel1(donor,k);
limiter=0.0;
if (vdiffuw*vdiffdw > 0.0) {
auw=fabs(vdiffuw);
adw=fabs(vdiffdw);
wind=1.0;
if (vdiffdw <= 0.0) wind=-1.0;
limiter=wind*MIN(MIN(width*((2.0-sigma)*adw/width+(1.0+sigma)*auw/celldx(dif))/6.0,auw),adw);
}
advec_vel_s=vel1(donor,k)+(1.0-sigma)*limiter;
mom_flux(j,k)=advec_vel_s*node_flux(j,k);
});
// DO k=y_min,y_max+1
// DO j=x_min,x_max+1
Kokkos::parallel_for("advec_mom dir1, vel1",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min+1, y_min+1}, {x_max+1+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
vel1 (j,k)=(vel1 (j,k)*node_mass_pre(j,k)+mom_flux(j-1,k)-mom_flux(j,k))/node_mass_post(j,k);
});
}
else if (direction == 2) {
if (which_vel == 1) {
// DO k=y_min-2,y_max+2
// DO j=x_min,x_max+1
Kokkos::parallel_for("advec_mom dir2, vel1, node_flux",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min+1, y_min-2+1}, {x_max+1+2, y_max+2+2}),
KOKKOS_LAMBDA (const int j, const int k) {
// Find staggered mesh mass fluxes and nodal masses and volumes.
node_flux(j,k)=0.25*(mass_flux_y(j-1,k )+mass_flux_y(j ,k )
+mass_flux_y(j-1,k+1)+mass_flux_y(j ,k+1));
});
// DO k=y_min-1,y_max+2
// DO j=x_min,x_max+1
Kokkos::parallel_for("advec_mom dir2, vel1, node_mass_pre",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min+1, y_min-1+1}, {x_max+1+2, y_max+2+2}),
KOKKOS_LAMBDA (const int j, const int k) {
node_mass_post(j,k)=0.25*(density1(j ,k-1)*post_vol(j ,k-1)
+density1(j ,k )*post_vol(j ,k )
+density1(j-1,k-1)*post_vol(j-1,k-1)
+density1(j-1,k )*post_vol(j-1,k ));
node_mass_pre(j,k)=node_mass_post(j,k)-node_flux(j,k-1)+node_flux(j,k);
});
}
// DO k=y_min-1,y_max+1
// DO j=x_min,x_max+1
Kokkos::parallel_for("advec_mom dir2, mom_flux",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min+1, y_min-1+1}, {x_max+1+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
int upwind, donor, downwind, dif;
double sigma, width, limiter, vdiffuw, vdiffdw, auw, adw, wind, advec_vel_s;
if (node_flux(j,k) < 0.0) {
upwind=k+2;
donor=k+1;
downwind=k;
dif=donor;
}
else {
upwind=k-1;
donor=k;
downwind=k+1;
dif=upwind;
}
sigma=fabs(node_flux(j,k))/(node_mass_pre(j,donor));
width=celldy(k);
vdiffuw=vel1(j,donor)-vel1(j,upwind);
vdiffdw=vel1(j,downwind)-vel1(j,donor);
limiter=0.0;
if (vdiffuw*vdiffdw > 0.0) {
auw=fabs(vdiffuw);
adw=fabs(vdiffdw);
wind=1.0;
if (vdiffdw <= 0.0) wind=-1.0;
limiter=wind*MIN(MIN(width*((2.0-sigma)*adw/width+(1.0+sigma)*auw/celldy(dif))/6.0,auw),adw);
}
advec_vel_s=vel1(j,donor)+(1.0-sigma)*limiter;
mom_flux(j,k)=advec_vel_s*node_flux(j,k);
});
// DO k=y_min,y_max+1
// DO j=x_min,x_max+1
Kokkos::parallel_for("advec_mom dir2, vel1",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({x_min+1, y_min+1}, {x_max+1+2, y_max+1+2}),
KOKKOS_LAMBDA (const int j, const int k) {
vel1 (j,k)=(vel1(j,k)*node_mass_pre(j,k)+mom_flux(j,k-1)-mom_flux(j,k))/node_mass_post(j,k);
});
}
}
// @brief Momentum advection driver
// @author Wayne Gaudin
// @details Invokes the user specified momentum advection kernel.
void advec_mom_driver(global_variables& globals, int tile, int which_vel, int direction, int sweep_number) {
if (which_vel == 1) {
advec_mom_kernel(
globals.chunk.tiles[tile].t_xmin,
globals.chunk.tiles[tile].t_xmax,
globals.chunk.tiles[tile].t_ymin,
globals.chunk.tiles[tile].t_ymax,
globals.chunk.tiles[tile].field.xvel1,
globals.chunk.tiles[tile].field.mass_flux_x,
globals.chunk.tiles[tile].field.vol_flux_x,
globals.chunk.tiles[tile].field.mass_flux_y,
globals.chunk.tiles[tile].field.vol_flux_y,
globals.chunk.tiles[tile].field.volume,
globals.chunk.tiles[tile].field.density1,
globals.chunk.tiles[tile].field.work_array1,
globals.chunk.tiles[tile].field.work_array2,
globals.chunk.tiles[tile].field.work_array3,
globals.chunk.tiles[tile].field.work_array4,
globals.chunk.tiles[tile].field.work_array5,
globals.chunk.tiles[tile].field.work_array6,
globals.chunk.tiles[tile].field.celldx,
globals.chunk.tiles[tile].field.celldy,
which_vel,
sweep_number,
direction);
}
else {
advec_mom_kernel(
globals.chunk.tiles[tile].t_xmin,
globals.chunk.tiles[tile].t_xmax,
globals.chunk.tiles[tile].t_ymin,
globals.chunk.tiles[tile].t_ymax,
globals.chunk.tiles[tile].field.yvel1,
globals.chunk.tiles[tile].field.mass_flux_x,
globals.chunk.tiles[tile].field.vol_flux_x,
globals.chunk.tiles[tile].field.mass_flux_y,
globals.chunk.tiles[tile].field.vol_flux_y,
globals.chunk.tiles[tile].field.volume,
globals.chunk.tiles[tile].field.density1,
globals.chunk.tiles[tile].field.work_array1,
globals.chunk.tiles[tile].field.work_array2,
globals.chunk.tiles[tile].field.work_array3,
globals.chunk.tiles[tile].field.work_array4,
globals.chunk.tiles[tile].field.work_array5,
globals.chunk.tiles[tile].field.work_array6,
globals.chunk.tiles[tile].field.celldx,
globals.chunk.tiles[tile].field.celldy,
which_vel,
sweep_number,
direction);
}
}