32 use,
intrinsic :: iso_fortran_env
73 integer,
public,
parameter :: &
83 real(real64),
allocatable :: vpsl(:)
85 type(projector_t),
allocatable :: proj(:)
90 real(real64),
allocatable :: e_field(:)
91 real(real64),
allocatable :: v_ext(:)
92 real(real64),
allocatable :: b_field(:)
93 real(real64),
allocatable :: a_static(:,:)
98 real(real64) :: gyromagnetic_ratio
101 real(real64) :: so_strength
105 real(real64),
allocatable :: fii(:, :)
106 real(real64),
allocatable :: vdw_forces(:, :)
107 real(real64),
allocatable :: photon_forces(:)
110 real(real64) :: vdw_stress(3, 3)
112 real(real64),
allocatable,
private :: local_potential(:,:)
113 logical,
private :: local_potential_precalculated
115 logical,
private :: have_density
116 type(poisson_t),
pointer,
private :: poisson_solver
118 logical :: nlcc = .false.
124 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
125 type(epot_t),
intent(out) :: ep
126 type(namespace_t),
intent(in) :: namespace
127 type(grid_t),
intent(in) :: gr
128 type(ions_t),
intent(inout) :: ions
129 type(poisson_t),
target,
intent(in) :: psolver
130 integer,
intent(in) :: ispin
131 integer,
intent(in) :: xc_family
132 type(kpoints_t),
intent(in) :: kpoints
168 do ispec = 1, ions%nspecies
169 call ions%species(ispec)%s%init_potential(namespace,
mesh_gcutoff(gr), filter)
172 safe_allocate(ep%vpsl(1:gr%np))
216 call parse_variable(namespace,
'RelativisticCorrection', norel, ep%reltype)
221 message(1) =
"The spin-orbit term can only be applied when using spinors."
242 ep%so_strength =
m_one
245 safe_allocate(ep%proj(1:ions%natoms))
247 ep%natoms = ions%natoms
248 ep%non_local = .false.
251 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
254 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
257 safe_allocate(ep%photon_forces(1:ions%space%dim))
260 ep%local_potential_precalculated = .false.
263 ep%have_density = .false.
264 do ia = 1, ions%nspecies
266 ep%have_density = .
true.
271 if (ep%have_density)
then
272 ep%poisson_solver => psolver
274 nullify(ep%poisson_solver)
279 do ia = 1, ions%nspecies
280 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
288 type(
epot_t),
intent(inout) :: ep
294 if (ep%have_density)
then
295 nullify(ep%poisson_solver)
298 safe_deallocate_a(ep%local_potential)
299 safe_deallocate_a(ep%fii)
300 safe_deallocate_a(ep%vdw_forces)
301 safe_deallocate_a(ep%vpsl)
302 safe_deallocate_a(ep%photon_forces)
305 safe_deallocate_a(ep%e_field)
306 safe_deallocate_a(ep%v_ext)
307 safe_deallocate_a(ep%b_field)
308 safe_deallocate_a(ep%a_static)
310 do iproj = 1, ep%natoms
315 assert(
allocated(ep%proj))
316 safe_deallocate_a(ep%proj)
324 type(
epot_t),
intent(inout) :: ep
326 class(
mesh_t),
target,
intent(in) :: mesh
327 type(
ions_t),
target,
intent(inout) :: ions
331 type(
ps_t),
pointer :: ps
341 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
344 do ia = 1, ions%natoms
345 select type(spec=>ions%atom(ia)%species)
348 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%reltype)
352 do ia = ions%atoms_dist%start, ions%atoms_dist%end
354 select type(spec=>ions%atom(ia)%species)
357 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), ps%rc_max)
361 if (ions%atoms_dist%parallel)
then
362 do ia = 1, ions%natoms
364 select type(spec=>ions%atom(ia)%species)
367 call submesh_broadcast(ep%proj(ia)%sphere, ions%space, mesh, ions%pos(:, ia), ps%rc_max, &
368 ions%atoms_dist%node(ia), ions%atoms_dist%mpi_grp)
373 do ia = 1, ions%natoms
374 select type(spec=>ions%atom(ia)%species)
388 class(
space_t),
intent(in) :: space
391 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
397 type(
epot_t),
intent(in) :: ep
398 type(namespace_t),
intent(in) :: namespace
399 class(space_t),
intent(in) :: space
400 type(lattice_vectors_t),
intent(in) :: latt
401 class(mesh_t),
intent(in) :: mesh
402 class(species_t),
target,
intent(in) :: species
403 real(real64),
intent(in) :: pos(1:space%dim)
404 integer,
intent(in) :: iatom
405 real(real64),
contiguous,
intent(inout) :: vpsl(:)
408 real(real64) :: radius
409 real(real64),
allocatable :: vl(:), rho(:)
410 type(submesh_t) :: sphere
411 type(ps_t),
pointer :: ps
414 call profiling_in(
"EPOT_LOCAL")
416 if (ep%local_potential_precalculated)
then
419 vpsl(ip) = vpsl(ip) + ep%local_potential(ip, iatom)
426 safe_allocate(vl(1:mesh%np))
429 safe_allocate(rho(1:mesh%np))
431 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
433 if (poisson_solver_is_iterative(ep%poisson_solver))
then
436 vl(1:mesh%np) = m_zero
439 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
441 safe_deallocate_a(rho)
445 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
449 call lalg_axpy(mesh%np, m_one, vl, vpsl)
450 safe_deallocate_a(vl)
454 class is(pseudopotential_t)
458 radius = ps%vl%x_threshold*1.05_real64
459 if (.not. submesh_compatible(sphere, radius, pos, minval(mesh%spacing(1:space%dim))))
then
460 call submesh_end(sphere)
461 call submesh_init(sphere, space, mesh, latt, pos, radius)
463 safe_allocate(vl(1:sphere%np))
467 if(sphere%r(ip) <= radius)
then
468 vl(ip) = spline_eval(ps%vl, sphere%r(ip))
472 call submesh_add_to_mesh(sphere, vl, vpsl)
474 safe_deallocate_a(vl)
478 call submesh_end(sphere)
482 call profiling_out(
"EPOT_LOCAL")
488 type(
epot_t),
intent(inout) :: ep
489 type(namespace_t),
intent(in) :: namespace
490 type(grid_t),
intent(in) :: gr
491 type(ions_t),
intent(in) :: ions
497 if (.not.
allocated(ep%local_potential))
then
498 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
501 ep%local_potential_precalculated = .false.
503 do iatom = 1, ions%natoms
504 ep%local_potential(1:gr%np, iatom) = m_zero
506 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))
508 ep%local_potential_precalculated = .
true.
516 type(
epot_t),
intent(in) :: ep
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public spinors
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)
subroutine, public epot_generate(ep, namespace, mesh, ions, st_d)
real(real64), parameter, public p_g
real(real64), parameter, public m_zero
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_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 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.
subroutine, public projector_build(p, ps, so_strength)
logical elemental function, public projector_is(p, type)
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
subroutine, public projector_end(p)
logical elemental function, public projector_is_null(p)
integer, parameter, public ps_filter_ts
integer, parameter, public ps_filter_none
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.
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
class for organizing spins and k-points