-
Notifications
You must be signed in to change notification settings - Fork 1
/
cheb.f90
549 lines (397 loc) · 11.3 KB
/
cheb.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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
MODULE cheb
USE prms
IMPLICIT none
real, allocatable, dimension(:,:,:) :: Gr,Gt
real, allocatable, dimension(:,:,:) :: Dccr,Dddr,Dcdr
real, allocatable, dimension(:,:,:) :: Dcct,Dddt,Dcdt
real, allocatable, dimension(:,:) :: Tccr,Tddr,Tcdr,Thddr,Thccr,Thdcr
real, allocatable, dimension(:,:) :: Tcct,Tddt,Tcdt,Thddt,Thcct,Thdct
real, allocatable, dimension(:,:) :: Tfdr,Tfdt
real, allocatable, dimension(:,:,:) :: Hdr
real, allocatable, dimension(:) :: Xcr,Xdr,Xct,Xdt,Xfr,Xft
real, allocatable, dimension(:) :: Rc,Tc,Rd,Td,Rf,Tf,Rdd,Tdd
real,allocatable,dimension(:,:) :: XXdr,XX2dr,XXdt,XX2dt,XX3dr,XX3dt,XX4dr,XX4dt
integer, parameter :: NDmax = 6
CONTAINS
SUBROUTINE initcheb
call getcol
call makeTs
call makeDs
call makeGs
call makeHs
call makeRmat
END SUBROUTINE initcheb
SUBROUTINE makeRmat
integer :: i,j
allocate(XXdr(0:Ndr,0:Ndr))
allocate(XX2dr(0:Ndr,0:Ndr))
allocate(XXdt(0:Ndr,0:Ndr))
allocate(XX2dt(0:Ndr,0:Ndr))
allocate(XX3dr(0:Ndr,0:Ndr))
allocate(XX3dt(0:Ndr,0:Ndr))
allocate(XX4dr(0:Ndr,0:Ndr))
allocate(XX4dt(0:Ndr,0:Ndr))
Do i = 0,Ndr
Do j = 0,Ndr
If (i == j) then
XXdr(i,j) = Rdd(i)
XXdt(i,j) = Tdd(i)
else
XXdr(i,j) = 0
XXdt(i,j) = 0
End If
End Do
End Do
XX2dr(:,:) = Matmul(XXdr(:,:),XXdr(:,:))
XX2dt(:,:) = Matmul(XXdt(:,:),XXdt(:,:))
XX3dr(:,:) = Matmul(XX2dr(:,:),XXdr(:,:))
XX3dt(:,:) = Matmul(XX2dt(:,:),XXdt(:,:))
XX4dr(:,:) = Matmul(XX2dr(:,:),XX2dr(:,:))
XX4dt(:,:) = Matmul(XX2dt(:,:),XX2dt(:,:))
END SUBROUTINE makeRmat
SUBROUTINE getcol
integer :: i,j
allocate(Xcr(0:Ncr),Xct(0:Nct))
allocate(Xdr(0:Ndr),Xdt(0:Ndt))
allocate(Xfr(0:Nfr),Xft(0:Nft))
allocate(Rc(0:Ncr),Tc(0:Nct))
allocate(Rd(0:Ndr),Td(0:Ndt))
allocate(Rf(0:Nfr),Tf(0:Nft))
allocate(Rdd(0:Ndr),Tdd(0:Ndr))
call makeX(Ncr,Xcr)
call makeX(Nct,Xct)
call makeX(Ndr,Xdr)
call makeX(Ndt,Xdt)
call makeX(Nfr,Xfr)
call makeX(Nft,Xft)
Rc = 0.5*Rmax*(Xcr+1.)
Tc = 0.5*Tmax*(Xct+1.)+Rmax
Rd = 0.5*Rmax*(Xdr+1.)
Td = 0.5*Tmax*(Xdt+1.)+Rmax
Rf = 0.5*Rmax*(Xfr+1.)
Tf = 0.5*Tmax*(Xft+1.)+Rmax
!inverse order
Do i=0,Ndr
Rdd(i) = Rd(Ndr-i)
Tdd(i) = Td(Ndr-i)
End Do
END SUBROUTINE getcol
SUBROUTINE makeX(N,X)
integer :: N
real, dimension(0:N) :: X
integer :: i
do i = 0,N
X(i) = COS(REAL(i)*Pi/N)
end do
END SUBROUTINE makeX
SUBROUTINE makeTs
allocate(Tccr(0:Ncr,0:Ncr))
allocate(Tddr(0:Ndr,0:Ndr))
allocate(Tcdr(0:Ncr,0:Ndr))
allocate(Tcct(0:Nct,0:Nct))
allocate(Tddt(0:Ndt,0:Ndt))
allocate(Tcdt(0:Nct,0:Ndt))
allocate(Thccr(0:Ncr,0:Ncr))
allocate(Thddr(0:Ndr,0:Ndr))
allocate(Thdcr(0:Ndr,0:Ncr))
allocate(Thcct(0:Nct,0:Nct))
allocate(Thddt(0:Ndt,0:Ndt))
allocate(Thdct(0:Ndt,0:Nct))
allocate(Tfdr(0:Nfr,0:Ndr))
allocate(Tfdt(0:Nft,0:Ndt))
call makeT(Ncr,Ncr,Tccr)
call makeT(Ndr,Ndr,Tddr)
call makeT(Ncr,Ndr,Tcdr)
call makeTh(Ncr,Ncr,Thccr)
call makeTh(Ndr,Ndr,Thddr)
call makeTh(Ndr,Ncr,Thdcr)
call makeT(Nct,Nct,Tcct)
call makeT(Ndt,Ndt,Tddt)
call makeT(Nct,Ndt,Tcdt)
call makeTh(Nct,Nct,Thcct)
call makeTh(Ndt,Ndt,Thddt)
call makeTh(Ndt,Nct,Thdct)
call makeT(Nft,Ndt,Tfdt)
call makeT(Nfr,Ndr,Tfdr)
END SUBROUTINE makeTs
SUBROUTINE makeGs
integer :: m
!deallocate(Gr)
allocate(Gr(0:Ndr,0:Ndr,0:NDmax))
allocate(Gt(0:Ndt,0:Ndt,0:NDmax))
call makeG(Ndr,Gr(0,0,1))
call makeG(Ndt,Gt(0,0,1))
call identity(Ndr,Gr(0,0,0))
call identity(Ndt,Gt(0,0,0))
Gr(:,:,1) = Gr(:,:,1)*(2./Rmax)
Gt(:,:,1) = Gt(:,:,1)*(2./Tmax)
do m = 2,NDmax
Gr(:,:,m) = MATMUL(Gr(:,:,1),Gr(:,:,m-1))
Gt(:,:,m) = MATMUL(Gt(:,:,1),Gt(:,:,m-1))
end do
END SUBROUTINE makeGs
SUBROUTINE makeGG(p,q,r,GG)
integer :: p,q,r
real, dimension(0:Ndr,0:Ndt,0:Ndr,0:Ndt) :: GG
real, dimension(0:Ndr,0:Ndt,0:Ndr,0:Ndt) :: GGr,GGt
integer :: i,j
do j = 0,Ndt
GGr(:,j,:,j) = MATMUL(Hdr(:,:,r),Gr(:,:,p))
end do
do i = 0,Ndr
GGt(i,:,i,:) = Gt(:,:,q)
end do
call MATMUL2(GGr,GGt,GG)
END SUBROUTINE makeGG
SUBROUTINE MATMUL2(A,B,C)
real, dimension(0:Ndr,0:Ndt,0:Ndr,0:Ndt) :: A,B,C
integer :: i,j,ii,jj
C = 0.
do jj = 0,Ndt
do ii = 0,Ndr
do j = 0,Nct
do i = 0,Ncr
C(i,j,ii,jj) = SUM(A(i,j,:,:)*B(:,:,ii,jj))
end do
end do
end do
end do
END SUBROUTINE MATMUL2
SUBROUTINE makeDs
integer :: m
allocate(Dccr(0:Ncr,0:Ncr,0:NDmax))
allocate(Dddr(0:Ndr,0:Ndr,0:NDmax))
allocate(Dcdr(0:Ncr,0:Ndr,0:NDmax))
allocate(Dcct(0:Nct,0:Nct,0:NDmax))
allocate(Dddt(0:Ndt,0:Ndt,0:NDmax))
allocate(Dcdt(0:Nct,0:Ndt,0:NDmax))
call makeD(Ncr,Ncr,Dccr)
call makeD(Ndr,Ndr,Dddr)
call makeD(Ncr,Ndr,Dcdr)
do m = 1,NDmax
Dccr(:,:,m) = Dccr(:,:,m)*(2./Rmax)**m
Dddr(:,:,m) = Dddr(:,:,m)*(2./Rmax)**m
Dcdr(:,:,m) = Dcdr(:,:,m)*(2./Rmax)**m
end do
call makeD(Nct,Nct,Dcct)
call makeD(Ndt,Ndt,Dddt)
call makeD(Nct,Ndt,Dcdt)
do m = 1,NDmax
Dcct(:,:,m) = Dcct(:,:,m)*(2./Tmax)**m
Dddt(:,:,m) = Dddt(:,:,m)*(2./Tmax)**m
Dcdt(:,:,m) = Dcdt(:,:,m)*(2./Tmax)**m
end do
END SUBROUTINE makeDs
SUBROUTINE makeD(Nc,Nd,D)
integer :: Nc,Nd
real, dimension(0:Nc,0:Nd,0:NDmax) :: D
real, dimension(0:Nc,0:Nd) :: Tcd
real, dimension(0:Nd,0:Nd) :: Thdd, Gdd, Gdd1
!!$ real, dimension(Nd+1) :: Work
!!$ integer, dimension(0:Nd) :: ipiv
!!$ integer :: info
real :: dum
integer :: m,ibc
call makeT(Nc,Nd,Tcd)
call makeTh(Nd,Nd,Thdd)
call makeG(Nd,Gdd)
D(:,:,0) = MATMUL(Tcd,Thdd)
Gdd1 = Gdd
do m = 1,NDmax
D(:,:,m) = MATMUL(Tcd,MATMUL(Gdd,Thdd))
Gdd = MATMUL(Gdd,Gdd1)
end do
END SUBROUTINE makeD
SUBROUTINE makeTpDerVec(NN,p,x,bv)
integer :: NN
integer :: p ! derivative order
real :: x ! x = +/- 1
real, dimension(0:NN) :: bv ! coef of a_n
integer :: n
do n = 0,NN
call makeTpDer(NN,p,n,x,bv(n))
end do
END SUBROUTINE makeTpDerVec
SUBROUTINE makeTpDer(NN,p,n,x,b)
integer :: NN
integer :: p ! derivative order
integer :: n ! as in T_n
real :: x ! x = +/- 1
real :: b ! coef of a_n
integer :: k
b = (x)**(n+p)
do k = 0,p-1
b = b * (n**2 - k**2)/(2.*k+1)
end do
END SUBROUTINE makeTpDer
SUBROUTINE identity(Np,A)
integer :: Np
real, dimension(0:Np,0:Np) :: A
integer :: j
A = 0.
do j = 0,Np
A(j,j) = 1.
end do
END SUBROUTINE identity
SUBROUTINE makeG(Np,G)
integer :: Np
real, dimension(0:Np,0:Np) :: G
integer :: p,n
do p = 0,Np
do n = 0,Np
if (p.ge.n.or.is_even(p+n)) then
G(p,n) = 0.
else
G(p,n) = 2.*REAL(n)/c(Np,p)
end if
end do
end do
END SUBROUTINE makeG
SUBROUTINE makeHs
allocate(Hdr(0:Ndr,0:Ndr,0:4))
call identity(Ndr,Hdr(0,0,0))
call makeH(Ndr,Hdr(0,0,1))
Hdr(:,:,2) = MATMUL(Hdr(:,:,1),Hdr(:,:,1))
Hdr(:,:,3) = MATMUL(Hdr(:,:,1),Hdr(:,:,2))
Hdr(:,:,4) = MATMUL(Hdr(:,:,2),Hdr(:,:,2))
END SUBROUTINE makeHs
SUBROUTINE makeH(Np,H)
integer :: Np
real, dimension(0:Np,0:Np) :: H
integer :: p,n
H = 0.
do p = 0,Np
do n = 0,Np
if (ABS(p-n).eq.1) then
H(p,n) = 0.5
else if (p.eq.n) then
H(p,n) = 1.0
end if
end do
end do
H(1,0) = 1.
H = H*(Rmax/2.)
END SUBROUTINE makeH
SUBROUTINE makeHinv(Np,H)
integer :: Np
real, dimension(0:Np,0:Np) :: H
integer :: p,n
do p = 0,Np
do n = 0,Np
if (is_even(p+n)) then
H(p,n) = 0.
else if (n.lt.p .and. is_even(p+1)) then
H(p,n) = 2*(-1)**((p-n-1)/2)
else if (n.gt.p .and. is_even(p)) then
H(p,n) = 2*(-1)**((p-n)/2)/c(Np,p)
end if
end do
end do
END SUBROUTINE makeHinv
SUBROUTINE fromcheb2(MM,NN,u,a)
integer :: MM,NN
real, dimension(0:MM,0:NN) :: u,a
real, dimension(0:MM,0:NN) :: ua
real, dimension(0:NN,0:MM) :: uat,ut
integer :: i,j,m,n
do j = 0,NN
call fromcheb1(MM,ua(0,j),a(0,j))
end do
uat = TRANSPOSE(ua)
do i = 0,MM
call fromcheb1(NN,ut(0,i),uat(0,i))
end do
u = TRANSPOSE(ut)
END SUBROUTINE fromcheb2
SUBROUTINE tocheb2(MM,NN,u,a)
integer :: MM,NN
real, dimension(0:MM,0:NN) :: u,a
real, dimension(0:MM,0:NN) :: ua
real, dimension(0:NN,0:MM) :: uat,at
integer :: i,j,m,n
do j = 0,NN
call tocheb1(MM,u(0,j),ua(0,j))
end do
uat = TRANSPOSE(ua)
do i = 0,MM
call tocheb1(NN,uat(0,i),at(0,i))
end do
a = TRANSPOSE(at)
END SUBROUTINE tocheb2
SUBROUTINE tocheb1(NN,u,a)
integer :: NN
real, dimension(0:NN) :: u,a
real, dimension(0:NN) :: X
integer :: i,n
call makeX(NN,X)
a = 0.
do i = 0,NN
do n = 0,NN
a(n) = a(n) + 2./REAL(NN)/c(NN,n)/c(NN,i)*u(i)*chebT(n,X(i))
end do
end do
END SUBROUTINE tocheb1
SUBROUTINE fromcheb1(NN,u,a)
integer :: NN
real, dimension(0:NN) :: u,a
real, dimension(0:NN) :: X
integer :: i,n
call makeX(NN,X)
u = 0.
do i = 0,NN
do n = 0,NN
u(i) = u(i) + a(n)*chebT(n,X(i))
end do
end do
END SUBROUTINE fromcheb1
SUBROUTINE makeT(Nc,Nd,T)
integer :: Nc,Nd
real, dimension(0:Nc,0:Nd) :: T
real, dimension(0:Nc) :: X
integer :: n,j
call makeX(Nc,X)
do n = 0,Nd
do j = 0,Nc
T(j,n) = chebT(n,X(j))
end do
end do
END SUBROUTINE makeT
SUBROUTINE makeTh(Nc,Nd,Th)
integer :: Nc,Nd
real, dimension(0:Nc,0:Nd) :: Th
real, dimension(0:Nd) :: X
integer :: n,j
call makeX(Nd,X)
do n = 0,Nc
do j = 0,Nd
Th(n,j) = chebT(n,X(j))/c(Nc,n)/c(Nd,j)
end do
end do
Th = 2.*Th/REAL(Nd)
END SUBROUTINE makeTh
FUNCTION c(Np,j) RESULT (cval)
integer :: Np,j
real :: cval
if (j.eq.0 .or. j.eq.Np) then
cval = 2.
else
cval = 1.
end if
END FUNCTION c
FUNCTION chebT(n,xx) RESULT (T)
integer :: n
real :: xx
real :: T
! T = COS(Pi*REAL(n*j)/REAL(Nc))
T = COS(REAL(n)*ACOS(xx))
END FUNCTION chebT
FUNCTION is_even (i) RESULT (y)
integer :: i
logical :: y
if (NINT(REAL(i)/2.0) .eq. i/2) then
y = .TRUE.
else
y = .FALSE.
end if
END FUNCTION is_even
END MODULE cheb