Methods
Some various methods used in BranchFlowModel.jl:
Model builders
BranchFlowModel.build_bfm! — Functionbuild_bfm!(m::JuMP.AbstractModel, net::Network{SinglePhase}, mtype::ModelType=AngleRelaxation)Top-level single phase builder that dispatches the ModelType enum
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)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)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)build_bfm!(m::JuMP.AbstractModel, net::Network{MultiPhase}, mtype::ModelType=Unrelaxed)Top-level multiphase builder that dispatches the ModelType enum
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:
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:
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:
Variable builders
BranchFlowModel.add_bfm_variables — Functionadd_bfm_variables(m, net::Network{MultiPhase})Define complex variables for:
:vbus voltage vectors:ibranch current vectors:Sijbranch power flow matrices:sjbus net power injection vectors
BranchFlowModel.add_sdp_variables — Functionadd_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
BranchFlowModel.add_linear_variables — Functionadd_linear_variables(m, net::Network{SinglePhase})Add variables for the single-phase, linear model:
pijandqijfor alledges(net)p0andq0slack bus power
add_linear_variables(m, net::Network{MultiPhase})Define real phase-vector variables for:
:vsqrdbus voltage magnitude squared:pij,:qijbranch power flows:p,:qfor the slack bus net power injection
BranchFlowModel.add_vsqrd_variables — Functionadd_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.
BranchFlowModel.add_isqrd_variables — Functionadd_isqrd_variables(m, net::Network{SinglePhase})Add m[:lij] time vector variables with a lower bound of zero.
Constraint builders
BranchFlowModel.constrain_power_balance — Functionfunction 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}$
BranchFlowModel.constrain_KVL — Functionconstrain_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}\]
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}$
BranchFlowModel.constrain_bfm_nlp — Functionconstrain_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}$
BranchFlowModel.constrain_linear_power_balance — Functionconstrain_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]$
BranchFlowModel.constrain_KVL_linear — Functionconstrain_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}\]
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}$
BranchFlowModel.constrain_power_balance_with_isqrd_losses — Functionfunction 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 = 0The 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
BranchFlowModel.constrain_bilinear — Functionconstrain_bilinear(m, net::Network{SinglePhase})\[w_i \ell_{ij} = p_{ij}^2 + q_{ij}^2 \quad \forall (i, j) \in \mathcal{E} \]
BranchFlowModel.constrain_substation_voltage — Functionconstrain_substation_voltage(m, net::Network{SinglePhase})Constrain m[:vsqrd][net.substation_bus] to net.v0^2 (or net.v0[t]^2 if net.v0 is not Real)
BranchFlowModel.constrain_cone — Functionconstrain_cone(m, net::Network{SinglePhase})\[\ell_{ij} \geq \frac{p_{ij}^2 + q_{ij}^2}{w_i} \quad \forall (i, j) \in \mathcal{E}\]
Other
BranchFlowModel.MPij — FunctionMPij(i::String, j::String, net::Network{MultiPhase})Real power coefficients for 3 phase voltage drop from node i to j
BranchFlowModel.MQij — FunctionMQij(i::String, j::String, net::Network{MultiPhase})Reactive power coefficients for 3 phase voltage drop from node i to j
BranchFlowModel.check_rank_one — Functioncheck_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.
CommonOPF.reduce_tree! — Functionreduce_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.
CommonOPF.trim_tree! — Functiontrim_tree!(net::Network)Trim any branches that have empty busses, i.e. remove the branches that have no loads or DER.
BranchFlowModel.set_inputs! — Functionset_inputs!(mg::MetaGraphsNext.MetaGraph; α::Float64=0.0)Set the shared values in each subgraph / vertex of mg:
- set the current vertex's v0 to its inneighbor's voltage
- set the current vertex P/Qload to the outneighbors' substation_bus loads
BranchFlowModel.get_diffs — Functionget_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[]
BranchFlowModel.solve_metagraph! — Functionsolve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Function, tol::T; α::T=0.5, verbose=false) where T <: RealGiven 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.
solve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Function, tols::Vector{T}; α::T=0.5, verbose=false) where T <: RealGiven 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.
solve_metagraph!(mg::MetaGraphsNext.MetaGraph, builder::Dict{Int64, Function}, tols::Vector{T}; α::T=0.5, verbose=false) where T <: RealGiven 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.
BranchFlowModel.check_statuses — Functioncheck_statuses(mg::MetaGraphsNext.MetaGraph)Warn if any sub-model has a JuMP.termination_status not in [MOI.OPTIMAL, MOI.ALMOST_OPTIMAL, MOI.LOCALLY_SOLVED]
CommonOPF.remove_bus! — Functionremove_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
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.