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_kernel.f90
343 lines (324 loc) · 11.9 KB
/
advec_mom_kernel.f90
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
!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 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.
MODULE advec_mom_kernel_mod
CONTAINS
SUBROUTINE advec_mom_kernel(x_min,x_max,y_min,y_max, &
xvel1, &
yvel1, &
mass_flux_x, &
vol_flux_x, &
mass_flux_y, &
vol_flux_y, &
volume, &
density1, &
node_flux, &
node_mass_post, &
node_mass_pre, &
advec_vel, &
mom_flux, &
pre_vol, &
post_vol, &
celldx, &
celldy, &
which_vel, &
sweep_number, &
direction, &
vector )
IMPLICIT NONE
INTEGER :: x_min,x_max,y_min,y_max
INTEGER :: which_vel,sweep_number,direction
LOGICAL :: vector
REAL(KIND=8), TARGET,DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: xvel1,yvel1
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+2) :: mass_flux_x
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+2) :: vol_flux_x
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+3) :: mass_flux_y
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+3) :: vol_flux_y
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: volume
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: density1
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: node_flux
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: node_mass_post
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: node_mass_pre
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: advec_vel
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: mom_flux
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: pre_vol
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3) :: post_vol
REAL(KIND=8), DIMENSION(x_min-2:x_max+2) :: celldx
REAL(KIND=8), DIMENSION(y_min-2:y_max+2) :: celldy
INTEGER :: j,k,mom_sweep
INTEGER :: upwind,donor,downwind,dif
REAL(KIND=8) :: sigma,wind,width
REAL(KIND=8) :: sigma2,wind2
REAL(KIND=8) :: vdiffuw,vdiffdw,auw,adw,limiter
REAL(KIND=8) :: vdiffuw2,vdiffdw2,auw2,limiter2
REAL(KIND=8), POINTER, DIMENSION(:,:) :: vel1
! Choose the correct velocity, ideally, remove this pointer
! if it affects performance.
! Leave this one in as a test of performance
IF(which_vel.EQ.1)THEN
vel1=>xvel1
ELSE
vel1=>yvel1
ENDIF
mom_sweep=direction+2*(sweep_number-1)
!$OMP PARALLEL
IF(mom_sweep.EQ.1)THEN ! x 1
!$OMP DO
DO k=y_min-2,y_max+2
DO j=x_min-2,x_max+2
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)
ENDDO
ENDDO
!$OMP END DO
ELSEIF(mom_sweep.EQ.2)THEN ! y 1
!$OMP DO
DO k=y_min-2,y_max+2
DO j=x_min-2,x_max+2
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)
ENDDO
ENDDO
!$OMP END DO
ELSEIF(mom_sweep.EQ.3)THEN ! x 2
!$OMP DO
DO k=y_min-2,y_max+2
DO j=x_min-2,x_max+2
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)
ENDDO
ENDDO
!$OMP END DO
ELSEIF(mom_sweep.EQ.4)THEN ! y 2
!$OMP DO
DO k=y_min-2,y_max+2
DO j=x_min-2,x_max+2
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)
ENDDO
ENDDO
!$OMP END DO
ENDIF
IF(direction.EQ.1)THEN
!$OMP DO
DO k=y_min,y_max+1
DO j=x_min-2,x_max+2
! Find staggered mesh mass fluxes, nodal masses and volumes.
node_flux(j,k)=0.25_8*(mass_flux_x(j,k-1 )+mass_flux_x(j ,k) &
+mass_flux_x(j+1,k-1)+mass_flux_x(j+1,k)) ! Mass Flux
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO k=y_min,y_max+1
DO j=x_min-1,x_max+2
! Staggered cell mass post advection
node_mass_post(j,k)=0.25_8*(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 ))
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO k=y_min,y_max+1
DO j=x_min-1,x_max+2
! Stagered cell mass pre advection
node_mass_pre(j,k)=node_mass_post(j,k)-node_flux(j-1,k)+node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
IF(vector) THEN
!$OMP DO PRIVATE(sigma,width,limiter,vdiffuw,vdiffdw,auw,adw,wind &
!$OMP ,sigma2,limiter2,vdiffuw2,vdiffdw2,auw2,wind2)
DO k=y_min,y_max+1
DO j=x_min-1,x_max+1
sigma=ABS(node_flux(j,k))/(node_mass_pre(j+1,k))
sigma2=ABS(node_flux(j,k))/(node_mass_pre(j,k))
width=celldx(j)
vdiffuw=vel1(j+1,k)-vel1(j+2,k)
vdiffdw=vel1(j,k)-vel1(j+1,k)
vdiffuw2=vel1(j,k)-vel1(j-1,k)
vdiffdw2=-vdiffdw
auw=ABS(vdiffuw)
adw=ABS(vdiffdw)
auw2=ABS(vdiffuw2)
wind=1.0_8
wind2=1.0_8
IF(vdiffdw.LE.0.0) wind=-1.0_8
IF(vdiffdw2.LE.0.0) wind2=-1.0_8
limiter=wind*MIN(width*((2.0_8-sigma)*adw/width+(1.0_8+sigma)*auw/celldx(j+1))/6.0_8,auw,adw)
limiter2=wind2*MIN(width*((2.0_8-sigma2)*adw/width+(1.0_8+sigma2)*auw2/celldx(j-1))/6.0_8,auw2,adw)
IF(vdiffuw*vdiffdw.LE.0.0) limiter=0.0
IF(vdiffuw2*vdiffdw2.LE.0.0) limiter2=0.0
IF(node_flux(j,k).LT.0.0)THEN
advec_vel(j,k)=vel1(j+1,k)+(1.0-sigma)*limiter
ELSE
advec_vel(j,k)=vel1(j,k)+(1.0-sigma2)*limiter2
ENDIF
mom_flux(j,k)=advec_vel(j,k)*node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
ELSE
!$OMP DO PRIVATE(upwind,downwind,donor,dif,sigma,width,limiter,vdiffuw,vdiffdw,auw,adw,wind)
DO k=y_min,y_max+1
DO j=x_min-1,x_max+1
IF(node_flux(j,k).LT.0.0_8)THEN
upwind=j+2
donor=j+1
downwind=j
dif=donor
ELSE
upwind=j-1
donor=j
downwind=j+1
dif=upwind
ENDIF
sigma=ABS(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_8
IF(vdiffuw*vdiffdw.GT.0.0_8)THEN
auw=ABS(vdiffuw)
adw=ABS(vdiffdw)
wind=1.0_8
IF(vdiffdw.LE.0.0_8) wind=-1.0_8
limiter=wind*MIN(width*((2.0_8-sigma)*adw/width+(1.0_8+sigma)*auw/celldx(dif))/6.0_8,auw,adw)
ENDIF
advec_vel(j,k)=vel1(donor,k)+(1.0_8-sigma)*limiter
mom_flux(j,k)=advec_vel(j,k)*node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
ENDIF
!$OMP DO
DO k=y_min,y_max+1
DO j=x_min,x_max+1
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)
ENDDO
ENDDO
!$OMP END DO
ELSEIF(direction.EQ.2)THEN
!$OMP DO
DO k=y_min-2,y_max+2
DO j=x_min,x_max+1
! Find staggered mesh mass fluxes and nodal masses and volumes.
node_flux(j,k)=0.25_8*(mass_flux_y(j-1,k )+mass_flux_y(j ,k ) &
+mass_flux_y(j-1,k+1)+mass_flux_y(j ,k+1))
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO k=y_min-1,y_max+2
DO j=x_min,x_max+1
node_mass_post(j,k)=0.25_8*(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 ))
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO k=y_min-1,y_max+2
DO j=x_min,x_max+1
node_mass_pre(j,k)=node_mass_post(j,k)-node_flux(j,k-1)+node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
IF(vector) THEN
!$OMP DO PRIVATE(sigma,width,limiter,vdiffuw,vdiffdw,auw,adw,wind &
!$OMP ,sigma2,limiter2,vdiffuw2,vdiffdw2,auw2,wind2)
DO k=y_min-1,y_max+1
DO j=x_min,x_max+1
sigma=ABS(node_flux(j,k))/(node_mass_pre(j,k+1))
sigma2=ABS(node_flux(j,k))/(node_mass_pre(j,k))
width=celldy(k)
vdiffuw=vel1(j,k+1)-vel1(j,k+2)
vdiffdw=vel1(j,k)-vel1(j,k+1)
vdiffuw2=vel1(j,k)-vel1(j,k-1)
vdiffdw2=-vdiffdw
auw=ABS(vdiffuw)
adw=ABS(vdiffdw)
auw2=ABS(vdiffuw2)
wind=1.0_8
wind2=1.0_8
IF(vdiffdw.LE.0.0) wind=-1.0_8
IF(vdiffdw2.LE.0.0) wind2=-1.0_8
limiter=wind*MIN(width*((2.0_8-sigma)*adw/width+(1.0_8+sigma)*auw/celldy(k+1))/6.0_8,auw,adw)
limiter2=wind2*MIN(width*((2.0_8-sigma2)*adw/width+(1.0_8+sigma2)*auw2/celldy(k-1))/6.0_8,auw2,adw)
IF(vdiffuw*vdiffdw.LE.0.0) limiter=0.0
IF(vdiffuw2*vdiffdw2.LE.0.0) limiter2=0.0
IF(node_flux(j,k).LT.0.0)THEN
advec_vel(j,k)=vel1(j,k+1)+(1.0-sigma)*limiter
ELSE
advec_vel(j,k)=vel1(j,k)+(1.0-sigma2)*limiter2
ENDIF
mom_flux(j,k)=advec_vel(j,k)*node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
ELSE
!$OMP DO PRIVATE(upwind,donor,downwind,dif,sigma,width,limiter,vdiffuw,vdiffdw,auw,adw,wind)
DO k=y_min-1,y_max+1
DO j=x_min,x_max+1
IF(node_flux(j,k).LT.0.0_8)THEN
upwind=k+2
donor=k+1
downwind=k
dif=donor
ELSE
upwind=k-1
donor=k
downwind=k+1
dif=upwind
ENDIF
sigma=ABS(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_8
IF(vdiffuw*vdiffdw.GT.0.0_8)THEN
auw=ABS(vdiffuw)
adw=ABS(vdiffdw)
wind=1.0_8
IF(vdiffdw.LE.0.0_8) wind=-1.0_8
limiter=wind*MIN(width*((2.0_8-sigma)*adw/width+(1.0_8+sigma)*auw/celldy(dif))/6.0_8,auw,adw)
ENDIF
advec_vel(j,k)=vel1(j,donor)+(1.0_8-sigma)*limiter
mom_flux(j,k)=advec_vel(j,k)*node_flux(j,k)
ENDDO
ENDDO
!$OMP END DO
ENDIF
!$OMP DO
DO k=y_min,y_max+1
DO j=x_min,x_max+1
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)
ENDDO
ENDDO
!$OMP END DO
ENDIF
!$OMP END PARALLEL
END SUBROUTINE advec_mom_kernel
END MODULE advec_mom_kernel_mod