35 use,
intrinsic :: iso_fortran_env
78 integer,
public,
parameter :: &
88 real(real64),
allocatable :: vpsl(:)
90 type(projector_t),
allocatable :: proj(:)
92 type(augmentation_species_t),
pointer :: aug_species(:) => null()
94 type(distributed_t) :: atoms_dist_plane
96 logical :: requires_generalized_overlap = .false.
97 logical :: has_paw = .false.
101 real(real64),
allocatable :: e_field(:)
102 real(real64),
allocatable :: v_ext(:)
103 real(real64),
allocatable :: b_field(:)
104 real(real64),
allocatable :: a_static(:,:)
108 integer :: proj_reltype
112 real(real64) :: gyromagnetic_ratio
115 real(real64) :: so_strength
119 real(real64),
allocatable :: fii(:, :)
120 real(real64),
allocatable :: vdw_forces(:, :)
121 real(real64),
allocatable :: photon_forces(:)
124 real(real64) :: vdw_stress(3, 3)
126 real(real64),
allocatable,
private :: local_potential(:,:)
127 logical,
private :: local_potential_precalculated
129 logical,
private :: have_density
130 type(poisson_t),
pointer,
private :: poisson_solver
133 logical,
private :: proj_check_done = .false.
135 logical :: nlcc = .false.
139 type(double_grid_t) :: dgrid
145 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
146 type(epot_t),
intent(out) :: ep
147 type(namespace_t),
intent(in) :: namespace
148 type(grid_t),
intent(in) :: gr
149 type(ions_t),
intent(inout) :: ions
151 integer,
intent(in) :: ispin
152 integer,
intent(in) :: xc_family
158 real(real64) :: gcutoff
163 if (ep%dgrid%enabled .and. gr%use_curvilinear)
then
200 if (ep%dgrid%enabled) gcutoff = gcutoff*ep%dgrid%divisor
201 do ispec = 1, ions%nspecies
202 call ions%species(ispec)%s%init_potential(namespace, gcutoff, filter)
205 safe_allocate(ep%vpsl(1:gr%np))
267 call parse_variable(namespace,
'RelativisticCorrection', norel, ep%reltype)
272 message(1) =
"The spin-orbit term can only be applied when using spinors."
281 do ia = 1, ions%nspecies
282 if (.not. ions%species(ia)%s%is_ps()) cycle
283 message(1) =
"ZORA is meant for all-electron species, but species '" &
284 //trim(ions%species(ia)%s%get_label())//
"' is a pseudopotential,"
285 message(2) =
"which already contains the relativistic effects."
287 message(3) =
"Use RelativisticCorrection = spin_orbit for pseudopotentials, or an"
288 message(4) =
"all-electron species (see AllElectronType) for ZORA."
291 message(3) =
"Scalar relativistic effects will therefore be counted twice."
299 ep%proj_reltype = norel
333 ep%so_strength =
m_one
336 safe_allocate(ep%proj(1:ions%natoms))
337 allocate(ep%aug_species(1:ions%nspecies))
340 ep%natoms = ions%natoms
341 ep%non_local = .false.
342 ep%requires_generalized_overlap = .false.
345 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
348 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
351 safe_allocate(ep%photon_forces(1:ions%space%dim))
354 ep%local_potential_precalculated = .false.
357 ep%have_density = .false.
358 do ia = 1, ions%nspecies
360 ep%have_density = .
true.
365 if (ep%have_density)
then
366 ep%poisson_solver => psolver
368 nullify(ep%poisson_solver)
373 ep%requires_generalized_overlap = .false.
375 do ia = 1, ions%nspecies
376 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
377 select type(spec=>ions%species(ia)%s)
379 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
380 ep%has_paw = ep%has_paw .or. spec%is_paw()
389 type(
epot_t),
intent(inout) :: ep
395 if (ep%have_density)
then
396 nullify(ep%poisson_solver)
399 safe_deallocate_a(ep%local_potential)
400 safe_deallocate_a(ep%fii)
401 safe_deallocate_a(ep%vdw_forces)
402 safe_deallocate_a(ep%vpsl)
403 safe_deallocate_a(ep%photon_forces)
406 safe_deallocate_a(ep%e_field)
407 safe_deallocate_a(ep%v_ext)
408 safe_deallocate_a(ep%b_field)
409 safe_deallocate_a(ep%a_static)
411 do iproj = 1, ep%natoms
416 assert(
allocated(ep%proj))
417 safe_deallocate_a(ep%proj)
419 if (
associated(ep%aug_species))
then
420 do iproj = 1,
size(ep%aug_species)
423 deallocate(ep%aug_species)
424 nullify(ep%aug_species)
440 type(
epot_t),
intent(inout) :: ep
441 type(
poisson_t),
target,
intent(in) :: psolver
445 if (ep%have_density)
then
446 ep%poisson_solver => psolver
448 nullify(ep%poisson_solver)
455 subroutine epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
456 type(
epot_t),
intent(inout) :: ep
458 class(
mesh_t),
target,
intent(in) :: mesh
459 type(
ions_t),
target,
intent(inout) :: ions
462 type(
mpi_grp_t),
optional,
intent(in) :: kpt_st_grp
464 integer :: ia, ispec, paw_nspin
466 type(
ps_t),
pointer :: ps
467 logical,
allocatable :: spec_checked(:)
477 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
480 do ia = 1, ions%natoms
481 select type(spec=>ions%atom(ia)%species)
484 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%proj_reltype)
485 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
486 ep%has_paw = ep%has_paw .or. spec%is_paw()
492 do ia = ions%atoms_dist%start, ions%atoms_dist%end
494 select type(spec=>ions%atom(ia)%species)
497 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), &
502 if (ions%atoms_dist%parallel)
then
503 do ia = 1, ions%natoms
505 select type(spec=>ions%atom(ia)%species)
510 ions%atoms_dist%process(ia), ions%atoms_dist%mpi_grp)
516 paw_nspin = st_d%nspin
519 do ia = 1, ions%natoms
521 select type(spec=>ions%atom(ia)%species)
523 if (spec%is_paw() .and. spec%ps%relativistic_treatment ==
proj_j_dependent &
525 message(1) =
"Fully-relativistic (j-dependent) PAW datasets require"
526 message(2) =
"SpinComponents = spinors and RelativisticCorrection = spin_orbit."
530 message(1) =
"SOStrength /= 1 is not supported for PAW datasets: their spin-orbit splitting is"
531 message(2) =
"mostly carried by the j-dependent partial waves, which are not scaled."
536 message(1) =
"Spin-orbit coupling with an ultrasoft/PAW pseudopotential requires a"
537 message(2) =
"fully-relativistic (j-dependent) dataset; this one is scalar-relativistic."
540 ispec = spec%get_index()
541 if (.not.
allocated(ep%aug_species(ispec)%dij))
then
542 safe_allocate(ep%aug_species(ispec)%dij(0:ep%proj(ia)%lmax, 1:spec%ps%kbc, 1:spec%ps%kbc))
543 ep%aug_species(ispec)%dij = spec%ps%h
544 if (
allocated(spec%ps%radial_augmentation) .and. spec%is_paw() .and. paw_nspin > 0)
then
545 allocate(ep%aug_species(ispec)%paw)
556 if (
present(kpt_st_grp))
then
557 call distributed_init(ep%atoms_dist_plane, ions%natoms, kpt_st_grp%comm,
"atoms_plane")
562 do ia = 1, ions%natoms
563 select type(spec=>ions%atom(ia)%species)
566 if (ep%atoms_dist_plane%parallel)
then
567 fill = (ep%atoms_dist_plane%process(ia) == ep%atoms_dist_plane%mpi_grp%rank)
569 call projector_build(ep%proj(ia), spec, ep%so_strength, ep%dgrid, namespace, paw_nspin, &
570 kpt_st_grp, fill_values = fill, aug_species = ep%aug_species(spec%get_index()))
575 if (ep%atoms_dist_plane%parallel)
then
576 do ia = 1, ions%natoms
577 select type(spec=>ions%atom(ia)%species)
579 call projector_bcast_fill(ep%proj(ia), ep%atoms_dist_plane%mpi_grp, ep%atoms_dist_plane%process(ia))
586 if (.not. ep%proj_check_done)
then
587 safe_allocate(spec_checked(1:ions%nspecies))
588 spec_checked = .false.
589 do ia = 1, ions%natoms
591 if (spec_checked(ions%atom(ia)%species%get_index())) cycle
592 select type(spec=>ions%atom(ia)%species)
595 spec_checked(ions%atom(ia)%species%get_index()) = .
true.
598 safe_deallocate_a(spec_checked)
599 ep%proj_check_done = .
true.
611 type(
epot_t),
intent(in) :: ep
612 type(
ps_t),
intent(in) :: ps
613 class(
mesh_t),
intent(in) :: mesh
616 if (ep%dgrid%enabled)
then
617 if (
allocated(ps%radial_augmentation)) radius = max(radius, maxval(ps%radial_augmentation(:, :)%x_threshold))
625 class(space_t),
intent(in) :: space
626 class(species_t),
intent(in) :: species
628 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
634 type(
epot_t),
intent(in) :: ep
635 type(namespace_t),
intent(in) :: namespace
636 class(space_t),
intent(in) :: space
637 type(lattice_vectors_t),
intent(in) :: latt
638 class(mesh_t),
intent(in) :: mesh
639 class(species_t),
target,
intent(in) :: species
640 real(real64),
intent(in) :: pos(1:space%dim)
641 integer,
intent(in) :: iatom
642 real(real64),
contiguous,
intent(inout) :: vpsl(:)
644 real(real64),
allocatable :: vl(:), rho(:)
645 type(submesh_t) :: sphere
648 call profiling_in(
"EPOT_LOCAL")
650 if (ep%local_potential_precalculated)
then
652 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
659 safe_allocate(vl(1:mesh%np))
662 safe_allocate(rho(1:mesh%np))
664 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
666 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
668 safe_deallocate_a(rho)
672 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
676 call lalg_axpy(mesh%np, m_one, vl, vpsl)
677 safe_deallocate_a(vl)
680 call species_get_local_sr(species, space, latt, pos, mesh, sphere, vpsl, ep%dgrid)
681 call submesh_end(sphere)
685 call profiling_out(
"EPOT_LOCAL")
691 type(
epot_t),
intent(inout) :: ep
692 type(namespace_t),
intent(in) :: namespace
693 type(grid_t),
intent(in) :: gr
694 type(ions_t),
intent(in) :: ions
700 if (.not.
allocated(ep%local_potential))
then
701 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
704 ep%local_potential_precalculated = .false.
706 do iatom = 1, ions%natoms
707 ep%local_potential(1:gr%np, iatom) = m_zero
709 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))
711 ep%local_potential_precalculated = .
true.
719 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_precalc_local_potential(ep, namespace, gr, ions)
subroutine, public epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
subroutine, public epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
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)
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.
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