Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief module that contains the definitions of the scf types
10 : !> \par History
11 : !> 02.2003 created [fawzi]
12 : !> \author fawzi
13 : ! **************************************************************************************************
14 : MODULE qs_density_mixing_types
15 : #if defined(__TBLITE)
16 : USE tblite_scf, ONLY: mixer_type
17 : #endif
18 : USE ao_util, ONLY: exp_radius
19 : USE input_constants, ONLY: broy_mix, &
20 : direct_p_mix, &
21 : gaussian, &
22 : kerker_mix, &
23 : modified_broy_mix, &
24 : multisec_mix, &
25 : no_mix, &
26 : pulay_mix
27 : USE input_keyword_types, ONLY: keyword_create, &
28 : keyword_release, &
29 : keyword_type
30 : USE input_section_types, ONLY: section_add_keyword, &
31 : section_create, &
32 : section_type, &
33 : section_vals_type, &
34 : section_vals_val_get
35 : USE input_val_types, ONLY: real_t
36 : USE kinds, ONLY: default_string_length, &
37 : dp
38 : USE qs_rho_atom_types, ONLY: rho_atom_coeff
39 : USE string_utilities, ONLY: s2a
40 : #include "./base/base_uses.f90"
41 :
42 : IMPLICIT NONE
43 : PRIVATE
44 :
45 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
46 :
47 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_density_mixing_types'
48 :
49 : INTEGER, PARAMETER, PUBLIC :: no_mixing_nr = 0, direct_mixing_nr = 1, &
50 : gspace_mixing_nr = 2, pulay_mixing_nr = 3, &
51 : broyden_mixing_nr = 4, &
52 : modified_broyden_mixing_nr = 5, &
53 : multisecant_mixing_nr = 6
54 : PUBLIC :: cp_1d_z_p_type, mixing_storage_create, mixing_storage_type, mixing_storage_release, create_mixing_section
55 :
56 : TYPE cp_1d_z_p_type
57 : COMPLEX(dp), DIMENSION(:), POINTER :: cc => NULL()
58 : END TYPE cp_1d_z_p_type
59 :
60 : TYPE mixing_storage_type
61 : INTEGER :: ig_max = -1, ncall = -1, ncall_p(2) = -1, nbuffer = -1, n_simple_mix = -1, &
62 : nskip_mixing = -1, p_metric_method = -1
63 : INTEGER, POINTER, DIMENSION(:) :: ig_global_index => NULL()
64 : LOGICAL :: gmix_p = .FALSE.
65 : LOGICAL, POINTER, DIMENSION(:) :: paw => NULL()
66 : CHARACTER(len=15) :: iter_method = ""
67 : REAL(KIND=dp) :: alpha = -1.0_dp, bconst = -1.0_dp, beta = -1.0_dp, broy_w0 = -1.0_dp, &
68 : max_g2 = -1.0_dp, max_gvec_exp = -1.0_dp, pulay_alpha = -1.0_dp, &
69 : pulay_beta = -1.0_dp, r_step = -1.0_dp, reg_par = -1.0_dp, &
70 : sigma_max = -1.0_dp, wc = -1.0_dp, wmax = -1.0_dp
71 : ! Spin-channel-specific mixing parameters (for nspin==2, ispin=2 is the magnetization channel)
72 : REAL(KIND=dp) :: alpha_mag = -1.0_dp, beta_mag = -1.0_dp
73 : REAL(KIND=dp), DIMENSION(:), POINTER :: p_metric => NULL()
74 : REAL(KIND=dp), DIMENSION(:), POINTER :: kerker_factor => NULL()
75 : REAL(KIND=dp), DIMENSION(:), POINTER :: kerker_factor_mag => NULL()
76 : REAL(KIND=dp), DIMENSION(:), POINTER :: special_metric => NULL()
77 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: weight => NULL()
78 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: norm_res_buffer => NULL()
79 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: fmat => NULL(), gmat => NULL(), pulay_matrix => NULL(), smat => NULL()
80 : !
81 : INTEGER :: nat_local = -1, max_shell = -1
82 : INTEGER :: tb_scc_mixer_memory = 0, tb_scc_mixer_natom = 0, &
83 : tb_scc_mixer_ns = 0, tb_scc_mixer_step = 0
84 : REAL(KIND=dp) :: tb_scc_mixer_error = 0.0_dp
85 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: acharge => NULL()
86 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: dacharge => NULL()
87 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: dfbroy => NULL()
88 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: ubroy => NULL()
89 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: abroy => NULL()
90 : REAL(KIND=dp), DIMENSION(:), POINTER :: wbroy => NULL()
91 : INTEGER, DIMENSION(:), POINTER :: atlist => NULL()
92 : !
93 : TYPE(cp_1d_z_p_type), DIMENSION(:), POINTER :: last_res => NULL(), rhoin => NULL(), rhoin_old => NULL()
94 : TYPE(cp_1d_z_p_type), DIMENSION(:, :), POINTER :: delta_res => NULL(), u_vec => NULL(), z_vec => NULL()
95 : TYPE(cp_1d_z_p_type), DIMENSION(:, :), POINTER :: drho_buffer => NULL(), rhoin_buffer => NULL(), res_buffer => NULL()
96 : !
97 : TYPE(rho_atom_coeff), DIMENSION(:, :), POINTER :: cpc_h_lastres => NULL(), cpc_s_lastres => NULL()
98 : TYPE(rho_atom_coeff), DIMENSION(:, :), POINTER :: cpc_h_in => NULL(), cpc_s_in => NULL()
99 : TYPE(rho_atom_coeff), DIMENSION(:, :), POINTER :: cpc_h_old => NULL(), cpc_s_old => NULL()
100 : TYPE(rho_atom_coeff), DIMENSION(:, :, :), POINTER :: cpc_h_in_buffer => NULL(), cpc_s_in_buffer => NULL()
101 : TYPE(rho_atom_coeff), DIMENSION(:, :, :), POINTER :: cpc_h_res_buffer => NULL(), cpc_s_res_buffer => NULL()
102 : TYPE(rho_atom_coeff), DIMENSION(:, :, :), POINTER :: dcpc_h_in => NULL(), dcpc_s_in => NULL()
103 : #if defined(__TBLITE)
104 : CLASS(mixer_type), ALLOCATABLE :: tb_scc_mixer
105 : #endif
106 : END TYPE mixing_storage_type
107 :
108 : CONTAINS
109 :
110 : ! **************************************************************************************************
111 : !> \brief creates a mixing_storage
112 : !> \param mixing_store ...
113 : !> \param mixing_section ...
114 : !> \param mixing_method ...
115 : !> \param ecut ...
116 : !> \par History
117 : !> 05.2009 created [MI]
118 : !> \author [MI]
119 : ! **************************************************************************************************
120 30964 : SUBROUTINE mixing_storage_create(mixing_store, mixing_section, mixing_method, ecut)
121 : TYPE(mixing_storage_type), INTENT(OUT) :: mixing_store
122 : TYPE(section_vals_type), POINTER :: mixing_section
123 : INTEGER, INTENT(IN) :: mixing_method
124 : REAL(dp), INTENT(IN) :: ecut
125 :
126 : REAL(dp) :: alpha, eps, gcut
127 :
128 7741 : mixing_store%nbuffer = 0
129 7741 : mixing_store%n_simple_mix = 0
130 7741 : mixing_store%ncall = 0
131 23223 : mixing_store%ncall_p = 0
132 7741 : mixing_store%alpha = 1.0_dp
133 7741 : mixing_store%pulay_beta = 1.0_dp
134 7741 : mixing_store%beta = 1.0_dp
135 7741 : mixing_store%alpha_mag = -1.0_dp
136 7741 : mixing_store%beta_mag = -1.0_dp
137 7741 : mixing_store%iter_method = "NoMix"
138 7741 : mixing_store%max_g2 = 2._dp*ecut
139 7741 : mixing_store%gmix_p = .FALSE.
140 7741 : mixing_store%tb_scc_mixer_error = 0.0_dp
141 : mixing_store%tb_scc_mixer_memory = 0
142 : mixing_store%tb_scc_mixer_natom = 0
143 : mixing_store%tb_scc_mixer_ns = 0
144 : mixing_store%tb_scc_mixer_step = 0
145 :
146 7741 : NULLIFY (mixing_store%p_metric)
147 7741 : NULLIFY (mixing_store%kerker_factor)
148 7741 : NULLIFY (mixing_store%kerker_factor_mag)
149 7741 : NULLIFY (mixing_store%special_metric)
150 7741 : NULLIFY (mixing_store%pulay_matrix)
151 7741 : NULLIFY (mixing_store%weight)
152 7741 : NULLIFY (mixing_store%fmat)
153 7741 : NULLIFY (mixing_store%gmat)
154 7741 : NULLIFY (mixing_store%smat)
155 7741 : NULLIFY (mixing_store%acharge)
156 7741 : NULLIFY (mixing_store%dacharge)
157 7741 : NULLIFY (mixing_store%dfbroy)
158 7741 : NULLIFY (mixing_store%ubroy)
159 7741 : NULLIFY (mixing_store%abroy)
160 7741 : NULLIFY (mixing_store%wbroy)
161 7741 : NULLIFY (mixing_store%atlist)
162 7741 : NULLIFY (mixing_store%last_res)
163 7741 : NULLIFY (mixing_store%rhoin)
164 7741 : NULLIFY (mixing_store%rhoin_old)
165 7741 : NULLIFY (mixing_store%delta_res)
166 7741 : NULLIFY (mixing_store%u_vec)
167 7741 : NULLIFY (mixing_store%z_vec)
168 7741 : NULLIFY (mixing_store%drho_buffer)
169 7741 : NULLIFY (mixing_store%rhoin_buffer)
170 7741 : NULLIFY (mixing_store%res_buffer)
171 7741 : NULLIFY (mixing_store%norm_res_buffer)
172 7741 : NULLIFY (mixing_store%ig_global_index)
173 7741 : NULLIFY (mixing_store%paw)
174 7741 : NULLIFY (mixing_store%cpc_h_in)
175 7741 : NULLIFY (mixing_store%cpc_s_in)
176 7741 : NULLIFY (mixing_store%cpc_h_old)
177 7741 : NULLIFY (mixing_store%cpc_s_old)
178 7741 : NULLIFY (mixing_store%dcpc_h_in)
179 7741 : NULLIFY (mixing_store%dcpc_s_in)
180 7741 : NULLIFY (mixing_store%cpc_h_lastres)
181 7741 : NULLIFY (mixing_store%cpc_s_lastres)
182 7741 : NULLIFY (mixing_store%cpc_h_in_buffer)
183 7741 : NULLIFY (mixing_store%cpc_s_in_buffer)
184 7741 : NULLIFY (mixing_store%cpc_h_res_buffer)
185 7741 : NULLIFY (mixing_store%cpc_s_res_buffer)
186 :
187 7741 : CALL section_vals_val_get(mixing_section, "ALPHA", r_val=mixing_store%alpha)
188 7741 : CALL section_vals_val_get(mixing_section, "BETA", r_val=mixing_store%beta)
189 7741 : CALL section_vals_val_get(mixing_section, "ALPHA_MAG", r_val=mixing_store%alpha_mag)
190 7741 : CALL section_vals_val_get(mixing_section, "BETA_MAG", r_val=mixing_store%beta_mag)
191 : ! Fall back to charge-channel values if magnetization parameters are not set
192 7741 : IF (mixing_store%alpha_mag < 0.0_dp) mixing_store%alpha_mag = mixing_store%alpha
193 7741 : IF (mixing_store%beta_mag < 0.0_dp) mixing_store%beta_mag = mixing_store%beta
194 7741 : CALL section_vals_val_get(mixing_section, "N_SIMPLE_MIX", i_val=mixing_store%n_simple_mix)
195 7741 : CALL section_vals_val_get(mixing_section, "NBUFFER", i_val=mixing_store%nbuffer)
196 7741 : CALL section_vals_val_get(mixing_section, "NSKIP", i_val=mixing_store%nskip_mixing)
197 7741 : CALL section_vals_val_get(mixing_section, "MAX_GVEC_EXP", r_val=mixing_store%max_gvec_exp)
198 7741 : CALL section_vals_val_get(mixing_section, "GMIX_P", l_val=mixing_store%gmix_p)
199 :
200 7741 : IF (mixing_store%max_gvec_exp > 0._dp) THEN
201 0 : alpha = 0.25_dp/mixing_store%max_gvec_exp
202 0 : eps = 1.e-4_dp
203 0 : gcut = exp_radius(3, alpha, eps, 1.0_dp)
204 0 : mixing_store%max_g2 = gcut*gcut
205 : END IF
206 :
207 7753 : SELECT CASE (mixing_method)
208 : CASE (gspace_mixing_nr)
209 12 : mixing_store%nbuffer = 1
210 : CASE (pulay_mixing_nr)
211 36 : CALL section_vals_val_get(mixing_section, "PULAY_ALPHA", r_val=mixing_store%pulay_alpha)
212 36 : CALL section_vals_val_get(mixing_section, "PULAY_BETA", r_val=mixing_store%pulay_beta)
213 : CASE (broyden_mixing_nr)
214 728 : CALL section_vals_val_get(mixing_section, "BROY_W0", r_val=mixing_store%broy_w0)
215 728 : mixing_store%bconst = 20.0_dp
216 : CASE (modified_broyden_mixing_nr)
217 4 : CALL section_vals_val_get(mixing_section, "BROY_W0", r_val=mixing_store%broy_w0)
218 4 : CALL section_vals_val_get(mixing_section, "BROY_WREF", r_val=mixing_store%wc)
219 4 : CALL section_vals_val_get(mixing_section, "BROY_WMAX", r_val=mixing_store%wmax)
220 4 : mixing_store%bconst = 20.0_dp
221 : CASE (multisecant_mixing_nr)
222 0 : CALL section_vals_val_get(mixing_section, "REGULARIZATION", r_val=mixing_store%reg_par)
223 0 : CALL section_vals_val_get(mixing_section, "MAX_STEP", r_val=mixing_store%sigma_max)
224 7741 : CALL section_vals_val_get(mixing_section, "R_FACTOR", r_val=mixing_store%r_step)
225 : END SELECT
226 :
227 7741 : END SUBROUTINE mixing_storage_create
228 :
229 : ! **************************************************************************************************
230 : !> \brief releases a mixing_storage
231 : !> \param mixing_store ...
232 : !> \par History
233 : !> 05.2009 created [MI]
234 : !> \author [MI]
235 : ! **************************************************************************************************
236 7741 : SUBROUTINE mixing_storage_release(mixing_store)
237 : TYPE(mixing_storage_type), INTENT(INOUT) :: mixing_store
238 :
239 : INTEGER :: i, j, k
240 :
241 7741 : IF (ASSOCIATED(mixing_store%kerker_factor)) THEN
242 360 : DEALLOCATE (mixing_store%kerker_factor)
243 : END IF
244 :
245 7741 : IF (ASSOCIATED(mixing_store%kerker_factor_mag)) THEN
246 360 : DEALLOCATE (mixing_store%kerker_factor_mag)
247 : END IF
248 :
249 7741 : IF (ASSOCIATED(mixing_store%special_metric)) THEN
250 360 : DEALLOCATE (mixing_store%special_metric)
251 : END IF
252 :
253 7741 : IF (ASSOCIATED(mixing_store%pulay_matrix)) THEN
254 34 : DEALLOCATE (mixing_store%pulay_matrix)
255 : END IF
256 :
257 7741 : IF (ASSOCIATED(mixing_store%rhoin_buffer)) THEN
258 72 : DO i = 1, SIZE(mixing_store%rhoin_buffer, 2)
259 298 : DO j = 1, SIZE(mixing_store%rhoin_buffer, 1)
260 264 : DEALLOCATE (mixing_store%rhoin_buffer(j, i)%cc)
261 : END DO
262 : END DO
263 34 : DEALLOCATE (mixing_store%rhoin_buffer)
264 : END IF
265 :
266 7741 : IF (ASSOCIATED(mixing_store%paw)) THEN
267 16 : DEALLOCATE (mixing_store%paw)
268 : END IF
269 7741 : IF (ASSOCIATED(mixing_store%cpc_h_in)) THEN
270 38 : DO j = 1, SIZE(mixing_store%cpc_h_in, 2)
271 214 : DO k = 1, SIZE(mixing_store%cpc_h_in, 1)
272 198 : IF (ASSOCIATED(mixing_store%cpc_h_in(k, j)%r_coef)) THEN
273 106 : DEALLOCATE (mixing_store%cpc_h_in(k, j)%r_coef)
274 106 : DEALLOCATE (mixing_store%cpc_s_in(k, j)%r_coef)
275 : END IF
276 : END DO
277 : END DO
278 16 : DEALLOCATE (mixing_store%cpc_h_in)
279 16 : DEALLOCATE (mixing_store%cpc_s_in)
280 : END IF
281 7741 : IF (ASSOCIATED(mixing_store%cpc_h_old)) THEN
282 30 : DO j = 1, SIZE(mixing_store%cpc_h_old, 2)
283 174 : DO k = 1, SIZE(mixing_store%cpc_h_old, 1)
284 162 : IF (ASSOCIATED(mixing_store%cpc_h_old(k, j)%r_coef)) THEN
285 102 : DEALLOCATE (mixing_store%cpc_h_old(k, j)%r_coef)
286 102 : DEALLOCATE (mixing_store%cpc_s_old(k, j)%r_coef)
287 : END IF
288 : END DO
289 : END DO
290 12 : DEALLOCATE (mixing_store%cpc_h_old)
291 12 : DEALLOCATE (mixing_store%cpc_s_old)
292 : END IF
293 7741 : IF (ASSOCIATED(mixing_store%cpc_h_in_buffer)) THEN
294 4 : DO i = 1, SIZE(mixing_store%cpc_h_in_buffer, 3)
295 20 : DO j = 1, SIZE(mixing_store%cpc_h_in_buffer, 2)
296 98 : DO k = 1, SIZE(mixing_store%cpc_h_in_buffer, 1)
297 96 : IF (ASSOCIATED(mixing_store%cpc_h_in_buffer(k, j, i)%r_coef)) THEN
298 10 : DEALLOCATE (mixing_store%cpc_h_in_buffer(k, j, i)%r_coef)
299 10 : DEALLOCATE (mixing_store%cpc_s_in_buffer(k, j, i)%r_coef)
300 : END IF
301 : END DO
302 : END DO
303 : END DO
304 2 : DEALLOCATE (mixing_store%cpc_h_in_buffer)
305 2 : DEALLOCATE (mixing_store%cpc_s_in_buffer)
306 : END IF
307 7741 : IF (ASSOCIATED(mixing_store%cpc_h_res_buffer)) THEN
308 4 : DO i = 1, SIZE(mixing_store%cpc_h_res_buffer, 3)
309 20 : DO j = 1, SIZE(mixing_store%cpc_h_res_buffer, 2)
310 98 : DO k = 1, SIZE(mixing_store%cpc_h_res_buffer, 1)
311 96 : IF (ASSOCIATED(mixing_store%cpc_h_res_buffer(k, j, i)%r_coef)) THEN
312 10 : DEALLOCATE (mixing_store%cpc_h_res_buffer(k, j, i)%r_coef)
313 10 : DEALLOCATE (mixing_store%cpc_s_res_buffer(k, j, i)%r_coef)
314 : END IF
315 : END DO
316 : END DO
317 : END DO
318 2 : DEALLOCATE (mixing_store%cpc_h_res_buffer)
319 2 : DEALLOCATE (mixing_store%cpc_s_res_buffer)
320 : END IF
321 :
322 7741 : IF (ASSOCIATED(mixing_store%dcpc_h_in)) THEN
323 30 : DO i = 1, SIZE(mixing_store%dcpc_h_in, 3)
324 174 : DO j = 1, SIZE(mixing_store%dcpc_h_in, 2)
325 1266 : DO k = 1, SIZE(mixing_store%dcpc_h_in, 1)
326 1248 : IF (ASSOCIATED(mixing_store%dcpc_h_in(k, j, i)%r_coef)) THEN
327 810 : DEALLOCATE (mixing_store%dcpc_h_in(k, j, i)%r_coef)
328 810 : DEALLOCATE (mixing_store%dcpc_s_in(k, j, i)%r_coef)
329 : END IF
330 : END DO
331 : END DO
332 : END DO
333 12 : DEALLOCATE (mixing_store%dcpc_h_in)
334 12 : DEALLOCATE (mixing_store%dcpc_s_in)
335 : END IF
336 7741 : IF (ASSOCIATED(mixing_store%cpc_h_lastres)) THEN
337 30 : DO j = 1, SIZE(mixing_store%cpc_h_lastres, 2)
338 174 : DO k = 1, SIZE(mixing_store%cpc_h_lastres, 1)
339 162 : IF (ASSOCIATED(mixing_store%cpc_h_lastres(k, j)%r_coef)) THEN
340 102 : DEALLOCATE (mixing_store%cpc_h_lastres(k, j)%r_coef)
341 102 : DEALLOCATE (mixing_store%cpc_s_lastres(k, j)%r_coef)
342 : END IF
343 : END DO
344 : END DO
345 12 : DEALLOCATE (mixing_store%cpc_h_lastres)
346 12 : DEALLOCATE (mixing_store%cpc_s_lastres)
347 : END IF
348 :
349 7741 : IF (ASSOCIATED(mixing_store%res_buffer)) THEN
350 748 : DO i = 1, SIZE(mixing_store%res_buffer, 2)
351 3610 : DO j = 1, SIZE(mixing_store%res_buffer, 1)
352 3262 : DEALLOCATE (mixing_store%res_buffer(j, i)%cc)
353 : END DO
354 : END DO
355 348 : DEALLOCATE (mixing_store%res_buffer)
356 : END IF
357 :
358 7741 : IF (ASSOCIATED(mixing_store%norm_res_buffer)) THEN
359 0 : DEALLOCATE (mixing_store%norm_res_buffer)
360 : END IF
361 :
362 7741 : IF (ASSOCIATED(mixing_store%ig_global_index)) THEN
363 0 : DEALLOCATE (mixing_store%ig_global_index)
364 : END IF
365 :
366 7741 : IF (ASSOCIATED(mixing_store%drho_buffer)) THEN
367 676 : DO i = 1, SIZE(mixing_store%drho_buffer, 2)
368 3312 : DO j = 1, SIZE(mixing_store%drho_buffer, 1)
369 2998 : DEALLOCATE (mixing_store%drho_buffer(j, i)%cc)
370 : END DO
371 : END DO
372 314 : DEALLOCATE (mixing_store%drho_buffer)
373 : END IF
374 :
375 7741 : IF (ASSOCIATED(mixing_store%last_res)) THEN
376 676 : DO i = 1, SIZE(mixing_store%last_res)
377 676 : DEALLOCATE (mixing_store%last_res(i)%cc)
378 : END DO
379 314 : DEALLOCATE (mixing_store%last_res)
380 : END IF
381 :
382 7741 : IF (ASSOCIATED(mixing_store%rhoin)) THEN
383 772 : DO i = 1, SIZE(mixing_store%rhoin)
384 772 : DEALLOCATE (mixing_store%rhoin(i)%cc)
385 : END DO
386 360 : DEALLOCATE (mixing_store%rhoin)
387 : END IF
388 :
389 7741 : IF (ASSOCIATED(mixing_store%rhoin_old)) THEN
390 676 : DO i = 1, SIZE(mixing_store%rhoin_old)
391 676 : DEALLOCATE (mixing_store%rhoin_old(i)%cc)
392 : END DO
393 314 : DEALLOCATE (mixing_store%rhoin_old)
394 : END IF
395 :
396 7741 : IF (ASSOCIATED(mixing_store%p_metric)) THEN
397 314 : DEALLOCATE (mixing_store%p_metric)
398 : END IF
399 :
400 7741 : IF (ASSOCIATED(mixing_store%weight)) THEN
401 2 : DEALLOCATE (mixing_store%weight)
402 : END IF
403 :
404 7741 : IF (ASSOCIATED(mixing_store%fmat)) THEN
405 0 : DEALLOCATE (mixing_store%fmat)
406 : END IF
407 :
408 7741 : IF (ASSOCIATED(mixing_store%acharge)) THEN
409 30 : DEALLOCATE (mixing_store%acharge)
410 : END IF
411 7741 : IF (ASSOCIATED(mixing_store%dacharge)) THEN
412 30 : DEALLOCATE (mixing_store%dacharge)
413 : END IF
414 7741 : IF (ASSOCIATED(mixing_store%dfbroy)) THEN
415 30 : DEALLOCATE (mixing_store%dfbroy)
416 : END IF
417 7741 : IF (ASSOCIATED(mixing_store%ubroy)) THEN
418 30 : DEALLOCATE (mixing_store%ubroy)
419 : END IF
420 7741 : IF (ASSOCIATED(mixing_store%abroy)) THEN
421 30 : DEALLOCATE (mixing_store%abroy)
422 : END IF
423 7741 : IF (ASSOCIATED(mixing_store%wbroy)) THEN
424 30 : DEALLOCATE (mixing_store%wbroy)
425 : END IF
426 7741 : IF (ASSOCIATED(mixing_store%atlist)) THEN
427 30 : DEALLOCATE (mixing_store%atlist)
428 : END IF
429 : #if defined(__TBLITE)
430 7741 : IF (ALLOCATED(mixing_store%tb_scc_mixer)) THEN
431 4 : DEALLOCATE (mixing_store%tb_scc_mixer)
432 : END IF
433 : #endif
434 :
435 7741 : IF (ASSOCIATED(mixing_store%delta_res)) THEN
436 0 : DO i = 1, SIZE(mixing_store%delta_res, 2)
437 0 : DO j = 1, SIZE(mixing_store%delta_res, 1)
438 0 : DEALLOCATE (mixing_store%delta_res(j, i)%cc)
439 : END DO
440 : END DO
441 0 : DEALLOCATE (mixing_store%delta_res)
442 : END IF
443 :
444 7741 : IF (ASSOCIATED(mixing_store%u_vec)) THEN
445 0 : DO i = 1, SIZE(mixing_store%u_vec, 2)
446 0 : DO j = 1, SIZE(mixing_store%u_vec, 1)
447 0 : DEALLOCATE (mixing_store%u_vec(j, i)%cc)
448 : END DO
449 : END DO
450 0 : DEALLOCATE (mixing_store%u_vec)
451 : END IF
452 :
453 7741 : IF (ASSOCIATED(mixing_store%z_vec)) THEN
454 0 : DO i = 1, SIZE(mixing_store%z_vec, 2)
455 0 : DO j = 1, SIZE(mixing_store%z_vec, 1)
456 0 : DEALLOCATE (mixing_store%z_vec(j, i)%cc)
457 : END DO
458 : END DO
459 0 : DEALLOCATE (mixing_store%z_vec)
460 : END IF
461 :
462 7741 : END SUBROUTINE mixing_storage_release
463 :
464 : ! **************************************************************************************************
465 : !> \brief Create CP2K input section for the mixing of the density matrix to
466 : !> be used only with diagonalization methods, i.e. not with OT
467 : !> \param section ...
468 : !> \param ls_scf ...
469 : !> \date 20.02.2009
470 : !> \par History
471 : !> 02.2015 moved here from input_cp2k_dft.F, modified for use in LS SCF
472 : !> [Patrick Seewald]
473 : !> \author MI
474 : !> \version 1.0
475 : ! **************************************************************************************************
476 79296 : SUBROUTINE create_mixing_section(section, ls_scf)
477 :
478 : TYPE(section_type), POINTER :: section
479 : LOGICAL, INTENT(IN), OPTIONAL :: ls_scf
480 :
481 : CHARACTER(LEN=default_string_length) :: section_name
482 : INTEGER :: default_mix
483 : LOGICAL :: ls
484 : TYPE(keyword_type), POINTER :: keyword
485 :
486 79296 : CPASSERT(.NOT. ASSOCIATED(section))
487 :
488 79296 : IF (PRESENT(ls_scf)) THEN
489 20540 : IF (ls_scf) THEN
490 : ls = .TRUE.
491 : ELSE
492 : ls = .FALSE.
493 : END IF
494 : ELSE
495 : ls = .FALSE.
496 : END IF
497 :
498 : IF (ls) THEN
499 10278 : section_name = "RHO_MIXING"
500 : ELSE
501 69018 : section_name = "MIXING"
502 : END IF
503 :
504 : CALL section_create(section, __LOCATION__, &
505 : name=section_name, &
506 : description="Define type and parameters for mixing "// &
507 : "procedures to be applied to the density matrix. Normally, "// &
508 : "only one type of mixing method should be accepted. The mixing "// &
509 : "procedures activated by this section are only active for diagonalization "// &
510 : "methods and linear scaling SCF, i.e. not with minimization methods based "// &
511 : "on OT.", &
512 : n_keywords=16, &
513 : n_subsections=0, &
514 79296 : repeats=.FALSE.)
515 :
516 79296 : NULLIFY (keyword)
517 :
518 : CALL keyword_create(keyword, __LOCATION__, &
519 : name="_SECTION_PARAMETERS_", &
520 : description="Controls the activation of the mixing procedure", &
521 : usage="&MIXING ON", &
522 : default_l_val=.TRUE., &
523 79296 : lone_keyword_l_val=.TRUE.)
524 79296 : CALL section_add_keyword(section, keyword)
525 79296 : CALL keyword_release(keyword)
526 :
527 79296 : IF (.NOT. ls) THEN
528 69018 : default_mix = direct_p_mix
529 : ELSE
530 10278 : default_mix = broy_mix
531 : END IF
532 :
533 : CALL keyword_create(keyword, __LOCATION__, &
534 : name="METHOD", &
535 : description="Mixing method to be applied", &
536 : repeats=.FALSE., &
537 : usage="METHOD KERKER_MIXING", &
538 : default_i_val=default_mix, &
539 : enum_c_vals=s2a("NONE", &
540 : "DIRECT_P_MIXING", &
541 : "KERKER_MIXING", &
542 : "PULAY_MIXING", &
543 : "BROYDEN_MIXING", &
544 : "MODIFIED_BROYDEN_MIXING", &
545 : "MULTISECANT_MIXING"), &
546 : enum_i_vals=[no_mix, direct_p_mix, kerker_mix, pulay_mix, broy_mix, &
547 : modified_broy_mix, &
548 : multisec_mix], &
549 : enum_desc=s2a("No mixing is applied", &
550 : "Direct mixing of new and old density matrices", &
551 : "Mixing of the potential in reciprocal space using the Kerker damping", &
552 : "Pulay mixing", &
553 : "Original CP2K Broyden mixing with a constant BROY_W0 regularization", &
554 : "Modified Broyden mixing with dynamic residual weights controlled by BROY_W0, "// &
555 : "BROY_WREF, and BROY_WMAX", &
556 79296 : "Multisecant scheme for mixing"))
557 :
558 79296 : CALL section_add_keyword(section, keyword)
559 79296 : CALL keyword_release(keyword)
560 :
561 : CALL keyword_create(keyword, __LOCATION__, &
562 : name="ALPHA", &
563 : description="Fraction of new density to be included", &
564 : repeats=.FALSE., &
565 : n_var=1, &
566 : type_of_var=real_t, &
567 : default_r_val=0.4_dp, &
568 79296 : usage="ALPHA 0.2")
569 79296 : CALL section_add_keyword(section, keyword)
570 79296 : CALL keyword_release(keyword)
571 :
572 : CALL keyword_create(keyword, __LOCATION__, &
573 : name="ALPHA_MAG", &
574 : description="Fraction of new magnetization density to be included "// &
575 : "(for spin-polarized calculations, ispin=2 channel after rho_total/m transform). "// &
576 : "A negative value (default) means: use the same value as ALPHA. "// &
577 : "For magnetic transition-metal systems, a larger value (e.g. 0.8-1.6) "// &
578 : "than ALPHA often improves convergence.", &
579 : repeats=.FALSE., &
580 : n_var=1, &
581 : type_of_var=real_t, &
582 : default_r_val=-1.0_dp, &
583 79296 : usage="ALPHA_MAG 0.8")
584 79296 : CALL section_add_keyword(section, keyword)
585 79296 : CALL keyword_release(keyword)
586 :
587 : CALL keyword_create(keyword, __LOCATION__, &
588 : name="BETA", &
589 : description="Denominator parameter in Kerker damping "// &
590 : "introduced to suppress charge sloshing: "// &
591 : "rho_mix(g) = rho_in(g) + alpha*g^2/(g^2 + beta^2)*(rho_out(g)-rho_in(g))", &
592 : repeats=.FALSE., &
593 : n_var=1, &
594 : type_of_var=real_t, &
595 : default_r_val=0.5_dp, &
596 : unit_str="bohr^-1", &
597 79296 : usage="BETA 1.5")
598 79296 : CALL section_add_keyword(section, keyword)
599 79296 : CALL keyword_release(keyword)
600 :
601 : CALL keyword_create(keyword, __LOCATION__, &
602 : name="BETA_MAG", &
603 : description="Kerker damping parameter for the magnetization channel "// &
604 : "(for spin-polarized calculations). A negative value (default) means: "// &
605 : "use the same value as BETA. Set to 0.0 to disable Kerker screening "// &
606 : "on the magnetization density, which avoids suppression of long-range "// &
607 : "magnetic order formation in transition-metal systems.", &
608 : repeats=.FALSE., &
609 : n_var=1, &
610 : type_of_var=real_t, &
611 : default_r_val=-1.0_dp, &
612 : unit_str="bohr^-1", &
613 79296 : usage="BETA_MAG 0.0")
614 79296 : CALL section_add_keyword(section, keyword)
615 79296 : CALL keyword_release(keyword)
616 :
617 : CALL keyword_create(keyword, __LOCATION__, &
618 : name="PULAY_ALPHA", &
619 : description="Fraction of new density to be added to the Pulay expansion", &
620 : repeats=.FALSE., &
621 : n_var=1, &
622 : type_of_var=real_t, &
623 : default_r_val=0.0_dp, &
624 79296 : usage="PULAY_ALPHA 0.2")
625 79296 : CALL section_add_keyword(section, keyword)
626 79296 : CALL keyword_release(keyword)
627 :
628 : CALL keyword_create(keyword, __LOCATION__, &
629 : name="PULAY_BETA", &
630 : description="Fraction of residual contribution to be added to Pulay expansion", &
631 : repeats=.FALSE., &
632 : n_var=1, &
633 : type_of_var=real_t, &
634 : default_r_val=1.0_dp, &
635 79296 : usage="PULAY_BETA 0.2")
636 79296 : CALL section_add_keyword(section, keyword)
637 79296 : CALL keyword_release(keyword)
638 :
639 : CALL keyword_create(keyword, __LOCATION__, name="NMIXING", &
640 : description="Minimal number of density mixing (should be greater than 0), "// &
641 : "before starting DIIS", &
642 79296 : usage="NMIXING 1", default_i_val=2)
643 79296 : CALL section_add_keyword(section, keyword)
644 79296 : CALL keyword_release(keyword)
645 :
646 : CALL keyword_create(keyword, __LOCATION__, name="NBUFFER", &
647 : variants=s2a("NPULAY", "NBROYDEN", "NMULTISECANT"), &
648 : description="Number of previous steps stored for the actual mixing scheme", &
649 79296 : usage="NBUFFER 2", default_i_val=4)
650 79296 : CALL section_add_keyword(section, keyword)
651 79296 : CALL keyword_release(keyword)
652 :
653 : CALL keyword_create(keyword, __LOCATION__, &
654 : name="BROY_W0", &
655 : description="Regularization weight used in Broyden mixing. For the original "// &
656 : "BROYDEN_MIXING method this is the constant diagonal regularization of the "// &
657 : "small Broyden system. For MODIFIED_BROYDEN_MIXING it is the corresponding "// &
658 : "diagonal regularization of the dynamically weighted Broyden system. "// &
659 : "The default follows tblite.", &
660 : repeats=.FALSE., &
661 : n_var=1, &
662 : type_of_var=real_t, &
663 : default_r_val=0.01_dp, &
664 79296 : usage="BROY_W0 0.03")
665 79296 : CALL section_add_keyword(section, keyword)
666 79296 : CALL keyword_release(keyword)
667 :
668 : CALL keyword_create(keyword, __LOCATION__, &
669 : name="BROY_WREF", &
670 : description="Reference factor for the dynamic residual weight. This keyword "// &
671 : "is only used by MODIFIED_BROYDEN_MIXING; the original BROYDEN_MIXING path "// &
672 : "is unchanged. The effective history weight is proportional to BROY_WREF "// &
673 : "divided by the residual norm, clipped to the interval [1, BROY_WMAX]. "// &
674 : "The default follows tblite.", &
675 : repeats=.FALSE., &
676 : n_var=1, &
677 : type_of_var=real_t, &
678 : default_r_val=0.01_dp, &
679 79296 : usage="BROY_WREF 0.01")
680 79296 : CALL section_add_keyword(section, keyword)
681 79296 : CALL keyword_release(keyword)
682 :
683 : CALL keyword_create(keyword, __LOCATION__, &
684 : name="BROY_WMAX", &
685 : description="Upper bound for the dynamic residual weight. This keyword is "// &
686 : "only used by MODIFIED_BROYDEN_MIXING; the original BROYDEN_MIXING path is "// &
687 : "unchanged. The lower bound is fixed to 1.0. The default follows tblite.", &
688 : repeats=.FALSE., &
689 : n_var=1, &
690 : type_of_var=real_t, &
691 : default_r_val=100000.0_dp, &
692 79296 : usage="BROY_WMAX 100000.0")
693 79296 : CALL section_add_keyword(section, keyword)
694 79296 : CALL keyword_release(keyword)
695 :
696 : CALL keyword_create(keyword, __LOCATION__, &
697 : name="REGULARIZATION", &
698 : description="Regularization parameter to stabilize "// &
699 : "the inversion of the residual matrix {Yn^t Yn} in the "// &
700 : "multisecant mixing scheme (noise)", &
701 : repeats=.FALSE., &
702 : n_var=1, &
703 : type_of_var=real_t, &
704 : default_r_val=0.00001_dp, &
705 79296 : usage="REGULARIZATION 0.000001")
706 79296 : CALL section_add_keyword(section, keyword)
707 79296 : CALL keyword_release(keyword)
708 :
709 : CALL keyword_create(keyword, __LOCATION__, &
710 : name="MAX_STEP", &
711 : description="Upper bound for the magnitude of the "// &
712 : "unpredicted step size in the update by the "// &
713 : "multisecant mixing scheme", &
714 : repeats=.FALSE., &
715 : n_var=1, &
716 : type_of_var=real_t, &
717 : default_r_val=0.1_dp, &
718 79296 : usage="MAX_STEP .2")
719 79296 : CALL section_add_keyword(section, keyword)
720 79296 : CALL keyword_release(keyword)
721 :
722 : CALL keyword_create(keyword, __LOCATION__, &
723 : name="R_FACTOR", &
724 : description="Control factor for the magnitude of the "// &
725 : "unpredicted step size in the update by the "// &
726 : "multisecant mixing scheme", &
727 : repeats=.FALSE., &
728 : n_var=1, &
729 : type_of_var=real_t, &
730 : default_r_val=0.05_dp, &
731 79296 : usage="R_FACTOR .12")
732 79296 : CALL section_add_keyword(section, keyword)
733 79296 : CALL keyword_release(keyword)
734 :
735 : CALL keyword_create(keyword, __LOCATION__, name="NSKIP", &
736 : variants=["NSKIP_MIXING"], &
737 : description="Number of initial iteration for which the mixing is skipped", &
738 158592 : usage="NSKIP 10", default_i_val=0)
739 79296 : CALL section_add_keyword(section, keyword)
740 79296 : CALL keyword_release(keyword)
741 :
742 : CALL keyword_create(keyword, __LOCATION__, name="N_SIMPLE_MIX", &
743 : variants=["NSIMPLEMIX"], &
744 : description="Number of kerker damping iterations before starting other mixing procedures", &
745 158592 : usage="NSIMPLEMIX", default_i_val=0)
746 79296 : CALL section_add_keyword(section, keyword)
747 79296 : CALL keyword_release(keyword)
748 :
749 : CALL keyword_create(keyword, __LOCATION__, name="MAX_GVEC_EXP", &
750 : description="Restricts the G-space mixing to lower part of G-vector spectrum,"// &
751 : " up to a G0, by assigning the exponent of the Gaussian that can be "// &
752 : "represented by vectors smaller than G0 within a certain accuracy. ", &
753 : repeats=.FALSE., &
754 : n_var=1, &
755 : type_of_var=real_t, &
756 : default_r_val=-1._dp, &
757 79296 : usage="MAX_GVEC_EXP 3.")
758 79296 : CALL section_add_keyword(section, keyword)
759 79296 : CALL keyword_release(keyword)
760 :
761 : CALL keyword_create(keyword, __LOCATION__, name="GMIX_P", &
762 : description="Activate the mixing of the density matrix, using the same"// &
763 : " mixing coefficient applied for the g-space mixing.", &
764 : repeats=.FALSE., &
765 : lone_keyword_l_val=.TRUE., &
766 : default_l_val=.FALSE., &
767 79296 : usage="GMIX_P")
768 79296 : CALL section_add_keyword(section, keyword)
769 79296 : CALL keyword_release(keyword)
770 :
771 79296 : END SUBROUTINE create_mixing_section
772 :
773 0 : END MODULE qs_density_mixing_types
|