forked from UK-MAC/CloverLeaf_OpenACC_3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_dt_kernel.f90
207 lines (168 loc) · 8.64 KB
/
calc_dt_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
!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 timestep kernel
!> @author Wayne Gaudin
!> @details Calculates the minimum timestep on the mesh chunk based on the CFL
!> condition, the velocity gradient and the velocity divergence. A safety
!> factor is used to ensure numerical stability.
MODULE calc_dt_kernel_module
CONTAINS
SUBROUTINE calc_dt_kernel(x_min,x_max,y_min,y_max,z_min,z_max, &
g_small,g_big,dtmin, &
dtc_safe, &
dtu_safe, &
dtv_safe, &
dtw_safe, &
dtdiv_safe, &
xarea, &
yarea, &
zarea, &
cellx, &
celly, &
cellz, &
celldx, &
celldy, &
celldz, &
volume, &
density0, &
energy0, &
pressure, &
viscosity_a, &
soundspeed, &
xvel0,yvel0,zvel0, &
dt_min, &
dt_min_val, &
dtl_control, &
xl_pos, &
yl_pos, &
zl_pos, &
jldt, &
kldt, &
lldt, &
small)
IMPLICIT NONE
INTEGER :: x_min,x_max,y_min,y_max,z_min,z_max
REAL(KIND=8) :: g_small,g_big,dtmin,dt_min_val
REAL(KIND=8) :: dtc_safe,dtu_safe,dtv_safe,dtw_safe,dtdiv_safe
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+2,z_min-2:z_max+2) :: xarea
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+3,z_min-2:z_max+2) :: yarea
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+3) :: zarea
REAL(KIND=8), DIMENSION(x_min-2:x_max+2) :: cellx
REAL(KIND=8), DIMENSION(y_min-2:y_max+2) :: celly
REAL(KIND=8), DIMENSION(z_min-2:z_max+2) :: cellz
REAL(KIND=8), DIMENSION(x_min-2:x_max+2) :: celldx
REAL(KIND=8), DIMENSION(y_min-2:y_max+2) :: celldy
REAL(KIND=8), DIMENSION(z_min-2:z_max+2) :: celldz
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: volume
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: density0
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: energy0
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: pressure
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: viscosity_a
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: soundspeed
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3,z_min-2:z_max+3) :: xvel0,yvel0,zvel0
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3,z_min-2:z_max+3) :: dt_min
INTEGER :: dtl_control
REAL(KIND=8) :: xl_pos,yl_pos,zl_pos
INTEGER :: jldt,kldt,lldt
INTEGER :: small
INTEGER :: j,k,l
REAL(KIND=8) :: div,dsx,dsy,dsz,dtut,dtvt,dtwt,dtct,dtdivt,cc,dv1,dv2,jkl_control
small=0
!$ACC DATA &
!$ACC PCOPY(celldx,celldy,celldz,cellx,celly,cellz,density0,soundspeed,viscosity_a,volume) &
!$ACC PCOPY(xarea,xvel0,yarea,yvel0,zarea,zvel0,dt_min) &
!$ACC COPYIN(g_small)
dt_min_val = g_big
jkl_control=1.1
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min,z_max
!$ACC LOOP INDEPENDENT
DO k=y_min,y_max
!$ACC LOOP INDEPENDENT PRIVATE(dsx,dsy,dsz,cc,dv1,dv2,div,dtct,dtut,dtvt,dtwt,dtdivt)
DO j=x_min,x_max
dsx=celldx(j)
dsy=celldy(k)
dsz=celldz(l)
cc=soundspeed(j,k,l)*soundspeed(j,k,l)
cc=cc+2.0_8*viscosity_a(j,k,l)/density0(j,k,l)
cc=MAX(SQRT(cc),g_small)
dtct=dtc_safe*MIN(dsx,dsy,dsz)/cc
div=0.0
dv1=(xvel0(j ,k ,l )+xvel0(j ,k+1,l )+xvel0(j ,k ,l+1)+xvel0(j ,k+1,l+1))*xarea(j ,k ,l )
dv2=(xvel0(j+1,k ,l )+xvel0(j+1,k+1,l )+xvel0(j+1,k ,l+1)+xvel0(j+1,k+1,l+1))*xarea(j+1,k ,l )
div=div+dv2-dv1
dtut=dtu_safe*2.0_8*volume(j,k,l )/MAX(ABS(dv1),ABS(dv2),g_small*volume(j,k,l))
dv1=(yvel0(j ,k ,l )+yvel0(j+1,k ,l )+yvel0(j ,k ,l+1)+yvel0(j+1,k ,l+1))*yarea(j ,k ,l )
dv2=(yvel0(j ,k+1,l )+yvel0(j+1,k+1,l )+yvel0(j ,k+1,l+1)+yvel0(j+1,k+1,l+1))*yarea(j ,k+1,l )
div=div+dv2-dv1
dtvt=dtv_safe*2.0_8*volume(j,k,l)/MAX(ABS(dv1),ABS(dv2),g_small*volume(j,k,l))
dv1=(zvel0(j ,k ,l )+zvel0(j+1,k ,l )+zvel0(j ,k+1,l )+zvel0(j+1,k+1,l ))*zarea(j ,k ,l )
dv2=(zvel0(j ,k ,l+1)+zvel0(j+1,k ,l+1)+zvel0(j ,k+1,l+1)+zvel0(j+1,k+1,l+1))*zarea(j ,k ,l+1)
div=div+dv2-dv1
dtwt=dtw_safe*2.0_8*volume(j,k,l)/MAX(ABS(dv1),ABS(dv2),g_small*volume(j,k,l))
div=div/(2.0_8*volume(j,k,l))
IF(div.LT.-g_small)THEN
dtdivt=dtdiv_safe*(-1.0_8/div)
ELSE
dtdivt=g_big
ENDIF
dt_min(j,k,l)=MIN(dtct,dtut,dtvt,dtwt,dtdivt)
ENDDO
ENDDO
ENDDO
!!$ACC LOOP INDEPENDENT REDUCTION(min:dt_min_val) GANG(128)
DO l=z_min,z_max
!$ACC LOOP INDEPENDENT REDUCTION(min:dt_min_val)
DO k=y_min,y_max
!$ACC LOOP INDEPENDENT REDUCTION(min:dt_min_val)
DO j=x_min,x_max
IF(dt_min(j,k,l).LT.dt_min_val) dt_min_val=dt_min(j,k,l)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
!$ACC END DATA
! Extract the mimimum timestep information
dtl_control=10.01*(jkl_control-INT(jkl_control))
jkl_control=jkl_control-(jkl_control-INT(jkl_control))
jldt=MOD(INT(jkl_control),x_max)
kldt=1+(jkl_control/x_max)
lldt=1+(jkl_control/x_max)
xl_pos=cellx(jldt)
yl_pos=celly(kldt)
zl_pos=cellz(lldt)
IF(dt_min_val.LT.dtmin) small=1
IF(small.NE.0)THEN
WRITE(0,*) 'Timestep information:'
WRITE(0,*) 'j, k : ',jldt,kldt
WRITE(0,*) 'x, y : ',cellx(jldt),celly(kldt)
WRITE(0,*) 'timestep : ',dt_min_val
WRITE(0,*) 'Cell velocities;'
WRITE(0,*) xvel0(jldt ,kldt ,lldt ),yvel0(jldt ,kldt ,lldt ),zvel0(jldt ,kldt ,lldt )
WRITE(0,*) xvel0(jldt+1,kldt ,lldt ),yvel0(jldt+1,kldt ,lldt ),zvel0(jldt ,kldt ,lldt )
WRITE(0,*) xvel0(jldt+1,kldt+1,lldt ),yvel0(jldt+1,kldt+1,lldt ),zvel0(jldt ,kldt ,lldt )
WRITE(0,*) xvel0(jldt ,kldt+1,lldt ),yvel0(jldt ,kldt+1,lldt ),zvel0(jldt ,kldt ,lldt )
WRITE(0,*) xvel0(jldt ,kldt ,lldt+1),yvel0(jldt ,kldt ,lldt+1),zvel0(jldt ,kldt ,lldt+1)
WRITE(0,*) xvel0(jldt+1,kldt ,lldt+1),yvel0(jldt+1,kldt ,lldt+1),zvel0(jldt ,kldt ,lldt+1)
WRITE(0,*) xvel0(jldt+1,kldt+1,lldt+1),yvel0(jldt+1,kldt+1,lldt+1),zvel0(jldt ,kldt ,lldt+1)
WRITE(0,*) xvel0(jldt ,kldt+1,lldt+1),yvel0(jldt ,kldt+1,lldt+1),zvel0(jldt ,kldt ,lldt+1)
WRITE(0,*) 'density, energy, pressure, soundspeed '
WRITE(0,*) density0(jldt,kldt,lldt),energy0(jldt,kldt,lldt),pressure(jldt,kldt,lldt),soundspeed(jldt,kldt,lldt)
ENDIF
END SUBROUTINE calc_dt_kernel
END MODULE calc_dt_kernel_module