find_periodic_neighbors_ole Function

private function find_periodic_neighbors_ole(this, ind, A)

Type Bound

ole

Arguments

Type IntentOptional Attributes Name
class(ole) :: this
integer, intent(in) :: ind(2)
integer, intent(in) :: A(:,:)

Return Value integer


Contents


Source Code

    integer function find_periodic_neighbors_ole(this, ind, A)
        ! function to give me a periodic neighbor of a specific lattice
        class(ole) :: this
        integer, intent(in) :: ind(2), A(:, :)
        integer :: temp(-this%length(1):(this%length(1) + 1), &
                        -this%length(2):this%length(1))

        integer :: unique, shift(4, 2), i
        ! i am not sure, if i have to specify the indices and size of the
        ! matrix inputted..

        ! get the lattice vectors:
        associate(r1 => this%lat_vec(1:2, 1), r2 => this%lat_vec(1:2, 2), &
                   x => ind(1), y => ind(2))

            shift = transpose(reshape([r1, r2, r1 + r2, r1 - r2], [2, 4]))

            find_periodic_neighbors_ole = -1

            do i = 1, 4
                ! apply all the periodic vectors one after the other
                ! negative and positive..
                temp = apply_pbc(A, shift(i, :))

                if (temp(x, y) /= 0) then
                    find_periodic_neighbors_ole = temp(x, y)
                    return
                end if

                temp = apply_pbc(A, -shift(i, :))

                if (temp(x, y) /= 0) then
                    find_periodic_neighbors_ole = temp(x, y)
                    return
                end if
            end do

        end associate

        find_periodic_neighbors_ole = unique

    end function find_periodic_neighbors_ole