-
Notifications
You must be signed in to change notification settings - Fork 0
/
deltac.f
2413 lines (2317 loc) · 92 KB
/
deltac.f
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c-----------------------------------------------------------------------
c file deltac.f.
c Galerkin method for the inner layer model in configuration space.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c code organization.
c-----------------------------------------------------------------------
c 0. delmatch_mod.
c 1. deltac_run.
c 2. deltac_init_asymp.
c 3. deltac_get_ua.
c 4. deltac_get_dua.
c 5. deltac_solve.
c 6. deltac_alloc.
c 7. deltac_dealloc.
c 8. deltac_make_grid.
c 9. deltac_pack.
c 10. deltac_hermite.
c 11. deltac_make_map_hermite.
c 12. deltac_make_arrays.
c 13. deltac_gauss_quad.
c 14. deltac_get_uv.
c 15. deltac_assemble_mat.
c 16. deltac_assemble_rhs.
c 17. deltac_set_boundary.
c 18. deltac_extension.
c 19. deltac_lsode_int.
c 20. deltac_lsode_der.
c 21. deltac_get_d2ua.
c 22. deltac_ua_diagnose.
c 23. deltac_get_solution.
c 24. deltac_output_solution.
c 25. deltac_read_parameters.
c 26. deltac_estimate_zi.
c-----------------------------------------------------------------------
c subprogram 0. delmatch_mod.
c module declarations.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
MODULE deltac_mod
USE gamma_mod
USE jacobi_mod
USE deltar_mod, ONLY : resist_type
IMPLICIT NONE
TYPE :: inner_type
INTEGER :: ising
REAL(r8) :: e,f,g,h,k,m,taua,taur,v1
REAL(r8) :: di,dr,p1,sfac
COMPLEX(r8) :: eig,q,x0
COMPLEX(r8),DIMENSION(2) :: deltar
END TYPE inner_type
TYPE :: asymp_type
REAL(r8), DIMENSION(2) :: p
COMPLEX(r8), DIMENSION(2):: s
COMPLEX(r8), DIMENSION(:,:,:), ALLOCATABLE :: v
END TYPE asymp_type
TYPE :: hermite_type
REAL(r8), DIMENSION(0:3) :: pb,qb
END TYPE hermite_type
TYPE :: cell_type
CHARACTER(6) :: etype
INTEGER :: np
INTEGER, DIMENSION(:), ALLOCATABLE :: emap
INTEGER, DIMENSION(:,:), ALLOCATABLE :: map
REAL(r8) :: x_lsode
REAL(r8), DIMENSION(2) :: x
COMPLEX(r8), DIMENSION(:,:), ALLOCATABLE :: rhs
COMPLEX(r8), DIMENSION(:,:,:,:), ALLOCATABLE :: mat
END TYPE cell_type
TYPE :: interval_type
REAL(r8), DIMENSION(:), ALLOCATABLE :: x,dx
TYPE(cell_type), DIMENSION(:), POINTER :: cell
END TYPE interval_type
TYPE :: solution_type
REAL(r8),DIMENSION(:), ALLOCATABLE :: xvar
COMPLEX(r8), DIMENSION(:,:,:),ALLOCATABLE :: sol
END TYPE solution_type
TYPE :: gal_type
INTEGER :: nx,nq,ndim,kl,ku,ldab,msol
INTEGER, DIMENSION(:), ALLOCATABLE :: ipiv
REAL(r8) :: pfac,dx1,dx2
COMPLEX(r8), DIMENSION(:,:), ALLOCATABLE :: rhs,sol
COMPLEX(r8), DIMENSION(:,:,:), ALLOCATABLE :: mat
TYPE(interval_type), POINTER :: intvl
TYPE(jacobi_type) :: quad
TYPE(hermite_type) :: hermite
END TYPE gal_type
LOGICAL, PRIVATE :: diagnose_res=.FALSE., method=.true.
lOGICAL :: deltac_bin_sol=.false.,deltac_out_sol=.false.
LOGICAL :: dx1dx2_flag=.false.,rescale=.true.
LOGICAL :: restore_uh=.false.,output_sol=.false.
LOGICAL :: restore_us=.false.,restore_ul=.false.
LOGICAL :: noexp=.false.
LOGICAL :: diagnose_params=.FALSE.
CHARACTER(10) :: gal_method="normal",side="right"
CHARACTER(256) :: deltabin_filename,galsol_filename
CHARACTER(256) :: galsol_filename_cut
INTEGER :: interp_np=10,xmax_method
INTEGER :: basis_type=0
INTEGER, PRIVATE :: np=3,mpert=3,msol=2
INTEGER :: order_pow=10,order_exp=3
INTEGER :: nx=128,nq=4,fulldomain=0
INTEGER :: cutoff=5,outt=3,nx_ua=100
INTEGER, DIMENSION(4), PRIVATE:: tid=(/3,5,6,4/)
INTEGER :: nstep=50000
REAL(r8) :: dx1=1e-2,dx2=1e-2
REAL(r8) :: xmin=0,deltac_tol=1e-5,pfac=1
REAL(r8) :: xmax=1,xfac=1
REAL(r8) :: x0_ua=0.01,x1_ua=1
REAL(r8) :: zi_deltac
COMPLEX(r8) :: q_deltac
TYPE(inner_type) :: in
TYPE(asymp_type) :: asp
TYPE(cell_type), POINTER :: cell
TYPE(solution_type), POINTER :: sol
CONTAINS
c-----------------------------------------------------------------------
c subprogram 1. deltac_run.
c sets up and solve inner layer.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_run(restype,eig,delta,fulldelta)
TYPE(resist_type), INTENT(IN) :: restype
COMPLEX(r8), INTENT(IN) :: eig
COMPLEX(r8), DIMENSION(2), INTENT(OUT) :: delta
COMPLEX(r8), DIMENSION(2,2), INTENT(OUT) :: fulldelta
LOGICAL, PARAMETER :: diagnose=.FALSE.
CHARACTER(80) :: message
REAL(r8) :: x0, q0,tmp1,tmp2,tmp3,tmp4,dr
COMPLEX(r8) :: tmp
c-----------------------------------------------------------------------
c format statements.
c-----------------------------------------------------------------------
10 FORMAT(6x,"E",10x,"F",10x,"H",10x,"G",10x,"K",10x,"M"//1p,6e11.3/)
20 FORMAT(6x,"DI",9x,"DR",9x,"p1",8x,"taua",7x,"taur",7x,"sfac"//
$ 1p,6e11.3/)
30 FORMAT(6x,"X0",9x,"Q0",9X,"V1"//1p,3e11.3)
40 FORMAT(7x,"DR",13x,"E",13x,"F",13x,"G",13x,"H",13x,"K"
$ //1p,6e14.6/)
50 FORMAT(8x,"M",11x,"taua",10x,"taur",11x,"v1",
$ 10x,"re eig",8x,"im eig"//1p,6e14.6/)
c-----------------------------------------------------------------------
c diagnose input.
c-----------------------------------------------------------------------
IF(diagnose)THEN
OPEN(UNIT=debug_unit,FILE="deltac.out",STATUS="REPLACE")
dr=restype%e+restype%f+restype%h**2
WRITE(debug_unit,40)dr,restype%e,restype%f,restype%g,restype%h,
$ restype%k
WRITE(debug_unit,50)restype%m,restype%taua,restype%taur,
$ restype%v1,eig
CLOSE(UNIT=debug_unit)
CALL program_stop("deltac_run: abort after diagnose input.")
ENDIF
c-----------------------------------------------------------------------
c set the domain to be solved
c-----------------------------------------------------------------------
SELECT CASE (fulldomain)
CASE(0)
xmin=0
CASE(1,2)
xmin=-xmax
END SELECT
c-----------------------------------------------------------------------
c copy input values.
c-----------------------------------------------------------------------
in%e=restype%e
in%f=restype%f
in%g=restype%g
in%h=restype%h
in%k=restype%k
in%m=restype%m
in%taua=restype%taua
in%taur=restype%taur
in%v1=restype%v1
in%ising=restype%ising
in%eig=eig
in%dr=in%e+in%f+in%h*in%h
in%di=in%e+in%f+in%h-0.25
in%p1=SQRT(-in%di)
c-----------------------------------------------------------------------
c define scale factors.
c-----------------------------------------------------------------------
in%sfac=in%taur/in%taua
x0=in%sfac**(-1._r8/3._r8)
q0=x0/in%taua
in%q=in%eig/q0
in%x0=x0
c-----------------------------------------------------------------------
c write output file with inner region parameters.
c-----------------------------------------------------------------------
IF(diagnose_params)THEN
OPEN(UNIT=debug_unit,FILE="params.out",STATUS="REPLACE")
WRITE(debug_unit,'(2a/)')
$ " deltabin_filename = ",TRIM(deltabin_filename)
WRITE(debug_unit,10)in%e,in%f,in%h,in%g,in%k,in%m
WRITE(debug_unit,20)in%di,in%dr,in%p1,in%taua,in%taur,in%sfac
WRITE(debug_unit,30)x0,q0,in%v1
CLOSE(UNIT=debug_unit)
endif
c-----------------------------------------------------------------------
c setup asymptotic solutions at large x.
c-----------------------------------------------------------------------
CALL deltac_init_asymp
SELECT CASE(xmax_method)
CASE(1)
tmp1=SQRT(ABS(in%q)**.5*(ABS(asp%s(1))+1))*xfac
tmp2=SQRT(ABS(in%q)**.5*(ABS(asp%s(2))+1))*xfac
IF (tmp2 > tmp1) tmp1=tmp2
xmax=tmp2
print *,"Xi1_large",asp%v(2,3,1)
print *,"Xi2_large",asp%v(2,3,2)
print *,"Upsilon1_large",asp%v(3,3,1)
print *,"Upsilon2_large",asp%v(3,3,2)
print *,"Xi2_small",asp%v(2,4,2)
print *,"Xi2_exp_small",asp%v(2,5,2)
print *,"Xi2_exp_large",asp%v(2,6,2)
print *,"E = ", in%e
print *,"Q = ", in%q
Case(2)
tmp1=MAXVAL(ABS(asp%v(:,5,1)))
tmp2=MAXVAL(ABS(asp%v(:,5,2)))
tmp3=tmp1/tmp2
tmp1=MAXVAL(ABS(asp%v(:,6,1)))
tmp2=MAXVAL(ABS(asp%v(:,6,2)))
tmp4=tmp1/tmp2
IF (tmp4 > tmp3) tmp3=tmp4
xmax=tmp3*xfac
CASE(3)
xmax=ABS(in%q)**.25*xfac
CASE(4)
xmax=xfac*ABS(in%q)**.25
$ *MAXVAL(1+SQRT(ABS(asp%s(:))))
CASE DEFAULT
WRITE(message,'(a,i2)')
$ "deltac_run: invalid value xmax_method = ",xmax_method
CALL program_stop(message)
END SELECT
c-----------------------------------------------------------------------
c set the domain to be solved
c-----------------------------------------------------------------------
SELECT CASE (fulldomain)
CASE(0)
xmin=0
CASE(1,2)
xmin=-xmax
CASE DEFAULT
WRITE(message,'(a,i2)')
$ "deltac_run: invalide value fulldomain = ",fulldomain
END SELECT
IF(diagnose_res)CALL deltac_ua_diagnose
c-----------------------------------------------------------------------
c estimate zi.
c-----------------------------------------------------------------------
CALL deltac_estimate_zi(zi_deltac)
q_deltac=in%q
c-----------------------------------------------------------------------
c run galerkin method to solve the inner layer.
c-----------------------------------------------------------------------
CALL deltac_solve(delta,fulldelta)
delta=delta*in%sfac**(2.0*in%p1/3.0)*in%v1**(2.0*in%p1)
fulldelta=fulldelta*in%sfac**(2.0*in%p1/3.0)*in%v1**(2.0*in%p1)
tmp=delta(1)
delta(1)=delta(2)
delta(2)=tmp
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_run
c-----------------------------------------------------------------------
c subprogram 2. deltac_init_asymp.
c initialize the asymptotic solutions at large x.
c coefficients of two power series and two small exponential
c solutions are solved.
c GJT Appendix A.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_init_asymp
INTEGER :: i,j,l,t,order
INTEGER :: info
INTEGER, DIMENSION(3) :: ipiv
REAL(r8) :: e,f,k,g,h
COMPLEX(r8),DIMENSION(2) :: p,s
COMPLEX(r8) :: sq,tmp,q
COMPLEX(r8), DIMENSION(4) :: term
COMPLEX(r8), DIMENSION(3) :: matb
COMPLEX(r8), DIMENSION(3,3) :: mata,mat
c-----------------------------------------------------------------------
c initialize the parameters (f,h,k,g,h,q) and the coefficients v
c-----------------------------------------------------------------------
order=order_pow
IF (order < order_exp) order=order_exp
ALLOCATE(asp%v(3,6,order+1))
e=in%e
f=in%f
k=in%k
g=in%g
h=in%h
q=in%q
asp%v=0.0
c-----------------------------------------------------------------------
c p power of large and small solutions (T_3,4).
c-----------------------------------------------------------------------
p(1)=-0.5+in%p1
p(2)=-0.5-in%p1
asp%p=p
c-----------------------------------------------------------------------
c solve large and small power-like solutions.
c-----------------------------------------------------------------------
DO i=1,2
t=2+i
c-----------------------------------------------------------------------
c zeroth order term.
c-----------------------------------------------------------------------
j=0
l=j+1
asp%v(:,t,l)=1
c-----------------------------------------------------------------------
c solve high order term.
c-----------------------------------------------------------------------
mata(1,1)=q
mata(1,2)=-q
mata(1,3)=0.0
mata(2,2)=0.0
mata(3,1)=1
mata(3,2)=0.0
mata(3,3)=-1
DO j=1,order_pow
l=j+1
mata(2,1)=(p(i)-2*j+h)*(p(i)-2*j+1)
mata(2,3)=-(h*(p(i)-2*j)-e-f)
matb(1)=(p(i)-2*j+2)*(p(i)-2*j+3)*asp%v(1,t,l-1)
$ -h*(p(i)-2*j+2)*asp%v(3,t,l-1)
matb(2)=-q*q*(p(i)-2*j+2)*(p(i)-2*j+1)*asp%v(2,t,l-1)
matb(3)=h*k*q*q*(p(i)-2*j+3)*asp%v(1,t,l-1)
$ -(g-e*k)*q*q*asp%v(2,t,l-1)
$ +(g+f*k)*q*q*asp%v(3,t,l-1)
IF (j > 1) matb(3)=matb(3)
$ -q*(p(i)-2*j+4)*(p(i)-2*j+3)*asp%v(3,t,l-2)
mat=mata
asp%v(:,t,l)=matb
CALL zgesv(3,1,mat,3,ipiv,asp%v(:,t,l),3,info)
ENDDO
ENDDO
c-----------------------------------------------------------------------
c s power of T_5,6, exponential power series.
c-----------------------------------------------------------------------
sq=sqrt(q)
term(1)=-sq*q*(1+g+k*(f+h*h))*0.25
term(2)=(g+k*f-1)**2.0
tmp=k*h*h
term(3)=tmp*(tmp+(g+k*f+1)*2.0)
term(4)=((g-k*e-1.0)*in%dr+h*h)*4.0
tmp=sqrt(q**3.0*(term(2)+term(3))+term(4))*0.25
s(1)=term(1)+tmp-0.5
s(2)=term(1)-tmp-0.5
asp%s=s
c-----------------------------------------------------------------------
c solve coefficients of small exponential solutions T5 and T6.
c-----------------------------------------------------------------------
DO i=1,2
mata(1,1)=1.0/q
mata(1,2)=q
mata(1,3)=h/sq
mata(2,1)=q-h/sq
mata(2,2)=-q*sq*(2*s(i)+1)
mata(2,3)=e+f
mata(3,1)=q*sq*k*h+1
mata(3,2)=q*q*(g-k*e)
mata(3,3)=-q*q*(g+k*f)-sq*(2.0*s(i)+1.0)
c-----------------------------------------------------------------------
c solve zeroth order term.
c-----------------------------------------------------------------------
t=4+i
j=0
l=j+1
asp%v(1,t,l)=1
matb(1)=-1.0/q
matb(2)=-(q-h/sq)
asp%v(2:3,t,l)=matb(1:2)
mat=mata
CALL zgesv(2,1,mat(1:2,2:3),2,ipiv(1:2),
$ asp%v(2:3,t,l),2,info)
c-----------------------------------------------------------------------
c solve high order.
c-----------------------------------------------------------------------
DO j=1,order_exp
l=j+1
mata(2,2)=-q*sq*(2*s(i)-4*j+1)
mata(3,3)=-q*q*(g+k*f)-sq*(2.0*s(i)-4*j+1.0)
matb(1)=((2.0*s(i)-4.0*j+3)/sq+q)*asp%v(1,t,l-1)
matb(1)=matb(1)+h*(s(i)-2*j+2)*asp%v(3,t,l-1)
IF (j > 1) matb(1)=-(s(i)+3-2*j)*(s(i)+2-2*j)
$ *asp%v(1,t,l-2)
matb(2)=-h*(s(i)+1.0-2.0*j)*asp%v(1,t,l-1)
matb(2)=matb(2)-q*q*(s(i)-2*j+2)*(s(i)-2*j+1)
$ *asp%v(2,t,l-1)
matb(3)=q*q*k*h*(s(i)+1.0-2.0*j)
$ *asp%v(1,t,l-1)
$ -q*(s(i)-2*j+2)*(s(i)-2*j+1)
$ *asp%v(3,t,l-1)
mat=mata
asp%v(:,t,l)=matb
CALL zgesv(3,1,mat,3,ipiv,asp%v(:,t,l),3,info)
ENDDO
ENDDO
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_init_asymp
c-----------------------------------------------------------------------
c subprogram 3. deltac_get_ua.
c get the value of the asymptotic solutions at large x.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_get_ua(xin,ua)
REAL(r8),INTENT(IN) :: xin
COMPLEX(r8),DIMENSION(3,6),INTENT(OUT) :: ua
INTEGER :: i,j,t,l
REAL(r8) :: x,x2
COMPLEX(r8) :: xp,xs,xj
c-----------------------------------------------------------------------
c change sign of x.
c-----------------------------------------------------------------------
IF (xin<0) THEN
x=-xin
ELSE
x=xin
ENDIF
c-----------------------------------------------------------------------
c computations.
c-----------------------------------------------------------------------
ua=0.0
x2=x*x
DO i=1,2
xp=x**asp%p(i)
IF (rescale) THEN
xs=EXP((-x2+xmax*xmax)/(SQRT(in%q)*2.0) )
$ *((x/xmax)**asp%s(i))
ELSE
xs=EXP(-x2/(SQRT(in%q)*2.0) )*(x**asp%s(i))
ENDIF
DO j=0, order_pow
l=j+1
xj=x**(-2.0*j)
t=2+i
ua(:,t)=ua(:,t)+asp%v(:,t,l)*xj
ENDDO
DO j=0, order_exp
l=j+1
xj=x**(-2.0*j)
t=4+i
ua(:,t)=ua(:,t)+asp%v(:,t,l)*xj
ENDDO
t=2+i
ua(:,t)=xp*ua(:,t)
ua(1,t)=x*ua(1,t)
t=4+i
ua(:,t)=xs*ua(:,t)
ua(1,t)=ua(1,t)/x
ENDDO
c-----------------------------------------------------------------------
c extend to negtive x with even parity.
c-----------------------------------------------------------------------
IF (xin<0 .AND. fulldomain .EQ. 1) THEN
ua(1,:)=-ua(1,:)
c ua(2,:)=-ua(2,:)
c ua(3,:)=-ua(3,:)
ENDIF
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_get_ua
c-----------------------------------------------------------------------
c subprogram 4. deltac_get_dua.
c get the derivative value of the asymptotic solutions at large x.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_get_dua(xin,dua)
REAL(r8),INTENT(IN) :: xin
REAL(r8) :: x
COMPLEX(r8),DIMENSION(3,6),INTENT(OUT) :: dua
INTEGER i,j,t,l
REAL(r8),DIMENSION(2) :: p
REAL(r8) :: x2
COMPLEX(r8) :: xp,xs,xj,q
COMPLEX(r8),DIMENSION(2) :: s
c-----------------------------------------------------------------------
c change sign of x.
c-----------------------------------------------------------------------
IF (xin<0) THEN
x=-xin
ELSE
x=xin
ENDIF
c-----------------------------------------------------------------------
c computations.
c-----------------------------------------------------------------------
q=in%q
dua=0.0
p=asp%p
s=asp%s
x2=x*x
DO i=1,2
xp=x**p(i)
IF (rescale) THEN
xs=EXP((-x2+xmax*xmax)/(SQRT(in%q)*2.0) )
$ *((x/xmax)**asp%s(i))
ELSE
xs=EXP(-x2/(SQRT(in%q)*2.0) )*(x**asp%s(i))
ENDIF
DO j=0, order_pow
l=j+1
t=2+i
xj=x**(-1.0-2.0*j)
dua(1,t)=dua(1,t)+asp%v(1,t,l)*(p(i)+1-2*j)*xj
dua(2:3,t)=dua(2:3,t)+asp%v(2:3,t,l)*(p(i)-2*j)*xj
ENDDO
DO j=0, order_exp
l=j+1
t=4+i
xj=x**(-2.0*j)
dua(1,t)=dua(1,t)
$ +asp%v(1,t,l)*((s(i)-1-2*j)/x2-1.0/SQRT(q))*xj
dua(2:3,t)=dua(2:3,t)
$ +asp%v(2:3,t,l)*((s(i)-2*j)/x-1.0/SQRT(q)*x)*xj
ENDDO
t=2+i
dua(:,t)=xp*dua(:,t)
dua(1,t)=x*dua(1,t)
t=4+i
dua(:,t)=xs*dua(:,t)
ENDDO
c-----------------------------------------------------------------------
c extend to negtive x with even parity.
c-----------------------------------------------------------------------
IF (xin<0 .AND. fulldomain .EQ. 1) THEN
c dua(1,:)=-dua(1,:)
dua(2,:)=-dua(2,:)
dua(3,:)=-dua(3,:)
ENDIF
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_get_dua
c-----------------------------------------------------------------------
c subprogram 5. deltac_solve.
c solves the inner layer model with galerkin method.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_solve(delta,fulldelta)
COMPLEX(r8), DIMENSION(2), INTENT(OUT) :: delta
COMPLEX(r8), DIMENSION(2,2), INTENT(OUT) :: fulldelta
INTEGER :: info,isol,imap,ix
TYPE(gal_type) :: gal
10 FORMAT("D11=",1p,2e11.3,"D12=",1p,2e11.3,
$ "D21=",1p,2e11.3,"D22=",1p,2e11.3/)
c-----------------------------------------------------------------------
c allocate and compute arrays.
c-----------------------------------------------------------------------
IF (basis_type == 0) np=3
IF (np <= 3)np=3
msol=2
CALL deltac_alloc(gal,nx,nq,dx1,dx2,pfac)
CALL deltac_make_arrays(gal)
c-----------------------------------------------------------------------
c solve the galerkin matrix.
c-----------672------------------------------------------------------------
DO isol=1,msol
gal%sol(:,isol)=gal%rhs(:,isol)
CALL zgbtrf(gal%ndim,gal%ndim,gal%kl,gal%ku,gal%mat(:,:,isol),
$ gal%ldab,gal%ipiv,info)
CALL zgbtrs("N",gal%ndim,gal%kl,gal%ku,1,gal%mat(:,:,isol),
$ gal%ldab,gal%ipiv,gal%sol(:,isol),gal%ndim,info)
ENDDO
c-----------------------------------------------------------------------
c compute and write delta.
c-----------------------------------------------------------------------
SELECT CASE (gal_method)
CASE ("normal")
SELECT CASE (fulldomain)
CASE (0)
DO isol=1,gal%msol
imap=gal%intvl%cell(nx)%map(1,4)
delta(isol)=gal%sol(imap,isol)
ENDDO
c WRITE(*,*)"delta1=",delta(1),"delta2=",delta(2)
c CALL program_stop("delta+- stop")
CASE (1,2)
DO isol=1,gal%msol
imap=gal%intvl%cell(-nx)%map(1,-1)
fulldelta(isol,1)=gal%sol(imap,isol)
imap=gal%intvl%cell(nx)%map(1,4)
fulldelta(isol,2)=gal%sol(imap,isol)
ENDDO
c WRITE (*,10) fulldelta(1,1),fulldelta(1,2),
c $ fulldelta(2,1),fulldelta(2,2)
c CALL program_stop
c $ ("Finish full domain comptation with normal method.")
END SELECT
CASE ("resonant")
DO isol=1,gal%msol
DO ix=1,gal%nx
cell => gal%intvl%cell(ix)
IF(cell%etype == "res")THEN
imap=cell%emap(1)
delta(isol)=gal%sol(imap,isol)
ENDIF
ENDDO
ENDDO
END SELECT
c IF(output_sol)CALL deltac_output_solution(gal)
c-----------------------------------------------------------------------
c deallocate arrays and finish.
c-----------------------------------------------------------------------
CALL deltac_dealloc(gal)
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_solve
c-----------------------------------------------------------------------
c subprogram 6. deltac_alloc.
c allocates arrays.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_alloc(gal,nx,nq,dx1,dx2,pfac)
TYPE(gal_type), INTENT(OUT) :: gal
INTEGER, INTENT(IN) :: nx,nq
REAL(r8), INTENT(IN) :: dx1,dx2,pfac
INTEGER :: ix,ixmin
TYPE(interval_type), POINTER :: intvl
TYPE(cell_type), POINTER :: cell
c-----------------------------------------------------------------------
c set integers.
c-----------------------------------------------------------------------
SELECT CASE (fulldomain)
CASE(0)
gal%nx=nx
CASE(1,2)
gal%nx=nx
END SELECT
gal%nq=nq
gal%dx1=dx1
gal%dx2=dx2
c-----------------------------------------------------------------------
c allocate arrays.
c-----------------------------------------------------------------------
ALLOCATE(gal%intvl)
CALL jacobi_alloc(gal%quad,nq,.TRUE.,.FALSE.,"gll")
intvl => gal%intvl
SELECT CASE (fulldomain)
CASE(0)
ALLOCATE(intvl%x(0:nx),intvl%dx(0:nx),intvl%cell(nx))
ixmin=1
CASE(1,2)
ALLOCATE(intvl%x(-nx:nx),intvl%dx(-nx:nx),intvl%cell(-nx:nx))
ixmin=-nx
CASE DEFAULT
WRITE(*,'(a,i2)')
$ "deltac_run: invalide value fulldomain = ",fulldomain
STOP
END SELECT
CALL deltac_make_grid(nx,dx1,dx2,pfac,intvl)
c-----------------------------------------------------------------------
c allocate map and local matrix for each element.
c-----------------------------------------------------------------------
DO ix=ixmin,nx
IF (ix == 0) CYCLE
cell => intvl%cell(ix)
IF (basis_type == 0) THEN
SELECT CASE(cell%etype)
c-----------------------------------------------------------------------
c allocate normal element.
c-----------------------------------------------------------------------
CASE ("none")
ALLOCATE(cell%map(mpert,0:np))
ALLOCATE(cell%mat(mpert,mpert,0:np,0:np))
cell%np=np
cell%x_lsode=0.0
c-----------------------------------------------------------------------
c allocate resonant element.
c-----------------------------------------------------------------------
CASE ("res")
IF (method) THEN
c-----------------------------------------------------------------------
c no hermite basis in resonant element.
c-----------------------------------------------------------------------
ALLOCATE(cell%map(3,0:0),cell%emap(3))
ALLOCATE(cell%mat(3,3,0:0,0:0))
ALLOCATE(cell%rhs(3,0:0))
cell%np=-1
ELSE
c-----------------------------------------------------------------------
c include hermite basis in resonant element.
c-----------------------------------------------------------------------
ALLOCATE(cell%map(mpert,0:2),cell%emap(3))
ALLOCATE(cell%mat(mpert,mpert,0:2,0:2))
ALLOCATE(cell%rhs(mpert,0:2))
cell%np=1
ENDIF
cell%rhs=0.0
cell%emap=0.0
cell%x_lsode=cell%x(2)
IF (ix<0) cell%x_lsode=cell%x(1)
c-----------------------------------------------------------------------
c allocate extension element connect to resonant element.
c-----------------------------------------------------------------------
CASE ("ext")
IF (basis_type == 0) THEN
IF (method) THEN
c-----------------------------------------------------------------------
c no hermite basis in resonant element.
c-----------------------------------------------------------------------
ALLOCATE(cell%map(mpert,0:2),cell%emap(3))
ALLOCATE(cell%mat(mpert,mpert,0:2,0:2))
ALLOCATE(cell%rhs(mpert,0:2))
cell%np=1
ELSE
c-----------------------------------------------------------------------
c include hermite basis in resonant element.
c-----------------------------------------------------------------------
ALLOCATE(cell%map(mpert,0:np+1),cell%emap(3))
ALLOCATE(cell%mat(mpert,mpert,0:np+1,0:np+1))
ALLOCATE(cell%rhs(mpert,0:np+1))
cell%np=np
ENDIF
ELSE
ALLOCATE(cell%map(mpert,0:np),cell%emap(3))
ALLOCATE(cell%mat(mpert,mpert,0:np,0:np))
ALLOCATE(cell%rhs(mpert,0:np))
cell%np=np-1
ENDIF
cell%emap=0.0
cell%rhs=0.0
cell%x_lsode=0.0
c-----------------------------------------------------------------------
c allocate extension element only has driving term.
c-----------------------------------------------------------------------
CASE ("ext1","ext2")
SELECT CASE (gal_method)
CASE("resonant")
ALLOCATE(cell%map(mpert,0:np))
ALLOCATE(cell%mat(mpert,mpert,0:np,0:np))
ALLOCATE(cell%rhs(mpert,0:np))
CASE("normal")
IF (ix == nx) THEN
ALLOCATE(cell%map(mpert,0:np+1))
ALLOCATE(cell%mat(mpert,mpert,0:np+1,0:np+1))
ALLOCATE(cell%rhs(mpert,0:np+1))
ELSEIF (ix==-nx) THEN
ALLOCATE(cell%map(mpert,-1:np))
ALLOCATE(cell%mat(mpert,mpert,-1:np,-1:np))
ALLOCATE(cell%rhs(mpert,-1:np))
ELSE
ALLOCATE(cell%map(mpert,0:np))
ALLOCATE(cell%mat(mpert,mpert,0:np,0:np))
ALLOCATE(cell%rhs(mpert,0:np))
ENDIF
END SELECT
cell%np=np
cell%rhs=0.0
cell%x_lsode=0.0
END SELECT
ELSE
ENDIF
cell%map=0.0
cell%mat=0.0
ENDDO
c IF(diagnose_grid)CALL deltac_diagnose_grid(gal)
c-----------------------------------------------------------------------
c create and diagnose local-to-global mapping.
c-----------------------------------------------------------------------
IF (basis_type==0) THEN
CALL deltac_make_map_hermite(gal)
ELSE
ENDIF
c-----------------------------------------------------------------------
c allocate global arrays for LU solver.
c note: kl considers both hermite and spectrum element's cases
c-----------------------------------------------------------------------
SELECT CASE (gal_method)
CASE ("normal")
gal%kl=mpert*(np+2)-1
CASE ("resonant")
IF (noexp) THEN
gal%kl=mpert*(np+1)+1-1
ELSE
gal%kl=mpert*(np+2)-1
ENDIF
END SELECT
gal%ku=gal%kl
gal%ldab=2*gal%kl+gal%ku+1
gal%msol=msol
ALLOCATE(gal%rhs(gal%ndim,gal%msol),gal%sol(gal%ndim,gal%msol))
ALLOCATE(gal%mat(gal%ldab,gal%ndim,2),gal%ipiv(gal%ndim))
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_alloc
c-----------------------------------------------------------------------
c subprogram 7. deltac_dealloc.
c deallocates arrays.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_dealloc(gal)
TYPE(gal_type), INTENT(INOUT) :: gal
INTEGER :: ix,ixmin
TYPE(interval_type), POINTER :: intvl
TYPE(cell_type), POINTER :: cell
c-----------------------------------------------------------------------
c deallocate arrays.
c-----------------------------------------------------------------------
DEALLOCATE(asp%v)
intvl => gal%intvl
ixmin=1
IF (fulldomain>0) ixmin=-gal%nx
DO ix=ixmin,gal%nx
IF (ix==0) CYCLE
cell => intvl%cell(ix)
DEALLOCATE(cell%map,cell%mat)
IF(cell%etype /= "none") DEALLOCATE(cell%rhs)
IF(cell%etype == "res" .OR. cell%etype == "ext")
$ DEALLOCATE(cell%emap)
ENDDO
DEALLOCATE(intvl%x,intvl%dx,intvl%cell)
DEALLOCATE(gal%rhs,gal%sol,gal%mat,gal%ipiv,gal%intvl)
CALL jacobi_dealloc(gal%quad)
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_dealloc
c-----------------------------------------------------------------------
c subprogram 8. deltac_make_grid.
c sets up grid in the interval.
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
SUBROUTINE deltac_make_grid(nx,dx1,dx2,pfac,intvl)
INTEGER :: nx
REAL(r8), INTENT(IN) :: dx1,dx2,pfac
TYPE(interval_type), INTENT(INOUT) :: intvl
INTEGER :: ixmin,ixmax,ix,mx
REAL(r8) :: x0,x1,xm,dx
c-----------------------------------------------------------------------
c set default extra.
c-----------------------------------------------------------------------
DO ix=1,nx
intvl%cell(ix)%etype="none"
ENDDO
c-----------------------------------------------------------------------
c set lower bound.
c-----------------------------------------------------------------------
ixmin=0
intvl%x(ixmin)=0
c-----------------------------------------------------------------------
c set upper bound.
c-----------------------------------------------------------------------
x1=xmax
intvl%x(nx)=x1
IF (dx1dx2_flag) THEN
intvl%x(nx-1)=x1-dx1
intvl%x(nx-2)=x1-(dx1+dx2)
ixmax=nx-2
ELSE
ixmax=nx
ENDIF
SELECT CASE (gal_method)
CASE("normal")
intvl%cell(nx)%etype="ext1"
DO ix=nx-1,nx-cutoff,-1
intvl%cell(ix)%etype="ext1"
ENDDO
CASE("resonant")
intvl%cell(nx-1)%etype="ext"
intvl%cell(nx)%etype="res"
DO ix=nx-2,nx-cutoff,-1
intvl%cell(ix)%etype="ext1"
ENDDO
CASE DEFAULT
CALL program_stop
$ ("invalid galerkin method.")
END SELECT
intvl%cell(ix)%etype="ext2"
c-----------------------------------------------------------------------
c compute interior packed grid.
c-----------------------------------------------------------------------
x0=intvl%x(ixmin)
x1=intvl%x(ixmax)
xm=(intvl%x(ixmax)+intvl%x(ixmin))/2
dx=(intvl%x(ixmax)-intvl%x(ixmin))/2
mx=(ixmax-ixmin)/2
c check pack output
IF(pfac < 1) side="left"
intvl%x(ixmin:ixmax)=xm+dx*deltac_pack(mx,pfac,side)
intvl%x(ixmin)=x0
intvl%x(ixmax)=x1
intvl%dx(0)=0
intvl%dx(1:nx)=intvl%x(1:nx)-intvl%x(0:nx-1)
DO ix=1,nx
intvl%cell(ix)%x=(/intvl%x(ix-1),intvl%x(ix)/)
ENDDO
IF (fulldomain>0 .AND. gal_method=="normal") THEN
DO ix=-nx,-1
intvl%cell(ix)%etype=intvl%cell(-ix)%etype
intvl%x(ix)=intvl%x(-ix)
intvl%dx(ix)=intvl%dx(-ix)
intvl%cell(ix)%x(1)=-intvl%cell(-ix)%x(2)
intvl%cell(ix)%x(2)=-intvl%cell(-ix)%x(1)
ENDDO
ENDIF
c-----------------------------------------------------------------------
c terminate.
c-----------------------------------------------------------------------
RETURN
END SUBROUTINE deltac_make_grid
c-----------------------------------------------------------------------
c subprogram 9. deltac_pack.
c computes packed grid on (0,1).
c-----------------------------------------------------------------------
c-----------------------------------------------------------------------
c declarations.
c-----------------------------------------------------------------------
FUNCTION deltac_pack(nx,pfac,side) RESULT(x)
INTEGER, INTENT(IN) :: nx
REAL(r8), INTENT(IN) :: pfac
CHARACTER(*), INTENT(IN) :: side
REAL(r8), DIMENSION(-nx:nx) :: x
INTEGER :: ix
REAL(r8) :: lambda,a
REAL(r8), DIMENSION(-nx:nx) :: xi,num,den
c-----------------------------------------------------------------------
c fill logical grid.