Exemplo n.º 1
0
    def opf(self):
        """
        Run a power flow for every circuit
        @return: OptimalPowerFlowResults object
        """

        numerical_circuit = compile_snapshot_opf_circuit(circuit=self.grid,
                                                         apply_temperature=self.pf_options.apply_temperature_correction,
                                                         branch_tolerance_mode=self.pf_options.branch_impedance_tolerance_mode)

        if self.options.solver == SolverType.DC_OPF:
            # DC optimal power flow
            problem = OpfDc(numerical_circuit=numerical_circuit, solver=self.options.mip_solver)

        elif self.options.solver == SolverType.AC_OPF:
            # AC optimal power flow
            problem = OpfAc(numerical_circuit=numerical_circuit, solver=self.options.mip_solver)

        elif self.options.solver == SolverType.Simple_OPF:
            # simplistic dispatch
            problem = OpfSimple(numerical_circuit=numerical_circuit)

        else:
            raise Exception('Solver not recognized ' + str(self.options.solver))

        # Solve
        problem.solve()

        # get the branch flows (it is used more than one time)
        Sbr = problem.get_branch_power()
        ld = problem.get_load_shedding()
        ld[ld == None] = 0
        bt = problem.get_battery_power()
        bt[bt == None] = 0
        gn = problem.get_generator_power()
        gn[gn == None] = 0

        # pack the results
        self.results = OptimalPowerFlowResults(bus_names=numerical_circuit.bus_data.bus_names,
                                               branch_names=numerical_circuit.branch_data.branch_names,
                                               load_names=numerical_circuit.load_data.load_names,
                                               generator_names=numerical_circuit.generator_data.generator_names,
                                               battery_names=numerical_circuit.battery_data.battery_names,
                                               Sbus=None,
                                               voltage=problem.get_voltage(),
                                               load_shedding=ld,
                                               generation_shedding=np.zeros_like(gn),
                                               battery_power=bt,
                                               controlled_generation_power=gn,
                                               Sf=Sbr,
                                               overloads=problem.get_overloads(),
                                               loading=problem.get_loading(),
                                               converged=bool(problem.converged()),
                                               bus_types=numerical_circuit.bus_types)

        return self.results
Exemplo n.º 2
0
    def opf(self):
        """
        Run a power flow for every circuit
        @return: OptimalPowerFlowResults object
        """

        numerical_circuit = compile_snapshot_opf_circuit(
            circuit=self.grid,
            apply_temperature=self.pf_options.apply_temperature_correction,
            branch_tolerance_mode=self.pf_options.
            branch_impedance_tolerance_mode)

        # islands = numerical_circuit.split_into_islands(ignore_single_node_islands=True)
        # for island in islands:

        island = numerical_circuit

        problem = OpfNTC(island,
                         area_from_bus_idx=self.options.area_from_bus_idx,
                         area_to_bus_idx=self.options.area_to_bus_idx,
                         solver_type=self.options.mip_solver)
        # Solve
        problem.solve()

        # pack the results
        self.results = OptimalNetTransferCapacityResults(
            bus_names=island.bus_data.bus_names,
            branch_names=island.branch_data.branch_names,
            load_names=island.load_data.load_names,
            generator_names=island.generator_data.generator_names,
            battery_names=island.battery_data.battery_names,
            hvdc_names=island.hvdc_data.names,
            Sbus=problem.get_power_injections(),
            voltage=problem.get_voltage(),
            load_shedding=np.zeros((island.nload, 1)),
            generator_shedding=np.zeros((island.ngen, 1)),
            battery_power=np.zeros((island.nbatt, 1)),
            controlled_generation_power=problem.get_generator_power(),
            Sf=problem.get_branch_power(),
            overloads=problem.get_overloads(),
            loading=problem.get_loading(),
            converged=bool(problem.converged()),
            bus_types=island.bus_types,
            hvdc_flow=problem.get_hvdc_flow(),
            hvdc_loading=problem.get_hvdc_loading(),
            hvdc_slacks=problem.get_hvdc_slacks(),
            node_slacks=problem.get_node_slacks(),
            phase_shift=problem.get_phase_angles(),
            generation_delta=problem.get_generator_delta(),
            inter_area_branches=problem.inter_area_branches,
            inter_area_hvdc=problem.inter_area_hvdc)

        return self.results
Exemplo n.º 3
0
if __name__ == '__main__':
    from GridCal.Engine.basic_structures import BranchImpedanceMode
    from GridCal.Engine.IO.file_handler import FileOpen
    from GridCal.Engine.Core.snapshot_opf_data import compile_snapshot_opf_circuit

    # fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/Lynn 5 Bus pv.gridcal'
    # fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE39_1W.gridcal'
    fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/grid_2_islands.xlsx'
    # fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/Lynn 5 Bus pv (2 islands).gridcal'

    main_circuit = FileOpen(fname).open()

    main_circuit.buses[3].controlled_generators[0].enabled_dispatch = False

    numerical_circuit_ = compile_snapshot_opf_circuit(circuit=main_circuit,
                                                      apply_temperature=False,
                                                      branch_tolerance_mode=BranchImpedanceMode.Specified)

    problem = OpfSimple(numerical_circuit=numerical_circuit_)

    print('Solving...')
    status = problem.solve()

    print("Status:", status)

    v = problem.get_voltage()
    print('Angles\n', np.angle(v))

    l = problem.get_loading()
    print('Branch loading\n', l)