def _parse_locations_as_set(locations):
    """Parse grid element locations as a set.

    Parameters
    ----------
    locations : str or iterable of str
        Grid locations.

    Returns
    -------
    set
        Grid locations as strings.

    Raises
    ------
    ValueError
        If any of the locations are invalid.
    """
    EVERYWHERE = {"node", "link", "patch", "corner", "face", "cell"}

    if isinstance(locations, str):
        as_set = set(locations.split(","))
    else:
        as_set = set(locations)

    as_set = {item.strip() for item in as_set}

    unknown = sorted(as_set - EVERYWHERE)
    if unknown:
        unknown = [repr(item) for item in unknown]
        raise ValueError(
            f"unknown location{'s' if len(unknown) > 1 else ''} ({', '.join(unknown)})"
        )

    return as_set