def node_below_adjacent_elements(node, surface):
    """
    node_below_adjacent_elements determines if a node is below any element adjacent to it in the surface.
    Consider the following layout:

    *-*-*-*  Here, the nodes are shown as * and node (0,0) as X. Elements are shown as o and neighboring
    |O|O|o|  elements to node X are O. This function determines if a node (i,j,k) is adjacent to or beneath
    *-x-*-*  any of the elements for which it could be a vertex. As four elements share a "corner", we need
    |O|O|o|  to check to see if the node is at the highest element position or below for any corner.
    *-*-*-*

    :param node: index of a node
    :param surface: mesh of element heights
    :return: boolean
    """
    (i, j, k) = node
    maximum = 0
    for location in [(i - 1, j - 1), (i, j - 1), (i - 1, j), (i, j)]:
        if 0 <= i < surface.shape[0] and 0 <= j < surface.shape[1]:
            maximum = max(maximum, surface[location])
    return k <= maximum + 1