GridCal.Engine.Simulations.OPF package

Submodules

GridCal.Engine.Simulations.OPF.ac_opf module

class GridCal.Engine.Simulations.OPF.ac_opf.AcOpf(multi_circuit: GridCal.Engine.Core.multi_circuit.MultiCircuit, verbose=False, allow_load_shedding=False, allow_generation_shedding=False, load_shedding_weight=10000, generation_shedding_weight=10000)

Bases: object

build_solvers()

Builds the solvers for each island :return:

get_batteries_power()

Get array of battery dispatched power

get_branch_flows()

Return the DC branch flows :return: numpy array

get_branch_flows_df()

Get hte DC branch flows DataFrame

get_controlled_generation()

Get array of controlled generators power

get_gen_results_df()

Get the generation values DataFrame

get_generation_shedding()

Load shedding array

get_load_shedding()

Load shedding array

get_loading()
get_overloads()

get the overloads into an array

get_voltage()

Get the complex voltage composition from the LP angles solution

get_voltage_results_df()

Get the voltage angles DataFrame

save()

Save all the problem instances

set_default_state()

Set the default loading state

set_state(load_power, static_gen_power, gen_power, Emin=None, Emax=None, E=None, dt=0, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01)

Set the current state :param load_power: vector of load power (same size as the number of loads) :param static_gen_power: vector of static generators load (same size as the static gen objects) :param gen_power: vector of controlled generators power (same size as the ctrl. generatos) :param force_batteries_to_charge: shall we force batteries to charge? :param bat_idx: battery indices that shall be forced to charge :param battery_loading_pu: amount of the changing band to force to charge

set_state_at(t, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01, Emin=None, Emax=None, E=None, dt=0)

Set the problem state at at time index :param t: time index

solve(verbose=False)

Solve all islands (the results remain in the variables…)

class GridCal.Engine.Simulations.OPF.ac_opf.AcOpfIsland(nbus, nbr, b_idx)

Bases: object

copy()
class GridCal.Engine.Simulations.OPF.ac_opf.AcOpf_old(calculation_input: GridCal.Engine.Core.calculation_inputs.CalculationInputs, buses=[], branches=[], options=None, voltage_band=0.1)

Bases: object

build(t_idx=None)

Formulate and Solve the AC LP problem :return: Nothing

copy()
get_results(save_lp_file=False, t_idx=None, realistic=False)

Return the optimization results :param save_lp_file: :param t_idx: :param realistic: compute the realistic values associated with the voltage solution :return: OptimalPowerFlowResults instance

print()
set_loads(t_idx=None)

Add the loads to the LP problem Args:

t_idx: time index, if none, the default object values are taken
solve()

Solve the LP OPF problem

GridCal.Engine.Simulations.OPF.dc_opf module

GridCal.Engine.Simulations.OPF.dc_opf.Cproduct(C, vect)

Connectivity matrix-vector product :param C: Connectivity matrix :param vect: vector of object type :return:

class GridCal.Engine.Simulations.OPF.dc_opf.DcOpf(multi_circuit: GridCal.Engine.Core.multi_circuit.MultiCircuit, verbose=False, allow_load_shedding=False, allow_generation_shedding=False, load_shedding_weight=10000, generation_shedding_weight=10000)

Bases: object

build_solvers()

Builds the solvers for each island :return:

get_batteries_power()

Get array of battery dispatched power

get_branch_flows()

Return the DC branch flows :return: numpy array

get_branch_flows_df()

Get hte DC branch flows DataFrame

get_controlled_generation()

Get array of controlled generators power

get_gen_results_df()

Get the generation values DataFrame

get_generation_shedding()

Load shedding array

get_load_shedding()

Load shedding array

get_loading()
get_overloads()

get the overloads into an array

get_voltage()

Get the complex voltage composition from the LP angles solution

get_voltage_results_df()

Get the voltage angles DataFrame

save()

Save all the problem instances

set_default_state()

Set the default loading state

set_state(load_power, static_gen_power, generator_power, Emin=None, Emax=None, E=None, dt=0, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01)

Set the loading and batteries state :param load_power: vector of load power (same size as the number of loads) :param static_gen_power: vector of static generators load (same size as the static gen objects) :param generator_power: vector of controlled generators power (same size as the ctrl. generators) :param Emin: Minimum energy per battery in MWh / Sbase -> 1/h :param Emax: Maximum energy per battery in MWh / Sbase -> 1/h :param E: Current energy charge in MWh / Sbase -> 1/h :param dt: time step in hours :param force_batteries_to_charge: shall we force batteries to charge? :param bat_idx: battery indices that shall be forced to charge :param battery_loading_pu: amount of the nominal band to charge to use (0.1=10%)

set_state_at(t, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01, Emin=None, Emax=None, E=None, dt=0)

Set the problem state at at time index :param t: time index

solve(verbose=False)

Solve all islands (the results remain in the variables…)

class GridCal.Engine.Simulations.OPF.dc_opf.DcOpfIsland(nbus, nbr, b_idx)

Bases: object

copy()

GridCal.Engine.Simulations.OPF.nelder_mead_opf module

class GridCal.Engine.Simulations.OPF.nelder_mead_opf.AcOpfNelderMead(multi_circuit: GridCal.Engine.Core.multi_circuit.MultiCircuit, options: GridCal.Engine.Simulations.PowerFlow.power_flow_driver.PowerFlowOptions, verbose=False, break_at_value=True, good_enough_value=0)

Bases: object

build_solvers()
f_obj(x)
get_batteries_power()
get_branch_flows()
get_controlled_generation()
get_generation_shedding()
get_load_shedding()
get_loading()
get_overloads()
get_voltage()
set_default_state()

Set the default loading state

set_state(load_power, static_gen_power, controlled_gen_power, storage_power, Emin=None, Emax=None, E=None, dt=0, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01)
set_state_at(t, force_batteries_to_charge=False, bat_idx=None, battery_loading_pu=0.01, Emin=None, Emax=None, E=None, dt=0)

Set the problem state at at time index Args:

t: force_batteries_to_charge: bat_idx: battery_loading_pu: Emin: Emax: E: dt:

Returns:

solve(verbose=False)
GridCal.Engine.Simulations.OPF.nelder_mead_opf.nelder_mead(objective_function, x_start, step=0.1, no_improve_thr=1e-05, no_improv_break=10, max_iter=0, alpha=1.0, gamma=2.0, rho=-0.5, sigma=0.5, break_at_value=False, good_enough_value=0.0, init_res=[], callback=None)
Args:
objective_function: function to optimize, must return a scalar score
and operate over a numpy array of the same dimensions as x_start

x_start: initial position LB: lower bounds (can be None) UB: upper bound (can be None) step: look-around radius in initial step no_improve_thr, no_improv_break: break after no_improv_break iterations with an improvement lower than no_improv_thr max_iter: always break after this number of iterations. Set it to 0 to loop indefinitely. alpha: gamma: rho: sigma:

Returns: xsol, fsol

GridCal.Engine.Simulations.OPF.nelder_mead_opf.nelder_mead_test()

GridCal.Engine.Simulations.OPF.opf_driver module

class GridCal.Engine.Simulations.OPF.opf_driver.OptimalPowerFlow(grid: GridCal.Engine.Core.multi_circuit.MultiCircuit, options: GridCal.Engine.Simulations.OPF.opf_driver.OptimalPowerFlowOptions)

Bases: PySide2.QtCore.QRunnable

cancel()
get_steps()

Get time steps list of strings

opf(t_idx=None, collect=True)

Run a power flow for every circuit @return: OptimalPowerFlowResults object

run()
Returns:
run_at(t)

Run power flow at the time series object index t @param t: time index @return: OptimalPowerFlowResults object

class GridCal.Engine.Simulations.OPF.opf_driver.OptimalPowerFlowOptions(verbose=False, load_shedding=False, generation_shedding=False, solver=<SolverType.DC_OPF: (14, )>, realistic_results=False, control_batteries=True, faster_less_accurate=False, generation_shedding_weight=10000, load_shedding_weight=10000, power_flow_options=None, bus_types=None, non_sequential=False)

Bases: object

GridCal.Engine.Simulations.OPF.opf_results module

class GridCal.Engine.Simulations.OPF.opf_results.OptimalPowerFlowResults(Sbus=None, voltage=None, load_shedding=None, generation_shedding=None, battery_power=None, controlled_generation_power=None, Sbranch=None, overloads=None, loading=None, losses=None, converged=None, bus_types=None)

Bases: object

OPF results.

Arguments:

Sbus: bus power injections

voltage: bus voltages

load_shedding: load shedding values

Sbranch: branch power values

overloads: branch overloading values

loading: branch loading values

losses: branch losses

converged: converged?

copy()

Return a copy of this @return:

initialize(n, m)

Initialize the arrays @param n: number of buses @param m: number of branches @return:

plot(result_type, ax=None, indices=None, names=None)

Plot the results :param result_type: type of results (string) :param ax: matplotlib axis object :param indices: element indices :param names: element names :return: DataFrame of the results (or None if the result was not understood)

GridCal.Engine.Simulations.OPF.opf_time_series_driver module

class GridCal.Engine.Simulations.OPF.opf_time_series_driver.NonSequentialOptimalPowerFlow(grid: GridCal.Engine.Core.multi_circuit.MultiCircuit, options: GridCal.Engine.Simulations.OPF.opf_driver.OptimalPowerFlowOptions, start_=0, end_=None)

Bases: PySide2.QtCore.QThread

cancel()
done_signal = <PySide2.QtCore.Signal object>
get_steps()

Get time steps list of strings

opf()

Run a power flow for every circuit @return: OptimalPowerFlowResults object

progress_signal = <PySide2.QtCore.Signal object>
progress_text = <PySide2.QtCore.Signal object>
run()
Returns:
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class GridCal.Engine.Simulations.OPF.opf_time_series_driver.OptimalPowerFlowTimeSeriesResults(n, m, nt, ngen=0, nbat=0, nload=0, time=None, is_dc=False)

Bases: object

init_object_results(ngen, nbat)

declare the generator results. This is done separately since these results are known at the end of the simulation :param ngen: number of generators :param nbat: number of batteries

plot(result_type, ax=None, indices=None, names=None)

Plot the results :param result_type: :param ax: :param indices: :param names: :return:

set_at(t, res: GridCal.Engine.Simulations.OPF.opf_results.OptimalPowerFlowResults)

Set the results :param t: time index :param res: OptimalPowerFlowResults instance

class GridCal.Engine.Simulations.OPF.opf_time_series_driver.SequentialOptimalPowerFlowTimeSeries(grid: GridCal.Engine.Core.multi_circuit.MultiCircuit, options: GridCal.Engine.Simulations.OPF.opf_driver.OptimalPowerFlowOptions, start_=0, end_=None)

Bases: PySide2.QtCore.QThread

cancel()

Set the cancel state

done_signal = <PySide2.QtCore.Signal object>
get_steps()

Get time steps list of strings

initialize_lp_vars()

initialize all the bus LP profiles :return:

progress_signal = <PySide2.QtCore.Signal object>
progress_text = <PySide2.QtCore.Signal object>
run()

Run the time series simulation @return:

staticMetaObject = <PySide2.QtCore.QMetaObject object>