Octopus
projector.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 projector_oct_m
22 use accel_oct_m
24 use batch_oct_m
27 use comm_oct_m
28 use debug_oct_m
30 use global_oct_m
31 use grid_oct_m
33 use ions_oct_m
36 use math_oct_m
37 use mesh_oct_m
39 use mpi_oct_m
44 use ps_oct_m
45 use pseudo_oct_m
53
54 implicit none
55
56 private
57 public :: &
80
81 integer, parameter :: MAX_NPROJECTIONS = 4
82 integer, parameter :: MAX_L = 5
83
95
96 type projector_t
97 private
98 integer, public :: type = proj_none
99 integer :: nprojections
100 integer, public :: lmax
101 integer, public :: lloc
102 integer :: nik
103 integer :: reltype
104
105 type(submesh_t), public :: sphere
106
109 type(double_grid_cache_t), public :: dg_cache
110
111
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(:, :, :)
119 end type projector_t
120
121contains
122
123 !---------------------------------------------------------
124 logical elemental function projector_is_null(p)
125 type(projector_t), intent(in) :: p
126
127 projector_is_null = (p%type == proj_none)
128 end function projector_is_null
129
130 !---------------------------------------------------------
131 logical elemental function projector_is(p, type)
132 type(projector_t), intent(in) :: p
133 integer, intent(in) :: type
134 projector_is = (p%type == type)
135 end function projector_is
136
137 !---------------------------------------------------------
140 logical elemental function projector_has_augmentation(p)
141 type(projector_t), intent(in) :: p
142 projector_has_augmentation = (p%type == proj_uspp)
143 end function projector_has_augmentation
144
145 !---------------------------------------------------------
146 subroutine projector_init(p, pseudo, namespace, dim, reltype)
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
152
153 type(ps_t), pointer :: ps
155 push_sub(projector_init)
156
157 ps => pseudo%ps
158
159 p%reltype = reltype
160 p%lmax = ps%lmax
161
162 if (ps%local) then
163 p%type = proj_none
164 pop_sub(projector_init)
165 return
166 end if
167
168 p%lloc = ps%llocal
169
170 p%type = ps%projector_type
172 ! reltype is epot_oct_m::proj_reltype, which is either NOREL (0) or SPIN_ORBIT (1);
173 ! the named constants cannot be used here, as epot_oct_m already uses this module.
174 if (p%type == proj_kb .and. reltype == 1) then
175 if (ps%relativistic_treatment == proj_j_dependent) then
176 p%type = proj_rkb
177 else
178 call messages_write("Spin-orbit coupling for species '"//trim(pseudo%get_label())//" is not available.")
179 call messages_warning(namespace=namespace)
180 end if
181 end if
182
183 ! Without SOC, the j-dependent ultrasoft channels would need to be j-averaged.
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", &
186 namespace=namespace)
187 end if
189 select case (p%type)
190 case (proj_kb, proj_rkb, proj_uspp)
191 p%nprojections = ps%kbc
192 case (proj_hgh)
193 p%nprojections = 3
194 case default
195 assert(.false.)
196 end select
197
198 pop_sub(projector_init)
199 end subroutine projector_init
200
201 !---------------------------------------------
202
203 subroutine projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
204 type(projector_t), intent(inout) :: this
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(:, :)
211
212 integer :: ns, iq, is, ikpoint
213 real(real64) :: kr, kpoint(dim)
214 integer :: nphase, iphase
215 real(real64), allocatable :: diff(:,:)
216
217 push_sub(projector_init_phases)
219 ns = this%sphere%np
220 nphase = 1
221 if (bnd%spiralBC) nphase = 3
222
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))
225 end if
226
227 ! Construct vectors which translate the submesh point back into the unit cell:
228 ! The positions this%sphere%x can lie outside the unit cell, while
229 ! this%sphere%mesh%x(this%sphere%map(is), 1:ndim) by construction is the periodic image inside the unit cell.
230 ! If a point of the submesh is inside the unit cell, diff(:,is) = 0.
231 safe_allocate(diff(1:dim, 1:ns))
232 !$omp parallel private(ikpoint, kpoint, iphase, is, kr, iq)
233 !$omp do
234 do is = 1, ns
235 diff(:, is) = this%sphere%rel_x(:,is) + this%sphere%center - this%sphere%mesh%x(:, this%sphere%map(is))
236 end do
237
238 do iq = std%kpt%start, std%kpt%end
239 ikpoint = std%get_kpoint_index(iq)
240
241 ! if this fails, it probably means that sb is not compatible with std
242 assert(ikpoint <= kpoints_number(kpoints))
243
244 kpoint = m_zero
245 kpoint(1:dim) = kpoints%get_point(ikpoint)
246
247 do iphase = 1, nphase
248 !$omp do
249 do is = 1, ns
250 ! this is only the correction to the global phase, that can
251 ! appear if the sphere crossed the boundary of the cell. (diff=0 otherwise)
252
253 kr = sum(kpoint(1:dim)*diff(1:dim, is))
254
255 if (present(vec_pot)) then
256 if (allocated(vec_pot)) kr = kr + sum(vec_pot(1:dim)*diff(1:dim, is))
257 end if
258
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))
262 end if
263
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))
266 end if
267
268 this%phase(is, iphase, iq) = exp(-m_zi*kr)
269 end do
270 !$omp end do nowait
271 end do
272 end do
273 !$omp end parallel
274
275 safe_deallocate_a(diff)
276
277 pop_sub(projector_init_phases)
278
279 end subroutine projector_init_phases
280
281 !---------------------------------------------------------
282 subroutine projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
283 type(projector_t), intent(inout) :: p
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
295
296 integer :: ll, mm, ic, ip
297
298 push_sub_with_profile(projector_build)
299
300 ! Build the double-grid geometry cache once for this sphere
301 if (dgrid%enabled .and. p%sphere%np > 0) then
302 call double_grid_cache_init(p%dg_cache, dgrid, p%sphere)
303 end if
304
305 select case (p%type)
306
307 case (proj_hgh)
308 safe_allocate(p%hgh_p(0:p%lmax, -p%lmax:p%lmax))
309 do ll = 0, p%lmax
310 if (ll == p%lloc) cycle
311 do mm = -ll, ll
312 call hgh_projector_init(p%hgh_p(ll, mm), p%sphere, p%reltype, ps, ll, mm, so_strength)
313 end do
314 end do
315
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.
323 else
324 safe_allocate(p%aug%dij(0:p%lmax, 1:ps%ps%kbc, 1:ps%ps%kbc))
325 p%aug%dij = ps%ps%h
326 end if
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
332 ! The augmentation is always stored as combined Q_ij^L(r) Y_LM columns:
333 ! with the double grid these are the effective (transformed) functions,
334 ! without it the plain product evaluated at the sphere points
335 call projector_build_aug_qflm(p, ps, dgrid, kpt_st_grp)
336 ! Only the spin-orbit (j-dependent) screening still uses the factored
337 ! radial x angular representation (complex recoupling).
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))
345 else
346 p%aug%qfunc(ip, ic, ll) = m_zero
347 end if
348 end do
349 end do
350 end do
351 end if
352 ! PAW one-center ("on-site") radial engine, built from the dataset. Geometry-independent;
353 ! it feeds the D^1 - D~1 + DeltaK coupling and the one-center energy correction that
354 ! update_dij / energy_calc_total apply each SCF step.
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
359 else
360 allocate(p%aug%paw)
361 call paw_onsite_init(p%aug%paw, ps%ps, namespace, paw_kresse_joubert, nspin)
362 end if
363 end if
364 end if
365 end if
366 do ll = 0, p%lmax
367 if (ll == p%lloc) cycle
368 do mm = -ll, ll
369 call kb_projector_init(p%kb_p(ll, mm), p%sphere, ps, ll, mm, dgrid, fill = fill_values)
370 end do
371 end do
372
373 ! Fully-relativistic (spin-orbit) ultrasoft
374 if (p%type == proj_uspp .and. ps%ps%relativistic_treatment == proj_j_dependent) then
375 ! The rkb projectors are built from complex spherical harmonics, which
376 ! the double grid does not handle yet (fenced at input parsing).
377 assert(.not. dgrid%enabled)
378 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
379 do ll = 1, p%lmax
380 if (ll == p%lloc) cycle
381 do mm = -ll, ll
382 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
383 end do
384 end do
385 end if
386
387 case (proj_rkb)
388 assert(.not. dgrid%enabled)
389 safe_allocate(p%rkb_p(1:p%lmax, -p%lmax:p%lmax))
390 do ll = 1, p%lmax
391 if (ll == p%lloc) cycle
392 do mm = -ll, ll
393 call rkb_projector_init(p%rkb_p(ll, mm), p%sphere, ps, ll, mm, so_strength)
394 end do
395 end do
396 ! for rkb, l = 0 is a normal kb
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)
400 end if
401
402 end select
403
404 pop_sub_with_profile(projector_build)
405 end subroutine projector_build
406
407 !---------------------------------------------------------
414 subroutine projector_check_discretization(pseudo, sm, namespace)
415 class(pseudopotential_t), target, intent(in) :: pseudo
416 type(submesh_t), intent(in) :: sm
417 type(namespace_t), intent(in) :: namespace
418
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
423
424 integer, parameter :: quad_points = 2000
426 real(real64), parameter :: norm_dev_warning = 0.05_real64
427
429
430 ps => pseudo%ps
431
432 dev = m_zero
433 safe_allocate(uv(1:max(sm%np, 1)))
434
435 do ll = 0, ps%lmax
436 if (ll == ps%llocal) cycle
437
438 nc = ps%kbc
439 if (ps%projector_type == proj_kb) nc = min(nc, ps%projectors_per_l(ll+1))
440
441 do ic = 1, nc
442 ! Norm^2 of the projector on the radial grid
443 rc = ps%kb(ll, ic)%x_threshold
444 if (rc <= m_epsilon) cycle
445 dr = rc/quad_points
446 norm_rad = m_zero
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
450 end do
451 norm_rad = norm_rad*dr
452 if (norm_rad <= 1.0e-10_real64) cycle
453
454 ! Norm^2 of the same projector discretized on the grid, for all values of m
455 do mm = -ll, ll
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)
459 end do
460 end do
461 end do
462
463 safe_deallocate_a(uv)
464
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.)
468
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)
475 end if
476
478 end subroutine projector_check_discretization
479
480 !---------------------------------------------------------
483 subroutine projector_bcast_fill(p, grp, root)
484 type(projector_t), intent(inout) :: p
485 type(mpi_grp_t), intent(in) :: grp
486 integer, intent(in) :: root
487
488 integer :: ll, mm
489
490 push_sub(projector_bcast_fill)
491
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)
498 end do
499 end do
500 end if
501
502 pop_sub(projector_bcast_fill)
503 end subroutine projector_bcast_fill
504
505 !---------------------------------------------------------
514 subroutine projector_build_aug_qflm(p, ps, dgrid, kpt_st_grp)
515 type(projector_t), intent(inout) :: p
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
519
520 integer, parameter :: qflm_block = 64
521 integer :: nbeta, lmaxq, ib, jb, ll, ic, ltot, mtot, mi, mj, lm, ncombo, icol, nblk, kk
522 integer :: nown, ib0
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
529
531
532 nbeta = p%aug%qfunc_nbeta
533 lmaxq = p%aug%qfunc_lmax
534 assert(nbeta > 0 .and. lmaxq >= 0)
535
536 ! l and channel of each beta in the global per-l-block ordering (the same
537 ! ordering as ps%radial_augmentation pair columns and pmat%beta_index).
538 safe_allocate(beta_l(1:nbeta))
539 safe_allocate(beta_c(1:nbeta))
540 ib = 0
541 do ll = 0, p%lmax
542 if (ll == p%lloc) cycle
543 do ic = 1, ps%ps%projectors_per_l(ll + 1)
544 ib = ib + 1
545 beta_l(ib) = ll
546 beta_c(ib) = ic
547 end do
548 end do
549 assert(ib == nbeta)
550
551 ! Enumerate the Gaunt-live combined columns: L restricted by triangle rule
552 ! and parity, (L, M) kept if any (m_i, m_j) pair carries a nonzero real
553 ! Gaunt coefficient (superset of every per-projection coefficient used by
554 ! the consumers).
555 safe_allocate(p%aug%qflm_map(1:nbeta*nbeta, 1:(lmaxq + 1)**2))
556 p%aug%qflm_map = 0
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)))
560 ncombo = 0
561 do ib = 1, nbeta
562 do jb = ib, nbeta
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
566 live = .false.
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
570 end do
571 end do
572 if (.not. live) cycle
573 ncombo = ncombo + 1
574 col_pair(ncombo) = (ib - 1)*nbeta + jb
575 col_l(ncombo) = ltot
576 col_m(ncombo) = mtot
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
580 end do
581 end do
582 end do
583 end do
584 p%aug%qflm_ncombo = ncombo
585
586 ! Transform in blocks to bound the kernel scratch memory
587 distributed = .false.
588 if (present(kpt_st_grp)) distributed = kpt_st_grp%size > 1
589
590 safe_allocate(owned(1:ncombo))
591 nown = 0
592 do icol = 1, ncombo
593 if (distributed) then
594 if (mod(icol - 1, kpt_st_grp%size) /= kpt_st_grp%rank) cycle
595 end if
596 nown = nown + 1
597 owned(nown) = icol
598 end do
599
600 safe_allocate(p%aug%qflm(1:p%sphere%np, 1:ncombo))
601 p%aug%qflm = m_zero
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)
609 do kk = 1, nblk
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
616 end do
617 call double_grid_transform(dgrid, p%sphere, nblk, spl, llv, mmv, rcut, &
618 qtmp(:, 1:nblk), cache = p%dg_cache)
619 do kk = 1, nblk
620 p%aug%qflm(1:p%sphere%np, owned(ib0 + kk - 1)) = qtmp(1:p%sphere%np, kk)
621 end do
622 end do
623 if (distributed .and. p%sphere%np > 0) then
624 call comm_allreduce(kpt_st_grp, p%aug%qflm)
625 end if
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)
632
633 ! Sum rule: the L = 0 columns of same-l pairs must integrate on the grid to
634 ! sqrt(4 pi) q_ij (the file overlap charges); report the worst deviation.
635 if (debug%info) then
636 qdev = m_zero
637 do ib = 1, nbeta
638 do jb = ib, nbeta
639 if (beta_l(ib) /= beta_l(jb)) cycle
640 icol = p%aug%qflm_map((ib - 1)*nbeta + jb, 1)
641 if (icol == 0) cycle
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))))
645 end do
646 end do
647 write(message(1), '(a,es13.4)') "Debug: double-grid augmentation charge deviation = ", qdev
648 call messages_info(1)
649 end if
650
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)
656
658 end subroutine projector_build_aug_qflm
659
660 !---------------------------------------------------------
667 subroutine projector_aug_pair_to_columns(proj, pmat, ncomp, pairw, wcol)
668 type(projector_t), intent(in) :: proj
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(:, :)
673
674 integer :: iproj, jproj, ltot, mtot, lm, pair_index
675 real(real64) :: coeff, vv(4)
676
678
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)
682
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
694 ! A nonzero Gaunt coefficient implies the column exists: the map
695 ! enumeration scans all (m_i, m_j) under the same selection rules.
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)
699 end do
700 end do
701 end do
702 end do
703
705 end subroutine projector_aug_pair_to_columns
706
707 !---------------------------------------------------------
713 subroutine projector_aug_columns_to_pairs(proj, pmat, ncomp, wq, pairm)
714 type(projector_t), intent(in) :: proj
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(:, :, :)
719
720 integer :: iproj, jproj, ltot, mtot, lm, pair_index
721 real(real64) :: coeff, ssum(4)
722
724
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)
728
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)
732 ssum = m_zero
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)
740 end do
741 end do
742 pairm(iproj, jproj, 1:ncomp) = ssum(1:ncomp)
743 end do
744 end do
745
747 end subroutine projector_aug_columns_to_pairs
748
749 !---------------------------------------------------------
750 subroutine projector_end(p)
751 type(projector_t), intent(inout) :: p
752
753 integer :: ll, mm
754
755 push_sub(projector_end)
756
757 call double_grid_cache_end(p%dg_cache)
758 call submesh_end(p%sphere)
759
760 select case (p%type)
761 case (proj_hgh)
762 do ll = 0, p%lmax
763 if (ll == p%lloc) cycle
764 do mm = -ll, ll
765 call hgh_projector_end(p%hgh_p(ll, mm))
766 end do
767 end do
768 safe_deallocate_a(p%hgh_p)
769
770 case (proj_kb, proj_uspp)
771 do ll = 0, p%lmax
772 if (ll == p%lloc) cycle
773 do mm = -ll, ll
774 call kb_projector_end(p%kb_p(ll, mm))
775 end do
776 end do
777 safe_deallocate_a(p%kb_p)
778 call augmentation_end(p%aug)
779
780 case (proj_rkb)
781 do ll = 1, p%lmax
782 if (ll == p%lloc) cycle
783 do mm = -ll, ll
784 call rkb_projector_end(p%rkb_p(ll, mm))
785 end do
786 end do
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)
791 end if
792
793 end select
794
795 p%type = proj_none
796
797 safe_deallocate_a(p%phase)
798
799 pop_sub(projector_end)
800 end subroutine projector_end
801
802#include "undef.F90"
803#include "real.F90"
804#include "projector_inc.F90"
805
806#include "undef.F90"
807#include "complex.F90"
808#include "projector_inc.F90"
809
810end module projector_oct_m
811
812
813
814!! Local Variables:
815!! mode: f90
816!! coding: utf-8
817!! End:
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:112
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:95
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:101
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.
Definition: grid.F90:96
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
PAW radial engine.
Definition: paw_onsite.F90:131
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
real(real64) function, public dprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
dprojector_matrix_element calculates <psia|projector|psib>
Definition: projector.F90:1277
subroutine, public dprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1396
logical elemental function, public projector_is(p, type)
Definition: projector.F90:204
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,...
Definition: projector.F90:740
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...
Definition: projector.F90:945
subroutine, public projector_init(p, pseudo, namespace, dim, reltype)
Definition: projector.F90:219
subroutine, public projector_init_phases(this, dim, std, bnd, kpoints, vec_pot, vec_pot_var)
Definition: projector.F90:276
subroutine, public projector_build(p, ps, so_strength, dgrid, namespace, nspin, kpt_st_grp, fill_values, aug_species)
Definition: projector.F90:355
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...
Definition: projector.F90:980
complex(real64) function, public zprojector_matrix_element(pj, bnd, dim, ik, psia, psib)
zprojector_matrix_element calculates <psia|projector|psib>
Definition: projector.F90:1985
subroutine, public zprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:2189
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 projector_build_aug_qflm(p, ps, dgrid, kpt_st_grp)
Build the effective (double-grid transformed) ultrasoft augmentation.
Definition: projector.F90:587
logical elemental function, public projector_has_augmentation(p)
Whether the projector carries an augmentation contribution (charge augmentation Q_ij and a generalize...
Definition: projector.F90:213
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...
Definition: projector.F90:1653
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...
Definition: projector.F90:1688
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
subroutine, public dprojector_commute_r_allatoms_alldir(pj, ions, mesh, dim, bnd, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:1481
subroutine, public zprojector_commute_r(pj, mesh, bnd, dim, idir, ik, psi, cpsi)
This function calculates |cpsi> += [x, V_nl] |psi>
Definition: projector.F90:2104
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,...
Definition: projector.F90:786
logical elemental function, public projector_is_null(p)
Definition: projector.F90:197
Definition: ps.F90:93
integer, parameter, public proj_none
Definition: ps.F90:151
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....
Definition: projector.F90:168
int true(void)