VeraGridEngine.Simulations.OPF.Formulations package

Submodules

VeraGridEngine.Simulations.OPF.Formulations.ac_opf_problem module

class VeraGridEngine.Simulations.OPF.Formulations.ac_opf_problem.NonLinearOptimalPfProblem(nc: NumericalCircuit, options: OptimalPowerFlowOptions, logger: Logger, pf_init: bool = True, Sbus_pf: ndarray[tuple[Any, ...], dtype[complex128]] | None = None, voltage_pf: ndarray[tuple[Any, ...], dtype[complex128]] | None = None, optimize_nodal_capacity: bool = False, nodal_capacity_sign: float = 1.0, capacity_nodes_idx: ndarray[tuple[Any, ...], dtype[int64]] | None = None)[source]

Bases: object

Cdispgen
Cdispgen_sh
Cdispgen_sh_t
Cdispgen_t
Cfmon
Cfmon_t
Ctmon
Ctmon_t
F_vsc
Inom
It_vsc
NV
P_hvdc_max
Pf_nondisp
Pf_vsc
Pfdc
Pg
Pg_max
Pg_min
Pt_vsc
Qg
Qg_max
Qg_min
Qsh_max
Qsh_min
Qt_vsc
R
Sbase
Scalc
Sd
Sf
Sf2
Sg_undis
St
St2
T_vsc
V
Va
Va_max
Va_min
Vm
Vm_max
Vm_min
X
Ybus_cols
Ybus_diag_pos
Ybus_indices
Ybus_indptr
ac_bus_idx
admittances
allSf
allSt
all_tap_m
all_tap_tau
analyze_branch_controls() None[source]

Analyze the control branches and compute the indices :return: None

br_idx
br_mon_idx
c0
c0n
c1
c1n
c2
c2n
c_s
c_v
c_vsc
capacity_nodes_idx
compute_branch_power_derivatives() Tuple[csr_matrix, lil_matrix, lil_matrix, csr_matrix, lil_matrix, lil_matrix][source]

TODO: Move outside of the class :return: First power derivatives with respect to the tap variables

[dSbusdm, dSfdm, dStdm, dSbusdt, dSfdtau, dStdtau]

compute_branch_power_second_derivatives(lam: ndarray[tuple[Any, ...], dtype[float64]], mu: ndarray[tuple[Any, ...], dtype[float64]]) Tuple[lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix, lil_matrix][source]

TODO: Move outside of the class :param lam: Lambda multiplier :param mu: Mu multiplier :return: Power second derivatives with respect to tap variables

dc_bus_idx
f_disp_hvdc
f_nd_hvdc
from_idx
gen_bus_idx
gen_disp_idx
gen_disp_idx_sh
gen_nondisp_idx
get_jacobians_and_hessians(mu: ndarray[tuple[Any, ...], dtype[float64]], lam: ndarray[tuple[Any, ...], dtype[float64]], compute_hessians: bool) Tuple[ndarray[tuple[Any, ...], dtype[float64]], csc_matrix, csc_matrix, csc_matrix, csc_matrix, csc_matrix][source]
TODO: we should split this function into functions outside the class, that should make it more manageable

one for each of these: fx, Gx, Hx, fxx, Gxx, Hxx, and leave this function just to call them

Parameters:
  • mu

  • lam

  • compute_hessians

Returns:

fx, Gx, Hx, fxx, Gxx, Hxx

get_solution(ips_results: IpsSolution, verbose: int = 0, plot_error: bool = False)[source]
Parameters:
  • ips_results

  • verbose

  • plot_error

Returns:

hvdc_disp_idx
hvdc_nondisp_idx
id_Vm_max0
id_Vm_min0
id_sh
ind_gens
indices
k_m
k_mtau
k_tau
logger
n_br_mon
n_dc_bus
n_disp_hvdc
n_gen_disp
n_gen_disp_sh
n_sl_vsc
n_slack
n_vsc_lim
n_vsc_vars
nbr
nbus
nc
neq
ngen
nineq
nodal_capacity_sign
npq
npv
nsh
nsl
nslcap
ntapm
ntapt
nvsc
optimize_nodal_capacity
options
pf
pq
pv
rates
rates2
results
sh_bus_idx
sl_sf
sl_st
sl_vmax
sl_vmin
sl_vsc
slack
slackgens
slcap
slcap0
t_disp_hvdc
t_nd_hvdc
tanmax
tap_m
tap_tau
tapm_max
tapm_min
tapt_max
tapt_min
to_idx
update(x: ndarray[tuple[Any, ...], dtype[float64]]) Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]][source]
var2x() ndarray[tuple[Any, ...], dtype[float64]][source]
vsc_alpha1
vsc_alpha2
vsc_alpha3
vsc_idx
vsc_lim_idx
vsc_rate_pu
x0
x2var(x: ndarray[tuple[Any, ...], dtype[float64]])[source]
class VeraGridEngine.Simulations.OPF.Formulations.ac_opf_problem.NonlinearOPFResults(Va: ndarray[tuple[Any, ...], dtype[float64]] = None, Vm: ndarray[tuple[Any, ...], dtype[float64]] = None, S: ndarray[tuple[Any, ...], dtype[complex128]] = None, Sf: ndarray[tuple[Any, ...], dtype[complex128]] = None, St: ndarray[tuple[Any, ...], dtype[complex128]] = None, loading: ndarray[tuple[Any, ...], dtype[float64]] = None, Pg: ndarray[tuple[Any, ...], dtype[float64]] = None, Qg: ndarray[tuple[Any, ...], dtype[float64]] = None, Qsh: ndarray[tuple[Any, ...], dtype[float64]] = None, Pcost: ndarray[tuple[Any, ...], dtype[float64]] = None, tap_module: ndarray[tuple[Any, ...], dtype[float64]] = None, tap_phase: ndarray[tuple[Any, ...], dtype[float64]] = None, hvdc_Pf: ndarray[tuple[Any, ...], dtype[float64]] = None, hvdc_loading: ndarray[tuple[Any, ...], dtype[float64]] = None, vsc_Pt: ndarray[tuple[Any, ...], dtype[float64]] = None, vsc_Qt: ndarray[tuple[Any, ...], dtype[float64]] = None, vsc_Pf: ndarray[tuple[Any, ...], dtype[float64]] = None, vsc_It: ndarray[tuple[Any, ...], dtype[float64]] = None, vsc_loading: ndarray[tuple[Any, ...], dtype[float64]] = None, lam_p: ndarray[tuple[Any, ...], dtype[float64]] = None, lam_q: ndarray[tuple[Any, ...], dtype[float64]] = None, sl_sf: ndarray[tuple[Any, ...], dtype[float64]] = None, sl_st: ndarray[tuple[Any, ...], dtype[float64]] = None, sl_vmax: ndarray[tuple[Any, ...], dtype[float64]] = None, sl_vmin: ndarray[tuple[Any, ...], dtype[float64]] = None, nodal_capacity: ndarray[tuple[Any, ...], dtype[float64]] = None, error: float = None, converged: bool = None, iterations: int = None, voltage: ndarray[tuple[Any, ...], dtype[complex128]] = None)[source]

Bases: object

Numerical non linear OPF results

Pcost: ndarray[tuple[Any, ...], dtype[float64]]
Pg: ndarray[tuple[Any, ...], dtype[float64]]
Qg: ndarray[tuple[Any, ...], dtype[float64]]
Qsh: ndarray[tuple[Any, ...], dtype[float64]]
S: ndarray[tuple[Any, ...], dtype[complex128]]
Sf: ndarray[tuple[Any, ...], dtype[complex128]]
St: ndarray[tuple[Any, ...], dtype[complex128]]
property V: ndarray[tuple[Any, ...], dtype[complex128]]

Complex voltage :return: CxVec

Va: ndarray[tuple[Any, ...], dtype[float64]]
Vm: ndarray[tuple[Any, ...], dtype[float64]]
converged: bool
error: float
hvdc_Pf: ndarray[tuple[Any, ...], dtype[float64]]
hvdc_loading: ndarray[tuple[Any, ...], dtype[float64]]
initialize(nbus: int, nbr: int, nil: int, nsh: int, ng: int, nhvdc: int, ncap: int, nvsc: int = 0)[source]

Initialize the arrays :param nbus: number of buses :param nbr: number of branches :param nsh: number of controllable shunt elements :param ng: number of generators :param nhvdc: number of HVDCs :param ncap: number of nodal capacity nodes :param nvsc: number of VSCs

iterations: int
lam_p: ndarray[tuple[Any, ...], dtype[float64]]
lam_q: ndarray[tuple[Any, ...], dtype[float64]]
loading: ndarray[tuple[Any, ...], dtype[float64]]
merge(other: NonlinearOPFResults, bus_idx: ndarray[tuple[Any, ...], dtype[int64]], br_idx: ndarray[tuple[Any, ...], dtype[int64]], il_idx: ndarray[tuple[Any, ...], dtype[int64]], gen_idx: ndarray[tuple[Any, ...], dtype[int64]], hvdc_idx: ndarray[tuple[Any, ...], dtype[int64]], ncap_idx: ndarray[tuple[Any, ...], dtype[int64]], contshunt_idx: ndarray[tuple[Any, ...], dtype[int64]], acopf_mode, vsc_idx: ndarray[tuple[Any, ...], dtype[int64]] = None)[source]
Parameters:
  • other

  • bus_idx

  • br_idx

  • il_idx

  • gen_idx

  • hvdc_idx

  • ncap_idx

  • contshunt_idx

  • acopf_mode

Returns:

nodal_capacity: ndarray[tuple[Any, ...], dtype[float64]]
sl_sf: ndarray[tuple[Any, ...], dtype[float64]]
sl_st: ndarray[tuple[Any, ...], dtype[float64]]
sl_vmax: ndarray[tuple[Any, ...], dtype[float64]]
sl_vmin: ndarray[tuple[Any, ...], dtype[float64]]
tap_module: ndarray[tuple[Any, ...], dtype[float64]]
tap_phase: ndarray[tuple[Any, ...], dtype[float64]]
voltage: ndarray[tuple[Any, ...], dtype[complex128]]
vsc_It: ndarray[tuple[Any, ...], dtype[float64]]
vsc_Pf: ndarray[tuple[Any, ...], dtype[float64]]
vsc_Pt: ndarray[tuple[Any, ...], dtype[float64]]
vsc_Qt: ndarray[tuple[Any, ...], dtype[float64]]
vsc_loading: ndarray[tuple[Any, ...], dtype[float64]]

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts module

This file implements a DC-OPF for time series That means that solves the OPF problem for a complete time series at once

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.BatteryVars(nt: int, n_elm: int)[source]

Bases: GenerationVars

struct extending the generation vars to handle the battery vars

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix = None, gen_fuel_rates_matrix: csc_matrix = None) BatteryVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: GenerationVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.BranchVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the branch related vars

add_contingency_flow(t: int, m: int, c: int, flow_var: float | LpVariable | None | LpAffineExpression, neg_slack: LpVariable | None, pos_slack: LpVariable | None)[source]

Add contingency flow :param t: time index :param m: monitored index :param c: contingency group index :param flow_var: flow var :param neg_slack: negative flow slack variable :param pos_slack: positive flow slack variable

get_values(Sbase: float, model: PulpLpModel | None) BranchVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: BranchVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.BusVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the bus related vars

get_values(Sbase: float, model: PulpLpModel | None) BusVars[source]

Return an instance of this class where the array’s content is not LP vars but their value :return: BusVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.FluidInjectionVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of injections of fluid type

get_values(model: PulpLpModel | None) FluidInjectionVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidInjectionVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.FluidNodeVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of nodes of fluid type

get_values(model: PulpLpModel | None) FluidNodeVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidNodeVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.FluidPathVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of paths of fluid type

get_values(model: PulpLpModel | None) FluidPathVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidPathVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.GenerationVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix) GenerationVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param Sbase: Base power (100 MVA) :param model: LpModel :param gen_emissions_rates_matrix: emissins rates matrix (n_emissions, n_gen) :param gen_fuel_rates_matrix: fuel rates matrix (n_fuels, n_gen) :return: GenerationVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.HvdcVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None) HvdcVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: HvdcVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.LoadVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the load related vars

get_values(Sbase: float, model: PulpLpModel | None) LoadVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: LoadVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.NodalCapacityVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the nodal capacity related vars

get_values(Sbase: float, model: PulpLpModel | None) NodalCapacityVars[source]

Return an instance of this class where the array’s content is not LP vars but their value :return: BusVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.OpfVars(nt: int, nbus: int, ng: int, nb: int, nl: int, nbr: int, n_hvdc: int, n_vsc: int, n_fluid_node: int, n_fluid_path: int, n_fluid_inj: int, n_cap_buses: int)[source]

Bases: object

Structure to host the opf variables

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix, gen_tech_shares_matrix: csc_matrix, batt_tech_shares_matrix: csc_matrix) OpfVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: OpfVars instance

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.SystemVars(nt: int)[source]

Bases: object

Struct to store the system vars

compute(gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix, gen_tech_shares_matrix: csc_matrix, batt_tech_shares_matrix: csc_matrix, gen_p: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], gen_cost: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], batt_p: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], shedding_cost: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]])[source]

Compute the system values :param gen_emissions_rates_matrix: emissions rates matrix (n_emissions, n_gen) :param gen_fuel_rates_matrix: fuel rates matrix (n_fuels, n_gen) :param gen_tech_shares_matrix: technology shares of the generators :param batt_tech_shares_matrix technology shares of the batteries :param gen_p: Generation power values (nt, ngen) :param gen_cost: Generation cost values (nt, ngen) :param batt_p: Battery power values (nt, nbatt) :param shedding_cost: Shedding cost values (nt, ngen)

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.VscVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None) HvdcVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: HvdcVars

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_copper_plate_balance(t_idx: int, bus_vars: BusVars, prob: PulpLpModel | None)[source]

Add the copperplate equality :param t_idx: time step :param bus_vars: BusVars :param prob: LpModel

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_hydro_formulation(t: int | None, time_global_tidx: int | None, time_array: DatetimeIndex, Sbase: float, node_vars: FluidNodeVars, path_vars: FluidPathVars, inj_vars: FluidInjectionVars, node_data: FluidNodeData, path_data: FluidPathData, turbine_data: FluidTurbineData, pump_data: FluidPumpData, p2x_data: FluidP2XData, generator_data: GeneratorData, generator_vars: GenerationVars, fluid_level_0: ndarray[tuple[Any, ...], dtype[float64]], prob: PulpLpModel | None, logger: Logger)[source]

Formulate the branches :param t: local time index :param time_global_tidx: global time index :param time_array: list of time indices :param Sbase: base power of the system :param node_vars: FluidNodeVars :param path_vars: FluidPathVars :param inj_vars: FluidInjectionVars :param node_data: FluidNodeData :param path_data: FluidPathData :param turbine_data: FluidTurbineData :param pump_data: FluidPumpData :param p2x_data: FluidP2XData :param generator_data: GeneratorData :param generator_vars: GeneratorVars :param fluid_level_0: Initial node level :param prob: OR problem :param logger: log of the LP :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_battery_formulation(t: int | None, Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, batt_data_t: BatteryData, batt_vars: BatteryVars, prob: PulpLpModel | None, unit_commitment: bool, ramp_constraints: bool, skip_generation_limits: bool, generation_expansion_planning: bool, energy_0: ndarray[tuple[Any, ...], dtype[float64]])[source]

Add MIP generation formulation :param t: time step, if None we assume single time step :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param batt_data_t: BatteryData structure :param batt_vars: BatteryVars structure :param prob: ORTools problem :param unit_commitment: formulate unit commitment? :param ramp_constraints: formulate ramp constraints? :param skip_generation_limits: skip the generation limits? :param generation_expansion_planning: generation expansion planning? :param energy_0: initial value of the energy stored :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_branches_contingencies_formulation(t_idx: int, Sbase: float, branch_data_t: PassiveBranchData, hvdc_vars: HvdcVars, vsc_vars: VscVars, branch_vars: BranchVars, bus_vars: BusVars, prob: PulpLpModel | None, linear_multi_contingencies: LinearMultiContingencies)[source]

Formulate the branches :param t_idx: time index :param Sbase: base power (100 MVA) :param branch_data_t: BranchData :param hvdc_vars: HvdcVars :param vsc_vars: VscVars :param branch_vars: BranchVars :param bus_vars: BusVars :param prob: OR problem :param linear_multi_contingencies: LinearMultiContingencies :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_branches_formulation(t: int, Sbase: float, bus_data_t: BusData, branch_data_t: PassiveBranchData, ctrl_branch_data_t: ActiveBranchData, branch_vars: BranchVars, bus_vars: BusVars, prob: PulpLpModel | None, inf=1e+20, add_losses_approximation: bool = False)[source]

Formulate the branches :param t: time index :param Sbase: base power (100 MVA) :param bus_data_t: BusData :param branch_data_t: BranchData :param ctrl_branch_data_t: ControllableBranchData :param branch_vars: BranchVars :param bus_vars: BusVars :param prob: OR problem :param inf: number considered infinite :param add_losses_approximation: If true the distribution factors losses approximation is used :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_generation_expansion_planning_formulation(local_t: int | None, Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, gen_data_t: GeneratorData, gen_vars: GenerationVars, prob: PulpLpModel | None, ramp_constraints: bool, skip_generation_limits: bool, use_glsk_as_cost: bool, logger: Logger) LpAffineExpression | None | float[source]

Add MIP generation formulation :param local_t: time step :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param gen_data_t: GeneratorData structure :param gen_vars: GenerationVars structure :param prob: LpModel :param ramp_constraints: formulate ramp constraints? :param skip_generation_limits: skip the generation limits? :param generation_expansion_planning: generation expansion plan? :param use_glsk_as_cost: if true, the GLSK values are used instead of the traditional costs :param logger: Logger object :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_generation_redispatch_formulation(local_t: int | None, Sbase: float, bus_vars: BusVars, gen_data_t: GeneratorData, gen_vars: GenerationVars, prob: PulpLpModel | None, inter_aggregation_info: InterAggregationInfo, skip_generation_limits: bool, use_glsk_as_cost: bool, logger: Logger) LpAffineExpression | None | float[source]

Add MIP generation redispatch formulation the main difference is that Pg = P + dP dP >= 0 for generators in A1 (sending), dP <= 0 for generators in A2 (receiving), :param local_t: time step :param Sbase: base power (100 MVA) :param bus_vars: BusVars :param gen_data_t: GeneratorData structure :param gen_vars: GenerationVars structure :param prob: LpModel :param inter_aggregation_info: :param skip_generation_limits: skip the generation limits? :param use_glsk_as_cost: if true, the GLSK values are used instead of the traditional costs :param logger: Logger object :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_generation_unit_commitment_formulation(local_t: int | None, Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, gen_data_t: GeneratorData, gen_vars: GenerationVars, prob: PulpLpModel | None, ramp_constraints: bool, consider_time_up_down: bool, area_spinning_reserve: bool, skip_generation_limits: bool, use_glsk_as_cost: bool, logger: Logger) LpAffineExpression | None | float[source]

Add MIP generation formulation :param local_t: time step :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param gen_data_t: GeneratorData structure :param gen_vars: GenerationVars structure :param prob: LpModel :param ramp_constraints: formulate ramp constraints? :param consider_time_up_down: consider time up/down? :param area_spinning_reserve: area spinning reserve? :param skip_generation_limits: skip the generation limits? :param use_glsk_as_cost: if true, the GLSK values are used instead of the traditional costs :param logger: Logger object :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_hvdc_formulation(t: int, Sbase: float, hvdc_data_t: HvdcData, hvdc_vars: HvdcVars, bus_vars: BusVars, prob: PulpLpModel | None, logger: Logger)[source]
Parameters:
  • t

  • Sbase

  • hvdc_data_t

  • hvdc_vars

  • bus_vars

  • prob

  • logger

Returns:

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_load_formulation(t: int | None, Sbase: float, bus_vars: BusVars, load_data_t: LoadData, load_vars: LoadVars, prob: PulpLpModel | None)[source]

Add MIP generation formulation :param t: time step, if None we assume single time step :param Sbase: base power (100 MVA) :param bus_vars: BusVars :param load_data_t: BatteryData structure :param load_vars: BatteryVars structure :param prob: ORTools problem :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_nodal_capacity_generation_formulation(local_t: int | None, Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, gen_data_t: GeneratorData, gen_vars: GenerationVars, prob: PulpLpModel | None, skip_generation_limits: bool, vd: ndarray[tuple[Any, ...], dtype[int64]], nodal_capacity_active: bool, use_glsk_as_cost: bool, logger: Logger) LpAffineExpression | None | float[source]

Add MIP generation formulation :param local_t: time step :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param gen_data_t: GeneratorData structure :param gen_vars: GenerationVars structure :param prob: LpModel :param skip_generation_limits: skip the generation limits? :param vd: slack indices :param nodal_capacity_active: nodal capacity active? :param use_glsk_as_cost: if true, the GLSK values are used instead of the traditional costs :param logger: Logger object :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_node_balance(t_idx: int, vd: ndarray[tuple[Any, ...], dtype[int64]], bus_data: BusData, bus_vars: BusVars, nodal_capacity_vars: NodalCapacityVars, capacity_nodes_idx: ndarray[tuple[Any, ...], dtype[int64]], prob: PulpLpModel | None, logger: Logger)[source]

Add the Kirchhoff nodal equality :param t_idx: time step :param vd: List of slack node indices :param bus_data: BusData :param bus_vars: BusVars :param nodal_capacity_vars: NodalCapacityVars :param capacity_nodes_idx: IntVec :param prob: LpModel :param logger: Logger

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_simple_generation_formulation(local_t: int | None, Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, gen_data_t: GeneratorData, gen_vars: GenerationVars, prob: PulpLpModel | None, ramp_constraints: bool, consider_time_up_down: bool, area_spinning_reserve: bool, skip_generation_limits: bool, use_glsk_as_cost: bool, logger: Logger) LpAffineExpression | None | float[source]

Add MIP generation formulation :param local_t: time step :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param gen_data_t: GeneratorData structure :param gen_vars: GenerationVars structure :param prob: LpModel :param ramp_constraints: formulate ramp constraints? :param consider_time_up_down: consider time up/down? :param area_spinning_reserve: area spinning reserve? :param skip_generation_limits: skip the generation limits? :param use_glsk_as_cost: if true, the GLSK values are used instead of the traditional costs :param logger: Logger object :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_linear_vsc_formulation(t: int, Sbase: float, vsc_data_t: VscData, vsc_vars: VscVars, bus_vars: BusVars, prob: PulpLpModel | None, logger: Logger)[source]
Parameters:
  • t

  • Sbase

  • vsc_data_t

  • vsc_vars

  • bus_vars

  • prob

  • logger

Returns:

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.add_nodal_capacity_formulation(t: int | None, nodal_capacity_vars: NodalCapacityVars, nodal_capacity_sign: float, capacity_nodes_idx: ndarray[tuple[Any, ...], dtype[int64]], prob: PulpLpModel | None)[source]

Add MIP generation formulation :param t: time step, if None we assume single time step :param nodal_capacity_vars: NodalCapacityVars structure :param nodal_capacity_sign: :param capacity_nodes_idx: IntVec :param prob: ORTools problem :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.get_contingency_flow_with_filter(multi_contingency: LinearMultiContingency, base_flow: ndarray[tuple[Any, ...], dtype[float64]], injections: None | ndarray[tuple[Any, ...], dtype[float64]], threshold: float, m: int) LpAffineExpression | None[source]

Get contingency flow :param multi_contingency: MultiContingency object :param base_flow: Base branch flows (nbranch) :param injections: Bus injections increments (nbus) :param threshold: threshold to filter contingency elements :param m: branch monitor index (int) :return: New flows (nbranch)

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.pmode3_formulation_impr(prob: PulpLpModel | None, elm_idx: int, t_idx: int, m: float, rate: float, P0: float, droop: float, theta_f: LpVariable | None, theta_t: LpVariable | None, base_name: str, logger: Logger)[source]

Formulation for HVDC link with three operating regions using big-M and binary variables. :param prob: :param elm_idx: :param t_idx: :param m: :param rate: :param P0: :param droop: :param theta_f: :param theta_t: :param base_name: :param logger: :return:

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts.run_linear_opf_ts(grid: ~VeraGridEngine.Devices.multi_circuit.MultiCircuit, time_indices: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.int64]] | None, dispatch_mode: ~VeraGridEngine.enumerations.OpfDispatchMode = Normal, solver_type: ~VeraGridEngine.enumerations.MIPSolvers = HIGHS, zonal_grouping: ~VeraGridEngine.enumerations.ZonalGrouping = No grouping, skip_generation_limits: bool = False, consider_contingencies: bool = False, contingency_groups_used: ~typing.List[~VeraGridEngine.Devices.Events.contingency_group.ContingencyGroup] | None = None, ramp_constraints: bool = False, consider_time_up_down: bool = False, area_spinning_reserve: bool = False, lodf_threshold: float = 0.001, inter_aggregation_info: ~VeraGridEngine.Devices.Aggregation.inter_aggregation_info.InterAggregationInfo | None = None, energy_0: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]] | None = None, fluid_level_0: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]] | None = None, nodal_capacity_sign: float = 1.0, capacity_nodes_idx: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.int64]] | None = None, use_glsk_as_cost: bool = False, add_losses_approximation: bool = False, logger: ~VeraGridEngine.basic_structures.Logger = <VeraGridEngine.basic_structures.Logger object>, progress_text: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, verbose: int = 0, robust: bool = False, mip_framework: ~VeraGridEngine.enumerations.MIPFramework = PuLP) Tuple[OpfVars, PulpLpModel | None][source]

Formulate linear optimal power flow :param grid: MultiCircuit instance :param time_indices: Time indices (in the general scheme) :param dispatch_mode: OpfDispatchMode :param solver_type: MIP solver to use :param zonal_grouping: Zonal grouping? :param skip_generation_limits: Skip the generation limits? :param consider_contingencies: Consider the contingencies? :param contingency_groups_used: List of contingency groups to use :param ramp_constraints: Formulate ramp constraints? :param consider_time_up_down: Consider the time up/down? :param area_spinning_reserve: Area spinning reserve? :param lodf_threshold: LODF threshold value to consider contingencies :param inter_aggregation_info: Inter rea (or country, etc) information :param energy_0: Vector of initial energy for batteries (size: Number of batteries) :param fluid_level_0: initial fluid level of the nodes :param nodal_capacity_sign: if > 0 the generation is maximized, if < 0 the load is maximized :param capacity_nodes_idx: Array of bus indices to optimize their nodal capacity for :param use_glsk_as_cost: If true the generators use the GLSK as dispatch values :param add_losses_approximation: If true the distribution factors losses approximation is used :param logger: logger instance :param progress_text: Text progress callback :param progress_func: Numerical progress callback :param verbose: verbosity level :param robust: Robust optimization? :param mip_framework: MIP framework to use :return: OpfVars

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b module

This file implements a DC-OPF for time series That means that solves the OPF problem for a complete time series at once

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.BatteryVars(nt: int, n_elm: int)[source]

Bases: GenerationVars

struct extending the generation vars to handle the battery vars

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix = None, gen_fuel_rates_matrix: csc_matrix = None) BatteryVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: GenerationVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.BranchVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the branch related vars

add_contingency_flow(t: int, m: int, c: int, flow_var: float | LpVariable | None | LpAffineExpression, neg_slack: LpVariable | None, pos_slack: LpVariable | None)[source]

Add contingency flow :param t: time index :param m: monitored index :param c: contingency group index :param flow_var: flow var :param neg_slack: negative flow slack variable :param pos_slack: positive flow slack variable

get_values(Sbase: float, model: PulpLpModel | None) BranchVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: BranchVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.BusVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the bus related vars

get_values(Sbase: float, model: PulpLpModel | None) BusVars[source]

Return an instance of this class where the array’s content is not LP vars but their value :return: BusVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.FluidInjectionVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of injections of fluid type

get_values(model: PulpLpModel | None) FluidInjectionVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidInjectionVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.FluidNodeVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of nodes of fluid type

get_values(model: PulpLpModel | None) FluidNodeVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidNodeVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.FluidPathVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the vars of paths of fluid type

get_values(model: PulpLpModel | None) FluidPathVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param model: LP model from where we extract the values :return: FluidPathVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.GenerationVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix) GenerationVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :param Sbase: Base power (100 MVA) :param model: LpModel :param gen_emissions_rates_matrix: emissins rates matrix (n_emissions, n_gen) :param gen_fuel_rates_matrix: fuel rates matrix (n_fuels, n_gen) :return: GenerationVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.HvdcVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None) HvdcVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: HvdcVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.LoadVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the load related vars

get_values(Sbase: float, model: PulpLpModel | None) LoadVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: LoadVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.NodalCapacityVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the nodal capacity related vars

get_values(Sbase: float, model: PulpLpModel | None) NodalCapacityVars[source]

Return an instance of this class where the array’s content is not LP vars but their value :return: BusVars

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.OpfVars(nt: int, nbus: int, ng: int, nb: int, nl: int, nbr: int, n_hvdc: int, n_vsc: int, n_fluid_node: int, n_fluid_path: int, n_fluid_inj: int, n_cap_buses: int)[source]

Bases: object

Structure to host the opf variables

get_values(Sbase: float, model: PulpLpModel | None, gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix, gen_tech_shares_matrix: csc_matrix, batt_tech_shares_matrix: csc_matrix) OpfVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: OpfVars instance

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.SystemVars(nt: int)[source]

Bases: object

Struct to store the system vars

compute(gen_emissions_rates_matrix: csc_matrix, gen_fuel_rates_matrix: csc_matrix, gen_tech_shares_matrix: csc_matrix, batt_tech_shares_matrix: csc_matrix, gen_p: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], gen_cost: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], batt_p: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], shedding_cost: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]])[source]

Compute the system values :param gen_emissions_rates_matrix: emissions rates matrix (n_emissions, n_gen) :param gen_fuel_rates_matrix: fuel rates matrix (n_fuels, n_gen) :param gen_tech_shares_matrix: technology shares of the generators :param batt_tech_shares_matrix technology shares of the batteries :param gen_p: Generation power values (nt, ngen) :param gen_cost: Generation cost values (nt, ngen) :param batt_p: Battery power values (nt, nbatt) :param shedding_cost: Shedding cost values (nt, ngen)

class VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.VscVars(nt: int, n_elm: int)[source]

Bases: object

Struct to store the generation vars

get_values(Sbase: float, model: PulpLpModel | None) HvdcVars[source]

Return an instance of this class where the arrays content are not LP vars but their value :return: HvdcVars

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_copper_plate_balance(t_idx: int, bus_vars: BusVars, prob: PulpLpModel | None)[source]

Add the copperplate equality :param t_idx: time step :param bus_vars: BusVars :param prob: LpModel

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_hydro_formulation(local_t: int | None, global_t: int | None, grid: MultiCircuit, time_array: DatetimeIndex, Sbase: float, node_vars: FluidNodeVars, path_vars: FluidPathVars, inj_vars: FluidInjectionVars, generator_vars: GenerationVars, fluid_level_0: ndarray[tuple[Any, ...], dtype[float64]], prob: PulpLpModel | None, logger: Logger)[source]

Formulate the branches :param local_t: local time index :param global_t: global time index :param grid: MultiCircuit :param time_array: list of time indices :param Sbase: base power of the system :param node_vars: FluidNodeVars :param path_vars: FluidPathVars :param inj_vars: FluidInjectionVars :param generator_vars: GeneratorVars :param fluid_level_0: Initial node level :param prob: OR problem :param logger: log of the LP :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_battery_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, batt_vars: BatteryVars, prob: PulpLpModel | None, unit_commitment: bool, ramp_constraints: bool, skip_generation_limits: bool, generation_expansion_planning: bool, energy_0: ndarray[tuple[Any, ...], dtype[float64]])[source]

Add MIP generation formulation :param local_t: time step (possibly reduced or from an interval) :param global_t: global time (integer or None to signal for the snapshot) :param grid: MultiCircuit instance :param bus_idx_dict: Bus-index dictionary :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param batt_data_t: BatteryData structure :param batt_vars: BatteryVars structure :param prob: ORTools problem :param unit_commitment: formulate unit commitment? :param ramp_constraints: formulate ramp constraints? :param skip_generation_limits: skip the generation limits? :param generation_expansion_planning: generation expansion planning? :param energy_0: initial value of the energy stored :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_branches_contingencies_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, Sbase: float, hvdc_vars: HvdcVars, vsc_vars: VscVars, branch_vars: BranchVars, bus_vars: BusVars, prob: PulpLpModel | None, linear_multi_contingencies: LinearMultiContingencies)[source]

Formulate the branches :param local_t: time step (possibly reduced or from an interval) :param global_t: global time (integer or None to signal for the snapshot) :param grid: MultiCircuit instance :param Sbase: base power (100 MVA) :param hvdc_vars: HvdcVars :param vsc_vars: VscVars :param branch_vars: BranchVars :param bus_vars: BusVars :param prob: OR problem :param linear_multi_contingencies: LinearMultiContingencies :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_branches_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, branch_vars: BranchVars, bus_vars: BusVars, prob: PulpLpModel | None, inf=1e+20, add_losses_approximation: bool = False)[source]

Formulate the branches :param local_t: time step (possibly reduced or from an interval) :param global_t: global time (integer or None to signal for the snapshot) :param grid: MultiCircuit instance :param bus_idx_dict: Bus-index dictionary :param Sbase: base power (100 MVA) :param branch_vars: BranchVars :param bus_vars: BusVars :param prob: OR problem :param inf: number considered infinite :param add_losses_approximation: If true the distribution factors losses approximation is used :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_generation_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, time_array: DatetimeIndex, bus_vars: BusVars, gen_vars: GenerationVars, prob: PulpLpModel | None, unit_commitment: bool, ramp_constraints: bool, skip_generation_limits: bool, all_generators_fixed: bool, vd: ndarray[tuple[Any, ...], dtype[int64]], nodal_capacity_active: bool, generation_expansion_planning: bool, use_glsk_as_cost: bool, logger: Logger)[source]

Add MIP generation formulation :param local_t: time step (possibly reduced or from an interval) :param global_t: global time (integer or None to signal for the snapshot) :param grid: MultiCircuit instance :param bus_idx_dict: Bus-index dictionary :param Sbase: base power (100 MVA) :param time_array: complete time array :param bus_vars: BusVars :param gen_vars: GenerationVars structure :param prob: LpModel :param unit_commitment: formulate unit commitment? :param ramp_constraints: formulate ramp constraints? :param skip_generation_limits: skip the generation limits? :param all_generators_fixed: All generators take their snapshot or profile values

instead of resorting to dispatchable status

Parameters:
  • vd – slack indices

  • nodal_capacity_active – nodal capacity active?

  • generation_expansion_planning – generation expansion plan?

  • use_glsk_as_cost – if true, the GLSK values are used instead of the traditional costs

  • logger – Logger instance

:return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_hvdc_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, hvdc_vars: HvdcVars, bus_vars: BusVars, prob: PulpLpModel | None)[source]
Parameters:
  • local_t

  • global_t

  • grid

  • bus_idx_dict

  • Sbase

  • hvdc_vars

  • bus_vars

  • prob

Returns:

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_load_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, bus_vars: BusVars, load_vars: LoadVars, prob: PulpLpModel | None)[source]

Add MIP generation formulation :param local_t: time step (possibly reduced or from an interval) :param global_t: global time (integer or None to signal for the snapshot) :param grid: MultiCircuit instance :param bus_idx_dict: Bus-index dictionary :param Sbase: base power (100 MVA) :param bus_vars: BusVars :param load_data_t: BatteryData structure :param load_vars: BatteryVars structure :param prob: ORTools problem :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_node_balance(local_t: int, grid: MultiCircuit, vd: ndarray[tuple[Any, ...], dtype[int64]], bus_vars: BusVars, nodal_capacity_vars: NodalCapacityVars, capacity_nodes_idx: ndarray[tuple[Any, ...], dtype[int64]], prob: PulpLpModel | None, logger: Logger)[source]

Add the Kirchhoff nodal equality :param local_t: time step :param grid: MultiCircuit :param vd: List of slack node indices :param bus_vars: BusVars :param nodal_capacity_vars: NodalCapacityVars :param capacity_nodes_idx: IntVec :param prob: LpModel :param logger: Logger

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_linear_vsc_formulation(local_t: int, global_t: int | None, grid: MultiCircuit, bus_idx_dict: Dict[Bus, int], Sbase: float, vsc_vars: VscVars, bus_vars: BusVars, prob: PulpLpModel | None, logger: Logger)[source]
Parameters:
  • local_t

  • global_t

  • grid

  • bus_idx_dict

  • Sbase

  • vsc_vars

  • bus_vars

  • prob

  • logger

Returns:

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.add_nodal_capacity_formulation(t: int | None, nodal_capacity_vars: NodalCapacityVars, nodal_capacity_sign: float, capacity_nodes_idx: ndarray[tuple[Any, ...], dtype[int64]], prob: PulpLpModel | None)[source]

Add MIP generation formulation :param t: time step, if None we assume single time step :param nodal_capacity_vars: NodalCapacityVars structure :param nodal_capacity_sign: :param capacity_nodes_idx: IntVec :param prob: ORTools problem :return objective function

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.get_contingency_flow_with_filter(multi_contingency: LinearMultiContingency, base_flow: ndarray[tuple[Any, ...], dtype[float64]], injections: None | ndarray[tuple[Any, ...], dtype[float64]], threshold: float, m: int) LpAffineExpression | None[source]

Get contingency flow :param multi_contingency: MultiContingency object :param base_flow: Base branch flows (nbranch) :param injections: Bus injections increments (nbus) :param threshold: threshold to filter contingency elements :param m: branch monitor index (int) :return: New flows (nbranch)

VeraGridEngine.Simulations.OPF.Formulations.linear_opf_ts_b.run_linear_opf_ts(grid: ~VeraGridEngine.Devices.multi_circuit.MultiCircuit, time_indices: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.int64]] | None, solver_type: ~VeraGridEngine.enumerations.MIPSolvers = HIGHS, zonal_grouping: ~VeraGridEngine.enumerations.ZonalGrouping = No grouping, skip_generation_limits: bool = False, consider_contingencies: bool = False, contingency_groups_used: ~typing.List[~VeraGridEngine.Devices.Events.contingency_group.ContingencyGroup] | None = None, unit_commitment: bool = False, ramp_constraints: bool = False, generation_expansion_planning: bool = False, all_generators_fixed: bool = False, lodf_threshold: float = 0.001, maximize_inter_area_flow: bool = False, inter_aggregation_info: ~VeraGridEngine.Devices.Aggregation.inter_aggregation_info.InterAggregationInfo | None = None, energy_0: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]] | None = None, fluid_level_0: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]] | None = None, optimize_nodal_capacity: bool = False, nodal_capacity_sign: float = 1.0, capacity_nodes_idx: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.int64]] | None = None, use_glsk_as_cost: bool = False, add_losses_approximation: bool = False, logger: ~VeraGridEngine.basic_structures.Logger = <VeraGridEngine.basic_structures.Logger object>, progress_text: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, verbose: int = 0, robust: bool = False, mip_framework: ~VeraGridEngine.enumerations.MIPFramework = PuLP) OpfVars[source]

Run linear optimal power flow :param grid: MultiCircuit instance :param time_indices: Time indices (in the general scheme) :param solver_type: MIP solver to use :param zonal_grouping: Zonal grouping? :param skip_generation_limits: Skip the generation limits? :param consider_contingencies: Consider the contingencies? :param contingency_groups_used: List of contingency groups to use :param unit_commitment: Formulate unit commitment? :param ramp_constraints: Formulate ramp constraints? :param generation_expansion_planning: Generation expansion planning? :param all_generators_fixed: All generators take their snapshot or profile values

instead of resorting to dispatchable status

Parameters:
  • lodf_threshold – LODF threshold value to consider contingencies

  • maximize_inter_area_flow – Maximize the inter-area flow?

  • inter_aggregation_info – Inter rea (or country, etc) information

  • energy_0 – Vector of initial energy for batteries (size: Number of batteries)

  • fluid_level_0 – initial fluid level of the nodes

  • optimize_nodal_capacity – Optimize the nodal capacity? (optional)

  • nodal_capacity_sign – if > 0 the generation is maximized, if < 0 the load is maximized

  • capacity_nodes_idx – Array of bus indices to optimize their nodal capacity for

  • use_glsk_as_cost – If true the generators use the GLSK as dispatch values

  • add_losses_approximation – If true the distribution factors losses approximation is used

  • logger – logger instance

  • progress_text – Text progress callback

  • progress_func – Numerical progress callback

  • verbose – verbosity level

  • robust – Robust optimization?

Returns:

OpfVars

Module contents