Take as input a matrix in which the n-th row stores the atoms that are in the same polarization group as the n-th atom (rows are padded with zeros) and assign to each atom a group index, according to the input information. This is a way of compressing and making more clear the handling of polarization groups.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(in) | :: | polgroup_neigh(:,:) | |||
integer(kind=ip), | intent(out) | :: | mm2pol(:) |
subroutine polgroup11_to_mm2pg(polgroup_neigh, mm2pol)
!! Take as input a matrix in which the n-th row stores the atoms
!! that are in the same polarization group as the n-th atom (rows are
!! padded with zeros) and assign to each atom a group index, according to
!! the input information. This is a way of compressing and making more
!! clear the handling of polarization groups.
use mod_memory, only : ip
implicit none
integer(ip), intent(in) :: polgroup_neigh(:,:)
integer(ip), intent(out) :: mm2pol(:)
integer(ip) :: i, j, maxn, ipg, mm_atoms
mm2pol = 0
ipg = 1
maxn = size(polgroup_neigh, 1)
mm_atoms = size(polgroup_neigh, 2)
do i=1, mm_atoms
if(mm2pol(i) == 0) then
! This is a new group
do j=1, maxn
if(polgroup_neigh(j,i) == 0) exit
if(mm2pol(polgroup_neigh(j,i)) /= 0) then
call fatal_error("Unexpected error in polgroup11_to_mm2pg")
end if
mm2pol(polgroup_neigh(j,i)) = ipg
end do
ipg = ipg + 1
end if
end do
if( any(mm2pol == 0) ) then
call fatal_error("Unexpected error in polgroup11_to_mm2pg")
end if
end subroutine polgroup11_to_mm2pg