31 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
119 logical,
private :: proj_check_done = .false.
121 logical :: nlcc = .false.
127 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
128 type(epot_t),
intent(out) :: ep
129 type(namespace_t),
intent(in) :: namespace
130 type(grid_t),
intent(in) :: gr
131 type(ions_t),
intent(inout) :: ions
132 type(poisson_t),
target,
intent(in) :: psolver
133 integer,
intent(in) :: ispin
134 integer,
intent(in) :: xc_family
135 type(kpoints_t),
intent(in) :: kpoints
171 do ispec = 1, ions%nspecies
172 call ions%species(ispec)%s%init_potential(namespace,
mesh_gcutoff(gr), filter)
175 safe_allocate(ep%vpsl(1:gr%np))
219 call parse_variable(namespace,
'RelativisticCorrection', norel, ep%reltype)
224 message(1) =
"The spin-orbit term can only be applied when using spinors."
245 ep%so_strength =
m_one
248 safe_allocate(ep%proj(1:ions%natoms))
250 ep%natoms = ions%natoms
251 ep%non_local = .false.
254 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
257 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
260 safe_allocate(ep%photon_forces(1:ions%space%dim))
263 ep%local_potential_precalculated = .false.
266 ep%have_density = .false.
267 do ia = 1, ions%nspecies
269 ep%have_density = .
true.
274 if (ep%have_density)
then
275 ep%poisson_solver => psolver
277 nullify(ep%poisson_solver)
282 do ia = 1, ions%nspecies
283 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
291 type(
epot_t),
intent(inout) :: ep
297 if (ep%have_density)
then
298 nullify(ep%poisson_solver)
301 safe_deallocate_a(ep%local_potential)
302 safe_deallocate_a(ep%fii)
303 safe_deallocate_a(ep%vdw_forces)
304 safe_deallocate_a(ep%vpsl)
305 safe_deallocate_a(ep%photon_forces)
308 safe_deallocate_a(ep%e_field)
309 safe_deallocate_a(ep%v_ext)
310 safe_deallocate_a(ep%b_field)
311 safe_deallocate_a(ep%a_static)
313 do iproj = 1, ep%natoms
318 assert(
allocated(ep%proj))
319 safe_deallocate_a(ep%proj)
330 type(
epot_t),
intent(inout) :: ep
331 type(
poisson_t),
target,
intent(in) :: psolver
335 if (ep%have_density)
then
336 ep%poisson_solver => psolver
338 nullify(ep%poisson_solver)
346 type(
epot_t),
intent(inout) :: ep
348 class(
mesh_t),
target,
intent(in) :: mesh
349 type(
ions_t),
target,
intent(inout) :: ions
353 type(
ps_t),
pointer :: ps
354 logical,
allocatable :: spec_checked(:)
364 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
367 do ia = 1, ions%natoms
368 select type(spec=>ions%atom(ia)%species)
371 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%reltype)
375 do ia = ions%atoms_dist%start, ions%atoms_dist%end
377 select type(spec=>ions%atom(ia)%species)
380 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), ps%rc_max)
384 if (ions%atoms_dist%parallel)
then
385 do ia = 1, ions%natoms
387 select type(spec=>ions%atom(ia)%species)
390 call submesh_broadcast(ep%proj(ia)%sphere, ions%space, mesh, ions%pos(:, ia), ps%rc_max, &
391 ions%atoms_dist%node(ia), ions%atoms_dist%mpi_grp)
396 do ia = 1, ions%natoms
397 select type(spec=>ions%atom(ia)%species)
406 if (.not. ep%proj_check_done)
then
407 safe_allocate(spec_checked(1:ions%nspecies))
408 spec_checked = .false.
409 do ia = 1, ions%natoms
411 if (spec_checked(ions%atom(ia)%species%get_index())) cycle
412 select type(spec=>ions%atom(ia)%species)
415 spec_checked(ions%atom(ia)%species%get_index()) = .
true.
418 safe_deallocate_a(spec_checked)
419 ep%proj_check_done = .
true.
429 class(
space_t),
intent(in) :: space
432 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
438 type(
epot_t),
intent(in) :: ep
439 type(namespace_t),
intent(in) :: namespace
440 class(space_t),
intent(in) :: space
441 type(lattice_vectors_t),
intent(in) :: latt
442 class(mesh_t),
intent(in) :: mesh
443 class(species_t),
target,
intent(in) :: species
444 real(real64),
intent(in) :: pos(1:space%dim)
445 integer,
intent(in) :: iatom
446 real(real64),
contiguous,
intent(inout) :: vpsl(:)
449 real(real64) :: radius
450 real(real64),
allocatable :: vl(:), rho(:)
451 type(submesh_t) :: sphere
452 type(ps_t),
pointer :: ps
455 call profiling_in(
"EPOT_LOCAL")
457 if (ep%local_potential_precalculated)
then
459 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
466 safe_allocate(vl(1:mesh%np))
469 safe_allocate(rho(1:mesh%np))
471 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
473 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
475 safe_deallocate_a(rho)
479 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
483 call lalg_axpy(mesh%np, m_one, vl, vpsl)
484 safe_deallocate_a(vl)
488 class is(pseudopotential_t)
492 radius = min(ps%vl%x_threshold*1.05_real64, spline_range_max(ps%vl))
493 if (.not. submesh_compatible(sphere, radius, pos, minval(mesh%spacing(1:space%dim))))
then
494 call submesh_end(sphere)
495 call submesh_init(sphere, space, mesh, latt, pos, radius)
497 safe_allocate(vl(1:sphere%np))
501 if(sphere%r(ip) <= radius)
then
502 vl(ip) = spline_eval(ps%vl, sphere%r(ip))
506 call submesh_add_to_mesh(sphere, vl, vpsl)
508 safe_deallocate_a(vl)
512 call submesh_end(sphere)
516 call profiling_out(
"EPOT_LOCAL")
522 type(
epot_t),
intent(inout) :: ep
523 type(namespace_t),
intent(in) :: namespace
524 type(grid_t),
intent(in) :: gr
525 type(ions_t),
intent(in) :: ions
531 if (.not.
allocated(ep%local_potential))
then
532 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
535 ep%local_potential_precalculated = .false.
537 do iatom = 1, ions%natoms
538 ep%local_potential(1:gr%np, iatom) = m_zero
540 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))
542 ep%local_potential_precalculated = .
true.
550 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)
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_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