Skip to content

Commit

Permalink
add constrain_line_amps for multiphase models (with simple test)
Browse files Browse the repository at this point in the history
  • Loading branch information
NLaws committed Jul 25, 2023
1 parent d29b516 commit 33e6391
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LinDistFlow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export
constrain_substation_voltage,
constrain_KVL,
constrain_loads,
constrain_line_amps,
get_bus_values,
get_edge_values,
# recover_voltage_current, # TODO validate this method
Expand Down
30 changes: 30 additions & 0 deletions src/model_multi_phase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,33 @@ function constrain_loads(m, p::Inputs{MultiPhase})
end # reactive loads
end
end


"""
constrain_line_amps(m, p::Inputs{MultiPhase})
Estimating the line amps as ``|\\Delta V / Z|``
"""
function constrain_line_amps(m, p::Inputs{MultiPhase})
w = m[:vsqrd]
m[:amps_pu] = Dict(ek => Dict() for ek in p.edge_keys)
for j in p.busses
for i in i_to_j(j, p) # for radial network there is only one i in i_to_j
ij_linecode = get_ijlinecode(i,j,p)
amps_pu = sqrt(p.Isquared_up_bounds[ij_linecode]) / p.Ibase
z = sqrt(rij(i,j,p)^2 + xij(i,j,p)^2) # in per-unit

for phs in p.phases_into_bus[j]
@constraint(m, [t in 1:p.Ntimesteps],
-amps_pu <= (w[i,phs,t] - w[j,phs,t]) / z[phs,phs] <= amps_pu
)
m[:amps_pu][i*"-"*j][phs] = Dict()
for t in 1:p.Ntimesteps
m[:amps_pu][i*"-"*j][phs][t] = (w[i,phs,t] - w[j,phs,t]) / z[phs,phs]
end
# TODO better storage of line amps (make an expression?)
# TODO line amps in Results?
end
end
end
end
58 changes: 57 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,60 @@ end
@test vs[("633", phs, 1)] 1.03^2
end

end
end


@testset "constrain line amps" begin

p = Inputs(
joinpath("data", "13bus", "IEEE13Nodeckt.dss"),
"rg60";
Pload=Dict(),
Qload=Dict(),
Sbase=5_000_000, # msankur has 5,000 kvar * 1e3
Vbase=4160,
v0 = 1.00,
v_uplim = 1.05,
v_lolim = 0.95,
Ntimesteps = 1,
P_up_bound=1e5,
Q_up_bound=1e5,
P_lo_bound=-1e5,
Q_lo_bound=-1e5,
);

m = Model(HiGHS.Optimizer)
build_ldf!(m, p)
@objective(m, Min, sum(
m[:Pj][p.substation_bus, phs, 1] + m[:Qj][p.substation_bus, phs, 1]
for phs in 1:3)
)
constrain_line_amps(m,p)
optimize!(m)

# find the max amps then constrain it, should get infeasible problem
optimal_amps = []
for (edge_key, phs_dict) in m[:amps_pu]
for (phs, time_dict) in phs_dict
for (t, var) in time_dict
push!(optimal_amps, value(var) * p.Ibase)
end
end
end
max_amps = maximum(optimal_amps)
p.Isquared_up_bounds = Dict(
k => (max_amps - 10)^2
for k in keys(p.Isquared_up_bounds)
)

m = Model(HiGHS.Optimizer)
build_ldf!(m, p)
@objective(m, Min, sum(
m[:Pj][p.substation_bus, phs, 1] + m[:Qj][p.substation_bus, phs, 1]
for phs in 1:3)
)

constrain_line_amps(m,p)
optimize!(m)
@test termination_status(m) == MOI.INFEASIBLE
end

0 comments on commit 33e6391

Please sign in to comment.