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