Running an optimal power flow¶
Warning
The OPF implementation is currently a beta feature. Its API and behavior may change in future versions.
You can use the module pypowsybl.opf to run optimal power flow calculations.
A standard load flow solves for branch flows and bus voltages from specified set points, such as generator active power and voltage targets. Optimal Power Flow (OPF) searches for the best operating point for a given objective, while satisfying the power-flow equations and operational constraints modeled by the OPF implementation.
OPF follows PowSyBl/IIDM conventions for signs and units.
In AC/DC mode, OPF solves a coupled model with AC buses, detailed DC nodes and lines, and voltage source converters (VSCs) linking the AC and DC sides.
Running an OPF¶
Start by importing the network and OPF modules:
import pypowsybl.network as n
import pypowsybl.opf as opf
Create a network, select an OPF mode, and run the calculation:
network = n.create_ieee14()
parameters = opf.OptimalPowerFlowParameters(
mode=opf.OptimalPowerFlowMode.LOADFLOW,
solver_type=opf.SolverType.IPOPT,
)
success = opf.run_ac(network, parameters)
if not success:
raise RuntimeError("OPF did not converge")
Solver¶
The OPF uses PyOptInterface with IPOPT as the default solver of the optimal power flow.
The IPOPT native library is not shipped with PyPowSyBl nor PyOptInterface. When it is not available, running an OPF raises RuntimeError: IPOPT library is not loaded. To install a precompiled IPOPT and make it discoverable, follow the PyOptInterface IPOPT setup guide.
Parameters¶
The calculation is configured with OptimalPowerFlowParameters.
This user guide only shows the main execution path. For the complete list of parameters, modes, solver options and default values, see the OPF API reference.
Results¶
The run_ac() function returns True when the calculation converges and False otherwise.
When the calculation converges, solved values are written back to the network object. This includes the computed operating point as well as the solved power flow results of the network. These values can be read from the usual network dataframes.
AC/DC model overview¶
In AC/DC mode, OPF solves AC and DC equations in the same optimization problem. The model includes:
AC bus voltage magnitudes and angles;
AC generated active and reactive powers;
DC node voltages;
DC line currents;
VSC active and reactive powers;
Converter DC currents.
AC/DC objective function¶
In AC/DC mode, the current objective function minimizes DC line current usage:
where I1 and I2 are the two oriented current variables of each modeled DC line.
DC buses¶
DC nodes satisfy a current-balance equation:
where the currents are defined as flowing out of the DC node.
DC lines¶
A DC line between dc_node1 and dc_node2 is modeled with Ohm’s law.
For a line resistance R and node voltages V1 and V2:
I1 is positive when current flows out of dc_node1 towards the line. I2 is positive when current flows out of dc_node2 towards the line.
Voltage source converters¶
A voltage source converter links one AC bus to two DC nodes.
A VSC can control either:
the active power on the AC side, with
P_PCCmode;the voltage difference between its two DC nodes, with
V_DCmode.
For V_DC mode, the voltage target is:
Converter power balance¶
The converter DC current I is oriented from dc_node1 to dc_node2.
The DC-side converter power is:
The AC-side converter active power P_AC follows the converter AC-terminal load convention. P_AC > 0 means the converter absorbs active power from the AC network, and P_AC < 0 means it injects active power into the AC network. For P_PCC mode, target_p and the written p_ac value follow this convention.
The active-power balance of the converter is:
with:
Converter losses are modeled as a function of the DC current magnitude:
where:
(I) is the DC current oriented from
dc_node1todc_node2;(a) is the idle loss;
(b) is the switching loss coefficient;
(c) is the resistive loss coefficient.
In rectifier mode, power flows from AC to DC:
In inverter mode, power flows from DC to AC:
DC voltage bases¶
In AC/DC OPF, networks with several nominal voltages inside the same DC component are rejected before solving.
Scope and limitations¶
As a beta, the optimal power flow in the AC/DC mode applies fixed placeholder operating limits instead of reading them from the network:
VSC active and reactive power bounds;
DC node voltage bounds;
DC line current bounds.
DC switches are not yet modeled.