60 integer,
allocatable :: imats(:)
61 integer,
allocatable :: coff(:)
64 logical :: is_cmplx = .false.
67 real(real64),
allocatable :: dt(:, :, :)
68 complex(real64),
allocatable :: zt(:, :, :)
75 logical,
public :: use_global_coupling = .false.
76 logical,
public :: coupling_built = .false.
77 integer :: ncluster = 0
78 integer,
allocatable :: proj_offset(:)
79 type(overlap_cluster_t),
allocatable :: clusters(:)
89 logical :: uspp_gpu_approx_warned = .false.
98 subroutine overlap_matrix_detect(this, nmat, projector_matrices, projector_to_atom, epot, space, self_overlap)
99 class(overlap_matrix_t),
intent(inout) :: this
100 integer,
intent(in) :: nmat
101 type(projector_matrix_t),
intent(in) :: projector_matrices(:)
102 integer,
intent(in) :: projector_to_atom(:)
103 type(epot_t),
intent(in) :: epot
104 class(space_t),
intent(in) :: space
105 logical,
intent(in) :: self_overlap
107 integer :: im, jm, ia, ja, ic, root, nroots, kk
108 integer,
allocatable :: parent(:), root_of(:), csize(:), cluster_of(:), fill(:)
109 logical :: any_overlap
116 safe_allocate(this%proj_offset(1:max(nmat, 1)))
119 this%proj_offset(im) = kk
120 kk = kk + projector_matrices(im)%nprojs
130 safe_allocate(parent(1:nmat))
134 any_overlap = .false.
136 ia = projector_to_atom(im)
138 ja = projector_to_atom(jm)
148 this%use_global_coupling = any_overlap .or. self_overlap
149 if (.not. this%use_global_coupling)
then
150 safe_deallocate_a(parent)
156 safe_allocate(cluster_of(1:nmat))
157 safe_allocate(root_of(1:nmat))
158 safe_allocate(csize(1:nmat))
165 if (root_of(kk) == root)
then
172 root_of(nroots) = root
176 csize(ic) = csize(ic) + 1
179 this%ncluster = nroots
180 safe_allocate(this%clusters(1:nroots))
181 safe_allocate(fill(1:nroots))
184 this%clusters(ic)%nmat = csize(ic)
185 safe_allocate(this%clusters(ic)%imats(1:csize(ic)))
186 safe_allocate(this%clusters(ic)%coff(1:csize(ic)))
191 fill(ic) = fill(ic) + 1
192 this%clusters(ic)%imats(fill(ic)) = im
196 do im = 1, this%clusters(ic)%nmat
197 this%clusters(ic)%coff(im) = kk
198 kk = kk + projector_matrices(this%clusters(ic)%imats(im))%nprojs
200 this%clusters(ic)%nc = kk
204 this%clusters(ic)%sdim = 1
205 if (
allocated(projector_matrices(this%clusters(ic)%imats(1))%zqmix)) this%clusters(ic)%sdim = 2
206 do im = 1, this%clusters(ic)%nmat
207 assert(
allocated(projector_matrices(this%clusters(ic)%imats(im))%zqmix) .eqv. this%clusters(ic)%sdim == 2)
211 safe_deallocate_a(parent)
212 safe_deallocate_a(cluster_of)
213 safe_deallocate_a(root_of)
214 safe_deallocate_a(csize)
215 safe_deallocate_a(fill)
222 recursive integer function uf_find(parent, ii)
result(rr)
223 integer,
intent(inout) :: parent(:)
224 integer,
intent(in) :: ii
226 if (parent(ii) /= ii) parent(ii) =
uf_find(parent, parent(ii))
233 integer,
intent(inout) :: parent(:)
234 integer,
intent(in) :: ii, jj
240 if (ri /= rj) parent(rj) = ri
262 complex(real64),
allocatable,
intent(in) :: projector_phases(:, :, :, :)
263 class(
mesh_t),
intent(in) :: mesh
264 integer,
intent(in) :: kstart
265 integer,
intent(in) :: kend
267 integer :: c, ik, nc, sdim, n2, a, b, oa, ob, s1, s2, ii, jj, nI
268 integer :: blkmap(2, 2)
271 complex(real64),
allocatable :: zgI(:, :), zgJ(:, :), mmat(:, :), qmat(:, :), amat(:, :), tmat(:, :)
275 if (.not. this%use_global_coupling)
then
284 uspp_gpu_approx_warned = .
true.
285 message(1) =
"Ultrasoft projector spheres of different atoms overlap on the grid."
286 message(2) =
"The exact inverse overlap S^{-1} is applied on the CPU only; the GPU path"
287 message(3) =
"still uses the per-atom approximation. Convergence on GPU may be degraded."
291 phased =
allocated(projector_phases)
299 do c = 1, this%ncluster
300 cl => this%clusters(c)
306 cl%is_cmplx = phased .or. sdim == 2 .or. projector_matrices(cl%imats(1))%is_cmplx
308 if (cl%is_cmplx)
then
309 if (.not.
allocated(cl%zt))
then
310 safe_allocate(cl%zt(1:n2, 1:n2, kstart:kend))
313 if (.not.
allocated(cl%dt))
then
314 safe_allocate(cl%dt(1:nc, 1:nc, kstart:kend))
318 safe_allocate(mmat(1:nc, 1:nc))
319 safe_allocate(qmat(1:n2, 1:n2))
320 safe_allocate(amat(1:n2, 1:n2))
321 safe_allocate(tmat(1:n2, 1:n2))
334 projector_matrices(cl%imats(b)), zgi, zgj, mmat, oa, ob)
335 safe_deallocate_a(zgj)
337 safe_deallocate_a(zgi)
342 mmat(ii, jj) = conjg(mmat(jj, ii))
346 if (mesh%parallel_in_domains)
call mesh%allreduce(mmat, dim = (/nc, nc/))
347 mmat = mmat * mesh%volume_element
352 ni = projector_matrices(cl%imats(a))%nprojs
355 qmat(oa+1:oa+ni, oa+1:oa+ni) = &
356 cmplx(projector_matrices(cl%imats(a))%qmix(1:ni, 1:ni),
m_zero, real64)
361 qmat((s1-1)*nc + oa+1:(s1-1)*nc + oa+ni, (s2-1)*nc + oa+1:(s2-1)*nc + oa+ni) = &
362 projector_matrices(cl%imats(a))%zqmix(1:ni, 1:ni, blkmap(s1, s2))
371 amat((s1-1)*nc + 1:s1*nc, :) = matmul(mmat, qmat((s1-1)*nc + 1:s1*nc, :))
374 amat(ii, ii) = amat(ii, ii) +
m_z1
377 tmat = matmul(qmat, amat)
379 if (cl%is_cmplx)
then
380 cl%zt(1:n2, 1:n2, ik) = -tmat(1:n2, 1:n2)
382 cl%dt(1:nc, 1:nc, ik) = -real(tmat(1:nc, 1:nc), real64)
387 safe_deallocate_a(mmat)
388 safe_deallocate_a(qmat)
389 safe_deallocate_a(amat)
390 safe_deallocate_a(tmat)
393 this%coupling_built = .
true.
401 integer,
intent(in) :: im
402 integer,
intent(in) :: ik
403 complex(real64),
allocatable,
intent(out) :: zg(:, :)
405 integer :: np, npr, p, i
406 complex(real64) :: ph
408 np = projector_matrices(im)%npoints
409 npr = projector_matrices(im)%nprojs
410 safe_allocate(zg(1:npr, 1:max(np, 1)))
413 if (
associated(projector_matrices(im)%zprojectors))
then
416 ph = conjg(projector_phases(p, 1, im, ik))
418 zg(i, p) = projector_matrices(im)%zprojectors(p, i)*ph
424 zg(i, p) = projector_matrices(im)%zprojectors(p, i)
431 ph = conjg(projector_phases(p, 1, im, ik))
433 zg(i, p) = projector_matrices(im)%dprojectors(p, i)*ph
439 zg(i, p) = cmplx(projector_matrices(im)%dprojectors(p, i),
m_zero, real64)
453 complex(real64),
intent(in) :: zgI(:, :)
454 complex(real64),
intent(in) :: zgJ(:, :)
455 complex(real64),
intent(inout) :: mmat(:, :)
456 integer,
intent(in) :: oa
457 integer,
intent(in) :: ob
459 integer :: ri, rj, ip, jp, ipe, jpe, ni, nj, i, j, dd
460 complex(real64) :: ket
464 do ri = 1, pmi%nregions
465 ipe = pmi%regions(ri + 1) - 1
466 do rj = 1, pmj%nregions
467 jpe = pmj%regions(rj + 1) - 1
470 do while (ip <= ipe .and. jp <= jpe)
471 dd = pmi%map(ip) - pmj%map(jp)
474 else if (dd > 0)
then
480 mmat(oa+i, ob+j) = mmat(oa+i, ob+j) + conjg(zgi(i, ip))*ket
502 if (
allocated(this%clusters))
then
503 do ic = 1,
size(this%clusters)
504 safe_deallocate_a(this%clusters(ic)%imats)
505 safe_deallocate_a(this%clusters(ic)%coff)
506 safe_deallocate_a(this%clusters(ic)%dt)
507 safe_deallocate_a(this%clusters(ic)%zt)
509 safe_deallocate_a(this%clusters)
511 safe_deallocate_a(this%proj_offset)
513 this%use_global_coupling = .false.
514 this%coupling_built = .false.
521#include "nonlocal_overlap_matrix_inc.F90"
524#include "complex.F90"
525#include "nonlocal_overlap_matrix_inc.F90"
pure logical function, public accel_is_enabled()
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_z1
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
Exact inverse of the ultrasoft/PAW generalized overlap operator for overlapping spheres.
subroutine doverlap_matrix_apply(this, projector_matrices, proj, nst_linear, nst, spin_dim, ik)
Apply the exact inverse-overlap coupling p` = -T p (mix = -T stored per cluster), dense within each o...
subroutine overlap_matrix_build(this, projector_matrices, projector_phases, mesh, kstart, kend)
Assemble the exact inverse-overlap coupling -T for each overlap cluster.
subroutine zoverlap_matrix_apply(this, projector_matrices, proj, nst_linear, nst, spin_dim, ik)
Apply the exact inverse-overlap coupling p` = -T p (mix = -T stored per cluster), dense within each o...
subroutine uf_union(parent, ii, jj)
Union-find "union" of two projector matrices into one cluster.
subroutine overlap_matrix_detect(this, nmat, projector_matrices, projector_to_atom, epot, space, self_overlap)
Detect distinct-atom projector overlap and group the projector matrices into the connected components...
subroutine overlap_matrix_end(this)
Release the exact inverse-overlap cluster data.
recursive integer function uf_find(parent, ii)
Union-find "find" with path compression (roots of the projector-overlap graph).
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
logical function, public submesh_overlap(sm1, sm2, space)
subroutine fill_phased_ket(im, ik, zg)
subroutine accumulate_gram(pmI, pmJ, zgI, zgJ, mmat, oa, ob)
Describes mesh distribution to nodes.
One connected component of the projector-overlap graph.
The exact inverse-overlap operator, grouped into overlap clusters.
A set of projectors defined on a submesh.