From cb0be21c34387ae2e74185c593c84099a6617d81 Mon Sep 17 00:00:00 2001 From: jjospina Date: Wed, 24 Jul 2024 14:00:04 -0600 Subject: [PATCH] WIP: storage balance constraints. --- src/PowerModelsITD.jl | 1 + src/form/storage.jl | 42 ++++++++++++++++++++++++++++++++++++++ src/prob/opfitd.jl | 1 + src/prob/opfitd_storage.jl | 1 + 4 files changed, 45 insertions(+) create mode 100644 src/form/storage.jl diff --git a/src/PowerModelsITD.jl b/src/PowerModelsITD.jl index 54ca1ad..a4acb47 100755 --- a/src/PowerModelsITD.jl +++ b/src/PowerModelsITD.jl @@ -63,6 +63,7 @@ module PowerModelsITD include("form/fotr.jl") include("form/fotp.jl") include("form/lindist3flow.jl") + include("form/storage.jl") include("prob/pfitd.jl") include("prob/opfitd.jl") diff --git a/src/form/storage.jl b/src/form/storage.jl new file mode 100644 index 0000000..a675a16 --- /dev/null +++ b/src/form/storage.jl @@ -0,0 +1,42 @@ +# Storage constraints + +function constraint_storage_phase_unbalance_distribution(pmd::_PMD.AbstractUnbalancedPowerModel, i::Int; nw::Int=nw_id_default, unbalance_factor::Float64=0.05) + + ps = _PMD.var(pmd, nw, :ps, i) + qs = _PMD.var(pmd, nw, :qs, i) + + sc = _PMD.var(pmd, nw, :sc, i) + sd = _PMD.var(pmd, nw, :sd, i) + + conns = length(ps) + connections = collect(range(1, stop=conns)) + + # sd_ps = JuMP.@variable(pmd.model, [c in connections], base_name="$(nw)_sd_ps_$(i)") + # sc_ps = JuMP.@variable(pmd.model, [c in connections], base_name="$(nw)_sc_ps_$(i)") + # sd_qs = JuMP.@variable(pmd.model, [c in connections], base_name="$(nw)_sd_qs_$(i)") + # sc_qs = JuMP.@variable(pmd.model, [c in connections], base_name="$(nw)_sc_qs_$(i)") + + # JuMP.@constraint(pmd.model, sum(ps) == (-1*sd + 1*sc)) + + JuMP.@constraint(pmd.model, ((sum(ps))^2+(sum(qs))^2) == (-1*sd + 1*sc)^2) + + + for (idx,c) in enumerate(connections) + if idx < length(connections) + for d in connections[idx+1:end] + + # JuMP.@constraint(pmd.model, ps[c] >= ps[d] - unbalance_factor*(-1*sd_ps[d] + 1*sc_ps[d])) + # JuMP.@constraint(pmd.model, ps[c] <= ps[d] + unbalance_factor*(-1*sd_ps[d] + 1*sc_ps[d])) + # JuMP.@constraint(pmd.model, qs[c] >= qs[d] - unbalance_factor*(-1*sd_qs[d] + 1*sc_qs[d])) + # JuMP.@constraint(pmd.model, qs[c] <= qs[d] + unbalance_factor*(-1*sd_qs[d] + 1*sc_qs[d])) + + JuMP.@constraint(pmd.model, ps[c] >= ps[d] - unbalance_factor*(-1*sd + 1*sc)) + JuMP.@constraint(pmd.model, ps[c] <= ps[d] + unbalance_factor*(-1*sd + 1*sc)) + + end + + + end + end + +end diff --git a/src/prob/opfitd.jl b/src/prob/opfitd.jl index d4abe28..24b045b 100755 --- a/src/prob/opfitd.jl +++ b/src/prob/opfitd.jl @@ -781,6 +781,7 @@ function build_mn_opfitd(pmitd::AbstractPowerModelITD) _PMD.constraint_storage_complementarity_nl(pmd_model, i; nw=n) _PMD.constraint_mc_storage_losses(pmd_model, i; nw=n) _PMD.constraint_mc_storage_thermal_limit(pmd_model, i; nw=n) + constraint_storage_phase_unbalance_distribution(pmd_model, i; nw=n) end for i in _PMD.ids(pmd_model, n, :branch) diff --git a/src/prob/opfitd_storage.jl b/src/prob/opfitd_storage.jl index 6c12a72..2a54c2d 100755 --- a/src/prob/opfitd_storage.jl +++ b/src/prob/opfitd_storage.jl @@ -818,6 +818,7 @@ function build_mn_opfitd_storage(pmitd::AbstractPowerModelITD) _PMD.constraint_storage_complementarity_nl(pmd_model, i; nw=n) _PMD.constraint_mc_storage_losses(pmd_model, i; nw=n) _PMD.constraint_mc_storage_thermal_limit(pmd_model, i; nw=n) + constraint_storage_phase_unbalance_distribution(pmd_model, i; nw=n) end for i in _PMD.ids(pmd_model, n, :branch)