102 type(projector_matrix_t),
allocatable,
public :: projector_matrices(:)
103 integer,
public :: nprojector_matrices
104 logical,
public :: apply_projector_matrices
105 logical,
public :: has_non_local_potential
106 integer,
public :: full_projection_size
107 integer,
public :: max_npoints
108 integer,
public :: total_points
109 integer,
public :: max_nprojs
110 logical :: projector_mix
111 complex(real64),
allocatable,
public :: projector_phases(:, :, :, :)
112 integer,
allocatable,
public :: projector_to_atom(:)
114 integer,
allocatable :: regions(:)
115 integer,
public :: nphase
120 type(accel_mem_t) :: buff_offsets
121 type(accel_mem_t) :: buff_matrices
122 type(accel_mem_t) :: buff_maps
123 type(accel_mem_t) :: buff_sphere_weights
124 type(accel_mem_t) :: buff_scals
125 type(accel_mem_t) :: buff_position
126 type(accel_mem_t) :: buff_pos
127 type(accel_mem_t) :: buff_invmap
128 type(accel_mem_t) :: buff_invmap_mat
129 type(accel_mem_t) :: buff_point_to_mat
130 type(accel_mem_t) :: buff_proj_to_mat
131 type(accel_mem_t),
public :: buff_projector_phases
132 type(accel_mem_t),
pointer,
public :: buff_bra_phasepsi => null()
133 type(accel_mem_t),
pointer,
public :: buff_bra_projection_temp => null()
134 type(accel_mem_t) :: buff_mix
135 logical :: projector_self_overlap
138 type(overlap_matrix_t),
public :: ovlp_inv
139 real(real64),
pointer,
public :: spin(:,:,:) => null()
140 logical,
public :: uspp_save_memory = .false.
146 real(real64),
allocatable,
public :: onsite_density_matrix(:, :, :, :)
149 real(real64),
allocatable,
public :: onsite_current_matrix(:, :, :, :)
151 real(real64),
public :: energy_paw =
m_zero
153 type(mpi_grp_t),
public :: paw_onsite_grp
155 logical :: ghost_checked = .false.
160 logical,
public :: owns_projector_data = .
true.
164 real(real64),
allocatable :: paw_symm_rot(:, :, :, :)
165 integer,
allocatable :: paw_symm_map(:, :)
166 integer :: paw_symm_nops = 0
167 integer :: paw_symm_lmax = -1
209 real(real64),
allocatable,
public :: dprojection(:, :)
210 complex(real64),
allocatable,
public :: zprojection(:, :)
213 integer :: cuda_stream_projection_dth
226 this%apply_projector_matrices = .false.
227 this%has_non_local_potential = .false.
228 this%nprojector_matrices = 0
230 this%projector_self_overlap = .false.
244 integer :: imat, iatom
250 nullify(this%buff_bra_phasepsi)
251 nullify(this%buff_bra_projection_temp)
252 safe_allocate(this%buff_bra_phasepsi)
253 safe_allocate(this%buff_bra_projection_temp)
255 if (.not.
allocated(this%projector_matrices) .or. this%nprojector_matrices == 0)
then
260 assert(
allocated(this%projector_to_atom))
261 assert(
size(this%projector_matrices) >= this%nprojector_matrices)
262 assert(
size(this%projector_to_atom) >= this%nprojector_matrices)
264 do imat = 1, this%nprojector_matrices
265 pmat => this%projector_matrices(imat)
266 iatom = this%projector_to_atom(imat)
268 assert(iatom >= 1 .and. iatom <= epot%natoms)
269 assert(
allocated(epot%proj))
270 assert(
allocated(epot%proj(iatom)%sphere%map))
271 assert(
allocated(epot%proj(iatom)%sphere%rel_x))
273 pmat%map => epot%proj(iatom)%sphere%map
274 pmat%position => epot%proj(iatom)%sphere%rel_x
302 if (.not.
allocated(this%projector_matrices))
then
306 assert(
allocated(donor%projector_matrices))
307 assert(this%nprojector_matrices == donor%nprojector_matrices)
308 assert(this%owns_projector_data)
309 assert(donor%owns_projector_data)
311 do imat = 1, this%nprojector_matrices
312 pmat => this%projector_matrices(imat)
313 dmat => donor%projector_matrices(imat)
316 assert(this%projector_to_atom(imat) == donor%projector_to_atom(imat))
317 assert(pmat%npoints == dmat%npoints .and. pmat%nprojs == dmat%nprojs)
318 assert(pmat%is_cmplx .eqv. dmat%is_cmplx)
321 safe_deallocate_p(pmat%dprojectors)
322 safe_deallocate_p(pmat%zprojectors)
323 pmat%dprojectors => dmat%dprojectors
324 pmat%zprojectors => dmat%zprojectors
326 this%owns_projector_data = .false.
346 real(real64),
pointer,
contiguous :: dsrc(:, :)
347 complex(real64),
pointer,
contiguous :: zsrc(:, :)
351 assert(this%owns_projector_data .or.
present(donor))
352 if (
allocated(this%projector_matrices))
then
353 do imat = 1, this%nprojector_matrices
354 pmat => this%projector_matrices(imat)
355 nullify(pmat%aug_ylm)
356 if (this%owns_projector_data)
then
357 dsrc => pmat%dprojectors
358 zsrc => pmat%zprojectors
359 safe_allocate_source_p(pmat%dprojectors, dsrc)
360 safe_allocate_source_p(pmat%zprojectors, zsrc)
362 pmat%dprojectors => donor%projector_matrices(imat)%dprojectors
363 pmat%zprojectors => donor%projector_matrices(imat)%zprojectors
380 if (
allocated(this%projector_matrices))
then
395 if (
allocated(this%projector_phases))
call accel_free_buffer(this%buff_projector_phases)
398 do iproj = 1, this%nprojector_matrices
401 this%owns_projector_data = .
true.
402 safe_deallocate_a(this%regions)
403 safe_deallocate_a(this%projector_matrices)
404 safe_deallocate_a(this%projector_phases)
405 safe_deallocate_a(this%projector_to_atom)
408 if (
associated(this%buff_bra_phasepsi))
then
411 if (
associated(this%buff_bra_projection_temp))
then
414 safe_deallocate_p(this%buff_bra_phasepsi)
415 safe_deallocate_p(this%buff_bra_projection_temp)
417 call this%ovlp_inv%end()
419 safe_deallocate_a(this%onsite_density_matrix)
420 safe_deallocate_a(this%onsite_current_matrix)
421 safe_deallocate_a(this%paw_symm_rot)
422 safe_deallocate_a(this%paw_symm_map)
423 this%paw_symm_nops = 0
424 this%paw_symm_lmax = -1
439 class(
space_t),
intent(in) :: space
440 class(
mesh_t),
intent(in) :: mesh
441 type(
epot_t),
target,
intent(in) :: epot
442 integer,
intent(in) :: ispin
443 logical,
optional,
intent(in) :: overlap_operator
444 logical,
optional,
intent(in) :: inverse_overlap_operator
446 integer :: iatom, iproj, ll, lmax, lloc, mm, ic, jc
447 integer :: nmat, imat, ip, iorder, dmix_channels, dm_nspin
448 integer :: nregion, jatom, katom, iregion
449 integer,
allocatable :: order(:), head(:), region_count(:)
450 logical,
allocatable :: atom_counted(:)
451 logical :: overlap, overlap_operator_, inverse_operator_, mix_is_uspp, spinors_, uspp_spinor_dmatrix
463 uspp_spinor_dmatrix = spinors_ .and. .not. (overlap_operator_ .or. inverse_operator_)
466 mix_is_uspp = overlap_operator_ .or. inverse_operator_
472 if (ispin ==
spin_polarized .and. .not. mix_is_uspp) dmix_channels = 2
479 safe_allocate(order(1:epot%natoms))
480 safe_allocate(head(1:epot%natoms + 1))
481 safe_allocate(region_count(1:epot%natoms))
482 safe_allocate(atom_counted(1:epot%natoms))
484 this%projector_self_overlap = .false.
485 atom_counted = .false.
491 nregion = nregion + 1
492 assert(nregion <= epot%natoms)
494 region_count(nregion) = 0
496 do iatom = 1, epot%natoms
497 if (atom_counted(iatom)) cycle
502 assert(
associated(epot%proj(iatom)%sphere%mesh))
503 do jatom = 1, region_count(nregion)
504 katom = order(head(nregion) + jatom - 1)
506 overlap =
submesh_overlap(epot%proj(iatom)%sphere, epot%proj(katom)%sphere, space)
511 if (.not. overlap)
then
514 region_count(nregion) = region_count(nregion) + 1
515 order(head(nregion) - 1 + region_count(nregion)) = iatom
516 atom_counted(iatom) = .
true.
521 head(nregion + 1) = head(nregion) + region_count(nregion)
523 if (all(atom_counted))
exit
526 safe_deallocate_a(atom_counted)
527 safe_deallocate_a(region_count)
534 do iregion = 1, nregion
535 do iatom = head(iregion), head(iregion + 1) - 1
537 do jatom = head(iregion), iatom - 1
539 assert(.not.
submesh_overlap(epot%proj(order(iatom))%sphere, epot%proj(order(jatom))%sphere, space))
551 safe_allocate(this%buff_bra_phasepsi)
552 safe_allocate(this%buff_bra_projection_temp)
555 this%nprojector_matrices = 0
556 this%apply_projector_matrices = .false.
557 this%has_non_local_potential = .false.
558 this%nregions = nregion
561 do iorder = 1, epot%natoms
562 iatom = order(iorder)
565 this%has_non_local_potential = .
true.
570 do iorder = 1, epot%natoms
571 iatom = order(iorder)
574 this%nprojector_matrices = this%nprojector_matrices + 1
575 this%apply_projector_matrices = .
true.
580 if (mesh%use_curvilinear) this%apply_projector_matrices = .false.
582 if (.not. this%apply_projector_matrices)
then
583 safe_deallocate_a(order)
584 safe_deallocate_a(head)
591 safe_allocate(this%projector_matrices(1:this%nprojector_matrices))
592 safe_allocate(this%regions(1:this%nregions + 1))
593 safe_allocate(this%projector_to_atom(1:epot%natoms))
595 this%full_projection_size = 0
596 this%regions(this%nregions + 1) = this%nprojector_matrices + 1
598 this%projector_mix = .false.
601 do iregion = 1, this%nregions
602 this%regions(iregion) = iproj + 1
603 do iorder = head(iregion), head(iregion + 1) - 1
605 iatom = order(iorder)
611 pmat => this%projector_matrices(iproj)
613 this%projector_to_atom(iproj) = iatom
615 lmax = epot%proj(iatom)%lmax
616 lloc = epot%proj(iatom)%lloc
623 if (ll == lloc) cycle
625 nmat = nmat + epot%proj(iatom)%kb_p(ll, mm)%n_c
635 if (ll == lloc) cycle
637 kb_p => epot%proj(iatom)%kb_p(ll, mm)
639 call lalg_copy(pmat%npoints, kb_p%p(:, ic), pmat%dprojectors(:, imat))
642 pmat%scal(imat) = kb_p%e(ic)*mesh%volume_element
645 pmat%channel(imat) = ic
652 this%projector_self_overlap = this%projector_self_overlap .or. epot%proj(iatom)%sphere%overlap
656 this%projector_mix = .
true.
660 if (ll == lloc) cycle
662 nmat = nmat + epot%proj(iatom)%kb_p(ll, mm)%n_c
668 pmat%zprojectors =
m_z0
670 safe_allocate(pmat%qmix(1:nmat, 1:nmat))
676 if (ll == lloc) cycle
678 kb_p => epot%proj(iatom)%kb_p(ll, mm)
682 pmat%zprojectors(1:pmat%npoints, imat - 1 + ic) = &
683 cmplx(kb_p%p(1:pmat%npoints, ic),
m_zero, real64)
685 pmat%zprojectors(1:pmat%npoints, imat - 1 + ic) = &
686 epot%proj(iatom)%rkb_p(ll, mm)%ket(1:pmat%npoints, ic, 1, 1)
688 pmat%scal(imat - 1 + ic) = mesh%volume_element
689 pmat%l(imat - 1 + ic) = ll
690 pmat%m(imat - 1 + ic) = mm
691 pmat%channel(imat - 1 + ic) = ic
694 pmat%qmix(imat - 1 + ic, imat - 1 + jc) = epot%proj(iatom)%aug%qij(ll, ic, jc)
697 imat = imat + kb_p%n_c
703 use_qij = (overlap_operator_ .or. inverse_operator_), so_strength = epot%so_strength)
706 this%projector_self_overlap = this%projector_self_overlap .or. epot%proj(iatom)%sphere%overlap
710 this%projector_mix = .
true.
715 if (ll == lloc) cycle
717 nmat = nmat + epot%proj(iatom)%kb_p(ll, mm)%n_c
722 complex_mix = uspp_spinor_dmatrix, nspin_channels = dmix_channels)
728 if (
allocated(pmat%dmix)) pmat%dmix =
m_zero
729 if (
allocated(pmat%zmix)) pmat%zmix =
m_zero
734 safe_allocate(pmat%qmix(1:nmat, 1:nmat))
738 if (ll == lloc) cycle
740 kb_p => epot%proj(iatom)%kb_p(ll, mm)
742 call lalg_copy(pmat%npoints, kb_p%p(:, ic), pmat%dprojectors(:, imat - 1 + ic))
743 pmat%scal(imat - 1 + ic) = mesh%volume_element
744 pmat%l(imat - 1 + ic) = ll
745 pmat%m(imat - 1 + ic) = mm
746 pmat%channel(imat - 1 + ic) = ic
749 pmat%qmix(imat - 1 + ic, imat - 1 + jc) = epot%proj(iatom)%aug%qij(ll, ic, jc)
750 if (inverse_operator_)
then
752 pmat%dmix(imat - 1 + ic, imat - 1 + jc, 1) =
m_zero
753 else if (overlap_operator_)
then
754 pmat%dmix(imat - 1 + ic, imat - 1 + jc, 1) = epot%proj(iatom)%aug%qij(ll, ic, jc)
755 else if (uspp_spinor_dmatrix)
then
757 pmat%zmix(imat - 1 + ic, imat - 1 + jc, 1) = epot%proj(iatom)%aug%dij(ll, ic, jc)
758 pmat%zmix(imat - 1 + ic, imat - 1 + jc, 2) = epot%proj(iatom)%aug%dij(ll, ic, jc)
762 pmat%dmix(imat - 1 + ic, imat - 1 + jc, :) = epot%proj(iatom)%aug%dij(ll, ic, jc)
766 imat = imat + kb_p%n_c
776 if (inverse_operator_)
then
780 this%projector_self_overlap = this%projector_self_overlap .or. epot%proj(iatom)%sphere%overlap
784 this%projector_mix = .
true.
789 if (ll == lloc) cycle
796 has_mix_matrix = .
true., is_cmplx = (epot%proj_reltype ==
spin_orbit))
809 if (ll == lloc) cycle
811 hgh_p => epot%proj(iatom)%hgh_p(ll, mm)
818 pmat%zmix(imat - 1 + ic, imat - 1 + jc, 1) = hgh_p%h(ic, jc) +
m_half*mm*hgh_p%k(ic, jc)
819 pmat%zmix(imat - 1 + ic, imat - 1 + jc, 2) = hgh_p%h(ic, jc) -
m_half*mm*hgh_p%k(ic, jc)
822 pmat%zmix(imat - 1 + ic, imat + 3 - 1 + jc, 3) =
m_half*hgh_p%k(ic, jc) * &
823 sqrt(real(ll*(ll+1)-mm*(mm+1), real64))
827 pmat%zmix(imat - 1 + ic, imat - 3 - 1 + jc, 4) =
m_half*hgh_p%k(ic, jc) * &
828 sqrt(real(ll*(ll+1)-mm*(mm-1), real64))
835 pmat%dmix(imat - 1 + ic, imat - 1 + jc, 1) = hgh_p%h(ic, jc)
842 call lalg_copy(pmat%npoints, hgh_p%zp(:, ic), pmat%zprojectors(:, imat))
844 call lalg_copy(pmat%npoints, hgh_p%dp(:, ic), pmat%dprojectors(:, imat))
846 pmat%scal(imat) = mesh%volume_element
853 this%projector_self_overlap = this%projector_self_overlap .or. epot%proj(iatom)%sphere%overlap
858 this%projector_mix = .
true.
862 if (lloc /= 0) nmat = nmat + epot%proj(iatom)%kb_p(1, 1)%n_c
865 if (ll == lloc) cycle
867 nmat = nmat + epot%proj(iatom)%rkb_p(ll, mm)%n_c
872 has_mix_matrix = .
true., is_cmplx = .
true.)
879 kb_p => epot%proj(iatom)%kb_p(1, 1)
882 pmat%zmix(ic, ic, 1:2) = kb_p%e(ic)
883 pmat%zprojectors(1:pmat%npoints, ic) = kb_p%p(1:pmat%npoints, ic)
884 pmat%scal(ic) = mesh%volume_element
891 if (ll == lloc) cycle
893 rkb_p => epot%proj(iatom)%rkb_p(ll, mm)
896 do ic = 0, rkb_p%n_c/2-1
897 pmat%zmix(imat + ic*2, imat + ic*2, 1) = rkb_p%f(ic*2+1, 1, 1)
898 pmat%zmix(imat + ic*2, imat + ic*2, 2) = rkb_p%f(ic*2+1, 2, 2)
900 pmat%zmix(imat + ic*2+1, imat + ic*2+1, 1) = rkb_p%f(ic*2+2, 1, 1)
901 pmat%zmix(imat + ic*2+1, imat + ic*2+1, 2) = rkb_p%f(ic*2+2, 2, 2)
904 pmat%zmix(imat + ic*2+rkb_p%n_c, imat + ic*2, 4) = rkb_p%f(ic*2+1, 2, 1)
905 pmat%zmix(imat + ic*2+1+rkb_p%n_c, imat + ic*2+1, 4) = rkb_p%f(ic*2+2, 2, 1)
909 pmat%zmix(imat + ic*2-rkb_p%n_c, imat + ic*2, 3) = rkb_p%f(ic*2+1, 1, 2)
910 pmat%zmix(imat + ic*2+1-rkb_p%n_c, imat + ic*2+1, 3) = rkb_p%f(ic*2+2, 1, 2)
915 call lalg_copy(pmat%npoints, rkb_p%ket(:, ic, 1, 1), pmat%zprojectors(:, imat))
916 pmat%scal(imat) = mesh%volume_element
924 this%projector_self_overlap = this%projector_self_overlap .or. epot%proj(iatom)%sphere%overlap
930 pmat%map => epot%proj(iatom)%sphere%map
931 pmat%position => epot%proj(iatom)%sphere%rel_x
933 pmat%regions = epot%proj(iatom)%sphere%regions
935 this%full_projection_size = this%full_projection_size + pmat%nprojs
938 if (mesh%use_vol_pp)
then
939 safe_allocate(pmat%sphere_weights(1:max(pmat%npoints, 1)))
940 do ip = 1, pmat%npoints
941 pmat%sphere_weights(ip) = mesh%vol_pp(pmat%map(ip))
948 if (mesh%parallel_in_domains)
then
949 call mesh%mpi_grp%allreduce_inplace(this%projector_self_overlap, 1, mpi_logical, mpi_lor)
955 if (inverse_operator_)
then
956 call this%ovlp_inv%detect(this%nprojector_matrices, this%projector_matrices, &
957 this%projector_to_atom, epot, space, this%projector_self_overlap)
960 safe_deallocate_a(order)
961 safe_deallocate_a(head)
963 this%total_points = 0
966 do imat = 1, this%nprojector_matrices
967 pmat => this%projector_matrices(imat)
969 this%max_npoints = max(this%max_npoints, pmat%npoints)
970 this%max_nprojs = max(this%max_nprojs, pmat%nprojs)
971 this%total_points = this%total_points + pmat%npoints
975 safe_deallocate_a(this%onsite_density_matrix)
976 safe_deallocate_a(this%onsite_current_matrix)
977 if (overlap_operator_ .and. epot%has_paw .and. this%nprojector_matrices > 0)
then
980 if (ispin ==
spinors) dm_nspin = 4
981 safe_allocate(this%onsite_density_matrix(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:dm_nspin))
982 this%onsite_density_matrix =
m_zero
985 safe_allocate(this%onsite_current_matrix(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:dm_nspin))
986 this%onsite_current_matrix =
m_zero
1002 if (mix_is_uspp)
then
1020 class(
mesh_t),
intent(in) :: mesh
1022 integer :: nn, sdim, n2, s1, s2, ia
1023 integer :: blkmap(2, 2)
1024 real(real64) :: min_eig
1025 complex(real64),
allocatable :: mmat(:, :), qmat(:, :), amat(:, :), tmat(:, :)
1026 complex(real64),
allocatable :: eamat(:, :), evals(:)
1033 if (
allocated(pmat%zmix)) sdim = 2
1042 safe_allocate(mmat(1:nn, 1:nn))
1043 if (pmat%npoints > 0)
then
1044 if (
associated(pmat%zprojectors))
then
1045 mmat = matmul(conjg(transpose(pmat%zprojectors(1:pmat%npoints, 1:nn))), &
1046 pmat%zprojectors(1:pmat%npoints, 1:nn))
1048 mmat = matmul(transpose(pmat%dprojectors(1:pmat%npoints, 1:nn)), &
1049 pmat%dprojectors(1:pmat%npoints, 1:nn))
1055 if (mesh%parallel_in_domains)
call mesh%allreduce(mmat, dim = (/nn, nn/))
1056 mmat = mmat * mesh%volume_element
1059 safe_allocate(qmat(1:n2, 1:n2))
1060 safe_allocate(amat(1:n2, 1:n2))
1061 safe_allocate(tmat(1:n2, 1:n2))
1063 qmat(1:nn, 1:nn) = pmat%qmix(1:nn, 1:nn)
1065 safe_allocate(pmat%zqmix(1:nn, 1:nn, 1:4))
1066 pmat%zqmix(1:nn, 1:nn, 1:4) = pmat%zmix(1:nn, 1:nn, 1:4)
1069 qmat((s1-1)*nn + 1:s1*nn, (s2-1)*nn + 1:s2*nn) = pmat%zmix(1:nn, 1:nn, blkmap(s1, s2))
1078 amat((s1-1)*nn + 1:s1*nn, :) = matmul(mmat, qmat((s1-1)*nn + 1:s1*nn, :))
1081 amat(ia, ia) = amat(ia, ia) +
m_one
1090 safe_allocate(eamat(1:n2, 1:n2))
1091 safe_allocate(evals(1:n2))
1094 min_eig = minval(real(evals(1:n2), real64))
1095 if (min_eig < 1.0e-3_real64)
then
1096 write(
message(1),
'(a,es12.4)')
'The discretized ultrasoft/PAW overlap operator of an atom has the', min_eig
1097 write(
message(2),
'(a)')
'smallest eigenvalue printed above, which is not safely positive.'
1098 write(
message(3),
'(a)')
'Either the grid spacing under-resolves the augmentation projectors, or'
1099 write(
message(4),
'(a)')
'the dataset itself has an indefinite overlap (truncated partial waves).'
1100 write(
message(5),
'(a)')
'Generalized-eigenproblem results are unreliable; check the spacing'
1101 write(
message(6),
'(a)')
'convergence or use a different PAW dataset for this element.'
1104 safe_deallocate_a(eamat)
1105 safe_deallocate_a(evals)
1108 tmat = matmul(qmat, amat)
1111 pmat%dmix(1:nn, 1:nn, 1) = -real(tmat(1:nn, 1:nn), real64)
1115 pmat%zmix(1:nn, 1:nn, blkmap(s1, s2)) = -tmat((s1-1)*nn + 1:s1*nn, (s2-1)*nn + 1:s2*nn)
1120 safe_deallocate_a(mmat)
1121 safe_deallocate_a(qmat)
1122 safe_deallocate_a(amat)
1123 safe_deallocate_a(tmat)
1133 integer,
intent(in) :: ll
1134 integer,
intent(in) :: ic
1140 assert(ll >= 0 .and. ll <= proj%lmax)
1145 if (il == proj%lloc) cycle
1146 index = index + proj%kb_p(il, 0)%n_c
1156 class(
space_t),
intent(in) :: space
1157 class(
mesh_t),
intent(in) :: mesh
1168 if (.not.
allocated(this%projector_matrices) .or. this%nprojector_matrices <= 0)
then
1206 class(
space_t),
intent(in) :: space
1207 class(
mesh_t),
intent(in) :: mesh
1209 integer,
parameter :: OFFSET_SIZE = 6
1210 integer,
parameter :: POINTS = 1, projs = 2, matrix = 3, map = 4, scal = 5, mix = 6
1211 integer :: imat, matrix_size, scal_size
1212 integer :: ip, is, ii, ipos, mix_offset
1213 integer,
allocatable :: cnt(:), invmap(:, :), invmap2(:), pos(:)
1214 integer,
allocatable :: invmap_mat(:, :), invmap_mat2(:)
1215 integer,
allocatable :: offsets(:, :), point_to_mat(:), proj_to_mat(:)
1220 assert(
allocated(this%projector_matrices))
1221 assert(this%nprojector_matrices > 0)
1223 safe_allocate(offsets(1:offset_size, 1:this%nprojector_matrices))
1224 safe_allocate(cnt(1:mesh%np))
1229 this%total_points = 0
1231 this%max_npoints = 0
1234 do imat = 1, this%nprojector_matrices
1235 pmat => this%projector_matrices(imat)
1237 this%max_npoints = max(this%max_npoints, pmat%npoints)
1238 this%max_nprojs = max(this%max_nprojs, pmat%nprojs)
1240 offsets(points, imat) = pmat%npoints
1241 offsets(projs, imat) = pmat%nprojs
1243 offsets(matrix, imat) = matrix_size
1244 matrix_size = matrix_size + pmat%npoints*pmat%nprojs
1246 offsets(map, imat) = this%total_points
1247 this%total_points = this%total_points + pmat%npoints
1249 offsets(scal, imat) = scal_size
1250 scal_size = scal_size + pmat%nprojs
1252 offsets(mix, imat) = mix_offset
1253 if (
allocated(pmat%dmix))
then
1254 mix_offset = mix_offset + pmat%nprojs**2
1255 else if (
allocated(pmat%zmix))
then
1256 mix_offset = mix_offset + 4*pmat%nprojs**2
1258 offsets(mix, imat) = -1
1261 do is = 1, pmat%npoints
1263 cnt(ip) = cnt(ip) + 1
1267 safe_allocate(invmap(1:max(maxval(cnt), 1), 1:mesh%np))
1268 safe_allocate(invmap2(1:max(maxval(cnt)*mesh%np, 1)))
1269 safe_allocate(invmap_mat(1:max(maxval(cnt), 1), 1:mesh%np))
1270 safe_allocate(invmap_mat2(1:max(maxval(cnt)*mesh%np, 1)))
1271 safe_allocate(pos(1:mesh%np + 1))
1275 do imat = 1, this%nprojector_matrices
1276 pmat => this%projector_matrices(imat)
1277 do is = 1, pmat%npoints
1279 cnt(ip) = cnt(ip) + 1
1280 invmap(cnt(ip), ip) = ii
1281 invmap_mat(cnt(ip), ip) = imat - 1
1291 invmap2(ipos) = invmap(ii, ip)
1292 invmap_mat2(ipos) = invmap_mat(ii, ip)
1297 if (this%projector_matrices(1)%is_cmplx)
then
1303 if (mesh%use_vol_pp)
then
1309 if (mix_offset > 0)
then
1310 if (
allocated(this%projector_matrices(1)%zmix))
then
1317 do imat = 1, this%nprojector_matrices
1318 pmat => this%projector_matrices(imat)
1319 if (pmat%npoints > 0)
then
1320 if (pmat%is_cmplx)
then
1321 call accel_write_buffer(this%buff_matrices, pmat%npoints, pmat%nprojs, pmat%zprojectors, &
1322 offset = offsets(matrix, imat))
1324 call accel_write_buffer(this%buff_matrices, pmat%npoints, pmat%nprojs, pmat%dprojectors, &
1325 offset = offsets(matrix, imat))
1327 call accel_write_buffer(this%buff_maps, pmat%npoints, pmat%map, offset = offsets(map, imat))
1328 if (mesh%use_vol_pp)
then
1329 call accel_write_buffer(this%buff_sphere_weights, pmat%npoints, pmat%sphere_weights, &
1330 offset = offsets(map, imat))
1332 call accel_write_buffer(this%buff_position, space%dim, pmat%npoints, pmat%position, &
1333 offset = 3*offsets(map, imat))
1335 call accel_write_buffer(this%buff_scals, pmat%nprojs, pmat%scal, offset = offsets(scal, imat))
1336 if (offsets(mix, imat) /= -1)
then
1337 if (
allocated(pmat%zmix))
then
1338 call accel_write_buffer(this%buff_mix, pmat%nprojs, pmat%nprojs, 4, pmat%zmix, offset = offsets(mix, imat))
1342 assert(
size(pmat%dmix, 3) == 1)
1343 call accel_write_buffer(this%buff_mix, pmat%nprojs, pmat%nprojs, pmat%dmix(:, :, 1), offset = offsets(mix, imat))
1349 call accel_write_buffer(this%buff_offsets, offset_size, this%nprojector_matrices, offsets)
1361 safe_allocate(point_to_mat(1:max(this%total_points, 1)))
1362 safe_allocate(proj_to_mat(1:max(scal_size, 1)))
1363 do imat = 1, this%nprojector_matrices
1364 pmat => this%projector_matrices(imat)
1365 point_to_mat(offsets(map, imat) + 1:offsets(map, imat) + pmat%npoints) = imat - 1
1366 proj_to_mat(offsets(scal, imat) + 1:offsets(scal, imat) + pmat%nprojs) = imat - 1
1374 safe_deallocate_a(offsets)
1375 safe_deallocate_a(point_to_mat)
1376 safe_deallocate_a(proj_to_mat)
1377 safe_deallocate_a(cnt)
1378 safe_deallocate_a(invmap)
1379 safe_deallocate_a(invmap2)
1380 safe_deallocate_a(invmap_mat)
1381 safe_deallocate_a(invmap_mat2)
1382 safe_deallocate_a(pos)
1392 integer :: ik, imat, iphase, nphase, offset, npoints
1396 if (.not.
allocated(this%projector_phases))
then
1401 nphase =
size(this%projector_phases, 2)
1402 this%nphase = nphase
1405 this%total_points*nphase*
size(this%projector_phases, 4))
1408 do ik = lbound(this%projector_phases, 4), ubound(this%projector_phases, 4)
1409 do imat = 1, this%nprojector_matrices
1410 npoints = this%projector_matrices(imat)%npoints
1411 do iphase = 1, nphase
1412 if (npoints > 0)
then
1413 call accel_write_buffer(this%buff_projector_phases, npoints, this%projector_phases(1:, iphase, imat, ik), &
1414 offset = offset, async=.
true.)
1416 offset = offset + npoints
1428 logical pure function nonlocal_pseudopotential_self_overlap(this) result(projector_self_overlap)
1431 projector_self_overlap = this%projector_self_overlap
1449 class(mesh_t),
intent(in) :: mesh
1450 type(epot_t),
target,
intent(in) :: epot
1451 real(real64),
intent(in) :: veff(:, :)
1452 logical,
optional,
intent(in) :: add_bare
1455 real(real64),
optional,
contiguous,
intent(in) :: onsite_density_matrix(:, :, :, :)
1457 integer :: imat, iatom, iproj, jproj, is, np
1459 integer :: icomp, ncomp
1460 real(real64),
allocatable :: vweight(:, :), pairm(:, :, :)
1461 real(real64),
allocatable :: dij_buf(:, :, :, :)
1462 logical :: spinor, is_paw_atom, add_bare_
1463 integer :: n_paw, ipaw
1464 integer,
allocatable :: paw_imat(:)
1465 type(projector_matrix_t),
pointer :: pmat
1466 type(projector_t),
pointer :: proj
1470 add_bare_ = optional_default(add_bare, .
true.)
1471 this%energy_paw = m_zero
1476 safe_allocate(paw_imat(1:this%nprojector_matrices))
1478 do imat = 1, this%nprojector_matrices
1479 pmat => this%projector_matrices(imat)
1480 proj => epot%proj(this%projector_to_atom(imat))
1481 if (.not. projector_has_augmentation(proj)) cycle
1482 if (.not. (
allocated(pmat%dmix) .or.
allocated(pmat%zmix))) cycle
1483 if (.not.
associated(proj%aug%paw)) cycle
1485 paw_imat(n_paw) = imat
1489 assert(
present(onsite_density_matrix))
1494 do imat = 1, this%nprojector_matrices
1495 pmat => this%projector_matrices(imat)
1496 iatom = this%projector_to_atom(imat)
1497 proj => epot%proj(iatom)
1499 if (.not. projector_has_augmentation(proj)) cycle
1500 spinor =
allocated(pmat%zmix)
1502 is_paw_atom =
associated(proj%aug%paw)
1503 if (.not. (
allocated(pmat%dmix) .or. spinor)) cycle
1504 assert(
allocated(proj%aug%qflm))
1506 if (is_paw_atom .and. add_bare_)
then
1508 assert(ipaw <= n_paw)
1509 assert(paw_imat(ipaw) == imat)
1512 if (spinor .and. epot%reltype == spin_orbit)
then
1515 so_strength = epot%so_strength)
1519 if (is_paw_atom .and. add_bare_)
then
1521 dij_onsite = dij_buf(:, :, :, ipaw))
1525 if (this%uspp_save_memory)
then
1526 safe_deallocate_p(pmat%aug_ylm)
1539 ncomp =
size(pmat%dmix, 3)
1541 assert(
size(veff, 2) >= ncomp)
1544 safe_allocate(vweight(1:np, 1:ncomp))
1547 vweight(is, icomp) = veff(pmat%map(is), icomp)
1553 safe_allocate(pairm(1:pmat%nprojs, 1:pmat%nprojs, 1:ncomp))
1556 vol = mesh%volume_element
1557 do iproj = 1, pmat%nprojs
1558 do jproj = 1, pmat%nprojs
1560 pmat%zmix(iproj, jproj, 1) = cmplx(pairm(iproj, jproj, 1)*vol, m_zero, real64)
1561 pmat%zmix(iproj, jproj, 2) = cmplx(pairm(iproj, jproj, 2)*vol, m_zero, real64)
1562 pmat%zmix(iproj, jproj, 3) = cmplx(pairm(iproj, jproj, 3)*vol, pairm(iproj, jproj, 4)*vol, real64)
1563 pmat%zmix(iproj, jproj, 4) = cmplx(pairm(iproj, jproj, 3)*vol, -pairm(iproj, jproj, 4)*vol, real64)
1565 pmat%dmix(iproj, jproj, 1:ncomp) = pairm(iproj, jproj, 1:ncomp)*vol
1570 safe_deallocate_a(vweight)
1571 safe_deallocate_a(pairm)
1574 if (mesh%parallel_in_domains)
then
1576 call mesh%allreduce(pmat%zmix, dim = (/pmat%nprojs, pmat%nprojs, 4/))
1578 call mesh%allreduce(pmat%dmix, dim = (/pmat%nprojs, pmat%nprojs, ncomp/))
1582 if (.not. add_bare_) cycle
1588 do iproj = 1, pmat%nprojs
1589 do jproj = 1, pmat%nprojs
1590 if (pmat%l(iproj) == pmat%l(jproj) .and. pmat%m(iproj) == pmat%m(jproj))
then
1592 pmat%zmix(iproj, jproj, 1:2) = pmat%zmix(iproj, jproj, 1:2) + &
1593 proj%aug%dij(pmat%l(iproj), pmat%channel(iproj), pmat%channel(jproj))
1596 pmat%dmix(iproj, jproj, :) = pmat%dmix(iproj, jproj, :) + &
1597 proj%aug%dij(pmat%l(iproj), pmat%channel(iproj), pmat%channel(jproj))
1606 if (is_paw_atom)
then
1608 do jproj = 1, pmat%nprojs
1609 do iproj = 1, pmat%nprojs
1610 pmat%zmix(iproj, jproj, 1) = pmat%zmix(iproj, jproj, 1) + dij_buf(iproj, jproj, 1, ipaw)
1611 pmat%zmix(iproj, jproj, 2) = pmat%zmix(iproj, jproj, 2) + dij_buf(iproj, jproj, 2, ipaw)
1612 pmat%zmix(iproj, jproj, 3) = pmat%zmix(iproj, jproj, 3) &
1613 + cmplx(dij_buf(iproj, jproj, 3, ipaw), dij_buf(iproj, jproj, 4, ipaw), real64)
1614 pmat%zmix(iproj, jproj, 4) = pmat%zmix(iproj, jproj, 4) &
1615 + cmplx(dij_buf(iproj, jproj, 3, ipaw), -dij_buf(iproj, jproj, 4, ipaw), real64)
1619 do is = 1,
size(dij_buf, 3)
1620 pmat%dmix(1:pmat%nprojs, 1:pmat%nprojs, is) = pmat%dmix(1:pmat%nprojs, 1:pmat%nprojs, is) &
1621 + dij_buf(1:pmat%nprojs, 1:pmat%nprojs, is, ipaw)
1627 if (.not. this%ghost_checked)
then
1628 this%ghost_checked = .
true.
1632 safe_deallocate_a(paw_imat)
1633 safe_deallocate_a(dij_buf)
1651 class(mesh_t),
intent(in) :: mesh
1652 type(epot_t),
target,
intent(in) :: epot
1654 integer :: imat, iatom, iproj, ll, mm, i1, i2, np
1655 real(real64) :: bb(2, 2), qq(2, 2), dd(2, 2), sd(2, 2), binv(2, 2)
1656 real(real64) :: det, tr, lmin, lmax, vv(2), vnorm, vdv, vol
1657 complex(real64) :: zbb(2, 2)
1658 real(real64),
allocatable :: dpp(:, :)
1659 complex(real64),
allocatable :: zpp(:, :)
1661 type(projector_matrix_t),
pointer :: pmat
1662 type(projector_t),
pointer :: proj
1667 vol = mesh%volume_element
1669 do imat = 1, this%nprojector_matrices
1671 pmat => this%projector_matrices(imat)
1672 iatom = this%projector_to_atom(imat)
1673 proj => epot%proj(iatom)
1674 if (.not. projector_has_augmentation(proj)) cycle
1675 if (.not. (
allocated(pmat%dmix) .or.
allocated(pmat%zmix))) cycle
1679 if (
associated(pmat%zprojectors))
then
1680 safe_allocate(zpp(1:np, 1:2))
1682 safe_allocate(dpp(1:np, 1:2))
1686 do ll = 0, proj%lmax
1691 if (
associated(pmat%zprojectors) .and. ll > 0) cycle
1697 do iproj = 1, pmat%nprojs
1698 if (pmat%l(iproj) /= ll .or. pmat%m(iproj) /= mm) cycle
1699 if (pmat%channel(iproj) == 1) i1 = iproj
1700 if (pmat%channel(iproj) == 2) i2 = iproj
1702 if (i1 == 0 .or. i2 == 0) cycle
1706 if (
associated(pmat%zprojectors))
then
1707 call lalg_copy(np, pmat%zprojectors(:, i1), zpp(:, 1))
1708 call lalg_copy(np, pmat%zprojectors(:, i2), zpp(:, 2))
1709 call lalg_gemm_cn(2, 2, np, cmplx(vol, m_zero, real64), zpp, zpp, m_z0, zbb)
1710 bb = real(zbb, real64)
1712 call lalg_copy(np, pmat%dprojectors(:, i1), dpp(:, 1))
1713 call lalg_copy(np, pmat%dprojectors(:, i2), dpp(:, 2))
1714 call lalg_gemm_cn(2, 2, np, vol, dpp, dpp, m_zero, bb)
1719 if (mesh%parallel_in_domains)
call mesh%allreduce(bb, dim = (/2, 2/))
1721 det = bb(1, 1)*bb(2, 2) - bb(1, 2)*bb(2, 1)
1722 if (det <= m_epsilon*bb(1, 1)*bb(2, 2)) cycle
1723 binv(1, 1) = bb(2, 2)/det
1724 binv(2, 2) = bb(1, 1)/det
1725 binv(1, 2) = -bb(1, 2)/det
1726 binv(2, 1) = binv(1, 2)
1728 qq(1, 1) = proj%aug%qij(ll, 1, 1)
1729 qq(1, 2) = proj%aug%qij(ll, 1, 2)
1731 qq(2, 2) = proj%aug%qij(ll, 2, 2)
1735 tr = sd(1, 1) + sd(2, 2)
1736 det = sd(1, 1)*sd(2, 2) - sd(1, 2)*sd(2, 1)
1737 lmin = m_half*(tr -
sqrt(max(tr*tr - m_four*det, m_zero)))
1738 lmax = m_half*(tr +
sqrt(max(tr*tr - m_four*det, m_zero)))
1739 if (lmin <= m_zero .or. lmin > 0.05_real64*lmax) cycle
1741 vv(2) = lmin - sd(1, 1)
1742 vnorm =
sqrt(vv(1)**2 + vv(2)**2)
1743 if (vnorm <= m_epsilon) cycle
1747 if (
allocated(pmat%zmix))
then
1748 dd(1, 1) = real(pmat%zmix(i1, i1, 1), real64)
1749 dd(1, 2) = real(pmat%zmix(i1, i2, 1), real64)
1750 dd(2, 2) = real(pmat%zmix(i2, i2, 1), real64)
1752 dd(1, 1) = pmat%dmix(i1, i1, 1)
1753 dd(1, 2) = pmat%dmix(i1, i2, 1)
1754 dd(2, 2) = pmat%dmix(i2, i2, 1)
1757 vdv = vv(1)*vv(1)*dd(1, 1) + m_two*vv(1)*vv(2)*dd(1, 2) + vv(2)*vv(2)*dd(2, 2)
1759 if (vdv < -1.0e-3_real64)
then
1760 write(message(1),
'(a,i2,a)')
"The pseudopotential of atom " , iatom, &
1761 " has a near-singular augmentation channel"
1762 write(message(2),
'(a,i2,a,es9.2,a,f8.4,a)')
"block (l = ", ll, &
1763 "): overlap direction ", lmin/lmax,
" with attractive coupling (", vdv,
" Ha)."
1764 message(3) =
"Spurious (ghost) states are likely on the real-space grid and the SCF"
1765 message(4) =
"may diverge. This is a dataset conditioning problem; consider a"
1766 message(5) =
"different pseudopotential for this element."
1767 call messages_warning(5)
1772 safe_deallocate_a(dpp)
1773 safe_deallocate_a(zpp)
1793 type(epot_t),
target,
intent(in) :: epot
1794 integer,
intent(in) :: n_paw
1795 integer,
intent(in) :: paw_imat(:)
1796 real(real64),
contiguous,
intent(in) :: onsite_density_matrix(:, :, :, :)
1797 real(real64),
allocatable,
intent(out) :: dij_buf(:, :, :, :)
1799 integer :: ipaw, imat, iu, nlm, nsp, nprojs, is, iproj, jproj
1800 logical :: ae, distributed
1801 integer,
allocatable :: map(:)
1802 real(real64),
allocatable :: rho(:, :, :), d_side(:, :, :)
1803 real(real64),
allocatable :: e_buf(:, :)
1804 real(real64) :: e_side, ecorr, sgn
1805 real(real64),
parameter :: wcomp(4) = [m_one, m_one, m_two, m_two]
1806 type(projector_matrix_t),
pointer :: pmat
1807 type(projector_t),
pointer :: proj
1811 distributed = this%paw_onsite_grp%size > 1
1813 proj => epot%proj(this%projector_to_atom(paw_imat(1)))
1814 nsp = paw_onsite_nspin(proj%aug%paw)
1815 assert(
size(onsite_density_matrix, 4) >= nsp)
1817 safe_allocate(dij_buf(1:this%max_nprojs, 1:this%max_nprojs, 1:nsp, 1:n_paw))
1818 safe_allocate(e_buf(1:2, 1:n_paw))
1822 do iu = 0, 2*n_paw - 1
1823 if (distributed)
then
1824 if (mod(iu, this%paw_onsite_grp%size) /= this%paw_onsite_grp%rank) cycle
1827 ae = (mod(iu, 2) == 0)
1828 imat = paw_imat(ipaw)
1829 pmat => this%projector_matrices(imat)
1830 proj => epot%proj(this%projector_to_atom(imat))
1831 nprojs = pmat%nprojs
1832 nlm = paw_onsite_nlm(proj%aug%paw)
1833 assert(nlm == nprojs)
1834 assert(paw_onsite_nspin(proj%aug%paw) == nsp)
1837 safe_allocate(map(1:nprojs))
1838 call paw_onsite_pmat_map(proj%aug%paw, nprojs, pmat%l, pmat%m, pmat%channel, map)
1840 safe_allocate(rho(1:nlm, 1:nlm, 1:nsp))
1841 safe_allocate(d_side(1:nlm, 1:nlm, 1:nsp))
1843 call paw_onsite_reorder_pmat(nprojs, map, onsite_density_matrix(:, :, imat, is), rho(:, :, is))
1846 call paw_onsite_side(proj%aug%paw, rho, ae, e_side, d_side, hxc_only = .
true.)
1850 e_buf(1, ipaw) = e_side
1853 e_buf(2, ipaw) = e_side
1858 do jproj = 1, nprojs
1859 do iproj = 1, nprojs
1860 dij_buf(iproj, jproj, is, ipaw) = dij_buf(iproj, jproj, is, ipaw) &
1861 + sgn*d_side(map(iproj), map(jproj), is)
1866 safe_deallocate_a(map)
1867 safe_deallocate_a(rho)
1868 safe_deallocate_a(d_side)
1871 if (distributed)
then
1872 call comm_allreduce(this%paw_onsite_grp, dij_buf)
1873 call comm_allreduce(this%paw_onsite_grp, e_buf)
1878 imat = paw_imat(ipaw)
1879 pmat => this%projector_matrices(imat)
1880 ecorr = e_buf(1, ipaw) - e_buf(2, ipaw)
1882 do jproj = 1, pmat%nprojs
1883 do iproj = 1, pmat%nprojs
1884 ecorr = ecorr - wcomp(is)*onsite_density_matrix(iproj, jproj, imat, is)*dij_buf(iproj, jproj, is, ipaw)
1888 this%energy_paw = this%energy_paw + ecorr
1891 safe_deallocate_a(e_buf)
1908 type(epot_t),
intent(in) :: epot
1909 class(space_t),
intent(in) :: space
1910 type(grid_t),
intent(in) :: gr
1911 type(ions_t),
intent(in) :: ions
1913 integer :: nops, lmax, imat, iatom, iatom_sym, jmat, iop, ll, mm, im, imp, norb, nprojs
1914 real(real64) :: rc, origin(1:space%dim)
1915 type(submesh_t) :: sphere
1916 real(real64),
allocatable :: orb(:,:), orb_sym(:), ylm(:), nrm(:)
1920 safe_deallocate_a(this%paw_symm_rot)
1921 safe_deallocate_a(this%paw_symm_map)
1922 this%paw_symm_nops = 0
1923 this%paw_symm_lmax = -1
1925 if (this%nprojector_matrices == 0)
then
1932 do imat = 1, this%nprojector_matrices
1933 iatom = this%projector_to_atom(imat)
1934 if (.not.
associated(epot%proj(iatom)%aug%paw)) cycle
1935 nprojs = this%projector_matrices(imat)%nprojs
1936 lmax = max(lmax, maxval(this%projector_matrices(imat)%l(1:nprojs)))
1943 nops = ions%symm%nops
1944 this%paw_symm_nops = nops
1945 this%paw_symm_lmax = lmax
1951 safe_allocate(this%paw_symm_map(1:this%nprojector_matrices, 1:nops))
1952 this%paw_symm_map = 0
1953 do imat = 1, this%nprojector_matrices
1954 iatom = this%projector_to_atom(imat)
1955 if (.not.
associated(epot%proj(iatom)%aug%paw)) cycle
1957 iatom_sym = ions%inv_map_symm_atoms(iatom, iop)
1958 do jmat = 1, this%nprojector_matrices
1959 if (this%projector_to_atom(jmat) == iatom_sym)
then
1960 this%paw_symm_map(imat, iop) = jmat
1965 assert(this%paw_symm_map(imat, iop) > 0)
1971 safe_allocate(this%paw_symm_rot(1:2*lmax+1, 1:2*lmax+1, 0:lmax, 1:nops))
1972 this%paw_symm_rot = m_zero
1975 rc = (50.0_real64 * m_three/m_four/m_pi*product(gr%spacing))**m_third
1977 call submesh_init(sphere, space, gr, ions%latt, origin, rc)
1978 safe_allocate(ylm(1:sphere%np))
1979 safe_allocate(orb_sym(1:gr%np))
1980 safe_allocate(nrm(1:2*lmax+1))
1983 safe_allocate(orb(1:gr%np, 1:norb))
1989 if (sphere%np > 0)
then
1990 call loct_ylm(sphere%np, sphere%rel_x(1, 1), sphere%r(1), ll, mm, ylm(1))
1991 call submesh_add_to_mesh(sphere, ylm, orb(:, im))
1993 nrm(im) = dmf_nrm2(gr, orb(:, im))
1998 call dgrid_symmetrize_single(gr, iop, orb(:, im), orb_sym)
2000 this%paw_symm_rot(im, imp, ll, iop) = &
2001 dmf_dotp(gr, orb(:, imp), orb_sym, reduce = .false.) / (nrm(im)*nrm(imp))
2005 safe_deallocate_a(orb)
2007 safe_deallocate_a(nrm)
2008 call gr%allreduce(this%paw_symm_rot)
2009 safe_deallocate_a(ylm)
2010 safe_deallocate_a(orb_sym)
2011 call submesh_end(sphere)
2014 this%paw_symm_rot(1, 1, 0, 1:nops) = m_one
2031 integer :: nsym, imat, imat_src, iop, is, nspin, nprojs
2032 integer :: iproj, jproj, ki, kj, li, lj, oi, oj
2033 real(real64) :: wi, wj, s
2034 real(real64),
allocatable :: tmp(:, :, :, :)
2035 integer,
allocatable :: part(:, :)
2036 type(projector_matrix_t),
pointer :: pmat
2038 if (.not.
allocated(this%onsite_density_matrix))
return
2039 if (.not.
allocated(this%paw_symm_rot))
return
2040 nsym = this%paw_symm_nops
2041 if (nsym <= 1)
return
2045 nspin =
size(this%onsite_density_matrix, 4)
2046 safe_allocate(tmp(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:nspin))
2047 tmp = this%onsite_density_matrix
2048 this%onsite_density_matrix = m_zero
2050 do imat = 1, this%nprojector_matrices
2051 pmat => this%projector_matrices(imat)
2052 nprojs = pmat%nprojs
2056 if (this%paw_symm_map(imat, 1) == 0)
then
2057 this%onsite_density_matrix(1:nprojs, 1:nprojs, imat, 1:nspin) = tmp(1:nprojs, 1:nprojs, imat, 1:nspin)
2063 safe_allocate(part(1:nprojs, 1:2*this%paw_symm_lmax+1))
2065 do iproj = 1, nprojs
2067 if (pmat%l(ki) == pmat%l(iproj) .and. pmat%channel(ki) == pmat%channel(iproj))
then
2068 part(iproj, pmat%m(ki) + pmat%l(iproj) + 1) = ki
2074 imat_src = this%paw_symm_map(imat, iop)
2075 assert(this%projector_matrices(imat_src)%nprojs == nprojs)
2077 do iproj = 1, nprojs
2079 oi = pmat%m(iproj) + li + 1
2080 do jproj = 1, nprojs
2082 oj = pmat%m(jproj) + lj + 1
2085 wi = this%paw_symm_rot(oi, ki, li, iop)
2086 if (abs(wi) < 1.0e-12_real64) cycle
2088 wj = this%paw_symm_rot(oj, kj, lj, iop)
2089 if (abs(wj) < 1.0e-12_real64) cycle
2090 s = s + wi*wj*tmp(part(iproj, ki), part(jproj, kj), imat_src, is)
2093 this%onsite_density_matrix(iproj, jproj, imat, is) = &
2094 this%onsite_density_matrix(iproj, jproj, imat, is) + s/real(nsym, real64)
2099 safe_deallocate_a(part)
2102 safe_deallocate_a(tmp)
2118 type(projector_t),
intent(in) :: proj
2119 type(projector_matrix_t),
intent(in) :: pmat
2120 integer,
intent(in) :: np, ncomp
2121 real(real64),
contiguous,
intent(in) :: field(:, :)
2122 real(real64),
intent(out) :: pairm(:, :, :)
2124 real(real64),
allocatable :: wq(:, :)
2128 safe_allocate(wq(1:proj%aug%qflm_ncombo, 1:ncomp))
2132 call blas_gemm(
'T',
'N', proj%aug%qflm_ncombo, ncomp, np, m_one, &
2133 proj%aug%qflm(1, 1), np, field(1, 1), np, m_zero, wq(1, 1), proj%aug%qflm_ncombo)
2135 call projector_aug_columns_to_pairs(proj, pmat, ncomp, wq, pairm)
2136 safe_deallocate_a(wq)
2149 type(projector_matrix_t),
target,
intent(inout) :: pmat
2150 type(projector_t),
target,
intent(in) :: proj
2151 logical,
intent(in) :: use_qij
2153 real(real64),
optional,
intent(in) :: so_strength
2155 integer :: ll, nc, ci, cj, ip, ki, kj
2156 real(real64) :: lam, wplus, wminus, avg
2157 integer,
allocatable :: pidx(:, :)
2158 logical,
allocatable :: jplus(:)
2159 real(real64),
allocatable :: mat(:, :)
2163 assert(
allocated(pmat%zmix))
2166 do ll = 0, proj%lmax
2167 if (ll == proj%lloc) cycle
2168 nc = proj%kb_p(ll, 0)%n_c
2171 safe_allocate(jplus(1:nc))
2172 safe_allocate(pidx(1:2*ll+1, 1:nc))
2173 safe_allocate(mat(1:nc, 1:nc))
2176 jplus(ci) = (ll == 0) .or. (mod(ci, 2) == 1)
2179 do ip = 1, pmat%nprojs
2180 if (pmat%l(ip) /= ll) cycle
2181 pidx(pmat%m(ip) + ll + 1, pmat%channel(ip)) = ip
2186 mat(ci, cj) = proj%aug%qij(ll, ci, cj)
2188 mat(ci, cj) = proj%aug%dij(ll, ci, cj)
2199 lam = optional_default(so_strength, m_one)
2200 if (
associated(proj%aug%paw)) lam = m_one
2201 if (abs(lam - m_one) > m_epsilon .and. .not. use_qij .and. ll > 0 .and. mod(nc, 2) == 0)
then
2202 wplus = real(2*ll + 2, real64)
2203 wminus = real(2*ll, real64)
2206 avg = (wplus*mat(2*ki - 1, 2*kj - 1) + wminus*mat(2*ki, 2*kj))/(wplus + wminus)
2207 mat(2*ki - 1, 2*kj - 1) = avg + lam*(mat(2*ki - 1, 2*kj - 1) - avg)
2208 mat(2*ki, 2*kj) = avg + lam*(mat(2*ki, 2*kj) - avg)
2213 call soc_uspp_add_channel_coupling_cmplx(ll, nc, jplus, mat, pidx, pmat%zmix)
2215 safe_deallocate_a(jplus)
2216 safe_deallocate_a(pidx)
2217 safe_deallocate_a(mat)
2234 type(projector_matrix_t),
target,
intent(inout) :: pmat
2235 type(projector_t),
target,
intent(in) :: proj
2236 class(mesh_t),
intent(in) :: mesh
2237 real(real64),
intent(in) :: veff(:, :)
2238 real(real64),
optional,
intent(in) :: dij_onsite(:, :, :)
2240 integer :: np, lmaxq, iproj, jproj, is, ltot, mtot, pair_index, lm, icomp
2241 integer :: sa, sb, n2
2242 real(real64) :: vol, coeff, ssum(4), acc_lm
2243 real(real64),
allocatable :: vweight(:, :), qyv(:)
2244 complex(real64),
allocatable :: dr(:, :, :), gmat(:, :), dfl(:, :)
2245 integer :: blkmap_screen(2, 2)
2249 blkmap_screen(1, 1) = 1
2250 blkmap_screen(2, 2) = 2
2251 blkmap_screen(1, 2) = 3
2252 blkmap_screen(2, 1) = 4
2255 lmaxq = proj%aug%qfunc_lmax
2256 vol = mesh%volume_element
2257 call projector_matrix_build_aug_ylm(pmat, lmaxq)
2260 safe_allocate(vweight(1:np, 1:4))
2263 vweight(is, icomp) = veff(pmat%map(is), icomp)
2269 safe_allocate(qyv(1:np))
2270 safe_allocate(dr(1:pmat%nprojs, 1:pmat%nprojs, 1:3))
2273 do iproj = 1, pmat%nprojs
2274 do jproj = 1, pmat%nprojs
2275 pair_index = (pmat%beta_index(iproj) - 1)*proj%aug%qfunc_nbeta + pmat%beta_index(jproj)
2278 do mtot = -ltot, ltot
2279 coeff = real_gaunt(pmat%l(iproj), pmat%m(iproj), pmat%l(jproj), pmat%m(jproj), ltot, mtot)
2280 if (abs(coeff) <= 1.0e-12_real64) cycle
2281 lm = ltot*(ltot + 1) + mtot + 1
2284 qyv(is) = pmat%aug_ylm(is, lm)*proj%aug%qfunc(is, pair_index, ltot)
2287 acc_lm = blas_dot(np, vweight(1, icomp), 1, qyv(1), 1)
2288 ssum(icomp) = ssum(icomp) + coeff*acc_lm
2292 dr(iproj, jproj, 1) = cmplx(ssum(1)*vol, m_zero, real64)
2293 dr(iproj, jproj, 2) = cmplx(ssum(2)*vol, m_zero, real64)
2294 dr(iproj, jproj, 3) = cmplx(ssum(3)*vol, ssum(4)*vol, real64)
2298 safe_deallocate_a(vweight)
2299 safe_deallocate_a(qyv)
2300 if (mesh%parallel_in_domains)
call mesh%allreduce(dr, dim = (/pmat%nprojs, pmat%nprojs, 3/))
2306 if (
present(dij_onsite))
then
2307 do jproj = 1, pmat%nprojs
2308 do iproj = 1, pmat%nprojs
2309 dr(iproj, jproj, 1) = dr(iproj, jproj, 1) + dij_onsite(iproj, jproj, 1)
2310 dr(iproj, jproj, 2) = dr(iproj, jproj, 2) + dij_onsite(iproj, jproj, 2)
2311 dr(iproj, jproj, 3) = dr(iproj, jproj, 3) &
2312 + cmplx(dij_onsite(iproj, jproj, 3), dij_onsite(iproj, jproj, 4), real64)
2325 safe_allocate(gmat(1:n2, 1:n2))
2330 safe_allocate(dfl(1:n2, 1:n2))
2331 dfl(1:pmat%nprojs, 1:pmat%nprojs) = dr(:, :, 1)
2332 dfl(pmat%nprojs + 1:n2, pmat%nprojs + 1:n2) = dr(:, :, 2)
2333 dfl(1:pmat%nprojs, pmat%nprojs + 1:n2) = dr(:, :, 3)
2334 dfl(pmat%nprojs + 1:n2, 1:pmat%nprojs) = conjg(transpose(dr(:, :, 3)))
2336 dfl = matmul(conjg(gmat), matmul(dfl, transpose(gmat)))
2340 pmat%zmix(1:pmat%nprojs, 1:pmat%nprojs, blkmap_screen(sa, sb)) = &
2341 pmat%zmix(1:pmat%nprojs, 1:pmat%nprojs, blkmap_screen(sa, sb)) + &
2342 dfl((sa-1)*pmat%nprojs + 1:sa*pmat%nprojs, (sb-1)*pmat%nprojs + 1:sb*pmat%nprojs)
2346 safe_deallocate_a(gmat)
2347 safe_deallocate_a(dfl)
2348 safe_deallocate_a(dr)
2368 class(mesh_t),
intent(in) :: mesh
2369 type(states_elec_dim_t),
intent(in) :: std
2370 logical,
intent(in) :: spiral_bnd
2371 type(wfs_elec_t),
intent(in) :: psib
2372 real(real64),
intent(in) :: weight(:)
2373 real(real64),
allocatable,
intent(inout) :: beta_density(:, :, :, :)
2375 real(real64),
allocatable,
optional,
intent(inout) :: beta_current(:, :, :, :)
2377 integer :: imat, iproj, ist, iprojection, nprojs
2379 type(projector_matrix_t),
pointer :: pmat
2380 complex(real64),
allocatable :: pbra_u(:, :), pbra_d(:, :), pket_u(:, :), pket_d(:, :)
2381 complex(real64),
allocatable :: rho_uu(:, :), rho_dd(:, :), rho_ud(:, :)
2385 assert(.not. spiral_bnd)
2386 assert(this%apply_projector_matrices)
2387 assert(psib%status() /= batch_device_packed)
2388 assert(std%dim == 2)
2389 assert(
size(weight) == psib%nst)
2391 if (.not.
allocated(beta_density))
then
2392 safe_allocate(beta_density(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:4))
2393 beta_density = m_zero
2395 if (
present(beta_current))
then
2396 if (.not.
allocated(beta_current))
then
2397 safe_allocate(beta_current(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:4))
2398 beta_current = m_zero
2404 if (mesh%parallel_in_domains)
then
2405 call mesh%allreduce(projection%zprojection)
2409 do imat = 1, this%nprojector_matrices
2410 pmat => this%projector_matrices(imat)
2411 nprojs = pmat%nprojs
2417 safe_allocate(pbra_u(1:nprojs, 1:psib%nst))
2418 safe_allocate(pbra_d(1:nprojs, 1:psib%nst))
2419 safe_allocate(pket_u(1:nprojs, 1:psib%nst))
2420 safe_allocate(pket_d(1:nprojs, 1:psib%nst))
2421 do ist = 1, psib%nst
2422 do iproj = 1, nprojs
2423 pket_u(iproj, ist) = projection%zprojection((ist - 1)*std%dim + 1, iprojection + iproj)
2424 pket_d(iproj, ist) = projection%zprojection((ist - 1)*std%dim + 2, iprojection + iproj)
2425 pbra_u(iproj, ist) = weight(ist)*conjg(pket_u(iproj, ist))
2426 pbra_d(iproj, ist) = weight(ist)*conjg(pket_d(iproj, ist))
2432 rho_uu = matmul(pbra_u, transpose(pket_u))
2433 call lalg_axpy(nprojs, nprojs, m_one, real(rho_uu, real64), beta_density(1:nprojs, 1:nprojs, imat, 1))
2434 rho_dd = matmul(pbra_d, transpose(pket_d))
2435 call lalg_axpy(nprojs, nprojs, m_one, real(rho_dd, real64), beta_density(1:nprojs, 1:nprojs, imat, 2))
2437 rho_ud = matmul(pbra_d, transpose(pket_u))
2438 call lalg_axpy(nprojs, nprojs, m_one, real(rho_ud, real64), beta_density(1:nprojs, 1:nprojs, imat, 3))
2439 call lalg_axpy(nprojs, nprojs, m_one, aimag(rho_ud), beta_density(1:nprojs, 1:nprojs, imat, 4))
2441 if (
present(beta_current))
then
2443 beta_current(:, :, imat, :))
2446 safe_deallocate_a(pbra_u)
2447 safe_deallocate_a(pbra_d)
2448 safe_deallocate_a(pket_u)
2449 safe_deallocate_a(pket_d)
2450 safe_deallocate_a(rho_uu)
2451 safe_deallocate_a(rho_dd)
2452 safe_deallocate_a(rho_ud)
2454 iprojection = iprojection + nprojs
2457 safe_deallocate_a(projection%zprojection)
2472 integer,
intent(in) :: nprojs
2473 complex(real64),
intent(in) :: rho_uu(:, :), rho_dd(:, :), rho_ud(:, :)
2474 real(real64),
intent(inout) :: cur(:, :, :)
2482 cur(ip, jp, 1) = cur(ip, jp, 1) + aimag(rho_uu(ip, jp))
2483 cur(ip, jp, 2) = cur(ip, jp, 2) + aimag(rho_dd(ip, jp))
2484 cur(ip, jp, 3) = cur(ip, jp, 3) + m_half*(aimag(rho_ud(ip, jp)) - aimag(rho_ud(jp, ip)))
2485 cur(ip, jp, 4) = cur(ip, jp, 4) - m_half*(real(rho_ud(ip, jp), real64) - real(rho_ud(jp, ip), real64))
2502 class(mesh_t),
intent(in) :: mesh
2503 type(states_elec_dim_t),
intent(in) :: std
2504 logical,
intent(in) :: spiral_bnd
2505 type(wfs_elec_t),
intent(in) :: psib
2506 real(real64),
intent(in) :: weight(:)
2507 complex(real64),
allocatable,
intent(inout) :: beta_density(:, :, :, :, :)
2509 integer :: imat, iproj, jproj, ist, iprojection, nprojs, s1, s2
2511 type(projector_matrix_t),
pointer :: pmat
2512 complex(real64) :: pi_s(2), pj_s(2)
2516 assert(.not. spiral_bnd)
2517 assert(this%apply_projector_matrices)
2518 assert(psib%status() /= batch_device_packed)
2519 assert(std%dim == 2)
2520 assert(
size(weight) == psib%nst)
2522 if (.not.
allocated(beta_density))
then
2523 safe_allocate(beta_density(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:2, 1:2))
2529 if (mesh%parallel_in_domains)
then
2530 call mesh%allreduce(projection%zprojection)
2534 do imat = 1, this%nprojector_matrices
2535 pmat => this%projector_matrices(imat)
2536 nprojs = pmat%nprojs
2538 do ist = 1, psib%nst
2539 if (abs(weight(ist)) <= m_epsilon) cycle
2540 do iproj = 1, nprojs
2541 pi_s(1) = projection%zprojection((ist - 1)*std%dim + 1, iprojection + iproj)
2542 pi_s(2) = projection%zprojection((ist - 1)*std%dim + 2, iprojection + iproj)
2543 do jproj = iproj, nprojs
2544 pj_s(1) = projection%zprojection((ist - 1)*std%dim + 1, iprojection + jproj)
2545 pj_s(2) = projection%zprojection((ist - 1)*std%dim + 2, iprojection + jproj)
2548 beta_density(iproj, jproj, imat, s1, s2) = beta_density(iproj, jproj, imat, s1, s2) + &
2549 weight(ist)*conjg(pi_s(s1))*pj_s(s2)
2556 do iproj = 2, nprojs
2557 do jproj = 1, iproj - 1
2560 beta_density(iproj, jproj, imat, s1, s2) = conjg(beta_density(jproj, iproj, imat, s2, s1))
2566 iprojection = iprojection + nprojs
2569 safe_deallocate_a(projection%zprojection)
2586 type(epot_t),
target,
intent(in) :: epot
2587 complex(real64),
allocatable,
intent(in) :: rho_cmplx(:, :, :, :, :)
2588 real(real64),
allocatable,
intent(inout) :: beta_density(:, :, :, :)
2590 real(real64),
allocatable,
optional,
intent(inout) :: beta_current(:, :, :, :)
2592 integer :: imat, iatom, ip, jp, sa, sb, nprojs, n2
2593 type(projector_matrix_t),
pointer :: pmat
2594 type(projector_t),
pointer :: proj
2595 complex(real64),
allocatable :: gmat(:, :), rho_flat(:, :)
2599 if (.not.
allocated(rho_cmplx))
then
2603 assert(
allocated(beta_density))
2604 if (
present(beta_current))
then
2605 if (.not.
allocated(beta_current))
then
2606 safe_allocate(beta_current(1:this%max_nprojs, 1:this%max_nprojs, 1:this%nprojector_matrices, 1:4))
2607 beta_current = m_zero
2611 do imat = 1, this%nprojector_matrices
2612 pmat => this%projector_matrices(imat)
2613 nprojs = pmat%nprojs
2615 iatom = this%projector_to_atom(imat)
2616 proj => epot%proj(iatom)
2617 if (.not. projector_has_augmentation(proj)) cycle
2622 safe_allocate(gmat(1:n2, 1:n2))
2625 safe_allocate(rho_flat(1:n2, 1:n2))
2628 rho_flat((sa-1)*nprojs + 1:sa*nprojs, (sb-1)*nprojs + 1:sb*nprojs) = &
2629 rho_cmplx(1:nprojs, 1:nprojs, imat, sa, sb)
2632 rho_flat = matmul(conjg(transpose(gmat)), matmul(rho_flat, gmat))
2637 beta_density(ip, jp, imat, 1) = real(rho_flat(ip, jp), real64)
2638 beta_density(ip, jp, imat, 2) = real(rho_flat(nprojs + ip, nprojs + jp), real64)
2639 beta_density(ip, jp, imat, 3) = real(rho_flat(nprojs + ip, jp), real64)
2640 beta_density(ip, jp, imat, 4) = aimag(rho_flat(nprojs + ip, jp))
2644 if (
present(beta_current))
then
2646 rho_flat(nprojs + 1:n2, nprojs + 1:n2), rho_flat(nprojs + 1:n2, 1:nprojs), beta_current(:, :, imat, :))
2649 safe_deallocate_a(gmat)
2650 safe_deallocate_a(rho_flat)
2660 complex(real64) function soc_recouple_a(ll, jplus, m, m_target, s, uu)
result(aval)
2661 integer,
intent(in) :: ll, m, m_target, s
2662 logical,
intent(in) :: jplus
2663 complex(real64),
intent(in) :: uu(:, :)
2666 real(real64) :: coeff
2670 if (ml < -ll .or. ml > ll)
return
2671 coeff = soc_uspp_spinor_coeff(ll, jplus, m, s)
2672 if (abs(coeff) <= m_epsilon)
return
2674 aval = coeff * conjg(uu(m_target + ll + 1, ml + ll + 1))
2695 type(projector_matrix_t),
intent(in) :: pmat
2696 type(projector_t),
intent(in) :: proj
2697 complex(real64),
intent(out) :: gmat(:, :)
2699 integer :: nprojs, ll, ia, ipc, sa, s1, ma
2701 complex(real64),
allocatable :: uu(:, :), uu_all(:, :, :)
2705 nprojs = pmat%nprojs
2706 assert(
size(gmat, 1) == 2*nprojs .and.
size(gmat, 2) == 2*nprojs)
2709 safe_allocate(uu(1:2*proj%lmax+1, 1:2*proj%lmax+1))
2710 safe_allocate(uu_all(1:2*proj%lmax+1, 1:2*proj%lmax+1, 0:proj%lmax))
2712 do ll = 0, proj%lmax
2713 if (ll == proj%lloc) cycle
2714 call soc_uspp_ylm_transform(ll, uu(1:2*ll+1, 1:2*ll+1))
2715 uu_all(1:2*ll+1, 1:2*ll+1, ll) = uu(1:2*ll+1, 1:2*ll+1)
2717 safe_deallocate_a(uu)
2722 jplus = (ll == 0) .or. (mod(pmat%channel(ia), 2) == 1)
2724 if (pmat%l(ipc) /= ll .or. pmat%channel(ipc) /= pmat%channel(ia)) cycle
2726 ma = pmat%m(ipc) - (sa - 1)
2728 gmat(ipc + (sa-1)*nprojs, ia + (s1-1)*nprojs) = &
2729 soc_recouple_a(ll, jplus, ma, pmat%m(ia), s1, uu_all(:, :, ll)) * &
2730 soc_uspp_spinor_coeff(ll, jplus, ma, sa)
2735 safe_deallocate_a(uu_all)
2748 type(projector_t),
intent(in) :: proj
2749 type(projector_matrix_t),
intent(in) :: pmat
2750 integer,
intent(in) :: np, ncomp
2751 real(real64),
intent(in) :: vweight(:, :)
2752 real(real64),
intent(in) :: wij(:, :, :)
2753 real(real64),
intent(in) :: cw(:)
2754 real(real64),
intent(in) :: volume_element
2756 integer :: iproj, jproj
2757 real(real64) :: vv(ncomp)
2758 real(real64),
allocatable :: pairm(:, :, :)
2762 safe_allocate(pairm(1:pmat%nprojs, 1:pmat%nprojs, 1:ncomp))
2765 do iproj = 1, pmat%nprojs
2766 do jproj = 1, pmat%nprojs
2767 vv(1:ncomp) = wij(iproj, jproj, 1:ncomp)
2768 if (sum(abs(vv(1:ncomp))) <= m_epsilon) cycle
2769 res = res + sum(cw(1:ncomp)*vv(1:ncomp)*pairm(iproj, jproj, 1:ncomp))
2772 res = res*volume_element
2773 safe_deallocate_a(pairm)
2807 class(mesh_t),
intent(in) :: mesh
2808 type(epot_t),
target,
intent(in) :: epot
2809 integer,
intent(in) :: ndim
2810 real(real64),
intent(in) :: grad_pot(:, :, :)
2811 real(real64),
intent(in) :: force_aug_weight(:, :, :, :)
2812 real(real64),
intent(inout) :: force(:, :)
2814 integer :: imat, iatom, is, np, idir
2815 integer :: ncomp, icomp
2816 real(real64) :: cw(4)
2817 real(real64),
allocatable :: vweight(:, :)
2818 real(real64),
allocatable :: faug(:, :)
2819 type(projector_matrix_t),
pointer :: pmat
2820 type(projector_t),
pointer :: proj
2824 ncomp =
size(force_aug_weight, dim=4)
2825 assert(ncomp >= 1 .and. ncomp <= 4)
2826 assert(
size(grad_pot, dim=3) == ncomp)
2832 safe_allocate(faug(1:ndim, 1:ubound(force, dim=2)))
2835 do imat = 1, this%nprojector_matrices
2836 pmat => this%projector_matrices(imat)
2837 iatom = this%projector_to_atom(imat)
2838 proj => epot%proj(iatom)
2840 if (.not. projector_has_augmentation(proj)) cycle
2841 if (.not.
allocated(pmat%qmix)) cycle
2842 assert(
allocated(proj%aug%qflm))
2846 safe_allocate(vweight(1:np, 1:ncomp))
2852 vweight(is, icomp) = grad_pot(pmat%map(is), idir, icomp)
2858 vweight, force_aug_weight(:, :, imat, :), cw, mesh%volume_element)
2861 safe_deallocate_a(vweight)
2865 if (mesh%parallel_in_domains)
call mesh%allreduce(faug)
2867 force(1:ndim, :) = force(1:ndim, :) + faug(1:ndim, :)
2869 safe_deallocate_a(faug)
2897 class(mesh_t),
intent(in) :: mesh
2898 type(epot_t),
target,
intent(in) :: epot
2899 integer,
intent(in) :: periodic_dim
2900 real(real64),
intent(in) :: grad_pot(:, :, :)
2901 real(real64),
intent(in) :: aug_weight(:, :, :, :)
2902 real(real64),
intent(out) :: stress_aug(3, 3)
2904 integer :: imat, iatom, is, np, adir, bdir
2905 integer :: ncomp, icomp
2906 real(real64) :: cw(4)
2907 real(real64),
allocatable :: vweight(:, :)
2908 type(projector_matrix_t),
pointer :: pmat
2909 type(projector_t),
pointer :: proj
2913 ncomp =
size(aug_weight, dim=4)
2914 assert(ncomp >= 1 .and. ncomp <= 4)
2915 assert(
size(grad_pot, dim=3) == ncomp)
2923 do imat = 1, this%nprojector_matrices
2924 pmat => this%projector_matrices(imat)
2925 iatom = this%projector_to_atom(imat)
2926 proj => epot%proj(iatom)
2928 if (.not. projector_has_augmentation(proj)) cycle
2929 if (.not.
allocated(pmat%qmix)) cycle
2930 assert(
allocated(proj%aug%qflm))
2934 safe_allocate(vweight(1:np, 1:ncomp))
2936 do adir = 1, periodic_dim
2937 do bdir = 1, periodic_dim
2945 vweight(is, icomp) = grad_pot(pmat%map(is), adir, icomp)*pmat%position(bdir, is)
2953 np, ncomp, vweight, aug_weight(:, :, imat, :), cw, mesh%volume_element)
2957 safe_deallocate_a(vweight)
2961 if (mesh%parallel_in_domains)
call mesh%allreduce(stress_aug)
2988 class(mesh_t),
intent(in) :: mesh
2989 type(epot_t),
target,
intent(in) :: epot
2990 real(real64),
intent(in) :: op(:)
2991 real(real64),
intent(inout) :: aug_op(:, :, :)
2993 integer :: imat, iatom, is, np
2994 real(real64),
allocatable :: vweight(:, :), pairm(:, :, :)
2995 type(projector_matrix_t),
pointer :: pmat
2996 type(projector_t),
pointer :: proj
3002 do imat = 1, this%nprojector_matrices
3003 pmat => this%projector_matrices(imat)
3004 iatom = this%projector_to_atom(imat)
3005 proj => epot%proj(iatom)
3007 if (.not. projector_has_augmentation(proj)) cycle
3008 assert(
allocated(proj%aug%qflm))
3013 safe_allocate(vweight(1:np, 1:1))
3015 vweight(is, 1) = op(pmat%map(is))
3020 safe_allocate(pairm(1:pmat%nprojs, 1:pmat%nprojs, 1:1))
3022 aug_op(1:pmat%nprojs, 1:pmat%nprojs, imat) = pairm(1:pmat%nprojs, 1:pmat%nprojs, 1)*mesh%volume_element
3024 safe_deallocate_a(vweight)
3025 safe_deallocate_a(pairm)
3028 if (mesh%parallel_in_domains)
then
3029 call mesh%allreduce(aug_op(:, :, imat), dim = (/pmat%nprojs, pmat%nprojs/))
3046 class(mesh_t),
intent(in) :: mesh
3047 type(epot_t),
target,
intent(in) :: epot
3048 real(real64),
intent(in) :: force_aug_weight(:, :, :)
3049 real(real64),
intent(inout) :: aug_density(:)
3051 integer :: imat, iatom, is, ip, np
3052 real(real64),
allocatable :: acc(:), wcol(:, :)
3053 type(projector_matrix_t),
pointer :: pmat
3054 type(projector_t),
pointer :: proj
3058 do imat = 1, this%nprojector_matrices
3059 pmat => this%projector_matrices(imat)
3060 iatom = this%projector_to_atom(imat)
3061 proj => epot%proj(iatom)
3063 if (.not. projector_has_augmentation(proj)) cycle
3064 if (.not.
allocated(pmat%qmix)) cycle
3065 assert(
allocated(proj%aug%qflm))
3071 safe_allocate(wcol(1:proj%aug%qflm_ncombo, 1:1))
3073 call projector_aug_pair_to_columns(proj, pmat, 1, force_aug_weight(:, :, imat:imat), wcol)
3076 safe_allocate(acc(1:np))
3077 call blas_gemv(
'N', np, proj%aug%qflm_ncombo, m_one, proj%aug%qflm(1, 1), np, &
3078 wcol(1, 1), 1, m_zero, acc(1), 1)
3082 aug_density(ip) = aug_density(ip) + acc(is)
3084 safe_deallocate_a(acc)
3087 safe_deallocate_a(wcol)
3096#include "nonlocal_pseudopotential_inc.F90"
3099#include "complex.F90"
3100#include "nonlocal_pseudopotential_inc.F90"
Copies a vector x, to a vector y.
double sqrt(double __x) __attribute__((__nothrow__
subroutine, public accel_free_buffer(this, async)
subroutine, public accel_finish()
subroutine, public accel_detach_buffer(this)
Clear a buffer handle without freeing device memory.
logical pure function, public accel_buffer_is_allocated(this)
pure logical function, public accel_is_enabled()
integer, parameter, public accel_mem_read_only
This module implements batches of mesh functions.
This module implements common operations on batches of mesh functions.
This module contains interfaces for BLAS routines You should not use these routines directly....
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
integer, parameter, public spinors
integer, parameter, public spin_polarized
integer, parameter, public spin_orbit
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module is intended to contain "only mathematical" functions and procedures.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Exact inverse of the ultrasoft/PAW generalized overlap operator for overlapping spheres.
subroutine, public nonlocal_pseudopotential_force_uspp(this, mesh, epot, ndim, grad_pot, force_aug_weight, force)
Ultrasoft augmentation contribution to the forces.
subroutine nonlocal_pseudopotential_destroy_proj(this)
Destroy the data of nonlocal_pseudopotential_t.
subroutine nonlocal_pseudopotential_detach_accel_buffers(this)
Clear copied accelerator handles so they do not alias source buffers.
subroutine dnonlocal_pseudopotential_force(this, mesh, st, spiral_bnd, iqn, ndim, psi1b, psi2b, force)
calculate contribution to forces, from non-local potentials
subroutine znonlocal_pseudopotential_position_commutator(this, mesh, std, spiral_bnd, psib, commpsib, async)
apply the commutator between the non-local potential and the position to the wave functions.
subroutine, public nonlocal_pseudopotential_aug_density(this, mesh, epot, force_aug_weight, aug_density)
Accumulate the ultrasoft augmentation density n_aug(r) = sum_ij rho_ij Q_ij(r-R) (summed over all ult...
subroutine znonlocal_pseudopotential_r_vnlocal(this, mesh, std, spiral_bnd, psib, commpsib, eigenval, only_qmix)
Accumulates to commpsib the result of x V_{nl} | psib >
subroutine, public znonlocal_pseudopotential_start(this, mesh, std, spiral_bnd, psib, projection, async)
Start application of non-local potentials (stored in the Hamiltonian) to the wave functions.
subroutine, public nonlocal_pseudopotential_stress_uspp(this, mesh, epot, periodic_dim, grad_pot, aug_weight, stress_aug)
Ultrasoft augmentation contribution to the stress tensor.
subroutine, public znonlocal_pseudopotential_add_overlap_inplace(this, mesh, std, xb, phase, spiral_bnd, apply_phase)
In-place version of the generalized overlap: xb := S xb (or S^{-1} xb, depending on this)....
subroutine nonlocal_pseudopotential_soc_build_zmix_cmplx(pmat, proj, use_qij, so_strength)
Build the spin-orbit 2x2 spin coupling (zmix) in the COMPLEX-Y_lm projector basis.
subroutine nonlocal_pseudopotential_paw_onsite(this, epot, n_paw, paw_imat, onsite_density_matrix, dij_buf)
Compute the PAW one-center Hamiltonian coupling of every PAW atom and accumulate the energy correctio...
integer function projector_beta_index(proj, ll, ic)
subroutine, public dnonlocal_pseudopotential_density_matrix(this, mesh, std, spiral_bnd, psib, weight, beta_density, weight2, beta_density2, beta_current)
Accumulate occupation-weighted beta-projector density matrices for USPP density.
subroutine znonlocal_pseudopotential_force(this, mesh, st, spiral_bnd, iqn, ndim, psi1b, psi2b, force)
calculate contribution to forces, from non-local potentials
subroutine dnonlocal_pseudopotential_force_overlap_cross(this, mesh, st, iqn, ndim, psib, gpsib, chib, gchib, force)
Ultrasoft DFT+U force: the overlap-derivative (d_R S) term, as a cross density matrix.
real(real64) function nonlocal_pseudopotential_aug_contract(proj, pmat, np, ncomp, vweight, wij, cw, volume_element)
Integrate a gathered per-sphere-point field against the augmentation charges and contract with the co...
subroutine, public dnonlocal_pseudopotential_apply_overlap(this, mesh, std, psib, spsib, phase, spiral_bnd, apply_phase)
Apply the ultrasoft/PAW generalized overlap S = 1 + sum_ij |beta_i> q_ij <beta_j| (or,...
subroutine dnonlocal_pseudopotential_finish(this, mesh, spiral_bnd, std, projection, vpsib)
finish the application of non-local potentials.
subroutine, public nonlocal_pseudopotential_accel_rebuild(this, space, mesh)
Rebuild accelerator buffers after an intrinsic copy.
subroutine dnonlocal_pseudopotential_position_commutator(this, mesh, std, spiral_bnd, psib, commpsib, async)
apply the commutator between the non-local potential and the position to the wave functions.
subroutine, public nonlocal_pseudopotential_share_projector_data(this, donor)
Alias the heavy per-point projector data of a donor instance.
subroutine, public nonlocal_pseudopotential_rebind_projectors(this, epot)
Rebind projector matrix pointers (map, position) to a target epot.
subroutine znonlocal_pseudopotential_force_overlap_cross(this, mesh, st, iqn, ndim, psib, gpsib, chib, gchib, force)
Ultrasoft DFT+U force: the overlap-derivative (d_R S) term, as a cross density matrix.
subroutine, public znonlocal_pseudopotential_reconstruct_paw_wfs(this, epot, mesh, ik, psi)
Add the PAW one-center correction to a single smooth wavefunction, reconstructing the all-electron wa...
subroutine dnonlocal_pseudopotential_r_vnlocal(this, mesh, std, spiral_bnd, psib, commpsib, eigenval, only_qmix)
Accumulates to commpsib the result of x V_{nl} | psib >
subroutine, public dnonlocal_pseudopotential_reconstruct_paw_wfs(this, epot, mesh, ik, psi)
Add the PAW one-center correction to a single smooth wavefunction, reconstructing the all-electron wa...
subroutine nonlocal_pseudopotential_build_accel_buffers(this, space, mesh)
Build accelerator buffers for projectors from host-side projector matrices.
subroutine, public nonlocal_pseudopotential_soc_density_to_real(this, epot, rho_cmplx, beta_density, beta_current)
Rotate the complex-Y_lm projector density matrix to the real-Y_lm basis (SOC USPP).
subroutine, public znonlocal_pseudopotential_density_matrix(this, mesh, std, spiral_bnd, psib, weight, beta_density, weight2, beta_density2, beta_current)
Accumulate occupation-weighted beta-projector density matrices for USPP density.
subroutine, public znonlocal_pseudopotential_apply_overlap(this, mesh, std, psib, spsib, phase, spiral_bnd, apply_phase)
Apply the ultrasoft/PAW generalized overlap S = 1 + sum_ij |beta_i> q_ij <beta_j| (or,...
subroutine nonlocal_pseudopotential_qij_to_pairs(proj, pmat, np, ncomp, field, pairm)
Integrate a mesh field against the augmentation charges Q_ij over one augmentation sphere: pairm_ij^c...
subroutine, public nonlocal_pseudopotential_aug_moment(this, mesh, epot, op, aug_op)
Ultrasoft augmentation moments of a local operator A(r): int A(r) Q_ij(r-R_I) dr.
subroutine, public nonlocal_pseudopotential_density_matrix_spinor(this, mesh, std, spiral_bnd, psib, weight, beta_density, beta_current)
Noncollinear (spinor) projector density matrix for the ultrasoft augmentation.
subroutine nonlocal_pseudopotential_soc_screen_cmplx(pmat, proj, mesh, veff, dij_onsite)
Add the screening int V^{ab}(r) Q_ij(r) to the complex-Y_lm SOC zmix.
subroutine, public dnonlocal_pseudopotential_add_overlap_inplace(this, mesh, std, xb, phase, spiral_bnd, apply_phase)
In-place version of the generalized overlap: xb := S xb (or S^{-1} xb, depending on this)....
subroutine nonlocal_pseudopotential_spinor_current_slabs(nprojs, rho_uu, rho_dd, rho_ud, cur)
Accumulate the four one-center current slabs of a spinor projector density matrix.
subroutine, public nonlocal_pseudopotential_symmetrize_onsite(this)
Symmetrize the PAW one-center density matrix rho_ij over the crystal symmetries.
subroutine, public nonlocal_pseudopotential_density_matrix_spinor_cmplx(this, mesh, std, spiral_bnd, psib, weight, beta_density)
Full COMPLEX spinor projector density matrix (fully-relativistic ultrasoft).
logical pure function nonlocal_pseudopotential_self_overlap(this)
Returns .true. if the Hamiltonian contains projectors, which overlap with themself.
subroutine nonlocal_pseudopotential_ghost_check(this, mesh, epot)
Warn about augmentation ghost channels: a near-singular direction of the channel-block overlap metric...
subroutine nonlocal_pseudopotential_init(this)
initialize the nonlocal_pseudopotential_t object
subroutine, public dnonlocal_pseudopotential_start(this, mesh, std, spiral_bnd, psib, projection, async)
Start application of non-local potentials (stored in the Hamiltonian) to the wave functions.
subroutine nonlocal_pseudopotential_soc_recoupling_matrix(pmat, proj, gmat)
Build the mixed (l,j)->spin recoupling matrix G on composite (projector, spin) indices.
subroutine, public nonlocal_pseudopotential_detach_copy(this, donor)
Detach the projector data of an instance obtained by intrinsic assignment.
complex(real64) function soc_recouple_a(ll, jplus, m, m_target, s, uu)
A(l,jplus,m,m_l_target,s) = spinor_coeff(l,jplus,m,s) * conjg(uu(a, m_l+l+1)), with m_l = m + (s-1) r...
subroutine, public nonlocal_pseudopotential_update_dij(this, mesh, epot, veff, add_bare, onsite_density_matrix)
Screen the ultrasoft nonlocal coupling matrix D_ij with the local potential.
subroutine nonlocal_pseudopotential_build_proj(this, space, mesh, epot, ispin, overlap_operator, inverse_overlap_operator)
build the projectors for the application of pseudo-potentials
subroutine nonlocal_pseudopotential_build_projector_phase_accel_buffer(this)
Rebuild projector phase accelerator buffer from host-side projector phases.
subroutine, public nonlocal_pseudopotential_build_paw_symm(this, epot, space, gr, ions)
Build the crystal-symmetry data used to symmetrize the PAW one-center density matrix.
subroutine znonlocal_pseudopotential_finish(this, mesh, spiral_bnd, std, projection, vpsib)
finish the application of non-local potentials.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
subroutine, public projector_matrix_deallocate(this, owns_data)
subroutine, public projector_matrix_allocate(this, nprojs, sphere, has_mix_matrix, is_cmplx, complex_mix, nspin_channels)
logical elemental function, public projector_is(p, type)
logical elemental function, public projector_is_null(p)
integer, parameter, public proj_hgh
integer, parameter, public proj_uspp
integer, parameter, public proj_rkb
integer, parameter, public proj_none
integer, parameter, public proj_kb
Spin-orbit coupling for fully-relativistic ultrasoft pseudopotentials.
This module handles spin dimensions of the states and the k-point distribution.
logical function, public submesh_overlap(sm1, sm2, space)
type(type_t), parameter, public type_cmplx
type(type_t), parameter, public type_integer
type(type_t), parameter, public type_float
subroutine build_inverse_overlap_sim_grid(pmat, mesh)
Rebuild the inverse-overlap mix matrix (mix = -T, with T = q (1 + M q)^{-1}) using the projector over...
logical function projector_counted(proj)
Describes mesh distribution to nodes.
nonlocal part of the pseudopotential
Class for projections of wave functions.
A set of projectors defined on a submesh.
The projector data type is intended to hold the local and non-local parts of the pseudopotentials....
The rkb_projector data type holds the KB projectors build with total angular momentum eigenfunctions....