9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-23 20:13:42 +01:00
qp2/plugins/local/non_h_ints_mu/total_tc_int.irp.f

227 lines
8.5 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
double precision, allocatable :: b_mat(:,:,:,:), c_mat(:,:,:)
double precision, external :: get_ao_two_e_integral
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")
read(11) ao_two_e_tc_tot
close(11)
else
PROVIDE tc_integ_type
print*, ' approach for integrals: ', tc_integ_type
! ---
PROVIDE int2_grad1_u12_square_ao
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)
2023-03-04 02:19:15 +01:00
enddo
enddo
enddo
2024-01-15 12:02:38 +01:00
!$OMP END DO
!$OMP END PARALLEL
2023-05-07 12:44:59 +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_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)
2023-03-04 02:19:15 +01:00
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-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-01-15 12:02:38 +01:00
FREE int2_u2_env2
endif ! use_ipp
2023-04-26 08:52:06 +02:00
2024-01-15 12:02:38 +01:00
deallocate(c_mat)
! ---
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-01-15 12:05:26 +01:00
allocate(b_mat(n_points_final_grid,ao_num,ao_num,3))
2023-02-06 19:00:35 +01:00
2024-01-15 12:05:26 +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, aos_grad_in_r_array_transp_bis, b_mat, &
!$OMP ao_num, n_points_final_grid, final_weight_at_r_vector)
2024-01-15 12:02:38 +01:00
!$OMP DO SCHEDULE (static)
do i = 1, ao_num
do k = 1, ao_num
do ipoint = 1, n_points_final_grid
2023-02-06 19:00:35 +01:00
2024-01-15 12:05:26 +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)
2023-02-06 19:00:35 +01:00
2024-01-15 12:05:26 +01:00
b_mat(ipoint,k,i,1) = weight1 * (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))
b_mat(ipoint,k,i,2) = weight1 * (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))
b_mat(ipoint,k,i,3) = weight1 * (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-01-15 12:02:38 +01:00
enddo
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
2023-02-06 19:00:35 +01:00
2024-01-15 12:05:26 +01:00
do m = 1, 3
2024-01-17 11:10:28 +01:00
call dgemm( "N", "N", ao_num*ao_num, ao_num*ao_num, n_points_final_grid, -1.d0 &
2024-01-15 12:05:26 +01:00
, int2_grad1_u12_ao(1,1,1,m), ao_num*ao_num, b_mat(1,1,1,m), 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)
2024-01-15 12:05:26 +01:00
enddo
deallocate(b_mat)
2023-02-06 19:00:35 +01:00
2024-01-17 11:10:28 +01:00
FREE int2_grad1_u12_ao
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-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
PROVIDE ao_integrals_map
2024-01-15 12:05:26 +01:00
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(ao_num, ao_two_e_tc_tot, ao_integrals_map) &
2024-01-15 12:02:38 +01:00
!$OMP PRIVATE(i, j, k, l)
!$OMP DO
do j = 1, ao_num
do l = 1, ao_num
do i = 1, ao_num
do k = 1, ao_num
2024-01-15 12:05:26 +01:00
! < 1:i, 2:j | 1:k, 2:l >
ao_two_e_tc_tot(k,i,l,j) = ao_two_e_tc_tot(k,i,l,j) + get_ao_two_e_integral(i, j, k, l, ao_integrals_map)
2024-01-15 12:02:38 +01:00
enddo
2023-02-06 19:00:35 +01:00
enddo
enddo
enddo
2024-01-15 12:02:38 +01:00
!$OMP END DO
!$OMP END PARALLEL
2024-01-15 12:05:26 +01:00
if(tc_integ_type .eq. "numeric") 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-01-15 12:05:26 +01:00
write(11) ao_two_e_tc_tot
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
! ---