Octopus
epot.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module epot_oct_m
23 use comm_oct_m
24 use debug_oct_m
30 use global_oct_m
31 use grid_oct_m
33 use ions_oct_m
35 use, intrinsic :: iso_fortran_env
38 use mesh_oct_m
40 use mpi_oct_m
43 use parser_oct_m
48 use ps_oct_m
50 use space_oct_m
59 use unit_oct_m
62 use xc_oct_m
63
64 implicit none
65
66 private
67 public :: &
68 epot_t, &
69 epot_init, &
70 epot_end, &
77
78 integer, public, parameter :: &
79 NOREL = 0, &
80 spin_orbit = 1, &
83
84 type epot_t
85 ! Components are public by default
86
87 ! Ions
88 real(real64), allocatable :: vpsl(:)
89 ! !< plus the potential from static electric fields
90 type(projector_t), allocatable :: proj(:)
92 type(augmentation_species_t), pointer :: aug_species(:) => null()
94 type(distributed_t) :: atoms_dist_plane
95 logical :: non_local
96 logical :: requires_generalized_overlap = .false.
97 logical :: has_paw = .false.
98 integer :: natoms
99
100 ! External e-m fields
101 real(real64), allocatable :: e_field(:)
102 real(real64), allocatable :: v_ext(:)
103 real(real64), allocatable :: b_field(:)
104 real(real64), allocatable :: a_static(:,:)
105 integer :: reltype
108 integer :: proj_reltype
109
112 real(real64) :: gyromagnetic_ratio
113
115 real(real64) :: so_strength
116
118 real(real64) :: eii
119 real(real64), allocatable :: fii(:, :)
120 real(real64), allocatable :: vdw_forces(:, :)
121 real(real64), allocatable :: photon_forces(:)
122
124 real(real64) :: vdw_stress(3, 3)
125
126 real(real64), allocatable, private :: local_potential(:,:)
127 logical, private :: local_potential_precalculated
128
129 logical, private :: have_density
130 type(poisson_t), pointer, private :: poisson_solver
131
133 logical, private :: proj_check_done = .false.
134
135 logical :: nlcc = .false.
136
139 type(double_grid_t) :: dgrid
140 end type epot_t
141
142contains
143
144 ! ---------------------------------------------------------
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
150 type(poisson_t), target, intent(in) :: psolver
151 integer, intent(in) :: ispin
152 integer, intent(in) :: xc_family
153 type(kpoints_t), intent(in) :: kpoints
154
155
156 integer :: ispec, ia
157 integer :: filter
158 real(real64) :: gcutoff
159
160 push_sub(epot_init)
161
162 call double_grid_init(ep%dgrid, namespace, gr%box%dim)
163 if (ep%dgrid%enabled .and. gr%use_curvilinear) then
164 call messages_not_implemented("DoubleGrid with curvilinear coordinates", namespace=namespace)
165 end if
167 !%Variable FilterPotentials
168 !%Type integer
169 !%Default filter_ts
170 !%Section Hamiltonian
171 !%Description
172 !% <tt>Octopus</tt> can filter the pseudopotentials so that they no
173 !% longer contain Fourier components larger than the mesh itself. This is
174 !% very useful to decrease the egg-box effect, and so should be used in
175 !% all instances where atoms move (<i>e.g.</i> geometry optimization,
176 !% molecular dynamics, and vibrational modes).
177 !% No filtering is applied to HGH pseudopotentials, as these are already
178 !% smooth, analytical potentials in both real and Fourier space.
179 !%Option filter_none 0
180 !% Do not filter.
181 !%Option filter_TS 2
182 !% The filter of M. Tafipolsky and R. Schmid, <i>J. Chem. Phys.</i> <b>124</b>, 174102 (2006).
183 !%Option filter_BSB 3
184 !% The filter of E. L. Briggs, D. J. Sullivan, and J. Bernholc, <i>Phys. Rev. B</i> <b>54</b>, 14362 (1996).
185 !%End
186 call parse_variable(namespace, 'FilterPotentials', ps_filter_ts, filter)
187 if (.not. varinfo_valid_option('FilterPotentials', filter)) call messages_input_error(namespace, 'FilterPotentials')
188 call messages_print_var_option("FilterPotentials", filter, namespace=namespace)
189
190 if (family_is_mgga(xc_family) .and. filter /= ps_filter_none) then
191 call messages_not_implemented("FilterPotentials different from filter_none with MGGA", namespace=namespace)
192 end if
194 if (filter == ps_filter_ts) call spline_filter_mask_init()
195 ! With the double grid, the localized functions (projectors, short-range
196 ! local potential, core density) are constructed with a resolution divisor
197 ! times finer than the mesh, so the filter must keep the Fourier components
198 ! the fine grid resolves.
199 gcutoff = mesh_gcutoff(gr)
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)
203 end do
204
205 safe_allocate(ep%vpsl(1:gr%np))
206
207 ep%vpsl(1:gr%np) = m_zero
208
209 ! No more "UserDefinedTDPotential" from this version on.
210 call messages_obsolete_variable(namespace, 'UserDefinedTDPotential', 'TDExternalFields')
212 call messages_obsolete_variable(namespace, 'ClassicalPotential')
213
214 !%Variable GyromagneticRatio
215 !%Type float
216 !%Default 2.0023193043768
217 !%Section Hamiltonian
218 !%Description
219 !% The gyromagnetic ratio of the electron. This is of course a physical
220 !% constant, and the default value is the exact one that you should not
221 !% touch, unless:
222 !% (i) You want to disconnect the anomalous Zeeman term in the Hamiltonian
223 !% (then set it to zero; this number only affects that term);
224 !% (ii) You are using an effective Hamiltonian, as is the case when
225 !% you calculate a 2D electron gas, in which case you have an effective
226 !% gyromagnetic factor that depends on the material.
227 !%End
228 call parse_variable(namespace, 'GyromagneticRatio', p_g, ep%gyromagnetic_ratio)
229
230 !%Variable RelativisticCorrection
231 !%Type integer
232 !%Default non_relativistic
233 !%Section Hamiltonian
234 !%Description
235 !% The default value means that <i>no</i> relativistic correction is used. To
236 !% include spin-orbit coupling turn <tt>RelativisticCorrection</tt> to <tt>spin_orbit</tt>
237 !% (this will only work if <tt>SpinComponents</tt> has been set to <tt>non_collinear</tt>, which ensures
238 !% the use of spinors).
239 !%
240 !% The two ZORA options are meant for all-electron species (see <tt>AllElectronType</tt>).
241 !% For pseudopotentials the relativistic effects are already contained in the pseudopotential
242 !% itself, so <tt>fully_relativistic_zora</tt> is rejected for pseudopotential species and
243 !% <tt>scalar_relativistic_zora</tt> only issues a warning; use <tt>spin_orbit</tt> instead.
244 !%
245 !% Three properties of the ZORA implementation are worth knowing:
246 !%
247 !% <ul>
248 !% <li> The potential <i>V</i> entering the ZORA prefactor <math>c^2/(2mc^2-V)</math> is the
249 !% ionic plus external potential only; the Hartree and exchange-correlation potential are
250 !% <i>not</i> included. This is a deliberate approximation, which makes this ZORA comparable
251 !% to a one-electron X2C rather than to a full ZORA. </li>
252 !% <li> As a consequence the ZORA prefactor carries no spin dependence: it is built from a
253 !% single, spin-independent potential and applied identically to both spin channels. </li>
254 !% <li> The forces receive no contribution from the ZORA terms, and are therefore only
255 !% approximate; a warning is printed if they are requested. The stress tensor is not
256 !% available with ZORA at all. </li>
257 !% </ul>
258 !%Option non_relativistic 0
259 !% No relativistic corrections.
260 !%Option spin_orbit 1
261 !% Spin-orbit, from the j-dependent projectors of a fully-relativistic pseudopotential.
262 !%Option scalar_relativistic_zora 2
263 !% Scalar relativistic ZORA Hamiltonian
264 !%Option fully_relativistic_zora 3
265 !% Fully relativistic spin-orbit ZORA Hamiltonian including SR and SO terms
266 !%End
267 call parse_variable(namespace, 'RelativisticCorrection', norel, ep%reltype)
268 if (.not. varinfo_valid_option('RelativisticCorrection', ep%reltype)) then
269 call messages_input_error(namespace, 'RelativisticCorrection')
270 end if
271 if (ispin /= spinors .and. ( ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora ) ) then
272 message(1) = "The spin-orbit term can only be applied when using spinors."
273 call messages_fatal(1, namespace=namespace)
274 end if
275
276 if((ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora) .and. kpoints%use_symmetries) then
277 call messages_not_implemented("Spin-orbit coupling and k-point symmetries", namespace=namespace)
278 end if
279
280 if (ep%reltype == scalar_relativistic_zora .or. ep%reltype == fully_relativistic_zora) then
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."
286 if (ep%reltype == fully_relativistic_zora) then
287 message(3) = "Use RelativisticCorrection = spin_orbit for pseudopotentials, or an"
288 message(4) = "all-electron species (see AllElectronType) for ZORA."
289 call messages_fatal(4, namespace=namespace)
290 else
291 message(3) = "Scalar relativistic effects will therefore be counted twice."
292 call messages_warning(3, namespace=namespace)
293 end if
294 end do
295 end if
296
299 ep%proj_reltype = norel
300 if (ep%reltype == spin_orbit) ep%proj_reltype = spin_orbit
301
302 ! The double grid acts on projectors built from real spherical harmonics;
303 ! the j-dependent (rkb) projectors are built from complex ones.
304 if (ep%dgrid%enabled .and. (ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora)) then
305 call messages_not_implemented("DoubleGrid with spin-orbit coupling", namespace=namespace)
306 end if
307
308 call messages_print_var_option("RelativisticCorrection", ep%reltype, namespace=namespace)
309
310 !%Variable SOStrength
311 !%Type float
312 !%Default 1.0
313 !%Section Hamiltonian
314 !%Description
315 !% Tuning of the spin-orbit coupling strength: setting this value to zero turns off spin-orbit terms in
316 !% the Hamiltonian, and setting it to one corresponds to full spin-orbit.
317 !%
318 !% This variable is parsed both for <tt>RelativisticCorrection = spin_orbit</tt> and for
319 !% <tt>fully_relativistic_zora</tt>. In the latter case it scales the ZORA spin-orbit term only,
320 !% so <tt>SOStrength = 0.0</tt> reproduces <tt>scalar_relativistic_zora</tt> exactly. This is
321 !% the cleanest way to separate the scalar-relativistic and the spin-orbit ZORA contributions
322 !% within a single code path.
323 !%
324 !% For fully-relativistic ultrasoft pseudopotentials, it scales the splitting between the
325 !% j = l + 1/2 and j = l - 1/2 channels of the bare nonlocal coupling D_ij around their
326 !% (2j+1)-weighted average; the j dependence of the augmentation functions Q_ij is not scaled.
327 !% It is not supported for fully-relativistic PAW datasets, whose spin-orbit splitting is
328 !% mostly carried by the j-dependent partial waves: only <tt>SOStrength = 1.0</tt> is allowed there.
329 !%End
330 if (ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora) then
331 call parse_variable(namespace, 'SOStrength', m_one, ep%so_strength)
332 else
333 ep%so_strength = m_one
334 end if
335
336 safe_allocate(ep%proj(1:ions%natoms))
337 allocate(ep%aug_species(1:ions%nspecies))
338 call distributed_init_serial(ep%atoms_dist_plane, ions%natoms)
339
340 ep%natoms = ions%natoms
341 ep%non_local = .false.
342 ep%requires_generalized_overlap = .false.
343
344 ep%eii = m_zero
345 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
346 ep%fii = m_zero
347
348 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
349 ep%vdw_forces = m_zero
350
351 safe_allocate(ep%photon_forces(1:ions%space%dim))
352 ep%photon_forces = m_zero
353
354 ep%local_potential_precalculated = .false.
355
356
357 ep%have_density = .false.
358 do ia = 1, ions%nspecies
359 if (local_potential_has_density(ions%space, ions%species(ia)%s)) then
360 ep%have_density = .true.
361 exit
362 end if
363 end do
364
365 if (ep%have_density) then
366 ep%poisson_solver => psolver
367 else
368 nullify(ep%poisson_solver)
369 end if
370
371 ! find out if we need non-local core corrections
372 ep%nlcc = .false.
373 ep%requires_generalized_overlap = .false.
374 ep%has_paw = .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)
378 type is(pseudopotential_t)
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()
381 end select
382 end do
383
384 pop_sub(epot_init)
385 end subroutine epot_init
386
387 ! ---------------------------------------------------------
388 subroutine epot_end(ep)
389 type(epot_t), intent(inout) :: ep
390
391 integer :: iproj
392
393 push_sub(epot_end)
394
395 if (ep%have_density) then
396 nullify(ep%poisson_solver)
397 end if
398
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)
404
405 ! the macroscopic fields
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)
410
411 do iproj = 1, ep%natoms
412 if (projector_is_null(ep%proj(iproj))) cycle
413 call projector_end(ep%proj(iproj))
414 end do
415
416 assert(allocated(ep%proj))
417 safe_deallocate_a(ep%proj)
418
419 if (associated(ep%aug_species)) then
420 do iproj = 1, size(ep%aug_species)
421 call augmentation_species_end(ep%aug_species(iproj))
422 end do
423 deallocate(ep%aug_species)
424 nullify(ep%aug_species)
425 end if
426
427 call distributed_end(ep%atoms_dist_plane)
428
429 call double_grid_end(ep%dgrid)
430
431 pop_sub(epot_end)
432
433 end subroutine epot_end
434
435 ! ---------------------------------------------------------
439 subroutine epot_bind_poisson_solver(ep, psolver)
440 type(epot_t), intent(inout) :: ep
441 type(poisson_t), target, intent(in) :: psolver
442
444
445 if (ep%have_density) then
446 ep%poisson_solver => psolver
447 else
448 nullify(ep%poisson_solver)
449 end if
450
452 end subroutine epot_bind_poisson_solver
453
454 ! ---------------------------------------------------------
455 subroutine epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
456 type(epot_t), intent(inout) :: ep
457 type(namespace_t), intent(in) :: namespace
458 class(mesh_t), target, intent(in) :: mesh
459 type(ions_t), target, intent(inout) :: ions
460 type(states_elec_dim_t), intent(inout) :: st_d
462 type(mpi_grp_t), optional, intent(in) :: kpt_st_grp
463
464 integer :: ia, ispec, paw_nspin
465 logical :: fill
466 type(ps_t), pointer :: ps
467 logical, allocatable :: spec_checked(:)
468
469 call profiling_in("EPOT_GENERATE")
470 push_sub(epot_generate)
471
472 ! Local part
473 ep%vpsl = m_zero
474
475 ! we assume that we need to recalculate the ion-ion energy
476 call ion_interaction_calculate(ions%ion_interaction, ions%space, ions%latt, ions%atom, &
477 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
478
479 ! the pseudopotential part.
480 do ia = 1, ions%natoms
481 select type(spec=>ions%atom(ia)%species)
482 type is(pseudopotential_t)
483 call projector_end(ep%proj(ia))
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()
487 end select
488 end do
489
490 ! With the double grid, the effective support of the transformed projectors
491 ! extends beyond their analytic support by the interpolation-stencil reach.
492 do ia = ions%atoms_dist%start, ions%atoms_dist%end
493 if (ep%proj(ia)%type == proj_none) cycle
494 select type(spec=>ions%atom(ia)%species)
495 type is(pseudopotential_t)
496 ps => spec%ps
497 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), &
498 epot_projector_radius(ep, ps, mesh))
499 end select
500 end do
501
502 if (ions%atoms_dist%parallel) then
503 do ia = 1, ions%natoms
504 if (ep%proj(ia)%type == proj_none) cycle
505 select type(spec=>ions%atom(ia)%species)
506 type is(pseudopotential_t)
507 ps => spec%ps
508 call submesh_broadcast(ep%proj(ia)%sphere, ions%space, mesh, ions%pos(:, ia), &
509 epot_projector_radius(ep, ps, mesh), &
510 ions%atoms_dist%process(ia), ions%atoms_dist%mpi_grp)
511 end select
512 end do
513 end if
514
515 ! Number of spin components of the PAW one-center density matrix
516 paw_nspin = st_d%nspin
517
518 ! Shared per-species augmentation data: built once per species
519 do ia = 1, ions%natoms
520 if (ep%proj(ia)%type /= proj_uspp) cycle
521 select type(spec=>ions%atom(ia)%species)
522 type is(pseudopotential_t)
523 if (spec%is_paw() .and. spec%ps%relativistic_treatment == proj_j_dependent &
524 .and. ep%reltype /= spin_orbit) then
525 message(1) = "Fully-relativistic (j-dependent) PAW datasets require"
526 message(2) = "SpinComponents = spinors and RelativisticCorrection = spin_orbit."
527 call messages_fatal(2, namespace=namespace)
528 end if
529 if (spec%is_paw() .and. ep%reltype == spin_orbit .and. abs(ep%so_strength - m_one) > m_epsilon) then
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."
532 call messages_fatal(2, namespace=namespace)
533 end if
534 if (ep%reltype == spin_orbit .and. spec%ps%projector_type == proj_uspp &
535 .and. spec%ps%relativistic_treatment /= proj_j_dependent) then
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."
538 call messages_fatal(2, namespace=namespace)
539 end if
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)
546 call paw_onsite_init(ep%aug_species(ispec)%paw, spec%ps, namespace, paw_kresse_joubert, paw_nspin)
547 end if
548 end if
549 end select
550 end do
551
552 ! Atom-level distribution of the per-atom construction work over the kpoint-states
553 ! plane: built once and stored in the epot (the group and the atom count are
554 ! run-constant), then reused here and by the local-potential, core-density and
555 ! stress consumers instead of each creating its own distribution.
556 if (present(kpt_st_grp)) then
557 call distributed_init(ep%atoms_dist_plane, ions%natoms, kpt_st_grp%comm, "atoms_plane")
558 else
559 call distributed_init_serial(ep%atoms_dist_plane, ions%natoms)
560 end if
561
562 do ia = 1, ions%natoms
563 select type(spec=>ions%atom(ia)%species)
564 type is(pseudopotential_t)
565 fill = .true.
566 if (ep%atoms_dist_plane%parallel) then
567 fill = (ep%atoms_dist_plane%process(ia) == ep%atoms_dist_plane%mpi_grp%rank)
568 end if
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()))
571 if (.not. projector_is(ep%proj(ia), proj_none)) ep%non_local = .true.
572 end select
573 end do
574
575 if (ep%atoms_dist_plane%parallel) then
576 do ia = 1, ions%natoms
577 select type(spec=>ions%atom(ia)%species)
578 type is(pseudopotential_t)
579 call projector_bcast_fill(ep%proj(ia), ep%atoms_dist_plane%mpi_grp, ep%atoms_dist_plane%process(ia))
580 end select
581 end do
582 end if
583
584 ! Check once, for one atom of each species, that the projectors are properly
585 ! resolved on the grid, to warn about possible spurious (ghost) states
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
590 if (ep%proj(ia)%type == proj_none) cycle
591 if (spec_checked(ions%atom(ia)%species%get_index())) cycle
592 select type(spec=>ions%atom(ia)%species)
593 type is(pseudopotential_t)
594 call projector_check_discretization(spec, ep%proj(ia)%sphere, namespace)
595 spec_checked(ions%atom(ia)%species%get_index()) = .true.
596 end select
597 end do
598 safe_deallocate_a(spec_checked)
599 ep%proj_check_done = .true.
600 end if
601
602 pop_sub(epot_generate)
603 call profiling_out("EPOT_GENERATE")
604 end subroutine epot_generate
605
606 ! ---------------------------------------------------------
610 real(real64) function epot_projector_radius(ep, ps, mesh) result(radius)
611 type(epot_t), intent(in) :: ep
612 type(ps_t), intent(in) :: ps
613 class(mesh_t), intent(in) :: mesh
614
615 radius = ps%rc_max
616 if (ep%dgrid%enabled) then
617 if (allocated(ps%radial_augmentation)) radius = max(radius, maxval(ps%radial_augmentation(:, :)%x_threshold))
618 radius = radius + double_grid_margin(ep%dgrid, mesh)
619 end if
620 end function epot_projector_radius
621
622 ! ---------------------------------------------------------
623
624 logical pure function local_potential_has_density(space, species) result(has_density)
625 class(space_t), intent(in) :: space
626 class(species_t), intent(in) :: species
627
628 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
629
630 end function local_potential_has_density
631
632 ! ---------------------------------------------------------
633 subroutine epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
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(:)
643
644 real(real64), allocatable :: vl(:), rho(:)
645 type(submesh_t) :: sphere
646
647 push_sub(epot_local_potential)
648 call profiling_in("EPOT_LOCAL")
649
650 if (ep%local_potential_precalculated) then
651
652 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
653
654 else
655
656 !Local potential, we can get it by solving the Poisson equation
657 !(for all-electron species or pseudopotentials in periodic
658 !systems) or by applying it directly to the grid
659 safe_allocate(vl(1:mesh%np))
660
661 if (local_potential_has_density(space, species)) then
662 safe_allocate(rho(1:mesh%np))
663
664 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
665
666 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
667
668 safe_deallocate_a(rho)
669
670 else
671
672 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
673
674 end if
675
676 call lalg_axpy(mesh%np, m_one, vl, vpsl)
677 safe_deallocate_a(vl)
678
679 !the localized part
680 call species_get_local_sr(species, space, latt, pos, mesh, sphere, vpsl, ep%dgrid)
681 call submesh_end(sphere)
683 end if
684
685 call profiling_out("EPOT_LOCAL")
686 pop_sub(epot_local_potential)
687 end subroutine epot_local_potential
688
689 ! ---------------------------------------------------------
690 subroutine epot_precalc_local_potential(ep, namespace, gr, ions)
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
695
696 integer :: iatom
697
699
700 if (.not. allocated(ep%local_potential)) then
701 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
702 end if
703
704 ep%local_potential_precalculated = .false.
706 do iatom = 1, ions%natoms
707 ep%local_potential(1:gr%np, iatom) = m_zero
708 call epot_local_potential(ep, namespace, ions%space, ions%latt, gr, ions%atom(iatom)%species, &
709 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))!, time)
710 end do
711 ep%local_potential_precalculated = .true.
712
714 end subroutine epot_precalc_local_potential
715
716 ! ---------------------------------------------------------
717
718 logical function epot_have_external_potentials(ep)
719 type(epot_t), intent(in) :: ep
720
722
723 epot_have_external_potentials = allocated(ep%e_field)
724
726
728
729end module epot_oct_m
730
731!! Local Variables:
732!! mode: f90
733!! coding: utf-8
734!! End:
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...
Definition: epot.F90:683
subroutine, public epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
Definition: epot.F90:528
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...
Definition: epot.F90:512
logical function, public epot_have_external_potentials(ep)
Definition: epot.F90:791
logical pure function, public local_potential_has_density(space, species)
Definition: epot.F90:697
integer, parameter, public spin_orbit
Definition: epot.F90:150
integer, parameter, public scalar_relativistic_zora
Definition: epot.F90:150
subroutine, public epot_end(ep)
Definition: epot.F90:461
integer, parameter, public fully_relativistic_zora
Definition: epot.F90:150
subroutine, public epot_precalc_local_potential(ep, namespace, gr, ions)
Definition: epot.F90:763
subroutine, public epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
Definition: epot.F90:706
subroutine, public epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints)
Definition: epot.F90:218
real(real64), parameter, public p_g
Definition: global.F90:217
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_one
Definition: global.F90:174
This module implements the underlying real-space grid.
Definition: grid.F90:96
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.
Definition: mesh.F90:97
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...
Definition: mesh.F90:432
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
PAW radial engine.
Definition: paw_onsite.F90:131
subroutine, public paw_onsite_init(this, ps, namespace, formulation, nspin)
Build the per-species one-center data from a (PAW) pseudopotential.
Definition: paw_onsite.F90:313
integer, parameter, public paw_kresse_joubert
PAW formulation: selects the compensation-charge / reference treatment.
Definition: paw_onsite.F90:180
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
logical elemental function, public projector_is(p, type)
Definition: projector.F90:204
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
Definition: projector.F90:219
subroutine, public projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
Definition: projector.F90:355
subroutine, public projector_end(p)
Definition: projector.F90:823
subroutine, public projector_bcast_fill(p, grp, root)
Broadcast the projector values built by the owning rank of an atom-distributed projector build.
Definition: projector.F90:556
subroutine, public projector_check_discretization(pseudo, sm, namespace)
Check how well the nonlocal projectors are resolved on the real-space grid.
Definition: projector.F90:487
logical elemental function, public projector_is_null(p)
Definition: projector.F90:197
Definition: ps.F90:93
integer, parameter, public ps_filter_ts
Definition: ps.F90:146
integer, parameter, public ps_filter_none
Definition: ps.F90:146
integer, parameter, public proj_uspp
Definition: ps.F90:151
integer, parameter, public proj_j_dependent
Fully-relativistic j-dependent pseudopotentials.
Definition: ps.F90:158
integer, parameter, public proj_none
Definition: ps.F90:151
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)
Definition: submesh.F90:613
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
Definition: submesh.F90:209
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
This module defines the unit system, used for input and output.
Definition: xc.F90:97
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
Definition: xc.F90:694
Describes mesh distribution to nodes.
Definition: mesh.F90:165
This is defined even when running serial.
Definition: mpi.F90:121
A type storing the information and data about a pseudopotential.
Definition: ps.F90:169
class for organizing spins and k-points
int true(void)