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
64
65 implicit none
66
67 private
68 public :: &
69 epot_t, &
70 epot_init, &
72 epot_end, &
79
80 integer, public, parameter :: &
81 NOREL = 0, &
82 spin_orbit = 1, &
85
86 type epot_t
87 ! Components are public by default
88
89 ! Ions
90 real(real64), allocatable :: vpsl(:)
91 ! !< plus the potential from static electric fields
92 type(projector_t), allocatable :: proj(:)
94 type(augmentation_species_t), pointer :: aug_species(:) => null()
96 type(distributed_t) :: atoms_dist_plane
97 logical :: non_local
98 logical :: requires_generalized_overlap = .false.
99 logical :: has_paw = .false.
100 integer :: natoms
101 integer :: xc_id(2) = 0
103 logical :: usexcnhat = .true.
104
105 ! External e-m fields
106 real(real64), allocatable :: e_field(:)
107 real(real64), allocatable :: v_ext(:)
108 real(real64), allocatable :: b_field(:)
109 real(real64), allocatable :: a_static(:,:)
110 integer :: reltype
113 integer :: proj_reltype
114
117 real(real64) :: gyromagnetic_ratio
118
120 real(real64) :: so_strength
121
123 real(real64) :: eii
124 real(real64), allocatable :: fii(:, :)
125 real(real64), allocatable :: vdw_forces(:, :)
126 real(real64), allocatable :: photon_forces(:)
127
129 real(real64) :: vdw_stress(3, 3)
130
131 real(real64), allocatable, private :: local_potential(:,:)
132 logical, private :: local_potential_precalculated
133
134 logical, private :: have_density
135 type(poisson_t), pointer, private :: poisson_solver
136
138 logical, private :: proj_check_done = .false.
139
140 logical :: nlcc = .false.
141
144 type(double_grid_t) :: dgrid
145 end type epot_t
146
147contains
148
149 ! ---------------------------------------------------------
150 subroutine epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints, xc_id)
151 type(epot_t), intent(out) :: ep
152 type(namespace_t), intent(in) :: namespace
153 type(grid_t), intent(in) :: gr
154 type(ions_t), intent(inout) :: ions
155 type(poisson_t), target, intent(in) :: psolver
156 integer, intent(in) :: ispin
157 integer, intent(in) :: xc_family
158 type(kpoints_t), intent(in) :: kpoints
159 integer, optional, intent(in) :: xc_id(2)
160
161
162 integer :: ispec, ia
163 integer :: filter, paw_comp_scheme
164 real(real64) :: gcutoff
165
166 push_sub(epot_init)
167
168 if (present(xc_id)) ep%xc_id(:) = xc_id(:)
170 call double_grid_init(ep%dgrid, namespace, gr%box%dim)
171 if (ep%dgrid%enabled .and. gr%use_curvilinear) then
172 call messages_not_implemented("DoubleGrid with curvilinear coordinates", namespace=namespace)
173 end if
174
175 !%Variable FilterPotentials
176 !%Type integer
177 !%Default filter_ts
178 !%Section Hamiltonian
179 !%Description
180 !% <tt>Octopus</tt> can filter the pseudopotentials so that they no
181 !% longer contain Fourier components larger than the mesh itself. This is
182 !% very useful to decrease the egg-box effect, and so should be used in
183 !% all instances where atoms move (<i>e.g.</i> geometry optimization,
184 !% molecular dynamics, and vibrational modes).
185 !% No filtering is applied to HGH pseudopotentials, as these are already
186 !% smooth, analytical potentials in both real and Fourier space.
187 !%Option filter_none 0
188 !% Do not filter.
189 !%Option filter_TS 2
190 !% The filter of M. Tafipolsky and R. Schmid, <i>J. Chem. Phys.</i> <b>124</b>, 174102 (2006).
191 !%Option filter_BSB 3
192 !% The filter of E. L. Briggs, D. J. Sullivan, and J. Bernholc, <i>Phys. Rev. B</i> <b>54</b>, 14362 (1996).
193 !%End
194 call parse_variable(namespace, 'FilterPotentials', ps_filter_ts, filter)
195 if (.not. varinfo_valid_option('FilterPotentials', filter)) call messages_input_error(namespace, 'FilterPotentials')
196 call messages_print_var_option("FilterPotentials", filter, namespace=namespace)
198 if (family_is_mgga(xc_family) .and. filter /= ps_filter_none) then
199 call messages_not_implemented("FilterPotentials different from filter_none with MGGA", namespace=namespace)
200 end if
202 if (filter == ps_filter_ts) call spline_filter_mask_init()
203 ! With the double grid, the localized functions (projectors, short-range
204 ! local potential, core density) are constructed with a resolution divisor
205 ! times finer than the mesh, so the filter must keep the Fourier components
206 ! the fine grid resolves.
207 gcutoff = mesh_gcutoff(gr)
208 if (ep%dgrid%enabled) gcutoff = gcutoff*ep%dgrid%divisor
209 do ispec = 1, ions%nspecies
210 call ions%species(ispec)%s%init_potential(namespace, gcutoff, filter)
211 end do
213 safe_allocate(ep%vpsl(1:gr%np))
214
215 ep%vpsl(1:gr%np) = m_zero
217 ! No more "UserDefinedTDPotential" from this version on.
218 call messages_obsolete_variable(namespace, 'UserDefinedTDPotential', 'TDExternalFields')
219
220 call messages_obsolete_variable(namespace, 'ClassicalPotential')
221
222 !%Variable GyromagneticRatio
223 !%Type float
224 !%Default 2.0023193043768
225 !%Section Hamiltonian
226 !%Description
227 !% The gyromagnetic ratio of the electron. This is of course a physical
228 !% constant, and the default value is the exact one that you should not
229 !% touch, unless:
230 !% (i) You want to disconnect the anomalous Zeeman term in the Hamiltonian
231 !% (then set it to zero; this number only affects that term);
232 !% (ii) You are using an effective Hamiltonian, as is the case when
233 !% you calculate a 2D electron gas, in which case you have an effective
234 !% gyromagnetic factor that depends on the material.
235 !%End
236 call parse_variable(namespace, 'GyromagneticRatio', p_g, ep%gyromagnetic_ratio)
237
238 !%Variable RelativisticCorrection
239 !%Type integer
240 !%Default non_relativistic
241 !%Section Hamiltonian
242 !%Description
243 !% The default value means that <i>no</i> relativistic correction is used. To
244 !% include spin-orbit coupling turn <tt>RelativisticCorrection</tt> to <tt>spin_orbit</tt>
245 !% (this will only work if <tt>SpinComponents</tt> has been set to <tt>non_collinear</tt>, which ensures
246 !% the use of spinors).
247 !%
248 !% The two ZORA options are meant for all-electron species (see <tt>AllElectronType</tt>).
249 !% For pseudopotentials the relativistic effects are already contained in the pseudopotential
250 !% itself, so <tt>fully_relativistic_zora</tt> is rejected for pseudopotential species and
251 !% <tt>scalar_relativistic_zora</tt> only issues a warning; use <tt>spin_orbit</tt> instead.
252 !%
253 !% Three properties of the ZORA implementation are worth knowing:
254 !%
255 !% <ul>
256 !% <li> The potential <i>V</i> entering the ZORA prefactor <math>c^2/(2mc^2-V)</math> is the
257 !% ionic plus external potential only; the Hartree and exchange-correlation potential are
258 !% <i>not</i> included. This is a deliberate approximation, which makes this ZORA comparable
259 !% to a one-electron X2C rather than to a full ZORA. </li>
260 !% <li> As a consequence the ZORA prefactor carries no spin dependence: it is built from a
261 !% single, spin-independent potential and applied identically to both spin channels. </li>
262 !% <li> The forces receive no contribution from the ZORA terms, and are therefore only
263 !% approximate; a warning is printed if they are requested. The stress tensor is not
264 !% available with ZORA at all. </li>
265 !% </ul>
266 !%Option non_relativistic 0
267 !% No relativistic corrections.
268 !%Option spin_orbit 1
269 !% Spin-orbit, from the j-dependent projectors of a fully-relativistic pseudopotential.
270 !%Option scalar_relativistic_zora 2
271 !% Scalar relativistic ZORA Hamiltonian
272 !%Option fully_relativistic_zora 3
273 !% Fully relativistic spin-orbit ZORA Hamiltonian including SR and SO terms
274 !%End
275 call parse_variable(namespace, 'RelativisticCorrection', norel, ep%reltype)
276 if (.not. varinfo_valid_option('RelativisticCorrection', ep%reltype)) then
277 call messages_input_error(namespace, 'RelativisticCorrection')
278 end if
279 if (ispin /= spinors .and. ( ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora ) ) then
280 message(1) = "The spin-orbit term can only be applied when using spinors."
281 call messages_fatal(1, namespace=namespace)
282 end if
283
284 if((ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora) .and. kpoints%use_symmetries) then
285 call messages_not_implemented("Spin-orbit coupling and k-point symmetries", namespace=namespace)
286 end if
287
288 if (ep%reltype == scalar_relativistic_zora .or. ep%reltype == fully_relativistic_zora) then
289 do ia = 1, ions%nspecies
290 if (.not. ions%species(ia)%s%is_ps()) cycle
291 message(1) = "ZORA is meant for all-electron species, but species '" &
292 //trim(ions%species(ia)%s%get_label())//"' is a pseudopotential,"
293 message(2) = "which already contains the relativistic effects."
294 if (ep%reltype == fully_relativistic_zora) then
295 message(3) = "Use RelativisticCorrection = spin_orbit for pseudopotentials, or an"
296 message(4) = "all-electron species (see AllElectronType) for ZORA."
297 call messages_fatal(4, namespace=namespace)
298 else
299 message(3) = "Scalar relativistic effects will therefore be counted twice."
300 call messages_warning(3, namespace=namespace)
301 end if
302 end do
303 end if
304
307 ep%proj_reltype = norel
308 if (ep%reltype == spin_orbit) ep%proj_reltype = spin_orbit
309
310 ! The double grid acts on projectors built from real spherical harmonics;
311 ! the j-dependent (rkb) projectors are built from complex ones.
312 if (ep%dgrid%enabled .and. (ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora)) then
313 call messages_not_implemented("DoubleGrid with spin-orbit coupling", namespace=namespace)
314 end if
315
316 call messages_print_var_option("RelativisticCorrection", ep%reltype, namespace=namespace)
317
318 !%Variable SOStrength
319 !%Type float
320 !%Default 1.0
321 !%Section Hamiltonian
322 !%Description
323 !% Tuning of the spin-orbit coupling strength: setting this value to zero turns off spin-orbit terms in
324 !% the Hamiltonian, and setting it to one corresponds to full spin-orbit.
325 !%
326 !% This variable is parsed both for <tt>RelativisticCorrection = spin_orbit</tt> and for
327 !% <tt>fully_relativistic_zora</tt>. In the latter case it scales the ZORA spin-orbit term only,
328 !% so <tt>SOStrength = 0.0</tt> reproduces <tt>scalar_relativistic_zora</tt> exactly. This is
329 !% the cleanest way to separate the scalar-relativistic and the spin-orbit ZORA contributions
330 !% within a single code path.
331 !%
332 !% For fully-relativistic ultrasoft pseudopotentials, it scales the splitting between the
333 !% j = l + 1/2 and j = l - 1/2 channels of the bare nonlocal coupling D_ij around their
334 !% (2j+1)-weighted average; the j dependence of the augmentation functions Q_ij is not scaled.
335 !% It is not supported for fully-relativistic PAW datasets, whose spin-orbit splitting is
336 !% mostly carried by the j-dependent partial waves: only <tt>SOStrength = 1.0</tt> is allowed there.
337 !%End
338 if (ep%reltype == spin_orbit .or. ep%reltype == fully_relativistic_zora) then
339 call parse_variable(namespace, 'SOStrength', m_one, ep%so_strength)
340 else
341 ep%so_strength = m_one
342 end if
343
344 safe_allocate(ep%proj(1:ions%natoms))
345 allocate(ep%aug_species(1:ions%nspecies))
346 call distributed_init_serial(ep%atoms_dist_plane, ions%natoms)
347
348 ep%natoms = ions%natoms
349 ep%non_local = .false.
350 ep%requires_generalized_overlap = .false.
351
352 ep%eii = m_zero
353 safe_allocate(ep%fii(1:ions%space%dim, 1:ions%natoms))
354 ep%fii = m_zero
355
356 safe_allocate(ep%vdw_forces(1:ions%space%dim, 1:ions%natoms))
357 ep%vdw_forces = m_zero
358
359 safe_allocate(ep%photon_forces(1:ions%space%dim))
360 ep%photon_forces = m_zero
361
362 ep%local_potential_precalculated = .false.
363
364
365 ep%have_density = .false.
366 do ia = 1, ions%nspecies
367 if (local_potential_has_density(ions%space, ions%species(ia)%s)) then
368 ep%have_density = .true.
369 exit
370 end if
371 end do
372
373 if (ep%have_density) then
374 ep%poisson_solver => psolver
375 else
376 nullify(ep%poisson_solver)
377 end if
378
379 ! find out if we need non-local core corrections
380 ep%nlcc = .false.
381 ep%requires_generalized_overlap = .false.
382 ep%has_paw = .false.
383 do ia = 1, ions%nspecies
384 ep%nlcc = (ep%nlcc .or. ions%species(ia)%s%is_ps_with_nlcc())
385 select type(spec=>ions%species(ia)%s)
386 type is(pseudopotential_t)
387 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
388 ep%has_paw = ep%has_paw .or. spec%is_paw()
389 end select
390 end do
391
392 ! Treatment of the PAW compensation charge in the XC (the ultrasoft augmentation charge is
393 ! always included in the XC density)
394 ep%usexcnhat = .true.
395 if (ep%has_paw) then
396 !%Variable PAWCompensationScheme
397 !%Type integer
398 !%Default auto
399 !%Section Hamiltonian::XC
400 !%Description
401 !% For PAW pseudopotentials, selects whether the compensation charge
402 !% <math>\hat{n} = \sum_{ij} \rho_{ij} Q_{ij}(\mathbf{r})</math> is included in the
403 !% exchange-correlation density (both on the mesh and in the one-center reconstruction).
404 !%Option auto -1
405 !% Bloechl for meta-GGA (where the compensation charge has no kinetic-energy-density
406 !% counterpart), Kresse-Joubert otherwise. This is the recommended default.
407 !%Option kresse_joubert 1
408 !% Include the compensation charge in the XC density (usexcnhat = 1). The historical
409 !% octopus PAW default; not allowed for meta-GGA.
410 !%Option bloechl 0
411 !% Exclude the compensation charge from the XC density (usexcnhat = 0). Uses the smooth
412 !% valence + smooth core density only.
413 !%End
414 call parse_variable(namespace, 'PAWCompensationScheme', -1, paw_comp_scheme)
415 select case (paw_comp_scheme)
416 case (-1) ! auto
417 ep%usexcnhat = .not. family_is_mgga(xc_family)
418 case (1) ! kresse_joubert
419 if (family_is_mgga(xc_family)) then
420 message(1) = "PAWCompensationScheme = kresse_joubert is not supported for meta-GGA"
421 message(2) = "(the compensation charge has no kinetic-energy-density counterpart)."
422 call messages_fatal(2, namespace=namespace)
423 end if
424 ep%usexcnhat = .true.
425 case (0) ! bloechl
426 ep%usexcnhat = .false.
427 case default
428 call messages_input_error(namespace, 'PAWCompensationScheme')
429 end select
430 ! The noncollinear XC would also need the compensation charge removed before the rotation
431 ! to the local spin frame.
432 if (.not. ep%usexcnhat .and. ispin == spinors) then
433 call messages_not_implemented("PAW with spinors and the Bloechl compensation scheme", namespace=namespace)
434 end if
435 end if
436
437 pop_sub(epot_init)
438 end subroutine epot_init
439
440 ! ---------------------------------------------------------
441 subroutine epot_end(ep)
442 type(epot_t), intent(inout) :: ep
443
444 integer :: iproj
445
446 push_sub(epot_end)
447
448 if (ep%have_density) then
449 nullify(ep%poisson_solver)
450 end if
451
452 safe_deallocate_a(ep%local_potential)
453 safe_deallocate_a(ep%fii)
454 safe_deallocate_a(ep%vdw_forces)
455 safe_deallocate_a(ep%vpsl)
456 safe_deallocate_a(ep%photon_forces)
457
458 ! the macroscopic fields
459 safe_deallocate_a(ep%e_field)
460 safe_deallocate_a(ep%v_ext)
461 safe_deallocate_a(ep%b_field)
462 safe_deallocate_a(ep%a_static)
463
464 do iproj = 1, ep%natoms
465 if (projector_is_null(ep%proj(iproj))) cycle
466 call projector_end(ep%proj(iproj))
467 end do
468
469 assert(allocated(ep%proj))
470 safe_deallocate_a(ep%proj)
471
472 if (associated(ep%aug_species)) then
473 do iproj = 1, size(ep%aug_species)
474 call augmentation_species_end(ep%aug_species(iproj))
475 end do
476 deallocate(ep%aug_species)
477 nullify(ep%aug_species)
478 end if
479
480 call distributed_end(ep%atoms_dist_plane)
481
482 call double_grid_end(ep%dgrid)
483
484 pop_sub(epot_end)
485
486 end subroutine epot_end
487
488 ! ---------------------------------------------------------
492 subroutine epot_bind_poisson_solver(ep, psolver)
493 type(epot_t), intent(inout) :: ep
494 type(poisson_t), target, intent(in) :: psolver
495
497
498 if (ep%have_density) then
499 ep%poisson_solver => psolver
500 else
501 nullify(ep%poisson_solver)
502 end if
503
505 end subroutine epot_bind_poisson_solver
506
507 ! ---------------------------------------------------------
508 subroutine epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
509 type(epot_t), intent(inout) :: ep
510 type(namespace_t), intent(in) :: namespace
511 class(mesh_t), target, intent(in) :: mesh
512 type(ions_t), target, intent(inout) :: ions
513 type(states_elec_dim_t), intent(inout) :: st_d
515 type(mpi_grp_t), optional, intent(in) :: kpt_st_grp
516
517 integer :: ia, ispec, paw_nspin
518 logical :: fill
519 type(ps_t), pointer :: ps
520 logical, allocatable :: spec_checked(:)
521
522 call profiling_in("EPOT_GENERATE")
523 push_sub(epot_generate)
524
525 ! Local part
526 ep%vpsl = m_zero
527
528 ! we assume that we need to recalculate the ion-ion energy
529 call ion_interaction_calculate(ions%ion_interaction, ions%space, ions%latt, ions%atom, &
530 ions%natoms, ions%pos, mesh%box%bounding_box_l, ep%eii, ep%fii)
531
532 ! the pseudopotential part.
533 do ia = 1, ions%natoms
534 select type(spec=>ions%atom(ia)%species)
535 type is(pseudopotential_t)
536 call projector_end(ep%proj(ia))
537 call projector_init(ep%proj(ia), spec, namespace, st_d%dim, ep%proj_reltype)
538 ep%requires_generalized_overlap = ep%requires_generalized_overlap .or. spec%requires_generalized_overlap()
539 ep%has_paw = ep%has_paw .or. spec%is_paw()
540 end select
541 end do
542
543 ! With the double grid, the effective support of the transformed projectors
544 ! extends beyond their analytic support by the interpolation-stencil reach.
545 do ia = ions%atoms_dist%start, ions%atoms_dist%end
546 if (ep%proj(ia)%type == proj_none) cycle
547 select type(spec=>ions%atom(ia)%species)
548 type is(pseudopotential_t)
549 ps => spec%ps
550 call submesh_init(ep%proj(ia)%sphere, ions%space, mesh, ions%latt, ions%pos(:, ia), &
551 epot_projector_radius(ep, ps, mesh))
552 end select
553 end do
554
555 if (ions%atoms_dist%parallel) then
556 do ia = 1, ions%natoms
557 if (ep%proj(ia)%type == proj_none) cycle
558 select type(spec=>ions%atom(ia)%species)
559 type is(pseudopotential_t)
560 ps => spec%ps
561 call submesh_broadcast(ep%proj(ia)%sphere, ions%space, mesh, ions%pos(:, ia), &
562 epot_projector_radius(ep, ps, mesh), &
563 ions%atoms_dist%process(ia), ions%atoms_dist%mpi_grp)
564 end select
565 end do
566 end if
567
568 ! Number of spin components of the PAW one-center density matrix
569 paw_nspin = st_d%nspin
570
571 ! Shared per-species augmentation data: built once per species
572 do ia = 1, ions%natoms
573 if (ep%proj(ia)%type /= proj_uspp) cycle
574 select type(spec=>ions%atom(ia)%species)
575 type is(pseudopotential_t)
576 if (spec%is_paw() .and. spec%ps%relativistic_treatment == proj_j_dependent &
577 .and. ep%reltype /= spin_orbit) then
578 message(1) = "Fully-relativistic (j-dependent) PAW datasets require"
579 message(2) = "SpinComponents = spinors and RelativisticCorrection = spin_orbit."
580 call messages_fatal(2, namespace=namespace)
581 end if
582 if (spec%is_paw() .and. ep%reltype == spin_orbit .and. abs(ep%so_strength - m_one) > m_epsilon) then
583 message(1) = "SOStrength /= 1 is not supported for PAW datasets: their spin-orbit splitting is"
584 message(2) = "mostly carried by the j-dependent partial waves, which are not scaled."
585 call messages_fatal(2, namespace=namespace)
586 end if
587 if (ep%reltype == spin_orbit .and. spec%ps%projector_type == proj_uspp &
588 .and. spec%ps%relativistic_treatment /= proj_j_dependent) then
589 message(1) = "Spin-orbit coupling with an ultrasoft/PAW pseudopotential requires a"
590 message(2) = "fully-relativistic (j-dependent) dataset; this one is scalar-relativistic."
591 call messages_fatal(2, namespace=namespace)
592 end if
593 ispec = spec%get_index()
594 if (.not. allocated(ep%aug_species(ispec)%dij)) then
595 safe_allocate(ep%aug_species(ispec)%dij(0:ep%proj(ia)%lmax, 1:spec%ps%kbc, 1:spec%ps%kbc))
596 ep%aug_species(ispec)%dij = spec%ps%h
597 if (allocated(spec%ps%radial_augmentation) .and. spec%is_paw() .and. paw_nspin > 0) then
598 allocate(ep%aug_species(ispec)%paw)
599 call paw_onsite_init(ep%aug_species(ispec)%paw, spec%ps, namespace, paw_kresse_joubert, paw_nspin, &
600 xc_ids=ep%xc_id, usexcnhat=ep%usexcnhat)
601 end if
602 end if
603 end select
604 end do
605
606 ! Atom-level distribution of the per-atom construction work over the kpoint-states
607 ! plane: built once and stored in the epot (the group and the atom count are
608 ! run-constant), then reused here and by the local-potential, core-density and
609 ! stress consumers instead of each creating its own distribution.
610 if (present(kpt_st_grp)) then
611 call distributed_init(ep%atoms_dist_plane, ions%natoms, kpt_st_grp%comm, "atoms_plane")
612 else
613 call distributed_init_serial(ep%atoms_dist_plane, ions%natoms)
614 end if
615
616 do ia = 1, ions%natoms
617 select type(spec=>ions%atom(ia)%species)
618 type is(pseudopotential_t)
619 fill = .true.
620 if (ep%atoms_dist_plane%parallel) then
621 fill = (ep%atoms_dist_plane%process(ia) == ep%atoms_dist_plane%mpi_grp%rank)
622 end if
623 call projector_build(ep%proj(ia), spec, ep%so_strength, ep%dgrid, namespace, paw_nspin, &
624 kpt_st_grp, fill_values = fill, aug_species = ep%aug_species(spec%get_index()))
625 if (.not. projector_is(ep%proj(ia), proj_none)) ep%non_local = .true.
626 end select
627 end do
628
629 if (ep%atoms_dist_plane%parallel) then
630 do ia = 1, ions%natoms
631 select type(spec=>ions%atom(ia)%species)
632 type is(pseudopotential_t)
633 call projector_bcast_fill(ep%proj(ia), ep%atoms_dist_plane%mpi_grp, ep%atoms_dist_plane%process(ia))
634 end select
635 end do
636 end if
637
638 ! Check once, for one atom of each species, that the projectors are properly
639 ! resolved on the grid, to warn about possible spurious (ghost) states
640 if (.not. ep%proj_check_done) then
641 safe_allocate(spec_checked(1:ions%nspecies))
642 spec_checked = .false.
643 do ia = 1, ions%natoms
644 if (ep%proj(ia)%type == proj_none) cycle
645 if (spec_checked(ions%atom(ia)%species%get_index())) cycle
646 select type(spec=>ions%atom(ia)%species)
647 type is(pseudopotential_t)
648 call projector_check_discretization(spec, ep%proj(ia)%sphere, namespace)
649 spec_checked(ions%atom(ia)%species%get_index()) = .true.
650 end select
651 end do
652 safe_deallocate_a(spec_checked)
653 ep%proj_check_done = .true.
654 end if
655
656 pop_sub(epot_generate)
657 call profiling_out("EPOT_GENERATE")
658 end subroutine epot_generate
659
660 ! ---------------------------------------------------------
664 real(real64) function epot_projector_radius(ep, ps, mesh) result(radius)
665 type(epot_t), intent(in) :: ep
666 type(ps_t), intent(in) :: ps
667 class(mesh_t), intent(in) :: mesh
668
669 radius = ps%rc_max
670 if (ep%dgrid%enabled) then
671 if (allocated(ps%radial_augmentation)) radius = max(radius, maxval(ps%radial_augmentation(:, :)%x_threshold))
672 radius = radius + double_grid_margin(ep%dgrid, mesh)
673 end if
674 end function epot_projector_radius
675
676 ! ---------------------------------------------------------
678 subroutine epot_set_shared_paw_xc(ep, functl)
679 type(epot_t), intent(inout) :: ep
680 type(xc_functional_t), pointer, intent(in) :: functl(:)
681
682 integer :: ispec
683
684 push_sub(epot_set_shared_paw_xc)
685
686 if (associated(ep%aug_species)) then
687 do ispec = 1, size(ep%aug_species)
688 if (allocated(ep%aug_species(ispec)%paw)) then
689 call paw_onsite_set_shared_xc(ep%aug_species(ispec)%paw, functl)
690 end if
691 end do
692 end if
693
695 end subroutine epot_set_shared_paw_xc
696
697 ! ---------------------------------------------------------
698
699 logical pure function local_potential_has_density(space, species) result(has_density)
700 class(space_t), intent(in) :: space
701 class(species_t), intent(in) :: species
702
703 has_density = species%has_density .or. (species%is_ps() .and. space%is_periodic())
704
705 end function local_potential_has_density
706
707 ! ---------------------------------------------------------
708 subroutine epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
709 type(epot_t), intent(in) :: ep
710 type(namespace_t), intent(in) :: namespace
711 class(space_t), intent(in) :: space
712 type(lattice_vectors_t), intent(in) :: latt
713 class(mesh_t), intent(in) :: mesh
714 class(species_t), target, intent(in) :: species
715 real(real64), intent(in) :: pos(1:space%dim)
716 integer, intent(in) :: iatom
717 real(real64), contiguous, intent(inout) :: vpsl(:)
718
719 real(real64), allocatable :: vl(:), rho(:)
720 type(submesh_t) :: sphere
721
722 push_sub(epot_local_potential)
723 call profiling_in("EPOT_LOCAL")
724
725 if (ep%local_potential_precalculated) then
726
727 call lalg_axpy(mesh%np, m_one, ep%local_potential(:, iatom), vpsl)
728
729 else
730
731 !Local potential, we can get it by solving the Poisson equation
732 !(for all-electron species or pseudopotentials in periodic
733 !systems) or by applying it directly to the grid
734 safe_allocate(vl(1:mesh%np))
735
736 if (local_potential_has_density(space, species)) then
737 safe_allocate(rho(1:mesh%np))
738
739 call species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere)
740
741 call dpoisson_solve(ep%poisson_solver, namespace, vl, rho, all_nodes = .false.)
742
743 safe_deallocate_a(rho)
744
745 else
746
747 call species_get_local(species, namespace, space, latt, pos, mesh, vl)
748
749 end if
751 call lalg_axpy(mesh%np, m_one, vl, vpsl)
752 safe_deallocate_a(vl)
753
754 !the localized part
755 call species_get_local_sr(species, space, latt, pos, mesh, sphere, vpsl, ep%dgrid)
756 call submesh_end(sphere)
757
758 end if
759
760 call profiling_out("EPOT_LOCAL")
761 pop_sub(epot_local_potential)
762 end subroutine epot_local_potential
763
764 ! ---------------------------------------------------------
765 subroutine epot_precalc_local_potential(ep, namespace, gr, ions)
766 type(epot_t), intent(inout) :: ep
767 type(namespace_t), intent(in) :: namespace
768 type(grid_t), intent(in) :: gr
769 type(ions_t), intent(in) :: ions
770
771 integer :: iatom
772
774
775 if (.not. allocated(ep%local_potential)) then
776 safe_allocate(ep%local_potential(1:gr%np, 1:ions%natoms))
777 end if
778
779 ep%local_potential_precalculated = .false.
781 do iatom = 1, ions%natoms
782 ep%local_potential(1:gr%np, iatom) = m_zero
783 call epot_local_potential(ep, namespace, ions%space, ions%latt, gr, ions%atom(iatom)%species, &
784 ions%pos(:, iatom), iatom, ep%local_potential(1:gr%np, iatom))!, time)
785 end do
786 ep%local_potential_precalculated = .true.
787
789 end subroutine epot_precalc_local_potential
790
791 ! ---------------------------------------------------------
792
793 logical function epot_have_external_potentials(ep)
794 type(epot_t), intent(in) :: ep
795
797
798 epot_have_external_potentials = allocated(ep%e_field)
799
801
803
804end module epot_oct_m
805
806!! Local Variables:
807!! mode: f90
808!! coding: utf-8
809!! 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:737
subroutine, public epot_generate(ep, namespace, mesh, ions, st_d, kpt_st_grp)
Definition: epot.F90:581
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:565
logical function, public epot_have_external_potentials(ep)
Definition: epot.F90:866
logical pure function, public local_potential_has_density(space, species)
Definition: epot.F90:772
integer, parameter, public spin_orbit
Definition: epot.F90:152
integer, parameter, public scalar_relativistic_zora
Definition: epot.F90:152
subroutine, public epot_end(ep)
Definition: epot.F90:514
integer, parameter, public fully_relativistic_zora
Definition: epot.F90:152
subroutine, public epot_set_shared_paw_xc(ep, functl)
Point every PAW one-center engine at the shared xc functional.
Definition: epot.F90:751
subroutine, public epot_init(ep, namespace, gr, ions, psolver, ispin, xc_family, kpoints, xc_id)
Definition: epot.F90:223
subroutine, public epot_precalc_local_potential(ep, namespace, gr, ions)
Definition: epot.F90:838
subroutine, public epot_local_potential(ep, namespace, space, latt, mesh, species, pos, iatom, vpsl)
Definition: epot.F90:781
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, xc_ids, usexcnhat)
Build the per-species one-center data from a (PAW) pseudopotential.
Definition: paw_onsite.F90:340
integer, parameter, public paw_kresse_joubert
PAW formulation: selects the compensation-charge / reference treatment.
Definition: paw_onsite.F90:184
/* 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:697
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
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)