mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-23 12:56:14 +01:00
Cleaned Davidson
This commit is contained in:
parent
8c93d3b1a8
commit
1446bf9ace
@ -640,8 +640,10 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
include 'constants.include.F'
|
include 'constants.include.F'
|
||||||
|
|
||||||
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
||||||
if (N_st_diag > sze) then
|
if (N_st_diag*3 > sze) then
|
||||||
stop 'error in Davidson : N_st_diag > sze'
|
print *, 'error in Davidson :'
|
||||||
|
print *, 'Increase n_det_max_jacobi to ', N_st_diag*3
|
||||||
|
stop -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
PROVIDE nuclear_repulsion
|
PROVIDE nuclear_repulsion
|
||||||
@ -763,10 +765,11 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
1.d0, U, size(U,1), S, size(S,1), &
|
1.d0, U, size(U,1), S, size(S,1), &
|
||||||
0.d0, s_, size(s_,1))
|
0.d0, s_, size(s_,1))
|
||||||
|
|
||||||
! Diagonalize S^2
|
! ! Diagonalize S^2
|
||||||
! ---------------
|
! ! ---------------
|
||||||
call lapack_diag(s2,y,s_,size(s_,1),shift2)
|
!
|
||||||
|
! call lapack_diag(s2,y,s_,size(s_,1),shift2)
|
||||||
|
!
|
||||||
! ! Rotate H in the basis of eigenfunctions of s2
|
! ! Rotate H in the basis of eigenfunctions of s2
|
||||||
! ! ---------------------------------------------
|
! ! ---------------------------------------------
|
||||||
!
|
!
|
||||||
@ -823,7 +826,7 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
if (s2_eig) then
|
if (s2_eig) then
|
||||||
logical :: state_ok(N_st_diag*davidson_sze_max)
|
logical :: state_ok(N_st_diag*davidson_sze_max)
|
||||||
do k=1,shift2
|
do k=1,shift2
|
||||||
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.3d0)
|
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.6d0)
|
||||||
enddo
|
enddo
|
||||||
else
|
else
|
||||||
state_ok(k) = .True.
|
state_ok(k) = .True.
|
||||||
@ -844,39 +847,43 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
endif
|
endif
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
! Compute overlap with U_in
|
if (state_following) then
|
||||||
! -------------------------
|
|
||||||
|
|
||||||
integer :: coord(2), order(N_st_diag)
|
! Compute overlap with U_in
|
||||||
overlap = -1.d0
|
! -------------------------
|
||||||
do k=1,shift2
|
|
||||||
do i=1,shift2
|
integer :: coord(2), order(N_st_diag)
|
||||||
overlap(k,i) = dabs(y(k,i))
|
overlap = -1.d0
|
||||||
|
do k=1,shift2
|
||||||
|
do i=1,shift2
|
||||||
|
overlap(k,i) = dabs(y(k,i))
|
||||||
|
enddo
|
||||||
enddo
|
enddo
|
||||||
enddo
|
do k=1,N_st
|
||||||
do k=1,N_st
|
coord = maxloc(overlap)
|
||||||
coord = maxloc(overlap)
|
order( coord(2) ) = coord(1)
|
||||||
order( coord(2) ) = coord(1)
|
overlap(:,coord(2)) = -1.d0
|
||||||
overlap(:,coord(2)) = -1.d0
|
enddo
|
||||||
enddo
|
overlap = y
|
||||||
overlap = y
|
do k=1,N_st
|
||||||
do k=1,N_st
|
l = order(k)
|
||||||
l = order(k)
|
if (k /= l) then
|
||||||
if (k /= l) then
|
y(1:shift2,k) = overlap(1:shift2,l)
|
||||||
y(1:shift2,k) = overlap(1:shift2,l)
|
endif
|
||||||
endif
|
enddo
|
||||||
enddo
|
do k=1,N_st
|
||||||
do k=1,N_st
|
overlap(k,1) = lambda(k)
|
||||||
overlap(k,1) = lambda(k)
|
overlap(k,2) = s2(k)
|
||||||
overlap(k,2) = s2(k)
|
enddo
|
||||||
enddo
|
do k=1,N_st
|
||||||
do k=1,N_st
|
l = order(k)
|
||||||
l = order(k)
|
if (k /= l) then
|
||||||
if (k /= l) then
|
lambda(k) = overlap(l,1)
|
||||||
lambda(k) = overlap(l,1)
|
s2(k) = overlap(l,2)
|
||||||
s2(k) = overlap(l,2)
|
endif
|
||||||
endif
|
enddo
|
||||||
enddo
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
! Express eigenvectors of h in the determinant basis
|
! Express eigenvectors of h in the determinant basis
|
||||||
@ -940,22 +947,18 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
|
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
if (.not.converged) then
|
|
||||||
iter = itermax-1
|
|
||||||
endif
|
|
||||||
|
|
||||||
! Re-contract to u_in
|
! Re-contract to u_in
|
||||||
! -----------
|
! -----------
|
||||||
|
|
||||||
do k=1,N_st_diag
|
|
||||||
energies(k) = lambda(k)
|
|
||||||
enddo
|
|
||||||
|
|
||||||
call dgemm('N','N', sze, N_st_diag, shift2, &
|
call dgemm('N','N', sze, N_st_diag, shift2, &
|
||||||
1.d0, U, size(U,1), y, size(y,1), 0.d0, u_in, size(u_in,1))
|
1.d0, U, size(U,1), y, size(y,1), 0.d0, u_in, size(u_in,1))
|
||||||
|
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
|
do k=1,N_st_diag
|
||||||
|
energies(k) = lambda(k)
|
||||||
|
enddo
|
||||||
|
|
||||||
write_buffer = '===== '
|
write_buffer = '===== '
|
||||||
do i=1,N_st
|
do i=1,N_st
|
||||||
write_buffer = trim(write_buffer)//' ================ =========== ==========='
|
write_buffer = trim(write_buffer)//' ================ =========== ==========='
|
||||||
@ -966,7 +969,7 @@ subroutine davidson_diag_hjj_sjj_mrcc(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
|
|
||||||
deallocate ( &
|
deallocate ( &
|
||||||
W, residual_norm, &
|
W, residual_norm, &
|
||||||
U, &
|
U, overlap, &
|
||||||
c, S, &
|
c, S, &
|
||||||
h, &
|
h, &
|
||||||
y, s_, s_tmp, &
|
y, s_, s_tmp, &
|
||||||
|
@ -15,3 +15,16 @@ type: Strictly_positive_int
|
|||||||
doc: Number of micro-iterations before re-contracting
|
doc: Number of micro-iterations before re-contracting
|
||||||
default: 10
|
default: 10
|
||||||
interface: ezfio,provider,ocaml
|
interface: ezfio,provider,ocaml
|
||||||
|
|
||||||
|
[state_following]
|
||||||
|
type: logical
|
||||||
|
doc: If true, the states are re-ordered to match the input states
|
||||||
|
default: False
|
||||||
|
interface: ezfio,provider,ocaml
|
||||||
|
|
||||||
|
[disk_based_davidson]
|
||||||
|
type: logical
|
||||||
|
doc: If true, disk space is used to store the vectors
|
||||||
|
default: False
|
||||||
|
interface: ezfio,provider,ocaml
|
||||||
|
|
||||||
|
@ -45,8 +45,11 @@ subroutine davidson_diag_hs2(dets_in,u_in,s2_out,dim_in,energies,sze,N_st,N_st_d
|
|||||||
!$OMP END DO
|
!$OMP END DO
|
||||||
!$OMP END PARALLEL
|
!$OMP END PARALLEL
|
||||||
|
|
||||||
call davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_st,N_st_diag,Nint,iunit)
|
if (disk_based_davidson) then
|
||||||
! call davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_st,N_st_diag,Nint,iunit)
|
call davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_st,N_st_diag,Nint,iunit)
|
||||||
|
else
|
||||||
|
call davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_st,N_st_diag,Nint,iunit)
|
||||||
|
endif
|
||||||
do i=1,N_st_diag
|
do i=1,N_st_diag
|
||||||
s2_out(i) = S2_jj(i)
|
s2_out(i) = S2_jj(i)
|
||||||
enddo
|
enddo
|
||||||
@ -84,8 +87,8 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
integer, intent(in) :: dim_in, sze, N_st, N_st_diag, Nint
|
integer, intent(in) :: dim_in, sze, N_st, N_st_diag, Nint
|
||||||
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
|
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
|
||||||
double precision, intent(in) :: H_jj(sze)
|
double precision, intent(in) :: H_jj(sze)
|
||||||
double precision, intent(inout) :: S2_jj(sze)
|
double precision, intent(inout) :: S2_jj(sze)
|
||||||
integer, intent(in) :: iunit
|
integer, intent(in) :: iunit
|
||||||
double precision, intent(inout) :: u_in(dim_in,N_st_diag)
|
double precision, intent(inout) :: u_in(dim_in,N_st_diag)
|
||||||
double precision, intent(out) :: energies(N_st_diag)
|
double precision, intent(out) :: energies(N_st_diag)
|
||||||
|
|
||||||
@ -99,7 +102,7 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
integer :: k_pairs, kl
|
integer :: k_pairs, kl
|
||||||
|
|
||||||
integer :: iter2
|
integer :: iter2
|
||||||
double precision, allocatable :: W(:,:), U(:,:), S(:,:)
|
double precision, allocatable :: W(:,:), U(:,:), S(:,:), overlap(:,:)
|
||||||
double precision, allocatable :: y(:,:), h(:,:), lambda(:), s2(:)
|
double precision, allocatable :: y(:,:), h(:,:), lambda(:), s2(:)
|
||||||
double precision, allocatable :: c(:), s_(:,:), s_tmp(:,:)
|
double precision, allocatable :: c(:), s_(:,:), s_tmp(:,:)
|
||||||
double precision :: diag_h_mat_elem
|
double precision :: diag_h_mat_elem
|
||||||
@ -108,13 +111,15 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
double precision :: to_print(3,N_st)
|
double precision :: to_print(3,N_st)
|
||||||
double precision :: cpu, wall
|
double precision :: cpu, wall
|
||||||
integer :: shift, shift2, itermax
|
integer :: shift, shift2, itermax
|
||||||
|
double precision :: r1, r2
|
||||||
|
logical :: state_ok(N_st_diag*davidson_sze_max)
|
||||||
include 'constants.include.F'
|
include 'constants.include.F'
|
||||||
|
|
||||||
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
||||||
if (N_st_diag*3 > sze) then
|
if (N_st_diag*3 > sze) then
|
||||||
print *, 'error in Davidson :'
|
print *, 'error in Davidson :'
|
||||||
print *, 'Increase n_det_max_jacobi to ', N_st_diag*3
|
print *, 'Increase n_det_max_jacobi to ', N_st_diag*3
|
||||||
stop -1
|
stop -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
PROVIDE nuclear_repulsion expected_s2
|
PROVIDE nuclear_repulsion expected_s2
|
||||||
@ -137,7 +142,7 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
write_buffer = ' Iter'
|
write_buffer = ' Iter'
|
||||||
do i=1,N_st
|
do i=1,N_st
|
||||||
write_buffer = trim(write_buffer)//' Energy S^2 Residual'
|
write_buffer = trim(write_buffer)//' Energy S^2 Residual '
|
||||||
enddo
|
enddo
|
||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
write_buffer = '===== '
|
write_buffer = '===== '
|
||||||
@ -146,30 +151,31 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
enddo
|
enddo
|
||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
|
|
||||||
integer, external :: align_double
|
integer, external :: align_double
|
||||||
sze_8 = align_double(sze)
|
sze_8 = align_double(sze)
|
||||||
|
|
||||||
itermax = min(davidson_sze_max, sze/N_st_diag)
|
itermax = min(davidson_sze_max, sze/N_st_diag)
|
||||||
allocate( &
|
allocate( &
|
||||||
W(sze_8,N_st_diag*itermax), &
|
W(sze_8,N_st_diag*itermax), &
|
||||||
U(sze_8,N_st_diag*itermax), &
|
U(sze_8,N_st_diag*itermax), &
|
||||||
S(sze_8,N_st_diag*itermax), &
|
S(sze_8,N_st_diag*itermax), &
|
||||||
h(N_st_diag*itermax,N_st_diag*itermax), &
|
h(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
y(N_st_diag*itermax,N_st_diag*itermax), &
|
y(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
s_(N_st_diag*itermax,N_st_diag*itermax), &
|
s_(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
s_tmp(N_st_diag*itermax,N_st_diag*itermax), &
|
s_tmp(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
residual_norm(N_st_diag), &
|
residual_norm(N_st_diag), &
|
||||||
c(N_st_diag*itermax), &
|
c(N_st_diag*itermax), &
|
||||||
s2(N_st_diag*itermax), &
|
s2(N_st_diag*itermax), &
|
||||||
|
overlap(N_st_diag*itermax, N_st_diag*itermax), &
|
||||||
lambda(N_st_diag*itermax))
|
lambda(N_st_diag*itermax))
|
||||||
|
|
||||||
h = 0.d0
|
h = 0.d0
|
||||||
s_ = 0.d0
|
|
||||||
s_tmp = 0.d0
|
|
||||||
U = 0.d0
|
U = 0.d0
|
||||||
W = 0.d0
|
W = 0.d0
|
||||||
S = 0.d0
|
S = 0.d0
|
||||||
y = 0.d0
|
y = 0.d0
|
||||||
|
s_ = 0.d0
|
||||||
|
s_tmp = 0.d0
|
||||||
|
|
||||||
|
|
||||||
ASSERT (N_st > 0)
|
ASSERT (N_st > 0)
|
||||||
@ -183,15 +189,15 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
|
|
||||||
converged = .False.
|
converged = .False.
|
||||||
|
|
||||||
double precision :: r1, r2
|
|
||||||
do k=N_st+1,N_st_diag
|
do k=N_st+1,N_st_diag
|
||||||
do i=1,sze
|
u_in(k,k) = 10.d0
|
||||||
call random_number(r1)
|
do i=1,sze
|
||||||
call random_number(r2)
|
call random_number(r1)
|
||||||
r1 = dsqrt(-2.d0*dlog(r1))
|
call random_number(r2)
|
||||||
r2 = dtwo_pi*r2
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
u_in(i,k) = r1*dcos(r2)
|
r2 = dtwo_pi*r2
|
||||||
enddo
|
u_in(i,k) = r1*dcos(r2)
|
||||||
|
enddo
|
||||||
enddo
|
enddo
|
||||||
do k=1,N_st_diag
|
do k=1,N_st_diag
|
||||||
call normalize(u_in(1,k),sze)
|
call normalize(u_in(1,k),sze)
|
||||||
@ -233,8 +239,49 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
0.d0, s_, size(s_,1))
|
0.d0, s_, size(s_,1))
|
||||||
|
|
||||||
|
|
||||||
|
! ! Diagonalize S^2
|
||||||
|
! ! ---------------
|
||||||
|
!
|
||||||
|
! call lapack_diag(s2,y,s_,size(s_,1),shift2)
|
||||||
|
!
|
||||||
|
!
|
||||||
|
! ! Rotate H in the basis of eigenfunctions of s2
|
||||||
|
! ! ---------------------------------------------
|
||||||
|
!
|
||||||
|
! call dgemm('N','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, h, size(h,1), y, size(y,1), &
|
||||||
|
! 0.d0, s_tmp, size(s_tmp,1))
|
||||||
|
!
|
||||||
|
! call dgemm('T','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, y, size(y,1), s_tmp, size(s_tmp,1), &
|
||||||
|
! 0.d0, h, size(h,1))
|
||||||
|
!
|
||||||
|
! ! Damp interaction between different spin states
|
||||||
|
! ! ------------------------------------------------
|
||||||
|
!
|
||||||
|
! do k=1,shift2
|
||||||
|
! do l=1,shift2
|
||||||
|
! if (dabs(s2(k) - s2(l)) > 1.d0) then
|
||||||
|
! h(k,l) = h(k,l)*(max(0.d0,1.d0 - dabs(s2(k) - s2(l))))
|
||||||
|
! endif
|
||||||
|
! enddo
|
||||||
|
! enddo
|
||||||
|
!
|
||||||
|
! ! Rotate back H
|
||||||
|
! ! -------------
|
||||||
|
!
|
||||||
|
! call dgemm('N','T',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, h, size(h,1), y, size(y,1), &
|
||||||
|
! 0.d0, s_tmp, size(s_tmp,1))
|
||||||
|
!
|
||||||
|
! call dgemm('N','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, y, size(y,1), s_tmp, size(s_tmp,1), &
|
||||||
|
! 0.d0, h, size(h,1))
|
||||||
|
|
||||||
|
|
||||||
! Diagonalize h
|
! Diagonalize h
|
||||||
! -------------
|
! -------------
|
||||||
|
|
||||||
call lapack_diag(lambda,y,h,size(h,1),shift2)
|
call lapack_diag(lambda,y,h,size(h,1),shift2)
|
||||||
|
|
||||||
! Compute S2 for each eigenvector
|
! Compute S2 for each eigenvector
|
||||||
@ -255,24 +302,61 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
enddo
|
enddo
|
||||||
|
|
||||||
if (s2_eig) then
|
if (s2_eig) then
|
||||||
logical :: state_ok(N_st_diag*davidson_sze_max)
|
do k=1,shift2
|
||||||
|
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.6d0)
|
||||||
|
enddo
|
||||||
|
else
|
||||||
|
state_ok(k) = .True.
|
||||||
|
endif
|
||||||
|
|
||||||
|
do k=1,shift2
|
||||||
|
if (.not. state_ok(k)) then
|
||||||
|
do l=k+1,shift2
|
||||||
|
if (state_ok(l)) then
|
||||||
|
call dswap(shift2, y(1,k), 1, y(1,l), 1)
|
||||||
|
call dswap(1, s2(k), 1, s2(l), 1)
|
||||||
|
call dswap(1, lambda(k), 1, lambda(l), 1)
|
||||||
|
state_ok(k) = .True.
|
||||||
|
state_ok(l) = .False.
|
||||||
|
exit
|
||||||
|
endif
|
||||||
|
enddo
|
||||||
|
endif
|
||||||
|
enddo
|
||||||
|
|
||||||
|
if (state_following) then
|
||||||
|
|
||||||
|
integer :: coord(2), order(N_st_diag)
|
||||||
|
overlap = -1.d0
|
||||||
do k=1,shift2
|
do k=1,shift2
|
||||||
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.6d0)
|
do i=1,shift2
|
||||||
|
overlap(k,i) = dabs(y(k,i))
|
||||||
|
enddo
|
||||||
enddo
|
enddo
|
||||||
do k=1,shift2
|
do k=1,N_st
|
||||||
if (.not. state_ok(k)) then
|
coord = maxloc(overlap)
|
||||||
do l=k+1,shift2
|
order( coord(2) ) = coord(1)
|
||||||
if (state_ok(l)) then
|
overlap(:,coord(2)) = -1.d0
|
||||||
call dswap(shift2, y(1,k), 1, y(1,l), 1)
|
enddo
|
||||||
call dswap(1, s2(k), 1, s2(l), 1)
|
overlap = y
|
||||||
call dswap(1, lambda(k), 1, lambda(l), 1)
|
do k=1,N_st
|
||||||
state_ok(k) = .True.
|
l = order(k)
|
||||||
state_ok(l) = .False.
|
if (k /= l) then
|
||||||
exit
|
y(1:shift2,k) = overlap(1:shift2,l)
|
||||||
endif
|
|
||||||
enddo
|
|
||||||
endif
|
endif
|
||||||
enddo
|
enddo
|
||||||
|
do k=1,N_st
|
||||||
|
overlap(k,1) = lambda(k)
|
||||||
|
overlap(k,2) = s2(k)
|
||||||
|
enddo
|
||||||
|
do k=1,N_st
|
||||||
|
l = order(k)
|
||||||
|
if (k /= l) then
|
||||||
|
lambda(k) = overlap(l,1)
|
||||||
|
s2(k) = overlap(l,2)
|
||||||
|
endif
|
||||||
|
enddo
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@ -290,11 +374,31 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
! -----------------------------------------
|
! -----------------------------------------
|
||||||
|
|
||||||
do k=1,N_st_diag
|
do k=1,N_st_diag
|
||||||
do i=1,sze
|
if (state_ok(k)) then
|
||||||
U(i,shift2+k) = (lambda(k) * U(i,shift2+k) - W(i,shift2+k) ) &
|
do i=1,sze
|
||||||
* (1.d0 + s2(k) * U(i,shift2+k) - S(i,shift2+k) - S_z2_Sz &
|
U(i,shift2+k) = (lambda(k) * U(i,shift2+k) - W(i,shift2+k) ) &
|
||||||
)/max(H_jj(i) - lambda (k),1.d-2)
|
* (1.d0 + s2(k) * U(i,shift2+k) - S(i,shift2+k) - S_z2_Sz &
|
||||||
enddo
|
)/max(H_jj(i) - lambda (k),1.d-2)
|
||||||
|
enddo
|
||||||
|
else
|
||||||
|
! Randomize components with bad <S2>
|
||||||
|
do i=1,sze-2,2
|
||||||
|
call random_number(r1)
|
||||||
|
call random_number(r2)
|
||||||
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
|
r2 = dtwo_pi*r2
|
||||||
|
U(i,shift2+k) = r1*dcos(r2)
|
||||||
|
U(i+1,shift2+k) = r1*dsin(r2)
|
||||||
|
enddo
|
||||||
|
do i=sze-2+1,sze
|
||||||
|
call random_number(r1)
|
||||||
|
call random_number(r2)
|
||||||
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
|
r2 = dtwo_pi*r2
|
||||||
|
U(i,shift2+k) = r1*dcos(r2)
|
||||||
|
enddo
|
||||||
|
endif
|
||||||
|
|
||||||
if (k <= N_st) then
|
if (k <= N_st) then
|
||||||
residual_norm(k) = u_dot_u(U(1,shift2+k),sze)
|
residual_norm(k) = u_dot_u(U(1,shift2+k),sze)
|
||||||
to_print(1,k) = lambda(k) + nuclear_repulsion
|
to_print(1,k) = lambda(k) + nuclear_repulsion
|
||||||
@ -339,7 +443,7 @@ subroutine davidson_diag_hjj_sjj(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sze,N_s
|
|||||||
|
|
||||||
deallocate ( &
|
deallocate ( &
|
||||||
W, residual_norm, &
|
W, residual_norm, &
|
||||||
U, &
|
U, overlap, &
|
||||||
c, S, &
|
c, S, &
|
||||||
h, &
|
h, &
|
||||||
y, s_, s_tmp, &
|
y, s_, s_tmp, &
|
||||||
@ -378,8 +482,8 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
integer, intent(in) :: dim_in, sze, N_st, N_st_diag, Nint
|
integer, intent(in) :: dim_in, sze, N_st, N_st_diag, Nint
|
||||||
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
|
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
|
||||||
double precision, intent(in) :: H_jj(sze)
|
double precision, intent(in) :: H_jj(sze)
|
||||||
double precision, intent(inout) :: S2_jj(sze)
|
double precision, intent(inout) :: S2_jj(sze)
|
||||||
integer, intent(in) :: iunit
|
integer, intent(in) :: iunit
|
||||||
double precision, intent(inout) :: u_in(dim_in,N_st_diag)
|
double precision, intent(inout) :: u_in(dim_in,N_st_diag)
|
||||||
double precision, intent(out) :: energies(N_st_diag)
|
double precision, intent(out) :: energies(N_st_diag)
|
||||||
|
|
||||||
@ -393,7 +497,7 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
integer :: k_pairs, kl
|
integer :: k_pairs, kl
|
||||||
|
|
||||||
integer :: iter2
|
integer :: iter2
|
||||||
double precision, pointer :: W(:,:), U(:,:), S(:,:)
|
double precision, pointer :: W(:,:), U(:,:), S(:,:), overlap(:,:)
|
||||||
double precision, allocatable :: y(:,:), h(:,:), lambda(:), s2(:)
|
double precision, allocatable :: y(:,:), h(:,:), lambda(:), s2(:)
|
||||||
double precision, allocatable :: c(:), s_(:,:), s_tmp(:,:)
|
double precision, allocatable :: c(:), s_(:,:), s_tmp(:,:)
|
||||||
double precision :: diag_h_mat_elem
|
double precision :: diag_h_mat_elem
|
||||||
@ -401,14 +505,15 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
character*(16384) :: write_buffer
|
character*(16384) :: write_buffer
|
||||||
double precision :: to_print(3,N_st)
|
double precision :: to_print(3,N_st)
|
||||||
double precision :: cpu, wall
|
double precision :: cpu, wall
|
||||||
|
logical :: state_ok(N_st_diag*davidson_sze_max)
|
||||||
integer :: shift, shift2, itermax
|
integer :: shift, shift2, itermax
|
||||||
include 'constants.include.F'
|
include 'constants.include.F'
|
||||||
|
|
||||||
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: U, W, S, y, h, lambda
|
||||||
if (N_st_diag*3 > sze) then
|
if (N_st_diag*3 > sze) then
|
||||||
print *, 'error in Davidson :'
|
print *, 'error in Davidson :'
|
||||||
print *, 'Increase n_det_max_jacobi to ', N_st_diag*3
|
print *, 'Increase n_det_max_jacobi to ', N_st_diag*3
|
||||||
stop -1
|
stop -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
PROVIDE nuclear_repulsion expected_s2
|
PROVIDE nuclear_repulsion expected_s2
|
||||||
@ -431,7 +536,7 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
write_buffer = ' Iter'
|
write_buffer = ' Iter'
|
||||||
do i=1,N_st
|
do i=1,N_st
|
||||||
write_buffer = trim(write_buffer)//' Energy S^2 Residual'
|
write_buffer = trim(write_buffer)//' Energy S^2 Residual '
|
||||||
enddo
|
enddo
|
||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
write_buffer = '===== '
|
write_buffer = '===== '
|
||||||
@ -440,48 +545,49 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
enddo
|
enddo
|
||||||
write(iunit,'(A)') trim(write_buffer)
|
write(iunit,'(A)') trim(write_buffer)
|
||||||
|
|
||||||
integer, external :: align_double
|
integer, external :: align_double
|
||||||
integer :: fd(3)
|
integer :: fd(3)
|
||||||
type(c_ptr) :: c_pointer(3)
|
type(c_ptr) :: c_pointer(3)
|
||||||
sze_8 = align_double(sze)
|
sze_8 = align_double(sze)
|
||||||
|
|
||||||
itermax = min(davidson_sze_max, sze/N_st_diag)
|
itermax = min(davidson_sze_max, sze/N_st_diag)
|
||||||
|
|
||||||
call mmap( &
|
call mmap( &
|
||||||
trim(ezfio_work_dir)//'U', &
|
trim(ezfio_work_dir)//'U', &
|
||||||
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
||||||
8, fd(1), .False., c_pointer(1))
|
8, fd(1), .False., c_pointer(1))
|
||||||
call c_f_pointer(c_pointer(1), W, (/ sze_8,N_st_diag*itermax /) )
|
call c_f_pointer(c_pointer(1), W, (/ sze_8,N_st_diag*itermax /) )
|
||||||
|
|
||||||
call mmap( &
|
call mmap( &
|
||||||
trim(ezfio_work_dir)//'W', &
|
trim(ezfio_work_dir)//'W', &
|
||||||
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
||||||
8, fd(2), .False., c_pointer(2))
|
8, fd(2), .False., c_pointer(2))
|
||||||
call c_f_pointer(c_pointer(2), U, (/ sze_8,N_st_diag*itermax /) )
|
call c_f_pointer(c_pointer(2), U, (/ sze_8,N_st_diag*itermax /) )
|
||||||
|
|
||||||
call mmap( &
|
call mmap( &
|
||||||
trim(ezfio_work_dir)//'S', &
|
trim(ezfio_work_dir)//'S', &
|
||||||
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
(/ int(sze_8,8),int(N_st_diag*itermax,8) /), &
|
||||||
8, fd(3), .False., c_pointer(3))
|
8, fd(3), .False., c_pointer(3))
|
||||||
call c_f_pointer(c_pointer(3), S, (/ sze_8,N_st_diag*itermax /) )
|
call c_f_pointer(c_pointer(3), S, (/ sze_8,N_st_diag*itermax /) )
|
||||||
|
|
||||||
allocate( &
|
allocate( &
|
||||||
h(N_st_diag*itermax,N_st_diag*itermax), &
|
h(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
y(N_st_diag*itermax,N_st_diag*itermax), &
|
y(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
s_(N_st_diag*itermax,N_st_diag*itermax), &
|
s_(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
s_tmp(N_st_diag*itermax,N_st_diag*itermax), &
|
s_tmp(N_st_diag*itermax,N_st_diag*itermax), &
|
||||||
|
overlap(N_st_diag*itermax, N_st_diag*itermax), &
|
||||||
residual_norm(N_st_diag), &
|
residual_norm(N_st_diag), &
|
||||||
c(N_st_diag*itermax), &
|
c(N_st_diag*itermax), &
|
||||||
s2(N_st_diag*itermax), &
|
s2(N_st_diag*itermax), &
|
||||||
lambda(N_st_diag*itermax))
|
lambda(N_st_diag*itermax))
|
||||||
|
|
||||||
h = 0.d0
|
h = 0.d0
|
||||||
s_ = 0.d0
|
|
||||||
s_tmp = 0.d0
|
|
||||||
U = 0.d0
|
U = 0.d0
|
||||||
W = 0.d0
|
W = 0.d0
|
||||||
S = 0.d0
|
S = 0.d0
|
||||||
y = 0.d0
|
y = 0.d0
|
||||||
|
s_ = 0.d0
|
||||||
|
s_tmp = 0.d0
|
||||||
|
|
||||||
|
|
||||||
ASSERT (N_st > 0)
|
ASSERT (N_st > 0)
|
||||||
@ -497,6 +603,7 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
|
|
||||||
double precision :: r1, r2
|
double precision :: r1, r2
|
||||||
do k=N_st+1,N_st_diag
|
do k=N_st+1,N_st_diag
|
||||||
|
u_in(k,k) = 10.d0
|
||||||
do i=1,sze
|
do i=1,sze
|
||||||
call random_number(r1)
|
call random_number(r1)
|
||||||
r1 = dsqrt(-2.d0*dlog(r1))
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
@ -546,6 +653,45 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
0.d0, s_(shift+1,1), size(s_,1))
|
0.d0, s_(shift+1,1), size(s_,1))
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
|
! ! Diagonalize S^2
|
||||||
|
! ! ---------------
|
||||||
|
!
|
||||||
|
! call lapack_diag(s2,y,s_,size(s_,1),shift2)
|
||||||
|
!
|
||||||
|
!
|
||||||
|
! ! Rotate H in the basis of eigenfunctions of s2
|
||||||
|
! ! ---------------------------------------------
|
||||||
|
!
|
||||||
|
! call dgemm('N','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, h, size(h,1), y, size(y,1), &
|
||||||
|
! 0.d0, s_tmp, size(s_tmp,1))
|
||||||
|
!
|
||||||
|
! call dgemm('T','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, y, size(y,1), s_tmp, size(s_tmp,1), &
|
||||||
|
! 0.d0, h, size(h,1))
|
||||||
|
!
|
||||||
|
! ! Damp interaction between different spin states
|
||||||
|
! ! ------------------------------------------------
|
||||||
|
!
|
||||||
|
! do k=1,shift2
|
||||||
|
! do l=1,shift2
|
||||||
|
! if (dabs(s2(k) - s2(l)) > 1.d0) then
|
||||||
|
! h(k,l) = h(k,l)*(max(0.d0,1.d0 - dabs(s2(k) - s2(l))))
|
||||||
|
! endif
|
||||||
|
! enddo
|
||||||
|
! enddo
|
||||||
|
!
|
||||||
|
! ! Rotate back H
|
||||||
|
! ! -------------
|
||||||
|
!
|
||||||
|
! call dgemm('N','T',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, h, size(h,1), y, size(y,1), &
|
||||||
|
! 0.d0, s_tmp, size(s_tmp,1))
|
||||||
|
!
|
||||||
|
! call dgemm('N','N',shift2,shift2,shift2, &
|
||||||
|
! 1.d0, y, size(y,1), s_tmp, size(s_tmp,1), &
|
||||||
|
! 0.d0, h, size(h,1))
|
||||||
|
|
||||||
|
|
||||||
! Diagonalize h
|
! Diagonalize h
|
||||||
! -------------
|
! -------------
|
||||||
@ -568,36 +714,63 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
s2(k) = s_(k,k) + S_z2_Sz
|
s2(k) = s_(k,k) + S_z2_Sz
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
|
|
||||||
if (s2_eig) then
|
if (s2_eig) then
|
||||||
logical :: state_ok(N_st_diag*davidson_sze_max)
|
do k=1,shift2
|
||||||
|
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.6d0)
|
||||||
|
enddo
|
||||||
|
else
|
||||||
|
state_ok(k) = .True.
|
||||||
|
endif
|
||||||
|
|
||||||
|
do k=1,shift2
|
||||||
|
if (.not. state_ok(k)) then
|
||||||
|
do l=k+1,shift2
|
||||||
|
if (state_ok(l)) then
|
||||||
|
call dswap(shift2, y(1,k), 1, y(1,l), 1)
|
||||||
|
call dswap(1, s2(k), 1, s2(l), 1)
|
||||||
|
call dswap(1, lambda(k), 1, lambda(l), 1)
|
||||||
|
state_ok(k) = .True.
|
||||||
|
state_ok(l) = .False.
|
||||||
|
exit
|
||||||
|
endif
|
||||||
|
enddo
|
||||||
|
endif
|
||||||
|
enddo
|
||||||
|
|
||||||
|
if (state_following) then
|
||||||
|
|
||||||
|
integer :: coord(2), order(N_st_diag)
|
||||||
|
overlap = -1.d0
|
||||||
do k=1,shift2
|
do k=1,shift2
|
||||||
state_ok(k) = (dabs(s2(k)-expected_s2) < 0.6d0)
|
do i=1,shift2
|
||||||
|
overlap(k,i) = dabs(y(k,i))
|
||||||
|
enddo
|
||||||
enddo
|
enddo
|
||||||
do k=1,shift2
|
do k=1,N_st
|
||||||
if (.not. state_ok(k)) then
|
coord = maxloc(overlap)
|
||||||
do l=k+1,shift2
|
order( coord(2) ) = coord(1)
|
||||||
if (state_ok(l)) then
|
overlap(:,coord(2)) = -1.d0
|
||||||
call dswap(shift2, y(1,k), 1, y(1,l), 1)
|
enddo
|
||||||
call dswap(1, s2(k), 1, s2(l), 1)
|
overlap = y
|
||||||
call dswap(1, lambda(k), 1, lambda(l), 1)
|
do k=1,N_st
|
||||||
state_ok(k) = .True.
|
l = order(k)
|
||||||
state_ok(l) = .False.
|
if (k /= l) then
|
||||||
exit
|
y(1:shift2,k) = overlap(1:shift2,l)
|
||||||
endif
|
|
||||||
enddo
|
|
||||||
endif
|
endif
|
||||||
enddo
|
enddo
|
||||||
! Randomize components with bad <S2>
|
do k=1,N_st
|
||||||
if (.not. state_ok(k)) then
|
overlap(k,1) = lambda(k)
|
||||||
do i=1,shift2
|
overlap(k,2) = s2(k)
|
||||||
call random_number(r1)
|
enddo
|
||||||
call random_number(r2)
|
do k=1,N_st
|
||||||
r1 = dsqrt(-2.d0*dlog(r1))
|
l = order(k)
|
||||||
r2 = dtwo_pi*r2
|
if (k /= l) then
|
||||||
y(i,k) = r1*dcos(r2)
|
lambda(k) = overlap(l,1)
|
||||||
lambda(k) = 1.d0
|
s2(k) = overlap(l,2)
|
||||||
enddo
|
endif
|
||||||
endif
|
enddo
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@ -615,11 +788,31 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
! -----------------------------------------
|
! -----------------------------------------
|
||||||
|
|
||||||
do k=1,N_st_diag
|
do k=1,N_st_diag
|
||||||
do i=1,sze
|
if (state_ok(k)) then
|
||||||
U(i,shift2+k) = (lambda(k) * U(i,shift2+k) - W(i,shift2+k) ) &
|
do i=1,sze
|
||||||
* (1.d0 + s2(k) * U(i,shift2+k) - S(i,shift2+k) - S_z2_Sz &
|
U(i,shift2+k) = (lambda(k) * U(i,shift2+k) - W(i,shift2+k) ) &
|
||||||
)/max(H_jj(i) - lambda (k),1.d-2)
|
* (1.d0 + s2(k) * U(i,shift2+k) - S(i,shift2+k) - S_z2_Sz &
|
||||||
enddo
|
)/max(H_jj(i) - lambda (k),1.d-2)
|
||||||
|
enddo
|
||||||
|
else
|
||||||
|
! Randomize components with bad <S2>
|
||||||
|
do i=1,sze-2,2
|
||||||
|
call random_number(r1)
|
||||||
|
call random_number(r2)
|
||||||
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
|
r2 = dtwo_pi*r2
|
||||||
|
U(i,shift2+k) = r1*dcos(r2)
|
||||||
|
U(i+1,shift2+k) = r1*dsin(r2)
|
||||||
|
enddo
|
||||||
|
do i=sze-2+1,sze
|
||||||
|
call random_number(r1)
|
||||||
|
call random_number(r2)
|
||||||
|
r1 = dsqrt(-2.d0*dlog(r1))
|
||||||
|
r2 = dtwo_pi*r2
|
||||||
|
U(i,shift2+k) = r1*dcos(r2)
|
||||||
|
enddo
|
||||||
|
endif
|
||||||
|
|
||||||
if (k <= N_st) then
|
if (k <= N_st) then
|
||||||
residual_norm(k) = u_dot_u(U(1,shift2+k),sze)
|
residual_norm(k) = u_dot_u(U(1,shift2+k),sze)
|
||||||
to_print(1,k) = lambda(k) + nuclear_repulsion
|
to_print(1,k) = lambda(k) + nuclear_repulsion
|
||||||
@ -676,7 +869,7 @@ subroutine davidson_diag_hjj_sjj_mmap(dets_in,u_in,H_jj,S2_jj,energies,dim_in,sz
|
|||||||
|
|
||||||
deallocate ( &
|
deallocate ( &
|
||||||
residual_norm, &
|
residual_norm, &
|
||||||
c, &
|
c, overlap, &
|
||||||
h, &
|
h, &
|
||||||
y, s_, s_tmp, &
|
y, s_, s_tmp, &
|
||||||
lambda &
|
lambda &
|
||||||
|
Loading…
Reference in New Issue
Block a user