Methods

Some various methods used in BranchFlowModel.jl:

Model builders

BranchFlowModel.build_bfm!Function
build_bfm!(m::JuMP.AbstractModel, net::Network{SinglePhase}, mtype::ModelType=AngleRelaxation)

Top-level single phase builder that dispatches the ModelType enum

source
build_bfm!(m::JuMP.AbstractModel, net::Network{SinglePhase}, ::Val{AngleRelaxation})

Add variables and constraints to m using the values in net. Calls the following functions:

add_linear_variables(m, net)
add_vsqrd_variables(m, net)
add_isqrd_variables(m, net)
constrain_power_balance_with_isqrd_losses(m, net)
constrain_substation_voltage(m, net)
constrain_KVL(m, net)
constrain_bilinear(m, net)
source
build_bfm!(m::JuMP.AbstractModel, net::Network{SinglePhase}, ::Val{SOC})

Add variables and constraints to m using the values in net. Calls the following functions:

add_linear_variables(m, net)
add_vsqrd_variables(m, net)
add_isqrd_variables(m, net)
constrain_power_balance_with_isqrd_losses(m, net)
constrain_substation_voltage(m, net)
constrain_KVL(m, net)
constrain_cone(m, net)
source
build_bfm!(m::JuMP.AbstractModel, net::Network{SinglePhase}, ::Val{Linear})

Add variables and constraints to m using the values in net. Calls the following functions:

add_linear_variables(m, net)
add_vsqrd_variables(m, net)
add_isqrd_variables(m, net)
constrain_power_balance_with_isqrd_losses(m, net)
constrain_substation_voltage(m, net)
constrain_KVL(m, net)
constrain_cone(m, net)
source
build_bfm!(m::JuMP.AbstractModel, net::Network{MultiPhase}, mtype::ModelType=Unrelaxed)

Top-level multiphase builder that dispatches the ModelType enum

source
build_bfm!(m::JuMP.AbstractModel, net::Network{MultiPhase}, ::Val{Unrelaxed})

Add variables and constraints to m using the values in net to make an unrelaxed branch flow model. Calls the following functions:

source
build_bfm!(m::JuMP.AbstractModel, net::Network{MultiPhase}, ::Val{Semidefinite})

Add variables and constraints to m using the values in net. Calls the following functions:

source
build_bfm!(m::JuMP.AbstractModel, net::Network{MultiPhase}, ::Val{Linear})

Add variables and constraints to m using the values in net. Calls the following functions:

source

Variable builders

BranchFlowModel.add_bfm_variablesFunction
add_bfm_variables(m, net::Network{MultiPhase})

Define complex variables for:

  • :v bus voltage vectors
  • :i branch current vectors
  • :Sij branch power flow matrices
  • :sj bus net power injection vectors
source
BranchFlowModel.add_sdp_variablesFunction
add_sdp_variables(m, net::Network{MultiPhase})

Create complex variables:

  • m[:w] are 3x3 Hermitian matrices of voltage squared (V*V^T)
  • m[:l] are 3x3 Hermitian matrices of current squared (I*I^T)
  • m[:sj] are 3x1 matrices of net power injections (at bus j)
  • m[:Sij] are 3x3 Complex matrices of line flow powers (from i to j)

Also:

  • m[:H] are 3x3 Hermitian matrices of the positive semi-definite constraints
source
BranchFlowModel.add_linear_variablesFunction
add_linear_variables(m, net::Network{SinglePhase})

Add variables for the single-phase, linear model:

  • pij and qij for all edges(net)
  • p0 and q0 slack bus power
source
add_linear_variables(m, net::Network{MultiPhase})

Define real phase-vector variables for:

  • :vsqrd bus voltage magnitude squared
  • :pij, :qij branch power flows
  • :p, :q for the slack bus net power injection
source
BranchFlowModel.add_vsqrd_variablesFunction
add_vsqrd_variables(m, net::Network{SinglePhase})

Add m[:vsqrd] time vectdor variables. Applies upper/lower bounds if the net.bounds.v_lower/upper_mag are not missing.

source

Constraint builders

BranchFlowModel.constrain_power_balanceFunction
function constrain_power_balance(m, net::Network{MultiPhase})

Sij in - losses == sum of line flows out + net injection NOTE: using sum over pij for future expansion to mesh grids i -> j -> k

All of the power balance constraints are stored in m[:power_balance_constraints] with the bus name (string) as the first index. For example m[:power_balance_constraints]["busname"] will give the constrain container from JuMP for all time steps.

$\sum_{i : i \rightarrow j} \text{diag}( \boldsymbol S_{ij} - \boldsymbol Z_{ij} \left[ \boldsymbol i_{ij} \boldsymbol i_{ij}^H \right]) + \boldsymbol s_j = \sum_{k : j \rightarrow k} \text{diag}( \boldsymbol S_{jk} )^{\Phi_j} \quad \forall j \in \mathcal{N}$

source
BranchFlowModel.constrain_KVLFunction
constrain_KVL(m, net::Network{SinglePhase})

\[w_{j} = w_{i} - 2 (p_{ij} r_{ij} + q_{ij} x_{ij}) + (r_{ij}^2 + x_{ij}^2) \ell_{ij} \quad \forall (i, j) \in \mathcal{E}\]

source
constrain_KVL(m, net::Network{MultiPhase})

Add the voltage drop definitions between busses using the sending end powers and the current squared variables. This is the angle-relaxation form used in the semi-definite program.

NOTE regulators are also hacked in here, setting the voltage to vreg_pu or using the turn_ratio as appropriate.

$w_j = w_i - S_{ij} Z^{\star} - Z S_{ij}^{\star} + Z L_{ij} Z^{\star}$

source
BranchFlowModel.constrain_bfm_nlpFunction
constrain_bfm_nlp(m, net::Network{MultiPhase})

Add the unrelaxed branch flow constraints. Also calls constrain_power_balance.

$\boldsymbol S_{ij} = \boldsymbol v_i^{\Phi_{ij}} \boldsymbol i_{ij}^H \quad \forall (i, j) \in \mathcal{E}$

$\boldsymbol v_i^{\Phi_{ij}} - \boldsymbol v_j = \boldsymbol Z_{ij} \boldsymbol i_{ij} \quad \forall (i, j) \in \mathcal{E}$

source
BranchFlowModel.constrain_linear_power_balanceFunction
constrain_linear_power_balance(m, net::Network{MultiPhase})

$p_{ij,\phi} + p_{j,\phi} = \sum{k:j\rightarrow k} p_{jk,\phi} \quad \forall j \in \mathcal{N}, \forall \phi \in [1,2,3]$

$q_{ij,\phi} + q_{j,\phi} = \sum{k:j\rightarrow k} q_{jk,\phi} \quad \forall j \in \mathcal{N}, \forall \phi \in [1,2,3]$

source
BranchFlowModel.constrain_KVL_linearFunction
constrain_KVL_linear(m, net::Network{SinglePhase})

\[w_j = w_i - 2 r_{ij} P_{ij} - 2 x_{ij} Q_{ij} \quad \forall j \in \mathcal{N}\]

source
constrain_KVL_linear(m, net::Network{MultiPhase})

$\boldsymbol{w}_j = \boldsymbol{w}_i + \boldsymbol{M}_{P,ij} \boldsymbol{P}_{ij} + \boldsymbol{M}_{Q,ij} \boldsymbol{Q}_{ij}$

See MPij and MQij for their definitions.

source
BranchFlowModel.constrain_power_balance_with_isqrd_lossesFunction
function constrain_power_balance_with_isqrd_losses(m, net::Network)

Define the m[:powerbalanceconstraints][bus] ∀ bus ∈ busses(net) as a Dict of constraints. The keys are "p" and "q" for real and reactive power balance respectively. The values are the JuMP constraints.

∑ pij in - losses + net injection - ∑ Pjk out = 0

The net injection are user defined loads. If one wishes to make the net injection a decision variable then delete the constraint and redefine the constraint with your decision variable.

NOTE: using sum over pij for future expansion to mesh grids and the convention: i -> j -> k

source
BranchFlowModel.constrain_coneFunction
constrain_cone(m, net::Network{SinglePhase})

\[\ell_{ij} \geq \frac{p_{ij}^2 + q_{ij}^2}{w_i} \quad \forall (i, j) \in \mathcal{E}\]

source

Other

BranchFlowModel.MPijFunction
MPij(i::String, j::String, net::Network{MultiPhase})

Real power coefficients for 3 phase voltage drop from node i to j

source
BranchFlowModel.MQijFunction
MQij(i::String, j::String, net::Network{MultiPhase})

Reactive power coefficients for 3 phase voltage drop from node i to j

source
BranchFlowModel.check_rank_oneFunction
check_rank_one(m::JuMP.AbstractModel, net::Network, tol=1e-3)

Check the rank of the m[:H] matrices from the PSD cone constraints. Warnings express any values with rank greater than one.

source
CommonOPF.reduce_tree!Function
reduce_tree!(net::Network{SinglePhase})

combine any line sets with intermediate busses that have indegree == outdegree == 1 and is not a load bus into a single line

See remove_bus! for how the two lines are combined.

source
CommonOPF.trim_tree!Function
trim_tree!(net::Network)

Trim any branches that have empty busses, i.e. remove the branches that have no loads or DER.

source
BranchFlowModel.set_inputs!Function
set_inputs!(mg::MetaGraphsNext.MetaGraph; α::Float64=0.0)

Set the shared values in each subgraph / vertex of mg:

  1. set the current vertex's v0 to its inneighbor's voltage
  2. set the current vertex P/Qload to the outneighbors' substation_bus loads
source
BranchFlowModel.get_diffsFunction
get_diffs(mg::MetaGraphsNext.MetaGraph)

Uses the JuMP Models stored in mg.graph_data[:models] to calculate the difference between power injections/loads, and |v| at every leaf/substation connection.

returns three Float64[]

source
BranchFlowModel.solve_metagraph!Function
solve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Function, tol::T; α::T=0.5, verbose=false) where T <: Real

Given a MetaGraphsNext.MetaGraph and a JuMP Model builder method iteratively solve the models until the tol is met for the differences provided by BranchFlowModel.get_diffs.

The builder must accept only one argument of type CommonOPF.AbstractNetwork that returns a JuMP.AbstractModel. Each model returned from the builder is stored as an :m property in each vertex of mg.

Note

tol is compared to the maximum absolute value of all the p, q, and v differences.

source
solve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Function, tols::Vector{T}; α::T=0.5, verbose=false) where T <: Real

Given a MetaGraphsNext.MetaGraph and a JuMP Model builder method iteratively solve the models until the tols are met for the differences provided by BranchFlowModel.get_diffs.

The builder must accept only one argument of type CommonOPF.AbstractNetwork that returns a JuMP.AbstractModel. Each model returned from the builder is stored as an :m property in each vertex of mg.

Note

The tols should have a length of three. The first value is compared to the maximum absolute difference in real power, the second for reactive power, and the third for |v|. All differences are calculated at the leaf/substation connections.

source
solve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Dict{Int64, Function}, tols::Vector{T}; α::T=0.5, verbose=false) where T <: Real

Given a MetaGraphsNext.MetaGraph and a JuMP Model builder method iteratively solve the models until the tols are met for the differences provided by BranchFlowModel.get_diffs. The builder dict is used to build each model for the corresponding vertex key.

Each function in the builder dict must accept only one argument of type CommonOPF.AbstractNetwork that returns a JuMP.AbstractModel. Each model returned from the builder function is stored as an :m property in each vertex of mg.

Note

The tols should have a length of three. The first value is compared to the maximum absolute difference in real power, the second for reactive power, and the third for |v|. All differences are calculated at the leaf/substation connections.

source
BranchFlowModel.check_statusesFunction
check_statuses(mg::MetaGraphsNext.MetaGraph)

Warn if any sub-model has a JuMP.termination_status not in [MOI.OPTIMAL, MOI.ALMOST_OPTIMAL, MOI.LOCALLY_SOLVED]

source
CommonOPF.remove_bus!Function
remove_bus!(j::String, net::Network{SinglePhase})

Remove bus j in the line i->j->k from the model by making an equivalent line from busses i->k

source
remove_bus!(j::String, net::Network{MultiPhase})

Remove bus j in the line i->j->k from the model by making an equivalent line from busses i->k. We assume the conductors from i->j and j->k have impedance matrices.

source