10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-22 20:34:58 +01:00

FIXED BUG IN OPTIM J_BH

This commit is contained in:
Abdallah Ammar 2024-05-02 17:18:45 +02:00
parent 23acd603d0
commit bd8d45b99b
5 changed files with 117 additions and 133 deletions

View File

@ -336,9 +336,6 @@ BEGIN_PROVIDER [double precision, noL_0e]
double precision, allocatable :: tmp_M(:,:), tmp_S(:), tmp_O(:), tmp_J(:,:) double precision, allocatable :: tmp_M(:,:), tmp_S(:), tmp_O(:), tmp_J(:,:)
double precision, allocatable :: tmp_M_priv(:,:), tmp_S_priv(:), tmp_O_priv(:), tmp_J_priv(:,:) double precision, allocatable :: tmp_M_priv(:,:), tmp_S_priv(:), tmp_O_priv(:), tmp_J_priv(:,:)
call wall_time(t0)
print*, " Providing noL_0e ..."
if(elec_alpha_num .eq. elec_beta_num) then if(elec_alpha_num .eq. elec_beta_num) then
allocate(tmp(elec_beta_num)) allocate(tmp(elec_beta_num))
@ -713,11 +710,6 @@ BEGIN_PROVIDER [double precision, noL_0e]
endif endif
call wall_time(t1)
print*, " Wall time for noL_0e (min) = ", (t1 - t0)/60.d0
print*, " noL_0e = ", noL_0e
END_PROVIDER END_PROVIDER
! --- ! ---

View File

@ -167,7 +167,7 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
integer :: jpoint integer :: jpoint
integer :: i_nucl, p, mpA, npA, opA integer :: i_nucl, p, mpA, npA, opA
double precision :: r2(3) double precision :: r2(3)
double precision :: dx, dy, dz, r12, tmp, r12_inv double precision :: dx, dy, dz, r12, tmp
double precision :: mu_val, mu_tmp, mu_der(3) double precision :: mu_val, mu_tmp, mu_der(3)
double precision :: rn(3), f1A, grad1_f1A(3), f2A, grad2_f2A(3), g12, grad1_g12(3) double precision :: rn(3), f1A, grad1_f1A(3), f2A, grad2_f2A(3), g12, grad1_g12(3)
double precision :: tmp1, tmp2 double precision :: tmp1, tmp2
@ -191,19 +191,15 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
dy = r1(2) - r2(2) dy = r1(2) - r2(2)
dz = r1(3) - r2(3) dz = r1(3) - r2(3)
r12 = dx * dx + dy * dy + dz * dz r12 = dsqrt(dx * dx + dy * dy + dz * dz)
if(r12 .lt. 1d-10) then
if(r12 .lt. 1d-20) then
gradx(jpoint) = 0.d0 gradx(jpoint) = 0.d0
grady(jpoint) = 0.d0 grady(jpoint) = 0.d0
gradz(jpoint) = 0.d0 gradz(jpoint) = 0.d0
cycle cycle
endif endif
r12_inv = 1.d0/dsqrt(r12) tmp = 0.5d0 * (1.d0 - derf(mu_erf * r12)) / r12
r12 = r12*r12_inv
tmp = 0.5d0 * (1.d0 - derf(mu_erf * r12)) * r12_inv
gradx(jpoint) = tmp * dx gradx(jpoint) = tmp * dx
grady(jpoint) = tmp * dy grady(jpoint) = tmp * dy
@ -224,29 +220,23 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
dx = r1(1) - r2(1) dx = r1(1) - r2(1)
dy = r1(2) - r2(2) dy = r1(2) - r2(2)
dz = r1(3) - r2(3) dz = r1(3) - r2(3)
r12 = dsqrt(dx * dx + dy * dy + dz * dz)
r12 = dx * dx + dy * dy + dz * dz call mu_r_val_and_grad(r1, r2, mu_val, mu_der)
mu_tmp = mu_val * r12
tmp = inv_sq_pi_2 * dexp(-mu_tmp*mu_tmp) / (mu_val * mu_val)
gradx(jpoint) = tmp * mu_der(1)
grady(jpoint) = tmp * mu_der(2)
gradz(jpoint) = tmp * mu_der(3)
if(r12 .lt. 1d-20) then if(r12 .lt. 1d-10) then
gradx(jpoint) = 0.d0 gradx(jpoint) = 0.d0
grady(jpoint) = 0.d0 grady(jpoint) = 0.d0
gradz(jpoint) = 0.d0 gradz(jpoint) = 0.d0
cycle cycle
endif endif
r12_inv = 1.d0/dsqrt(r12) tmp = 0.5d0 * (1.d0 - derf(mu_tmp)) / r12
r12 = r12*r12_inv
call mu_r_val_and_grad(r1, r2, mu_val, mu_der)
mu_tmp = mu_val * r12
tmp = inv_sq_pi_2 * dexp(-mu_tmp*mu_tmp) / (mu_val * mu_val)
gradx(jpoint) = tmp * mu_der(1)
grady(jpoint) = tmp * mu_der(2)
gradz(jpoint) = tmp * mu_der(3)
tmp = 0.5d0 * (1.d0 - derf(mu_tmp)) * r12_inv
gradx(jpoint) = gradx(jpoint) + tmp * dx gradx(jpoint) = gradx(jpoint) + tmp * dx
grady(jpoint) = grady(jpoint) + tmp * dy grady(jpoint) = grady(jpoint) + tmp * dy
@ -273,8 +263,7 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
dx = r1(1) - r2(1) dx = r1(1) - r2(1)
dy = r1(2) - r2(2) dy = r1(2) - r2(2)
dz = r1(3) - r2(3) dz = r1(3) - r2(3)
r12 = dx * dx + dy * dy + dz * dz r12 = dsqrt(dx * dx + dy * dy + dz * dz)
if(r12 .lt. 1d-10) then if(r12 .lt. 1d-10) then
gradx(jpoint) = 0.d0 gradx(jpoint) = 0.d0
grady(jpoint) = 0.d0 grady(jpoint) = 0.d0
@ -282,8 +271,6 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
cycle cycle
endif endif
r12 = dsqrt(r12)
tmp = 1.d0 + a_boys * r12 tmp = 1.d0 + a_boys * r12
tmp = 0.5d0 / (r12 * tmp * tmp) tmp = 0.5d0 / (r12 * tmp * tmp)
@ -294,10 +281,13 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
elseif(j2e_type .eq. "Boys_Handy") then elseif(j2e_type .eq. "Boys_Handy") then
integer :: powmax integer :: powmax1, powmax, powmax2
powmax = max(maxval(jBH_m),maxval(jBH_n))
double precision, allocatable :: f1A_power(:), f2A_power(:), double_p(:), g12_power(:) double precision, allocatable :: f1A_power(:), f2A_power(:), double_p(:), g12_power(:)
powmax1 = max(maxval(jBH_m), maxval(jBH_n))
powmax2 = maxval(jBH_o)
powmax = max(powmax1, powmax2)
allocate(f1A_power(-1:powmax), f2A_power(-1:powmax), g12_power(-1:powmax), double_p(0:powmax)) allocate(f1A_power(-1:powmax), f2A_power(-1:powmax), g12_power(-1:powmax), double_p(0:powmax))
do p = 0, powmax do p = 0, powmax
@ -321,7 +311,6 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
gradx(jpoint) = 0.d0 gradx(jpoint) = 0.d0
grady(jpoint) = 0.d0 grady(jpoint) = 0.d0
gradz(jpoint) = 0.d0 gradz(jpoint) = 0.d0
do i_nucl = 1, nucl_num do i_nucl = 1, nucl_num
rn(1) = nucl_coord(i_nucl,1) rn(1) = nucl_coord(i_nucl,1)
@ -332,23 +321,15 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
call jBH_elem_fct_grad(jBH_en(i_nucl), r2, rn, f2A, grad2_f2A) call jBH_elem_fct_grad(jBH_en(i_nucl), r2, rn, f2A, grad2_f2A)
call jBH_elem_fct_grad(jBH_ee(i_nucl), r1, r2, g12, grad1_g12) call jBH_elem_fct_grad(jBH_ee(i_nucl), r1, r2, g12, grad1_g12)
! Compute powers of f1A and f2A ! Compute powers of f1A and f2A
do p = 1, powmax1
do p = 1, maxval(jBH_m(:,i_nucl))
f1A_power(p) = f1A_power(p-1) * f1A f1A_power(p) = f1A_power(p-1) * f1A
enddo
do p = 1, maxval(jBH_n(:,i_nucl))
f2A_power(p) = f2A_power(p-1) * f2A f2A_power(p) = f2A_power(p-1) * f2A
enddo enddo
do p = 1, powmax2
do p = 1, maxval(jBH_o(:,i_nucl))
g12_power(p) = g12_power(p-1) * g12 g12_power(p) = g12_power(p-1) * g12
enddo enddo
do p = 1, jBH_size do p = 1, jBH_size
mpA = jBH_m(p,i_nucl) mpA = jBH_m(p,i_nucl)
npA = jBH_n(p,i_nucl) npA = jBH_n(p,i_nucl)
@ -358,28 +339,23 @@ subroutine grad1_j12_r1_seq(r1, n_grid2, gradx, grady, gradz)
tmp = tmp * 0.5d0 tmp = tmp * 0.5d0
endif endif
!TODO : Powers to optimize here tmp1 = double_p(mpA) * f1A_power(mpA-1) * f2A_power(npA) + double_p(npA) * f1A_power(npA-1) * f2A_power(mpA)
tmp1 = tmp1 * g12_power(opA)
tmp2 = double_p(opA) * g12_power(opA-1) * (f1A_power(mpA) * f2A_power(npA) + f1A_power(npA) * f2A_power(mpA))
!tmp1 = 0.d0 !tmp1 = 0.d0
!if(mpA .gt. 0) then !if(mpA .gt. 0) then
! tmp1 = tmp1 + dble(mpA) * f1A**(mpA-1) * f2A**npA ! tmp1 = tmp1 + dble(mpA) * f1A**dble(mpA-1) * f2A**dble(npA)
!endif !endif
!if(npA .gt. 0) then !if(npA .gt. 0) then
! tmp1 = tmp1 + dble(npA) * f1A**(npA-1) * f2A**mpA ! tmp1 = tmp1 + dble(npA) * f1A**dble(npA-1) * f2A**dble(mpA)
!endif !endif
! tmp1 = tmp1 * g12**(opA) !tmp1 = tmp1 * g12**dble(opA)
!
!tmp2 = 0.d0 !tmp2 = 0.d0
!if(opA .gt. 0) then !if(opA .gt. 0) then
! tmp2 = tmp2 + dble(opA) * g12**(opA-1) * (f1A**(mpA) * f2A**(npA) + f1A**(npA) * f2A**(mpA)) ! tmp2 = tmp2 + dble(opA) * g12**dble(opA-1) * (f1A**dble(mpA) * f2A**dble(npA) + f1A**dble(npA) * f2A**dble(mpA))
!endif !endif
tmp1 = double_p(mpA) * f1A_power(mpA-1) * f2A_power(npA) + double_p(npA) * f1A_power(npA-1) * f2A_power(mpA)
tmp1 = tmp1 * g12_power(opA)
tmp2 = double_p(opA) * g12_power(opA-1) * (f1A_power(mpA) * f2A_power(npA) + f1A_power(npA) * f2A_power(mpA))
gradx(jpoint) = gradx(jpoint) + tmp * (tmp1 * grad1_f1A(1) + tmp2 * grad1_g12(1)) gradx(jpoint) = gradx(jpoint) + tmp * (tmp1 * grad1_f1A(1) + tmp2 * grad1_g12(1))
grady(jpoint) = grady(jpoint) + tmp * (tmp1 * grad1_f1A(2) + tmp2 * grad1_g12(2)) grady(jpoint) = grady(jpoint) + tmp * (tmp1 * grad1_f1A(2) + tmp2 * grad1_g12(2))
gradz(jpoint) = gradz(jpoint) + tmp * (tmp1 * grad1_f1A(3) + tmp2 * grad1_g12(3)) gradz(jpoint) = gradz(jpoint) + tmp * (tmp1 * grad1_f1A(3) + tmp2 * grad1_g12(3))
@ -418,7 +394,7 @@ subroutine grad1_jmu_r1_seq(mu, r1, n_grid2, gradx, grady, gradz)
integer :: jpoint integer :: jpoint
double precision :: r2(3) double precision :: r2(3)
double precision :: dx, dy, dz, r12, r12_inv, tmp double precision :: dx, dy, dz, r12, tmp
do jpoint = 1, n_points_extra_final_grid ! r2 do jpoint = 1, n_points_extra_final_grid ! r2
@ -431,19 +407,15 @@ subroutine grad1_jmu_r1_seq(mu, r1, n_grid2, gradx, grady, gradz)
dy = r1(2) - r2(2) dy = r1(2) - r2(2)
dz = r1(3) - r2(3) dz = r1(3) - r2(3)
r12 = dx * dx + dy * dy + dz * dz r12 = dsqrt(dx * dx + dy * dy + dz * dz)
if(r12 .lt. 1d-10) then
if(r12 .lt. 1d-20) then
gradx(jpoint) = 0.d0 gradx(jpoint) = 0.d0
grady(jpoint) = 0.d0 grady(jpoint) = 0.d0
gradz(jpoint) = 0.d0 gradz(jpoint) = 0.d0
cycle cycle
endif endif
r12_inv = 1.d0 / dsqrt(r12) tmp = 0.5d0 * (1.d0 - derf(mu * r12)) / r12
r12 = r12 * r12_inv
tmp = 0.5d0 * (1.d0 - derf(mu * r12)) * r12_inv
gradx(jpoint) = tmp * dx gradx(jpoint) = tmp * dx
grady(jpoint) = tmp * dy grady(jpoint) = tmp * dy
@ -467,7 +439,7 @@ subroutine j12_r1_seq(r1, n_grid2, res)
integer :: jpoint integer :: jpoint
double precision :: r2(3) double precision :: r2(3)
double precision :: dx, dy, dz double precision :: dx, dy, dz
double precision :: mu_tmp, r12, mu_erf_inv double precision :: mu_tmp, r12
PROVIDE final_grid_points_extra PROVIDE final_grid_points_extra
@ -475,7 +447,6 @@ subroutine j12_r1_seq(r1, n_grid2, res)
PROVIDE mu_erf PROVIDE mu_erf
mu_erf_inv = 1.d0 / mu_erf
do jpoint = 1, n_points_extra_final_grid ! r2 do jpoint = 1, n_points_extra_final_grid ! r2
r2(1) = final_grid_points_extra(1,jpoint) r2(1) = final_grid_points_extra(1,jpoint)
@ -489,7 +460,7 @@ subroutine j12_r1_seq(r1, n_grid2, res)
mu_tmp = mu_erf * r12 mu_tmp = mu_erf * r12
res(jpoint) = 0.5d0 * r12 * (1.d0 - derf(mu_tmp)) - inv_sq_pi_2 * dexp(-mu_tmp*mu_tmp) * mu_erf_inv res(jpoint) = 0.5d0 * r12 * (1.d0 - derf(mu_tmp)) - inv_sq_pi_2 * dexp(-mu_tmp*mu_tmp) / mu_erf
enddo enddo
elseif(j2e_type .eq. "Boys") then elseif(j2e_type .eq. "Boys") then

View File

@ -22,6 +22,7 @@ BEGIN_PROVIDER [double precision, htilde_matrix_elmt_bi_ortho, (N_det,N_det)]
if(noL_standard) then if(noL_standard) then
PROVIDE noL_0e PROVIDE noL_0e
print*, "noL_0e =", noL_0e
PROVIDE noL_1e PROVIDE noL_1e
PROVIDE noL_2e PROVIDE noL_2e
endif endif

View File

@ -9,15 +9,6 @@ program print_tc_energy
read_wf = .True. read_wf = .True.
touch read_wf touch read_wf
PROVIDE j2e_type
PROVIDE j1e_type
PROVIDE env_type
print *, ' j2e_type = ', j2e_type
print *, ' j1e_type = ', j1e_type
print *, ' env_type = ', env_type
my_grid_becke = .True. my_grid_becke = .True.
PROVIDE tc_grid1_a tc_grid1_r PROVIDE tc_grid1_a tc_grid1_r
my_n_pt_r_grid = tc_grid1_r my_n_pt_r_grid = tc_grid1_r
@ -38,6 +29,24 @@ program print_tc_energy
call write_int(6, my_n_pt_a_extra_grid, 'angular internal grid over') call write_int(6, my_n_pt_a_extra_grid, 'angular internal grid over')
endif endif
call main()
end
! ---
subroutine main()
implicit none
PROVIDE j2e_type
PROVIDE j1e_type
PROVIDE env_type
print *, ' j2e_type = ', j2e_type
print *, ' j1e_type = ', j1e_type
print *, ' env_type = ', env_type
call write_tc_energy() call write_tc_energy()
end end

View File

@ -7,15 +7,6 @@ program tc_scf
END_DOC END_DOC
implicit none implicit none
integer :: i
logical :: good_angles
print *, ' TC-SCF with:'
print *, ' j2e_type = ', j2e_type
print *, ' j1e_type = ', j1e_type
print *, ' env_type = ', env_type
write(json_unit,json_array_open_fmt) 'tc-scf'
my_grid_becke = .True. my_grid_becke = .True.
PROVIDE tc_grid1_a tc_grid1_r PROVIDE tc_grid1_a tc_grid1_r
@ -37,6 +28,26 @@ program tc_scf
call write_int(6, my_n_pt_a_extra_grid, 'angular internal grid over') call write_int(6, my_n_pt_a_extra_grid, 'angular internal grid over')
endif endif
call main()
end
! ---
subroutine main()
implicit none
integer :: i
logical :: good_angles
print *, ' TC-SCF with:'
print *, ' j2e_type = ', j2e_type
print *, ' j1e_type = ', j1e_type
print *, ' env_type = ', env_type
write(json_unit,json_array_open_fmt) 'tc-scf'
call rh_tcscf_diis() call rh_tcscf_diis()
PROVIDE Fock_matrix_tc_diag_mo_tot PROVIDE Fock_matrix_tc_diag_mo_tot
@ -84,7 +95,7 @@ subroutine create_guess()
SOFT_TOUCH mo_label SOFT_TOUCH mo_label
endif endif
end subroutine create_guess end
! --- ! ---