(git:ccc2433)
ec_env_types.F
Go to the documentation of this file.
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 Types needed for a for a Energy Correction
10 !> \par History
11 !> 2019.09 created
12 !> \author JGH
13 ! **************************************************************************************************
16  USE dbcsr_api, ONLY: dbcsr_p_type
17  USE dm_ls_scf_types, ONLY: ls_scf_env_type,&
19  USE hfx_types, ONLY: hfx_release,&
20  hfx_type
22  section_vals_type
23  USE kinds, ONLY: dp
24  USE pw_types, ONLY: pw_r3d_rs_type
26  qs_dispersion_type
28  qs_force_type
29  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
31  USE qs_p_env_types, ONLY: p_env_release,&
32  qs_p_env_type
34  efield_berry_type
36  task_list_type
37 #include "./base/base_uses.f90"
38 
39  IMPLICIT NONE
40 
41  PRIVATE
42 
43  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_env_types'
44 
45  PUBLIC :: energy_correction_type, ec_env_release
46 
47 ! *****************************************************************************
48 !> \brief Contains information on the energy correction functional for KG
49 !> \par History
50 !> 03.2014 created
51 !> \author JGH
52 ! *****************************************************************************
53  TYPE energy_correction_type
54  CHARACTER(len=20) :: ec_name = ""
55  INTEGER :: energy_functional = 0
56  INTEGER :: ks_solver = 0
57  INTEGER :: factorization = 0
58  INTEGER :: ec_initial_guess = 0
59  REAL(KIND=dp) :: eps_default = 0.0_dp
60  LOGICAL :: do_ec_admm = .false.
61  LOGICAL :: do_ec_hfx = .false.
62  LOGICAL :: should_update = .false.
63  LOGICAL :: use_ls_solver = .false.
64  LOGICAL :: reuse_hfx = .false.
65  LOGICAL :: basis_inconsistent = .false.
66  ! debug
67  LOGICAL :: debug_forces = .false.
68  LOGICAL :: debug_stress = .false.
69  ! basis set
70  CHARACTER(len=20) :: basis = ""
71  LOGICAL :: mao = .false.
72  ! Skip EC calculation if ground-state didnt converge
73  LOGICAL :: do_skip = .false., skip_ec = .false.
74  INTEGER :: mao_max_iter = 0
75  REAL(KIND=dp) :: mao_eps_grad = 0.0_dp
76  REAL(KIND=dp) :: mao_eps1 = 0.0_dp
77  INTEGER :: mao_iolevel = 0
78  ! energy components
79  REAL(KIND=dp) :: etotal = 0.0_dp, old_etotal = 0.0_dp
80  REAL(KIND=dp) :: eband = 0.0_dp, ecore = 0.0_dp, exc = 0.0_dp, &
81  ehartree = 0.0_dp, vhxc = 0.0_dp
82  REAL(KIND=dp) :: edispersion = 0.0_dp, efield_elec = 0.0_dp, &
83  efield_nuclear = 0.0_dp, ex = 0.0_dp, exc_aux_fit = 0.0_dp
84  ! forces
85  TYPE(qs_force_type), DIMENSION(:), POINTER :: force => null()
86  ! full neighbor lists and corresponding task list
87  TYPE(neighbor_list_set_p_type), &
88  DIMENSION(:), POINTER :: sab_orb => null(), sac_ppl => null(), sap_ppnl => null()
89  TYPE(task_list_type), POINTER :: task_list => null()
90  ! the XC function to be used for the correction, dispersion info
91  TYPE(section_vals_type), POINTER :: xc_section => null()
92  TYPE(qs_dispersion_type), POINTER :: dispersion_env => null()
93  ! matrices in complete basis
94  ! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
95  ! P: Harris density, W: Harris energy weighted density
96  TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks => null(), &
97  matrix_h => null(), &
98  matrix_s => null(), &
99  matrix_t => null(), &
100  matrix_p => null(), &
101  matrix_w => null()
102  ! reduce basis
103  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef => null()
104  ! CP equations
105  TYPE(qs_p_env_type), POINTER :: p_env => null()
106  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz => null(), matrix_wz => null(), &
107  matrix_z => null(), z_admm => null()
108  ! Harris (rhoout), and response density (rhoz) on grid
109  TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoout_r => null(), rhoz_r => null()
110  ! potentials from input density
111  TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
112  TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => null(), vtau_rspace => null(), vadmm_rspace => null()
113  ! efield
114  TYPE(efield_berry_type), POINTER :: efield => null()
115  ! LS matrices and types
116  TYPE(ls_scf_env_type), POINTER :: ls_env => null()
117  ! Environment for Hartree-Fock exchange
118  TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => null()
119  ! ADMM XC environments
120  TYPE(section_vals_type), POINTER :: xc_section_primary => null(), &
121  xc_section_aux => null()
122  END TYPE energy_correction_type
123 
124 CONTAINS
125 
126 ! **************************************************************************************************
127 !> \brief ...
128 !> \param ec_env ...
129 ! **************************************************************************************************
130  SUBROUTINE ec_env_release(ec_env)
131  TYPE(energy_correction_type), POINTER :: ec_env
132 
133  CHARACTER(LEN=*), PARAMETER :: routinen = 'ec_env_release'
134 
135  INTEGER :: handle, iab
136 
137  CALL timeset(routinen, handle)
138 
139  IF (ASSOCIATED(ec_env)) THEN
140  ! neighbor lists
141  CALL release_neighbor_list_sets(ec_env%sab_orb)
142  CALL release_neighbor_list_sets(ec_env%sac_ppl)
143  CALL release_neighbor_list_sets(ec_env%sap_ppnl)
144  ! forces
145  IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
146  ! operator matrices
147  IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
148  IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
149  IF (ASSOCIATED(ec_env%matrix_s)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_s)
150  IF (ASSOCIATED(ec_env%matrix_t)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_t)
151  IF (ASSOCIATED(ec_env%matrix_p)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_p)
152  IF (ASSOCIATED(ec_env%matrix_w)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_w)
153  IF (ASSOCIATED(ec_env%task_list)) THEN
154  CALL deallocate_task_list(ec_env%task_list)
155  END IF
156  ! reduced basis
157  IF (ASSOCIATED(ec_env%mao_coef)) CALL dbcsr_deallocate_matrix_set(ec_env%mao_coef)
158  ! dispersion environment
159  IF (ASSOCIATED(ec_env%dispersion_env)) THEN
160  CALL qs_dispersion_release(ec_env%dispersion_env)
161  END IF
162 
163  IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
164  IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
165  IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
166  IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
167  NULLIFY (ec_env%matrix_z, ec_env%matrix_hz, ec_env%matrix_wz)
168  NULLIFY (ec_env%z_admm)
169 
170  IF (ASSOCIATED(ec_env%p_env)) THEN
171  CALL p_env_release(ec_env%p_env)
172  DEALLOCATE (ec_env%p_env)
173  END IF
174  ! potential
175  IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
176  CALL ec_env%vh_rspace%release()
177  END IF
178  IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
179  DO iab = 1, SIZE(ec_env%vxc_rspace)
180  CALL ec_env%vxc_rspace(iab)%release()
181  END DO
182  DEALLOCATE (ec_env%vxc_rspace)
183  END IF
184  IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
185  DO iab = 1, SIZE(ec_env%vtau_rspace)
186  CALL ec_env%vtau_rspace(iab)%release()
187  END DO
188  DEALLOCATE (ec_env%vtau_rspace)
189  END IF
190  IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
191  DO iab = 1, SIZE(ec_env%vadmm_rspace)
192  CALL ec_env%vadmm_rspace(iab)%release()
193  END DO
194  DEALLOCATE (ec_env%vadmm_rspace)
195  END IF
196  CALL efield_berry_release(ec_env%efield)
197 
198  IF (ASSOCIATED(ec_env%ls_env)) THEN
199  CALL ls_scf_release(ec_env%ls_env)
200  END IF
201 
202  IF (.NOT. ec_env%reuse_hfx) THEN
203  IF (ASSOCIATED(ec_env%x_data)) CALL hfx_release(ec_env%x_data)
204  END IF
205 
206  IF (ASSOCIATED(ec_env%xc_section_aux)) CALL section_vals_release(ec_env%xc_section_aux)
207  IF (ASSOCIATED(ec_env%xc_section_primary)) CALL section_vals_release(ec_env%xc_section_primary)
208 
209  DEALLOCATE (ec_env)
210 
211  END IF
212 
213  NULLIFY (ec_env)
214 
215  CALL timestop(handle)
216 
217  END SUBROUTINE ec_env_release
218 
219 END MODULE ec_env_types
DBCSR operations in CP2K.
Types needed for a linear scaling quickstep SCF run based on the density matrix.
subroutine, public ls_scf_release(ls_scf_env)
release the LS type.
Types needed for a for a Energy Correction.
Definition: ec_env_types.F:14
subroutine, public ec_env_release(ec_env)
...
Definition: ec_env_types.F:131
Types and set/get functions for HFX.
Definition: hfx_types.F:15
subroutine, public hfx_release(x_data)
This routine deallocates all data structures
Definition: hfx_types.F:1905
objects that represent the structure of input sections and the data contained in an input section
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Definition of disperson types for DFT calculations.
subroutine, public qs_dispersion_release(dispersion_env)
...
subroutine, public deallocate_qs_force(qs_force)
Deallocate a Quickstep force data structure.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
basis types for the calculation of the perturbation of density theory.
subroutine, public p_env_release(p_env)
relases the given p_env (see doc/ReferenceCounting.html)
type for berry phase efield matrices. At the moment only used for cosmat and sinmat
subroutine, public efield_berry_release(efield)
...
types for task lists
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself