10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-19 12:32:30 +01:00
QuantumPackage/plugins/local/tc_int/compute_tc_int.irp.f

302 lines
9.9 KiB
Fortran
Raw Normal View History

2024-06-26 15:31:44 +02:00
! ---
subroutine provide_int2_grad1_u12_ao()
2024-08-01 10:05:47 +02:00
2024-06-26 15:31:44 +02:00
BEGIN_DOC
!
2024-07-12 17:32:41 +02:00
! int2_grad1_u12_ao(i,j,ipoint,1) = \int dr2 [\grad1 u(r1,r2)]_x1 \chi_i(r2) \chi_j(r2)
! int2_grad1_u12_ao(i,j,ipoint,2) = \int dr2 [\grad1 u(r1,r2)]_y1 \chi_i(r2) \chi_j(r2)
! int2_grad1_u12_ao(i,j,ipoint,3) = \int dr2 [\grad1 u(r1,r2)]_z1 \chi_i(r2) \chi_j(r2)
! int2_grad1_u12_ao(i,j,ipoint,4) = \int dr2 [-(1/2) [\grad1 u(r1,r2)]^2] \chi_i(r2) \chi_j(r2)
2024-06-26 15:31:44 +02:00
!
!
2024-07-12 17:32:41 +02:00
! tc_int_2e_ao(k,i,l,j) = (ki|V^TC(r_12)|lj)
! = <lk| V^TC(r_12) |ji> where V^TC(r_12) is the total TC operator
2024-06-26 15:31:44 +02:00
! = tc_grad_and_lapl_ao(k,i,l,j) + tc_grad_square_ao(k,i,l,j) + ao_two_e_coul(k,i,l,j)
! where:
!
! tc_grad_and_lapl_ao(k,i,l,j) = < k l | -1/2 \Delta_1 u(r1,r2) - \grad_1 u(r1,r2) . \grad_1 | ij >
2024-07-12 17:32:41 +02:00
! = -1/2 \int dr1 (phi_k(r1) \grad_r1 phi_i(r1) - phi_i(r1) \grad_r1 phi_k(r1)) . \int dr2 \grad_r1 u(r1,r2) \phi_l(r2) \phi_j(r2)
! = 1/2 \int dr1 (phi_k(r1) \grad_r1 phi_i(r1) - phi_i(r1) \grad_r1 phi_k(r1)) . \int dr2 (-1) \grad_r1 u(r1,r2) \phi_l(r2) \phi_j(r2)
2024-06-26 15:31:44 +02:00
!
! tc_grad_square_ao(k,i,l,j) = -1/2 <kl | |\grad_1 u(r1,r2)|^2 + |\grad_2 u(r1,r2)|^2 | ij>
!
! ao_two_e_coul(k,i,l,j) = < l k | 1/r12 | j i > = ( k i | 1/r12 | l j )
!
END_DOC
implicit none
integer :: i, j, k, l, m, ipoint, jpoint
integer :: n_blocks, n_rest, n_pass
integer :: i_blocks, i_rest, i_pass, ii
double precision :: mem, n_double
double precision :: weight1, ao_k_r, ao_i_r
double precision :: der_envsq_x, der_envsq_y, der_envsq_z, lap_envsq
double precision :: time0, time1, time2, tc1, tc2, tc
2024-08-01 10:05:47 +02:00
double precision, allocatable :: int2_grad1_u12_ao(:,:,:,:)
double precision, allocatable :: tmp_grad1_u12(:,:,:), tmp(:,:,:)
2024-07-12 17:32:41 +02:00
double precision, allocatable :: c_mat(:,:,:), tc_int_2e_ao(:,:,:,:)
2024-06-26 15:31:44 +02:00
double precision, external :: get_ao_two_e_integral
PROVIDE final_weight_at_r_vector_extra aos_in_r_array_extra
PROVIDE final_weight_at_r_vector aos_grad_in_r_array_transp_bis final_weight_at_r_vector aos_in_r_array_transp
print*, ' start provide_int2_grad1_u12_ao ...'
call wall_time(time0)
call total_memory(mem)
mem = max(1.d0, qp_max_mem - mem)
n_double = mem * 1.d8
n_blocks = int(min(n_double / (n_points_extra_final_grid * 4.d0), 1.d0*n_points_final_grid))
n_rest = int(mod(n_points_final_grid, n_blocks))
n_pass = int((n_points_final_grid - n_rest) / n_blocks)
call write_int(6, n_pass, 'Number of passes')
call write_int(6, n_blocks, 'Size of the blocks')
call write_int(6, n_rest, 'Size of the last block')
! ---
! ---
! ---
2024-08-01 10:05:47 +02:00
allocate(int2_grad1_u12_ao(ao_num,ao_num,n_points_final_grid,4))
2024-06-26 15:31:44 +02:00
2024-08-01 10:05:47 +02:00
allocate(tmp(n_points_extra_final_grid,ao_num,ao_num))
2024-06-26 15:31:44 +02:00
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (j, i, jpoint) &
!$OMP SHARED (tmp, ao_num, n_points_extra_final_grid, final_weight_at_r_vector_extra, aos_in_r_array_extra_transp)
!$OMP DO SCHEDULE (static)
do j = 1, ao_num
do i = 1, ao_num
do jpoint = 1, n_points_extra_final_grid
2024-08-01 10:05:47 +02:00
tmp(jpoint,i,j) = final_weight_at_r_vector_extra(jpoint) * aos_in_r_array_extra_transp(jpoint,i) * aos_in_r_array_extra_transp(jpoint,j)
2024-06-26 15:31:44 +02:00
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
2024-08-01 10:05:47 +02:00
allocate(tmp_grad1_u12(n_points_extra_final_grid,n_blocks,4))
2024-06-26 15:31:44 +02:00
tc = 0.d0
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
do i_pass = 1, n_pass
ii = (i_pass-1)*n_blocks + 1
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
call wall_time(tc1)
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i_blocks, ipoint) &
2024-08-01 10:05:47 +02:00
!$OMP SHARED (n_blocks, n_points_extra_final_grid, ii, tmp_grad1_u12)
2024-07-12 17:32:41 +02:00
!$OMP DO
2024-06-26 15:31:44 +02:00
do i_blocks = 1, n_blocks
ipoint = ii - 1 + i_blocks ! r1
2024-08-01 10:05:47 +02:00
call get_grad1_u12_for_tc(ipoint, n_points_extra_final_grid, tmp_grad1_u12(1,i_blocks,1), tmp_grad1_u12(1,i_blocks,2), &
tmp_grad1_u12(1,i_blocks,3), tmp_grad1_u12(1,i_blocks,4))
2024-06-26 15:31:44 +02:00
enddo
!$OMP END DO
!$OMP END PARALLEL
call wall_time(tc2)
2024-07-12 17:32:41 +02:00
tc = tc + tc2 - tc1
2024-06-26 15:31:44 +02:00
do m = 1, 4
2024-08-01 10:05:47 +02:00
call dgemm("T", "N", ao_num*ao_num, n_blocks, n_points_extra_final_grid, 1.d0 &
, tmp(1,1,1), n_points_extra_final_grid, tmp_grad1_u12(1,1,m), n_points_extra_final_grid &
, 0.d0, int2_grad1_u12_ao(1,1,ii,m), ao_num*ao_num)
2024-06-26 15:31:44 +02:00
enddo
enddo
if(n_rest .gt. 0) then
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
ii = n_pass*n_blocks + 1
call wall_time(tc1)
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i_rest, ipoint) &
2024-08-01 10:05:47 +02:00
!$OMP SHARED (n_rest, n_points_extra_final_grid, ii, tmp_grad1_u12)
2024-07-12 17:32:41 +02:00
!$OMP DO
2024-06-26 15:31:44 +02:00
do i_rest = 1, n_rest
ipoint = ii - 1 + i_rest ! r1
2024-08-01 10:05:47 +02:00
call get_grad1_u12_for_tc(ipoint, n_points_extra_final_grid, tmp_grad1_u12(1,i_rest,1), tmp_grad1_u12(1,i_rest,2), &
tmp_grad1_u12(1,i_rest,3), tmp_grad1_u12(1,i_rest,4))
2024-06-26 15:31:44 +02:00
enddo
!$OMP END DO
!$OMP END PARALLEL
call wall_time(tc2)
2024-07-12 17:32:41 +02:00
tc = tc + tc2 - tc1
2024-06-26 15:31:44 +02:00
do m = 1, 4
2024-08-01 10:05:47 +02:00
call dgemm("T", "N", ao_num*ao_num, n_rest, n_points_extra_final_grid, 1.d0 &
, tmp(1,1,1), n_points_extra_final_grid, tmp_grad1_u12(1,1,m), n_points_extra_final_grid &
, 0.d0, int2_grad1_u12_ao(1,1,ii,m), ao_num*ao_num)
2024-06-26 15:31:44 +02:00
enddo
endif
2024-08-01 10:05:47 +02:00
deallocate(tmp_grad1_u12)
2024-07-12 17:32:41 +02:00
2024-08-01 10:05:47 +02:00
deallocate(tmp)
2024-06-26 15:31:44 +02:00
call wall_time(time1)
print*, ' wall time for int2_grad1_u12_ao (min) = ', (time1-time0) / 60.d0
print*, ' wall time Jastrow derivatives (min) = ', tc / 60.d0
2024-08-02 21:16:27 +02:00
2024-06-26 15:31:44 +02:00
call print_memory_usage()
! ---
! ---
! ---
2024-08-02 21:16:27 +02:00
allocate(c_mat(n_points_final_grid,ao_num,ao_num))
2024-06-26 15:31:44 +02:00
allocate(tc_int_2e_ao(ao_num,ao_num,ao_num,ao_num))
call wall_time(time1)
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i, k, ipoint) &
!$OMP SHARED (aos_in_r_array_transp, c_mat, ao_num, n_points_final_grid, final_weight_at_r_vector)
!$OMP DO SCHEDULE (static)
do i = 1, ao_num
do k = 1, ao_num
do ipoint = 1, n_points_final_grid
c_mat(ipoint,k,i) = final_weight_at_r_vector(ipoint) * aos_in_r_array_transp(ipoint,i) * aos_in_r_array_transp(ipoint,k)
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
call dgemm( "N", "N", ao_num*ao_num, ao_num*ao_num, n_points_final_grid, 1.d0 &
2024-08-01 10:05:47 +02:00
, int2_grad1_u12_ao(1,1,1,4), ao_num*ao_num, c_mat(1,1,1), n_points_final_grid &
2024-06-26 15:31:44 +02:00
, 0.d0, tc_int_2e_ao(1,1,1,1), ao_num*ao_num)
call wall_time(time2)
print*, ' wall time of Hermitian part of tc_int_2e_ao (min) ', (time2 - time1) / 60.d0
2024-08-02 21:16:27 +02:00
2024-06-26 15:31:44 +02:00
call print_memory_usage()
! ---
call wall_time(time1)
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
do m = 1, 3
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
2024-07-12 17:32:41 +02:00
!$OMP PRIVATE (i, k, ipoint, weight1, ao_i_r, ao_k_r) &
!$OMP SHARED (aos_in_r_array_transp, aos_grad_in_r_array_transp_bis, c_mat, &
2024-06-26 15:31:44 +02:00
!$OMP ao_num, n_points_final_grid, final_weight_at_r_vector, m)
!$OMP DO SCHEDULE (static)
do i = 1, ao_num
do k = 1, ao_num
do ipoint = 1, n_points_final_grid
2024-07-12 17:32:41 +02:00
2024-08-04 11:58:19 +02:00
weight1 = final_weight_at_r_vector(ipoint)
2024-06-26 15:31:44 +02:00
ao_i_r = aos_in_r_array_transp(ipoint,i)
ao_k_r = aos_in_r_array_transp(ipoint,k)
2024-07-12 17:32:41 +02:00
2024-06-26 15:31:44 +02:00
c_mat(ipoint,k,i) = weight1 * (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,m) - ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,m))
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
2024-08-04 11:58:19 +02:00
call dgemm( "N", "N", ao_num*ao_num, ao_num*ao_num, n_points_final_grid, -0.5d0 &
2024-08-01 10:05:47 +02:00
, int2_grad1_u12_ao(1,1,1,m), ao_num*ao_num, c_mat(1,1,1), n_points_final_grid &
2024-06-26 15:31:44 +02:00
, 1.d0, tc_int_2e_ao(1,1,1,1), ao_num*ao_num)
enddo
call wall_time(time2)
print*, ' wall time of non-Hermitian part of tc_int_2e_ao (min) ', (time2 - time1) / 60.d0
2024-08-02 21:16:27 +02:00
deallocate(c_mat)
2024-06-26 15:31:44 +02:00
call print_memory_usage()
! ---
call wall_time(time1)
call sum_A_At(tc_int_2e_ao(1,1,1,1), ao_num*ao_num)
call wall_time(time2)
print*, ' lower- and upper-triangle of tc_int_2e_ao (min) ', (time2 - time1) / 60.d0
2024-08-02 21:16:27 +02:00
2024-06-26 15:31:44 +02:00
call print_memory_usage()
! ---
2024-08-05 14:49:35 +02:00
double precision :: tmp_omp
2024-07-12 17:32:41 +02:00
call wall_time(time1)
2024-06-26 15:31:44 +02:00
PROVIDE ao_integrals_map
2024-08-05 14:49:35 +02:00
tmp_omp = get_ao_two_e_integral(1, 1, 1, 1, ao_integrals_map)
2024-06-26 15:31:44 +02:00
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(ao_num, tc_int_2e_ao, ao_integrals_map) &
!$OMP PRIVATE(i, j, k, l)
!$OMP DO COLLAPSE(3)
do j = 1, ao_num
do l = 1, ao_num
do i = 1, ao_num
do k = 1, ao_num
2024-07-12 17:32:41 +02:00
! < 1:i, 2:j | 1:k, 2:l >
2024-06-26 15:31:44 +02:00
tc_int_2e_ao(k,i,l,j) = tc_int_2e_ao(k,i,l,j) + get_ao_two_e_integral(i, j, k, l, ao_integrals_map)
enddo
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
call wall_time(time2)
print*, ' wall time of Coulomb part of tc_int_2e_ao (min) ', (time2 - time1) / 60.d0
call print_memory_usage()
! ---
print*, ' Writing int2_grad1_u12_ao in ', trim(ezfio_filename) // '/work/int2_grad1_u12_ao'
open(unit=11, form="unformatted", file=trim(ezfio_filename)//'/work/int2_grad1_u12_ao', action="write")
2024-08-01 10:05:47 +02:00
call ezfio_set_work_empty(.False.)
write(11) int2_grad1_u12_ao(:,:,:,1:3)
2024-06-26 15:31:44 +02:00
close(11)
2024-08-01 10:05:47 +02:00
deallocate(int2_grad1_u12_ao)
2024-06-26 15:31:44 +02:00
print*, ' Saving tc_int_2e_ao in ', trim(ezfio_filename) // '/work/ao_two_e_tc_tot'
open(unit=11, form="unformatted", file=trim(ezfio_filename)//'/work/ao_two_e_tc_tot', action="write")
call ezfio_set_work_empty(.False.)
do i = 1, ao_num
write(11) tc_int_2e_ao(:,:,:,i)
enddo
close(11)
! ----
deallocate(tc_int_2e_ao)
call wall_time(time2)
print*, ' wall time for tc_int_2e_ao (min) = ', (time2-time1) / 60.d0
call print_memory_usage()
! ---
call wall_time(time1)
print*, ' wall time for TC-integrals (min) = ', (time1-time0) / 60.d0
return
end
! ---