From f760dd69c03ac5cccf7c58afd0797b9e0c8c84bd Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 20 Nov 2024 12:54:18 -0700 Subject: [PATCH] fix to qloss and 3 issue. New objective added --- src/PowerModelsGMD.jl | 2 ++ src/core/constraint.jl | 2 +- src/core/constraint_template.jl | 17 +++++++++++++++++ src/core/data.jl | 2 +- src/form/acp.jl | 10 ++++++---- src/form/wr.jl | 17 +++++++++++------ src/prob/gmd_blocker_placement.jl | 4 ++-- src/prob/gmd_bounds.jl | 2 +- src/prob/gmd_mld.jl | 5 +++-- 9 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/PowerModelsGMD.jl b/src/PowerModelsGMD.jl index f0a1269..4b665e5 100644 --- a/src/PowerModelsGMD.jl +++ b/src/PowerModelsGMD.jl @@ -15,6 +15,8 @@ const _PMGMD = PowerModelsGMD import JSON import JuMP import Memento + import Ipopt + # Suppressing information and warning messages: const _LOGGER = Memento.getlogger(@__MODULE__) diff --git a/src/core/constraint.jl b/src/core/constraint.jl index e130ca7..8ef5470 100644 --- a/src/core/constraint.jl +++ b/src/core/constraint.jl @@ -330,7 +330,7 @@ function constraint_qloss_constant_ieff(pm::_PM.AbstractPowerModel, n::Int, k, i == # Use this if we implement piecewise K # (pm.data["baseMVA"]) / branchMVA ) * (K * vm * ieff) / (3.0 * branchMVA) - (K * vm * ieff) / (3.0 * baseMVA) + (K * vm * ieff) / (3.0 * baseMVA) # need to change based on response # K is per phase ) diff --git a/src/core/constraint_template.jl b/src/core/constraint_template.jl index f4070c5..2fbd5b8 100644 --- a/src/core/constraint_template.jl +++ b/src/core/constraint_template.jl @@ -314,6 +314,23 @@ function constraint_qloss(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default) end +"CONSTRAINT: Calculation of qloss on a per edge basis" +function constraint_qloss_pu(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default) + + branch = _PM.ref(pm, nw, :branch, k) + + i = branch["hi_bus"] + j = branch["lo_bus"] + + bus = _PM.ref(pm, nw, :bus, i) + + K = calc_branch_K_pu(pm,k;nw=nw) + + constraint_qloss_pu(pm, nw, k, i, j, K) + +end + + "CONSTRAINT: Calculation of qloss on a per edge basis where ieff is a constant" function constraint_qloss_constant_ieff(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default) diff --git a/src/core/data.jl b/src/core/data.jl index 2b55953..a384904 100644 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -531,7 +531,7 @@ function calc_branch_K_pu(pm::_PM.AbstractPowerModel, i; nw::Int=pm.cnw) branch = _PM.ref(pm, nw, :branch, i) ibase = calc_branch_ibase(pm,i;nw=nw) - return haskey(branch, "gmd_k") ? (branch["gmd_k"]) / (ibase) / 3 : 0.0 + return haskey(branch, "gmd_k") ? (branch["gmd_k"]) / (ibase) : 0.0 # waiting for response end "FUNCTION: calculate qloss returns MVA diff --git a/src/form/acp.jl b/src/form/acp.jl index a6f859f..4ef2a5c 100644 --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -47,6 +47,7 @@ end "CONSTRAINT: dc current on ungrounded gwye-gwye transformers" function constraint_dc_current_mag_gwye_gwye_xf_3w(pm::_PM.AbstractACPModel, n::Int, k, kh, ih, jh) + Memento.debug(_LOGGER, "branch[$k]: hi_branch[$kh], 0.0") ieff = _PM.var(pm, n, :i_dc_mag)[k] ihi = _PM.var(pm, n, :dc)[(kh,ih,jh)] @@ -94,17 +95,18 @@ end # JuMP.@constraint(pm.model, qloss[(k,j,i)] == 0.0) # end -"CONSTRAINT: qloss calculcated from dc current only" -function constraint_qloss(pm::_PM.AbstractACPModel, n::Int, k, i, j, baseMVA, K) +"CONSTRAINT: qloss calculcated for ac formulation single phase" +function constraint_qloss_pu(pm::_PM.AbstractACPModel, n::Int, k, i, j, K) branch = _PM.ref(pm, n, :branch, k) qloss = _PM.var(pm, n, :qloss) vm = _PM.var(pm, n, :vm)[i] ieff = _PM.var(pm, n, :i_dc_mag, k) - + if branch["type"] == "xfmr" JuMP.@constraint(pm.model, - qloss[(k,i,j)] == K / (3.0 * baseMVA) * ieff * vm + # qloss[(k,i,j)] == K / 3.0 * ieff * vm + qloss[(k,i,j)] == K * ieff * vm ) else diff --git a/src/form/wr.jl b/src/form/wr.jl index 06d30c7..540d8ab 100644 --- a/src/form/wr.jl +++ b/src/form/wr.jl @@ -99,12 +99,16 @@ end "CONSTRAINT: dc current on ungrounded gwye-delta transformers" function constraint_dc_current_mag_gwye_delta_xf(pm::_PM.AbstractWRModel, n::Int, k, kh, ih, jh, ieff_max) - + branch = _PM.ref(pm, n, :branch, k) ieff = _PM.var(pm, n, :i_dc_mag)[k] ihi = _PM.var(pm, n, :dc)[(kh,ih,jh)] - JuMP.@constraint(pm.model, ieff >= ihi) - JuMP.@constraint(pm.model, ieff >= -ihi) + if haskey(branch,"hi_3w_branch") + JuMP.@constraint(pm.model, ieff == 0.0) + else + JuMP.@constraint(pm.model, ieff >= ihi) + JuMP.@constraint(pm.model, ieff >= -ihi) + end # TODO: use variable bounds for this if !isnothing(ieff_max) @@ -260,9 +264,9 @@ end """ -CONSTRAINT: relaxed qloss calculcated from ac voltage and dc current +CONSTRAINT: relaxed qloss calculcated for ac formulation single phase """ -function constraint_qloss(pm::_PM.AbstractWRModel, n::Int, k, i, j, baseMVA, K) +function constraint_qloss_pu(pm::_PM.AbstractWRModel, n::Int, k, i, j, K) branch = _PM.ref(pm, n, :branch, k) qloss = _PM.var(pm, n, :qloss) @@ -270,7 +274,8 @@ function constraint_qloss(pm::_PM.AbstractWRModel, n::Int, k, i, j, baseMVA, K) ieff = _PM.var(pm, n, :i_dc_mag, k) if branch["type"] == "xfmr" - scaled_relaxation_product(pm.model, K/(3.0 * baseMVA), ieff, vm, qloss[(k,i,j)]) + # scaled_relaxation_product(pm.model, K/3.0, ieff, vm, qloss[(k,i,j)]) + scaled_relaxation_product(pm.model, K, ieff, vm, qloss[(k,i,j)]) else JuMP.@constraint(pm.model, qloss[(k,i,j)] == 0.0 diff --git a/src/prob/gmd_blocker_placement.jl b/src/prob/gmd_blocker_placement.jl index 0261264..f93f4df 100644 --- a/src/prob/gmd_blocker_placement.jl +++ b/src/prob/gmd_blocker_placement.jl @@ -39,7 +39,7 @@ function solve_blocker_placement(case, model_type::Type, optimizer; kwargs...) ], solution_processors = [ solution_gmd!, - solution_gmd_qloss!, + # solution_gmd_qloss!, ], kwargs..., ) @@ -87,7 +87,7 @@ function build_blocker_placement(pm::_PM.AbstractPowerModel; kwargs...) _PM.constraint_thermal_limit_from(pm, i) _PM.constraint_thermal_limit_to(pm, i) - constraint_qloss(pm, i) + constraint_qloss_pu(pm, i) constraint_dc_current_mag(pm, i) end diff --git a/src/prob/gmd_bounds.jl b/src/prob/gmd_bounds.jl index c09854b..3759402 100644 --- a/src/prob/gmd_bounds.jl +++ b/src/prob/gmd_bounds.jl @@ -23,7 +23,7 @@ function solve_bound_gmd_bus_v(case, model_type::Type, optimizer; kwargs...) if length(conn) > 1 t = time() for i in conn - bus = _case["gmd_bus"]["$i"] + bus = _case["gmd_bus"]["$i"] if bus["sub"] == -1 kwargs[:setting]["gmd_bus"] = bus["index"] kwargs[:setting]["max"] = true diff --git a/src/prob/gmd_mld.jl b/src/prob/gmd_mld.jl index 08d634c..25cc866 100644 --- a/src/prob/gmd_mld.jl +++ b/src/prob/gmd_mld.jl @@ -78,7 +78,7 @@ function build_gmd_mld(pm::_PM.AbstractPowerModel; kwargs...) _PM.constraint_thermal_limit_from(pm, i) _PM.constraint_thermal_limit_to(pm, i) - constraint_qloss(pm, i) + constraint_qloss_pu(pm, i) constraint_dc_current_mag(pm, i) end @@ -94,7 +94,8 @@ function build_gmd_mld(pm::_PM.AbstractPowerModel; kwargs...) constraint_dc_ohms(pm, i) end - _PM.objective_max_loadability(pm) + # _PM.objective_max_loadability(pm) + objective_max_loadability(pm) end