Octopus
v_ks.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module v_ks_oct_m
22 use accel_oct_m
23 use types_oct_m
25 use debug_oct_m
28 use energy_oct_m
32 use global_oct_m
33 use grid_oct_m
37 use ions_oct_m
38 use, intrinsic :: iso_fortran_env
39 use isdf_oct_m, only: isdf_parallel_ace_compute_potentials => isdf_ace_compute_potentials
44 use lda_u_oct_m
48 use mesh_oct_m
51 use mpi_oct_m
54 use parser_oct_m
59 use pseudo_oct_m
62 use sort_oct_m
63 use space_oct_m
71 use xc_cam_oct_m
72 use xc_oct_m
73 use xc_f03_lib_m
74 use xc_fbe_oct_m
79 use xc_oep_oct_m
80 use xc_sic_oct_m
82 use xc_vxc_oct_m
83 use xc_vdw_oct_m
85
86 ! from the dftd3 library
87 use dftd3_api
88
89 implicit none
90
91 private
92 public :: &
93 v_ks_t, &
94 v_ks_init, &
95 v_ks_end, &
98 v_ks_calc, &
105
106 type v_ks_calc_t
107 private
108 logical :: calculating
109 logical :: time_present
110 real(real64) :: time
111 real(real64), allocatable :: density(:, :)
112 logical :: total_density_alloc
113 real(real64), pointer, contiguous :: total_density(:)
114 type(energy_t), allocatable :: energy
115
116 type(states_elec_t), pointer :: hf_st
120
121 real(real64), allocatable :: vxc(:, :)
122 real(real64), allocatable :: vtau(:, :)
123 real(real64), allocatable :: axc(:, :, :)
124 real(real64), allocatable :: a_ind(:, :)
125 real(real64), allocatable :: b_ind(:, :)
126 logical :: calc_energy
127 end type v_ks_calc_t
128
129 type v_ks_t
130 private
131 integer, public :: theory_level = -1
132 logical, public :: frozen_hxc = .false.
133
134 integer, public :: xc_family = 0
135 integer, public :: xc_flags = 0
136 integer, public :: xc_photon = 0
137 type(xc_t), public :: xc
138 type(xc_photons_t), public :: xc_photons
139 type(xc_oep_t), public :: oep
140 type(xc_oep_photon_t), public :: oep_photon
141 type(xc_ks_inversion_t), public :: ks_inversion
142 type(xc_sic_t), public :: sic
143 type(xc_vdw_t), public :: vdw
144 type(grid_t), pointer, public :: gr
145 type(v_ks_calc_t) :: calc
146 logical :: calculate_current = .false.
147 type(current_t) :: current_calculator
148 logical :: include_td_field = .false.
149 logical, public :: has_photons = .false.
150 logical :: xc_photon_include_hartree = .true.
151
152 real(real64), public :: stress_xc_gga(3, 3)
153 type(photon_mode_t), pointer, public :: pt => null()
154 type(mf_t), public :: pt_mx
155 end type v_ks_t
156
157contains
158
159 ! ---------------------------------------------------------
160 subroutine v_ks_init(ks, namespace, gr, st, ions, mc, space, kpoints)
161 type(v_ks_t), intent(inout) :: ks
162 type(namespace_t), intent(in) :: namespace
163 type(grid_t), target, intent(inout) :: gr
164 type(states_elec_t), intent(in) :: st
165 type(ions_t), intent(inout) :: ions
166 type(multicomm_t), intent(in) :: mc
167 class(space_t), intent(in) :: space
168 type(kpoints_t), intent(in) :: kpoints
169
170 integer :: x_id, c_id, xk_id, ck_id, default, val
171 logical :: parsed_theory_level, using_hartree_fock
172 integer :: pseudo_x_functional, pseudo_c_functional
173 integer :: oep_type
174
175 push_sub(v_ks_init)
176
177 ! We need to parse TheoryLevel and XCFunctional, this is
178 ! complicated because they are interdependent.
179
180 !%Variable TheoryLevel
181 !%Type integer
182 !%Section Hamiltonian
183 !%Description
184 !% The calculations can be run with different "theory levels" that
185 !% control how electrons are simulated. The default is
186 !% <tt>dft</tt>. When hybrid functionals are requested, through
187 !% the <tt>XCFunctional</tt> variable, the default is
188 !% <tt>hartree_fock</tt>.
189 !%Option independent_particles 2
190 !% Particles will be considered as independent, <i>i.e.</i> as non-interacting.
191 !% This mode is mainly used for testing purposes, as the code is usually
192 !% much faster with <tt>independent_particles</tt>.
193 !%Option hartree 1
194 !% Calculation within the Hartree method (experimental). Note that, contrary to popular
195 !% belief, the Hartree potential is self-interaction-free. Therefore, this run
196 !% mode will not yield the same result as <tt>kohn-sham</tt> without exchange-correlation.
197 !%Option hartree_fock 3
198 !% This is the traditional Hartree-Fock scheme. Like the Hartree scheme, it is fully
199 !% self-interaction-free.
200 !%Option kohn_sham 4
201 !% This is the default density-functional theory scheme. Note that you can also use
202 !% hybrid functionals in this scheme, but they will be handled the "DFT" way, <i>i.e.</i>,
203 !% solving the OEP equation.
204 !%Option generalized_kohn_sham 5
205 !% This is similar to the <tt>kohn-sham</tt> scheme, except that this allows for nonlocal operators.
206 !% This is the default mode to run hybrid functionals, meta-GGA functionals, or DFT+U.
207 !% It can be more convenient to use <tt>kohn-sham</tt> DFT within the OEP scheme to get similar (but not the same) results.
208 !% Note that within this scheme you can use a correlation functional, or a hybrid
209 !% functional (see <tt>XCFunctional</tt>). In the latter case, you will be following the
210 !% quantum-chemistry recipe to use hybrids.
211 !%Option rdmft 7
212 !% (Experimental) Reduced Density Matrix functional theory.
213 !%End
214
215 ks%xc_family = xc_family_none
216 ks%sic%level = sic_none
217 ks%oep%level = oep_level_none
218 ks%oep_photon%level = oep_level_none
220 ks%theory_level = kohn_sham_dft
221 parsed_theory_level = .false.
222
223 ! the user knows what he wants, give her that
224 if (parse_is_defined(namespace, 'TheoryLevel')) then
225 call parse_variable(namespace, 'TheoryLevel', kohn_sham_dft, ks%theory_level)
226 if (.not. varinfo_valid_option('TheoryLevel', ks%theory_level)) call messages_input_error(namespace, 'TheoryLevel')
228 parsed_theory_level = .true.
229 end if
231 ! parse the XC functional
233 call get_functional_from_pseudos(pseudo_x_functional, pseudo_c_functional)
235 default = 0
236 if (ks%theory_level == kohn_sham_dft .or. ks%theory_level == generalized_kohn_sham_dft) then
237 default = xc_get_default_functional(space%dim, pseudo_x_functional, pseudo_c_functional)
238 end if
240 if (.not. parse_is_defined(namespace, 'XCFunctional') &
241 .and. (pseudo_x_functional /= pseudo_exchange_any .or. pseudo_c_functional /= pseudo_correlation_any)) then
242 call messages_write('Info: the XCFunctional has been selected to match the pseudopotentials', new_line = .true.)
243 call messages_write(' used in the calculation.')
244 call messages_info(namespace=namespace)
245 end if
246
247 ! The description of this variable can be found in file src/xc/functionals_list.F90
248 call parse_variable(namespace, 'XCFunctional', default, val)
250 ! the first 3 digits of the number indicate the X functional and
251 ! the next 3 the C functional.
252 c_id = val / libxc_c_index
253 x_id = val - c_id * libxc_c_index
254
255 if ((x_id /= pseudo_x_functional .and. pseudo_x_functional /= pseudo_exchange_any) .or. &
256 (c_id /= pseudo_c_functional .and. pseudo_c_functional /= pseudo_correlation_any)) then
257 call messages_write('The XCFunctional that you selected does not match the one used', new_line = .true.)
258 call messages_write('to generate the pseudopotentials.')
259 call messages_warning(namespace=namespace)
260 end if
261
262 ! FIXME: we rarely need this. We should only parse when necessary.
263
264 !%Variable XCKernel
265 !%Type integer
266 !%Default -1
267 !%Section Hamiltonian::XC
268 !%Description
269 !% Defines the exchange-correlation kernel. Only LDA kernels are available currently.
270 !% The options are the same as <tt>XCFunctional</tt>.
271 !% Note: the kernel is only needed for Casida, Sternheimer, or optimal-control calculations.
272 !%Option xc_functional -1
273 !% The same functional defined by <tt>XCFunctional</tt>. By default, this is the case.
274 !%End
275 call parse_variable(namespace, 'XCKernel', -1, val)
276 if (-1 == val) then
277 ck_id = c_id
278 xk_id = x_id
279 else
280 ck_id = val / libxc_c_index
281 xk_id = val - ck_id * libxc_c_index
282 end if
283
284 call messages_obsolete_variable(namespace, 'XFunctional', 'XCFunctional')
285 call messages_obsolete_variable(namespace, 'CFunctional', 'XCFunctional')
286
287 !%Variable XCPhotonFunctional
288 !%Type integer
289 !%Default 0
290 !%Section Hamiltonian::XC
291 !%Description
292 !% Defines the exchange and correlation functionals to be used for the QEDFT
293 !% description of the electron-photon system.
294 !%Option none 0
295 !% No functional is used
296 !%Option photon_x_lda 10
297 !% Exchange-only local density approcimation
298 !%Option photon_xc_lda 11
299 !% Exchange-correlation local density approcimation
300 !%Option photon_x_wfn 20
301 !% Exchange-only based on wave functions
302 !%Option photon_xc_wfn 21
303 !% Exchange-correlation based on wave functions
304 !%End
305
306 call parse_variable(namespace, 'XCPhotonFunctional', option__xcphotonfunctional__none, ks%xc_photon)
307
308 !%Variable XCPhotonIncludeHartree
309 !%Type logical
310 !%Default yes
311 !%Section Hamiltonian::XC
312 !%Description
313 !% Use the Hartree potential and energy in calculations
314 !%End
315
316 call parse_variable(namespace, 'XCPhotonIncludeHartree', .true., ks%xc_photon_include_hartree)
317
318 if (.not. ks%xc_photon_include_hartree) then
319 call messages_write('turn off hartree potential and energy')
320 call messages_warning(namespace=namespace)
321 end if
322
323 ! initialize XC modules
324
325 ! This is a bit ugly, theory_level might not be generalized KS or HF now
326 ! but it might become generalized KS or HF later. This is safe because it
327 ! becomes generalized KS in the cases where the functional is hybrid
328 ! and the ifs inside check for both conditions.
329 using_hartree_fock = (ks%theory_level == hartree_fock) &
330 .or. (ks%theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(ks%xc))
331 call xc_init(ks%xc, namespace, space%dim, space%periodic_dim, st%qtot, &
332 x_id, c_id, xk_id, ck_id, hartree_fock = using_hartree_fock, ispin=st%d%ispin)
333
334 ks%xc_family = ks%xc%family
335 ks%xc_flags = ks%xc%flags
336
337 if (.not. parsed_theory_level) then
338 default = kohn_sham_dft
339
340 ! the functional is a hybrid, use Hartree-Fock as theory level by default
341 if (family_is_hybrid(ks%xc) .or. family_is_mgga_with_exc(ks%xc)) then
343 end if
344
345 ! In principle we do not need to parse. However we do it for consistency
346 call parse_variable(namespace, 'TheoryLevel', default, ks%theory_level)
347 if (.not. varinfo_valid_option('TheoryLevel', ks%theory_level)) call messages_input_error(namespace, 'TheoryLevel')
348
349 end if
350
351 ! In case we need OEP, we need to find which type of OEP it is
352 oep_type = -1
353 if (family_is_mgga_with_exc(ks%xc)) then
354 call messages_experimental('MGGA energy functionals')
355
356 if (ks%theory_level == kohn_sham_dft) then
357 call messages_experimental("MGGA within the Kohn-Sham scheme")
358 ks%xc_family = ior(ks%xc_family, xc_family_oep)
359 oep_type = oep_type_mgga
360 end if
361 end if
362
363 call messages_obsolete_variable(namespace, 'NonInteractingElectrons', 'TheoryLevel')
364 call messages_obsolete_variable(namespace, 'HartreeFock', 'TheoryLevel')
365
366 ! Due to how the code is made, we need to set this to have theory level other than DFT
367 ! correct...
368 ks%sic%amaldi_factor = m_one
369
370 select case (ks%theory_level)
372
373 case (hartree)
374 call messages_experimental("Hartree theory level")
375 if (space%periodic_dim == space%dim) then
376 call messages_experimental("Hartree in fully periodic system")
377 end if
378 if (kpoints%full%npoints > 1) then
379 call messages_not_implemented("Hartree with k-points", namespace=namespace)
380 end if
381
382 case (hartree_fock)
383 if (kpoints%full%npoints > 1) then
384 call messages_experimental("Hartree-Fock with k-points")
385 end if
386
388 if (kpoints%full%npoints > 1 .and. family_is_hybrid(ks%xc)) then
389 call messages_experimental("Hybrid functionals with k-points")
390 end if
391
392 case (rdmft)
393 call messages_experimental('RDMFT theory level')
394
395 case (kohn_sham_dft)
396
397 ! check for SIC
398 if (bitand(ks%xc_family, xc_family_lda + xc_family_gga) /= 0) then
399 call xc_sic_init(ks%sic, namespace, gr, st, mc, space)
400 end if
401
402 if (bitand(ks%xc_family, xc_family_oep) /= 0) then
403 select case (ks%xc%functional(func_x,1)%id)
404 case (xc_oep_x_slater)
405 if (kpoints%reduced%npoints > 1 .and. st%d%ispin == spinors) then
406 call messages_not_implemented("Slater with k-points and spinor wavefunctions", namespace=namespace)
407 end if
408 if (kpoints%use_symmetries) then
409 call messages_not_implemented("Slater with k-points symmetries", namespace=namespace)
410 end if
411 ks%oep%level = oep_level_none
412 case (xc_oep_x_fbe)
413 if (kpoints%reduced%npoints > 1) then
414 call messages_not_implemented("FBE functional with k-points", namespace=namespace)
415 end if
416 ks%oep%level = oep_level_none
417 case default
418 if((.not. ks%has_photons) .or. (ks%xc_photon /= 0)) then
419 if(oep_type == -1) then ! Else we have a MGGA
420 oep_type = oep_type_exx
421 end if
422 call xc_oep_init(ks%oep, namespace, gr, st, mc, space, oep_type)
423 end if
424 end select
425 else
426 ks%oep%level = oep_level_none
427 end if
428
429 if (bitand(ks%xc_family, xc_family_ks_inversion) /= 0) then
430 call xc_ks_inversion_init(ks%ks_inversion, namespace, gr, ions, st, ks%xc, mc, space, kpoints)
431 end if
432
433 end select
434
435 if (ks%theory_level /= kohn_sham_dft .and. parse_is_defined(namespace, "SICCorrection")) then
436 message(1) = "SICCorrection can only be used with Kohn-Sham DFT"
437 call messages_fatal(1, namespace=namespace)
438 end if
439
440 if (st%d%ispin == spinors) then
441 if (bitand(ks%xc_family, xc_family_mgga + xc_family_hyb_mgga) /= 0) then
442 call messages_not_implemented("MGGA with spinors", namespace=namespace)
443 end if
444 end if
445
446 ks%frozen_hxc = .false.
447
448 call v_ks_write_info(ks, namespace=namespace)
449
450 ks%gr => gr
451 ks%calc%calculating = .false.
452
453 !The value of ks%calculate_current is set to false or true by Output
454 call current_init(ks%current_calculator, namespace)
455
456 call ks%vdw%init(namespace, space, gr, ks%xc, ions, x_id, c_id)
457 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. ks%theory_level == rdmft) then
458 message(1) = "VDWCorrection and RDMFT are not compatible"
459 call messages_fatal(1, namespace=namespace)
460 end if
461 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. ks%theory_level == independent_particles) then
462 message(1) = "VDWCorrection and independent particles are not compatible"
463 call messages_fatal(1, namespace=namespace)
464 end if
465
466 if (ks%xc_photon /= 0) then
467 ! initilize the photon free variables
468 call ks%xc_photons%init(namespace, ks%xc_photon , space, gr, st)
469 ! remornalize the electron mass due to light-matter interaction; here we only deal with it in free space
470 ks%oep_photon%level = oep_level_none
471 end if
472
473
474 pop_sub(v_ks_init)
475
476 contains
477
479 subroutine get_functional_from_pseudos(x_functional, c_functional)
480 integer, intent(out) :: x_functional
481 integer, intent(out) :: c_functional
482
483 integer :: xf, cf, ispecies
484 logical :: warned_inconsistent
485
486 x_functional = pseudo_exchange_any
487 c_functional = pseudo_correlation_any
488
489 warned_inconsistent = .false.
490 do ispecies = 1, ions%nspecies
491 select type(spec=>ions%species(ispecies)%s)
492 class is(pseudopotential_t)
493 xf = spec%x_functional()
494 cf = spec%c_functional()
495
496 if (xf == pseudo_exchange_unknown .or. cf == pseudo_correlation_unknown) then
497 call messages_write("Unknown XC functional for species '"//trim(ions%species(ispecies)%s%get_label())//"'")
498 call messages_warning(namespace=namespace)
499 cycle
500 end if
501
502 if (x_functional == pseudo_exchange_any) then
503 x_functional = xf
504 else
505 if (xf /= x_functional .and. .not. warned_inconsistent) then
506 call messages_write('Inconsistent XC functional detected between species')
507 call messages_warning(namespace=namespace)
508 warned_inconsistent = .true.
509 end if
510 end if
511
512 if (c_functional == pseudo_correlation_any) then
513 c_functional = cf
514 else
515 if (cf /= c_functional .and. .not. warned_inconsistent) then
516 call messages_write('Inconsistent XC functional detected between species')
517 call messages_warning(namespace=namespace)
518 warned_inconsistent = .true.
519 end if
520 end if
521
522 class default
525 end select
526
527 end do
528
529 assert(x_functional /= pseudo_exchange_unknown)
530 assert(c_functional /= pseudo_correlation_unknown)
531
532 end subroutine get_functional_from_pseudos
533 end subroutine v_ks_init
534 ! ---------------------------------------------------------
535
536 ! ---------------------------------------------------------
537 subroutine v_ks_end(ks)
538 type(v_ks_t), intent(inout) :: ks
539
540 push_sub(v_ks_end)
541
542 call ks%vdw%end()
543
544 select case (ks%theory_level)
545 case (kohn_sham_dft)
546 if (bitand(ks%xc_family, xc_family_ks_inversion) /= 0) then
547 call xc_ks_inversion_end(ks%ks_inversion)
548 end if
549 if (bitand(ks%xc_family, xc_family_oep) /= 0) then
550 call xc_oep_end(ks%oep)
551 end if
552 call xc_end(ks%xc)
554 call xc_end(ks%xc)
555 end select
556
557 call xc_sic_end(ks%sic)
558
559 if (ks%xc_photon /= 0) then
560 call ks%xc_photons%end()
561 end if
562
563 pop_sub(v_ks_end)
564 end subroutine v_ks_end
565 ! ---------------------------------------------------------
566
567
568 ! ---------------------------------------------------------
569 subroutine v_ks_write_info(ks, iunit, namespace)
570 type(v_ks_t), intent(in) :: ks
571 integer, optional, intent(in) :: iunit
572 type(namespace_t), optional, intent(in) :: namespace
573
575
576 call messages_print_with_emphasis(msg="Theory Level", iunit=iunit, namespace=namespace)
577 call messages_print_var_option("TheoryLevel", ks%theory_level, iunit=iunit, namespace=namespace)
578
579 select case (ks%theory_level)
581 call messages_info(iunit=iunit, namespace=namespace)
582 call xc_write_info(ks%xc, iunit, namespace)
583
584 case (kohn_sham_dft)
585 call messages_info(iunit=iunit, namespace=namespace)
586 call xc_write_info(ks%xc, iunit, namespace)
587
588 call messages_info(iunit=iunit, namespace=namespace)
589
590 call xc_sic_write_info(ks%sic, iunit, namespace)
591 call xc_oep_write_info(ks%oep, iunit, namespace)
592 call xc_ks_inversion_write_info(ks%ks_inversion, iunit, namespace)
593
594 end select
595
596 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
597
598 pop_sub(v_ks_write_info)
599 end subroutine v_ks_write_info
600 ! ---------------------------------------------------------
601
602
603 !----------------------------------------------------------
604 subroutine v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
605 type(namespace_t), intent(in) :: namespace
606 type(electron_space_t), intent(in) :: space
607 type(grid_t), intent(in) :: gr
608 type(ions_t), intent(in) :: ions
609 type(partner_list_t), intent(in) :: ext_partners
610 type(states_elec_t), intent(inout) :: st
611 type(v_ks_t), intent(inout) :: ks
612 type(hamiltonian_elec_t), intent(inout) :: hm
613 logical, optional, intent(in) :: calc_eigenval
614 logical, optional, intent(in) :: calc_current
615
616 integer, allocatable :: ind(:)
617 integer :: ist, ik
618 real(real64), allocatable :: copy_occ(:)
619 logical :: calc_eigenval_
620 logical :: calc_current_
621
622 push_sub(v_ks_h_setup)
623
624 calc_eigenval_ = optional_default(calc_eigenval, .true.)
625 calc_current_ = optional_default(calc_current, .true.)
626 call states_elec_fermi(st, namespace, gr)
627 call density_calc(st, gr, st%rho)
628 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
629 calc_eigenval = calc_eigenval_, calc_current = calc_current_) ! get potentials
630
631 if (st%restart_reorder_occs .and. .not. st%fromScratch) then
632 message(1) = "Reordering occupations for restart."
633 call messages_info(1, namespace=namespace)
634
635 safe_allocate(ind(1:st%nst))
636 safe_allocate(copy_occ(1:st%nst))
637
638 do ik = 1, st%nik
639 call sort(st%eigenval(:, ik), ind)
640 copy_occ(1:st%nst) = st%occ(1:st%nst, ik)
641 do ist = 1, st%nst
642 st%occ(ist, ik) = copy_occ(ind(ist))
643 end do
644 end do
645
646 safe_deallocate_a(ind)
647 safe_deallocate_a(copy_occ)
648 end if
649
650 if (calc_eigenval_) call states_elec_fermi(st, namespace, gr) ! occupations
651 call energy_calc_total(namespace, space, hm, gr, st, ext_partners)
652
653 pop_sub(v_ks_h_setup)
654 end subroutine v_ks_h_setup
655
656 ! ---------------------------------------------------------
657 subroutine v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
658 calc_eigenval, time, calc_energy, calc_current, force_semilocal)
659 type(v_ks_t), intent(inout) :: ks
660 type(namespace_t), intent(in) :: namespace
661 type(electron_space_t), intent(in) :: space
662 type(hamiltonian_elec_t), intent(inout) :: hm
663 type(states_elec_t), intent(inout) :: st
664 type(ions_t), intent(in) :: ions
665 type(partner_list_t), intent(in) :: ext_partners
666 logical, optional, intent(in) :: calc_eigenval
667 real(real64), optional, intent(in) :: time
668 logical, optional, intent(in) :: calc_energy
669 logical, optional, intent(in) :: calc_current
670 logical, optional, intent(in) :: force_semilocal
671
672 logical :: calc_current_
673
674 push_sub(v_ks_calc)
675
676 calc_current_ = optional_default(calc_current, .true.) &
677 .and. (ks%calculate_current &
678 .and. states_are_complex(st) &
680
681 if (calc_current_) then
682 call states_elec_allocate_current(st, space, ks%gr)
683 call current_calculate(ks%current_calculator, namespace, ks%gr, hm, space, st)
684 end if
685
686 call v_ks_calc_start(ks, namespace, space, hm, st, ions, hm%kpoints%latt, ext_partners, time, &
687 calc_energy, force_semilocal=force_semilocal)
688 call v_ks_calc_finish(ks, hm, namespace, space, hm%kpoints%latt, st, &
689 ext_partners, force_semilocal=force_semilocal)
690
691 if (optional_default(calc_eigenval, .false.)) then
692 call energy_calc_eigenvalues(namespace, hm, ks%gr%der, st)
693 end if
694
695 ! Update the magnetic constrain
696 call magnetic_constrain_update(hm%magnetic_constrain, ks%gr, st%d, space, hm%kpoints%latt, ions%pos, st%rho)
697 ! We add the potential to vxc, as this way the potential gets mixed together with vxc
698 ! While this is not ideal, this is a simple practical solution
699 if (hm%magnetic_constrain%level /= constrain_none) then
700 call lalg_axpy(ks%gr%np, st%d%nspin, m_one, hm%magnetic_constrain%pot, hm%ks_pot%vhxc)
701 end if
702
703 pop_sub(v_ks_calc)
704 end subroutine v_ks_calc
705
706 ! ---------------------------------------------------------
707
712 subroutine v_ks_calc_start(ks, namespace, space, hm, st, ions, latt, ext_partners, time, &
713 calc_energy, force_semilocal)
714 type(v_ks_t), target, intent(inout) :: ks
715 type(namespace_t), intent(in) :: namespace
716 class(space_t), intent(in) :: space
717 type(hamiltonian_elec_t), target, intent(in) :: hm
718 type(states_elec_t), target, intent(inout) :: st
719 type(ions_t), intent(in) :: ions
720 type(lattice_vectors_t), intent(in) :: latt
721 type(partner_list_t), intent(in) :: ext_partners
722 real(real64), optional, intent(in) :: time
723 logical, optional, intent(in) :: calc_energy
724 logical, optional, intent(in) :: force_semilocal
725
726 push_sub(v_ks_calc_start)
727
728 call profiling_in("KOHN_SHAM_CALC")
729
730 assert(.not. ks%calc%calculating)
731 ks%calc%calculating = .true.
732
733 write(message(1), '(a)') 'Debug: Calculating Kohn-Sham potential.'
734 call messages_info(1, namespace=namespace, debug_only=.true.)
735
736 ks%calc%time_present = present(time)
737 ks%calc%time = optional_default(time, m_zero)
738
739 ks%calc%calc_energy = optional_default(calc_energy, .true.)
740
741 ! If the Hxc term is frozen, there is nothing more to do (WARNING: MISSING ks%calc%energy%intnvxc)
742 if (ks%frozen_hxc) then
743 call profiling_out("KOHN_SHAM_CALC")
744 pop_sub(v_ks_calc_start)
745 return
746 end if
747
748 allocate(ks%calc%energy)
749
750 call energy_copy(hm%energy, ks%calc%energy)
751
752 ks%calc%energy%intnvxc = m_zero
753
754 nullify(ks%calc%total_density)
755
756 if (ks%theory_level /= independent_particles .and. abs(ks%sic%amaldi_factor) > m_epsilon) then
757
758 call calculate_density()
759
760 if (poisson_is_async(hm%psolver)) then
761 call dpoisson_solve_start(hm%psolver, ks%calc%total_density)
762 end if
763
764 if (ks%theory_level /= hartree .and. ks%theory_level /= rdmft) call v_a_xc(hm, force_semilocal)
765 else
766 ks%calc%total_density_alloc = .false.
767 end if
768
769 ! The exchange operator is computed from the states of the previous iteration
770 ! This is done by copying the state object to ks%calc%hf_st
771 ! For ACE, the states are the same in ks%calc%hf_st and st, as we compute the
772 ! ACE potential in v_ks_finish, so the copy is not needed
773 nullify(ks%calc%hf_st)
774 if (ks%theory_level == hartree .or. ks%theory_level == hartree_fock &
775 .or. ks%theory_level == rdmft .or. (ks%theory_level == generalized_kohn_sham_dft &
776 .and. family_is_hybrid(ks%xc))) then
777
778 if (st%parallel_in_states) then
779 if (accel_is_enabled()) then
780 call messages_write('State parallelization of Hartree-Fock exchange is not supported')
781 call messages_new_line()
782 call messages_write('when running with GPUs. Please use domain parallelization')
783 call messages_new_line()
784 call messages_write("or disable acceleration using 'DisableAccel = yes'.")
785 call messages_fatal(namespace=namespace)
786 end if
787 end if
788
789 if (hm%exxop%useACE) then
790 ks%calc%hf_st => st
791 else
792 safe_allocate(ks%calc%hf_st)
793 call states_elec_copy(ks%calc%hf_st, st)
794 end if
795 end if
796
797 ! Calculate the vector potential induced by the electronic current.
798 ! WARNING: calculating the self-induced magnetic field here only makes
799 ! sense if it is going to be used in the Hamiltonian, which does not happen
800 ! now. Otherwise one could just calculate it at the end of the calculation.
801 if (hm%self_induced_magnetic) then
802 safe_allocate(ks%calc%a_ind(1:ks%gr%np_part, 1:space%dim))
803 safe_allocate(ks%calc%b_ind(1:ks%gr%np_part, 1:space%dim))
804 call magnetic_induced(namespace, ks%gr, st, hm%psolver, hm%kpoints, ks%calc%a_ind, ks%calc%b_ind)
805 end if
806
807 if ((ks%has_photons) .and. (ks%calc%time_present) .and. (ks%xc_photon == 0) ) then
808 call mf_calc(ks%pt_mx, ks%gr, st, ions, ks%pt, time)
809 end if
810
811 ! if (ks%has_vibrations) then
812 ! call vibrations_eph_coup(ks%vib, ks%gr, hm, ions, st)
813 ! end if
814
815 call profiling_out("KOHN_SHAM_CALC")
816 pop_sub(v_ks_calc_start)
817
818 contains
819
820 subroutine calculate_density()
821 integer :: ip
822
824
825 ! get density taking into account non-linear core corrections
826 safe_allocate(ks%calc%density(1:ks%gr%np, 1:st%d%nspin))
827 call states_elec_total_density(st, ks%gr, ks%calc%density)
828
829 ! Amaldi correction on CPU
830 if (ks%sic%level == sic_amaldi) then
831 call lalg_scal(ks%gr%np, st%d%nspin, ks%sic%amaldi_factor, ks%calc%density)
832 end if
833
834 ! GPU counterpart of the CPU corrections above: the CPU path includes rho_core, frozen_rho,
835 ! and Amaldi scaling directly into ks%calc%density before calling xc_get_vxc.
836 ! On the GPU we cannot do the same to st%buff_density because:
837 ! - it is in wavefunction storage layout (pnp, nspin) while libxc expects (spin_channels, np)
838 ! - permanently modifying st%buff_density would corrupt the density for subsequent SCF steps.
839 ! Instead we upload the correction arrays here so that xc_update_internal_quantities can apply
840 ! them to dens_buff (already in libxc layout) via the xc_dens_apply_corrections kernel,
841 ! immediately after the xc_dens_extract_block kernel runs.
842 if (.not. ks%xc%xc_on_host .and. accel_buffer_is_allocated(st%buff_density)) then
843 if (allocated(st%rho_core)) then
844 call accel_create_buffer(ks%xc%quantities%buff_rho_core, &
845 accel_mem_read_only, type_float, int(ks%gr%np, int64))
846 call accel_write_buffer(ks%xc%quantities%buff_rho_core, &
847 int(ks%gr%np, int64), st%rho_core)
848 end if
849 if (allocated(st%frozen_rho)) then
850 call accel_create_buffer(ks%xc%quantities%buff_frozen_rho, &
851 accel_mem_read_only, type_float, int(ks%gr%np, int64)*int(st%d%nspin, int64))
852 call accel_write_buffer(ks%xc%quantities%buff_frozen_rho, &
853 int(ks%gr%np, int64), int(st%d%nspin, int64), st%frozen_rho)
854 ks%xc%quantities%frozen_rho_np = ks%gr%np
855 end if
856 if (ks%sic%level == sic_amaldi) then
857 ks%xc%quantities%amaldi_factor = ks%sic%amaldi_factor
858 end if
859 end if
860
861 nullify(ks%calc%total_density)
862 if (allocated(st%rho_core) .or. hm%d%spin_channels > 1) then
863 ks%calc%total_density_alloc = .true.
864
865 safe_allocate(ks%calc%total_density(1:ks%gr%np))
866
867 do ip = 1, ks%gr%np
868 ks%calc%total_density(ip) = sum(ks%calc%density(ip, 1:hm%d%spin_channels))
869 end do
870
871 ! remove non-local core corrections
872 if (allocated(st%rho_core)) then
873 call lalg_axpy(ks%gr%np, -ks%sic%amaldi_factor, st%rho_core, ks%calc%total_density)
874 end if
875 else
876 ks%calc%total_density_alloc = .false.
877 ks%calc%total_density => ks%calc%density(:, 1)
878 end if
879
881 end subroutine calculate_density
882
883 ! ---------------------------------------------------------
884 subroutine v_a_xc(hm, force_semilocal)
885 type(hamiltonian_elec_t), intent(in) :: hm
886 logical, optional, intent(in) :: force_semilocal
887
888 integer :: ispin
889
890 push_sub(v_ks_calc_start.v_a_xc)
891 call profiling_in("XC")
892
893 ks%calc%energy%exchange = m_zero
894 ks%calc%energy%correlation = m_zero
895 ks%calc%energy%xc_j = m_zero
896 ks%calc%energy%vdw = m_zero
897
898 allocate(ks%calc%vxc(1:ks%gr%np, 1:st%d%nspin))
899 ks%calc%vxc = m_zero
900
901 if (family_is_mgga_with_exc(hm%xc)) then
902 safe_allocate(ks%calc%vtau(1:ks%gr%np, 1:st%d%nspin))
903 ks%calc%vtau = m_zero
904 end if
905
906 ! Get the *local* XC term
907 if (ks%calc%calc_energy) then
908 if (family_is_mgga_with_exc(hm%xc)) then
909 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, st%d%ispin, &
910 latt%rcell_volume, ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation, &
911 deltaxc = ks%calc%energy%delta_xc, vtau = ks%calc%vtau, force_orbitalfree=force_semilocal)
912 else
913 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, st%d%ispin, &
914 latt%rcell_volume, ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation, &
915 deltaxc = ks%calc%energy%delta_xc, stress_xc=ks%stress_xc_gga, force_orbitalfree=force_semilocal)
916 end if
917 else
918 if (family_is_mgga_with_exc(hm%xc)) then
919 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, &
920 st%d%ispin, latt%rcell_volume, ks%calc%vxc, vtau = ks%calc%vtau, force_orbitalfree=force_semilocal)
921 else
922 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, &
923 st%d%ispin, latt%rcell_volume, ks%calc%vxc, stress_xc=ks%stress_xc_gga, force_orbitalfree=force_semilocal)
924 end if
925 end if
926
927 !Noncollinear functionals
928 if (bitand(hm%xc%family, xc_family_nc_lda + xc_family_nc_mgga) /= 0) then
929 if (st%d%ispin /= spinors) then
930 message(1) = "Noncollinear functionals can only be used with spinor wavefunctions."
931 call messages_fatal(1)
932 end if
933
934 if (optional_default(force_semilocal, .false.)) then
935 message(1) = "Cannot perform LCAO for noncollinear MGGAs."
936 message(2) = "Please perform a LDA calculation first."
937 call messages_fatal(2)
938 end if
939
940 if (ks%calc%calc_energy) then
941 if (family_is_mgga_with_exc(hm%xc)) then
942 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc, &
943 vtau = ks%calc%vtau, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
944 else
945 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc, &
946 ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
947 end if
948 else
949 if (family_is_mgga_with_exc(hm%xc)) then
950 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, &
951 ks%calc%vxc, vtau = ks%calc%vtau)
952 else
953 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc)
954 end if
955 end if
956 end if
957
958 call ks%vdw%calc(namespace, space, latt, ions%atom, ions%natoms, ions%pos, &
959 ks%gr, st, ks%calc%energy%vdw, ks%calc%vxc)
960
961 if (optional_default(force_semilocal, .false.)) then
962 call profiling_out("XC")
963 pop_sub(v_ks_calc_start.v_a_xc)
964 return
965 end if
966
967 ! ADSIC correction
968 if (ks%sic%level == sic_adsic) then
969 if (family_is_mgga(hm%xc%family)) then
970 call messages_not_implemented('ADSIC with MGGAs', namespace=namespace)
971 end if
972 if (ks%calc%calc_energy) then
973 call xc_sic_calc_adsic(ks%sic, namespace, space, ks%gr, st, hm, ks%xc, ks%calc%density, &
974 ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
975 else
976 call xc_sic_calc_adsic(ks%sic, namespace, space, ks%gr, st, hm, ks%xc, ks%calc%density, &
977 ks%calc%vxc)
978 end if
979 end if
980 !PZ SIC is done in the finish routine as OEP full needs to update the Hamiltonian
981
982 if (ks%theory_level == kohn_sham_dft) then
983 ! The OEP family has to be handled specially
984 ! Note that OEP is done in the finish state, as it requires updating the Hamiltonian and needs the new Hartre and vxc term
985 if (bitand(ks%xc_family, xc_family_oep) /= 0 .or. family_is_mgga_with_exc(ks%xc)) then
986
987 if (ks%xc%functional(func_x,1)%id == xc_oep_x_slater) then
988 call x_slater_calc(namespace, ks%gr, space, hm%exxop, st, hm%kpoints, ks%calc%energy%exchange, &
989 vxc = ks%calc%vxc)
990 else if (ks%xc%functional(func_x,1)%id == xc_oep_x_fbe .or. ks%xc%functional(func_x,1)%id == xc_oep_x_fbe_sl) then
991 call x_fbe_calc(ks%xc%functional(func_x,1)%id, namespace, hm%psolver, ks%gr, st, space, &
992 ks%calc%energy%exchange, vxc = ks%calc%vxc)
993
994 else if (ks%xc%functional(func_c,1)%id == xc_lda_c_fbe_sl) then
995
996 call fbe_c_lda_sl(namespace, ks%gr, st, space, ks%calc%energy%correlation, vxc = ks%calc%vxc)
997
998 end if
999
1000 end if
1001
1002 if (bitand(ks%xc_family, xc_family_ks_inversion) /= 0) then
1003 ! Also treat KS inversion separately (not part of libxc)
1004 call xc_ks_inversion_calc(ks%ks_inversion, namespace, space, ks%gr, hm, ext_partners, st, vxc = ks%calc%vxc, &
1005 time = ks%calc%time)
1006 end if
1007
1008 ! compute the photon-free photon exchange potential and energy
1009 if (ks%xc_photon /= 0) then
1010
1011 call ks%xc_photons%v_ks(namespace, ks%calc%total_density, ks%gr, space, hm%psolver, st)
1012
1013 ! add the photon-free px potential into the xc potential
1014 do ispin = 1, hm%d%spin_channels
1015 call lalg_axpy(ks%gr%np, m_one, ks%xc_photons%vpx(1:ks%gr%np), ks%calc%vxc(1:ks%gr%np, ispin) )
1016 end do
1017
1018 ! photon-exchange energy
1019 ks%calc%energy%photon_exchange = ks%xc_photons%ex
1020 end if
1021
1022 end if
1023
1024 if (ks%calc%calc_energy) then
1025 ! MGGA vtau contribution is done after copying vtau to hm%vtau
1026
1027 call v_ks_update_dftu_energy(ks, namespace, hm, st, ks%calc%energy%int_dft_u)
1028 end if
1029
1030 call profiling_out("XC")
1031 pop_sub(v_ks_calc_start.v_a_xc)
1032 end subroutine v_a_xc
1033
1034 end subroutine v_ks_calc_start
1035 ! ---------------------------------------------------------
1036
1037 subroutine v_ks_calc_finish(ks, hm, namespace, space, latt, st, ext_partners, force_semilocal)
1038 type(v_ks_t), target, intent(inout) :: ks
1039 type(hamiltonian_elec_t), intent(inout) :: hm
1040 type(namespace_t), intent(in) :: namespace
1041 class(space_t), intent(in) :: space
1042 type(lattice_vectors_t), intent(in) :: latt
1043 type(states_elec_t), intent(inout) :: st
1044 type(partner_list_t), intent(in) :: ext_partners
1045 logical, optional, intent(in) :: force_semilocal
1046
1047 integer :: ip, ispin
1048 type(states_elec_t) :: xst
1050 real(real64) :: exx_energy
1051 real(real64) :: factor
1052
1053 push_sub(v_ks_calc_finish)
1054
1055 assert(ks%calc%calculating)
1056 ks%calc%calculating = .false.
1057
1058 if (ks%frozen_hxc) then
1059 pop_sub(v_ks_calc_finish)
1060 return
1061 end if
1062
1063 !change the pointer to the energy object
1064 safe_deallocate_a(hm%energy)
1065 call move_alloc(ks%calc%energy, hm%energy)
1066
1067 if (hm%self_induced_magnetic) then
1068 hm%a_ind(1:ks%gr%np, 1:space%dim) = ks%calc%a_ind(1:ks%gr%np, 1:space%dim)
1069 hm%b_ind(1:ks%gr%np, 1:space%dim) = ks%calc%b_ind(1:ks%gr%np, 1:space%dim)
1070
1071 safe_deallocate_a(ks%calc%a_ind)
1072 safe_deallocate_a(ks%calc%b_ind)
1073 end if
1074
1075 if (allocated(hm%v_static)) then
1076 hm%energy%intnvstatic = dmf_dotp(ks%gr, ks%calc%total_density, hm%v_static)
1077 else
1078 hm%energy%intnvstatic = m_zero
1079 end if
1080
1081 if (ks%theory_level == independent_particles .or. abs(ks%sic%amaldi_factor) <= m_epsilon) then
1082
1083 hm%ks_pot%vhxc = m_zero
1084 hm%energy%intnvxc = m_zero
1085 hm%energy%hartree = m_zero
1086 hm%energy%exchange = m_zero
1087 hm%energy%exchange_hf = m_zero
1088 hm%energy%correlation = m_zero
1089 else
1090
1091 hm%energy%hartree = m_zero
1092 call v_ks_hartree(namespace, ks, space, hm, ext_partners)
1093
1094 if (.not. optional_default(force_semilocal, .false.)) then
1095 !PZ-SIC
1096 if(ks%sic%level == sic_pz_oep) then
1097 if (states_are_real(st)) then
1098 call dxc_oep_calc(ks%sic%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1099 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1100 else
1101 call zxc_oep_calc(ks%sic%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1102 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1103 end if
1104 end if
1105
1106 ! OEP for exchange ad MGGAs (within Kohn-Sham DFT)
1107 if (ks%theory_level == kohn_sham_dft .and. ks%oep%level /= oep_level_none) then
1108 ! The OEP family has to be handled specially
1109 if (ks%xc%functional(func_x,1)%id == xc_oep_x .or. family_is_mgga_with_exc(ks%xc)) then
1110 if (states_are_real(st)) then
1111 call dxc_oep_calc(ks%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1112 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1113 else
1114 call zxc_oep_calc(ks%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1115 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1116 end if
1117 end if
1118 end if
1119 end if
1120
1121 if (ks%theory_level == kohn_sham_dft .and. ks%oep_photon%level /= oep_level_none) then
1122 if (states_are_real(st)) then
1123 call dxc_oep_photon_calc(ks%oep_photon, namespace, ks%xc, ks%gr, &
1124 hm, st, space, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1125 else
1126 call zxc_oep_photon_calc(ks%oep_photon, namespace, ks%xc, ks%gr, &
1127 hm, st, space, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1128 end if
1129 hm%energy%photon_exchange = ks%oep_photon%pt%ex
1130 end if
1131
1133 if (ks%calc%calc_energy) then
1134 ! Now we calculate Int[n vxc] = energy%intnvxc
1135 hm%energy%intnvxc = m_zero
1136
1137 if (ks%theory_level /= independent_particles .and. ks%theory_level /= hartree .and. ks%theory_level /= rdmft) then
1138 do ispin = 1, hm%d%nspin
1139 if (ispin <= 2) then
1140 factor = m_one
1141 else
1142 factor = m_two
1143 end if
1144 hm%energy%intnvxc = hm%energy%intnvxc + &
1145 factor*dmf_dotp(ks%gr, st%rho(:, ispin), ks%calc%vxc(:, ispin), reduce = .false.)
1146 end do
1147 call ks%gr%allreduce(hm%energy%intnvxc)
1148 end if
1149 end if
1150
1151
1152 if (ks%theory_level /= hartree .and. ks%theory_level /= rdmft) then
1153 ! move allocation of vxc from ks%calc to hm
1154 safe_deallocate_a(hm%ks_pot%vxc)
1155 call move_alloc(ks%calc%vxc, hm%ks_pot%vxc)
1156
1157 if (family_is_mgga_with_exc(hm%xc)) then
1158 call hm%ks_pot%set_vtau(ks%calc%vtau)
1159 safe_deallocate_a(ks%calc%vtau)
1160
1161 ! We need to evaluate the energy after copying vtau to hm%vtau
1162 if (ks%theory_level == generalized_kohn_sham_dft .and. ks%calc%calc_energy) then
1163 ! MGGA vtau contribution
1164 if (states_are_real(st)) then
1165 hm%energy%intnvxc = hm%energy%intnvxc &
1166 + denergy_calc_electronic(namespace, hm, ks%gr%der, st, terms = term_mgga)
1167 else
1168 hm%energy%intnvxc = hm%energy%intnvxc &
1169 + zenergy_calc_electronic(namespace, hm, ks%gr%der, st, terms = term_mgga)
1170 end if
1171 end if
1172 end if
1173
1174 else
1175 hm%ks_pot%vxc = m_zero
1176 end if
1177
1178 if (.not. ks%xc_photon_include_hartree) then
1179 hm%energy%hartree = m_zero
1180 hm%ks_pot%vhartree = m_zero
1181 end if
1182
1183 ! Build Hartree + XC potential
1184
1185 do ip = 1, ks%gr%np
1186 hm%ks_pot%vhxc(ip, 1) = hm%ks_pot%vxc(ip, 1) + hm%ks_pot%vhartree(ip)
1187 end do
1188 if (allocated(hm%vberry)) then
1189 do ip = 1, ks%gr%np
1190 hm%ks_pot%vhxc(ip, 1) = hm%ks_pot%vhxc(ip, 1) + hm%vberry(ip, 1)
1191 end do
1192 end if
1193
1194 if (hm%d%ispin > unpolarized) then
1195 do ip = 1, ks%gr%np
1196 hm%ks_pot%vhxc(ip, 2) = hm%ks_pot%vxc(ip, 2) + hm%ks_pot%vhartree(ip)
1197 end do
1198 if (allocated(hm%vberry)) then
1199 do ip = 1, ks%gr%np
1200 hm%ks_pot%vhxc(ip, 2) = hm%ks_pot%vhxc(ip, 2) + hm%vberry(ip, 2)
1201 end do
1202 end if
1203 end if
1204
1205 if (hm%d%ispin == spinors) then
1206 do ispin=3, 4
1207 do ip = 1, ks%gr%np
1208 hm%ks_pot%vhxc(ip, ispin) = hm%ks_pot%vxc(ip, ispin)
1209 end do
1210 end do
1211 end if
1212
1213 ! Note: this includes hybrids calculated with the Fock operator instead of OEP
1214 hm%energy%exchange_hf = m_zero
1215 if (ks%theory_level == hartree .or. ks%theory_level == hartree_fock &
1216 .or. ks%theory_level == rdmft &
1217 .or. (ks%theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(ks%xc))) then
1218
1219 ! swap the states object
1220 if (.not. hm%exxop%useACE) then
1221 ! We also close the MPI remote memory access to the old object
1222 if (associated(hm%exxop%st)) then
1224 call states_elec_end(hm%exxop%st)
1225 safe_deallocate_p(hm%exxop%st)
1226 end if
1227 ! We activate the MPI remote memory access for ks%calc%hf_st
1228 ! This allows to have all calls to exchange_operator_apply_standard to access
1229 ! the states over MPI
1231 end if
1232
1233 ! The exchange operator will use ks%calc%hf_st
1234 ! For the ACE case, this is the same as st
1235 if (.not. optional_default(force_semilocal, .false.)) then
1236 select case (ks%theory_level)
1238 if (family_is_hybrid(ks%xc)) then
1239 call exchange_operator_reinit(hm%exxop, ks%xc%cam, ks%calc%hf_st)
1240 end if
1241 case (hartree_fock)
1242 call exchange_operator_reinit(hm%exxop, ks%xc%cam, ks%calc%hf_st)
1243 case (hartree, rdmft)
1244 call exchange_operator_reinit(hm%exxop, cam_exact_exchange, ks%calc%hf_st)
1245 end select
1246
1247 !This should be changed and the CAM parameters should also be obtained from the restart information
1248 !Maybe the parameters should be mixed too.
1249 exx_energy = m_zero
1250 if (hm%exxop%useACE) then
1251 call xst%nullify()
1252 if (states_are_real(ks%calc%hf_st)) then
1253 ! TODO(Alex) Clean up nested if statements
1254 if (hm%exxop%with_isdf) then
1255 ! Find interpolation points from density, or read from file
1256 ! TODO(Alex) Issue #1195 Extend ISDF to spin-polarised systems
1257 call hm%exxop%isdf%get_interpolation_points(namespace, space, ks%gr, st%rho(1:ks%gr%np, 1))
1258 call isdf_ace_compute_potentials(hm%exxop, namespace, space, ks%gr, &
1259 ks%calc%hf_st, xst, hm%kpoints)
1260 else
1261 call dexchange_operator_compute_potentials(hm%exxop, namespace, space, ks%gr, &
1262 ks%calc%hf_st, xst, hm%kpoints)
1263 endif
1264 exx_energy = dexchange_operator_compute_ex(ks%gr, ks%calc%hf_st, xst)
1265 call dexchange_operator_ace(hm%exxop, namespace, ks%gr, ks%calc%hf_st, xst)
1266 else
1267 call zexchange_operator_compute_potentials(hm%exxop, namespace, space, ks%gr, &
1268 ks%calc%hf_st, xst, hm%kpoints)
1269 exx_energy = zexchange_operator_compute_ex(ks%gr, ks%calc%hf_st, xst)
1270 if (hm%phase%is_allocated()) then
1271 call zexchange_operator_ace(hm%exxop, namespace, ks%gr, ks%calc%hf_st, xst, hm%phase)
1272 else
1273 call zexchange_operator_ace(hm%exxop, namespace, ks%gr, ks%calc%hf_st, xst)
1274 end if
1275 end if
1276 call states_elec_end(xst)
1277 exx_energy = exx_energy + hm%exxop%singul%energy
1278 end if
1279
1280 ! Add the energy only the ACE case. In the non-ACE case, the singularity energy is added in energy_calc.F90
1281 select case (ks%theory_level)
1283 if (family_is_hybrid(ks%xc)) then
1284 hm%energy%exchange_hf = hm%energy%exchange_hf + exx_energy
1285 end if
1286 case (hartree_fock)
1287 hm%energy%exchange_hf = hm%energy%exchange_hf + exx_energy
1288 end select
1289 else
1290 ! If we ask for semilocal, we deactivate the exchange operator entirely
1291 call exchange_operator_reinit(hm%exxop, cam_null, ks%calc%hf_st)
1292 end if
1293 end if
1294
1295 end if
1296
1297 ! Because of the intent(in) in v_ks_calc_start, we need to update the parameters of hybrids for OEP
1298 ! here
1299 if (ks%theory_level == kohn_sham_dft .and. bitand(ks%xc_family, xc_family_oep) /= 0) then
1300 if (ks%xc%functional(func_x,1)%id /= xc_oep_x_slater .and. ks%xc%functional(func_x,1)%id /= xc_oep_x_fbe) then
1301 call exchange_operator_reinit(hm%exxop, ks%xc%cam)
1302 end if
1303 end if
1304
1305 if (ks%has_photons .and. (ks%xc_photon == 0)) then
1306 if (associated(ks%pt_mx%vmf)) then
1307 call lalg_axpy(ks%gr%np, m_one, ks%pt_mx%vmf, hm%ks_pot%vhxc(:, 1))
1308 if (hm%d%ispin > unpolarized) then
1309 call lalg_axpy(ks%gr%np, m_one, ks%pt_mx%vmf, hm%ks_pot%vhxc(:, 2))
1310 end if
1311 end if
1312 hm%ep%photon_forces(1:space%dim) = ks%pt_mx%fmf(1:space%dim)
1313 end if
1314
1315 if (ks%vdw%vdw_correction /= option__vdwcorrection__none) then
1316 assert(allocated(ks%vdw%forces))
1317 hm%ep%vdw_forces(:, :) = ks%vdw%forces(:, :)
1318 hm%ep%vdw_stress = ks%vdw%stress
1319 safe_deallocate_a(ks%vdw%forces)
1320 else
1321 hm%ep%vdw_forces = 0.0_real64
1322 end if
1323
1324 if (ks%calc%time_present .or. hm%time_zero) then
1325 call hm%update(ks%gr, namespace, space, ext_partners, time = ks%calc%time)
1326 else
1327 call hamiltonian_elec_update_pot(hm, ks%gr)
1328 end if
1329
1330
1331 safe_deallocate_a(ks%calc%density)
1332 if (ks%calc%total_density_alloc) then
1333 safe_deallocate_p(ks%calc%total_density)
1334 end if
1335 nullify(ks%calc%total_density)
1336
1337 pop_sub(v_ks_calc_finish)
1338 end subroutine v_ks_calc_finish
1339
1340
1343 !
1344 !! TODO(Alex) Once the implementation is finalised and benchmarked
1345 !! remove the serial version, and get rid of this routine.
1346 subroutine isdf_ace_compute_potentials(exxop, namespace, space, gr, hf_st, xst, kpoints)
1347 type(exchange_operator_t), intent(in ) :: exxop
1348 type(namespace_t), intent(in ) :: namespace
1349 class(space_t), intent(in ) :: space
1350 class(mesh_t), intent(in ) :: gr
1351 type(states_elec_t), intent(in ) :: hf_st
1352 type(kpoints_t), intent(in ) :: kpoints
1353
1354 type(states_elec_t), intent(inout) :: xst
1355
1356 if (exxop%isdf%use_serial) then
1357 call isdf_serial_ace_compute_potentials(exxop, namespace, space, gr, &
1358 hf_st, xst, kpoints)
1359 else
1360 call isdf_parallel_ace_compute_potentials(exxop, namespace, space, gr, &
1361 hf_st, xst, kpoints)
1362 endif
1363
1364 end subroutine isdf_ace_compute_potentials
1365
1366 ! ---------------------------------------------------------
1367 !
1371 !
1372 subroutine v_ks_hartree(namespace, ks, space, hm, ext_partners)
1373 type(namespace_t), intent(in) :: namespace
1374 type(v_ks_t), intent(inout) :: ks
1375 class(space_t), intent(in) :: space
1376 type(hamiltonian_elec_t), intent(inout) :: hm
1377 type(partner_list_t), intent(in) :: ext_partners
1378
1379 push_sub(v_ks_hartree)
1380
1381 if (.not. poisson_is_async(hm%psolver)) then
1382 ! solve the Poisson equation
1383 call dpoisson_solve(hm%psolver, namespace, hm%ks_pot%vhartree, ks%calc%total_density, reset=.false.)
1384 else
1385 ! The calculation was started by v_ks_calc_start.
1386 call dpoisson_solve_finish(hm%psolver, hm%ks_pot%vhartree)
1387 end if
1388
1389 if (ks%calc%calc_energy) then
1390 ! Get the Hartree energy
1391 hm%energy%hartree = m_half*dmf_dotp(ks%gr, ks%calc%total_density, hm%ks_pot%vhartree)
1392 end if
1393
1395 if(ks%calc%time_present) then
1396 if(hamiltonian_elec_has_kick(hm)) then
1397 call pcm_hartree_potential(hm%pcm, space, ks%gr, hm%psolver, ext_partners, hm%ks_pot%vhartree, &
1398 ks%calc%total_density, hm%energy%pcm_corr, kick=hm%kick, time=ks%calc%time)
1399 else
1400 call pcm_hartree_potential(hm%pcm, space, ks%gr, hm%psolver, ext_partners, hm%ks_pot%vhartree, &
1401 ks%calc%total_density, hm%energy%pcm_corr, time=ks%calc%time)
1402 end if
1403 else
1404 if(hamiltonian_elec_has_kick(hm)) then
1405 call pcm_hartree_potential(hm%pcm, space, ks%gr, hm%psolver, ext_partners, hm%ks_pot%vhartree, &
1406 ks%calc%total_density, hm%energy%pcm_corr, kick=hm%kick)
1407 else
1408 call pcm_hartree_potential(hm%pcm, space, ks%gr, hm%psolver, ext_partners, hm%ks_pot%vhartree, &
1409 ks%calc%total_density, hm%energy%pcm_corr)
1410 end if
1411 end if
1412
1413 pop_sub(v_ks_hartree)
1414 end subroutine v_ks_hartree
1415 ! ---------------------------------------------------------
1416
1417
1418 ! ---------------------------------------------------------
1419 subroutine v_ks_freeze_hxc(ks)
1420 type(v_ks_t), intent(inout) :: ks
1421
1422 push_sub(v_ks_freeze_hxc)
1423
1424 ks%frozen_hxc = .true.
1425
1426 pop_sub(v_ks_freeze_hxc)
1427 end subroutine v_ks_freeze_hxc
1428 ! ---------------------------------------------------------
1429
1430 subroutine v_ks_calculate_current(this, calc_cur)
1431 type(v_ks_t), intent(inout) :: this
1432 logical, intent(in) :: calc_cur
1433
1434 push_sub(v_ks_calculate_current)
1435
1436 this%calculate_current = calc_cur
1437
1438 pop_sub(v_ks_calculate_current)
1439 end subroutine v_ks_calculate_current
1440
1442 subroutine v_ks_update_dftu_energy(ks, namespace, hm, st, int_dft_u)
1443 type(v_ks_t), intent(inout) :: ks
1444 type(hamiltonian_elec_t), intent(in) :: hm
1445 type(namespace_t), intent(in) :: namespace
1446 type(states_elec_t), intent(inout) :: st
1447 real(real64), intent(out) :: int_dft_u
1448
1449 int_dft_u = m_zero
1450 if (hm%lda_u_level == dft_u_none) return
1451
1452 push_sub(v_ks_update_dftu_energy)
1453
1454 if (states_are_real(st)) then
1455 int_dft_u = denergy_calc_electronic(namespace, hm, ks%gr%der, st, terms = term_dft_u)
1456 else
1457 int_dft_u = zenergy_calc_electronic(namespace, hm, ks%gr%der, st, terms = term_dft_u)
1458 end if
1459
1461 end subroutine v_ks_update_dftu_energy
1462end module v_ks_oct_m
1463
1464!! Local Variables:
1465!! mode: f90
1466!! coding: utf-8
1467!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:173
scales a vector by a constant
Definition: lalg_basic.F90:159
This is the common interface to a sorting routine. It performs the shell algorithm,...
Definition: sort.F90:156
logical pure function, public accel_buffer_is_allocated(this)
Definition: accel.F90:1116
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
integer, parameter, public accel_mem_read_only
Definition: accel.F90:186
subroutine, public current_calculate(this, namespace, gr, hm, space, st)
Compute total electronic current density.
Definition: current.F90:372
subroutine, public current_init(this, namespace)
Definition: current.F90:180
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public states_elec_total_density(st, mesh, total_rho)
This routine calculates the total electronic density.
Definition: density.F90:892
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
real(real64) function, public zenergy_calc_electronic(namespace, hm, der, st, terms)
real(real64) function, public denergy_calc_electronic(namespace, hm, der, st, terms)
subroutine, public energy_calc_eigenvalues(namespace, hm, der, st)
subroutine, public energy_copy(ein, eout)
Definition: energy.F90:170
subroutine, public dexchange_operator_ace(this, namespace, mesh, st, xst, phase)
subroutine, public zexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public exchange_operator_reinit(this, cam, st)
subroutine, public dexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public zexchange_operator_ace(this, namespace, mesh, st, xst, phase)
real(real64) function, public dexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
real(real64) function, public zexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
integer, parameter, public rdmft
Definition: global.F90:250
integer, parameter, public hartree_fock
Definition: global.F90:250
integer, parameter, public independent_particles
Theory level.
Definition: global.F90:250
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
integer, parameter, public hartree
Definition: global.F90:250
This module implements the underlying real-space grid.
Definition: grid.F90:119
integer, parameter, public term_mgga
integer, parameter, public term_dft_u
logical function, public hamiltonian_elec_has_kick(hm)
logical function, public hamiltonian_elec_needs_current(hm, states_are_real)
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
This module defines classes and functions for interaction partners.
Interoperable Separable Density Fitting (ISDF) molecular implementation.
Definition: isdf.F90:116
subroutine, public isdf_ace_compute_potentials(exxop, namespace, space, mesh, st, Vx_on_st, kpoints)
ISDF wrapper computing interpolation points and vectors, which are used to build the potential used ...
Definition: isdf.F90:161
Serial prototype for benchmarking and validating ISDF implementation.
subroutine, public isdf_serial_ace_compute_potentials(exxop, namespace, space, mesh, st, Vx_on_st, kpoints)
ISDF wrapper computing interpolation points and vectors, which are used to build the potential used ...
A module to handle KS potential, without the external potential.
integer, parameter, public dft_u_none
Definition: lda_u.F90:205
This modules implements the routines for doing constrain DFT for noncollinear magnetism.
integer, parameter, public constrain_none
subroutine, public magnetic_constrain_update(this, mesh, std, space, latt, pos, rho)
Recomputes the magnetic contraining potential.
subroutine, public magnetic_induced(namespace, gr, st, psolver, kpoints, a_ind, b_ind)
This subroutine receives as input a current, and produces as an output the vector potential that it i...
Definition: magnetic.F90:517
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
subroutine, public messages_new_line()
Definition: messages.F90:1089
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
subroutine, public pcm_hartree_potential(pcm, space, mesh, psolver, ext_partners, vhartree, density, pcm_corr, kick, time)
PCM reaction field due to the electronic density.
subroutine, public mf_calc(this, gr, st, ions, pt_mode, time)
subroutine, public dpoisson_solve_start(this, rho)
Definition: poisson.F90:2002
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:862
subroutine, public dpoisson_solve_finish(this, pot)
Definition: poisson.F90:2010
logical pure function, public poisson_is_async(this)
Definition: poisson.F90:1118
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
integer, parameter, public pseudo_exchange_unknown
Definition: pseudo.F90:190
integer, parameter, public pseudo_correlation_unknown
Definition: pseudo.F90:194
integer, parameter, public pseudo_correlation_any
Definition: pseudo.F90:194
integer, parameter, public pseudo_exchange_any
Definition: pseudo.F90:190
This module is intended to contain "only mathematical" functions and procedures.
Definition: sort.F90:119
integer, parameter, private libxc_c_index
Definition: species.F90:280
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special)
make a (selective) copy of a states_elec_t object
subroutine, public states_elec_allocate_current(st, space, mesh)
This module provides routines for communicating states when using states parallelization.
subroutine, public states_elec_parallel_remote_access_stop(this)
stop remote memory access for states on other processors
subroutine, public states_elec_parallel_remote_access_start(this)
start remote memory access for states on other processors
type(type_t), parameter, public type_float
Definition: types.F90:135
subroutine v_ks_hartree(namespace, ks, space, hm, ext_partners)
Hartree contribution to the KS potential. This function is designed to be used by v_ks_calc_finish an...
Definition: v_ks.F90:1468
subroutine, public v_ks_calc_finish(ks, hm, namespace, space, latt, st, ext_partners, force_semilocal)
Definition: v_ks.F90:1133
subroutine, public v_ks_freeze_hxc(ks)
Definition: v_ks.F90:1515
subroutine, public v_ks_end(ks)
Definition: v_ks.F90:633
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1526
subroutine, public v_ks_write_info(ks, iunit, namespace)
Definition: v_ks.F90:665
subroutine, public v_ks_update_dftu_energy(ks, namespace, hm, st, int_dft_u)
Update the value of <\psi | V_U | \psi>, where V_U is the DFT+U potential.
Definition: v_ks.F90:1538
subroutine, public v_ks_calc_start(ks, namespace, space, hm, st, ions, latt, ext_partners, time, calc_energy, force_semilocal)
This routine starts the calculation of the Kohn-Sham potential. The routine v_ks_calc_finish must be ...
Definition: v_ks.F90:809
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:754
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:700
subroutine, public v_ks_init(ks, namespace, gr, st, ions, mc, space, kpoints)
Definition: v_ks.F90:256
subroutine, public x_slater_calc(namespace, gr, space, exxop, st, kpoints, ex, vxc)
Interface to X(slater_calc)
Definition: x_slater.F90:147
type(xc_cam_t), parameter, public cam_null
All CAM parameters set to zero.
Definition: xc_cam.F90:152
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
Definition: xc_cam.F90:155
subroutine, public x_fbe_calc(id, namespace, psolver, gr, st, space, ex, vxc)
Interface to X(x_fbe_calc) Two possible run modes possible: adiabatic and Sturm-Liouville....
Definition: xc_fbe.F90:173
subroutine, public fbe_c_lda_sl(namespace, gr, st, space, ec, vxc)
Sturm-Liouville version of the FBE local-density correlation functional.
Definition: xc_fbe.F90:462
integer, parameter, public xc_family_ks_inversion
declaring 'family' constants for 'functionals' not handled by libxc careful not to use a value define...
integer function, public xc_get_default_functional(dim, pseudo_x_functional, pseudo_c_functional)
Returns the default functional given the one parsed from the pseudopotentials and the space dimension...
integer, parameter, public xc_family_nc_mgga
integer, parameter, public xc_oep_x
Exact exchange.
integer, parameter, public xc_lda_c_fbe_sl
LDA correlation based ib the force-balance equation - Sturm-Liouville version.
integer, parameter, public xc_family_nc_lda
integer, parameter, public xc_oep_x_fbe_sl
Exchange approximation based on the force balance equation - Sturn-Liouville version.
integer, parameter, public xc_oep_x_fbe
Exchange approximation based on the force balance equation.
integer, parameter, public xc_oep_x_slater
Slater approximation to the exact exchange.
integer, parameter, public func_c
integer, parameter, public func_x
subroutine, public xc_ks_inversion_end(ks_inv)
subroutine, public xc_ks_inversion_write_info(ks_inversion, iunit, namespace)
subroutine, public xc_ks_inversion_init(ks_inv, namespace, gr, ions, st, xc, mc, space, kpoints)
subroutine, public xc_ks_inversion_calc(ks_inversion, namespace, space, gr, hm, ext_partners, st, vxc, time)
subroutine, public xc_get_nc_vxc(gr, xcs, st, kpoints, space, namespace, rho, vxc, ex, ec, vtau, ex_density, ec_density)
This routines is similar to xc_get_vxc but for noncollinear functionals, which are not implemented in...
Definition: xc.F90:120
subroutine, public xc_write_info(xcs, iunit, namespace)
Definition: xc.F90:265
subroutine, public xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, hartree_fock, ispin)
Definition: xc.F90:352
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Definition: xc.F90:702
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
Definition: xc.F90:721
subroutine, public xc_end(xcs)
Definition: xc.F90:600
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:736
integer, parameter, public oep_type_mgga
Definition: xc_oep.F90:186
integer, parameter, public oep_level_none
the OEP levels
Definition: xc_oep.F90:174
subroutine, public xc_oep_end(oep)
Definition: xc_oep.F90:358
subroutine, public zxc_oep_calc(oep, namespace, xcs, gr, hm, st, space, rcell_volume, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
Definition: xc_oep.F90:2364
subroutine, public dxc_oep_calc(oep, namespace, xcs, gr, hm, st, space, rcell_volume, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
Definition: xc_oep.F90:1467
subroutine, public xc_oep_write_info(oep, iunit, namespace)
Definition: xc_oep.F90:380
integer, parameter, public oep_type_exx
The different types of OEP that we can work with.
Definition: xc_oep.F90:186
subroutine, public xc_oep_init(oep, namespace, gr, st, mc, space, oep_type)
Definition: xc_oep.F90:219
subroutine, public zxc_oep_photon_calc(oep, namespace, xcs, gr, hm, st, space, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
subroutine, public dxc_oep_photon_calc(oep, namespace, xcs, gr, hm, st, space, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
This module implements the "photon-free" electron-photon exchange-correlation functional.
Definition: xc_photons.F90:123
integer, parameter, public sic_none
no self-interaction correction
Definition: xc_sic.F90:153
subroutine, public xc_sic_write_info(sic, iunit, namespace)
Definition: xc_sic.F90:259
integer, parameter, public sic_adsic
Averaged density SIC.
Definition: xc_sic.F90:153
subroutine, public xc_sic_init(sic, namespace, gr, st, mc, space)
initialize the SIC object
Definition: xc_sic.F90:173
subroutine, public xc_sic_end(sic)
finalize the SIC and, if needed, the included OEP
Definition: xc_sic.F90:245
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
Definition: xc_sic.F90:153
integer, parameter, public sic_amaldi
Amaldi correction term.
Definition: xc_sic.F90:153
subroutine, public xc_sic_calc_adsic(sic, namespace, space, gr, st, hm, xc, density, vxc, ex, ec)
Computes the ADSIC potential and energy.
Definition: xc_sic.F90:290
A module that takes care of xc contribution from vdW interactions.
Definition: xc_vdw.F90:118
subroutine, public xc_get_vxc(gr, xcs, st, kpoints, psolver, namespace, space, rho, ispin, rcell_volume, vxc, ex, ec, deltaxc, vtau, ex_density, ec_density, stress_xc, force_orbitalfree, force_host)
Definition: xc_vxc.F90:191
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
int true(void)
subroutine get_functional_from_pseudos(x_functional, c_functional)
Tries to find out the functional from the pseudopotential.
Definition: v_ks.F90:575
subroutine v_a_xc(hm, force_semilocal)
Definition: v_ks.F90:980
subroutine calculate_density()
Definition: v_ks.F90:916