forked from alexei-matveev/paragauss-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ll_calculate.f90
2189 lines (1920 loc) · 81.9 KB
/
ll_calculate.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
!
! ParaGauss, a program package for high-performance computations of
! molecular systems
!
! Copyright (C) 2014 T. Belling, T. Grauschopf, S. Krüger,
! F. Nörtemann, M. Staufer, M. Mayer, V. A. Nasluzov, U. Birkenheuer,
! A. Hu, A. V. Matveev, A. V. Shor, M. S. K. Fuchs-Rohr, K. M. Neyman,
! D. I. Ganyushin, T. Kerdcharoen, A. Woiterski, A. B. Gordienko,
! S. Majumder, M. H. i Rotllant, R. Ramakrishnan, G. Dixit,
! A. Nikodem, T. Soini, M. Roderus, N. Rösch
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License version 2 as
! published by the Free Software Foundation [1].
!
! This program is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! General Public License for more details.
!
! [1] http://www.gnu.org/licenses/gpl-2.0.html
!
! Please see the accompanying LICENSE file for further information.
!
!=====================================================================
! Public interface of module
!=====================================================================
subroutine ll_calculate(na,nb,la,lb,imode,many_3c)
!
! Purpose: calculation of all primitive 2 center orbital
! and 3 center integrals for a given set of indizes
! (unique_atom1,unique_atom2,la,lb).
! For three center integrals, contraction and symmetry-
! adaption concerning fitfunctions is also performed.
!
!
! Author: MS
! Date: 8/96
!
!== Interrupt of public interface of module ========================
!-------------------------------------------------------------------
! Modifications
!-------------------------------------------------------------------
! Modification (Please copy before editing)
! Author: AS
! Date: 11-12/99
! Description: integrals of electrostatic potential are added
!
! Modification
! Author: SB
! Date: 02/05
! Description: symmetrization for fit functions in 3c Coulomb integrals
! was added
! NEW: l_fit_symmetry_adaption_v2
! also coulomb calculations was rebuilded.
!
! Modification (Please copy before editing)
! Author: ...
! Date: ...
! Description: ...
!-------------------------------------------------------------------
! define FPP_TIMERS 2
# include "def.h"
use unique_atom_module, noname=>pseudopot_present
use gamma_module
use type_module
use datatype
use solid_harmonics_module, only : solid_harmonics_calc,solid_harmonics_scalar
use int_data_2cob3c_module
use solhrules_module
use fitcontract_module
use integralpar_module
use pointcharge_module
use options_module, only: options_integral_expmax
use potential_module
use elec_static_field_module
use calc3c_switches,only: old_potential,old_3c_co,old_elfield
use symmetry_data_module,only: symmetry_data_n_irreps, &
symmetry_data_n_partners,&
get_totalsymmetric_irrep
!!$ use iounitadmin_module
use shgi_cntrl, only: IPSEU
implicit none
!== Interrupt end of public interface of module ====================
integer(kind=i4_kind),intent(in) :: na ! number of unique atom a
integer(kind=i4_kind),intent(in) :: nb ! number of unique atom b
integer(kind=i4_kind),intent(in) :: la ! angular momentum of unique atom a
integer(kind=i4_kind),intent(in) :: lb ! angular momentum of unique atom b
integer(kind=i8_kind),intent(in) :: imode ! for control
real(r8_kind),optional,intent(out) :: many_3c(:,:,:,:,:)
! many_3c(nbexp,naexp,N_INTS*index3c,nlmb,nlma)
! Stored as illustrated by
! do ua=1,N_UA
! Int1[ua] stored at [3*(ua-1) + OFF_PVSP ] ! PVSP(ua)
! Int2[ua] stored at [3*(ua-1) + OFF_V ] ! V(ua)
! Int3[ua] stored at [3*(ua-1) + OFF_VFIN ] ! V_{fin}(ua)
! ...
! enddo
! offsets OFF_* defined in int_data_2cob3c_module
!===================================================================
! End of public interface of module
!===================================================================
integer(i4_kind), parameter :: &
AxB = 1, &
BxA = 2
integer(kind=i4_kind) :: naexps,nbexps,ncexps
real(kind=r8_kind),pointer :: aexps(:),bexps(:)
real(kind=r8_kind),pointer :: cexps(:)
real(kind=r8_kind) :: z ! charge
real(kind=r8_kind) :: zc ! core charge
integer(kind=i4_kind) :: max_order
! constants
! real(kind=r8_kind),dimension(3,3),parameter :: unity_matrix=reshape&
real(kind=r8_kind),dimension(3,3) :: unity_matrix=reshape&
((/1.0_r8_kind,0.0_r8_kind,0.0_r8_kind,0.0_r8_kind,1.0_r8_kind,&
0.0_r8_kind,0.0_r8_kind,0.0_r8_kind,1.0_r8_kind/),(/3,3/))
real(kind=r8_kind),parameter :: &
pi=3.14159265358979324_r8_kind, &
very_small=1.0e-100_r8_kind, &
very_big=1.0e100_r8_kind, &
zero=0.0_r8_kind, &
one=1.0_r8_kind, &
two=2.0_r8_kind, &
four=4.0_r8_kind, &
six=6.0_r8_kind
! real(kind=r8_kind),parameter,dimension(0:8) :: dfac= &
real(kind=r8_kind),dimension(0:8) :: dfac= &
(/ 1.0_r8_kind, 1.0_r8_kind, 3.0_r8_kind, 15.0_r8_kind, 105.0_r8_kind, &
945.0_r8_kind, 10395.0_r8_kind, 135135.0_r8_kind, 2027025.0_r8_kind /)
integer(kind=i4_kind) :: one_i,zero_i
integer(kind=i4_kind) :: num,counter,m,ma,mb,alloc_stat(40)=0
integer(kind=i4_kind) :: memstat
logical, allocatable :: cutoff(:,:)
! help factors
real(kind=r8_kind),allocatable,dimension(:,:):: &
fact0_arr, fact1_arr, fact2_arr, fact10
real(kind=r8_kind),allocatable,dimension(:) :: &
fact0, fact1, fact2, fact4, fact5, fact6, fact7, fact8, rcsabc, tau
! help arrays for gamma-function
real(kind=r8_kind),allocatable,dimension(:,:) :: gamma_arg, gamma_arg2, gamma_help
! help arrays for solid harmincs
real(kind=r8_kind),allocatable :: &
yl_arr(:,:,:), yl_arr2(:,:,:), clmamb(:,:), clmamb2(:,:), clmamb_scalar(:)
! help arrays for product_rule and diff_rule
real(kind=r8_kind),allocatable :: &
prod_arr(:,:,:,:,:), diff_arr(:,:,:), diff_arr0(:,:), &
intermediate(:,:,:,:,:,:)
real(kind=r8_kind) :: arg
! cartesian coordinates
real(kind=r8_kind),dimension(3) :: xa,xb,xc,xd
integer(kind=i4_kind) :: i,j,i_l,j_l,i_lb,k,i_ind,i_cnt,l !,l_cf,l_j
integer(kind=i4_kind) :: lmax_ch,lmax_xc,lmax_abs,ly_max
integer(kind=i4_kind) :: n_equals,n_independent_fcts,n_contributing_fcts
integer(kind=i4_kind), pointer :: eq_atom(:),magn(:)
real(kind=r8_kind), pointer :: coeff(:)
real(kind=r8_kind),allocatable :: aexp_arr(:),bexp_arr(:)
real(kind=r8_kind),allocatable :: nested2_fac1(:,:),nested2_fac2(:,:),nested2_fac12(:,:,:)
real(kind=r8_kind) :: expmax
type(unique_atom_type), pointer :: ua_pointer
! the calculated integrals
real(kind=r8_kind),allocatable :: potential(:,:,:,:), field(:,:,:,:), intermed_3c(:) !!!!!!!!!!!!
real(kind=r8_kind),allocatable :: prod_arr_gr(:,:,:,:,:),help_vec(:),prod_arr_gr_vec(:,:,:), &
help_mat(:,:,:)
real(kind=r8_kind),allocatable :: diff_arr_xyz(:,:,:,:),yl_arr_xyz(:,:,:)
real(kind=r8_kind),allocatable :: &
overlap(:,:,:), kinetic(:), &
nuc(:,:,:), nuc_pseudo(:,:,:)
logical :: pseudopot_present ! same name as in UA module
real(kind=r8_kind),allocatable :: nuc_pc_timps(:,:,:)
type(three_center_l) :: xc_int !! coul_int
!! SB: new store for coul_int
!! coul_int(n_irreps)%l(-1:lmx_co)%m(num,ncexps,n_if,mb,ma,n_pa)
type(three_center_l_v2),allocatable :: coul_int(:)
!! end of new stores
type nested2_opt
integer(kind=i4_kind):: n
!??? type(nested2_vars),allocatable,dimension(:)::summands
type(nested2_vars),pointer,dimension(:)::summands
end type nested2_opt
type(nested2_opt),allocatable,dimension(:):: nested2_summands
integer(kind=i4_kind):: nested2_l1_max,nested2_l3_max,l1_max,l3_max
logical:: opt_nested2=.true.
logical :: split3c
real(r8_kind),allocatable :: this(:,:,:) ! (num,nlmA,nlmB)
!!$ real(r8_kind),allocatable :: this5d(:,:,:,:,:) ! (num,1,1,nlmB,nlmA)
real(r8_kind),allocatable :: this6d(:,:,:,:,:,:) ! (num,1,1,nlmB,nlmA,1)
! should it be like that --- AxB, BxA ?! ...
real(r8_kind) :: zexps(1) ! for finite nuc only
logical :: with_timps
integer(i4_kind) :: N_length
FPP_TIMER_DECL(pll)
integer(i4_kind) :: i_ir, i_pa, n_pa
intrinsic max
pseudopot_present = IAND(imode,IPSEU) .ne. 0
DPRINT 'll_calculate: PP=',pseudopot_present,' imode=',imode
! print*, 'in ll_calc'
split3c = present(many_3c)
if(opt_nested2) then
allocate(nested2_summands((lb+1)**2),stat=alloc_stat(1))
if(alloc_stat(1).ne.0) call error_handler('nested2_summands not allocated')
alloc_stat(1)=1
counter=0
nested2_l1_max=0
nested2_l3_max=0
do i_l=0,lb
do mb=1,2*i_l+1
counter=counter+1
nested2_summands(counter)%n=nsum_prod_rule_nested2(la,i_l,mb)
! print*,nested2_summands(counter)%n,'nested2_summands n'
allocate (nested2_summands(counter)%summands(nested2_summands(counter)%n), &
stat=alloc_stat(2))
if(alloc_stat(2).ne.0) call error_handler('2 nested2_summands%summands allocate failed')
alloc_stat(2)=1
call summands_prod_rule_nested2(la,i_l,mb,nested2_summands(counter)%summands,l1_max,l3_max)
if(l1_max.gt.nested2_l1_max) nested2_l1_max=l1_max
if(l3_max.gt.nested2_l3_max) nested2_l3_max=l3_max
end do
end do
endif
one_i=1_i4_kind
zero_i=0_i4_kind
naexps = unique_atoms(na)%l_ob(la)%n_exponents
nbexps = unique_atoms(nb)%l_ob(lb)%n_exponents
allocate( &
fact0_arr(nbexps,naexps), &
fact1_arr(nbexps,naexps), &
fact2_arr(nbexps,naexps), &
cutoff(nbexps,naexps), &
stat=alloc_stat(3))
if (alloc_stat(3).ne.0) call error_handler &
("LL_CALCULATE: allocation (1) failed")
alloc_stat(3)=1
alloc_stat(4)=1 !cutoff
xa = center1
xb = center2
xd =xa-xb
aexps => unique_atoms(na)%l_ob(la)%exponents(:)
bexps => unique_atoms(nb)%l_ob(lb)%exponents(:)
arg=sum(xd**2)
fact0_arr=(spread(aexps,1,nbexps)+spread(bexps,2,naexps))
fact1_arr=(spread(aexps,1,nbexps)*spread(bexps,2,naexps))
where(fact0_arr>=very_small) ! prevent division by zero
fact2_arr=fact1_arr/fact0_arr
elsewhere
fact2_arr=very_big
end where
expmax = options_integral_expmax()
where(fact2_arr*arg> expmax ) ! cutoff: where almost no overlap
cutoff=.false. ! is present calculation is not necessary
elsewhere
cutoff=.true.
end where
num=count(cutoff)
if(num==0) then ! all integrals are equal zero
if (integralpar_2cob_ol) then
prim_int_2cob_ol = 0.0_r8_kind
end if
if (integralpar_2cob_kin) then
prim_int_2cob_kin= 0.0_r8_kind
end if
if (integralpar_2cob_nuc) then
prim_int_2cob_nuc(:,:,:,:)=0.0_r8_kind
end if
if (integralpar_2cob_potential) then
prim_int_2cob_poten(:,:,:,:,:)=0.0_r8_kind !!!!!!!!!!!!!!!
end if
if (integralpar_2cob_field) then
prim_int_2cob_field(:,:,:,:,:)=0.0_r8_kind !!!!!!!!!!!!!!!
end if
if(integralpar_relativistic)then
prim_int_2cob_pvsp = zero
endif
if(integralpar_3c_co) then
prim_int_3c_co=0.0_r8_kind
end if
if(integralpar_3c_xc) then
prim_int_3c_xc=0.0_r8_kind
end if
if( split3c )then
ASSERT(integralpar_relativistic)
many_3c = zero
endif
deallocate(fact0_arr,fact1_arr,&
fact2_arr,cutoff,stat=alloc_stat(3))
if (alloc_stat(3).ne.0) call error_handler &
("LL_CALCULATE: deallocation (1) failed")
alloc_stat(4)=0
!return
goto 999 ! clean up and exit
end if
allocate (&
fact0(num),fact1(num),fact2(num),fact4(num),fact5(num),&
fact6(num),fact7(num),fact8(num),rcsabc(num),tau(num),& !tau 6
gamma_arg(num,3),aexp_arr(num),bexp_arr(num),&
overlap(num,(la+1)**2,(lb+1)**2),& !5
clmamb_scalar((max(la,lb)+1)**2),& !5
clmamb(num,(la+1)**2),& !5
clmamb2(num,(la+1)**2),& !6
diff_arr(num,(la+1)**2,(lb+1)**2),& !5
diff_arr0((la+1)**2,(lb+1)**2),& !5
stat=alloc_stat(5))
if (alloc_stat(5).ne.0) call error_handler &
("LL_CALCULATE: allocation (2) failed")
alloc_stat(5)=1
alloc_stat(6)=1 !tau clmamb2
! AxB
allocate( this(num,2*la+1,2*lb+1), stat=memstat)
ASSERT(memstat==0)
if(split3c)then
! BxA
!!$ allocate( this5d(num,1,1,2*lb+1,2*la+1), stat=memstat)
!!$ ASSERT(memstat==0)
allocate( this6d(num,1,1,2*lb+1,2*la+1,1), stat=memstat)
ASSERT(memstat==0)
endif
if (integralpar_2cob_kin) then
allocate(kinetic(num),stat=alloc_stat(7))
if (alloc_stat(7).ne.0) call error_handler &
("LL_CALCULATE: allocation (3) failed")
alloc_stat(7)=1
end if
if (integralpar_2cob_nuc) then
allocate(nuc(num,2*la+1,2*lb+1), stat=alloc_stat(8))
if (alloc_stat(8).ne.0) call error_handler &
("LL_CALCULATE: allocation (4) failed")
alloc_stat(8)=1
nuc=0.0_r8_kind
if (pseudopot_present) then
allocate(nuc_pseudo(num,2*la+1,2*lb+1), &
stat=alloc_stat(9))
if (alloc_stat(9).ne.0) call error_handler &
("LL_CALCULATE: allocation (4) failed")
alloc_stat(9)=1
nuc_pseudo = 0.0_r8_kind
with_timps = pointcharge_N+n_timps .gt. 0
if (with_timps .and. integralpar_relativistic) then
allocate(nuc_pc_timps(num,2*la+1,2*lb+1), &
stat=alloc_stat(10))
if (alloc_stat(10).ne.0) call error_handler &
("LL_CALCULATE: allocation nuc_pc_timps failed")
alloc_stat(10)=1
nuc_pc_timps = 0.0_r8_kind
endif
end if ! pseudopot_present
end if ! integralpar_2cob_nuc
if (integralpar_2cob_potential) then
allocate(potential(N_points,num,2*la+1,2*lb+1), stat=alloc_stat(11))
if (alloc_stat(11).ne.0) call error_handler &
("LL_CALCULATE: allocation (5) failed")
potential=0.0_r8_kind
allocate(intermed_3c(num), stat=alloc_stat(11))
if (alloc_stat(11).ne.0) call error_handler &
("LL_CALCULATE: allocation (5a) failed")
alloc_stat(11)=1
end if
#if 0
if (integralpar_2cob_field) then
if(calc_normal) then
N_length=N_surface_points
else
N_length=totsym_field_length
end if
allocate(field(N_length,num,2*lb+1,2*la+1), stat=alloc_stat(11))
if (alloc_stat(11).ne.0) call error_handler &
("LL_CALCULATE: allocation (6) failed")
field=0.0_r8_kind
allocate(intermed_3c(num), stat=alloc_stat(11))
if (alloc_stat(11).ne.0) call error_handler &
("LL_CALCULATE: allocation (6a) failed")
alloc_stat(11)=1
end if
#endif
! List of *facts* at the beginning
! fact0 = a + b
! fact1 = a * b
! fact2 = a*b/(a+b)
! fact7= 1/sqrt(a**l*(2l-1)!!)
fact0=pack(fact0_arr,cutoff)
fact1=pack(fact1_arr,cutoff)
fact2=pack(fact2_arr,cutoff)
aexp_arr=pack(spread(aexps,1,nbexps),cutoff)
bexp_arr=pack(spread(bexps,2,naexps),cutoff)
if(opt_nested2) then
allocate(nested2_fac1(size(aexp_arr,1),0:nested2_l3_max), &
nested2_fac2(size(bexp_arr,1),0:nested2_l1_max),stat=alloc_stat(12))
if (alloc_stat(12)/=0) call error_handler("allocation nested2_fac failed")
allocate(nested2_fac12(size(aexp_arr,1),0:nested2_l3_max,0:nested2_l1_max), &
stat=alloc_stat(12))
if (alloc_stat(12)/=0) call error_handler("allocation nested2_fac12 failed")
alloc_stat(12)=1
nested2_fac1(:,0)=1.0_r8_kind
nested2_fac2(:,0)=1.0_r8_kind
do i_l=1,nested2_l3_max
nested2_fac1(:,i_l)=nested2_fac1(:,i_l-1)*(-2.0_r8_kind*aexp_arr)
enddo
do i_l=1,nested2_l1_max
nested2_fac2(:,i_l)=nested2_fac2(:,i_l-1)*(-2.0_r8_kind*bexp_arr)
enddo
do i_l=0,nested2_l3_max
do j_l=0,nested2_l1_max
nested2_fac12(:,i_l,j_l)=nested2_fac1(:,i_l)*nested2_fac2(:,j_l)
enddo
enddo
endif
deallocate(fact0_arr,fact1_arr,fact2_arr,stat=alloc_stat(3))
if (alloc_stat(3)/=0) call error_handler &
("LL_CALCULATE: deallocation (2) failed")
! gamma_arg = (a*vec_a + b*vec_b)/(a + b)
gamma_arg(:,1)=(pack(spread(aexps*xa(1),1,nbexps) + &
spread(bexps*xb(1),2,naexps),cutoff))/fact0
gamma_arg(:,2)=(pack(spread(aexps*xa(2),1,nbexps) + &
spread(bexps*xb(2),2,naexps),cutoff))/fact0
gamma_arg(:,3)=(pack(spread(aexps*xa(3),1,nbexps) + &
spread(bexps*xb(3),2,naexps),cutoff))/fact0
! precalculation of solid harmonics
clmamb_scalar=solid_harmonics_scalar(max(la,lb),xd)
fact4=1.0_r8_kind
counter=1
tau=fact2*arg ! a*b/(a+b)*(A-B)**2
do l=0,la
do m=1,2*l+1
clmamb(:,counter)=clmamb_scalar(counter)*fact4
clmamb2(:,counter)=clmamb_scalar(counter)&
*fact4*(tau-real(l,kind=r8_kind))
counter=counter+1
enddo
fact4=-fact4*fact2*2.0_r8_kind
enddo
! first calculating 2-center integrals----------------
! fact5=fact2*(3.0_r8_kind-2.0_r8_kind*tau+2.0_r8_kind*la)
! a*b/(a+b)(3-2*tau+2*l)
fact6=1.0_r8_kind/sqrt(aexp_arr**la*dfac(la))/&
sqrt(bexp_arr**lb*dfac(lb))*exp(-tau)*&
(4.0_r8_kind*fact2/fact0)**0.75_r8_kind
fact5=fact2*fact6
fact7=(fact2*2.0_r8_kind)**lb
counter=1
do i_l=0,lb
do mb=1,2*i_l+1
diff_arr0(:,counter)=reshape(diff_rule(spread(clmamb_scalar,1,1),&
1,(la+1)**2,counter),(/(la+1)**2/))
counter=counter+1
end do
end do
counter=1
do i_l=0,lb
magnetic_number_b: do mb=1,2*i_l+1
! overlap
overlap(:,1:(la+1)**2,counter)=spread(fact6*(2.0_r8_kind*fact2)**i_l,&
2,(la+1)**2)*&
prod_rule(spread(diff_arr0&
(:,counter),1,num),clmamb(:,:),1,&
(la+1)**2)
counter=counter+1
end do magnetic_number_b
enddo
if (integralpar_2cob_ol) then
do ma=1,2*la+1
do mb=1,2*lb+1
prim_int_2cob_ol(:,:,mb,ma) = unpack&
(overlap(:,la**2+ma,lb**2+mb),cutoff,zero)
end do
end do
end if
if (integralpar_2cob_kin) then
do ma=1,2*la+1
do mb=1,2*lb+1
! kinetic energy
kinetic=fact5*fact7*reshape(prod_rule(spread(diff_arr0&
(:,lb**2+mb),1,num),(3.0_r8_kind+2.0_r8_kind*lb)&
*clmamb(:,:)-2.0_r8_kind*clmamb2,(la)**2+ma,&
(la)**2+ma),(/num/))
! re-map them to the int_data_2cob3c_stuff
prim_int_2cob_kin(:,:,mb,ma)= unpack(kinetic,cutoff,zero)
end do
end do
deallocate(kinetic,STAT=alloc_stat(7))
if (alloc_stat(7).ne.0) call error_handler &
("LL_CACLULATE : deallocation (3) failed")
endif
call integral_interrupt_2cob3c()
deallocate(clmamb2,tau,stat=alloc_stat(6))
if (alloc_stat(6).ne.0) call error_handler &
("LL_CACLULATE : deallocation (4) failed")
! calculate integrals that involve third center,
! i.e. fit integrals, nuclear attraction and relativistic pv scalar p
third_center_required: if ( integralpar_2cob_nuc .or. integralpar_3c_xc &
.or. integralpar_3c_co .or. integralpar_relativistic &
!!! MF merge bug fix
! .or. integralpar_2cob_potential) then
) then
fact8=2.0_r8_kind*sqrt(fact0/pi)
unique_atom_loop: do i=1,n_unique_atoms + n_timps ! loop over third center
if(i<=n_unique_atoms) then
ua_pointer=>unique_atoms(i)
lmax_ch= ua_pointer%lmax_ch ! maximum l for chargefit
lmax_xc= ua_pointer%lmax_xc ! maximum l for xcfit
! determine the maximal angular momentum
ly_max=max(la,lb,lmax_ch,lmax_xc)
if (.not.integralpar_3c_xc) then
lmax_abs=lmax_ch
else
lmax_abs=max(lmax_ch,lmax_xc)
endif
ly_max=max(la,lb,lmax_ch,lmax_xc)
max_order=max(1+la+lb+lmax_abs,3+la+lb)
z= ua_pointer%z ! charge
zc= ua_pointer%zc ! core charge
n_equals=ua_pointer%n_equal_atoms
! NUC and PP is handled by SHGI, skip the NUC:
DPRINT 'll_calc: ua=',i,', zero its charge!'
zc = zero
z = zero
allocate ( &
gamma_help(num,max_order), &
gamma_arg2(num,n_equals), &
stat=alloc_stat(13))
if (alloc_stat(13)/=0) call error_handler &
("LL_CACLULATE : allocation (5) failed")
alloc_stat(13)=1
! --- further allocation ----------------------------------
! num : number of pairs(a,b) which are inside the cutoff
! for s-and r2-type there is only 1 indep. fct
if(integralpar_3c_co_resp) then
#ifdef WITH_RESPONSE
allocate (coul_int(symmetry_data_n_irreps()),stat=alloc_stat(14))
i_ir_alloc_: DO i_ir=1,symmetry_data_n_irreps() !!allocation for coul_int
n_pa = symmetry_data_n_partners(i_ir)
allocate (coul_int(i_ir)%l(-1:lmax_ch),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l failed")
ncexps = ua_pointer%r2_ch%n_exponents
n_independent_fcts = &
ua_pointer%symadapt_partner(i_ir,0)%n_independent_fcts
allocate(coul_int(i_ir)%l(-1)%m(num,ncexps,n_independent_fcts,&
2*lb+1,2*la+1,n_pa),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l(-1)%m failed")
ncexps = ua_pointer%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,n_independent_fcts,&
2*lb+1,2*la+1,n_pa),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l(0)%m failed")
alloc_stat(14)=1
do i_l=1,lmax_ch
ncexps = ua_pointer%l_ch(i_l)%n_exponents
n_independent_fcts = &
ua_pointer%symadapt_partner(i_ir,i_l)%n_independent_fcts
allocate(coul_int(i_ir)%l(i_l)%m(num,ncexps,n_independent_fcts,&
2*lb+1,2*la+1,n_pa),&
stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation (8) failed")
alloc_stat(14)=1
end do
do i_l = -1,lmax_ch
coul_int(i_ir)%l(i_l)%m = 0.0_r8_kind
end do
END DO i_ir_alloc_
#else
ABORT('recompile w/ -DWITH_RESPONSE')
#endif
elseif (integralpar_3c_co) then
i_ir = get_totalsymmetric_irrep()
allocate (coul_int(i_ir),stat=alloc_stat(14))
n_pa = 1
allocate (coul_int(i_ir)%l(-1:lmax_ch),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l failed")
ncexps = ua_pointer%r2_ch%n_exponents
allocate(coul_int(i_ir)%l(-1)%m(num,ncexps,1,2*lb+1,2*la+1,n_pa),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l(-1)%m failed")
ncexps = ua_pointer%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,1,2*lb+1,2*la+1,n_pa),stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation coul_int%l(0)%m failed")
alloc_stat(14)=1
do i_l=1,lmax_ch
ncexps = ua_pointer%l_ch(i_l)%n_exponents
n_independent_fcts = &
ua_pointer%symadapt_partner(i_ir,i_l)%n_independent_fcts
allocate(coul_int(i_ir)%l(i_l)%m(num,ncexps,n_independent_fcts,&
2*lb+1,2*la+1,n_pa),&
stat=alloc_stat(14))
if (alloc_stat(14)/=0) call error_handler &
("LL_CACLULATE : allocation (8) failed")
alloc_stat(14)=1
end do
do i_l = -1,lmax_ch
coul_int(i_ir)%l(i_l)%m = 0.0_r8_kind
end do
end if
if(integralpar_3c_xc) then
allocate (xc_int%l(-1:lmax_xc),stat=alloc_stat(15))
if (alloc_stat(15)/=0) call error_handler &
("LL_CACLULATE : allocation xc_int%l failed")
ncexps = ua_pointer%r2_xc%n_exponents
allocate(xc_int%l(-1)%m(num,ncexps,1,2*lb+1,2*la+1),stat=alloc_stat(15))
if (alloc_stat(15)/=0) call error_handler &
("LL_CACLULATE : allocation xc_int%l(-1)%m failed")
ncexps = ua_pointer%l_xc(0)%n_exponents
allocate(xc_int%l(0)%m(num,ncexps,1,2*lb+1,2*la+1),stat=alloc_stat(15))
if (alloc_stat(15)/=0) call error_handler &
("LL_CACLULATE : allocation xc_int%l(0)%m failed")
alloc_stat(15)=1
xc_int%l(0)%m = 0.0_r8_kind
xc_int%l(-1)%m = 0.0_r8_kind
endif
ly_max=max(la,lb,lmax_ch,lmax_xc)
allocate( &
yl_arr(num,(ly_max+1)**2,n_equals),&
fact10(num,(ly_max+1)**2),&
yl_arr2(num,(ly_max+1)**2,n_equals),&
prod_arr(num,(la+1)**2,(lb+1)**2,0:la+lb,n_equals),&
stat=alloc_stat(16))
if (alloc_stat(16)/=0) call error_handler &
("LL_CACLULATE : allocation (6) failed")
alloc_stat(16)=1
prod_arr=0.0_r8_kind
! do a precalculation of a factor needed for the
! product rule
counter=1
fact4=1.0_r8_kind
do i_l=0,ly_max
do ma=1,2*i_l+1
fact10(:,counter)=fact4
counter=counter+1
enddo
fact4=fact4*aexp_arr/(fact0)
enddo
! precalculate prod_arr and calculate nuclear attraction
call precalculate_and_nuc(this)
if( integralpar_2cob_nuc )then
nuc = nuc + this
endif
if( split3c )then
call unpack_many_3c(this,i,OFF_V,form=AxB)
end if
!
! now calculating fit integrals
!
! XC part was not changed, but separated
! s-type xc fit integrals
if(integralpar_3c_xc) call s_xc()
! r2-type exchange fit integral
if(integralpar_3c_xc) call r2_xc()
! l_type coloumb and exchange fit integral
if(integralpar_3c_xc .or. integralpar_3c_co) then
do i_l=1,lmax_abs
n_independent_fcts = &
ua_pointer%symadapt_partner(1,i_l)%n_independent_fcts
allocate( &
intermediate(num,2*la+1,2*lb+1,n_independent_fcts,n_equals,0:la+lb) &
,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler('LL_CALCULATE: allocation (7) failed')
alloc_stat(17)=1
! symmetry adaption for l-type xc fit integrals
! results are stored in intermediate array
call l_fit_symmetry_adapt()
! now the same for exchange
if(integralpar_3c_xc.and.lmax_xc>=i_l) call l_xc()
deallocate(intermediate,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler &
("LL_CACLULATE : deallocation (5) failed")
end do! loop over lc
! finished with l-type fit integrals
endif
! END of XC part
! Coulomb part was rebuilded for symmetry
if (integralpar_3c_co_resp) then
#ifdef WITH_RESPONSE
i_ir_: do i_ir=1,symmetry_data_n_irreps()
i_pa_: do i_pa=1,symmetry_data_n_partners(i_ir)
i_l = 0 ! r2 and s i_l=0
n_independent_fcts = &
unique_atoms(i)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
! s-type coulomb fit integrals
call s_coulomb( &
unique_atoms(i)%l_ch(0)%exponents(:), &
coul_int(i_ir)%l(0)%m &
)
if( split3c )then
zexps(1) = (3.0_r8_kind/2.0_r8_kind) / unique_atoms(i)%nuclear_radius**2
call s_coulomb( zexps, this6d )
call unpack_many_3c(this6d(:,1,1,:,:,1),i,OFF_VFIN,form=BxA)
end if
! r2-type coloumb fit integral
call r2_coulomb()
end if
! l_type coloumb fit integral
do i_l=1,lmax_ch
n_independent_fcts = &
unique_atoms(i)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
allocate( &
intermediate(num,2*la+1,2*lb+1,n_independent_fcts,n_equals,0:la+lb) &
,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler('LL_CALCULATE: allocation (7) failed')
alloc_stat(17)=1
! symmetry adaption for l-type charge fit integrals
! results are stored in intermediate array
call l_fit_symmetry_adapt_v2(i,i_l,i_ir,i_pa,intermediate)
! coulomb integrals
call l_coulomb()
deallocate(intermediate,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler &
("LL_CACLULATE : deallocation (5) failed")
end if
end do! loop over lc
! finished with l-type fit integrals
end do i_pa_
end do i_ir_
#else
ABORT('recompile w/ -DWITH_RESPONSE')
#endif
elseif (integralpar_3c_co) then
i_ir = get_totalsymmetric_irrep()
i_pa = 1
i_l = 0 ! r2 and s i_l=0
n_independent_fcts = &
unique_atoms(i)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
!!$ allocate( &
!!$ intermediate(num,2*la+1,2*lb+1,n_independent_fcts,n_equals,0:la+lb) &
!!$ ,stat=alloc_stat(17))
!!$ if (alloc_stat(17)/=0) call error_handler('LL_CALCULATE: allocation (7) failed')
!!$ alloc_stat(17)=1
!!$ call l_fit_symmetry_adapt_v2(i,i_l,i_ir,i_pa,intermediate)
! s-type coulomb fit integrals
call s_coulomb( &
unique_atoms(i)%l_ch(0)%exponents(:), &
coul_int(i_ir)%l(0)%m &
)
if( split3c )then
zexps(1) = (3.0_r8_kind/2.0_r8_kind) / unique_atoms(i)%nuclear_radius**2
call s_coulomb( zexps, this6d )
call unpack_many_3c(this6d(:,1,1,:,:,1),i,OFF_VFIN,form=BxA)
end if
! r2-type coloumb fit integral
call r2_coulomb()
!!$ deallocate(intermediate,stat=alloc_stat(17))
!!$ if (alloc_stat(17)/=0) call error_handler &
!!$ ("LL_CACLULATE : deallocation (5) failed")
end if
! l_type coloumb fit integral
if(integralpar_3c_co .and. old_3c_co) then
do i_l=1,lmax_ch
n_independent_fcts = &
unique_atoms(i)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
allocate( &
intermediate(num,2*la+1,2*lb+1,n_independent_fcts,n_equals,0:la+lb) &
,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler('LL_CALCULATE: allocation (7) failed')
alloc_stat(17)=1
! symmetry adaption for l-type charge fit integrals
! results are stored in intermediate array
call l_fit_symmetry_adapt_v2(i,i_l,i_ir,i_pa,intermediate)
! coulomb integrals
call l_coulomb()
deallocate(intermediate,stat=alloc_stat(17))
if (alloc_stat(17)/=0) call error_handler &
("LL_CACLULATE : deallocation (5) failed")
end if
end do! loop over lc
! finished with l-type fit integrals
endif
end if
! contract the fit integrals with respect to fit dimension
! and write them to their final location in int_data_2cob3c_module
if(integralpar_3c_co_resp) then
#ifdef WITH_RESPONSE
call fitcontract_v2(num,i,cutoff,coul_int)
do i_ir=1,symmetry_data_n_irreps()
do i_l = -1, lmax_ch
deallocate(coul_int(i_ir)%l(i_l)%m,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l%m failed")
enddo
deallocate (coul_int(i_ir)%l,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l failed")
end do
deallocate(coul_int,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l failed")
#else
ABORT('recompile w/ -DWITH_RESPONSE')
#endif
elseif(integralpar_3c_co) then
call fitcontract_v2(num,i,cutoff,coul_int)
i_ir=get_totalsymmetric_irrep()
do i_l = -1, lmax_ch
deallocate(coul_int(i_ir)%l(i_l)%m,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l%m failed")
enddo
deallocate (coul_int(i_ir)%l,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l failed")
deallocate(coul_int,STAT=alloc_stat(14))
if(alloc_stat(14).ne.0) call error_handler &
("LL_CALCULATE : deallocation coul_int%l failed")
endif
if(integralpar_3c_xc) then
call fitcontract('xc',num,i,cutoff,xc_int)
do i_l = -1, lmax_xc
deallocate(xc_int%l(i_l)%m,STAT=alloc_stat(15))
if(alloc_stat(15).ne.0) call error_handler &
("LL_CALCULATE : deallocation xc_int%l%m failed")
enddo
deallocate (xc_int%l,STAT=alloc_stat(15))
if(alloc_stat(15).ne.0) call error_handler &
("LL_CALCULATE : deallocation xc_int%l failed")
end if
deallocate(yl_arr,yl_arr2,gamma_help,gamma_arg2,fact10,&
prod_arr,stat=alloc_stat(13)) !gamma_help,gamma_arg2
if (alloc_stat(13)/=0) call error_handler &
("LL_CALCULATE : deallocation (7) failed")
alloc_stat(16)=0 ! yl_arr,yl_arr2 fact10 prod_arr
! end do unique_atom_loop
else !timp
ua_pointer=>unique_timps(i-n_unique_atoms)
z= ua_pointer%z ! charge
zc= ua_pointer%zc ! core charge
n_equals=ua_pointer%n_equal_atoms
end if
if(zc/=0.0_r8_kind .and. .not.integralpar_2cob_potential) then ! pseudopotential contributions
ABORT('not supported')
endif ! end of pseudopotential contributions
end do unique_atom_loop
! add contribution of point charges to nuclear attraction
if ( (integralpar_2cob_nuc .or. integralpar_relativistic) &
.and. pointcharge_N+n_timps .gt. 0) call add_pointcharges()
end if third_center_required
DPRINT 'TIMER: ll_pseudo=',FPP_TIMER_VALUE(pll)
if (integralpar_2cob_potential.and.old_potential) call calc_potential() !!!!!!!!!!!!!!!!1
#if 0
if (integralpar_2cob_field ) &
call calc_field() !!!!!!!!!!!!!!!!!
#endif
if (integralpar_2cob_nuc) then
if (pseudopot_present &
.and.(.not.integralpar_relativistic)) then
do mb=1,2*lb+1
do ma=1,2*la+1
prim_int_2cob_nuc(:,:,mb,ma)= &
unpack(nuc(:,ma,mb)+nuc_pseudo(:,ma,mb),cutoff,zero)
enddo
end do
else ! i.e. relativistic
do mb=1,2*lb+1
do ma=1,2*la+1
prim_int_2cob_nuc(:,:,mb,ma)=unpack(nuc(:,ma,mb),cutoff,zero)
enddo
enddo
if(pseudopot_present) then
do mb=1,2*lb+1
do ma=1,2*la+1
prim_int_2cob_nuc_pseudo(:,:,mb,ma)=unpack(nuc_pseudo(:,ma,mb),cutoff,zero)
enddo
enddo