-
Notifications
You must be signed in to change notification settings - Fork 1
/
auxil.f90
3325 lines (2856 loc) · 97.5 KB
/
auxil.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
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
!------------------------------------------------------------------------
! Some Auxiliary subroutines:
!
! print_orbs
! print_NO
! zbisect
! zbrent_so
! zbrent_gr
! times_init
! print_times
! consistency
! MathOut
! normal_test
! eigenvector_test
! orthog_vec
! symmet_orthog
! Akima
! zbrent... is from the Numerical recipes. Akima is public domain
! The diagon_NAGrest created by N. N. Lathiotakis and I.Theophilou
!------------------------------------------------------------------------
subroutine print_orbs(nb,nat,vecnat)
!..Global
use params_general
implicit none
!..Arguments
integer, intent(in) :: nb,nat
integer, intent(in) :: vecnat(lnbasis,lnnatorb)
!..Local variables
integer :: i,ia
do ia=1,nat
write(50+ia,'(e20.10)')(vecnat(i,ia),i=1,nb)
write(50+ia,*)
! write(6,'(f20.10)')(vecnat(i,ia),i=1,nb)
! write(6,*)
enddo
end subroutine print_orbs
!------------------------------------------------------------------------
subroutine print_NO(nnatorb)
!..Global
use matrices
implicit none
!..Arguments
integer, intent(in) :: nnatorb
!..Local Variables
integer :: ia,ib
print*,'-------------------------------------------'
Print*, 'HcoreNO:'
do ia=1,nnatorb
do ib=1,nnatorb
print*,ia,ib,HcoreNO(ia,ib)
enddo
enddo
print*,'-------------------------------------------'
Print*, 'CoulNO:'
do ia=1,nnatorb
do ib=1,nnatorb
print*,ia,ib,CoulNO(ia,ib)
enddo
enddo
print*,'-------------------------------------------'
Print*, 'ExchNO:'
do ia=1,nnatorb
do ib=1,nnatorb
print*,ia,ib,ExchNO(ia,ib)
enddo
enddo
print*,'-------------------------------------------'
end subroutine print_NO
!------------------------------------------------------------------------
function zbisect(func,a1,a2,ITMAX,tol,it_done,occnumtmp)
!------------------------------------------------------------------------
! BISECTION METHOD FOR ROOT FINDING
! func: function the root of which will be found.
! a1, a2: lower, upper bound.
! ITMAX: Maximum number of iterations.
! tol: tolerance.
! it_done: final number of iterations.
! The bisection or false position methods ca be chosen by
! commenting in/out the eppropriate lines below.
!------------------------------------------------------------------------
!..Global
use params_general
implicit none
!..The function
real(dp) :: zbisect
!..Arguments
integer, intent(in) :: ITMAX
integer, intent(out) :: it_done
real(dp), intent(in) :: a1, a2, tol
real(dp), external :: func
real(dp) :: occnumtmp(lnbasis,3)
!..Local
integer :: iter
real(dp) :: x1, x2, g1, g2, xm, gm
x1 = a1
x2 = a2
g1 = func(x1,occnumtmp)
g2 = func(x2,occnumtmp)
iter=1
do iter=1, ITMAX
!..Bisection rule:
xm = (x1 + x2)/2._dp
!..False position method:
! xm = (x1*g2 - x2*g1)/(g2 - g1)
gm=func(xm,occnumtmp)
if(gm*g1.lt.0._dp) then
x2 = xm
g2 = gm
else
x1 = xm
g1 = gm
endif
if(abs((x2-x1)/x2) < tol) exit
! if(abs(gm) < tol) goto 148
enddo !iter
it_done = iter
zbisect = xm
end function zbisect
!------------------------------------------------------------------------
function zbisect_pot(func,a1,a2,ITMAX,tol,it_done,X_0)
!------------------------------------------------------------------------
! BISECTION METHOD FOR ROOT FINDING
! func: function the root of which will be found.
! a1, a2: lower, upper bound.
! ITMAX: Maximum number of iterations.
! tol: tolerance.
! it_done: final number of iterations.
! The bisection or false position methods ca be chosen by
! commenting in/out the eppropriate lines below.
!------------------------------------------------------------------------
!..Global
use params_general
implicit none
!..The function
real(dp) :: zbisect_pot
!..Arguments
integer, intent(in) :: ITMAX
integer, intent(out) :: it_done
real(dp), intent(in) :: a1, a2, tol
real(dp), external :: func
real(dp) :: X_0(*)
!..Local
integer :: iter
real(dp) :: x1, x2, g1, g2, xm, gm
x1 = a1
x2 = a2
g1 = func(x1, X_0)
g2 = func(x2, X_0)
iter=1
do iter=1, ITMAX
!..Bisection rule:
xm = (x1 + x2)/2._dp
!..False position method:
! xm = (x1*g2 - x2*g1)/(g2 - g1)
gm=func(xm, X_0)
if(gm*g1.lt.0._dp) then
x2 = xm
g2 = gm
else
x1 = xm
g1 = gm
endif
if(abs((x2-x1)/x2) < tol) exit
! if(abs(gm) < tol) goto 148
enddo !iter
it_done = iter
zbisect_pot = xm
end function zbisect_pot
!------------------------------------------------------------------------
function zbrent_so(f,x1,x2,ITMAX,tol,iter,occnumtmp)
!------------------------------------------------------------------------
! The brent method (From Numerical recipes f77 code adapted)
! Using the Brent method, find the root of a function func bracketed
! between x1 and x2. The root returned as zbrent, will be refined until
! its accuracy is tol. Parameters: Maximum allowed number of iterations,
! and machine floating-point precision.
!------------------------------------------------------------------------
!..Global
use params_general
implicit none
!..The function
real(dp) :: zbrent_so
!..Arguments
integer, intent(in) :: ITMAX
real(dp), intent(in) :: tol,x1,x2
real(dp), external :: f
real(dp), parameter :: EPS=zero
integer, intent(inout) :: iter
real(dp), intent(inout) :: occnumtmp(lnbasis,3)
!..Local
real(dp) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm
a=x1
b=x2
fa=f(a,occnumtmp)
fb=f(b,occnumtmp)
if((fa.gt.0..and.fb.gt.0.).or.(fa.lt.0..and.fb.lt.0.)) then
print*,'a,b',a,b
print*,'fa,fb',fa,fb
stop 'zbrent_so: root must be bracketed for zbrent_so'
endif
c=b
fc=fb
do 11 iter=1,ITMAX
if((fb.gt.0..and.fc.gt.0.).or.(fb.lt.0..and.fc.lt.0.))then
c=a
fc=fa
d=b-a
e=d
endif
if(abs(fc).lt.abs(fb)) then
a=b
b=c
c=a
fa=fb
fb=fc
fc=fa
endif
tol1=2._dp*EPS*abs(b)+0.5_dp*tol
xm=.5_dp*(c-b)
if(abs(xm).le.tol1 .or. fb.eq.0.)then
zbrent_so=b
! print*,'To vrika metaxy:',c,b
! print*,'solveocc:',fb,fc
return
endif
if(abs(e).ge.tol1 .and. abs(fa).gt.abs(fb)) then
s=fb/fa
if(a.eq.c) then
p=2._dp*xm*s
q=1._dp-s
else
q=fa/fc
r=fb/fc
p=s*(2._dp*xm*q*(q-r)-(b-a)*(r-1._dp))
q=(q-1._dp)*(r-1._dp)*(s-1._dp)
endif
if(p.gt.0._dp) q=-q
p=abs(p)
if(2._dp*p .lt. min(3._dp*xm*q-abs(tol1*q),abs(e*q))) then
e=d
d=p/q
else
d=xm
e=d
endif
else
d=xm
e=d
endif
a=b
fa=fb
if(abs(d) .gt. tol1) then
b=b+d
else
b=b+sign(tol1,xm)
endif
fb=f(b,occnumtmp)
11 continue
print *, 'zbrent_so:zbrent exceeding maximum iterations'
zbrent_so=b
END function zbrent_so
! (C) Copr. 1986-92 Numerical Recipes Software 5.)2ptN75L:52.
!------------------------------------------------------------------------
function zbrent_gr(f,x1,x2,ITMAX,tol,iter,occnumtmp)
!..Global
use params_general
implicit none
!..Arguments
real(dp) :: zbrent_gr
integer,intent(in) :: ITMAX
real(dp), intent(in) :: tol,x1,x2
real(dp), external :: f
real(dp), parameter :: EPS=zero
integer, intent(out) :: iter
real(dp), intent(inout):: occnumtmp(lnbasis,3)
!..Local
real(dp) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm
a=x1
b=x2
fa=f(a,occnumtmp)
fb=f(b,occnumtmp)
if((fa.gt.0..and.fb.gt.0.).or.(fa.lt.0..and.fb.lt.0.)) then
print*,'a,b',a,b
print*,'fa,fb',fa,fb
stop 'zbrent_gr: root must be bracketed for zbrent'
endif
c=b
fc=fb
do 11 iter=1,ITMAX
if((fb.gt.0..and.fc.gt.0.).or.(fb.lt.0..and.fc.lt.0.))then
c=a
fc=fa
d=b-a
e=d
endif
if(abs(fc).lt.abs(fb)) then
a=b
b=c
c=a
fa=fb
fb=fc
fc=fa
endif
tol1=2._dp*EPS*abs(b)+0.5_dp*tol
xm=.5_dp*(c-b)
if(abs(xm).le.tol1 .or. fb.eq.0.)then
zbrent_gr=b
return
endif
if(abs(e).ge.tol1 .and. abs(fa).gt.abs(fb)) then
s=fb/fa
if(a.eq.c) then
p=2._dp*xm*s
q=1._dp-s
else
q=fa/fc
r=fb/fc
p=s*(2._dp*xm*q*(q-r)-(b-a)*(r-1._dp))
q=(q-1._dp)*(r-1._dp)*(s-1._dp)
endif
if(p.gt.0._dp) q=-q
p=abs(p)
if(2._dp*p .lt. min(3._dp*xm*q-abs(tol1*q),abs(e*q))) then
e=d
d=p/q
else
d=xm
e=d
endif
else
d=xm
e=d
endif
a=b
fa=fb
if(abs(d) .gt. tol1) then
b=b+d
else
b=b+sign(tol1,xm)
endif
fb=f(b,occnumtmp)
11 continue
zbrent_gr=b
END function zbrent_gr
function zbrent_pot(f,x1,x2,ITMAX,tol,iter, &
X_0)
!..Global
use params_general
implicit none
!..Arguments
real(dp) :: zbrent_pot
integer,intent(in) :: ITMAX
real(dp), intent(in) :: tol,x1,x2
real(dp), external :: f
real(dp), parameter :: EPS=zero
integer, intent(out) :: iter
real(dp), intent(in):: X_0(*)
!..Local
real(dp) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm
a=x1
b=x2
fa=f(a,X_0)
fb=f(b,X_0)
if((fa.gt.0..and.fb.gt.0.).or.(fa.lt.0..and.fb.lt.0.)) then
print*,'a,b',a,b
print*,'fa,fb',fa,fb
stop 'zbrent_pot: root must be bracketed for zbrent'
endif
c=b
fc=fb
do 11 iter=1,ITMAX
if((fb.gt.0..and.fc.gt.0.).or.(fb.lt.0..and.fc.lt.0.))then
c=a
fc=fa
d=b-a
e=d
endif
if(abs(fc).lt.abs(fb)) then
a=b
b=c
c=a
fa=fb
fb=fc
fc=fa
endif
tol1=2._dp*EPS*abs(b)+0.5_dp*tol
xm=.5_dp*(c-b)
if(abs(xm).le.tol1 .or. fb.eq.0.)then
zbrent_pot=b
return
endif
if(abs(e).ge.tol1 .and. abs(fa).gt.abs(fb)) then
s=fb/fa
if(a.eq.c) then
p=2._dp*xm*s
q=1._dp-s
else
q=fa/fc
r=fb/fc
p=s*(2._dp*xm*q*(q-r)-(b-a)*(r-1._dp))
q=(q-1._dp)*(r-1._dp)*(s-1._dp)
endif
if(p.gt.0._dp) q=-q
p=abs(p)
if(2._dp*p .lt. min(3._dp*xm*q-abs(tol1*q),abs(e*q))) then
e=d
d=p/q
else
d=xm
e=d
endif
else
d=xm
e=d
endif
a=b
fa=fb
if(abs(d) .gt. tol1) then
b=b+d
else
b=b+sign(tol1,xm)
endif
fb=f(b,X_0)
11 continue
zbrent_pot=b
END function zbrent_pot
!------------------------------------------------------------------------
subroutine times_init()
! Just initialize the times spend in each subroutine to zero
!..Global
use global
implicit none
time_tot=0._dp
time_fock=0._dp
time_occ=0._dp
time_vec=0._dp
time_nbas=0._dp
time_tote=0._dp
time_rdgm=0._dp
time_sumint=0._dp
end subroutine times_init
!------------------------------------------------------------------------
subroutine print_times()
! Prints the time spent in each (important) subroutine
!..Global
use params_general
use global
implicit none
write(6,*)'-----------------------------------------------------'
write(6,*)'TIME DISTRIBUTION INFORMATION: '
write(6,'(a30,f10.2,a4)') ' Total time=', time_tot, &
'sec'
write(6,*)'-----------------------------------------------------'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Read Gamess out time=',&
time_rdgm, 'sec',100._dp*time_rdgm/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Fock construction time=',&
time_fock, 'sec',100._dp*time_fock/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'K_ab, J_ab constr time=',&
time_nbas, 'sec',100._dp*time_nbas/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Orbital minimiz. time=',&
time_vec, 'sec',100._dp*time_vec/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Occ.Nu. minimiz. time=',&
time_occ, 'sec',100._dp*time_occ/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Integral summ. time=',&
time_sumint, 'sec',100._dp*time_sumint/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Lagr. mat. calc. time=',&
time_lagr, 'sec',100._dp*time_lagr/time_tot,'%'
write(6,'(a30,f10.2,a4,f6.2,a1)') 'Tot. Energy calc. time=',&
time_tote, 'sec',100._dp*time_tote/time_tot,'%'
write(6,*)'-----------------------------------------------------'
end subroutine print_times
!------------------------------------------------------------------------
subroutine normal_test(test,criter,iwork)
!------------------------------------------------------------------------
! Checks if vecnat is an orthonormal set of vectors. The basis set
! is not orthogonal and the overlap matrix is provided by the
! 'matrices.com', while the orbitals are procided through the
! 'orbocc.com'
! OUTPUT:
! test (logical): successful/unsuccessful
! iwork (integer):
! 0: do not print,
! other: print
!------------------------------------------------------------------------
!..Global
use global
use matrices
use orbocc
implicit none
!..Arguments
logical :: test
integer :: iwork
real(dp) :: criter
!..Local
integer :: ia,ib,i,j
real(dp), allocatable :: Fsmall(:,:)
real(dp) :: trial_mat, comp_0, comp_1, divmax
!..Local array allocation
allocate ( Fsmall(lnbasis,lnbasis) )
divmax=0._dp
test=.true.
if(iwork /= 0) print*,'-------------------------------------------------'
if(iwork /= 0) print*,'Orthonormality test:'
do ia=1,nnatorb
do ib=1,nbasis
Fsmall(ia,ib)=0._dp
do i=1,nbasis
do j=1,nbasis
! trial_mat=F(i,j,ia)-F(i,j,ib) ! hermiticity of Lagr mult
trial_mat=ovlap(i,j)
Fsmall(ia,ib)= Fsmall(ia,ib) + &
vecnat(i,ia)*trial_mat*vecnat(j,ib)
enddo
enddo
comp_0 = abs(Fsmall(ia,ib))
comp_1 = abs(Fsmall(ia,ib)-1._dp)
divmax= max(divmax,min(comp_0, comp_1))
if(comp_0>criter.and.comp_1>criter) then
if(iwork /= 0) print*,'for ',ia,ib,'Ovlap=',Fsmall(ia,ib)
test=.false.
endif
enddo
enddo
if(test) then
if(iwork /= 0) print*,'The orthonormality test was PASSED'
else
if(iwork /= 0) print*,'The orthonormality test NOT PASSED'
endif
if(iwork /= 0) print*,'Maximum difference from zero or one:',divmax
if(iwork /= 0) print*,'-------------------------------------------------'
deallocate ( Fsmall )
end subroutine normal_test
!-------------------------------------------------------------------------
subroutine symmet_orthog()
!-----------------------------------------------------------------------
! Symmetric orthogonalization of vecnat. The basis set
! is not orthogonal and the overlap matrix is provided by the
! 'matrices.com', while the orbitals are provided through the
! 'orbocc' module.
! The Formula used is C_orth = ((3/2) I - (1/2) D) C_north
! where C_north is the non orthogonal set of vectors,
! C_orth is the final orthogonal set,
! D is the overlap matrix of the C_orth set, and
! I is the unit matrix.
! It works well for initial vectors not far from being orthogonal
! since this formula is a taylor expansion for small D
!-----------------------------------------------------------------------
!..Global
use global
use orbocc
use matrices
implicit none
!..local variables:
integer i,ia,ib
real(dp), allocatable :: ovl(:,:)
real(dp), allocatable :: vnew(:,:)
real(dp) :: q_ovl
!..Local array allocation
allocate( ovl(lnbasis,lnbasis), vnew(lnbasis,lnbasis) )
do ia=1,nbasis
do ib=1, ia
ovl(ia,ib)=dot_product(vecnat(:,ia),(matmul(ovlap,vecnat(:,ib))))
! do i=1,nbasis
! do j=1,nbasis
! ovl(ia,ib)=ovl(ia,ib) &
! +vecnat(i,ia)*ovlap(i,j)*vecnat(j,ib)
! enddo
! enddo
ovl(ib,ia)= ovl(ia,ib)
enddo
enddo
do ia=1,nbasis
do i=1,nbasis
vnew(i,ia)=0._dp
do ib=1,nbasis
q_ovl=-0.5_dp*ovl(ia,ib)
if(ib == ia) q_ovl=q_ovl+1.5_dp
vnew(i,ia)=vnew(i,ia)+vecnat(i,ib)*q_ovl
enddo
enddo
enddo
vecnat=vnew
deallocate( ovl, vnew )
end subroutine symmet_orthog
!-----------------------------------------------------------------------
function BBC1_strength(ec_over_ek,MC)
!-----------------------------------------------------------------------
! This function calculates the strength of the BBC1 correction i.e.
! the factor multiplying the xc terms for both orbitals being weakly
! occupied as a function of the ratio of the correlation over the
! kinetic energy 'ec_over_ek'. That is done by spline interpolation
! to the results of the Homogeneous electron gas. For the Homogeneous
! electron gas there are two sets of data. Those fitted to reproduce
! the Ceperley&Adler Monte-Carlo results for the correlation energy
! and those fitted to reproduce the Ortiz&Balone Monte-Carlo results.
!
! INPUT:
! ec_over_ek : The ratio E_correlation / E_kinetic
! MC : 1: Ceperley&Adler, 2: Ortiz&Balone
! OUTPUT (function value): the strength of the xc term
!-----------------------------------------------------------------------
!..Global
use global
implicit none
!..The function
real(dp) :: BBC1_strength
!..Arguments
integer, intent(in) :: MC !1: Ceperley&Adler, 2: Ortiz&Balone
real(dp),intent(in) :: ec_over_ek
!..Local
integer, parameter :: SIZE=16
real(dp) :: str1(0:SIZE), ecek1(0:SIZE)
real(dp) :: str2(0:SIZE), ecek2(0:SIZE)
integer :: ntable, i, ierr
real(dp) :: alpha,str_new
ntable=SIZE ! The number of str/ecek pairs below
!..Data for strengt/ratio for Ceperley-Alder
str1(1) =4.80_dp
str1(2) =2.6366_dp
str1(3) =1.7585_dp
str1(4) =0.981_dp
str1(5) =0.6253_dp
str1(6) =0.34203_dp
str1(7) =-0.0064_dp
str1(8) =-0.1176_dp
str1(9) =-0.202_dp
str1(10) =-0.24_dp
ecek1(1) =-1.0939794e-3_dp
ecek1(2) =-3.66072678e-3_dp
ecek1(3) =-7.331623097e-3_dp
ecek1(4) =-1.73353975e-2_dp
ecek1(5) =-3.02585e-2_dp
ecek1(6) =-5.40964154e-2_dp
ecek1(7) =-0.1620329_dp
ecek1(8) =-0.3008926129_dp
ecek1(9) =-0.638405507_dp
ecek1(10)=-1.680826122_dp
!..Ortiz Ballone
str2(1) =4.913_dp !rs=0.1
str2(2) =2.7510_dp !rs=0.2
str2(3) =1.86703_dp !rs=0.3
str2(4) =1.389858_dp !rs=0.4
str2(5) =1.08743_dp !rs=0.5
str2(6) =0.87688_dp !rs=0.6
str2(7) =0.727_dp !rs=0.7
str2(8) =0.602166_dp !rs=0.8
str2(9) =0.4354_dp !rs=1.0
str2(10) =0.190003_dp !rs=1.5
str2(11) =0.0594_dp !rs=2.0
str2(12) =-0.074_dp !rs=3.0
str2(13) =-0.1461026_dp !rs=4.0
str2(14) =-0.189_dp !rs=5.0
str2(15) =-0.2338115_dp !rs=7.0
str2(16) =-0.26305_dp !rs=10.0
ecek2(1) =-1.086055e-3_dp !rs=0.1
ecek2(2) =-3.616377e-3_dp !rs=0.2
ecek2(3) =-7.21488e-3_dp !rs=0.3
ecek2(4) =-1.170173e-2_dp !rs=0.4
ecek2(5) =-1.6961415e-2_dp !rs=0.5
ecek2(6) =-2.291107355e-2_dp !rs=0.6
ecek2(7) =-2.948745e-2_dp !rs=0.7
ecek2(8) =-3.6640197e-2_dp !rs=0.8
ecek2(9) =-5.251647e-2_dp !rs=1.0
ecek2(10) =-0.100056734_dp !rs=1.5
ecek2(11) = -0.1569155_dp !rs=2.0
ecek2(12) =-0.292846_dp !rs=3.0
ecek2(13) =-0.45262455_dp !rs=4.0
ecek2(14) =-0.631738_dp !rs=5.0
ecek2(15) =-1.036181313_dp !rs=7.0
ecek2(16) =-1.728741821_dp !rs=10.0
do i=1,ntable
ecek1(i)=-ecek1(i)
ecek2(i)=-ecek2(i)
enddo
alpha=-ec_over_ek
if(MC==1) then
alpha=max(min(alpha,ecek1(SIZE)-0.000001_dp),ecek1(1)+0.000001_dp)
call Akima(ntable, ierr, alpha, str_new, ecek1, str1)
elseif(MC==2) then
alpha=max(min(alpha,ecek2(SIZE)-0.000001_dp),ecek2(1)+0.000001_dp)
call Akima(ntable, ierr, alpha, str_new, ecek2, str2)
else
print*,'Function BBC1_strength: MC =', MC
stop 'BBC1_strength: MC must be 1 or 2 '
endif
BBC1_strength = str_new
end function BBC1_strength
function BBC1_strength_b(ec_over_ex,MC)
!LIKE BBC1_strength above but the paramere is Ec/Ex
!-----------------------------------------------------------------------
! This function calculates the strength of the BBC1 correction i.e.
! the factor multiplying the xc terms for both orbitals being weakly
! occupied as a function of the ratio of the correlation over the
! exchange energy 'ec_over_ex'. That is done by spline interpolation
! to the results of the Homogeneous electron gas. For the Homogeneous
! electron gas there are two sets of data. Those fitted to reproduce
! the Ceperley&Adler Monte-Carlo results for the correlation energy
! and those fitted to reproduce the Ortiz&Balone Monte-Carlo results.
!
! INPUT:
! ec_over_ek : The ratio E_correlation / E_kinetic
! MC : 1: Ceperley&Adler, 2: Ortiz&Balone
! OUTPUT (function value): the strength of the xc term
!-----------------------------------------------------------------------
!..Global
use global
implicit none
!..The function
real(dp) :: BBC1_strength_b
!..Arguments
integer, intent(in) :: MC !1: Ceperley&Adler, 2: Ortiz&Balone
real(dp),intent(in) :: ec_over_ex
!..Local
integer, parameter :: SIZE=16
real(dp) :: str1(0:SIZE), ecex1(0:SIZE)
real(dp) :: str2(0:SIZE), ecex2(0:SIZE)
integer :: ntable, ierr
real(dp) :: alpha,str_new
ntable=SIZE ! The number of str/x pairs below
if( MC == 1) then
stop 'auxil: BBC1_strength_b works only with Ortiz Balone, MC=2'
endif
!..Ortiz Ballone
str2(1) =4.913_dp !rs=0.1
str2(2) =2.7510_dp !rs=0.2
str2(3) =1.86703_dp !rs=0.3
str2(4) =1.389858_dp !rs=0.4
str2(5) =1.08743_dp !rs=0.5
str2(6) =0.87688_dp !rs=0.6
str2(7) =0.727_dp !rs=0.7
str2(8) =0.602166_dp !rs=0.8
str2(9) =0.4354_dp !rs=1.0
str2(10) =0.190003_dp !rs=1.5
str2(11) =0.0594_dp !rs=2.0
str2(12) =-0.074_dp !rs=3.0
str2(13) =-0.1461026_dp !rs=4.0
str2(14) =-0.189_dp !rs=5.0
str2(15) =-0.2338115_dp !rs=7.0
str2(16) =-0.26305_dp !rs=10.0
ecex2(1) =0.26192229e-1_dp !rs=0.1
ecex2(2) =0.43607816e-1_dp !rs=0.2
ecex2(3) =0.58000046e-1_dp !rs=0.3
ecex2(4) =0.70552246e-1_dp !rs=0.4
ecex2(5) =0.81811200e-1_dp !rs=0.5
ecex2(6) =0.92090506e-1_dp !rs=0.6
ecex2(7) =0.10159207_dp !rs=0.7
ecex2(8) =0.11045579_dp !rs=0.8
ecex2(9) = 0.12665320_dp !rs=1.0
ecex2(10) = 0.16087025_dp!rs=1.5
ecex2(11) = 0.18921539_dp!rs=2.0
ecex2(12) = 0.23541737_dp!rs=3.0
ecex2(13) = 0.27289701_dp!rs=4.0
ecex2(14) = 0.30471095_dp!rs=5.0
ecex2(15) = 0.35699192_dp!rs=7.0
ecex2(16) = 0.41691815_dp!rs=10.0
! do i=1,ntable
! ecex1(i)=-ecex1(i)
! ecex2(i)=-ecex2(i)
! enddo
! alpha=-ec_over_ex
if( ec_over_ex < ecex2(1) .or. ec_over_ex > ecex2(16) ) then
print*,'!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print*,'!!!!!!!!!a=',ec_over_ex,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print*,'!!!!!!!!!!!!!alpha out of bounds!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print*,'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
endif
if(MC==1) then
alpha=max(min(alpha,ecex1(SIZE)-0.000001_dp),ecex1(1)+0.000001_dp)
call Akima(ntable, ierr, alpha, str_new, ecex1, str1)
elseif(MC==2) then
alpha=max(min(alpha,ecex2(SIZE)-0.000001_dp),ecex2(1)+0.000001_dp)
call Akima(ntable, ierr, alpha, str_new, ecex2, str2)
else
print*,'Function BBC1_strength: MC =', MC
stop 'BBC1_strength: MC must be 1 or 2 '
endif
BBC1_strength_b = str_new
end function BBC1_strength_b
!-----------------------------------------------------------------------
!********************************************************
!* Akima spline fitting subroutine *
!* ---------------------------------------------------- *
!* The input table is X(i), Y(i), where Y(i) is the *
!* dependant variable. The interpolation point is x_int,*
!* which is assumed to be in the interval of the table *
!* with at least one table value to the left, and three *
!* to the right. The interpolated returned value is *
!* y_int. *
!* ierr is returned as an error check (ierr=0 implies *
!* error). *
!* It is also assumed that the X(i) are in ascending *
!* order. *
!********************************************************
subroutine Akima(npoints,ierr,x_int,y_int,X,Y)
use global; implicit none
integer SIZE
parameter(SIZE=16)
integer i,npoints,ierr
real*8 x_int,y_int
real*8 X(0:SIZE), Y(0:SIZE)
real*8 XM(0:SIZE+3)
real*8 Z (0:SIZE)
real*8 a,b
ierr=1
!..special case x_int=0
if (x_int.eq.0.0) then
y_int=0._dp
return
end if
!..Check to see if interpolation point is correct
if (x_int.lt.X(1).or.x_int.ge.X(npoints)) then
ierr=0
return
end if
X(0)=2._dp*X(1)-X(2)
!..Calculate Akima coefficients, a and b
do i = 1, npoints-1
!.....Shift i to i+2
XM(i+2)=(Y(i+1)-Y(i))/(X(i+1)-X(i))
end do
XM(npoints+2)=2._dp*XM(npoints+1)-XM(npoints)
XM(npoints+3)=2._dp*XM(npoints+2)-XM(npoints+1)
XM(2)=2._dp*XM(3)-XM(4)
XM(1)=2._dp*XM(2)-XM(3)
do i = 1, npoints
a=dabs(XM(i+3)-XM(i+2))
b=dabs(XM(i+1)-XM(i))
if (a+b.ne.0._dp) goto 10
Z(i)=(XM(i+2)+XM(i+1))/2._dp
goto 20
10 Z(i)=(a*XM(i+1)+b*XM(i+2))/(a+b)
20 end do
!..Find relevant table interval
i=0
30 i=i+1
if (x_int.gt.X(i)) goto 30
i=i-1
!..Begin interpolation
b=X(i+1)-X(i)
a=x_int-X(i)
y_int=Y(i)+Z(i)*a+(3._dp*XM(i+2)-2._dp*Z(i)-Z(i+1))*a*a/b
y_int=y_int+(Z(i)+Z(i+1)-2._dp*XM(i+2))*a*a*a/(b*b)
end subroutine Akima
!-----------------------------------------------------------------------
function s_rho(rho)
!-----------------------------------------------------------------------
! INPUT:
! rho : The local density
! OUTPUT (function value): the strength of the xc term
! The Ortiz Ballone data are used
!-----------------------------------------------------------------------
!..Global
use global; implicit none
!..The function
real(dp) :: s_rho
!..Arguments
real(dp),intent(in) :: rho
!..Local
integer, parameter :: SIZE=16
real(dp) :: str2(0:SIZE), rstab2(0:SIZE), r_s
integer :: ntable, ierr
real(dp) :: str_new
ntable=SIZE ! The number of str/ecek pairs below
!..Ortiz Ballone
str2(1) =4.913_dp; rstab2(1)=0.1_dp
str2(2) =2.7510_dp; rstab2(2)=0.2_dp
str2(3) =1.86703_dp; rstab2(3)=0.3_dp
str2(4) =1.389858_dp; rstab2(4)=0.4_dp
str2(5) =1.08743_dp; rstab2(5)=0.5_dp
str2(6) =0.87688_dp; rstab2(6)=0.6_dp
str2(7) =0.727_dp; rstab2(7)=0.7_dp
str2(8) =0.602166_dp; rstab2(8)=0.8_dp
str2(9) =0.4354_dp; rstab2(9)=1.0_dp
str2(10) =0.190003_dp; rstab2(10)=1.5_dp
str2(11) =0.0594_dp; rstab2(11)=2.0_dp
str2(12) =-0.074_dp; rstab2(12)=3.0_dp
str2(13) =-0.1461026_dp; rstab2(13)=4.0_dp
str2(14) =-0.189_dp; rstab2(14)=5.0_dp
str2(15) =-0.2338115_dp; rstab2(15)=7.0_dp
str2(16) =-0.26305_dp; rstab2(16)=10.0_dp
! ecek2(1) =-1.086055d-3 !rs=0.1
! ecek2(2) =-3.616377d-3 !rs=0.2
! ecek2(3) =-7.21488d-3 !rs=0.3
! ecek2(4) =-1.170173d-2 !rs=0.4
! ecek2(5) =-1.6961415d-2 !rs=0.5
! ecek2(6) =-2.291107355d-2 !rs=0.6
! ecek2(7) =-2.948745d-2 !rs=0.7
! ecek2(8) =-3.6640197d-2 !rs=0.8