65 use,
intrinsic :: iso_fortran_env
77#ifdef HAVE_LIBXC_FUNCS
112 integer,
parameter :: PAW_KRESSE_JOUBERT = 1
113 integer,
parameter :: PAW_BLOCHL = 2
116 integer,
parameter :: &
117 PAW_XC_SCHEME_FULL = 1, & !< exact evaluation on the radial x angular grid
125 integer :: spin_channels = 1
128 real(real64) :: rc =
m_zero
130 real(real64),
allocatable :: r(:)
131 real(real64),
allocatable :: r2(:)
132 real(real64),
allocatable :: invr(:)
135 real(real64),
allocatable :: wr(:)
136 real(real64),
allocatable :: vwr(:)
140 integer,
allocatable :: lrad(:)
141 real(real64),
allocatable :: phi_ae(:,:)
142 real(real64),
allocatable :: phi_ps(:,:)
143 integer,
allocatable :: rad_2j(:)
144 logical :: has_small = .false.
145 real(real64),
allocatable :: phi_ae_small(:,:)
149 integer,
allocatable :: p_rad(:)
150 integer,
allocatable :: p_l(:)
151 integer,
allocatable :: p_m(:)
155 real(real64),
allocatable :: qaug(:,:,:)
162 real(real64),
allocatable :: pair_ae(:,:)
163 real(real64),
allocatable :: pair_ps(:,:)
165 integer,
allocatable :: gnt_pair(:)
166 integer,
allocatable :: gnt_l(:)
167 integer,
allocatable :: gnt_lm(:)
168 real(real64),
allocatable :: gnt_c(:)
169 integer,
allocatable :: gnt_ptr(:)
176 real(real64),
allocatable :: dpair_ae(:,:)
177 real(real64),
allocatable :: dpair_ps(:,:)
178 real(real64),
allocatable :: dqaug(:,:,:)
179 real(real64),
allocatable :: nc_ae_der(:)
180 real(real64),
allocatable :: nc_ps_der(:)
189 integer :: der_nw = 5
190 real(real64),
allocatable :: der_w(:,:)
191 integer,
allocatable :: der_i0(:)
192 integer :: der_ntw = 0
193 real(real64),
allocatable :: der_wt(:,:)
194 integer,
allocatable :: der_trow0(:)
195 integer,
allocatable :: der_tn(:)
198 logical :: has_ae_core = .false.
199 logical :: has_ps_core = .false.
200 real(real64),
allocatable :: nc_ae(:)
201 real(real64),
allocatable :: nc_ps(:)
202 real(real64),
allocatable :: vref_ae(:)
203 real(real64),
allocatable :: vref_ps(:)
206 real(real64),
allocatable :: kin_ae(:,:)
207 real(real64),
allocatable :: kin_ps(:,:)
211 integer :: lmax_rho = 0
212 integer :: nlm_rho = 0
213 real(real64),
allocatable :: wang(:)
214 real(real64),
allocatable :: ylm(:,:)
215 real(real64),
allocatable :: dylm_dth(:,:)
216 real(real64),
allocatable :: dylm_dph(:,:)
217 real(real64),
allocatable :: wylm(:,:)
218 real(real64),
allocatable :: wdylm_dth(:,:)
219 real(real64),
allocatable :: wdylm_dph(:,:)
223 real(real64),
allocatable :: rhat(:,:)
224 real(real64),
allocatable :: that(:,:)
225 real(real64),
allocatable :: phat(:,:)
233 real(real64),
allocatable :: tau_c_ae(:)
234 real(real64),
allocatable :: tau_c_ps(:)
235 real(real64),
allocatable :: nc_ae_lapl(:)
236 real(real64),
allocatable :: nc_ps_lapl(:)
239 real(real64),
allocatable :: dphi_ae(:,:)
240 real(real64),
allocatable :: dphi_ps(:,:)
241 real(real64),
allocatable :: d2phi_ae(:,:)
242 real(real64),
allocatable :: d2phi_ps(:,:)
245 integer :: formulation = paw_kresse_joubert
248 logical :: owns_xc_functl = .
true.
249 logical :: xc_is_gga = .false.
250 logical :: xc_is_mgga = .false.
251 logical :: xc_needs_laplacian = .false.
254 logical :: usexcnhat = .
true.
258 real(real64),
parameter ::
gaunt_tol = 1.0e-12_real64
267 subroutine paw_onsite_init(this, ps, namespace, formulation, nspin, xc_ids, usexcnhat)
269 type(
ps_t),
intent(in) :: ps
271 integer,
intent(in) :: formulation
272 integer,
intent(in) :: nspin
274 integer,
optional,
intent(in) :: xc_ids(2)
276 logical,
optional,
intent(in) :: usexcnhat
278 integer :: nr, nr_full, i, j, k, maxl, ilm, ll, mm, pair
279 integer,
allocatable :: cpos(:)
280 real(real64),
allocatable :: r_full(:), phi_ae_full(:,:), phi_ps_full(:,:), work(:), dwork(:)
281 real(real64),
allocatable :: phi_ae_small_full(:,:)
282 real(real64),
allocatable :: qaug_full(:,:,:)
287 assert(formulation == paw_kresse_joubert .or. formulation == paw_blochl)
289 this%formulation = formulation
291 this%spin_channels = min(nspin, 2)
297 assert(.not. (this%xc_is_mgga .and. this%usexcnhat))
326 "(use PAWXCScheme = paw_xc_full)", namespace=namespace)
328 message(1) =
"Info: meta-GGA functional in the PAW one-center terms: using PAWXCScheme = paw_xc_full."
330 this%xc_scheme = paw_xc_scheme_full
337 message(1) =
"PAWXCScheme = paw_xc_moments needs the second and third derivatives (fxc and kxc)"
338 message(2) =
"of the exchange-correlation functional of the PAW dataset, which this functional"
339 message(3) =
"or this LibXC library does not provide. Use PAWXCScheme = paw_xc_full instead."
342 message(1) =
"Info: the exchange-correlation functional of the PAW dataset has no fxc/kxc in this"
343 message(2) =
" LibXC library: using PAWXCScheme = paw_xc_full."
345 this%xc_scheme = paw_xc_scheme_full
353 nr_full =
size(ps%paw_grid)
354 safe_allocate(r_full(1:nr_full))
355 r_full(1:nr_full) = ps%paw_grid(1:nr_full)
356 this%rc = ps%paw_cutoff_radius
360 if (r_full(k) > this%rc*(
m_one + 1.0e-6_real64))
exit
365 safe_allocate(this%r(1:nr))
366 safe_allocate(this%r2(1:nr))
367 safe_allocate(this%wr(1:nr))
368 safe_allocate(this%vwr(1:nr))
369 this%r(1:nr) = r_full(1:nr)
370 this%r2(1:nr) = this%r(1:nr)**2
371 this%wr(1:nr) = ps%paw_rab(1:nr)
372 this%vwr(1:nr) = this%r2(1:nr)*this%wr(1:nr)
375 safe_allocate(this%invr(1:nr))
377 if (this%r(k) >
m_zero)
then
378 this%invr(k) =
m_one/this%r(k)
388 this%nrad = ps%paw_nwavefunctions
389 this%npair = (this%nrad*(this%nrad + 1))/2
390 safe_allocate(this%lrad(1:this%nrad))
391 this%lrad(1:this%nrad) = ps%paw_l(1:this%nrad)
392 safe_allocate(this%rad_2j(1:this%nrad))
394 if (
allocated(ps%paw_2j)) this%rad_2j(1:this%nrad) = ps%paw_2j(1:this%nrad)
395 safe_allocate(phi_ae_full(1:nr_full, 1:this%nrad))
396 safe_allocate(phi_ps_full(1:nr_full, 1:this%nrad))
399 phi_ae_full(k, i) =
spline_eval(ps%paw_phi_ae(i), r_full(k))
400 phi_ps_full(k, i) =
spline_eval(ps%paw_phi_ps(i), r_full(k))
403 safe_allocate(this%phi_ae(1:nr, 1:this%nrad))
404 safe_allocate(this%phi_ps(1:nr, 1:this%nrad))
405 this%phi_ae(1:nr, :) = phi_ae_full(1:nr, :)
406 this%phi_ps(1:nr, :) = phi_ps_full(1:nr, :)
409 this%has_small = ps%paw_has_small
410 if (this%has_small)
then
411 safe_allocate(phi_ae_small_full(1:nr_full, 1:this%nrad))
414 phi_ae_small_full(k, i) =
spline_eval(ps%paw_phi_ae_small(i), r_full(k))
417 safe_allocate(this%phi_ae_small(1:nr, 1:this%nrad))
418 this%phi_ae_small(1:nr, :) = phi_ae_small_full(1:nr, :)
421 maxl = maxval(this%lrad(1:this%nrad))
422 this%lmax_rho = 2*maxl
425 if (this%lmax_rho > 6)
then
432 this%nlm = this%nlm + 2*this%lrad(i) + 1
434 safe_allocate(this%p_rad(1:this%nlm))
435 safe_allocate(this%p_l(1:this%nlm))
436 safe_allocate(this%p_m(1:this%nlm))
439 do mm = -this%lrad(i), this%lrad(i)
442 this%p_l(ilm) = this%lrad(i)
446 assert(ilm == this%nlm)
448 this%nlm_rho = (this%lmax_rho + 1)**2
458 assert(ps%radial_augmentation_nprojectors == this%nrad)
460 assert(this%lrad(i) >= this%lrad(i-1))
462 safe_allocate(cpos(1:this%nrad))
466 if (this%lrad(j) == this%lrad(i)) pair = pair + 1
469 if (this%rad_2j(i) > 0 .and. this%lrad(i) > 0)
then
470 if (this%rad_2j(i) == 2*this%lrad(i) - 1)
then
471 cpos(i) = (pair - 1)/2*2 + 2
473 cpos(i) = (pair - 1)/2*2 + 1
476 cpos(i) = i - pair + cpos(i)
479 this%laug = ps%radial_augmentation_lmax
480 assert(this%laug >= 0)
481 safe_allocate(qaug_full(1:nr_full, 1:this%npair, 0:this%laug))
487 qaug_full(k, pair, ll) =
spline_eval(ps%radial_augmentation((cpos(i)-1)*this%nrad + cpos(j), ll), r_full(k))
492 safe_allocate(this%qaug(1:nr, 1:this%npair, 0:this%laug))
493 this%qaug(1:nr, :, :) = qaug_full(1:nr, :, :)
494 safe_deallocate_a(cpos)
497 this%has_ae_core = ps%paw_has_ae_core
499 safe_allocate(this%nc_ae(1:nr))
500 safe_allocate(this%nc_ps(1:nr))
501 safe_allocate(this%vref_ae(1:nr))
502 safe_allocate(this%vref_ps(1:nr))
506 if (this%has_ae_core) this%nc_ae(k) =
spline_eval(ps%paw_ae_core, this%r(k))
507 if (this%has_ps_core) this%nc_ps(k) =
spline_eval(ps%core, this%r(k))
508 this%vref_ae(k) =
spline_eval(ps%paw_ae_vlocal, this%r(k))
513 if (this%xc_is_gga)
then
514 safe_allocate(work(1:nr_full))
515 safe_allocate(dwork(1:nr_full))
516 safe_allocate(this%dpair_ae(1:nr, 1:this%npair))
517 safe_allocate(this%dpair_ps(1:nr, 1:this%npair))
518 safe_allocate(this%dqaug(1:nr, 1:this%npair, 0:this%laug))
522 work(:) = phi_ae_full(:, i)*phi_ae_full(:, j)
524 if (this%has_small) work(:) = work(:) + phi_ae_small_full(:, i)*phi_ae_small_full(:, j)
526 this%dpair_ae(1:nr, pair) = dwork(1:nr)
527 work(:) = phi_ps_full(:, i)*phi_ps_full(:, j)
529 this%dpair_ps(1:nr, pair) = dwork(1:nr)
532 this%dqaug(1:nr, pair, ll) = dwork(1:nr)
537 safe_allocate(this%nc_ae_der(1:nr))
538 safe_allocate(this%nc_ps_der(1:nr))
541 if (this%has_ae_core)
then
546 this%nc_ae_der(1:nr) = dwork(1:nr)
548 if (this%has_ps_core)
then
553 this%nc_ps_der(1:nr) = dwork(1:nr)
555 safe_deallocate_a(work)
556 safe_deallocate_a(dwork)
562 if (this%xc_is_mgga)
then
575 safe_deallocate_a(r_full)
576 safe_deallocate_a(phi_ae_full)
577 safe_deallocate_a(phi_ae_small_full)
578 safe_deallocate_a(phi_ps_full)
579 safe_deallocate_a(qaug_full)
593 assert(
associated(functl))
595 if (this%owns_xc_functl .and.
associated(this%xc_functl))
then
598 safe_deallocate_p(this%xc_functl)
600 this%xc_functl => functl
601 this%owns_xc_functl = .false.
611 integer,
intent(in) :: ri, rj
627 integer :: i, j, ri, rj, li, mi, lj, mj, ll, mm, pair, ig, ij, np, ipass
633 assert(this%npair == (this%nrad*(this%nrad + 1))/2)
634 safe_allocate(this%pair_ae(1:np, 1:this%npair))
635 safe_allocate(this%pair_ps(1:np, 1:this%npair))
639 this%pair_ae(:, pair) = this%phi_ae(:, i)*this%phi_ae(:, j)
640 this%pair_ps(:, pair) = this%phi_ps(:, i)*this%phi_ps(:, j)
643 if (this%has_small)
then
644 this%pair_ae(:, pair) = this%pair_ae(:, pair) + this%phi_ae_small(:, i)*this%phi_ae_small(:, j)
650 safe_allocate(this%gnt_ptr(1:this%nlm*this%nlm + 1))
662 ij = (i-1)*this%nlm + j
663 if (ipass == 2) this%gnt_ptr(ij) = ig + 1
664 do ll = abs(li-lj), min(li+lj, this%lmax_rho), 2
666 c = real_gaunt(li, mi, lj, mj, ll, mm)
670 this%gnt_pair(ig) = pair
672 this%gnt_lm(ig) = ll*(ll+1) + mm + 1
681 safe_allocate(this%gnt_pair(1:this%ngnt))
682 safe_allocate(this%gnt_l(1:this%ngnt))
683 safe_allocate(this%gnt_lm(1:this%ngnt))
684 safe_allocate(this%gnt_c(1:this%ngnt))
686 this%gnt_ptr(this%nlm*this%nlm + 1) = ig + 1
687 assert(ig == this%ngnt)
698 type(ps_t),
intent(in) :: ps
699 type(namespace_t),
intent(in) :: namespace
701 integer,
optional,
intent(in) :: xc_ids(2)
703 integer :: ixc, ids(2)
707 if (
present(xc_ids))
then
715 if (ps%exchange_functional == pseudo_exchange_unknown .or. &
716 ps%correlation_functional == pseudo_correlation_unknown)
then
717 message(1) =
"PAW one-center engine: the exchange-correlation functional of the PAW dataset"
718 message(2) =
"could not be identified. Only LDA, GGA and meta-GGA functionals are supported."
719 call messages_fatal(2, namespace=namespace)
722 ids(1) = ps%exchange_functional
723 ids(2) = ps%correlation_functional
726 this%xc_is_gga = .false.
727 this%xc_is_mgga = .false.
728 this%xc_needs_laplacian = .false.
730 safe_allocate(this%xc_functl(1:2))
731 this%owns_xc_functl = .
true.
734 if (ids(ixc) > 0)
then
735 call xc_functional_init(this%xc_functl(ixc), namespace, ids(ixc), 3, ps%z_val, this%spin_channels, .
true.)
737 call xc_functional_init(this%xc_functl(ixc), namespace, 0, 3, ps%z_val, this%spin_channels, .
true.)
740 select case (this%xc_functl(ixc)%family)
741 case (xc_family_none, xc_family_lda)
744 this%xc_is_gga = .
true.
745 case (xc_family_mgga)
746 this%xc_is_mgga = .
true.
747 this%xc_is_gga = .
true.
748 if (bitand(this%xc_functl(ixc)%flags, xc_flags_needs_laplacian) /= 0)
then
749 this%xc_needs_laplacian = .
true.
751 case (xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga)
752 call messages_not_implemented(
"PAW one-center engine with hybrid functionals", namespace=namespace)
754 call messages_not_implemented(
"PAW one-center engine with this XC functional family " // &
755 "(only LDA, GGA and meta-GGA are supported)", namespace=namespace)
782 type(ps_t),
intent(in) :: ps
783 type(namespace_t),
intent(in) :: namespace
784 real(real64),
intent(in) :: r_full(:)
785 real(real64),
intent(in) :: phi_ae_full(:,:)
786 real(real64),
intent(in) :: phi_ps_full(:,:)
788 integer :: nr, nr_full, k, i, ic, ll
789 real(real64) :: occ, c_tf, nn, q_orb, q_stored
790 real(real64),
allocatable :: phi(:), dphi(:), work(:), dwork(:), nc_der_full(:)
791 real(real64),
parameter :: tiny = 1.0e-10_real64
793 real(real64),
parameter :: core_charge_tol = 1.0e-4_real64
797 assert(this%xc_is_gga)
799 if (this%nspin == 4)
then
800 call messages_not_implemented(
"PAW meta-GGA with noncollinear spins", namespace=namespace)
804 if (this%has_small)
then
805 call messages_not_implemented(
"PAW meta-GGA with fully-relativistic (j-dependent) datasets", &
811 if (this%has_ae_core .and. ps%paw_ncore == 0)
then
812 message(1) =
"PAW meta-GGA: the dataset has an all-electron core density but no frozen-core orbitals"
813 message(2) =
"(PP_GIPAW/PP_GIPAW_CORE_ORBITALS), which are needed for the core kinetic-energy density."
814 call messages_fatal(2, namespace=namespace)
818 nr_full =
size(r_full)
820 safe_allocate(work(1:nr_full))
821 safe_allocate(dwork(1:nr_full))
824 safe_allocate(this%dphi_ae(1:nr, 1:this%nrad))
825 safe_allocate(this%dphi_ps(1:nr, 1:this%nrad))
826 if (this%xc_needs_laplacian)
then
827 safe_allocate(this%d2phi_ae(1:nr, 1:this%nrad))
828 safe_allocate(this%d2phi_ps(1:nr, 1:this%nrad))
832 this%dphi_ae(1:nr, i) = work(1:nr)
834 this%dphi_ps(1:nr, i) = work(1:nr)
835 if (this%xc_needs_laplacian)
then
837 this%d2phi_ae(1:nr, i) = work(1:nr)
839 this%d2phi_ps(1:nr, i) = work(1:nr)
843 safe_allocate(this%tau_c_ae(1:nr))
844 safe_allocate(this%tau_c_ps(1:nr))
845 this%tau_c_ae = m_zero
846 this%tau_c_ps = m_zero
852 safe_allocate(nc_der_full(1:nr_full))
854 if (ps%paw_ncore > 0)
then
855 safe_allocate(phi(1:nr_full))
856 safe_allocate(dphi(1:nr_full))
858 do ic = 1, ps%paw_ncore
859 ll = ps%paw_core_l(ic)
860 occ = real(2*(2*ll + 1), real64)
862 phi(k) = spline_eval(ps%paw_core_orbital(ic), r_full(k))
866 this%tau_c_ae(k) = this%tau_c_ae(k) + occ/(m_four*m_pi) &
867 *(dphi(k)**2 + real(ll*(ll+1), real64)*(phi(k)*this%invr(k))**2)
869 nc_der_full(:) = nc_der_full(:) + occ*m_two*phi(:)*dphi(:)/(m_four*m_pi)
870 q_orb = q_orb + occ*sum(phi(:)**2*r_full(:)**2*ps%paw_rab(1:nr_full))
872 safe_deallocate_a(phi)
873 safe_deallocate_a(dphi)
878 if (this%has_ae_core)
then
880 work(k) = spline_eval(ps%paw_ae_core, r_full(k))
882 q_stored = m_four*m_pi*sum(work(:)*r_full(:)**2*ps%paw_rab(1:nr_full))
884 if (abs(q_orb - q_stored) > core_charge_tol)
then
885 write(message(1),
'(a)')
"PAW meta-GGA: the frozen-core orbitals of the dataset do not reproduce its"
886 write(message(2),
'(a,f12.6,a,f12.6,a)')
"all-electron core density (core charge ", q_orb, &
887 " from the orbitals, ", q_stored,
" stored)."
888 message(3) =
"The core kinetic-energy density is inconsistent with the core density."
889 call messages_warning(3, namespace=namespace)
892 this%nc_ae_der(1:nr) = nc_der_full(1:nr)
897 if (this%has_ps_core)
then
898 c_tf = (m_three/m_five)*(m_three*m_pi**2)**m_twothird
902 this%tau_c_ps(k) = c_tf*nn**(m_five/m_three) &
903 + (m_one/9.0_real64)*m_fourth*this%nc_ps_der(k)**2/nn
910 if (this%xc_needs_laplacian)
then
913 safe_allocate(this%nc_ae_lapl(1:nr))
914 safe_allocate(this%nc_ps_lapl(1:nr))
915 this%nc_ae_lapl = m_zero
916 this%nc_ps_lapl = m_zero
917 if (this%has_ae_core)
then
919 work(k) = spline_eval(ps%paw_ae_core, r_full(k))
923 this%nc_ae_lapl(k) = dwork(k) + m_two*this%invr(k)*this%nc_ae_der(k)
926 if (this%has_ps_core)
then
928 work(k) = spline_eval(ps%core, r_full(k))
932 this%nc_ps_lapl(k) = dwork(k) + m_two*this%invr(k)*this%nc_ps_der(k)
937 safe_deallocate_a(work)
938 safe_deallocate_a(dwork)
939 safe_deallocate_a(nc_der_full)
946 this%tau_c_ae(1:nr) = this%tau_c_ae(1:nr)/this%spin_channels
947 this%tau_c_ps(1:nr) = this%tau_c_ps(1:nr)/this%spin_channels
948 if (this%xc_needs_laplacian)
then
949 this%nc_ae_lapl(1:nr) = this%nc_ae_lapl(1:nr)/this%spin_channels
950 this%nc_ps_lapl(1:nr) = this%nc_ps_lapl(1:nr)/this%spin_channels
968 if (this%xc_functl(ixc)%family == xc_family_none) cycle
969 if (bitand(this%xc_functl(ixc)%flags, xc_flags_have_fxc) == 0) has_kernels = .false.
970 if (bitand(this%xc_functl(ixc)%flags, xc_flags_have_kxc) == 0) has_kernels = .false.
987 real(real64),
intent(in) :: r_full(:)
988 real(real64),
intent(in) :: phi_ae_full(:,:)
989 real(real64),
intent(in) :: phi_ps_full(:,:)
991 integer :: i, j, k, nr, ll
992 real(real64),
allocatable :: uae(:,:), ups(:,:), duae(:,:), dups(:,:)
993 real(real64) :: kae, kps, cent
997 safe_allocate(uae(1:
size(r_full), 1:this%nrad))
998 safe_allocate(ups(1:
size(r_full), 1:this%nrad))
999 safe_allocate(duae(1:
size(r_full), 1:this%nrad))
1000 safe_allocate(dups(1:
size(r_full), 1:this%nrad))
1003 uae(:, i) = r_full(:) * phi_ae_full(:, i)
1004 ups(:, i) = r_full(:) * phi_ps_full(:, i)
1010 safe_allocate(this%kin_ae(1:this%nrad, 1:this%nrad))
1011 safe_allocate(this%kin_ps(1:this%nrad, 1:this%nrad))
1012 this%kin_ae = m_zero
1013 this%kin_ps = m_zero
1016 if (this%lrad(i) /= this%lrad(j)) cycle
1018 cent = real(ll*(ll+1), real64)
1026 kae = kae + (duae(k,i)*duae(k,j) + cent*uae(k,i)*uae(k,j)/this%r2(k)) * this%wr(k)
1027 kps = kps + (dups(k,i)*dups(k,j) + cent*ups(k,i)*ups(k,j)/this%r2(k)) * this%wr(k)
1029 this%kin_ae(i, j) = m_half*kae
1030 this%kin_ps(i, j) = m_half*kps
1034 safe_deallocate_a(uae)
1035 safe_deallocate_a(ups)
1036 safe_deallocate_a(duae)
1037 safe_deallocate_a(dups)
1045 real(real64),
intent(in) :: r(:)
1046 real(real64),
intent(in) ::
f(:)
1047 real(real64),
intent(out) :: df(:)
1050 type(spline_t) :: sp, dsp
1055 call spline_init(sp)
1056 call spline_init(dsp)
1057 call spline_fit(n, r,
f, sp)
1058 call spline_der(sp, dsp, m_zero)
1060 df(k) = spline_eval(dsp, r(k))
1063 call spline_end(dsp)
1072 real(real64),
intent(in) :: r(:)
1073 real(real64),
intent(in) :: f(:)
1074 real(real64),
intent(out) :: d2f(:)
1077 type(spline_t) :: sp, d2sp
1082 call spline_init(sp)
1083 call spline_init(d2sp)
1084 call spline_fit(n, r, f, sp)
1085 call spline_der2(sp, d2sp, m_zero)
1087 d2f(k) = spline_eval(d2sp, r(k))
1090 call spline_end(d2sp)
1104 integer :: ip, i0, nw, jj, kk
1105 integer,
allocatable :: first(:), last(:)
1110 assert(this%nr >= nw)
1111 safe_allocate(this%der_w(1:nw, 1:this%nr))
1112 safe_allocate(this%der_i0(1:this%nr))
1114 i0 = min(max(ip - (nw-1)/2, 1), this%nr - nw + 1)
1115 this%der_i0(ip) = i0
1119 safe_allocate(first(1:this%nr))
1120 safe_allocate(last(1:this%nr))
1125 jj = this%der_i0(ip) + kk - 1
1126 first(jj) = min(first(jj), ip)
1127 last(jj) = max(last(jj), ip)
1130 this%der_ntw = maxval(last - first + 1)
1131 safe_allocate(this%der_wt(1:this%der_ntw, 1:this%nr))
1132 safe_allocate(this%der_trow0(1:this%nr))
1133 safe_allocate(this%der_tn(1:this%nr))
1134 this%der_wt = m_zero
1135 this%der_trow0(1:this%nr) = first(1:this%nr)
1136 this%der_tn(1:this%nr) = last(1:this%nr) - first(1:this%nr) + 1
1139 jj = this%der_i0(ip) + kk - 1
1140 this%der_wt(ip - first(jj) + 1, jj) = this%der_w(kk, ip)
1143 safe_deallocate_a(first)
1144 safe_deallocate_a(last)
1153 real(real64),
intent(in) :: z
1154 real(real64),
intent(in) :: x(:)
1155 integer,
intent(in) :: n
1156 real(real64),
intent(out) :: w(:)
1158 integer :: i, j, k, mn
1159 real(real64) :: c1, c2, c3, c4, c5
1160 real(real64) :: c(n, 0:1)
1176 if (j == i - 1)
then
1178 c(i, k) = c1*(real(k, real64)*c(i-1, k-1) - c5*c(i-1, k))/c2
1180 c(i, 0) = -c1*c5*c(i-1, 0)/c2
1183 c(j, k) = (c4*c(j, k) - real(k, real64)*c(j, k-1))/c3
1185 c(j, 0) = c4*c(j, 0)/c3
1198 real(real64),
intent(in) :: f(:)
1199 real(real64),
intent(out) :: df(:)
1201 integer :: ip, k, i0
1207 i0 = this%der_i0(ip)
1209 do k = 1, this%der_nw
1210 acc = acc + this%der_w(k, ip)*f(i0 + k - 1)
1222 real(real64),
allocatable,
intent(out) :: r(:)
1226 safe_allocate(r(1:this%nr))
1227 r(1:this%nr) = this%r(1:this%nr)
1240 real(real64),
intent(in) :: f(:)
1241 real(real64),
intent(out) :: df(:)
1243 integer :: ip, k, i0
1249 i0 = this%der_trow0(ip)
1251 do k = 1, this%der_tn(ip)
1252 acc = acc + this%der_wt(k, ip)*f(i0 + k - 1)
1265 integer :: nth, nphi, ith, iphi, ia, ll, mm, lm
1266 real(real64),
allocatable :: gx(:), gw(:)
1267 real(real64) :: dphi, phi, sinth, costh, xx(3), y, dyth, dyph
1273 nth = this%lmax_rho + 6
1274 nphi = 2*this%lmax_rho + 3
1275 this%nang = nth*nphi
1276 assert(this%nlm_rho == (this%lmax_rho + 1)**2)
1278 safe_allocate(gx(1:nth))
1279 safe_allocate(gw(1:nth))
1280 call gauss_legendre_newton(nth, gx, gw)
1282 safe_allocate(this%wang(1:this%nang))
1283 safe_allocate(this%ylm(1:this%nang, 1:this%nlm_rho))
1287 safe_allocate(this%dylm_dth(1:this%nang, 1:this%nlm_rho))
1288 safe_allocate(this%dylm_dph(1:this%nang, 1:this%nlm_rho))
1289 safe_allocate(this%rhat(1:this%nang, 1:3))
1290 safe_allocate(this%that(1:this%nang, 1:3))
1291 safe_allocate(this%phat(1:this%nang, 1:3))
1293 dphi = m_two*m_pi/real(nphi, real64)
1297 sinth =
sqrt(max(m_one - costh**2, m_zero))
1300 phi = (real(iphi, real64) - m_half)*dphi
1301 xx(1) = sinth*
cos(phi)
1302 xx(2) = sinth*
sin(phi)
1305 this%rhat(ia, 1:3) = xx(1:3)
1306 this%that(ia, 1) = costh*
cos(phi)
1307 this%that(ia, 2) = costh*
sin(phi)
1308 this%that(ia, 3) = -sinth
1309 this%phat(ia, 1) = -
sin(phi)
1311 this%phat(ia, 3) = m_zero
1312 this%wang(ia) = gw(ith)*dphi
1313 do ll = 0, this%lmax_rho
1315 lm = ll*(ll+1) + mm + 1
1317 call ylmr_real_with_grad(xx, ll, mm, y, dyth, dyph)
1318 this%ylm(ia, lm) = y
1319 this%dylm_dth(ia, lm) = dyth
1320 this%dylm_dph(ia, lm) = dyph
1325 assert(ia == this%nang)
1329 safe_allocate(this%wylm(1:this%nang, 1:this%nlm_rho))
1330 safe_allocate(this%wdylm_dth(1:this%nang, 1:this%nlm_rho))
1331 safe_allocate(this%wdylm_dph(1:this%nang, 1:this%nlm_rho))
1332 do lm = 1, this%nlm_rho
1333 do ia = 1, this%nang
1334 this%wylm(ia, lm) = this%wang(ia)*this%ylm(ia, lm)
1335 this%wdylm_dth(ia, lm) = this%wang(ia)*this%dylm_dth(ia, lm)
1336 this%wdylm_dph(ia, lm) = this%wang(ia)*this%dylm_dph(ia, lm)
1340 safe_deallocate_a(gx)
1341 safe_deallocate_a(gw)
1354 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
1355 real(real64),
intent(out) :: e1
1356 real(real64),
intent(out) :: e1t
1357 real(real64),
contiguous,
intent(out) :: dij(:,:,:)
1360 logical,
optional,
intent(in) :: hxc_only
1362 real(real64) :: e_ae, e_ps, kae, kps
1363 real(real64),
allocatable :: d_ae(:,:,:), d_ps(:,:,:)
1365 logical :: hxc_only_
1369 hxc_only_ = optional_default(hxc_only, .false.)
1371 safe_allocate(d_ae(1:this%nlm, 1:this%nlm, 1:this%nspin))
1372 safe_allocate(d_ps(1:this%nlm, 1:this%nlm, 1:this%nspin))
1381 dij(:, :, :) = d_ae(:, :, :) - d_ps(:, :, :)
1386 if (.not. hxc_only_)
then
1387 do is = 1, this%spin_channels
1390 if (this%p_l(i) /= this%p_l(j) .or. this%p_m(i) /= this%p_m(j)) cycle
1391 kae = this%kin_ae(this%p_rad(i), this%p_rad(j))
1392 kps = this%kin_ps(this%p_rad(i), this%p_rad(j))
1393 dij(i, j, is) = dij(i, j, is) + kae - kps
1394 e1 = e1 + rho(i, j, is)*kae
1395 e1t = e1t + rho(i, j, is)*kps
1401 safe_deallocate_a(d_ae)
1402 safe_deallocate_a(d_ps)
1413 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
1414 logical,
intent(in) :: ae
1415 real(real64),
intent(out) :: energy
1416 real(real64),
contiguous,
intent(out) :: dij(:,:,:)
1419 logical,
optional,
intent(in) :: hxc_only
1421 integer :: nr, nlmr, lm, k, is
1422 logical :: xc_with_comp, hxc_only_, need_der
1423 real(real64),
allocatable :: nlm_rho(:,:,:)
1424 real(real64),
allocatable :: nlm_xc(:,:,:)
1425 real(real64),
allocatable :: nlm_xc_der(:,:,:)
1426 real(real64),
allocatable :: nlm_tot(:,:)
1427 real(real64),
allocatable :: vlm(:,:)
1428 real(real64),
allocatable :: vref(:), ncore(:)
1429 real(real64) :: e_h, e_ref, e_xc, sqrt4pi
1435 sqrt4pi =
sqrt(m_four*m_pi)
1436 hxc_only_ = optional_default(hxc_only, .false.)
1443 xc_with_comp = (.not. ae) .and. (this%formulation ==
paw_kresse_joubert) .and. this%usexcnhat
1445 safe_allocate(nlm_rho(1:nr, 1:nlmr, 1:this%nspin))
1446 safe_allocate(nlm_xc(1:nr, 1:nlmr, 1:this%nspin))
1447 safe_allocate(nlm_tot(1:nr, 1:nlmr))
1448 safe_allocate(vlm(1:nr, 1:nlmr))
1449 safe_allocate(vref(1:nr))
1450 safe_allocate(ncore(1:nr))
1454 vref(:) = this%vref_ae(:)
1455 ncore(:) = this%nc_ae(:)/this%spin_channels
1457 vref(:) = this%vref_ps(:)
1458 ncore(:) = this%nc_ps(:)/this%spin_channels
1465 need_der = this%xc_is_gga .and. this%xc_scheme ==
paw_xc_scheme_full .and. .not. this%xc_is_mgga
1467 safe_allocate(nlm_xc_der(1:nr, 1:nlmr, 1:this%nspin))
1469 do is = 1, this%nspin
1472 call paw_build_density(this, rho(:,:,is), ae, xc_with_comp, nlm_xc(:,:,is), nlm_xc_der(:,:,is))
1473 else if (xc_with_comp .eqv. (.not. ae))
then
1474 nlm_xc(:,:,is) = nlm_rho(:,:,is)
1480 nlm_tot = nlm_rho(:,:,1)
1481 do is = 2, this%spin_channels
1482 nlm_tot = nlm_tot + nlm_rho(:,:,is)
1490 e_h = e_h + m_half*nlm_tot(k, lm)*vlm(k, lm)*this%vwr(k)
1499 if (.not. hxc_only_)
then
1501 e_ref = e_ref + sqrt4pi*vref(k)*nlm_tot(k, 1)*this%vwr(k)
1504 call lalg_axpy(nr, sqrt4pi, vref, vlm(:, 1))
1509 do is = 1, this%spin_channels
1515 call paw_xc_moments(this, nlm_xc, ncore, ae, xc_with_comp, e_xc, dij)
1517 call paw_xc(this, nlm_xc, nlm_xc_der, rho, ncore, ae, xc_with_comp, e_xc, dij)
1520 energy = e_h + e_ref + e_xc
1522 safe_deallocate_a(nlm_rho)
1523 safe_deallocate_a(nlm_xc)
1524 safe_deallocate_a(nlm_xc_der)
1525 safe_deallocate_a(nlm_tot)
1526 safe_deallocate_a(vlm)
1527 safe_deallocate_a(vref)
1528 safe_deallocate_a(ncore)
1546 real(real64),
contiguous,
intent(in) :: rho(:,:)
1547 logical,
intent(in) :: ae
1548 logical,
intent(in) :: with_comp
1549 real(real64),
contiguous,
intent(out) :: nlm_rho(:,:)
1550 real(real64),
contiguous,
optional,
intent(out) :: nlm_der(:,:)
1552 integer :: i, j, ij, ig
1553 real(real64) :: rho_ij
1554 real(real64),
allocatable :: cmat(:,:)
1558 assert(.not.
present(nlm_der) .or. this%xc_is_gga)
1563 safe_allocate(cmat(1:this%npair, 1:this%nlm_rho))
1568 if (j > i) rho_ij = rho_ij + rho(j, i)
1569 if (abs(rho_ij) <= m_epsilon) cycle
1570 ij = (i-1)*this%nlm + j
1571 do ig = this%gnt_ptr(ij), this%gnt_ptr(ij+1) - 1
1572 cmat(this%gnt_pair(ig), this%gnt_lm(ig)) = cmat(this%gnt_pair(ig), this%gnt_lm(ig)) &
1573 + rho_ij*this%gnt_c(ig)
1579 call lalg_gemm(this%pair_ae, cmat, nlm_rho)
1580 if (
present(nlm_der))
call lalg_gemm(this%dpair_ae, cmat, nlm_der)
1582 call lalg_gemm(this%pair_ps, cmat, nlm_rho)
1583 if (
present(nlm_der))
call lalg_gemm(this%dpair_ps, cmat, nlm_der)
1586 if (
present(nlm_der))
call paw_qaug_gemv(this, this%dqaug,
'N', cmat, nlm_der)
1590 safe_deallocate_a(cmat)
1602 real(real64),
contiguous,
intent(in) :: qtab(:, :, 0:)
1603 character(1),
intent(in) :: trans
1604 real(real64),
contiguous,
intent(in) :: xx(:, :)
1605 real(real64),
contiguous,
intent(inout) :: yy(:, :)
1611 do lm = 1, this%nlm_rho
1612 ll = int(
sqrt(real(lm-1, real64)))
1613 if (ll > this%laug) cycle
1614 call blas_gemv(trans, this%nr, this%npair, m_one, qtab(1, 1, ll), this%nr, &
1615 xx(1, lm), 1, m_one, yy(1, lm), 1)
1625 real(real64),
contiguous,
intent(in) :: w(:, :)
1626 real(real64),
contiguous,
intent(inout) :: dij(:, :)
1628 integer :: i, j, ij, ig
1635 ij = (i-1)*this%nlm + j
1637 do ig = this%gnt_ptr(ij), this%gnt_ptr(ij+1) - 1
1638 acc = acc + this%gnt_c(ig)*w(this%gnt_pair(ig), this%gnt_lm(ig))
1640 dij(i, j) = dij(i, j) + acc
1641 if (j > i) dij(j, i) = dij(j, i) + acc
1652 real(real64),
contiguous,
intent(in) :: field_lm(:, :)
1653 real(real64),
intent(in) :: tol
1654 integer,
intent(out) :: ncol
1655 type(spline_t),
allocatable,
intent(out) :: spl(:)
1656 integer,
allocatable,
intent(out) :: ll(:)
1657 integer,
allocatable,
intent(out) :: mm(:)
1658 real(real64),
intent(out) :: rcut
1664 safe_allocate(spl(1:this%nlm_rho))
1665 safe_allocate(ll(1:this%nlm_rho))
1666 safe_allocate(mm(1:this%nlm_rho))
1668 do lm = 1, this%nlm_rho
1669 if (maxval(abs(field_lm(:, lm))) <= tol) cycle
1671 l0 = int(
sqrt(real(lm-1, real64)))
1673 mm(ncol) = lm - l0*(l0+1) - 1
1674 call spline_init(spl(ncol))
1675 call spline_fit(this%nr, this%r, field_lm(:, lm), spl(ncol))
1677 rcut = this%r(this%nr)
1687 real(real64),
contiguous,
intent(out) :: dphi_ae(:, :)
1688 real(real64),
contiguous,
intent(out) :: dphi_ps(:, :)
1709 real(real64),
contiguous,
intent(in) :: flux(:)
1710 real(real64),
contiguous,
intent(inout) :: div(:)
1711 real(real64),
contiguous,
intent(inout) :: vfield(:)
1719 if (this%vwr(ip) > m_zero)
then
1720 vfield(ip) = vfield(ip) + div(ip)/this%vwr(ip)
1729 integer,
intent(in) :: nprojs
1730 integer,
intent(in) :: map(:)
1731 real(real64),
contiguous,
intent(in) :: src(:, :)
1732 real(real64),
contiguous,
intent(out) :: dst(:, :)
1734 integer :: iproj, jproj
1738 do jproj = 1, nprojs
1739 do iproj = 1, nprojs
1740 dst(map(iproj), map(jproj)) = src(iproj, jproj)
1752 integer,
intent(in) :: lm
1753 real(real64),
intent(in) :: nl(:)
1754 real(real64),
intent(out) :: vl(:)
1756 integer :: k, nr, ll
1757 real(real64) :: pref, inner, outer, ti, to
1758 real(real64),
allocatable :: cum_in(:)
1763 ll = int(
sqrt(real(lm-1, real64)))
1764 pref = m_four*m_pi/real(2*ll+1, real64)
1766 safe_allocate(cum_in(1:nr))
1770 ti = nl(k)*this%r(k)**(ll+2)*this%wr(k)
1772 cum_in(k) = inner - m_half*ti
1778 if (this%r(k) > m_zero)
then
1779 to = nl(k)*this%r(k)**(1-ll)*this%wr(k)
1784 if (this%r(k) > m_zero)
then
1785 vl(k) = pref*( cum_in(k)/this%r(k)**(ll+1) + (outer - m_half*to)*this%r(k)**ll )
1789 if (this%r(1) <= m_zero) vl(1) = vl(2)
1791 safe_deallocate_a(cum_in)
1818 subroutine paw_xc(this, nlm_rho, nlm_der, rho, ncore, ae, with_comp, e_xc, dij)
1820 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
1822 real(real64),
optional,
contiguous,
intent(in) :: nlm_der(:,:,:)
1823 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
1824 real(real64),
contiguous,
intent(in) :: ncore(:)
1825 logical,
intent(in) :: ae
1826 logical,
intent(in) :: with_comp
1827 real(real64),
intent(out) :: e_xc
1828 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
1830 logical :: gga, mgga, mgga_exc, needs_lapl
1831 integer :: np, npa, ibase, ip, ia, is, nsp, nsig
1832 real(real64) :: ntot
1833 real(real64),
allocatable :: ncder(:)
1837 real(real64),
allocatable :: dens(:,:)
1838 real(real64),
allocatable :: densp(:,:)
1839 real(real64),
allocatable :: sigma(:,:)
1840 real(real64),
allocatable :: dpol(:)
1841 real(real64),
allocatable :: exc(:), vs(:,:)
1842 real(real64),
allocatable,
target :: vr(:,:)
1843 real(real64),
allocatable :: g(:,:,:,:)
1844 real(real64),
allocatable :: gp(:,:,:,:)
1845 real(real64),
allocatable :: vxc_lm(:,:,:)
1846 real(real64),
allocatable :: tau(:,:), lapl(:,:)
1847 real(real64),
allocatable :: vtau(:,:), vlapl(:,:)
1848 real(real64),
pointer :: phi_pw(:,:), dphi_pw(:,:), d2phi_pw(:,:)
1849 real(real64),
pointer :: vmat(:,:)
1851 push_sub_with_profile(
paw_xc)
1853 gga = this%xc_is_gga
1854 mgga = this%xc_is_mgga
1855 needs_lapl = this%xc_needs_laplacian
1858 nsp = this%spin_channels
1861 safe_allocate(dens(1:npa, 1:this%nspin))
1862 safe_allocate(densp(1:npa, 1:nsp))
1863 safe_allocate(sigma(1:npa, 1:nsig))
1864 safe_allocate(exc(1:npa))
1865 safe_allocate(vr(1:npa, 1:this%nspin))
1866 safe_allocate(vs(1:npa, 1:nsig))
1869 safe_allocate(dpol(1:npa))
1873 safe_allocate(tau(1:npa, 1:nsp))
1874 safe_allocate(lapl(1:npa, 1:nsp))
1876 phi_pw => this%phi_ae
1877 dphi_pw => this%dphi_ae
1878 if (needs_lapl) d2phi_pw => this%d2phi_ae
1880 phi_pw => this%phi_ps
1881 dphi_pw => this%dphi_ps
1882 if (needs_lapl) d2phi_pw => this%d2phi_ps
1889 safe_allocate(ncder(1:np))
1891 ncder(:) = this%nc_ae_der(:)/this%spin_channels
1893 ncder(:) = this%nc_ps_der(:)/this%spin_channels
1895 safe_allocate(g(1:np, 1:this%nspin, 1:this%nang, 1:3))
1896 safe_allocate(gp(1:np, 1:nsp, 1:this%nang, 1:3))
1899 if (needs_lapl)
then
1901 ncore=ncore, ncder=ncder, dens=dens, gn=g, tau=tau, lapl=lapl)
1904 ncore=ncore, ncder=ncder, dens=dens, gn=g, tau=tau)
1907 densp(1:npa, 1:nsp) = dens(1:npa, 1:nsp)
1909 assert(
present(nlm_der))
1917 safe_allocate(vtau(1:npa, 1:nsp))
1918 safe_allocate(vlapl(1:npa, 1:nsp))
1919 call paw_xc_eval(this, npa, nsp, nsig, densp, sigma, exc, vr(:, 1:nsp), vs, &
1920 lapl=lapl, tau=tau, vlapl=vlapl, vtau=vtau, mgga_exc=mgga_exc)
1923 call paw_xc_eval(this, npa, nsp, nsig, densp, sigma, exc, vr(:, 1:nsp), vs)
1929 do ia = 1, this%nang
1934 ntot = ntot + max(densp(ibase + ip, is), m_zero)
1936 e_xc = e_xc + ntot*exc(ibase + ip)*this%vwr(ip)*this%wang(ia)
1946 if (mgga_exc .and. needs_lapl)
then
1947 call paw_xc_mgga_dij(this, phi_pw, dphi_pw, g, vr, vs, dij, vtau=vtau, d2phi=d2phi_pw, vlapl=vlapl)
1948 else if (mgga_exc)
then
1949 call paw_xc_mgga_dij(this, phi_pw, dphi_pw, g, vr, vs, dij, vtau=vtau)
1950 else if (needs_lapl)
then
1951 call paw_xc_mgga_dij(this, phi_pw, dphi_pw, g, vr, vs, dij, d2phi=d2phi_pw, vlapl=vlapl)
1962 safe_allocate(vxc_lm(1:np, 1:this%nlm_rho, 1:this%nspin))
1963 do is = 1, this%nspin
1964 vmat(1:np, 1:this%nang) => vr(:, is)
1965 call lalg_gemm(np, this%nlm_rho, this%nang, m_one, vmat, this%wylm, m_zero, vxc_lm(:, :, is))
1967 do is = 1, this%nspin
1972 safe_deallocate_a(dens)
1973 safe_deallocate_a(densp)
1974 safe_deallocate_a(sigma)
1975 safe_deallocate_a(dpol)
1976 safe_deallocate_a(exc)
1977 safe_deallocate_a(vr)
1978 safe_deallocate_a(vs)
1979 safe_deallocate_a(ncder)
1980 safe_deallocate_a(g)
1981 safe_deallocate_a(gp)
1982 safe_deallocate_a(vxc_lm)
1983 safe_deallocate_a(tau)
1984 safe_deallocate_a(vtau)
1985 safe_deallocate_a(lapl)
1986 safe_deallocate_a(vlapl)
1988 pop_sub_with_profile(
paw_xc)
1995 subroutine paw_xc_density(this, nlm_rho, ncore, dens, densp, dpol)
1997 real(real64),
intent(in) :: nlm_rho(:,:,:)
1998 real(real64),
intent(in) :: ncore(:)
1999 real(real64),
contiguous,
intent(out) :: dens(:,:)
2000 real(real64),
contiguous,
intent(out) :: densp(:,:)
2001 real(real64),
contiguous,
intent(out) :: dpol(:)
2003 integer :: np, ibase, ip, ia, ic
2011 do ia = 1, this%nang
2013 do ic = 1, this%nspin
2016 dens(ibase + ip, ic) = ncore(ip)
2020 dens(ibase + ip, ic) = m_zero
2023 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
2024 this%ylm(ia, 1), this%nang, m_one, dens(ibase + 1, ic), 1)
2028 if (this%nspin == 4)
then
2030 do ip = 1, np*this%nang
2032 densp(ip, 1) = m_half*(dens(ip, 1) + dens(ip, 2) + dpol(ip))
2033 densp(ip, 2) = m_half*(dens(ip, 1) + dens(ip, 2) - dpol(ip))
2036 do ic = 1, this%spin_channels
2037 call lalg_copy(np*this%nang, dens(:, ic), densp(:, ic))
2054 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
2055 real(real64),
contiguous,
intent(in) :: nlm_der(:,:,:)
2056 real(real64),
contiguous,
intent(in) :: ncder(:)
2057 real(real64),
contiguous,
intent(out) :: g(:,:,:,:)
2059 integer :: np, ip, ia, ic
2065 do ia = 1, this%nang
2066 do ic = 1, this%nspin
2069 g(ip, ic, ia, 1) = ncder(ip)
2073 g(ip, ic, ia, 1) = m_zero
2076 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_der(1, 1, ic), np, &
2077 this%ylm(ia, 1), this%nang, m_one, g(1, ic, ia, 1), 1)
2078 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
2079 this%dylm_dth(ia, 1), this%nang, m_zero, g(1, ic, ia, 2), 1)
2080 call blas_gemv(
'N', np, this%nlm_rho, m_one, nlm_rho(1, 1, ic), np, &
2081 this%dylm_dph(ia, 1), this%nang, m_zero, g(1, ic, ia, 3), 1)
2083 g(ip, ic, ia, 2) = g(ip, ic, ia, 2)*this%invr(ip)
2084 g(ip, ic, ia, 3) = g(ip, ic, ia, 3)*this%invr(ip)
2096 subroutine paw_xc_sigma(this, dens, dpol, g, gp, sigma)
2098 real(real64),
contiguous,
intent(in) :: dens(:,:)
2099 real(real64),
contiguous,
intent(in) :: dpol(:)
2100 real(real64),
contiguous,
intent(in) :: g(:,:,:,:)
2101 real(real64),
contiguous,
intent(out) :: gp(:,:,:,:)
2102 real(real64),
contiguous,
intent(out) :: sigma(:,:)
2104 integer :: np, ibase, ip, ia, k
2105 real(real64) :: uu, gq
2111 if (this%nspin == 4)
then
2113 do ia = 1, this%nang
2116 uu = dens(ibase + ip, 1) - dens(ibase + ip, 2)
2118 if (dpol(ibase + ip) > m_zero)
then
2119 gq = (uu*(g(ip, 1, ia, k) - g(ip, 2, ia, k)) &
2120 + m_four*(dens(ibase + ip, 3)*g(ip, 3, ia, k) &
2121 + dens(ibase + ip, 4)*g(ip, 4, ia, k)))/dpol(ibase + ip)
2125 gp(ip, 1, ia, k) = m_half*(g(ip, 1, ia, k) + g(ip, 2, ia, k) + gq)
2126 gp(ip, 2, ia, k) = m_half*(g(ip, 1, ia, k) + g(ip, 2, ia, k) - gq)
2131 gp(:, :, :, :) = g(:, :, :, :)
2135 do ia = 1, this%nang
2138 sigma(ibase + ip, 1) = gp(ip,1,ia,1)**2 + gp(ip,1,ia,2)**2 + gp(ip,1,ia,3)**2
2139 if (this%spin_channels == 2)
then
2140 sigma(ibase + ip, 2) = gp(ip,1,ia,1)*gp(ip,2,ia,1) + gp(ip,1,ia,2)*gp(ip,2,ia,2) &
2141 + gp(ip,1,ia,3)*gp(ip,2,ia,3)
2142 sigma(ibase + ip, 3) = gp(ip,2,ia,1)**2 + gp(ip,2,ia,2)**2 + gp(ip,2,ia,3)**2
2154 real(real64),
contiguous,
intent(in) :: dens(:,:)
2155 real(real64),
contiguous,
intent(inout) :: vr(:,:)
2158 real(real64) :: dpol, fwp(4, 2), v1, v2
2160 if (this%nspin /= 4)
return
2165 do ip = 1, this%nr*this%nang
2170 vr(ip, ic) = fwp(ic, 1)*v1 + fwp(ic, 2)*v2
2181 logical,
intent(in) :: ae
2182 logical,
intent(in) :: with_comp
2183 real(real64),
contiguous,
intent(in) :: dens(:,:)
2184 real(real64),
contiguous,
intent(in) :: g(:,:,:,:), gp(:,:,:,:)
2185 real(real64),
contiguous,
intent(in) :: vr(:,:), vs(:,:)
2186 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2188 integer :: np, ibase, ip, ia, is, os, iss
2189 real(real64),
allocatable :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
2193 if (this%nspin == 4)
then
2200 safe_allocate(a1(1:np, 1:this%nang, 1:this%nspin))
2201 safe_allocate(a2(1:np, 1:this%nang, 1:this%nspin))
2202 safe_allocate(a3(1:np, 1:this%nang, 1:this%nspin))
2203 safe_allocate(a4(1:np, 1:this%nang, 1:this%nspin))
2206 do is = 1, this%nspin
2208 do ia = 1, this%nang
2210 os = min(this%nspin, 3 - is)
2212 if (this%nspin == 1)
then
2214 a1(ip, ia, 1) = vr(ibase + ip, 1)
2215 a2(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 1)
2216 a3(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 2)
2217 a4(ip, ia, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, 3)
2221 a1(ip, ia, is) = vr(ibase + ip, is)
2222 a2(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 1) + vs(ibase + ip, 2)*gp(ip, os, ia, 1)
2223 a3(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 2) + vs(ibase + ip, 2)*gp(ip, os, ia, 2)
2224 a4(ip, ia, is) = m_two*vs(ibase + ip, iss)*gp(ip, is, ia, 3) + vs(ibase + ip, 2)*gp(ip, os, ia, 3)
2233 safe_deallocate_a(a1)
2234 safe_deallocate_a(a2)
2235 safe_deallocate_a(a3)
2236 safe_deallocate_a(a4)
2245 subroutine paw_xc_eval(this, np, nsp, nsig, dens, sigma, exc, vrho, vsigma, lapl, tau, vlapl, vtau, mgga_exc)
2247 integer,
intent(in) :: np, nsp, nsig
2248 real(real64),
contiguous,
intent(in) :: dens(:,:)
2249 real(real64),
contiguous,
intent(in) :: sigma(:,:)
2250 real(real64),
contiguous,
intent(out) :: exc(:)
2251 real(real64),
contiguous,
intent(out) :: vrho(:,:)
2252 real(real64),
contiguous,
intent(out) :: vsigma(:,:)
2253 real(real64),
contiguous,
optional,
intent(in) :: lapl(:,:)
2254 real(real64),
contiguous,
optional,
intent(in) :: tau(:,:)
2255 real(real64),
contiguous,
optional,
intent(out) :: vlapl(:,:)
2256 real(real64),
contiguous,
optional,
intent(out) :: vtau(:,:)
2258 logical,
optional,
intent(out) :: mgga_exc
2260 integer,
parameter :: block_size = 4096
2261 integer :: ib, nblock, ixc
2265 assert(
present(tau) .eqv. this%xc_is_mgga)
2267 if (
present(mgga_exc))
then
2270 if (this%xc_functl(ixc)%family /= xc_family_none .and. &
2271 xc_functional_is_energy_functional(this%xc_functl(ixc))) mgga_exc = .
true.
2275 nblock = (np + block_size - 1)/block_size
2279 call paw_xc_eval_block(this, np, (ib - 1)*block_size, min(block_size, np - (ib - 1)*block_size), &
2280 nsp, nsig, dens, sigma, exc, vrho, vsigma, lapl, tau, vlapl, vtau)
2288 subroutine paw_xc_eval_block(this, np, ip0, bs, nsp, nsig, dens, sigma, exc, vrho, vsigma, lapl, tau, vlapl, vtau)
2290 integer,
intent(in) :: np, ip0, bs, nsp, nsig
2291 real(real64),
contiguous,
intent(in) :: dens(:,:)
2292 real(real64),
contiguous,
intent(in) :: sigma(:,:)
2293 real(real64),
contiguous,
intent(out) :: exc(:)
2294 real(real64),
contiguous,
intent(out) :: vrho(:,:)
2295 real(real64),
contiguous,
intent(out) :: vsigma(:,:)
2296 real(real64),
contiguous,
optional,
intent(in) :: lapl(:,:)
2297 real(real64),
contiguous,
optional,
intent(in) :: tau(:,:)
2298 real(real64),
contiguous,
optional,
intent(out) :: vlapl(:,:)
2299 real(real64),
contiguous,
optional,
intent(out) :: vtau(:,:)
2301 integer :: ixc, ip, is
2302 logical :: mgga, is_efunc
2303 real(real64) :: ntot
2304 real(real64) :: dclamp(nsp, bs), ssig(nsig, bs)
2305 real(real64) :: eb(bs), vb(nsp, bs), vsb(nsig, bs)
2306 real(real64) :: ez(bs), vz(nsp, bs), vsz(nsig, bs)
2308 real(real64) :: lb(nsp, bs), tb(nsp, bs), vlb(nsp, bs), vtb(nsp, bs), vlz(nsp, bs), vtz(nsp, bs)
2316 dclamp(is, ip) = max(dens(ip0 + ip, is), m_zero)
2319 if (this%xc_is_gga)
then
2322 ssig(is, ip) = sigma(ip0 + ip, is)
2329 lb(is, ip) = lapl(ip0 + ip, is)
2330 tb(is, ip) = m_half*tau(ip0 + ip, is)
2342 is_efunc = xc_functional_is_energy_functional(this%xc_functl(ixc))
2343 select case (this%xc_functl(ixc)%family)
2344 case (xc_family_none)
2346 case (xc_family_lda)
2347 call xc_f03_lda_exc_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ez, vz)
2348 case (xc_family_gga)
2349 call xc_f03_gga_exc_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ssig, &
2351 case (xc_family_mgga)
2353 call xc_f03_mgga_exc_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ssig, lb, tb, &
2354 ez, vz, vsz, vlz, vtz)
2357 call xc_f03_mgga_vxc(this%xc_functl(ixc)%conf, int(bs, c_size_t), dclamp, ssig, lb, tb, &
2361 message(1) =
"PAW one-center engine: unsupported XC functional family."
2362 call messages_fatal(1)
2370 vb(is, ip) = vb(is, ip) + vz(is, ip)
2373 if (.not. is_efunc) cycle
2375 eb(ip) = eb(ip) + ez(ip)
2377 if (this%xc_functl(ixc)%family == xc_family_gga .or. this%xc_functl(ixc)%family == xc_family_mgga)
then
2380 vsb(is, ip) = vsb(is, ip) + vsz(is, ip)
2388 vlb(is, ip) = vlb(is, ip) + vlz(is, ip)
2389 vtb(is, ip) = vtb(is, ip) + m_half*vtz(is, ip)
2404 if (dens(ip0 + ip, is) < m_zero) vb(is, ip) = m_zero
2405 ntot = ntot + dclamp(is, ip)
2407 if (ntot < m_epsilon)
then
2416 exc(ip0 + ip) = eb(ip)
2418 vrho(ip0 + ip, is) = vb(is, ip)
2421 vsigma(ip0 + ip, is) = vsb(is, ip)
2425 vlapl(ip0 + ip, is) = vlb(is, ip)
2426 vtau(ip0 + ip, is) = vtb(is, ip)
2446 subroutine paw_xc_quantities(this, rho, ae, phi, dphi, d2phi, ncore, ncder, dens, gn, tau, lapl)
2448 real(real64),
contiguous,
intent(in) :: rho(:,:,:)
2449 logical,
intent(in) :: ae
2450 real(real64),
contiguous,
intent(in) :: phi(:,:)
2451 real(real64),
contiguous,
intent(in) :: dphi(:,:)
2452 real(real64),
contiguous,
optional,
intent(in) :: d2phi(:,:)
2453 real(real64),
contiguous,
optional,
intent(in) :: ncore(:)
2454 real(real64),
contiguous,
optional,
intent(in) :: ncder(:)
2455 real(real64),
contiguous,
optional,
intent(out) :: dens(:,:)
2456 real(real64),
contiguous,
optional,
intent(out) :: gn(:,:,:,:)
2457 real(real64),
contiguous,
optional,
intent(out) :: tau(:,:)
2458 real(real64),
contiguous,
optional,
intent(out) :: lapl(:,:)
2460 integer :: np, nsp, is, i, j, ip, ia, ri, rj, lmi, lmj, ibase
2461 real(real64) :: rho_ij, yi, yj, dti, dtj, dpi, dpj, cr, ct, cp, cv, cl, pij, rp, rpp
2462 logical :: ld, lg, lt, ll
2463 real(real64),
pointer :: tcore(:), nclapl(:)
2464 real(real64),
parameter :: tol = 1.0e-14_real64
2469 nsp = this%spin_channels
2475 tcore => this%tau_c_ae
2476 nclapl => this%nc_ae_lapl
2478 tcore => this%tau_c_ps
2479 nclapl => this%nc_ps_lapl
2484 if (ld) dens(1:np*this%nang, 1:this%nspin) = m_zero
2485 if (lg) gn(1:np, 1:this%nspin, 1:this%nang, 1:3) = m_zero
2486 if (lt) tau(1:np*this%nang, 1:this%nspin) = m_zero
2487 if (ll) lapl(1:np*this%nang, 1:this%nspin) = m_zero
2489 do ia = 1, this%nang
2492 if (ld) dens(ibase + ip, is) = ncore(ip)
2493 if (lg) gn(ip, is, ia, 1) = ncder(ip)
2494 if (lt) tau(ibase + ip, is) = tcore(ip)
2495 if (ll) lapl(ibase + ip, is) = nclapl(ip)
2501 do is = 1, this%nspin
2502 do ia = 1, this%nang
2506 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
2508 rho_ij = rho(i, j, is)
2509 if (abs(rho_ij) <= tol) cycle
2511 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
2512 yi = this%ylm(ia, lmi)
2513 yj = this%ylm(ia, lmj)
2514 dti = this%dylm_dth(ia, lmi)
2515 dtj = this%dylm_dth(ia, lmj)
2516 dpi = this%dylm_dph(ia, lmi)
2517 dpj = this%dylm_dph(ia, lmj)
2519 ct = rho_ij*(dti*yj + yi*dtj)
2520 cp = rho_ij*(dpi*yj + yi*dpj)
2521 cv = rho_ij*(dti*dtj + dpi*dpj)
2522 cl = rho_ij*(-real(this%p_l(i)*(this%p_l(i)+1) + this%p_l(j)*(this%p_l(j)+1), real64)*yi*yj &
2523 + m_two*(dti*dtj + dpi*dpj))
2525 pij = phi(ip, ri)*phi(ip, rj)
2526 if (ld) dens(ibase + ip, is) = dens(ibase + ip, is) + cr*pij
2527 if (lg .or. ll) rp = dphi(ip, ri)*phi(ip, rj) + phi(ip, ri)*dphi(ip, rj)
2529 gn(ip, is, ia, 1) = gn(ip, is, ia, 1) + cr*rp
2530 gn(ip, is, ia, 2) = gn(ip, is, ia, 2) + ct*pij*this%invr(ip)
2531 gn(ip, is, ia, 3) = gn(ip, is, ia, 3) + cp*pij*this%invr(ip)
2533 if (lt) tau(ibase + ip, is) = tau(ibase + ip, is) &
2534 + cr*dphi(ip, ri)*dphi(ip, rj) + cv*(this%invr(ip)**2)*pij
2536 rpp = d2phi(ip, ri)*phi(ip, rj) + m_two*dphi(ip, ri)*dphi(ip, rj) + phi(ip, ri)*d2phi(ip, rj)
2537 lapl(ibase + ip, is) = lapl(ibase + ip, is) &
2538 + cr*(rpp + m_two*this%invr(ip)*rp) + cl*(this%invr(ip)**2)*pij
2555 subroutine paw_xc_mgga_dij(this, phi, dphi, gn, vr, vs, dij, vtau, d2phi, vlapl)
2557 real(real64),
contiguous,
intent(in) :: phi(:,:)
2558 real(real64),
contiguous,
intent(in) :: dphi(:,:)
2559 real(real64),
contiguous,
intent(in) :: gn(:,:,:,:)
2560 real(real64),
contiguous,
intent(in) :: vr(:,:)
2561 real(real64),
contiguous,
intent(in) :: vs(:,:)
2562 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2563 real(real64),
contiguous,
optional,
intent(in) :: vtau(:,:)
2564 real(real64),
contiguous,
optional,
intent(in) :: d2phi(:,:)
2565 real(real64),
contiguous,
optional,
intent(in) :: vlapl(:,:)
2567 integer :: np, nsp, is, os, iss, i, j, ip, ia, ri, rj, lmi, lmj, ibase
2568 real(real64) :: yi, yj, dti, dtj, dpi, dpj, yij, acc, w, pipj, vt, vl, rp, rpp, laplo
2569 real(real64) :: gradr, gradt, gradp, tauk
2571 real(real64),
allocatable :: fl(:,:,:,:)
2576 nsp = this%spin_channels
2578 lvl =
present(vlapl) .and.
present(d2phi)
2581 safe_allocate(fl(1:np, 1:this%nang, 1:nsp, 1:3))
2584 os = min(nsp, 3 - is)
2585 do ia = 1, this%nang
2588 fl(ip, ia, is, 1) = m_two*vs(ibase + ip, iss)*gn(ip, is, ia, 1)
2589 fl(ip, ia, is, 2) = m_two*vs(ibase + ip, iss)*gn(ip, is, ia, 2)
2590 fl(ip, ia, is, 3) = m_two*vs(ibase + ip, iss)*gn(ip, is, ia, 3)
2592 fl(ip, ia, is, 1) = fl(ip, ia, is, 1) + vs(ibase + ip, 2)*gn(ip, os, ia, 1)
2593 fl(ip, ia, is, 2) = fl(ip, ia, is, 2) + vs(ibase + ip, 2)*gn(ip, os, ia, 2)
2594 fl(ip, ia, is, 3) = fl(ip, ia, is, 3) + vs(ibase + ip, 2)*gn(ip, os, ia, 3)
2601 do ia = 1, this%nang
2605 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
2608 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
2609 yi = this%ylm(ia, lmi)
2610 yj = this%ylm(ia, lmj)
2611 dti = this%dylm_dth(ia, lmi)
2612 dtj = this%dylm_dth(ia, lmj)
2613 dpi = this%dylm_dph(ia, lmi)
2614 dpj = this%dylm_dph(ia, lmj)
2619 pipj = phi(ip, ri)*phi(ip, rj)
2621 gradr = (dphi(ip, ri)*phi(ip, rj) + phi(ip, ri)*dphi(ip, rj))*yij
2622 gradt = pipj*this%invr(ip)*(dti*yj + yi*dtj)
2623 gradp = pipj*this%invr(ip)*(dpi*yj + yi*dpj)
2624 tauk = dphi(ip, ri)*dphi(ip, rj)*yij &
2625 + pipj*(this%invr(ip)**2)*(dti*dtj + dpi*dpj)
2627 if (lvt) vt = vtau(ibase + ip, is)*tauk
2631 rp = dphi(ip, ri)*phi(ip, rj) + phi(ip, ri)*dphi(ip, rj)
2632 rpp = d2phi(ip, ri)*phi(ip, rj) + m_two*dphi(ip, ri)*dphi(ip, rj) + phi(ip, ri)*d2phi(ip, rj)
2633 laplo = -real(this%p_l(i)*(this%p_l(i)+1) + this%p_l(j)*(this%p_l(j)+1), real64)*yij &
2634 + m_two*(dti*dtj + dpi*dpj)
2635 vl = vlapl(ibase + ip, is)*(yij*(rpp + m_two*this%invr(ip)*rp) + pipj*(this%invr(ip)**2)*laplo)
2637 acc = acc + w*(vr(ibase + ip, is)*pipj*yij &
2638 + fl(ip, ia, is, 1)*gradr + fl(ip, ia, is, 2)*gradt + fl(ip, ia, is, 3)*gradp &
2641 dij(i, j, is) = dij(i, j, is) + this%wang(ia)*acc
2647 safe_deallocate_a(fl)
2662 integer,
intent(in) :: nsp, nsig
2663 real(real64),
contiguous,
intent(in) :: n0(:,:)
2664 real(real64),
contiguous,
intent(in) :: sigma0(:,:)
2665 real(real64),
contiguous,
intent(in) :: dn0(:,:)
2666 real(real64),
contiguous,
intent(out) :: exc0(:)
2667 real(real64),
contiguous,
intent(out) :: vsph(:,:)
2669 integer :: ip, is, os, iss
2670 real(real64),
allocatable :: vs(:,:), flux(:), div(:)
2674 safe_allocate(vs(1:this%nr, 1:nsig))
2675 call paw_xc_eval(this, this%nr, nsp, nsig, n0, sigma0, exc0, vsph, vs)
2677 if (this%xc_is_gga)
then
2678 safe_allocate(flux(1:this%nr))
2679 safe_allocate(div(1:this%nr))
2681 os = min(nsp, 3 - is)
2685 flux(ip) = (m_two*vs(ip, iss)*dn0(ip, is) + vs(ip, 2)*dn0(ip, os))*this%vwr(ip)
2689 flux(ip) = m_two*vs(ip, iss)*dn0(ip, is)*this%vwr(ip)
2694 safe_deallocate_a(flux)
2695 safe_deallocate_a(div)
2698 safe_deallocate_a(vs)
2712 subroutine paw_xc_kernels(this, nsp, nsig, n0, sigma0, dn0, kk, k2)
2714 integer,
intent(in) :: nsp, nsig
2715 real(real64),
contiguous,
intent(in) :: n0(:,:)
2716 real(real64),
contiguous,
intent(in) :: sigma0(:,:)
2717 real(real64),
contiguous,
intent(in) :: dn0(:,:)
2718 real(real64),
contiguous,
intent(out) :: kk(:,:,:)
2719 real(real64),
contiguous,
intent(out) :: k2(:,:,:,:)
2721 integer :: np, ip, is, it, iu, os, ixc, nf2, nrs, nk3, idx
2722 real(real64) :: ntot
2723 real(real64),
allocatable :: dclamp(:,:), ssig(:,:)
2724 real(real64),
allocatable :: v2rho2(:,:), v2rhosigma(:,:), v2sigma2(:,:)
2725 real(real64),
allocatable :: s2rho2(:,:), s2rhosigma(:,:)
2726 real(real64),
allocatable :: v3rho3(:,:), v3rho2s(:,:), v3rhos2(:,:), v3s3(:,:)
2727 real(real64),
allocatable :: s3rho3(:,:)
2728 real(real64),
allocatable :: flux(:), div(:)
2730 integer,
parameter :: N_V3RHO2SIGMA(2) = [1, 9], n_v3rhosigma2(2) = [1, 12], n_v3sigma3(2) = [1, 10]
2738 assert(nsp == 1 .or. nsp == 2)
2739 assert(nsig == 2*nsp - 1)
2742 nrs = nsp*(2*nsp - 1)
2749 assert(nf2 == nsig .and. nrs == nsp*nsig)
2751 safe_allocate(dclamp(1:nsp, 1:np))
2754 dclamp(is, ip) = max(n0(ip, is), m_zero)
2757 if (this%xc_is_gga)
then
2758 safe_allocate(ssig(1:nsig, 1:np))
2761 ssig(is, ip) = sigma0(ip, is)
2766 safe_allocate(v2rho2(1:nf2, 1:np))
2767 safe_allocate(s2rho2(1:nf2, 1:np))
2768 safe_allocate(v3rho3(1:nk3, 1:np))
2769 safe_allocate(s3rho3(1:nk3, 1:np))
2772 if (this%xc_is_gga)
then
2773 safe_allocate(v2rhosigma(1:nrs, 1:np))
2774 safe_allocate(v2sigma2(1:nrs, 1:np))
2775 safe_allocate(s2rhosigma(1:nrs, 1:np))
2779 safe_allocate(v3rho2s(1:n_v3rho2sigma(nsp), 1:np))
2780 safe_allocate(v3rhos2(1:n_v3rhosigma2(nsp), 1:np))
2781 safe_allocate(v3s3(1:n_v3sigma3(nsp), 1:np))
2786 select case (this%xc_functl(ixc)%family)
2787 case (xc_family_none)
2789 case (xc_family_lda)
2790 call xc_f03_lda_fxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, v2rho2)
2791 s2rho2 = s2rho2 + v2rho2
2792 call xc_f03_lda_kxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, v3rho3)
2793 s3rho3 = s3rho3 + v3rho3
2794 case (xc_family_gga)
2795 call xc_f03_gga_fxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, ssig, &
2796 v2rho2, v2rhosigma, v2sigma2)
2797 s2rho2 = s2rho2 + v2rho2
2798 s2rhosigma = s2rhosigma + v2rhosigma
2799 call xc_f03_gga_kxc(this%xc_functl(ixc)%conf, int(np, c_size_t), dclamp, ssig, &
2800 v3rho3, v3rho2s, v3rhos2, v3s3)
2801 s3rho3 = s3rho3 + v3rho3
2803 message(1) =
"PAW one-center engine: unsupported XC functional family."
2804 call messages_fatal(1)
2812 if (nsp == 2) idx = is + it - 1
2814 kk(ip, is, it) = s2rho2(idx, ip)
2821 if (this%xc_is_gga)
then
2822 safe_allocate(flux(1:np))
2823 safe_allocate(div(1:np))
2826 os = min(nsp, 3 - is)
2829 flux(ip) = m_two*s2rhosigma(1, ip)*dn0(ip, 1)*this%vwr(ip)
2831 flux(ip) = (m_two*s2rhosigma((it-1)*3 + 2*is - 1, ip)*dn0(ip, is) &
2832 + s2rhosigma((it-1)*3 + 2, ip)*dn0(ip, os))*this%vwr(ip)
2838 safe_deallocate_a(flux)
2839 safe_deallocate_a(div)
2844 kk(ip, 1, 2) = m_half*(kk(ip, 1, 2) + kk(ip, 2, 1))
2845 kk(ip, 2, 1) = kk(ip, 1, 2)
2856 if (nsp == 2) idx = is + it + iu - 2
2858 k2(ip, is, it, iu) = s3rho3(idx, ip)
2869 ntot = ntot + dclamp(is, ip)
2871 if (ntot < m_epsilon)
then
2872 kk(ip, :, :) = m_zero
2873 k2(ip, :, :, :) = m_zero
2877 safe_deallocate_a(dclamp)
2878 safe_deallocate_a(ssig)
2879 safe_deallocate_a(v2rho2)
2880 safe_deallocate_a(s2rho2)
2881 safe_deallocate_a(v3rho3)
2882 safe_deallocate_a(s3rho3)
2883 safe_deallocate_a(v2rhosigma)
2884 safe_deallocate_a(v2sigma2)
2885 safe_deallocate_a(s2rhosigma)
2886 safe_deallocate_a(v3rho2s)
2887 safe_deallocate_a(v3rhos2)
2888 safe_deallocate_a(v3s3)
2913 subroutine paw_xc_moments(this, nlm_rho, ncore, ae, with_comp, e_xc, dij)
2915 real(real64),
contiguous,
intent(in) :: nlm_rho(:,:,:)
2916 real(real64),
contiguous,
intent(in) :: ncore(:)
2917 logical,
intent(in) :: ae
2918 logical,
intent(in) :: with_comp
2919 real(real64),
intent(out) :: e_xc
2920 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
2923 integer :: np, nsp, nsig, is, it, iu, ic, lm, ip
2924 real(real64) :: sq4pi, acc, dpol, n0c(4), fwp(4, 2)
2925 real(real64),
parameter :: wc(4) = [m_one, m_one, m_two, m_two]
2926 real(real64),
allocatable :: wrad(:)
2927 real(real64),
allocatable :: f0(:,:,:)
2928 real(real64),
allocatable :: n0(:,:), dn0(:,:), sigma0(:,:)
2929 real(real64),
allocatable :: exc0(:), v0(:,:)
2930 real(real64),
allocatable :: kk(:,:,:)
2931 real(real64),
allocatable :: k2(:,:,:,:)
2932 real(real64),
allocatable :: mlm(:,:,:)
2933 real(real64),
allocatable :: msum(:,:,:)
2934 real(real64),
allocatable :: vxc_lm(:,:,:)
2935 real(real64),
allocatable :: vrot(:,:)
2939 noncol = this%nspin == 4
2941 nsp = this%spin_channels
2943 sq4pi =
sqrt(m_four*m_pi)
2948 safe_allocate(n0(1:np, 1:nsp))
2949 safe_allocate(dn0(1:np, 1:nsp))
2950 safe_allocate(sigma0(1:np, 1:nsig))
2952 safe_allocate(f0(1:np, 1:4, 1:2))
2955 n0c(ic) = nlm_rho(ip, 1, ic)/sq4pi
2957 n0c(1) = n0c(1) + ncore(ip)
2958 n0c(2) = n0c(2) + ncore(ip)
2960 f0(ip, 1:4, 1:2) = fwp(1:4, 1:2)
2961 n0(ip, 1) = m_half*(n0c(1) + n0c(2) + dpol)
2962 n0(ip, 2) = m_half*(n0c(1) + n0c(2) - dpol)
2967 n0(ip, is) = nlm_rho(ip, 1, is)/sq4pi + ncore(ip)
2975 sigma0(ip, 1) = dn0(ip, 1)**2
2977 sigma0(ip, 2) = dn0(ip, 1)*dn0(ip, 2)
2978 sigma0(ip, 3) = dn0(ip, 2)**2
2983 safe_allocate(exc0(1:np))
2984 safe_allocate(v0(1:np, 1:nsp))
2987 safe_allocate(wrad(1:np))
2989 wrad(ip) = exc0(ip)*this%vwr(ip)
2993 e_xc = e_xc + blas_dot(np, n0(1, is), 1, wrad(1), 1)
2995 e_xc = m_four*m_pi*e_xc
2999 safe_allocate(kk(1:np, 1:nsp, 1:nsp))
3000 safe_allocate(k2(1:np, 1:nsp, 1:nsp, 1:nsp))
3005 safe_allocate(mlm(1:np, 1:this%nlm_rho, 1:nsp))
3009 do lm = 2, this%nlm_rho
3011 mlm(ip, lm, is) = wc(1)*f0(ip, 1, is)*nlm_rho(ip, lm, 1) &
3012 + wc(2)*f0(ip, 2, is)*nlm_rho(ip, lm, 2) &
3013 + wc(3)*f0(ip, 3, is)*nlm_rho(ip, lm, 3) &
3014 + wc(4)*f0(ip, 4, is)*nlm_rho(ip, lm, 4)
3019 call lalg_copy(np, this%nlm_rho, nsp, nlm_rho, mlm)
3025 safe_allocate(msum(1:np, 1:nsp, 1:nsp))
3030 do lm = 2, this%nlm_rho
3032 msum(ip, is, it) = msum(ip, is, it) + mlm(ip, lm, is)*mlm(ip, lm, it)
3036 acc = acc + kk(ip, is, it)*msum(ip, is, it)*this%vwr(ip)
3040 e_xc = e_xc + m_half*acc
3043 safe_allocate(vxc_lm(1:np, 1:this%nlm_rho, 1:nsp))
3049 acc = acc + k2(ip, is, it, iu)*msum(ip, it, iu)
3052 vxc_lm(ip, 1, is) = sq4pi*v0(ip, is) + acc/(m_two*sq4pi)
3054 do lm = 2, this%nlm_rho
3058 acc = acc + kk(ip, is, it)*mlm(ip, lm, it)
3060 vxc_lm(ip, lm, is) = acc
3068 safe_allocate(vrot(1:np, 1:this%nlm_rho))
3070 do lm = 1, this%nlm_rho
3072 vrot(ip, lm) = f0(ip, ic, 1)*vxc_lm(ip, lm, 1) + f0(ip, ic, 2)*vxc_lm(ip, lm, 2)
3083 safe_deallocate_a(wrad)
3084 safe_deallocate_a(f0)
3085 safe_deallocate_a(n0)
3086 safe_deallocate_a(dn0)
3087 safe_deallocate_a(sigma0)
3088 safe_deallocate_a(exc0)
3089 safe_deallocate_a(v0)
3090 safe_deallocate_a(kk)
3091 safe_deallocate_a(k2)
3092 safe_deallocate_a(mlm)
3093 safe_deallocate_a(msum)
3094 safe_deallocate_a(vxc_lm)
3095 safe_deallocate_a(vrot)
3103 real(real64),
intent(in) :: n1, n2, n3, n4
3104 real(real64) :: dpol
3106 dpol =
sqrt((n1 - n2)**2 + m_four*(n3**2 + n4**2))
3114 real(real64),
intent(in) :: n1, n2, n3, n4
3115 real(real64),
intent(out) :: dpol
3116 real(real64),
intent(out) :: fw(:,:)
3120 dpol =
sqrt((n1 - n2)**2 + m_four*(n3**2 + n4**2))
3123 fw(1, 1) = m_half*(m_one + pp)
3124 fw(1, 2) = m_half*(m_one - pp)
3125 fw(2, 1) = m_half*(m_one - pp)
3126 fw(2, 2) = m_half*(m_one + pp)
3152 logical,
intent(in) :: ae
3153 logical,
intent(in) :: with_comp
3154 real(real64),
contiguous,
intent(in) :: dens(:,:)
3155 real(real64),
contiguous,
intent(in) :: g(:,:,:,:), gp(:,:,:,:)
3156 real(real64),
contiguous,
intent(in) :: vr(:,:), vs(:,:)
3157 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
3159 integer :: np, ibase, ip, ia, ic, k
3160 real(real64) :: dpol, uu, gradp
3161 real(real64) :: fwp(4, 2), gq(3), hh(3, 4), bs(3, 2), bd(3)
3162 real(real64),
allocatable :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
3168 safe_allocate(a1(1:np, 1:this%nang, 1:4))
3169 safe_allocate(a2(1:np, 1:this%nang, 1:4))
3170 safe_allocate(a3(1:np, 1:this%nang, 1:4))
3171 safe_allocate(a4(1:np, 1:this%nang, 1:4))
3174 do ia = 1, this%nang
3178 dens(ibase + ip, 3), dens(ibase + ip, 4), dpol, fwp)
3181 bs(k, 1) = m_two*vs(ibase + ip, 1)*gp(ip, 1, ia, k) + vs(ibase + ip, 2)*gp(ip, 2, ia, k)
3182 bs(k, 2) = m_two*vs(ibase + ip, 3)*gp(ip, 2, ia, k) + vs(ibase + ip, 2)*gp(ip, 1, ia, k)
3183 bd(k) = bs(k, 1) - bs(k, 2)
3188 if (dpol > m_zero)
then
3189 uu = dens(ibase + ip, 1) - dens(ibase + ip, 2)
3191 gq(k) = (uu*(g(ip, 1, ia, k) - g(ip, 2, ia, k)) &
3192 + m_four*(dens(ibase + ip, 3)*g(ip, 3, ia, k) &
3193 + dens(ibase + ip, 4)*g(ip, 4, ia, k)))/dpol
3194 gradp = ((g(ip, 1, ia, k) - g(ip, 2, ia, k)) - (uu/dpol)*gq(k))/dpol
3195 hh(k, 1) = m_half*gradp
3196 hh(k, 2) = -m_half*gradp
3197 hh(k, 3) = (g(ip, 3, ia, k) - dens(ibase + ip, 3)*gq(k)/dpol)/dpol
3198 hh(k, 4) = (g(ip, 4, ia, k) - dens(ibase + ip, 4)*gq(k)/dpol)/dpol
3202 a1(ip, ia, ic) = fwp(ic, 1)*vr(ibase + ip, 1) + fwp(ic, 2)*vr(ibase + ip, 2) &
3203 + bd(1)*hh(1, ic) + bd(2)*hh(2, ic) + bd(3)*hh(3, ic)
3204 a2(ip, ia, ic) = fwp(ic, 1)*bs(1, 1) + fwp(ic, 2)*bs(1, 2)
3205 a3(ip, ia, ic) = fwp(ic, 1)*bs(2, 1) + fwp(ic, 2)*bs(2, 2)
3206 a4(ip, ia, ic) = fwp(ic, 1)*bs(3, 1) + fwp(ic, 2)*bs(3, 2)
3213 safe_deallocate_a(a1)
3214 safe_deallocate_a(a2)
3215 safe_deallocate_a(a3)
3216 safe_deallocate_a(a4)
3229 logical,
intent(in) :: ae
3230 logical,
intent(in) :: with_comp
3231 real(real64),
contiguous,
intent(in) :: a1(:,:,:), a2(:,:,:), a3(:,:,:), a4(:,:,:)
3232 real(real64),
contiguous,
intent(inout) :: dij(:,:,:)
3234 integer :: np, ip, lm, ic
3235 real(real64),
allocatable :: t1(:,:), t2(:,:), t3(:,:), t4(:,:)
3236 real(real64),
allocatable :: u1(:,:), u2(:,:)
3237 real(real64),
allocatable :: w(:,:)
3243 safe_allocate(t1(1:np, 1:this%nlm_rho))
3244 safe_allocate(t2(1:np, 1:this%nlm_rho))
3245 safe_allocate(t3(1:np, 1:this%nlm_rho))
3246 safe_allocate(t4(1:np, 1:this%nlm_rho))
3247 safe_allocate(u1(1:np, 1:this%nlm_rho))
3248 safe_allocate(u2(1:np, 1:this%nlm_rho))
3249 safe_allocate(w(1:this%npair, 1:this%nlm_rho))
3251 do ic = 1,
size(dij, 3)
3253 call lalg_gemm(a1(:, :, ic), this%wylm, t1)
3254 call lalg_gemm(a2(:, :, ic), this%wylm, t2)
3255 call lalg_gemm(a3(:, :, ic), this%wdylm_dth, t3)
3256 call lalg_gemm(a4(:, :, ic), this%wdylm_dph, t4)
3260 do lm = 1, this%nlm_rho
3262 u1(ip, lm) = (t1(ip, lm) + (t3(ip, lm) + t4(ip, lm))*this%invr(ip))*this%vwr(ip)
3263 u2(ip, lm) = t2(ip, lm)*this%vwr(ip)
3269 call lalg_gemm(this%pair_ae, u1, w, transa =
'T')
3270 call lalg_gemm(this%dpair_ae, u2, w, transa =
'T', beta = m_one)
3272 call lalg_gemm(this%pair_ps, u1, w, transa =
'T')
3273 call lalg_gemm(this%dpair_ps, u2, w, transa =
'T', beta = m_one)
3284 safe_deallocate_a(t1)
3285 safe_deallocate_a(t2)
3286 safe_deallocate_a(t3)
3287 safe_deallocate_a(t4)
3288 safe_deallocate_a(u1)
3289 safe_deallocate_a(u2)
3290 safe_deallocate_a(w)
3304 logical,
intent(in) :: ae
3305 logical,
intent(in) :: with_comp
3306 real(real64),
contiguous,
intent(in) :: vlm(:,:)
3307 real(real64),
contiguous,
intent(inout) :: dij(:,:)
3310 real(real64),
allocatable :: vw(:,:), w(:,:)
3317 safe_allocate(vw(1:this%nr, 1:this%nlm_rho))
3318 do lm = 1, this%nlm_rho
3320 vw(ip, lm) = vlm(ip, lm)*this%vwr(ip)
3324 safe_allocate(w(1:this%npair, 1:this%nlm_rho))
3326 call lalg_gemm(this%pair_ae, vw, w, transa =
'T')
3328 call lalg_gemm(this%pair_ps, vw, w, transa =
'T')
3329 if (with_comp)
call paw_qaug_gemv(this, this%qaug,
'T', vw, w)
3335 safe_deallocate_a(vw)
3336 safe_deallocate_a(w)
3374 integer,
intent(in) :: nprojs
3375 integer,
intent(in) :: pl(:)
3376 integer,
intent(in) :: pm(:)
3377 integer,
intent(in) :: pchannel(:)
3378 integer,
intent(out) :: map(:)
3380 integer :: i, ic, maxl, maxchan, iproj, ri, lm
3381 integer,
allocatable :: cnt(:), rad_of(:,:)
3385 assert(nprojs == this%nlm)
3387 maxl = maxval(this%lrad(1:this%nrad))
3389 safe_allocate(cnt(0:maxl))
3390 safe_allocate(rad_of(0:maxl, 1:maxchan))
3394 cnt(this%lrad(i)) = cnt(this%lrad(i)) + 1
3395 ic = cnt(this%lrad(i))
3399 if (this%rad_2j(i) > 0 .and. this%lrad(i) > 0)
then
3400 if (this%rad_2j(i) == 2*this%lrad(i) - 1)
then
3401 ic = (ic - 1)/2*2 + 2
3403 assert(this%rad_2j(i) == 2*this%lrad(i) + 1)
3404 ic = (ic - 1)/2*2 + 1
3407 rad_of(this%lrad(i), ic) = i
3411 do iproj = 1, nprojs
3412 assert(pl(iproj) >= 0 .and. pl(iproj) <= maxl)
3413 assert(pchannel(iproj) >= 1 .and. pchannel(iproj) <= cnt(pl(iproj)))
3414 ri = rad_of(pl(iproj), pchannel(iproj))
3416 assert(this%lrad(ri) == pl(iproj))
3418 if (this%p_rad(lm) == ri .and. this%p_m(lm) == pm(iproj) .and. this%p_l(lm) == pl(iproj))
then
3423 assert(map(iproj) > 0)
3426 safe_deallocate_a(cnt)
3427 safe_deallocate_a(rad_of)
3439 real(real64),
intent(in) :: occ(:)
3440 real(real64),
intent(out) :: rho(:,:,:)
3447 do is = 1, this%spin_channels
3449 rho(i, i, is) = occ(this%p_rad(i)) / real((2*this%p_l(i) + 1)*this%spin_channels, real64)
3463 real(real64),
intent(in) :: rho(:,:,:)
3464 logical,
intent(in) :: ae
3467 real(real64),
allocatable :: nlm_rho(:,:)
3468 real(real64) :: sqrt4pi
3473 sqrt4pi =
sqrt(m_four*m_pi)
3474 safe_allocate(nlm_rho(1:nr, 1:this%nlm_rho))
3477 do is = 1, this%spin_channels
3480 charge = charge + sqrt4pi*blas_dot(nr, nlm_rho(1, 1), 1, this%vwr(1), 1)
3482 safe_deallocate_a(nlm_rho)
3497 real(real64),
intent(in) :: rho(:,:)
3498 integer,
intent(out) :: ncol
3499 type(spline_t),
allocatable,
intent(out) :: spl(:)
3500 integer,
allocatable,
intent(out) :: ll(:)
3501 integer,
allocatable,
intent(out) :: mm(:)
3502 real(real64),
intent(out) :: rcut
3504 real(real64),
allocatable :: nae(:,:), nps(:,:)
3505 real(real64),
parameter :: tol = 1.0e-14_real64
3509 safe_allocate(nae(1:this%nr, 1:this%nlm_rho))
3510 safe_allocate(nps(1:this%nr, 1:this%nlm_rho))
3515 call lalg_axpy(this%nr, this%nlm_rho, -m_one, nps, nae)
3518 safe_deallocate_a(nae)
3519 safe_deallocate_a(nps)
3539 real(real64),
intent(in) :: rho(:,:)
3540 integer,
intent(out) :: ncol
3541 type(spline_t),
allocatable,
intent(out) :: spl(:)
3542 integer,
allocatable,
intent(out) :: ll(:)
3543 integer,
allocatable,
intent(out) :: mm(:)
3544 real(real64),
intent(out) :: rcut
3548 real(real64),
optional,
intent(out) :: tau_integral
3550 integer :: i, j, k, ia, ri, rj, lmi, lmj
3551 real(real64) :: rho_ij, ang_grad, ang_val, wa, cg, cv
3552 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:), dtau_lm(:,:), dtaua(:,:)
3553 real(real64),
parameter :: tol = 1.0e-14_real64
3557 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
3558 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
3565 safe_allocate(dtaua(1:this%nr, 1:this%nang))
3566 dtaua(1:this%nr, 1:this%nang) = m_zero
3567 do ia = 1, this%nang
3571 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
3574 if (abs(rho_ij) <= tol) cycle
3576 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
3577 ang_grad = this%ylm(ia, lmi)*this%ylm(ia, lmj)
3578 ang_val = this%dylm_dth(ia, lmi)*this%dylm_dth(ia, lmj) &
3579 + this%dylm_dph(ia, lmi)*this%dylm_dph(ia, lmj)
3580 cg = rho_ij*wa*ang_grad
3581 cv = rho_ij*wa*ang_val
3584 dtaua(k, ia) = dtaua(k, ia) &
3585 + cg*(dphi_ae(k, ri)*dphi_ae(k, rj) - dphi_ps(k, ri)*dphi_ps(k, rj)) &
3586 + 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))
3594 safe_allocate(dtau_lm(1:this%nr, 1:this%nlm_rho))
3595 call lalg_gemm(this%nr, this%nlm_rho, this%nang, m_one, dtaua, this%ylm, m_zero, dtau_lm)
3596 safe_deallocate_a(dtaua)
3603 if (
present(tau_integral))
then
3604 tau_integral =
sqrt(m_four*m_pi)*blas_dot(this%nr, dtau_lm(1, 1), 1, this%vwr(1), 1)
3607 safe_deallocate_a(dphi_ae)
3608 safe_deallocate_a(dphi_ps)
3609 safe_deallocate_a(dtau_lm)
3631 real(real64),
intent(in) :: arho(:,:)
3632 integer,
intent(in) :: idir
3633 integer,
intent(out) :: ncol
3634 type(spline_t),
allocatable,
intent(out) :: spl(:)
3635 integer,
allocatable,
intent(out) :: ll(:)
3636 integer,
allocatable,
intent(out) :: mm(:)
3637 real(real64),
intent(out) :: rcut
3638 real(real64),
optional,
intent(out) :: current_integral
3640 integer :: i, j, ip, ia, ri, rj, lmi, lmj, ra, rb, rp, npr
3641 real(real64) :: aij, yi
3642 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:), dj_lm(:,:), dja(:,:), rmat(:,:), cmat(:,:)
3643 real(real64),
parameter :: tol = 1.0e-14_real64
3647 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
3648 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
3661 npr = this%nrad*this%nrad
3662 safe_allocate(rmat(1:this%nr, 1:2*npr))
3663 do ra = 1, this%nrad
3664 do rb = 1, this%nrad
3665 rp = (ra-1)*this%nrad + rb
3667 rmat(ip, rp) = this%phi_ae(ip, ra)*dphi_ae(ip, rb) - this%phi_ps(ip, ra)*dphi_ps(ip, rb)
3668 rmat(ip, npr + rp) = this%invr(ip)*(this%phi_ae(ip, ra)*this%phi_ae(ip, rb) &
3669 - this%phi_ps(ip, ra)*this%phi_ps(ip, rb))
3674 safe_allocate(cmat(1:2*npr, 1:this%nang))
3675 cmat(1:2*npr, 1:this%nang) = m_zero
3678 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
3681 if (abs(aij) <= tol) cycle
3683 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
3684 rp = (ri-1)*this%nrad + rj
3685 do ia = 1, this%nang
3686 yi = aij*this%wang(ia)*this%ylm(ia, lmi)
3687 cmat(rp, ia) = cmat(rp, ia) + yi*this%ylm(ia, lmj)*this%rhat(ia, idir)
3688 cmat(npr + rp, ia) = cmat(npr + rp, ia) &
3689 + yi*(this%dylm_dth(ia, lmj)*this%that(ia, idir) + this%dylm_dph(ia, lmj)*this%phat(ia, idir))
3694 safe_allocate(dja(1:this%nr, 1:this%nang))
3695 call lalg_gemm(this%nr, this%nang, 2*npr, m_one, rmat, cmat, m_zero, dja)
3696 safe_deallocate_a(rmat)
3697 safe_deallocate_a(cmat)
3700 safe_allocate(dj_lm(1:this%nr, 1:this%nlm_rho))
3701 call lalg_gemm(this%nr, this%nlm_rho, this%nang, m_one, dja, this%ylm, m_zero, dj_lm)
3702 safe_deallocate_a(dja)
3706 if (
present(current_integral))
then
3707 current_integral =
sqrt(m_four*m_pi)*blas_dot(this%nr, dj_lm(1, 1), 1, this%vwr(1), 1)
3710 safe_deallocate_a(dphi_ae)
3711 safe_deallocate_a(dphi_ps)
3712 safe_deallocate_a(dj_lm)
3725 real(real64),
allocatable,
intent(out) :: vmat(:,:,:)
3727 integer :: i, j, ip, ia, ri, rj, lmi, lmj, idir
3728 real(real64) :: yi, aa, bb, c1, c2, wa, acc
3729 real(real64),
allocatable :: dphi_ae(:,:), dphi_ps(:,:)
3733 safe_allocate(dphi_ae(1:this%nr, 1:this%nrad))
3734 safe_allocate(dphi_ps(1:this%nr, 1:this%nrad))
3742 safe_allocate(vmat(1:this%nlm, 1:this%nlm, 1:3))
3745 do ia = 1, this%nang
3749 lmi = this%p_l(i)*(this%p_l(i)+1) + this%p_m(i) + 1
3750 yi = this%ylm(ia, lmi)
3753 lmj = this%p_l(j)*(this%p_l(j)+1) + this%p_m(j) + 1
3754 aa = this%ylm(ia, lmj)*this%rhat(ia, idir)
3755 bb = this%dylm_dth(ia, lmj)*this%that(ia, idir) + this%dylm_dph(ia, lmj)*this%phat(ia, idir)
3760 acc = acc + this%vwr(ip)*( &
3761 c1*(this%phi_ae(ip, ri)*dphi_ae(ip, rj) - this%phi_ps(ip, ri)*dphi_ps(ip, rj)) &
3762 + c2*this%invr(ip)*(this%phi_ae(ip, ri)*this%phi_ae(ip, rj) - this%phi_ps(ip, ri)*this%phi_ps(ip, rj)))
3764 vmat(i, j, idir) = vmat(i, j, idir) + wa*acc
3770 safe_deallocate_a(dphi_ae)
3771 safe_deallocate_a(dphi_ps)
3788 integer,
intent(in) :: nprojs
3789 integer,
intent(in) :: pl(:)
3790 integer,
intent(in) :: pm(:)
3791 integer,
intent(in) :: pchannel(:)
3792 type(spline_t),
allocatable,
intent(out) :: spl(:)
3793 integer,
allocatable,
intent(out) :: ll(:)
3794 integer,
allocatable,
intent(out) :: mm(:)
3795 real(real64),
intent(out) :: rcut
3798 integer,
allocatable :: map(:)
3799 real(real64),
allocatable :: diff(:)
3803 safe_allocate(map(1:nprojs))
3806 safe_allocate(spl(1:nprojs))
3807 safe_allocate(ll(1:nprojs))
3808 safe_allocate(mm(1:nprojs))
3809 safe_allocate(diff(1:this%nr))
3811 ri = this%p_rad(map(i))
3812 diff(1:this%nr) = this%phi_ae(1:this%nr, ri) - this%phi_ps(1:this%nr, ri)
3815 call spline_init(spl(i))
3816 call spline_fit(this%nr, this%r, diff, spl(i))
3818 rcut = this%r(this%nr)
3820 safe_deallocate_a(map)
3821 safe_deallocate_a(diff)
3836 real(real64),
allocatable,
intent(out) :: deltak(:,:)
3837 integer,
allocatable,
intent(out) :: p_rad(:)
3838 integer,
allocatable,
intent(out) :: p_l(:)
3839 integer,
allocatable,
intent(out) :: p_m(:)
3843 safe_allocate(deltak(1:this%nrad, 1:this%nrad))
3844 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)
3845 safe_allocate(p_rad(1:this%nlm))
3846 p_rad(1:this%nlm) = this%p_rad(1:this%nlm)
3847 safe_allocate(p_l(1:this%nlm))
3848 p_l(1:this%nlm) = this%p_l(1:this%nlm)
3849 safe_allocate(p_m(1:this%nlm))
3850 p_m(1:this%nlm) = this%p_m(1:this%nlm)
3863 if (this%owns_xc_functl)
then
3864 if (
associated(this%xc_functl))
then
3865 call xc_functional_end(this%xc_functl(1))
3866 call xc_functional_end(this%xc_functl(2))
3867 safe_deallocate_p(this%xc_functl)
3870 nullify(this%xc_functl)
3873 safe_deallocate_a(this%r)
3874 safe_deallocate_a(this%r2)
3875 safe_deallocate_a(this%invr)
3876 safe_deallocate_a(this%wr)
3877 safe_deallocate_a(this%vwr)
3878 safe_deallocate_a(this%der_w)
3879 safe_deallocate_a(this%der_i0)
3880 safe_deallocate_a(this%der_wt)
3881 safe_deallocate_a(this%der_trow0)
3882 safe_deallocate_a(this%der_tn)
3883 safe_deallocate_a(this%lrad)
3884 safe_deallocate_a(this%rad_2j)
3885 safe_deallocate_a(this%phi_ae_small)
3886 safe_deallocate_a(this%phi_ae)
3887 safe_deallocate_a(this%phi_ps)
3888 safe_deallocate_a(this%p_rad)
3889 safe_deallocate_a(this%p_l)
3890 safe_deallocate_a(this%p_m)
3891 safe_deallocate_a(this%qaug)
3892 safe_deallocate_a(this%pair_ae)
3893 safe_deallocate_a(this%pair_ps)
3894 safe_deallocate_a(this%gnt_pair)
3895 safe_deallocate_a(this%gnt_l)
3896 safe_deallocate_a(this%gnt_lm)
3897 safe_deallocate_a(this%gnt_c)
3898 safe_deallocate_a(this%gnt_ptr)
3899 safe_deallocate_a(this%dpair_ae)
3900 safe_deallocate_a(this%dpair_ps)
3901 safe_deallocate_a(this%dqaug)
3902 safe_deallocate_a(this%nc_ae)
3903 safe_deallocate_a(this%nc_ps)
3904 safe_deallocate_a(this%nc_ae_der)
3905 safe_deallocate_a(this%nc_ps_der)
3906 safe_deallocate_a(this%tau_c_ae)
3907 safe_deallocate_a(this%tau_c_ps)
3908 safe_deallocate_a(this%nc_ae_lapl)
3909 safe_deallocate_a(this%nc_ps_lapl)
3910 safe_deallocate_a(this%dphi_ae)
3911 safe_deallocate_a(this%dphi_ps)
3912 safe_deallocate_a(this%d2phi_ae)
3913 safe_deallocate_a(this%d2phi_ps)
3914 safe_deallocate_a(this%vref_ae)
3915 safe_deallocate_a(this%vref_ps)
3916 safe_deallocate_a(this%kin_ae)
3917 safe_deallocate_a(this%kin_ps)
3918 safe_deallocate_a(this%wang)
3919 safe_deallocate_a(this%ylm)
3920 safe_deallocate_a(this%dylm_dth)
3921 safe_deallocate_a(this%dylm_dph)
3922 safe_deallocate_a(this%wylm)
3923 safe_deallocate_a(this%wdylm_dth)
3924 safe_deallocate_a(this%wdylm_dph)
3925 safe_deallocate_a(this%rhat)
3926 safe_deallocate_a(this%that)
3927 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_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 paw_xc_eval_block(this, np, ip0, bs, nsp, nsig, dens, sigma, exc, vrho, vsigma, lapl, tau, vlapl, vtau)
Evaluate the functionals on one contiguous block of bs points.
subroutine, public paw_onsite_init(this, ps, namespace, formulation, nspin, xc_ids, usexcnhat)
Build the per-species one-center data from a (PAW) pseudopotential.
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, public paw_onsite_set_shared_xc(this, functl)
Share the main (mesh) xc functional handles with the one-center engine, instead of the sphere-owned c...
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 paw_onsite_init_xc(this, ps, namespace, xc_ids)
Initialize the exchange and correlation functionals from the ones stored in the pseudopotential.
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) ...
integer, parameter, public paw_kresse_joubert
PAW formulation: selects the compensation-charge / reference treatment.
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_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>,...
subroutine paw_xc_eval(this, np, nsp, nsig, dens, sigma, exc, vrho, vsigma, lapl, tau, vlapl, vtau, mgga_exc)
Functional-specific part of the one-center XC.
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, public paw_radial_derivative(r, f, df)
Radial derivative of a grid-sampled function via the cubic-spline derivative.
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_xc(this, nlm_rho, nlm_der, rho, ncore, ae, with_comp, e_xc, dij)
Exchange-correlation on the radial x angular grid: LibXC evaluated pointwise, accumulating the XC ene...
subroutine, public paw_onsite_radial_grid(this, r)
Accessor: return (allocate) the one-center radial grid. Used by the standalone test to drive the radi...
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_mgga_dij(this, phi, dphi, gn, vr, vs, dij, vtau, d2phi, vlapl)
Unified meta-GGA one-center D matrix, built entirely from the partial-wave gradients so it is the exa...
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_quantities(this, rho, ae, phi, dphi, d2phi, ncore, ncder, dens, gn, tau, lapl)
One-center quantities from the partial waves.
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....
subroutine paw_onsite_init_mgga(this, ps, namespace, r_full, phi_ae_full, phi_ps_full)
Meta-GGA one-center data, built once at init.
subroutine, public paw_radial_second_derivative(r, f, d2f)
Radial second derivative of a grid-sampled function via the cubic-spline second derivative....
/* 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)
subroutine, public xc_functional_end(functl)
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.