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