Skip to content

Commit cef544c

Browse files
authored
Merge pull request #1209 from ymiftah/bugfix/AreaBalance
extend expression for AreaBalance equations
2 parents fdd0699 + 3e48499 commit cef544c

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/devices_models/devices/common/add_to_expression.jl

+24
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,30 @@ function add_to_expression!(
14641464
return
14651465
end
14661466

1467+
function add_to_expression!(
1468+
container::OptimizationContainer,
1469+
::Type{T},
1470+
::Type{U},
1471+
sys::PSY.System,
1472+
::NetworkModel{W},
1473+
) where {
1474+
T <: ActivePowerBalance,
1475+
U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown},
1476+
W <: AreaBalancePowerModel,
1477+
}
1478+
variable = get_variable(container, U(), PSY.Area)
1479+
expression = get_expression(container, T(), PSY.Area)
1480+
@assert_op length(axes(variable, 1)) == length(axes(expression, 1))
1481+
for t in get_time_steps(container), n in axes(expression, 1)
1482+
_add_to_jump_expression!(
1483+
expression[n, t],
1484+
variable[n, t],
1485+
get_variable_multiplier(U(), PSY.Area, W),
1486+
)
1487+
end
1488+
return
1489+
end
1490+
14671491
function add_to_expression!(
14681492
container::OptimizationContainer,
14691493
::Type{T},

test/test_network_constructors.jl

+34
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,40 @@ end
712712
end
713713
end
714714

715+
@testset "2 Areas AreaBalance PowerModel - with slacks" begin
716+
c_sys = build_system(PSITestSystems, "c_sys5_uc")
717+
# Extend the system with two areas
718+
areas = [Area("Area_1", 0, 0, 0), Area("Area_2", 0, 0, 0)]
719+
add_components!(c_sys, areas)
720+
for (i, comp) in enumerate(get_components(ACBus, c_sys))
721+
(i < 3) ? set_area!(comp, areas[1]) : set_area!(comp, areas[2])
722+
end
723+
# Deactivate generators on Area 1: as there is no area interchange defined,
724+
# slacks will be required for feasibility
725+
for gen in get_components(x -> (get_area(get_bus(x)) == areas[1]), Generator, c_sys)
726+
set_available!(gen, false)
727+
end
728+
729+
template = get_thermal_dispatch_template_network(
730+
NetworkModel(AreaBalancePowerModel, use_slacks=true)
731+
)
732+
ps_model = DecisionModel(template, c_sys; optimizer = HiGHS_optimizer)
733+
734+
@test build!(ps_model; output_dir = mktempdir(; cleanup = true)) ==
735+
PSI.ModelBuildStatus.BUILT
736+
@test solve!(ps_model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED
737+
738+
opt_container = PSI.get_optimization_container(ps_model)
739+
copper_plate_constraints =
740+
PSI.get_constraint(opt_container, CopperPlateBalanceConstraint(), PSY.Area)
741+
@test size(copper_plate_constraints) == (2, 24)
742+
743+
results = OptimizationProblemResults(ps_model)
744+
slacks_up = read_variable(results, "SystemBalanceSlackUp__Area")
745+
@test all(slacks_up[!, "Area_1"] .> 0.)
746+
@test all(slacks_up[!, "Area_2"] .≈ 0.)
747+
end
748+
715749
@testset "2 Areas AreaBalance PowerModel" begin
716750
c_sys = PSB.build_system(PSISystems, "two_area_pjm_DA")
717751
transform_single_time_series!(c_sys, Hour(24), Hour(1))

0 commit comments

Comments
 (0)