Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates for transmission interface #1087

Merged
merged 9 commits into from
Apr 27, 2024
22 changes: 12 additions & 10 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ function build_impl!(
ArgumentConstructStage(),
get_service_models(template),
get_device_models(template),
transmission_model,
)
end

Expand All @@ -588,16 +589,6 @@ function build_impl!(
end
end

TimerOutputs.@timeit BUILD_PROBLEMS_TIMER "Services" begin
construct_services!(
container,
sys,
ModelConstructStage(),
get_service_models(template),
get_device_models(template),
)
end

for device_model in values(template.devices)
@debug "Building Model for $(get_component_type(device_model)) with $(get_formulation(device_model)) formulation" _group =
LOG_GROUP_OPTIMIZATION_CONTAINER
Expand Down Expand Up @@ -643,6 +634,17 @@ function build_impl!(
end
end

TimerOutputs.@timeit BUILD_PROBLEMS_TIMER "Services" begin
construct_services!(
container,
sys,
ModelConstructStage(),
get_service_models(template),
get_device_models(template),
transmission_model,
)
end

TimerOutputs.@timeit BUILD_PROBLEMS_TIMER "Objective" begin
@debug "Building Objective" _group = LOG_GROUP_OPTIMIZATION_CONTAINER
update_objective_function!(container)
Expand Down
22 changes: 22 additions & 0 deletions src/services_models/services_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function construct_services!(
stage::ArgumentConstructStage,
services_template::ServicesModelContainer,
devices_template::DevicesModelContainer,
network_model::NetworkModel{<:PM.AbstractPowerModel},
)
isempty(services_template) && return
incompatible_device_types = get_incompatible_devices(devices_template)
Expand All @@ -37,6 +38,7 @@ function construct_services!(
service_model,
devices_template,
incompatible_device_types,
network_model,
)
end
groupservice === nothing || construct_service!(
Expand All @@ -46,6 +48,7 @@ function construct_services!(
services_template[groupservice],
devices_template,
incompatible_device_types,
network_model,
)
return
end
Expand All @@ -56,6 +59,7 @@ function construct_services!(
stage::ModelConstructStage,
services_template::ServicesModelContainer,
devices_template::DevicesModelContainer,
network_model::NetworkModel{<:PM.AbstractPowerModel},
)
isempty(services_template) && return
incompatible_device_types = get_incompatible_devices(devices_template)
Expand All @@ -74,6 +78,7 @@ function construct_services!(
service_model,
devices_template,
incompatible_device_types,
network_model,
)
end
groupservice === nothing || construct_service!(
Expand All @@ -83,6 +88,7 @@ function construct_services!(
services_template[groupservice],
devices_template,
incompatible_device_types,
network_model,
)
return
end
Expand All @@ -94,6 +100,7 @@ function construct_service!(
model::ServiceModel{SR, RangeReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -119,6 +126,7 @@ function construct_service!(
model::ServiceModel{SR, RangeReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand Down Expand Up @@ -148,6 +156,7 @@ function construct_service!(
model::ServiceModel{SR, RangeReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.StaticReserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -172,6 +181,7 @@ function construct_service!(
model::ServiceModel{SR, RangeReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.StaticReserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand Down Expand Up @@ -200,6 +210,7 @@ function construct_service!(
model::ServiceModel{SR, StepwiseCostReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -224,6 +235,7 @@ function construct_service!(
model::ServiceModel{SR, StepwiseCostReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -246,6 +258,7 @@ function construct_service!(
model::ServiceModel{S, T},
devices_template::Dict{Symbol, DeviceModel},
::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {S <: PSY.AGC, T <: AbstractAGCFormulation}
services = get_available_components(S, sys)
agc_areas = PSY.get_area.(services)
Expand Down Expand Up @@ -299,6 +312,7 @@ function construct_service!(
model::ServiceModel{S, T},
devices_template::Dict{Symbol, DeviceModel},
::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {S <: PSY.AGC, T <: AbstractAGCFormulation}
areas = PSY.get_components(PSY.Area, sys)
services = get_available_components(S, sys)
Expand Down Expand Up @@ -340,6 +354,7 @@ function construct_service!(
model::ServiceModel{SR, GroupReserve},
::Dict{Symbol, DeviceModel},
::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.StaticReserveGroup}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -357,6 +372,7 @@ function construct_service!(
model::ServiceModel{SR, GroupReserve},
::Dict{Symbol, DeviceModel},
::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.StaticReserveGroup}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -381,6 +397,7 @@ function construct_service!(
model::ServiceModel{SR, RampReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -406,6 +423,7 @@ function construct_service!(
model::ServiceModel{SR, RampReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.Reserve}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand Down Expand Up @@ -436,6 +454,7 @@ function construct_service!(
model::ServiceModel{SR, NonSpinningReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.ReserveNonSpinning}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand All @@ -460,6 +479,7 @@ function construct_service!(
model::ServiceModel{SR, NonSpinningReserve},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
::NetworkModel{<:PM.AbstractPowerModel},
) where {SR <: PSY.ReserveNonSpinning}
name = get_service_name(model)
service = PSY.get_component(SR, sys, name)
Expand Down Expand Up @@ -497,6 +517,7 @@ function construct_service!(
model::ServiceModel{T, ConstantMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{<:PM.AbstractPowerModel},
) where {T <: PSY.TransmissionInterface}
interfaces = get_available_components(T, sys)
if get_use_slacks(model)
Expand Down Expand Up @@ -524,6 +545,7 @@ function construct_service!(
model::ServiceModel{T, ConstantMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{<:PM.AbstractActivePowerModel},
) where {T <: PSY.TransmissionInterface}
name = get_service_name(model)
service = PSY.get_component(T, sys, name)
Expand Down
45 changes: 45 additions & 0 deletions test/test_services_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,48 @@ end

@test found_constraints == 2
end

@testset "Test Transmission Interface" begin
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
interface = TransmissionInterface(;
name = "west_east",
available = true,
active_power_flow_limits = (min = 0.0, max = 400.0),
)
interface_lines = [
get_component(Line, c_sys5_uc, "1"),
get_component(Line, c_sys5_uc, "2"),
get_component(Line, c_sys5_uc, "6"),
]
add_service!(c_sys5_uc, interface, interface_lines)

template = get_thermal_dispatch_template_network(DCPPowerModel)
set_service_model!(
template,
ServiceModel(TransmissionInterface, ConstantMaxInterfaceFlow; use_slacks = true),
)

model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 432, 144, 288, 288, 288, false)

template = get_thermal_dispatch_template_network(PTDFPowerModel)
set_service_model!(
template,
ServiceModel(TransmissionInterface, ConstantMaxInterfaceFlow; use_slacks = true),
)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 312, 0, 288, 288, 168, false)

#= TODO: Fix this test
template = get_thermal_dispatch_template_network(ACPPowerModel; use_slacks = true) where
set_service_model!(
template,
ServiceModel(TransmissionInterface, ConstantMaxInterfaceFlow; use_slacks = true),
)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 312, 0, 288, 288, 168, false)
=#
end
Loading