def get_ele_and_grain_with_node_id(
        mesh, node_id, grain_id_1, grain_id_2, set_type="poly"):
    """
    Find the element that has vertices with the node identifier node_id
    and if it belongs to grain with identifier grain_id_1 or grain_id_2

    :param mesh: The mesh.
    :type mesh: :class:`Mesh`
    :param node_id: THe node to find the tet
    :type node_id: int
    :param grain_id_1: Identifier for the first grain.
    :type grain_id_1: int
    :param grain_id_2: Identifier for the second grain.
    :type grain_id_2: int
    :param set_type: Type of elements, poly for 3d and face for 2d
    :type set_type: string
    :return: Returns a tuple of the grain identifier the element is
             in and the identifier of the element.
    :rtype: tuple (int, int)

    """
    three_d_element = []
    grains = []

    for grain_id in [grain_id_1, grain_id_2]:
        for element_id in mesh.element_sets[set_type + str(grain_id)].ids:
            element = mesh.elements[element_id]
            if node_id in element.vertices:
                three_d_element.append(element_id)
                grains.append(grain_id)

    return grains, three_d_element