Get power flow equations from PowerModels?

Is it possible to obtain the power flow equations in the form of f(x) = 0 from PowerModels.jl?

Follow-up question, is it possible to get the system of nonlinear equations h(x) = 0 that make up a power flow problem, i.e. h(x) = 0, where h(x) = [ f(x)^\top\!, \, g(x)]^\top, where f(x) are the said power flow equations, and h(x) are the bus specifications?

Perhaps @ccoffrin can help me out? Thanks!

Hi @timueh! Thanks for your question.

As of PowerModels v0.14, PowerModels focuses on building JuMP models (with DC Power Flow being the only dedicated routine that does not require JuMP). So it is not easy to extract the system of equations into Julia functions, such as f(x). If you would like to quickly inspect the JuMP model you can do this,

using PowerModels; using JuMP; using Ipopt
m = Model()
result = run_ac_opf("case.m", with_optimizer(Ipopt.Optimizer), jump_model=m)
println(m)

This issue may be of interest, Dedicated AC Power Flow Solver · Issue #590 · lanl-ansi/PowerModels.jl · GitHub, which seeks to develop a dedicated AC Power Flow solver in PowerModels that would not require JuMP, which could be used to extract the functions you are interested in.

You might find the calc_power_balance and calc_branch_flow_ac functions useful, which simply evaluate the power flow equations on the data model.

Some new documentation on this point, Power Flow · PowerModels

1 Like

Thanks for the great work! Unfortunately, this comes three months too late for an industry project, but I’ll definitely bear that in mind for future reference.

I very much like that you compute the Jacobian as well!

Related to the original question, if I were to return the function f!, that gives me the desired equations.

Oh, one more thing: what’s the dimension of F and x. Is it like in matpower that x \in \mathbb{R}^{n_{pv} + 2n_{pq}}?

The dimension of F and x is 2*|N| where N is the number of buses. What each varibales means varies by the bus type.