(git:9754b87)
Loading...
Searching...
No Matches
qs_mixing_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
11 USE cp_dbcsr_api, ONLY: dbcsr_create,&
13 dbcsr_set,&
15 dbcsr_type_symmetric
19 USE kinds, ONLY: dp
21 USE pw_types, ONLY: pw_c1d_gs_type
31 USE qs_rho_types, ONLY: qs_rho_get,&
33 USE qs_scf_methods, ONLY: cp_sm_mix
34#include "./base/base_uses.f90"
35
36 IMPLICIT NONE
37
38 PRIVATE
39
40 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_mixing_utils'
41
44
45CONTAINS
46
47! **************************************************************************************************
48!> \brief ...
49!> \param rho_ao ...
50!> \param p_delta ...
51!> \param para_env ...
52!> \param p_out ...
53!> \param delta ...
54! **************************************************************************************************
55 SUBROUTINE self_consistency_check(rho_ao, p_delta, para_env, p_out, delta)
56 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao, p_delta
57 TYPE(mp_para_env_type), POINTER :: para_env
58 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: p_out
59 REAL(kind=dp), INTENT(INOUT) :: delta
60
61 CHARACTER(len=*), PARAMETER :: routinen = 'self_consistency_check'
62
63 INTEGER :: handle, ic, ispin, nimg, nspins
64 REAL(kind=dp) :: tmp
65 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_q, p_in
66
67 CALL timeset(routinen, handle)
68
69 NULLIFY (matrix_q, p_in)
70
71 cpassert(ASSOCIATED(p_out))
72 NULLIFY (matrix_q, p_in)
73 p_in => rho_ao
74 matrix_q => p_delta
75 nspins = SIZE(p_in, 1)
76 nimg = SIZE(p_in, 2)
77
78 ! Compute the difference (p_out - p_in)and check convergence
79 delta = 0.0_dp
80 DO ispin = 1, nspins
81 DO ic = 1, nimg
82 CALL dbcsr_set(matrix_q(ispin, ic)%matrix, 0.0_dp)
83 CALL cp_sm_mix(m1=p_out(ispin, ic)%matrix, m2=p_in(ispin, ic)%matrix, &
84 p_mix=1.0_dp, delta=tmp, para_env=para_env, &
85 m3=matrix_q(ispin, ic)%matrix)
86 delta = max(tmp, delta)
87 END DO
88 END DO
89 CALL timestop(handle)
90
91 END SUBROUTINE self_consistency_check
92
93! **************************************************************************************************
94!> \brief allocation needed when density mixing is used
95!> \param qs_env ...
96!> \param mixing_method ...
97!> \param p_mix_new ...
98!> \param p_delta ...
99!> \param nspins ...
100!> \param mixing_store ...
101!> \par History
102!> 05.2009 created [MI]
103!> 08.2014 kpoints [JGH]
104!> 02.2015 changed input to make g-space mixing available in linear scaling SCF [Patrick Seewald]
105!> 02.2019 charge mixing [JGH]
106!> \author fawzi
107! **************************************************************************************************
108 SUBROUTINE mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
109 TYPE(qs_environment_type), POINTER :: qs_env
110 INTEGER :: mixing_method
111 TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, &
112 POINTER :: p_mix_new, p_delta
113 INTEGER, INTENT(IN) :: nspins
114 TYPE(mixing_storage_type), POINTER :: mixing_store
115
116 CHARACTER(LEN=*), PARAMETER :: routinen = 'mixing_allocate'
117
118 INTEGER :: handle, i, ia, iat, ic, ikind, ispin, &
119 max_shell, na, natom, nbuffer, nel, &
120 nimg, nkind
121 LOGICAL :: charge_mixing
122 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
123 TYPE(dbcsr_type), POINTER :: refmatrix
124 TYPE(dft_control_type), POINTER :: dft_control
125 TYPE(distribution_1d_type), POINTER :: distribution_1d
126 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
127 POINTER :: sab_orb
128 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom
129
130 CALL timeset(routinen, handle)
131
132 NULLIFY (matrix_s, dft_control, sab_orb, refmatrix, rho_atom)
133 CALL get_qs_env(qs_env, &
134 sab_orb=sab_orb, &
135 matrix_s_kp=matrix_s, &
136 dft_control=dft_control)
137
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
142
143 ! *** allocate p_mix_new ***
144 IF (PRESENT(p_mix_new)) THEN
145 IF (.NOT. ASSOCIATED(p_mix_new)) THEN
146 CALL dbcsr_allocate_matrix_set(p_mix_new, nspins, nimg)
147 DO i = 1, nspins
148 DO ic = 1, nimg
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)
152 CALL cp_dbcsr_alloc_block_from_nbl(p_mix_new(i, ic)%matrix, sab_orb)
153 CALL dbcsr_set(p_mix_new(i, ic)%matrix, 0.0_dp)
154 END DO
155 END DO
156 END IF
157 END IF
158
159 ! *** allocate p_delta ***
160 IF (PRESENT(p_delta)) THEN
161 IF (mixing_method >= gspace_mixing_nr) THEN
162 IF (.NOT. ASSOCIATED(p_delta)) THEN
163 CALL dbcsr_allocate_matrix_set(p_delta, nspins, nimg)
164 DO i = 1, nspins
165 DO ic = 1, nimg
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)
169 CALL cp_dbcsr_alloc_block_from_nbl(p_delta(i, ic)%matrix, sab_orb)
170 CALL dbcsr_set(p_delta(i, ic)%matrix, 0.0_dp)
171 END DO
172 END DO
173 END IF
174 cpassert(ASSOCIATED(mixing_store))
175 END IF
176 END IF
177
178 IF (charge_mixing) THEN
179 ! *** allocate buffer for charge mixing ***
180 IF (mixing_method >= gspace_mixing_nr) THEN
181 cpassert(.NOT. mixing_store%gmix_p)
182 IF (dft_control%qs_control%dftb) THEN
183 max_shell = 1
184 ELSEIF (dft_control%qs_control%xtb) THEN
185 max_shell = 5
186 ELSE
187 cpabort('UNKNOWN METHOD')
188 END IF
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
198 ia = 0
199 DO ikind = 1, nkind
200 nel = distribution_1d%n_el(ikind)
201 DO iat = 1, nel
202 ia = ia + 1
203 mixing_store%atlist(ia) = distribution_1d%list(ikind)%array(iat)
204 END DO
205 END DO
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))
210 END IF
211 IF (mixing_method == pulay_mixing_nr) THEN
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
215 ELSEIF (mixing_method == broyden_mixing_nr) THEN
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
228 ELSEIF (mixing_method == multisecant_mixing_nr) THEN
229 cpabort("multisecant_mixing not available")
230 END IF
231 ELSE
232 ! *** allocate buffer for gspace mixing ***
233 IF (mixing_method >= gspace_mixing_nr) THEN
234 nbuffer = mixing_store%nbuffer
235 mixing_store%ncall = 0
236 IF (.NOT. ASSOCIATED(mixing_store%rhoin)) THEN
237 ALLOCATE (mixing_store%rhoin(nspins))
238 DO ispin = 1, nspins
239 NULLIFY (mixing_store%rhoin(ispin)%cc)
240 END DO
241 END IF
242
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))
251 DO ispin = 1, nspins
252 DO iat = 1, natom
253 NULLIFY (mixing_store%cpc_h_in(iat, ispin)%r_coef)
254 NULLIFY (mixing_store%cpc_s_in(iat, ispin)%r_coef)
255 END DO
256 END DO
257 END IF
258 END IF
259 END IF
260
261 ! *** allocare res_buffer if needed
262 IF (mixing_method >= pulay_mixing_nr) THEN
263 IF (.NOT. ASSOCIATED(mixing_store%res_buffer)) THEN
264 ALLOCATE (mixing_store%res_buffer(nbuffer, nspins))
265 DO ispin = 1, nspins
266 DO i = 1, nbuffer
267 NULLIFY (mixing_store%res_buffer(i, ispin)%cc)
268 END DO
269 END DO
270 END IF
271 END IF
272
273 ! *** allocate pulay
274 IF (mixing_method == pulay_mixing_nr) THEN
275 IF (.NOT. ASSOCIATED(mixing_store%pulay_matrix)) THEN
276 ALLOCATE (mixing_store%pulay_matrix(nbuffer, nbuffer, nspins))
277 END IF
278
279 IF (.NOT. ASSOCIATED(mixing_store%rhoin_buffer)) THEN
280 ALLOCATE (mixing_store%rhoin_buffer(nbuffer, nspins))
281 DO ispin = 1, nspins
282 DO i = 1, nbuffer
283 NULLIFY (mixing_store%rhoin_buffer(i, ispin)%cc)
284 END DO
285 END DO
286 END IF
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))
294 DO ispin = 1, nspins
295 DO iat = 1, natom
296 DO i = 1, nbuffer
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)
301 END DO
302 END DO
303 END DO
304 END IF
305 END IF
306 END IF
307
308 END IF
309 ! *** allocate broyden buffer ***
310 IF (mixing_method == broyden_mixing_nr) THEN
311 IF (.NOT. ASSOCIATED(mixing_store%rhoin_old)) THEN
312 ALLOCATE (mixing_store%rhoin_old(nspins))
313 DO ispin = 1, nspins
314 NULLIFY (mixing_store%rhoin_old(ispin)%cc)
315 END DO
316 END IF
317 IF (.NOT. ASSOCIATED(mixing_store%drho_buffer)) THEN
318 ALLOCATE (mixing_store%drho_buffer(nbuffer, nspins))
319 ALLOCATE (mixing_store%last_res(nspins))
320 DO ispin = 1, nspins
321 DO i = 1, nbuffer
322 NULLIFY (mixing_store%drho_buffer(i, ispin)%cc)
323 END DO
324 NULLIFY (mixing_store%last_res(ispin)%cc)
325 END DO
326 END IF
327 IF (mixing_store%gmix_p) THEN
328
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))
333 DO ispin = 1, nspins
334 DO iat = 1, natom
335 NULLIFY (mixing_store%cpc_h_old(iat, ispin)%r_coef)
336 NULLIFY (mixing_store%cpc_s_old(iat, ispin)%r_coef)
337 END DO
338 END DO
339 END IF
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))
345 DO ispin = 1, nspins
346 DO iat = 1, natom
347 DO i = 1, nbuffer
348 NULLIFY (mixing_store%dcpc_h_in(i, iat, ispin)%r_coef)
349 NULLIFY (mixing_store%dcpc_s_in(i, iat, ispin)%r_coef)
350 END DO
351 NULLIFY (mixing_store%cpc_h_lastres(iat, ispin)%r_coef)
352 NULLIFY (mixing_store%cpc_s_lastres(iat, ispin)%r_coef)
353 END DO
354 END DO
355 END IF
356 END IF
357 END IF
358 END IF
359
360 ! *** allocate multisecant buffer ***
361 IF (mixing_method == multisecant_mixing_nr) THEN
362 IF (.NOT. ASSOCIATED(mixing_store%norm_res_buffer)) THEN
363 ALLOCATE (mixing_store%norm_res_buffer(nbuffer, nspins))
364 END IF
365 END IF
366
367 IF (mixing_method == multisecant_mixing_nr) THEN
368 IF (.NOT. ASSOCIATED(mixing_store%rhoin_buffer)) THEN
369 ALLOCATE (mixing_store%rhoin_buffer(nbuffer, nspins))
370 DO ispin = 1, nspins
371 DO i = 1, nbuffer
372 NULLIFY (mixing_store%rhoin_buffer(i, ispin)%cc)
373 END DO
374 END DO
375 END IF
376 END IF
377
378 END IF
379
380 CALL timestop(handle)
381
382 END SUBROUTINE mixing_allocate
383
384! **************************************************************************************************
385!> \brief initialiation needed when gspace mixing is used
386!> \param mixing_method ...
387!> \param rho ...
388!> \param mixing_store ...
389!> \param para_env ...
390!> \param rho_atom ...
391!> \par History
392!> 05.2009 created [MI]
393!> \author MI
394! **************************************************************************************************
395 SUBROUTINE mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom)
396 INTEGER, INTENT(IN) :: mixing_method
397 TYPE(qs_rho_type), POINTER :: rho
398 TYPE(mixing_storage_type), POINTER :: mixing_store
399 TYPE(mp_para_env_type), POINTER :: para_env
400 TYPE(rho_atom_type), DIMENSION(:), OPTIONAL, &
401 POINTER :: rho_atom
402
403 CHARACTER(len=*), PARAMETER :: routinen = 'mixing_init'
404
405 INTEGER :: handle, iat, ib, ig, ig1, ig_count, &
406 iproc, ispin, n1, n2, natom, nbuffer, &
407 ng, nimg, nspin
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
412 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
413
414 CALL timeset(routinen, handle)
415
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)
418
419 nspin = SIZE(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
425
426 IF (mixing_store%max_gvec_exp > 0._dp) THEN
427 DO ig = 1, ng
428 IF (g2(ig) > mixing_store%max_g2) THEN
429 mixing_store%ig_max = ig
430 EXIT
431 END IF
432 END DO
433 END IF
434
435 IF (.NOT. ASSOCIATED(mixing_store%kerker_factor)) THEN
436 ALLOCATE (mixing_store%kerker_factor(ng))
437 END IF
438 IF (.NOT. ASSOCIATED(mixing_store%special_metric)) THEN
439 ALLOCATE (mixing_store%special_metric(ng))
440 END IF
441 beta = mixing_store%beta
442 kmin = 0.1_dp
443 mixing_store%kerker_factor = 1.0_dp
444 mixing_store%special_metric = 1.0_dp
445 ig1 = 1
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)))
456 END DO
457
458 nbuffer = mixing_store%nbuffer
459 DO ispin = 1, nspin
460 IF (.NOT. ASSOCIATED(mixing_store%rhoin(ispin)%cc)) THEN
461 ALLOCATE (mixing_store%rhoin(ispin)%cc(ng))
462 END IF
463 mixing_store%rhoin(ispin)%cc = rho_g(ispin)%array
464
465 IF (ASSOCIATED(mixing_store%rhoin_buffer)) THEN
466 IF (.NOT. ASSOCIATED(mixing_store%rhoin_buffer(1, ispin)%cc)) THEN
467 DO ib = 1, nbuffer
468 ALLOCATE (mixing_store%rhoin_buffer(ib, ispin)%cc(ng))
469 END DO
470 END IF
471 mixing_store%rhoin_buffer(1, ispin)%cc(1:ng) = &
472 rho_g(ispin)%array(1:ng)
473 END IF
474 IF (ASSOCIATED(mixing_store%res_buffer)) THEN
475 IF (.NOT. ASSOCIATED(mixing_store%res_buffer(1, ispin)%cc)) THEN
476 DO ib = 1, nbuffer
477 ALLOCATE (mixing_store%res_buffer(ib, ispin)%cc(ng))
478 END DO
479 END IF
480 END IF
481 END DO
482
483 IF (nspin == 2) THEN
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
489 END IF
490 END IF
491
492 IF (mixing_store%gmix_p) THEN
493 IF (PRESENT(rho_atom)) THEN
494 natom = SIZE(rho_atom)
495 DO ispin = 1, nspin
496 DO iat = 1, natom
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))
505 END IF
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
508 END IF
509 END IF
510 END DO
511 END DO
512 END IF
513 END IF
514
515 IF (mixing_method == gspace_mixing_nr) THEN
516 ELSEIF (mixing_method == pulay_mixing_nr) THEN
517 IF (mixing_store%gmix_p .AND. PRESENT(rho_atom)) THEN
518 DO ispin = 1, nspin
519 DO iat = 1, natom
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
524 DO ib = 1, nbuffer
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))
529 END DO
530 END IF
531 DO ib = 1, nbuffer
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
536 END DO
537 END IF
538 END DO
539 END DO
540 END IF
541 ELSEIF (mixing_method == broyden_mixing_nr) THEN
542 DO ispin = 1, nspin
543 IF (.NOT. ASSOCIATED(mixing_store%rhoin_old(ispin)%cc)) THEN
544 ALLOCATE (mixing_store%rhoin_old(ispin)%cc(ng))
545 END IF
546 IF (.NOT. ASSOCIATED(mixing_store%drho_buffer(1, ispin)%cc)) THEN
547 DO ib = 1, nbuffer
548 ALLOCATE (mixing_store%drho_buffer(ib, ispin)%cc(ng))
549 END DO
550 ALLOCATE (mixing_store%last_res(ispin)%cc(ng))
551 END IF
552 DO ib = 1, nbuffer
553 mixing_store%drho_buffer(ib, ispin)%cc = cmplx(0.0_dp, 0.0_dp, kind=dp)
554 END DO
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)
557 END DO
558 IF (mixing_store%gmix_p) THEN
559 IF (PRESENT(rho_atom)) THEN
560 DO ispin = 1, nspin
561 DO iat = 1, natom
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))
568 END IF
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
572 DO ib = 1, nbuffer
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))
575 END DO
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))
578 END IF
579 DO ib = 1, nbuffer
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
582 END DO
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
585 END IF
586 END DO
587 END DO
588 END IF
589 END IF
590
591 IF (.NOT. ASSOCIATED(mixing_store%p_metric)) THEN
592 ALLOCATE (mixing_store%p_metric(ng))
593 bconst = mixing_store%bconst
594 g2min = 1.e30_dp
595 DO ig = 1, ng
596 IF (g2(ig) > 1.e-10_dp) g2min = min(g2min, g2(ig))
597 END DO
598 g2max = -1.e30_dp
599 DO ig = 1, ng
600 g2max = max(g2max, g2(ig))
601 END DO
602 CALL para_env%min(g2min)
603 CALL para_env%max(g2max)
604 ! fdamp/g2 varies between (bconst-1) and 0
605 ! i.e. p_metric varies between bconst and 1
606 ! fdamp = (bconst-1.0_dp)*g2min
607 fdamp = (bconst - 1.0_dp)*g2min*g2max/(g2max - g2min*bconst)
608 DO ig = 1, ng
609 mixing_store%p_metric(ig) = (g2(ig) + fdamp)/max(g2(ig), 1.e-10_dp)
610 END DO
611 IF (rho_g(1)%pw_grid%have_g0) mixing_store%p_metric(1) = bconst
612 END IF
613 ELSEIF (mixing_method == multisecant_mixing_nr) THEN
614 IF (.NOT. ASSOCIATED(mixing_store%ig_global_index)) THEN
615 ALLOCATE (mixing_store%ig_global_index(ng))
616 END IF
617 mixing_store%ig_global_index = 0
618 ig_count = 0
619 DO iproc = 0, para_env%num_pe - 1
620 IF (para_env%mepos == iproc) THEN
621 DO ig = 1, ng
622 ig_count = ig_count + 1
623 mixing_store%ig_global_index(ig) = ig_count
624 END DO
625 END IF
626 CALL para_env%bcast(ig_count, iproc)
627 END DO
628 END IF
629
630 CALL timestop(handle)
631
632 END SUBROUTINE mixing_init
633
634! **************************************************************************************************
635!> \brief initialiation needed when charge mixing is used
636!> \param mixing_store ...
637!> \par History
638!> 02.2019 created [JGH]
639!> \author JGH
640! **************************************************************************************************
641 ELEMENTAL SUBROUTINE charge_mixing_init(mixing_store)
642 TYPE(mixing_storage_type), INTENT(INOUT) :: mixing_store
643
644 mixing_store%acharge = 0.0_dp
645
646 END SUBROUTINE charge_mixing_init
647
648END MODULE qs_mixing_utils
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
module that contains the definitions of the scf types
integer, parameter, public broyden_mixing_nr
integer, parameter, public multisecant_mixing_nr
integer, parameter, public pulay_mixing_nr
integer, parameter, public gspace_mixing_nr
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.
elemental subroutine, public charge_mixing_init(mixing_store)
initialiation needed when charge mixing is used
subroutine, public mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom)
initialiation needed when gspace mixing is used
subroutine, public mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
allocation needed when density mixing is used
subroutine, public self_consistency_check(rho_ao, p_delta, para_env, p_out, delta)
...
Define the neighbor list data types and the corresponding functionality.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public cp_sm_mix(m1, m2, p_mix, delta, para_env, m3)
Perform a mixing of the given matrixes into the first matrix m1 = m2 + p_mix (m1-m2)
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
keeps the density in various representations, keeping track of which ones are valid.