forked from alexei-matveev/paragauss-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls_calculate.f90
1764 lines (1539 loc) · 64.3 KB
/
ls_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 ls_calculate(na,nb,la_in,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,l1,equal_atom2).
! 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 (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 symmetry_data_module,only: symmetry_data_n_irreps, &
symmetry_data_n_partners,&
get_totalsymmetric_irrep
use calc3c_switches,only: old_potential,old_3c_co,old_elfield
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_in ! 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(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, &
three_half=1.5_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 /)
logical,allocatable :: cutoff(:,:)
integer(kind=i4_kind) :: num,counter,m,ma,alloc_stat
integer(kind=i4_kind) :: memstat
! 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
real(kind=r8_kind),allocatable,dimension(:,:,:) :: gamma_help
! help arrays for solid harmincs
real(kind=r8_kind),allocatable :: yl_arr(:,:,:)
real(kind=r8_kind),allocatable :: clmamb(:,:),clmamb_scalar(:)
! help arrays for product_rule and diff_rule
real(kind=r8_kind),allocatable :: prod_arr(:,:,:,:),&
diff_arr(:,:),intermediate(:,:,:,:,:)
real(kind=r8_kind) :: arg
! cartesian coordinates
real(kind=r8_kind),dimension(3) :: xa,xb,xc,xd
logical :: laltlb ! flag to decide if la is lower then lb or not
integer(kind=i4_kind) :: i,j,i_la,i_lb,i_l,k,i_ind,i_cnt,nm_la,nm_lb,&
la_org,lb_org,la,l !,l_cg
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 :: overlap(:,:), &
kinetic(:),aexp_arr(:)
real(kind=r8_kind),allocatable,dimension(:,:) :: nuc
real(kind=r8_kind),allocatable,dimension(:,:,:) :: potential
#if 0
real(kind=r8_kind),allocatable,dimension(:,:,:) :: field
#endif
real(kind=r8_kind),allocatable,dimension(:) :: intermed_3c
real(kind=r8_kind),allocatable :: prod_arr_gr(:,:,:,:),help_arr_gr(:,:,:,:)
real(kind=r8_kind),allocatable :: diff_arr_grad(:,:,:),rsaba(:),overlap1(:,:)
real(kind=r8_kind),allocatable,dimension(:,:) :: nuc_pc_timps
real(kind=r8_kind),allocatable,dimension(:,:) :: nuc_pseudo
real(kind=r8_kind) :: expmax
logical :: pseudopot_present ! same name is in UA module
type(three_center_l) :: xc_int
type(three_center_l_v2),allocatable :: coul_int(:)
type(unique_atom_type), pointer :: ua_pointer
logical :: split3c
real(r8_kind), allocatable :: this(:,:) ! (num,nlma)
!!$ real(r8_kind), allocatable :: this5d(:,:,:,:,:) ! (num,1,1,nlmB,nlmA)
real(r8_kind), allocatable :: this6d(:,:,:,:,:,:) ! (num,1,1,nlmB,nlmA)
real(r8_kind) :: zexps(1) ! for finite nuc only
logical :: with_timps
integer(i4_kind) :: N_length !!!!!!!!!!!!
FPP_TIMER_DECL(pls)
integer(i4_kind) :: i_ir, i_pa, n_pa
intrinsic max
pseudopot_present = IAND(imode,IPSEU) .ne. 0
DPRINT 'ls_calculate: PP=',pseudopot_present,' imode=',imode
split3c = present(many_3c)
nm_la=2*la_in+1
nm_lb=2*lb+1
la_org=la_in
lb_org=lb
naexps = unique_atoms(na)%l_ob(la_in)%n_exponents
nbexps = unique_atoms(nb)%l_ob(lb)%n_exponents
if(lb>la_in) then
laltlb=.true.
la=lb
else
laltlb=.false.
la=la_in
end if
allocate( &
fact0_arr(nbexps,naexps), &
fact1_arr(nbexps,naexps), &
fact2_arr(nbexps,naexps), &
cutoff(nbexps,naexps), &
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation fact0_arr ... failed")
xa = center1 ! from int_data_module
xb = center2 ! from int_data_module
xd =xa-xb
aexps => unique_atoms(na)%l_ob(la_in)%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)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: deallocation fact0_arr ... failed")
return
end if
allocate ( &
fact0(num), fact1(num), fact2(num), fact4(num), &
fact5(num), fact6(num), fact7(num), fact8(num), &
aexp_arr(num), rcsabc(num), tau(num),&
overlap(num,2*la+1), &
gamma_arg(num,3),&
clmamb_scalar((la+1)**2), &
clmamb(num,(la+1)**2), &
diff_arr(num,(la+1)**2), &
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation fact0 ... failed")
allocate(this(num,2*la+1),stat=memstat)
ASSERT(memstat==0)
if( split3c )then
! original (true) dimensions nm_la, nm_lb:
allocate(this6d(num,1,1,nm_lb,nm_la,1),stat=memstat)
ASSERT(memstat==0)
endif
if (integralpar_2cob_kin) then
allocate(kinetic(num),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation kinetic failed")
end if
if (integralpar_2cob_nuc) then
allocate(nuc(num,2*la+1),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation failed")
nuc=0.0_r8_kind
if (pseudopot_present) then
allocate(nuc_pseudo(num,2*la+1),&
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation(nuc_pseudo) failed")
nuc_pseudo=0.0_r8_kind
end if
with_timps = pointcharge_N +n_timps .gt. 0
if ( integralpar_relativistic .and. pseudopot_present .and. &
with_timps ) then
allocate(nuc_pc_timps(num,2*la+1),&
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation(nuc_pc_timps) failed")
nuc_pc_timps=0.0_r8_kind
endif !
end if ! integralpar_2cob_nuc
if (integralpar_2cob_potential.and.old_potential) then
allocate(potential(N_points,num,2*la+1),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation of potential failed")
potential=0.0_r8_kind
allocate(intermed_3c(num),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation of intermed_3c failed")
end if
#if 0
if (integralpar_2cob_field.and.old_elfield) then
if( calc_normal) then
N_length=N_surface_points
else
N_length=totsym_field_length
end if
allocate(field(N_length,num,2*la+1),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation of field failed")
field=0.0_r8_kind
allocate(intermed_3c(num),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CALCULATE: allocation of intermed_3c for field failed")
end if
#endif
! List of *facts* at the beginning
! fact0 = a + b
! fact1 = a * b
! fact2 = a*b/(a+b)
fact0=pack(fact0_arr,cutoff)
fact1=pack(fact1_arr,cutoff)
fact2=pack(fact2_arr,cutoff)
if(.not.laltlb) then
aexp_arr=pack(spread(aexps,1,nbexps),cutoff)
else
aexp_arr=pack(spread(bexps,2,naexps),cutoff)
end if
deallocate(fact0_arr,fact1_arr,fact2_arr,stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation fact0_arr ... 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
if(laltlb) then
xd=-xd
end if
! precalculation of solid harmonics
clmamb_scalar=solid_harmonics_scalar(la,xd)
fact4=1.0_r8_kind
counter=1
do i=0,la
do m=1,2*i+1
clmamb(:,counter)=clmamb_scalar(counter)*fact4
counter=counter+1
enddo
fact4=-fact4*fact2*2.0_r8_kind
enddo
! first calculating 2-center integrals----------------
tau=fact2*arg
fact5=fact2*(3.0_r8_kind-2.0_r8_kind*tau+2*la) ! a*b/(a+b)(3-2*tau+2*l)
fact6=1.0_r8_kind/sqrt(aexp_arr**la*dfac(la))*exp(-tau)*&
(4.0_r8_kind*fact2/fact0)**0.75_r8_kind !
fact2=2.0_r8_kind*fact6*sqrt(fact0/pi)
if(.not.laltlb) then
if (integralpar_2cob_ol) then
magnetic_number: do m=1,2*la+1
! overlap
overlap(:,m)=fact6*clmamb(:,(la)**2+m)
! re-map them to the int_data_2cob3c_stuff
prim_int_2cob_ol(:,:,1,m) = unpack(overlap(:,m),cutoff,zero)
end do magnetic_number
end if
if (integralpar_2cob_kin) then
magnetic_number_kin: do m=1,2*la+1
! kinetic energy
kinetic=fact5*overlap(:,m)
! re-map them to the int_data_2cob3c_stuff
prim_int_2cob_kin(:,:,1,m)=unpack(kinetic,cutoff,zero)
end do magnetic_number_kin
endif
else
if (integralpar_2cob_ol) then
magnetic_number_2: do m=1,2*la+1
! overlap
overlap(:,m)=fact6*clmamb(:,(la)**2+m)
! re-map them to the int_data_2cob3c_stuff
prim_int_2cob_ol(:,:,m,1) = unpack(overlap(:,m),cutoff,zero)
end do magnetic_number_2
end if
if (integralpar_2cob_kin) then
magnetic_number_kin_2: do m=1,2*la+1
! kinetic energy
kinetic=fact5*overlap(:,m)
! re-map them to the int_data_2cob3c_stuff
prim_int_2cob_kin(:,:,m,1)=unpack(kinetic,cutoff,zero)
end do magnetic_number_kin_2
endif
end if
if (integralpar_2cob_kin) then
deallocate(kinetic,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CACLULATE : deallocation kinetic failed")
endif
!!! deallocate(tau,fact5,overlap,stat=alloc_stat)
deallocate(tau,fact5,stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("LS_CACLULATE : deallocation tau ... failed")
call integral_interrupt_2cob3c()
! 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 &
) then
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
if (integralpar_3c_xc) then
lmax_abs=lmax_ch
else
lmax_abs=max(lmax_ch,lmax_xc)
endif
ly_max=max(la,lmax_ch,lmax_xc)
max_order=max(1+la+lmax_abs,3+la)
z= ua_pointer%z ! charge
zc = ua_pointer%zc ! charge
n_equals=unique_atoms(i)%n_equal_atoms
! NUC and PP is handled by SHGI, skip the NUC:
DPRINT 'ls_calc: ua=',i,', zero its charge!'
zc = zero
z = zero
allocate ( &
gamma_help(num,max_order,n_equals), &
gamma_arg2(num,n_equals), &
fact10(num,(ly_max+1)**2), &
stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LL_CACLULATE : allocation gamma_help ... failed")
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
allocate( &
yl_arr(num,(ly_max+1)**2,n_equals), &
prod_arr(num,(la+1)**2,0:la,n_equals), &
stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation yl_arr, prod_arr failed")
! calculate help arrays and 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)
end if
! --- 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)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l failed")
i_ir_alloc_: DO i_ir=1,symmetry_data_n_irreps()
n_pa = symmetry_data_n_partners(i_ir)
allocate (coul_int(i_ir)%l(-1:lmax_ch),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l failed")
ncexps = unique_atoms(i)%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,&
nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(-1)%m failed")
ncexps = unique_atoms(i)%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,n_independent_fcts,&
nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(0)%m failed")
coul_int(i_ir)%l(0)%m = 0.0_r8_kind
coul_int(i_ir)%l(-1)%m = 0.0_r8_kind
do i_l=1,lmax_ch
ncexps = unique_atoms(i)%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,&
nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(0)%m failed")
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)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l failed")
n_pa = 1
allocate (coul_int(i_ir)%l(-1:lmax_ch),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l failed")
ncexps = unique_atoms(i)%r2_ch%n_exponents
allocate(coul_int(i_ir)%l(-1)%m(num,ncexps,1,nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(-1)%m failed")
ncexps = unique_atoms(i)%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,1,nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(0)%m failed")
coul_int(i_ir)%l(0)%m=0.0_r8_kind
coul_int(i_ir)%l(-1)%m=0.0_r8_kind
do i_l=1,lmax_ch
ncexps = unique_atoms(i)%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,&
nm_lb,nm_la,n_pa),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation coul_int%l(0)%m failed")
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)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation xc_int%l failed")
ncexps = unique_atoms(i)%r2_xc%n_exponents
allocate(xc_int%l(-1)%m(num,ncexps,1,nm_lb,nm_la),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation xc_int%l(-1)%m failed")
ncexps = unique_atoms(i)%l_xc(0)%n_exponents
allocate(xc_int%l(0)%m(num,ncexps,1,nm_lb,nm_la),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("LS_CACLULATE : allocation xc_int%l(0)%m failed")
xc_int%l(0)%m=0.0_r8_kind
xc_int%l(-1)%m=0.0_r8_kind
endif
!
! now calculating XC fit integrals
!
! s-type xc integrals
if(integralpar_3c_xc) call s_xc()
! now treating r2-type exchange integral
if(integralpar_3c_xc) call r2_xc()
! l-type fit integrals
do i_l=1,lmax_abs
n_independent_fcts = &
unique_atoms(i)%symadapt_partner(1,i_l)%n_independent_fcts
allocate(intermediate(num,2*la+1,n_independent_fcts,n_equals,0:la),&
stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: allocation intermediate failed")
! precalculate symmetry adaption and store result in intermediate
call l_fit_symmetry_adapt()
! l-type exchange integrals
if(integralpar_3c_xc.and.lmax_xc>=i_l) call l_xc()
deallocate(intermediate,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation intermediate failed")
end do! loop over lc
! finished with l-type fit integrals
!
! - CO calculations
!
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
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
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 )
if( laltlb )then
call unpack_many_3c(this6d(:,1,1,:,1,1),i,OFF_VFIN)
else
call unpack_many_3c(this6d(:,1,1,1,:,1),i,OFF_VFIN)
endif
end if
! r2-type coloumb integral
call r2_coulomb()
end if
! l-type fit integrals
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,n_independent_fcts,n_equals,0:la),&
stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: allocation intermediate failed")
! precalculate symmetry adaption and store result in intermediate
call l_fit_symmetry_adapt_v2()
! l-type coulomb integrals
call l_coulomb
deallocate(intermediate,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation intermediate failed")
end if
end do! loop over lc
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
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
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 )
if( laltlb )then
call unpack_many_3c(this6d(:,1,1,:,1,1),i,OFF_VFIN)
else
call unpack_many_3c(this6d(:,1,1,1,:,1),i,OFF_VFIN)
endif
end if
! r2-type coloumb integral
call r2_coulomb()
end if
! l-type fit integrals
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,n_independent_fcts,n_equals,0:la),&
stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: allocation intermediate failed")
! precalculate symmetry adaption and store result in intermediate
call l_fit_symmetry_adapt_v2()
! l-type coulomb integrals
call l_coulomb
deallocate(intermediate,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation intermediate failed")
end if
end do! loop over lc
end if
!
! - End of CO calculations
!
! 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)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation coul_int%l%m failed")
end do
deallocate (coul_int(i_ir)%l,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation coul_int%l failed")
end do
deallocate (coul_int,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("LS_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)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation coul_int%l%m failed")
end do
deallocate (coul_int(i_ir)%l,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation coul_int%l failed")
deallocate (coul_int,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("LS_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)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation xc_int%l%m failed")
enddo
deallocate (xc_int%l,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("LS_CALCULATE : deallocation xc_int%l failed")
end if
deallocate(yl_arr,gamma_help,gamma_arg2,fact10,&
prod_arr,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation yl_arr ... failed")
else
ua_pointer=>unique_timps(i-n_unique_atoms)
n_equals=ua_pointer%n_equal_atoms
z= ua_pointer%z ! charge
zc = ua_pointer%zc ! charge
end if
if(zc/=0.0_r8_kind .and. .not. integralpar_2cob_potential) then ! pseudopotential
ABORT('not supported')
end if ! 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) then
call add_pointcharges()
endif
end if third_center_required
DPRINT 'TIMER: ls_pseudo=',FPP_TIMER_VALUE(pls)
if (integralpar_2cob_potential.and.old_potential) &
call calc_potential() !!!!!!!!!!!!!!
#if 0
if (integralpar_2cob_field .and. old_elfield) &
call calc_field() !!!!!!!!!!!!!!
#endif
deallocate(overlap,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation overlap failed")
! remap nuc to the appropriate data structure
if (integralpar_2cob_nuc) then
if (pseudopot_present.and.(.not.integralpar_relativistic)) then
if(.not.laltlb) then
do m=1,2*la+1
prim_int_2cob_nuc(:,:,1,m)=unpack(nuc(:,m)+&
nuc_pseudo(:,m),cutoff,zero)
enddo
else
do m=1,2*la+1
prim_int_2cob_nuc(:,:,m,1)=unpack(nuc(:,m)+&
nuc_pseudo(:,m),cutoff,zero)
enddo
end if
else ! relativistic
if(.not.laltlb) then
do m=1,2*la+1
prim_int_2cob_nuc(:,:,1,m)=unpack(nuc(:,m),cutoff,zero)
enddo
else
do m=1,2*la+1
prim_int_2cob_nuc(:,:,m,1)=unpack(nuc(:,m),cutoff,zero)
enddo
endif
if(pseudopot_present) then
if(.not.laltlb) then
do m=1,2*la+1
prim_int_2cob_nuc_pseudo(:,:,1,m)=unpack(nuc_pseudo(:,m),cutoff,zero)
enddo
else
do m=1,2*la+1
prim_int_2cob_nuc_pseudo(:,:,m,1)=unpack(nuc_pseudo(:,m),cutoff,zero)
enddo
endif
with_timps = pointcharge_N +n_timps .gt. 0
if( with_timps ) then
! add point charge and TIMP to PP contributions
if(.not.laltlb) then
do m=1,2*la+1
prim_int_2cob_nuc_pseudo(:,:,1,m)=prim_int_2cob_nuc_pseudo(:,:,1,m) &
+ unpack(nuc_pc_timps(:,m),cutoff,zero)
enddo
else
do m=1,2*la+1
prim_int_2cob_nuc_pseudo(:,:,m,1)=prim_int_2cob_nuc_pseudo(:,:,m,1) &
+ unpack(nuc_pc_timps(:,m),cutoff,zero)
enddo
endif
endif
endif ! pseudopot_present
end if ! else of PP and not rel
deallocate(nuc,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation nuc failed")
if (pseudopot_present) then
deallocate(nuc_pseudo,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation nuc_pseudo failed")
end if
!!! call print_nuclear()
end if
if (integralpar_2cob_potential.and.old_potential) then
if(.not.laltlb) then
do i=1,N_points
do m=1,2*la+1
!restoring needed for VPP
intermed_3c(:)=potential(i,:,m)
prim_int_2cob_poten(:,:,i,1,m)=unpack(intermed_3c(:),cutoff,zero)
enddo
enddo
else
do i=1,N_points
do m=1,2*la+1
intermed_3c(:)=potential(i,:,m)
prim_int_2cob_poten(:,:,i,m,1)=unpack(intermed_3c(:),cutoff,zero)
enddo
enddo
end if
deallocate(potential,stat=alloc_stat) !!!!!!!!!!!!!!!
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation potential failed")
deallocate(intermed_3c,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation intermed_3c failed")
endif
#if 0
if (integralpar_2cob_field .and. old_elfield) then
if(calc_normal) then
N_length=N_surface_points
else
N_length=totsym_field_length
end if
if(.not.laltlb) then
do i=1,N_length
do m=1,2*la+1
intermed_3c(:)=field(i,:,m)
prim_int_2cob_field(:,:,i,1,m)=unpack(intermed_3c,cutoff,zero)
enddo
enddo
else
do i=1,N_length
do m=1,2*la+1
intermed_3c(:)=field(i,:,m)
prim_int_2cob_field(:,:,i,m,1)=unpack(intermed_3c,cutoff,zero)
enddo
enddo
end if
deallocate(field,stat=alloc_stat)
if(alloc_stat/=0) call error_handler &
("LS_CALCULATE: deallocation field failed")
deallocate(intermed_3c,stat=alloc_stat)