@@ -17,8 +17,11 @@ subroutine CVS_phULR(TDA,nSa,nSb,nSt,Aph,Bph,EcRPA,Om,XpY,XmY)
1717! Local variables
1818
1919 double precision ,external :: trace_matrix
20- complex * 16 ,allocatable :: RPA_matrix(:,:)
21- complex * 16 ,allocatable :: OmOmminus(:)
20+ double precision ,allocatable :: RPA_matrix(:,:)
21+ complex * 16 ,allocatable :: complex_RPA_matrix(:,:)
22+ double precision ,allocatable :: vectors(:,:)
23+ double precision ,allocatable :: OmOmminus(:)
24+ integer :: i
2225
2326! Output variables
2427
@@ -38,34 +41,63 @@ subroutine CVS_phULR(TDA,nSa,nSb,nSt,Aph,Bph,EcRPA,Om,XpY,XmY)
3841
3942 else
4043
41- allocate (RPA_matrix(2 * nSt,2 * nSt),OmOmminus(2 * nSt))
44+ allocate (RPA_matrix(2 * nSt,2 * nSt),vectors( 2 * nSt, 2 * nSt), OmOmminus(2 * nSt))
4245
43- RPA_matrix(1 :nSt,1 :nSt) = cmplx ( Aph(:,:),0d0 ,kind= 8 )
44- RPA_matrix(1 :nSt,nSt+1 :2 * nSt) = cmplx ( Bph(:,:),0d0 ,kind= 8 )
45- RPA_matrix(nSt+1 :2 * nSt,1 :nSt) = cmplx (- Bph(:,:),0d0 ,kind= 8 )
46- RPA_matrix(nSt+1 :2 * nSt,nSt+1 :2 * nSt) = cmplx (- Aph(:,:),0d0 ,kind= 8 )
46+ RPA_matrix(1 :nSt,1 :nSt) = Aph(:,:)
47+ RPA_matrix(1 :nSt,nSt+1 :2 * nSt) = Bph(:,:)
48+ RPA_matrix(nSt+1 :2 * nSt,1 :nSt) = - Bph(:,:)
49+ RPA_matrix(nSt+1 :2 * nSt,nSt+1 :2 * nSt) = - Aph(:,:)
50+
51+ call diagonalize_general_matrix(2 * nSt,RPA_matrix,OmOmminus,vectors)
52+
53+ RPA_matrix(:,:) = vectors(:,:)
54+
55+ deallocate (vectors)
56+
57+ call sort_eigenvalues_RPA(2 * nSt,OmOmminus,RPA_matrix)
58+
59+ allocate (complex_RPA_matrix(2 * nSt,2 * nSt))
60+
61+ complex_RPA_matrix = cmplx (0.0d0 , 0.0d0 , kind= 8 )
62+ complex_RPA_matrix(1 :nSt, 1 :nSt) = cmplx (RPA_matrix(:,:), 0.0d0 , kind= 8 )
63+ complex_RPA_matrix = cmplx (RPA_matrix(:,:),RPA_matrix(:,:)* 0d0 ,kind= 8 )
64+
65+ deallocate (RPA_matrix)
66+
67+ call complex_normalize_RPA(nSt,complex_RPA_matrix)
4768
48- call complex_diagonalize_matrix_without_sort(2 * nSt,RPA_matrix,OmOmminus)
49- call complex_sort_eigenvalues_RPA(2 * nSt,OmOmminus,RPA_matrix)
50- call complex_normalize_RPA(nSt,RPA_matrix)
51- call rotate_vectors_to_real_axis(2 * nSt,nSt,RPA_matrix(1 :2 * nSt,1 :nSt))
52-
53- Om(:) = real (OmOmminus(1 :nSt))
5469 if (maxval (abs (OmOmminus(1 :nSt)+ OmOmminus(nSt+1 :2 * nSt))) > 1e-8 ) then
5570 call print_warning(' We dont find a Om and -Om structure as solution of the RPA. There might be a problem somewhere.' )
5671 write (* ,* ) " Maximal difference :" , maxval (abs (OmOmminus(1 :nSt)+ OmOmminus(nSt+1 :2 * nSt)))
5772 end if
58- if (maxval (abs (aimag (OmOmminus(:))))>1d-8 )&
59- call print_warning(' You may have instabilities in linear response: complex excitation eigenvalue !' )
60- if (maxval (aimag (RPA_matrix(1 :2 * nSt,1 :nSt)))>1d-8 ) then
73+
74+ Om(:) = OmOmminus(1 :nSt)
75+
76+ deallocate (OmOmminus)
77+
78+ ! Set transition vectors of zero modes to 0
79+ do i= 1 ,nSt
80+ if (abs (Om(i))<1d-8 ) then
81+ complex_RPA_matrix(:,i) = (0d0 ,0d0 )
82+ complex_RPA_matrix(:,i+ nSt) = (0d0 ,0d0 )
83+ end if
84+ end do
85+
86+
87+ if (maxval (aimag (complex_RPA_matrix(1 :2 * nSt,1 :nSt)))>1d-8 ) then
6188 call print_warning(' You may have instabilities in linear response: complex transition vectors !' )
62- print * , " Max imag value X+Y:" ,maxval (aimag (transpose (RPA_matrix(1 :nSt,1 :nSt) + RPA_matrix(nSt+1 :2 * nSt,1 :nSt))))
63- print * , " Max imag value X-Y:" ,maxval (aimag (transpose (RPA_matrix(1 :nSt,1 :nSt) - RPA_matrix(nSt+1 :2 * nSt,1 :nSt))))
89+ print * , " Max imag value X+Y:" ,maxval (aimag (transpose (complex_RPA_matrix(1 :nSt,1 :nSt) + complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))),&
90+ " at" ,maxloc (aimag (transpose (complex_RPA_matrix(1 :nSt,1 :nSt) + complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt))))
91+
92+ print * , " Max imag value X-Y:" ,maxval (aimag (transpose (complex_RPA_matrix(1 :nSt,1 :nSt) - complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))),&
93+ " at" ,maxloc (aimag (transpose (complex_RPA_matrix(1 :nSt,1 :nSt) - complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt))))
6494 end if
65- XpY(:,:) = transpose (real (RPA_matrix(1 :nSt,1 :nSt) + RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))
66- XmY(:,:) = transpose (real (RPA_matrix(1 :nSt,1 :nSt) - RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))
67- deallocate (RPA_matrix,OmOmminus)
6895
96+ XpY(:,:) = transpose (real (complex_RPA_matrix(1 :nSt,1 :nSt) + complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))
97+ XmY(:,:) = transpose (real (complex_RPA_matrix(1 :nSt,1 :nSt) - complex_RPA_matrix(nSt+1 :2 * nSt,1 :nSt)))
98+
99+ deallocate (complex_RPA_matrix)
100+
69101 end if
70102
71103! Compute the RPA correlation energy
0 commit comments