Skip to content

Commit

Permalink
PW: Bind functions to objects, remove reference counting from pw_pois…
Browse files Browse the repository at this point in the history
…son_type (#3106)
  • Loading branch information
fstein93 committed Nov 12, 2023
1 parent 1df1199 commit bfa4778
Show file tree
Hide file tree
Showing 127 changed files with 2,354 additions and 2,724 deletions.
14 changes: 6 additions & 8 deletions src/cp_ddapc.F
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ MODULE cp_ddapc
pw_scale,&
pw_transfer,&
pw_zero
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
REALDATA3D,&
REALSPACE,&
Expand Down Expand Up @@ -139,13 +137,13 @@ SUBROUTINE qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace,
dft_control%qs_control%ddapc_explicit_potential = explicit_potential
dft_control%qs_control%ddapc_restraint_is_spin = ddapc_restraint_is_spin
IF (explicit_potential) THEN
CALL pw_pool_create_pw(auxbas_pw_pool, v_spin_ddapc_rest_g, &
use_data=COMPLEXDATA1D, in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(v_spin_ddapc_rest_g, &
use_data=COMPLEXDATA1D, in_space=RECIPROCALSPACE)
CALL pw_zero(v_spin_ddapc_rest_g)
NULLIFY (v_spin_ddapc_rest_r)
ALLOCATE (v_spin_ddapc_rest_r)
CALL pw_pool_create_pw(auxbas_pw_pool, v_spin_ddapc_rest_r, &
use_data=REALDATA3D, in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(v_spin_ddapc_rest_r, &
use_data=REALDATA3D, in_space=REALSPACE)
END IF

IF (calculate_forces) CALL reset_ch_pulay(qs_env)
Expand Down Expand Up @@ -204,7 +202,7 @@ SUBROUTINE qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace,
END IF

IF (explicit_potential) THEN
CALL pw_pool_give_back_pw(auxbas_pw_pool, v_spin_ddapc_rest_g)
CALL auxbas_pw_pool%give_back_pw(v_spin_ddapc_rest_g)
END IF
CALL timestop(handle)

Expand Down
7 changes: 3 additions & 4 deletions src/cp_ddapc_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ MODULE cp_ddapc_types
USE pw_grid_types, ONLY: pw_grid_type
USE pw_grids, ONLY: pw_grid_release
USE pw_poisson_types, ONLY: pw_poisson_multipole
USE pw_pool_types, ONLY: pw_pool_give_back_pw,&
pw_pool_release,&
USE pw_pool_types, ONLY: pw_pool_release,&
pw_pool_type
USE pw_types, ONLY: pw_type
#include "./base/base_uses.f90"
Expand Down Expand Up @@ -407,11 +406,11 @@ SUBROUTINE cp_ddapc_ewald_release(cp_ddapc_ewald)

IF (ASSOCIATED(cp_ddapc_ewald)) THEN
IF (ASSOCIATED(cp_ddapc_ewald%coeff_qm)) THEN
CALL pw_pool_give_back_pw(cp_ddapc_ewald%pw_pool_qm, cp_ddapc_ewald%coeff_qm)
CALL cp_ddapc_ewald%pw_pool_qm%give_back_pw(cp_ddapc_ewald%coeff_qm)
DEALLOCATE (cp_ddapc_ewald%coeff_qm)
END IF
IF (ASSOCIATED(cp_ddapc_ewald%coeff_mm)) THEN
CALL pw_pool_give_back_pw(cp_ddapc_ewald%pw_pool_mm, cp_ddapc_ewald%coeff_mm)
CALL cp_ddapc_ewald%pw_pool_mm%give_back_pw(cp_ddapc_ewald%coeff_mm)
DEALLOCATE (cp_ddapc_ewald%coeff_mm)
END IF
IF (ASSOCIATED(cp_ddapc_ewald%pw_pool_qm)) THEN
Expand Down
16 changes: 7 additions & 9 deletions src/cp_ddapc_util.F
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ MODULE cp_ddapc_util
USE pw_methods, ONLY: pw_axpy,&
pw_copy,&
pw_transfer
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
RECIPROCALSPACE,&
pw_type
Expand Down Expand Up @@ -136,8 +134,8 @@ SUBROUTINE cp_ddapc_init(qs_env)
WRITE (iw, '(/,A)') " Initializing the DDAPC Environment"
END IF
CALL pw_env_get(pw_env=pw_env, auxbas_pw_pool=auxbas_pool)
CALL pw_pool_create_pw(auxbas_pool, rho_tot_g, in_space=RECIPROCALSPACE, &
use_data=COMPLEXDATA1D)
CALL auxbas_pool%create_pw(rho_tot_g, in_space=RECIPROCALSPACE, &
use_data=COMPLEXDATA1D)
Vol = rho_tot_g%pw_grid%vol
!
! Get Input Parameters
Expand Down Expand Up @@ -179,7 +177,7 @@ SUBROUTINE cp_ddapc_init(qs_env)
CALL cp_print_key_finished_output(iw2, logger, density_fit_section, &
"PROGRAM_RUN_INFO/CONDITION_NUMBER")
DEALLOCATE (radii)
CALL pw_pool_give_back_pw(auxbas_pool, rho_tot_g)
CALL auxbas_pool%give_back_pw(rho_tot_g)
END IF
CALL timestop(handle)
END SUBROUTINE cp_ddapc_init
Expand Down Expand Up @@ -277,8 +275,8 @@ RECURSIVE SUBROUTINE get_ddapc(qs_env, calc_force, density_fit_section, &
END IF
CALL pw_env_get(pw_env=pw_env, &
auxbas_pw_pool=auxbas_pool)
CALL pw_pool_create_pw(auxbas_pool, rho_tot_g, in_space=RECIPROCALSPACE, &
use_data=COMPLEXDATA1D)
CALL auxbas_pool%create_pw(rho_tot_g, in_space=RECIPROCALSPACE, &
use_data=COMPLEXDATA1D)
IF (PRESENT(ext_rho_tot_g)) THEN
! If provided use the input density in g-space
CALL pw_transfer(ext_rho_tot_g, rho_tot_g)
Expand Down Expand Up @@ -516,7 +514,7 @@ RECURSIVE SUBROUTINE get_ddapc(qs_env, calc_force, density_fit_section, &
CALL cp_print_key_finished_output(iw, logger, density_fit_section, &
"PROGRAM_RUN_INFO")
END IF
CALL pw_pool_give_back_pw(auxbas_pool, rho_tot_g)
CALL auxbas_pool%give_back_pw(rho_tot_g)
CALL timestop(handle)
END SUBROUTINE get_ddapc

Expand Down
22 changes: 9 additions & 13 deletions src/dm_ls_scf_qs.F
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ MODULE dm_ls_scf_qs
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_methods, ONLY: pw_zero
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_p_type,&
USE pw_pool_types, ONLY: pw_pool_p_type,&
pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
REALDATA3D,&
Expand Down Expand Up @@ -668,15 +666,13 @@ SUBROUTINE write_matrix_to_cube(qs_env, ls_scf_env, matrix_p_ls, unit_nr, title,
CALL pw_env_get(pw_env=pw_env, &
auxbas_pw_pool=auxbas_pw_pool, &
pw_pools=pw_pools)
CALL pw_pool_create_pw(pool=auxbas_pw_pool, &
pw=wf_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(pw=wf_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL pw_zero(wf_r)
CALL pw_pool_create_pw(pool=auxbas_pw_pool, &
pw=wf_g, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(pw=wf_g, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL pw_zero(wf_g)
CALL calculate_rho_elec(matrix_p=matrix_p_qs, &
rho=wf_r, &
Expand All @@ -688,8 +684,8 @@ SUBROUTINE write_matrix_to_cube(qs_env, ls_scf_env, matrix_p_ls, unit_nr, title,
particles=particles, stride=stride)

!free memory
CALL pw_pool_give_back_pw(auxbas_pw_pool, wf_r)
CALL pw_pool_give_back_pw(auxbas_pw_pool, wf_g)
CALL auxbas_pw_pool%give_back_pw(wf_r)
CALL auxbas_pw_pool%give_back_pw(wf_g)
CALL dbcsr_release(matrix_p_qs)

CALL timestop(handle)
Expand Down
11 changes: 5 additions & 6 deletions src/ec_env_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ MODULE ec_env_types
USE input_section_types, ONLY: section_vals_release,&
section_vals_type
USE kinds, ONLY: dp
USE pw_types, ONLY: pw_release,&
pw_type
USE pw_types, ONLY: pw_type
USE qs_dispersion_types, ONLY: qs_dispersion_release,&
qs_dispersion_type
USE qs_force_types, ONLY: deallocate_qs_force,&
Expand Down Expand Up @@ -174,23 +173,23 @@ SUBROUTINE ec_env_release(ec_env)
END IF
! potential
IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
CALL pw_release(ec_env%vh_rspace)
CALL ec_env%vh_rspace%release()
END IF
IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
DO iab = 1, SIZE(ec_env%vxc_rspace)
CALL pw_release(ec_env%vxc_rspace(iab))
CALL ec_env%vxc_rspace(iab)%release()
END DO
DEALLOCATE (ec_env%vxc_rspace)
END IF
IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
DO iab = 1, SIZE(ec_env%vtau_rspace)
CALL pw_release(ec_env%vtau_rspace(iab))
CALL ec_env%vtau_rspace(iab)%release()
END DO
DEALLOCATE (ec_env%vtau_rspace)
END IF
IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
DO iab = 1, SIZE(ec_env%vadmm_rspace)
CALL pw_release(ec_env%vadmm_rspace(iab))
CALL ec_env%vadmm_rspace(iab)%release()
END DO
DEALLOCATE (ec_env%vadmm_rspace)
END IF
Expand Down
35 changes: 15 additions & 20 deletions src/ec_orth_solver.F
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ MODULE ec_orth_solver
pw_zero
USE pw_poisson_methods, ONLY: pw_poisson_solve
USE pw_poisson_types, ONLY: pw_poisson_type
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_p_type,&
USE pw_pool_types, ONLY: pw_pool_p_type,&
pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
REALDATA3D,&
Expand Down Expand Up @@ -1182,18 +1180,15 @@ SUBROUTINE hessian_op2(qs_env, p_env, matrix_Ax, matrix_p, matrix_s_sqrt_inv, ep
poisson_env=poisson_env)

! Calculate the NSC Hartree potential
CALL pw_pool_create_pw(pool=auxbas_pw_pool, &
pw=v_hartree_gspace, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL pw_pool_create_pw(pool=auxbas_pw_pool, &
pw=rho_tot_gspace, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL pw_pool_create_pw(pool=auxbas_pw_pool, &
pw=v_hartree_rspace, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(pw=v_hartree_gspace, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(pw=rho_tot_gspace, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(pw=v_hartree_rspace, &
use_data=REALDATA3D, &
in_space=REALSPACE)

! XC-Kernel
NULLIFY (v_xc, v_xc_tau, xc_section)
Expand Down Expand Up @@ -1322,16 +1317,16 @@ SUBROUTINE hessian_op2(qs_env, p_env, matrix_Ax, matrix_p, matrix_s_sqrt_inv, ep
CALL commutator(matrix_G, matrix_p, matrix_Ax, eps_filter, .FALSE., 1.0_dp, 1.0_dp)

! release pw grids
CALL pw_pool_give_back_pw(auxbas_pw_pool, v_hartree_gspace)
CALL pw_pool_give_back_pw(auxbas_pw_pool, v_hartree_rspace)
CALL pw_pool_give_back_pw(auxbas_pw_pool, rho_tot_gspace)
CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
DO ispin = 1, nspins
CALL pw_pool_give_back_pw(auxbas_pw_pool, v_xc(ispin))
CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
END DO
DEALLOCATE (v_xc)
IF (ASSOCIATED(v_xc_tau)) THEN
DO ispin = 1, nspins
CALL pw_pool_give_back_pw(auxbas_pw_pool, v_xc_tau(ispin))
CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
END DO
DEALLOCATE (v_xc_tau)
END IF
Expand Down
22 changes: 10 additions & 12 deletions src/ed_analysis.F
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ MODULE ed_analysis
pw_env_type
USE pw_methods, ONLY: pw_axpy,&
pw_scale
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: REALDATA3D,&
REALSPACE,&
pw_type
Expand Down Expand Up @@ -693,18 +691,18 @@ SUBROUTINE vhxc_correction(qs_env, vhxc_mat, exc_mat, atecc, ate1xc, ate1h)
needs = xc_functionals_get_needs(xc_fun_section, (nspins == 2), .TRUE.)

CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
CALL pw_pool_create_pw(auxbas_pw_pool, xc_den, &
use_data=REALDATA3D, in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(xc_den, &
use_data=REALDATA3D, in_space=REALSPACE)
ALLOCATE (vxc(nspins))
DO ispin = 1, nspins
CALL pw_pool_create_pw(auxbas_pw_pool, vxc(ispin), &
use_data=REALDATA3D, in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(vxc(ispin), &
use_data=REALDATA3D, in_space=REALSPACE)
END DO
IF (needs%tau .OR. needs%tau_spin) THEN
ALLOCATE (vtau(nspins))
DO ispin = 1, nspins
CALL pw_pool_create_pw(auxbas_pw_pool, vtau(ispin), &
use_data=REALDATA3D, in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(vtau(ispin), &
use_data=REALDATA3D, in_space=REALSPACE)
END DO
END IF

Expand Down Expand Up @@ -777,13 +775,13 @@ SUBROUTINE vhxc_correction(qs_env, vhxc_mat, exc_mat, atecc, ate1xc, ate1h)
END IF
END IF

CALL pw_pool_give_back_pw(auxbas_pw_pool, xc_den)
CALL auxbas_pw_pool%give_back_pw(xc_den)
DO ispin = 1, nspins
CALL pw_pool_give_back_pw(auxbas_pw_pool, vxc(ispin))
CALL auxbas_pw_pool%give_back_pw(vxc(ispin))
END DO
IF (needs%tau .OR. needs%tau_spin) THEN
DO ispin = 1, nspins
CALL pw_pool_give_back_pw(auxbas_pw_pool, vtau(ispin))
CALL auxbas_pw_pool%give_back_pw(vtau(ispin))
END DO
END IF

Expand Down
12 changes: 5 additions & 7 deletions src/emd/rt_propagation_output.F
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ MODULE rt_propagation_output
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_methods, ONLY: pw_zero
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
REALDATA3D,&
REALSPACE,&
Expand Down Expand Up @@ -724,8 +722,8 @@ SUBROUTINE rt_current(qs_env, P_im, dft_section, spin, nspin)
END IF
current_env%gauge = -1
current_env%gauge_init = .FALSE.
CALL pw_pool_create_pw(auxbas_pw_pool, rs, use_data=REALDATA3D, in_space=REALSPACE)
CALL pw_pool_create_pw(auxbas_pw_pool, gs, use_data=COMPLEXDATA1D, in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(rs, use_data=REALDATA3D, in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(gs, use_data=COMPLEXDATA1D, in_space=RECIPROCALSPACE)

NULLIFY (stride)
ALLOCATE (stride(3))
Expand Down Expand Up @@ -762,8 +760,8 @@ SUBROUTINE rt_current(qs_env, P_im, dft_section, spin, nspin)

END DO

CALL pw_pool_give_back_pw(auxbas_pw_pool, rs)
CALL pw_pool_give_back_pw(auxbas_pw_pool, gs)
CALL auxbas_pw_pool%give_back_pw(rs)
CALL auxbas_pw_pool%give_back_pw(gs)

CALL dbcsr_deallocate_matrix(zero)
CALL dbcsr_deallocate_matrix(tmp)
Expand Down
28 changes: 13 additions & 15 deletions src/emd/rt_propagation_utils.F
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ MODULE rt_propagation_utils
pw_env_type
USE pw_methods, ONLY: pw_multiply,&
pw_zero
USE pw_pool_types, ONLY: pw_pool_create_pw,&
pw_pool_give_back_pw,&
pw_pool_p_type,&
USE pw_pool_types, ONLY: pw_pool_p_type,&
pw_pool_type
USE pw_types, ONLY: COMPLEXDATA1D,&
REALDATA3D,&
Expand Down Expand Up @@ -793,15 +791,15 @@ SUBROUTINE write_rtp_mo_cubes(qs_env, rtp)
! Setup the grids needed to compute a wavefunction given a vector
CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
pw_pools=pw_pools)
CALL pw_pool_create_pw(auxbas_pw_pool, wf_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL pw_pool_create_pw(auxbas_pw_pool, wf_g, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL pw_pool_create_pw(auxbas_pw_pool, density_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(wf_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL auxbas_pw_pool%create_pw(wf_g, &
use_data=COMPLEXDATA1D, &
in_space=RECIPROCALSPACE)
CALL auxbas_pw_pool%create_pw(density_r, &
use_data=REALDATA3D, &
in_space=REALSPACE)
CALL get_rtp(rtp=rtp, mos_new=mos_new)

DO ispin = 1, nspins
Expand Down Expand Up @@ -874,9 +872,9 @@ SUBROUTINE write_rtp_mo_cubes(qs_env, rtp)
END DO

! Deallocate grids needed to compute wavefunctions
CALL pw_pool_give_back_pw(auxbas_pw_pool, wf_r)
CALL pw_pool_give_back_pw(auxbas_pw_pool, wf_g)
CALL pw_pool_give_back_pw(auxbas_pw_pool, density_r)
CALL auxbas_pw_pool%give_back_pw(wf_r)
CALL auxbas_pw_pool%give_back_pw(wf_g)
CALL auxbas_pw_pool%give_back_pw(density_r)

CALL timestop(handle)

Expand Down

0 comments on commit bfa4778

Please sign in to comment.