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