65 use,
intrinsic :: iso_fortran_env
77#ifdef HAVE_LIBXC_FUNCS
108 integer,
parameter :: PAW_KRESSE_JOUBERT = 1
109 integer,
parameter :: PAW_BLOCHL = 2
112 integer,
parameter :: &
113 PAW_XC_SCHEME_FULL = 1, & !< exact evaluation on the radial x angular grid
121 integer :: spin_channels = 1
124 real(real64) :: rc =
m_zero
126 real(real64),
allocatable :: r(:)
127 real(real64),
allocatable :: r2(:)
128 real(real64),
allocatable :: invr(:)
131 real(real64),
allocatable :: wr(:)
132 real(real64),
allocatable :: vwr(:)
136 integer,
allocatable :: lrad(:)
137 real(real64),
allocatable :: phi_ae(:,:)
138 real(real64),
allocatable :: phi_ps(:,:)
139 integer,
allocatable :: rad_2j(:)
140 logical :: has_small = .false.
141 real(real64),
allocatable :: phi_ae_small(:,:)
145 integer,
allocatable :: p_rad(:)
146 integer,
allocatable :: p_l(:)
147 integer,
allocatable :: p_m(:)
151 real(real64),
allocatable :: qaug(:,:,:)
158 real(real64),
allocatable :: pair_ae(:,:)
159 real(real64),
allocatable :: pair_ps(:,:)
161 integer,
allocatable :: gnt_pair(:)
162 integer,
allocatable :: gnt_l(:)
163 integer,
allocatable :: gnt_lm(:)
164 real(real64),
allocatable :: gnt_c(:)
165 integer,
allocatable :: gnt_ptr(:)
172 real(real64),
allocatable :: dpair_ae(:,:)
173 real(real64),
allocatable :: dpair_ps(:,:)
174 real(real64),
allocatable :: dqaug(:,:,:)
175 real(real64),
allocatable :: nc_ae_der(:)
176 real(real64),
allocatable :: nc_ps_der(:)
185 integer :: der_nw = 5
186 real(real64),
allocatable :: der_w(:,:)
187 integer,
allocatable :: der_i0(:)
188 integer :: der_ntw = 0
189 real(real64),
allocatable :: der_wt(:,:)
190 integer,
allocatable :: der_trow0(:)
191 integer,
allocatable :: der_tn(:)
194 logical :: has_ae_core = .false.
195 logical :: has_ps_core = .false.
196 real(real64),
allocatable :: nc_ae(:)
197 real(real64),
allocatable :: nc_ps(:)
198 real(real64),
allocatable :: vref_ae(:)
199 real(real64),
allocatable :: vref_ps(:)
202 real(real64),
allocatable :: kin_ae(:,:)
203 real(real64),
allocatable :: kin_ps(:,:)
207 integer :: lmax_rho = 0
208 integer :: nlm_rho = 0
209 real(real64),
allocatable :: wang(:)
210 real(real64),
allocatable :: ylm(:,:)
211 real(real64),
allocatable :: dylm_dth(:,:)
212 real(real64),
allocatable :: dylm_dph(:,:)
213 real(real64),
allocatable :: wylm(:,:)
214 real(real64),
allocatable :: wdylm_dth(:,:)
215 real(real64),
allocatable :: wdylm_dph(:,:)
219 real(real64),
allocatable :: rhat(:,:)
220 real(real64),
allocatable :: that(:,:)
221 real(real64),
allocatable :: phat(:,:)
224 integer :: formulation = paw_kresse_joubert
227 logical :: xc_is_gga = .false.
242 type(
ps_t),
intent(in) :: ps
244 integer,
intent(in) :: formulation
245 integer,
intent(in) :: nspin
247 integer :: nr, nr_full, i, j, k, maxl, ilm, ll, mm, pair
248 integer,
allocatable :: cpos(:)
249 real(real64),
allocatable :: r_full(:), phi_ae_full(:,:), phi_ps_full(:,:), work(:), dwork(:)
250 real(real64),
allocatable :: phi_ae_small_full(:,:)
251 real(real64),
allocatable :: qaug_full(:,:,:)
256 assert(formulation == paw_kresse_joubert .or. formulation == paw_blochl)
258 this%formulation = formulation
260 this%spin_channels = min(nspin, 2)
292 message(1) =
"PAWXCScheme = paw_xc_moments needs the second and third derivatives (fxc and kxc)"
293 message(2) =
"of the exchange-correlation functional of the PAW dataset, which this functional"
294 message(3) =
"or this LibXC library does not provide. Use PAWXCScheme = paw_xc_full instead."
297 message(1) =
"Info: the exchange-correlation functional of the PAW dataset has no fxc/kxc in this"
298 message(2) =
" LibXC library: using PAWXCScheme = paw_xc_full."
300 this%xc_scheme = paw_xc_scheme_full
308 nr_full =
size(ps%paw_grid)
309 safe_allocate(r_full(1:nr_full))
310 r_full(1:nr_full) = ps%paw_grid(1:nr_full)
311 this%rc = ps%paw_cutoff_radius
315 if (r_full(k) > this%rc*(
m_one + 1.0e-6_real64))
exit
320 safe_allocate(this%r(1:nr))
321 safe_allocate(this%r2(1:nr))
322 safe_allocate(this%wr(1:nr))
323 safe_allocate(this%vwr(1:nr))
324 this%r(1:nr) = r_full(1:nr)
325 this%r2(1:nr) = this%r(1:nr)**2
326 this%wr(1:nr) = ps%paw_rab(1:nr)
327 this%vwr(1:nr) = this%r2(1:nr)*this%wr(1:nr)
330 safe_allocate(this%invr(1:nr))
332 if (this%r(k) >
m_zero)
then
333 this%invr(k) =
m_one/this%r(k)
343 this%nrad = ps%paw_nwavefunctions
344 this%npair = (this%nrad*(this%nrad + 1))/2
345 safe_allocate(this%lrad(1:this%nrad))
346 this%lrad(1:this%nrad) = ps%paw_l(1:this%nrad)
347 safe_allocate(this%rad_2j(1:this%nrad))
349 if (
allocated(ps%paw_2j)) this%rad_2j(1:this%nrad) = ps%paw_2j(1:this%nrad)
350 safe_allocate(phi_ae_full(1:nr_full, 1:this%nrad))
351 safe_allocate(phi_ps_full(1:nr_full, 1:this%nrad))
354 phi_ae_full(k, i) =
spline_eval(ps%paw_phi_ae(i), r_full(k))
355 phi_ps_full(k, i) =
spline_eval(ps%paw_phi_ps(i), r_full(k))
358 safe_allocate(this%phi_ae(1:nr, 1:this%nrad))
359 safe_allocate(this%phi_ps(1:nr, 1:this%nrad))
360 this%phi_ae(1:nr, :) = phi_ae_full(1:nr, :)
361 this%phi_ps(1:nr, :) = phi_ps_full(1:nr, :)
364 this%has_small = ps%paw_has_small
365 if (this%has_small)
then
366 safe_allocate(phi_ae_small_full(1:nr_full, 1:this%nrad))
369 phi_ae_small_full(k, i) =
spline_eval(ps%paw_phi_ae_small(i), r_full(k))
372 safe_allocate(this%phi_ae_small(1:nr, 1:this%nrad))
373 this%phi_ae_small(1:nr, :) = phi_ae_small_full(1:nr, :)
376 maxl = maxval(this%lrad(1:this%nrad))
377 this%lmax_rho = 2*maxl
380 if (this%lmax_rho > 6)
then
387 this%nlm = this%nlm + 2*this%lrad(i) + 1
389 safe_allocate(this%p_rad(1:this%nlm))
390 safe_allocate(this%p_l(1:this%nlm))
391 safe_allocate(this%p_m(1:this%nlm))
394 do mm = -this%lrad(i), this%lrad(i)
397 this%p_l(ilm) = this%lrad(i)
401 assert(ilm == this%nlm)
403 this%nlm_rho = (this%lmax_rho + 1)**2
413 assert(ps%radial_augmentation_nprojectors == this%nrad)
415 assert(this%lrad(i) >= this%lrad(i-1))
417 safe_allocate(cpos(1:this%nrad))
421 if (this%lrad(j) == this%lrad(i)) pair = pair + 1
424 if (this%rad_2j(i) > 0 .and. this%lrad(i) > 0)
then
425 if (this%rad_2j(i) == 2*this%lrad(i) - 1)
then
426 cpos(i) = (pair - 1)/2*2 + 2
428 cpos(i) = (pair - 1)/2*2 + 1
431 cpos(i) = i - pair + cpos(i)
434 this%laug = ps%radial_augmentation_lmax
435 assert(this%laug >= 0)
436 safe_allocate(qaug_full(1:nr_full, 1:this%npair, 0:this%laug))
442 qaug_full(k, pair, ll) =
spline_eval(ps%radial_augmentation((cpos(i)-1)*this%nrad + cpos(j), ll), r_full(k))
447 safe_allocate(this%qaug(1:nr, 1:this%npair, 0:this%laug))
448 this%qaug(1:nr, :, :) = qaug_full(1:nr, :, :)
449 safe_deallocate_a(cpos)
452 this%has_ae_core = ps%paw_has_ae_core
454 safe_allocate(this%nc_ae(1:nr))
455 safe_allocate(this%nc_ps(1:nr))
456 safe_allocate(this%vref_ae(1:nr))
457 safe_allocate(this%vref_ps(1:nr))
461 if (this%has_ae_core) this%nc_ae(k) =
spline_eval(ps%paw_ae_core, this%r(k))
462 if (this%has_ps_core) this%nc_ps(k) =
spline_eval(ps%core, this%r(k))
463 this%vref_ae(k) =
spline_eval(ps%paw_ae_vlocal, this%r(k))
468 if (this%xc_is_gga)
then
469 safe_allocate(work(1:nr_full))
470 safe_allocate(dwork(1:nr_full))
471 safe_allocate(this%dpair_ae(1:nr, 1:this%npair))
472 safe_allocate(this%dpair_ps(1:nr, 1:this%npair))
473 safe_allocate(this%dqaug(1:nr, 1:this%npair, 0:this%laug))
477 work(:) = phi_ae_full(:, i)*phi_ae_full(:, j)
479 if (this%has_small) work(:) = work(:) + phi_ae_small_full(:, i)*phi_ae_small_full(:, j)
481 this%dpair_ae(1:nr, pair) = dwork(1:nr)
482 work(:) = phi_ps_full(:, i)*phi_ps_full(:, j)
484 this%dpair_ps(1:nr, pair) = dwork(1:nr)
487 this%dqaug(1:nr, pair, ll) = dwork(1:nr)
492 safe_allocate(this%nc_ae_der(1:nr))
493 safe_allocate(this%nc_ps_der(1:nr))
496 if (this%has_ae_core)
then
501 this%nc_ae_der(1:nr) = dwork(1:nr)
503 if (this%has_ps_core)
then
508 this%nc_ps_der(1:nr) = dwork(1:nr)
510 safe_deallocate_a(work)
511 safe_deallocate_a(dwork)
523 safe_deallocate_a(r_full)
524 safe_deallocate_a(phi_ae_full)
525 safe_deallocate_a(phi_ae_small_full)
526 safe_deallocate_a(phi_ps_full)
527 safe_deallocate_a(qaug_full)
537 integer,
intent(in) :: ri, rj
553 integer :: i, j, ri, rj, li, mi, lj, mj, ll, mm, pair, ig, ij, np, ipass
559 assert(this%npair == (this%nrad*(this%nrad + 1))/2)
560 safe_allocate(this%pair_ae(1:np, 1:this%npair))
561 safe_allocate(this%pair_ps(1:np, 1:this%npair))
565 this%pair_ae(:, pair) = this%phi_ae(:, i)*this%phi_ae(:, j)
566 this%pair_ps(:, pair) = this%phi_ps(:, i)*this%phi_ps(:, j)
569 if (this%has_small)
then
570 this%pair_ae(:, pair) = this%pair_ae(:, pair) + this%phi_ae_small(:, i)*this%phi_ae_small(:, j)
576 safe_allocate(this%gnt_ptr(1:this%nlm*this%nlm + 1))
588 ij = (i-1)*this%nlm + j
589 if (ipass == 2) this%gnt_ptr(ij) = ig + 1
590 do ll = abs(li-lj), min(li+lj, this%lmax_rho), 2
592 c = real_gaunt(li, mi, lj, mj, ll, mm)
596 this%gnt_pair(ig) = pair
598 this%gnt_lm(ig) = ll*(ll+1) + mm + 1
607 safe_allocate(this%gnt_pair(1:this%ngnt))
608 safe_allocate(this%gnt_l(1:this%ngnt))
609 safe_allocate(this%gnt_lm(1:this%ngnt))
610 safe_allocate(this%gnt_c(1:this%ngnt))
612 this%gnt_ptr(this%nlm*this%nlm + 1) = ig + 1
613 assert(ig == this%ngnt)
624 type(ps_t),
intent(in) :: ps
625 type(namespace_t),
intent(in) :: namespace
627 integer :: ixc, ids(2)
633 if (ps%exchange_functional == pseudo_exchange_unknown .or. &
634 ps%correlation_functional == pseudo_correlation_unknown)
then
635 message(1) =
"PAW one-center engine: the exchange-correlation functional of the PAW dataset"
636 message(2) =
"could not be identified. Only LDA and GGA functionals are supported."
637 call messages_fatal(2, namespace=namespace)
640 ids(1) = ps%exchange_functional
641 ids(2) = ps%correlation_functional
643 this%xc_is_gga = .false.
646 if (ids(ixc) > 0)
then
647 call xc_functional_init(this%xc_functl(ixc), namespace, ids(ixc), 3, ps%z_val, this%spin_channels, .
true.)
649 call xc_functional_init(this%xc_functl(ixc), namespace, 0, 3, ps%z_val, this%spin_channels, .
true.)
652 select case (this%xc_functl(ixc)%family)
653 case (xc_family_none, xc_family_lda)
656 this%xc_is_gga = .
true.
657 case (xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga)
658 call messages_not_implemented(
"PAW one-center engine with hybrid functionals", namespace=namespace)
660 call messages_not_implemented(
"PAW one-center engine with this XC functional family " // &
661 "(only LDA and GGA are supported)", namespace=namespace)
680 if (this%xc_functl(ixc)%family == xc_family_none) cycle
681 if (bitand(this%xc_functl(ixc)%flags, xc_flags_have_fxc) == 0) has_kernels = .false.
682 if (bitand(this%xc_functl(ixc)%flags, xc_flags_have_kxc) == 0) has_kernels = .false.
699 real(real64),
intent(in) :: r_full(:)
700 real(real64),
intent(in) :: phi_ae_full(:,:)
701 real(real64),
intent(in) :: phi_ps_full(:,:)
703 integer :: i, j, k, nr, ll
704 real(real64),
allocatable :: uae(:,:), ups(:,:), duae(:,:), dups(:,:)
705 real(real64) :: kae, kps, cent
709 safe_allocate(uae(1:
size(r_full), 1:this%nrad))
710 safe_allocate(ups(1:
size(r_full), 1:this%nrad))
711 safe_allocate(duae(1:
size(r_full), 1:this%nrad))
712 safe_allocate(dups(1:
size(r_full), 1:this%nrad))
715 uae(:, i) = r_full(:) * phi_ae_full(:, i)
716 ups(:, i) = r_full(:) * phi_ps_full(:, i)
722 safe_allocate(this%kin_ae(1:this%nrad, 1:this%nrad))
723 safe_allocate(this%kin_ps(1:this%nrad, 1:this%nrad))
728 if (this%lrad(i) /= this%lrad(j)) cycle
730 cent = real(ll*(ll+1), real64)
738 kae = kae + (duae(k,i)*duae(k,j) + cent*uae(k,i)*uae(k,j)/this%r2(k)) * this%wr(k)
739 kps = kps + (dups(k,i)*dups(k,j) + cent*ups(k,i)*ups(k,j)/this%r2(k)) * this%wr(k)
741 this%kin_ae(i, j) = m_half*kae
742 this%kin_ps(i, j) = m_half*kps
746 safe_deallocate_a(uae)
747 safe_deallocate_a(ups)
748 safe_deallocate_a(duae)
749 safe_deallocate_a(dups)
757 real(real64),
intent(in) :: r(:)
758 real(real64),
intent(in) ::
f(:)
759 real(real64),
intent(out) :: df(:)
762 type(spline_t) :: sp, dsp
768 call spline_init(dsp)
769 call spline_fit(n, r,
f, sp)
770 call spline_der(sp, dsp, m_zero)
772 df(k) = spline_eval(dsp, r(k))
789 integer :: ip, i0, nw, jj, kk
790 integer,
allocatable :: first(:), last(:)
795 assert(this%nr >= nw)
796 safe_allocate(this%der_w(1:nw, 1:this%nr))
797 safe_allocate(this%der_i0(1:this%nr))
799 i0 = min(max(ip - (nw-1)/2, 1), this%nr - nw + 1)
804 safe_allocate(first(1:this%nr))
805 safe_allocate(last(1:this%nr))
810 jj = this%der_i0(ip) + kk - 1
811 first(jj) = min(first(jj), ip)
812 last(jj) = max(last(jj), ip)
815 this%der_ntw = maxval(last - first + 1)
816 safe_allocate(this%der_wt(1:this%der_ntw, 1:this%nr))
817 safe_allocate(this%der_trow0(1:this%nr))
818 safe_allocate(this%der_tn(1:this%nr))
820 this%der_trow0(1:this%nr) = first(1:this%nr)
821 this%der_tn(1:this%nr) = last(1:this%nr) - first(1:this%nr) + 1
824 jj = this%der_i0(ip) + kk - 1
825 this%der_wt(ip - first(jj) + 1, jj) = this%der_w(kk, ip)
828 safe_deallocate_a(first)
829 safe_deallocate_a(last)
838 real(real64),
intent(in) :: z
839 real(real64),
intent(in) :: x(:)
840 integer,
intent(in) :: n
841 real(real64),
intent(out) :: w(:)
843 integer :: i, j, k, mn
844 real(real64) :: c1, c2, c3, c4, c5
845 real(real64) :: c(n, 0:1)
863 c(i, k) = c1*(real(k, real64)*c(i-1, k-1) - c5*c(i-1, k))/c2
865 c(i, 0) = -c1*c5*c(i-1, 0)/c2
868 c(j, k) = (c4*c(j, k) - real(k, real64)*c(j, k-1))/c3
870 c(j, 0) = c4*c(j, 0)/c3
883 real(real64),
intent(in) :: f(:)
884 real(real64),
intent(out) :: df(:)
894 do k = 1, this%der_nw
895 acc = acc + this%der_w(k, ip)*f(i0 + k - 1)
910 real(real64),
intent(in) :: f(:)
911 real(real64),
intent(out) :: df(:)
919 i0 = this%der_trow0(ip)
921 do k = 1, this%der_tn(ip)
922 acc = acc + this%der_wt(k, ip)*f(i0 + k - 1)
935 integer :: nth, nphi, ith, iphi, ia, ll, mm, lm
936 real(real64),
allocatable :: gx(:), gw(:)
937 real(real64) :: dphi, phi, sinth, costh, xx(3), y, dyth, dyph
943 nth = this%lmax_rho + 6
944 nphi = 2*this%lmax_rho + 3
946 assert(this%nlm_rho == (this%lmax_rho + 1)**2)
948 safe_allocate(gx(1:nth))
949 safe_allocate(gw(1:nth))
950 call gauss_legendre_newton(nth, gx, gw)
952 safe_allocate(this%wang(1:this%nang))
953 safe_allocate(this%ylm(1:this%nang, 1:this%nlm_rho))
957 safe_allocate(this%dylm_dth(1:this%nang, 1:this%nlm_rho))
958 safe_allocate(this%dylm_dph(1:this%nang, 1:this%nlm_rho))
959 safe_allocate(this%rhat(1:this%nang, 1:3))
960 safe_allocate(this%that(1:this%nang, 1:3))
961 safe_allocate(this%phat(1:this%nang, 1:3))
963 dphi = m_two*m_pi/real(nphi, real64)
967 sinth =
sqrt(max(m_one - costh**2, m_zero))
970 phi = (real(iphi, real64) - m_half)*dphi
971 xx(1) = sinth*
cos(phi)
972 xx(2) = sinth*
sin(phi)
975 this%rhat(ia, 1:3) = xx(1:3)
976 this%that(ia, 1) = costh*
cos(phi)
977 this%that(ia, 2) = costh*
sin(phi)
978 this%that(ia, 3) = -sinth
979 this%phat(ia, 1) = -
sin(phi)
980 this%phat(ia, 2) =
cos(phi)
981 this%phat(ia, 3) = m_zero
982 this%wang(ia) = gw(ith)*dphi
983 do ll = 0, this%lmax_rho
985 lm = ll*(ll+1) + mm + 1
987 call ylmr_real_with_grad(xx, ll, mm, y, dyth, dyph)
989 this%dylm_dth(ia, lm) = dyth
990 this%dylm_dph(ia, lm) = dyph
995 assert(ia == this%nang)
999 safe_allocate(this%wylm(1:this%nang, 1:this%nlm_rho))
1000 safe_allocate(this%wdylm_dth(1:this%nang, 1:this%nlm_rho))
1001 safe_allocate(this%wdylm_dph(1:this%nang, 1:this%nlm_rho))
1002 do lm = 1, this%nlm_rho
1003 do ia = 1, this%nang
1004 this%wylm(ia, lm) = this%wang(ia)*this%ylm(ia, lm)
1005 this%wdylm_dth(ia, lm) = this%wang(ia)*this%dylm_dth(ia, lm)
1006 this%wdylm_dph(ia, lm) = this%wang(ia)*this%dylm_dph(ia, lm)
1010 safe_deallocate_a(gx)
1011 safe_deallocate_a(gw)
1024 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
1025 real(real64),
intent(out) :: e1
1026 real(real64),
intent(out) :: e1t
1027 real(real64),
contiguous,
intent(out) :: dij(:,:,:)
1030 logical,
optional,
intent(in) :: hxc_only
1032 real(real64) :: e_ae, e_ps, kae, kps
1033 real(real64),
allocatable :: d_ae(:,:,:), d_ps(:,:,:)
1035 logical :: hxc_only_
1039 hxc_only_ = optional_default(hxc_only, .false.)
1041 safe_allocate(d_ae(1:this%nlm, 1:this%nlm, 1:this%nspin))
1042 safe_allocate(d_ps(1:this%nlm, 1:this%nlm, 1:this%nspin))
1051 dij(:, :, :) = d_ae(:, :, :) - d_ps(:, :, :)
1056 if (.not. hxc_only_)
then
1057 do is = 1, this%spin_channels
1060 if (this%p_l(i) /= this%p_l(j) .or. this%p_m(i) /= this%p_m(j)) cycle
1061 kae = this%kin_ae(this%p_rad(i), this%p_rad(j))
1062 kps = this%kin_ps(this%p_rad(i), this%p_rad(j))
1063 dij(i, j, is) = dij(i, j, is) + kae - kps
1064 e1 = e1 + rho(i, j, is)*kae
1065 e1t = e1t + rho(i, j, is)*kps
1071 safe_deallocate_a(d_ae)
1072 safe_deallocate_a(d_ps)
1083 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
1084 logical,
intent(in) :: ae
1085 real(real64),
intent(out) :: energy
1086 real(real64),
contiguous,
intent(out) :: dij(:,:,:)
1089 logical,
optional,
intent(in) :: hxc_only
1091 integer :: nr, nlmr, lm, k, is
1092 logical :: xc_with_comp, hxc_only_, need_der
1093 real(real64),
allocatable :: nlm_rho(:,:,:)
1094 real(real64),
allocatable :: nlm_xc(:,:,:)
1095 real(real64),
allocatable :: nlm_xc_der(:,:,:)
1096 real(real64),
allocatable :: nlm_tot(:,:)
1097 real(real64),
allocatable :: vlm(:,:)
1098 real(real64),
allocatable :: vref(:), ncore(:)
1099 real(real64) :: e_h, e_ref, e_xc, sqrt4pi
1105 sqrt4pi =
sqrt(m_four*m_pi)
1106 hxc_only_ = optional_default(hxc_only, .false.)
1112 safe_allocate(nlm_rho(1:nr, 1:nlmr, 1:this%nspin))
1113 safe_allocate(nlm_xc(1:nr, 1:nlmr, 1:this%nspin))
1114 safe_allocate(nlm_tot(1:nr, 1:nlmr))
1115 safe_allocate(vlm(1:nr, 1:nlmr))
1116 safe_allocate(vref(1:nr))
1117 safe_allocate(ncore(1:nr))
1121 vref(:) = this%vref_ae(:)
1122 ncore(:) = this%nc_ae(:)/this%spin_channels
1124 vref(:) = this%vref_ps(:)
1125 ncore(:) = this%nc_ps(:)/this%spin_channels
1133 safe_allocate(nlm_xc_der(1:nr, 1:nlmr, 1:this%nspin))
1135 do is = 1, this%nspin
1138 call paw_build_density(this, rho(:,:,is), ae, xc_with_comp, nlm_xc(:,:,is), nlm_xc_der(:,:,is))
1139 else if (xc_with_comp .eqv. (.not. ae))
then
1140 nlm_xc(:,:,is) = nlm_rho(:,:,is)
1146 nlm_tot = nlm_rho(:,:,1)
1147 do is = 2, this%spin_channels
1148 nlm_tot = nlm_tot + nlm_rho(:,:,is)
1156 e_h = e_h + m_half*nlm_tot(k, lm)*vlm(k, lm)*this%vwr(k)
1165 if (.not. hxc_only_)
then
1167 e_ref = e_ref + sqrt4pi*vref(k)*nlm_tot(k, 1)*this%vwr(k)
1170 call lalg_axpy(nr, sqrt4pi, vref, vlm(:, 1))
1175 do is = 1, this%spin_channels
1181 call paw_xc_moments(this, nlm_xc, ncore, ae, xc_with_comp, e_xc, dij)
1183 call paw_xc(this, nlm_xc, nlm_xc_der, ncore, ae, xc_with_comp, e_xc, dij)
1186 energy = e_h + e_ref + e_xc
1188 safe_deallocate_a(nlm_rho)
1189 safe_deallocate_a(nlm_xc)
1190 safe_deallocate_a(nlm_xc_der)
1191 safe_deallocate_a(nlm_tot)
1192 safe_deallocate_a(vlm)
1193 safe_deallocate_a(vref)
1194 safe_deallocate_a(ncore)
1212 real(real64),
contiguous,
intent(in) :: rho(:,:)
1213 logical,
intent(in) :: ae
1214 logical,
intent(in) :: with_comp
1215 real(real64),
contiguous,
intent(out) :: nlm_rho(:,:)
1216 real(real64),
contiguous,
optional,
intent(out) :: nlm_der(:,:)
1218 integer :: i, j, ij, ig
1219 real(real64) :: rho_ij
1220 real(real64),
allocatable :: cmat(:,:)
1224 assert(.not.
present(nlm_der) .or. this%xc_is_gga)
1229 safe_allocate(cmat(1:this%npair, 1:this%nlm_rho))
1234 if (j > i) rho_ij = rho_ij + rho(j, i)
1235 if (abs(rho_ij) <= m_epsilon) cycle
1236 ij = (i-1)*this%nlm + j
1237 do ig = this%gnt_ptr(ij), this%gnt_ptr(ij+1) - 1
1238 cmat(this%gnt_pair(ig), this%gnt_lm(ig)) = cmat(this%gnt_pair(ig), this%gnt_lm(ig)) &
1239 + rho_ij*this%gnt_c(ig)
1245 call lalg_gemm(this%pair_ae, cmat, nlm_rho)
1246 if (
present(nlm_der))
call lalg_gemm(this%dpair_ae, cmat, nlm_der)
1248 call lalg_gemm(this%pair_ps, cmat, nlm_rho)
1249 if (
present(nlm_der))
call lalg_gemm(this%dpair_ps, cmat, nlm_der)
1252 if (
present(nlm_der))
call paw_qaug_gemv(this, this%dqaug,
'N', cmat, nlm_der)
1256 safe_deallocate_a(cmat)
1268 real(real64),
contiguous,
intent(in) :: qtab(:, :, 0:)
1269 character(1),
intent(in) :: trans
1270 real(real64),
contiguous,
intent(in) :: xx(:, :)
1271 real(real64),
contiguous,
intent(inout) :: yy(:, :)
1277 do lm = 1, this%nlm_rho
1278 ll = int(
sqrt(real(lm-1, real64)))
1279 if (ll > this%laug) cycle
1280 call blas_gemv(trans, this%nr, this%npair, m_one, qtab(1, 1, ll), this%nr, &
1281 xx(1, lm), 1, m_one, yy(1, lm), 1)
1291 real(real64),
contiguous,
intent(in) :: w(:, :)
1292 real(real64),
contiguous,
intent(inout) :: dij(:, :)
1294 integer :: i, j, ij, ig
1301 ij = (i-1)*this%nlm + j
1303 do ig = this%gnt_ptr(ij), this%gnt_ptr(ij+1) - 1
1304 acc = acc + this%gnt_c(ig)*w(this%gnt_pair(ig), this%gnt_lm(ig))
1306 dij(i, j) = dij(i, j) + acc
1307 if (j > i) dij(j, i) = dij(j, i) + acc
1318 real(real64),
contiguous,
intent(in) :: field_lm(:, :)
1319 real(real64),
intent(in) :: tol
1320 integer,
intent(out) :: ncol
1321 type(spline_t),
allocatable,
intent(out) :: spl(:)
1322 integer,
allocatable,
intent(out) :: ll(:)
1323 integer,
allocatable,
intent(out) :: mm(:)
1324 real(real64),
intent(out) :: rcut
1330 safe_allocate(spl(1:this%nlm_rho))
1331 safe_allocate(ll(1:this%nlm_rho))
1332 safe_allocate(mm(1:this%nlm_rho))
1334 do lm = 1, this%nlm_rho
1335 if (maxval(abs(field_lm(:, lm))) <= tol) cycle
1337 l0 = int(
sqrt(real(lm-1, real64)))
1339 mm(ncol) = lm - l0*(l0+1) - 1
1340 call spline_init(spl(ncol))
1341 call spline_fit(this%nr, this%r, field_lm(:, lm), spl(ncol))
1343 rcut = this%r(this%nr)
1353 real(real64),
contiguous,
intent(out) :: dphi_ae(:, :)
1354 real(real64),
contiguous,
intent(out) :: dphi_ps(:, :)
1375 real(real64),
contiguous,
intent(in) :: flux(:)
1376 real(real64),
contiguous,
intent(inout) :: div(:)
1377 real(real64),
contiguous,
intent(inout) :: vfield(:)
1385 if (this%vwr(ip) > m_zero)
then
1386 vfield(ip) = vfield(ip) + div(ip)/this%vwr(ip)
1395 integer,
intent(in) :: nprojs
1396 integer,
intent(in) :: map(:)
1397 real(real64),
contiguous,
intent(in) :: src(:, :)
1398 real(real64),
contiguous,
intent(out) :: dst(:, :)
1400 integer :: iproj, jproj
1404 do jproj = 1, nprojs
1405 do iproj = 1, nprojs
1406 dst(map(iproj), map(jproj)) = src(iproj, jproj)
1418 integer,
intent(in) :: lm
1419 real(real64),
intent(in) :: nl(:)
1420 real(real64),
intent(out) :: vl(:)
1422 integer :: k, nr, ll
1423 real(real64) :: pref, inner, outer, ti, to
1424 real(real64),
allocatable :: cum_in(:)
1429 ll = int(
sqrt(real(lm-1, real64)))
1430 pref = m_four*m_pi/real(2*ll+1, real64)
1432 safe_allocate(cum_in(1:nr))
1436 ti = nl(k)*this%r(k)**(ll+2)*this%wr(k)
1438 cum_in(k) = inner - m_half*ti
1444 if (this%r(k) > m_zero)
then
1445 to = nl(k)*this%r(k)**(1-ll)*this%wr(k)
1450 if (this%r(k) > m_zero)
then
1451 vl(k) = pref*( cum_in(k)/this%r(k)**(ll+1) + (outer - m_half*to)*this%r(k)**ll )
1455 if (this%r(1) <= m_zero) vl(1) = vl(2)
1457 safe_deallocate_a(cum_in)
1479 subroutine paw_xc(this, nlm_rho, nlm_der, ncore, ae, with_comp, e_xc, dij)
1481 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
1483 real(real64),
optional,
contiguous,
intent(in) :: nlm_der(:,:,:)
1484 real(real64),
contiguous,
intent(in) :: ncore(:)
1485 logical,
intent(in) :: ae
1486 logical,
intent(in) :: with_comp
1487 real(real64),
intent(out) :: e_xc
1488 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
1491 integer :: np, npa, ibase, ip, ia, is, nsp, nsig
1492 real(real64) :: ntot
1493 real(real64),
allocatable :: ncder(:)
1497 real(real64),
allocatable :: dens(:,:)
1498 real(real64),
allocatable :: densp(:,:)
1499 real(real64),
allocatable :: sigma(:,:)
1500 real(real64),
allocatable :: dpol(:)
1501 real(real64),
allocatable :: exc(:), vs(:,:)
1502 real(real64),
allocatable,
target :: vr(:,:)
1503 real(real64),
allocatable :: g(:,:,:,:)
1504 real(real64),
allocatable :: gp(:,:,:,:)
1505 real(real64),
allocatable :: vxc_lm(:,:,:)
1506 real(real64),
pointer :: vmat(:,:)
1508 push_sub_with_profile(
paw_xc)
1510 gga = this%xc_is_gga
1513 nsp = this%spin_channels
1516 safe_allocate(dens(1:npa, 1:this%nspin))
1517 safe_allocate(densp(1:npa, 1:nsp))
1518 safe_allocate(sigma(1:npa, 1:nsig))
1519 safe_allocate(exc(1:npa))
1520 safe_allocate(vr(1:npa, 1:this%nspin))
1521 safe_allocate(vs(1:npa, 1:nsig))
1524 safe_allocate(dpol(1:npa))
1528 assert(
present(nlm_der))
1529 safe_allocate(ncder(1:np))
1531 ncder(:) = this%nc_ae_der(:)/this%spin_channels
1533 ncder(:) = this%nc_ps_der(:)/this%spin_channels
1535 safe_allocate(g(1:np, 1:this%nspin, 1:this%nang, 1:3))
1536 safe_allocate(gp(1:np, 1:nsp, 1:this%nang, 1:3))
1542 call paw_xc_eval(this, npa, nsp, nsig, densp, sigma, exc, vr(:, 1:nsp), vs)
1547 do ia = 1, this%nang
1552 ntot = ntot + max(densp(ibase + ip, is), m_zero)
1554 e_xc = e_xc + ntot*exc(ibase + ip)*this%vwr(ip)*this%wang(ia)
1566 safe_allocate(vxc_lm(1:np, 1:this%nlm_rho, 1:this%nspin))
1567 do is = 1, this%nspin
1568 vmat(1:np, 1:this%nang) => vr(:, is)
1569 call lalg_gemm(np, this%nlm_rho, this%nang, m_one, vmat, this%wylm, m_zero, vxc_lm(:, :, is))
1571 do is = 1, this%nspin
1576 safe_deallocate_a(dens)
1577 safe_deallocate_a(densp)
1578 safe_deallocate_a(sigma)
1579 safe_deallocate_a(dpol)
1580 safe_deallocate_a(exc)
1581 safe_deallocate_a(vr)
1582 safe_deallocate_a(vs)
1583 safe_deallocate_a(ncder)
1584 safe_deallocate_a(g)
1585 safe_deallocate_a(gp)
1586 safe_deallocate_a(vxc_lm)
1588 pop_sub_with_profile(
paw_xc)
1595 subroutine paw_xc_density(this, nlm_rho, ncore, dens, densp, dpol)
1597 real(real64),
intent(in) :: nlm_rho(:,:,:)
1598 real(real64),
intent(in) :: ncore(:)
1599 real(real64),
contiguous,
intent(out) :: dens(:,:)
1600 real(real64),
contiguous,
intent(out) :: densp(:,:)
1601 real(real64),
contiguous,
intent(out) :: dpol(:)
1603 integer :: np, ibase, ip, ia, ic
1611 do ia = 1, this%nang
1613 do ic = 1, this%nspin
1616 dens(ibase + ip, ic) = ncore(ip)
1620 dens(ibase + ip, ic) = m_zero
1623 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
1624 this%ylm(ia, 1), this%nang, m_one, dens(ibase + 1, ic), 1)
1628 if (this%nspin == 4)
then
1630 do ip = 1, np*this%nang
1632 densp(ip, 1) = m_half*(dens(ip, 1) + dens(ip, 2) + dpol(ip))
1633 densp(ip, 2) = m_half*(dens(ip, 1) + dens(ip, 2) - dpol(ip))
1636 do ic = 1, this%spin_channels
1637 call lalg_copy(np*this%nang, dens(:, ic), densp(:, ic))
1654 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
1655 real(real64),
contiguous,
intent(in) :: nlm_der(:,:,:)
1656 real(real64),
contiguous,
intent(in) :: ncder(:)
1657 real(real64),
contiguous,
intent(out) :: g(:,:,:,:)
1659 integer :: np, ip, ia, ic
1665 do ia = 1, this%nang
1666 do ic = 1, this%nspin
1669 g(ip, ic, ia, 1) = ncder(ip)
1673 g(ip, ic, ia, 1) = m_zero
1676 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_der(1, 1, ic), np, &
1677 this%ylm(ia, 1), this%nang, m_one, g(1, ic, ia, 1), 1)
1678 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
1679 this%dylm_dth(ia, 1), this%nang, m_zero, g(1, ic, ia, 2), 1)
1680 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
1681 this%dylm_dph(ia, 1), this%nang, m_zero, g(1, ic, ia, 3), 1)
1683 g(ip, ic, ia, 2) = g(ip, ic, ia, 2)*this%invr(ip)
1684 g(ip, ic, ia, 3) = g(ip, ic, ia, 3)*this%invr(ip)
1696 subroutine paw_xc_sigma(this, dens, dpol, g, gp, sigma)
1698 real(real64),
contiguous,
intent(in) :: dens(:,:)
1699 real(real64),
contiguous,
intent(in) :: dpol(:)
1700 real(real64),
contiguous,
intent(in) :: g(:,:,:,:)
1701 real(real64),
contiguous,
intent(out) :: gp(:,:,:,:)
1702 real(real64),
contiguous,
intent(out) :: sigma(:,:)
1704 integer :: np, ibase, ip, ia, k
1705 real(real64) :: uu, gq
1711 if (this%nspin == 4)
then
1713 do ia = 1, this%nang
1716 uu = dens(ibase + ip, 1) - dens(ibase + ip, 2)
1718 if (dpol(ibase + ip) > m_zero)
then
1719 gq = (uu*(g(ip, 1, ia, k) - g(ip, 2, ia, k)) &
1720 + m_four*(dens(ibase + ip, 3)*g(ip, 3, ia, k) &
1721 + dens(ibase + ip, 4)*g(ip, 4, ia, k)))/dpol(ibase + ip)
1725 gp(ip, 1, ia, k) = m_half*(g(ip, 1, ia, k) + g(ip, 2, ia, k) + gq)
1726 gp(ip, 2, ia, k) = m_half*(g(ip, 1, ia, k) + g(ip, 2, ia, k) - gq)
1731 gp(:, :, :, :) = g(:, :, :, :)
1735 do ia = 1, this%nang
1738 sigma(ibase + ip, 1) = gp(ip,1,ia,1)**2 + gp(ip,1,ia,2)**2 + gp(ip,1,ia,3)**2
1739 if (this%spin_channels == 2)
then
1740 sigma(ibase + ip, 2) = gp(ip,1,ia,1)*gp(ip,2,ia,1) + gp(ip,1,ia,2)*gp(ip,2,ia,2) &
1741 + gp(ip,1,ia,3)*gp(ip,2,ia,3)
1742 sigma(ibase + ip, 3) = gp(ip,2,ia,1)**2 + gp(ip,2,ia,2)**2 + gp(ip,2,ia,3)**2
1754 real(real64),
contiguous,
intent(in) :: dens(:,:)
1755 real(real64),
contiguous,
intent(inout) :: vr(:,:)
1758 real(real64) :: dpol, fwp(4, 2), v1, v2
1760 if (this%nspin /= 4)
return
1765 do ip = 1, this%nr*this%nang
1770 vr(ip, ic) = fwp(ic, 1)*v1 + fwp(ic, 2)*v2
1781 logical,
intent(in) :: ae
1782 logical,
intent(in) :: with_comp
1783 real(real64),
contiguous,
intent(in) :: dens(:,:)
1784 real(real64),
contiguous,
intent(in) :: g(:,:,:,:), gp(:,:,:,:)
1785 real(real64),
contiguous,
intent(in) :: vr(:,:), vs(:,:)
1786 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
1788 integer :: np, ibase, ip, ia, is, os, iss
1789 real(real64),
allocatable :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
1793 if (this%nspin == 4)
then
1800 safe_allocate(a1(1:np, 1:this%nang, 1:this%nspin))
1801 safe_allocate(a2(1:np, 1:this%nang, 1:this%nspin))
1802 safe_allocate(a3(1:np, 1:this%nang, 1:this%nspin))
1803 safe_allocate(a4(1:np, 1:this%nang, 1:this%nspin))
1806 do is = 1, this%nspin
1808 do ia = 1, this%nang
1810 os = min(this%nspin, 3 - is)
1812 if (this%nspin == 1)
then
1814 a1(ip, ia, 1) = vr(ibase + ip, 1)
1815 a2(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 1)
1816 a3(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 2)
1817 a4(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 3)
1821 a1(ip, ia, is) = vr(ibase + ip, is)
1822 a2(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 1) + vs(ibase + ip, 2)*gp(ip, os, ia, 1)
1823 a3(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 2) + vs(ibase + ip, 2)*gp(ip, os, ia, 2)
1824 a4(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 3) + vs(ibase + ip, 2)*gp(ip, os, ia, 3)
1833 safe_deallocate_a(a1)
1834 safe_deallocate_a(a2)
1835 safe_deallocate_a(a3)
1836 safe_deallocate_a(a4)
1845 subroutine paw_xc_eval(this, np, nsp, nsig, dens, sigma, exc, vrho, vsigma)
1847 integer,
intent(in) :: np, nsp, nsig
1848 real(real64),
contiguous,
intent(in) :: dens(:,:)
1849 real(real64),
contiguous,
intent(in) :: sigma(:,:)
1850 real(real64),
contiguous,
intent(out) :: exc(:)
1851 real(real64),
contiguous,
intent(out) :: vrho(:,:)
1852 real(real64),
contiguous,
intent(out) :: vsigma(:,:)
1854 integer,
parameter :: block_size = 4096
1855 integer :: ib, nblock
1859 nblock = (np + block_size - 1)/block_size
1863 call paw_xc_eval_block(this, np, (ib - 1)*block_size, min(block_size, np - (ib - 1)*block_size), &
1864 nsp, nsig, dens, sigma, exc, vrho, vsigma)
1872 subroutine paw_xc_eval_block(this, np, ip0, bs, nsp, nsig, dens, sigma, exc, vrho, vsigma)
1874 integer,
intent(in) :: np, ip0, bs, nsp, nsig
1875 real(real64),
contiguous,
intent(in) :: dens(:,:)
1876 real(real64),
contiguous,
intent(in) :: sigma(:,:)
1877 real(real64),
contiguous,
intent(out) :: exc(:)
1878 real(real64),
contiguous,
intent(out) :: vrho(:,:)
1879 real(real64),
contiguous,
intent(out) :: vsigma(:,:)
1881 integer :: ixc, ip, is
1882 real(real64) :: ntot
1883 real(real64) :: dclamp(nsp, bs), ssig(nsig, bs)
1884 real(real64) :: eb(bs), vb(nsp, bs), vsb(nsig, bs)
1885 real(real64) :: ez(bs), vz(nsp, bs), vsz(nsig, bs)
1891 dclamp(is, ip) = max(dens(ip0 + ip, is), m_zero)
1894 if (this%xc_is_gga)
then
1897 ssig(is, ip) = sigma(ip0 + ip, is)
1908 select case (this%xc_functl(ixc)%family)
1909 case (xc_family_none)
1911 case (xc_family_lda)
1912 call xc_f03_lda_exc_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ez, vz)
1913 case (xc_family_gga)
1914 call xc_f03_gga_exc_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ssig, &
1917 message(1) =
"PAW one-center engine: unsupported XC functional family."
1918 call messages_fatal(1)
1923 eb(ip) = eb(ip) + ez(ip)
1925 vb(is, ip) = vb(is, ip) + vz(is, ip)
1928 if (this%xc_functl(ixc)%family == xc_family_gga)
then
1931 vsb(is, ip) = vsb(is, ip) + vsz(is, ip)
1946 if (dens(ip0 + ip, is) < m_zero) vb(is, ip) = m_zero
1947 ntot = ntot + dclamp(is, ip)
1949 if (ntot < m_epsilon)
then
1954 exc(ip0 + ip) = eb(ip)
1956 vrho(ip0 + ip, is) = vb(is, ip)
1959 vsigma(ip0 + ip, is) = vsb(is, ip)
1975 integer,
intent(in) :: nsp, nsig
1976 real(real64),
contiguous,
intent(in) :: n0(:,:)
1977 real(real64),
contiguous,
intent(in) :: sigma0(:,:)
1978 real(real64),
contiguous,
intent(in) :: dn0(:,:)
1979 real(real64),
contiguous,
intent(out) :: exc0(:)
1980 real(real64),
contiguous,
intent(out) :: vsph(:,:)
1982 integer :: ip, is, os, iss
1983 real(real64),
allocatable :: vs(:,:), flux(:), div(:)
1987 safe_allocate(vs(1:this%nr, 1:nsig))
1988 call paw_xc_eval(this, this%nr, nsp, nsig, n0, sigma0, exc0, vsph, vs)
1990 if (this%xc_is_gga)
then
1991 safe_allocate(flux(1:this%nr))
1992 safe_allocate(div(1:this%nr))
1994 os = min(nsp, 3 - is)
1998 flux(ip) = (m_two*vs(ip, iss)*dn0(ip, is) + vs(ip, 2)*dn0(ip, os))*this%vwr(ip)
2002 flux(ip) = m_two*vs(ip, iss)*dn0(ip, is)*this%vwr(ip)
2007 safe_deallocate_a(flux)
2008 safe_deallocate_a(div)
2011 safe_deallocate_a(vs)
2025 subroutine paw_xc_kernels(this, nsp, nsig, n0, sigma0, dn0, kk, k2)
2027 integer,
intent(in) :: nsp, nsig
2028 real(real64),
contiguous,
intent(in) :: n0(:,:)
2029 real(real64),
contiguous,
intent(in) :: sigma0(:,:)
2030 real(real64),
contiguous,
intent(in) :: dn0(:,:)
2031 real(real64),
contiguous,
intent(out) :: kk(:,:,:)
2032 real(real64),
contiguous,
intent(out) :: k2(:,:,:,:)
2034 integer :: np, ip, is, it, iu, os, ixc, nf2, nrs, nk3, idx
2035 real(real64) :: ntot
2036 real(real64),
allocatable :: dclamp(:,:), ssig(:,:)
2037 real(real64),
allocatable :: v2rho2(:,:), v2rhosigma(:,:), v2sigma2(:,:)
2038 real(real64),
allocatable :: s2rho2(:,:), s2rhosigma(:,:)
2039 real(real64),
allocatable :: v3rho3(:,:), v3rho2s(:,:), v3rhos2(:,:), v3s3(:,:)
2040 real(real64),
allocatable :: s3rho3(:,:)
2041 real(real64),
allocatable :: flux(:), div(:)
2043 integer,
parameter :: N_V3RHO2SIGMA(2) = [1, 9], n_v3rhosigma2(2) = [1, 12], n_v3sigma3(2) = [1, 10]
2051 assert(nsp == 1 .or. nsp == 2)
2052 assert(nsig == 2*nsp - 1)
2055 nrs = nsp*(2*nsp - 1)
2062 assert(nf2 == nsig .and. nrs == nsp*nsig)
2064 safe_allocate(dclamp(1:nsp, 1:np))
2067 dclamp(is, ip) = max(n0(ip, is), m_zero)
2070 if (this%xc_is_gga)
then
2071 safe_allocate(ssig(1:nsig, 1:np))
2074 ssig(is, ip) = sigma0(ip, is)
2079 safe_allocate(v2rho2(1:nf2, 1:np))
2080 safe_allocate(s2rho2(1:nf2, 1:np))
2081 safe_allocate(v3rho3(1:nk3, 1:np))
2082 safe_allocate(s3rho3(1:nk3, 1:np))
2085 if (this%xc_is_gga)
then
2086 safe_allocate(v2rhosigma(1:nrs, 1:np))
2087 safe_allocate(v2sigma2(1:nrs, 1:np))
2088 safe_allocate(s2rhosigma(1:nrs, 1:np))
2092 safe_allocate(v3rho2s(1:n_v3rho2sigma(nsp), 1:np))
2093 safe_allocate(v3rhos2(1:n_v3rhosigma2(nsp), 1:np))
2094 safe_allocate(v3s3(1:n_v3sigma3(nsp), 1:np))
2099 select case (this%xc_functl(ixc)%family)
2100 case (xc_family_none)
2102 case (xc_family_lda)
2103 call xc_f03_lda_fxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, v2rho2)
2104 s2rho2 = s2rho2 + v2rho2
2105 call xc_f03_lda_kxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, v3rho3)
2106 s3rho3 = s3rho3 + v3rho3
2107 case (xc_family_gga)
2108 call xc_f03_gga_fxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, ssig, &
2109 v2rho2, v2rhosigma, v2sigma2)
2110 s2rho2 = s2rho2 + v2rho2
2111 s2rhosigma = s2rhosigma + v2rhosigma
2112 call xc_f03_gga_kxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, ssig, &
2113 v3rho3, v3rho2s, v3rhos2, v3s3)
2114 s3rho3 = s3rho3 + v3rho3
2116 message(1) =
"PAW one-center engine: unsupported XC functional family."
2117 call messages_fatal(1)
2125 if (nsp == 2) idx = is + it - 1
2127 kk(ip, is, it) = s2rho2(idx, ip)
2134 if (this%xc_is_gga)
then
2135 safe_allocate(flux(1:np))
2136 safe_allocate(div(1:np))
2139 os = min(nsp, 3 - is)
2142 flux(ip) = m_two*s2rhosigma(1, ip)*dn0(ip, 1)*this%vwr(ip)
2144 flux(ip) = (m_two*s2rhosigma((it-1)*3 + 2*is - 1, ip)*dn0(ip, is) &
2145 + s2rhosigma((it-1)*3 + 2, ip)*dn0(ip, os))*this%vwr(ip)
2151 safe_deallocate_a(flux)
2152 safe_deallocate_a(div)
2157 kk(ip, 1, 2) = m_half*(kk(ip, 1, 2) + kk(ip, 2, 1))
2158 kk(ip, 2, 1) = kk(ip, 1, 2)
2169 if (nsp == 2) idx = is + it + iu - 2
2171 k2(ip, is, it, iu) = s3rho3(idx, ip)
2182 ntot = ntot + dclamp(is, ip)
2184 if (ntot < m_epsilon)
then
2185 kk(ip, :, :) = m_zero
2186 k2(ip, :, :, :) = m_zero
2190 safe_deallocate_a(dclamp)
2191 safe_deallocate_a(ssig)
2192 safe_deallocate_a(v2rho2)
2193 safe_deallocate_a(s2rho2)
2194 safe_deallocate_a(v3rho3)
2195 safe_deallocate_a(s3rho3)
2196 safe_deallocate_a(v2rhosigma)
2197 safe_deallocate_a(v2sigma2)
2198 safe_deallocate_a(s2rhosigma)
2199 safe_deallocate_a(v3rho2s)
2200 safe_deallocate_a(v3rhos2)
2201 safe_deallocate_a(v3s3)
2226 subroutine paw_xc_moments(this, nlm_rho, ncore, ae, with_comp, e_xc, dij)
2228 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
2229 real(real64),
contiguous,
intent(in) :: ncore(:)
2230 logical,
intent(in) :: ae
2231 logical,
intent(in) :: with_comp
2232 real(real64),
intent(out) :: e_xc
2233 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2236 integer :: np, nsp, nsig, is, it, iu, ic, lm, ip
2237 real(real64) :: sq4pi, acc, dpol, n0c(4), fwp(4, 2)
2238 real(real64),
parameter :: wc(4) = [m_one, m_one, m_two, m_two]
2239 real(real64),
allocatable :: wrad(:)
2240 real(real64),
allocatable :: f0(:,:,:)
2241 real(real64),
allocatable :: n0(:,:), dn0(:,:), sigma0(:,:)
2242 real(real64),
allocatable :: exc0(:), v0(:,:)
2243 real(real64),
allocatable :: kk(:,:,:)
2244 real(real64),
allocatable :: k2(:,:,:,:)
2245 real(real64),
allocatable :: mlm(:,:,:)
2246 real(real64),
allocatable :: msum(:,:,:)
2247 real(real64),
allocatable :: vxc_lm(:,:,:)
2248 real(real64),
allocatable :: vrot(:,:)
2252 noncol = this%nspin == 4
2254 nsp = this%spin_channels
2256 sq4pi =
sqrt(m_four*m_pi)
2261 safe_allocate(n0(1:np, 1:nsp))
2262 safe_allocate(dn0(1:np, 1:nsp))
2263 safe_allocate(sigma0(1:np, 1:nsig))
2265 safe_allocate(f0(1:np, 1:4, 1:2))
2268 n0c(ic) = nlm_rho(ip, 1, ic)/sq4pi
2270 n0c(1) = n0c(1) + ncore(ip)
2271 n0c(2) = n0c(2) + ncore(ip)
2273 f0(ip, 1:4, 1:2) = fwp(1:4, 1:2)
2274 n0(ip, 1) = m_half*(n0c(1) + n0c(2) + dpol)
2275 n0(ip, 2) = m_half*(n0c(1) + n0c(2) - dpol)
2280 n0(ip, is) = nlm_rho(ip, 1, is)/sq4pi + ncore(ip)
2288 sigma0(ip, 1) = dn0(ip, 1)**2
2290 sigma0(ip, 2) = dn0(ip, 1)*dn0(ip, 2)
2291 sigma0(ip, 3) = dn0(ip, 2)**2
2296 safe_allocate(exc0(1:np))
2297 safe_allocate(v0(1:np, 1:nsp))
2300 safe_allocate(wrad(1:np))
2302 wrad(ip) = exc0(ip)*this%vwr(ip)
2306 e_xc = e_xc + blas_dot(np, n0(1, is), 1, wrad(1), 1)
2308 e_xc = m_four*m_pi*e_xc
2312 safe_allocate(kk(1:np, 1:nsp, 1:nsp))
2313 safe_allocate(k2(1:np, 1:nsp, 1:nsp, 1:nsp))
2318 safe_allocate(mlm(1:np, 1:this%nlm_rho, 1:nsp))
2322 do lm = 2, this%nlm_rho
2324 mlm(ip, lm, is) = wc(1)*f0(ip, 1, is)*nlm_rho(ip, lm, 1) &
2325 + wc(2)*f0(ip, 2, is)*nlm_rho(ip, lm, 2) &
2326 + wc(3)*f0(ip, 3, is)*nlm_rho(ip, lm, 3) &
2327 + wc(4)*f0(ip, 4, is)*nlm_rho(ip, lm, 4)
2332 call lalg_copy(np, this%nlm_rho, nsp, nlm_rho, mlm)
2338 safe_allocate(msum(1:np, 1:nsp, 1:nsp))
2343 do lm = 2, this%nlm_rho
2345 msum(ip, is, it) = msum(ip, is, it) + mlm(ip, lm, is)*mlm(ip, lm, it)
2349 acc = acc + kk(ip, is, it)*msum(ip, is, it)*this%vwr(ip)
2353 e_xc = e_xc + m_half*acc
2356 safe_allocate(vxc_lm(1:np, 1:this%nlm_rho, 1:nsp))
2362 acc = acc + k2(ip, is, it, iu)*msum(ip, it, iu)
2365 vxc_lm(ip, 1, is) = sq4pi*v0(ip, is) + acc/(m_two*sq4pi)
2367 do lm = 2, this%nlm_rho
2371 acc = acc + kk(ip, is, it)*mlm(ip, lm, it)
2373 vxc_lm(ip, lm, is) = acc
2381 safe_allocate(vrot(1:np, 1:this%nlm_rho))
2383 do lm = 1, this%nlm_rho
2385 vrot(ip, lm) = f0(ip, ic, 1)*vxc_lm(ip, lm, 1) + f0(ip, ic, 2)*vxc_lm(ip, lm, 2)
2396 safe_deallocate_a(wrad)
2397 safe_deallocate_a(f0)
2398 safe_deallocate_a(n0)
2399 safe_deallocate_a(dn0)
2400 safe_deallocate_a(sigma0)
2401 safe_deallocate_a(exc0)
2402 safe_deallocate_a(v0)
2403 safe_deallocate_a(kk)
2404 safe_deallocate_a(k2)
2405 safe_deallocate_a(mlm)
2406 safe_deallocate_a(msum)
2407 safe_deallocate_a(vxc_lm)
2408 safe_deallocate_a(vrot)
2416 real(real64),
intent(in) :: n1, n2, n3, n4
2417 real(real64) :: dpol
2419 dpol =
sqrt((n1 - n2)**2 + m_four*(n3**2 + n4**2))
2427 real(real64),
intent(in) :: n1, n2, n3, n4
2428 real(real64),
intent(out) :: dpol
2429 real(real64),
intent(out) :: fw(:,:)
2433 dpol =
sqrt((n1 - n2)**2 + m_four*(n3**2 + n4**2))
2436 fw(1, 1) = m_half*(m_one + pp)
2437 fw(1, 2) = m_half*(m_one - pp)
2438 fw(2, 1) = m_half*(m_one - pp)
2439 fw(2, 2) = m_half*(m_one + pp)
2465 logical,
intent(in) :: ae
2466 logical,
intent(in) :: with_comp
2467 real(real64),
contiguous,
intent(in) :: dens(:,:)
2468 real(real64),
contiguous,
intent(in) :: g(:,:,:,:), gp(:,:,:,:)
2469 real(real64),
contiguous,
intent(in) :: vr(:,:), vs(:,:)
2470 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2472 integer :: np, ibase, ip, ia, ic, k
2473 real(real64) :: dpol, uu, gradp
2474 real(real64) :: fwp(4, 2), gq(3), hh(3, 4), bs(3, 2), bd(3)
2475 real(real64),
allocatable :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
2481 safe_allocate(a1(1:np, 1:this%nang, 1:4))
2482 safe_allocate(a2(1:np, 1:this%nang, 1:4))
2483 safe_allocate(a3(1:np, 1:this%nang, 1:4))
2484 safe_allocate(a4(1:np, 1:this%nang, 1:4))
2487 do ia = 1, this%nang
2491 dens(ibase + ip, 3), dens(ibase + ip, 4), dpol, fwp)
2494 bs(k, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, k) + vs(ibase + ip, 2)*gp(ip, 2, ia, k)
2495 bs(k, 2) = m_two*vs(ibase + ip, 3)*gp(ip, 2, ia, k) + vs(ibase + ip, 2)*gp(ip, 1, ia, k)
2496 bd(k) = bs(k, 1) - bs(k, 2)
2501 if (dpol > m_zero)
then
2502 uu = dens(ibase + ip, 1) - dens(ibase + ip, 2)
2504 gq(k) = (uu*(g(ip, 1, ia, k) - g(ip, 2, ia, k)) &
2505 + m_four*(dens(ibase + ip, 3)*g(ip, 3, ia, k) &
2506 + dens(ibase + ip, 4)*g(ip, 4, ia, k)))/dpol
2507 gradp = ((g(ip, 1, ia, k) - g(ip, 2, ia, k)) - (uu/dpol)*gq(k))/dpol
2508 hh(k, 1) = m_half*gradp
2509 hh(k, 2) = -m_half*gradp
2510 hh(k, 3) = (g(ip, 3, ia, k) - dens(ibase + ip, 3)*gq(k)/dpol)/dpol
2511 hh(k, 4) = (g(ip, 4, ia, k) - dens(ibase + ip, 4)*gq(k)/dpol)/dpol
2515 a1(ip, ia, ic) = fwp(ic, 1)*vr(ibase + ip, 1) + fwp(ic, 2)*vr(ibase + ip, 2) &
2516 + bd(1)*hh(1, ic) + bd(2)*hh(2, ic) + bd(3)*hh(3, ic)
2517 a2(ip, ia, ic) = fwp(ic, 1)*bs(1, 1) + fwp(ic, 2)*bs(1, 2)
2518 a3(ip, ia, ic) = fwp(ic, 1)*bs(2, 1) + fwp(ic, 2)*bs(2, 2)
2519 a4(ip, ia, ic) = fwp(ic, 1)*bs(3, 1) + fwp(ic, 2)*bs(3, 2)
2526 safe_deallocate_a(a1)
2527 safe_deallocate_a(a2)
2528 safe_deallocate_a(a3)
2529 safe_deallocate_a(a4)
2542 logical,
intent(in) :: ae
2543 logical,
intent(in) :: with_comp
2544 real(real64),
contiguous,
intent(in) :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
2545 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2547 integer :: np, ip, lm, ic
2548 real(real64),
allocatable :: t1(:,:), t2(:,:), t3(:,:), t4(:,:)
2549 real(real64),
allocatable :: u1(:,:), u2(:,:)
2550 real(real64),
allocatable :: w(:,:)
2556 safe_allocate(t1(1:np, 1:this%nlm_rho))
2557 safe_allocate(t2(1:np, 1:this%nlm_rho))
2558 safe_allocate(t3(1:np, 1:this%nlm_rho))
2559 safe_allocate(t4(1:np, 1:this%nlm_rho))
2560 safe_allocate(u1(1:np, 1:this%nlm_rho))
2561 safe_allocate(u2(1:np, 1:this%nlm_rho))
2562 safe_allocate(w(1:this%npair, 1:this%nlm_rho))
2564 do ic = 1,
size(dij, 3)
2566 call lalg_gemm(a1(:, :, ic), this%wylm, t1)
2567 call lalg_gemm(a2(:, :, ic), this%wylm, t2)
2568 call lalg_gemm(a3(:, :, ic), this%wdylm_dth, t3)
2569 call lalg_gemm(a4(:, :, ic), this%wdylm_dph, t4)
2573 do lm = 1, this%nlm_rho
2575 u1(ip, lm) = (t1(ip, lm) + (t3(ip, lm) + t4(ip, lm))*this%invr(ip))*this%vwr(ip)
2576 u2(ip, lm) = t2(ip, lm)*this%vwr(ip)
2582 call lalg_gemm(this%pair_ae, u1, w, transa =
'T')
2583 call lalg_gemm(this%dpair_ae, u2, w, transa =
'T', beta = m_one)
2585 call lalg_gemm(this%pair_ps, u1, w, transa =
'T')
2586 call lalg_gemm(this%dpair_ps, u2, w, transa =
'T', beta = m_one)
2597 safe_deallocate_a(t1)
2598 safe_deallocate_a(t2)
2599 safe_deallocate_a(t3)
2600 safe_deallocate_a(t4)
2601 safe_deallocate_a(u1)
2602 safe_deallocate_a(u2)
2603 safe_deallocate_a(w)
2617 logical,
intent(in) :: ae
2618 logical,
intent(in) :: with_comp
2619 real(real64),
contiguous,
intent(in) :: vlm(:,:)
2620 real(real64),
contiguous,
intent(inout) :: dij(:,:)
2623 real(real64),
allocatable :: vw(:,:), w(:,:)
2630 safe_allocate(vw(1:this%nr, 1:this%nlm_rho))
2631 do lm = 1, this%nlm_rho
2633 vw(ip, lm) = vlm(ip, lm)*this%vwr(ip)
2637 safe_allocate(w(1:this%npair, 1:this%nlm_rho))
2639 call lalg_gemm(this%pair_ae, vw, w, transa =
'T')
2641 call lalg_gemm(this%pair_ps, vw, w, transa =
'T')
2642 if (with_comp)
call paw_qaug_gemv(this, this%qaug,
'T', vw, w)
2648 safe_deallocate_a(vw)
2649 safe_deallocate_a(w)
2687 integer,
intent(in) :: nprojs
2688 integer,
intent(in) :: pl(:)
2689 integer,
intent(in) :: pm(:)
2690 integer,
intent(in) :: pchannel(:)
2691 integer,
intent(out) :: map(:)
2693 integer :: i, ic, maxl, maxchan, iproj, ri, lm
2694 integer,
allocatable :: cnt(:), rad_of(:,:)
2698 assert(nprojs == this%nlm)
2700 maxl = maxval(this%lrad(1:this%nrad))
2702 safe_allocate(cnt(0:maxl))
2703 safe_allocate(rad_of(0:maxl, 1:maxchan))
2707 cnt(this%lrad(i)) = cnt(this%lrad(i)) + 1
2708 ic = cnt(this%lrad(i))
2712 if (this%rad_2j(i) > 0 .and. this%lrad(i) > 0)
then
2713 if (this%rad_2j(i) == 2*this%lrad(i) - 1)
then
2714 ic = (ic - 1)/2*2 + 2
2716 assert(this%rad_2j(i) == 2*this%lrad(i) + 1)
2717 ic = (ic - 1)/2*2 + 1
2720 rad_of(this%lrad(i), ic) = i
2724 do iproj = 1, nprojs
2725 assert(pl(iproj) >= 0 .and. pl(iproj) <= maxl)
2726 assert(pchannel(iproj) >= 1 .and. pchannel(iproj) <= cnt(pl(iproj)))
2727 ri = rad_of(pl(iproj), pchannel(iproj))
2729 assert(this%lrad(ri) == pl(iproj))
2731 if (this%p_rad(lm) == ri .and. this%p_m(lm) == pm(iproj) .and. this%p_l(lm) == pl(iproj))
then
2736 assert(map(iproj) > 0)
2739 safe_deallocate_a(cnt)
2740 safe_deallocate_a(rad_of)
2752 real(real64),
intent(in) :: occ(:)
2753 real(real64),
intent(out) :: rho(:,:,:)
2760 do is = 1, this%spin_channels
2762 rho(i, i, is) = occ(this%p_rad(i)) / real((2*this%p_l(i) + 1)*this%spin_channels, real64)
2776 real(real64),
intent(in) :: rho(:,:,:)
2777 logical,
intent(in) :: ae
2780 real(real64),
allocatable :: nlm_rho(:,:)
2781 real(real64) :: sqrt4pi
2786 sqrt4pi =
sqrt(m_four*m_pi)
2787 safe_allocate(nlm_rho(1:nr, 1:this%nlm_rho))
2790 do is = 1, this%spin_channels
2793 charge = charge + sqrt4pi*blas_dot(nr, nlm_rho(1, 1), 1, this%vwr(1), 1)
2795 safe_deallocate_a(nlm_rho)
2810 real(real64),
intent(in) :: rho(:,:)
2811 integer,
intent(out) :: ncol
2812 type(spline_t),
allocatable,
intent(out) :: spl(:)
2813 integer,
allocatable,
intent(out) :: ll(:)
2814 integer,
allocatable,
intent(out) :: mm(:)
2815 real(real64),
intent(out) :: rcut
2817 real(real64),
allocatable :: nae(:,:), nps(:,:)
2818 real(real64),
parameter :: tol = 1.0e-14_real64
2822 safe_allocate(nae(1:this%nr, 1:this%nlm_rho))
2823 safe_allocate(nps(1:this%nr, 1:this%nlm_rho))
2828 call lalg_axpy(this%nr, this%nlm_rho, -m_one, nps, nae)
2831 safe_deallocate_a(nae)
2832 safe_deallocate_a(nps)
2852 real(real64),
intent(in) :: rho(:,:)
2853 integer,
intent(out) :: ncol
2854 type(spline_t),
allocatable,
intent(out) :: spl(:)
2855 integer,
allocatable,
intent(out) :: ll(:)
2856 integer,
allocatable,
intent(out) :: mm(:)
2857 real(real64),
intent(out) :: rcut
2861 real(real64),
optional,
intent(out) :: tau_integral
2863 integer :: i, j, k, ia, ri, rj, lmi, lmj
2864 real(real64) :: rho_ij, ang_grad, ang_val, wa, cg, cv
2865 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:), dtau_lm(:,:), dtaua(:,:)
2866 real(real64),
parameter :: tol = 1.0e-14_real64
2870 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
2871 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
2878 safe_allocate(dtaua(1:this%nr, 1:this%nang))
2879 dtaua(1:this%nr, 1:this%nang) = m_zero
2880 do ia = 1, this%nang
2884 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
2887 if (abs(rho_ij) <= tol) cycle
2889 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
2890 ang_grad = this%ylm(ia, lmi)*this%ylm(ia, lmj)
2891 ang_val = this%dylm_dth(ia, lmi)*this%dylm_dth(ia, lmj) &
2892 + this%dylm_dph(ia, lmi)*this%dylm_dph(ia, lmj)
2893 cg = rho_ij*wa*ang_grad
2894 cv = rho_ij*wa*ang_val
2897 dtaua(k, ia) = dtaua(k, ia) &
2898 + cg*(dphi_ae(k, ri)*dphi_ae(k, rj) - dphi_ps(k, ri)*dphi_ps(k, rj)) &
2899 + cv*this%invr(k)**2*(this%phi_ae(k, ri)*this%phi_ae(k, rj) - this%phi_ps(k, ri)*this%phi_ps(k, rj))
2907 safe_allocate(dtau_lm(1:this%nr, 1:this%nlm_rho))
2908 call lalg_gemm(this%nr, this%nlm_rho, this%nang, m_one, dtaua, this%ylm, m_zero, dtau_lm)
2909 safe_deallocate_a(dtaua)
2916 if (
present(tau_integral))
then
2917 tau_integral =
sqrt(m_four*m_pi)*blas_dot(this%nr, dtau_lm(1, 1), 1, this%vwr(1), 1)
2920 safe_deallocate_a(dphi_ae)
2921 safe_deallocate_a(dphi_ps)
2922 safe_deallocate_a(dtau_lm)
2944 real(real64),
intent(in) :: arho(:,:)
2945 integer,
intent(in) :: idir
2946 integer,
intent(out) :: ncol
2947 type(spline_t),
allocatable,
intent(out) :: spl(:)
2948 integer,
allocatable,
intent(out) :: ll(:)
2949 integer,
allocatable,
intent(out) :: mm(:)
2950 real(real64),
intent(out) :: rcut
2951 real(real64),
optional,
intent(out) :: current_integral
2953 integer :: i, j, ip, ia, ri, rj, lmi, lmj, ra, rb, rp, npr
2954 real(real64) :: aij, yi
2955 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:), dj_lm(:,:), dja(:,:), rmat(:,:), cmat(:,:)
2956 real(real64),
parameter :: tol = 1.0e-14_real64
2960 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
2961 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
2974 npr = this%nrad*this%nrad
2975 safe_allocate(rmat(1:this%nr, 1:2*npr))
2976 do ra = 1, this%nrad
2977 do rb = 1, this%nrad
2978 rp = (ra-1)*this%nrad + rb
2980 rmat(ip, rp) = this%phi_ae(ip, ra)*dphi_ae(ip, rb) - this%phi_ps(ip, ra)*dphi_ps(ip, rb)
2981 rmat(ip, npr + rp) = this%invr(ip)*(this%phi_ae(ip, ra)*this%phi_ae(ip, rb) &
2982 - this%phi_ps(ip, ra)*this%phi_ps(ip, rb))
2987 safe_allocate(cmat(1:2*npr, 1:this%nang))
2988 cmat(1:2*npr, 1:this%nang) = m_zero
2991 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
2994 if (abs(aij) <= tol) cycle
2996 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
2997 rp = (ri-1)*this%nrad + rj
2998 do ia = 1, this%nang
2999 yi = aij*this%wang(ia)*this%ylm(ia, lmi)
3000 cmat(rp, ia) = cmat(rp, ia) + yi*this%ylm(ia, lmj)*this%rhat(ia, idir)
3001 cmat(npr + rp, ia) = cmat(npr + rp, ia) &
3002 + yi*(this%dylm_dth(ia, lmj)*this%that(ia, idir) + this%dylm_dph(ia, lmj)*this%phat(ia, idir))
3007 safe_allocate(dja(1:this%nr, 1:this%nang))
3008 call lalg_gemm(this%nr, this%nang, 2*npr, m_one, rmat, cmat, m_zero, dja)
3009 safe_deallocate_a(rmat)
3010 safe_deallocate_a(cmat)
3013 safe_allocate(dj_lm(1:this%nr, 1:this%nlm_rho))
3014 call lalg_gemm(this%nr, this%nlm_rho, this%nang, m_one, dja, this%ylm, m_zero, dj_lm)
3015 safe_deallocate_a(dja)
3019 if (
present(current_integral))
then
3020 current_integral =
sqrt(m_four*m_pi)*blas_dot(this%nr, dj_lm(1, 1), 1, this%vwr(1), 1)
3023 safe_deallocate_a(dphi_ae)
3024 safe_deallocate_a(dphi_ps)
3025 safe_deallocate_a(dj_lm)
3038 real(real64),
allocatable,
intent(out) :: vmat(:,:,:)
3040 integer :: i, j, ip, ia, ri, rj, lmi, lmj, idir
3041 real(real64) :: yi, aa, bb, c1, c2, wa, acc
3042 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:)
3046 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
3047 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
3055 safe_allocate(vmat(1:this%nlm, 1:this%nlm, 1:3))
3058 do ia = 1, this%nang
3062 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
3063 yi = this%ylm(ia, lmi)
3066 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
3067 aa = this%ylm(ia, lmj)*this%rhat(ia, idir)
3068 bb = this%dylm_dth(ia, lmj)*this%that(ia, idir) + this%dylm_dph(ia, lmj)*this%phat(ia, idir)
3073 acc = acc + this%vwr(ip)*( &
3074 c1*(this%phi_ae(ip, ri)*dphi_ae(ip, rj) - this%phi_ps(ip, ri)*dphi_ps(ip, rj)) &
3075 + c2*this%invr(ip)*(this%phi_ae(ip, ri)*this%phi_ae(ip, rj) - this%phi_ps(ip, ri)*this%phi_ps(ip, rj)))
3077 vmat(i, j, idir) = vmat(i, j, idir) + wa*acc
3083 safe_deallocate_a(dphi_ae)
3084 safe_deallocate_a(dphi_ps)
3101 integer,
intent(in) :: nprojs
3102 integer,
intent(in) :: pl(:)
3103 integer,
intent(in) :: pm(:)
3104 integer,
intent(in) :: pchannel(:)
3105 type(spline_t),
allocatable,
intent(out) :: spl(:)
3106 integer,
allocatable,
intent(out) :: ll(:)
3107 integer,
allocatable,
intent(out) :: mm(:)
3108 real(real64),
intent(out) :: rcut
3111 integer,
allocatable :: map(:)
3112 real(real64),
allocatable :: diff(:)
3116 safe_allocate(map(1:nprojs))
3119 safe_allocate(spl(1:nprojs))
3120 safe_allocate(ll(1:nprojs))
3121 safe_allocate(mm(1:nprojs))
3122 safe_allocate(diff(1:this%nr))
3124 ri = this%p_rad(map(i))
3125 diff(1:this%nr) = this%phi_ae(1:this%nr, ri) - this%phi_ps(1:this%nr, ri)
3128 call spline_init(spl(i))
3129 call spline_fit(this%nr, this%r, diff, spl(i))
3131 rcut = this%r(this%nr)
3133 safe_deallocate_a(map)
3134 safe_deallocate_a(diff)
3149 real(real64),
allocatable,
intent(out) :: deltak(:,:)
3150 integer,
allocatable,
intent(out) :: p_rad(:)
3151 integer,
allocatable,
intent(out) :: p_l(:)
3152 integer,
allocatable,
intent(out) :: p_m(:)
3156 safe_allocate(deltak(1:this%nrad, 1:this%nrad))
3157 deltak(1:this%nrad, 1:this%nrad) = this%kin_ae(1:this%nrad, 1:this%nrad) - this%kin_ps(1:this%nrad, 1:this%nrad)
3158 safe_allocate(p_rad(1:this%nlm))
3159 p_rad(1:this%nlm) = this%p_rad(1:this%nlm)
3160 safe_allocate(p_l(1:this%nlm))
3161 p_l(1:this%nlm) = this%p_l(1:this%nlm)
3162 safe_allocate(p_m(1:this%nlm))
3163 p_m(1:this%nlm) = this%p_m(1:this%nlm)
3174 call xc_functional_end(this%xc_functl(1))
3175 call xc_functional_end(this%xc_functl(2))
3177 safe_deallocate_a(this%r)
3178 safe_deallocate_a(this%r2)
3179 safe_deallocate_a(this%invr)
3180 safe_deallocate_a(this%wr)
3181 safe_deallocate_a(this%vwr)
3182 safe_deallocate_a(this%der_w)
3183 safe_deallocate_a(this%der_i0)
3184 safe_deallocate_a(this%der_wt)
3185 safe_deallocate_a(this%der_trow0)
3186 safe_deallocate_a(this%der_tn)
3187 safe_deallocate_a(this%lrad)
3188 safe_deallocate_a(this%rad_2j)
3189 safe_deallocate_a(this%phi_ae_small)
3190 safe_deallocate_a(this%phi_ae)
3191 safe_deallocate_a(this%phi_ps)
3192 safe_deallocate_a(this%p_rad)
3193 safe_deallocate_a(this%p_l)
3194 safe_deallocate_a(this%p_m)
3195 safe_deallocate_a(this%qaug)
3196 safe_deallocate_a(this%pair_ae)
3197 safe_deallocate_a(this%pair_ps)
3198 safe_deallocate_a(this%gnt_pair)
3199 safe_deallocate_a(this%gnt_l)
3200 safe_deallocate_a(this%gnt_lm)
3201 safe_deallocate_a(this%gnt_c)
3202 safe_deallocate_a(this%gnt_ptr)
3203 safe_deallocate_a(this%dpair_ae)
3204 safe_deallocate_a(this%dpair_ps)
3205 safe_deallocate_a(this%dqaug)
3206 safe_deallocate_a(this%nc_ae)
3207 safe_deallocate_a(this%nc_ps)
3208 safe_deallocate_a(this%nc_ae_der)
3209 safe_deallocate_a(this%nc_ps_der)
3210 safe_deallocate_a(this%vref_ae)
3211 safe_deallocate_a(this%vref_ps)
3212 safe_deallocate_a(this%kin_ae)
3213 safe_deallocate_a(this%kin_ps)
3214 safe_deallocate_a(this%wang)
3215 safe_deallocate_a(this%ylm)
3216 safe_deallocate_a(this%dylm_dth)
3217 safe_deallocate_a(this%dylm_dph)
3218 safe_deallocate_a(this%wylm)
3219 safe_deallocate_a(this%wdylm_dth)
3220 safe_deallocate_a(this%wdylm_dph)
3221 safe_deallocate_a(this%rhat)
3222 safe_deallocate_a(this%that)
3223 safe_deallocate_a(this%phat)
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
This module contains interfaces for BLAS routines You should not use these routines directly....
real(real64), parameter, public m_zero
real(real64), parameter, public m_one
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_not_implemented(feature, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
logical function, public parse_is_defined(namespace, name)
subroutine paw_onsite_init_pairs(this)
Tabulate the species-constant radial pair products phi_i phi_j and pack the nonzero real Gaunt coupli...
subroutine, public paw_onsite_tau_diff(this, rho, ncol, spl, ll, mm, rcut, tau_integral)
Build the one-center all-electron-minus-pseudo kinetic-energy-density difference for a single colline...
subroutine paw_partial_wave_derivatives(this, dphi_ae, dphi_ps)
Radial derivatives of all (AE, PS) partial waves phi (not u = r phi): grad(phi Y) uses dphi/dr.
subroutine paw_onsite_init_xc(this, ps, namespace)
Initialize the exchange and correlation functionals from the ones stored in the pseudopotential.
subroutine paw_qaug_gemv(this, qtab, trans, xx, yy)
Contract the packed compensation shapes against per-LM fields, restricted to the Gaunt-live L channel...
real(real64), parameter paw_xc_tiny
Relative polarization threshold of the noncollinear local-frame projection.
subroutine, public paw_onsite_partial_wave_diff(this, nprojs, pl, pm, pchannel, spl, ll, mm, rcut)
Build the partial-wave difference (phi_i - phitilde_i)(r) for each projector, as radial splines ready...
subroutine, public paw_onsite_end(this)
subroutine paw_gaunt_scatter_dij(this, w, dij)
Scatter the per-(pair, LM) reductions through the packed Gaunt couplings into the symmetric D matrix:...
integer, parameter, public paw_blochl
Bloechl (GPAW/ABINIT); nhat excluded from XC.
subroutine paw_build_density(this, rho, ae, with_comp, nlm_rho, nlm_der)
Build the density coefficients n_LM(r) from rho_ij ([Torrent08] Eqs. (44)-(47)). On the PS side,...
subroutine paw_onsite_init_derivative(this)
Build the five-point Fornberg first-derivative weights for every radial point (B. Fornberg,...
integer pure function paw_pair_index(ri, rj)
Packed index of the unordered radial channel pair (ri, rj). The radial pair products and compensation...
subroutine paw_xc_eval_block(this, np, ip0, bs, nsp, nsig, dens, sigma, exc, vrho, vsigma)
Evaluate the functionals on one contiguous block of bs points.
subroutine paw_radial_derivative_fd(this, f, df)
Radial derivative of a function sampled on the sphere grid: apply the banded Fornberg operator built ...
subroutine, public paw_onsite_compute(this, rho, e1, e1t, dij, hxc_only)
Given the one-center density matrix rho_ij, compute the one-center energies E1 (AE) and E1t (PS) and ...
integer, parameter paw_xc_scheme_full
exact evaluation on the radial x angular grid
subroutine, public paw_onsite_current_diff(this, arho, idir, ncol, spl, ll, mm, rcut, current_integral)
One-center all-electron current-density correction Delta j^alpha = j^1 - j~^1.
subroutine paw_xc_kernels(this, nsp, nsig, n0, sigma0, dn0, kk, k2)
Analytic XC kernels of the spherical one-center problem at fixed radial gradient: K_st(r) = d v_s(r) ...
subroutine, public paw_onsite_init(this, ps, namespace, formulation, nspin)
Build the per-species one-center data from a (PAW) pseudopotential.
integer, parameter, public paw_kresse_joubert
PAW formulation: selects the compensation-charge / reference treatment.
subroutine paw_xc(this, nlm_rho, nlm_der, ncore, ae, with_comp, e_xc, dij)
Exchange-correlation on the radial x angular grid: LibXC evaluated pointwise, accumulating the XC ene...
subroutine paw_xc_dij_gga_fields(this, ae, with_comp, a1, a2, a3, a4, dij)
Accumulate the D-matrix components from the angular fields of the White-Bird GGA coupling,...
subroutine paw_xc_density(this, nlm_rho, ncore, dens, densp, dpol)
: Prepare the density for the XC calculation with libxc The polarization magnitude dpol (noncollinear...
integer pure function, public paw_onsite_nlm(this)
Number of (l,m)-resolved projectors, i.e. the leading dimension of rho_ij.
subroutine paw_xc_dij_gga_noncollinear(this, ae, with_comp, dens, g, gp, vr, vs, dij)
Noncollinear GGA D-matrix contribution: the exact derivative of the local-frame projected E_xc with r...
pure real(real64) function paw_xc_noncol_dpol(n1, n2, n3, n4)
Noncollinear polarization magnitude dpol = |m| at one point.
integer pure function, public paw_onsite_nlm_rho(this)
Number of real-harmonic columns (lmax_rho+1)^2 of the one-center density expansion; the upper bound o...
subroutine, public paw_onsite_reorder_pmat(nprojs, map, src, dst)
Reorder one spin channel of a projector-ordered matrix.
subroutine, public paw_onsite_pmat_map(this, nprojs, pl, pm, pchannel, map)
Map the projector-matrix enumeration (l, m, channel) used by the mesh nonlocal machinery to the one-c...
subroutine paw_xc_sigma(this, dens, dpol, g, gp, sigma)
Conversion from gradients to sigma, for GGA with libxc.
subroutine, public paw_onsite_get_kinetic_data(this, deltaK, p_rad, p_l, p_m)
Read-only access to the frozen kinetic correction DeltaK = K^AE - K^PS (the radial-channel matrix,...
subroutine paw_radial_derivative(r, f, df)
Radial derivative of a grid-sampled function via the cubic-spline derivative.
subroutine paw_onsite_kinetic(this, r_full, phi_ae_full, phi_ps_full)
Kinetic matrices K^AE_ij = <phi_i|T|phi_j> and K^PS_ij = <phitilde_i|T|phitilde_j>,...
real(real64), parameter gaunt_tol
subroutine paw_xc_lda_process(this, dens, vr)
Rotate the LDA potential from the local spin frame back to the global fram.
subroutine paw_adjoint_divergence_add(this, flux, div, vfield)
Add the discrete-adjoint divergence of a vwr-weighted radial flux to a potential-like field: vfield(i...
subroutine paw_xc_gga_process(this, ae, with_comp, dens, g, gp, vr, vs, dij)
Rotate the GGA part of the potential from the local spin frame back to the global fram.
subroutine, public paw_onsite_reference_density(this, occ, rho)
Build the spherical reference density matrix from per-radial-channel occupations occ(1:nrad): each sh...
subroutine paw_xc_sph_potential(this, nsp, nsig, n0, sigma0, dn0, exc0, vsph)
Energy density and full XC potential of a spherically symmetric density on the radial grid....
subroutine paw_onsite_angular_grid(this)
Angular grid: Gauss-Legendre in cos(theta) x uniform in phi, plus the real spherical harmonics tabula...
subroutine, public paw_onsite_get_velocity_matrix(this, vmat)
Velocity (momentum) matrix of the partial waves, V^alpha_ij = int (g_i grad_alpha g_j) dV,...
subroutine paw_fornberg_weights(z, x, n, w)
First-derivative weights at z from function values at the n points x (Fornberg 1988 recursion,...
integer, parameter paw_xc_scheme_moments
second-order moment expansion around the spherical density
subroutine paw_hartree_lm(this, lm, nl, vl)
Radial Hartree potential for one (L,M) channel (classical multipole expansion of 1/|r-r_prime|,...
subroutine paw_xc_moments(this, nlm_rho, ncore, ae, with_comp, e_xc, dij)
One-center XC by the second-order moment expansion around the spherical density ([Torrent08] Sec....
integer pure function, public paw_onsite_nspin(this)
Number of collinear spin channels (1 or 2) the sphere was built for.
subroutine paw_emit_lm_columns(this, field_lm, tol, ncol, spl, ll, mm, rcut)
Fit the nonzero (L, M) columns of a one-center radial field field_lm(np, nlm_rho) into splines ready ...
subroutine paw_accumulate_dij(this, ae, with_comp, vlm, dij)
Accumulate D_ij = sum_LM gaunt(l_i m_i, l_j m_j, L M) int v_LM(r) g_ij^L(r) r^2 dr where g_ij^L is th...
logical function paw_onsite_xc_has_kernels(this)
Whether all the functionals of the dataset provide the second and third derivatives (fxc,...
subroutine, public paw_onsite_side(this, rho, ae, energy, dij, hxc_only)
One side (AE or PS) of the one-center calculation: build the density in the Y_LM expansion,...
real(real64) function, public paw_onsite_charge(this, rho, ae)
Integrated L=0 charge of the one-center density (spin-summed) for a given rho: the all-electron (ae==...
subroutine paw_xc_eval(this, np, nsp, nsig, dens, sigma, exc, vrho, vsigma)
Functional-specific part of the one-center XC.
pure subroutine paw_xc_noncol_weights(n1, n2, n3, n4, dpol, fw)
Noncollinear local-frame projection weights F_c^s = d n_s / d n_c at one point.
subroutine, public paw_onsite_density_diff(this, rho, ncol, spl, ll, mm, rcut)
Build the one-center all-electron-minus-(pseudo+compensation) density difference for a single colline...
subroutine paw_xc_gradient(this, nlm_rho, nlm_der, ncder, g)
Gradient stage of paw_xc.
subroutine paw_radial_derivative_t(this, f, df)
Apply the transpose of the banded radial-derivative operator: df_j = sum_i D_ij f_i....
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
pure logical function, public ps_is_paw(ps)
pure logical function, public ps_has_nlcc(ps)
integer, parameter, public pseudo_exchange_unknown
integer, parameter, public pseudo_correlation_unknown
real(real64) function, public spline_eval(spl, x)
static double f(double w, void *p)
Per-species, geometry-independent one-center data. Built once at setup and immutable during the SCF; ...
A type storing the information and data about a pseudopotential.