From 97ef99fc7875c0819aa8961f665a2b35f7d3a433 Mon Sep 17 00:00:00 2001 From: Carleton Coffrin Date: Wed, 16 Jun 2021 13:16:16 -0600 Subject: [PATCH] fix bfa sign bug, closes #779 (#780) --- CHANGELOG.md | 1 + src/form/bf.jl | 4 ++-- test/multinetwork.jl | 8 ++++---- test/opf.jl | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2e336c..27aefc57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ PowerModels.jl Change Log ========================= ### Staged +- Fixed sign bug in BFA models (#779) - Fixed `correct_component_refrence_bus!` when no active generators are present (#776) ### v0.18.1 diff --git a/src/form/bf.jl b/src/form/bf.jl index d5f3b6f9..cde93e9a 100644 --- a/src/form/bf.jl +++ b/src/form/bf.jl @@ -162,8 +162,8 @@ function constraint_power_losses(pm::AbstractBFAModel, n::Int, i, f_bus, t_bus, w_fr = var(pm, n, :w, f_bus) w_to = var(pm, n, :w, t_bus) - JuMP.@constraint(pm.model, p_fr + p_to == g_sh_fr*(w_fr/tm^2) + g_sh_to*w_to) - JuMP.@constraint(pm.model, q_fr + q_to == b_sh_fr*(w_fr/tm^2) + b_sh_to*w_to) + JuMP.@constraint(pm.model, p_fr + p_to == g_sh_fr*(w_fr/tm^2) + g_sh_to*w_to) + JuMP.@constraint(pm.model, q_fr + q_to == -b_sh_fr*(w_fr/tm^2) - b_sh_to*w_to) end diff --git a/test/multinetwork.jl b/test/multinetwork.jl index 433d431b..b979b4b1 100644 --- a/test/multinetwork.jl +++ b/test/multinetwork.jl @@ -385,22 +385,22 @@ TESTLOG = Memento.getlogger(PowerModels) @test isapprox(result["objective"], 57980.0; atol = 1e0) @test isapprox(result["solution"]["nw"]["1"]["storage"]["1"]["ps"], 0.0000000; atol = 1e-3) - @test isapprox(result["solution"]["nw"]["1"]["storage"]["1"]["qs"], 0.0543982; atol = 1e-3) + @test isapprox(result["solution"]["nw"]["1"]["storage"]["1"]["qs"], 0.0562204; atol = 1e-3) @test isapprox(result["solution"]["nw"]["1"]["storage"]["2"]["ps"], -0.0834412; atol = 1e-3) @test isapprox(result["solution"]["nw"]["1"]["storage"]["2"]["qs"], 0.0801070; atol = 1e-3) @test isapprox(result["solution"]["nw"]["2"]["storage"]["1"]["ps"], 0.0000000; atol = 1e-3) - @test isapprox(result["solution"]["nw"]["2"]["storage"]["1"]["qs"], 0.0552175; atol = 1e-3) + @test isapprox(result["solution"]["nw"]["2"]["storage"]["1"]["qs"], 0.0569621; atol = 1e-3) @test isapprox(result["solution"]["nw"]["2"]["storage"]["2"]["ps"], 0.0000000; atol = 1e-3) @test isapprox(result["solution"]["nw"]["2"]["storage"]["2"]["qs"], 0.0803519; atol = 1e-3) @test isapprox(result["solution"]["nw"]["3"]["storage"]["1"]["ps"], 0.0000000; atol = 1e-3) - @test isapprox(result["solution"]["nw"]["3"]["storage"]["1"]["qs"], 0.0535058; atol = 1e-3) + @test isapprox(result["solution"]["nw"]["3"]["storage"]["1"]["qs"], 0.0553956; atol = 1e-3) @test isapprox(result["solution"]["nw"]["3"]["storage"]["2"]["ps"], -0.1565587; atol = 1e-3) @test isapprox(result["solution"]["nw"]["3"]["storage"]["2"]["qs"], 0.0806228; atol = 1e-3) @test isapprox(result["solution"]["nw"]["4"]["storage"]["1"]["ps"], -0.1800000; atol = 1e-3) - @test isapprox(result["solution"]["nw"]["4"]["storage"]["1"]["qs"], 0.0549343; atol = 1e-3) + @test isapprox(result["solution"]["nw"]["4"]["storage"]["1"]["qs"], 0.0566681; atol = 1e-3) @test isapprox(result["solution"]["nw"]["4"]["storage"]["2"]["ps"], 0.0000000; atol = 1e-3) @test isapprox(result["solution"]["nw"]["4"]["storage"]["2"]["qs"], 0.0802049; atol = 1e-3) diff --git a/test/opf.jl b/test/opf.jl index 23c9aa4d..48f59f1d 100644 --- a/test/opf.jl +++ b/test/opf.jl @@ -748,7 +748,7 @@ end result = run_opf_bf("../test/data/matpower/case3.m", BFAPowerModel, ipopt_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 5658.22; atol = 1e0) + @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus transformer swap case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m")