Skip to content

Commit

Permalink
WIP sotchastic artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjospina committed Sep 13, 2024
1 parent 0c9d6d7 commit a64539c
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/PowerModelsITD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module PowerModelsITD
include("form/fotr.jl")
include("form/fotp.jl")
include("form/lindist3flow.jl")
include("form/acp_stochastic.jl")

include("form_decomposition/boundary.jl")
include("form_decomposition/acr.jl")
Expand All @@ -80,6 +81,7 @@ module PowerModelsITD
include("form_decomposition/fotr.jl")
include("form_decomposition/fotp.jl")
include("form_decomposition/lindist3flow.jl")
include("form_decomposition/acp_stochastic.jl")

include("prob/pfitd.jl")
include("prob/opfitd.jl")
Expand All @@ -88,6 +90,8 @@ module PowerModelsITD
include("prob/opfitd_storage.jl")
include("prob/opfitd_decomposition.jl")
include("prob/pfitd_decomposition.jl")
include("prob/opfitd_stochastic.jl")
include("prob/opfitd_decomposition_stochastic.jl")

# This must come last to support automated export.
include("core/export.jl")
Expand Down
12 changes: 6 additions & 6 deletions src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ function instantiate_model_decomposition(
master_boundary_vars_vector = Vector{Vector{Vector{JuMP.VariableRef}}}(undef, number_of_subproblems)

# Threaded loop for instantiating subproblems
# Threads.@threads for i in 1:1:number_of_subproblems # faster but causes +RAM usage
for i in 1:1:number_of_subproblems
Threads.@threads for i in 1:1:number_of_subproblems # faster but causes +RAM usage
# for i in 1:1:number_of_subproblems
ckt_name = ckts_names_vector[i]
ckt_data = ckts_data_vector[i]

Expand All @@ -374,8 +374,8 @@ function instantiate_model_decomposition(
ckt_data[pmitd_it_name] = boundary_for_ckt

# Initialize MP and SP in RemoteChannel
mp_string_vector_rcs[i] = Distributed.RemoteChannel(()->Channel{Vector{String}}(1))
sp_string_vector_rcs[i] = Distributed.RemoteChannel(()->Channel{Vector{String}}(1))
mp_string_vector_rcs[i] = Distributed.RemoteChannel(()->Channel{String}(1))
sp_string_vector_rcs[i] = Distributed.RemoteChannel(()->Channel{String}(1))

# Initialize MP and SP in RemoteChannel
status_signal_vector_rcs[i] = Distributed.RemoteChannel(()->Channel{String}(1))
Expand Down Expand Up @@ -492,8 +492,8 @@ function instantiate_model_decomposition(
boundary_vars_vector = Vector{Vector{Vector{JuMP.VariableRef}}}(undef, number_of_subproblems)

# Threaded loop for instantiating subproblems
# Threads.@threads for i in 1:1:number_of_subproblems # faster but causes +RAM usage
for i in 1:number_of_subproblems
Threads.@threads for i in 1:1:number_of_subproblems # faster but causes +RAM usage
# for i in 1:number_of_subproblems
ckt_name = ckts_names_vector[i]
ckt_data = ckts_data_vector[i]

Expand Down
71 changes: 71 additions & 0 deletions src/form/acp_stochastic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ACP Constraints

"""
function constraint_transmission_power_balance(
pmitd::AbstractPowerModelITD,
pm::_PM.AbstractACPModel,
n::Int,
i::Int,
bus_arcs,
bus_arcs_dc,
bus_arcs_sw,
bus_gens,
bus_storage,
bus_pd,
bus_qd,
bus_gs,
bus_bs,
bus_arcs_boundary_from
)
ACP transmission constraint power balance.
"""
function constraint_transmission_power_balance_stochastic(pmitd::AbstractPowerModelITD, pm::_PM.AbstractACPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs, bus_arcs_boundary_from)

vm = _PM.var(pm, n, :vm, i)

p = _PM.get(_PM.var(pm, n), :p, Dict()); _PM._check_var_keys(p, bus_arcs, "active power", "branch")
q = _PM.get(_PM.var(pm, n), :q, Dict()); _PM._check_var_keys(q, bus_arcs, "reactive power", "branch")
pg = _PM.get(_PM.var(pm, n), :pg, Dict()); _PM._check_var_keys(pg, bus_gens, "active power", "generator")
qg = _PM.get(_PM.var(pm, n), :qg, Dict()); _PM._check_var_keys(qg, bus_gens, "reactive power", "generator")
ps = _PM.get(_PM.var(pm, n), :ps, Dict()); _PM._check_var_keys(ps, bus_storage, "active power", "storage")
qs = _PM.get(_PM.var(pm, n), :qs, Dict()); _PM._check_var_keys(qs, bus_storage, "reactive power", "storage")
psw = _PM.get(_PM.var(pm, n), :psw, Dict()); _PM._check_var_keys(psw, bus_arcs_sw, "active power", "switch")
qsw = _PM.get(_PM.var(pm, n), :qsw, Dict()); _PM._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch")
p_dc = _PM.get(_PM.var(pm, n), :p_dc, Dict()); _PM._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline")
q_dc = _PM.get(_PM.var(pm, n), :q_dc, Dict()); _PM._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline")

# Boundary
pbound_fr = get(var(pmitd, n), :pbound_fr, Dict()); _PM._check_var_keys(pbound_fr, bus_arcs_boundary_from, "active power", "boundary")
qbound_fr = get(var(pmitd, n), :qbound_fr, Dict()); _PM._check_var_keys(qbound_fr, bus_arcs_boundary_from, "reactive power", "boundary")

cstr_p = JuMP.@constraint(pmitd.model,
sum(p[a] for a in bus_arcs)
+ sum(p_dc[a_dc] for a_dc in bus_arcs_dc)
+ sum(psw[a_sw] for a_sw in bus_arcs_sw)
+ pbound_fr[bus_arcs_boundary_from[1]][1]
==
sum(pg[g] for g in bus_gens)
- sum(ps[s] for s in bus_storage)
- sum(pd for (i,pd) in bus_pd)
- sum(gs for (i,gs) in bus_gs)*vm^2
)

cstr_q = JuMP.@constraint(pmitd.model,
sum(q[a] for a in bus_arcs)
+ sum(q_dc[a_dc] for a_dc in bus_arcs_dc)
+ sum(qsw[a_sw] for a_sw in bus_arcs_sw)
+ qbound_fr[bus_arcs_boundary_from[1]][1]
==
sum(qg[g] for g in bus_gens)
- sum(qs[s] for s in bus_storage)
- sum(qd for (i,qd) in bus_qd)
+ sum(bs for (i,bs) in bus_bs)*vm^2
)

if _IM.report_duals(pmitd)
sol(pmitd, n, :bus, i)[:lam_kcl_r] = cstr_p
sol(pmitd, n, :bus, i)[:lam_kcl_i] = cstr_q
end

end
35 changes: 35 additions & 0 deletions src/form/boundary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,41 @@ function constraint_boundary_voltage_angle(pmitd::AbstractPowerModelITD, i::Int;

end

### Bus - KCL Constraints ###
"""
function constraint_transmission_power_balance_boundary(
pmitd::AbstractPowerModelITD,
i::Int;
nw_pmitd::Int=nw_id_default
)
General power balance contraints for boundary buses in the transmission system-side.
"""
function constraint_transmission_power_balance_boundary_stochastic(pmitd::AbstractPowerModelITD, i::Int; nw_pmitd::Int=nw_id_default)

# Extract the transmission model
pm_model = _get_powermodel_from_powermodelitd(pmitd)
bus = _PM.ref(pm_model, nw_pmitd, :bus, i)

bus_arcs = _PM.ref(pm_model, nw_pmitd, :bus_arcs, i)
bus_arcs_dc = _PM.ref(pm_model, nw_pmitd, :bus_arcs_dc, i)
bus_arcs_sw = _PM.ref(pm_model, nw_pmitd, :bus_arcs_sw, i)
bus_gens = _PM.ref(pm_model, nw_pmitd, :bus_gens, i)
bus_loads = _PM.ref(pm_model, nw_pmitd, :bus_loads, i)
bus_shunts = _PM.ref(pm_model, nw_pmitd, :bus_shunts, i)
bus_storage = _PM.ref(pm_model, nw_pmitd, :bus_storage, i)

bus_pd = Dict(k => _PM.ref(pm_model, nw_pmitd, :load, k, "pd") for k in bus_loads)
bus_qd = Dict(k => _PM.ref(pm_model, nw_pmitd, :load, k, "qd") for k in bus_loads)

bus_gs = Dict(k => _PM.ref(pm_model, nw_pmitd, :shunt, k, "gs") for k in bus_shunts)
bus_bs = Dict(k => _PM.ref(pm_model, nw_pmitd, :shunt, k, "bs") for k in bus_shunts)

bus_arcs_boundary_from = ref(pmitd, nw_pmitd, :bus_arcs_boundary_from, i)
constraint_transmission_power_balance_stochastic(pmitd, pm_model, nw_pmitd, i, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs, bus_arcs_boundary_from)

end


### Bus - KCL Constraints ###
"""
Expand Down
70 changes: 70 additions & 0 deletions src/form_decomposition/acp_stochastic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ACP Constraints & Boundary Linking Vars.

"""
function constraint_transmission_power_balance(
pm::_PM.AbstractACPModel,
n::Int,
i::Int,
bus_arcs,
bus_arcs_dc,
bus_arcs_sw,
bus_gens,
bus_storage,
bus_pd,
bus_qd,
bus_gs,
bus_bs,
bus_arcs_boundary_from
)
ACP transmission constraint power balance for decomposition model.
"""
function constraint_transmission_power_balance_stochastic(pm::_PM.AbstractACPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs, bus_arcs_boundary_from)

vm = _PM.var(pm, n, :vm, i)

p = _PM.get(_PM.var(pm, n), :p, Dict()); _PM._check_var_keys(p, bus_arcs, "active power", "branch")
q = _PM.get(_PM.var(pm, n), :q, Dict()); _PM._check_var_keys(q, bus_arcs, "reactive power", "branch")
pg = _PM.get(_PM.var(pm, n), :pg, Dict()); _PM._check_var_keys(pg, bus_gens, "active power", "generator")
qg = _PM.get(_PM.var(pm, n), :qg, Dict()); _PM._check_var_keys(qg, bus_gens, "reactive power", "generator")
ps = _PM.get(_PM.var(pm, n), :ps, Dict()); _PM._check_var_keys(ps, bus_storage, "active power", "storage")
qs = _PM.get(_PM.var(pm, n), :qs, Dict()); _PM._check_var_keys(qs, bus_storage, "reactive power", "storage")
psw = _PM.get(_PM.var(pm, n), :psw, Dict()); _PM._check_var_keys(psw, bus_arcs_sw, "active power", "switch")
qsw = _PM.get(_PM.var(pm, n), :qsw, Dict()); _PM._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch")
p_dc = _PM.get(_PM.var(pm, n), :p_dc, Dict()); _PM._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline")
q_dc = _PM.get(_PM.var(pm, n), :q_dc, Dict()); _PM._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline")

# Boundary
pbound_load = get(_PM.var(pm, n), :pbound_load, Dict()); _PM._check_var_keys(pbound_load, bus_arcs_boundary_from, "active power", "boundary")
qbound_load = get(_PM.var(pm, n), :qbound_load, Dict()); _PM._check_var_keys(qbound_load, bus_arcs_boundary_from, "reactive power", "boundary")

cstr_p = JuMP.@constraint(pm.model,
sum(p[a] for a in bus_arcs)
+ sum(p_dc[a_dc] for a_dc in bus_arcs_dc)
+ sum(psw[a_sw] for a_sw in bus_arcs_sw)
+ pbound_load[bus_arcs_boundary_from[1]][1]
==
sum(pg[g] for g in bus_gens)
- sum(ps[s] for s in bus_storage)
- sum(pd for (i,pd) in bus_pd)
- sum(gs for (i,gs) in bus_gs)*vm^2
)

cstr_q = JuMP.@constraint(pm.model,
sum(q[a] for a in bus_arcs)
+ sum(q_dc[a_dc] for a_dc in bus_arcs_dc)
+ sum(qsw[a_sw] for a_sw in bus_arcs_sw)
+ qbound_load[bus_arcs_boundary_from[1]][1]
==
sum(qg[g] for g in bus_gens)
- sum(qs[s] for s in bus_storage)
- sum(qd for (i,qd) in bus_qd)
+ sum(bs for (i,bs) in bus_bs)*vm^2
)

if _IM.report_duals(pm)
_PM.sol(pm, n, :bus, i)[:lam_kcl_r] = cstr_p
_PM.sol(pm, n, :bus, i)[:lam_kcl_i] = cstr_q
end

end
32 changes: 32 additions & 0 deletions src/form_decomposition/boundary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@ function constraint_boundary_voltage_angle(pmd::_PMD.AbstractUnbalancedPowerMode
end


"""
function constraint_transmission_power_balance_boundary(
pm::_PM.AbstractPowerModel,
i::Int;
nw_pm::Int=nw_id_default
)
General power balance contraints for boundary buses in the transmission system-side for decomposition.
"""
function constraint_transmission_power_balance_boundary_stochastic(pm::_PM.AbstractPowerModel, i::Int; nw_pm::Int=nw_id_default)

bus_arcs = _PM.ref(pm, nw_pm, :bus_arcs, i)
bus_arcs_dc = _PM.ref(pm, nw_pm, :bus_arcs_dc, i)
bus_arcs_sw = _PM.ref(pm, nw_pm, :bus_arcs_sw, i)
bus_gens = _PM.ref(pm, nw_pm, :bus_gens, i)
bus_loads = _PM.ref(pm, nw_pm, :bus_loads, i)
bus_shunts = _PM.ref(pm, nw_pm, :bus_shunts, i)
bus_storage = _PM.ref(pm, nw_pm, :bus_storage, i)

bus_pd = Dict(k => _PM.ref(pm, nw_pm, :load, k, "pd") for k in bus_loads)
bus_qd = Dict(k => _PM.ref(pm, nw_pm, :load, k, "qd") for k in bus_loads)

bus_gs = Dict(k => _PM.ref(pm, nw_pm, :shunt, k, "gs") for k in bus_shunts)
bus_bs = Dict(k => _PM.ref(pm, nw_pm, :shunt, k, "bs") for k in bus_shunts)

bus_arcs_boundary_from = _PM.ref(pm, nw_pm, :bus_arcs_boundary_from, i)
constraint_transmission_power_balance_stochastic(pm, nw_pm, i, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs, bus_arcs_boundary_from)

end



"""
function constraint_transmission_power_balance_boundary(
pm::_PM.AbstractPowerModel,
Expand Down
Loading

0 comments on commit a64539c

Please sign in to comment.