Skip to content

Commit

Permalink
Adding density matrix based conjugate-gradient linear response solver. (
Browse files Browse the repository at this point in the history
#1664)

* Adding densitry matrix based conjugate-gradient linear response solver.

 * Controlled by RESPONSE_SOLVER environment in Harris functional

 * Preconditioner (MULTI_LEVEL) for AO_ORTHO solver (cheaper CG solver without XC-kernel calculation)

Adding new Harris functional solvers:

 * Linear scaling purificatio methods (SIGN_MATRIX, TC2, TRS4)

 * OT Diagonalization (Intitial guess by Atomic block or ground-state density guess)

Stress tensor for Harris functional, response solver, and subsystem DFT (embedding and atomic potential).

* Updates requested by dev_zero

* Removed unused debug prints in AO response solver

* Removed passing iounit to subroutines
  • Loading branch information
fbelle committed Oct 5, 2021
1 parent 77c056f commit 62b873b
Show file tree
Hide file tree
Showing 44 changed files with 6,023 additions and 894 deletions.
26 changes: 20 additions & 6 deletions src/dm_ls_scf.F
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MODULE dm_ls_scf
matrix_qs_to_ls,&
rho_mixing_ls_init
USE dm_ls_scf_types, ONLY: ls_scf_env_type
USE ec_env_types, ONLY: energy_correction_type
USE input_constants, ONLY: ls_cluster_atomic,&
ls_scf_pexsi,&
ls_scf_sign,&
Expand Down Expand Up @@ -91,7 +92,7 @@ MODULE dm_ls_scf

CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dm_ls_scf'

PUBLIC :: ls_scf
PUBLIC :: calculate_w_matrix_ls, ls_scf, post_scf_sparsities

CONTAINS

Expand Down Expand Up @@ -459,6 +460,7 @@ SUBROUTINE ls_scf_main(qs_env, ls_scf_env)
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
TYPE(dbcsr_type), ALLOCATABLE, DIMENSION(:) :: matrix_ks_deviation, matrix_mixing_old
TYPE(energy_correction_type), POINTER :: ec_env
TYPE(qs_diis_buffer_type_sparse), POINTER :: diis_buffer
TYPE(transport_env_type), POINTER :: transport_env

Expand Down Expand Up @@ -530,6 +532,11 @@ SUBROUTINE ls_scf_main(qs_env, ls_scf_env)
ELSE
IF (should_stop .OR. iscf >= ls_scf_env%max_scf) THEN
IF (unit_nr > 0) WRITE (unit_nr, '(T2,A)') "SCF not converged! "
! Skip Harris functional calculation if ground-state is NOT converged
IF (qs_env%energy_correction) THEN
CALL get_qs_env(qs_env, ec_env=ec_env)
IF (ec_env%skip_ec) ec_env%do_skip = .TRUE.
END IF
EXIT
ENDIF
END IF
Expand Down Expand Up @@ -709,7 +716,14 @@ SUBROUTINE ls_scf_main(qs_env, ls_scf_env)
END IF
ELSE
! exit criterion on the energy only for the time being
IF (check_convergence .AND. ABS(energy_diff) < ls_scf_env%eps_scf*ls_scf_env%nelectron_total) EXIT
IF (check_convergence .AND. ABS(energy_diff) < ls_scf_env%eps_scf*ls_scf_env%nelectron_total) THEN
! Skip Harris functional calculation if ground-state is NOT converged
IF (qs_env%energy_correction) THEN
CALL get_qs_env(qs_env, ec_env=ec_env)
IF (ec_env%skip_ec) ec_env%do_skip = .FALSE.
END IF
EXIT
END IF
END IF

IF (ls_scf_env%ls_diis) THEN
Expand Down Expand Up @@ -801,7 +815,7 @@ SUBROUTINE ls_scf_post(qs_env, ls_scf_env)
IF (ls_scf_env%do_pexsi) THEN
CALL pexsi_to_qs(ls_scf_env, qs_env, matrix_w=ls_scf_env%pexsi%matrix_w)
ELSE
CALL calculate_w_matrix(matrix_w, ls_scf_env)
CALL calculate_w_matrix_ls(matrix_w, ls_scf_env)
ENDIF
ENDIF

Expand Down Expand Up @@ -1164,11 +1178,11 @@ END SUBROUTINE report_matrix_sparsity
!> 2010.11 created [Joost VandeVondele]
!> \author Joost VandeVondele
! **************************************************************************************************
SUBROUTINE calculate_w_matrix(matrix_w, ls_scf_env)
SUBROUTINE calculate_w_matrix_ls(matrix_w, ls_scf_env)
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_w
TYPE(ls_scf_env_type) :: ls_scf_env

CHARACTER(len=*), PARAMETER :: routineN = 'calculate_w_matrix'
CHARACTER(len=*), PARAMETER :: routineN = 'calculate_w_matrix_ls'

INTEGER :: handle, ispin
REAL(KIND=dp) :: scaling
Expand Down Expand Up @@ -1208,7 +1222,7 @@ SUBROUTINE calculate_w_matrix(matrix_w, ls_scf_env)

CALL timestop(handle)

END SUBROUTINE calculate_w_matrix
END SUBROUTINE calculate_w_matrix_ls

! **************************************************************************************************
!> \brief a place for quick experiments
Expand Down
2 changes: 1 addition & 1 deletion src/dm_ls_scf_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ MODULE dm_ls_scf_methods

PUBLIC :: ls_scf_init_matrix_S
PUBLIC :: density_matrix_sign, density_matrix_sign_fixed_mu
PUBLIC :: apply_matrix_preconditioner
PUBLIC :: apply_matrix_preconditioner, compute_matrix_preconditioner
PUBLIC :: density_matrix_trs4, density_matrix_tc2, compute_homo_lumo

CONTAINS
Expand Down
51 changes: 26 additions & 25 deletions src/ec_env_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
! **************************************************************************************************
MODULE ec_env_types
USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
USE cp_fm_types, ONLY: cp_fm_p_type,&
cp_fm_release
USE dbcsr_api, ONLY: dbcsr_p_type
USE dm_ls_scf_types, ONLY: ls_scf_env_type,&
ls_scf_release
USE input_section_types, ONLY: section_vals_type
USE kinds, ONLY: dp
USE pw_types, ONLY: pw_p_type,&
pw_release
USE qs_dispersion_types, ONLY: qs_dispersion_release,&
qs_dispersion_type
USE qs_force_types, ONLY: deallocate_qs_force,&
qs_force_type
USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
release_neighbor_list_sets
USE qs_p_env_types, ONLY: p_env_release,&
Expand Down Expand Up @@ -53,19 +51,21 @@ MODULE ec_env_types
INTEGER :: energy_functional
INTEGER :: ks_solver
INTEGER :: factorization
INTEGER :: ec_initial_guess
REAL(KIND=dp) :: eps_default
LOGICAL :: should_update
LOGICAL :: use_ls_solver
! basis set
CHARACTER(len=20) :: basis
LOGICAL :: mao
! Skip EC calculation if ground-state didnt converge
LOGICAL :: do_skip, skip_ec
INTEGER :: mao_max_iter
REAL(KIND=dp) :: mao_eps_grad
! energy components
REAL(KIND=dp) :: etotal
REAL(KIND=dp) :: eband, exc, ehartree, vhxc
REAL(KIND=dp) :: edispersion, efield_nuclear
! forces
TYPE(qs_force_type), DIMENSION(:), POINTER :: force => Null()
! full neighbor lists and corresponding task list
TYPE(neighbor_list_set_p_type), &
DIMENSION(:), POINTER :: sab_orb, sac_ppl, sap_ppnl
Expand All @@ -75,23 +75,24 @@ MODULE ec_env_types
TYPE(qs_dispersion_type), POINTER :: dispersion_env
! matrices in complete basis
! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_t
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_w
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, &
matrix_h, &
matrix_s, &
matrix_t, &
matrix_p, &
matrix_w
! reduce basis
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef
! CP equations
TYPE(qs_p_env_type), POINTER :: p_env
TYPE(cp_fm_p_type), DIMENSION(:), POINTER :: cpmos
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz, matrix_z, matrix_wz, z_admm
! potentials from input density
TYPE(pw_p_type), POINTER :: vh_rspace
TYPE(pw_p_type), DIMENSION(:), POINTER :: vxc_rspace, vtau_rspace, vadmm_rspace
! efield
TYPE(efield_berry_type), POINTER :: efield => NULL()
! LS matrices and types
TYPE(ls_scf_env_type), POINTER :: ls_env
END TYPE energy_correction_type

CONTAINS
Expand All @@ -114,8 +115,6 @@ SUBROUTINE ec_env_release(ec_env)
CALL release_neighbor_list_sets(ec_env%sab_orb)
CALL release_neighbor_list_sets(ec_env%sac_ppl)
CALL release_neighbor_list_sets(ec_env%sap_ppnl)
! forces
IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
! operator matrices
IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
Expand All @@ -132,17 +131,13 @@ SUBROUTINE ec_env_release(ec_env)
IF (ASSOCIATED(ec_env%dispersion_env)) THEN
CALL qs_dispersion_release(ec_env%dispersion_env)
END IF
! CP env
IF (ASSOCIATED(ec_env%cpmos)) THEN
DO iab = 1, SIZE(ec_env%cpmos)
CALL cp_fm_release(ec_env%cpmos(iab)%matrix)
END DO
DEALLOCATE (ec_env%cpmos)
NULLIFY (ec_env%cpmos)
END IF

IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
NULLIFY (ec_env%matrix_hz)
IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
NULLIFY (ec_env%matrix_z, ec_env%matrix_hz, ec_env%matrix_wz)
NULLIFY (ec_env%z_admm)

IF (ASSOCIATED(ec_env%p_env)) THEN
CALL p_env_release(ec_env%p_env)
Expand Down Expand Up @@ -172,10 +167,16 @@ SUBROUTINE ec_env_release(ec_env)
END IF
CALL efield_berry_release(ec_env%efield)

IF (ASSOCIATED(ec_env%ls_env)) THEN
CALL ls_scf_release(ec_env%ls_env)
ENDIF

DEALLOCATE (ec_env)

END IF

NULLIFY (ec_env)

CALL timestop(handle)

END SUBROUTINE ec_env_release
Expand Down

0 comments on commit 62b873b

Please sign in to comment.