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
|
/*@@
@file GRHydro_WENOReconstruct.F90
@date Fri Jan 3 2013
@author Ian Hawke, Christian Reisswig
@desc
Routines to set up the coefficient array and to perform one dimensional
ENO reconstruction of arbitrary order.
@enddesc
@@*/
#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"
/*@@
@routine GRHydro_WENOSetup
@date Fri Jan 3 2013
@author Christian Reisswig
@desc
Sets up the coefficient array for WENO reconstruction.
Uses the notation of Shu, equation (2.21), in
''High Order ENO and WENO Schemes for CFD''
(see ThornGuide for full reference).
One exception: (Shu) r -> (Here) i: avoiding name clash.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
subroutine GRHydro_WENOSetup(CCTK_ARGUMENTS)
USE GRHydro_WENOScalars
implicit none
DECLARE_CCTK_ARGUMENTS
DECLARE_CCTK_PARAMETERS
CCTK_INT :: i, j, k, l, m, q, allocstat
CCTK_REAL :: denominator, numerator, numerator_product
if(.not.coeffs_allocated) then
! Right now we hardcode to 5th order
allocate(weno_coeffs(3, 5), STAT=allocstat)
if (allocstat .ne. 0) call CCTK_WARN(0, "Failed to allocate WENO coefficient arrays!")
allocate(beta_shu(3, 6), STAT=allocstat)
if (allocstat .ne. 0) call CCTK_WARN(0, "Failed to allocate smoothness indicator stencil coefficient arrays!")
coeffs_allocated = .true.
endif
! Set stencils
weno_coeffs(1,1) = 3.0d0/8.0d0
weno_coeffs(1,2) = -5.0d0/4.0d0
weno_coeffs(1,3) = 15.0d0/8.0d0
weno_coeffs(1,4) = 0.0d0
weno_coeffs(1,5) = 0.0d0
weno_coeffs(2,1) = 0.0d0
weno_coeffs(2,2) = -1.0d0/8.0d0
weno_coeffs(2,3) = 3.0d0/4.0d0
weno_coeffs(2,4) = 3.0d0/8.0d0
weno_coeffs(2,5) = 0.0d0
weno_coeffs(3,1) = 0.0d0
weno_coeffs(3,2) = 0.0d0
weno_coeffs(3,3) = 3.0d0/8.0d0
weno_coeffs(3,4) = 3.0d0/4.0d0
weno_coeffs(3,5) = -1.0d0/8.0d0
! Shu smoothness indicator stencil coefficients
beta_shu(1,1) = 4.0d0/3.0d0
beta_shu(1,2) = -19.0d0/3.0d0
beta_shu(1,3) = 25.0d0/3.0d0
beta_shu(1,4) = 11.0d0/3.0d0
beta_shu(1,5) = -31.0d0/3.0d0
beta_shu(1,6) = 10.0d0/3.0d0
beta_shu(2,1) = 4.0d0/3.0d0
beta_shu(2,2) = -13.0d0/3.0d0
beta_shu(2,3) = 13.0d0/3.0d0
beta_shu(2,4) = 5.0d0/3.0d0
beta_shu(2,5) = -13.0d0/3.0d0
beta_shu(2,6) = 4.0d0/3.0d0
beta_shu(3,1) = 10.0d0/3.0d0
beta_shu(3,2) = -31.0d0/3.0d0
beta_shu(3,3) = 25.0d0/3.0d0
beta_shu(3,4) = 11.0d0/3.0d0
beta_shu(3,5) = -19.0d0/3.0d0
beta_shu(3,6) = 4.0d0/3.0d0
end subroutine GRHydro_WENOSetup
/*@@
@routine GRHydro_ENOShutdown
@date Fri Jan 3 2013
@author Christian Reisswig
@desc
Deallocates the coefficient arrays
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
subroutine GRHydro_WENOShutdown(CCTK_ARGUMENTS)
USE GRHydro_WENOScalars
implicit none
DECLARE_CCTK_ARGUMENTS
CCTK_INT :: deallocstat
if(coeffs_allocated) then
deallocate(weno_coeffs, STAT = deallocstat)
if (deallocstat .ne. 0) call CCTK_WARN(0, "Failed to deallocate WENO coefficients.")
deallocate(beta_shu, STAT = deallocstat)
if (deallocstat .ne. 0) call CCTK_WARN(0, "Failed to deallocate shu smoothness indicator coefficients.")
coeffs_allocated = .false.
endif
end subroutine GRHydro_WENOShutdown
/*@@
@routine GRHydro_ENOReconstruct1d
@date Fri Jan 3 2013
@author Christian Reisswig
@desc
Perform a one dimensional reconstruction of a given array using WENO.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
#define SpaceMask_CheckStateBitsF90_1D(mask,i,type_bits,state_bits) \
(iand(mask((i)),(type_bits)).eq.(state_bits))
subroutine GRHydro_WENOReconstruct1d(order, nx, v, vminus, vplus, trivial_rp, &
hydro_excision_mask)
USE GRHydro_WENOScalars
implicit none
DECLARE_CCTK_PARAMETERS
CCTK_INT :: order, nx, i, j, k, r
CCTK_REAL, dimension(nx) :: v, vplus, vminus
CCTK_INT, dimension(nx) :: hydro_excision_mask
logical, dimension(nx) :: trivial_rp
logical, dimension(nx) :: excise
logical :: normal_weno
CCTK_REAL :: large = 1.d10, gamma1, gamma2, gamma3, beta1, beta2, beta3, vnorm, betanorm
CCTK_REAL :: wplus1, wplus2, wplus3, wbarplus1, wbarplus2, wbarplus3
CCTK_REAL :: wminus1, wminus2, wminus3, wbarminus1, wbarminus2, wbarminus3
vminus = 0.d0
vplus = 0.d0
excise = .false.
trivial_rp = .false.
!!$ Initialize excision
do i = 1, nx
if (GRHydro_enable_internal_excision /= 0 .and. (hydro_excision_mask(i) .ne. 0)) then
trivial_rp(i) = .true.
excise(i) = .true.
if (i > 1) then
trivial_rp(i-1) = .true.
end if
end if
end do
do i = 3, nx-2
!!$ Handle excision
normal_weno = .true.
if (i < nx) then
if (excise(i+1)) then
vminus(i) = v(i)
vplus(i) = v(i)
normal_weno = .false.
end if
end if
if (i > 1) then
if (excise(i-1)) then
vminus(i) = v(i)
vplus(i) = v(i)
normal_weno = .false.
end if
end if
if (normal_weno) then
!!$ Compute smoothness indicators
!!$ This is from Tchekhovskoy et al 2007 (WHAM code paper).
beta1 = beta_shu(1,1)*v(i-2)**2 &
+ beta_shu(1,2)*v(i-2)*v(i-1) &
+ beta_shu(1,3)*v(i-1)**2 &
+ beta_shu(1,4)*v(i-2)*v(i) &
+ beta_shu(1,5)*v(i-1)*v(i) &
+ beta_shu(1,6)*v(i)**2
beta2 = beta_shu(2,1)*v(i-1)**2 &
+ beta_shu(2,2)*v(i-1)*v(i) &
+ beta_shu(2,3)*v(i)**2 &
+ beta_shu(2,4)*v(i-1)*v(i+1) &
+ beta_shu(2,5)*v(i)*v(i+1) &
+ beta_shu(2,6)*v(i+1)**2
beta3 = beta_shu(3,1)*v(i)**2 &
+ beta_shu(3,2)*v(i)*v(i+1) &
+ beta_shu(3,3)*v(i+1)**2 &
+ beta_shu(3,4)*v(i)*v(i+2) &
+ beta_shu(3,5)*v(i+1)*v(i+2) &
+ beta_shu(3,6)*v(i+2)**2
vnorm = (v(i-2)**2 + v(i-1)**2 + v(i)**2 + v(i+1)**2 + v(i+2)**2)
beta1 = beta1 + 100.0d0*weno_eps*(vnorm + 1.0d0)
beta2 = beta2 + 100.0d0*weno_eps*(vnorm + 1.0d0)
beta3 = beta3 + 100.0d0*weno_eps*(vnorm + 1.0d0)
betanorm = beta1 + beta2 + beta3
beta1 = beta1 / betanorm
beta2 = beta2 / betanorm
beta3 = beta3 / betanorm
wbarplus1 = 1.0d0/16.0d0 / (weno_eps + beta1)**2
wbarplus2 = 5.0d0/8.0d0 / (weno_eps + beta2)**2
wbarplus3 = 5.0d0/16.0d0 / (weno_eps + beta3)**2
wplus1 = wbarplus1 / (wbarplus1 + wbarplus2 + wbarplus3)
wplus2 = wbarplus2 / (wbarplus1 + wbarplus2 + wbarplus3)
wplus3 = wbarplus3 / (wbarplus1 + wbarplus2 + wbarplus3)
wbarminus1 = 5.0d0/16.0d0 / (weno_eps + beta1)**2
wbarminus2 = 5.0d0/8.0d0 / (weno_eps + beta2)**2
wbarminus3 = 1.0d0/16.0d0 / (weno_eps + beta3)**2
wminus1 = wbarminus1 / (wbarminus1 + wbarminus2 + wbarminus3)
wminus2 = wbarminus2 / (wbarminus1 + wbarminus2 + wbarminus3)
wminus3 = wbarminus3 / (wbarminus1 + wbarminus2 + wbarminus3)
!!$ Calculate the reconstruction
do j = 1, 5
vplus(i) = vplus(i) + wplus1 * weno_coeffs(1,j)*v(i-3+j) &
+ wplus2 * weno_coeffs(2,j)*v(i-3+j) &
+ wplus3 * weno_coeffs(3,j)*v(i-3+j)
vminus(i) = vminus(i) + wminus1 * weno_coeffs(3,6-j)*v(i-3+j) &
+ wminus2 * weno_coeffs(2,6-j)*v(i-3+j) &
+ wminus3 * weno_coeffs(1,6-j)*v(i-3+j)
end do
!vminus(i) = v(i)
!vplus(i) = v(i)
end if
end do
do i = 1, nx
if (excise(i)) then
if (i > 1) then
if (.not. excise(i-1)) then
vminus(i) = vplus(i-1)
end if
end if
vplus(i) = vminus(i)
end if
end do
do i = nx, 1, -1
if (excise(i)) then
if (i < nx) then
if (.not. excise(i+1)) then
vplus(i) = vminus(i+1)
end if
end if
vminus(i) = vplus(i)
end if
end do
end subroutine GRHydro_WENOReconstruct1d
|