2020-09-30 20:44:53 +02:00
|
|
|
program svdwf
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! Make the SVD of the alpha-beta wave function and print singular values.
|
|
|
|
END_DOC
|
|
|
|
read_wf = .True.
|
|
|
|
TOUCH read_wf
|
|
|
|
call run()
|
|
|
|
end
|
|
|
|
|
|
|
|
subroutine run
|
|
|
|
implicit none
|
|
|
|
include 'constants.include.F'
|
|
|
|
double precision, allocatable :: U(:,:), V(:,:), D(:), A(:,:)
|
|
|
|
integer :: i, j, k, l, q, r, m, n, iter
|
2020-09-30 21:20:45 +02:00
|
|
|
double precision,allocatable :: Z(:,:), P(:,:), Yt(:,:), UYt(:,:), r1(:,:)
|
2020-09-30 20:44:53 +02:00
|
|
|
|
|
|
|
m = n_det_alpha_unique
|
|
|
|
n = n_det_beta_unique
|
|
|
|
|
|
|
|
r = min(1000,n)
|
|
|
|
|
|
|
|
allocate(Z(m,r))
|
|
|
|
|
2021-02-22 16:25:05 +01:00
|
|
|
! Z(m,r) = A(m,n).P(n,r)
|
|
|
|
do j=1,r
|
|
|
|
do i=1,m
|
|
|
|
Z(i,j) = 0.d0
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-09-30 21:20:45 +02:00
|
|
|
allocate(P(n,r))
|
|
|
|
|
|
|
|
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j,k,l,r1)
|
|
|
|
allocate(r1(N_det,2))
|
2021-02-22 16:25:05 +01:00
|
|
|
!$OMP DO
|
2020-09-30 20:44:53 +02:00
|
|
|
do l=1,r
|
2020-09-30 21:20:45 +02:00
|
|
|
call random_number(r1)
|
|
|
|
r1(:,1) = dsqrt(-2.d0*dlog(r1(:,1)))
|
|
|
|
r1(:,1) = r1(:,1) * dcos(dtwo_pi*r1(:,2))
|
2020-09-30 20:44:53 +02:00
|
|
|
do k=1,N_det
|
|
|
|
i = psi_bilinear_matrix_rows(k)
|
|
|
|
j = psi_bilinear_matrix_columns(k)
|
2021-02-22 16:25:05 +01:00
|
|
|
Z(i,l) = Z(i,l) + psi_bilinear_matrix_values(k,1) * r1(k,1)
|
2020-09-30 20:44:53 +02:00
|
|
|
enddo
|
|
|
|
enddo
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP END DO
|
|
|
|
deallocate(r1)
|
|
|
|
!$OMP END PARALLEL
|
2020-09-30 20:44:53 +02:00
|
|
|
|
|
|
|
! Power iterations
|
|
|
|
do iter=1,20
|
2020-09-30 21:20:45 +02:00
|
|
|
print *, 'Power iteration ', iter, '/', 20
|
|
|
|
|
2020-09-30 20:44:53 +02:00
|
|
|
! P(n,r) = At(n,m).Z(m,r)
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j,k,l)
|
|
|
|
!$OMP DO
|
2020-09-30 20:44:53 +02:00
|
|
|
do l=1,r
|
2020-09-30 21:20:45 +02:00
|
|
|
P(:,l) = 0.d0
|
2020-09-30 20:44:53 +02:00
|
|
|
do k=1,N_det
|
|
|
|
i = psi_bilinear_matrix_rows(k)
|
|
|
|
j = psi_bilinear_matrix_columns(k)
|
|
|
|
P(j,l) = P(j,l) + psi_bilinear_matrix_values(k,1) * Z(i,l)
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP END DO
|
|
|
|
|
|
|
|
!$OMP BARRIER
|
|
|
|
|
|
|
|
!$OMP DO
|
2020-09-30 20:44:53 +02:00
|
|
|
do l=1,r
|
2020-09-30 21:20:45 +02:00
|
|
|
Z(:,l) = 0.d0
|
2020-09-30 20:44:53 +02:00
|
|
|
do k=1,N_det
|
|
|
|
i = psi_bilinear_matrix_rows(k)
|
|
|
|
j = psi_bilinear_matrix_columns(k)
|
|
|
|
Z(i,l) = Z(i,l) + psi_bilinear_matrix_values(k,1) * P(j,l)
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP END DO
|
|
|
|
|
|
|
|
!$OMP END PARALLEL
|
|
|
|
|
2020-09-30 20:44:53 +02:00
|
|
|
! Compute QR
|
|
|
|
call ortho_qr(Z,size(Z,1),m,r)
|
|
|
|
enddo
|
|
|
|
|
|
|
|
! Y(r,n) = Zt(r,m).A(m,n)
|
|
|
|
allocate(Yt(n,r))
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j,k,l)
|
|
|
|
!$OMP DO
|
2020-09-30 20:44:53 +02:00
|
|
|
do l=1,r
|
2021-01-04 22:14:55 +01:00
|
|
|
do k=1,n
|
|
|
|
Yt(k,l) = 0.d0
|
|
|
|
enddo
|
2020-09-30 20:44:53 +02:00
|
|
|
do k=1,N_det
|
|
|
|
i = psi_bilinear_matrix_rows(k)
|
|
|
|
j = psi_bilinear_matrix_columns(k)
|
|
|
|
Yt(j,l) = Yt(j,l) + Z(i,l) * psi_bilinear_matrix_values(k,1)
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-09-30 21:20:45 +02:00
|
|
|
!$OMP END DO
|
|
|
|
!$OMP END PARALLEL
|
2020-09-30 20:44:53 +02:00
|
|
|
|
|
|
|
allocate(D(r),V(n,r), UYt(r,r))
|
|
|
|
call svd(Yt,size(Yt,1),V,size(V,1),D,UYt,size(UYt,1),n,r)
|
|
|
|
deallocate(Yt)
|
|
|
|
|
2021-02-22 16:25:05 +01:00
|
|
|
! U(m,r) = Z(m,r).UY(r,r)
|
2020-09-30 20:44:53 +02:00
|
|
|
allocate(U(m,r))
|
|
|
|
call dgemm('N','T',m,r,r,1.d0,Z,size(Z,1),UYt,size(UYt,1),0.d0,U,size(U,1))
|
|
|
|
deallocate(UYt,Z)
|
|
|
|
|
|
|
|
do i=1,r
|
|
|
|
print *, i, real(D(i)), real(D(i)**2), real(sum(D(1:i)**2))
|
|
|
|
if (D(i) < 1.d-15) then
|
|
|
|
k = i
|
|
|
|
exit
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
print *, 'threshold: ', 2.858 * D(k/2)
|
|
|
|
do i=1,m
|
|
|
|
print '(I6,4(X,F12.8))', i, U(i,1:4)
|
|
|
|
enddo
|
|
|
|
print *, ''
|
|
|
|
do i=1,n
|
|
|
|
print '(I6,4(X,F12.8))', i, V(i,1:4)
|
|
|
|
enddo
|
|
|
|
|
|
|
|
deallocate(U,D,V)
|
|
|
|
end
|