-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrad2.f90
459 lines (379 loc) · 11.7 KB
/
grad2.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
!=============================================================================!
subroutine grad2 (ndof, nx, ny, v, g1v, g11v, g12v, g22v, dx, dy, &
optx, opty, xper, yper, lsym, rsym, bsym, tsym)
!
! Take the second derivative of a 2-D field.
! Updated to sixth-order accurate differencing on the interior with
! the option for optimized fourth-order differencing.
!
! Added g1v as input to improve efficiency
!
! Revised: 6-28-95
!
!=============================================================================!
use stencils
implicit none
integer :: ndof, nx, ny, optx, opty
logical :: xper, yper
logical :: lsym, rsym, bsym, tsym
real :: v(ny,nx,ndof), g1v(ny,nx,ndof)
real :: g11v(ny,nx,ndof), g12v(ny,nx,ndof), g22v(ny,nx,ndof)
real :: dx, dy
real, parameter :: one = 1.0, pt5 = 0.5, two = 2.0
real :: dxinv, dyinv, dxsinv, dysinv
real :: a, b, c, w
real :: gx1, gx2, gx3, gx4, gx5, gx6
real :: gy1, gy2, gy3, gy4, gy5, gy6
real :: dx1, dx2, dx3, dx4, dx5, dx6, dx7
real :: dy1, dy2, dy3, dy4, dy5, dy6, dy7
integer :: idof, isign
!=============================================================================!
dxinv = one / dx
dyinv = one / dy
dxsinv = one / dx**2
dysinv = one / dy**2
!.... seven point stencil in x
if (optx.eq.0) then
c = 1.0 / 60.0
else if (optx.eq.-1) then
c = 0.0
else
w = 2.0 * 3.1415926535897932385e+0 / 12.0
c = (w/2.0 - 2.0*Sin(w)/3.0 + Sin(2.0*w)/12.0) / &
(5.0*Sin(w) - 4.0*Sin(2.0*w) + Sin(3.0*w))
end if
a = (2.0 + 15.0 * c) / 3.0
b = -(1.0 + 48.0 * c) / 12.0
gx1 = -c * dxinv
gx2 = -b * dxinv
gx3 = -a * dxinv
gx4 = a * dxinv
gx5 = b * dxinv
gx6 = c * dxinv
if (optx.eq.0) then
c = 1.0 / 90.0
else if (optx.eq.-1) then
c = 0.0
else
w = 2.0 * 3.1415926535897932385e+0 / 12.0
c = -(3.0*w**2 - 16.0*Sin(w/2.0)**2 + Sin(w)**2) / &
(12.0*(-15.0*Sin(w/2.0)**2 + 6.0*Sin(w)**2 - &
Sin(3.0*w/2.0)**2))
end if
a = (4.0 + 45.0 * c) / 3.0
b = -(1.0 + 72.0 * c) / 12.0
dx1 = c * dxsinv
dx2 = b * dxsinv
dx3 = a * dxsinv
dx4 = -2.0 * ( a + b + c ) * dxsinv
dx5 = a * dxsinv
dx6 = b * dxsinv
dx7 = c * dxsinv
!.... seven point stencil in y
if (opty.eq.0) then
c = 1.0 / 60.0
else if (opty.eq.-1) then
c = 0.0
else
w = 2.0 * 3.1415926535897932385e+0 / 12.0
c = (w/2.0 - 2.0*Sin(w)/3.0 + Sin(2.0*w)/12.0) / &
(5.0*Sin(w) - 4.0*Sin(2.0*w) + Sin(3.0*w))
end if
a = (2.0 + 15.0 * c) / 3.0
b = -(1.0 + 48.0 * c) / 12.0
gy1 = -c * dyinv
gy2 = -b * dyinv
gy3 = -a * dyinv
gy4 = a * dyinv
gy5 = b * dyinv
gy6 = c * dyinv
if (opty.eq.0) then
c = 1.0 / 90.0
else if (opty.eq.-1) then
c = 0.0
else
w = 2.0 * 3.1415926535897932385e+0 / 12.0
c = -(3.0*w**2 - 16.0*Sin(w/2.0)**2 + Sin(w)**2) / &
(12.0*(-15.0*Sin(w/2.0)**2 + 6.0*Sin(w)**2 - &
Sin(3.0*w/2.0)**2))
end if
a = (4.0 + 45.0 * c) / 3.0
b = -(1.0 + 72.0 * c) / 12.0
dy1 = c * dysinv
dy2 = b * dysinv
dy3 = a * dysinv
dy4 = -2.0 * ( a + b + c ) * dysinv
dy5 = a * dysinv
dy6 = b * dysinv
dy7 = c * dysinv
!=============================================================================!
!.... compute the second derivative in x
!=============================================================================!
if (xper) then
g11v(:,1,:) = ( dx1 * v(:,nx-3,:) + &
dx2 * v(:,nx-2,:) + &
dx3 * v(:,nx-1,:) + &
dx4 * v(:,1,:) + &
dx5 * v(:,2,:) + &
dx6 * v(:,3,:) + &
dx7 * v(:,4,:) )
g11v(:,2,:) = ( dx1 * v(:,nx-2,:) + &
dx2 * v(:,nx-1,:) + &
dx3 * v(:,1,:) + &
dx4 * v(:,2,:) + &
dx5 * v(:,3,:) + &
dx6 * v(:,4,:) + &
dx7 * v(:,5,:) )
g11v(:,3,:) = ( dx1 * v(:,nx-1,:) + &
dx2 * v(:,1,:) + &
dx3 * v(:,2,:) + &
dx4 * v(:,3,:) + &
dx5 * v(:,4,:) + &
dx6 * v(:,5,:) + &
dx7 * v(:,6,:) )
g11v(:,nx-2,:) = ( dx1 * v(:,nx-5,:) + &
dx2 * v(:,nx-4,:) + &
dx3 * v(:,nx-3,:) + &
dx4 * v(:,nx-2,:) + &
dx5 * v(:,nx-1,:) + &
dx6 * v(:,1,:) + &
dx7 * v(:,2,:) )
g11v(:,nx-1,:) = ( dx1 * v(:,nx-4,:) + &
dx2 * v(:,nx-3,:) + &
dx3 * v(:,nx-2,:) + &
dx4 * v(:,nx-1,:) + &
dx5 * v(:,1,:) + &
dx6 * v(:,2,:) + &
dx7 * v(:,3,:) )
g11v(:,nx,:) = g11v(:,1,:)
else
g11v(:,1,:) = ( dd1 * v(:,1,:) + &
dd2 * v(:,2,:) + &
dd3 * v(:,3,:) + &
dd4 * v(:,4,:) + &
dd5 * v(:,5,:) ) * dxsinv
g11v(:,2,:) = ( db1 * v(:,1,:) + &
db2 * v(:,2,:) + &
db3 * v(:,3,:) + &
db4 * v(:,4,:) + &
db5 * v(:,5,:) ) * dxsinv
g11v(:,3,:) = ( da1 * v(:,1,:) + &
da2 * v(:,2,:) + &
da3 * v(:,3,:) + &
da4 * v(:,4,:) + &
da5 * v(:,5,:) ) * dxsinv
g11v(:,nx-2,:) = ( da1 * v(:,nx-4,:) + &
da2 * v(:,nx-3,:) + &
da3 * v(:,nx-2,:) + &
da4 * v(:,nx-1,:) + &
da5 * v(:,nx,:) ) * dxsinv
g11v(:,nx-1,:) = ( db1 * v(:,nx,:) + &
db2 * v(:,nx-1,:) + &
db3 * v(:,nx-2,:) + &
db4 * v(:,nx-3,:) + &
db5 * v(:,nx-4,:) ) * dxsinv
g11v(:,nx,:) = ( dd1 * v(:,nx,:) + &
dd2 * v(:,nx-1,:) + &
dd3 * v(:,nx-2,:) + &
dd4 * v(:,nx-3,:) + &
dd5 * v(:,nx-4,:) ) * dxsinv
end if
!.... implement symmetry conditions
if (lsym) then
do idof = 1, ndof
if (idof .eq. 3) then
isign = -one
else
isign = one
end if
g11v(:,1,idof) = ( isign * dx1 * v(:,4,idof) + &
isign * dx2 * v(:,3,idof) + &
isign * dx3 * v(:,2,idof) + &
dx4 * v(:,1,idof) + &
dx5 * v(:,2,idof) + &
dx6 * v(:,3,idof) + &
dx7 * v(:,4,idof) )
g11v(:,2,idof) = ( isign * dx1 * v(:,3,idof) + &
isign * dx2 * v(:,2,idof) + &
dx3 * v(:,1,idof) + &
dx4 * v(:,2,idof) + &
dx5 * v(:,3,idof) + &
dx6 * v(:,4,idof) + &
dx7 * v(:,5,idof) )
g11v(:,3,idof) = ( isign * dx1 * v(:,2,idof) + &
dx2 * v(:,1,idof) + &
dx3 * v(:,2,idof) + &
dx4 * v(:,3,idof) + &
dx5 * v(:,4,idof) + &
dx6 * v(:,5,idof) + &
dx7 * v(:,6,idof) )
end do
end if
!.... interior
g11v(:,4:nx-3,:) = ( dx1 * v(:,1:nx-6,:) + &
dx2 * v(:,2:nx-5,:) + &
dx3 * v(:,3:nx-4,:) + &
dx4 * v(:,4:nx-3,:) + &
dx5 * v(:,5:nx-2,:) + &
dx6 * v(:,6:nx-1,:) + &
dx7 * v(:,7:nx ,:) )
!=============================================================================!
!.... compute the second derivative in y
!=============================================================================!
if (yper) then
g22v(1,:,:) = ( dy1 * v(ny-3,:,:) + &
dy2 * v(ny-2,:,:) + &
dy3 * v(ny-1,:,:) + &
dy4 * v(1,:,:) + &
dy5 * v(2,:,:) + &
dy6 * v(3,:,:) + &
dy7 * v(4,:,:) )
g22v(2,:,:) = ( dy1 * v(ny-2,:,:) + &
dy2 * v(ny-1,:,:) + &
dy3 * v(1,:,:) + &
dy4 * v(2,:,:) + &
dy5 * v(3,:,:) + &
dy6 * v(4,:,:) + &
dy7 * v(5,:,:) )
g22v(3,:,:) = ( dy1 * v(ny-1,:,:) + &
dy2 * v(1,:,:) + &
dy3 * v(2,:,:) + &
dy4 * v(3,:,:) + &
dy5 * v(4,:,:) + &
dy6 * v(5,:,:) + &
dy7 * v(6,:,:) )
g22v(ny-2,:,:) = ( dy1 * v(ny-5,:,:) + &
dy2 * v(ny-4,:,:) + &
dy3 * v(ny-3,:,:) + &
dy4 * v(ny-2,:,:) + &
dy5 * v(ny-1,:,:) + &
dy6 * v(1,:,:) + &
dy7 * v(2,:,:) )
g22v(ny-1,:,:) = ( dy1 * v(ny-4,:,:) + &
dy2 * v(ny-3,:,:) + &
dy3 * v(ny-2,:,:) + &
dy4 * v(ny-1,:,:) + &
dy5 * v(1,:,:) + &
dy6 * v(2,:,:) + &
dy7 * v(3,:,:) )
g22v(ny,:,:) = g22v(1,:,:)
else
g22v(1,:,:) = ( dd1 * v(1,:,:) + &
dd2 * v(2,:,:) + &
dd3 * v(3,:,:) + &
dd4 * v(4,:,:) + &
dd5 * v(5,:,:) ) * dysinv
!.... adiabatic wall
! g22v(1,:,ndof) = ( dc1 * v(1,:,ndof) + &
! dc2 * v(2,:,ndof) + &
! dc3 * v(3,:,ndof) + &
! dc4 * v(4,:,ndof) + &
! dc5 * v(5,:,ndof) ) * dysinv
g22v(2,:,:) = ( db1 * v(1,:,:) + &
db2 * v(2,:,:) + &
db3 * v(3,:,:) + &
db4 * v(4,:,:) + &
db5 * v(5,:,:) ) * dysinv
g22v(3,:,:) = ( da1 * v(1,:,:) + &
da2 * v(2,:,:) + &
da3 * v(3,:,:) + &
da4 * v(4,:,:) + &
da5 * v(5,:,:) ) * dysinv
g22v(ny-2,:,:) = ( da1 * v(ny-4,:,:) + &
da2 * v(ny-3,:,:) + &
da3 * v(ny-2,:,:) + &
da4 * v(ny-1,:,:) + &
da5 * v(ny,:,:) ) * dysinv
g22v(ny-1,:,:) = ( db1 * v(ny,:,:) + &
db2 * v(ny-1,:,:) + &
db3 * v(ny-2,:,:) + &
db4 * v(ny-3,:,:) + &
db5 * v(ny-4,:,:) ) * dysinv
g22v(ny,:,:) = ( dd1 * v(ny,:,:) + &
dd2 * v(ny-1,:,:) + &
dd3 * v(ny-2,:,:) + &
dd4 * v(ny-3,:,:) + &
dd5 * v(ny-4,:,:) ) * dysinv
endif
!.... interior
g22v(4:ny-3,:,:) = ( dy1 * v(1:ny-6,:,:) + &
dy2 * v(2:ny-5,:,:) + &
dy3 * v(3:ny-4,:,:) + &
dy4 * v(4:ny-3,:,:) + &
dy5 * v(5:ny-2,:,:) + &
dy6 * v(6:ny-1,:,:) + &
dy7 * v(7:ny ,:,:) )
!=============================================================================!
!.... compute the cross derivative
!=============================================================================!
if (yper) then
g12v(1,:,:) = ( gy1 * g1v(ny-3,:,:) + &
gy2 * g1v(ny-2,:,:) + &
gy3 * g1v(ny-1,:,:) + &
gy4 * g1v(2,:,:) + &
gy5 * g1v(3,:,:) + &
gy6 * g1v(4,:,:) )
g12v(2,:,:) = ( gy1 * g1v(ny-2,:,:) + &
gy2 * g1v(ny-1,:,:) + &
gy3 * g1v(1,:,:) + &
gy4 * g1v(3,:,:) + &
gy5 * g1v(4,:,:) + &
gy6 * g1v(5,:,:) )
g12v(3,:,:) = ( gy1 * g1v(ny-1,:,:) + &
gy2 * g1v(1,:,:) + &
gy3 * g1v(2,:,:) + &
gy4 * g1v(4,:,:) + &
gy5 * g1v(5,:,:) + &
gy6 * g1v(6,:,:) )
g12v(ny-2,:,:) = ( gy1 * g1v(ny-5,:,:) + &
gy2 * g1v(ny-4,:,:) + &
gy3 * g1v(ny-3,:,:) + &
gy4 * g1v(ny-1,:,:) + &
gy5 * g1v(1,:,:) + &
gy6 * g1v(2,:,:) )
g12v(ny-1,:,:) = ( gy1 * g1v(ny-4,:,:) + &
gy2 * g1v(ny-3,:,:) + &
gy3 * g1v(ny-2,:,:) + &
gy4 * g1v(1,:,:) + &
gy5 * g1v(2,:,:) + &
gy6 * g1v(3,:,:) )
g12v(ny,:,:) = g12v(1,:,:)
else
g12v(1,:,:) = ( gc1 * g1v(1,:,:) + &
gc2 * g1v(2,:,:) + &
gc3 * g1v(3,:,:) + &
gc4 * g1v(4,:,:) + &
gc5 * g1v(5,:,:) ) * dyinv
g12v(2,:,:) = ( gb1 * g1v(1,:,:) + &
gb2 * g1v(2,:,:) + &
gb3 * g1v(3,:,:) + &
gb4 * g1v(4,:,:) + &
gb5 * g1v(5,:,:) ) * dyinv
g12v(3,:,:) = ( ga1 * g1v(1,:,:) + &
ga2 * g1v(2,:,:) + &
ga3 * g1v(4,:,:) + &
ga4 * g1v(5,:,:) ) * dyinv
g12v(ny-2,:,:) = ( ga1 * g1v(ny-4,:,:) + &
ga2 * g1v(ny-3,:,:) + &
ga3 * g1v(ny-1,:,:) + &
ga4 * g1v(ny ,:,:) ) * dyinv
g12v(ny-1,:,:) = -( gb1 * g1v(ny ,:,:) + &
gb2 * g1v(ny-1,:,:) + &
gb3 * g1v(ny-2,:,:) + &
gb4 * g1v(ny-3,:,:) + &
gb5 * g1v(ny-4,:,:) ) * dyinv
g12v(ny,:,:) = -( gc1 * g1v(ny ,:,:) + &
gc2 * g1v(ny-1,:,:) + &
gc3 * g1v(ny-2,:,:) + &
gc4 * g1v(ny-3,:,:) + &
gc5 * g1v(ny-4,:,:) ) * dyinv
end if
!.... interior
g12v(4:ny-3,:,:) = ( gy1 * g1v(1:ny-6,:,:) + &
gy2 * g1v(2:ny-5,:,:) + &
gy3 * g1v(3:ny-4,:,:) + &
gy4 * g1v(5:ny-2,:,:) + &
gy5 * g1v(6:ny-1,:,:) + &
gy6 * g1v(7:ny ,:,:) )
return
end