# GetUEGKE Subroutine

## public subroutine GetUEGKE(I, J, K, ALat, tUEGTrueEnergies, tUEGOffset, k_offset, Energy, dUnscaledEnergy)

### Arguments

Type IntentOptional Attributes Name
integer :: I
integer :: J
integer :: K
real(kind=dp) :: ALat(3)
logical :: tUEGTrueEnergies
logical :: tUEGOffset
real(kind=dp) :: k_offset(3)
real(kind=dp) :: Energy
real(kind=dp) :: dUnscaledEnergy

## Source Code

    SUBROUTINE GetUEGKE(I, J, K, ALAT, tUEGTrueEnergies, tUEGOffset, k_offset, Energy, dUnscaledEnergy)
INTEGER I, J, K
real(dp) ALat(3), k_offset(3), Energy, E
LOGICAL tUEGOffset, tUEGTrueEnergies
real(dp) ::  dUnscaledEnergy
integer :: kvecX, kvecY, kvecZ
!==================================
! initialize unscaled energy for the case of not using tUEGTrueEnergies
dunscaledEnergy = 0.0_dp
if (tUEG2) then
! kvectors in cartesian coordinates
kvecX = k_lattice_vectors(1, 1) * I + k_lattice_vectors(2, 1) * J + k_lattice_vectors(3, 1) * K
kvecY = k_lattice_vectors(1, 2) * I + k_lattice_vectors(2, 2) * J + k_lattice_vectors(3, 2) * K
kvecZ = k_lattice_vectors(1, 3) * I + k_lattice_vectors(2, 3) * J + k_lattice_vectors(3, 3) * K

IF (tUEGTrueEnergies) then
if (tUEGOffset) then
E = (kvecX + k_offset(1))**2 + (kvecY + k_offset(2))**2 + (kvecZ + k_offset(3))**2
else
E = (kvecX)**2 + (kvecY)**2 + (kvecZ)**2
end if
Energy = 0.5_dp * E * k_lattice_constant**2
dUnscaledEnergy = ((kvecX)**2 + (kvecY)**2 + (kvecZ)**2)
ELSE
Energy = ((kvecX)**2 + (kvecY)**2 + (kvecZ)**2)
end if

return
end if
!==================================
IF (tUEGTrueEnergies) then
IF (tUEGOffset) then
E = ((I + k_offset(1))**2 / ALAT(1)**2)
E = E + ((J + k_offset(2))**2 / ALAT(2)**2)
E = E + ((K + k_offset(3))**2 / ALAT(3)**2)
else
E = (I * I / ALAT(1)**2)
E = E + (J * J / ALAT(2)**2)
E = E + (K * K / ALAT(3)**2)
end if
Energy = 0.5 * 4 * PI * PI * E
dUnscaledEnergy = (I * I)
dUnscaledEnergy = dUnscaledEnergy + (J * J)
dUnscaledEnergy = dUnscaledEnergy + (K * K)
ELSE
E = (I * I)
E = E + (J * J)
E = E + (K * K)
Energy = E
end if
END SUBROUTINE GetUEGKE