35 use,
intrinsic :: iso_fortran_env
80 integer,
public,
parameter :: &
90 real(real64),
allocatable :: vpsl(:)
92 type(projector_t),
allocatable :: proj(:)
94 type(augmentation_species_t),
pointer :: aug_species(:) => null()
96 type(distributed_t) :: atoms_dist_plane
98 logical :: requires_generalized_overlap = .false.
99 logical :: has_paw = .false.
101 integer :: xc_id(2) = 0
103 logical :: usexcnhat = .
true.
106 real(real64),
allocatable :: e_field(:)
107 real(real64),
allocatable :: v_ext(:)
108 real(real64),
allocatable :: b_field(:)
109 real(real64),
allocatable :: a_static(:,:)
113 integer :: proj_reltype
117 real(real64) :: gyromagnetic_ratio
120 real(real64) :: so_strength
124 real(real64),
allocatable :: fii(:, :)
125 real(real64),
allocatable :: vdw_forces(:, :)
126 real(real64),
allocatable :: photon_forces(:)
129 real(real64) :: vdw_stress(3, 3)
131 real(real64),
allocatable,
private :: local_potential(:,:)
132 logical,
private :: local_potential_precalculated
134 logical,
private :: have_density
135 type(poisson_t),
pointer,
private :: poisson_solver
138 logical,
private :: proj_check_done = .false.
140 logical :: nlcc = .false.
144 type(double_grid_t) :: dgrid
150 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints, xc_id)
151 type(epot_t),
intent(out) :: ep
153 type(
grid_t),
intent(in) :: gr
154 type(
ions_t),
intent(inout) :: ions
155 type(
poisson_t),
target,
intent(in) :: psolver
156 integer,
intent(in) :: ispin
157 integer,
intent(in) :: xc_family
158 type(kpoints_t),
intent(in) :: kpoints
159 integer,
optional,
intent(in) :: xc_id(2)
163 integer :: filter, paw_comp_scheme
164 real(real64) :: gcutoff
168 if (
present(xc_id)) ep%xc_id(:) = xc_id(:)
171 if (ep%dgrid%enabled .and. gr%use_curvilinear)
then
208 if (ep%dgrid%enabled) gcutoff = gcutoff*ep%dgrid%divisor
209 do ispec = 1, ions%nspecies
210 call ions%species(ispec)%s%init_potential(namespace, gcutoff, filter)
213 safe_allocate(ep%vpsl(1:gr%np))
275 call parse_variable(namespace,
'RelativisticCorrection', norel, ep%reltype)
280 message(1) =
"The spin-orbit term can only be applied when using spinors."
289 do ia = 1, ions%nspecies
290 if (.not. ions%species(ia)%s%is_ps()) cycle
291 message(1) =
"ZORA is meant for all-electron species, but species '" &
292 //trim(ions%species(ia)%s%get_label())//
"' is a pseudopotential,"
293 message(2) =
"which already contains the relativistic effects."
295 message(3) =
"Use RelativisticCorrection = spin_orbit for pseudopotentials, or an"
296 message(4) =
"all-electron species (see AllElectronType) for ZORA."
299 message(3) =
"Scalar relativistic effects will therefore be counted twice."
307 ep%proj_reltype = norel
341 ep%so_strength =
m_one
344 safe_allocate(ep%proj(1:ions%natoms))
345 allocate(ep%aug_species(1:ions%nspecies))
348 ep%natoms = ions%natoms
349 ep%non_local = .false.
350 ep%requires_generalized_overlap = .false.
353 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
356 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
359 safe_allocate(ep%photon_forces(1:ions%space%dim))
362 ep%local_potential_precalculated = .false.
365 ep%have_density = .false.
366 do ia = 1, ions%nspecies
368 ep%have_density = .
true.
373 if (ep%have_density)
then
374 ep%poisson_solver => psolver
376 nullify(ep%poisson_solver)
381 ep%requires_generalized_overlap = .false.
383 do ia = 1, ions%nspecies
384 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
385 select type(spec=>ions%species(ia)%s)
387 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
388 ep%has_paw = ep%has_paw .or. spec%is_paw()
394 ep%usexcnhat = .
true.
414 call parse_variable(namespace,
'PAWCompensationScheme', -1, paw_comp_scheme)
415 select case (paw_comp_scheme)
420 message(1) =
"PAWCompensationScheme = kresse_joubert is not supported for meta-GGA"
421 message(2) =
"(the compensation charge has no kinetic-energy-density counterpart)."
424 ep%usexcnhat = .
true.
426 ep%usexcnhat = .false.
432 if (.not. ep%usexcnhat .and. ispin ==
spinors)
then
442 type(
epot_t),
intent(inout) :: ep
448 if (ep%have_density)
then
449 nullify(ep%poisson_solver)
452 safe_deallocate_a(ep%local_potential)
453 safe_deallocate_a(ep%fii)
454 safe_deallocate_a(ep%vdw_forces)
455 safe_deallocate_a(ep%vpsl)
456 safe_deallocate_a(ep%photon_forces)
459 safe_deallocate_a(ep%e_field)
460 safe_deallocate_a(ep%v_ext)
461 safe_deallocate_a(ep%b_field)
462 safe_deallocate_a(ep%a_static)
464 do iproj = 1, ep%natoms
469 assert(
allocated(ep%proj))
470 safe_deallocate_a(ep%proj)
472 if (
associated(ep%aug_species))
then
473 do iproj = 1,
size(ep%aug_species)
476 deallocate(ep%aug_species)
477 nullify(ep%aug_species)
493 type(
epot_t),
intent(inout) :: ep
494 type(
poisson_t),
target,
intent(in) :: psolver
498 if (ep%have_density)
then
499 ep%poisson_solver => psolver
501 nullify(ep%poisson_solver)
508 subroutine epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
509 type(
epot_t),
intent(inout) :: ep
511 class(
mesh_t),
target,
intent(in) :: mesh
512 type(
ions_t),
target,
intent(inout) :: ions
515 type(
mpi_grp_t),
optional,
intent(in) :: kpt_st_grp
517 integer :: ia, ispec, paw_nspin
519 type(
ps_t),
pointer :: ps
520 logical,
allocatable :: spec_checked(:)
530 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
533 do ia = 1, ions%natoms
534 select type(spec=>ions%atom(ia)%species)
537 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%proj_reltype)
538 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
539 ep%has_paw = ep%has_paw .or. spec%is_paw()
545 do ia = ions%atoms_dist%start, ions%atoms_dist%end
547 select type(spec=>ions%atom(ia)%species)
550 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), &
555 if (ions%atoms_dist%parallel)
then
556 do ia = 1, ions%natoms
558 select type(spec=>ions%atom(ia)%species)
563 ions%atoms_dist%process(ia), ions%atoms_dist%mpi_grp)
569 paw_nspin = st_d%nspin
572 do ia = 1, ions%natoms
574 select type(spec=>ions%atom(ia)%species)
576 if (spec%is_paw() .and. spec%ps%relativistic_treatment ==
proj_j_dependent &
578 message(1) =
"Fully-relativistic (j-dependent) PAW datasets require"
579 message(2) =
"SpinComponents = spinors and RelativisticCorrection = spin_orbit."
583 message(1) =
"SOStrength /= 1 is not supported for PAW datasets: their spin-orbit splitting is"
584 message(2) =
"mostly carried by the j-dependent partial waves, which are not scaled."
589 message(1) =
"Spin-orbit coupling with an ultrasoft/PAW pseudopotential requires a"
590 message(2) =
"fully-relativistic (j-dependent) dataset; this one is scalar-relativistic."
593 ispec = spec%get_index()
594 if (.not.
allocated(ep%aug_species(ispec)%dij))
then
595 safe_allocate(ep%aug_species(ispec)%dij(0:ep%proj(ia)%lmax, 1:spec%ps%kbc, 1:spec%ps%kbc))
596 ep%aug_species(ispec)%dij = spec%ps%h
597 if (
allocated(spec%ps%radial_augmentation) .and. spec%is_paw() .and. paw_nspin > 0)
then
598 allocate(ep%aug_species(ispec)%paw)
600 xc_ids=ep%xc_id, usexcnhat=ep%usexcnhat)
610 if (
present(kpt_st_grp))
then
611 call distributed_init(ep%atoms_dist_plane, ions%natoms, kpt_st_grp%comm,
"atoms_plane")
616 do ia = 1, ions%natoms
617 select type(spec=>ions%atom(ia)%species)
620 if (ep%atoms_dist_plane%parallel)
then
621 fill = (ep%atoms_dist_plane%process(ia) == ep%atoms_dist_plane%mpi_grp%rank)
623 call projector_build(ep%proj(ia), spec, ep%so_strength, ep%dgrid, namespace, paw_nspin, &
624 kpt_st_grp, fill_values = fill, aug_species = ep%aug_species(spec%get_index()))
629 if (ep%atoms_dist_plane%parallel)
then
630 do ia = 1, ions%natoms
631 select type(spec=>ions%atom(ia)%species)
633 call projector_bcast_fill(ep%proj(ia), ep%atoms_dist_plane%mpi_grp, ep%atoms_dist_plane%process(ia))
640 if (.not. ep%proj_check_done)
then
641 safe_allocate(spec_checked(1:ions%nspecies))
642 spec_checked = .false.
643 do ia = 1, ions%natoms
645 if (spec_checked(ions%atom(ia)%species%get_index())) cycle
646 select type(spec=>ions%atom(ia)%species)
649 spec_checked(ions%atom(ia)%species%get_index()) = .
true.
652 safe_deallocate_a(spec_checked)
653 ep%proj_check_done = .
true.
665 type(
epot_t),
intent(in) :: ep
666 type(
ps_t),
intent(in) :: ps
667 class(
mesh_t),
intent(in) :: mesh
670 if (ep%dgrid%enabled)
then
671 if (
allocated(ps%radial_augmentation)) radius = max(radius, maxval(ps%radial_augmentation(:, :)%x_threshold))
679 type(
epot_t),
intent(inout) :: ep
680 type(xc_functional_t),
pointer,
intent(in) :: functl(:)
686 if (
associated(ep%aug_species))
then
687 do ispec = 1,
size(ep%aug_species)
688 if (
allocated(ep%aug_species(ispec)%paw))
then
689 call paw_onsite_set_shared_xc(ep%aug_species(ispec)%paw, functl)
700 class(space_t),
intent(in) :: space
701 class(species_t),
intent(in) :: species
703 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
709 type(
epot_t),
intent(in) :: ep
710 type(namespace_t),
intent(in) :: namespace
711 class(space_t),
intent(in) :: space
712 type(lattice_vectors_t),
intent(in) :: latt
713 class(mesh_t),
intent(in) :: mesh
714 class(species_t),
target,
intent(in) :: species
715 real(real64),
intent(in) :: pos(1:space%dim)
716 integer,
intent(in) :: iatom
717 real(real64),
contiguous,
intent(inout) :: vpsl(:)
719 real(real64),
allocatable :: vl(:), rho(:)
720 type(submesh_t) :: sphere
723 call profiling_in(
"EPOT_LOCAL")
725 if (ep%local_potential_precalculated)
then
727 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
734 safe_allocate(vl(1:mesh%np))
737 safe_allocate(rho(1:mesh%np))
739 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
741 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
743 safe_deallocate_a(rho)
747 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
751 call lalg_axpy(mesh%np, m_one, vl, vpsl)
752 safe_deallocate_a(vl)
755 call species_get_local_sr(species, space, latt, pos, mesh, sphere, vpsl, ep%dgrid)
756 call submesh_end(sphere)
760 call profiling_out(
"EPOT_LOCAL")
766 type(
epot_t),
intent(inout) :: ep
767 type(namespace_t),
intent(in) :: namespace
768 type(grid_t),
intent(in) :: gr
769 type(ions_t),
intent(in) :: ions
775 if (.not.
allocated(ep%local_potential))
then
776 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
779 ep%local_potential_precalculated = .false.
781 do iatom = 1, ions%natoms
782 ep%local_potential(1:gr%np, iatom) = m_zero
784 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))
786 ep%local_potential_precalculated = .
true.
794 type(
epot_t),
intent(in) :: ep
subroutine, public augmentation_species_end(this)
Free one entry of the shared per-species augmentation store.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public distributed_end(this)
subroutine, public distributed_init(this, total, comm, tag, scalapack_compat)
Distribute N instances across M processes of communicator comm
subroutine, public distributed_init_serial(this, total)
Serial initialization of a distributed instance. The calling process is assigned all total instances,...
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
real(real64) function, public double_grid_margin(this, mesh)
Submesh radius enlargement needed to contain the effective support of a transformed function: the ten...
subroutine, public double_grid_end(this)
subroutine, public double_grid_init(this, namespace, dim)
integer, parameter, public spinors
real(real64) function epot_projector_radius(ep, ps, mesh)
Radius of the projector sphere. With the double grid, it also contains the support of the ultrasoft a...
subroutine, public epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
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...
logical function, public epot_have_external_potentials(ep)
logical pure function, public local_potential_has_density(space, species)
integer, parameter, public spin_orbit
integer, parameter, public scalar_relativistic_zora
subroutine, public epot_end(ep)
integer, parameter, public fully_relativistic_zora
subroutine, public epot_set_shared_paw_xc(ep, functl)
Point every PAW one-center engine at the shared xc functional.
subroutine, public epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints, xc_id)
subroutine, public epot_precalc_local_potential(ep, namespace, gr, ions)
subroutine, public epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
real(real64), parameter, public p_g
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public ion_interaction_calculate(this, space, latt, atom, natoms, pos, lsize, energy, force, energy_components, force_components)
Top level routine for computing electrostatic energies and forces between ions.
This module defines the meshes, which are used in Octopus.
real(real64) function, public mesh_gcutoff(mesh)
mesh_gcutoff returns the "natural" band limitation of the grid mesh, in terms of the maximum G vector...
subroutine, public messages_not_implemented(feature, namespace)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
This module handles the communicators for the various parallelization strategies.
subroutine, public paw_onsite_init(this, ps, namespace, formulation, nspin, xc_ids, usexcnhat)
Build the per-species one-center data from a (PAW) pseudopotential.
integer, parameter, public paw_kresse_joubert
PAW formulation: selects the compensation-charge / reference treatment.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
logical elemental function, public projector_is(p, type)
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
subroutine, public projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
subroutine, public projector_end(p)
subroutine, public projector_bcast_fill(p, grp, root)
Broadcast the projector values built by the owning rank of an atom-distributed projector build.
subroutine, public projector_check_discretization(pseudo, sm, namespace)
Check how well the nonlocal projectors are resolved on the real-space grid.
logical elemental function, public projector_is_null(p)
integer, parameter, public ps_filter_ts
integer, parameter, public ps_filter_none
integer, parameter, public proj_uspp
integer, parameter, public proj_j_dependent
Fully-relativistic j-dependent pseudopotentials.
integer, parameter, public proj_none
subroutine, public spline_filter_mask_init()
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public submesh_broadcast(this, space, mesh, center, radius, root, mpi_grp)
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
This module defines the unit system, used for input and output.
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
This is defined even when running serial.
A type storing the information and data about a pseudopotential.
class for organizing spins and k-points