Skip to content

Commit

Permalink
fix branch map for interchange
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Jun 13, 2024
1 parent 3450a2b commit 3f67db8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,17 @@ function construct_device!(
end

function _get_branch_map(
modeled_branch_types::Vector{DataType},
network_model::NetworkModel{AreaPTDFPowerModel},
sys::PSY.System,
)
@assert !isempty(network_model.modeled_branch_types)
inter_area_branch_map =
Dict{Tuple{PSY.Area, PSY.Area}, Dict{DataType, Vector{<:PSY.ACBranch}}}()
for branch_type in modeled_branch_types
for d in get_available_components(branch_type, sys)
for branch_type in network_model.modeled_branch_types
if branch_type == PSY.AreaInterchange
continue
end
for d in get_available_components(network_model, branch_type, sys)
area_from = PSY.get_area(PSY.get_arc(d).from)
area_to = PSY.get_area(PSY.get_arc(d).to)
if area_from != area_to
Expand Down Expand Up @@ -969,7 +973,7 @@ function construct_device!(
# Not ideal to do this here, but it is a not terrible workaround
# The area interchanges are like a services/device mix.
# Doesn't include the possibility of Multi-terminal HVDC
inter_area_branch_map = _get_branch_map(network_model.modeled_branch_types, sys)
inter_area_branch_map = _get_branch_map(network_model, sys)

add_constraints!(
container,
Expand Down Expand Up @@ -999,7 +1003,7 @@ function construct_device!(
model::DeviceModel{PSY.AreaInterchange, StaticBranchUnbounded},
network_model::NetworkModel{AreaPTDFPowerModel},
)
inter_area_branch_map = _get_branch_map(network_model.modeled_branch_types, sys)
inter_area_branch_map = _get_branch_map(network_model, sys)
# Not ideal to do this here, but it is a not terrible workaround
# The area interchanges are like a services/device mix.
# Doesn't include the possibility of Multi-terminal HVDC
Expand Down
6 changes: 5 additions & 1 deletion src/devices_models/devices/area_interchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ function add_constraints!(
devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange},
model::DeviceModel{PSY.AreaInterchange, <:AbstractBranchFormulation},
network_model::NetworkModel{AreaPTDFPowerModel},
inter_area_branch_map,
inter_area_branch_map::Dict{
Tuple{PSY.Area, PSY.Area},
Dict{DataType, Vector{<:PSY.ACBranch}},
},
)
@assert !isempty(inter_area_branch_map)
time_steps = get_time_steps(container)
device_names = [PSY.get_name(d) for d in devices]

Expand Down
4 changes: 2 additions & 2 deletions src/operation/problem_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ end
function _add_modeled_lines!(template::ProblemTemplate, sys::PSY.System)
network_model = get_network_model(template)
branch_models = get_branch_models(template)
for k in keys(branch_models)
push!(network_model.modeled_branch_types)
for v in values(branch_models)
push!(network_model.modeled_branch_types, get_component_type(v))
end
return
end
Expand Down

0 comments on commit 3f67db8

Please sign in to comment.