Octopus
hamiltonian_elec.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2020 M. Marques, A. Castro, A. Rubio, G. Bertsch,
2!! N. Tancogne-Dejean, M. Lueders
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
24 use accel_oct_m
26 use batch_oct_m
29 use debug_oct_m
32 use energy_oct_m
37 use epot_oct_m
40 use global_oct_m
41 use grid_oct_m
45 use io_oct_m
46 use ions_oct_m
47 use kick_oct_m
48 use, intrinsic :: iso_fortran_env
52 use lasers_oct_m
54 use lda_u_oct_m
57 use math_oct_m
58 use mesh_oct_m
61 use mpi_oct_m
65 use nlcc_oct_m
70 use parser_oct_m
75 use pcm_oct_m
76 use phase_oct_m
79 use space_oct_m
87 use types_oct_m
88 use unit_oct_m
92 use xc_oct_m
93 use xc_cam_oct_m
94 use xc_f03_lib_m
98 use zora_oct_m
99
100 implicit none
101
102 private
103 public :: &
122 dvmask, &
123 zvmask, &
139
140
141 type, extends(hamiltonian_abst_t) :: hamiltonian_elec_t
142 ! Components are public by default
143
146 type(space_t), private :: space
147 type(states_elec_dim_t) :: d
148 type(hamiltonian_elec_base_t) :: hm_base
149 type(phase_t) :: phase
150 type(energy_t), allocatable :: energy
151 type(absorbing_boundaries_t) :: abs_boundaries
152 type(ks_potential_t) :: ks_pot
153 real(real64), allocatable :: vberry(:,:)
154
155 type(derivatives_t), pointer, private :: der
156
157 type(nonlocal_pseudopotential_t) :: vnl
158 type(nonlocal_pseudopotential_t) :: aug_overlap
159 type(nonlocal_pseudopotential_t) :: aug_inverse_overlap
160
161 type(ions_t), pointer :: ions
162 logical, private :: owns_ions = .false.
163 logical, private :: is_copy_snapshot = .false.
164 real(real64) :: exx_coef
165
166 class(poisson_t), allocatable :: psolver
167
169 logical :: self_induced_magnetic
170 real(real64), allocatable :: a_ind(:, :)
171 real(real64), allocatable :: b_ind(:, :)
172
173 integer :: theory_level
174 type(xc_t), pointer :: xc
175 type(xc_photons_t), pointer :: xc_photons
176
177 class(epot_t), allocatable :: ep
178 class(pcm_t), allocatable :: pcm
179
181 logical, private :: adjoint
182
184 real(real64), private :: mass
185
187 logical, private :: inh_term
188 class(states_elec_t), allocatable :: inh_st
189
192 type(oct_exchange_t) :: oct_exchange
193
194 class(scissor_t), allocatable :: scissor
195
196 real(real64) :: current_time
197 logical, private :: is_applied_packed
198
200 class(lda_u_t), allocatable :: lda_u
201 integer :: lda_u_level
202
203 logical, public :: time_zero
204
205 class(exchange_operator_t), allocatable, public :: exxop
206
207 type(kpoints_t), pointer, public :: kpoints => null()
208
209 type(partner_list_t) :: external_potentials
210 real(real64), allocatable, public :: v_ext_pot(:)
211 real(real64), allocatable, public :: v_static(:)
212
213 type(ion_electron_local_potential_t) :: v_ie_loc
214 type(nlcc_t) :: nlcc
215
216 type(magnetic_constrain_t) :: magnetic_constrain
217
219 type(kick_t) :: kick
222 type(mxll_coupling_t) :: mxll
223 type(zora_t), pointer :: zora => null()
225 contains
226 procedure :: update => hamiltonian_elec_update
227 procedure :: apply_packed => hamiltonian_elec_apply_packed
228 procedure :: update_span => hamiltonian_elec_span
229 procedure :: dapply => dhamiltonian_elec_apply
230 procedure :: zapply => zhamiltonian_elec_apply
232 procedure :: needs_mgga_term => hamiltonian_elec_needs_mgga_term
233 procedure :: set_mass => hamiltonian_elec_set_mass
236 integer, public, parameter :: &
237 length = 1, &
239
240
241contains
243 ! ---------------------------------------------------------
244 subroutine hamiltonian_elec_init(hm, namespace, space, gr, ions, ext_partners, st, theory_level, xc, &
245 mc, kpoints, need_exchange, xc_photons)
246 type(hamiltonian_elec_t), target, intent(inout) :: hm
247 type(namespace_t), intent(in) :: namespace
248 class(space_t), intent(in) :: space
249 type(grid_t), target, intent(inout) :: gr
250 type(ions_t), target, intent(inout) :: ions
251 type(partner_list_t), intent(inout) :: ext_partners
252 type(states_elec_t), target, intent(inout) :: st
253 integer, intent(in) :: theory_level
254 type(xc_t), target, intent(in) :: xc
255 type(multicomm_t), intent(in) :: mc
256 type(kpoints_t), target, intent(in) :: kpoints
257 logical, optional, intent(in) :: need_exchange
258 type(xc_photons_t), optional, target, intent(in) :: xc_photons
261 logical :: need_exchange_
262 real(real64) :: rashba_coupling
263
265
266 ! class(...), allocatable members: see electrons_t
267 safe_allocate(hm%lda_u)
268 safe_allocate(hm%exxop)
269 safe_allocate(hm%psolver)
270 safe_allocate(hm%scissor)
271 safe_allocate(hm%inh_st)
272 safe_allocate(hm%ep)
273 safe_allocate(hm%pcm)
274 safe_allocate(hm%lda_u%basis)
275 call profiling_in('HAMILTONIAN_ELEC_INIT')
276
277 ! make a couple of local copies
278 hm%space = space
279 hm%theory_level = theory_level
280 call states_elec_dim_copy(hm%d, st%d)
282 hm%kpoints => kpoints
284 !%Variable ParticleMass
285 !%Type float
286 !%Default 1.0
287 !%Section Hamiltonian
288 !%Description
289 !% It is possible to make calculations for a particle with a mass
290 !% different from one (atomic unit of mass, or mass of the electron).
291 !% This is useful to describe non-electronic systems, or for
292 !% esoteric purposes.
293 !%End
294 call parse_variable(namespace, 'ParticleMass', m_one, hm%mass)
296 !%Variable RashbaSpinOrbitCoupling
297 !%Type float
298 !%Default 0.0
299 !%Section Hamiltonian
300 !%Description
301 !% (Experimental.) For systems described in 2D (electrons confined to 2D in semiconductor structures), one
302 !% may add the Bychkov-Rashba spin-orbit coupling term [Bychkov and Rashba, <i>J. Phys. C: Solid
303 !% State Phys.</i> <b>17</b>, 6031 (1984)]. This variable determines the strength
304 !% of this perturbation, and has dimensions of energy times length.
305 !%End
306 call parse_variable(namespace, 'RashbaSpinOrbitCoupling', m_zero, rashba_coupling, units_inp%energy*units_inp%length)
307 if (parse_is_defined(namespace, 'RashbaSpinOrbitCoupling')) then
308 if (space%dim /= 2) then
309 write(message(1),'(a)') 'Rashba spin-orbit coupling can only be used for two-dimensional systems.'
310 call messages_fatal(1, namespace=namespace)
311 end if
312 call messages_experimental('RashbaSpinOrbitCoupling', namespace=namespace)
313 end if
314
315 call hm%hm_base%init(hm%d%nspin, hm%mass, rashba_coupling)
316 call hm%vnl%init()
317 call hm%aug_overlap%init()
318 call hm%aug_inverse_overlap%init()
319 call mpi_grp_copy(hm%vnl%paw_onsite_grp, st%st_kpt_mpi_grp)
320
321 assert(associated(gr%der%lapl))
322 hm%hm_base%kinetic => gr%der%lapl
323
324 safe_allocate(hm%energy)
325
326 !Keep pointers to derivatives, geometry and xc
327 hm%der => gr%der
328 hm%ions => ions
329 hm%owns_ions = .false.
330 hm%is_copy_snapshot = .false.
331 hm%xc => xc
332
333 if(present(xc_photons)) then
334 hm%xc_photons => xc_photons
335 else
336 hm%xc_photons => null()
337 end if
338
339 ! allocate potentials and density of the cores
340 ! In the case of spinors, vxc_11 = hm%vxc(:, 1), vxc_22 = hm%vxc(:, 2), Re(vxc_12) = hm%vxc(:. 3);
341 ! Im(vxc_12) = hm%vxc(:, 4)
342 call hm%ks_pot%init(gr%der, gr%np, gr%np_part, hm%d%nspin, hm%theory_level, family_is_mgga_with_exc(hm%xc))
343
344 !Initialize Poisson solvers
345 call poisson_init(hm%psolver, namespace, space, gr%der, mc, gr%stencil, st%qtot)
346
347 ! Initialize external potential
348 call epot_init(hm%ep, namespace, gr, hm%ions, hm%psolver, hm%d%ispin, hm%xc%family, hm%kpoints, &
349 xc_id=[hm%xc%functional(func_x, 1)%id, hm%xc%functional(func_c, 1)%id])
350 hm%xc%usexcnhat = hm%ep%usexcnhat
351 st%requires_generalized_overlap = hm%ep%requires_generalized_overlap
352 ! Ultrasoft/PAW (generalized overlap) is not implemented for curvilinear grids
353 ! (the radial-grid overlap and the augmentation-density quadrature assume a
354 ! uniform Cartesian mesh) nor on accelerators (the overlap, inverse overlap and
355 ! augmentation-density kernels have no GPU path).
356 if (hm%ep%requires_generalized_overlap) then
357 if (gr%use_curvilinear) then
358 call messages_not_implemented("ultrasoft/PAW generalized overlap with curvilinear coordinates", &
359 namespace=namespace)
360 end if
361 if (accel_is_enabled()) then
362 call messages_not_implemented("ultrasoft/PAW generalized overlap on GPU/accelerators", &
363 namespace=namespace)
364 end if
365
366 !%Variable USPPSaveMemory
367 !%Type logical
368 !%Default no
369 !%Section Hamiltonian
370 !%Description
371 !% For fully-relativistic (spin-orbit) ultrasoft pseudopotentials, the real spherical
372 !% harmonics <math>Y_{LM}</math> on the augmentation spheres are, by default, precomputed
373 !% once and cached in the projector matrices for the <math>D_{ij}</math> screening, which
374 !% stores an extra <tt>n_points * (l_max+1)^2</tt> reals per atom. Set this to
375 !% <tt>yes</tt> to instead recompute them on every call, trading speed for a smaller
376 !% memory footprint. The augmentation functions <math>Q_{ij}^L(r) Y_{LM}</math> used
377 !% elsewhere are always stored and are not affected by this variable.
378 !%End
379 call parse_variable(namespace, 'USPPSaveMemory', .false., hm%vnl%uspp_save_memory)
380 hm%aug_overlap%uspp_save_memory = hm%vnl%uspp_save_memory
381 hm%aug_inverse_overlap%uspp_save_memory = hm%vnl%uspp_save_memory
382 end if
383 call kick_init(hm%kick, namespace, space, hm%kpoints, hm%d%ispin)
384
385 hm%zora => zora_t(namespace, hm%der, hm%d, hm%ep, hm%mass)
386
387 !Temporary construction of the ion-electron interactions
388 call hm%v_ie_loc%init(gr, hm%psolver, hm%ions, namespace, hm%ep%dgrid, hm%ep%atoms_dist_plane)
389 if (hm%ep%nlcc) then
390 call hm%nlcc%init(gr, hm%ions, hm%ep%dgrid, hm%ep%atoms_dist_plane)
391 safe_allocate(st%rho_core(1:gr%np))
392 st%rho_core(:) = m_zero
393 end if
394
395 !Static magnetic field or rashba spin-orbit interaction requires complex wavefunctions
396 if (parse_is_defined(namespace, 'StaticMagneticField') .or. list_has_gauge_field(ext_partners) .or. &
397 parse_is_defined(namespace, 'RashbaSpinOrbitCoupling')) then
398 call states_set_complex(st)
399 end if
400
401 !%Variable CalculateSelfInducedMagneticField
402 !%Type logical
403 !%Default no
404 !%Section Hamiltonian
405 !%Description
406 !% The existence of an electronic current implies the creation of a self-induced magnetic
407 !% field, which may in turn back-react on the system. Of course, a fully consistent treatment
408 !% of this kind of effect should be done in QED theory, but we will attempt a first
409 !% approximation to the problem by considering the lowest-order relativistic terms
410 !% plugged into the normal Hamiltonian equations (spin-other-orbit coupling terms, etc.).
411 !% For the moment being, none of this is done, but a first step is taken by calculating
412 !% the induced magnetic field of a system that has a current, by considering the magnetostatic
413 !% approximation and Biot-Savart law:
414 !%
415 !% <math> \nabla^2 \vec{A} + 4\pi\alpha \vec{J} = 0</math>
416 !%
417 !% <math> \vec{B} = \vec{\nabla} \times \vec{A}</math>
418 !%
419 !% If <tt>CalculateSelfInducedMagneticField</tt> is set to yes, this <i>B</i> field is
420 !% calculated at the end of a <tt>gs</tt> calculation (nothing is done -- yet -- in the <tt>td</tt>case)
421 !% and printed out, if the <tt>Output</tt> variable contains the <tt>potential</tt> keyword (the prefix
422 !% of the output files is <tt>Bind</tt>).
423 !%End
424 call parse_variable(namespace, 'CalculateSelfInducedMagneticField', .false., hm%self_induced_magnetic)
425 if (hm%self_induced_magnetic) then
426 safe_allocate(hm%a_ind(1:gr%np_part, 1:space%dim))
427 safe_allocate(hm%b_ind(1:gr%np_part, 1:space%dim))
428
429 !(for dim = we could save some memory, but it is better to keep it simple)
430 end if
431
432 ! Absorbing boundaries
433 call absorbing_boundaries_init(hm%abs_boundaries, namespace, space, gr)
434
435 hm%inh_term = .false.
436 call oct_exchange_remove(hm%oct_exchange)
437
438 hm%adjoint = .false.
439
440 call hm%phase%init(gr, hm%d%kpt, hm%kpoints, st%d, space)
441
442 !%Variable DFTULevel
443 !%Type integer
444 !%Default no
445 !%Section Hamiltonian::XC
446 !%Description
447 !% This variable selects which DFT+U expression is added to the Hamiltonian.
448 !%Option dft_u_none 0
449 !% No +U term is not applied.
450 !%Option dft_u_empirical 1
451 !% An empiricial Hubbard U is added on the orbitals specified in the block species
452 !% with hubbard_l and hubbard_u
453 !%Option dft_u_acbn0 2
454 !% Octopus determines the effective U term using the
455 !% ACBN0 functional as defined in PRX 5, 011006 (2015)
456 !%End
457 call parse_variable(namespace, 'DFTULevel', dft_u_none, hm%lda_u_level)
458 call messages_print_var_option('DFTULevel', hm%lda_u_level, namespace=namespace)
459 if (hm%lda_u_level /= dft_u_none) then
460 call lda_u_init(hm%lda_u, namespace, space, hm%lda_u_level, gr, ions, st, mc, hm%kpoints)
461
462 !In the present implementation of DFT+U, in case of spinors, we have off-diagonal terms
463 !in spin space which break the assumption of the generalized Bloch theorem
464 if (kick_get_type(hm%kick) == kick_magnon_mode .and. gr%der%boundaries%spiral) then
465 call messages_not_implemented("DFT+U with generalized Bloch theorem and magnon kick", namespace=namespace)
466 end if
467
468 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
469 if(hm%lda_u_level /= dft_u_none .and. hm%phase%is_allocated()) then
470 call lda_u_build_phase_correction(hm%lda_u, space, hm%d, gr%der%boundaries, namespace, hm%kpoints)
471 end if
472 end if
473
474 !%Variable HamiltonianApplyPacked
475 !%Type logical
476 !%Default yes
477 !%Section Execution::Optimization
478 !%Description
479 !% If set to yes (the default), Octopus will 'pack' the
480 !% wave-functions when operating with them. This might involve some
481 !% additional copying but makes operations more efficient.
482 !% See also the related <tt>StatesPack</tt> variable.
483 !%End
484 call parse_variable(namespace, 'HamiltonianApplyPacked', .true., hm%is_applied_packed)
485
486 if (hm%theory_level == hartree_fock .and. st%parallel_in_states) then
487 call messages_experimental('Hartree-Fock parallel in states', namespace=namespace)
488 end if
489
490 if (hm%theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(hm%xc) &
491 .and. st%parallel_in_states) then
492 call messages_experimental('Hybrid functionals parallel in states', namespace=namespace)
493 end if
494
495 !%Variable TimeZero
496 !%Type logical
497 !%Default no
498 !%Section Hamiltonian
499 !%Description
500 !% (Experimental) If set to yes, the ground state and other time
501 !% dependent calculation will assume that they are done at time
502 !% zero, so that all time depedent field at that time will be
503 !% included.
504 !%End
505 call parse_variable(namespace, 'TimeZero', .false., hm%time_zero)
506 if (hm%time_zero) call messages_experimental('TimeZero', namespace=namespace)
507
508 !Cam parameters are irrelevant here and are updated later
509 need_exchange_ = optional_default(need_exchange, .false.)
510 if (hm%xc%compute_exchange(hm%theory_level) .or. need_exchange_) then
511 !We test Slater before OEP, as Slater is treated as OEP for the moment....
512 if (hm%xc%functional(func_x,1)%id == xc_oep_x_slater) then
513 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
514 hm%kpoints, cam_exact_exchange)
515 else if (bitand(hm%xc%family, xc_family_oep) /= 0 .or. hm%theory_level == rdmft) then
516 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
517 hm%kpoints, hm%xc%cam)
518 if (hm%theory_level == rdmft) hm%exxop%useACE = .false.
519 else
520 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
521 hm%kpoints, cam_exact_exchange)
522 end if
523 end if
524
525 if (hm%is_applied_packed .and. accel_is_enabled()) then
526 ! Check if we can actually apply the hamiltonian packed
527 if (gr%use_curvilinear) then
528 if (accel_allow_cpu_only()) then
529 hm%is_applied_packed = .false.
530 call messages_write('Cannot use GPUs as curvilinear coordinates are used.')
531 call messages_warning(namespace=namespace)
532 else
533 call messages_write('Cannot use GPUs as curvilinear coordinates are used.', new_line = .true.)
534 call messages_write('Calculation will not be continued. To force execution, set AllowCPUonly = yes.')
535 call messages_fatal(namespace=namespace)
536 end if
537 end if
538 end if
539
540 !We are building the list of external potentials
541 !This is done here at the moment, because we pass directly the mesh
542 !TODO: Once the abstract Hamiltonian knows about an abstract basis, we might move this to the
543 ! abstract Hamiltonian
544 call load_external_potentials(hm%external_potentials, namespace)
545
546 !Some checks which are electron specific, like k-points
548
549 !At the moment we do only have static external potential, so we never update them
551
552 !Build the resulting interactions
553 !TODO: This will be moved to the actual interactions
554 call build_interactions()
555
556 ! Constrained DFT for noncollinear magnetism
557 if (hm%theory_level /= independent_particles) then
558 call magnetic_constrain_init(hm%magnetic_constrain, namespace, gr, st%d, ions%natoms, ions%min_distance())
559 end if
560
561 ! init maxwell-electrons coupling
562 call mxll_coupling_init(hm%mxll, st%d, gr, namespace, hm%mass)
563
564 if (associated(hm%xc_photons)) then
565 if (hm%xc_photons%wants_to_renormalize_mass()) then
566 ! remornalize the electron mass due to light-matter interaction; here we only deal with it in free space
567 call hm%set_mass(namespace, hm%xc_photons%get_renormalized_mass())
568 end if
569 end if
570
571 if (hm%xc%compute_exchange(hm%theory_level) .or. need_exchange_) call hm%exxop%write_info(namespace)
572
573 call profiling_out('HAMILTONIAN_ELEC_INIT')
574 pop_sub(hamiltonian_elec_init)
575
576 contains
577
578 ! ---------------------------------------------------------
579 subroutine build_external_potentials()
580 type(list_iterator_t) :: iter
581 class(*), pointer :: potential
582 integer :: iop
583
585
586 safe_allocate(hm%v_ext_pot(1:gr%np))
587 hm%v_ext_pot(1:gr%np) = m_zero
588
589 call iter%start(hm%external_potentials)
590 do while (iter%has_next())
591 potential => iter%get_next()
592 select type (potential)
593 class is (external_potential_t)
594
595 call potential%allocate_memory(gr)
596 call potential%calculate(namespace, gr, hm%psolver)
597 !To preserve the old behavior, we are adding the various potentials
598 !to the corresponding arrays
599 select case (potential%type)
601 call lalg_axpy(gr%np, m_one, potential%pot, hm%v_ext_pot)
602
604 if (states_are_real(st)) then
605 message(1) = "Cannot use static magnetic field with real wavefunctions"
606 call messages_fatal(1, namespace=namespace)
607 end if
608
609 if (.not. allocated(hm%ep%b_field)) then
610 safe_allocate(hm%ep%b_field(1:3)) !Cannot be space%dim
611 hm%ep%b_field(1:3) = m_zero
612 end if
613 hm%ep%b_field(1:3) = hm%ep%b_field(1:3) + potential%b_field(1:3)
614
615 if (.not. allocated(hm%ep%a_static)) then
616 safe_allocate(hm%ep%a_static(1:gr%np, 1:space%dim))
617 hm%ep%a_static(1:gr%np, 1:space%dim) = m_zero
618 end if
619 call lalg_axpy(gr%np, space%dim, m_one, potential%a_static, hm%ep%a_static)
620
622 if (.not. allocated(hm%ep%e_field)) then
623 safe_allocate(hm%ep%e_field(1:space%dim))
624 hm%ep%e_field(1:space%dim) = m_zero
625 end if
626 hm%ep%e_field(1:space%dim) = hm%ep%e_field(1:space%dim) + potential%e_field(1:space%dim)
627
628 !In the fully periodic case, we use Berry phases
629 if (space%periodic_dim < space%dim) then
630 if (.not. allocated(hm%v_static)) then
631 safe_allocate(hm%v_static(1:gr%np))
632 hm%v_static(1:gr%np) = m_zero
633 end if
634 if (.not. allocated(hm%ep%v_ext)) then
635 safe_allocate(hm%ep%v_ext(1:gr%np_part))
636 hm%ep%v_ext(1:gr%np_part) = m_zero
637 end if
638 call lalg_axpy(gr%np, m_one, potential%pot, hm%v_static)
639 call lalg_axpy(gr%np, m_one, potential%v_ext, hm%ep%v_ext)
640 end if
641
642 if (hm%kpoints%use_symmetries) then
643 do iop = 1, symmetries_number(hm%kpoints%symm)
644 if (iop == symmetries_identity_index(hm%kpoints%symm)) cycle
645 if (.not. symm_op_invariant_cart(hm%kpoints%symm%ops(iop), hm%ep%e_field, 1e-5_real64)) then
646 message(1) = "The StaticElectricField breaks (at least) one of the symmetries used to reduce the k-points."
647 message(2) = "Set SymmetryBreakDir equal to StaticElectricField."
648 call messages_fatal(2, namespace=namespace)
649 end if
650 end do
651 end if
652
653 end select
654 call potential%deallocate_memory()
655
656 class default
657 assert(.false.)
658 end select
659 end do
660
662 end subroutine build_external_potentials
663
664 ! ---------------------------------------------------------
665 subroutine external_potentials_checks()
666 type(list_iterator_t) :: iter
667 class(*), pointer :: potential
668
670
671 call iter%start(hm%external_potentials)
672 do while (iter%has_next())
673 potential => iter%get_next()
674 select type (potential)
675 class is (external_potential_t)
676
677 if (potential%type == external_pot_static_efield .and. hm%kpoints%reduced%npoints > 1) then
678 message(1) = "Applying StaticElectricField in a periodic direction is only accurate for large supercells."
679 message(2) = "Single-point Berry phase is not appropriate when k-point sampling is needed."
680 call messages_warning(2, namespace=namespace)
681 end if
682
683 class default
684 assert(.false.)
685 end select
686 end do
687
689 end subroutine external_potentials_checks
690
691
692 !The code in this routines needs to know about the external potentials.
693 !This will be treated in the future by the interactions directly.
694 subroutine build_interactions()
695 logical :: external_potentials_present
696 logical :: kick_present
697
699
700 if (allocated(hm%ep%e_field) .and. space%is_periodic() .and. .not. list_has_gauge_field(ext_partners)) then
701 ! only need vberry if there is a field in a periodic direction
702 ! and we are not setting a gauge field
703 if (any(abs(hm%ep%e_field(1:space%periodic_dim)) > m_epsilon)) then
704 safe_allocate(hm%vberry(1:gr%np, 1:hm%d%nspin))
705 hm%vberry = m_zero
706 end if
707 end if
708
709 external_potentials_present = epot_have_external_potentials(hm%ep) .or. &
710 list_has_lasers(ext_partners) .or. allocated(hm%v_static)
711
712
713 kick_present = hamiltonian_elec_has_kick(hm)
714
715 call pcm_init(hm%pcm, namespace, space, ions, gr, st%qtot, st%val_charge, external_potentials_present, kick_present)
716 if (hm%pcm%run_pcm) then
717 if (hm%theory_level /= kohn_sham_dft) call messages_not_implemented("PCM for TheoryLevel /= kohn_sham", namespace=namespace)
718 end if
719
721
722 end subroutine build_interactions
723
724
725 end subroutine hamiltonian_elec_init
726
727
728
729
730 ! ---------------------------------------------------------
731 subroutine hamiltonian_elec_end(hm)
732 type(hamiltonian_elec_t), target, intent(inout) :: hm
733
734 type(partner_iterator_t) :: iter
735 class(interaction_partner_t), pointer :: potential
736
738
739 if (hm%is_copy_snapshot) then
740 ! release only pointer targets created by hamiltonian_elec_copy
742 if (allocated(hm%lda_u)) then
743 safe_deallocate_a(hm%lda_u%basis)
744 end if
745 safe_deallocate_a(hm%lda_u)
746 safe_deallocate_a(hm%exxop)
747 safe_deallocate_a(hm%psolver)
748 safe_deallocate_a(hm%scissor)
749 safe_deallocate_a(hm%inh_st)
750 safe_deallocate_a(hm%ep)
751 safe_deallocate_a(hm%pcm)
752 pop_sub(hamiltonian_elec_end)
753 return
754 end if
755
756 call hm%hm_base%end()
757 call hm%vnl%end()
758 call hm%aug_overlap%end()
759 call hm%aug_inverse_overlap%end()
760
761 call hm%phase%end()
762
763 call hm%ks_pot%end()
764 safe_deallocate_a(hm%vberry)
765 safe_deallocate_a(hm%a_ind)
766 safe_deallocate_a(hm%b_ind)
767 safe_deallocate_a(hm%v_ext_pot)
768
769 safe_deallocate_p(hm%zora)
770
771 call poisson_end(hm%psolver)
772
773 nullify(hm%xc)
774
775 call kick_end(hm%kick)
776 call epot_end(hm%ep)
777 if (hm%owns_ions .and. associated(hm%ions)) then
778 ! ions_copy currently aliases species objects through species wrappers.
779 ! Detach wrapper storage to avoid double-finalizing shared species.
780 if (allocated(hm%ions%species)) then
781 safe_deallocate_a(hm%ions%species)
782 hm%ions%nspecies = 0
783 end if
784 safe_deallocate_p(hm%ions)
785 hm%owns_ions = .false.
786 else
787 nullify(hm%ions)
788 hm%owns_ions = .false.
789 end if
790
791 call absorbing_boundaries_end(hm%abs_boundaries)
792
793 call states_elec_dim_end(hm%d)
794
795 if (hm%scissor%apply) call scissor_end(hm%scissor)
796
797 call exchange_operator_end(hm%exxop)
798 call lda_u_end(hm%lda_u)
799
800 safe_deallocate_a(hm%energy)
801
802 if (hm%pcm%run_pcm) call pcm_end(hm%pcm)
804 call hm%v_ie_loc%end()
805 call hm%nlcc%end()
806
807 call iter%start(hm%external_potentials)
808 do while (iter%has_next())
809 potential => iter%get_next()
810 safe_deallocate_p(potential)
811 end do
812 call hm%external_potentials%empty()
813 safe_deallocate_a(hm%v_static)
814
815 call magnetic_constrain_end(hm%magnetic_constrain)
816
817 call mxll_coupling_end(hm%mxll)
818
819 hm%is_copy_snapshot = .false.
820
821 if (allocated(hm%lda_u)) then
822 safe_deallocate_a(hm%lda_u%basis)
823 end if
824 safe_deallocate_a(hm%lda_u)
825 safe_deallocate_a(hm%exxop)
826 safe_deallocate_a(hm%psolver)
827 safe_deallocate_a(hm%scissor)
828 safe_deallocate_a(hm%inh_st)
829 safe_deallocate_a(hm%ep)
830 safe_deallocate_a(hm%pcm)
831
832 pop_sub(hamiltonian_elec_end)
833 end subroutine hamiltonian_elec_end
834
835 ! ---------------------------------------------------------
840 type(hamiltonian_elec_t), target, intent(inout) :: hm
841
842 type(partner_iterator_t) :: iter
843 class(interaction_partner_t), pointer :: potential
844
846
847 if (hm%owns_ions .and. associated(hm%ions)) then
848 if (allocated(hm%ions%species)) then
849 safe_deallocate_a(hm%ions%species)
850 hm%ions%nspecies = 0
851 end if
852 safe_deallocate_p(hm%ions)
853 hm%owns_ions = .false.
854 else
855 nullify(hm%ions)
856 hm%owns_ions = .false.
857 end if
858
859 if (associated(hm%zora)) then
860 safe_deallocate_p(hm%zora)
861 end if
862
863 call iter%start(hm%external_potentials)
864 do while (iter%has_next())
865 potential => iter%get_next()
866 safe_deallocate_p(potential)
867 end do
868 call hm%external_potentials%empty()
869
870 call hm%hm_base%end()
871 call hm%ks_pot%end()
872 call hm%phase%end()
873 call hm%vnl%end()
874 call hm%aug_overlap%end()
875 call hm%aug_inverse_overlap%end()
876 if (hm%lda_u_level /= dft_u_none) call lda_u_end(hm%lda_u)
877
878 hm%is_copy_snapshot = .false.
879
882
883 ! ---------------------------------------------------------
890 subroutine hamiltonian_elec_copy(hm_out, hm_in)
891 type(hamiltonian_elec_t), target, intent(out) :: hm_out
892 type(hamiltonian_elec_t), intent(inout) :: hm_in
893
894 type(ions_t), pointer :: ions_out
895 type(zora_t), pointer :: zora_out
896 type(partner_list_t) :: external_potentials_in
897 type(partner_list_t) :: external_potentials_out
898 type(list_iterator_t) :: iter
899 class(*), pointer :: ptr
900 class(external_potential_t), pointer :: ext_pot
901 logical :: runtime_initialized
902
903 push_sub(hamiltonian_elec_copy)
904
906 runtime_initialized = associated(hm_in%kpoints)
907
908 call iter%start(hm_in%external_potentials)
909 do while (iter%has_next())
910 ptr => iter%get_next()
911 select type (ptr)
912 class is (external_potential_t)
913 call external_potentials_in%add(ptr)
914 call external_potential_clone(ext_pot, ptr)
915 call external_potentials_out%add(ext_pot)
916 class default
917 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
918 end select
919 end do
920 call hm_in%external_potentials%empty()
921
922 hm_out = hm_in
923 hm_out%is_copy_snapshot = .true.
924
925 call epot_bind_poisson_solver(hm_out%ep, hm_out%psolver)
926 call nonlocal_pseudopotential_rebind_projectors(hm_out%vnl, hm_out%ep)
927 call nonlocal_pseudopotential_rebind_projectors(hm_out%aug_overlap, hm_out%ep)
928 call nonlocal_pseudopotential_rebind_projectors(hm_out%aug_inverse_overlap, hm_out%ep)
929 ! The intrinsic assignment aliases the projector-value pointers
931 call nonlocal_pseudopotential_detach_copy(hm_out%aug_overlap, hm_out%vnl)
932 call nonlocal_pseudopotential_detach_copy(hm_out%aug_inverse_overlap, hm_out%vnl)
933
934 if (accel_is_enabled() .and. runtime_initialized .and. associated(hm_out%der)) then
935 call hamiltonian_elec_base_accel_rebuild(hm_out%hm_base, hm_out%der%mesh)
936 call ks_potential_accel_rebuild(hm_out%ks_pot)
937 call phase_accel_rebuild(hm_out%phase, hm_out%der%mesh, hm_out%d%kpt)
938 call nonlocal_pseudopotential_accel_rebuild(hm_out%vnl, hm_out%space, hm_out%der%mesh)
939 call nonlocal_pseudopotential_accel_rebuild(hm_out%aug_overlap, hm_out%space, hm_out%der%mesh)
940 call nonlocal_pseudopotential_accel_rebuild(hm_out%aug_inverse_overlap, hm_out%space, hm_out%der%mesh)
941 end if
942
943 call hm_out%external_potentials%empty()
944 call iter%start(external_potentials_out)
945 do while (iter%has_next())
946 ptr => iter%get_next()
947 select type (ptr)
948 class is (external_potential_t)
949 call hm_out%external_potentials%add(ptr)
950 class default
951 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
952 end select
953 end do
954 call iter%start(external_potentials_in)
955 do while (iter%has_next())
956 ptr => iter%get_next()
957 select type (ptr)
958 class is (external_potential_t)
959 call hm_in%external_potentials%add(ptr)
960 class default
961 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
962 end select
963 end do
964 call external_potentials_out%empty()
965 call external_potentials_in%empty()
966
967 if (runtime_initialized) then
968 call kick_end(hm_out%kick)
969 call kick_copy(hm_out%kick, hm_in%kick)
970
971 if (allocated(hm_in%energy)) then
972 if (.not. allocated(hm_out%energy)) safe_allocate(hm_out%energy)
973 call energy_copy(hm_in%energy, hm_out%energy)
974 else
975 safe_deallocate_a(hm_out%energy)
976 end if
977
978 call magnetic_constrain_copy(hm_out%magnetic_constrain, hm_in%magnetic_constrain)
979 call mxll_coupling_copy(hm_out%mxll, hm_in%mxll, hm_out%der)
980 end if
981
982 if (associated(hm_in%ions)) then
983 safe_allocate(ions_out)
984 ions_out = hm_in%ions
985 hm_out%ions => ions_out
986 hm_out%owns_ions = .true.
987 call hm_out%v_ie_loc%bind(hm_out%psolver, hm_out%ions)
988 call hm_out%nlcc%bind(hm_out%ions)
989 else
990 nullify(hm_out%ions)
991 hm_out%owns_ions = .false.
992 nullify(hm_out%v_ie_loc%atoms_dist)
993 nullify(hm_out%v_ie_loc%atom)
994 nullify(hm_out%v_ie_loc%pos)
995 nullify(hm_out%nlcc%atoms_dist)
996 nullify(hm_out%nlcc%atom)
997 nullify(hm_out%nlcc%pos)
998 end if
999
1000 if (hm_out%lda_u_level /= dft_u_none .and. associated(hm_out%ions)) then
1001 call lda_u_rebind_after_copy(hm_out%lda_u, hm_out%ions)
1002 if (accel_is_enabled() .and. runtime_initialized) then
1003 call lda_u_accel_rebuild(hm_out%lda_u, hm_out%d%kpt)
1004 end if
1005 end if
1006
1007 if (associated(hm_in%zora)) then
1008 allocate(zora_out, source=hm_in%zora)
1009 hm_out%zora => zora_out
1010 else
1011 nullify(hm_out%zora)
1012 end if
1013
1014 pop_sub(hamiltonian_elec_copy)
1015
1016 end subroutine hamiltonian_elec_copy
1017
1018 ! ---------------------------------------------------------
1021 type(hamiltonian_elec_t), intent(in) :: hm_in
1022
1023 logical :: runtime_initialized
1024
1026
1027 runtime_initialized = associated(hm_in%kpoints)
1028 if (.not. runtime_initialized) then
1030 return
1031 end if
1032
1033 if (hm_in%theory_level == hartree_fock .or. hm_in%theory_level == rdmft) then
1034 call messages_not_implemented("hamiltonian_elec_copy with HF/RDMFT exchange operator paths")
1035 end if
1036
1037 if (associated(hm_in%xc)) then
1038 if (hm_in%xc%compute_exchange(hm_in%theory_level)) then
1039 call messages_not_implemented("hamiltonian_elec_copy with hybrid/OEP exchange paths")
1040 end if
1041 end if
1042
1043 if (hamiltonian_elec_inh_term(hm_in)) then
1044 call messages_not_implemented("hamiltonian_elec_copy with OCT inhomogeneous/source term")
1045 end if
1046
1047 if (oct_exchange_enabled(hm_in%oct_exchange)) then
1048 call messages_not_implemented("hamiltonian_elec_copy with OCT exchange term")
1049 end if
1050
1051 if (hm_in%pcm%run_pcm) then
1052 call messages_not_implemented("hamiltonian_elec_copy with PCM enabled")
1053 end if
1054
1057
1058
1059 ! ---------------------------------------------------------
1060 ! True if the Hamiltonian is Hermitian, false otherwise
1061 logical function hamiltonian_elec_hermitian(hm)
1062 class(hamiltonian_elec_t), intent(in) :: hm
1063
1065 hamiltonian_elec_hermitian = .not.((hm%abs_boundaries%abtype == imaginary_absorbing) .or. &
1066 oct_exchange_enabled(hm%oct_exchange))
1067
1069 end function hamiltonian_elec_hermitian
1070
1071 ! ---------------------------------------------------------
1072 ! True if the Hamiltonian needs to apply the mGGA term
1073 pure logical function hamiltonian_elec_needs_mgga_term(hm, terms)
1074 class(hamiltonian_elec_t), intent(in) :: hm
1075 integer, intent(in) :: terms
1076
1078
1079 if (bitand(term_mgga, terms) /= 0 .and. family_is_mgga_with_exc(hm%xc) &
1080 .and. hm%theory_level == generalized_kohn_sham_dft) then
1082 end if
1083
1084 !For OEP
1085 if(terms == term_mgga .and. family_is_mgga_with_exc(hm%xc) .and. hm%theory_level == kohn_sham_dft) then
1087 end if
1088
1090
1091
1093 ! ---------------------------------------------------------
1094 subroutine hamiltonian_elec_span(hm, delta, emin, namespace)
1095 class(hamiltonian_elec_t), intent(inout) :: hm
1096 real(real64), intent(in) :: delta(:)
1097 real(real64), intent(in) :: emin
1098 type(namespace_t), intent(in) :: namespace
1099
1100 real(real64) :: emax
1101
1102 push_sub(hamiltonian_elec_span)
1103
1104 ! estimate maximum energy of discrete kinetic operator
1105 ! this neglects possible contributions from the non-local part of the pseudopotentials
1107
1108 hm%spectral_middle_point = (emax + emin) / m_two
1109 hm%spectral_half_span = (emax - emin) / m_two
1110
1111 pop_sub(hamiltonian_elec_span)
1112 end subroutine hamiltonian_elec_span
1113
1114
1115 ! ---------------------------------------------------------
1116 pure logical function hamiltonian_elec_inh_term(hm) result(inh)
1117 type(hamiltonian_elec_t), intent(in) :: hm
1118
1119 inh = hm%inh_term
1120 end function hamiltonian_elec_inh_term
1121
1122
1123 ! ---------------------------------------------------------
1124 subroutine hamiltonian_elec_set_inh(hm, st)
1125 type(hamiltonian_elec_t), intent(inout) :: hm
1126 type(states_elec_t), intent(in) :: st
1127
1128 push_sub(hamiltonian_elec_set_inh)
1129
1130 if (hm%inh_term) call states_elec_end(hm%inh_st)
1131 call states_elec_copy(hm%inh_st, st)
1132 hm%inh_term = .true.
1135 end subroutine hamiltonian_elec_set_inh
1136
1137
1138 ! ---------------------------------------------------------
1139 subroutine hamiltonian_elec_remove_inh(hm)
1140 type(hamiltonian_elec_t), intent(inout) :: hm
1141
1143
1144 if (hm%inh_term) then
1145 call states_elec_end(hm%inh_st)
1146 hm%inh_term = .false.
1147 end if
1148
1150 end subroutine hamiltonian_elec_remove_inh
1151
1152 ! ---------------------------------------------------------
1153 subroutine hamiltonian_elec_adjoint(hm)
1154 type(hamiltonian_elec_t), intent(inout) :: hm
1155
1156 push_sub(hamiltonian_elec_adjoint)
1157
1158 if (.not. hm%adjoint) then
1159 hm%adjoint = .true.
1160 if (hm%abs_boundaries%abtype == imaginary_absorbing) then
1161 hm%abs_boundaries%mf = -hm%abs_boundaries%mf
1162 end if
1163 end if
1164
1167
1168
1169 ! ---------------------------------------------------------
1170 subroutine hamiltonian_elec_not_adjoint(hm)
1171 type(hamiltonian_elec_t), intent(inout) :: hm
1172
1174
1175 if (hm%adjoint) then
1176 hm%adjoint = .false.
1177 if (hm%abs_boundaries%abtype == imaginary_absorbing) then
1178 hm%abs_boundaries%mf = -hm%abs_boundaries%mf
1179 end if
1180 end if
1181
1183 end subroutine hamiltonian_elec_not_adjoint
1184
1185
1186 ! ---------------------------------------------------------
1188 subroutine hamiltonian_elec_update(this, mesh, namespace, space, ext_partners, time)
1189 class(hamiltonian_elec_t), intent(inout) :: this
1190 class(mesh_t), intent(in) :: mesh
1191 type(namespace_t), intent(in) :: namespace
1192 class(space_t), intent(in) :: space
1193 type(partner_list_t), intent(in) :: ext_partners
1194 real(real64), optional, intent(in) :: time
1195
1196 integer :: ispin, ip, idir, iatom, ilaser
1197 real(real64) :: aa(space%dim), time_
1198 real(real64), allocatable :: vp(:,:)
1199 type(lasers_t), pointer :: lasers
1200 type(gauge_field_t), pointer :: gfield
1201 real(real64) :: am(space%dim)
1202
1203 push_sub(hamiltonian_elec_update)
1204 call profiling_in("HAMILTONIAN_ELEC_UPDATE")
1205
1206 this%current_time = m_zero
1207 if (present(time)) this%current_time = time
1208
1209 time_ = optional_default(time, 0.0_real64)
1210
1211 ! set everything to zero
1212 call this%hm_base%clear(mesh%np)
1213
1214 ! alllocate the scalar potential for the xc, hartree and external potentials
1215 call this%hm_base%allocate_field(mesh, field_potential, &
1216 complex_potential = this%abs_boundaries%abtype == imaginary_absorbing)
1217
1218 ! the lasers
1219 if (present(time) .or. this%time_zero) then
1220
1221 lasers => list_get_lasers(ext_partners)
1222 if(associated(lasers)) then
1223 do ilaser = 1, lasers%no_lasers
1224 select case (laser_kind(lasers%lasers(ilaser)))
1226 do ispin = 1, this%d%spin_channels
1227 call laser_potential(lasers%lasers(ilaser), mesh, &
1228 this%hm_base%potential(:, ispin), time_)
1229 end do
1230 case (e_field_magnetic)
1231 call this%hm_base%allocate_field(mesh, field_vector_potential + field_uniform_magnetic_field, &
1232 .false.)
1233 ! get the vector potential
1234 safe_allocate(vp(1:mesh%np, 1:space%dim))
1235 vp(1:mesh%np, 1:space%dim) = m_zero
1236 call laser_vector_potential(lasers%lasers(ilaser), mesh, vp, time_)
1237 !$omp parallel do private(idir) schedule(static)
1238 do ip = 1, mesh%np
1239 do idir = 1, space%dim
1240 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + vp(ip, idir)/p_c
1241 end do
1242 end do
1243 ! and the magnetic field
1244 call laser_field(lasers%lasers(ilaser), this%hm_base%uniform_magnetic_field(1:space%dim), time_)
1245 safe_deallocate_a(vp)
1247 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1248 ! get the uniform vector potential associated with a magnetic field
1249 aa = m_zero
1250 call laser_field(lasers%lasers(ilaser), aa, time_)
1251 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1252 end select
1253 end do
1254
1255 if (lasers_with_nondipole_field(lasers)) then
1256 assert( allocated(this%hm_base%uniform_vector_potential))
1257 call lasers_nondipole_laser_field_step(lasers, am, time_)
1258 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - am/p_c
1259 end if
1260 end if
1261
1262 ! the gauge field
1263 gfield => list_get_gauge_field(ext_partners)
1264 if (associated(gfield)) then
1265 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1266 call gauge_field_get_vec_pot(gfield, aa)
1267 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1268 end if
1269
1270 ! the electric field for a periodic system through the gauge field
1271 if (allocated(this%ep%e_field) .and. associated(gfield)) then
1272 this%hm_base%uniform_vector_potential(1:space%periodic_dim) = &
1273 this%hm_base%uniform_vector_potential(1:space%periodic_dim) - time_*this%ep%e_field(1:space%periodic_dim)
1274 end if
1275
1276 ! add the photon-free mean-field vector potential
1277 if (associated(this%xc_photons)) then
1278 if(this%xc_photons%lpfmf .and. allocated(this%xc_photons%mf_vector_potential)) then
1279 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1280 ! here we put a minus sign in front of the mean field term to get the right answer (need to check the formula)
1281 this%hm_base%uniform_vector_potential(1:space%dim) = &
1282 this%hm_base%uniform_vector_potential(1:space%dim) - this%xc_photons%mf_vector_potential(1:space%dim)/p_c
1283 end if
1284 end if
1285
1286 end if
1287
1288 ! the vector potential of a static magnetic field
1289 if (allocated(this%ep%a_static)) then
1290 call this%hm_base%allocate_field(mesh, field_vector_potential, .false.)
1291 !ep%a_static contains 1/c A(r)
1292 !$omp parallel do private(idir) schedule(static)
1293 do ip = 1, mesh%np
1294 do idir = 1, space%dim
1295 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + this%ep%a_static(ip, idir)
1296 end do
1297 end do
1298 end if
1299
1300 ! add Maxwell coupling to Hamiltonian and sets the magnetic field for the Zeeman term added below
1301 call mxll_coupling_calc(this%mxll, this%hm_base, mesh, this%d, space)
1302
1303 !The electric field was added to the KS potential
1304 call this%hm_base%accel_copy_pot(mesh)
1305
1306 ! and the static magnetic field
1307 if (allocated(this%ep%b_field)) then
1308 call this%hm_base%allocate_field(mesh, field_uniform_magnetic_field, .false.)
1309 do idir = 1, 3
1310 this%hm_base%uniform_magnetic_field(idir) = this%hm_base%uniform_magnetic_field(idir) + this%ep%b_field(idir)
1311 end do
1312 end if
1313
1314 ! Combine the uniform and non-uniform fields and compute the Zeeman term
1315 call this%hm_base%update_magnetic_terms(mesh, this%ep%gyromagnetic_ratio, this%d%ispin)
1316
1317 ! This needs to be called at the end as the zeeman term enters the potential
1318 call hamiltonian_elec_update_pot(this, mesh, accumulate = .true.)
1319
1320 if (this%mxll%test_equad) then
1321 call set_electric_quadrupole_pot(this%mxll, mesh)
1322 end if
1323
1324 call build_phase()
1325
1326 ! Note: the ultrasoft/PAW screening D_ij = D_ij^(0) + int V_s(r) Q_ij(r) dr is done
1327 ! in hamiltonian_elec_update_pot (called above via hamiltonian_elec_update_pot with
1328 ! accumulate=.true.), where the full local potential V_s = V_loc + V_Hxc is assembled.
1329
1330 call profiling_out("HAMILTONIAN_ELEC_UPDATE")
1332
1333 contains
1334
1335 subroutine build_phase()
1336
1338
1339 if ((.not. this%kpoints%gamma_only()) .or. allocated(this%hm_base%uniform_vector_potential)) then
1340
1341 call profiling_in('UPDATE_PHASES')
1342 ! now regenerate the phases for the pseudopotentials
1343 do iatom = 1, this%ep%natoms
1344 call projector_init_phases(this%ep%proj(iatom), space%dim, this%d, this%der%boundaries, this%kpoints, &
1345 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1346 end do
1347
1348 call profiling_out('UPDATE_PHASES')
1349 end if
1350
1351 if (allocated(this%hm_base%uniform_vector_potential)) then
1352
1353 call this%phase%update(mesh, this%d%kpt, this%kpoints, this%d, space, this%hm_base%uniform_vector_potential)
1354
1355 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
1356 if (this%lda_u_level /= dft_u_none) then
1357 call lda_u_build_phase_correction(this%lda_u, space, this%d, this%der%boundaries, namespace, this%kpoints, &
1358 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1359 end if
1360 end if
1361
1362 call hamiltonian_elec_build_projector_phases(this, this%vnl, async=.true.)
1363 if (this%ep%requires_generalized_overlap) then
1364 call profiling_in('UPDATE_OVERLAP')
1365 call hamiltonian_elec_build_projector_phases(this, this%aug_overlap, async=.true.)
1366 call hamiltonian_elec_build_projector_phases(this, this%aug_inverse_overlap, async=.true.)
1367 ! Exact inverse overlap
1368 if (this%aug_inverse_overlap%ovlp_inv%use_global_coupling) then
1369 if (.not. this%aug_inverse_overlap%ovlp_inv%coupling_built .or. this%phase%is_allocated()) then
1370 call this%aug_inverse_overlap%ovlp_inv%build(this%aug_inverse_overlap%projector_matrices, &
1371 this%aug_inverse_overlap%projector_phases, mesh, this%d%kpt%start, this%d%kpt%end)
1372 end if
1373 end if
1374 call profiling_out('UPDATE_OVERLAP')
1375 end if
1376
1377 call accel_finish()
1378
1380 end subroutine build_phase
1381
1382 end subroutine hamiltonian_elec_update
1383
1384
1385 !----------------------------------------------------------------
1388 ! TODO: See Issue #1064
1389 subroutine hamiltonian_elec_update_pot(this, mesh, accumulate)
1390 type(hamiltonian_elec_t), intent(inout) :: this
1391 class(mesh_t), intent(in) :: mesh
1392 logical, optional, intent(in) :: accumulate
1393
1394 integer :: ispin, ip
1395 real(real64), allocatable :: vscreen(:,:)
1396
1398
1399 ! By default we nullify first the result
1400 if (.not. optional_default(accumulate, .false.)) then
1401 !$omp parallel private(ip, ispin)
1402 do ispin = 1, this%d%nspin
1403 !$omp do simd schedule(static)
1404 do ip = 1, mesh%np
1405 this%hm_base%potential(ip, ispin) = m_zero
1406 end do
1407 end do
1408 !$omp end parallel
1409 if (this%abs_boundaries%abtype == imaginary_absorbing) then
1410 this%hm_base%Impotential = m_zero
1411 end if
1412 end if
1413
1414 !$omp parallel private(ip, ispin)
1415 do ispin = 1, this%d%nspin
1416 if (ispin <= 2) then
1417 !$omp do simd schedule(static)
1418 ! this%vhxc(ip, ispin) is added after the calculation of ZORA potential
1419 do ip = 1, mesh%np
1420 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%ep%vpsl(ip) + this%v_ext_pot(ip)
1421 end do
1422
1424 if (this%pcm%run_pcm) then
1425 if (this%pcm%solute) then
1426 !$omp do simd schedule(static)
1427 do ip = 1, mesh%np
1428 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + &
1429 this%pcm%v_e_rs(ip) + this%pcm%v_n_rs(ip)
1430 end do
1431 !$omp end do simd nowait
1432 end if
1433 if (this%pcm%localf) then
1434 !$omp do simd schedule(static)
1435 do ip = 1, mesh%np
1436 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + &
1437 this%pcm%v_ext_rs(ip)
1438 end do
1439 !$omp end do simd nowait
1440 end if
1441 end if
1442
1444 if (this%abs_boundaries%abtype == imaginary_absorbing) then
1445 !$omp do simd schedule(static)
1446 do ip = 1, mesh%np
1447 this%hm_base%Impotential(ip, ispin) = this%hm_base%Impotential(ip, ispin) + this%abs_boundaries%mf(ip)
1448 end do
1449 !$omp end do simd nowait
1450 end if
1451 end if
1452 end do
1453 !$omp end parallel
1454
1455 ! scalar relativistic ZORA contribution
1456 ! \boldsymbol{p} \frac{c^2}{2c^2 - V} \boldsymbol{p} \Phi^\mathrm{ZORA}
1457 ! Note that V here is the ionic plus external potential only: vHxc is added below, and is
1458 ! deliberately excluded from the ZORA prefactor. This makes it comparable to a one-electron
1459 ! X2C rather than to a full ZORA, and it is what allows zora_update to treat V as spin
1460 ! independent. Do not move this call after add_vhxc without revisiting zora_update.
1461 if (this%ep%reltype == scalar_relativistic_zora .or. this%ep%reltype == fully_relativistic_zora) then
1462 call this%zora%update(this%der, this%hm_base%potential)
1463 end if
1464
1465 !$omp parallel private(ip, ispin)
1466 do ispin = 1, this%d%nspin
1467 ! Adding Zeeman potential to hm_base%potential
1468 if (allocated(this%hm_base%zeeman_pot)) then
1469 !$omp do simd schedule(static)
1470 do ip = 1, mesh%np
1471 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%hm_base%zeeman_pot(ip, ispin)
1472 end do
1473 !$omp end do simd nowait
1474 end if
1475
1476 ! Adding Quadrupole potential from static E-field (test)
1477 if (this%mxll%test_equad) then
1478 !$omp do simd schedule(static)
1479 do ip = 1, mesh%np
1480 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%mxll%e_quadrupole_pot(ip)
1481 end do
1482 !$omp end do simd
1483 end if
1484 end do
1485 !$omp end parallel
1486
1487
1488 ! Add the Hartree and KS potential
1489 call this%ks_pot%add_vhxc(this%hm_base%potential)
1490
1491 call this%hm_base%accel_copy_pot(mesh)
1492
1493 ! For ultrasoft/PAW, screen the nonlocal coupling with the freshly assembled
1494 ! full local potential V_s = V_loc + V_Hxc: D_ij = D_ij^(0) + int V_s(r) Q_ij(r) dr.
1495 if (this%ep%requires_generalized_overlap) then
1496 ! In the Bloechl scheme n^hat is excluded from the XC, so V_xc must not screen the coupling
1497 if (this%ep%has_paw .and. .not. this%xc%usexcnhat) then
1498 safe_allocate(vscreen(1:mesh%np, 1:this%d%nspin))
1499 call lalg_copy(mesh%np, this%d%nspin, this%hm_base%potential, vscreen)
1500 call lalg_axpy(mesh%np, this%d%nspin, -m_one, this%ks_pot%vxc, vscreen)
1501 end if
1502 ! For PAW the one-center density matrix (onsite_density_matrix) is accumulated during the density
1503 ! calculation on the overlap instance; pass it so update_dij can build the one-center
1504 ! Hartree/XC coupling (D^1 - D~^1)_Hxc and energy correction. Once the projectors are built
1505 ! the matrix must exist: without it the one-center terms cannot be evaluated.
1506 if (this%ep%has_paw .and. this%vnl%nprojector_matrices > 0) then
1507 if (.not. allocated(this%aug_overlap%onsite_density_matrix)) then
1508 message(1) = "Internal error: the PAW one-center density matrix is not allocated,"
1509 message(2) = "the one-center contributions to the Hamiltonian cannot be computed."
1510 call messages_fatal(2)
1511 end if
1512 if (allocated(vscreen)) then
1513 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, vscreen, &
1514 onsite_density_matrix = this%aug_overlap%onsite_density_matrix)
1515 else
1516 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, this%hm_base%potential, &
1517 onsite_density_matrix = this%aug_overlap%onsite_density_matrix)
1518 end if
1519 else
1520 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, this%hm_base%potential)
1521 end if
1522 safe_deallocate_a(vscreen)
1523 end if
1524
1526 end subroutine hamiltonian_elec_update_pot
1527
1528 ! ---------------------------------------------------------
1534 subroutine hamiltonian_elec_xc_nhat(this, mesh, nhat)
1535 type(hamiltonian_elec_t), intent(in) :: this
1536 class(mesh_t), intent(in) :: mesh
1537 real(real64), allocatable, intent(inout) :: nhat(:,:)
1538
1539 integer :: is
1540
1541 push_sub(hamiltonian_elec_xc_nhat)
1542
1543 safe_deallocate_a(nhat)
1544 if (this%ep%has_paw .and. .not. this%xc%usexcnhat) then
1545 assert(this%d%ispin /= spinors)
1546 safe_allocate(nhat(1:mesh%np_part, 1:this%d%spin_channels))
1547 nhat = m_zero
1548 if (allocated(this%aug_overlap%onsite_density_matrix)) then
1549 do is = 1, this%d%spin_channels
1550 call nonlocal_pseudopotential_aug_density(this%vnl, mesh, this%ep, &
1551 this%aug_overlap%onsite_density_matrix(:, :, :, is), nhat(:, is))
1552 end do
1553 end if
1554 end if
1555
1557 end subroutine hamiltonian_elec_xc_nhat
1558
1559 ! ---------------------------------------------------------
1560 subroutine hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
1561 ! target: the NLCC reinit below stores a pointer to the epot-owned atom distribution
1562 type(hamiltonian_elec_t), target, intent(inout) :: this
1563 type(namespace_t), intent(in) :: namespace
1564 class(electron_space_t), intent(in) :: space
1565 type(grid_t), intent(in) :: gr
1566 type(ions_t), target, intent(inout) :: ions
1567 type(partner_list_t), intent(in) :: ext_partners
1568 type(states_elec_t), intent(inout) :: st
1569 real(real64), optional, intent(in) :: time
1570
1571 type(xc_functional_t), pointer :: xfp(:)
1572 integer :: xc_spin_col
1573
1575
1576 this%ions => ions
1577 call epot_generate(this%ep, namespace, gr, this%ions, this%d, st%st_kpt_mpi_grp)
1578 st%requires_generalized_overlap = this%ep%requires_generalized_overlap
1579
1580 ! Share that handle with the PAW one-center engines so they use the same parameters
1581 if (this%ep%has_paw .and. associated(this%xc)) then
1582 if (xc_functional_needs_shared_paw_handle(this%xc%functional(func_x, 1))) then
1583 xc_spin_col = merge(1, 2, this%d%ispin == unpolarized)
1584 xfp => this%xc%functional(:, xc_spin_col)
1585 call epot_set_shared_paw_xc(this%ep, xfp)
1586 end if
1587 end if
1588
1589 ! Interation terms are treated below
1590
1591 ! First we add the static electric field
1592 if (allocated(this%ep%e_field) .and. space%periodic_dim < space%dim) then
1593 call lalg_axpy(gr%np, m_one, this%v_static, this%ep%vpsl)
1594 end if
1595
1596 ! Here we need to pass this again, else test are failing.
1597 ! This is not a real problem, as the multisystem framework will indeed to this anyway
1598 this%v_ie_loc%atoms_dist => ions%atoms_dist
1599 this%v_ie_loc%atom => ions%atom
1600 call this%v_ie_loc%calculate()
1601
1602 ! At the moment we need to add this to ep%vpsl, to keep the behavior of the code
1603 call lalg_axpy(gr%np, m_one, this%v_ie_loc%potential(:,1), this%ep%vpsl)
1604
1605 ! Here we need to reinit the NLCC object
1606 ! This is not a real problem, as the multisystem framework will indeed to this anyway
1607 if (this%ep%nlcc) then
1608 call this%nlcc%end()
1609 call this%nlcc%init(gr, ions, this%ep%dgrid, this%ep%atoms_dist_plane)
1610 call this%nlcc%calculate()
1611 call lalg_copy(gr%np, this%nlcc%density(:,1), st%rho_core)
1612 end if
1613
1614 call this%vnl%build(space, gr, this%ep, this%d%ispin)
1615 if (this%ep%requires_generalized_overlap) then
1616 call this%aug_overlap%build(space, gr, this%ep, this%d%ispin, overlap_operator = .true.)
1617 call this%aug_inverse_overlap%build(space, gr, this%ep, this%d%ispin, inverse_overlap_operator = .true.)
1618 if (allocated(this%aug_overlap%onsite_current_matrix)) then
1619 call paw_ae_build_current_basis(this%aug_overlap, this%ep, space%dim)
1620 end if
1621 ! The three instances project onto the same beta functions; free the duplicate
1622 ! per-point projector arrays of the overlap instances and alias the vnl ones
1623 ! (only the small mix matrices differ).
1624 call nonlocal_pseudopotential_share_projector_data(this%aug_overlap, this%vnl)
1625 call nonlocal_pseudopotential_share_projector_data(this%aug_inverse_overlap, this%vnl)
1626 ! PAW: precompute the crystal-symmetry data to symmetrize the one-center density matrix
1627 ! (accumulated on the overlap instance during the density calculation).
1628 if (this%ep%has_paw) then
1629 call nonlocal_pseudopotential_build_paw_symm(this%aug_overlap, this%ep, space, gr, ions)
1630 end if
1631 else
1632 call this%aug_overlap%end()
1633 call this%aug_inverse_overlap%end()
1634 end if
1635 call hamiltonian_elec_update(this, gr, namespace, space, ext_partners, time)
1636
1637 ! Check if projectors are still compatible with apply_packed on GPU
1638 if (this%is_applied_packed .and. accel_is_enabled()) then
1639 if (this%ep%non_local .and. .not. this%vnl%apply_projector_matrices) then
1640 if (accel_allow_cpu_only()) then
1641 call messages_write('Relativistic pseudopotentials have not been fully implemented for GPUs.')
1642 call messages_warning(namespace=namespace)
1643 else
1644 call messages_write('Relativistic pseudopotentials have not been fully implemented for GPUs.',&
1645 new_line = .true.)
1646 call messages_write('Calculation will not be continued. To force execution, set AllowCPUonly = yes.')
1647 call messages_fatal(namespace=namespace)
1648 end if
1649 end if
1650
1651 end if
1652
1653 if (this%pcm%run_pcm) then
1656 if (this%pcm%solute) then
1657 call pcm_calc_pot_rs(this%pcm, gr, this%psolver, ions = ions)
1658 end if
1659
1662 ! Interpolation is needed, hence gr%np_part -> 1:gr%np
1663 if (this%pcm%localf .and. allocated(this%v_static)) then
1664 call pcm_calc_pot_rs(this%pcm, gr, this%psolver, v_ext = this%ep%v_ext(1:gr%np_part))
1665 end if
1666
1667 end if
1668
1669 call lda_u_update_basis(this%lda_u, space, gr, ions, st, this%psolver, namespace, this%kpoints, &
1670 this%phase%is_allocated(), this%aug_overlap)
1671
1673 end subroutine hamiltonian_elec_epot_generate
1674
1675 ! -----------------------------------------------------------------
1676
1677 real(real64) function hamiltonian_elec_get_time(this) result(time)
1678 type(hamiltonian_elec_t), intent(inout) :: this
1679
1680 time = this%current_time
1681 end function hamiltonian_elec_get_time
1682
1683 ! -----------------------------------------------------------------
1684
1685 pure logical function hamiltonian_elec_apply_packed(this) result(apply)
1686 class(hamiltonian_elec_t), intent(in) :: this
1687
1688 apply = this%is_applied_packed
1689
1691
1692
1693 ! -----------------------------------------------------------------
1694 subroutine zhamiltonian_elec_apply_atom (hm, namespace, space, latt, species, pos, ia, mesh, psi, vpsi)
1695 type(hamiltonian_elec_t), intent(in) :: hm
1696 type(namespace_t), intent(in) :: namespace
1697 class(space_t), intent(in) :: space
1698 type(lattice_vectors_t), intent(in) :: latt
1699 class(species_t), intent(in) :: species
1700 real(real64), intent(in) :: pos(1:space%dim)
1701 integer, intent(in) :: ia
1702 class(mesh_t), intent(in) :: mesh
1703 complex(real64), contiguous, intent(in) :: psi(:,:)
1704 complex(real64), contiguous, intent(out) :: vpsi(:,:)
1705
1706 integer :: idim, ip
1707 real(real64), allocatable :: vlocal(:)
1709
1710 safe_allocate(vlocal(1:mesh%np_part))
1711 vlocal = m_zero
1712 call epot_local_potential(hm%ep, namespace, space, latt, mesh, species, pos, ia, vlocal)
1713
1714 !$omp parallel private(idim, ip)
1715 do idim = 1, hm%d%dim
1716 !$omp do
1717 do ip = 1, mesh%np
1718 vpsi(ip, idim) = vlocal(ip) * psi(ip, idim)
1719 end do
1720 end do
1721 !$omp end parallel
1722
1723 safe_deallocate_a(vlocal)
1725 end subroutine zhamiltonian_elec_apply_atom
1726
1727 ! ---------------------------------------------------------
1732 subroutine hamiltonian_elec_update_with_ext_pot(this, mesh, space, ext_partners, time, mu)
1733 type(hamiltonian_elec_t), intent(inout) :: this
1734 class(space_t), intent(in) :: space
1735 class(mesh_t), intent(in) :: mesh
1736 type(partner_list_t), intent(in) :: ext_partners
1737 real(real64), intent(in) :: time(1:2)
1738 real(real64), intent(in) :: mu(1:2)
1739
1740 integer :: ispin, ip, idir, iatom, ilaser, itime
1741 real(real64) :: aa(space%dim), bb(space%dim), time_
1742 real(real64), allocatable :: vp(:,:)
1743 real(real64), allocatable :: velectric(:)
1744 type(lasers_t), pointer :: lasers
1745 type(gauge_field_t), pointer :: gfield
1746
1748 call profiling_in("HAMILTONIAN_ELEC_UPDATE_EXT_POT")
1750 this%current_time = m_zero
1751 this%current_time = time(1)
1752
1753 ! set everything to zero
1754 call this%hm_base%clear(mesh%np)
1755
1756 ! the xc, hartree and external potentials
1757 call this%hm_base%allocate_field(mesh, field_potential, &
1758 complex_potential = this%abs_boundaries%abtype == imaginary_absorbing)
1759
1760 do itime = 1, 2
1761 time_ = time(itime)
1762
1763 lasers => list_get_lasers(ext_partners)
1764 if(associated(lasers)) then
1765 do ilaser = 1, lasers%no_lasers
1766 select case (laser_kind(lasers%lasers(ilaser)))
1767 case (e_field_scalar_potential, e_field_electric)
1768 safe_allocate(velectric(1:mesh%np))
1769 do ispin = 1, this%d%spin_channels
1770 velectric = m_zero
1771 call laser_potential(lasers%lasers(ilaser), mesh, velectric, time_)
1772 !$omp parallel do simd schedule(static)
1773 do ip = 1, mesh%np
1774 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + mu(itime) * velectric(ip)
1775 end do
1776 end do
1777 safe_deallocate_a(velectric)
1778 case (e_field_magnetic)
1779 call this%hm_base%allocate_field(mesh, field_vector_potential + field_uniform_magnetic_field, .false.)
1780 ! get the vector potential
1781 safe_allocate(vp(1:mesh%np, 1:space%dim))
1782 vp(1:mesh%np, 1:space%dim) = m_zero
1783 call laser_vector_potential(lasers%lasers(ilaser), mesh, vp, time_)
1784 do idir = 1, space%dim
1785 !$omp parallel do schedule(static)
1786 do ip = 1, mesh%np
1787 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) &
1788 + mu(itime) * vp(ip, idir)/p_c
1789 end do
1790 end do
1791 ! and the magnetic field
1792 bb = m_zero
1793 call laser_field(lasers%lasers(ilaser), bb(1:space%dim), time_)
1794 this%hm_base%uniform_magnetic_field = this%hm_base%uniform_magnetic_field &
1795 + mu(itime) * bb
1796 safe_deallocate_a(vp)
1797 case (e_field_vector_potential)
1798 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1799 ! get the uniform vector potential associated with a magnetic field
1800 aa = m_zero
1801 call laser_field(lasers%lasers(ilaser), aa, time_)
1802 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) &
1803 - mu(itime) * aa/p_c
1804 end select
1805 end do
1806 end if
1807
1808 ! the gauge field
1809 gfield => list_get_gauge_field(ext_partners)
1810 if (associated(gfield)) then
1811 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1812 call gauge_field_get_vec_pot(gfield, aa)
1813 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1814 end if
1815
1816 ! the electric field for a periodic system through the gauge field
1817 ! TODO: The condition is wrong here: the e_field should be in non-periodic dims as E field
1818 ! and as a gauge field in the periodic dim, unless we use a Bery phase, in which, we do not use it
1819 ! this way. But this is unrelated to the gauge field
1820 if (allocated(this%ep%e_field) .and. associated(gfield)) then
1821 this%hm_base%uniform_vector_potential(1:space%periodic_dim) = &
1822 this%hm_base%uniform_vector_potential(1:space%periodic_dim) - time_*this%ep%e_field(1:space%periodic_dim)
1823 end if
1824
1825 end do
1826
1827 ! the vector potential of a static magnetic field
1828 if (allocated(this%ep%a_static)) then
1829 call this%hm_base%allocate_field(mesh, field_vector_potential, .false.)
1830 !ep%a_static contains 1/c A(r)
1831 !$omp parallel do schedule(static) private(idir)
1832 do ip = 1, mesh%np
1833 do idir = 1, space%dim
1834 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + this%ep%a_static(ip, idir)
1835 end do
1836 end do
1837 end if
1838
1839 !The electric field is added to the KS potential
1840 call this%hm_base%accel_copy_pot(mesh)
1841
1842 ! and the static magnetic field
1843 if (allocated(this%ep%b_field)) then
1844 call this%hm_base%allocate_field(mesh, field_uniform_magnetic_field, .false.)
1845 do idir = 1, 3
1846 this%hm_base%uniform_magnetic_field(idir) = this%hm_base%uniform_magnetic_field(idir) + this%ep%b_field(idir)
1847 end do
1848 end if
1849
1850 call this%hm_base%update_magnetic_terms(mesh, this%ep%gyromagnetic_ratio, this%d%ispin)
1851
1852 call hamiltonian_elec_update_pot(this, mesh)
1853
1854 call build_phase()
1855
1856 call profiling_out("HAMILTONIAN_ELEC_UPDATE_EXT_POT")
1858
1859 contains
1860
1861 subroutine build_phase()
1862
1864
1865 if ((.not. this%kpoints%gamma_only()) .or. allocated(this%hm_base%uniform_vector_potential)) then
1866
1867 call profiling_in('UPDATE_PHASES')
1868 ! now regenerate the phases for the pseudopotentials
1869 do iatom = 1, this%ep%natoms
1870 call projector_init_phases(this%ep%proj(iatom), space%dim, this%d, this%der%boundaries, this%kpoints, &
1871 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1872 end do
1873
1874 call profiling_out('UPDATE_PHASES')
1875 end if
1876
1877 if (allocated(this%hm_base%uniform_vector_potential)) then
1878 call this%phase%update(mesh, this%d%kpt, this%kpoints, this%d, space, this%hm_base%uniform_vector_potential)
1879 end if
1880
1881 call hamiltonian_elec_build_projector_phases(this, this%vnl)
1882 if (this%ep%requires_generalized_overlap) then
1883 call hamiltonian_elec_build_projector_phases(this, this%aug_overlap)
1884 call hamiltonian_elec_build_projector_phases(this, this%aug_inverse_overlap)
1885 ! Exact inverse overlap
1886 if (this%aug_inverse_overlap%ovlp_inv%use_global_coupling) then
1887 if (.not. this%aug_inverse_overlap%ovlp_inv%coupling_built .or. this%phase%is_allocated()) then
1888 call this%aug_inverse_overlap%ovlp_inv%build(this%aug_inverse_overlap%projector_matrices, &
1889 this%aug_inverse_overlap%projector_phases, mesh, this%d%kpt%start, this%d%kpt%end)
1890 end if
1891 end if
1892 end if
1893
1895 end subroutine build_phase
1896
1898
1899 ! ---------------------------------------------------------
1905 subroutine hamiltonian_elec_build_projector_phases(this, nlpp, async)
1906 type(hamiltonian_elec_t), intent(in) :: this
1907 type(nonlocal_pseudopotential_t), intent(inout) :: nlpp
1908 logical, optional, intent(in) :: async
1909
1910 integer :: ik, imat, nmat, max_npoints, offset, iphase, nphase, ip, iatom
1911
1913
1914 if (this%phase%is_allocated() .and. allocated(nlpp%projector_matrices)) then
1915
1916 max_npoints = nlpp%max_npoints
1917 nmat = nlpp%nprojector_matrices
1918
1919 nphase = 1
1920 if (this%der%boundaries%spiralBC) nphase = 3
1921
1922 if (.not. allocated(nlpp%projector_phases)) then
1923 safe_allocate(nlpp%projector_phases(1:max_npoints, 1:nphase, nmat, this%d%kpt%start:this%d%kpt%end))
1924 if (accel_is_enabled()) then
1925 call accel_create_buffer(nlpp%buff_projector_phases, accel_mem_read_only, &
1926 type_cmplx, nlpp%total_points*nphase*this%d%kpt%nlocal())
1927 ! We need to save nphase, with which the array has been build,
1928 ! as the number might change throughout the run
1929 nlpp%nphase = nphase
1930 end if
1931 end if
1932
1933 offset = 0
1934 do ik = this%d%kpt%start, this%d%kpt%end
1935 do imat = 1, nlpp%nprojector_matrices
1936 iatom = nlpp%projector_to_atom(imat)
1937 do iphase = 1, nphase
1938 !$omp parallel do simd schedule(static)
1939 do ip = 1, nlpp%projector_matrices(imat)%npoints
1940 nlpp%projector_phases(ip, iphase, imat, ik) = this%ep%proj(iatom)%phase(ip, iphase, ik)
1941 end do
1942
1943 if (accel_is_enabled() .and. nlpp%projector_matrices(imat)%npoints > 0) then
1944 call accel_write_buffer(nlpp%buff_projector_phases, &
1945 nlpp%projector_matrices(imat)%npoints, nlpp%projector_phases(1:, iphase, imat, ik), &
1946 offset = offset, async=optional_default(async, .false.))
1947 end if
1948 offset = offset + nlpp%projector_matrices(imat)%npoints
1949 end do
1950 end do
1951 end do
1952
1953 end if
1954
1957
1958 logical function hamiltonian_elec_needs_current(hm, states_are_real)
1959 type(hamiltonian_elec_t), intent(in) :: hm
1960 logical, intent(in) :: states_are_real
1961
1963
1964 if (hm%self_induced_magnetic) then
1965 if (.not. states_are_real) then
1967 else
1968 message(1) = 'No current density for real states since it is identically zero.'
1969 call messages_warning(1)
1970 end if
1971 end if
1972
1974
1975 ! ---------------------------------------------------------
1976 subroutine zhamiltonian_elec_apply_all(hm, namespace, gr, st, hst)
1977 type(hamiltonian_elec_t), intent(inout) :: hm
1978 type(namespace_t), intent(in) :: namespace
1979 type(grid_t), intent(in) :: gr
1980 type(states_elec_t), intent(inout) :: st
1981 type(states_elec_t), intent(inout) :: hst
1982
1983 integer :: ik, ib, ist
1984 complex(real64), allocatable :: psi(:, :)
1985 complex(real64), allocatable :: psiall(:, :, :, :)
1986
1988
1989 do ik = st%d%kpt%start, st%d%kpt%end
1990 do ib = st%group%block_start, st%group%block_end
1991 call zhamiltonian_elec_apply_batch(hm, namespace, gr, st%group%psib(ib, ik), hst%group%psib(ib, ik))
1992 end do
1993 end do
1994
1995 if (oct_exchange_enabled(hm%oct_exchange)) then
1996
1997 safe_allocate(psiall(gr%np_part, 1:hst%d%dim, st%st_start:st%st_end, st%d%kpt%start:st%d%kpt%end))
1998
1999 call states_elec_get_state(st, gr, psiall)
2000
2001 call oct_exchange_prepare(hm%oct_exchange, gr, psiall, hm%xc, hm%psolver, namespace)
2002
2003 safe_deallocate_a(psiall)
2004
2005 safe_allocate(psi(gr%np_part, 1:hst%d%dim))
2006
2007 do ik = 1, st%nik
2008 do ist = 1, st%nst
2009 call states_elec_get_state(hst, gr, ist, ik, psi)
2010 call oct_exchange_operator(hm%oct_exchange, namespace, gr, psi, ist, ik)
2011 call states_elec_set_state(hst, gr, ist, ik, psi)
2012 end do
2013 end do
2014
2015 safe_deallocate_a(psi)
2016
2017 end if
2018
2020 end subroutine zhamiltonian_elec_apply_all
2021
2022 ! ---------------------------------------------------------
2023 logical function hamiltonian_elec_has_kick(hm)
2024 type(hamiltonian_elec_t), intent(in) :: hm
2025
2027
2028 hamiltonian_elec_has_kick = (abs(hm%kick%delta_strength) > m_epsilon)
2029
2031 end function hamiltonian_elec_has_kick
2032
2034 !
2035 subroutine hamiltonian_elec_set_mass(this, namespace, mass)
2036 class(hamiltonian_elec_t) , intent(inout) :: this
2037 type(namespace_t), intent(in) :: namespace
2038 real(real64), intent(in) :: mass
2039
2041
2042 if (parse_is_defined(namespace, 'ParticleMass')) then
2043 message(1) = 'Attempting to redefine a non-unit electron mass'
2044 call messages_fatal(1)
2045 else
2046 this%mass = mass
2047 end if
2050 end subroutine hamiltonian_elec_set_mass
2051
2052 ! ---------------------------------------------------------
2053 subroutine hamiltonian_elec_diagonal (hm, mesh, diag, ik)
2054 type(hamiltonian_elec_t), intent(in) :: hm
2055 class(mesh_t), intent(in) :: mesh
2056 real(real64), contiguous, intent(out) :: diag(:,:)
2057 integer, intent(in) :: ik
2058
2059 integer :: idim, ip, ispin
2060
2061 real(real64), allocatable :: ldiag(:)
2062
2064
2065 safe_allocate(ldiag(1:mesh%np))
2066
2067 diag = m_zero
2068
2069 call derivatives_lapl_diag(hm%der, ldiag)
2070
2071 !$omp parallel private(idim, ip)
2072 do idim = 1, hm%d%dim
2073 !$omp do
2074 do ip = 1, mesh%np
2075 diag(ip, idim) = -m_half/hm%mass*ldiag(ip)
2076 end do
2077 end do
2078 !$omp end parallel
2079
2080 select case (hm%d%ispin)
2081
2082 case (unpolarized, spin_polarized)
2083 ispin = hm%d%get_spin_index(ik)
2084 !$omp parallel do
2085 do ip = 1, mesh%np
2086 diag(ip, 1) = diag(ip, 1) + hm%ep%vpsl(ip)
2087 end do
2088 !$omp end parallel do
2089
2090 case (spinors)
2091 do ip = 1, mesh%np
2092 diag(ip, 1) = diag(ip, 1) + hm%ep%vpsl(ip)
2093 diag(ip, 2) = diag(ip, 2) + hm%ep%vpsl(ip)
2094 end do
2096 end select
2097
2098 call hm%ks_pot%add_vhxc(diag)
2099
2101 end subroutine hamiltonian_elec_diagonal
2102
2103
2104
2105#include "undef.F90"
2106#include "real.F90"
2107#include "hamiltonian_elec_inc.F90"
2108
2109#include "undef.F90"
2110#include "complex.F90"
2111#include "hamiltonian_elec_inc.F90"
2112
2113end module hamiltonian_elec_oct_m
2114
2115!! Local Variables:
2116!! mode: f90
2117!! coding: utf-8
2118!! End:
subroutine build_external_potentials()
subroutine build_phase()
subroutine external_potentials_checks()
subroutine build_interactions()
constant times a vector plus a vector
Definition: lalg_basic.F90:171
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:197
integer, parameter, public imaginary_absorbing
subroutine, public absorbing_boundaries_end(this)
subroutine, public absorbing_boundaries_init(this, namespace, space, gr)
pure logical function, public accel_allow_cpu_only()
Definition: accel.F90:401
subroutine, public accel_finish()
Definition: accel.F90:1104
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
This module implements batches of mesh functions.
Definition: batch.F90:112
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:95
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:101
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64) function, public derivatives_lapl_get_max_eigenvalue(this)
Get maximum eigenvalue of discrete Laplacian. For the star and star_general stencils,...
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
subroutine, public energy_copy(ein, eout)
Definition: energy.F90:153
subroutine, public epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
Definition: epot.F90:581
subroutine, public epot_bind_poisson_solver(ep, psolver)
Bind the Poisson solver if the potential manages a density. The Poisson solver pointer is aliased whe...
Definition: epot.F90:565
logical function, public epot_have_external_potentials(ep)
Definition: epot.F90:866
integer, parameter, public scalar_relativistic_zora
Definition: epot.F90:152
subroutine, public epot_end(ep)
Definition: epot.F90:514
integer, parameter, public fully_relativistic_zora
Definition: epot.F90:152
subroutine, public epot_set_shared_paw_xc(ep, functl)
Point every PAW one-center engine at the shared xc functional.
Definition: epot.F90:751
subroutine, public epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints, xc_id)
Definition: epot.F90:223
subroutine, public exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
subroutine, public exchange_operator_end(this)
logical function, public list_has_gauge_field(partners)
type(gauge_field_t) function, pointer, public list_get_gauge_field(partners)
logical function, public list_has_lasers(partners)
type(lasers_t) function, pointer, public list_get_lasers(partners)
integer, parameter, public external_pot_from_file
potential, defined in a file
subroutine, public load_external_potentials(external_potentials, namespace)
integer, parameter, public external_pot_charge_density
user-defined function for charge density
integer, parameter, public external_pot_usdef
user-defined function for local potential
integer, parameter, public external_pot_static_efield
Static electric field.
integer, parameter, public external_pot_static_bfield
Static magnetic field.
subroutine, public external_potential_clone(pot_out, pot_in)
Deep-clone an external potential instance.
subroutine, public gauge_field_get_vec_pot(this, vec_pot)
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 p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:215
real(real64), parameter, public m_one
Definition: global.F90:174
This module implements the underlying real-space grid.
Definition: grid.F90:96
This module defines an abstract class for Hamiltonians.
integer, parameter, public field_uniform_magnetic_field
integer, parameter, public field_uniform_vector_potential
integer, parameter, public field_vector_potential
integer, parameter, public term_mgga
subroutine, public hamiltonian_elec_base_accel_rebuild(this, mesh)
Rebuild accelerator buffers after an intrinsic copy.
integer, parameter, public field_potential
subroutine, public zhamiltonian_elec_apply_overlap_single(hm, namespace, mesh, psi, spsi, ist, ik, set_bc, set_phase, inverse)
Apply the overlap S (or its inverse) to a single state (wrapper around the batch routine).
subroutine, public dhamiltonian_elec_apply_sinvh_batch(hm, namespace, mesh, psib, hspsib, terms, set_bc, set_phase)
Apply the operator A = S^{-1} H to a batch (for ultrasoft/PAW).
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...
subroutine, public zhamiltonian_elec_apply_overlap_batch(hm, namespace, mesh, psib, spsib, set_bc, inverse, set_phase)
Apply the generalized ultrasoft overlap operator S (or its inverse) to a batch.
pure logical function, public hamiltonian_elec_apply_packed(this)
subroutine, public hamiltonian_elec_set_inh(hm, st)
subroutine, public zvmask(mesh, hm, st)
subroutine, public dhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc, set_phase, spsib)
subroutine, public hamiltonian_elec_adjoint(hm)
subroutine, public hamiltonian_elec_end(hm)
subroutine, public zhamiltonian_elec_apply_single(hm, namespace, mesh, psi, hpsi, ist, ik, terms, set_bc, set_phase)
pure logical function hamiltonian_elec_needs_mgga_term(hm, terms)
logical function, public hamiltonian_elec_has_kick(hm)
integer, parameter, public length
subroutine hamiltonian_elec_build_projector_phases(this, nlpp, async)
Build the projector phases for a given nonlocal-pseudopotential set.
logical function hamiltonian_elec_hermitian(hm)
subroutine, public dhamiltonian_elec_apply_single(hm, namespace, mesh, psi, hpsi, ist, ik, terms, set_bc, set_phase)
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
real(real64) function, public hamiltonian_elec_get_time(this)
subroutine, public zhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc, set_phase, spsib)
subroutine, public hamiltonian_elec_copy(hm_out, hm_in)
Deep-copy a hamiltonian_elec_t snapshot.
subroutine, public zhamiltonian_elec_apply_sinvh_single(hm, namespace, mesh, psi, hspsi, ist, ik, terms, set_bc, set_phase)
Apply A = S^{-1} H to a single state (wrapper around the batch routine).
subroutine, public dhamiltonian_elec_apply_sinvh_single(hm, namespace, mesh, psi, hspsi, ist, ik, terms, set_bc, set_phase)
Apply A = S^{-1} H to a single state (wrapper around the batch routine).
subroutine, public dhamiltonian_elec_apply_overlap_batch(hm, namespace, mesh, psib, spsib, set_bc, inverse, set_phase)
Apply the generalized ultrasoft overlap operator S (or its inverse) to a batch.
subroutine, public dvmask(mesh, hm, st)
logical function, public hamiltonian_elec_needs_current(hm, states_are_real)
subroutine, public hamiltonian_elec_remove_inh(hm)
subroutine, public dhamiltonian_elec_apply_overlap_single(hm, namespace, mesh, psi, spsi, ist, ik, set_bc, set_phase, inverse)
Apply the overlap S (or its inverse) to a single state (wrapper around the batch routine).
subroutine, public zhamiltonian_elec_apply_atom(hm, namespace, space, latt, species, pos, ia, mesh, psi, vpsi)
subroutine hamiltonian_elec_release_copy_owned(hm)
Release owned pointer targets created by hamiltonian_elec_copy.
subroutine, public zhamiltonian_elec_apply_all(hm, namespace, gr, st, hst)
subroutine, public zhamiltonian_elec_apply_sinvh_batch(hm, namespace, mesh, psib, hspsib, terms, set_bc, set_phase)
Apply the operator A = S^{-1} H to a batch (for ultrasoft/PAW).
subroutine, public hamiltonian_elec_diagonal(hm, mesh, diag, ik)
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
integer, parameter, public velocity
subroutine hamiltonian_elec_update(this, mesh, namespace, space, ext_partners, time)
(re-)build the Hamiltonian for the next application:
subroutine hamiltonian_elec_copy_guard_supported(hm_in)
Hard-fail guard matrix for unsupported hamiltonian snapshots.
subroutine hamiltonian_elec_span(hm, delta, emin, namespace)
subroutine, public hamiltonian_elec_init(hm, namespace, space, gr, ions, ext_partners, st, theory_level, xc, mc, kpoints, need_exchange, xc_photons)
subroutine dhamiltonian_elec_apply(hm, namespace, mesh, psib, hpsib, terms, set_bc)
pure logical function, public hamiltonian_elec_inh_term(hm)
subroutine hamiltonian_elec_set_mass(this, namespace, mass)
set the effective electron mass, checking whether it was previously redefined.
subroutine, public hamiltonian_elec_update_with_ext_pot(this, mesh, space, ext_partners, time, mu)
This is an extension of "hamiltonian_elec_update_pot" to be used by the CFM4 propagator....
subroutine, public hamiltonian_elec_not_adjoint(hm)
subroutine, public zhamiltonian_elec_external(this, mesh, psib, vpsib)
subroutine zhamiltonian_elec_apply(hm, namespace, mesh, psib, hpsib, terms, set_bc)
This module defines classes and functions for interaction partners.
Definition: io.F90:93
subroutine, public kick_copy(kick_out, kick_in)
Definition: kick.F90:733
integer, parameter, public kick_magnon_mode
Definition: kick.F90:142
subroutine, public kick_end(kick)
Definition: kick.F90:776
subroutine, public kick_init(kick, namespace, space, kpoints, nspin)
Definition: kick.F90:202
pure integer function, public kick_get_type(kick)
Definition: kick.F90:1354
A module to handle KS potential, without the external potential.
subroutine, public ks_potential_accel_rebuild(this)
Rebuild accelerator buffers after an intrinsic copy.
subroutine, public laser_vector_potential(laser, mesh, aa, time)
Definition: lasers.F90:1065
subroutine, public lasers_nondipole_laser_field_step(this, field, time)
Retrieves the NDSFA vector_potential correction. The nondipole field is obtained for consecutive time...
Definition: lasers.F90:1137
logical function, public lasers_with_nondipole_field(lasers)
Check if a nondipole SFA correction should be computed for the given laser.
Definition: lasers.F90:724
integer, parameter, public e_field_electric
Definition: lasers.F90:158
integer, parameter, public e_field_vector_potential
Definition: lasers.F90:158
subroutine, public laser_potential(laser, mesh, pot, time)
Definition: lasers.F90:1030
integer, parameter, public e_field_scalar_potential
Definition: lasers.F90:158
integer pure elemental function, public laser_kind(laser)
Definition: lasers.F90:700
subroutine, public laser_field(laser, field, time)
Retrieves the value of either the electric or the magnetic field. If the laser is given by a scalar p...
Definition: lasers.F90:1102
integer, parameter, public e_field_magnetic
Definition: lasers.F90:158
integer, parameter, public dft_u_none
Definition: lda_u.F90:188
subroutine, public lda_u_init(this, namespace, space, level, gr, ions, st, mc, kpoints)
Definition: lda_u.F90:270
subroutine, public lda_u_accel_rebuild(this, kpt)
Rebuild DFT+U accelerator buffers after intrinsic assignment.
Definition: lda_u.F90:758
subroutine, public lda_u_rebind_after_copy(this, ions)
Rebind non-owning pointers after intrinsic assignment of lda_u_t.
Definition: lda_u.F90:713
subroutine, public lda_u_build_phase_correction(this, space, std, boundaries, namespace, kpoints, vec_pot, vec_pot_var)
Build the phase correction to the global phase for all orbitals.
Definition: lda_u.F90:942
subroutine, public lda_u_end(this)
Definition: lda_u.F90:667
subroutine, public lda_u_update_basis(this, space, gr, ions, st, psolver, namespace, kpoints, has_phase, aug_overlap)
Definition: lda_u.F90:801
This module implements fully polymorphic linked lists, and some specializations thereof.
Definition: linked_list.F90:84
This modules implements the routines for doing constrain DFT for noncollinear magnetism.
subroutine, public magnetic_constrain_copy(this_out, this_in)
Deep-copy magnetic constrain data.
subroutine, public magnetic_constrain_end(this)
Releases memory of the magnetic constrain.
subroutine, public magnetic_constrain_init(this, namespace, mesh, std, natoms, min_dist)
Initilializes the magnetic_constrain_t object.
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
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_not_implemented(feature, namespace)
Definition: messages.F90:1048
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
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_experimental(name, namespace)
Definition: messages.F90:1020
subroutine mpi_grp_copy(mpi_grp_out, mpi_grp_in)
MPI_THREAD_FUNNELED allows for calls to MPI from an OMP region if the thread is the team master.
Definition: mpi.F90:428
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
subroutine, public mxll_coupling_init(this, d, gr, namespace, mass)
Parse variables and initialize Maxwell coupling.
subroutine, public set_electric_quadrupole_pot(this, mesh)
Computes the electric quadrupole potential where .
subroutine, public mxll_coupling_end(this)
Finalize and deallocate Maxwell coupling arrays.
subroutine, public mxll_coupling_calc(this, hm_base, mesh, d, space)
Add the Maxwell coupling to the electronic Hamiltonian.
subroutine, public mxll_coupling_copy(this_out, this_in, der_target)
Deep-copy Maxwell-electron coupling data and rebind derivatives.
subroutine, public nonlocal_pseudopotential_aug_density(this, mesh, epot, force_aug_weight, aug_density)
Accumulate the ultrasoft augmentation density n_aug(r) = sum_ij rho_ij Q_ij(r-R) (summed over all ult...
subroutine, public nonlocal_pseudopotential_accel_rebuild(this, space, mesh)
Rebuild accelerator buffers after an intrinsic copy.
subroutine, public nonlocal_pseudopotential_share_projector_data(this, donor)
Alias the heavy per-point projector data of a donor instance.
subroutine, public nonlocal_pseudopotential_rebind_projectors(this, epot)
Rebind projector matrix pointers (map, position) to a target epot.
subroutine, public nonlocal_pseudopotential_detach_copy(this, donor)
Detach the projector data of an instance obtained by intrinsic assignment.
subroutine, public nonlocal_pseudopotential_update_dij(this, mesh, epot, veff, add_bare, onsite_density_matrix)
Screen the ultrasoft nonlocal coupling matrix D_ij with the local potential.
subroutine, public nonlocal_pseudopotential_build_paw_symm(this, epot, space, gr, ions)
Build the crystal-symmetry data used to symmetrize the PAW one-center density matrix.
logical function, public oct_exchange_enabled(this)
subroutine, public oct_exchange_remove(this)
this module contains the low-level part of the output system
Definition: output_low.F90:94
Some general things and nomenclature:
Definition: par_vec.F90:150
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
All-electron reconstruction of mesh fields from the PAW one-center terms.
subroutine, public paw_ae_build_current_basis(this, epot, dim)
Tabulate the one-center all-electron current basis on each projector sphere.
subroutine, public pcm_calc_pot_rs(pcm, mesh, psolver, ions, v_h, v_ext, kick, time_present, kick_time)
Definition: pcm.F90:1205
subroutine, public pcm_end(pcm)
Definition: pcm.F90:3059
subroutine, public pcm_init(pcm, namespace, space, ions, grid, qtot, val_charge, external_potentials_present, kick_present)
Initializes the PCM calculation: reads the VdW molecular cavity and generates the PCM response matrix...
Definition: pcm.F90:277
subroutine, public phase_accel_rebuild(phase, mesh, kpt)
Rebuild phase accelerator buffers after an intrinsic copy.
Definition: phase.F90:518
subroutine, public poisson_init(this, namespace, space, der, mc, stencil, qtot, label, solver, verbose, force_serial, force_cmplx, fft_library, fft_batch_size, single_precision)
Definition: poisson.F90:223
subroutine, public poisson_end(this)
Definition: poisson.F90:712
/* 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
subroutine, public projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
Definition: projector.F90:276
subroutine, public scissor_end(this)
Definition: scissor.F90:226
subroutine, public states_set_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_dim_copy(dout, din)
subroutine, public states_elec_dim_end(dim)
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
This module provides routines for communicating states when using states parallelization.
integer pure function, public symmetries_identity_index(this)
Definition: symmetries.F90:614
integer pure function, public symmetries_number(this)
Definition: symmetries.F90:568
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
This module defines the unit system, used for input and output.
type(unit_system_t), public units_inp
the units systems for reading and writing
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
Definition: xc_cam.F90:131
logical pure function, public xc_functional_needs_shared_paw_handle(functl)
Whether a functional has an external parameter recomputed from the density each SCF step the PAW one-...
integer, parameter, public xc_oep_x_slater
Slater approximation to the exact exchange.
integer, parameter, public func_c
integer, parameter, public func_x
Definition: xc.F90:97
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
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:731
This module implements the "photon-free" electron-photon exchange-correlation functional.
Definition: xc_photons.F90:100
This module implements the ZORA terms for the Hamoiltonian.
Definition: zora.F90:95
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
The abstract Hamiltonian class defines a skeleton for specific implementations.
abstract class for general interaction partners
Describes mesh distribution to nodes.
Definition: mesh.F90:165
Stores all communicators and groups.
Definition: multicomm.F90:185
The states_elec_t class contains all electronic wave functions.
This class described the 'photon-exchange' electron-photon xc functionals, based on QEDFT.
Definition: xc_photons.F90:137
This class is responsible for calculating and applying the ZORA.
Definition: zora.F90:124
int true(void)