(git:d43dca4)
Loading...
Searching...
No Matches
qs_density_mixing_types.F
Go to the documentation of this file.
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! **************************************************************************************************
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, &
21 gaussian, &
22 kerker_mix, &
25 no_mix, &
35 USE input_val_types, ONLY: real_t
36 USE kinds, ONLY: default_string_length, &
37 dp
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, &
55
57 COMPLEX(dp), DIMENSION(:), POINTER :: cc => null()
58 END TYPE cp_1d_z_p_type
59
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
108CONTAINS
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 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 mixing_store%nbuffer = 0
129 mixing_store%n_simple_mix = 0
130 mixing_store%ncall = 0
131 mixing_store%ncall_p = 0
132 mixing_store%alpha = 1.0_dp
133 mixing_store%pulay_beta = 1.0_dp
134 mixing_store%beta = 1.0_dp
135 mixing_store%alpha_mag = -1.0_dp
136 mixing_store%beta_mag = -1.0_dp
137 mixing_store%iter_method = "NoMix"
138 mixing_store%max_g2 = 2._dp*ecut
139 mixing_store%gmix_p = .false.
140 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 NULLIFY (mixing_store%p_metric)
147 NULLIFY (mixing_store%kerker_factor)
148 NULLIFY (mixing_store%kerker_factor_mag)
149 NULLIFY (mixing_store%special_metric)
150 NULLIFY (mixing_store%pulay_matrix)
151 NULLIFY (mixing_store%weight)
152 NULLIFY (mixing_store%fmat)
153 NULLIFY (mixing_store%gmat)
154 NULLIFY (mixing_store%smat)
155 NULLIFY (mixing_store%acharge)
156 NULLIFY (mixing_store%dacharge)
157 NULLIFY (mixing_store%dfbroy)
158 NULLIFY (mixing_store%ubroy)
159 NULLIFY (mixing_store%abroy)
160 NULLIFY (mixing_store%wbroy)
161 NULLIFY (mixing_store%atlist)
162 NULLIFY (mixing_store%last_res)
163 NULLIFY (mixing_store%rhoin)
164 NULLIFY (mixing_store%rhoin_old)
165 NULLIFY (mixing_store%delta_res)
166 NULLIFY (mixing_store%u_vec)
167 NULLIFY (mixing_store%z_vec)
168 NULLIFY (mixing_store%drho_buffer)
169 NULLIFY (mixing_store%rhoin_buffer)
170 NULLIFY (mixing_store%res_buffer)
171 NULLIFY (mixing_store%norm_res_buffer)
172 NULLIFY (mixing_store%ig_global_index)
173 NULLIFY (mixing_store%paw)
174 NULLIFY (mixing_store%cpc_h_in)
175 NULLIFY (mixing_store%cpc_s_in)
176 NULLIFY (mixing_store%cpc_h_old)
177 NULLIFY (mixing_store%cpc_s_old)
178 NULLIFY (mixing_store%dcpc_h_in)
179 NULLIFY (mixing_store%dcpc_s_in)
180 NULLIFY (mixing_store%cpc_h_lastres)
181 NULLIFY (mixing_store%cpc_s_lastres)
182 NULLIFY (mixing_store%cpc_h_in_buffer)
183 NULLIFY (mixing_store%cpc_s_in_buffer)
184 NULLIFY (mixing_store%cpc_h_res_buffer)
185 NULLIFY (mixing_store%cpc_s_res_buffer)
186
187 CALL section_vals_val_get(mixing_section, "ALPHA", r_val=mixing_store%alpha)
188 CALL section_vals_val_get(mixing_section, "BETA", r_val=mixing_store%beta)
189 CALL section_vals_val_get(mixing_section, "ALPHA_MAG", r_val=mixing_store%alpha_mag)
190 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 IF (mixing_store%alpha_mag < 0.0_dp) mixing_store%alpha_mag = mixing_store%alpha
193 IF (mixing_store%beta_mag < 0.0_dp) mixing_store%beta_mag = mixing_store%beta
194 CALL section_vals_val_get(mixing_section, "N_SIMPLE_MIX", i_val=mixing_store%n_simple_mix)
195 CALL section_vals_val_get(mixing_section, "NBUFFER", i_val=mixing_store%nbuffer)
196 CALL section_vals_val_get(mixing_section, "NSKIP", i_val=mixing_store%nskip_mixing)
197 CALL section_vals_val_get(mixing_section, "MAX_GVEC_EXP", r_val=mixing_store%max_gvec_exp)
198 CALL section_vals_val_get(mixing_section, "GMIX_P", l_val=mixing_store%gmix_p)
199
200 IF (mixing_store%max_gvec_exp > 0._dp) THEN
201 alpha = 0.25_dp/mixing_store%max_gvec_exp
202 eps = 1.e-4_dp
203 gcut = exp_radius(3, alpha, eps, 1.0_dp)
204 mixing_store%max_g2 = gcut*gcut
205 END IF
206
207 SELECT CASE (mixing_method)
208 CASE (gspace_mixing_nr)
209 mixing_store%nbuffer = 1
210 CASE (pulay_mixing_nr)
211 CALL section_vals_val_get(mixing_section, "PULAY_ALPHA", r_val=mixing_store%pulay_alpha)
212 CALL section_vals_val_get(mixing_section, "PULAY_BETA", r_val=mixing_store%pulay_beta)
213 CASE (broyden_mixing_nr)
214 CALL section_vals_val_get(mixing_section, "BROY_W0", r_val=mixing_store%broy_w0)
215 mixing_store%bconst = 20.0_dp
217 CALL section_vals_val_get(mixing_section, "BROY_W0", r_val=mixing_store%broy_w0)
218 CALL section_vals_val_get(mixing_section, "BROY_WREF", r_val=mixing_store%wc)
219 CALL section_vals_val_get(mixing_section, "BROY_WMAX", r_val=mixing_store%wmax)
220 mixing_store%bconst = 20.0_dp
222 CALL section_vals_val_get(mixing_section, "REGULARIZATION", r_val=mixing_store%reg_par)
223 CALL section_vals_val_get(mixing_section, "MAX_STEP", r_val=mixing_store%sigma_max)
224 CALL section_vals_val_get(mixing_section, "R_FACTOR", r_val=mixing_store%r_step)
225 END SELECT
226
227 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 SUBROUTINE mixing_storage_release(mixing_store)
237 TYPE(mixing_storage_type), INTENT(INOUT) :: mixing_store
238
239 INTEGER :: i, j, k
240
241 IF (ASSOCIATED(mixing_store%kerker_factor)) THEN
242 DEALLOCATE (mixing_store%kerker_factor)
243 END IF
244
245 IF (ASSOCIATED(mixing_store%kerker_factor_mag)) THEN
246 DEALLOCATE (mixing_store%kerker_factor_mag)
247 END IF
248
249 IF (ASSOCIATED(mixing_store%special_metric)) THEN
250 DEALLOCATE (mixing_store%special_metric)
251 END IF
252
253 IF (ASSOCIATED(mixing_store%pulay_matrix)) THEN
254 DEALLOCATE (mixing_store%pulay_matrix)
255 END IF
256
257 IF (ASSOCIATED(mixing_store%rhoin_buffer)) THEN
258 DO i = 1, SIZE(mixing_store%rhoin_buffer, 2)
259 DO j = 1, SIZE(mixing_store%rhoin_buffer, 1)
260 DEALLOCATE (mixing_store%rhoin_buffer(j, i)%cc)
261 END DO
262 END DO
263 DEALLOCATE (mixing_store%rhoin_buffer)
264 END IF
265
266 IF (ASSOCIATED(mixing_store%paw)) THEN
267 DEALLOCATE (mixing_store%paw)
268 END IF
269 IF (ASSOCIATED(mixing_store%cpc_h_in)) THEN
270 DO j = 1, SIZE(mixing_store%cpc_h_in, 2)
271 DO k = 1, SIZE(mixing_store%cpc_h_in, 1)
272 IF (ASSOCIATED(mixing_store%cpc_h_in(k, j)%r_coef)) THEN
273 DEALLOCATE (mixing_store%cpc_h_in(k, j)%r_coef)
274 DEALLOCATE (mixing_store%cpc_s_in(k, j)%r_coef)
275 END IF
276 END DO
277 END DO
278 DEALLOCATE (mixing_store%cpc_h_in)
279 DEALLOCATE (mixing_store%cpc_s_in)
280 END IF
281 IF (ASSOCIATED(mixing_store%cpc_h_old)) THEN
282 DO j = 1, SIZE(mixing_store%cpc_h_old, 2)
283 DO k = 1, SIZE(mixing_store%cpc_h_old, 1)
284 IF (ASSOCIATED(mixing_store%cpc_h_old(k, j)%r_coef)) THEN
285 DEALLOCATE (mixing_store%cpc_h_old(k, j)%r_coef)
286 DEALLOCATE (mixing_store%cpc_s_old(k, j)%r_coef)
287 END IF
288 END DO
289 END DO
290 DEALLOCATE (mixing_store%cpc_h_old)
291 DEALLOCATE (mixing_store%cpc_s_old)
292 END IF
293 IF (ASSOCIATED(mixing_store%cpc_h_in_buffer)) THEN
294 DO i = 1, SIZE(mixing_store%cpc_h_in_buffer, 3)
295 DO j = 1, SIZE(mixing_store%cpc_h_in_buffer, 2)
296 DO k = 1, SIZE(mixing_store%cpc_h_in_buffer, 1)
297 IF (ASSOCIATED(mixing_store%cpc_h_in_buffer(k, j, i)%r_coef)) THEN
298 DEALLOCATE (mixing_store%cpc_h_in_buffer(k, j, i)%r_coef)
299 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 DEALLOCATE (mixing_store%cpc_h_in_buffer)
305 DEALLOCATE (mixing_store%cpc_s_in_buffer)
306 END IF
307 IF (ASSOCIATED(mixing_store%cpc_h_res_buffer)) THEN
308 DO i = 1, SIZE(mixing_store%cpc_h_res_buffer, 3)
309 DO j = 1, SIZE(mixing_store%cpc_h_res_buffer, 2)
310 DO k = 1, SIZE(mixing_store%cpc_h_res_buffer, 1)
311 IF (ASSOCIATED(mixing_store%cpc_h_res_buffer(k, j, i)%r_coef)) THEN
312 DEALLOCATE (mixing_store%cpc_h_res_buffer(k, j, i)%r_coef)
313 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 DEALLOCATE (mixing_store%cpc_h_res_buffer)
319 DEALLOCATE (mixing_store%cpc_s_res_buffer)
320 END IF
321
322 IF (ASSOCIATED(mixing_store%dcpc_h_in)) THEN
323 DO i = 1, SIZE(mixing_store%dcpc_h_in, 3)
324 DO j = 1, SIZE(mixing_store%dcpc_h_in, 2)
325 DO k = 1, SIZE(mixing_store%dcpc_h_in, 1)
326 IF (ASSOCIATED(mixing_store%dcpc_h_in(k, j, i)%r_coef)) THEN
327 DEALLOCATE (mixing_store%dcpc_h_in(k, j, i)%r_coef)
328 DEALLOCATE (mixing_store%dcpc_s_in(k, j, i)%r_coef)
329 END IF
330 END DO
331 END DO
332 END DO
333 DEALLOCATE (mixing_store%dcpc_h_in)
334 DEALLOCATE (mixing_store%dcpc_s_in)
335 END IF
336 IF (ASSOCIATED(mixing_store%cpc_h_lastres)) THEN
337 DO j = 1, SIZE(mixing_store%cpc_h_lastres, 2)
338 DO k = 1, SIZE(mixing_store%cpc_h_lastres, 1)
339 IF (ASSOCIATED(mixing_store%cpc_h_lastres(k, j)%r_coef)) THEN
340 DEALLOCATE (mixing_store%cpc_h_lastres(k, j)%r_coef)
341 DEALLOCATE (mixing_store%cpc_s_lastres(k, j)%r_coef)
342 END IF
343 END DO
344 END DO
345 DEALLOCATE (mixing_store%cpc_h_lastres)
346 DEALLOCATE (mixing_store%cpc_s_lastres)
347 END IF
348
349 IF (ASSOCIATED(mixing_store%res_buffer)) THEN
350 DO i = 1, SIZE(mixing_store%res_buffer, 2)
351 DO j = 1, SIZE(mixing_store%res_buffer, 1)
352 DEALLOCATE (mixing_store%res_buffer(j, i)%cc)
353 END DO
354 END DO
355 DEALLOCATE (mixing_store%res_buffer)
356 END IF
357
358 IF (ASSOCIATED(mixing_store%norm_res_buffer)) THEN
359 DEALLOCATE (mixing_store%norm_res_buffer)
360 END IF
361
362 IF (ASSOCIATED(mixing_store%ig_global_index)) THEN
363 DEALLOCATE (mixing_store%ig_global_index)
364 END IF
365
366 IF (ASSOCIATED(mixing_store%drho_buffer)) THEN
367 DO i = 1, SIZE(mixing_store%drho_buffer, 2)
368 DO j = 1, SIZE(mixing_store%drho_buffer, 1)
369 DEALLOCATE (mixing_store%drho_buffer(j, i)%cc)
370 END DO
371 END DO
372 DEALLOCATE (mixing_store%drho_buffer)
373 END IF
374
375 IF (ASSOCIATED(mixing_store%last_res)) THEN
376 DO i = 1, SIZE(mixing_store%last_res)
377 DEALLOCATE (mixing_store%last_res(i)%cc)
378 END DO
379 DEALLOCATE (mixing_store%last_res)
380 END IF
381
382 IF (ASSOCIATED(mixing_store%rhoin)) THEN
383 DO i = 1, SIZE(mixing_store%rhoin)
384 DEALLOCATE (mixing_store%rhoin(i)%cc)
385 END DO
386 DEALLOCATE (mixing_store%rhoin)
387 END IF
388
389 IF (ASSOCIATED(mixing_store%rhoin_old)) THEN
390 DO i = 1, SIZE(mixing_store%rhoin_old)
391 DEALLOCATE (mixing_store%rhoin_old(i)%cc)
392 END DO
393 DEALLOCATE (mixing_store%rhoin_old)
394 END IF
395
396 IF (ASSOCIATED(mixing_store%p_metric)) THEN
397 DEALLOCATE (mixing_store%p_metric)
398 END IF
399
400 IF (ASSOCIATED(mixing_store%weight)) THEN
401 DEALLOCATE (mixing_store%weight)
402 END IF
403
404 IF (ASSOCIATED(mixing_store%fmat)) THEN
405 DEALLOCATE (mixing_store%fmat)
406 END IF
407
408 IF (ASSOCIATED(mixing_store%acharge)) THEN
409 DEALLOCATE (mixing_store%acharge)
410 END IF
411 IF (ASSOCIATED(mixing_store%dacharge)) THEN
412 DEALLOCATE (mixing_store%dacharge)
413 END IF
414 IF (ASSOCIATED(mixing_store%dfbroy)) THEN
415 DEALLOCATE (mixing_store%dfbroy)
416 END IF
417 IF (ASSOCIATED(mixing_store%ubroy)) THEN
418 DEALLOCATE (mixing_store%ubroy)
419 END IF
420 IF (ASSOCIATED(mixing_store%abroy)) THEN
421 DEALLOCATE (mixing_store%abroy)
422 END IF
423 IF (ASSOCIATED(mixing_store%wbroy)) THEN
424 DEALLOCATE (mixing_store%wbroy)
425 END IF
426 IF (ASSOCIATED(mixing_store%atlist)) THEN
427 DEALLOCATE (mixing_store%atlist)
428 END IF
429#if defined(__TBLITE)
430 IF (ALLOCATED(mixing_store%tb_scc_mixer)) THEN
431 DEALLOCATE (mixing_store%tb_scc_mixer)
432 END IF
433#endif
434
435 IF (ASSOCIATED(mixing_store%delta_res)) THEN
436 DO i = 1, SIZE(mixing_store%delta_res, 2)
437 DO j = 1, SIZE(mixing_store%delta_res, 1)
438 DEALLOCATE (mixing_store%delta_res(j, i)%cc)
439 END DO
440 END DO
441 DEALLOCATE (mixing_store%delta_res)
442 END IF
443
444 IF (ASSOCIATED(mixing_store%u_vec)) THEN
445 DO i = 1, SIZE(mixing_store%u_vec, 2)
446 DO j = 1, SIZE(mixing_store%u_vec, 1)
447 DEALLOCATE (mixing_store%u_vec(j, i)%cc)
448 END DO
449 END DO
450 DEALLOCATE (mixing_store%u_vec)
451 END IF
452
453 IF (ASSOCIATED(mixing_store%z_vec)) THEN
454 DO i = 1, SIZE(mixing_store%z_vec, 2)
455 DO j = 1, SIZE(mixing_store%z_vec, 1)
456 DEALLOCATE (mixing_store%z_vec(j, i)%cc)
457 END DO
458 END DO
459 DEALLOCATE (mixing_store%z_vec)
460 END IF
461
462 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 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 cpassert(.NOT. ASSOCIATED(section))
487
488 IF (PRESENT(ls_scf)) THEN
489 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 section_name = "RHO_MIXING"
500 ELSE
501 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 repeats=.false.)
515
516 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 lone_keyword_l_val=.true.)
524 CALL section_add_keyword(section, keyword)
525 CALL keyword_release(keyword)
526
527 IF (.NOT. ls) THEN
528 default_mix = direct_p_mix
529 ELSE
530 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"), &
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 "Multisecant scheme for mixing"))
557
558 CALL section_add_keyword(section, keyword)
559 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 usage="ALPHA 0.2")
569 CALL section_add_keyword(section, keyword)
570 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 usage="ALPHA_MAG 0.8")
584 CALL section_add_keyword(section, keyword)
585 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 usage="BETA 1.5")
598 CALL section_add_keyword(section, keyword)
599 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 usage="BETA_MAG 0.0")
614 CALL section_add_keyword(section, keyword)
615 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 usage="PULAY_ALPHA 0.2")
625 CALL section_add_keyword(section, keyword)
626 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 usage="PULAY_BETA 0.2")
636 CALL section_add_keyword(section, keyword)
637 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 usage="NMIXING 1", default_i_val=2)
643 CALL section_add_keyword(section, keyword)
644 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 usage="NBUFFER 2", default_i_val=4)
650 CALL section_add_keyword(section, keyword)
651 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 usage="BROY_W0 0.03")
665 CALL section_add_keyword(section, keyword)
666 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 usage="BROY_WREF 0.01")
680 CALL section_add_keyword(section, keyword)
681 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 usage="BROY_WMAX 100000.0")
693 CALL section_add_keyword(section, keyword)
694 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 usage="REGULARIZATION 0.000001")
706 CALL section_add_keyword(section, keyword)
707 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 usage="MAX_STEP .2")
719 CALL section_add_keyword(section, keyword)
720 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 usage="R_FACTOR .12")
732 CALL section_add_keyword(section, keyword)
733 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 usage="NSKIP 10", default_i_val=0)
739 CALL section_add_keyword(section, keyword)
740 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 usage="NSIMPLEMIX", default_i_val=0)
746 CALL section_add_keyword(section, keyword)
747 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 usage="MAX_GVEC_EXP 3.")
758 CALL section_add_keyword(section, keyword)
759 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 usage="GMIX_P")
768 CALL section_add_keyword(section, keyword)
769 CALL keyword_release(keyword)
770
771 END SUBROUTINE create_mixing_section
772
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius(l, alpha, threshold, prefactor, epsabs, epsrel, rlow)
The radius of a primitive Gaussian function for a given threshold is calculated. g(r) = prefactor*r**...
Definition ao_util.F:96
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public broy_mix
integer, parameter, public pulay_mix
integer, parameter, public direct_p_mix
integer, parameter, public modified_broy_mix
integer, parameter, public no_mix
integer, parameter, public kerker_mix
integer, parameter, public multisec_mix
integer, parameter, public gaussian
represents keywords in an input
subroutine, public keyword_release(keyword)
releases the given keyword (see doc/ReferenceCounting.html)
subroutine, public keyword_create(keyword, location, name, description, usage, type_of_var, n_var, repeats, variants, default_val, default_l_val, default_r_val, default_lc_val, default_c_val, default_i_val, default_l_vals, default_r_vals, default_c_vals, default_i_vals, lone_keyword_val, lone_keyword_l_val, lone_keyword_r_val, lone_keyword_c_val, lone_keyword_i_val, lone_keyword_l_vals, lone_keyword_r_vals, lone_keyword_c_vals, lone_keyword_i_vals, enum_c_vals, enum_i_vals, enum, enum_strict, enum_desc, unit_str, citations, deprecation_notice, removed)
creates a keyword object
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_create(section, location, name, description, n_keywords, n_subsections, repeats, citations, deprecation_notice)
creates a list of keywords
subroutine, public section_add_keyword(section, keyword)
adds a keyword to the given section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
a wrapper for basic fortran types.
integer, parameter, public real_t
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
module that contains the definitions of the scf types
integer, parameter, public broyden_mixing_nr
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage
integer, parameter, public modified_broyden_mixing_nr
integer, parameter, public no_mixing_nr
integer, parameter, public direct_mixing_nr
subroutine, public create_mixing_section(section, ls_scf)
Create CP2K input section for the mixing of the density matrix to be used only with diagonalization m...
integer, parameter, public multisecant_mixing_nr
integer, parameter, public pulay_mixing_nr
subroutine, public mixing_storage_create(mixing_store, mixing_section, mixing_method, ecut)
creates a mixing_storage
integer, parameter, public gspace_mixing_nr
Utilities for string manipulations.
represent a keyword in the input
represent a section of the input file