def get_grains_connected_to_face(mesh, face_set, node_id_grain_lut):
    """
    This function find the grain connected to the face set given as argument.

    Three nodes on a grain boundary can all be intersected by one grain
    in which case the grain face is on the boundary or by two grains. It
    is therefore sufficient to look at the set of grains contained by any
    three nodes in the face set and take the intersection of these sets.

    :param mesh: The mesh
    :type mesh: :class:`Mesh`
    :param face_set: The face set to find grains connected to
    :type: face_set: :class:`ElementSet`
    :return: The grain identifiers that intersect the face.
    :rtype: list of ints
    """

    grains_connected_to_face = []

    grains = face_set.name[4:].split("_")
    if len(grains) == 2:
        return [int(g) for g in grains]

    triangle_element = mesh.elements[face_set.ids[0]]

    for node_id in triangle_element.vertices:
        grains_with_node_id = node_id_grain_lut[node_id]
        grains_connected_to_face.append(set(grains_with_node_id))

    return list(set.intersection(*grains_connected_to_face))