get_neighbors_lattice Function

private function get_neighbors_lattice(this, ind) result(neighbors)

Type Bound

lattice

Arguments

Type IntentOptional Attributes Name
class(lattice) :: this
integer, intent(in) :: ind

Return Value integer, allocatable, (:)


Contents

Source Code


Source Code

    function get_neighbors_lattice(this, ind) result(neighbors)
        class(lattice) :: this
        integer, intent(in) :: ind
        ! i can't really use the stored information here, since it is
        ! input dependent and this can be out of bound.. exactly what i
        ! want to avoid.. so allocate it here!
        integer, allocatable :: neighbors(:)
#ifdef DEBUG_
        character(*), parameter :: this_routine = "get_neighbors_lattice"
#endif

        ! make all assert on a seperate line, so we exactly know what is
        ! going wrong..
        ASSERT(ind <= this%get_nsites())
        ASSERT(ind > 0)
        ASSERT(allocated(this%sites))
        ASSERT(allocated(this%sites(ind)%neighbors))

        ! apparently i have to access the data directly..
        if (this%get_nsites() == 1) then
            ! output -1 to indicate that there are no neighbors, since the
            ! lattice is too small and catch errors early.. or i could
            ! users not allow to initialize such a lattice.. woudl also
            ! make sense!
            allocate(neighbors(1))
            neighbors = -1
        else
            allocate(neighbors(this%sites(ind)%get_num_neighbors()))
            neighbors = this%sites(ind)%neighbors
        end if

    end function get_neighbors_lattice