-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_operator_spatial_space_omp.f90
More file actions
1849 lines (1443 loc) · 59.1 KB
/
module_operator_spatial_space_omp.f90
File metadata and controls
1849 lines (1443 loc) · 59.1 KB
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
!===============================================================================
! calc. the matrix element of kinetic energy and nuclei attractive
! potential, dipole matrix in fedvr_3d, spherial coordiante
!===============================================================================
module operator_spatial_space
use global
use operator_3d
use wfunction
use twoe_basis_set
use fedvr3d_basis_set
implicit none
complex(kind=k2),allocatable,save :: ham_onebody(:),xmat_spatial_space(:),&
ymat_spatial_space(:),zmat_spatial_space(:),dvdxmat_spatial_space(:),&
dvdymat_spatial_space(:),dvdzmat_spatial_space(:)
complex(kind=k2),allocatable,save :: ch_dummy(:,:)
complex(kind=k2),allocatable,save :: tei_spatial(:,:,:,:),cww(:,:,:,:)
complex(kind=k2), allocatable, save :: mean_field_lm(:,:,:)
!! mean_field_lm is the Mean Field Operator written in the coupled basis.
!! Arguments
!!
!! #1 Coupled basis function
!! #2 Orbital which is complex conjugated (coming from the bra).
!! #3 Orbital which is not complex conjujated (coming from the ket).
!!
contains
!
! calc. the onebody operator in the spatial space
!
subroutine update_ham_onebody_spatial_space()
implicit none
integer :: i_spatial,j_spatial,k_temp
integer :: i_angle,i_r
integer :: i_row_r,i_column_r,i_row,i_column,index_here
integer :: idicp,jdicp,kdicp,idicp_prime,jdicp_prime
real(kind=k1) ::h_onebody
complex(kind=k2):: sumtemp,sumtemp_laser_term
integer:: iangle,ibra,iket,iorb !! indexes for the loops.
integer :: iangle_bra, iangle_ket !! indexes for the loops in angular functions
integer:: norbital, nbasis !! number of orbitals and basis fuctions.
integer:: nbasis_r !! number of radial fucntions
integer:: l_basis !!angular momentum
real(kind=k1) :: ang_x, ang_y, ang_z !! \cos\theta,\sin\theta\cos\phi, and \sin\theta\sin\phi contributions
!! for the differents functions.
complex(kind=k2),dimension(fedvr3d%nb_r*fedvr3d%nb_angle,system%nptot) :: korb
interface
function OMP_get_thread_num()
integer :: OMP_get_thread_num
end function OMP_get_thread_num
function OMP_get_num_procs()
integer :: OMP_get_num_procs
end function OMP_get_num_procs
function OMP_get_num_threads()
integer :: OMP_get_num_threads
end function OMP_get_num_threads
function OMP_get_max_threads()
integer :: OMP_get_num_threads
end function OMP_get_max_threads
subroutine omp_set_num_threads(num_threads)
integer, intent(in) :: num_threads
end subroutine omp_set_num_threads
!!$ function omp_set_num_threads()
!!$ integer :: OMP_set_num_threads
!!$ End function omp_set_num_threads
function OMP_get_nested()
logical :: OMP_get_nested
end function OMP_get_nested
subroutine OMP_set_nested(enable)
logical, intent(in) :: enable
end subroutine OMP_set_nested
end interface
nbasis_r=fedvr3d%nb_r !! number of radial functions
! allocate(ham_onebody(system%nptot*(system%nptot+1)/2))
k_temp = 0
do i_spatial =1, system%nptot
do j_spatial =1,i_spatial
k_temp = k_temp +1
!
! the total number of non-zero matrix element of ham_onebody
!
sumtemp = zzero
do i_angle =1, fedvr3d%nb_angle
do i_r = 1,n_total_kinetic
i_row_r = index_kinetic_basis(i_r,1)
i_column_r = index_kinetic_basis(i_r,2)
i_row = (i_angle-1)*fedvr3d%nb_r + i_row_r
i_column = (i_angle-1)*fedvr3d%nb_r + i_column_r
! index_here = ia(max(i_row_r,i_column_r) + min(i_row_r,i_column_r))
! if(i_row == i_column) then
! h_onebody = tmat_3d(i_row_r,i_angle) + vmat_radial(i_row_r) + tmat_radial(index_here)
! endif
! if(i_row /= i_column) then
! h_onebody = tmat_radial(index_here)
! endif
! sumtemp = sumtemp + dconjg(phi(i_row,i_spatial))*phi(i_column,j_spatial)*h_onebody
if(i_row==i_column) then
sumtemp = sumtemp + dconjg(phi(i_row,i_spatial))*phi(i_column,j_spatial)*&
(tmat_3d(i_row_r,i_angle) +vmat_radial(i_row_r) + tmat_radial(i_r) )
endif
if(i_row /= i_column) then
sumtemp = sumtemp + dconjg(phi(i_row,i_spatial))*phi(i_column,j_spatial)* tmat_radial(i_r) + &
dconjg(phi(i_column,i_spatial))*phi(i_row,j_spatial)* tmat_radial(i_r)
endif
enddo
enddo
!=========================================================================================================
! laser field term, add here
!=========================================================================================================
sumtemp_laser_term = zzero
If (laser%tdornot) then
!!PARALLELIZE HERE
!$OMP PARALLEL PRIVATE(iangle_bra,ang_x,ang_y,ang_z,iket)
!$OMP DO SCHEDULE(dynamic)
Do iangle_ket=1,size(lm_l(:))!! run in the angular functions of the ket
Do iangle_bra=1,size(lm_l(:)) !! run in the angular functions of the bra
ang_x=xmat_3d(iangle_bra,iangle_ket) !! angular contribution of x direction
ang_y=ymat_3d(iangle_bra,iangle_ket) !! angular contribution of y direction
ang_z=zmat_3d(iangle_bra,iangle_ket) !! angular contribution of z direction
Do iket=1,nbasis_r !! run in the radial basis
korb(nbasis_r*(iangle_bra-1)+iket,j_spatial)=korb(nbasis_r*(iangle_bra-1)+iket,j_spatial)+phi(nbasis_r*(iangle_ket-1)+iket,j_spatial)*fedvrx_global(iket)*(laser%ex_t*ang_x+laser%ey_t*ang_y*ci+laser%ez_t*ang_z)
!! multiply by the imaginary unity the contribution in the Y direction.
!! Add the absorbing potential
If (iangle_ket.eq.iangle_bra) then
korb(nbasis_r*(iangle_ket-1)+iket,j_spatial)=korb(nbasis_r*(iangle_ket-1)+iket,j_spatial)+phi(nbasis_r*(iangle_ket-1)+iket,j_spatial)*vabsorb_pot_fedvr3d(iket)*ci !! we add the imaginary unit here, which is part of the absorbing potential.
End If
End Do !! iket
!! initialize the variables
ang_x=zero
ang_y=zero
ang_z=zero
End Do !! iangle_bra
End Do !! iangle_ket
!$OMP END DO
!$OMP END PARALLEL
sumtemp_laser_term=dot_product(phi(:,i_spatial),korb(:,j_spatial)) !! laser and absorbing potential contribution
End If
ham_onebody(k_temp) = sumtemp + sumtemp_laser_term
enddo
enddo
return
end subroutine update_ham_onebody_spatial_space
!
! stiffness onebody operator
!
subroutine update_ham_onebody_spatial_space2()
implicit none
integer :: i_spatial,j_spatial
integer :: idicp,jdicp,kdicp,ldicp,idicp_prime,jdicp_prime
complex(kind=k2) :: sumtemp,sumtemp_laser_term
do i_spatial =1,system%nptot
do j_spatial =1,i_spatial
sumtemp = zzero
do idicp =1,fedvr3d%nb_angle
ldicp = 0
do jdicp =(idicp-1)*fedvr3d%nb_r+1,(idicp-1)*fedvr3d%nb_r+fedvr3d%nb_r
do kdicp =(idicp-1)*fedvr3d%nb_r+1,jdicp
ldicp = ldicp +1
if(jdicp/=kdicp) then
sumtemp = sumtemp + (dconjg(phi(jdicp,i_spatial))*phi(kdicp,j_spatial) + &
dconjg(phi(kdicp,i_spatial))*phi(jdicp,j_spatial))*h_stiffness(ldicp,idicp)
else
sumtemp = sumtemp + dconjg(phi(jdicp,i_spatial))*phi(kdicp,j_spatial)*h_stiffness(ldicp,idicp)
endif
enddo
enddo
enddo
!=========================================================================================================
! laser field term, add here
!=========================================================================================================
sumtemp_laser_term = zzero
if(laser%tdornot) then
do idicp =1,fedvr3d%nb_angle
do jdicp =1, fedvr3d%nb_angle
do kdicp =1,fedvr3d%nb_r
idicp_prime = (idicp-1)*fedvr3d%nb_r + kdicp
jdicp_prime = (jdicp-1)*fedvr3d%nb_r + kdicp
sumtemp_laser_term = sumtemp_laser_term + dconjg(phi(idicp_prime,i_spatial ))* phi(jdicp_prime,j_spatial)*&
(zmat_3d(idicp,jdicp)*fedvrx_global(kdicp)*laser%ez_t)
If (idicp_prime.eq.jdicp_prime) then
sumtemp_laser_term=sumtemp_laser_term+ci*vabsorb_pot_fedvr3d(kdicp)*dconjg(phi(idicp_prime,i_spatial ))* phi(jdicp_prime,j_spatial)
End If
!!$ print*, 'vabsorb_pot_fedvr3d is not well used here -stif-'
!!$ print*, 'module_operator_spatial_space.f90'
!!$ stop
! sumtemp_laser_term = sumtemp_laser_term + dconjg(phi(idicp_prime,i_spatial ))* phi(jdicp_prime,j_spatial)*&
! xmat_3d(idicp,jdicp)*fedvrx_global(kdicp)*laser%ex_t
! sumtemp_laser_term = sumtemp_laser_term + dconjg(phi(idicp_prime,i_spatial ))* phi(jdicp_prime,j_spatial)*&
! ymat_3d(idicp,jdicp)*fedvrx_global(kdicp)*ci*laser%ey_t
enddo
enddo
enddo
endif
ham_onebody(ia(i_spatial)+j_spatial ) = sumtemp + sumtemp_laser_term
enddo
enddo
return
end subroutine update_ham_onebody_spatial_space2
!
! stiffness onebody operator !! Done by Juan
!
subroutine update_ham_onebody_spatial_space_stif_2(orb,hl,laserp,ham1body)
implicit none
integer:: i_spatial, j_spatial,counter
!! INPUT
complex(kind=k2), allocatable, intent(in) :: orb(:,:)
!! orb stores the orbitals
!! Arguments
!!
!! #1: component of the global basis (FE-DVR+Angular).
!! #2: number of the orbital.
real(kind=k1), allocatable, intent(in) :: hl(:,:,:)
!! Hamiltonian after the stiffness procedure.
!! The hamiltonian matrix is the same for each value of the
!! angular momentum l.
!! Arguments
!!
!! #1: FE-DVR function of the bra.
!! #2: FE-DVR function of the ket.
!! #3: Angular momentum of the Hamiltonian, l.
!!
type(laser_prime), intent(in) :: laserp
!! laserp stores the properties of the laser
!! OUTPUT
complex(kind=k2), allocatable, intent(inout) :: ham1body(:)
!! ham1body stores the one body hamiltonian <phi_i|H|phi_j>.
!! <phi_i|H|phi_j>=ham1body(i(i-1)/2+j), with j<=i
!! AUXILIAR
complex(kind=k2), dimension(fedvr3d%nb_r*fedvr3d%nb_angle,system%nptot) :: korb_aux
!! korb_aux stores the orbitals after applying the one body
!! Hamiltonian.
!! Arguments
!!
!! #1: component of the global basis (FE-DVR+Angular).
!! #2: number of the orbital.
!! First, apply the one body Hamiltonian on the orbitals
call act_stif_2(orb,hl, laserp,korb_aux)
ham1body=zzero !! initialize
do i_spatial =1,system%nptot
do j_spatial =1,i_spatial
counter=i_spatial*(i_spatial-1)/2+j_spatial
!! counter stores half of the matrix
ham1body(counter)=ham1body(counter)+dot_product(orb(:,i_spatial),korb_aux(:,j_spatial))
enddo
enddo
!!$ if (allocated(korb_aux)) deallocate(korb_aux) !! DEBUG 11/5/2015
return
end subroutine update_ham_onebody_spatial_space_stif_2
!
! twobody operator in spatial space
!
!
!
! calc. the CWW matrix, mean field operator
!
!
!
! calc. the mean field operator matrix in fedvr-3d
!
subroutine update_twobody_spatial_space
implicit none
integer :: imo,jmo,kmo,lmo,i_fedvr3d,j_fedvr3d,k_fedvr3d,l_fedvr3d
integer :: n1,l1,m1,n2,l2,m2,n3,l3,m3,n4,l4,m4
complex(kind=k2) :: sumtemp
real(kind=k1) :: rtemp
integer :: idicp,jdicp,itwo,kdicp,ldicp,mdicp,ndicp,i_global,j_global
real(kind=k1) :: start,finish
select case (fedvr3d%store)
case (0) !! do not store cww
call two_body_orbitals(tei_spatial)
case (1) !! stores cww
cww = zzero
do jdicp =1, fedvr3d%nb_angle
do idicp =1, fedvr3d%nb_r*fedvr3d%nb_angle
do itwo = 1, num_two(idicp,jdicp)
kdicp = index_two_storage(1,itwo,idicp,jdicp)
ldicp = index_two_storage(2,itwo,idicp,jdicp)
do ndicp =1, system%nptot
do mdicp = 1, system%nptot
cww(idicp,jdicp,mdicp,ndicp) = cww(idicp,jdicp,mdicp,ndicp) + &
dconjg(phi(kdicp,mdicp)) * phi(ldicp,ndicp) *two_storage(itwo,idicp,jdicp)
enddo
enddo
enddo
enddo
enddo
! cal. two-electron repulsive in spatial space
!
! * *
! fi(1) fj(1) fk(2) fl(2)
!
do jmo =1, system%nptot
do lmo = 1,system%nptot
do kmo =1, system%nptot
do imo =1, system%nptot
sumtemp = zzero
do j_fedvr3d =1,fedvr3d%nb_angle
do i_fedvr3d =1,fedvr3d%nb_r*fedvr3d%nb_angle
i_global = index_two(1,i_fedvr3d,j_fedvr3d)
j_global = index_two(2,i_fedvr3d,j_fedvr3d)
sumtemp = sumtemp + dconjg(phi(i_global,imo))*phi(j_global,jmo)*cww(i_fedvr3d,j_fedvr3d,kmo,lmo)
enddo
enddo
tei_spatial(imo,kmo,lmo,jmo) = sumtemp
enddo
enddo
enddo
enddo
continue
case(2) !! coupled case
!! Transforms the product of two orbitals to the coupled representation
call mean_field_and_phikl(twoe_radial_store, phi, llmm_lm, mean_field_lm, phi_coupled)
!! calculation of the two-body element
call two_body_coupled(mean_field_lm,phi_coupled,tei_spatial)
continue
End select
return
end subroutine update_twobody_spatial_space
!
! update xyzmat_spatial_space
!
subroutine update_xyzmat_spatial_space(xyzmat_3d,ndim,xyzmat_spatial,mdim)
implicit none
integer :: i_spatial,j_spatial,ktemp,i_row,i_column
integer,intent(in) :: ndim,mdim
real(kind=k1),intent(in) :: xyzmat_3d(ndim,ndim)
complex(kind=k2),intent(out) :: xyzmat_spatial(mdim*(mdim+1)/2)
complex(kind=k2) :: sumtemp
integer :: i_angle,j_angle,k_r
ktemp =0
do i_spatial =1, mdim ! nptot
do j_spatial =1,i_spatial
ktemp = ktemp +1
sumtemp =zzero
do i_angle =1, ndim ! fedvr3d%nb_angle
do j_angle =1, ndim ! fedvr3d%nb_angle
if(xyzmat_3d(i_angle,j_angle)/=0.0d0) then !!??? !! This line is not correct!!! : JUAN found mistake
do k_r =1,fedvr3d%nb_r
i_row = (i_angle-1)*ndim + k_r
i_column = (j_angle-1)*ndim + k_r
sumtemp = sumtemp + dconjg(phi(i_row,i_spatial))*phi(i_column,j_spatial)*fedvrx_global(k_r)*&
xyzmat_3d(i_angle,j_angle)
enddo
endif
enddo
enddo
xyzmat_spatial(ktemp) = sumtemp
enddo
enddo
return
end subroutine update_xyzmat_spatial_space
!
! update dvdxyz_spatial_space for hhg
!
subroutine update_dvdxyzmat_spatial_space(xyzmat_3d,ndim,dvxyzmat_spatial,mdim)
implicit none
integer :: i_spatial,j_spatial,ktemp,i_row,i_column
complex(kind=k2) :: sumtemp
integer,intent(in) :: ndim,mdim
real(kind=k1),intent(in) :: xyzmat_3d(ndim,ndim)
complex(kind=k2),intent(out) :: dvxyzmat_spatial(mdim*(mdim+1)/2)
integer :: i_angle,j_angle,k_r
ktemp =0
do i_spatial =1, mdim !system%nptot
do j_spatial =1,i_spatial
ktemp = ktemp +1
sumtemp =zzero
do i_angle =1,ndim !fedvr3d%nb_angle
do j_angle =1,ndim !fedvr3d%nb_angle
if(xmat_3d(i_angle,j_angle)/=0.0d0) then
do k_r =1,fedvr3d%nb_r
i_row = (i_angle-1)*ndim + k_r
i_column = (j_angle-1)*ndim + k_r
sumtemp = sumtemp + dconjg(phi(i_row,i_spatial))*phi(i_column,j_spatial)*&
xyzmat_3d(i_angle,j_angle)
enddo
endif
enddo
enddo
dvxyzmat_spatial(ktemp) = sumtemp
enddo
enddo
return
end subroutine update_dvdxyzmat_spatial_space
!! This subroutines are done by Juan to avoid the storing of the two body operators
!! Calculate the average the due to the two electrons interaction integrating in one coordinate for two orbitals ph1 and phi2
Function cww_calc(chi1,chi2_ang,phi1,phi2)
implicit none
integer :: chi1, chi2, chi2_ang !! FEDVR functions
!! chi1 is the global FEDVR of the first DVR.
!! chi2 is the angular part of the second DVR function.
integer :: phi1, phi2 !! orbitals
complex(kind=k2) :: cww_calc
!!Auxiliar variables
integer :: kdicp, ldicp, ldicp_ang,kdicp_ang, kdicp_radial
integer :: kdicp_end,ldicp_ang_end
integer :: n1, l1,m1,n2,l2,m2,n3,l3,m3,l4,m4
integer :: k, kp,ll, ang1,ang2, lmin,lmax,ang3,ang4, ii
real(kind=k1) :: twoe_fedvr_aux, twoe_fedvr_angle,twoe_fedvr_radial
!!$allocate(a(1:fedvr3d%nb_r,1:fedvr3d%nb_r,1:2*fedvr3d%nb_angle))
!!$print*, size(a)
!!$stop
If (chi1.gt.fedvr3d%nb_r*fedvr3d%nb_angle) then
print*, 'ERROR IN cww_calc'
stop
end If
If (chi2_ang.gt.fedvr3d%nb_angle) then
print*, 'ERROR IN cww_calc'
stop
end If
!! For the FEDVR function
n1=global_to_local(chi1,1)
l1=global_to_local(chi1,2)
m1=global_to_local(chi1,3)
chi2=(chi2_ang-1)*fedvr3d%nb_r+n1
n2=n1
l2=global_to_local(chi2,2)
m2=global_to_local(chi2,3)
cww_calc=cmplx(0.0d0,0.0d0)
If (phi1.gt.system%np0+system%np1) then !! Conditions for the core
kdicp_end=fedvr3d%nb_r*fedvr3d%nb_angle
Else
kdicp_end=fedvr3d%nb_r*ang_max_core
End If
If (phi2.gt.system%np0+system%np1) then !! Conditions for the core
ldicp_ang_end=fedvr3d%nb_angle
Else
ldicp_ang_end=ang_max_core
End If
ang1=(chi1-n1)/fedvr3d%nb_r+1 !angular for the first function
ang2=chi2_ang ! angular for the second function
Do kdicp=1, kdicp_end!fedvr3d%nb_r*fedvr3d%nb_angle ! Juan: 25 November
If (abs(phi(kdicp,phi1)).lt.1d-10) cycle
n3=global_to_local(kdicp,1) !!Juan: 25 november
kdicp_radial=n3
kdicp_ang=(kdicp-n3)/fedvr3d%nb_r+1
l3=lm_l(kdicp_ang)
m3=lm_m(kdicp_ang)
Do ldicp_ang=1,ldicp_ang_end!fedvr3d%nb_angle !! Run in the angular FEDVR basis for the angular part (since the radial is the same).
ldicp=(ldicp_ang-1)*fedvr3d%nb_r+n3
If (abs(phi(ldicp,phi2)).lt.1d-10) cycle
If (abs(conjg(phi(kdicp,phi1))*phi(ldicp,phi2)).lt.1d-15) cycle
l4=lm_l(ldicp_ang)
m4=lm_m(ldicp_ang)
If ((m1-m2).ne.(m4-m3)) cycle
If (max(abs(l1-l2), abs(l3-l4)).gt.min((l1+l2), (l3+l4))) cycle
Do ll=max(abs(l1-l2), abs(l3-l4)), min((l1+l2), (l3+l4))
twoe_fedvr_angle=fedvr3dbase_angpart(ll,l1,m1,l2,m2,l3,m3,l4,m4)!!twoe_angle_store(ang1,chi2_ang,kdicp_ang,ldicp_ang,ll)
!!$ If (abs(twoe_fedvr_angle).lt.1d-15) cycle
!!$ twoe_fedvr_aux=zero
twoe_fedvr_aux=twoe_radial_store(n1,n3,ll)*twoe_fedvr_angle !!twoe_angle_store(ang1,ang2,ang3,ang4,ll) !! Juan: 25 November
cww_calc = cww_calc + conjg(phi(kdicp,phi1))*phi(ldicp,phi2)*twoe_fedvr_aux !! Juan: I have included this (November 24th)
End Do
Enddo
End Do
return
End Function cww_calc
Subroutine two_body_orbitals(tei_spatial)
implicit none
complex(kind=k2),allocatable, intent(inout) :: tei_spatial(:,:,:,:) !! orbitals
!!Auxiliary variable
complex(kind=k2) :: sumtemp
integer :: imo,jmo,kmo,lmo,i_fedvr3d,j_fedvr3d
integer :: i_global, j_global
complex(kind=k2),allocatable,save :: tei_spatial_proc(:,:,:,:,:)
integer :: num_proc,proc !! number of processes
interface
function OMP_get_thread_num()
integer :: OMP_get_thread_num
end function OMP_get_thread_num
function OMP_get_num_procs()
integer :: OMP_get_num_procs
end function OMP_get_num_procs
function OMP_get_num_threads()
integer :: OMP_get_num_threads
end function OMP_get_num_threads
function OMP_get_max_threads()
integer :: OMP_get_num_threads
end function OMP_get_max_threads
subroutine omp_set_num_threads(num_threads)
integer, intent(in) :: num_threads
end subroutine omp_set_num_threads
!!$ function omp_set_num_threads()
!!$ integer :: OMP_set_num_threads
!!$ End function omp_set_num_threads
function OMP_get_nested()
logical :: OMP_get_nested
end function OMP_get_nested
subroutine OMP_set_nested(enable)
logical, intent(in) :: enable
end subroutine OMP_set_nested
end interface
If (allocated(tei_spatial)) then
continue
else
!! If tei_spatial is not allocated, do it!
allocate(tei_spatial(1:system%nptot,1:system%nptot,1:system%nptot,1:system%nptot))
End If
tei_spatial=zzero !! initialize the two body integrals
!! AUXILIARY VARIABLES FOR PARALLELIZATION
!! SET MAX NUM OF THREADS
!!$ call OMP_set_num_threads(4)
proc=OMP_get_num_procs()
if (allocated(tei_spatial_proc)) then
continue
else
allocate(tei_spatial_proc(0:proc-1,1:system%nptot,1:system%nptot,1:system%nptot,1:system%nptot)) !! to parallelize
!! this is the contribution of each processor
End if
tei_spatial_proc=zzero
!!PARALLELIZE HERE
!$OMP PARALLEL PRIVATE(j_fedvr3d,i_global,j_global,imo,jmo,kmo,lmo)
!$OMP DO SCHEDULE(dynamic)!, 2200)
do i_fedvr3d =1,fedvr3d%nb_r*fedvr3d%nb_angle
do j_fedvr3d =1,fedvr3d%nb_angle
i_global = i_fedvr3d
j_global = (j_fedvr3d-1)*fedvr3d%nb_r+global_to_local(i_fedvr3d,1)
do imo =1, system%nptot !! Run in orbitals
If (abs(phi(i_global,imo)).lt.1d-10) cycle !! Juan: change 14 november AQUI
do jmo =1, system%nptot !! Run in orbitals
If (abs(conjg(phi(i_global,imo))*phi(j_global,jmo)).lt.1d-10) cycle !! Juan: change 13 november AQUI
do kmo =1, system%nptot !! Run in orbitals
do lmo = 1,system%nptot !! Run in orbitals
tei_spatial_proc(OMP_get_thread_num(),imo,kmo,lmo,jmo)=&
tei_spatial_proc(OMP_get_thread_num(),imo,kmo,lmo,jmo)+&
dconjg(phi(i_global,imo))*cww_calc(i_fedvr3d,j_fedvr3d,kmo,lmo)*phi(j_global,jmo)
enddo
enddo
enddo
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
Do num_proc=0,proc-1
!! sum all the contributions
tei_spatial(:,:,:,:)=tei_spatial(:,:,:,:)+tei_spatial_proc(num_proc,:,:,:,:)
End Do
deallocate(tei_spatial_proc)
return
End Subroutine two_body_orbitals
!! End of the subroutines to avoid the storing of the two body matrix
!! SUBROUTINES TO BUILD THE MEAN FIELD OPERATOR USING THE FOURIER TRANSFORM.
Subroutine al_make(k_max,fedvr_r,l_max,al,fl) !!CHECK
implicit none
!! INPUT
!! Maximum linear momentum considered
real (kind=k1) :: k_max
!! Nodes of the FE-DVR for the position space.
real (kind=k1), intent(in), allocatable :: fedvr_r(:)
!! Maximum value of the orbital angular momentum.
integer, intent(in) :: l_max
!! OUTPUT
!! Operator A_L, which performs the Fourier Transform for fixed angular momentum
!! L of reduced wavefunctions (wavefunctions multiplied by the radial coordinate)
!! The Fourier Transform goes as F\psi= \sqrt(2/\pi)\times (-i)**L A_L\psi
!! Arguments
!! #1 is the row of the matrix. It changes with the momentum
!! #2 is the row of the matrix. It changes with the position
!! #3 labels the angular momentum of each matrix.
real (kind=k1), intent(out), allocatable :: al(:,:,:)
!! fl is the matrix which performs the operation to obtain the mean field operator. It collects the operations F(-1)(W(k)F(phi*phi)). In matricial form, this operation can be approximated as f_l=a_l**(inverse) W(k) a_l = a_l**(transpose)*a_l.
real (kind=k1), intent(out), allocatable :: fl(:,:,:)
!! The transpose of al is the Inverse Fourier Transform applied to the Fourier transform of the potential.
!! AUXILIAR VARIABLES
integer :: nk, nr !! number of nodes on each FE-DVR, momentum and position.
integer :: i, j,k,l !! indexes to run the loop
!! needed for initial_fedvr3d_radial_momentum
integer, allocatable :: element(:), basis(:)
real(kind=k1), allocatable :: fedvr_k_node(:,:), fedvr_k_weight(:,:)
real(kind=k1), allocatable :: fedvr_k_total(:), fedvr_k_weight_total(:)
!! SPHERICAL BESSEL FUNCTIONS
INTERFACE
Function besselj(n,x)
integer :: n
real*8 :: x
real*8 :: besselj
End Function besselj
END INTERFACE
nr=size(fedvr_r) !! size of the position FE-DVR
!! Construct the FE-DVR in the momentum space to build the matrix al and fl.
call initial_fedvr3d_radial_momentum(k_max, 0.0d0,which_element,which_basis,fedvr_k_weight,fedvr_k_node, fedvr_k_total)
!! Allocate the FE-DVR in momentum space with the same size than in spatial space. This can be modified.
nk=size(fedvr_k_total) !! size of the momentum FE-DVR.
allocate(fedvr_k_weight_total(1:nk)) !! allocate the global weights.
!! Rearrange the weights
Do j=1,size(which_element)-1
If (which_basis(j).gt.which_basis(j+1)) then !! if the functions is a border of the element.
fedvr_k_weight_total(j)=fedvr_k_weight(which_element(j),which_basis(j))+fedvr_k_weight(which_element(j)+1,1)
Else !! if it is not a border of the element
fedvr_k_weight_total(j)=fedvr_k_weight(which_element(j),which_basis(j))
End If
End Do
fedvr_k_weight_total(nk)= fedvr_k_weight(which_element(nk),which_basis(nk))!! Last weight function
!! Deallocate the variables that we do not need.
deallocate(fedvr_k_weight,fedvr_k_node)
!! We construct the matrices for each angular momentum
allocate(al(1:nk,1:nr,0:2*l_max)) !! allocate the memory for the matrices.
allocate(fl(1:nr,1:nr,0:2*l_max)) !! allocate the memory for the matrices.
al=zero !! Initialize the matrices.
fl=zero
Do l=0,2*l_max !! Run for the angular momentum
Do j=1,nr !! Run for the position grid
Do i=1,nk !! Run for the momentum grid
al(i,j,l)=besselj(l,fedvr_k_total(i)*fedvr_r(j))
End Do
End Do
!! calculation of the the matrix fl.
Do j=1,nr !! Running in the indexes of fl. These indexes correspond to the
!! position space.
Do i=1,nr
Do k=1,nk !! Runing in the internal indexes fo al. This index corresponds to the momentum
fl(i,j,l)=fl(i,j,l)+al(k,i,l)*al(k,j,l)*fedvr_k_weight_total(k)
End Do
End Do
End Do
End Do
deallocate(fedvr_k_weight_total,fedvr_k_total)
fl=4.0d0*pi*fl !! we include the factor 4\pi, which comes from the transform of the coulomb potential
return
End Subroutine al_make
!!=====================================================================
!!
!! phikphil_to_phikl transforms two orbitals from uncoupled basis to
!! the coupled basis. Note that the operation is
!!
!! phi_k* phi_l -> phi_{kl}
!!
!!=====================================================================
Subroutine phikphil_to_phikl(phi, c_llmm_lm, phi_coupled)
implicit none
!! INPUT
complex (kind=k2), allocatable, intent(in):: phi(:,:) !! orbitals in the uncoupled basis
type (llmm_lm_type), intent(in) :: c_llmm_lm !! coefficients which link the uncouple basis with the coupled basis for Spherical Harmonics.
!! OUTPUT
complex (kind=k2), allocatable, intent(out) :: phi_coupled(:,:,:) !! orbitals in the coupled basis
!! AUXILIAR VARIABLES
integer :: i, j, k, l
integer :: alpha, beta, gamma !! number of angular functions.
real(kind=k1) :: aux_coupling
integer :: alpha_max, beta_max, gamma_max !! total number of angular functions.
integer :: nr !! number of radial points.
integer :: num_couplings !! length of the c_llmm_lm matrix
interface
function OMP_get_thread_num()
integer :: OMP_get_thread_num
end function OMP_get_thread_num
function OMP_get_num_procs()
integer :: OMP_get_num_procs
end function OMP_get_num_procs
function OMP_get_num_threads()
integer :: OMP_get_num_threads
end function OMP_get_num_threads
function OMP_get_max_threads()
integer :: OMP_get_num_threads
end function OMP_get_max_threads
subroutine omp_set_num_threads(num_threads)
integer, intent(in) :: num_threads
end subroutine omp_set_num_threads
!!$ function omp_set_num_threads()
!!$ integer :: OMP_set_num_threads
!!$ End function omp_set_num_threads
function OMP_get_nested()
logical :: OMP_get_nested
end function OMP_get_nested
subroutine OMP_set_nested(enable)
logical, intent(in) :: enable
end subroutine OMP_set_nested
end interface
!! Check which is the largest value of the gamma.
alpha_max=maxval(c_llmm_lm%alpha(:))
beta_max=maxval(c_llmm_lm%beta(:))
gamma_max=maxval(c_llmm_lm%gamma(:))
nr=size(phi(:,1))/alpha_max !! since phi(1:nr*alpha_max)
!! allocate the coupling functions.
If (allocated(phi_coupled)) then
continue
else
allocate(phi_coupled(1:nr*gamma_max,size(phi(1,:)),size(phi(1,:))))
End If
!! initialize the coupling functions.
phi_coupled=zzero
!! number of couplings among angular momentum
num_couplings=size(c_llmm_lm%alpha(:))
!!PARALLELIZE HERE
!$OMP PARALLEL PRIVATE(l,i,alpha,beta,gamma,aux_coupling,j)
!$OMP DO SCHEDULE(dynamic)!, 2200)
Do k=1,size(phi(1,:)) !! Run in the orbitals for the complex conjugate
Do l=1,size(phi(1,:)) !! Run in the orbitals
Do i=1, num_couplings !! Run in the non-vanishing couplings of the angular functions.
alpha=c_llmm_lm%alpha(i) !! Y_alpha*
beta=c_llmm_lm%beta(i) !! Y_beta
gamma=c_llmm_lm%gamma(i) !! Y_gamma
aux_coupling=c_llmm_lm%value(i) !! Coupling(alpha, beta, gamma)
Do j=1,nr !! Run in the FE-DVR
phi_coupled(nr*(gamma-1)+j,k,l)= phi_coupled(nr*(gamma-1)+j,k,l)+aux_coupling*conjg(phi(nr*(alpha-1)+j,k))*phi(nr*(beta-1)+j,l)
End Do
End Do
End Do
End Do
!$OMP END DO
!$OMP END PARALLEL
return
End Subroutine phikphil_to_phikl
!!=============================================================
!!
!! Calculation of the Mean Field Operator using the angular
!! coupled basis.
!!
!! The output is an array of vectors written in the coupled
!! basis. Each of them corresponds to the vector phi_k* phi_l.
!!
!! Subroutine: mean_field_coupled
!!
!!=============================================================
Subroutine mean_field_coupled(fl,phi_coupled,lmax,mmax,lmax_coupled, mean_field)
implicit none
!! INPUT
real(kind=k1), allocatable, intent(in) :: fl(:,:,:)
!! fl performs the operation to obtain the mean field operator using
!! the coupled basis
!!
!! Arguments
!! #1 is the row of the L block.
!! #2 is the column of the L block.
!! #3 is the L block matrix.
complex(kind=k2), allocatable, intent(in) :: phi_coupled(:,:,:)
!! phi_coupled(:,k,l) is the product of two orbital functions
!! phi(:,k)* phi(:,l) in the coupled basis.
!!
!! Arguments
!! #1 is the coefficient in the coupled basis.
!! #2 and #3 just explained above.
integer, intent(in) :: lmax,mmax ,lmax_coupled
!! lmax is the maximum value of the orbital angular momentum.
!! mmax is the maximum value of the orbital magnetic quantum number.
!! lmax_coupled is the maximum component in the coupled representation
!! OUTPUT
complex(kind=k2), allocatable, intent(inout) :: mean_field(:,:,:)
!! Mean field is the the mean field operator.
!! Arguments
!!
!! #1 is the coefficient in the coupled basis.
!! #2 orbital complex conjugated.
!! #3 orbital without complex conjugate.
!! AUXILIAR
integer :: l_i,m_i,k, counter
integer :: l !! auxiliar variable to store temporarily the
!! total angular momentum.
integer :: nr, nangle, nrangle, norbital
!! nr is the number of radial poits
!! nangle is the number of angular functions (in the coupled basis)
!! nrangle is the number of functions of the radial and angular functions
!! in the coupled basis
!! norbital is the number of orbitals
integer :: orb1, orb2 !! indeces in the loops for the orbitals.
integer :: r1, r2 !! indeces for the loops in the radial part.