(git:d18deda)
Loading...
Searching...
No Matches
qs_harris_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! **************************************************************************************************
9!> \brief Harris method environment setup and handling
10!> \par History
11!> 2024.07 created
12!> \author JGH
13! **************************************************************************************************
19 USE cell_types, ONLY: cell_type
21 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
31 USE ec_methods, ONLY: create_kernel
32 USE input_constants, ONLY: hden_atomic,&
38 USE kinds, ONLY: dp
41 USE pw_env_types, ONLY: pw_env_get,&
44 USE pw_methods, ONLY: pw_axpy,&
45 pw_copy,&
48 pw_scale,&
54 USE pw_types, ONLY: pw_c1d_gs_type,&
66 USE qs_integrate_potential, ONLY: integrate_function,&
67 integrate_v_core_rspace,&
68 integrate_v_rspace
69 USE qs_kind_types, ONLY: get_qs_kind,&
72 USE qs_rho_types, ONLY: qs_rho_get,&
74#include "./base/base_uses.f90"
75
76 IMPLICIT NONE
77
78 PRIVATE
79
80 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_harris_utils'
81
84
85CONTAINS
86
87! **************************************************************************************************
88!> \brief Allocates and intitializes harris_env
89!> \param qs_env The QS environment
90!> \param harris_env The Harris method environment (the object to create)
91!> \param harris_section The Harris method input section
92!> \par History
93!> 2024.07 created
94!> \author JGH
95! **************************************************************************************************
96 SUBROUTINE harris_env_create(qs_env, harris_env, harris_section)
97 TYPE(qs_environment_type), POINTER :: qs_env
98 TYPE(harris_type), POINTER :: harris_env
99 TYPE(section_vals_type), OPTIONAL, POINTER :: harris_section
100
101 cpassert(.NOT. ASSOCIATED(harris_env))
102 ALLOCATE (harris_env)
103 CALL init_harris_env(qs_env, harris_env, harris_section)
104
105 END SUBROUTINE harris_env_create
106
107! **************************************************************************************************
108!> \brief Initializes Harris method environment
109!> \param qs_env The QS environment
110!> \param harris_env The Harris method environment
111!> \param harris_section The Harris method input section
112!> \par History
113!> 2024.07 created
114!> \author JGH
115! **************************************************************************************************
116 SUBROUTINE init_harris_env(qs_env, harris_env, harris_section)
117 TYPE(qs_environment_type), POINTER :: qs_env
118 TYPE(harris_type), POINTER :: harris_env
119 TYPE(section_vals_type), OPTIONAL, POINTER :: harris_section
120
121 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_harris_env'
122
123 INTEGER :: handle, unit_nr
124 TYPE(cp_logger_type), POINTER :: logger
125
126 CALL timeset(routinen, handle)
127
128 IF (qs_env%harris_method) THEN
129
130 cpassert(PRESENT(harris_section))
131 ! get a useful output_unit
132 logger => cp_get_default_logger()
133 IF (logger%para_env%is_source()) THEN
134 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
135 ELSE
136 unit_nr = -1
137 END IF
138
139 CALL section_vals_val_get(harris_section, "ENERGY_FUNCTIONAL", &
140 i_val=harris_env%energy_functional)
141 CALL section_vals_val_get(harris_section, "DENSITY_SOURCE", &
142 i_val=harris_env%density_source)
143 CALL section_vals_val_get(harris_section, "ORBITAL_BASIS", &
144 i_val=harris_env%orbital_basis)
145 !
146 CALL section_vals_val_get(harris_section, "DEBUG_FORCES", &
147 l_val=harris_env%debug_forces)
148 CALL section_vals_val_get(harris_section, "DEBUG_STRESS", &
149 l_val=harris_env%debug_stress)
150
151 END IF
152
153 CALL timestop(handle)
154
155 END SUBROUTINE init_harris_env
156
157! **************************************************************************************************
158!> \brief Print out the Harris method input section
159!>
160!> \param harris_env ...
161!> \par History
162!> 2024.07 created [JGH]
163!> \author JGH
164! **************************************************************************************************
165 SUBROUTINE harris_write_input(harris_env)
166 TYPE(harris_type), POINTER :: harris_env
167
168 CHARACTER(LEN=*), PARAMETER :: routinen = 'harris_write_input'
169
170 INTEGER :: handle, unit_nr
171 TYPE(cp_logger_type), POINTER :: logger
172
173 CALL timeset(routinen, handle)
174
175 logger => cp_get_default_logger()
176 IF (logger%para_env%is_source()) THEN
177 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
178 ELSE
179 unit_nr = -1
180 END IF
181
182 IF (unit_nr > 0) THEN
183
184 WRITE (unit_nr, '(/,T2,A)') &
185 "!"//repeat("-", 29)//" Harris Model "//repeat("-", 29)//"!"
186
187 ! Type of energy functional
188 SELECT CASE (harris_env%energy_functional)
189 CASE (hfun_harris)
190 WRITE (unit_nr, '(T2,A,T61,A20)') "Energy Functional: ", "Harris"
191 END SELECT
192 ! density source
193 SELECT CASE (harris_env%density_source)
194 CASE (hden_atomic)
195 WRITE (unit_nr, '(T2,A,T61,A20)') "Harris model density: Type", " Atomic kind density"
196 END SELECT
197 WRITE (unit_nr, '(T2,A,T71,A10)') "Harris model density: Basis type", &
198 adjustr(trim(harris_env%rhoin%basis_type))
199 WRITE (unit_nr, '(T2,A,T71,I10)') "Harris model density: Number of basis functions", &
200 harris_env%rhoin%nbas
201 ! orbital basis
202 SELECT CASE (harris_env%orbital_basis)
203 CASE (horb_default)
204 WRITE (unit_nr, '(T2,A,T61,A20)') "Harris model basis: ", "Atomic kind orbitals"
205 END SELECT
206
207 WRITE (unit_nr, '(T2,A)') repeat("-", 79)
208 WRITE (unit_nr, '()')
209
210 END IF ! unit_nr
211
212 CALL timestop(handle)
213
214 END SUBROUTINE harris_write_input
215
216! **************************************************************************************************
217!> \brief ...
218!> \param qs_env ...
219!> \param harris_env ...
220! **************************************************************************************************
221 SUBROUTINE harris_density_update(qs_env, harris_env)
222 TYPE(qs_environment_type), POINTER :: qs_env
223 TYPE(harris_type), POINTER :: harris_env
224
225 CHARACTER(LEN=*), PARAMETER :: routinen = 'harris_density_update'
226
227 INTEGER :: handle, i, ikind, ngto, nkind, nset, nsgf
228 INTEGER, DIMENSION(:), POINTER :: lmax, npgf
229 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: coef
230 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: density
231 REAL(kind=dp), DIMENSION(:), POINTER :: norm
232 REAL(kind=dp), DIMENSION(:, :), POINTER :: zet
233 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: gcc
234 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
235 TYPE(atomic_kind_type), POINTER :: atomic_kind
236 TYPE(gto_basis_set_type), POINTER :: basis_set
237 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
238 TYPE(qs_kind_type), POINTER :: qs_kind
239
240 CALL timeset(routinen, handle)
241
242 SELECT CASE (harris_env%density_source)
243 CASE (hden_atomic)
244 IF (.NOT. harris_env%rhoin%frozen) THEN
245 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
246 nkind=nkind)
247 DO ikind = 1, nkind
248 atomic_kind => atomic_kind_set(ikind)
249 qs_kind => qs_kind_set(ikind)
250 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, &
251 basis_type=harris_env%rhoin%basis_type)
252 CALL get_gto_basis_set(gto_basis_set=basis_set, nset=nset, lmax=lmax, nsgf=nsgf, &
253 npgf=npgf, norm_cgf=norm, zet=zet, gcc=gcc)
254 IF (nset /= 1 .OR. lmax(1) /= 0 .OR. npgf(1) /= nsgf) THEN
255 cpabort("RHOIN illegal basis type")
256 END IF
257 DO i = 1, npgf(1)
258 IF (sum(abs(gcc(1:npgf(1), i, 1))) /= maxval(abs(gcc(1:npgf(1), i, 1)))) THEN
259 cpabort("RHOIN illegal basis type")
260 END IF
261 END DO
262 !
263 ngto = npgf(1)
264 ALLOCATE (density(ngto, 2))
265 density(1:ngto, 1) = zet(1:ngto, 1)
266 density(1:ngto, 2) = 0.0_dp
267 CALL calculate_atomic_density(density, atomic_kind, qs_kind, ngto, &
268 optbasis=.false., confine=.true.)
269 ALLOCATE (coef(ngto))
270 DO i = 1, ngto
271 coef(i) = density(i, 2)/gcc(i, i, 1)/norm(i)
272 END DO
273 IF (harris_env%rhoin%nspin == 2) THEN
274 DO i = 1, SIZE(harris_env%rhoin%rhovec(ikind, 1)%rvecs, 2)
275 harris_env%rhoin%rhovec(ikind, 1)%rvecs(1:ngto, i) = coef(1:ngto)*0.5_dp
276 harris_env%rhoin%rhovec(ikind, 2)%rvecs(1:ngto, i) = coef(1:ngto)*0.5_dp
277 END DO
278 ELSE
279 DO i = 1, SIZE(harris_env%rhoin%rhovec(ikind, 1)%rvecs, 2)
280 harris_env%rhoin%rhovec(ikind, 1)%rvecs(1:ngto, i) = coef(1:ngto)
281 END DO
282 END IF
283 DEALLOCATE (density, coef)
284 END DO
285 harris_env%rhoin%frozen = .true.
286 END IF
287 CASE DEFAULT
288 cpabort("Illeagal value of harris_env%density_source")
289 END SELECT
290
291 CALL timestop(handle)
292
293 END SUBROUTINE harris_density_update
294
295! **************************************************************************************************
296!> \brief ...
297!> \param qs_env ...
298!> \param rhoin ...
299!> \param rho_struct ...
300! **************************************************************************************************
301 SUBROUTINE calculate_harris_density(qs_env, rhoin, rho_struct)
302 TYPE(qs_environment_type), POINTER :: qs_env
303 TYPE(harris_rhoin_type), INTENT(IN) :: rhoin
304 TYPE(qs_rho_type), INTENT(INOUT) :: rho_struct
305
306 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_harris_density'
307
308 INTEGER :: handle, i1, i2, iatom, ikind, ilocal, &
309 ispin, n, nkind, nlocal, nspin
310 REAL(kind=dp) :: eps_rho_rspace
311 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: vector
312 REAL(kind=dp), DIMENSION(:), POINTER :: total_rho
313 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
314 TYPE(cell_type), POINTER :: cell
315 TYPE(dft_control_type), POINTER :: dft_control
316 TYPE(distribution_1d_type), POINTER :: local_particles
317 TYPE(mp_para_env_type), POINTER :: para_env
318 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
319 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_gspace
320 TYPE(pw_env_type), POINTER :: pw_env
321 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_rspace
322 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
323
324 CALL timeset(routinen, handle)
325
326 CALL get_qs_env(qs_env, dft_control=dft_control, para_env=para_env)
327 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
328 CALL get_qs_env(qs_env, &
329 atomic_kind_set=atomic_kind_set, particle_set=particle_set, &
330 local_particles=local_particles, &
331 qs_kind_set=qs_kind_set, cell=cell, pw_env=pw_env)
332
333 CALL qs_rho_get(rho_struct, rho_r=rho_rspace, rho_g=rho_gspace, &
334 tot_rho_r=total_rho)
335
336 ALLOCATE (vector(rhoin%nbas))
337
338 nkind = SIZE(rhoin%rhovec, 1)
339 nspin = SIZE(rhoin%rhovec, 2)
340
341 DO ispin = 1, nspin
342 vector = 0.0_dp
343 DO ikind = 1, nkind
344 nlocal = local_particles%n_el(ikind)
345 DO ilocal = 1, nlocal
346 iatom = local_particles%list(ikind)%array(ilocal)
347 i1 = rhoin%basptr(iatom, 1)
348 i2 = rhoin%basptr(iatom, 2)
349 n = i2 - i1 + 1
350 vector(i1:i2) = rhoin%rhovec(ikind, ispin)%rvecs(1:n, ilocal)
351 END DO
352 END DO
353 CALL para_env%sum(vector)
354 !
355 CALL collocate_function(vector, rho_rspace(ispin), rho_gspace(ispin), &
356 atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, &
357 eps_rho_rspace, rhoin%basis_type)
358 total_rho(ispin) = pw_integrate_function(rho_rspace(ispin), isign=-1)
359 END DO
360
361 DEALLOCATE (vector)
362
363 CALL timestop(handle)
364
365 END SUBROUTINE calculate_harris_density
366
367! **************************************************************************************************
368!> \brief ...
369!> \param qs_env ...
370!> \param rhoin ...
371!> \param v_rspace ...
372!> \param calculate_forces ...
373! **************************************************************************************************
374 SUBROUTINE calculate_harris_integrals(qs_env, rhoin, v_rspace, calculate_forces)
375 TYPE(qs_environment_type), POINTER :: qs_env
376 TYPE(harris_rhoin_type), INTENT(INOUT) :: rhoin
377 TYPE(pw_r3d_rs_type), DIMENSION(:), INTENT(IN) :: v_rspace
378 LOGICAL, INTENT(IN) :: calculate_forces
379
380 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_harris_integrals'
381
382 INTEGER :: handle, i1, i2, iatom, ikind, ilocal, &
383 ispin, n, nkind, nlocal, nspin
384 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: integral, vector
385 TYPE(distribution_1d_type), POINTER :: local_particles
386 TYPE(mp_para_env_type), POINTER :: para_env
387
388 CALL timeset(routinen, handle)
389
390 CALL get_qs_env(qs_env, para_env=para_env, local_particles=local_particles)
391
392 ALLOCATE (vector(rhoin%nbas))
393 ALLOCATE (integral(rhoin%nbas))
394
395 nkind = SIZE(rhoin%rhovec, 1)
396 nspin = SIZE(rhoin%rhovec, 2)
397
398 DO ispin = 1, nspin
399 vector = 0.0_dp
400 integral = 0.0_dp
401 DO ikind = 1, nkind
402 nlocal = local_particles%n_el(ikind)
403 DO ilocal = 1, nlocal
404 iatom = local_particles%list(ikind)%array(ilocal)
405 i1 = rhoin%basptr(iatom, 1)
406 i2 = rhoin%basptr(iatom, 2)
407 n = i2 - i1 + 1
408 vector(i1:i2) = rhoin%rhovec(ikind, ispin)%rvecs(1:n, ilocal)
409 END DO
410 END DO
411 CALL para_env%sum(vector)
412 !
413 CALL integrate_function(qs_env, v_rspace(ispin), vector, integral, &
414 calculate_forces, rhoin%basis_type)
415 DO ikind = 1, nkind
416 nlocal = local_particles%n_el(ikind)
417 DO ilocal = 1, nlocal
418 iatom = local_particles%list(ikind)%array(ilocal)
419 i1 = rhoin%basptr(iatom, 1)
420 i2 = rhoin%basptr(iatom, 2)
421 n = i2 - i1 + 1
422 rhoin%intvec(ikind, ispin)%rvecs(1:n, ilocal) = integral(i1:i2)
423 END DO
424 END DO
425 END DO
426
427 DEALLOCATE (vector, integral)
428
429 CALL timestop(handle)
430
431 END SUBROUTINE calculate_harris_integrals
432
433! **************************************************************************************************
434!> \brief ...
435!> \param harris_env ...
436!> \param vh_rspace ...
437!> \param vxc_rspace ...
438! **************************************************************************************************
439 SUBROUTINE harris_set_potentials(harris_env, vh_rspace, vxc_rspace)
440 TYPE(harris_type), POINTER :: harris_env
441 TYPE(pw_r3d_rs_type), INTENT(IN) :: vh_rspace
442 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace
443
444 INTEGER :: iab, ispin, nspins
445 TYPE(pw_grid_type), POINTER :: pw_grid
446
447 ! release possible old potentials
448 IF (ASSOCIATED(harris_env%vh_rspace%pw_grid)) THEN
449 CALL harris_env%vh_rspace%release()
450 END IF
451 IF (ASSOCIATED(harris_env%vxc_rspace)) THEN
452 DO iab = 1, SIZE(harris_env%vxc_rspace)
453 CALL harris_env%vxc_rspace(iab)%release()
454 END DO
455 DEALLOCATE (harris_env%vxc_rspace)
456 END IF
457
458 ! generate new potential data structures
459 nspins = harris_env%rhoin%nspin
460 ALLOCATE (harris_env%vxc_rspace(nspins))
461
462 pw_grid => vh_rspace%pw_grid
463 CALL harris_env%vh_rspace%create(pw_grid)
464 DO ispin = 1, nspins
465 CALL harris_env%vxc_rspace(ispin)%create(pw_grid)
466 END DO
467
468 ! copy potentials
469 CALL pw_transfer(vh_rspace, harris_env%vh_rspace)
470 IF (ASSOCIATED(vxc_rspace)) THEN
471 DO ispin = 1, nspins
472 CALL pw_transfer(vxc_rspace(ispin), harris_env%vxc_rspace(ispin))
473 CALL pw_scale(harris_env%vxc_rspace(ispin), vxc_rspace(ispin)%pw_grid%dvol)
474 END DO
475 ELSE
476 DO ispin = 1, nspins
477 CALL pw_zero(harris_env%vxc_rspace(ispin))
478 END DO
479 END IF
480
481 END SUBROUTINE harris_set_potentials
482
483! **************************************************************************************************
484!> \brief ...
485!> \param qs_env ...
486!> \param calculate_forces ...
487! **************************************************************************************************
488 SUBROUTINE harris_energy_correction(qs_env, calculate_forces)
489 TYPE(qs_environment_type), POINTER :: qs_env
490 LOGICAL, INTENT(IN) :: calculate_forces
491
492 CHARACTER(LEN=*), PARAMETER :: routinen = 'harris_energy_correction'
493
494 INTEGER :: handle, iounit, ispin, nspins
495 REAL(kind=dp) :: dvol, ec, eh, exc, vxc
496 TYPE(cp_logger_type), POINTER :: logger
497 TYPE(harris_energy_type), POINTER :: energy
498 TYPE(harris_type), POINTER :: harris_env
499 TYPE(pw_c1d_gs_type), POINTER :: rho_core
500 TYPE(pw_env_type), POINTER :: pw_env
501 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
502 TYPE(pw_r3d_rs_type) :: core_rspace
503 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
504 TYPE(qs_energy_type), POINTER :: ks_energy
505 TYPE(qs_rho_type), POINTER :: rho
506
507 mark_used(calculate_forces)
508
509 CALL timeset(routinen, handle)
510
511 CALL get_qs_env(qs_env, harris_env=harris_env, energy=ks_energy)
512 energy => harris_env%energy
513 energy%eband = ks_energy%band
514 energy%ewald_correction = ks_energy%core_overlap + ks_energy%core_self
515 energy%dispersion = ks_energy%dispersion
516
517 nspins = harris_env%rhoin%nspin
518
519 CALL get_qs_env(qs_env, rho=rho, rho_core=rho_core)
520 CALL qs_rho_get(rho, rho_r=rho_r)
521
522 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
523 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
524 CALL auxbas_pw_pool%create_pw(core_rspace)
525 CALL pw_transfer(rho_core, core_rspace)
526
527 dvol = harris_env%vh_rspace%pw_grid%dvol
528 eh = 0.0_dp
529 DO ispin = 1, nspins
530 eh = eh + pw_integral_ab(rho_r(ispin), harris_env%vh_rspace)/dvol
531 END DO
532 ec = pw_integral_ab(core_rspace, harris_env%vh_rspace)/dvol
533 eh = 0.5_dp*(eh + ec)
534 energy%eh_correction = ec - eh
535
536 exc = ks_energy%exc
537 vxc = 0.0_dp
538 IF (ASSOCIATED(harris_env%vxc_rspace)) THEN
539 DO ispin = 1, nspins
540 vxc = vxc + pw_integral_ab(rho_r(ispin), harris_env%vxc_rspace(ispin))/ &
541 harris_env%vxc_rspace(ispin)%pw_grid%dvol
542 END DO
543 END IF
544 energy%exc_correction = exc - vxc
545
546 ! Total Harris model energy
547 energy%eharris = energy%eband + energy%eh_correction + energy%exc_correction + &
548 energy%ewald_correction + energy%dispersion
549
550 CALL auxbas_pw_pool%give_back_pw(core_rspace)
551
552 ks_energy%total = ks_energy%total + ks_energy%core
553 ks_energy%nonscf_correction = energy%eharris - ks_energy%total
554 ks_energy%total = energy%eharris
555
556 logger => cp_get_default_logger()
557 iounit = cp_logger_get_default_io_unit(logger)
558
559 CALL harris_print_energy(iounit, energy)
560
561 IF (calculate_forces) THEN
562 CALL harris_forces(qs_env, iounit)
563 END IF
564
565 CALL timestop(handle)
566
567 END SUBROUTINE harris_energy_correction
568
569! **************************************************************************************************
570!> \brief ...
571!> \param qs_env ...
572!> \param iounit ...
573! **************************************************************************************************
574 SUBROUTINE harris_forces(qs_env, iounit)
575 TYPE(qs_environment_type), POINTER :: qs_env
576 INTEGER, INTENT(IN) :: iounit
577
578 CHARACTER(LEN=*), PARAMETER :: routinen = 'harris_forces'
579 LOGICAL, PARAMETER :: debug_forces = .true.
580
581 INTEGER :: handle, ispin, nspins
582 REAL(kind=dp) :: ehartree
583 REAL(kind=dp), DIMENSION(3) :: fodeb
584 TYPE(dbcsr_p_type) :: scrm
585 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rhoh_ao, smat
586 TYPE(harris_type), POINTER :: harris_env
587 TYPE(mp_para_env_type), POINTER :: para_env
588 TYPE(pw_c1d_gs_type) :: rhoh_tot_gspace, vhout_gspace
589 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g, rhoh_g
590 TYPE(pw_c1d_gs_type), POINTER :: rho_core
591 TYPE(pw_env_type), POINTER :: pw_env
592 TYPE(pw_poisson_type), POINTER :: poisson_env
593 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
594 TYPE(pw_r3d_rs_type) :: vhout_rspace, vhxc_rspace
595 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fhxc_rspace, ftau, fxc, rho_r, rhoh_r, &
596 tauh_r
597 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
598 TYPE(qs_ks_env_type), POINTER :: ks_env
599 TYPE(qs_rho_type), POINTER :: rho
600 TYPE(section_vals_type), POINTER :: xc_section
601
602 CALL timeset(routinen, handle)
603
604 IF (debug_forces) THEN
605 IF (iounit > 0) WRITE (iounit, "(/,T3,A)") &
606 "DEBUG:: Harris Method Forces (density dependent)"
607 END IF
608
609 CALL get_qs_env(qs_env, harris_env=harris_env, force=force, para_env=para_env)
610 nspins = harris_env%rhoin%nspin
611
612 CALL get_qs_env(qs_env, rho=rho, rho_core=rho_core, matrix_s=smat)
613 ! Warning: rho_ao = output DM; rho_r = rhoin
614 CALL qs_rho_get(rho, rho_ao=rhoh_ao, rho_r=rho_r, rho_g=rho_g)
615 ALLOCATE (scrm%matrix)
616 CALL dbcsr_create(scrm%matrix, template=rhoh_ao(1)%matrix)
617 CALL dbcsr_copy(scrm%matrix, smat(1)%matrix)
618 CALL dbcsr_set(scrm%matrix, 0.0_dp)
619
620 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, ks_env=ks_env)
621 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
622 CALL auxbas_pw_pool%create_pw(vhxc_rspace)
623
624 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
625 DO ispin = 1, nspins
626 CALL pw_copy(harris_env%vh_rspace, vhxc_rspace)
627 CALL pw_axpy(harris_env%vxc_rspace(ispin), vhxc_rspace)
628 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
629 hmat=scrm, pmat=rhoh_ao(ispin), &
630 qs_env=qs_env, calculate_forces=.true.)
631 END DO
632 IF (debug_forces) THEN
633 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
634 CALL para_env%sum(fodeb)
635 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P*(Vh[in]+Vxc)", fodeb
636 END IF
637
638 CALL dbcsr_release(scrm%matrix)
639 DEALLOCATE (scrm%matrix)
640 CALL auxbas_pw_pool%give_back_pw(vhxc_rspace)
641
642 ALLOCATE (rhoh_r(nspins), rhoh_g(nspins))
643 DO ispin = 1, nspins
644 CALL auxbas_pw_pool%create_pw(rhoh_r(ispin))
645 CALL auxbas_pw_pool%create_pw(rhoh_g(ispin))
646 END DO
647 CALL auxbas_pw_pool%create_pw(rhoh_tot_gspace)
648 CALL pw_copy(rho_core, rhoh_tot_gspace)
649 DO ispin = 1, nspins
650 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=rhoh_ao(ispin)%matrix, &
651 rho=rhoh_r(ispin), rho_gspace=rhoh_g(ispin))
652 CALL pw_axpy(rhoh_g(ispin), rhoh_tot_gspace)
653 END DO
654 ! no meta functionals here
655 NULLIFY (tauh_r)
656
657 CALL auxbas_pw_pool%create_pw(vhout_rspace)
658 CALL auxbas_pw_pool%create_pw(vhout_gspace)
659 CALL pw_env_get(pw_env, poisson_env=poisson_env)
660 !
661 CALL pw_poisson_solve(poisson_env, rhoh_tot_gspace, ehartree, vhout_gspace)
662 !
663 CALL pw_transfer(vhout_gspace, vhout_rspace)
664 CALL pw_scale(vhout_rspace, vhout_rspace%pw_grid%dvol)
665
666 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
667 CALL integrate_v_core_rspace(vhout_rspace, qs_env)
668 IF (debug_forces) THEN
669 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
670 CALL para_env%sum(fodeb)
671 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Vh[out]*dncore ", fodeb
672 END IF
673
674 ALLOCATE (fhxc_rspace(nspins))
675 DO ispin = 1, nspins
676 CALL auxbas_pw_pool%create_pw(fhxc_rspace(ispin))
677 END DO
678 ! vh = vh[out] - vh[in]
679 CALL pw_axpy(harris_env%vh_rspace, vhout_rspace, alpha=-1._dp, beta=1.0_dp)
680 ! kernel fxc
681 ! drho = rho[out] - rho[in]
682 DO ispin = 1, nspins
683 CALL pw_axpy(rho_r(ispin), rhoh_r(ispin), alpha=-1._dp, beta=1.0_dp)
684 CALL pw_axpy(rho_g(ispin), rhoh_g(ispin), alpha=-1._dp, beta=1.0_dp)
685 END DO
686 xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
687 NULLIFY (fxc, ftau)
688 CALL create_kernel(qs_env, vxc=fxc, vxc_tau=ftau, &
689 rho=rho, rho1_r=rhoh_r, rho1_g=rhoh_g, tau1_r=tauh_r, &
690 xc_section=xc_section)
691 cpassert(.NOT. ASSOCIATED(ftau))
692
693 DO ispin = 1, nspins
694 CALL pw_copy(vhout_rspace, fhxc_rspace(ispin))
695 IF (ASSOCIATED(fxc)) THEN
696 CALL pw_scale(fxc(ispin), fxc(ispin)%pw_grid%dvol)
697 CALL pw_axpy(fxc(ispin), fhxc_rspace(ispin))
698 END IF
699 END DO
700
701 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
702 CALL calculate_harris_integrals(qs_env, harris_env%rhoin, fhxc_rspace, .true.)
703 IF (debug_forces) THEN
704 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
705 CALL para_env%sum(fodeb)
706 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: (dVh+fxc)*dn[in] ", fodeb
707 END IF
708
709 IF (ASSOCIATED(fxc)) THEN
710 DO ispin = 1, nspins
711 CALL auxbas_pw_pool%give_back_pw(fxc(ispin))
712 END DO
713 DEALLOCATE (fxc)
714 END IF
715 IF (ASSOCIATED(ftau)) THEN
716 DO ispin = 1, nspins
717 CALL auxbas_pw_pool%give_back_pw(ftau(ispin))
718 END DO
719 DEALLOCATE (ftau)
720 END IF
721
722 CALL auxbas_pw_pool%give_back_pw(rhoh_tot_gspace)
723 CALL auxbas_pw_pool%give_back_pw(vhout_rspace)
724 CALL auxbas_pw_pool%give_back_pw(vhout_gspace)
725
726 DO ispin = 1, nspins
727 CALL auxbas_pw_pool%give_back_pw(rhoh_r(ispin))
728 CALL auxbas_pw_pool%give_back_pw(rhoh_g(ispin))
729 CALL auxbas_pw_pool%give_back_pw(fhxc_rspace(ispin))
730 END DO
731 DEALLOCATE (rhoh_r, rhoh_g, fhxc_rspace)
732
733 CALL timestop(handle)
734
735 END SUBROUTINE harris_forces
736
737END MODULE qs_harris_utils
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_density(density, atomic_kind, qs_kind, ngto, iunit, optbasis, allelectron, confine)
...
Define the atomic kind types and their sub types.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Routines used for Harris functional Kohn-Sham calculation.
Definition ec_methods.F:15
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
Definition ec_methods.F:88
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public hfun_harris
integer, parameter, public horb_default
integer, parameter, public hden_atomic
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
subroutine, public collocate_function(vector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, eps_rho_rspace, basis_type)
maps a given function on the grid
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.
Types needed for a for a Harris model calculation.
subroutine, public harris_print_energy(iounit, energy)
...
Harris method environment setup and handling.
subroutine, public calculate_harris_density(qs_env, rhoin, rho_struct)
...
subroutine, public harris_write_input(harris_env)
Print out the Harris method input section.
subroutine, public harris_density_update(qs_env, harris_env)
...
subroutine, public harris_set_potentials(harris_env, vh_rspace, vxc_rspace)
...
subroutine, public harris_energy_correction(qs_env, calculate_forces)
...
subroutine, public harris_env_create(qs_env, harris_env, harris_section)
Allocates and intitializes harris_env.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
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...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
type of a logger, at the moment it contains just a print level starting at which level it should be l...
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Contains information on the Harris method.
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.