Exemplo n.º 1
0
def run(fname):

    circuit = FileOpen(fname).open()

    options = PowerFlowOptions(
        solver_type=SolverType.NR,
        retry_with_other_methods=False,
        verbose=False,
        initialize_with_existing_solution=False,
        tolerance=1e-4,
        max_iter=5,
        max_outer_loop_iter=10,
        control_q=ReactivePowerControlMode.NoControl,
        control_taps=TapsControlMode.NoControl,
        multi_core=False,
        dispatch_storage=False,
        control_p=False,
        apply_temperature_correction=False,
        branch_impedance_tolerance_mode=BranchImpedanceMode.Specified,
        q_steepness_factor=30,
        distributed_slack=False,
        ignore_single_node_islands=False,
        correction_parameter=1e-4)

    driver = SampledTimeSeries(grid=circuit,
                               options=options,
                               number_of_steps=100)
    driver.run()

    # compose the train set
    nc = circuit.compile()
    Pbus = nc.get_power_injections().real.T

    model = KNeighborsRegressor(n_neighbors=2)
    model.fit(driver.results.S.real, np.abs(driver.results.voltage))
    V_pred = model.predict(Pbus)

    model = KNeighborsRegressor(n_neighbors=2)
    model.fit(driver.results.S.real, driver.results.Sbranch.real)
    Sbr_pred = model.predict(Pbus)

    return V_pred, Sbr_pred
Exemplo n.º 2
0
    end = time.time()
    elapsed = end - start

    return voltage, converged, normF, Scalc, iter_, elapsed, error_list


if __name__ == '__main__':

    # fname = r'/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE 9 Bus.gridcal'
    fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE39_1W.gridcal'
    from matplotlib import pyplot as plt
    from GridCal.Engine import FileOpen

    circuit = FileOpen(fname).open()
    nc = circuit.compile()
    islands = nc.compute()
    island = islands[0]

    voltage, converged, normF, Scalc, iter_, elapsed, err_lst = FDPF(
        Vbus=island.Vbus,
        Sbus=island.Sbus,
        Ibus=island.Ibus,
        Ybus=island.Ybus,
        B1=island.B1,
        B2=island.B2,
        pq=island.pq,
        pv=island.pv,
        pqpv=island.pqpv,
        tol=1e-9,
        max_it=100)
Exemplo n.º 3
0
def run(fname):

    circuit = FileOpen(fname).open()

    pf_options = PowerFlowOptions(
        solver_type=SolverType.NR,
        retry_with_other_methods=False,
        verbose=False,
        initialize_with_existing_solution=False,
        tolerance=1e-6,
        max_iter=5,
        max_outer_loop_iter=10,
        control_q=ReactivePowerControlMode.NoControl,
        control_taps=TapsControlMode.NoControl,
        multi_core=False,
        dispatch_storage=False,
        control_p=False,
        apply_temperature_correction=False,
        branch_impedance_tolerance_mode=BranchImpedanceMode.Specified,
        q_steepness_factor=30,
        distributed_slack=False,
        ignore_single_node_islands=False,
        correction_parameter=1e-4)

    nc = circuit.compile()

    ts_driver = TimeSeries(circuit, pf_options)
    ts_driver.run()

    ptdf_driver = PtdfTimeSeries(circuit, pf_options, power_delta=10)
    ptdf_driver.run()

    npoints = int(len(circuit.time_profile) * 1)
    lhs_driver = LatinHypercubeSampling(circuit,
                                        pf_options,
                                        sampling_points=npoints)
    lhs_driver.run()

    P = nc.get_power_injections().real.T
    Q = nc.get_power_injections().imag.T
    Pbr_ts = ts_driver.results.Sbranch.real

    Pbr_ptdf = ptdf_driver.results.Sbranch.real
    P_lhs = lhs_driver.results.S_points.real
    Q_lhs = lhs_driver.results.S_points.imag
    Pbr_lhs = lhs_driver.results.Sbr_points.real

    # KNN
    n_neighbors = 3
    model = neighbors.KNeighborsRegressor(n_neighbors)
    # model.fit(P[:40], Pbr_ts[:40])
    # model.fit(P_lhs, Pbr_lhs)  # just the LHS for training
    # X = np.r_[np.c_[P_lhs, Q], np.c_[P, Q]]
    # Y = np.r_[Pbr_lhs, Pbr_ts]

    X = np.c_[P, Q][:60]
    Y = Pbr_ts[:60]

    model.fit(X, Y)  # LHS + TS for training ("dreaming")
    Pbr_knn = model.predict(np.c_[P, Q])

    fig = plt.figure(figsize=(12, 8))
    ax = fig.add_subplot(111)
    i = 10  # branch index
    ax.plot(Pbr_ts[i, :], label='Real flow', linewidth=5, c='orange')
    ax.plot(Pbr_ptdf[i, :], label='PTDF', c='b', linestyle='--')
    ax.plot(Pbr_knn[i, :], label='KNN', c='k', linestyle=':')
    ax.set_xlabel('Time')
    ax.set_ylabel('MW')
    fig.legend()
    plt.show()
Exemplo n.º 4
0
    from matplotlib import pyplot as plt

    # grid.load_file('lynn5buspq.xlsx')
    # grid.load_file('lynn5buspv.xlsx')
    # grid.load_file('IEEE30.xlsx')
    # grid.load_file('/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE 14.xlsx')
    # grid.load_file('/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE39.xlsx')
    # grid.load_file('/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/1354 Pegase.xlsx')

    # fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE 14.xlsx'
    fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/IEEE39_1W.gridcal'
    # fname = '/home/santi/Documentos/GitHub/GridCal/Grids_and_profiles/grids/1354 Pegase.xlsx'

    grid = FileOpen(fname).open()

    numerical_circuit = grid.compile()

    circuits = numerical_circuit.compute()

    circuit = circuits[0]

    print('\nYbus:\n', circuit.Ybus.todense())
    print('\nSbus:\n', circuit.Sbus)
    print('\nIbus:\n', circuit.Ibus)
    print('\nVbus:\n', circuit.Vbus)
    print('\ntypes:\n', circuit.types)
    print('\npq:\n', circuit.pq)
    print('\npv:\n', circuit.pv)
    print('\nvd:\n', circuit.ref)

    start_time = time.time()
Exemplo n.º 5
0
    import pandas as pd
    import os
    import time

    pd.set_option('display.max_rows', 500)
    pd.set_option('display.max_columns', 500)
    pd.set_option('display.width', 1000)

    # fname = os.path.join('..', '..', '..', 'Grids_and_profiles', 'grids', 'IEEE 30 Bus with storage.xlsx')
    # fname = os.path.join('..', '..', '..', 'Grids_and_profiles', 'grids', 'Illinois200Bus.xlsx')
    # fname = os.path.join('..', '..', '..', 'Grids_and_profiles', 'grids', 'Pegase 2869.xlsx')
    # fname = os.path.join('..', '..', '..', 'Grids_and_profiles', 'grids', '1354 Pegase.xlsx')
    fname = '/home/santi/Documentos/Private_Grids/2026_INVIERNO_para Plexos_FINAL_9.raw'

    grid = FileOpen(file_name=fname).open()
    nc = grid.compile()
    islands = nc.compute()
    circuit = islands[0]

    # declare figure
    fig = plt.figure(figsize=(12, 7))
    ax = fig.add_subplot(1, 1, 1)

    circuit.Vbus = np.ones(len(circuit.Vbus), dtype=complex)

    print('Newton-Raphson-Line-search 1')
    for acc in [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 0.1]:
        start_time = time.time()

        error_data1 = list()
        V1, converged_, err, S, el = NR_LS(Ybus=circuit.Ybus,