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