32 use,
intrinsic :: iso_fortran_env
74 integer,
public,
parameter :: &
84 real(real64),
allocatable :: vpsl(:)
86 type(projector_t),
allocatable :: proj(:)
91 real(real64),
allocatable :: e_field(:)
92 real(real64),
allocatable :: v_ext(:)
93 real(real64),
allocatable :: b_field(:)
94 real(real64),
allocatable :: a_static(:,:)
99 real(real64) :: gyromagnetic_ratio
102 real(real64) :: so_strength
106 real(real64),
allocatable :: fii(:, :)
107 real(real64),
allocatable :: vdw_forces(:, :)
108 real(real64),
allocatable :: photon_forces(:)
111 real(real64) :: vdw_stress(3, 3)
113 real(real64),
allocatable,
private :: local_potential(:,:)
114 logical,
private :: local_potential_precalculated
116 logical,
private :: have_density
117 type(poisson_t),
pointer,
private :: poisson_solver
119 logical :: nlcc = .false.
125 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
126 type(epot_t),
intent(out) :: ep
127 type(namespace_t),
intent(in) :: namespace
128 type(grid_t),
intent(in) :: gr
129 type(ions_t),
intent(inout) :: ions
130 type(poisson_t),
target,
intent(in) :: psolver
131 integer,
intent(in) :: ispin
132 integer,
intent(in) :: xc_family
133 type(kpoints_t),
intent(in) :: kpoints
169 do ispec = 1, ions%nspecies
170 call ions%species(ispec)%s%init_potential(namespace,
mesh_gcutoff(gr), filter)
173 safe_allocate(ep%vpsl(1:gr%np))
217 call parse_variable(namespace,
'RelativisticCorrection', norel, ep%reltype)
222 message(1) =
"The spin-orbit term can only be applied when using spinors."
243 ep%so_strength =
m_one
246 safe_allocate(ep%proj(1:ions%natoms))
248 ep%natoms = ions%natoms
249 ep%non_local = .false.
252 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
255 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
258 safe_allocate(ep%photon_forces(1:ions%space%dim))
261 ep%local_potential_precalculated = .false.
264 ep%have_density = .false.
265 do ia = 1, ions%nspecies
267 ep%have_density = .
true.
272 if (ep%have_density)
then
273 ep%poisson_solver => psolver
275 nullify(ep%poisson_solver)
280 do ia = 1, ions%nspecies
281 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
289 type(
epot_t),
intent(inout) :: ep
295 if (ep%have_density)
then
296 nullify(ep%poisson_solver)
299 safe_deallocate_a(ep%local_potential)
300 safe_deallocate_a(ep%fii)
301 safe_deallocate_a(ep%vdw_forces)
302 safe_deallocate_a(ep%vpsl)
303 safe_deallocate_a(ep%photon_forces)
306 safe_deallocate_a(ep%e_field)
307 safe_deallocate_a(ep%v_ext)
308 safe_deallocate_a(ep%b_field)
309 safe_deallocate_a(ep%a_static)
311 do iproj = 1, ep%natoms
316 assert(
allocated(ep%proj))
317 safe_deallocate_a(ep%proj)
328 type(
epot_t),
intent(inout) :: ep
329 type(
poisson_t),
target,
intent(in) :: psolver
333 if (ep%have_density)
then
334 ep%poisson_solver => psolver
336 nullify(ep%poisson_solver)
344 type(
epot_t),
intent(inout) :: ep
346 class(
mesh_t),
target,
intent(in) :: mesh
347 type(
ions_t),
target,
intent(inout) :: ions
351 type(
ps_t),
pointer :: ps
361 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
364 do ia = 1, ions%natoms
365 select type(spec=>ions%atom(ia)%species)
368 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%reltype)
372 do ia = ions%atoms_dist%start, ions%atoms_dist%end
374 select type(spec=>ions%atom(ia)%species)
377 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), ps%rc_max)
381 if (ions%atoms_dist%parallel)
then
382 do ia = 1, ions%natoms
384 select type(spec=>ions%atom(ia)%species)
387 call submesh_broadcast(ep%proj(ia)%sphere, ions%space, mesh, ions%pos(:, ia), ps%rc_max, &
388 ions%atoms_dist%node(ia), ions%atoms_dist%mpi_grp)
393 do ia = 1, ions%natoms
394 select type(spec=>ions%atom(ia)%species)
408 class(
space_t),
intent(in) :: space
411 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
417 type(
epot_t),
intent(in) :: ep
418 type(namespace_t),
intent(in) :: namespace
419 class(space_t),
intent(in) :: space
420 type(lattice_vectors_t),
intent(in) :: latt
421 class(mesh_t),
intent(in) :: mesh
422 class(species_t),
target,
intent(in) :: species
423 real(real64),
intent(in) :: pos(1:space%dim)
424 integer,
intent(in) :: iatom
425 real(real64),
contiguous,
intent(inout) :: vpsl(:)
428 real(real64) :: radius
429 real(real64),
allocatable :: vl(:), rho(:)
430 type(submesh_t) :: sphere
431 type(ps_t),
pointer :: ps
434 call profiling_in(
"EPOT_LOCAL")
436 if (ep%local_potential_precalculated)
then
438 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
445 safe_allocate(vl(1:mesh%np))
448 safe_allocate(rho(1:mesh%np))
450 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
452 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
454 safe_deallocate_a(rho)
458 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
462 call lalg_axpy(mesh%np, m_one, vl, vpsl)
463 safe_deallocate_a(vl)
467 class is(pseudopotential_t)
471 radius = min(ps%vl%x_threshold*1.05_real64, spline_range_max(ps%vl))
472 if (.not. submesh_compatible(sphere, radius, pos, minval(mesh%spacing(1:space%dim))))
then
473 call submesh_end(sphere)
474 call submesh_init(sphere, space, mesh, latt, pos, radius)
476 safe_allocate(vl(1:sphere%np))
480 if(sphere%r(ip) <= radius)
then
481 vl(ip) = spline_eval(ps%vl, sphere%r(ip))
485 call submesh_add_to_mesh(sphere, vl, vpsl)
487 safe_deallocate_a(vl)
491 call submesh_end(sphere)
495 call profiling_out(
"EPOT_LOCAL")
501 type(
epot_t),
intent(inout) :: ep
502 type(namespace_t),
intent(in) :: namespace
503 type(grid_t),
intent(in) :: gr
504 type(ions_t),
intent(in) :: ions
510 if (.not.
allocated(ep%local_potential))
then
511 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
514 ep%local_potential_precalculated = .false.
516 do iatom = 1, ions%natoms
517 ep%local_potential(1:gr%np, iatom) = m_zero
519 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))
521 ep%local_potential_precalculated = .
true.
529 type(
epot_t),
intent(in) :: ep
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public spinors
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)
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.
A type storing the information and data about a pseudopotential.
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
class for organizing spins and k-points