10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-03 20:54:00 +01:00

Merge branch 'garniron-master' into develop

This commit is contained in:
Anthony Scemama 2016-07-07 13:31:29 +02:00
commit 862883cbde
25 changed files with 2840 additions and 178 deletions

View File

@ -35,7 +35,7 @@ OPENMP : 1 ; Append OpenMP flags
# -ffast-math and the Fortran-specific # -ffast-math and the Fortran-specific
# -fno-protect-parens and -fstack-arrays. # -fno-protect-parens and -fstack-arrays.
[OPT] [OPT]
FCFLAGS : -Ofast FCFLAGS : -Ofast
# Profiling flags # Profiling flags
################# #################

View File

@ -51,7 +51,7 @@ FCFLAGS : -Ofast
# -g : Extra debugging information # -g : Extra debugging information
# #
[DEBUG] [DEBUG]
FCFLAGS : -g -pedantic -msse4.2 FCFLAGS : -g -msse4.2
# OpenMP flags # OpenMP flags
################# #################

View File

@ -32,14 +32,14 @@ OPENMP : 1 ; Append OpenMP flags
# #
[OPT] [OPT]
FC : -traceback FC : -traceback
FCFLAGS : -xSSE4.2 -O2 -ip -ftz -g -traceback FCFLAGS : -xSSE4.2 -O2 -ip -ftz -g
# Profiling flags # Profiling flags
################# #################
# #
[PROFILE] [PROFILE]
FC : -p -g -traceback FC : -p -g -traceback
FCFLAGS : -xSSE4.2 -O2 -ip -ftz FCFLAGS : -xSSE4.2 -O2 -ip -ftz
# Debugging flags # Debugging flags
################# #################
@ -52,7 +52,7 @@ FCFLAGS : -xSSE4.2 -O2 -ip -ftz
# #
[DEBUG] [DEBUG]
FC : -g -traceback FC : -g -traceback
FCFLAGS : -xSSE2 -C FCFLAGS : -xSSE2 -C -fpe0
IRPF90_FLAGS : --openmp IRPF90_FLAGS : --openmp
# OpenMP flags # OpenMP flags

View File

@ -780,7 +780,7 @@ Ar GEN 10 2
-1386.79918148 2 4.23753203 -1386.79918148 2 4.23753203
1350.57102634 2 6.12344921 1350.57102634 2 6.12344921
Ag GEN 36 2 Ag GEN 36 2
6 6
11.00000000 1 7.02317516 11.00000000 1 7.02317516
178.71479273 2 1.36779344 178.71479273 2 1.36779344

View File

@ -31,11 +31,11 @@ s.set_perturbation("epstein_nesbet_2x2")
s.unset_openmp() s.unset_openmp()
print s print s
#s = H_apply_zmq("mrcc_PT2") s = H_apply_zmq("mrcepa_PT2")
#s.energy = "ci_electronic_energy_dressed" s.energy = "psi_ref_energy_diagonalized"
#s.set_perturbation("epstein_nesbet_2x2") s.set_perturbation("epstein_nesbet_2x2")
#s.unset_openmp() s.unset_openmp()
#print s print s
END_SHELL END_SHELL

View File

@ -47,7 +47,7 @@ subroutine davidson_diag_mrcc(dets_in,u_in,energies,dim_in,sze,N_st,Nint,iunit,i
!$OMP END DO !$OMP END DO
!$OMP DO SCHEDULE(guided) !$OMP DO SCHEDULE(guided)
do i=1,N_det_ref do i=1,N_det_ref
H_jj(idx_ref(i)) += delta_ii(i,istate) H_jj(idx_ref(i)) += delta_ii(istate,i)
enddo enddo
!$OMP END DO !$OMP END DO
!$OMP END PARALLEL !$OMP END PARALLEL
@ -269,7 +269,7 @@ subroutine davidson_diag_hjj_mrcc(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,Nin
to_print(2,k) = residual_norm(k) to_print(2,k) = residual_norm(k)
enddo enddo
write(iunit,'(X,I3,X,100(X,F16.10,X,E16.6))'), iter, to_print(:,1:N_st) write(iunit,'(X,I3,X,100(X,F16.10,X,E16.6))') iter, to_print(:,1:N_st)
call davidson_converged(lambda,residual_norm,wall,iter,cpu,N_st,converged) call davidson_converged(lambda,residual_norm,wall,iter,cpu,N_st,converged)
if (converged) then if (converged) then
exit exit
@ -487,8 +487,8 @@ subroutine H_u_0_mrcc(v_0,u_0,H_jj,n,keys_tmp,Nint,istate)
i = idx_ref(ii) i = idx_ref(ii)
do jj = 1, n_det_non_ref do jj = 1, n_det_non_ref
j = idx_non_ref(jj) j = idx_non_ref(jj)
vt (i) = vt (i) + delta_ij(ii,jj,istate)*u_0(j) vt (i) = vt (i) + delta_ij(istate,jj,ii)*u_0(j)
vt (j) = vt (j) + delta_ij(ii,jj,istate)*u_0(i) vt (j) = vt (j) + delta_ij(istate,jj,ii)*u_0(i)
enddo enddo
enddo enddo
!$OMP END DO !$OMP END DO

View File

@ -51,9 +51,9 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
integer(bit_kind), allocatable :: microlist(:,:,:), microlist_zero(:,:,:) integer(bit_kind), allocatable :: microlist(:,:,:), microlist_zero(:,:,:)
integer, allocatable :: idx_microlist(:), N_microlist(:), ptr_microlist(:), idx_microlist_zero(:) integer, allocatable :: idx_microlist(:), N_microlist(:), ptr_microlist(:), idx_microlist_zero(:)
integer :: mobiles(2), smallerlist integer :: mobiles(2), smallerlist
logical, external :: is_generable
print *, i_generator
leng = max(N_det_generators, N_det_non_ref) leng = max(N_det_generators, N_det_non_ref)
allocate(miniList(Nint, 2, leng), idx_minilist(leng), hij_cache(N_det_non_ref)) allocate(miniList(Nint, 2, leng), idx_minilist(leng), hij_cache(N_det_non_ref))
@ -69,7 +69,7 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
allocate( microlist(Nint,2,N_minilist*4), & allocate( microlist(Nint,2,N_minilist*4), &
idx_microlist(N_minilist*4)) idx_microlist(N_minilist*4))
if(key_mask(1,1) /= 0) then if(key_mask(1,1) /= 0_8) then
call create_microlist(miniList, N_minilist, key_mask, microlist, idx_microlist, N_microlist, ptr_microlist, Nint) call create_microlist(miniList, N_minilist, key_mask, microlist, idx_microlist, N_microlist, ptr_microlist, Nint)
call find_triples_and_quadruples_micro(i_generator,n_selected,det_buffer,Nint,tq,N_tq,microlist,ptr_microlist,N_microlist,key_mask) call find_triples_and_quadruples_micro(i_generator,n_selected,det_buffer,Nint,tq,N_tq,microlist,ptr_microlist,N_microlist,key_mask)
else else
@ -87,6 +87,7 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
! |alpha> ! |alpha>
if(N_tq > 0) then if(N_tq > 0) then
call create_minilist(key_mask, psi_non_ref, miniList, idx_minilist, N_det_non_ref, N_minilist, Nint) call create_minilist(key_mask, psi_non_ref, miniList, idx_minilist, N_det_non_ref, N_minilist, Nint)
if(N_minilist == 0) return if(N_minilist == 0) return
@ -117,8 +118,18 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
do i_alpha=1,N_tq do i_alpha=1,N_tq
! ok = .false.
! do i=N_det_generators, 1, -1
! if(is_generable(psi_det_generators(1,1,i), tq(1,1,i_alpha), Nint)) then
! ok = .true.
! exit
! end if
! end do
! if(.not. ok) then
! cycle
! end if
if(key_mask(1,1) /= 0) then if(key_mask(1,1) /= 0) then
call getMobiles(tq(1,1,i_alpha), key_mask, mobiles, Nint) call getMobiles(tq(1,1,i_alpha), key_mask, mobiles, Nint)
@ -138,37 +149,6 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
do j=1,idx_alpha(0) do j=1,idx_alpha(0)
idx_alpha(j) = idx_microlist_zero(idx_alpha(j)) idx_alpha(j) = idx_microlist_zero(idx_alpha(j))
end do end do
! i = 1
! j = 2
! do j = 2, idx_alpha_tmp(0)
! if(idx_alpha_tmp(j) < idx_alpha_tmp(j-1)) exit
! end do
!
! m = j
!
! idx_alpha(0) = idx_alpha_tmp(0)
!
! do l = 1, idx_alpha(0)
! if(j > idx_alpha_tmp(0)) then
! k = i
! i += 1
! else if(i >= m) then
! k = j
! j += 1
! else if(idx_alpha_tmp(i) < idx_alpha_tmp(j)) then
! k = i
! i += 1
! else
! k = j
! j += 1
! end if
! ! k=l
! idx_alpha(l) = idx_alpha_tmp(k)
! degree_alpha(l) = degree_alpha_tmp(k)
! end do
!
else else
call get_excitation_degree_vector(miniList,tq(1,1,i_alpha),degree_alpha,Nint,N_minilist,idx_alpha) call get_excitation_degree_vector(miniList,tq(1,1,i_alpha),degree_alpha,Nint,N_minilist,idx_alpha)
do j=1,idx_alpha(0) do j=1,idx_alpha(0)
@ -177,12 +157,6 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
end if end if
! call get_excitation_degree_vector(miniList,tq(1,1,i_alpha),degree_alpha,Nint,N_minilist,idx_alpha)
! do j=1,idx_alpha(0)
! idx_alpha(j) = idx_miniList(idx_alpha(j))
! end do
!print *, idx_alpha(:idx_alpha(0))
do l_sd=1,idx_alpha(0) do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd) k_sd = idx_alpha(l_sd)
call i_h_j(tq(1,1,i_alpha),psi_non_ref(1,1,idx_alpha(l_sd)),Nint,hij_cache(k_sd)) call i_h_j(tq(1,1,i_alpha),psi_non_ref(1,1,idx_alpha(l_sd)),Nint,hij_cache(k_sd))
@ -285,33 +259,31 @@ subroutine mrcc_dress(delta_ij_, delta_ii_, Nstates, Ndet_non_ref, Ndet_ref,i_ge
enddo enddo
enddo enddo
call omp_set_lock( psi_ref_lock(i_I) ) call omp_set_lock( psi_ref_lock(i_I) )
do i_state=1,Nstates do i_state=1,Nstates
if(dabs(psi_ref_coef(i_I,i_state)).ge.5.d-5)then if(dabs(psi_ref_coef(i_I,i_state)).ge.5.d-5)then
do l_sd=1,idx_alpha(0) do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd) k_sd = idx_alpha(l_sd)
delta_ij_(i_state,k_sd,i_I) = delta_ij_(i_state,k_sd,i_I) + dIa_hla(i_state,k_sd) delta_ij_(i_state,k_sd,i_I) = delta_ij_(i_state,k_sd,i_I) + dIa_hla(i_state,k_sd)
delta_ii_(i_state,i_I) = delta_ii_(i_state,i_I) - dIa_hla(i_state,k_sd) * ci_inv(i_state) * psi_non_ref_coef_transp(i_state,k_sd) delta_ii_(i_state,i_I) = delta_ii_(i_state,i_I) - dIa_hla(i_state,k_sd) * ci_inv(i_state) * psi_non_ref_coef_transp(i_state,k_sd)
enddo enddo
else else
delta_ii_(i_state,i_I) = 0.d0 !delta_ii_(i_state,i_I) = 0.d0
do l_sd=1,idx_alpha(0) do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd) k_sd = idx_alpha(l_sd)
delta_ij_(i_state,k_sd,i_I) = delta_ij_(i_state,k_sd,i_I) + dIa_hla(i_state,k_sd) delta_ij_(i_state,k_sd,i_I) = delta_ij_(i_state,k_sd,i_I) + dIa_hla(i_state,k_sd)
enddo enddo
endif endif
enddo enddo
call omp_unset_lock( psi_ref_lock(i_I) ) call omp_unset_lock( psi_ref_lock(i_I) )
enddo enddo
enddo enddo
!deallocate (dIa_hla,hij_cache) deallocate (dIa_hla,hij_cache)
!deallocate(miniList, idx_miniList) deallocate(miniList, idx_miniList)
end end
subroutine find_triples_and_quadruples(i_generator,n_selected,det_buffer,Nint,tq,N_tq,miniList,N_miniList) subroutine find_triples_and_quadruples(i_generator,n_selected,det_buffer,Nint,tq,N_tq,miniList,N_miniList)
use bitmasks use bitmasks
@ -360,7 +332,7 @@ subroutine find_triples_and_quadruples(i_generator,n_selected,det_buffer,Nint,tq
endif endif
enddo enddo
if (good) then if (good) then
if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint,N_det)) then if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint)) then
N_tq += 1 N_tq += 1
do k=1,N_int do k=1,N_int
tq(k,1,N_tq) = det_buffer(k,1,i) tq(k,1,N_tq) = det_buffer(k,1,i)
@ -437,7 +409,7 @@ subroutine find_triples_and_quadruples_micro(i_generator,n_selected,det_buffer,N
endif endif
enddo enddo
if (good) then if (good) then
if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint,N_det)) then if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint)) then
N_tq += 1 N_tq += 1
do k=1,N_int do k=1,N_int
tq(k,1,N_tq) = det_buffer(k,1,i) tq(k,1,N_tq) = det_buffer(k,1,i)

View File

@ -1,60 +1,3 @@
subroutine run_mrcc
implicit none
call set_generators_bitmasks_as_holes_and_particles
call mrcc_iterations
end
subroutine mrcc_iterations
implicit none
integer :: i,j
double precision :: E_new, E_old, delta_e
integer :: iteration,i_oscillations
double precision :: E_past(4), lambda
E_new = 0.d0
delta_E = 1.d0
iteration = 0
j = 1
i_oscillations = 0
lambda = 1.d0
do while (delta_E > 1.d-7)
iteration += 1
print *, '==========================='
print *, 'MRCC Iteration', iteration
print *, '==========================='
print *, ''
E_old = sum(ci_energy_dressed)
call write_double(6,ci_energy_dressed(1),"MRCC energy")
call diagonalize_ci_dressed(lambda)
E_new = sum(ci_energy_dressed)
delta_E = dabs(E_new - E_old)
! if (E_new > E_old) then
! lambda = lambda * 0.7d0
! else
! lambda = min(1.d0, lambda * 1.1d0)
! endif
! print *, 'energy lambda ', lambda
E_past(j) = E_new
j +=1
call save_wavefunction
if (iteration > 200) then
exit
endif
print*,'------------'
print*,'VECTOR'
do i = 1, N_det_ref
print*,''
print*,'psi_ref_coef(i,1) = ',psi_ref_coef(i,1)
print*,'delta_ii(i,1) = ',delta_ii(i,1)
enddo
print*,'------------'
enddo
call write_double(6,ci_energy_dressed(1),"Final MRCC energy")
call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1))
call save_wavefunction
end
subroutine set_generators_bitmasks_as_holes_and_particles subroutine set_generators_bitmasks_as_holes_and_particles
implicit none implicit none
@ -81,7 +24,4 @@ subroutine set_generators_bitmasks_as_holes_and_particles
enddo enddo
enddo enddo
touch generators_bitmask touch generators_bitmask
end end

View File

@ -1,5 +1,13 @@
BEGIN_PROVIDER [ double precision, lambda_mrcc, (N_states,psi_det_size) ] use bitmasks
BEGIN_PROVIDER [ integer, mrmode ]
mrmode = 0
END_PROVIDER
BEGIN_PROVIDER [ double precision, lambda_mrcc, (N_states, N_det_non_ref) ]
&BEGIN_PROVIDER [ integer, lambda_mrcc_pt2, (0:psi_det_size) ] &BEGIN_PROVIDER [ integer, lambda_mrcc_pt2, (0:psi_det_size) ]
&BEGIN_PROVIDER [ integer, lambda_mrcc_pt3, (0:psi_det_size) ]
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! cm/<Psi_0|H|D_m> or perturbative 1/Delta_E(m) ! cm/<Psi_0|H|D_m> or perturbative 1/Delta_E(m)
@ -8,48 +16,51 @@
double precision :: ihpsi_current(N_states) double precision :: ihpsi_current(N_states)
integer :: i_pert_count integer :: i_pert_count
double precision :: hii, lambda_pert double precision :: hii, lambda_pert
integer :: N_lambda_mrcc_pt2 integer :: N_lambda_mrcc_pt2, N_lambda_mrcc_pt3
i_pert_count = 0 i_pert_count = 0
lambda_mrcc = 0.d0 lambda_mrcc = 0.d0
N_lambda_mrcc_pt2 = 0 N_lambda_mrcc_pt2 = 0
N_lambda_mrcc_pt3 = 0
lambda_mrcc_pt2(0) = 0 lambda_mrcc_pt2(0) = 0
lambda_mrcc_pt3(0) = 0
do i=1,N_det_non_ref do i=1,N_det_non_ref
call i_h_psi(psi_non_ref(1,1,i), psi_ref, psi_ref_coef, N_int, N_det_ref,& call i_h_psi(psi_non_ref(1,1,i), psi_ref, psi_ref_coef, N_int, N_det_ref,&
size(psi_ref_coef,1), N_states,ihpsi_current) size(psi_ref_coef,1), N_states,ihpsi_current)
call i_H_j(psi_non_ref(1,1,i),psi_non_ref(1,1,i),N_int,hii) call i_H_j(psi_non_ref(1,1,i),psi_non_ref(1,1,i),N_int,hii)
do k=1,N_states do k=1,N_states
if (ihpsi_current(k) == 0.d0) then if (ihpsi_current(k) == 0.d0) then
ihpsi_current(k) = 1.d-32 ihpsi_current(k) = 1.d-32
endif
lambda_mrcc(k,i) = min(-1.d-32,psi_non_ref_coef(i,k)/ihpsi_current(k) )
lambda_pert = 1.d0 / (psi_ref_energy_diagonalized(k)-hii)
if (lambda_pert / lambda_mrcc(k,i) < 0.5d0) then
i_pert_count += 1
lambda_mrcc(k,i) = 0.d0
if (lambda_mrcc_pt2(N_lambda_mrcc_pt2) /= i) then
N_lambda_mrcc_pt2 += 1
lambda_mrcc_pt2(N_lambda_mrcc_pt2) = i
endif endif
lambda_mrcc(k,i) = min(0.d0,psi_non_ref_coef(i,k)/ihpsi_current(k) ) else
lambda_pert = 1.d0 / (psi_ref_energy_diagonalized(k)-hii) if (lambda_mrcc_pt3(N_lambda_mrcc_pt3) /= i) then
if (lambda_pert / lambda_mrcc(k,i) < 0.5d0) then N_lambda_mrcc_pt3 += 1
i_pert_count += 1 lambda_mrcc_pt3(N_lambda_mrcc_pt3) = i
lambda_mrcc(k,i) = 0.d0
if (lambda_mrcc_pt2(N_lambda_mrcc_pt2) /= i) then
N_lambda_mrcc_pt2 += 1
lambda_mrcc_pt2(N_lambda_mrcc_pt2) = i
endif
endif endif
enddo endif
enddo enddo
lambda_mrcc_pt2(0) = N_lambda_mrcc_pt2 enddo
lambda_mrcc_pt2(0) = N_lambda_mrcc_pt2
lambda_mrcc_pt3(0) = N_lambda_mrcc_pt3
print*,'N_det_non_ref = ',N_det_non_ref print*,'N_det_non_ref = ',N_det_non_ref
print*,'Number of ignored determinants = ',i_pert_count
print*,'psi_coef_ref_ratio = ',psi_ref_coef(2,1)/psi_ref_coef(1,1) print*,'psi_coef_ref_ratio = ',psi_ref_coef(2,1)/psi_ref_coef(1,1)
print*,'lambda max = ',maxval(dabs(lambda_mrcc)) print*,'lambda max = ',maxval(dabs(lambda_mrcc))
print*,'Number of ignored determinants = ',i_pert_count
END_PROVIDER END_PROVIDER
BEGIN_PROVIDER [ double precision, hij_mrcc, (N_det_non_ref,N_det_ref) ] BEGIN_PROVIDER [ double precision, hij_mrcc, (N_det_non_ref,N_det_ref) ]
implicit none implicit none
BEGIN_DOC BEGIN_DOC
@ -74,7 +85,9 @@ END_PROVIDER
delta_ij = 0.d0 delta_ij = 0.d0
delta_ii = 0.d0 delta_ii = 0.d0
call H_apply_mrcc(delta_ij,delta_ii,N_states,N_det_non_ref,N_det_ref) call H_apply_mrcc(delta_ij,delta_ii,N_states,N_det_non_ref,N_det_ref)
END_PROVIDER END_PROVIDER
BEGIN_PROVIDER [ double precision, h_matrix_dressed, (N_det,N_det,N_states) ] BEGIN_PROVIDER [ double precision, h_matrix_dressed, (N_det,N_det,N_states) ]
implicit none implicit none
@ -201,3 +214,763 @@ subroutine diagonalize_CI_dressed(lambda)
end end
logical function is_generable(det1, det2, Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind) :: det1(Nint, 2), det2(Nint, 2)
integer :: degree, f, exc(0:2, 2, 2), t
integer*2 :: h1, h2, p1, p2, s1, s2
integer, external :: searchExc
logical, external :: excEq
double precision :: phase
is_generable = .false.
call get_excitation(det1, det2, exc, degree, phase, Nint)
if(degree == -1) return
if(degree == 0) then
is_generable = .true.
return
end if
if(degree > 2) stop "?22??"
call decode_exc_int2(exc,degree,h1,p1,h2,p2,s1,s2)
if(degree == 1) then
h2 = h1
p2 = p1
s2 = s1
h1 = 0
p1 = 0
s1 = 0
end if
if(h1 + (s1-1)*mo_tot_num < h2 + (s2-1)*mo_tot_num) then
f = searchExc(hh_exists(1,1), (/s1, h1, s2, h2/), hh_shortcut(0))
else
f = searchExc(hh_exists(1,1), (/s2, h2, s1, h1/), hh_shortcut(0))
end if
if(f == -1) return
if(p1 + (s1-1)*mo_tot_num < p2 + (s2-1)*mo_tot_num) then
f = searchExc(pp_exists(1,hh_shortcut(f)), (/s1, p1, s2, p2/), hh_shortcut(f+1)-hh_shortcut(f))
else
f = searchExc(pp_exists(1,hh_shortcut(f)), (/s2, p2, s1, p1/), hh_shortcut(f+1)-hh_shortcut(f))
end if
if(f /= -1) is_generable = .true.
end function
integer function searchDet(dets, det, n, Nint)
implicit none
use bitmasks
integer(bit_kind),intent(in) :: dets(Nint,2,n), det(Nint,2)
integer, intent(in) :: nint, n
integer :: l, h, c
integer, external :: detCmp
logical, external :: detEq
l = 1
h = n
do while(.true.)
searchDet = (l+h)/2
c = detCmp(dets(1,1,searchDet), det(1,1), Nint)
if(c == 0) return
if(c == 1) then
h = searchDet-1
else
l = searchDet+1
end if
if(l > h) then
searchDet = -1
return
end if
end do
end function
integer function unsortedSearchDet(dets, det, n, Nint)
implicit none
use bitmasks
integer(bit_kind),intent(in) :: dets(Nint,2,n), det(Nint,2)
integer, intent(in) :: nint, n
integer :: l, h, c
integer, external :: detCmp
logical, external :: detEq
do l=1, n
if(detEq(det, dets(1,1,l), N_int)) then
unsortedSearchDet = l
return
end if
end do
unsortedSearchDet = -1
end function
integer function searchExc(excs, exc, n)
implicit none
use bitmasks
integer, intent(in) :: n
integer*2,intent(in) :: excs(4,n), exc(4)
integer :: l, h, c
integer, external :: excCmp
logical, external :: excEq
l = 1
h = n
do
searchExc = (l+h)/2
c = excCmp(excs(1,searchExc), exc(1))
if(c == 0) return
if(c == 1) then
h = searchExc-1
else
l = searchExc+1
end if
if(l > h) then
searchExc = -1
return
end if
end do
end function
subroutine sort_det(key, idx, N_key, Nint)
implicit none
integer, intent(in) :: Nint, N_key
integer(8),intent(inout) :: key(Nint,2,N_key)
integer,intent(inout) :: idx(N_key)
integer(8) :: tmp(Nint, 2)
integer :: tmpidx,i,ni
do i=1,N_key
idx(i) = i
end do
do i=N_key/2,1,-1
call tamiser(key, idx, i, N_key, Nint, N_key)
end do
do i=N_key,2,-1
do ni=1,Nint
tmp(ni,1) = key(ni,1,i)
tmp(ni,2) = key(ni,2,i)
key(ni,1,i) = key(ni,1,1)
key(ni,2,i) = key(ni,2,1)
key(ni,1,1) = tmp(ni,1)
key(ni,2,1) = tmp(ni,2)
enddo
tmpidx = idx(i)
idx(i) = idx(1)
idx(1) = tmpidx
call tamiser(key, idx, 1, i-1, Nint, N_key)
end do
end subroutine
subroutine sort_exc(key, N_key)
implicit none
integer, intent(in) :: N_key
integer*2,intent(inout) :: key(4,N_key)
integer*2 :: tmp(4)
integer :: i,ni
do i=N_key/2,1,-1
call tamise_exc(key, i, N_key, N_key)
end do
do i=N_key,2,-1
do ni=1,4
tmp(ni) = key(ni,i)
key(ni,i) = key(ni,1)
key(ni,1) = tmp(ni)
enddo
call tamise_exc(key, 1, i-1, N_key)
end do
end subroutine
logical function exc_inf(exc1, exc2)
implicit none
integer*2,intent(in) :: exc1(4), exc2(4)
integer :: i
exc_inf = .false.
do i=1,4
if(exc1(i) < exc2(i)) then
exc_inf = .true.
return
else if(exc1(i) > exc2(i)) then
return
end if
end do
end function
subroutine tamise_exc(key, no, n, N_key)
use bitmasks
implicit none
BEGIN_DOC
! Uncodumented : TODO
END_DOC
integer,intent(in) :: no, n, N_key
integer*2,intent(inout) :: key(4, N_key)
integer :: k,j
integer*2 :: tmp(4)
logical :: exc_inf
integer :: ni
k = no
j = 2*k
do while(j <= n)
if(j < n) then
if (exc_inf(key(1,j), key(1,j+1))) then
j = j+1
endif
endif
if(exc_inf(key(1,k), key(1,j))) then
do ni=1,4
tmp(ni) = key(ni,k)
key(ni,k) = key(ni,j)
key(ni,j) = tmp(ni)
enddo
k = j
j = k+k
else
return
endif
enddo
end subroutine
subroutine dec_exc(exc, h1, h2, p1, p2)
implicit none
integer :: exc(0:2,2,2), s1, s2, degree
integer*2, intent(out) :: h1, h2, p1, p2
degree = exc(0,1,1) + exc(0,1,2)
h1 = 0
h2 = 0
p1 = 0
p2 = 0
if(degree == 0) return
call decode_exc_int2(exc, degree, h1, p1, h2, p2, s1, s2)
h1 += mo_tot_num * (s1-1)
p1 += mo_tot_num * (s1-1)
if(degree == 2) then
h2 += mo_tot_num * (s2-1)
p2 += mo_tot_num * (s2-1)
if(h1 > h2) then
s1 = h1
h1 = h2
h2 = s1
end if
if(p1 > p2) then
s1 = p1
p1 = p2
p2 = s1
end if
else
h2 = h1
p2 = p1
p1 = 0
h1 = 0
end if
end subroutine
BEGIN_PROVIDER [ integer, N_hh_exists ]
&BEGIN_PROVIDER [ integer, N_pp_exists ]
&BEGIN_PROVIDER [ integer, N_ex_exists ]
implicit none
integer :: exc(0:2, 2, 2), degree, n, on, s, l, i
integer*2 :: h1, h2, p1, p2
double precision :: phase
logical,allocatable :: hh(:,:) , pp(:,:)
allocate(hh(0:mo_tot_num*2, 0:mo_tot_num*2))
allocate(pp(0:mo_tot_num*2, 0:mo_tot_num*2))
hh = .false.
pp = .false.
N_hh_exists = 0
N_pp_exists = 0
N_ex_exists = 0
n = 0
do i=1, N_det_ref
do l=1, N_det_non_ref
call get_excitation(psi_ref(1,1,i), psi_non_ref(1,1,l), exc, degree, phase, N_int)
if(degree == -1) cycle
call dec_exc(exc, h1, h2, p1, p2)
N_ex_exists += 1
if(.not. hh(h1,h2)) N_hh_exists = N_hh_exists + 1
if(.not. pp(p1,p2)) N_pp_exists = N_pp_exists + 1
hh(h1,h2) = .true.
pp(p1,p2) = .true.
end do
end do
N_pp_exists = min(N_ex_exists, N_pp_exists * N_hh_exists)
END_PROVIDER
BEGIN_PROVIDER [ integer(bit_kind), psi_non_ref_sorted, (N_int, 2, N_det_non_ref) ]
&BEGIN_PROVIDER [ integer, psi_non_ref_sorted_idx, (N_det_non_ref) ]
implicit none
psi_non_ref_sorted = psi_non_ref
call sort_det(psi_non_ref_sorted, psi_non_ref_sorted_idx, N_det_non_ref, N_int)
END_PROVIDER
BEGIN_PROVIDER [ double precision, dIj_unique, (hh_shortcut(hh_shortcut(0)+1)-1, N_states) ]
implicit none
logical :: ok
integer :: i, j, k, s, II, pp, hh, ind, wk, nex, a_col, at_row
integer, external :: searchDet, unsortedSearchDet
integer(bit_kind) :: myDet(N_int, 2), myMask(N_int, 2)
integer :: N, INFO, AtA_size, r1, r2
double precision , allocatable:: B(:), AtB(:), AtA_val(:), A_val(:,:), x(:), x_new(:), A_val_mwen(:)
double precision :: t, norm, cx
integer, allocatable :: A_ind(:,:), lref(:), AtA_ind(:), A_ind_mwen(:), col_shortcut(:), N_col(:)
nex = hh_shortcut(hh_shortcut(0)+1)-1
print *, "TI", nex, N_det_non_ref
allocate(A_ind(N_det_ref+1, nex), A_val(N_det_ref+1, nex))
allocate(AtA_ind(N_det_ref * nex), AtA_val(N_det_ref * nex)) !!!!! MAY BE TOO SMALL ? !!!!!!!!
allocate(x(nex), AtB(nex))
allocate(A_val_mwen(nex), A_ind_mwen(nex))
allocate(N_col(nex), col_shortcut(nex), B(N_det_non_ref))
allocate (x_new(nex))
do s = 1, N_states
A_val = 0d0
A_ind = 0
AtA_ind = 0
AtA_val = 0d0
x = 0d0
AtB = 0d0
A_val_mwen = 0d0
A_ind_mwen = 0
N_col = 0
col_shortcut = 0
B = 0d0
x_new = 0d0
!$OMP PARALLEL DO schedule(static,10) default(none) shared(psi_non_ref, hh_exists, pp_exists, N_int, A_val, A_ind) &
!$OMP shared(s, hh_shortcut, psi_ref_coef, N_det_non_ref, psi_non_ref_sorted, psi_non_ref_sorted_idx, psi_ref, N_det_ref) &
!$OMP private(lref, pp, II, ok, myMask, myDet, ind, wk)
do hh = 1, hh_shortcut(0)
do pp = hh_shortcut(hh), hh_shortcut(hh+1)-1
allocate(lref(N_det_non_ref))
lref = 0
do II = 1, N_det_ref
call apply_hole(psi_ref(1,1,II), hh_exists(1, hh), myMask, ok, N_int)
if(.not. ok) cycle
call apply_particle(myMask, pp_exists(1, pp), myDet, ok, N_int)
if(.not. ok) cycle
ind = searchDet(psi_non_ref_sorted(1,1,1), myDet(1,1), N_det_non_ref, N_int)
if(ind /= -1) then
lref(psi_non_ref_sorted_idx(ind)) = II
end if
end do
wk = 0
do i=1, N_det_non_ref
if(lref(i) /= 0) then
wk += 1
A_val(wk, pp) = psi_ref_coef(lref(i), s)
A_ind(wk, pp) = i
end if
end do
deallocate(lref)
end do
end do
!$OMP END PARALLEL DO
AtB = 0d0
AtA_size = 0
wk = 0
col_shortcut = 0
N_col = 0
!$OMP PARALLEL DO schedule(dynamic, 100) default(none) shared(k, psi_non_ref_coef, A_ind, A_val, x, N_det_ref, nex, N_det_non_ref) &
!$OMP private(at_row, a_col, t, i, r1, r2, wk, A_ind_mwen, A_val_mwen) &
!$OMP shared(col_shortcut, N_col, AtB, AtA_size, AtA_val, AtA_ind, s)
do at_row = 1, nex
wk = 0
if(mod(at_row, 10000) == 0) print *, "AtA", at_row, "/", nex
do i=1,N_det_ref
if(A_ind(i, at_row) == 0) exit
AtB(at_row) = AtB(at_row) + psi_non_ref_coef(A_ind(i, at_row), s) * A_val(i, at_row)
end do
do a_col = 1, nex
t = 0d0
r1 = 1
r2 = 1
do while(A_ind(r1, at_row) * A_ind(r2, a_col) /= 0)
if(A_ind(r1, at_row) < A_ind(r2, a_col)) then
r1 += 1
else if(A_ind(r1, at_row) > A_ind(r2, a_col)) then
r2 += 1
else
t = t - A_val(r1, at_row) * A_val(r2, a_col)
r1 += 1
r2 += 1
end if
end do
if(a_col == at_row) then
t = (t + 1d0)
end if
if(t /= 0d0) then
wk += 1
A_ind_mwen(wk) = a_col
A_val_mwen(wk) = t
end if
end do
if(wk /= 0) then
!$OMP CRITICAL
col_shortcut(at_row) = AtA_size+1
N_col(at_row) = wk
AtA_ind(AtA_size+1:AtA_size+wk) = A_ind_mwen(:wk)
AtA_val(AtA_size+1:AtA_size+wk) = A_val_mwen(:wk)
AtA_size += wk
!$OMP END CRITICAL
end if
end do
x = AtB
if(AtA_size > size(AtA_val)) stop "SIZA"
print *, "ATA SIZE", ata_size
integer :: iproc, omp_get_thread_num
iproc = omp_get_thread_num()
do i=1,nex
x_new(i) = 0.D0
enddo
do k=0,100000
!$OMP PARALLEL DO default(shared)
do i=1,nex
x_new(i) = AtB(i)
enddo
!$OMP PARALLEL DO default(shared) private(cx, i)
do a_col = 1, nex
cx = 0d0
do i=col_shortcut(a_col), col_shortcut(a_col) + N_col(a_col) - 1
cx += x(AtA_ind(i)) * AtA_val(i)
end do
x_new(a_col) += cx
end do
!$OMP END PARALLEL DO
double precision :: norm_cas
norm_cas = 0d0
do i = 1, N_det_ref
norm_cas += psi_ref_coef(i,s)**2
end do
norm = 0d0
t = 0d0
do j=1, size(X)
t = t + X_new(j) * X_new(j)
end do
t = (1d0 / norm_cas - 1d0) / t
x_new = x_new * sqrt(t)
do j=1, size(X)
norm += (X_new(j) - X(j))**2
x(j) = x_new(j)
end do
if(mod(k, 100) == 0) then
print *, "residu ", k, norm, "norm t", sqrt(t)
end if
if(norm < 1d-16) exit
end do
print *, "CONVERGENCE : ", norm
dIj_unique(:size(X), s) = X(:)
end do
print *, "done"
END_PROVIDER
BEGIN_PROVIDER [ double precision, dij, (N_det_ref, N_det_non_ref, N_states) ]
integer :: s,i,j
print *, "computing amplitudes..."
do s=1, N_states
do i=1, N_det_non_ref
do j=1, N_det_ref
dij(j, i, s) = get_dij_index(j, i, s, N_int)
end do
end do
end do
print *, "done computing amplitudes"
END_PROVIDER
double precision function get_dij_index(II, i, s, Nint)
integer, intent(in) :: II, i, s, Nint
double precision, external :: get_dij
double precision :: HIi
if(lambda_type == 0) then
get_dij_index = get_dij(psi_ref(1,1,II), psi_non_ref(1,1,i), s, Nint)
else
call i_h_j(psi_ref(1,1,II), psi_non_ref(1,1,i), Nint, HIi)
get_dij_index = HIi * lambda_mrcc(s, i)
end if
end function
double precision function get_dij(det1, det2, s, Nint)
use bitmasks
implicit none
integer, intent(in) :: s, Nint
integer(bit_kind) :: det1(Nint, 2), det2(Nint, 2)
integer :: degree, f, exc(0:2, 2, 2), t
integer*2 :: h1, h2, p1, p2, s1, s2
integer, external :: searchExc
logical, external :: excEq
double precision :: phase
get_dij = 0d0
call get_excitation(det1, det2, exc, degree, phase, Nint)
if(degree == -1) return
if(degree == 0) then
stop "get_dij"
end if
call decode_exc_int2(exc,degree,h1,p1,h2,p2,s1,s2)
if(degree == 1) then
h2 = h1
p2 = p1
s2 = s1
h1 = 0
p1 = 0
s1 = 0
end if
if(h1 + (s1-1)*mo_tot_num < h2 + (s2-1)*mo_tot_num) then
f = searchExc(hh_exists(1,1), (/s1, h1, s2, h2/), hh_shortcut(0))
else
f = searchExc(hh_exists(1,1), (/s2, h2, s1, h1/), hh_shortcut(0))
end if
if(f == -1) return
if(p1 + (s1-1)*mo_tot_num < p2 + (s2-1)*mo_tot_num) then
t = searchExc(pp_exists(1,hh_shortcut(f)), (/s1, p1, s2, p2/), hh_shortcut(f+1)-hh_shortcut(f))
else
t = searchExc(pp_exists(1,hh_shortcut(f)), (/s2, p2, s1, p1/), hh_shortcut(f+1)-hh_shortcut(f))
end if
if(t /= -1) then
get_dij = dIj_unique(t - 1 + hh_shortcut(f), s)
end if
end function
BEGIN_PROVIDER [ integer*2, hh_exists, (4, N_hh_exists) ]
&BEGIN_PROVIDER [ integer, hh_shortcut, (0:N_hh_exists + 1) ]
&BEGIN_PROVIDER [ integer*2, pp_exists, (4, N_pp_exists) ]
implicit none
integer*2,allocatable :: num(:,:)
integer :: exc(0:2, 2, 2), degree, n, on, s, l, i
integer*2 :: h1, h2, p1, p2
double precision :: phase
logical, external :: excEq
allocate(num(4, N_ex_exists+1))
hh_shortcut = 0
hh_exists = 0
pp_exists = 0
num = 0
n = 0
do i=1, N_det_ref
do l=1, N_det_non_ref
call get_excitation(psi_ref(1,1,i), psi_non_ref(1,1,l), exc, degree, phase, N_int)
if(degree == -1) cycle
call dec_exc(exc, h1, h2, p1, p2)
n += 1
num(:, n) = (/h1, h2, p1, p2/)
end do
end do
call sort_exc(num, n)
hh_shortcut(0) = 1
hh_shortcut(1) = 1
hh_exists(:,1) = (/1_2, num(1,1), 1_2, num(2,1)/)
pp_exists(:,1) = (/1_2, num(3,1), 1_2, num(4,1)/)
s = 1
do i=2,n
if(.not. excEq(num(1,i), num(1,s))) then
s += 1
num(:, s) = num(:, i)
pp_exists(:,s) = (/1_2, num(3,s), 1_2, num(4,s)/)
if(hh_exists(2, hh_shortcut(0)) /= num(1,s) .or. &
hh_exists(4, hh_shortcut(0)) /= num(2,s)) then
hh_shortcut(0) += 1
hh_shortcut(hh_shortcut(0)) = s
hh_exists(:,hh_shortcut(0)) = (/1_2, num(1,s), 1_2, num(2,s)/)
end if
end if
end do
hh_shortcut(hh_shortcut(0)+1) = s+1
do s=2,4,2
do i=1,hh_shortcut(0)
if(hh_exists(s, i) == 0) then
hh_exists(s-1, i) = 0
else if(hh_exists(s, i) > mo_tot_num) then
hh_exists(s, i) -= mo_tot_num
hh_exists(s-1, i) = 2
end if
end do
do i=1,hh_shortcut(hh_shortcut(0)+1)-1
if(pp_exists(s, i) == 0) then
pp_exists(s-1, i) = 0
else if(pp_exists(s, i) > mo_tot_num) then
pp_exists(s, i) -= mo_tot_num
pp_exists(s-1, i) = 2
end if
end do
end do
END_PROVIDER
logical function excEq(exc1, exc2)
implicit none
integer*2, intent(in) :: exc1(4), exc2(4)
integer :: i
excEq = .false.
do i=1, 4
if(exc1(i) /= exc2(i)) return
end do
excEq = .true.
end function
integer function excCmp(exc1, exc2)
implicit none
integer*2, intent(in) :: exc1(4), exc2(4)
integer :: i
excCmp = 0
do i=1, 4
if(exc1(i) > exc2(i)) then
excCmp = 1
return
else if(exc1(i) < exc2(i)) then
excCmp = -1
return
end if
end do
end function
subroutine apply_hole(det, exc, res, ok, Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer*2, intent(in) :: exc(4)
integer*2 :: s1, s2, h1, h2
integer(bit_kind),intent(in) :: det(Nint, 2)
integer(bit_kind),intent(out) :: res(Nint, 2)
logical, intent(out) :: ok
integer :: ii, pos
ok = .false.
s1 = exc(1)
h1 = exc(2)
s2 = exc(3)
h2 = exc(4)
res = det
if(h1 /= 0) then
ii = (h1-1)/bit_kind_size + 1
pos = mod(h1-1, 64)!iand(h1-1,bit_kind_size-1) ! mod 64
if(iand(det(ii, s1), ishft(1_bit_kind, pos)) == 0_8) return
res(ii, s1) = ibclr(res(ii, s1), pos)
end if
ii = (h2-1)/bit_kind_size + 1
pos = mod(h2-1, 64)!iand(h2-1,bit_kind_size-1)
if(iand(det(ii, s2), ishft(1_bit_kind, pos)) == 0_8) return
res(ii, s2) = ibclr(res(ii, s2), pos)
ok = .true.
end subroutine
subroutine apply_particle(det, exc, res, ok, Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer*2, intent(in) :: exc(4)
integer*2 :: s1, s2, p1, p2
integer(bit_kind),intent(in) :: det(Nint, 2)
integer(bit_kind),intent(out) :: res(Nint, 2)
logical, intent(out) :: ok
integer :: ii, pos
ok = .false.
s1 = exc(1)
p1 = exc(2)
s2 = exc(3)
p2 = exc(4)
res = det
if(p1 /= 0) then
ii = (p1-1)/bit_kind_size + 1
pos = mod(p1-1, 64)!iand(p1-1,bit_kind_size-1)
if(iand(det(ii, s1), ishft(1_bit_kind, pos)) /= 0_8) return
res(ii, s1) = ibset(res(ii, s1), pos)
end if
ii = (p2-1)/bit_kind_size + 1
pos = mod(p2-1, 64)!iand(p2-1,bit_kind_size-1)
if(iand(det(ii, s2), ishft(1_bit_kind, pos)) /= 0_8) return
res(ii, s2) = ibset(res(ii, s2), pos)
ok = .true.
end subroutine

View File

@ -0,0 +1,5 @@
[lambda_type]
type: Strictly_positive_int
doc: lambda type ( 0 = none, 1 = last version )
interface: ezfio,provider,ocaml
default: 0

View File

@ -0,0 +1 @@
Perturbation Selectors_full Generators_full Psiref_CAS MRCC_Utils ZMQ

View File

@ -0,0 +1,12 @@
=======
mrcepa0
=======
Needed Modules
==============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.
Documentation
=============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,593 @@
subroutine mrsc2_dressing_slave_tcp(i)
implicit none
integer, intent(in) :: i
BEGIN_DOC
! Task for parallel MR-SC2
END_DOC
call mrsc2_dressing_slave(0,i)
end
subroutine mrsc2_dressing_slave_inproc(i)
implicit none
integer, intent(in) :: i
BEGIN_DOC
! Task for parallel MR-SC2
END_DOC
call mrsc2_dressing_slave(1,i)
end
subroutine mrsc2_dressing_slave(thread,iproc)
use f77_zmq
implicit none
BEGIN_DOC
! Task for parallel MR-SC2
END_DOC
integer, intent(in) :: thread, iproc
! integer :: j,l
integer :: rc
integer :: worker_id, task_id
character*(512) :: task
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer(ZMQ_PTR), external :: new_zmq_push_socket
integer(ZMQ_PTR) :: zmq_socket_push
double precision, allocatable :: delta(:,:,:)
integer :: i_state, i, i_I, J, k, k2, k1, kk, ll, degree, degree2, m, l, deg, ni, m2
integer :: n(2)
integer :: p1,p2,h1,h2,s1,s2, blok, I_s, J_s, kn
logical :: ok
double precision :: phase_iI, phase_Ik, phase_Jl, phase_Ji, phase_al
double precision :: diI, hIi, hJi, delta_JI, dkI, HkI, ci_inv(N_states), cj_inv(N_states)
double precision :: contrib, wall, iwall
double precision, allocatable :: dleat(:,:,:)
integer, dimension(0:2,2,2) :: exc_iI, exc_Ik, exc_IJ
integer(bit_kind) :: det_tmp(N_int, 2), det_tmp2(N_int, 2), inac, virt
integer, external :: get_index_in_psi_det_sorted_bit, searchDet, detCmp
logical, external :: is_in_wavefunction, isInCassd, detEq
integer,allocatable :: komon(:)
logical :: komoned
!double precision, external :: get_dij
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
zmq_socket_push = new_zmq_push_socket(thread)
call connect_to_taskserver(zmq_to_qp_run_socket,worker_id,thread)
allocate (dleat(N_states, N_det_non_ref, 2), delta(N_states,0:N_det_non_ref, 2))
allocate(komon(0:N_det_non_ref))
do
call get_task_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id, task)
if (task_id == 0) exit
read (task,*) i_I, J, k1, k2
do i_state=1, N_states
ci_inv(i_state) = 1.d0 / psi_ref_coef(i_I,i_state)
cj_inv(i_state) = 1.d0 / psi_ref_coef(J,i_state)
end do
!delta = 0.d0
n = 0
delta(:,0,:) = 0d0
delta(:,:nlink(J),1) = 0d0
delta(:,:nlink(i_I),2) = 0d0
komon(0) = 0
komoned = .false.
do kk = k1, k2
k = det_cepa0_idx(linked(kk, i_I))
blok = blokMwen(kk, i_I)
call get_excitation(psi_ref(1,1,i_I),psi_non_ref(1,1,k),exc_Ik,degree,phase_Ik,N_int)
if(J /= i_I) then
call apply_excitation(psi_ref(1,1,J),exc_Ik,det_tmp2,ok,N_int)
if(.not. ok) cycle
l = searchDet(det_cepa0(1,1,cepa0_shortcut(blok)), det_tmp2, cepa0_shortcut(blok+1)-cepa0_shortcut(blok), N_int)
if(l == -1) cycle
ll = cepa0_shortcut(blok)-1+l
l = det_cepa0_idx(ll)
ll = child_num(ll, J)
else
l = k
ll = kk
end if
if(.not. komoned) then
m = 0
m2 = 0
do while(m < nlink(i_I) .and. m2 < nlink(J))
m += 1
m2 += 1
if(linked(m, i_I) < linked(m2, J)) then
m2 -= 1
cycle
else if(linked(m, i_I) > linked(m2, J)) then
m -= 1
cycle
end if
i = det_cepa0_idx(linked(m, i_I))
if(h_(J,i) == 0.d0) cycle
if(h_(i_I,i) == 0.d0) cycle
!ok = .false.
!do i_state=1, N_states
! if(lambda_mrcc(i_state, i) /= 0d0) then
! ok = .true.
! exit
! end if
!end do
!if(.not. ok) cycle
!
komon(0) += 1
kn = komon(0)
komon(kn) = i
! call get_excitation(psi_ref(1,1,J),psi_non_ref(1,1,i),exc_IJ,degree2,phase_Ji,N_int)
! if(I_i /= J) call get_excitation(psi_ref(1,1,I_i),psi_non_ref(1,1,i),exc_IJ,degree2,phase_Ii,N_int)
! if(I_i == J) phase_Ii = phase_Ji
do i_state = 1,N_states
dkI = h_(J,i) * dij(i_I, i, i_state)!get_dij(psi_ref(1,1,i_I), psi_non_ref(1,1,i), N_int)
!dkI = h_(J,i) * h_(i_I,i) * lambda_mrcc(i_state, i)
dleat(i_state, kn, 1) = dkI
dleat(i_state, kn, 2) = dkI
end do
end do
komoned = .true.
end if
do m = 1, komon(0)
i = komon(m)
call apply_excitation(psi_non_ref(1,1,i),exc_Ik,det_tmp,ok,N_int)
if(.not. ok) cycle
if(HP(1,i) + HP(1,k) <= 2 .and. HP(2,i) + HP(2,k) <= 2) then
! if(is_in_wavefunction(det_tmp, N_int)) cycle
cycle
end if
!if(isInCassd(det_tmp, N_int)) cycle
do i_state = 1, N_states
!if(lambda_mrcc(i_state, i) == 0d0) cycle
!contrib = h_(i_I,k) * lambda_mrcc(i_state, k) * dleat(i_state, m, 2)! * phase_al
contrib = dij(i_I, k, i_state) * dleat(i_state, m, 2)
delta(i_state,ll,1) += contrib
if(dabs(psi_ref_coef(i_I,i_state)).ge.5.d-5) then
delta(i_state,0,1) -= contrib * ci_inv(i_state) * psi_non_ref_coef(l,i_state)
endif
if(I_i == J) cycle
!contrib = h_(J,l) * lambda_mrcc(i_state, l) * dleat(i_state, m, 1)! * phase_al
contrib = dij(J, l, i_state) * dleat(i_state, m, 1)
delta(i_state,kk,2) += contrib
if(dabs(psi_ref_coef(J,i_state)).ge.5.d-5) then
delta(i_state,0,2) -= contrib * cj_inv(i_state) * psi_non_ref_coef(k,i_state)
end if
enddo !i_state
end do ! while
end do ! kk
call push_mrsc2_results(zmq_socket_push, I_i, J, delta, task_id)
call task_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id)
! end if
enddo
deallocate(delta)
call disconnect_from_taskserver(zmq_to_qp_run_socket,zmq_socket_push,worker_id)
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
call end_zmq_push_socket(zmq_socket_push,thread)
end
subroutine push_mrsc2_results(zmq_socket_push, I_i, J, delta, task_id)
use f77_zmq
implicit none
BEGIN_DOC
! Push integrals in the push socket
END_DOC
integer, intent(in) :: i_I, J
integer(ZMQ_PTR), intent(in) :: zmq_socket_push
double precision,intent(inout) :: delta(N_states, 0:N_det_non_ref, 2)
integer, intent(in) :: task_id
integer :: rc , i_state, i, kk, li
integer,allocatable :: idx(:,:)
integer ::n(2)
logical :: ok
allocate(idx(N_det_non_ref,2))
rc = f77_zmq_send( zmq_socket_push, i_I, 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, i_I, 4, ZMQ_SNDMORE)'
stop 'error'
endif
rc = f77_zmq_send( zmq_socket_push, J, 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, J, 4, ZMQ_SNDMORE)'
stop 'error'
endif
do kk=1,2
n(kk)=0
if(kk == 1) li = nlink(j)
if(kk == 2) li = nlink(i_I)
do i=1, li
ok = .false.
do i_state=1,N_states
if(delta(i_state, i, kk) /= 0d0) then
ok = .true.
exit
end if
end do
if(ok) then
n(kk) += 1
! idx(n,kk) = i
if(kk == 1) then
idx(n(1),1) = det_cepa0_idx(linked(i, J))
else
idx(n(2),2) = det_cepa0_idx(linked(i, i_I))
end if
do i_state=1, N_states
delta(i_state, n(kk), kk) = delta(i_state, i, kk)
end do
end if
end do
rc = f77_zmq_send( zmq_socket_push, n(kk), 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, n, 4, ZMQ_SNDMORE)'
stop 'error'
endif
if(n(kk) /= 0) then
rc = f77_zmq_send( zmq_socket_push, delta(1,0,kk), (n(kk)+1)*8*N_states, ZMQ_SNDMORE) ! delta(1,0,1) = delta_I delta(1,0,2) = delta_J
if (rc /= (n(kk)+1)*8*N_states) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, delta, (n(kk)+1)*8*N_states, ZMQ_SNDMORE)'
stop 'error'
endif
rc = f77_zmq_send( zmq_socket_push, idx(1,kk), n(kk)*4, ZMQ_SNDMORE)
if (rc /= n(kk)*4) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, delta, 8*n(kk), ZMQ_SNDMORE)'
stop 'error'
endif
end if
end do
rc = f77_zmq_send( zmq_socket_push, task_id, 4, 0)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_send( zmq_socket_push, task_id, 4, 0)'
stop 'error'
endif
! ! Activate is zmq_socket_push is a REQ
! integer :: idummy
! rc = f77_zmq_recv( zmq_socket_push, idummy, 4, 0)
! if (rc /= 4) then
! print *, irp_here, 'f77_zmq_send( zmq_socket_push, idummy, 4, 0)'
! stop 'error'
! endif
end
subroutine pull_mrsc2_results(zmq_socket_pull, I_i, J, n, idx, delta, task_id)
use f77_zmq
implicit none
BEGIN_DOC
! Push integrals in the push socket
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
integer, intent(out) :: i_I, J, n(2)
double precision, intent(inout) :: delta(N_states, 0:N_det_non_ref, 2)
integer, intent(out) :: task_id
integer :: rc , i, kk
integer,intent(inout) :: idx(N_det_non_ref,2)
logical :: ok
rc = f77_zmq_recv( zmq_socket_pull, i_I, 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, i_I, 4, ZMQ_SNDMORE)'
stop 'error'
endif
rc = f77_zmq_recv( zmq_socket_pull, J, 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, J, 4, ZMQ_SNDMORE)'
stop 'error'
endif
do kk = 1, 2
rc = f77_zmq_recv( zmq_socket_pull, n(kk), 4, ZMQ_SNDMORE)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, n, 4, ZMQ_SNDMORE)'
stop 'error'
endif
if(n(kk) /= 0) then
rc = f77_zmq_recv( zmq_socket_pull, delta(1,0,kk), (n(kk)+1)*8*N_states, ZMQ_SNDMORE)
if (rc /= (n(kk)+1)*8*N_states) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, delta, (n(kk)+1)*8*N_states, ZMQ_SNDMORE)'
stop 'error'
endif
rc = f77_zmq_recv( zmq_socket_pull, idx(1,kk), n(kk)*4, ZMQ_SNDMORE)
if (rc /= n(kk)*4) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, delta, n(kk)*4, ZMQ_SNDMORE)'
stop 'error'
endif
end if
end do
rc = f77_zmq_recv( zmq_socket_pull, task_id, 4, 0)
if (rc /= 4) then
print *, irp_here, 'f77_zmq_recv( zmq_socket_pull, task_id, 4, 0)'
stop 'error'
endif
! ! Activate is zmq_socket_pull is a REP
! integer :: idummy
! rc = f77_zmq_send( zmq_socket_pull, idummy, 4, 0)
! if (rc /= 4) then
! print *, irp_here, 'f77_zmq_send( zmq_socket_pull, idummy, 4, 0)'
! stop 'error'
! endif
end
subroutine mrsc2_dressing_collector(delta_ii_,delta_ij_)
use f77_zmq
implicit none
BEGIN_DOC
! Collects results from the AO integral calculation
END_DOC
double precision,intent(inout) :: delta_ij_(N_states,N_det_non_ref,N_det_ref)
double precision,intent(inout) :: delta_ii_(N_states,N_det_ref)
! integer :: j,l
integer :: rc
double precision, allocatable :: delta(:,:,:)
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer(ZMQ_PTR), external :: new_zmq_pull_socket
integer(ZMQ_PTR) :: zmq_socket_pull
integer*8 :: control, accu
integer :: task_id, more
integer :: I_i, J, l, i_state, n(2), kk
integer,allocatable :: idx(:,:)
delta_ii_(:,:) = 0d0
delta_ij_(:,:,:) = 0d0
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
zmq_socket_pull = new_zmq_pull_socket()
allocate ( delta(N_states,0:N_det_non_ref,2) )
allocate(idx(N_det_non_ref,2))
more = 1
do while (more == 1)
call pull_mrsc2_results(zmq_socket_pull, I_i, J, n, idx, delta, task_id)
do l=1, n(1)
do i_state=1,N_states
delta_ij_(i_state,idx(l,1),i_I) += delta(i_state,l,1)
end do
end do
do l=1, n(2)
do i_state=1,N_states
delta_ij_(i_state,idx(l,2),J) += delta(i_state,l,2)
end do
end do
!
! do l=1,nlink(J)
! do i_state=1,N_states
! delta_ij_(i_state,det_cepa0_idx(linked(l,J)),i_I) += delta(i_state,l,1)
! delta_ij_(i_state,det_cepa0_idx(linked(l,i_I)),j) += delta(i_state,l,2)
! end do
! end do
!
if(n(1) /= 0) then
do i_state=1,N_states
delta_ii_(i_state,i_I) += delta(i_state,0,1)
end do
end if
if(n(2) /= 0) then
do i_state=1,N_states
delta_ii_(i_state,J) += delta(i_state,0,2)
end do
end if
if (task_id /= 0) then
call zmq_delete_task(zmq_to_qp_run_socket,zmq_socket_pull,task_id,more)
endif
enddo
deallocate( delta )
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
call end_zmq_pull_socket(zmq_socket_pull)
end
BEGIN_PROVIDER [ double precision, delta_ij_old, (N_states,N_det_non_ref,N_det_ref) ]
&BEGIN_PROVIDER [ double precision, delta_ii_old, (N_states,N_det_ref) ]
implicit none
integer :: i_state, i, i_I, J, k, kk, degree, degree2, m, l, deg, ni, m2
integer :: p1,p2,h1,h2,s1,s2, blok, I_s, J_s, nex, nzer, ntot
! integer, allocatable :: linked(:,:), blokMwen(:, :), nlink(:)
logical :: ok
double precision :: phase_iI, phase_Ik, phase_Jl, phase_Ji, phase_al, diI, hIi, hJi, delta_JI, dkI(N_states), HkI, ci_inv(N_states), dia_hla(N_states)
double precision :: contrib, wall, iwall ! , searchance(N_det_ref)
integer, dimension(0:2,2,2) :: exc_iI, exc_Ik, exc_IJ
integer(bit_kind) :: det_tmp(N_int, 2), det_tmp2(N_int, 2), inac, virt
integer, external :: get_index_in_psi_det_sorted_bit, searchDet, detCmp
logical, external :: is_in_wavefunction, isInCassd, detEq
character*(512) :: task
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer :: KKsize = 1000000
call new_parallel_job(zmq_to_qp_run_socket,'mrsc2')
call wall_time(iwall)
! allocate(linked(N_det_non_ref, N_det_ref), blokMwen(N_det_non_ref, N_det_ref), nlink(N_det_ref))
! searchance = 0d0
! do J = 1, N_det_ref
! nlink(J) = 0
! do blok=1,cepa0_shortcut(0)
! do k=cepa0_shortcut(blok), cepa0_shortcut(blok+1)-1
! call get_excitation_degree(psi_ref(1,1,J),det_cepa0(1,1,k),degree,N_int)
! if(degree <= 2) then
! nlink(J) += 1
! linked(nlink(J),J) = k
! blokMwen(nlink(J),J) = blok
! searchance(J) += 1d0 + log(dfloat(cepa0_shortcut(blok+1) - cepa0_shortcut(blok)))
! end if
! end do
! end do
! end do
! stop
nzer = 0
ntot = 0
do nex = 3, 0, -1
print *, "los ",nex
do I_s = N_det_ref, 1, -1
! if(mod(I_s,1) == 0) then
! call wall_time(wall)
! wall = wall-iwall
! print *, I_s, "/", N_det_ref, wall * (dfloat(N_det_ref) / dfloat(I_s)), wall, wall * (dfloat(N_det_ref) / dfloat(I_s))-wall
! end if
do J_s = 1, I_s
call get_excitation_degree(psi_ref(1,1,J_s), psi_ref(1,1,I_s), degree, N_int)
if(degree /= nex) cycle
if(nex == 3) nzer = nzer + 1
ntot += 1
! if(degree > 3) then
! deg += 1
! cycle
! else if(degree == -10) then
! KKsize = 100000
! else
! KKsize = 1000000
! end if
if(searchance(I_s) < searchance(J_s)) then
i_I = I_s
J = J_s
else
i_I = J_s
J = I_s
end if
KKsize = nlink(1)
if(nex == 0) KKsize = int(float(nlink(1)) / float(nlink(i_I)) * (float(nlink(1)) / 64d0))
!if(KKsize == 0) stop "ZZEO"
do kk = 1 , nlink(i_I), KKsize
write(task,*) I_i, J, kk, int(min(kk+KKsize-1, nlink(i_I)))
call add_task_to_taskserver(zmq_to_qp_run_socket,task)
end do
! do kk = 1 , nlink(i_I)
! k = linked(kk,i_I)
! blok = blokMwen(kk,i_I)
! write(task,*) I_i, J, k, blok
! call add_task_to_taskserver(zmq_to_qp_run_socket,task)
!
! enddo !kk
enddo !J
enddo !I
end do ! nex
print *, "tasked"
! integer(ZMQ_PTR) collector_thread
! external ao_bielec_integrals_in_map_collector
! rc = pthread_create(collector_thread, mrsc2_dressing_collector)
print *, nzer, ntot, float(nzer) / float(ntot)
provide nproc
!$OMP PARALLEL DEFAULT(none) SHARED(delta_ii_old,delta_ij_old) PRIVATE(i) NUM_THREADS(nproc+1)
i = omp_get_thread_num()
if (i==0) then
call mrsc2_dressing_collector(delta_ii_old,delta_ij_old)
else
call mrsc2_dressing_slave_inproc(i)
endif
!$OMP END PARALLEL
! rc = pthread_join(collector_thread)
call end_parallel_job(zmq_to_qp_run_socket, 'mrsc2')
END_PROVIDER

View File

@ -0,0 +1,19 @@
program mrsc2sub
implicit none
double precision, allocatable :: energy(:)
allocate (energy(N_states))
!mrmode : 1=mrcepa0, 2=mrsc2 add, 3=mrcc
mrmode = 3
read_wf = .True.
SOFT_TOUCH read_wf
call print_cas_coefs
call set_generators_bitmasks_as_holes_and_particles
call run(N_states,energy)
if(do_pt2_end)then
call run_pt2(N_states,energy)
endif
deallocate(energy)
end

View File

@ -0,0 +1,19 @@
program mrcepa0
implicit none
double precision, allocatable :: energy(:)
allocate (energy(N_states))
!mrmode : 1=mrcepa0, 2=mrsc2 add, 3=mrcc
mrmode = 1
read_wf = .True.
SOFT_TOUCH read_wf
call print_cas_coefs
call set_generators_bitmasks_as_holes_and_particles
call run(N_states,energy)
if(do_pt2_end)then
call run_pt2(N_states,energy)
endif
deallocate(energy)
end

View File

@ -0,0 +1,169 @@
subroutine run(N_st,energy)
implicit none
integer, intent(in) :: N_st
double precision, intent(out) :: energy(N_st)
integer :: i,j
double precision :: E_new, E_old, delta_e
integer :: iteration
double precision :: E_past(4), lambda
integer :: n_it_mrcc_max
double precision :: thresh_mrcc
thresh_mrcc = 1d-7
n_it_mrcc_max = 10
if(n_it_mrcc_max == 1) then
do j=1,N_states_diag
do i=1,N_det
psi_coef(i,j) = CI_eigenvectors_dressed(i,j)
enddo
enddo
SOFT_TOUCH psi_coef ci_energy_dressed
call write_double(6,ci_energy_dressed(1),"Final MRCC energy")
call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1))
call save_wavefunction
energy(:) = ci_energy_dressed(:)
else
E_new = 0.d0
delta_E = 1.d0
iteration = 0
lambda = 1.d0
do while (delta_E > thresh_mrcc)
iteration += 1
print *, '==========================='
print *, 'MRCEPA0 Iteration', iteration
print *, '==========================='
print *, ''
E_old = sum(ci_energy_dressed)
call write_double(6,ci_energy_dressed(1),"MRCEPA0 energy")
call diagonalize_ci_dressed(lambda)
E_new = sum(ci_energy_dressed)
delta_E = dabs(E_new - E_old)
call save_wavefunction
call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1))
if (iteration > n_it_mrcc_max) then
exit
endif
enddo
call write_double(6,ci_energy_dressed(1),"Final MRCEPA0 energy")
energy(:) = ci_energy_dressed(:)
endif
end
subroutine run_pt2(N_st,energy)
implicit none
integer :: i,j,k
double precision, allocatable :: pt2(:), norm_pert(:), H_pert_diag(:)
integer, intent(in) :: N_st
double precision, intent(in) :: energy(N_st)
double precision :: pt3(N_st)
allocate (pt2(N_st), norm_pert(N_st),H_pert_diag(N_st))
pt2 = 0.d0
pt3 = 0d0
!if(lambda_mrcc_pt2(0) == 0) return
print*,'Last iteration only to compute the PT2'
threshold_selectors = 1.d0
threshold_generators = 0.999d0
N_det_generators = lambda_mrcc_pt3(0) + N_det_ref
N_det_selectors = lambda_mrcc_pt3(0) + N_det_ref
psi_det_generators(:,:,:N_det_ref) = psi_ref(:,:,:N_det_ref)
psi_selectors(:,:,:N_det_ref) = psi_ref(:,:,:N_det_ref)
psi_coef_generators(:N_det_ref,:) = psi_ref_coef(:N_det_ref,:)
psi_selectors_coef(:N_det_ref,:) = psi_ref_coef(:N_det_ref,:)
do i=N_det_ref+1,N_det_generators
j = lambda_mrcc_pt3(i-N_det_ref)
do k=1,N_int
psi_det_generators(k,1,i) = psi_non_ref(k,1,j)
psi_det_generators(k,2,i) = psi_non_ref(k,2,j)
psi_selectors(k,1,i) = psi_non_ref(k,1,j)
psi_selectors(k,2,i) = psi_non_ref(k,2,j)
enddo
do k=1,N_st
psi_coef_generators(i,k) = psi_non_ref_coef(j,k)
psi_selectors_coef(i,k) = psi_non_ref_coef(j,k)
enddo
enddo
SOFT_TOUCH N_det_selectors psi_selectors_coef psi_selectors N_det_generators psi_det_generators psi_coef_generators ci_eigenvectors_dressed ci_eigenvectors_s2_dressed ci_electronic_energy_dressed
SOFT_TOUCH psi_ref_coef_diagonalized psi_ref_energy_diagonalized! psi_coef_energy_diagonalized
call H_apply_mrcepa_PT2(pt2, norm_pert, H_pert_diag, N_st)
N_det_generators = N_det_non_ref + N_det_ref
N_det_selectors = N_det_non_ref + N_det_ref
psi_det_generators(:,:,:N_det_ref) = psi_ref(:,:,:N_det_ref)
psi_selectors(:,:,:N_det_ref) = psi_ref(:,:,:N_det_ref)
psi_coef_generators(:N_det_ref,:) = psi_ref_coef(:N_det_ref,:)
psi_selectors_coef(:N_det_ref,:) = psi_ref_coef(:N_det_ref,:)
do i=N_det_ref+1,N_det_generators
j = i-N_det_ref
do k=1,N_int
psi_det_generators(k,1,i) = psi_non_ref(k,1,j)
psi_det_generators(k,2,i) = psi_non_ref(k,2,j)
psi_selectors(k,1,i) = psi_non_ref(k,1,j)
psi_selectors(k,2,i) = psi_non_ref(k,2,j)
enddo
do k=1,N_st
psi_coef_generators(i,k) = psi_non_ref_coef(j,k)
psi_selectors_coef(i,k) = psi_non_ref_coef(j,k)
enddo
enddo
SOFT_TOUCH N_det_selectors psi_selectors_coef psi_selectors N_det_generators psi_det_generators psi_coef_generators ci_eigenvectors_dressed ci_eigenvectors_s2_dressed ci_electronic_energy_dressed
SOFT_TOUCH psi_ref_coef_diagonalized psi_ref_energy_diagonalized! psi_coef_energy_diagonalized
call H_apply_mrcepa_PT2(pt3, norm_pert, H_pert_diag, N_st)
!!!!!!!!!!!!!!!!
print *, "2-3 :",pt2, pt3
print *, lambda_mrcc_pt3(0), N_det, N_det_ref, psi_coef(1,1), psi_ref_coef(1,1)
pt2 = pt2 - pt3
print *, 'Final step'
print *, 'N_det = ', N_det
print *, 'N_states = ', N_states
print *, 'PT2 = ', pt2
print *, 'E = ', energy
print *, 'E+PT2 = ', energy+pt2
print *, '-----'
call ezfio_set_full_ci_energy_pt2(energy+pt2)
deallocate(pt2,norm_pert)
end
subroutine print_cas_coefs
implicit none
integer :: i,j
print *, 'CAS'
print *, '==='
do i=1,N_det_cas
print *, psi_cas_coef(i,:)
call debug_det(psi_cas(1,1,i),N_int)
enddo
call write_double(6,ci_energy(1),"Initial CI energy")
end

View File

@ -0,0 +1,19 @@
program mrsc2
implicit none
double precision, allocatable :: energy(:)
allocate (energy(N_states))
!mrmode : 1=mrcepa0, 2=mrsc2 add, 3=mrcc
mrmode = 2
read_wf = .True.
SOFT_TOUCH read_wf
call print_cas_coefs
call set_generators_bitmasks_as_holes_and_particles
call run(N_states,energy)
if(do_pt2_end)then
call run_pt2(N_states,energy)
endif
deallocate(energy)
end

View File

@ -11,7 +11,7 @@ subroutine $subroutine_diexc(key_in, key_prev, hole_1,particl_1, hole_2, particl
integer(bit_kind), intent(in) :: key_prev(N_int, 2, *) integer(bit_kind), intent(in) :: key_prev(N_int, 2, *)
PROVIDE N_int PROVIDE N_int
PROVIDE N_det PROVIDE N_det
$declarations $declarations
@ -180,7 +180,7 @@ subroutine $subroutine_diexcOrg(key_in,key_mask,hole_1,particl_1,hole_2, particl
$initialization $initialization
$omp_parallel $omp_parallel
!$ iproc = omp_get_thread_num() !$ iproc = omp_get_thread_num()
allocate (keys_out(N_int,2,size_max), hole_save(N_int,2), & allocate (keys_out(N_int,2,size_max), hole_save(N_int,2), &

View File

@ -165,7 +165,7 @@ logical function is_connected_to(key,keys,Nint,Ndet)
integer :: i, l integer :: i, l
integer :: degree_x2 integer :: degree_x2
logical, external :: is_generable_cassd
ASSERT (Nint > 0) ASSERT (Nint > 0)
ASSERT (Nint == N_int) ASSERT (Nint == N_int)
@ -183,12 +183,35 @@ logical function is_connected_to(key,keys,Nint,Ndet)
if (degree_x2 > 4) then if (degree_x2 > 4) then
cycle cycle
else else
! if(.not. is_generable_cassd(keys(1,1,i), key(1,1), Nint)) cycle !!!Nint==1 !!!!!
is_connected_to = .true. is_connected_to = .true.
return return
endif endif
enddo enddo
end end
logical function is_generable_cassd(det1, det2, Nint) !!! TEST Cl HARD !!!!!
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind) :: det1(Nint, 2), det2(Nint, 2)
integer :: degree, f, exc(0:2, 2, 2), h1, h2, p1, p2, s1, s2, t
double precision :: phase
is_generable_cassd = .false.
call get_excitation(det1, det2, exc, degree, phase, Nint)
if(degree == -1) return
if(degree == 0) then
is_generable_cassd = .true.
return
end if
call decode_exc(exc,degree,h1,p1,h2,p2,s1,s2)
if(degree == 1 .and. h1 <= 11) is_generable_cassd = .true.
if(degree == 2 .and. h1 <= 11 .and. h2 <= 11) is_generable_cassd = .true.
end function
logical function is_connected_to_by_mono(key,keys,Nint,Ndet) logical function is_connected_to_by_mono(key,keys,Nint,Ndet)
use bitmasks use bitmasks
implicit none implicit none

View File

@ -241,8 +241,8 @@ subroutine sort_dets_ab(key, idx, shortcut, N_key, Nint)
END_DOC END_DOC
integer, intent(in) :: Nint, N_key integer, intent(in) :: Nint, N_key
integer(bit_kind),intent(inout) :: key(Nint,2,N_key) integer(bit_kind),intent(inout) :: key(Nint,2,N_key)
integer,intent(out) :: idx(N_key) integer,intent(inout) :: idx(N_key)
integer,intent(out) :: shortcut(0:N_key+1) integer,intent(inout) :: shortcut(0:N_key+1)
integer(bit_kind) :: tmp(Nint, 2) integer(bit_kind) :: tmp(Nint, 2)
integer :: tmpidx,i,ni integer :: tmpidx,i,ni

View File

@ -664,3 +664,44 @@ subroutine save_wavefunction_specified(ndet,nstates,psidet,psicoef,ndetsave,inde
end end
logical function detEq(a,b,Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: a(Nint,2), b(Nint,2)
integer :: ni, i
detEq = .false.
do i=1,2
do ni=1,Nint
if(a(ni,i) /= b(ni,i)) return
end do
end do
detEq = .true.
end function
integer function detCmp(a,b,Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: a(Nint,2), b(Nint,2)
integer :: ni, i
detCmp = 0
do i=1,2
do ni=Nint,1,-1
if(a(ni,i) < b(ni,i)) then
detCmp = -1
return
else if(a(ni,i) > b(ni,i)) then
detCmp = 1
return
end if
end do
end do
end function

View File

@ -139,6 +139,72 @@ subroutine decode_exc(exc,degree,h1,p1,h2,p2,s1,s2)
end end
subroutine decode_exc_int2(exc,degree,h1,p1,h2,p2,s1,s2)
use bitmasks
implicit none
BEGIN_DOC
! Decodes the exc arrays returned by get_excitation.
! h1,h2 : Holes
! p1,p2 : Particles
! s1,s2 : Spins (1:alpha, 2:beta)
! degree : Degree of excitation
END_DOC
integer, intent(in) :: exc(0:2,2,2),degree
integer*2, intent(out) :: h1,h2,p1,p2,s1,s2
ASSERT (degree > 0)
ASSERT (degree < 3)
select case(degree)
case(2)
if (exc(0,1,1) == 2) then
h1 = exc(1,1,1)
h2 = exc(2,1,1)
p1 = exc(1,2,1)
p2 = exc(2,2,1)
s1 = 1
s2 = 1
else if (exc(0,1,2) == 2) then
h1 = exc(1,1,2)
h2 = exc(2,1,2)
p1 = exc(1,2,2)
p2 = exc(2,2,2)
s1 = 2
s2 = 2
else
h1 = exc(1,1,1)
h2 = exc(1,1,2)
p1 = exc(1,2,1)
p2 = exc(1,2,2)
s1 = 1
s2 = 2
endif
case(1)
if (exc(0,1,1) == 1) then
h1 = exc(1,1,1)
h2 = 0
p1 = exc(1,2,1)
p2 = 0
s1 = 1
s2 = 0
else
h1 = exc(1,1,2)
h2 = 0
p1 = exc(1,2,2)
p2 = 0
s1 = 2
s2 = 0
endif
case(0)
h1 = 0
p1 = 0
h2 = 0
p2 = 0
s1 = 0
s2 = 0
end select
end
subroutine get_double_excitation(det1,det2,exc,phase,Nint) subroutine get_double_excitation(det1,det2,exc,phase,Nint)
use bitmasks use bitmasks
implicit none implicit none
@ -915,7 +981,6 @@ subroutine create_minilist_find_previous(key_mask, fullList, miniList, N_fullLis
fullMatch = .false. fullMatch = .false.
N_miniList = 0 N_miniList = 0
N_subList = 0 N_subList = 0
l = popcnt(key_mask(1,1)) + popcnt(key_mask(1,2)) l = popcnt(key_mask(1,1)) + popcnt(key_mask(1,2))
do ni = 2,Nint do ni = 2,Nint
l = l + popcnt(key_mask(ni,1)) + popcnt(key_mask(ni,2)) l = l + popcnt(key_mask(ni,1)) + popcnt(key_mask(ni,2))
@ -948,8 +1013,13 @@ subroutine create_minilist_find_previous(key_mask, fullList, miniList, N_fullLis
miniList(ni,2,N_minilist) = fullList(ni,2,i) miniList(ni,2,N_minilist) = fullList(ni,2,i)
enddo enddo
else if(k == 0) then else if(k == 0) then
fullMatch = .true. N_minilist += 1
return do ni=1,Nint
miniList(ni,1,N_minilist) = fullList(ni,1,i)
miniList(ni,2,N_minilist) = fullList(ni,2,i)
enddo
! fullMatch = .true.
! return
end if end if
end do end do
end if end if
@ -1761,4 +1831,3 @@ subroutine apply_excitation(det, exc, res, ok, Nint)
ok = .true. ok = .true.
end subroutine end subroutine

View File

@ -10,7 +10,7 @@ integer*8 function spin_det_search_key(det,Nint)
use bitmasks use bitmasks
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Return an integer*8 corresponding to a determinant index for searching ! Return an integer(8) corresponding to a determinant index for searching
END_DOC END_DOC
integer, intent(in) :: Nint integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: det(Nint) integer(bit_kind), intent(in) :: det(Nint)
@ -64,9 +64,9 @@ BEGIN_TEMPLATE
integer :: i,j,k integer :: i,j,k
integer, allocatable :: iorder(:) integer, allocatable :: iorder(:)
integer*8, allocatable :: bit_tmp(:) integer(8), allocatable :: bit_tmp(:)
integer*8 :: last_key integer(8) :: last_key
integer*8, external :: spin_det_search_key integer(8), external :: spin_det_search_key
logical,allocatable :: duplicate(:) logical,allocatable :: duplicate(:)
allocate ( iorder(N_det), bit_tmp(N_det), duplicate(N_det) ) allocate ( iorder(N_det), bit_tmp(N_det), duplicate(N_det) )
@ -149,8 +149,8 @@ integer function get_index_in_psi_det_alpha_unique(key,Nint)
integer(bit_kind), intent(in) :: key(Nint) integer(bit_kind), intent(in) :: key(Nint)
integer :: i, ibegin, iend, istep, l integer :: i, ibegin, iend, istep, l
integer*8 :: det_ref, det_search integer(8) :: det_ref, det_search
integer*8, external :: spin_det_search_key integer(8), external :: spin_det_search_key
logical :: in_wavefunction logical :: in_wavefunction
in_wavefunction = .False. in_wavefunction = .False.
@ -231,8 +231,8 @@ integer function get_index_in_psi_det_beta_unique(key,Nint)
integer(bit_kind), intent(in) :: key(Nint) integer(bit_kind), intent(in) :: key(Nint)
integer :: i, ibegin, iend, istep, l integer :: i, ibegin, iend, istep, l
integer*8 :: det_ref, det_search integer(8) :: det_ref, det_search
integer*8, external :: spin_det_search_key integer(8), external :: spin_det_search_key
logical :: in_wavefunction logical :: in_wavefunction
in_wavefunction = .False. in_wavefunction = .False.
@ -305,10 +305,10 @@ end
subroutine write_spindeterminants subroutine write_spindeterminants
use bitmasks use bitmasks
implicit none implicit none
integer*8, allocatable :: tmpdet(:,:) integer(8), allocatable :: tmpdet(:,:)
integer :: N_int2 integer :: N_int2
integer :: i,j,k integer :: i,j,k
integer*8 :: det_8(100) integer(8) :: det_8(100)
integer(bit_kind) :: det_bk((100*8)/bit_kind) integer(bit_kind) :: det_bk((100*8)/bit_kind)
equivalence (det_8, det_bk) equivalence (det_8, det_bk)

View File

@ -148,10 +148,10 @@ subroutine ortho_lowdin(overlap,LDA,N,C,LDC,m)
integer, intent(in) :: LDA, ldc, n, m integer, intent(in) :: LDA, ldc, n, m
double precision, intent(in) :: overlap(lda,n) double precision, intent(in) :: overlap(lda,n)
double precision, intent(inout) :: C(ldc,n) double precision, intent(inout) :: C(ldc,n)
double precision :: U(ldc,n) double precision, allocatable :: U(:,:)
double precision :: Vt(lda,n) double precision, allocatable :: Vt(:,:)
double precision :: D(n) double precision, allocatable :: D(:)
double precision :: S_half(lda,n) double precision, allocatable :: S_half(:,:)
!DEC$ ATTRIBUTES ALIGN : 64 :: U, Vt, D !DEC$ ATTRIBUTES ALIGN : 64 :: U, Vt, D
integer :: info, i, j, k integer :: info, i, j, k
@ -159,6 +159,8 @@ subroutine ortho_lowdin(overlap,LDA,N,C,LDC,m)
return return
endif endif
allocate(U(ldc,n),Vt(lda,n),S_half(lda,n),D(n))
call svd(overlap,lda,U,ldc,D,Vt,lda,m,n) call svd(overlap,lda,U,ldc,D,Vt,lda,m,n)
!$OMP PARALLEL DEFAULT(NONE) & !$OMP PARALLEL DEFAULT(NONE) &
@ -203,6 +205,7 @@ subroutine ortho_lowdin(overlap,LDA,N,C,LDC,m)
call dgemm('N','N',m,n,n,1.d0,U,size(U,1),S_half,size(S_half,1),0.d0,C,size(C,1)) call dgemm('N','N',m,n,n,1.d0,U,size(U,1),S_half,size(S_half,1),0.d0,C,size(C,1))
deallocate(U,Vt,S_half,D)
end end