get_inverse_metric Subroutine

public pure subroutine get_inverse_metric(periodic, lattice, lat, ginv, error)

Lattice vectors of the periodic directions and the inverse metric of the periodic subspace.

For the periodic lattice vectors A the metric is G = A^T A. A vector r has the fractional coordinates s = G^-1 A^T r within the periodic subspace, and 1 / sqrt(G^-1_kk) is the height of the cell along lattice vector k. Nonperiodic directions have zero entries in both results, such that the same expressions hold for 1D, 2D and 3D periodicity.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: periodic(:)

Periodic dimensions

real(kind=wp), intent(in) :: lattice(:,:)

Lattice vectors

real(kind=wp), intent(out) :: lat(3,3)

Lattice vectors of the periodic directions, zero for nonperiodic ones

real(kind=wp), intent(out) :: ginv(3,3)

Inverse metric of the periodic subspace, zero for nonperiodic directions

type(error_type), intent(out), allocatable :: error

Error handling


Source Code

pure subroutine get_inverse_metric(periodic, lattice, lat, ginv, error)

   !> Periodic dimensions
   logical, intent(in) :: periodic(:)

   !> Lattice vectors
   real(wp), intent(in) :: lattice(:, :)

   !> Lattice vectors of the periodic directions, zero for nonperiodic ones
   real(wp), intent(out) :: lat(3, 3)

   !> Inverse metric of the periodic subspace, zero for nonperiodic directions
   real(wp), intent(out) :: ginv(3, 3)

   !> Error handling
   type(error_type), allocatable, intent(out) :: error

   integer :: k, ndim, p_axes(3)
   logical :: active(3)
   real(wp) :: metric(3, 3)

   call get_periodic_axes(periodic, ndim, p_axes)
   active(:) = .false.
   active(p_axes(:ndim)) = .true.

   lat(:, :) = 0.0_wp
   metric(:, :) = 0.0_wp
   do k = 1, 3
      if (active(k)) then
         lat(:, k) = lattice(:, k)
      else
         ! Decoupled unit entry keeps the metric invertible
         metric(k, k) = 1.0_wp
      end if
   end do
   metric(:, :) = metric + matmul(transpose(lat), lat)

   ! Squared volume of the periodic subspace relative to the squared lengths
   if (.not. (matdet_3x3(metric) > tol_deg**2 &
      & * metric(1, 1) * metric(2, 2) * metric(3, 3))) then
      call fatal_error(error, "Periodic lattice vectors are linearly dependent")
      return
   end if

   ginv(:, :) = matinv_3x3(metric)
   do k = 1, 3
      if (.not. active(k)) then
         ginv(k, :) = 0.0_wp
         ginv(:, k) = 0.0_wp
      end if
   end do

end subroutine get_inverse_metric