108 SUBROUTINE mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
110 INTEGER :: mixing_method
112 POINTER :: p_mix_new, p_delta
113 INTEGER,
INTENT(IN) :: nspins
116 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mixing_allocate'
118 INTEGER :: handle, i, ia, iat, ic, ikind, ispin, &
119 max_shell, na, natom, nbuffer, nel, &
121 LOGICAL :: charge_mixing
122 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
130 CALL timeset(routinen, handle)
132 NULLIFY (matrix_s, dft_control, sab_orb, refmatrix, rho_atom)
135 matrix_s_kp=matrix_s, &
136 dft_control=dft_control)
138 charge_mixing = dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb &
139 .OR. dft_control%qs_control%semi_empirical
140 refmatrix => matrix_s(1, 1)%matrix
141 nimg = dft_control%nimages
144 IF (
PRESENT(p_mix_new))
THEN
145 IF (.NOT.
ASSOCIATED(p_mix_new))
THEN
149 ALLOCATE (p_mix_new(i, ic)%matrix)
150 CALL dbcsr_create(matrix=p_mix_new(i, ic)%matrix, template=refmatrix, &
151 name=
"SCF DENSITY", matrix_type=dbcsr_type_symmetric)
153 CALL dbcsr_set(p_mix_new(i, ic)%matrix, 0.0_dp)
160 IF (
PRESENT(p_delta))
THEN
162 IF (.NOT.
ASSOCIATED(p_delta))
THEN
166 ALLOCATE (p_delta(i, ic)%matrix)
167 CALL dbcsr_create(matrix=p_delta(i, ic)%matrix, template=refmatrix, &
168 name=
"SCF DENSITY", matrix_type=dbcsr_type_symmetric)
170 CALL dbcsr_set(p_delta(i, ic)%matrix, 0.0_dp)
174 cpassert(
ASSOCIATED(mixing_store))
178 IF (charge_mixing)
THEN
181 cpassert(.NOT. mixing_store%gmix_p)
182 IF (dft_control%qs_control%dftb)
THEN
184 ELSEIF (dft_control%qs_control%xtb)
THEN
187 cpabort(
'UNKNOWN METHOD')
189 nbuffer = mixing_store%nbuffer
190 mixing_store%ncall = 0
191 CALL get_qs_env(qs_env, local_particles=distribution_1d)
192 nkind =
SIZE(distribution_1d%n_el)
193 na = sum(distribution_1d%n_el(:))
194 IF (
ASSOCIATED(mixing_store%atlist))
DEALLOCATE (mixing_store%atlist)
195 ALLOCATE (mixing_store%atlist(na))
196 mixing_store%nat_local = na
197 mixing_store%max_shell = max_shell
200 nel = distribution_1d%n_el(ikind)
203 mixing_store%atlist(ia) = distribution_1d%list(ikind)%array(iat)
206 IF (
ASSOCIATED(mixing_store%acharge))
DEALLOCATE (mixing_store%acharge)
207 ALLOCATE (mixing_store%acharge(na, max_shell, nbuffer))
208 IF (
ASSOCIATED(mixing_store%dacharge))
DEALLOCATE (mixing_store%dacharge)
209 ALLOCATE (mixing_store%dacharge(na, max_shell, nbuffer))
212 IF (
ASSOCIATED(mixing_store%pulay_matrix))
DEALLOCATE (mixing_store%pulay_matrix)
213 ALLOCATE (mixing_store%pulay_matrix(nbuffer, nbuffer, nspins))
214 mixing_store%pulay_matrix = 0.0_dp
216 IF (
ASSOCIATED(mixing_store%abroy))
DEALLOCATE (mixing_store%abroy)
217 ALLOCATE (mixing_store%abroy(nbuffer, nbuffer))
218 mixing_store%abroy = 0.0_dp
219 IF (
ASSOCIATED(mixing_store%wbroy))
DEALLOCATE (mixing_store%wbroy)
220 ALLOCATE (mixing_store%wbroy(nbuffer))
221 mixing_store%wbroy = 0.0_dp
222 IF (
ASSOCIATED(mixing_store%dfbroy))
DEALLOCATE (mixing_store%dfbroy)
223 ALLOCATE (mixing_store%dfbroy(na, max_shell, nbuffer))
224 mixing_store%dfbroy = 0.0_dp
225 IF (
ASSOCIATED(mixing_store%ubroy))
DEALLOCATE (mixing_store%ubroy)
226 ALLOCATE (mixing_store%ubroy(na, max_shell, nbuffer))
227 mixing_store%ubroy = 0.0_dp
229 cpabort(
"multisecant_mixing not available")
234 nbuffer = mixing_store%nbuffer
235 mixing_store%ncall = 0
236 IF (.NOT.
ASSOCIATED(mixing_store%rhoin))
THEN
237 ALLOCATE (mixing_store%rhoin(nspins))
239 NULLIFY (mixing_store%rhoin(ispin)%cc)
243 IF (mixing_store%gmix_p .AND. dft_control%qs_control%gapw)
THEN
244 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
245 natom =
SIZE(rho_atom)
246 IF (.NOT.
ASSOCIATED(mixing_store%paw))
THEN
247 ALLOCATE (mixing_store%paw(natom))
248 mixing_store%paw = .false.
249 ALLOCATE (mixing_store%cpc_h_in(natom, nspins))
250 ALLOCATE (mixing_store%cpc_s_in(natom, nspins))
253 NULLIFY (mixing_store%cpc_h_in(iat, ispin)%r_coef)
254 NULLIFY (mixing_store%cpc_s_in(iat, ispin)%r_coef)
263 IF (.NOT.
ASSOCIATED(mixing_store%res_buffer))
THEN
264 ALLOCATE (mixing_store%res_buffer(nbuffer, nspins))
267 NULLIFY (mixing_store%res_buffer(i, ispin)%cc)
275 IF (.NOT.
ASSOCIATED(mixing_store%pulay_matrix))
THEN
276 ALLOCATE (mixing_store%pulay_matrix(nbuffer, nbuffer, nspins))
279 IF (.NOT.
ASSOCIATED(mixing_store%rhoin_buffer))
THEN
280 ALLOCATE (mixing_store%rhoin_buffer(nbuffer, nspins))
283 NULLIFY (mixing_store%rhoin_buffer(i, ispin)%cc)
287 IF (mixing_store%gmix_p)
THEN
288 IF (dft_control%qs_control%gapw)
THEN
289 IF (.NOT.
ASSOCIATED(mixing_store%cpc_h_in_buffer))
THEN
290 ALLOCATE (mixing_store%cpc_h_in_buffer(nbuffer, natom, nspins))
291 ALLOCATE (mixing_store%cpc_s_in_buffer(nbuffer, natom, nspins))
292 ALLOCATE (mixing_store%cpc_h_res_buffer(nbuffer, natom, nspins))
293 ALLOCATE (mixing_store%cpc_s_res_buffer(nbuffer, natom, nspins))
297 NULLIFY (mixing_store%cpc_h_in_buffer(i, iat, ispin)%r_coef)
298 NULLIFY (mixing_store%cpc_s_in_buffer(i, iat, ispin)%r_coef)
299 NULLIFY (mixing_store%cpc_h_res_buffer(i, iat, ispin)%r_coef)
300 NULLIFY (mixing_store%cpc_s_res_buffer(i, iat, ispin)%r_coef)
311 IF (.NOT.
ASSOCIATED(mixing_store%rhoin_old))
THEN
312 ALLOCATE (mixing_store%rhoin_old(nspins))
314 NULLIFY (mixing_store%rhoin_old(ispin)%cc)
317 IF (.NOT.
ASSOCIATED(mixing_store%drho_buffer))
THEN
318 ALLOCATE (mixing_store%drho_buffer(nbuffer, nspins))
319 ALLOCATE (mixing_store%last_res(nspins))
322 NULLIFY (mixing_store%drho_buffer(i, ispin)%cc)
324 NULLIFY (mixing_store%last_res(ispin)%cc)
327 IF (mixing_store%gmix_p)
THEN
329 IF (dft_control%qs_control%gapw)
THEN
330 IF (.NOT.
ASSOCIATED(mixing_store%cpc_h_old))
THEN
331 ALLOCATE (mixing_store%cpc_h_old(natom, nspins))
332 ALLOCATE (mixing_store%cpc_s_old(natom, nspins))
335 NULLIFY (mixing_store%cpc_h_old(iat, ispin)%r_coef)
336 NULLIFY (mixing_store%cpc_s_old(iat, ispin)%r_coef)
340 IF (.NOT.
ASSOCIATED(mixing_store%dcpc_h_in))
THEN
341 ALLOCATE (mixing_store%dcpc_h_in(nbuffer, natom, nspins))
342 ALLOCATE (mixing_store%dcpc_s_in(nbuffer, natom, nspins))
343 ALLOCATE (mixing_store%cpc_h_lastres(natom, nspins))
344 ALLOCATE (mixing_store%cpc_s_lastres(natom, nspins))
348 NULLIFY (mixing_store%dcpc_h_in(i, iat, ispin)%r_coef)
349 NULLIFY (mixing_store%dcpc_s_in(i, iat, ispin)%r_coef)
351 NULLIFY (mixing_store%cpc_h_lastres(iat, ispin)%r_coef)
352 NULLIFY (mixing_store%cpc_s_lastres(iat, ispin)%r_coef)
362 IF (.NOT.
ASSOCIATED(mixing_store%norm_res_buffer))
THEN
363 ALLOCATE (mixing_store%norm_res_buffer(nbuffer, nspins))
368 IF (.NOT.
ASSOCIATED(mixing_store%rhoin_buffer))
THEN
369 ALLOCATE (mixing_store%rhoin_buffer(nbuffer, nspins))
372 NULLIFY (mixing_store%rhoin_buffer(i, ispin)%cc)
380 CALL timestop(handle)
395 SUBROUTINE mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom)
396 INTEGER,
INTENT(IN) :: mixing_method
403 CHARACTER(len=*),
PARAMETER :: routinen =
'mixing_init'
405 INTEGER :: handle, iat, ib, ig, ig1, ig_count, &
406 iproc, ispin, n1, n2, natom, nbuffer, &
408 REAL(
dp) :: bconst, beta, fdamp, g2max, g2min, kmin
409 REAL(
dp),
DIMENSION(:),
POINTER :: g2
410 REAL(
dp),
DIMENSION(:, :),
POINTER :: g_vec
411 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
414 CALL timeset(routinen, handle)
416 NULLIFY (g2, g_vec, rho_ao_kp, rho_g)
417 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp, rho_g=rho_g)
420 ng =
SIZE(rho_g(1)%pw_grid%gsq, 1)
421 nimg =
SIZE(rho_ao_kp, 2)
422 mixing_store%ig_max = ng
423 g2 => rho_g(1)%pw_grid%gsq
424 g_vec => rho_g(1)%pw_grid%g
426 IF (mixing_store%max_gvec_exp > 0._dp)
THEN
428 IF (g2(ig) > mixing_store%max_g2)
THEN
429 mixing_store%ig_max = ig
435 IF (.NOT.
ASSOCIATED(mixing_store%kerker_factor))
THEN
436 ALLOCATE (mixing_store%kerker_factor(ng))
438 IF (.NOT.
ASSOCIATED(mixing_store%special_metric))
THEN
439 ALLOCATE (mixing_store%special_metric(ng))
441 beta = mixing_store%beta
443 mixing_store%kerker_factor = 1.0_dp
444 mixing_store%special_metric = 1.0_dp
446 IF (rho_g(1)%pw_grid%have_g0) ig1 = 2
447 DO ig = ig1, mixing_store%ig_max
448 mixing_store%kerker_factor(ig) = max(g2(ig)/(g2(ig) + beta*beta), kmin)
449 mixing_store%special_metric(ig) = &
450 1.0_dp + 50.0_dp/8.0_dp*( &
451 1.0_dp + cos(g_vec(1, ig)) + cos(g_vec(2, ig)) + cos(g_vec(3, ig)) + &
452 cos(g_vec(1, ig))*cos(g_vec(2, ig)) + &
453 cos(g_vec(2, ig))*cos(g_vec(3, ig)) + &
454 cos(g_vec(1, ig))*cos(g_vec(3, ig)) + &
455 cos(g_vec(1, ig))*cos(g_vec(2, ig))*cos(g_vec(3, ig)))
458 nbuffer = mixing_store%nbuffer
460 IF (.NOT.
ASSOCIATED(mixing_store%rhoin(ispin)%cc))
THEN
461 ALLOCATE (mixing_store%rhoin(ispin)%cc(ng))
463 mixing_store%rhoin(ispin)%cc = rho_g(ispin)%array
465 IF (
ASSOCIATED(mixing_store%rhoin_buffer))
THEN
466 IF (.NOT.
ASSOCIATED(mixing_store%rhoin_buffer(1, ispin)%cc))
THEN
468 ALLOCATE (mixing_store%rhoin_buffer(ib, ispin)%cc(ng))
471 mixing_store%rhoin_buffer(1, ispin)%cc(1:ng) = &
472 rho_g(ispin)%array(1:ng)
474 IF (
ASSOCIATED(mixing_store%res_buffer))
THEN
475 IF (.NOT.
ASSOCIATED(mixing_store%res_buffer(1, ispin)%cc))
THEN
477 ALLOCATE (mixing_store%res_buffer(ib, ispin)%cc(ng))
484 mixing_store%rhoin(1)%cc = rho_g(1)%array + rho_g(2)%array
485 mixing_store%rhoin(2)%cc = rho_g(1)%array - rho_g(2)%array
486 IF (
ASSOCIATED(mixing_store%rhoin_buffer))
THEN
487 mixing_store%rhoin_buffer(1, 1)%cc = rho_g(1)%array + rho_g(2)%array
488 mixing_store%rhoin_buffer(1, 2)%cc = rho_g(1)%array - rho_g(2)%array
492 IF (mixing_store%gmix_p)
THEN
493 IF (
PRESENT(rho_atom))
THEN
494 natom =
SIZE(rho_atom)
497 IF (
ASSOCIATED(rho_atom(iat)%cpc_s(ispin)%r_coef))
THEN
498 mixing_store%paw(iat) = .true.
499 n1 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 1)
500 n2 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 2)
501 IF (
ASSOCIATED(mixing_store%cpc_s_in))
THEN
502 IF (.NOT.
ASSOCIATED(mixing_store%cpc_s_in(iat, ispin)%r_coef))
THEN
503 ALLOCATE (mixing_store%cpc_s_in(iat, ispin)%r_coef(n1, n2))
504 ALLOCATE (mixing_store%cpc_h_in(iat, ispin)%r_coef(n1, n2))
506 mixing_store%cpc_h_in(iat, ispin)%r_coef = rho_atom(iat)%cpc_h(ispin)%r_coef
507 mixing_store%cpc_s_in(iat, ispin)%r_coef = rho_atom(iat)%cpc_s(ispin)%r_coef
517 IF (mixing_store%gmix_p .AND.
PRESENT(rho_atom))
THEN
520 IF (mixing_store%paw(iat))
THEN
521 n1 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 1)
522 n2 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 2)
523 IF (.NOT.
ASSOCIATED(mixing_store%cpc_h_in_buffer(1, iat, ispin)%r_coef))
THEN
525 ALLOCATE (mixing_store%cpc_s_in_buffer(ib, iat, ispin)%r_coef(n1, n2))
526 ALLOCATE (mixing_store%cpc_h_in_buffer(ib, iat, ispin)%r_coef(n1, n2))
527 ALLOCATE (mixing_store%cpc_s_res_buffer(ib, iat, ispin)%r_coef(n1, n2))
528 ALLOCATE (mixing_store%cpc_h_res_buffer(ib, iat, ispin)%r_coef(n1, n2))
532 mixing_store%cpc_h_in_buffer(ib, iat, ispin)%r_coef = 0.0_dp
533 mixing_store%cpc_s_in_buffer(ib, iat, ispin)%r_coef = 0.0_dp
534 mixing_store%cpc_h_res_buffer(ib, iat, ispin)%r_coef = 0.0_dp
535 mixing_store%cpc_s_res_buffer(ib, iat, ispin)%r_coef = 0.0_dp
543 IF (.NOT.
ASSOCIATED(mixing_store%rhoin_old(ispin)%cc))
THEN
544 ALLOCATE (mixing_store%rhoin_old(ispin)%cc(ng))
546 IF (.NOT.
ASSOCIATED(mixing_store%drho_buffer(1, ispin)%cc))
THEN
548 ALLOCATE (mixing_store%drho_buffer(ib, ispin)%cc(ng))
550 ALLOCATE (mixing_store%last_res(ispin)%cc(ng))
553 mixing_store%drho_buffer(ib, ispin)%cc = cmplx(0.0_dp, 0.0_dp, kind=
dp)
555 mixing_store%last_res(ispin)%cc = cmplx(0.0_dp, 0.0_dp, kind=
dp)
556 mixing_store%rhoin_old(ispin)%cc = cmplx(0.0_dp, 0.0_dp, kind=
dp)
558 IF (mixing_store%gmix_p)
THEN
559 IF (
PRESENT(rho_atom))
THEN
562 IF (mixing_store%paw(iat))
THEN
563 n1 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 1)
564 n2 =
SIZE(rho_atom(iat)%cpc_s(ispin)%r_coef, 2)
565 IF (.NOT.
ASSOCIATED(mixing_store%cpc_s_old(iat, ispin)%r_coef))
THEN
566 ALLOCATE (mixing_store%cpc_s_old(iat, ispin)%r_coef(n1, n2))
567 ALLOCATE (mixing_store%cpc_h_old(iat, ispin)%r_coef(n1, n2))
569 mixing_store%cpc_h_old(iat, ispin)%r_coef = 0.0_dp
570 mixing_store%cpc_s_old(iat, ispin)%r_coef = 0.0_dp
571 IF (.NOT.
ASSOCIATED(mixing_store%dcpc_s_in(1, iat, ispin)%r_coef))
THEN
573 ALLOCATE (mixing_store%dcpc_h_in(ib, iat, ispin)%r_coef(n1, n2))
574 ALLOCATE (mixing_store%dcpc_s_in(ib, iat, ispin)%r_coef(n1, n2))
576 ALLOCATE (mixing_store%cpc_h_lastres(iat, ispin)%r_coef(n1, n2))
577 ALLOCATE (mixing_store%cpc_s_lastres(iat, ispin)%r_coef(n1, n2))
580 mixing_store%dcpc_h_in(ib, iat, ispin)%r_coef = 0.0_dp
581 mixing_store%dcpc_s_in(ib, iat, ispin)%r_coef = 0.0_dp
583 mixing_store%cpc_h_lastres(iat, ispin)%r_coef = 0.0_dp
584 mixing_store%cpc_s_lastres(iat, ispin)%r_coef = 0.0_dp
591 IF (.NOT.
ASSOCIATED(mixing_store%p_metric))
THEN
592 ALLOCATE (mixing_store%p_metric(ng))
593 bconst = mixing_store%bconst
596 IF (g2(ig) > 1.e-10_dp) g2min = min(g2min, g2(ig))
600 g2max = max(g2max, g2(ig))
602 CALL para_env%min(g2min)
603 CALL para_env%max(g2max)
607 fdamp = (bconst - 1.0_dp)*g2min*g2max/(g2max - g2min*bconst)
609 mixing_store%p_metric(ig) = (g2(ig) + fdamp)/max(g2(ig), 1.e-10_dp)
611 IF (rho_g(1)%pw_grid%have_g0) mixing_store%p_metric(1) = bconst
614 IF (.NOT.
ASSOCIATED(mixing_store%ig_global_index))
THEN
615 ALLOCATE (mixing_store%ig_global_index(ng))
617 mixing_store%ig_global_index = 0
619 DO iproc = 0, para_env%num_pe - 1
620 IF (para_env%mepos == iproc)
THEN
622 ig_count = ig_count + 1
623 mixing_store%ig_global_index(ig) = ig_count
626 CALL para_env%bcast(ig_count, iproc)
630 CALL timestop(handle)
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.