(git:34ef472)
dm_ls_scf_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 linear scaling quickstep SCF run based on the density
10 !> matrix
11 !> \par History
12 !> 2010.10 created [Joost VandeVondele]
13 !> \author Joost VandeVondele
14 ! **************************************************************************************************
16  USE dbcsr_api, ONLY: dbcsr_release,&
17  dbcsr_type
21  section_vals_type
22  USE kinds, ONLY: dp
24  mp_para_env_type
25  USE pao_types, ONLY: pao_env_type,&
27  USE pexsi_types, ONLY: lib_pexsi_env,&
30  mixing_storage_type
31 #include "./base/base_uses.f90"
32 
33  IMPLICIT NONE
34 
35  PRIVATE
36 
37  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dm_ls_scf_types'
38 
39  PUBLIC :: ls_scf_env_type, ls_mstruct_type, ls_cluster_atomic, ls_cluster_molecular, &
40  ls_scf_curvy_type
41 
42  TYPE ls_mstruct_type
43  INTEGER :: cluster_type = -1
44  LOGICAL :: do_pao = .false.
45  INTEGER, DIMENSION(:), ALLOCATABLE :: atom_to_molecule
46  TYPE(dbcsr_type) :: matrix_A
47  TYPE(dbcsr_type) :: matrix_B
48  END TYPE
49 
50  TYPE ls_mat_history_type
51  INTEGER :: istore = 0, nstore = 0
52  TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix
53  END TYPE
54 
55  TYPE ls_scf_curvy_type
56  TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_dp
57  TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p
58  TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_psave
59  TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_BCH
60  REAL(KIND=dp), DIMENSION(2) :: step_size = 0.0_dp
61  REAL(KIND=dp), DIMENSION(2) :: shift = 0.0_dp
62  REAL(KIND=dp), DIMENSION(2) :: cg_denom = 0.0_dp
63  REAL(KIND=dp), DIMENSION(2) :: cg_numer = 0.0_dp
64  REAL(KIND=dp), DIMENSION(6) :: energies = 0.0_dp
65  INTEGER :: line_search_step = 0
66  INTEGER, DIMENSION(2) :: BCH_saved = 0
67  LOGICAL :: double_step_size = .false.
68  LOGICAL, DIMENSION(2) :: fix_shift = .false.
69 
70  INTEGER :: line_search_type = 0
71  INTEGER :: n_bch_hist = 0
72  REAL(KIND=dp) :: scale_filter = 0.0_dp
73  REAL(KIND=dp) :: filter_factor = 0.0_dp
74  REAL(KIND=dp) :: min_shift = 0.0_dp
75  REAL(KIND=dp) :: min_filter = 0.0_dp
76  END TYPE
77 
78  TYPE chebyshev_type
79  LOGICAL :: compute_chebyshev = .false.
80  INTEGER :: n_chebyshev = 0
81  INTEGER :: n_gridpoint_dos = 0
82  REAL(KIND=dp), DIMENSION(:), POINTER :: min_energy => null()
83  REAL(KIND=dp), DIMENSION(:), POINTER :: max_energy => null()
84  TYPE(section_vals_type), POINTER :: print_key_dos => null()
85  TYPE(section_vals_type), POINTER :: print_key_cube => null()
86  END TYPE
87 
88  TYPE ls_scf_env_type
89  INTEGER :: nspins = 0, natoms = 0
90  INTEGER :: nelectron_total = 0
91  INTEGER, DIMENSION(2) :: nelectron_spin = 0
92  REAL(KIND=dp), DIMENSION(2) :: mu_spin = 0.0_dp
93  REAL(KIND=dp), DIMENSION(2) :: homo_spin = 0.0_dp
94  REAL(KIND=dp), DIMENSION(2) :: lumo_spin = 0.0_dp
95 
96  ! This prevents a bug in GCC up to version 9.x (9.5 seems to work though)
97  TYPE(ls_mat_history_type) :: scf_history = ls_mat_history_type(matrix=null())
98  INTEGER :: extrapolation_order = -1
99 
100  LOGICAL :: has_unit_metric = .false.
101 
102  LOGICAL :: curvy_steps = .false.
103  INTEGER :: s_preconditioner_type = 0
104  INTEGER :: s_inversion_type = 0
105  INTEGER :: purification_method = 0
106  INTEGER :: sign_method = 0
107  INTEGER :: sign_order = 0
108  LOGICAL :: sign_symmetric = .false.
109  INTEGER :: submatrix_sign_method = -1
110  INTEGER :: s_sqrt_method = 0
111  INTEGER :: s_sqrt_order = 0
112 
113  LOGICAL :: needs_s_inv = .false., has_s_preconditioner = .false., fixed_mu = .false., &
114  dynamic_threshold = .false., check_s_inv = .false.
115  LOGICAL :: restart_read = .false., restart_write = .false., non_monotonic = .false.
116  REAL(KIND=dp) :: eps_filter = 0.0_dp, eps_scf = 0.0_dp
117 
118  REAL(KIND=dp) :: eps_lanczos = 0.0_dp
119  INTEGER :: max_iter_lanczos = 0
120 
121  REAL(KIND=dp) :: mixing_fraction = 0.0_dp
122  INTEGER :: max_scf = 0
123  LOGICAL :: ls_diis = .false.
124  INTEGER :: iter_ini_diis = 0
125  INTEGER :: nmixing = 0, max_diis = 0
126  REAL(KIND=dp) :: eps_diis = 0.0_dp
127  REAL(KIND=dp) :: energy_init = 0.0_dp
128 
129  TYPE(dbcsr_type) :: matrix_s_inv
130  TYPE(dbcsr_type) :: matrix_s
131  TYPE(dbcsr_type) :: matrix_bs_sqrt, matrix_bs_sqrt_inv
132  TYPE(dbcsr_type) :: matrix_s_sqrt, matrix_s_sqrt_inv
133  TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ks
134  TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p
135 
136  LOGICAL :: report_all_sparsities = .false., perform_mu_scan = .false., use_s_sqrt = .false.
137 
138  TYPE(ls_mstruct_type) :: ls_mstruct
139  TYPE(ls_scf_curvy_type) :: curvy_data = ls_scf_curvy_type(matrix_dp=null(), matrix_p=null(), &
140  matrix_psave=null(), matrix_bch=null())
141 
142  TYPE(chebyshev_type) :: chebyshev = chebyshev_type()
143 
144  LOGICAL :: do_rho_mixing = .false.
145  INTEGER :: density_mixing_method = 0
146  TYPE(mixing_storage_type), POINTER :: mixing_store => null()
147 
148  LOGICAL :: do_transport = .false.
149  LOGICAL :: do_pexsi = .false.
150 
151  LOGICAL :: calculate_forces = .false.
152 
153  TYPE(lib_pexsi_env) :: pexsi
154 
155  TYPE(mp_para_env_type), POINTER :: para_env => null()
156  LOGICAL :: do_pao = .false.
157  TYPE(pao_env_type) :: pao_env
158  END TYPE ls_scf_env_type
159 
160  PUBLIC :: ls_scf_release
161 
162 CONTAINS
163 
164 ! **************************************************************************************************
165 !> \brief release the LS type.
166 !> \param ls_scf_env ...
167 !> \par History
168 !> 2012.11 created [Joost VandeVondele]
169 !> \author Joost VandeVondele
170 ! **************************************************************************************************
171  SUBROUTINE ls_scf_release(ls_scf_env)
172  TYPE(ls_scf_env_type), POINTER :: ls_scf_env
173 
174  CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_release'
175 
176  INTEGER :: handle, ispin, istore
177 
178  CALL timeset(routinen, handle)
179 
180  CALL mp_para_env_release(ls_scf_env%para_env)
181 
182  DEALLOCATE (ls_scf_env%ls_mstruct%atom_to_molecule)
183 
184  ! set up the buffer for the history of matrices
185  DO istore = 1, min(ls_scf_env%scf_history%istore, ls_scf_env%scf_history%nstore)
186  DO ispin = 1, SIZE(ls_scf_env%scf_history%matrix, 1)
187  CALL dbcsr_release(ls_scf_env%scf_history%matrix(ispin, istore))
188  END DO
189  END DO
190  DEALLOCATE (ls_scf_env%scf_history%matrix)
191 
192  IF (ALLOCATED(ls_scf_env%matrix_p)) THEN
193  DO ispin = 1, SIZE(ls_scf_env%matrix_p)
194  CALL dbcsr_release(ls_scf_env%matrix_p(ispin))
195  END DO
196  DEALLOCATE (ls_scf_env%matrix_p)
197  END IF
198 
199  IF (ASSOCIATED(ls_scf_env%chebyshev%print_key_dos)) &
200  CALL section_vals_release(ls_scf_env%chebyshev%print_key_dos)
201  IF (ASSOCIATED(ls_scf_env%chebyshev%print_key_cube)) &
202  CALL section_vals_release(ls_scf_env%chebyshev%print_key_cube)
203  IF (ASSOCIATED(ls_scf_env%chebyshev%min_energy)) THEN
204  DEALLOCATE (ls_scf_env%chebyshev%min_energy)
205  END IF
206  IF (ASSOCIATED(ls_scf_env%chebyshev%max_energy)) THEN
207  DEALLOCATE (ls_scf_env%chebyshev%max_energy)
208  END IF
209 
210  IF (ASSOCIATED(ls_scf_env%mixing_store)) THEN
211  CALL mixing_storage_release(ls_scf_env%mixing_store)
212  DEALLOCATE (ls_scf_env%mixing_store)
213  END IF
214 
215  IF (ls_scf_env%do_pexsi) THEN
216  CALL lib_pexsi_finalize(ls_scf_env%pexsi)
217  END IF
218 
219  IF (ls_scf_env%do_pao) &
220  CALL pao_finalize(ls_scf_env%pao_env)
221 
222  DEALLOCATE (ls_scf_env)
223 
224  CALL timestop(handle)
225 
226  END SUBROUTINE ls_scf_release
227 
228 END MODULE dm_ls_scf_types
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.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public ls_cluster_molecular
integer, parameter, public ls_cluster_atomic
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
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Types used by the PAO machinery.
Definition: pao_types.F:12
subroutine, public pao_finalize(pao)
Finalize the PAO environment.
Definition: pao_types.F:214
Environment storing all data that is needed in order to call the DFT driver of the PEXSI library with...
Definition: pexsi_types.F:18
subroutine, public lib_pexsi_finalize(pexsi_env)
Release all PEXSI data.
Definition: pexsi_types.F:202
module that contains the definitions of the scf types
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage