def get_facet_mask(function_space, mode='geometric', facet='bottom'):
    """
    Returns the top/bottom nodes of extruded 3D elements.

    :arg function_space: Firedrake :class:`FunctionSpace` object
    :kwarg str mode: 'topological', to retrieve nodes that lie on the facet, or
        'geometric' for nodes whose basis functions do not vanish on the facet.
    :kwarg str facet: 'top' or 'bottom'

    .. note::
        The definition of top/bottom depends on the direction of the extrusion.
        Here we assume that the mesh has been extruded upwards (along positive
        z axis).
    """
    section, iset, facets = function_space.cell_boundary_masks[mode]
    ifacet = -2 if facet == 'bottom' else -1
    off = section.getOffset(facets[ifacet])
    dof = section.getDof(facets[ifacet])
    indices = iset[off:off+dof]
    return indices