10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-29 07:35:48 +01:00
QuantumPackage/plugins/local/non_h_ints_mu/total_tc_int.irp.f

343 lines
13 KiB
Fortran
Raw Normal View History

2023-02-06 19:00:35 +01:00
! ---
2024-01-15 12:02:38 +01:00
BEGIN_PROVIDER [double precision, ao_two_e_tc_tot, (ao_num, ao_num, ao_num, ao_num)]
BEGIN_DOC
!
! CHEMIST NOTATION IS USED
!
! ao_two_e_tc_tot(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
! = 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)
2024-01-15 12:05:26 +01:00
! AND IF(var_tc):
!
! ao_two_e_tot(k,i,l,j) = (ki|V^TC(r_12) + [(V^TC)(r_12)]^\dagger|lj) / 2.0
! = tc_grad_square_ao(k,i,l,j) + ao_two_e_coul(k,i,l,j)
!
2024-01-15 12:02:38 +01:00
!
! 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 >
! = -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)
!
! 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
2023-03-04 02:19:15 +01:00
implicit none
2024-01-15 12:02:38 +01:00
integer :: i, j, k, l, m, ipoint
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
2024-03-28 17:05:00 +01:00
double precision, allocatable :: c_mat(:,:,:)
logical, external :: ao_two_e_integral_zero
2024-01-15 12:02:38 +01:00
double precision, external :: get_ao_two_e_integral
2024-03-28 17:05:00 +01:00
double precision, external :: ao_two_e_integral
2024-01-15 12:02:38 +01:00
2024-01-15 19:02:05 +01:00
PROVIDe tc_integ_type
2024-01-15 12:02:38 +01:00
PROVIDE env_type
PROVIDE j2e_type
PROVIDE j1e_type
2023-03-04 02:19:15 +01:00
2024-01-15 12:05:26 +01:00
call wall_time(time0)
2023-05-07 12:44:59 +02:00
2024-01-15 12:02:38 +01:00
print *, ' providing ao_two_e_tc_tot ...'
print*, ' j2e_type: ', j2e_type
print*, ' j1e_type: ', j1e_type
print*, ' env_type: ', env_type
2023-05-07 12:44:59 +02:00
2024-01-15 12:02:38 +01:00
if(read_tc_integ) then
print*, ' Reading ao_two_e_tc_tot from ', 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="read")
2024-04-07 00:33:09 +02:00
do i = 1, ao_num
read(11) ao_two_e_tc_tot(:,:,:,i)
enddo
2024-01-15 12:02:38 +01:00
close(11)
else
PROVIDE tc_integ_type
print*, ' approach for integrals: ', tc_integ_type
! ---
PROVIDE int2_grad1_u12_square_ao
2024-04-07 00:33:09 +02:00
if(tc_save_mem_loops) then
2024-03-28 15:27:11 +01:00
print*, ' LOOPS are used to evaluate Hermitian part of ao_two_e_tc_tot ...'
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i, j, k, l, ipoint, ao_i_r, ao_k_r, weight1) &
!$OMP SHARED (ao_num, n_points_final_grid, ao_two_e_tc_tot, &
!$OMP aos_in_r_array_transp, final_weight_at_r_vector, int2_grad1_u12_square_ao)
2024-05-11 10:27:03 +02:00
!$OMP DO COLLAPSE(3)
2024-03-28 15:27:11 +01:00
do i = 1, ao_num
do k = 1, ao_num
do l = 1, ao_num
do j = 1, ao_num
ao_two_e_tc_tot(j,l,k,i) = 0.d0
do ipoint = 1, n_points_final_grid
weight1 = final_weight_at_r_vector(ipoint)
ao_i_r = aos_in_r_array_transp(ipoint,i)
ao_k_r = aos_in_r_array_transp(ipoint,k)
ao_two_e_tc_tot(j,l,k,i) = ao_two_e_tc_tot(j,l,k,i) + int2_grad1_u12_square_ao(j,l,ipoint) * weight1 * ao_i_r * ao_k_r
enddo
enddo
enddo
2023-03-04 02:19:15 +01:00
enddo
enddo
2024-03-28 15:27:11 +01:00
!$OMP END DO
!$OMP END PARALLEL
else
2023-05-07 12:44:59 +02:00
2024-03-28 15:27:11 +01:00
print*, ' DGEMM are used to evaluate Hermitian part of ao_two_e_tc_tot ...'
2023-03-04 02:19:15 +01:00
2024-03-28 15:27:11 +01:00
allocate(c_mat(n_points_final_grid,ao_num,ao_num))
!$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 &
, int2_grad1_u12_square_ao(1,1,1), ao_num*ao_num, c_mat(1,1,1), n_points_final_grid &
, 0.d0, ao_two_e_tc_tot, ao_num*ao_num)
deallocate(c_mat)
endif
2024-01-15 12:02:38 +01:00
FREE int2_grad1_u12_square_ao
2023-03-04 02:19:15 +01:00
2024-01-15 12:05:26 +01:00
if( (tc_integ_type .eq. "semi-analytic") .and. &
2024-01-16 19:07:20 +01:00
(j2e_type .eq. "Mu") .and. &
((env_type .eq. "Prod_Gauss") .or. (env_type .eq. "Sum_Gauss")) .and. &
2024-01-15 12:02:38 +01:00
use_ipp ) then
2023-03-04 02:19:15 +01:00
2024-01-15 12:02:38 +01:00
! an additional term is added here directly instead of
! being added in int2_grad1_u12_square_ao for performance
2023-02-06 19:00:35 +01:00
2024-03-28 15:27:11 +01:00
allocate(c_mat(n_points_final_grid,ao_num,ao_num))
2024-01-15 12:02:38 +01:00
PROVIDE int2_u2_env2
2023-02-06 19:00:35 +01:00
2024-01-15 12:02:38 +01:00
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i, k, ipoint, weight1, ao_i_r, ao_k_r) &
!$OMP SHARED (aos_in_r_array_transp, c_mat, ao_num, n_points_final_grid, final_weight_at_r_vector, &
!$OMP env_square_grad, env_square_lapl, aos_grad_in_r_array_transp_bis)
!$OMP DO SCHEDULE (static)
do i = 1, ao_num
do k = 1, ao_num
do ipoint = 1, n_points_final_grid
2023-09-06 19:21:14 +02:00
2024-01-15 12:02:38 +01:00
weight1 = 0.25d0 * final_weight_at_r_vector(ipoint)
2023-04-26 08:52:06 +02:00
2024-01-15 12:02:38 +01:00
ao_i_r = aos_in_r_array_transp(ipoint,i)
ao_k_r = aos_in_r_array_transp(ipoint,k)
2023-05-07 12:44:59 +02:00
2024-01-15 12:02:38 +01:00
c_mat(ipoint,k,i) = weight1 * ( ao_k_r * ao_i_r * env_square_lapl(ipoint) &
+ (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,1) + ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,1)) * env_square_grad(ipoint,1) &
+ (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,2) + ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,2)) * env_square_grad(ipoint,2) &
+ (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,3) + ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,3)) * env_square_grad(ipoint,3) )
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
2023-04-26 08:52:06 +02:00
2024-01-15 12:02:38 +01:00
call dgemm( "N", "N", ao_num*ao_num, ao_num*ao_num, n_points_final_grid, 1.d0 &
, int2_u2_env2(1,1,1), ao_num*ao_num, c_mat(1,1,1), n_points_final_grid &
2024-02-04 13:22:26 +01:00
, 1.d0, ao_two_e_tc_tot(1,1,1,1), ao_num*ao_num)
2023-04-26 08:52:06 +02:00
2024-03-28 15:27:11 +01:00
deallocate(c_mat)
2024-01-15 12:02:38 +01:00
FREE int2_u2_env2
endif ! use_ipp
2023-04-26 08:52:06 +02:00
2024-03-28 15:27:11 +01:00
call wall_time(time1)
print*, ' done with Hermitian part after (min) ', (time1 - time0) / 60.d0
call print_memory_usage()
2024-01-15 12:02:38 +01:00
! ---
2024-01-15 12:05:26 +01:00
if(.not. var_tc) then
2024-01-15 12:02:38 +01:00
2024-01-15 12:05:26 +01:00
PROVIDE int2_grad1_u12_ao
2024-01-15 12:02:38 +01:00
2024-04-07 00:33:09 +02:00
if(tc_save_mem_loops) then
2023-02-06 19:00:35 +01:00
2024-03-28 15:27:11 +01:00
print*, ' LOOPS are used to evaluate non-Hermitian part of ao_two_e_tc_tot ...'
2023-02-06 19:00:35 +01:00
2024-03-28 15:27:11 +01:00
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$OMP PRIVATE (i, j, k, l, ipoint, ao_i_r, ao_k_r, weight1) &
!$OMP SHARED (ao_num, n_points_final_grid, ao_two_e_tc_tot, &
!$OMP aos_in_r_array_transp, final_weight_at_r_vector, &
!$OMP int2_grad1_u12_ao, aos_grad_in_r_array_transp_bis)
2024-05-11 10:27:03 +02:00
!$OMP DO COLLAPSE(3)
2024-03-28 15:27:11 +01:00
do i = 1, ao_num
do k = 1, ao_num
do l = 1, ao_num
do j = 1, ao_num
do ipoint = 1, n_points_final_grid
weight1 = 0.5d0 * final_weight_at_r_vector(ipoint)
ao_i_r = aos_in_r_array_transp(ipoint,i)
ao_k_r = aos_in_r_array_transp(ipoint,k)
ao_two_e_tc_tot(j,l,k,i) = ao_two_e_tc_tot(j,l,k,i) &
2024-03-28 17:05:00 +01:00
- weight1 * int2_grad1_u12_ao(j,l,ipoint,1) * (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,1) - ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,1)) &
- weight1 * int2_grad1_u12_ao(j,l,ipoint,2) * (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,2) - ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,2)) &
- weight1 * int2_grad1_u12_ao(j,l,ipoint,3) * (ao_k_r * aos_grad_in_r_array_transp_bis(ipoint,i,3) - ao_i_r * aos_grad_in_r_array_transp_bis(ipoint,k,3))
2024-03-28 15:27:11 +01:00
enddo
enddo
enddo
2024-01-15 12:02:38 +01:00
enddo
enddo
2024-03-28 15:27:11 +01:00
!$OMP END DO
!$OMP END PARALLEL
2023-02-06 19:00:35 +01:00
2024-03-28 15:27:11 +01:00
else
print*, ' DGEMM are used to evaluate non-Hermitian part of ao_two_e_tc_tot ...'
2023-02-06 19:00:35 +01:00
2024-03-28 17:05:00 +01:00
allocate(c_mat(n_points_final_grid,ao_num,ao_num))
do m = 1, 3
!$OMP PARALLEL &
!$OMP DEFAULT (NONE) &
!$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, &
!$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-03-28 15:27:11 +01:00
2024-03-28 17:05:00 +01:00
weight1 = 0.5d0 * final_weight_at_r_vector(ipoint)
ao_i_r = aos_in_r_array_transp(ipoint,i)
ao_k_r = aos_in_r_array_transp(ipoint,k)
2024-03-28 15:27:11 +01:00
2024-03-28 17:05:00 +01: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
2024-03-28 15:27:11 +01:00
enddo
enddo
2024-03-28 17:05:00 +01:00
!$OMP END DO
!$OMP END PARALLEL
call dgemm( "N", "N", ao_num*ao_num, ao_num*ao_num, n_points_final_grid, -1.d0 &
, int2_grad1_u12_ao(1,1,1,m), ao_num*ao_num, c_mat(1,1,1), n_points_final_grid &
2024-03-28 15:27:11 +01:00
, 1.d0, ao_two_e_tc_tot(1,1,1,1), ao_num*ao_num)
enddo
2024-03-28 17:05:00 +01:00
deallocate(c_mat)
2024-03-28 15:27:11 +01:00
end if
2024-02-04 13:22:26 +01:00
if(tc_integ_type .eq. "semi-analytic") then
FREE int2_grad1_u2e_ao
endif
2024-01-17 11:10:28 +01:00
2024-01-15 12:05:26 +01:00
endif ! var_tc
2023-02-06 19:00:35 +01:00
2024-03-28 15:27:11 +01:00
call wall_time(time1)
print*, ' done with non-Hermitian part after (min) ', (time1 - time0) / 60.d0
call print_memory_usage()
2024-01-15 12:02:38 +01:00
! ---
2023-02-06 19:00:35 +01:00
2024-01-15 12:05:26 +01:00
call sum_A_At(ao_two_e_tc_tot(1,1,1,1), ao_num*ao_num)
2024-01-15 12:02:38 +01:00
2024-03-28 15:27:11 +01:00
! ---
2024-03-28 17:05:00 +01:00
logical :: integ_zero
double precision :: integ_val
2024-03-28 15:27:11 +01:00
2024-03-28 17:05:00 +01:00
print*, ' adding ERI to ao_two_e_tc_tot ...'
2024-01-15 12:02:38 +01:00
2024-04-07 00:33:09 +02:00
if(tc_save_mem) then
print*, ' ao_integrals_map will not be used'
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(i, j, k, l, integ_zero, integ_val) &
!$OMP SHARED(ao_num, ao_two_e_tc_tot)
2024-05-11 10:27:03 +02:00
!$OMP DO COLLAPSE(3)
2024-04-07 00:33:09 +02:00
do j = 1, ao_num
do l = 1, ao_num
do i = 1, ao_num
do k = 1, ao_num
integ_zero = ao_two_e_integral_zero(i,j,k,l)
if(.not. integ_zero) then
! i,k : r1 j,l : r2
integ_val = ao_two_e_integral(i,k,j,l)
ao_two_e_tc_tot(k,i,l,j) = ao_two_e_tc_tot(k,i,l,j) + integ_val
endif
enddo
2024-01-15 12:02:38 +01:00
enddo
2023-02-06 19:00:35 +01:00
enddo
enddo
2024-04-07 00:33:09 +02:00
!$OMP END DO
!$OMP END PARALLEL
else
! print*, ' ao_integrals_map will be used'
! PROVIDE ao_integrals_map
print*,'Cholesky vectors will be used '
double precision :: get_ao_integ_chol,eri
eri = get_ao_integ_chol(1,1,1,1) ! FOR OPENMP
2024-04-07 00:33:09 +02:00
!$OMP PARALLEL DEFAULT(NONE) &
!!! !$OMP SHARED(ao_num, ao_two_e_tc_tot, ao_integrals_map) &
!$OMP SHARED(ao_num, ao_two_e_tc_tot) &
!$OMP PRIVATE(i, j, k, l,eri)
2024-05-11 10:27:03 +02:00
!$OMP DO COLLAPSE(3)
2024-04-07 00:33:09 +02:00
do j = 1, ao_num
do l = 1, ao_num
do i = 1, ao_num
do k = 1, ao_num
! < 1:i, 2:j | 1:k, 2:l >
! eri = get_ao_two_e_integral(i, j, k, l, ao_integrals_map)
eri = get_ao_integ_chol(i,k,j,l)
ao_two_e_tc_tot(k,i,l,j) = ao_two_e_tc_tot(k,i,l,j) + eri
2024-04-07 00:33:09 +02:00
enddo
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
! FREE ao_integrals_map
2024-04-07 00:33:09 +02:00
endif
if((tc_integ_type .eq. "numeric") .and. (.not. tc_save_mem)) then
2024-01-15 12:02:38 +01:00
FREE int2_grad1_u12_ao_num int2_grad1_u12_square_ao_num
endif
endif ! read_tc_integ
if(write_tc_integ .and. mpi_master) then
2024-01-15 12:05:26 +01:00
print*, ' Saving ao_two_e_tc_tot 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")
2024-01-15 12:02:38 +01:00
call ezfio_set_work_empty(.False.)
2024-04-07 00:33:09 +02:00
do i = 1, ao_num
write(11) ao_two_e_tc_tot(:,:,:,i)
enddo
2024-01-15 12:02:38 +01:00
close(11)
call ezfio_set_tc_keywords_io_tc_integ('Read')
endif
call wall_time(time1)
2024-01-15 12:05:26 +01:00
print*, ' Wall time for ao_two_e_tc_tot (min) = ', (time1 - time0) / 60.d0
2024-01-15 12:02:38 +01:00
call print_memory_usage()
2023-09-02 18:11:05 +02:00
2023-02-06 19:00:35 +01:00
END_PROVIDER
! ---