# AC Linear optimal power flow time series¶

General indices and dimensions

Variable Description
n Number of nodes
m Number of branches
ng Number of generators
nb Number of batteries
nt Number of time steps
pqpv Vector of node indices of the the PQ and PV buses.
vd Vector of node indices of the the Slack (or VD) buses.

## Objective function¶

The objective function minimizes the cost of generation plus all the slack variables set in the problem. ## Power injections¶

This equation is not a restriction but the computation of the power injections (fix and LP variables) that are injected per node, such that the vector is dimensionally coherent with the number of buses.  Variable Description Dimensions Type Units Matrix of active power per node and time step. n, nt Float + LP p.u. Bus-Generators connectivity matrix. n, ng int 1/0 Matrix of generators active power per time step. ng, nt LP p.u. Bus-Batteries connectivity matrix. nb int 1/0 Matrix of batteries active power per time step. nb, nt LP p.u. Bus-Generators connectivity matrix. n, nl int 1/0 Matrix of active power loads per time step. nl, nt Float p.u. Matrix of reactive power loads per time step. nl, nt Float p.u. Matrix of active power load slack variables per time step. nl, nt LP p.u.

## Nodal power balance¶

This is the OPF based on the formulation presented in Linearized AC Load Flow Applied to Analysis in Electric Power Systems , we obtain a way to solve circuits in one shot (without iterations) and with quite positive results for a linear approximation. This matrix equation turns into two sets of restrictions:  An additional set of restrictions is needed in order to include the slack nodes in the formulation. These are not required for the power flow formulation but they are in the optimal power flow one that is presented. Remember to set the slack-node voltage angles and module increments and the PV node voltage module increments to zero! Otherwise the generator’s power will no be used by the solver to provide voltage values.  Variable Description Dimensions Type Units Matrix of susceptances. . n, n Float p.u. Matrix of susceptances of the series elements. . n, n Float p.u. Matrix of conductances. . n, n Float p.u. Matrix of conductances of the series elements. . n, n Float p.u. Matrix of active power per node and per time step. n, nt Float + LP p.u. Matrix of reactive power per node and per time step. n, nt Float + LP p.u. Matrix of generators voltage angles increment per node and per time step. n, nt LP radians. Matrix of generators voltage module increments per node and per time step. n, nt LP p.u.

Something else that we need to do is to check that the branch flows respect the established limits. Note that because of the linear simplifications, the computed solution in active power might actually be dangerous for the grid. That is why a real power flow should counter check the OPF solution.

First we compute the arrays of nodal voltage angles for each of the “from” and “to” sides of each branch. This is not a restriction but a simple calculation to aid the next restrictions that apply per branch. Now, these are restrictions that define that the “from->to” and the “to->from” flows must respect the branch rating. Another restriction that we may impose is that the loading slacks must be equal, since they represent the extra line capacity required to transport the power in both senses of the transportation. Variable Description Dimensions Type Units Vector of series susceptances of the branches.

Can be computed as m Float p.u. Branch-Bus connectivity matrix at the “from” end of the branches. m, n int 1/0 Branch-Bus connectivity matrix at the “to” end of the branches. m, n int 1/0 Matrix of bus voltage angles at the “from” end of the branches per bus and time step. m, nt LP radians. Matrix of bus voltage angles at the “to” end of the branches per bus and time step. m, nt LP radians. Matrix of bus voltage angles per bus and time step. n, nt LP radians. Matrix of branch ratings per branch and time step. m, nt Float p.u. Matrix of branch rating slacks in the from->to sense per branch and time step. m, nt LP p.u. Matrix of branch rating slacks in the to->from sense per branch and time step. m, nt LP p.u.

## Battery discharge restrictions¶

The first value of the batteries’ energy is the initial state of charge ( ) times the battery capacity. The capacity in the subsequent time steps is the previous capacity minus the power dispatched. Note that the convention is that the positive power is discharged by the battery and the negative power values represent the power charged by the battery. The batteries’ energy has to be kept within the batteries’ operative ranges. Variable Description Dimensions Type Units Matrix of energy stored in the batteries. nb, nt LP p.u. Vector of initial states of charge. nb Float p.u. Vector of maximum states of charge. nb Float p.u. Vector of minimum states of charge. nb Float p.u. Vector of battery capacities. nb Float h  Time increment in the interval [t-1, t]. 1 Float Vector of battery power injections. nb LP p.u. Vector of Battery efficiency for charge and discharge. nb Float p.u.
  Rossoni, P. / Moreti da Rosa, W. / Antonio Belati, E., Linearized AC Load Flow Applied to Analysis in Electric Power Systems, IEEE Latin America Transactions, 14, 9; 4048-4053, 2016