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