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
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()
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()
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()
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()
104 CLASS(mixer_type),
ALLOCATABLE :: tb_scc_mixer
123 INTEGER,
INTENT(IN) :: mixing_method
124 REAL(
dp),
INTENT(IN) :: ecut
126 REAL(
dp) :: alpha, eps, gcut
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
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)
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
200 IF (mixing_store%max_gvec_exp > 0._dp)
THEN
201 alpha = 0.25_dp/mixing_store%max_gvec_exp
204 mixing_store%max_g2 = gcut*gcut
207 SELECT CASE (mixing_method)
209 mixing_store%nbuffer = 1
215 mixing_store%bconst = 20.0_dp
220 mixing_store%bconst = 20.0_dp
241 IF (
ASSOCIATED(mixing_store%kerker_factor))
THEN
242 DEALLOCATE (mixing_store%kerker_factor)
245 IF (
ASSOCIATED(mixing_store%kerker_factor_mag))
THEN
246 DEALLOCATE (mixing_store%kerker_factor_mag)
249 IF (
ASSOCIATED(mixing_store%special_metric))
THEN
250 DEALLOCATE (mixing_store%special_metric)
253 IF (
ASSOCIATED(mixing_store%pulay_matrix))
THEN
254 DEALLOCATE (mixing_store%pulay_matrix)
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)
263 DEALLOCATE (mixing_store%rhoin_buffer)
266 IF (
ASSOCIATED(mixing_store%paw))
THEN
267 DEALLOCATE (mixing_store%paw)
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)
278 DEALLOCATE (mixing_store%cpc_h_in)
279 DEALLOCATE (mixing_store%cpc_s_in)
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)
290 DEALLOCATE (mixing_store%cpc_h_old)
291 DEALLOCATE (mixing_store%cpc_s_old)
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)
304 DEALLOCATE (mixing_store%cpc_h_in_buffer)
305 DEALLOCATE (mixing_store%cpc_s_in_buffer)
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)
318 DEALLOCATE (mixing_store%cpc_h_res_buffer)
319 DEALLOCATE (mixing_store%cpc_s_res_buffer)
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)
333 DEALLOCATE (mixing_store%dcpc_h_in)
334 DEALLOCATE (mixing_store%dcpc_s_in)
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)
345 DEALLOCATE (mixing_store%cpc_h_lastres)
346 DEALLOCATE (mixing_store%cpc_s_lastres)
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)
355 DEALLOCATE (mixing_store%res_buffer)
358 IF (
ASSOCIATED(mixing_store%norm_res_buffer))
THEN
359 DEALLOCATE (mixing_store%norm_res_buffer)
362 IF (
ASSOCIATED(mixing_store%ig_global_index))
THEN
363 DEALLOCATE (mixing_store%ig_global_index)
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)
372 DEALLOCATE (mixing_store%drho_buffer)
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)
379 DEALLOCATE (mixing_store%last_res)
382 IF (
ASSOCIATED(mixing_store%rhoin))
THEN
383 DO i = 1,
SIZE(mixing_store%rhoin)
384 DEALLOCATE (mixing_store%rhoin(i)%cc)
386 DEALLOCATE (mixing_store%rhoin)
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)
393 DEALLOCATE (mixing_store%rhoin_old)
396 IF (
ASSOCIATED(mixing_store%p_metric))
THEN
397 DEALLOCATE (mixing_store%p_metric)
400 IF (
ASSOCIATED(mixing_store%weight))
THEN
401 DEALLOCATE (mixing_store%weight)
404 IF (
ASSOCIATED(mixing_store%fmat))
THEN
405 DEALLOCATE (mixing_store%fmat)
408 IF (
ASSOCIATED(mixing_store%acharge))
THEN
409 DEALLOCATE (mixing_store%acharge)
411 IF (
ASSOCIATED(mixing_store%dacharge))
THEN
412 DEALLOCATE (mixing_store%dacharge)
414 IF (
ASSOCIATED(mixing_store%dfbroy))
THEN
415 DEALLOCATE (mixing_store%dfbroy)
417 IF (
ASSOCIATED(mixing_store%ubroy))
THEN
418 DEALLOCATE (mixing_store%ubroy)
420 IF (
ASSOCIATED(mixing_store%abroy))
THEN
421 DEALLOCATE (mixing_store%abroy)
423 IF (
ASSOCIATED(mixing_store%wbroy))
THEN
424 DEALLOCATE (mixing_store%wbroy)
426 IF (
ASSOCIATED(mixing_store%atlist))
THEN
427 DEALLOCATE (mixing_store%atlist)
430 IF (
ALLOCATED(mixing_store%tb_scc_mixer))
THEN
431 DEALLOCATE (mixing_store%tb_scc_mixer)
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)
441 DEALLOCATE (mixing_store%delta_res)
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)
450 DEALLOCATE (mixing_store%u_vec)
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)
459 DEALLOCATE (mixing_store%z_vec)
479 LOGICAL,
INTENT(IN),
OPTIONAL :: ls_scf
481 CHARACTER(LEN=default_string_length) :: section_name
482 INTEGER :: default_mix
486 cpassert(.NOT.
ASSOCIATED(section))
488 IF (
PRESENT(ls_scf))
THEN
499 section_name =
"RHO_MIXING"
501 section_name =
"MIXING"
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 "// &
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.)
535 description=
"Mixing method to be applied", &
537 usage=
"METHOD KERKER_MIXING", &
538 default_i_val=default_mix, &
539 enum_c_vals=
s2a(
"NONE", &
544 "MODIFIED_BROYDEN_MIXING", &
545 "MULTISECANT_MIXING"), &
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", &
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"))
563 description=
"Fraction of new density to be included", &
567 default_r_val=0.4_dp, &
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.", &
582 default_r_val=-1.0_dp, &
583 usage=
"ALPHA_MAG 0.8")
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))", &
595 default_r_val=0.5_dp, &
596 unit_str=
"bohr^-1", &
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.", &
611 default_r_val=-1.0_dp, &
612 unit_str=
"bohr^-1", &
613 usage=
"BETA_MAG 0.0")
618 name=
"PULAY_ALPHA", &
619 description=
"Fraction of new density to be added to the Pulay expansion", &
623 default_r_val=0.0_dp, &
624 usage=
"PULAY_ALPHA 0.2")
630 description=
"Fraction of residual contribution to be added to Pulay expansion", &
634 default_r_val=1.0_dp, &
635 usage=
"PULAY_BETA 0.2")
640 description=
"Minimal number of density mixing (should be greater than 0), "// &
641 "before starting DIIS", &
642 usage=
"NMIXING 1", default_i_val=2)
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)
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.", &
663 default_r_val=0.01_dp, &
664 usage=
"BROY_W0 0.03")
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.", &
678 default_r_val=0.01_dp, &
679 usage=
"BROY_WREF 0.01")
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.", &
691 default_r_val=100000.0_dp, &
692 usage=
"BROY_WMAX 100000.0")
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)", &
704 default_r_val=0.00001_dp, &
705 usage=
"REGULARIZATION 0.000001")
711 description=
"Upper bound for the magnitude of the "// &
712 "unpredicted step size in the update by the "// &
713 "multisecant mixing scheme", &
717 default_r_val=0.1_dp, &
724 description=
"Control factor for the magnitude of the "// &
725 "unpredicted step size in the update by the "// &
726 "multisecant mixing scheme", &
730 default_r_val=0.05_dp, &
731 usage=
"R_FACTOR .12")
736 variants=[
"NSKIP_MIXING"], &
737 description=
"Number of initial iteration for which the mixing is skipped", &
738 usage=
"NSKIP 10", default_i_val=0)
743 variants=[
"NSIMPLEMIX"], &
744 description=
"Number of kerker damping iterations before starting other mixing procedures", &
745 usage=
"NSIMPLEMIX", default_i_val=0)
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. ", &
756 default_r_val=-1._dp, &
757 usage=
"MAX_GVEC_EXP 3.")
762 description=
"Activate the mixing of the density matrix, using the same"// &
763 " mixing coefficient applied for the g-space mixing.", &
765 lone_keyword_l_val=.true., &
766 default_l_val=.false., &