Skip to content

Instantly share code, notes, and snippets.

@kersulis
Last active November 12, 2015 21:25
Show Gist options
  • Save kersulis/db706e35667152739a18 to your computer and use it in GitHub Desktop.
Save kersulis/db706e35667152739a18 to your computer and use it in GitHub Desktop.
Injection shift factors for DC power flow. Accommodates both single slack and distributed slack (droop response).
"""
Calculate injection shift factor matrix.
Each row corresponds to a line in the network.
Each column corresponds to a node.
Credit to Jonathon Martin for derivation.
Inputs:
* `Y`: full admittance matrix
* `lines`: vector of tuples; each tuple encodes a line as (i,j)
* `ref`: index of angle reference bus
* `k`: vector of generator participation factors
"""
function isf(
Y::AbstractArray,
lines::Vector{Tuple{Int64,Int64}},
ref::Int64,
k=[NaN]::Vector{Float64}
)
Y = full(Y)
n,l = (size(Y,1),length(lines))
Bflow = zeros(l,n)
for idx in 1:l
i,j = lines[idx]
Bflow[idx,i] = Y[i,j]
Bflow[idx,j] = -Y[i,j]
end
if length(k) != 1
Y[:,ref] = k
B = Y
Bflow[:,ref] = zeros(l)
else
nonref = setdiff(1:n,ref)
B = Y[nonref,nonref]
Bflow = Bflow[:,nonref]
end
return Bflow/B
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment