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, derivatives = hm%ep%has_paw)
391 safe_allocate(st%rho_core(1:gr%np))
392 st%rho_core(:) = m_zero
393 if (hm%ep%has_paw) then
394 safe_allocate(st%rho_core_grad(1:gr%np, 1:space%dim))
395 safe_allocate(st%rho_core_lapl(1:gr%np))
396 st%rho_core_grad(:, :) = m_zero
397 st%rho_core_lapl(:) = m_zero
398 end if
399 end if
400
401 !Static magnetic field or rashba spin-orbit interaction requires complex wavefunctions
402 if (parse_is_defined(namespace, 'StaticMagneticField') .or. list_has_gauge_field(ext_partners) .or. &
403 parse_is_defined(namespace, 'RashbaSpinOrbitCoupling')) then
404 call states_set_complex(st)
405 end if
406
407 !%Variable CalculateSelfInducedMagneticField
408 !%Type logical
409 !%Default no
410 !%Section Hamiltonian
411 !%Description
412 !% The existence of an electronic current implies the creation of a self-induced magnetic
413 !% field, which may in turn back-react on the system. Of course, a fully consistent treatment
414 !% of this kind of effect should be done in QED theory, but we will attempt a first
415 !% approximation to the problem by considering the lowest-order relativistic terms
416 !% plugged into the normal Hamiltonian equations (spin-other-orbit coupling terms, etc.).
417 !% For the moment being, none of this is done, but a first step is taken by calculating
418 !% the induced magnetic field of a system that has a current, by considering the magnetostatic
419 !% approximation and Biot-Savart law:
420 !%
421 !% <math> \nabla^2 \vec{A} + 4\pi\alpha \vec{J} = 0</math>
422 !%
423 !% <math> \vec{B} = \vec{\nabla} \times \vec{A}</math>
424 !%
425 !% If <tt>CalculateSelfInducedMagneticField</tt> is set to yes, this <i>B</i> field is
426 !% calculated at the end of a <tt>gs</tt> calculation (nothing is done -- yet -- in the <tt>td</tt>case)
427 !% and printed out, if the <tt>Output</tt> variable contains the <tt>potential</tt> keyword (the prefix
428 !% of the output files is <tt>Bind</tt>).
429 !%End
430 call parse_variable(namespace, 'CalculateSelfInducedMagneticField', .false., hm%self_induced_magnetic)
431 if (hm%self_induced_magnetic) then
432 safe_allocate(hm%a_ind(1:gr%np_part, 1:space%dim))
433 safe_allocate(hm%b_ind(1:gr%np_part, 1:space%dim))
434
435 !(for dim = we could save some memory, but it is better to keep it simple)
436 end if
437
438 ! Absorbing boundaries
439 call absorbing_boundaries_init(hm%abs_boundaries, namespace, space, gr)
440
441 hm%inh_term = .false.
442 call oct_exchange_remove(hm%oct_exchange)
443
444 hm%adjoint = .false.
445
446 call hm%phase%init(gr, hm%d%kpt, hm%kpoints, st%d, space)
447
448 !%Variable DFTULevel
449 !%Type integer
450 !%Default no
451 !%Section Hamiltonian::XC
452 !%Description
453 !% This variable selects which DFT+U expression is added to the Hamiltonian.
454 !%Option dft_u_none 0
455 !% No +U term is not applied.
456 !%Option dft_u_empirical 1
457 !% An empiricial Hubbard U is added on the orbitals specified in the block species
458 !% with hubbard_l and hubbard_u
459 !%Option dft_u_acbn0 2
460 !% Octopus determines the effective U term using the
461 !% ACBN0 functional as defined in PRX 5, 011006 (2015)
462 !%End
463 call parse_variable(namespace, 'DFTULevel', dft_u_none, hm%lda_u_level)
464 call messages_print_var_option('DFTULevel', hm%lda_u_level, namespace=namespace)
465 if (hm%lda_u_level /= dft_u_none) then
466 call lda_u_init(hm%lda_u, namespace, space, hm%lda_u_level, gr, ions, st, mc, hm%kpoints)
467
468 !In the present implementation of DFT+U, in case of spinors, we have off-diagonal terms
469 !in spin space which break the assumption of the generalized Bloch theorem
470 if (kick_get_type(hm%kick) == kick_magnon_mode .and. gr%der%boundaries%spiral) then
471 call messages_not_implemented("DFT+U with generalized Bloch theorem and magnon kick", namespace=namespace)
472 end if
473
474 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
475 if(hm%lda_u_level /= dft_u_none .and. hm%phase%is_allocated()) then
476 call lda_u_build_phase_correction(hm%lda_u, space, hm%d, gr%der%boundaries, namespace, hm%kpoints)
477 end if
478 end if
479
480 !%Variable HamiltonianApplyPacked
481 !%Type logical
482 !%Default yes
483 !%Section Execution::Optimization
484 !%Description
485 !% If set to yes (the default), Octopus will 'pack' the
486 !% wave-functions when operating with them. This might involve some
487 !% additional copying but makes operations more efficient.
488 !% See also the related <tt>StatesPack</tt> variable.
489 !%End
490 call parse_variable(namespace, 'HamiltonianApplyPacked', .true., hm%is_applied_packed)
491
492 if (hm%theory_level == hartree_fock .and. st%parallel_in_states) then
493 call messages_experimental('Hartree-Fock parallel in states', namespace=namespace)
494 end if
495
496 if (hm%theory_level == generalized_kohn_sham_dft .and. family_is_hybrid(hm%xc) &
497 .and. st%parallel_in_states) then
498 call messages_experimental('Hybrid functionals parallel in states', namespace=namespace)
499 end if
500
501 !%Variable TimeZero
502 !%Type logical
503 !%Default no
504 !%Section Hamiltonian
505 !%Description
506 !% (Experimental) If set to yes, the ground state and other time
507 !% dependent calculation will assume that they are done at time
508 !% zero, so that all time depedent field at that time will be
509 !% included.
510 !%End
511 call parse_variable(namespace, 'TimeZero', .false., hm%time_zero)
512 if (hm%time_zero) call messages_experimental('TimeZero', namespace=namespace)
513
514 !Cam parameters are irrelevant here and are updated later
515 need_exchange_ = optional_default(need_exchange, .false.)
516 if (hm%xc%compute_exchange(hm%theory_level) .or. need_exchange_) then
517 !We test Slater before OEP, as Slater is treated as OEP for the moment....
518 if (hm%xc%functional(func_x,1)%id == xc_oep_x_slater) then
519 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
520 hm%kpoints, cam_exact_exchange)
521 else if (bitand(hm%xc%family, xc_family_oep) /= 0 .or. hm%theory_level == rdmft) then
522 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
523 hm%kpoints, hm%xc%cam)
524 if (hm%theory_level == rdmft) hm%exxop%useACE = .false.
525 else
526 call exchange_operator_init(hm%exxop, namespace, space, st, gr%der, mc, gr%stencil, &
527 hm%kpoints, cam_exact_exchange)
528 end if
529 end if
530
531 if (hm%is_applied_packed .and. accel_is_enabled()) then
532 ! Check if we can actually apply the hamiltonian packed
533 if (gr%use_curvilinear) then
534 if (accel_allow_cpu_only()) then
535 hm%is_applied_packed = .false.
536 call messages_write('Cannot use GPUs as curvilinear coordinates are used.')
537 call messages_warning(namespace=namespace)
538 else
539 call messages_write('Cannot use GPUs as curvilinear coordinates are used.', new_line = .true.)
540 call messages_write('Calculation will not be continued. To force execution, set AllowCPUonly = yes.')
541 call messages_fatal(namespace=namespace)
542 end if
543 end if
544 end if
545
546 !We are building the list of external potentials
547 !This is done here at the moment, because we pass directly the mesh
548 !TODO: Once the abstract Hamiltonian knows about an abstract basis, we might move this to the
549 ! abstract Hamiltonian
550 call load_external_potentials(hm%external_potentials, namespace)
551
552 !Some checks which are electron specific, like k-points
554
555 !At the moment we do only have static external potential, so we never update them
557
558 !Build the resulting interactions
559 !TODO: This will be moved to the actual interactions
560 call build_interactions()
561
562 ! Constrained DFT for noncollinear magnetism
563 if (hm%theory_level /= independent_particles) then
564 call magnetic_constrain_init(hm%magnetic_constrain, namespace, gr, st%d, ions%natoms, ions%min_distance())
565 end if
566
567 ! init maxwell-electrons coupling
568 call mxll_coupling_init(hm%mxll, st%d, gr, namespace, hm%mass)
569
570 if (associated(hm%xc_photons)) then
571 if (hm%xc_photons%wants_to_renormalize_mass()) then
572 ! remornalize the electron mass due to light-matter interaction; here we only deal with it in free space
573 call hm%set_mass(namespace, hm%xc_photons%get_renormalized_mass())
574 end if
575 end if
576
577 if (hm%xc%compute_exchange(hm%theory_level) .or. need_exchange_) call hm%exxop%write_info(namespace)
578
579 call profiling_out('HAMILTONIAN_ELEC_INIT')
580 pop_sub(hamiltonian_elec_init)
581
582 contains
583
584 ! ---------------------------------------------------------
585 subroutine build_external_potentials()
586 type(list_iterator_t) :: iter
587 class(*), pointer :: potential
588 integer :: iop
589
591
592 safe_allocate(hm%v_ext_pot(1:gr%np))
593 hm%v_ext_pot(1:gr%np) = m_zero
594
595 call iter%start(hm%external_potentials)
596 do while (iter%has_next())
597 potential => iter%get_next()
598 select type (potential)
599 class is (external_potential_t)
600
601 call potential%allocate_memory(gr)
602 call potential%calculate(namespace, gr, hm%psolver)
603 !To preserve the old behavior, we are adding the various potentials
604 !to the corresponding arrays
605 select case (potential%type)
607 call lalg_axpy(gr%np, m_one, potential%pot, hm%v_ext_pot)
608
610 if (states_are_real(st)) then
611 message(1) = "Cannot use static magnetic field with real wavefunctions"
612 call messages_fatal(1, namespace=namespace)
613 end if
614
615 if (.not. allocated(hm%ep%b_field)) then
616 safe_allocate(hm%ep%b_field(1:3)) !Cannot be space%dim
617 hm%ep%b_field(1:3) = m_zero
618 end if
619 hm%ep%b_field(1:3) = hm%ep%b_field(1:3) + potential%b_field(1:3)
620
621 if (.not. allocated(hm%ep%a_static)) then
622 safe_allocate(hm%ep%a_static(1:gr%np, 1:space%dim))
623 hm%ep%a_static(1:gr%np, 1:space%dim) = m_zero
624 end if
625 call lalg_axpy(gr%np, space%dim, m_one, potential%a_static, hm%ep%a_static)
626
628 if (.not. allocated(hm%ep%e_field)) then
629 safe_allocate(hm%ep%e_field(1:space%dim))
630 hm%ep%e_field(1:space%dim) = m_zero
631 end if
632 hm%ep%e_field(1:space%dim) = hm%ep%e_field(1:space%dim) + potential%e_field(1:space%dim)
633
634 !In the fully periodic case, we use Berry phases
635 if (space%periodic_dim < space%dim) then
636 if (.not. allocated(hm%v_static)) then
637 safe_allocate(hm%v_static(1:gr%np))
638 hm%v_static(1:gr%np) = m_zero
639 end if
640 if (.not. allocated(hm%ep%v_ext)) then
641 safe_allocate(hm%ep%v_ext(1:gr%np_part))
642 hm%ep%v_ext(1:gr%np_part) = m_zero
643 end if
644 call lalg_axpy(gr%np, m_one, potential%pot, hm%v_static)
645 call lalg_axpy(gr%np, m_one, potential%v_ext, hm%ep%v_ext)
646 end if
647
648 if (hm%kpoints%use_symmetries) then
649 do iop = 1, symmetries_number(hm%kpoints%symm)
650 if (iop == symmetries_identity_index(hm%kpoints%symm)) cycle
651 if (.not. symm_op_invariant_cart(hm%kpoints%symm%ops(iop), hm%ep%e_field, 1e-5_real64)) then
652 message(1) = "The StaticElectricField breaks (at least) one of the symmetries used to reduce the k-points."
653 message(2) = "Set SymmetryBreakDir equal to StaticElectricField."
654 call messages_fatal(2, namespace=namespace)
655 end if
656 end do
657 end if
658
659 end select
660 call potential%deallocate_memory()
661
662 class default
663 assert(.false.)
664 end select
665 end do
666
668 end subroutine build_external_potentials
669
670 ! ---------------------------------------------------------
671 subroutine external_potentials_checks()
672 type(list_iterator_t) :: iter
673 class(*), pointer :: potential
674
676
677 call iter%start(hm%external_potentials)
678 do while (iter%has_next())
679 potential => iter%get_next()
680 select type (potential)
681 class is (external_potential_t)
682
683 if (potential%type == external_pot_static_efield .and. hm%kpoints%reduced%npoints > 1) then
684 message(1) = "Applying StaticElectricField in a periodic direction is only accurate for large supercells."
685 message(2) = "Single-point Berry phase is not appropriate when k-point sampling is needed."
686 call messages_warning(2, namespace=namespace)
687 end if
688
689 class default
690 assert(.false.)
691 end select
692 end do
693
695 end subroutine external_potentials_checks
696
697
698 !The code in this routines needs to know about the external potentials.
699 !This will be treated in the future by the interactions directly.
700 subroutine build_interactions()
701 logical :: external_potentials_present
702 logical :: kick_present
703
705
706 if (allocated(hm%ep%e_field) .and. space%is_periodic() .and. .not. list_has_gauge_field(ext_partners)) then
707 ! only need vberry if there is a field in a periodic direction
708 ! and we are not setting a gauge field
709 if (any(abs(hm%ep%e_field(1:space%periodic_dim)) > m_epsilon)) then
710 safe_allocate(hm%vberry(1:gr%np, 1:hm%d%nspin))
711 hm%vberry = m_zero
712 end if
713 end if
714
715 external_potentials_present = epot_have_external_potentials(hm%ep) .or. &
716 list_has_lasers(ext_partners) .or. allocated(hm%v_static)
717
718
719 kick_present = hamiltonian_elec_has_kick(hm)
720
721 call pcm_init(hm%pcm, namespace, space, ions, gr, st%qtot, st%val_charge, external_potentials_present, kick_present)
722 if (hm%pcm%run_pcm) then
723 if (hm%theory_level /= kohn_sham_dft) call messages_not_implemented("PCM for TheoryLevel /= kohn_sham", namespace=namespace)
724 end if
725
727
728 end subroutine build_interactions
729
730
731 end subroutine hamiltonian_elec_init
732
733
734
735
736 ! ---------------------------------------------------------
737 subroutine hamiltonian_elec_end(hm)
738 type(hamiltonian_elec_t), target, intent(inout) :: hm
739
740 type(partner_iterator_t) :: iter
741 class(interaction_partner_t), pointer :: potential
742
744
745 if (hm%is_copy_snapshot) then
746 ! release only pointer targets created by hamiltonian_elec_copy
748 if (allocated(hm%lda_u)) then
749 safe_deallocate_a(hm%lda_u%basis)
750 end if
751 safe_deallocate_a(hm%lda_u)
752 safe_deallocate_a(hm%exxop)
753 safe_deallocate_a(hm%psolver)
754 safe_deallocate_a(hm%scissor)
755 safe_deallocate_a(hm%inh_st)
756 safe_deallocate_a(hm%ep)
757 safe_deallocate_a(hm%pcm)
758 pop_sub(hamiltonian_elec_end)
759 return
760 end if
761
762 call hm%hm_base%end()
763 call hm%vnl%end()
764 call hm%aug_overlap%end()
765 call hm%aug_inverse_overlap%end()
766
767 call hm%phase%end()
768
769 call hm%ks_pot%end()
770 safe_deallocate_a(hm%vberry)
771 safe_deallocate_a(hm%a_ind)
772 safe_deallocate_a(hm%b_ind)
773 safe_deallocate_a(hm%v_ext_pot)
774
775 safe_deallocate_p(hm%zora)
776
777 call poisson_end(hm%psolver)
778
779 nullify(hm%xc)
780
781 call kick_end(hm%kick)
782 call epot_end(hm%ep)
783 if (hm%owns_ions .and. associated(hm%ions)) then
784 ! ions_copy currently aliases species objects through species wrappers.
785 ! Detach wrapper storage to avoid double-finalizing shared species.
786 if (allocated(hm%ions%species)) then
787 safe_deallocate_a(hm%ions%species)
788 hm%ions%nspecies = 0
789 end if
790 safe_deallocate_p(hm%ions)
791 hm%owns_ions = .false.
792 else
793 nullify(hm%ions)
794 hm%owns_ions = .false.
795 end if
796
797 call absorbing_boundaries_end(hm%abs_boundaries)
798
799 call states_elec_dim_end(hm%d)
800
801 if (hm%scissor%apply) call scissor_end(hm%scissor)
802
803 call exchange_operator_end(hm%exxop)
804 call lda_u_end(hm%lda_u)
805
806 safe_deallocate_a(hm%energy)
807
808 if (hm%pcm%run_pcm) call pcm_end(hm%pcm)
810 call hm%v_ie_loc%end()
811 call hm%nlcc%end()
812
813 call iter%start(hm%external_potentials)
814 do while (iter%has_next())
815 potential => iter%get_next()
816 safe_deallocate_p(potential)
817 end do
818 call hm%external_potentials%empty()
819 safe_deallocate_a(hm%v_static)
820
821 call magnetic_constrain_end(hm%magnetic_constrain)
822
823 call mxll_coupling_end(hm%mxll)
824
825 hm%is_copy_snapshot = .false.
826
827 if (allocated(hm%lda_u)) then
828 safe_deallocate_a(hm%lda_u%basis)
829 end if
830 safe_deallocate_a(hm%lda_u)
831 safe_deallocate_a(hm%exxop)
832 safe_deallocate_a(hm%psolver)
833 safe_deallocate_a(hm%scissor)
834 safe_deallocate_a(hm%inh_st)
835 safe_deallocate_a(hm%ep)
836 safe_deallocate_a(hm%pcm)
837
838 pop_sub(hamiltonian_elec_end)
839 end subroutine hamiltonian_elec_end
840
841 ! ---------------------------------------------------------
846 type(hamiltonian_elec_t), target, intent(inout) :: hm
847
848 type(partner_iterator_t) :: iter
849 class(interaction_partner_t), pointer :: potential
850
852
853 if (hm%owns_ions .and. associated(hm%ions)) then
854 if (allocated(hm%ions%species)) then
855 safe_deallocate_a(hm%ions%species)
856 hm%ions%nspecies = 0
857 end if
858 safe_deallocate_p(hm%ions)
859 hm%owns_ions = .false.
860 else
861 nullify(hm%ions)
862 hm%owns_ions = .false.
863 end if
864
865 if (associated(hm%zora)) then
866 safe_deallocate_p(hm%zora)
867 end if
868
869 call iter%start(hm%external_potentials)
870 do while (iter%has_next())
871 potential => iter%get_next()
872 safe_deallocate_p(potential)
873 end do
874 call hm%external_potentials%empty()
875
876 call hm%hm_base%end()
877 call hm%ks_pot%end()
878 call hm%phase%end()
879 call hm%vnl%end()
880 call hm%aug_overlap%end()
881 call hm%aug_inverse_overlap%end()
882 if (hm%lda_u_level /= dft_u_none) call lda_u_end(hm%lda_u)
883
884 hm%is_copy_snapshot = .false.
885
888
889 ! ---------------------------------------------------------
896 subroutine hamiltonian_elec_copy(hm_out, hm_in)
897 type(hamiltonian_elec_t), target, intent(out) :: hm_out
898 type(hamiltonian_elec_t), intent(inout) :: hm_in
899
900 type(ions_t), pointer :: ions_out
901 type(zora_t), pointer :: zora_out
902 type(partner_list_t) :: external_potentials_in
903 type(partner_list_t) :: external_potentials_out
904 type(list_iterator_t) :: iter
905 class(*), pointer :: ptr
906 class(external_potential_t), pointer :: ext_pot
907 logical :: runtime_initialized
908
909 push_sub(hamiltonian_elec_copy)
910
912 runtime_initialized = associated(hm_in%kpoints)
913
914 call iter%start(hm_in%external_potentials)
915 do while (iter%has_next())
916 ptr => iter%get_next()
917 select type (ptr)
918 class is (external_potential_t)
919 call external_potentials_in%add(ptr)
920 call external_potential_clone(ext_pot, ptr)
921 call external_potentials_out%add(ext_pot)
922 class default
923 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
924 end select
925 end do
926 call hm_in%external_potentials%empty()
927
928 hm_out = hm_in
929 hm_out%is_copy_snapshot = .true.
930
931 call epot_bind_poisson_solver(hm_out%ep, hm_out%psolver)
932 call nonlocal_pseudopotential_rebind_projectors(hm_out%vnl, hm_out%ep)
933 call nonlocal_pseudopotential_rebind_projectors(hm_out%aug_overlap, hm_out%ep)
934 call nonlocal_pseudopotential_rebind_projectors(hm_out%aug_inverse_overlap, hm_out%ep)
935 ! The intrinsic assignment aliases the projector-value pointers
937 call nonlocal_pseudopotential_detach_copy(hm_out%aug_overlap, hm_out%vnl)
938 call nonlocal_pseudopotential_detach_copy(hm_out%aug_inverse_overlap, hm_out%vnl)
939
940 if (accel_is_enabled() .and. runtime_initialized .and. associated(hm_out%der)) then
941 call hamiltonian_elec_base_accel_rebuild(hm_out%hm_base, hm_out%der%mesh)
942 call ks_potential_accel_rebuild(hm_out%ks_pot)
943 call phase_accel_rebuild(hm_out%phase, hm_out%der%mesh, hm_out%d%kpt)
944 call nonlocal_pseudopotential_accel_rebuild(hm_out%vnl, hm_out%space, hm_out%der%mesh)
945 call nonlocal_pseudopotential_accel_rebuild(hm_out%aug_overlap, hm_out%space, hm_out%der%mesh)
946 call nonlocal_pseudopotential_accel_rebuild(hm_out%aug_inverse_overlap, hm_out%space, hm_out%der%mesh)
947 end if
948
949 call hm_out%external_potentials%empty()
950 call iter%start(external_potentials_out)
951 do while (iter%has_next())
952 ptr => iter%get_next()
953 select type (ptr)
954 class is (external_potential_t)
955 call hm_out%external_potentials%add(ptr)
956 class default
957 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
958 end select
959 end do
960 call iter%start(external_potentials_in)
961 do while (iter%has_next())
962 ptr => iter%get_next()
963 select type (ptr)
964 class is (external_potential_t)
965 call hm_in%external_potentials%add(ptr)
966 class default
967 call messages_not_implemented("hamiltonian_elec_copy with unsupported external potential partner")
968 end select
969 end do
970 call external_potentials_out%empty()
971 call external_potentials_in%empty()
972
973 if (runtime_initialized) then
974 call kick_end(hm_out%kick)
975 call kick_copy(hm_out%kick, hm_in%kick)
976
977 if (allocated(hm_in%energy)) then
978 if (.not. allocated(hm_out%energy)) safe_allocate(hm_out%energy)
979 call energy_copy(hm_in%energy, hm_out%energy)
980 else
981 safe_deallocate_a(hm_out%energy)
982 end if
983
984 call magnetic_constrain_copy(hm_out%magnetic_constrain, hm_in%magnetic_constrain)
985 call mxll_coupling_copy(hm_out%mxll, hm_in%mxll, hm_out%der)
986 end if
987
988 if (associated(hm_in%ions)) then
989 safe_allocate(ions_out)
990 ions_out = hm_in%ions
991 hm_out%ions => ions_out
992 hm_out%owns_ions = .true.
993 call hm_out%v_ie_loc%bind(hm_out%psolver, hm_out%ions)
994 call hm_out%nlcc%bind(hm_out%ions)
995 else
996 nullify(hm_out%ions)
997 hm_out%owns_ions = .false.
998 nullify(hm_out%v_ie_loc%atoms_dist)
999 nullify(hm_out%v_ie_loc%atom)
1000 nullify(hm_out%v_ie_loc%pos)
1001 nullify(hm_out%nlcc%atoms_dist)
1002 nullify(hm_out%nlcc%atom)
1003 nullify(hm_out%nlcc%pos)
1004 end if
1005
1006 if (hm_out%lda_u_level /= dft_u_none .and. associated(hm_out%ions)) then
1007 call lda_u_rebind_after_copy(hm_out%lda_u, hm_out%ions)
1008 if (accel_is_enabled() .and. runtime_initialized) then
1009 call lda_u_accel_rebuild(hm_out%lda_u, hm_out%d%kpt)
1010 end if
1011 end if
1012
1013 if (associated(hm_in%zora)) then
1014 allocate(zora_out, source=hm_in%zora)
1015 hm_out%zora => zora_out
1016 else
1017 nullify(hm_out%zora)
1018 end if
1019
1020 pop_sub(hamiltonian_elec_copy)
1021
1022 end subroutine hamiltonian_elec_copy
1023
1024 ! ---------------------------------------------------------
1027 type(hamiltonian_elec_t), intent(in) :: hm_in
1028
1029 logical :: runtime_initialized
1030
1032
1033 runtime_initialized = associated(hm_in%kpoints)
1034 if (.not. runtime_initialized) then
1036 return
1037 end if
1038
1039 if (hm_in%theory_level == hartree_fock .or. hm_in%theory_level == rdmft) then
1040 call messages_not_implemented("hamiltonian_elec_copy with HF/RDMFT exchange operator paths")
1041 end if
1042
1043 if (associated(hm_in%xc)) then
1044 if (hm_in%xc%compute_exchange(hm_in%theory_level)) then
1045 call messages_not_implemented("hamiltonian_elec_copy with hybrid/OEP exchange paths")
1046 end if
1047 end if
1048
1049 if (hamiltonian_elec_inh_term(hm_in)) then
1050 call messages_not_implemented("hamiltonian_elec_copy with OCT inhomogeneous/source term")
1051 end if
1052
1053 if (oct_exchange_enabled(hm_in%oct_exchange)) then
1054 call messages_not_implemented("hamiltonian_elec_copy with OCT exchange term")
1055 end if
1056
1057 if (hm_in%pcm%run_pcm) then
1058 call messages_not_implemented("hamiltonian_elec_copy with PCM enabled")
1059 end if
1060
1063
1064
1065 ! ---------------------------------------------------------
1066 ! True if the Hamiltonian is Hermitian, false otherwise
1067 logical function hamiltonian_elec_hermitian(hm)
1068 class(hamiltonian_elec_t), intent(in) :: hm
1069
1071 hamiltonian_elec_hermitian = .not.((hm%abs_boundaries%abtype == imaginary_absorbing) .or. &
1072 oct_exchange_enabled(hm%oct_exchange))
1073
1075 end function hamiltonian_elec_hermitian
1076
1077 ! ---------------------------------------------------------
1078 ! True if the Hamiltonian needs to apply the mGGA term
1079 pure logical function hamiltonian_elec_needs_mgga_term(hm, terms)
1080 class(hamiltonian_elec_t), intent(in) :: hm
1081 integer, intent(in) :: terms
1082
1084
1085 if (bitand(term_mgga, terms) /= 0 .and. family_is_mgga_with_exc(hm%xc) &
1086 .and. hm%theory_level == generalized_kohn_sham_dft) then
1088 end if
1089
1090 !For OEP
1091 if(terms == term_mgga .and. family_is_mgga_with_exc(hm%xc) .and. hm%theory_level == kohn_sham_dft) then
1093 end if
1094
1096
1097
1099 ! ---------------------------------------------------------
1100 subroutine hamiltonian_elec_span(hm, delta, emin, namespace)
1101 class(hamiltonian_elec_t), intent(inout) :: hm
1102 real(real64), intent(in) :: delta(:)
1103 real(real64), intent(in) :: emin
1104 type(namespace_t), intent(in) :: namespace
1105
1106 real(real64) :: emax
1107
1108 push_sub(hamiltonian_elec_span)
1109
1110 ! estimate maximum energy of discrete kinetic operator
1111 ! this neglects possible contributions from the non-local part of the pseudopotentials
1113
1114 hm%spectral_middle_point = (emax + emin) / m_two
1115 hm%spectral_half_span = (emax - emin) / m_two
1116
1117 pop_sub(hamiltonian_elec_span)
1118 end subroutine hamiltonian_elec_span
1119
1120
1121 ! ---------------------------------------------------------
1122 pure logical function hamiltonian_elec_inh_term(hm) result(inh)
1123 type(hamiltonian_elec_t), intent(in) :: hm
1124
1125 inh = hm%inh_term
1126 end function hamiltonian_elec_inh_term
1127
1128
1129 ! ---------------------------------------------------------
1130 subroutine hamiltonian_elec_set_inh(hm, st)
1131 type(hamiltonian_elec_t), intent(inout) :: hm
1132 type(states_elec_t), intent(in) :: st
1133
1134 push_sub(hamiltonian_elec_set_inh)
1135
1136 if (hm%inh_term) call states_elec_end(hm%inh_st)
1137 call states_elec_copy(hm%inh_st, st)
1138 hm%inh_term = .true.
1141 end subroutine hamiltonian_elec_set_inh
1142
1143
1144 ! ---------------------------------------------------------
1145 subroutine hamiltonian_elec_remove_inh(hm)
1146 type(hamiltonian_elec_t), intent(inout) :: hm
1147
1149
1150 if (hm%inh_term) then
1151 call states_elec_end(hm%inh_st)
1152 hm%inh_term = .false.
1153 end if
1154
1156 end subroutine hamiltonian_elec_remove_inh
1157
1158 ! ---------------------------------------------------------
1159 subroutine hamiltonian_elec_adjoint(hm)
1160 type(hamiltonian_elec_t), intent(inout) :: hm
1161
1162 push_sub(hamiltonian_elec_adjoint)
1163
1164 if (.not. hm%adjoint) then
1165 hm%adjoint = .true.
1166 if (hm%abs_boundaries%abtype == imaginary_absorbing) then
1167 hm%abs_boundaries%mf = -hm%abs_boundaries%mf
1168 end if
1169 end if
1170
1173
1174
1175 ! ---------------------------------------------------------
1176 subroutine hamiltonian_elec_not_adjoint(hm)
1177 type(hamiltonian_elec_t), intent(inout) :: hm
1178
1180
1181 if (hm%adjoint) then
1182 hm%adjoint = .false.
1183 if (hm%abs_boundaries%abtype == imaginary_absorbing) then
1184 hm%abs_boundaries%mf = -hm%abs_boundaries%mf
1185 end if
1186 end if
1187
1189 end subroutine hamiltonian_elec_not_adjoint
1190
1191
1192 ! ---------------------------------------------------------
1194 subroutine hamiltonian_elec_update(this, mesh, namespace, space, ext_partners, time)
1195 class(hamiltonian_elec_t), intent(inout) :: this
1196 class(mesh_t), intent(in) :: mesh
1197 type(namespace_t), intent(in) :: namespace
1198 class(space_t), intent(in) :: space
1199 type(partner_list_t), intent(in) :: ext_partners
1200 real(real64), optional, intent(in) :: time
1201
1202 integer :: ispin, ip, idir, iatom, ilaser
1203 real(real64) :: aa(space%dim), time_
1204 real(real64), allocatable :: vp(:,:)
1205 type(lasers_t), pointer :: lasers
1206 type(gauge_field_t), pointer :: gfield
1207 real(real64) :: am(space%dim)
1208
1209 push_sub(hamiltonian_elec_update)
1210 call profiling_in("HAMILTONIAN_ELEC_UPDATE")
1211
1212 this%current_time = m_zero
1213 if (present(time)) this%current_time = time
1214
1215 time_ = optional_default(time, 0.0_real64)
1216
1217 ! set everything to zero
1218 call this%hm_base%clear(mesh%np)
1219
1220 ! alllocate the scalar potential for the xc, hartree and external potentials
1221 call this%hm_base%allocate_field(mesh, field_potential, &
1222 complex_potential = this%abs_boundaries%abtype == imaginary_absorbing)
1223
1224 ! the lasers
1225 if (present(time) .or. this%time_zero) then
1226
1227 lasers => list_get_lasers(ext_partners)
1228 if(associated(lasers)) then
1229 do ilaser = 1, lasers%no_lasers
1230 select case (laser_kind(lasers%lasers(ilaser)))
1232 do ispin = 1, this%d%spin_channels
1233 call laser_potential(lasers%lasers(ilaser), mesh, &
1234 this%hm_base%potential(:, ispin), time_)
1235 end do
1236 case (e_field_magnetic)
1237 call this%hm_base%allocate_field(mesh, field_vector_potential + field_uniform_magnetic_field, &
1238 .false.)
1239 ! get the vector potential
1240 safe_allocate(vp(1:mesh%np, 1:space%dim))
1241 vp(1:mesh%np, 1:space%dim) = m_zero
1242 call laser_vector_potential(lasers%lasers(ilaser), mesh, vp, time_)
1243 !$omp parallel do private(idir) schedule(static)
1244 do ip = 1, mesh%np
1245 do idir = 1, space%dim
1246 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + vp(ip, idir)/p_c
1247 end do
1248 end do
1249 ! and the magnetic field
1250 call laser_field(lasers%lasers(ilaser), this%hm_base%uniform_magnetic_field(1:space%dim), time_)
1251 safe_deallocate_a(vp)
1253 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1254 ! get the uniform vector potential associated with a magnetic field
1255 aa = m_zero
1256 call laser_field(lasers%lasers(ilaser), aa, time_)
1257 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1258 end select
1259 end do
1260
1261 if (lasers_with_nondipole_field(lasers)) then
1262 assert( allocated(this%hm_base%uniform_vector_potential))
1263 call lasers_nondipole_laser_field_step(lasers, am, time_)
1264 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - am/p_c
1265 end if
1266 end if
1267
1268 ! the gauge field
1269 gfield => list_get_gauge_field(ext_partners)
1270 if (associated(gfield)) then
1271 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1272 call gauge_field_get_vec_pot(gfield, aa)
1273 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1274 end if
1275
1276 ! the electric field for a periodic system through the gauge field
1277 if (allocated(this%ep%e_field) .and. associated(gfield)) then
1278 this%hm_base%uniform_vector_potential(1:space%periodic_dim) = &
1279 this%hm_base%uniform_vector_potential(1:space%periodic_dim) - time_*this%ep%e_field(1:space%periodic_dim)
1280 end if
1281
1282 ! add the photon-free mean-field vector potential
1283 if (associated(this%xc_photons)) then
1284 if(this%xc_photons%lpfmf .and. allocated(this%xc_photons%mf_vector_potential)) then
1285 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1286 ! here we put a minus sign in front of the mean field term to get the right answer (need to check the formula)
1287 this%hm_base%uniform_vector_potential(1:space%dim) = &
1288 this%hm_base%uniform_vector_potential(1:space%dim) - this%xc_photons%mf_vector_potential(1:space%dim)/p_c
1289 end if
1290 end if
1291
1292 end if
1293
1294 ! the vector potential of a static magnetic field
1295 if (allocated(this%ep%a_static)) then
1296 call this%hm_base%allocate_field(mesh, field_vector_potential, .false.)
1297 !ep%a_static contains 1/c A(r)
1298 !$omp parallel do private(idir) schedule(static)
1299 do ip = 1, mesh%np
1300 do idir = 1, space%dim
1301 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + this%ep%a_static(ip, idir)
1302 end do
1303 end do
1304 end if
1305
1306 ! add Maxwell coupling to Hamiltonian and sets the magnetic field for the Zeeman term added below
1307 call mxll_coupling_calc(this%mxll, this%hm_base, mesh, this%d, space)
1308
1309 !The electric field was added to the KS potential
1310 call this%hm_base%accel_copy_pot(mesh)
1311
1312 ! and the static magnetic field
1313 if (allocated(this%ep%b_field)) then
1314 call this%hm_base%allocate_field(mesh, field_uniform_magnetic_field, .false.)
1315 do idir = 1, 3
1316 this%hm_base%uniform_magnetic_field(idir) = this%hm_base%uniform_magnetic_field(idir) + this%ep%b_field(idir)
1317 end do
1318 end if
1319
1320 ! Combine the uniform and non-uniform fields and compute the Zeeman term
1321 call this%hm_base%update_magnetic_terms(mesh, this%ep%gyromagnetic_ratio, this%d%ispin)
1322
1323 ! This needs to be called at the end as the zeeman term enters the potential
1324 call hamiltonian_elec_update_pot(this, mesh, accumulate = .true.)
1325
1326 if (this%mxll%test_equad) then
1327 call set_electric_quadrupole_pot(this%mxll, mesh)
1328 end if
1329
1330 call build_phase()
1331
1332 ! Note: the ultrasoft/PAW screening D_ij = D_ij^(0) + int V_s(r) Q_ij(r) dr is done
1333 ! in hamiltonian_elec_update_pot (called above via hamiltonian_elec_update_pot with
1334 ! accumulate=.true.), where the full local potential V_s = V_loc + V_Hxc is assembled.
1335
1336 call profiling_out("HAMILTONIAN_ELEC_UPDATE")
1338
1339 contains
1340
1341 subroutine build_phase()
1342
1344
1345 if ((.not. this%kpoints%gamma_only()) .or. allocated(this%hm_base%uniform_vector_potential)) then
1346
1347 call profiling_in('UPDATE_PHASES')
1348 ! now regenerate the phases for the pseudopotentials
1349 do iatom = 1, this%ep%natoms
1350 call projector_init_phases(this%ep%proj(iatom), space%dim, this%d, this%der%boundaries, this%kpoints, &
1351 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1352 end do
1353
1354 call profiling_out('UPDATE_PHASES')
1355 end if
1356
1357 if (allocated(this%hm_base%uniform_vector_potential)) then
1358
1359 call this%phase%update(mesh, this%d%kpt, this%kpoints, this%d, space, this%hm_base%uniform_vector_potential)
1360
1361 ! We rebuild the phase for the orbital projection, similarly to the one of the pseudopotentials
1362 if (this%lda_u_level /= dft_u_none) then
1363 call lda_u_build_phase_correction(this%lda_u, space, this%d, this%der%boundaries, namespace, this%kpoints, &
1364 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1365 end if
1366 end if
1367
1368 call hamiltonian_elec_build_projector_phases(this, this%vnl, async=.true.)
1369 if (this%ep%requires_generalized_overlap) then
1370 call profiling_in('UPDATE_OVERLAP')
1371 call hamiltonian_elec_build_projector_phases(this, this%aug_overlap, async=.true.)
1372 call hamiltonian_elec_build_projector_phases(this, this%aug_inverse_overlap, async=.true.)
1373 ! Exact inverse overlap
1374 if (this%aug_inverse_overlap%ovlp_inv%use_global_coupling) then
1375 if (.not. this%aug_inverse_overlap%ovlp_inv%coupling_built .or. this%phase%is_allocated()) then
1376 call this%aug_inverse_overlap%ovlp_inv%build(this%aug_inverse_overlap%projector_matrices, &
1377 this%aug_inverse_overlap%projector_phases, mesh, this%d%kpt%start, this%d%kpt%end)
1378 end if
1379 end if
1380 call profiling_out('UPDATE_OVERLAP')
1381 end if
1382
1383 call accel_finish()
1384
1386 end subroutine build_phase
1387
1388 end subroutine hamiltonian_elec_update
1389
1390
1391 !----------------------------------------------------------------
1394 ! TODO: See Issue #1064
1395 subroutine hamiltonian_elec_update_pot(this, mesh, accumulate)
1396 type(hamiltonian_elec_t), intent(inout) :: this
1397 class(mesh_t), intent(in) :: mesh
1398 logical, optional, intent(in) :: accumulate
1399
1400 integer :: ispin, ip
1401 real(real64), allocatable :: vscreen(:,:)
1402
1404
1405 ! By default we nullify first the result
1406 if (.not. optional_default(accumulate, .false.)) then
1407 !$omp parallel private(ip, ispin)
1408 do ispin = 1, this%d%nspin
1409 !$omp do simd schedule(static)
1410 do ip = 1, mesh%np
1411 this%hm_base%potential(ip, ispin) = m_zero
1412 end do
1413 end do
1414 !$omp end parallel
1415 if (this%abs_boundaries%abtype == imaginary_absorbing) then
1416 this%hm_base%Impotential = m_zero
1417 end if
1418 end if
1419
1420 !$omp parallel private(ip, ispin)
1421 do ispin = 1, this%d%nspin
1422 if (ispin <= 2) then
1423 !$omp do simd schedule(static)
1424 ! this%vhxc(ip, ispin) is added after the calculation of ZORA potential
1425 do ip = 1, mesh%np
1426 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%ep%vpsl(ip) + this%v_ext_pot(ip)
1427 end do
1428
1430 if (this%pcm%run_pcm) then
1431 if (this%pcm%solute) then
1432 !$omp do simd schedule(static)
1433 do ip = 1, mesh%np
1434 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + &
1435 this%pcm%v_e_rs(ip) + this%pcm%v_n_rs(ip)
1436 end do
1437 !$omp end do simd nowait
1438 end if
1439 if (this%pcm%localf) then
1440 !$omp do simd schedule(static)
1441 do ip = 1, mesh%np
1442 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + &
1443 this%pcm%v_ext_rs(ip)
1444 end do
1445 !$omp end do simd nowait
1446 end if
1447 end if
1448
1450 if (this%abs_boundaries%abtype == imaginary_absorbing) then
1451 !$omp do simd schedule(static)
1452 do ip = 1, mesh%np
1453 this%hm_base%Impotential(ip, ispin) = this%hm_base%Impotential(ip, ispin) + this%abs_boundaries%mf(ip)
1454 end do
1455 !$omp end do simd nowait
1456 end if
1457 end if
1458 end do
1459 !$omp end parallel
1460
1461 ! scalar relativistic ZORA contribution
1462 ! \boldsymbol{p} \frac{c^2}{2c^2 - V} \boldsymbol{p} \Phi^\mathrm{ZORA}
1463 ! Note that V here is the ionic plus external potential only: vHxc is added below, and is
1464 ! deliberately excluded from the ZORA prefactor. This makes it comparable to a one-electron
1465 ! X2C rather than to a full ZORA, and it is what allows zora_update to treat V as spin
1466 ! independent. Do not move this call after add_vhxc without revisiting zora_update.
1467 if (this%ep%reltype == scalar_relativistic_zora .or. this%ep%reltype == fully_relativistic_zora) then
1468 call this%zora%update(this%der, this%hm_base%potential)
1469 end if
1470
1471 !$omp parallel private(ip, ispin)
1472 do ispin = 1, this%d%nspin
1473 ! Adding Zeeman potential to hm_base%potential
1474 if (allocated(this%hm_base%zeeman_pot)) then
1475 !$omp do simd schedule(static)
1476 do ip = 1, mesh%np
1477 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%hm_base%zeeman_pot(ip, ispin)
1478 end do
1479 !$omp end do simd nowait
1480 end if
1481
1482 ! Adding Quadrupole potential from static E-field (test)
1483 if (this%mxll%test_equad) then
1484 !$omp do simd schedule(static)
1485 do ip = 1, mesh%np
1486 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + this%mxll%e_quadrupole_pot(ip)
1487 end do
1488 !$omp end do simd
1489 end if
1490 end do
1491 !$omp end parallel
1492
1493
1494 ! Add the Hartree and KS potential
1495 call this%ks_pot%add_vhxc(this%hm_base%potential)
1496
1497 call this%hm_base%accel_copy_pot(mesh)
1498
1499 ! For ultrasoft/PAW, screen the nonlocal coupling with the freshly assembled
1500 ! full local potential V_s = V_loc + V_Hxc: D_ij = D_ij^(0) + int V_s(r) Q_ij(r) dr.
1501 if (this%ep%requires_generalized_overlap) then
1502 ! In the Bloechl scheme n^hat is excluded from the XC, so V_xc must not screen the coupling
1503 if (this%ep%has_paw .and. .not. this%xc%usexcnhat .and. allocated(this%ks_pot%vxc)) then
1504 safe_allocate(vscreen(1:mesh%np, 1:this%d%nspin))
1505 call lalg_copy(mesh%np, this%d%nspin, this%hm_base%potential, vscreen)
1506 call lalg_axpy(mesh%np, this%d%nspin, -m_one, this%ks_pot%vxc, vscreen)
1507 end if
1508 ! For PAW the one-center density matrix (onsite_density_matrix) is accumulated during the density
1509 ! calculation on the overlap instance; pass it so update_dij can build the one-center
1510 ! Hartree/XC coupling (D^1 - D~^1)_Hxc and energy correction. Once the projectors are built
1511 ! the matrix must exist: without it the one-center terms cannot be evaluated.
1512 ! For independent particles there is no electron-electron interaction
1513 if (this%ep%has_paw .and. this%vnl%nprojector_matrices > 0 .and. this%theory_level == independent_particles) then
1514 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, this%hm_base%potential, &
1515 paw_onsite_hxc = .false.)
1516 else if (this%ep%has_paw .and. this%vnl%nprojector_matrices > 0) then
1517 if (.not. allocated(this%aug_overlap%onsite_density_matrix)) then
1518 message(1) = "Internal error: the PAW one-center density matrix is not allocated,"
1519 message(2) = "the one-center contributions to the Hamiltonian cannot be computed."
1520 call messages_fatal(2)
1521 end if
1522 if (allocated(vscreen)) then
1523 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, vscreen, &
1524 onsite_density_matrix = this%aug_overlap%onsite_density_matrix)
1525 else
1526 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, this%hm_base%potential, &
1527 onsite_density_matrix = this%aug_overlap%onsite_density_matrix)
1528 end if
1529 else
1530 call nonlocal_pseudopotential_update_dij(this%vnl, mesh, this%ep, this%hm_base%potential)
1531 end if
1532 safe_deallocate_a(vscreen)
1533 end if
1534
1536 end subroutine hamiltonian_elec_update_pot
1537
1538 ! ---------------------------------------------------------
1544 subroutine hamiltonian_elec_xc_nhat(this, mesh, nhat)
1545 type(hamiltonian_elec_t), intent(in) :: this
1546 class(mesh_t), intent(in) :: mesh
1547 real(real64), allocatable, intent(inout) :: nhat(:,:)
1548
1549 integer :: is
1550
1551 push_sub(hamiltonian_elec_xc_nhat)
1552
1553 safe_deallocate_a(nhat)
1554 if (this%ep%has_paw .and. .not. this%xc%usexcnhat) then
1555 assert(this%d%ispin /= spinors)
1556 safe_allocate(nhat(1:mesh%np_part, 1:this%d%spin_channels))
1557 nhat = m_zero
1558 if (allocated(this%aug_overlap%onsite_density_matrix)) then
1559 do is = 1, this%d%spin_channels
1560 call nonlocal_pseudopotential_aug_density(this%vnl, mesh, this%ep, &
1561 this%aug_overlap%onsite_density_matrix(:, :, :, is), nhat(:, is))
1562 end do
1563 end if
1564 end if
1565
1567 end subroutine hamiltonian_elec_xc_nhat
1568
1569 ! ---------------------------------------------------------
1570 subroutine hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
1571 ! target: the NLCC reinit below stores a pointer to the epot-owned atom distribution
1572 type(hamiltonian_elec_t), target, intent(inout) :: this
1573 type(namespace_t), intent(in) :: namespace
1574 class(electron_space_t), intent(in) :: space
1575 type(grid_t), intent(in) :: gr
1576 type(ions_t), target, intent(inout) :: ions
1577 type(partner_list_t), intent(in) :: ext_partners
1578 type(states_elec_t), intent(inout) :: st
1579 real(real64), optional, intent(in) :: time
1580
1581 type(xc_functional_t), pointer :: xfp(:)
1582 integer :: xc_spin_col
1583
1585
1586 this%ions => ions
1587 call epot_generate(this%ep, namespace, gr, this%ions, this%d, st%st_kpt_mpi_grp)
1588 st%requires_generalized_overlap = this%ep%requires_generalized_overlap
1589
1590 ! Share that handle with the PAW one-center engines so they use the same parameters
1591 if (this%ep%has_paw .and. associated(this%xc)) then
1592 if (xc_functional_needs_shared_paw_handle(this%xc%functional(func_x, 1))) then
1593 xc_spin_col = merge(1, 2, this%d%ispin == unpolarized)
1594 xfp => this%xc%functional(:, xc_spin_col)
1595 call epot_set_shared_paw_xc(this%ep, xfp)
1596 end if
1597 end if
1598
1599 ! Interation terms are treated below
1600
1601 ! First we add the static electric field
1602 if (allocated(this%ep%e_field) .and. space%periodic_dim < space%dim) then
1603 call lalg_axpy(gr%np, m_one, this%v_static, this%ep%vpsl)
1604 end if
1605
1606 ! Here we need to pass this again, else test are failing.
1607 ! This is not a real problem, as the multisystem framework will indeed to this anyway
1608 this%v_ie_loc%atoms_dist => ions%atoms_dist
1609 this%v_ie_loc%atom => ions%atom
1610 call this%v_ie_loc%calculate()
1611
1612 ! At the moment we need to add this to ep%vpsl, to keep the behavior of the code
1613 call lalg_axpy(gr%np, m_one, this%v_ie_loc%potential(:,1), this%ep%vpsl)
1614
1615 ! Here we need to reinit the NLCC object
1616 ! This is not a real problem, as the multisystem framework will indeed to this anyway
1617 if (this%ep%nlcc) then
1618 call this%nlcc%end()
1619 call this%nlcc%init(gr, ions, this%ep%dgrid, this%ep%atoms_dist_plane, derivatives = this%ep%has_paw)
1620 call this%nlcc%calculate()
1621 call lalg_copy(gr%np, this%nlcc%density(:,1), st%rho_core)
1622 if (allocated(st%rho_core_grad)) then
1623 call lalg_copy(gr%np, space%dim, this%nlcc%grad, st%rho_core_grad)
1624 call lalg_copy(gr%np, this%nlcc%lapl, st%rho_core_lapl)
1625 end if
1626 end if
1627
1628 call this%vnl%build(space, gr, this%ep, this%d%ispin)
1629 if (this%ep%requires_generalized_overlap) then
1630 call this%aug_overlap%build(space, gr, this%ep, this%d%ispin, overlap_operator = .true.)
1631 call this%aug_inverse_overlap%build(space, gr, this%ep, this%d%ispin, inverse_overlap_operator = .true.)
1632 if (allocated(this%aug_overlap%onsite_current_matrix)) then
1633 call paw_ae_build_current_basis(this%aug_overlap, this%ep, space%dim)
1634 end if
1635 ! The three instances project onto the same beta functions; free the duplicate
1636 ! per-point projector arrays of the overlap instances and alias the vnl ones
1637 ! (only the small mix matrices differ).
1638 call nonlocal_pseudopotential_share_projector_data(this%aug_overlap, this%vnl)
1639 call nonlocal_pseudopotential_share_projector_data(this%aug_inverse_overlap, this%vnl)
1640 ! PAW: precompute the crystal-symmetry data to symmetrize the one-center density matrix
1641 ! (accumulated on the overlap instance during the density calculation).
1642 if (this%ep%has_paw) then
1643 call nonlocal_pseudopotential_build_paw_symm(this%aug_overlap, this%ep, space, gr, ions)
1644 end if
1645 else
1646 call this%aug_overlap%end()
1647 call this%aug_inverse_overlap%end()
1648 end if
1649 call hamiltonian_elec_update(this, gr, namespace, space, ext_partners, time)
1650
1651 ! Check if projectors are still compatible with apply_packed on GPU
1652 if (this%is_applied_packed .and. accel_is_enabled()) then
1653 if (this%ep%non_local .and. .not. this%vnl%apply_projector_matrices) then
1654 if (accel_allow_cpu_only()) then
1655 call messages_write('Relativistic pseudopotentials have not been fully implemented for GPUs.')
1656 call messages_warning(namespace=namespace)
1657 else
1658 call messages_write('Relativistic pseudopotentials have not been fully implemented for GPUs.',&
1659 new_line = .true.)
1660 call messages_write('Calculation will not be continued. To force execution, set AllowCPUonly = yes.')
1661 call messages_fatal(namespace=namespace)
1662 end if
1663 end if
1664
1665 end if
1666
1667 if (this%pcm%run_pcm) then
1670 if (this%pcm%solute) then
1671 call pcm_calc_pot_rs(this%pcm, gr, this%psolver, ions = ions)
1672 end if
1673
1676 ! Interpolation is needed, hence gr%np_part -> 1:gr%np
1677 if (this%pcm%localf .and. allocated(this%v_static)) then
1678 call pcm_calc_pot_rs(this%pcm, gr, this%psolver, v_ext = this%ep%v_ext(1:gr%np_part))
1679 end if
1680
1681 end if
1682
1683 call lda_u_update_basis(this%lda_u, space, gr, ions, st, this%psolver, namespace, this%kpoints, &
1684 this%phase%is_allocated(), this%aug_overlap)
1685
1687 end subroutine hamiltonian_elec_epot_generate
1688
1689 ! -----------------------------------------------------------------
1690
1691 real(real64) function hamiltonian_elec_get_time(this) result(time)
1692 type(hamiltonian_elec_t), intent(inout) :: this
1693
1694 time = this%current_time
1695 end function hamiltonian_elec_get_time
1696
1697 ! -----------------------------------------------------------------
1698
1699 pure logical function hamiltonian_elec_apply_packed(this) result(apply)
1700 class(hamiltonian_elec_t), intent(in) :: this
1701
1702 apply = this%is_applied_packed
1703
1705
1706
1707 ! -----------------------------------------------------------------
1708 subroutine zhamiltonian_elec_apply_atom (hm, namespace, space, latt, species, pos, ia, mesh, psi, vpsi)
1709 type(hamiltonian_elec_t), intent(in) :: hm
1710 type(namespace_t), intent(in) :: namespace
1711 class(space_t), intent(in) :: space
1712 type(lattice_vectors_t), intent(in) :: latt
1713 class(species_t), intent(in) :: species
1714 real(real64), intent(in) :: pos(1:space%dim)
1715 integer, intent(in) :: ia
1716 class(mesh_t), intent(in) :: mesh
1717 complex(real64), contiguous, intent(in) :: psi(:,:)
1718 complex(real64), contiguous, intent(out) :: vpsi(:,:)
1719
1720 integer :: idim, ip
1721 real(real64), allocatable :: vlocal(:)
1723
1724 safe_allocate(vlocal(1:mesh%np_part))
1725 vlocal = m_zero
1726 call epot_local_potential(hm%ep, namespace, space, latt, mesh, species, pos, ia, vlocal)
1727
1728 !$omp parallel private(idim, ip)
1729 do idim = 1, hm%d%dim
1730 !$omp do
1731 do ip = 1, mesh%np
1732 vpsi(ip, idim) = vlocal(ip) * psi(ip, idim)
1733 end do
1734 end do
1735 !$omp end parallel
1736
1737 safe_deallocate_a(vlocal)
1739 end subroutine zhamiltonian_elec_apply_atom
1740
1741 ! ---------------------------------------------------------
1746 subroutine hamiltonian_elec_update_with_ext_pot(this, mesh, space, ext_partners, time, mu)
1747 type(hamiltonian_elec_t), intent(inout) :: this
1748 class(space_t), intent(in) :: space
1749 class(mesh_t), intent(in) :: mesh
1750 type(partner_list_t), intent(in) :: ext_partners
1751 real(real64), intent(in) :: time(1:2)
1752 real(real64), intent(in) :: mu(1:2)
1753
1754 integer :: ispin, ip, idir, iatom, ilaser, itime
1755 real(real64) :: aa(space%dim), bb(space%dim), time_
1756 real(real64), allocatable :: vp(:,:)
1757 real(real64), allocatable :: velectric(:)
1758 type(lasers_t), pointer :: lasers
1759 type(gauge_field_t), pointer :: gfield
1760
1762 call profiling_in("HAMILTONIAN_ELEC_UPDATE_EXT_POT")
1764 this%current_time = m_zero
1765 this%current_time = time(1)
1766
1767 ! set everything to zero
1768 call this%hm_base%clear(mesh%np)
1769
1770 ! the xc, hartree and external potentials
1771 call this%hm_base%allocate_field(mesh, field_potential, &
1772 complex_potential = this%abs_boundaries%abtype == imaginary_absorbing)
1773
1774 do itime = 1, 2
1775 time_ = time(itime)
1776
1777 lasers => list_get_lasers(ext_partners)
1778 if(associated(lasers)) then
1779 do ilaser = 1, lasers%no_lasers
1780 select case (laser_kind(lasers%lasers(ilaser)))
1781 case (e_field_scalar_potential, e_field_electric)
1782 safe_allocate(velectric(1:mesh%np))
1783 do ispin = 1, this%d%spin_channels
1784 velectric = m_zero
1785 call laser_potential(lasers%lasers(ilaser), mesh, velectric, time_)
1786 !$omp parallel do simd schedule(static)
1787 do ip = 1, mesh%np
1788 this%hm_base%potential(ip, ispin) = this%hm_base%potential(ip, ispin) + mu(itime) * velectric(ip)
1789 end do
1790 end do
1791 safe_deallocate_a(velectric)
1792 case (e_field_magnetic)
1793 call this%hm_base%allocate_field(mesh, field_vector_potential + field_uniform_magnetic_field, .false.)
1794 ! get the vector potential
1795 safe_allocate(vp(1:mesh%np, 1:space%dim))
1796 vp(1:mesh%np, 1:space%dim) = m_zero
1797 call laser_vector_potential(lasers%lasers(ilaser), mesh, vp, time_)
1798 do idir = 1, space%dim
1799 !$omp parallel do schedule(static)
1800 do ip = 1, mesh%np
1801 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) &
1802 + mu(itime) * vp(ip, idir)/p_c
1803 end do
1804 end do
1805 ! and the magnetic field
1806 bb = m_zero
1807 call laser_field(lasers%lasers(ilaser), bb(1:space%dim), time_)
1808 this%hm_base%uniform_magnetic_field = this%hm_base%uniform_magnetic_field &
1809 + mu(itime) * bb
1810 safe_deallocate_a(vp)
1811 case (e_field_vector_potential)
1812 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1813 ! get the uniform vector potential associated with a magnetic field
1814 aa = m_zero
1815 call laser_field(lasers%lasers(ilaser), aa, time_)
1816 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) &
1817 - mu(itime) * aa/p_c
1818 end select
1819 end do
1820 end if
1821
1822 ! the gauge field
1823 gfield => list_get_gauge_field(ext_partners)
1824 if (associated(gfield)) then
1825 call this%hm_base%allocate_field(mesh, field_uniform_vector_potential, .false.)
1826 call gauge_field_get_vec_pot(gfield, aa)
1827 this%hm_base%uniform_vector_potential(1:space%dim) = this%hm_base%uniform_vector_potential(1:space%dim) - aa/p_c
1828 end if
1829
1830 ! the electric field for a periodic system through the gauge field
1831 ! TODO: The condition is wrong here: the e_field should be in non-periodic dims as E field
1832 ! and as a gauge field in the periodic dim, unless we use a Bery phase, in which, we do not use it
1833 ! this way. But this is unrelated to the gauge field
1834 if (allocated(this%ep%e_field) .and. associated(gfield)) then
1835 this%hm_base%uniform_vector_potential(1:space%periodic_dim) = &
1836 this%hm_base%uniform_vector_potential(1:space%periodic_dim) - time_*this%ep%e_field(1:space%periodic_dim)
1837 end if
1838
1839 end do
1840
1841 ! the vector potential of a static magnetic field
1842 if (allocated(this%ep%a_static)) then
1843 call this%hm_base%allocate_field(mesh, field_vector_potential, .false.)
1844 !ep%a_static contains 1/c A(r)
1845 !$omp parallel do schedule(static) private(idir)
1846 do ip = 1, mesh%np
1847 do idir = 1, space%dim
1848 this%hm_base%vector_potential(idir, ip) = this%hm_base%vector_potential(idir, ip) + this%ep%a_static(ip, idir)
1849 end do
1850 end do
1851 end if
1852
1853 !The electric field is added to the KS potential
1854 call this%hm_base%accel_copy_pot(mesh)
1855
1856 ! and the static magnetic field
1857 if (allocated(this%ep%b_field)) then
1858 call this%hm_base%allocate_field(mesh, field_uniform_magnetic_field, .false.)
1859 do idir = 1, 3
1860 this%hm_base%uniform_magnetic_field(idir) = this%hm_base%uniform_magnetic_field(idir) + this%ep%b_field(idir)
1861 end do
1862 end if
1863
1864 call this%hm_base%update_magnetic_terms(mesh, this%ep%gyromagnetic_ratio, this%d%ispin)
1865
1866 call hamiltonian_elec_update_pot(this, mesh)
1867
1868 call build_phase()
1869
1870 call profiling_out("HAMILTONIAN_ELEC_UPDATE_EXT_POT")
1872
1873 contains
1874
1875 subroutine build_phase()
1876
1878
1879 if ((.not. this%kpoints%gamma_only()) .or. allocated(this%hm_base%uniform_vector_potential)) then
1880
1881 call profiling_in('UPDATE_PHASES')
1882 ! now regenerate the phases for the pseudopotentials
1883 do iatom = 1, this%ep%natoms
1884 call projector_init_phases(this%ep%proj(iatom), space%dim, this%d, this%der%boundaries, this%kpoints, &
1885 vec_pot = this%hm_base%uniform_vector_potential, vec_pot_var = this%hm_base%vector_potential)
1886 end do
1887
1888 call profiling_out('UPDATE_PHASES')
1889 end if
1890
1891 if (allocated(this%hm_base%uniform_vector_potential)) then
1892 call this%phase%update(mesh, this%d%kpt, this%kpoints, this%d, space, this%hm_base%uniform_vector_potential)
1893 end if
1894
1895 call hamiltonian_elec_build_projector_phases(this, this%vnl)
1896 if (this%ep%requires_generalized_overlap) then
1897 call hamiltonian_elec_build_projector_phases(this, this%aug_overlap)
1898 call hamiltonian_elec_build_projector_phases(this, this%aug_inverse_overlap)
1899 ! Exact inverse overlap
1900 if (this%aug_inverse_overlap%ovlp_inv%use_global_coupling) then
1901 if (.not. this%aug_inverse_overlap%ovlp_inv%coupling_built .or. this%phase%is_allocated()) then
1902 call this%aug_inverse_overlap%ovlp_inv%build(this%aug_inverse_overlap%projector_matrices, &
1903 this%aug_inverse_overlap%projector_phases, mesh, this%d%kpt%start, this%d%kpt%end)
1904 end if
1905 end if
1906 end if
1907
1909 end subroutine build_phase
1910
1912
1913 ! ---------------------------------------------------------
1919 subroutine hamiltonian_elec_build_projector_phases(this, nlpp, async)
1920 type(hamiltonian_elec_t), intent(in) :: this
1921 type(nonlocal_pseudopotential_t), intent(inout) :: nlpp
1922 logical, optional, intent(in) :: async
1923
1924 integer :: ik, imat, nmat, max_npoints, offset, iphase, nphase, ip, iatom
1925
1927
1928 if (this%phase%is_allocated() .and. allocated(nlpp%projector_matrices)) then
1929
1930 max_npoints = nlpp%max_npoints
1931 nmat = nlpp%nprojector_matrices
1932
1933 nphase = 1
1934 if (this%der%boundaries%spiralBC) nphase = 3
1935
1936 if (.not. allocated(nlpp%projector_phases)) then
1937 safe_allocate(nlpp%projector_phases(1:max_npoints, 1:nphase, nmat, this%d%kpt%start:this%d%kpt%end))
1938 if (accel_is_enabled()) then
1939 call accel_create_buffer(nlpp%buff_projector_phases, accel_mem_read_only, &
1940 type_cmplx, nlpp%total_points*nphase*this%d%kpt%nlocal())
1941 ! We need to save nphase, with which the array has been build,
1942 ! as the number might change throughout the run
1943 nlpp%nphase = nphase
1944 end if
1945 end if
1946
1947 offset = 0
1948 do ik = this%d%kpt%start, this%d%kpt%end
1949 do imat = 1, nlpp%nprojector_matrices
1950 iatom = nlpp%projector_to_atom(imat)
1951 do iphase = 1, nphase
1952 !$omp parallel do simd schedule(static)
1953 do ip = 1, nlpp%projector_matrices(imat)%npoints
1954 nlpp%projector_phases(ip, iphase, imat, ik) = this%ep%proj(iatom)%phase(ip, iphase, ik)
1955 end do
1956
1957 if (accel_is_enabled() .and. nlpp%projector_matrices(imat)%npoints > 0) then
1958 call accel_write_buffer(nlpp%buff_projector_phases, &
1959 nlpp%projector_matrices(imat)%npoints, nlpp%projector_phases(1:, iphase, imat, ik), &
1960 offset = offset, async=optional_default(async, .false.))
1961 end if
1962 offset = offset + nlpp%projector_matrices(imat)%npoints
1963 end do
1964 end do
1965 end do
1966
1967 end if
1968
1971
1972 logical function hamiltonian_elec_needs_current(hm, states_are_real)
1973 type(hamiltonian_elec_t), intent(in) :: hm
1974 logical, intent(in) :: states_are_real
1975
1977
1978 if (hm%self_induced_magnetic) then
1979 if (.not. states_are_real) then
1981 else
1982 message(1) = 'No current density for real states since it is identically zero.'
1983 call messages_warning(1)
1984 end if
1985 end if
1986
1988
1989 ! ---------------------------------------------------------
1990 subroutine zhamiltonian_elec_apply_all(hm, namespace, gr, st, hst)
1991 type(hamiltonian_elec_t), intent(inout) :: hm
1992 type(namespace_t), intent(in) :: namespace
1993 type(grid_t), intent(in) :: gr
1994 type(states_elec_t), intent(inout) :: st
1995 type(states_elec_t), intent(inout) :: hst
1996
1997 integer :: ik, ib, ist
1998 complex(real64), allocatable :: psi(:, :)
1999 complex(real64), allocatable :: psiall(:, :, :, :)
2000
2002
2003 do ik = st%d%kpt%start, st%d%kpt%end
2004 do ib = st%group%block_start, st%group%block_end
2005 call zhamiltonian_elec_apply_batch(hm, namespace, gr, st%group%psib(ib, ik), hst%group%psib(ib, ik))
2006 end do
2007 end do
2008
2009 if (oct_exchange_enabled(hm%oct_exchange)) then
2010
2011 safe_allocate(psiall(gr%np_part, 1:hst%d%dim, st%st_start:st%st_end, st%d%kpt%start:st%d%kpt%end))
2012
2013 call states_elec_get_state(st, gr, psiall)
2014
2015 call oct_exchange_prepare(hm%oct_exchange, gr, psiall, hm%xc, hm%psolver, namespace)
2016
2017 safe_deallocate_a(psiall)
2018
2019 safe_allocate(psi(gr%np_part, 1:hst%d%dim))
2020
2021 do ik = 1, st%nik
2022 do ist = 1, st%nst
2023 call states_elec_get_state(hst, gr, ist, ik, psi)
2024 call oct_exchange_operator(hm%oct_exchange, namespace, gr, psi, ist, ik)
2025 call states_elec_set_state(hst, gr, ist, ik, psi)
2026 end do
2027 end do
2028
2029 safe_deallocate_a(psi)
2030
2031 end if
2032
2034 end subroutine zhamiltonian_elec_apply_all
2035
2036 ! ---------------------------------------------------------
2037 logical function hamiltonian_elec_has_kick(hm)
2038 type(hamiltonian_elec_t), intent(in) :: hm
2039
2041
2042 hamiltonian_elec_has_kick = (abs(hm%kick%delta_strength) > m_epsilon)
2043
2045 end function hamiltonian_elec_has_kick
2046
2048 !
2049 subroutine hamiltonian_elec_set_mass(this, namespace, mass)
2050 class(hamiltonian_elec_t) , intent(inout) :: this
2051 type(namespace_t), intent(in) :: namespace
2052 real(real64), intent(in) :: mass
2053
2055
2056 if (parse_is_defined(namespace, 'ParticleMass')) then
2057 message(1) = 'Attempting to redefine a non-unit electron mass'
2058 call messages_fatal(1)
2059 else
2060 this%mass = mass
2061 end if
2064 end subroutine hamiltonian_elec_set_mass
2065
2066 ! ---------------------------------------------------------
2067 subroutine hamiltonian_elec_diagonal (hm, mesh, diag, ik)
2068 type(hamiltonian_elec_t), intent(in) :: hm
2069 class(mesh_t), intent(in) :: mesh
2070 real(real64), contiguous, intent(out) :: diag(:,:)
2071 integer, intent(in) :: ik
2072
2073 integer :: idim, ip, ispin
2074
2075 real(real64), allocatable :: ldiag(:)
2076
2078
2079 safe_allocate(ldiag(1:mesh%np))
2080
2081 diag = m_zero
2082
2083 call derivatives_lapl_diag(hm%der, ldiag)
2084
2085 !$omp parallel private(idim, ip)
2086 do idim = 1, hm%d%dim
2087 !$omp do
2088 do ip = 1, mesh%np
2089 diag(ip, idim) = -m_half/hm%mass*ldiag(ip)
2090 end do
2091 end do
2092 !$omp end parallel
2093
2094 select case (hm%d%ispin)
2095
2096 case (unpolarized, spin_polarized)
2097 ispin = hm%d%get_spin_index(ik)
2098 !$omp parallel do
2099 do ip = 1, mesh%np
2100 diag(ip, 1) = diag(ip, 1) + hm%ep%vpsl(ip)
2101 end do
2102 !$omp end parallel do
2103
2104 case (spinors)
2105 do ip = 1, mesh%np
2106 diag(ip, 1) = diag(ip, 1) + hm%ep%vpsl(ip)
2107 diag(ip, 2) = diag(ip, 2) + hm%ep%vpsl(ip)
2108 end do
2110 end select
2111
2112 call hm%ks_pot%add_vhxc(diag)
2113
2115 end subroutine hamiltonian_elec_diagonal
2116
2117
2118
2119#include "undef.F90"
2120#include "real.F90"
2121#include "hamiltonian_elec_inc.F90"
2122
2123#include "undef.F90"
2124#include "complex.F90"
2125#include "hamiltonian_elec_inc.F90"
2126
2127end module hamiltonian_elec_oct_m
2128
2129!! Local Variables:
2130!! mode: f90
2131!! coding: utf-8
2132!! 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_update_dij(this, mesh, epot, veff, add_bare, onsite_density_matrix, paw_onsite_hxc)
Screen the ultrasoft nonlocal coupling matrix D_ij with the local potential.
subroutine, public nonlocal_pseudopotential_detach_copy(this, donor)
Detach the projector data of an instance obtained by intrinsic assignment.
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:715
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
Definition: xc.F90:730
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)