59 INTEGER :: ig_max = -1, ncall = -1, ncall_p(2) = -1, nbuffer = -1, n_simple_mix = -1, &
60 nskip_mixing = -1, p_metric_method = -1
61 INTEGER,
POINTER,
DIMENSION(:) :: ig_global_index => null()
62 LOGICAL :: gmix_p = .false.
63 LOGICAL,
POINTER,
DIMENSION(:) :: paw => null()
64 CHARACTER(len=15) :: iter_method =
""
65 REAL(kind=
dp) :: alpha = -1.0_dp, bconst = -1.0_dp, beta = -1.0_dp, broy_w0 = -1.0_dp, &
66 max_g2 = -1.0_dp, max_gvec_exp = -1.0_dp, pulay_alpha = -1.0_dp, &
67 pulay_beta = -1.0_dp, r_step = -1.0_dp, reg_par = -1.0_dp, &
68 sigma_max = -1.0_dp, wc = -1.0_dp, wmax = -1.0_dp
70 REAL(kind=
dp) :: alpha_mag = -1.0_dp, beta_mag = -1.0_dp
71 REAL(kind=
dp),
DIMENSION(:),
POINTER :: p_metric => null()
72 REAL(kind=
dp),
DIMENSION(:),
POINTER :: kerker_factor => null()
73 REAL(kind=
dp),
DIMENSION(:),
POINTER :: kerker_factor_mag => null()
74 REAL(kind=
dp),
DIMENSION(:),
POINTER :: special_metric => null()
75 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: weight => null()
76 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: norm_res_buffer => null()
77 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: fmat => null(), gmat => null(), pulay_matrix => null(), smat => null()
79 INTEGER :: nat_local = -1, max_shell = -1
80 INTEGER :: tb_scc_mixer_memory = 0, tb_scc_mixer_natom = 0, &
81 tb_scc_mixer_ns = 0, tb_scc_mixer_step = 0
82 REAL(kind=
dp) :: tb_scc_mixer_error = 0.0_dp
83 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: acharge => null()
84 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dacharge => null()
85 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dfbroy => null()
86 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: ubroy => null()
87 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: abroy => null()
88 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wbroy => null()
89 INTEGER,
DIMENSION(:),
POINTER :: atlist => null()
91 TYPE(
cp_1d_z_p_type),
DIMENSION(:),
POINTER :: last_res => null(), rhoin => null(), rhoin_old => null()
92 TYPE(
cp_1d_z_p_type),
DIMENSION(:, :),
POINTER :: delta_res => null(), u_vec => null(), z_vec => null()
93 TYPE(
cp_1d_z_p_type),
DIMENSION(:, :),
POINTER :: drho_buffer => null(), rhoin_buffer => null(), res_buffer => null()
95 TYPE(
rho_atom_coeff),
DIMENSION(:, :),
POINTER :: cpc_h_lastres => null(), cpc_s_lastres => null()
96 TYPE(
rho_atom_coeff),
DIMENSION(:, :),
POINTER :: cpc_h_in => null(), cpc_s_in => null()
97 TYPE(
rho_atom_coeff),
DIMENSION(:, :),
POINTER :: cpc_h_old => null(), cpc_s_old => null()
98 TYPE(
rho_atom_coeff),
DIMENSION(:, :, :),
POINTER :: cpc_h_in_buffer => null(), cpc_s_in_buffer => null()
99 TYPE(
rho_atom_coeff),
DIMENSION(:, :, :),
POINTER :: cpc_h_res_buffer => null(), cpc_s_res_buffer => null()
100 TYPE(
rho_atom_coeff),
DIMENSION(:, :, :),
POINTER :: dcpc_h_in => null(), dcpc_s_in => null()
102 CLASS(mixer_type),
ALLOCATABLE :: tb_scc_mixer
121 INTEGER,
INTENT(IN) :: mixing_method
122 REAL(
dp),
INTENT(IN) :: ecut
124 REAL(
dp) :: alpha, eps, gcut
126 mixing_store%nbuffer = 0
127 mixing_store%n_simple_mix = 0
128 mixing_store%ncall = 0
129 mixing_store%ncall_p = 0
130 mixing_store%alpha = 1.0_dp
131 mixing_store%pulay_beta = 1.0_dp
132 mixing_store%beta = 1.0_dp
133 mixing_store%alpha_mag = -1.0_dp
134 mixing_store%beta_mag = -1.0_dp
135 mixing_store%iter_method =
"NoMix"
136 mixing_store%max_g2 = 2._dp*ecut
137 mixing_store%gmix_p = .false.
138 mixing_store%tb_scc_mixer_error = 0.0_dp
139 mixing_store%tb_scc_mixer_memory = 0
140 mixing_store%tb_scc_mixer_natom = 0
141 mixing_store%tb_scc_mixer_ns = 0
142 mixing_store%tb_scc_mixer_step = 0
144 NULLIFY (mixing_store%p_metric)
145 NULLIFY (mixing_store%kerker_factor)
146 NULLIFY (mixing_store%kerker_factor_mag)
147 NULLIFY (mixing_store%special_metric)
148 NULLIFY (mixing_store%pulay_matrix)
149 NULLIFY (mixing_store%weight)
150 NULLIFY (mixing_store%fmat)
151 NULLIFY (mixing_store%gmat)
152 NULLIFY (mixing_store%smat)
153 NULLIFY (mixing_store%acharge)
154 NULLIFY (mixing_store%dacharge)
155 NULLIFY (mixing_store%dfbroy)
156 NULLIFY (mixing_store%ubroy)
157 NULLIFY (mixing_store%abroy)
158 NULLIFY (mixing_store%wbroy)
159 NULLIFY (mixing_store%atlist)
160 NULLIFY (mixing_store%last_res)
161 NULLIFY (mixing_store%rhoin)
162 NULLIFY (mixing_store%rhoin_old)
163 NULLIFY (mixing_store%delta_res)
164 NULLIFY (mixing_store%u_vec)
165 NULLIFY (mixing_store%z_vec)
166 NULLIFY (mixing_store%drho_buffer)
167 NULLIFY (mixing_store%rhoin_buffer)
168 NULLIFY (mixing_store%res_buffer)
169 NULLIFY (mixing_store%norm_res_buffer)
170 NULLIFY (mixing_store%ig_global_index)
171 NULLIFY (mixing_store%paw)
172 NULLIFY (mixing_store%cpc_h_in)
173 NULLIFY (mixing_store%cpc_s_in)
174 NULLIFY (mixing_store%cpc_h_old)
175 NULLIFY (mixing_store%cpc_s_old)
176 NULLIFY (mixing_store%dcpc_h_in)
177 NULLIFY (mixing_store%dcpc_s_in)
178 NULLIFY (mixing_store%cpc_h_lastres)
179 NULLIFY (mixing_store%cpc_s_lastres)
180 NULLIFY (mixing_store%cpc_h_in_buffer)
181 NULLIFY (mixing_store%cpc_s_in_buffer)
182 NULLIFY (mixing_store%cpc_h_res_buffer)
183 NULLIFY (mixing_store%cpc_s_res_buffer)
190 IF (mixing_store%alpha_mag < 0.0_dp) mixing_store%alpha_mag = mixing_store%alpha
191 IF (mixing_store%beta_mag < 0.0_dp) mixing_store%beta_mag = mixing_store%beta
198 IF (mixing_store%max_gvec_exp > 0._dp)
THEN
199 alpha = 0.25_dp/mixing_store%max_gvec_exp
202 mixing_store%max_g2 = gcut*gcut
205 SELECT CASE (mixing_method)
207 mixing_store%nbuffer = 1
213 mixing_store%bconst = 20.0_dp
234 IF (
ASSOCIATED(mixing_store%kerker_factor))
THEN
235 DEALLOCATE (mixing_store%kerker_factor)
238 IF (
ASSOCIATED(mixing_store%kerker_factor_mag))
THEN
239 DEALLOCATE (mixing_store%kerker_factor_mag)
242 IF (
ASSOCIATED(mixing_store%special_metric))
THEN
243 DEALLOCATE (mixing_store%special_metric)
246 IF (
ASSOCIATED(mixing_store%pulay_matrix))
THEN
247 DEALLOCATE (mixing_store%pulay_matrix)
250 IF (
ASSOCIATED(mixing_store%rhoin_buffer))
THEN
251 DO i = 1,
SIZE(mixing_store%rhoin_buffer, 2)
252 DO j = 1,
SIZE(mixing_store%rhoin_buffer, 1)
253 DEALLOCATE (mixing_store%rhoin_buffer(j, i)%cc)
256 DEALLOCATE (mixing_store%rhoin_buffer)
259 IF (
ASSOCIATED(mixing_store%paw))
THEN
260 DEALLOCATE (mixing_store%paw)
262 IF (
ASSOCIATED(mixing_store%cpc_h_in))
THEN
263 DO j = 1,
SIZE(mixing_store%cpc_h_in, 2)
264 DO k = 1,
SIZE(mixing_store%cpc_h_in, 1)
265 IF (
ASSOCIATED(mixing_store%cpc_h_in(k, j)%r_coef))
THEN
266 DEALLOCATE (mixing_store%cpc_h_in(k, j)%r_coef)
267 DEALLOCATE (mixing_store%cpc_s_in(k, j)%r_coef)
271 DEALLOCATE (mixing_store%cpc_h_in)
272 DEALLOCATE (mixing_store%cpc_s_in)
274 IF (
ASSOCIATED(mixing_store%cpc_h_old))
THEN
275 DO j = 1,
SIZE(mixing_store%cpc_h_old, 2)
276 DO k = 1,
SIZE(mixing_store%cpc_h_old, 1)
277 IF (
ASSOCIATED(mixing_store%cpc_h_old(k, j)%r_coef))
THEN
278 DEALLOCATE (mixing_store%cpc_h_old(k, j)%r_coef)
279 DEALLOCATE (mixing_store%cpc_s_old(k, j)%r_coef)
283 DEALLOCATE (mixing_store%cpc_h_old)
284 DEALLOCATE (mixing_store%cpc_s_old)
286 IF (
ASSOCIATED(mixing_store%cpc_h_in_buffer))
THEN
287 DO i = 1,
SIZE(mixing_store%cpc_h_in_buffer, 3)
288 DO j = 1,
SIZE(mixing_store%cpc_h_in_buffer, 2)
289 DO k = 1,
SIZE(mixing_store%cpc_h_in_buffer, 1)
290 IF (
ASSOCIATED(mixing_store%cpc_h_in_buffer(k, j, i)%r_coef))
THEN
291 DEALLOCATE (mixing_store%cpc_h_in_buffer(k, j, i)%r_coef)
292 DEALLOCATE (mixing_store%cpc_s_in_buffer(k, j, i)%r_coef)
297 DEALLOCATE (mixing_store%cpc_h_in_buffer)
298 DEALLOCATE (mixing_store%cpc_s_in_buffer)
300 IF (
ASSOCIATED(mixing_store%cpc_h_res_buffer))
THEN
301 DO i = 1,
SIZE(mixing_store%cpc_h_res_buffer, 3)
302 DO j = 1,
SIZE(mixing_store%cpc_h_res_buffer, 2)
303 DO k = 1,
SIZE(mixing_store%cpc_h_res_buffer, 1)
304 IF (
ASSOCIATED(mixing_store%cpc_h_res_buffer(k, j, i)%r_coef))
THEN
305 DEALLOCATE (mixing_store%cpc_h_res_buffer(k, j, i)%r_coef)
306 DEALLOCATE (mixing_store%cpc_s_res_buffer(k, j, i)%r_coef)
311 DEALLOCATE (mixing_store%cpc_h_res_buffer)
312 DEALLOCATE (mixing_store%cpc_s_res_buffer)
315 IF (
ASSOCIATED(mixing_store%dcpc_h_in))
THEN
316 DO i = 1,
SIZE(mixing_store%dcpc_h_in, 3)
317 DO j = 1,
SIZE(mixing_store%dcpc_h_in, 2)
318 DO k = 1,
SIZE(mixing_store%dcpc_h_in, 1)
319 IF (
ASSOCIATED(mixing_store%dcpc_h_in(k, j, i)%r_coef))
THEN
320 DEALLOCATE (mixing_store%dcpc_h_in(k, j, i)%r_coef)
321 DEALLOCATE (mixing_store%dcpc_s_in(k, j, i)%r_coef)
326 DEALLOCATE (mixing_store%dcpc_h_in)
327 DEALLOCATE (mixing_store%dcpc_s_in)
329 IF (
ASSOCIATED(mixing_store%cpc_h_lastres))
THEN
330 DO j = 1,
SIZE(mixing_store%cpc_h_lastres, 2)
331 DO k = 1,
SIZE(mixing_store%cpc_h_lastres, 1)
332 IF (
ASSOCIATED(mixing_store%cpc_h_lastres(k, j)%r_coef))
THEN
333 DEALLOCATE (mixing_store%cpc_h_lastres(k, j)%r_coef)
334 DEALLOCATE (mixing_store%cpc_s_lastres(k, j)%r_coef)
338 DEALLOCATE (mixing_store%cpc_h_lastres)
339 DEALLOCATE (mixing_store%cpc_s_lastres)
342 IF (
ASSOCIATED(mixing_store%res_buffer))
THEN
343 DO i = 1,
SIZE(mixing_store%res_buffer, 2)
344 DO j = 1,
SIZE(mixing_store%res_buffer, 1)
345 DEALLOCATE (mixing_store%res_buffer(j, i)%cc)
348 DEALLOCATE (mixing_store%res_buffer)
351 IF (
ASSOCIATED(mixing_store%norm_res_buffer))
THEN
352 DEALLOCATE (mixing_store%norm_res_buffer)
355 IF (
ASSOCIATED(mixing_store%ig_global_index))
THEN
356 DEALLOCATE (mixing_store%ig_global_index)
359 IF (
ASSOCIATED(mixing_store%drho_buffer))
THEN
360 DO i = 1,
SIZE(mixing_store%drho_buffer, 2)
361 DO j = 1,
SIZE(mixing_store%drho_buffer, 1)
362 DEALLOCATE (mixing_store%drho_buffer(j, i)%cc)
365 DEALLOCATE (mixing_store%drho_buffer)
368 IF (
ASSOCIATED(mixing_store%last_res))
THEN
369 DO i = 1,
SIZE(mixing_store%last_res)
370 DEALLOCATE (mixing_store%last_res(i)%cc)
372 DEALLOCATE (mixing_store%last_res)
375 IF (
ASSOCIATED(mixing_store%rhoin))
THEN
376 DO i = 1,
SIZE(mixing_store%rhoin)
377 DEALLOCATE (mixing_store%rhoin(i)%cc)
379 DEALLOCATE (mixing_store%rhoin)
382 IF (
ASSOCIATED(mixing_store%rhoin_old))
THEN
383 DO i = 1,
SIZE(mixing_store%rhoin_old)
384 DEALLOCATE (mixing_store%rhoin_old(i)%cc)
386 DEALLOCATE (mixing_store%rhoin_old)
389 IF (
ASSOCIATED(mixing_store%p_metric))
THEN
390 DEALLOCATE (mixing_store%p_metric)
393 IF (
ASSOCIATED(mixing_store%weight))
THEN
394 DEALLOCATE (mixing_store%weight)
397 IF (
ASSOCIATED(mixing_store%fmat))
THEN
398 DEALLOCATE (mixing_store%fmat)
401 IF (
ASSOCIATED(mixing_store%acharge))
THEN
402 DEALLOCATE (mixing_store%acharge)
404 IF (
ASSOCIATED(mixing_store%dacharge))
THEN
405 DEALLOCATE (mixing_store%dacharge)
407 IF (
ASSOCIATED(mixing_store%dfbroy))
THEN
408 DEALLOCATE (mixing_store%dfbroy)
410 IF (
ASSOCIATED(mixing_store%ubroy))
THEN
411 DEALLOCATE (mixing_store%ubroy)
413 IF (
ASSOCIATED(mixing_store%abroy))
THEN
414 DEALLOCATE (mixing_store%abroy)
416 IF (
ASSOCIATED(mixing_store%wbroy))
THEN
417 DEALLOCATE (mixing_store%wbroy)
419 IF (
ASSOCIATED(mixing_store%atlist))
THEN
420 DEALLOCATE (mixing_store%atlist)
423 IF (
ALLOCATED(mixing_store%tb_scc_mixer))
THEN
424 DEALLOCATE (mixing_store%tb_scc_mixer)
428 IF (
ASSOCIATED(mixing_store%delta_res))
THEN
429 DO i = 1,
SIZE(mixing_store%delta_res, 2)
430 DO j = 1,
SIZE(mixing_store%delta_res, 1)
431 DEALLOCATE (mixing_store%delta_res(j, i)%cc)
434 DEALLOCATE (mixing_store%delta_res)
437 IF (
ASSOCIATED(mixing_store%u_vec))
THEN
438 DO i = 1,
SIZE(mixing_store%u_vec, 2)
439 DO j = 1,
SIZE(mixing_store%u_vec, 1)
440 DEALLOCATE (mixing_store%u_vec(j, i)%cc)
443 DEALLOCATE (mixing_store%u_vec)
446 IF (
ASSOCIATED(mixing_store%z_vec))
THEN
447 DO i = 1,
SIZE(mixing_store%z_vec, 2)
448 DO j = 1,
SIZE(mixing_store%z_vec, 1)
449 DEALLOCATE (mixing_store%z_vec(j, i)%cc)
452 DEALLOCATE (mixing_store%z_vec)
472 LOGICAL,
INTENT(IN),
OPTIONAL :: ls_scf
474 CHARACTER(LEN=default_string_length) :: section_name
475 INTEGER :: default_mix
479 cpassert(.NOT.
ASSOCIATED(section))
481 IF (
PRESENT(ls_scf))
THEN
492 section_name =
"RHO_MIXING"
494 section_name =
"MIXING"
499 description=
"Define type and parameters for mixing "// &
500 "procedures to be applied to the density matrix. Normally, "// &
501 "only one type of mixing method should be accepted. The mixing "// &
502 "procedures activated by this section are only active for diagonalization "// &
503 "methods and linear scaling SCF, i.e. not with minimization methods based "// &
512 name=
"_SECTION_PARAMETERS_", &
513 description=
"Controls the activation of the mixing procedure", &
514 usage=
"&MIXING ON", &
515 default_l_val=.true., &
516 lone_keyword_l_val=.true.)
528 description=
"Mixing method to be applied", &
530 usage=
"METHOD KERKER_MIXING", &
531 default_i_val=default_mix, &
532 enum_c_vals=
s2a(
"NONE", &
537 "MULTISECANT_MIXING"), &
540 enum_desc=
s2a(
"No mixing is applied", &
541 "Direct mixing of new and old density matrices", &
542 "Mixing of the potential in reciprocal space using the Kerker damping", &
543 "Pulay mixing",
"Broyden mixing", &
544 "Multisecant scheme for mixing"))
551 description=
"Fraction of new density to be included", &
555 default_r_val=0.4_dp, &
562 description=
"Fraction of new magnetization density to be included "// &
563 "(for spin-polarized calculations, ispin=2 channel after rho_total/m transform). "// &
564 "A negative value (default) means: use the same value as ALPHA. "// &
565 "For magnetic transition-metal systems, a larger value (e.g. 0.8-1.6) "// &
566 "than ALPHA often improves convergence.", &
570 default_r_val=-1.0_dp, &
571 usage=
"ALPHA_MAG 0.8")
577 description=
"Denominator parameter in Kerker damping "// &
578 "introduced to suppress charge sloshing: "// &
579 "rho_mix(g) = rho_in(g) + alpha*g^2/(g^2 + beta^2)*(rho_out(g)-rho_in(g))", &
583 default_r_val=0.5_dp, &
584 unit_str=
"bohr^-1", &
591 description=
"Kerker damping parameter for the magnetization channel "// &
592 "(for spin-polarized calculations). A negative value (default) means: "// &
593 "use the same value as BETA. Set to 0.0 to disable Kerker screening "// &
594 "on the magnetization density, which avoids suppression of long-range "// &
595 "magnetic order formation in transition-metal systems.", &
599 default_r_val=-1.0_dp, &
600 unit_str=
"bohr^-1", &
601 usage=
"BETA_MAG 0.0")
606 name=
"PULAY_ALPHA", &
607 description=
"Fraction of new density to be added to the Pulay expansion", &
611 default_r_val=0.0_dp, &
612 usage=
"PULAY_ALPHA 0.2")
618 description=
"Fraction of residual contribution to be added to Pulay expansion", &
622 default_r_val=1.0_dp, &
623 usage=
"PULAY_BETA 0.2")
628 description=
"Minimal number of density mixing (should be greater than 0), "// &
629 "before starting DIIS", &
630 usage=
"NMIXING 1", default_i_val=2)
635 variants=
s2a(
"NPULAY",
"NBROYDEN",
"NMULTISECANT"), &
636 description=
"Number of previous steps stored for the actual mixing scheme", &
637 usage=
"NBUFFER 2", default_i_val=4)
643 description=
" w0 parameter used in Broyden mixing", &
647 default_r_val=0.01_dp, &
648 usage=
"BROY_W0 0.03")
658 default_r_val=100.0_dp, &
659 usage=
"BROY_WREF 0.2")
669 default_r_val=30.0_dp, &
670 usage=
"BROY_WMAX 10.0")
675 name=
"REGULARIZATION", &
676 description=
"Regularization parameter to stabilize "// &
677 "the inversion of the residual matrix {Yn^t Yn} in the "// &
678 "multisecant mixing scheme (noise)", &
682 default_r_val=0.00001_dp, &
683 usage=
"REGULARIZATION 0.000001")
689 description=
"Upper bound for the magnitude of the "// &
690 "unpredicted step size in the update by the "// &
691 "multisecant mixing scheme", &
695 default_r_val=0.1_dp, &
702 description=
"Control factor for the magnitude of the "// &
703 "unpredicted step size in the update by the "// &
704 "multisecant mixing scheme", &
708 default_r_val=0.05_dp, &
709 usage=
"R_FACTOR .12")
714 variants=[
"NSKIP_MIXING"], &
715 description=
"Number of initial iteration for which the mixing is skipped", &
716 usage=
"NSKIP 10", default_i_val=0)
721 variants=[
"NSIMPLEMIX"], &
722 description=
"Number of kerker damping iterations before starting other mixing procedures", &
723 usage=
"NSIMPLEMIX", default_i_val=0)
728 description=
"Restricts the G-space mixing to lower part of G-vector spectrum,"// &
729 " up to a G0, by assigning the exponent of the Gaussian that can be "// &
730 "represented by vectors smaller than G0 within a certain accuracy. ", &
734 default_r_val=-1._dp, &
735 usage=
"MAX_GVEC_EXP 3.")
740 description=
"Activate the mixing of the density matrix, using the same"// &
741 " mixing coefficient applied for the g-space mixing.", &
743 lone_keyword_l_val=.true., &
744 default_l_val=.false., &