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

Jd/hvdc losses bugfix #1010

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1339,25 +1339,6 @@ function get_expression(
return get_expression(container, ExpressionKey(T, U, meta))
end

# Special getter functions to handle system balance expressions
function get_expression(
container::OptimizationContainer,
::T,
::Type{U},
meta = CONTAINER_KEY_EMPTY_META,
) where {T <: SystemBalanceExpressions, U <: PM.AbstractPowerModel}
return get_expression(container, ExpressionKey(T, PSY.ACBus, meta))
end

function get_expression(
container::OptimizationContainer,
::T,
::Type{CopperPlatePowerModel},
meta = CONTAINER_KEY_EMPTY_META,
) where {T <: SystemBalanceExpressions}
return get_expression(container, ExpressionKey(T, PSY.System, meta))
end

function read_expressions(container::OptimizationContainer)
return Dict(
k => to_dataframe(jump_value.(v), k) for (k, v) in get_expressions(container) if
Expand Down
16 changes: 16 additions & 0 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,22 @@ function construct_device!(
return
end

function construct_device!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::DeviceModel{T, HVDCTwoTerminalDispatch},
network_model::NetworkModel{CopperPlatePowerModel},
) where {T <: TwoTerminalHVDCTypes}
devices =
get_available_components(T, sys, get_attribute(model, "filter_function"))
@warn "CopperPlatePowerModel models with HVDC ignores inter-area losses"
add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model)
add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model)
add_constraint_dual!(container, sys, model)
return
end

function construct_device!(
container::OptimizationContainer,
sys::PSY.System,
Expand Down
2 changes: 1 addition & 1 deletion src/devices_models/devices/AC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function add_constraints!(
time_steps,
)
nodal_balance_expressions =
get_expression(container, ActivePowerBalance(), StandardPTDFModel)
get_expression(container, ActivePowerBalance(), PSY.ACBus)

flow_variables = get_variable(container, FlowActivePowerVariable(), B)
jump_model = get_jump_model(container)
Expand Down
114 changes: 59 additions & 55 deletions src/devices_models/devices/TwoTerminalDC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,58 +188,56 @@ function add_constraints!(
return
end

function add_constraints!(
function _add_hvdc_flow_constraints!(
container::OptimizationContainer,
::Type{FlowRateConstraint},
devices::IS.FlattenIteratorWrapper{T},
model::DeviceModel{T, HVDCTwoTerminalLossless},
network_model::NetworkModel{CopperPlatePowerModel},
devices::Union{Vector{T}, IS.FlattenIteratorWrapper{T}},
constraint::FlowRateConstraintFromTo,
) where {T <: PSY.TwoTerminalHVDCLine}
inter_network_branches = T[]
for d in devices
ref_bus_from = get_reference_bus(network_model, PSY.get_arc(d).from)
ref_bus_to = get_reference_bus(network_model, PSY.get_arc(d).to)
if ref_bus_from != ref_bus_to
push!(inter_network_branches, d)
end
end
if !isempty(inter_network_branches)
add_constraints!(
container,
FlowRateConstraint,
inter_network_branches,
model,
network_model,
)
end
return
_add_hvdc_flow_constraints!(
container,
devices,
FlowActivePowerFromToVariable(),
constraint,
)
end

function add_constraints!(
function _add_hvdc_flow_constraints!(
container::OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
::DeviceModel{U, HVDCTwoTerminalDispatch},
::NetworkModel{<:PM.AbstractDCPModel},
) where {T <: FlowRateConstraintFromTo, U <: PSY.TwoTerminalHVDCLine}
devices::Union{Vector{T}, IS.FlattenIteratorWrapper{T}},
constraint::FlowRateConstraintToFrom,
) where {T <: PSY.TwoTerminalHVDCLine}
_add_hvdc_flow_constraints!(
container,
devices,
FlowActivePowerToFromVariable(),
constraint,
)
end

function _add_hvdc_flow_constraints!(
container::OptimizationContainer,
devices::Union{Vector{T}, IS.FlattenIteratorWrapper{T}},
var::Union{FlowActivePowerFromToVariable, FlowActivePowerToFromVariable},
constraint::Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom},
) where {T <: PSY.TwoTerminalHVDCLine}
time_steps = get_time_steps(container)
names = [PSY.get_name(d) for d in devices]

var = get_variable(container, FlowActivePowerFromToVariable(), U)
variable = get_variable(container, var, T)
constraint_ub =
add_constraints_container!(container, T(), U, names, time_steps; meta = "ub")
add_constraints_container!(container, constraint, T, names, time_steps; meta = "ub")
constraint_lb =
add_constraints_container!(container, T(), U, names, time_steps; meta = "lb")
add_constraints_container!(container, constraint, T, names, time_steps; meta = "lb")
for d in devices
min_rate, max_rate = PSY.get_active_power_limits_from(d)
for t in time_steps
constraint_ub[PSY.get_name(d), t] = JuMP.@constraint(
get_jump_model(container),
var[PSY.get_name(d), t] <= max_rate
variable[PSY.get_name(d), t] <= max_rate
)
constraint_lb[PSY.get_name(d), t] = JuMP.@constraint(
get_jump_model(container),
min_rate <= var[PSY.get_name(d), t]
min_rate <= variable[PSY.get_name(d), t]
)
end
end
Expand All @@ -250,33 +248,39 @@ function add_constraints!(
container::OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
::DeviceModel{U, HVDCTwoTerminalDispatch},
::NetworkModel{<:PM.AbstractDCPModel},
) where {T <: FlowRateConstraintToFrom, U <: PSY.TwoTerminalHVDCLine}
time_steps = get_time_steps(container)
names = [PSY.get_name(d) for d in devices]

var = get_variable(container, FlowActivePowerToFromVariable(), U)
constraint_ub =
add_constraints_container!(container, T(), U, names, time_steps; meta = "ub")
constraint_lb =
add_constraints_container!(container, T(), U, names, time_steps; meta = "lb")
model::DeviceModel{U, HVDCTwoTerminalDispatch},
network_model::NetworkModel{CopperPlatePowerModel},
) where {
T <: Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom},
U <: PSY.TwoTerminalHVDCLine,
}
inter_network_branches = U[]
for d in devices
min_rate, max_rate = PSY.get_active_power_limits_to(d)
for t in time_steps
constraint_ub[PSY.get_name(d), t] = JuMP.@constraint(
get_jump_model(container),
var[PSY.get_name(d), t] <= max_rate
)
constraint_lb[PSY.get_name(d), t] = JuMP.@constraint(
get_jump_model(container),
min_rate <= var[PSY.get_name(d), t]
)
ref_bus_from = get_reference_bus(network_model, PSY.get_arc(d).from)
ref_bus_to = get_reference_bus(network_model, PSY.get_arc(d).to)
if ref_bus_from != ref_bus_to
push!(inter_network_branches, d)
end
end
if !isempty(inter_network_branches)
_add_hvdc_flow_constraints!(container, devices, T())
end
return
end

function add_constraints!(
container::OptimizationContainer,
::Type{T},
devices::IS.FlattenIteratorWrapper{U},
::DeviceModel{U, HVDCTwoTerminalDispatch},
::NetworkModel{<:PM.AbstractDCPModel},
) where {T <: Union{FlowRateConstraintToFrom, FlowRateConstraintFromTo},
U <: PSY.TwoTerminalHVDCLine}
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
_add_hvdc_flow_constraints!(container, devices, T())
return
end


jd-lara marked this conversation as resolved.
Show resolved Hide resolved
function add_constraints!(
container::OptimizationContainer,
::Type{T},
Expand Down
Loading