81 integer,
parameter :: MAX_NPROJECTIONS = 4
82 integer,
parameter :: MAX_L = 5
99 integer :: nprojections
100 integer,
public :: lmax
101 integer,
public :: lloc
105 type(submesh_t),
public :: sphere
109 type(double_grid_cache_t),
public :: dg_cache
114 type(hgh_projector_t),
allocatable,
public :: hgh_p(:, :)
115 type(kb_projector_t),
allocatable,
public :: kb_p(:, :)
116 type(rkb_projector_t),
allocatable,
public :: rkb_p(:, :)
117 type(augmentation_t),
public :: aug
118 complex(real64),
allocatable,
public :: phase(:, :, :)
124 logical elemental function projector_is_null(p)
125 type(projector_t),
intent(in) :: p
127 projector_is_null = (p%type ==
proj_none)
131 logical elemental function projector_is(p, type)
132 type(projector_t),
intent(in) :: p
133 integer,
intent(in) :: type
140 logical elemental function projector_has_augmentation(p)
141 type(projector_t),
intent(in) :: p
147 type(projector_t),
intent(inout) :: p
148 type(pseudopotential_t),
target,
intent(in) :: pseudo
149 type(namespace_t),
intent(in) :: namespace
150 integer,
intent(in) :: dim
151 integer,
intent(in) :: reltype
153 type(ps_t),
pointer :: ps
170 p%type = ps%projector_type
174 if (p%type == proj_kb .and. reltype == 1)
then
175 if (ps%relativistic_treatment == proj_j_dependent)
then
178 call messages_write(
"Spin-orbit coupling for species '"//trim(pseudo%get_label())//
" is not available.")
179 call messages_warning(namespace=namespace)
184 if (p%type == proj_uspp .and. reltype /= 1 .and. ps%relativistic_treatment == proj_j_dependent)
then
185 call messages_not_implemented(
"Fully-relativistic ultrasoft/PAW pseudopotential without spin-orbit coupling", &
190 case (proj_kb, proj_rkb, proj_uspp)
191 p%nprojections = ps%kbc
205 integer,
intent(in) :: dim
206 type(states_elec_dim_t),
intent(in) :: std
207 type(boundaries_t),
intent(in) :: bnd
208 type(kpoints_t),
intent(in) :: kpoints
209 real(real64),
optional,
allocatable,
intent(in) :: vec_pot(:)
210 real(real64),
optional,
allocatable,
intent(in) :: vec_pot_var(:, :)
212 integer :: ns, iq, is, ikpoint
213 real(real64) :: kr, kpoint(dim)
214 integer :: nphase, iphase
215 real(real64),
allocatable :: diff(:,:)
221 if (bnd%spiralBC) nphase = 3
223 if (.not.
allocated(this%phase) .and. ns > 0)
then
224 safe_allocate(this%phase(1:ns, 1:nphase, std%kpt%start:std%kpt%end))
231 safe_allocate(diff(1:dim, 1:ns))
235 diff(:, is) = this%sphere%rel_x(:,is) + this%sphere%center - this%sphere%mesh%x(:, this%sphere%map(is))
238 do iq = std%kpt%start, std%kpt%end
239 ikpoint = std%get_kpoint_index(iq)
242 assert(ikpoint <= kpoints_number(kpoints))
245 kpoint(1:dim) = kpoints%get_point(ikpoint)
247 do iphase = 1, nphase
253 kr = sum(kpoint(1:dim)*diff(1:dim, is))
255 if (
present(vec_pot))
then
256 if (
allocated(vec_pot)) kr = kr + sum(vec_pot(1:dim)*diff(1:dim, is))
259 if (
present(vec_pot_var))
then
260 if (
allocated(vec_pot_var)) kr = kr + sum(vec_pot_var(1:dim, this%sphere%map(is)) &
261 *(this%sphere%rel_x(:, is)+this%sphere%center))
264 if (bnd%spiralBC .and. iphase > 1)
then
265 kr = kr + (2*(iphase-1)-3)*sum(bnd%spiral_q(1:dim)*diff(1:dim, is))
268 this%phase(is, iphase, iq) =
exp(-m_zi*kr)
275 safe_deallocate_a(diff)
282 subroutine projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
284 class(pseudopotential_t),
intent(in) :: ps
285 real(real64),
intent(in) :: so_strength
286 type(double_grid_t),
intent(in) :: dgrid
287 type(namespace_t),
intent(in) :: namespace
288 integer,
intent(in) :: nspin
290 type(mpi_grp_t),
optional,
intent(in) :: kpt_st_grp
293 logical,
optional,
intent(in) :: fill_values
294 type(augmentation_species_t),
optional,
target,
intent(in) :: aug_species
296 integer :: ll, mm, ic, ip
301 if (dgrid%enabled .and. p%sphere%np > 0)
then
302 call double_grid_cache_init(p%dg_cache, dgrid, p%sphere)
308 safe_allocate(p%hgh_p(0:p%lmax, -p%lmax:p%lmax))
310 if (ll == p%lloc) cycle
312 call hgh_projector_init(p%hgh_p(ll, mm), p%sphere, p%reltype, ps, ll, mm, so_strength)
316 case (proj_kb, proj_uspp)
317 safe_allocate(p%kb_p(0:p%lmax, -p%lmax:p%lmax))
318 if (p%type == proj_uspp)
then
319 if (
present(aug_species))
then
320 assert(
allocated(aug_species%dij))
321 p%aug%dij => aug_species%dij
322 p%aug%owns_species_data = .false.
324 safe_allocate(p%aug%dij(0:p%lmax, 1:ps%ps%kbc, 1:ps%ps%kbc))
327 safe_allocate(p%aug%qij(0:p%lmax, 1:ps%ps%kbc, 1:ps%ps%kbc))
328 p%aug%qij = ps%ps%qij
329 if (
allocated(ps%ps%radial_augmentation))
then
330 p%aug%qfunc_lmax = ps%ps%radial_augmentation_lmax
331 p%aug%qfunc_nbeta = ps%ps%radial_augmentation_nprojectors
338 if (ps%ps%relativistic_treatment == proj_j_dependent)
then
339 safe_allocate(p%aug%qfunc(1:p%sphere%np, 1:p%aug%qfunc_nbeta*p%aug%qfunc_nbeta, 0:p%aug%qfunc_lmax))
340 do ll = 0, p%aug%qfunc_lmax
341 do ic = 1, p%aug%qfunc_nbeta*p%aug%qfunc_nbeta
342 do ip = 1, p%sphere%np
343 if (p%sphere%r(ip) < spline_range_max(ps%ps%radial_augmentation(ic, ll)))
then
344 p%aug%qfunc(ip, ic, ll) = spline_eval(ps%ps%radial_augmentation(ic, ll), p%sphere%r(ip))
346 p%aug%qfunc(ip, ic, ll) = m_zero
355 if (ps_is_paw(ps%ps) .and. nspin > 0)
then
356 if (
present(aug_species))
then
357 assert(
allocated(aug_species%paw))
358 p%aug%paw => aug_species%paw
361 call paw_onsite_init(p%aug%paw, ps%ps, namespace, paw_kresse_joubert, nspin)
367 if (ll == p%lloc) cycle
369 call kb_projector_init(p%kb_p(ll, mm), p%sphere, ps, ll, mm, dgrid, fill = fill_values)
374 if (p%type == proj_uspp .and. ps%ps%relativistic_treatment == proj_j_dependent)
then
377 assert(.not. dgrid%enabled)
378 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
380 if (ll == p%lloc) cycle
382 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
388 assert(.not. dgrid%enabled)
389 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
391 if (ll == p%lloc) cycle
393 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
397 if (p%lloc /= 0)
then
398 safe_allocate(p%kb_p(1, 1))
399 call kb_projector_init(p%kb_p(1, 1), p%sphere, ps, 0, 0, dgrid)
415 class(pseudopotential_t),
target,
intent(in) :: pseudo
416 type(submesh_t),
intent(in) :: sm
417 type(namespace_t),
intent(in) :: namespace
419 integer :: ll, mm, ic, ir, nc
420 real(real64) :: rc, dr, rr, norm_rad, norm_grid, dev
421 real(real64),
allocatable :: uv(:)
422 type(ps_t),
pointer :: ps
424 integer,
parameter :: quad_points = 2000
426 real(real64),
parameter :: norm_dev_warning = 0.05_real64
433 safe_allocate(uv(1:max(sm%np, 1)))
436 if (ll == ps%llocal) cycle
439 if (ps%projector_type == proj_kb) nc = min(nc, ps%projectors_per_l(ll+1))
443 rc = ps%kb(ll, ic)%x_threshold
444 if (rc <= m_epsilon) cycle
447 do ir = 1, quad_points
448 rr = (ir - m_half)*dr
449 norm_rad = norm_rad + spline_eval(ps%kb(ll, ic), rr)**2 * rr**2
451 norm_rad = norm_rad*dr
452 if (norm_rad <= 1.0e-10_real64) cycle
456 call pseudopotential_real_nl_projector(pseudo, sm%np, sm%rel_x, sm%r, ll, mm, ic, uv)
457 norm_grid = dsm_nrm2(sm, uv)**2
458 dev = max(dev, abs(norm_grid - norm_rad)/norm_rad)
463 safe_deallocate_a(uv)
465 write(message(1),
'(a,es9.2)')
"Debug: projector discretization error for species '" &
466 //trim(pseudo%get_label())//
"' = ", dev
467 call messages_info(1, namespace=namespace, debug_only=.
true.)
469 if (dev > norm_dev_warning)
then
470 write(message(1),
'(a)')
"The nonlocal projectors of species '"//trim(pseudo%get_label())//
"'"
471 write(message(2),
'(a)')
"are not well resolved on the real-space grid: at least one projector norm"
472 write(message(3),
'(a,f8.1,a)')
"deviates by ", dev*100,
"% from its radial-grid value."
473 write(message(4),
'(a)')
"This can produce spurious (ghost) states. Please reduce the grid Spacing."
474 call messages_warning(4, namespace=namespace)
485 type(mpi_grp_t),
intent(in) :: grp
486 integer,
intent(in) :: root
492 if (
allocated(p%kb_p))
then
493 do mm = lbound(p%kb_p, 2), ubound(p%kb_p, 2)
494 do ll = lbound(p%kb_p, 1), ubound(p%kb_p, 1)
495 if (.not.
allocated(p%kb_p(ll, mm)%p)) cycle
496 if (
size(p%kb_p(ll, mm)%p) == 0) cycle
497 call grp%bcast(p%kb_p(ll, mm)%p,
size(p%kb_p(ll, mm)%p), mpi_double_precision, root)
516 class(pseudopotential_t),
intent(in) :: ps
517 type(double_grid_t),
intent(in) :: dgrid
518 type(mpi_grp_t),
optional,
intent(in) :: kpt_st_grp
520 integer,
parameter :: qflm_block = 64
521 integer :: nbeta, lmaxq, ib, jb, ll, ic, ltot, mtot, mi, mj, lm, ncombo, icol, nblk, kk
523 logical :: live, distributed
524 integer,
allocatable :: beta_l(:), beta_c(:), col_pair(:), col_l(:), col_m(:)
525 integer,
allocatable :: llv(:), mmv(:), owned(:)
526 real(real64),
allocatable :: rcut(:), qtmp(:, :)
527 type(spline_t),
allocatable :: spl(:)
528 real(real64) :: qsum, qdev
532 nbeta = p%aug%qfunc_nbeta
533 lmaxq = p%aug%qfunc_lmax
534 assert(nbeta > 0 .and. lmaxq >= 0)
538 safe_allocate(beta_l(1:nbeta))
539 safe_allocate(beta_c(1:nbeta))
542 if (ll == p%lloc) cycle
543 do ic = 1, ps%ps%projectors_per_l(ll + 1)
555 safe_allocate(p%aug%qflm_map(1:nbeta*nbeta, 1:(lmaxq + 1)**2))
557 safe_allocate(col_pair(1:(nbeta*(nbeta + 1))/2*(lmaxq + 1)**2))
558 safe_allocate(col_l(1:
size(col_pair)))
559 safe_allocate(col_m(1:
size(col_pair)))
563 do ltot = abs(beta_l(ib) - beta_l(jb)), min(beta_l(ib) + beta_l(jb), lmaxq)
564 if (mod(beta_l(ib) + beta_l(jb) + ltot, 2) /= 0) cycle
565 do mtot = -ltot, ltot
567 do mi = -beta_l(ib), beta_l(ib)
568 do mj = -beta_l(jb), beta_l(jb)
569 live = live .or. abs(real_gaunt(beta_l(ib), mi, beta_l(jb), mj, ltot, mtot)) > 1.0e-12_real64
572 if (.not. live) cycle
574 col_pair(ncombo) = (ib - 1)*nbeta + jb
577 lm = ltot*(ltot + 1) + mtot + 1
578 p%aug%qflm_map((ib - 1)*nbeta + jb, lm) = ncombo
579 p%aug%qflm_map((jb - 1)*nbeta + ib, lm) = ncombo
584 p%aug%qflm_ncombo = ncombo
587 distributed = .false.
588 if (
present(kpt_st_grp)) distributed = kpt_st_grp%size > 1
590 safe_allocate(owned(1:ncombo))
593 if (distributed)
then
594 if (mod(icol - 1, kpt_st_grp%size) /= kpt_st_grp%rank) cycle
600 safe_allocate(p%aug%qflm(1:p%sphere%np, 1:ncombo))
602 safe_allocate(qtmp(1:p%sphere%np, 1:qflm_block))
603 safe_allocate(spl(1:qflm_block))
604 safe_allocate(llv(1:qflm_block))
605 safe_allocate(mmv(1:qflm_block))
606 safe_allocate(rcut(1:qflm_block))
607 do ib0 = 1, nown, qflm_block
608 nblk = min(qflm_block, nown - ib0 + 1)
610 icol = owned(ib0 + kk - 1)
611 spl(kk) = ps%ps%radial_augmentation(col_pair(icol), col_l(icol))
612 llv(kk) = col_l(icol)
613 mmv(kk) = col_m(icol)
614 rcut(kk) = spline_range_max(spl(kk))
615 if (dgrid%enabled) rcut(kk) = spl(kk)%x_threshold
617 call double_grid_transform(dgrid, p%sphere, nblk, spl, llv, mmv, rcut, &
618 qtmp(:, 1:nblk), cache = p%dg_cache)
620 p%aug%qflm(1:p%sphere%np, owned(ib0 + kk - 1)) = qtmp(1:p%sphere%np, kk)
623 if (distributed .and. p%sphere%np > 0)
then
624 call comm_allreduce(kpt_st_grp, p%aug%qflm)
626 safe_deallocate_a(owned)
627 safe_deallocate_a(qtmp)
628 safe_deallocate_a(spl)
629 safe_deallocate_a(llv)
630 safe_deallocate_a(mmv)
631 safe_deallocate_a(rcut)
639 if (beta_l(ib) /= beta_l(jb)) cycle
640 icol = p%aug%qflm_map((ib - 1)*nbeta + jb, 1)
642 qsum = sum(p%aug%qflm(1:p%sphere%np, icol))*p%sphere%mesh%volume_element
643 if (p%sphere%mesh%parallel_in_domains)
call p%sphere%mesh%allreduce(qsum)
644 qdev = max(qdev, abs(qsum/
sqrt(4.0_real64*m_pi) - ps%ps%qij(beta_l(ib), beta_c(ib), beta_c(jb))))
647 write(message(1),
'(a,es13.4)')
"Debug: double-grid augmentation charge deviation = ", qdev
648 call messages_info(1)
651 safe_deallocate_a(beta_l)
652 safe_deallocate_a(beta_c)
653 safe_deallocate_a(col_pair)
654 safe_deallocate_a(col_l)
655 safe_deallocate_a(col_m)
669 type(projector_matrix_t),
intent(in) :: pmat
670 integer,
intent(in) :: ncomp
671 real(real64),
intent(in) :: pairw(:, :, :)
672 real(real64),
intent(inout) :: wcol(:, :)
674 integer :: iproj, jproj, ltot, mtot, lm, pair_index
675 real(real64) :: coeff, vv(4)
679 assert(
allocated(proj%aug%qflm_map))
680 assert(ncomp >= 1 .and. ncomp <= 4)
681 assert(
size(wcol, 1) >= proj%aug%qflm_ncombo .and.
size(wcol, 2) >= ncomp)
683 do iproj = 1, pmat%nprojs
684 assert(pmat%beta_index(iproj) >= 1 .and. pmat%beta_index(iproj) <= proj%aug%qfunc_nbeta)
685 do jproj = 1, pmat%nprojs
686 vv(1:ncomp) = pairw(iproj, jproj, 1:ncomp)
687 if (sum(abs(vv(1:ncomp))) <= m_epsilon) cycle
688 pair_index = (pmat%beta_index(iproj) - 1)*proj%aug%qfunc_nbeta + pmat%beta_index(jproj)
689 do ltot = 0, proj%aug%qfunc_lmax
690 do mtot = -ltot, ltot
691 coeff = real_gaunt(pmat%l(iproj), pmat%m(iproj), pmat%l(jproj), pmat%m(jproj), ltot, mtot)
692 if (abs(coeff) <= 1.0e-12_real64) cycle
693 lm = ltot*(ltot + 1) + mtot + 1
696 assert(proj%aug%qflm_map(pair_index, lm) > 0)
697 wcol(proj%aug%qflm_map(pair_index, lm), 1:ncomp) = &
698 wcol(proj%aug%qflm_map(pair_index, lm), 1:ncomp) + coeff*vv(1:ncomp)
715 type(projector_matrix_t),
intent(in) :: pmat
716 integer,
intent(in) :: ncomp
717 real(real64),
intent(in) :: wq(:, :)
718 real(real64),
intent(out) :: pairm(:, :, :)
720 integer :: iproj, jproj, ltot, mtot, lm, pair_index
721 real(real64) :: coeff, ssum(4)
725 assert(
allocated(proj%aug%qflm_map))
726 assert(ncomp >= 1 .and. ncomp <= 4)
727 assert(
size(wq, 1) >= proj%aug%qflm_ncombo .and.
size(wq, 2) >= ncomp)
729 do iproj = 1, pmat%nprojs
730 do jproj = 1, pmat%nprojs
731 pair_index = (pmat%beta_index(iproj) - 1)*proj%aug%qfunc_nbeta + pmat%beta_index(jproj)
733 do ltot = 0, proj%aug%qfunc_lmax
734 do mtot = -ltot, ltot
735 coeff = real_gaunt(pmat%l(iproj), pmat%m(iproj), pmat%l(jproj), pmat%m(jproj), ltot, mtot)
736 if (abs(coeff) <= 1.0e-12_real64) cycle
737 lm = ltot*(ltot + 1) + mtot + 1
738 assert(proj%aug%qflm_map(pair_index, lm) > 0)
739 ssum(1:ncomp) = ssum(1:ncomp) + coeff*wq(proj%aug%qflm_map(pair_index, lm), 1:ncomp)
742 pairm(iproj, jproj, 1:ncomp) = ssum(1:ncomp)
757 call double_grid_cache_end(p%dg_cache)
758 call submesh_end(p%sphere)
763 if (ll == p%lloc) cycle
765 call hgh_projector_end(p%hgh_p(ll, mm))
768 safe_deallocate_a(p%hgh_p)
770 case (proj_kb, proj_uspp)
772 if (ll == p%lloc) cycle
774 call kb_projector_end(p%kb_p(ll, mm))
777 safe_deallocate_a(p%kb_p)
778 call augmentation_end(p%aug)
782 if (ll == p%lloc) cycle
784 call rkb_projector_end(p%rkb_p(ll, mm))
787 safe_deallocate_a(p%rkb_p)
788 if (p%lloc /= 0)
then
789 call kb_projector_end(p%kb_p(1, 1))
790 safe_deallocate_a(p%kb_p)
797 safe_deallocate_a(p%phase)
804#include "projector_inc.F90"
807#include "complex.F90"
808#include "projector_inc.F90"
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
This module implements common operations on batches of mesh functions.
Module implementing boundary conditions in Octopus.
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
This module implements the underlying real-space grid.
This module is intended to contain "only mathematical" functions and procedures.
This module defines the meshes, which are used in Octopus.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
real(real64) function, public dprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
dprojector_matrix_element calculates <psia|projector|psib>
subroutine, public dprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
logical elemental function, public projector_is(p, type)
subroutine, public projector_aug_pair_to_columns(proj, pmat, ncomp, pairw, wcol)
Apply the Gaunt coupling between projection pairs and the combined augmentation columns: wcol(col,...
subroutine, public dproject_psi(mesh, bnd, pj, npj, dim, psi, ppsi, ik)
dproject_psi calculates the action of a projector on the psi wavefunction. The result is summed up to...
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
subroutine, public projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
subroutine, public projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
subroutine, public dproject_psi_batch(mesh, bnd, pj, npj, dim, psib, ppsib)
To optimize the application of the non-local operator in parallel, the projectors are applied in step...
complex(real64) function, public zprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
zprojector_matrix_element calculates <psia|projector|psib>
subroutine, public zprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
subroutine, public projector_end(p)
subroutine, public projector_bcast_fill(p, grp, root)
Broadcast the projector values built by the owning rank of an atom-distributed projector build.
subroutine projector_build_aug_qflm(p, ps, dgrid, kpt_st_grp)
Build the effective (double-grid transformed) ultrasoft augmentation.
logical elemental function, public projector_has_augmentation(p)
Whether the projector carries an augmentation contribution (charge augmentation Q_ij and a generalize...
subroutine, public zproject_psi(mesh, bnd, pj, npj, dim, psi, ppsi, ik)
zproject_psi calculates the action of a projector on the psi wavefunction. The result is summed up to...
subroutine, public zproject_psi_batch(mesh, bnd, pj, npj, dim, psib, ppsib)
To optimize the application of the non-local operator in parallel, the projectors are applied in step...
subroutine, public projector_check_discretization(pseudo, sm, namespace)
Check how well the nonlocal projectors are resolved on the real-space grid.
subroutine, public dprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
subroutine, public zprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
subroutine, public projector_aug_columns_to_pairs(proj, pmat, ncomp, wq, pairm)
Contract combined-column values back to the projection-pair matrix: pairm(i, j, c) = sum_{(i,...
logical elemental function, public projector_is_null(p)
integer, parameter, public proj_none
This module handles spin dimensions of the states and the k-point distribution.
The projector data type is intended to hold the local and non-local parts of the pseudopotentials....