Skip to content

Commit

Permalink
FIX: implementation of polynomial nl costs above quadratic (#431)
Browse files Browse the repository at this point in the history
* FIX: implementation of polynomial nl costs above quadratic

* ADD: polynomial nl cost unit test.
  • Loading branch information
juanjospina authored May 6, 2023
1 parent a181da5 commit e5e7e3f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add native power flow solver by using `compute_mc_pf(data_math)`
- Fixed bug in `build_mc_pf` where `constraint_mc_storage_power_setpoint_real` was being applied to all storage objects, and not just ones on PV buses
- Fixed implementation of polynomial nonlinear (nl) costs above quadratic in `objective.jl`

## v0.14.8

Expand Down
4 changes: 2 additions & 2 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function _objective_mc_min_fuel_cost_polynomial_nl(pm::AbstractUnbalancedPowerMo
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2)
elseif length(cost_rev) >= 4
cost_rev_nl = cost_rev[4:end]
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+3) for (d,v) in enumerate(cost_rev_nl)) )
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) )
else
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0)
end
Expand Down Expand Up @@ -414,7 +414,7 @@ function _objective_mc_min_fuel_cost_polynomial_nl_switch(pm::AbstractUnbalanced
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2)
elseif length(cost_rev) >= 4
cost_rev_nl = cost_rev[4:end]
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+3) for (d,v) in enumerate(cost_rev_nl)) )
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) )
else
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0)
end
Expand Down
30 changes: 30 additions & 0 deletions test/opf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,36 @@
@test result["termination_status"] == LOCALLY_SOLVED
end

@testset "3-bus unbalanced test w/ gen nl costs above quadratic" begin
data = transform_data_model(case3_unbalanced)

#add a single-phase generator and assign a single-phase start value to it
data["gen"]["2"] = Dict{String, Any}(
"pg_start" => [-0.012],
"qg_start" => [-0.006],
"model" => 2,
"connections" => [2],
"shutdown" => 0.0,
"startup" => 0.0,
"configuration" => WYE,
"name" => "single_ph_generator",
"gen_bus" => 3,
"pmax" => [Inf],
"vbase" => 0.23094,
"index" => 2,
"cost" => [0.2, 0.5, 1.1, 1.4, 1.0],
"gen_status" => 1,
"qmax" => [Inf],
"qmin" => [-Inf],
"pmin" => [-Inf],
"ncost" => 5
)
result = solve_mc_opf(data, ACPUPowerModel, ipopt_solver)

@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 0.9666; atol = 1e-4)
end

@testset "3-bus unbalanced fotp opf with yy transformer" begin
result = solve_mc_opf(ut_trans_2w_yy, FOTPUPowerModel, ipopt_solver)

Expand Down

0 comments on commit e5e7e3f

Please sign in to comment.