Exemplo n.º 1
0
def calc_islands(circuit: CalculationInputs,
                 C_bus_bus,
                 C_branch_bus,
                 C_gen_bus,
                 C_batt_bus,
                 nbus,
                 nbr,
                 time_idx=None) -> List[CalculationInputs]:
    """
    Partition the circuit in islands for the designated time intervals
    :param circuit: CalculationInputs instance with all the data regardless of the islands and the branch states
    :param C_bus_bus: bus-bus connectivity matrix
    :param C_branch_bus: branch-bus connectivity matrix
    :param C_gen_bus: gen-bus connectivity matrix
    :param C_batt_bus: battery-bus connectivity matrix
    :param nbus: number of buses
    :param nbr: number of branches
    :param time_idx: array with the time indices where this set of islands belongs to
                    (if None all the time series are kept)
    :return: list of CalculationInputs instances
    """
    # find the islands of the circuit
    islands = Graph(csc_matrix(C_bus_bus)).find_islands()

    # clear the list of circuits
    calculation_islands = list()

    # find the branches that belong to each island
    island_branches = list()

    if len(islands) > 1:

        # there are islands, pack the islands into sub circuits
        for island_bus_idx in islands:
            # get the branch indices of the island
            island_br_idx = get_branches_of_the_island(island_bus_idx,
                                                       C_branch_bus)
            island_br_idx = np.sort(island_br_idx)  # sort
            island_branches.append(island_br_idx)

            # indices of batteries and controlled generators that belong to this island
            gen_idx = np.where(C_gen_bus[:, island_bus_idx].sum(axis=0) > 0)[0]
            bat_idx = np.where(
                C_batt_bus[:, island_bus_idx].sum(axis=0) > 0)[0]

            # Get the island circuit (the bus types are computed automatically)
            # The island original indices are generated within the get_island function
            circuit_island = circuit.get_island(island_bus_idx, island_br_idx,
                                                gen_idx, bat_idx)

            if time_idx is not None:
                circuit_island.trim_profiles(time_idx=time_idx)

            # store the island
            calculation_islands.append(circuit_island)

    else:
        # Only one island

        # compile bus types
        circuit.consolidate()

        # only one island, no need to split anything
        calculation_islands.append(circuit)

        island_bus_idx = np.arange(start=0, stop=nbus, step=1, dtype=int)
        island_br_idx = np.arange(start=0, stop=nbr, step=1, dtype=int)

        # set the indices in the island too
        circuit.original_bus_idx = island_bus_idx
        circuit.original_branch_idx = island_br_idx

        if time_idx is not None:
            circuit.trim_profiles(time_idx=time_idx)

        # append a list with all the branch indices for completeness
        island_branches.append(island_br_idx)

    # return the list of islands
    return calculation_islands
Exemplo n.º 2
0
def calc_islands(
        circuit: "StaticSnapshotIslandInputs",
        bus_active,
        C_bus_bus,
        C_branch_bus,
        C_bus_gen,
        C_bus_batt,
        nbus,
        nbr,
        time_idx=None,
        ignore_single_node_islands=False
) -> List["StaticSnapshotIslandInputs"]:
    """
    Partition the circuit in islands for the designated time intervals
    :param circuit: CalculationInputs instance with all the data regardless of the islands and the branch states
    :param C_bus_bus: bus-bus connectivity matrix
    :param C_branch_bus: branch-bus connectivity matrix
    :param C_bus_gen: gen-bus connectivity matrix
    :param C_bus_batt: battery-bus connectivity matrix
    :param nbus: number of buses
    :param nbr: number of branches
    :param time_idx: array with the time indices where this set of islands belongs to
                    (if None all the time series are kept)
    :param ignore_single_node_islands: Ignore the single node islands
    :return: list of CalculationInputs instances
    """
    # find the islands of the circuit
    g = Graph(C_bus_bus=sp.csc_matrix(C_bus_bus),
              C_branch_bus=sp.csc_matrix(C_branch_bus),
              bus_states=bus_active)
    islands = g.find_islands()

    # clear the list of circuits
    calculation_islands = list()

    # find the branches that belong to each island
    island_branches = list()

    if len(islands) > 1:

        # there are islands, pack the islands into sub circuits
        for island_bus_idx in islands:

            if ignore_single_node_islands and len(island_bus_idx) <= 1:
                keep = False
            else:
                keep = True

            if keep:
                # get the branch indices of the island
                island_br_idx = g.get_branches_of_the_island(island_bus_idx)
                island_br_idx = np.sort(island_br_idx)  # sort
                island_branches.append(island_br_idx)

                # indices of batteries and controlled generators that belong to this island
                gen_idx = np.where(
                    C_bus_gen[island_bus_idx, :].sum(axis=0) > 0)[0]
                bat_idx = np.where(
                    C_bus_batt[island_bus_idx, :].sum(axis=0) > 0)[0]

                # Get the island circuit (the bus types are computed automatically)
                # The island original indices are generated within the get_island function
                circuit_island = circuit.get_island(island_bus_idx,
                                                    island_br_idx, gen_idx,
                                                    bat_idx)

                # store the island
                calculation_islands.append(circuit_island)

    else:
        # Only one island

        # compile bus types
        circuit.consolidate()

        # only one island, no need to split anything
        calculation_islands.append(circuit)

        island_bus_idx = np.arange(start=0, stop=nbus, step=1, dtype=int)
        island_br_idx = np.arange(start=0, stop=nbr, step=1, dtype=int)

        # set the indices in the island too
        circuit.original_bus_idx = island_bus_idx
        circuit.original_branch_idx = island_br_idx

        # append a list with all the branch indices for completeness
        island_branches.append(island_br_idx)

    # return the list of islands
    return calculation_islands