Line data Source code
1 : !--------------------------------------------------------------------------------------------------! 2 : ! CP2K: A general program to perform molecular dynamics simulations ! 3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> ! 4 : ! ! 5 : ! SPDX-License-Identifier: GPL-2.0-or-later ! 6 : !--------------------------------------------------------------------------------------------------! 7 : 8 : ! ************************************************************************************************** 9 : !> \brief basis types for the calculation of the perturbation of density theory. 10 : !> \par History 11 : !> 4.2002 created [fawzi] 12 : !> \author Fawzi Mohamed 13 : ! ************************************************************************************************** 14 : MODULE qs_p_env_types 15 : USE cp_dbcsr_api, ONLY: dbcsr_p_type 16 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set 17 : USE cp_fm_types, ONLY: cp_fm_release,& 18 : cp_fm_type 19 : USE hartree_local_types, ONLY: hartree_local_release,& 20 : hartree_local_type 21 : USE preconditioner_types, ONLY: destroy_preconditioner,& 22 : preconditioner_type 23 : USE qs_kpp1_env_types, ONLY: kpp1_release,& 24 : qs_kpp1_env_type 25 : USE qs_local_rho_types, ONLY: local_rho_set_release,& 26 : local_rho_type 27 : USE qs_rho_types, ONLY: qs_rho_release,& 28 : qs_rho_type 29 : #include "./base/base_uses.f90" 30 : 31 : IMPLICIT NONE 32 : PRIVATE 33 : PUBLIC :: qs_p_env_type 34 : PUBLIC :: p_env_release 35 : 36 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE. 37 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_p_env_types' 38 : 39 : ! ************************************************************************************************** 40 : !> \brief Represent a qs system that is perturbed. 41 : !> Can calculate the linear operator and the rhs of the system 42 : !> of equations that needs to be solved for the perturbation. 43 : !> \param orthogonal_orbitals if the orbitals are orthogonal 44 : !> \param kpp 1: the kpp1 matrix (make it temporary?) 45 : !> \param kpp1_admm: collects the parts in auxiliary basis, they have to be added to kpp1 later 46 : !> \param m_epsilon minus epsilon: -<psi0d|H_rho|psi0d> 47 : !> \param psi 0d: the dual basis of psi0: psi0 (psi0^T S psi0)^-1 48 : !> \param S_psi 0: S times psi0, cached for performance reasons 49 : !> \param Smo_inv inverse of the mo overlap: (psi0^T S psi0)^-1 50 : !> \param rho 1: the density rho1 51 : !> \param rho 1: the soft density rho1 for gapw_xc 52 : !> \param rho 1_admm: density rho1 in auxiliary basis (for ADMM) 53 : !> \param n_mo cached number of mo: n_mo(i)=qs_env%c(i)%nmo 54 : !> \param n_ao cached number of ao: n_ao(i)=qs_env%c(i)%nao 55 : !> \note 56 : !> for the moment no smearing of the orbitals. 57 : ! ************************************************************************************************** 58 : TYPE qs_p_env_type 59 : LOGICAL :: orthogonal_orbitals = .FALSE. 60 : TYPE(qs_kpp1_env_type), POINTER :: kpp1_env => NULL() 61 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: kpp1 => NULL() 62 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: kpp1_admm => NULL() 63 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: p1 => NULL() 64 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: p1_admm => NULL() 65 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: w1 => NULL() 66 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: m_epsilon => NULL() 67 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: psi0d => NULL() 68 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: S_psi0 => NULL() 69 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: Smo_inv => NULL() 70 : TYPE(qs_rho_type), POINTER :: rho1 => NULL() 71 : TYPE(qs_rho_type), POINTER :: rho1_xc => NULL() 72 : TYPE(qs_rho_type), POINTER :: rho1_admm => NULL() 73 : INTEGER, DIMENSION(2) :: n_mo = -1, & ! no of molecular orbitals 74 : n_ao = -1 ! no of basis functions 75 : ! GAPW stuff 76 : TYPE(hartree_local_type), POINTER :: hartree_local => NULL() 77 : TYPE(local_rho_type), POINTER :: local_rho_set => NULL() 78 : TYPE(local_rho_type), POINTER :: local_rho_set_admm => NULL() 79 : 80 : ! Linear Response Modules 81 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: PS_psi0 => NULL() 82 : 83 : ! preconditioner matrix should be symmetric and positive definite 84 : LOGICAL :: new_preconditioner = .FALSE. 85 : TYPE(preconditioner_type), DIMENSION(:), POINTER :: preconditioner => NULL() 86 : 87 : END TYPE qs_p_env_type 88 : 89 : CONTAINS 90 : 91 : ! ************************************************************************************************** 92 : !> \brief relases the given p_env (see doc/ReferenceCounting.html) 93 : !> \param p_env the environment to release 94 : !> \par History 95 : !> 07.2002 created [fawzi] 96 : !> \author Fawzi Mohamed 97 : ! ************************************************************************************************** 98 1646 : SUBROUTINE p_env_release(p_env) 99 : 100 : TYPE(qs_p_env_type) :: p_env 101 : 102 : INTEGER :: ip 103 : 104 1646 : IF (ASSOCIATED(p_env%kpp1_env)) THEN 105 1646 : CALL kpp1_release(p_env%kpp1_env) 106 1646 : DEALLOCATE (p_env%kpp1_env) 107 : NULLIFY (p_env%kpp1_env) 108 : END IF 109 1646 : CALL cp_fm_release(p_env%S_psi0) 110 1646 : CALL cp_fm_release(p_env%m_epsilon) 111 1646 : CALL cp_fm_release(p_env%psi0d) 112 1646 : CALL cp_fm_release(p_env%Smo_inv) 113 1646 : IF (ASSOCIATED(p_env%rho1_xc)) THEN 114 1646 : CALL qs_rho_release(p_env%rho1_xc) 115 1646 : DEALLOCATE (p_env%rho1_xc) 116 : END IF 117 1646 : IF (ASSOCIATED(p_env%rho1)) THEN 118 1646 : CALL qs_rho_release(p_env%rho1) 119 1646 : DEALLOCATE (p_env%rho1) 120 : END IF 121 1646 : IF (ASSOCIATED(p_env%rho1_admm)) THEN 122 194 : CALL qs_rho_release(p_env%rho1_admm) 123 194 : DEALLOCATE (p_env%rho1_admm) 124 : END IF 125 1646 : IF (ASSOCIATED(p_env%kpp1)) CALL dbcsr_deallocate_matrix_set(p_env%kpp1) 126 1646 : IF (ASSOCIATED(p_env%kpp1_admm)) CALL dbcsr_deallocate_matrix_set(p_env%kpp1_admm) 127 1646 : IF (ASSOCIATED(p_env%p1)) CALL dbcsr_deallocate_matrix_set(p_env%p1) 128 1646 : IF (ASSOCIATED(p_env%w1)) CALL dbcsr_deallocate_matrix_set(p_env%w1) 129 1646 : IF (ASSOCIATED(p_env%p1_admm)) CALL dbcsr_deallocate_matrix_set(p_env%p1_admm) 130 1646 : IF (ASSOCIATED(p_env%local_rho_set)) THEN 131 218 : CALL local_rho_set_release(p_env%local_rho_set) 132 : END IF 133 1646 : IF (ASSOCIATED(p_env%hartree_local)) THEN 134 190 : CALL hartree_local_release(p_env%hartree_local) 135 : END IF 136 1646 : IF (ASSOCIATED(p_env%local_rho_set_admm)) THEN 137 28 : CALL local_rho_set_release(p_env%local_rho_set_admm) 138 : END IF 139 1646 : IF (ASSOCIATED(p_env%PS_psi0)) THEN 140 1630 : CALL cp_fm_release(p_env%PS_psi0) 141 : END IF 142 1646 : IF (ASSOCIATED(p_env%preconditioner)) THEN 143 3542 : DO ip = 1, SIZE(p_env%preconditioner, 1) 144 3542 : CALL destroy_preconditioner(p_env%preconditioner(ip)) 145 : END DO 146 1630 : DEALLOCATE (p_env%preconditioner) 147 : END IF 148 1646 : END SUBROUTINE p_env_release 149 : 150 0 : END MODULE qs_p_env_types