Skip to content

Commit

Permalink
add losses to power balance
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Nov 6, 2024
1 parent c67f721 commit b92b651
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const JuMPVariableArray = DenseAxisArray{JuMP.VariableRef}
const TwoTerminalHVDCTypes = Union{
PSY.TwoTerminalHVDCLine,
PSY.TwoTerminalVSCDCLine,
PSY.TwoTerminalHVDCDetailedLine,
PSY.TwoTerminalVSCLine,
}
# Settings constants
const UNSET_HORIZON = Dates.Millisecond(0)
Expand Down
12 changes: 10 additions & 2 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ function construct_device!(
container::OptimizationContainer,
sys::PSY.System,
::ArgumentConstructStage,
model::DeviceModel{PSY.TwoTerminalHVDCDetailedLine, HVDCTwoTerminalVSCLoss},
model::DeviceModel{PSY.TwoTerminalVSCLine, HVDCTwoTerminalVSCLoss},
network_model::NetworkModel{<:PM.AbstractActivePowerModel},
)
devices = get_available_components(model, sys)
Expand Down Expand Up @@ -980,6 +980,14 @@ function construct_device!(
model,
network_model,
)
add_to_expression!(
container,
ActivePowerBalance,
HVDCLosses,
devices,
model,
network_model,
)
# TODO: Add losses to balance expression to get full AC
add_feedforward_arguments!(container, model, devices)
return
Expand All @@ -989,7 +997,7 @@ function construct_device!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::DeviceModel{PSY.TwoTerminalHVDCDetailedLine, HVDCTwoTerminalVSCLoss},
model::DeviceModel{PSY.TwoTerminalVSCLine, HVDCTwoTerminalVSCLoss},
network_model::NetworkModel{<:PM.AbstractActivePowerModel},
)
devices = get_available_components(model, sys)
Expand Down
60 changes: 30 additions & 30 deletions src/devices_models/devices/TwoTerminalDC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,42 @@ get_variable_binary(
InterpolationSquaredBilinearVariableFrom,
InterpolationSquaredBilinearVariableTo,
},
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = false
get_variable_binary(
::InterpolationBinarySquaredVoltageVariableFrom,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredVoltageVariableTo,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredCurrentVariable,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredBilinearVariableFrom,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredBilinearVariableTo,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::ConverterPowerDirection,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::ConverterCurrentDirection,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::Type{<:PSY.TwoTerminalVSCLine},
::HVDCTwoTerminalVSCLoss,
) = true

Expand Down Expand Up @@ -176,25 +176,25 @@ get_variable_lower_bound(

get_variable_upper_bound(
::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_from(d).max

get_variable_lower_bound(
::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_from(d).min

get_variable_upper_bound(
::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_to(d).max

get_variable_lower_bound(
::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_to(d).min

Expand Down Expand Up @@ -233,31 +233,31 @@ get_variable_lower_bound(
### Two Terminal Physical Loss ###
get_variable_upper_bound(
::Union{DCVoltageFrom, DCVoltageTo},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = PSY.get_voltage_limits(d).max

get_variable_lower_bound(
::Union{DCVoltageFrom, DCVoltageTo},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = PSY.get_voltage_limits(d).min

get_variable_upper_bound(
::Union{SquaredDCVoltageFrom, SquaredDCVoltageTo},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = PSY.get_voltage_limits(d).max^2

get_variable_lower_bound(
::Union{SquaredDCVoltageFrom, SquaredDCVoltageTo},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = 0.0

get_variable_lower_bound(
::Union{ConverterPositiveCurrent, ConverterNegativeCurrent},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = 0.0

Expand All @@ -269,7 +269,7 @@ get_variable_upper_bound(
InterpolationSquaredBilinearVariableFrom,
InterpolationSquaredBilinearVariableTo,
},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = 1.0

Expand All @@ -281,7 +281,7 @@ get_variable_lower_bound(
InterpolationSquaredBilinearVariableFrom,
InterpolationSquaredBilinearVariableTo,
},
d::PSY.TwoTerminalHVDCDetailedLine,
d::PSY.TwoTerminalVSCLine,
::HVDCTwoTerminalVSCLoss,
) = 0.0

Expand All @@ -302,7 +302,7 @@ end
function get_default_attributes(
::Type{U},
::Type{V},
) where {U <: PSY.TwoTerminalHVDCDetailedLine, V <: HVDCTwoTerminalVSCLoss}
) where {U <: PSY.TwoTerminalVSCLine, V <: HVDCTwoTerminalVSCLoss}
return Dict{String, Any}(
"voltage_segments" => 3,
"current_segments" => 6,
Expand All @@ -322,7 +322,7 @@ function _add_sparse_pwl_interpolation_variables!(
container::OptimizationContainer,
devices,
model::DeviceModel{D, HVDCTwoTerminalVSCLoss},
) where {D <: PSY.TwoTerminalHVDCDetailedLine}
) where {D <: PSY.TwoTerminalVSCLine}
# TODO: Implement approach for deciding segment length
# Create Variables
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -918,7 +918,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: ConverterPowerCalculationConstraint,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: ConverterDirectionConstraint,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: ConverterMcCormickEnvelopes,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: InterpolationVoltageConstraints,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
dic_var_bkpts = Dict{String, Vector{Float64}}()
Expand Down Expand Up @@ -1428,7 +1428,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: InterpolationCurrentConstraints,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
dic_var_bkpts = Dict{String, Vector{Float64}}()
Expand Down Expand Up @@ -1466,7 +1466,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: InterpolationBilinearConstraints,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
dic_var_bkpts = Dict{String, Vector{Float64}}()
Expand Down Expand Up @@ -1520,7 +1520,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: ConverterCurrentBalanceConstraint,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -1571,7 +1571,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: CurrentAbsoluteValueConstraint,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down Expand Up @@ -1652,7 +1652,7 @@ function add_constraints!(
::NetworkModel{<:AbstractPTDFModel},
) where {
T <: ConverterLossesCalculationConstraint,
U <: PSY.TwoTerminalHVDCDetailedLine,
U <: PSY.TwoTerminalVSCLine,
V <: HVDCTwoTerminalVSCLoss,
}
time_steps = get_time_steps(container)
Expand Down
38 changes: 38 additions & 0 deletions src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,44 @@ function add_to_expression!(
return
end

function add_to_expression!(
container::OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
::DeviceModel{V, W},
network_model::NetworkModel{X},
) where {
T <: ActivePowerBalance,
U <: HVDCLosses,
V <: TwoTerminalHVDCTypes,
W <: HVDCTwoTerminalVSCLoss,
X <: AbstractPTDFModel,
}
var = get_variable(container, U(), V)
nodal_expr = get_expression(container, T(), PSY.ACBus)
sys_expr = get_expression(container, T(), _system_expression_type(X))
radial_network_reduction = get_radial_network_reduction(network_model)
for d in devices
bus_no_from =
PNM.get_mapped_bus_number(radial_network_reduction, PSY.get_arc(d).from)
bus_no_to =
PNM.get_mapped_bus_number(radial_network_reduction, PSY.get_arc(d).to)
ref_bus_to = get_reference_bus(network_model, PSY.get_arc(d).to)
ref_bus_from = get_reference_bus(network_model, PSY.get_arc(d).from)
for t in get_time_steps(container)
losses_variable = var[PSY.get_name(d), t]
_add_to_jump_expression!(nodal_expr[bus_no_from, t], losses_variable, -1.0)
_add_to_jump_expression!(nodal_expr[bus_no_to, t], losses_variable, -1.0)
if ref_bus_from != ref_bus_to
_add_to_jump_expression!(sys_expr[ref_bus_from, t], losses_variable, -1.0)
_add_to_jump_expression!(sys_expr[ref_bus_to, t], losses_variable, -1.0)
end
end
end
return
end

"""
Default implementation to add branch variables to SystemBalanceExpressions
"""
Expand Down
4 changes: 2 additions & 2 deletions test/test_device_branch_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ end

hvdc = first(get_components(TwoTerminalHVDCLine, c_sys5))

hvdc_new = TwoTerminalHVDCDetailedLine(;
hvdc_new = TwoTerminalVSCLine(;
name = get_name(hvdc),
available = get_available(hvdc),
active_power_flow = get_active_power_flow(hvdc),
Expand All @@ -772,7 +772,7 @@ end

template = get_thermal_dispatch_template_network(NetworkModel(PTDFPowerModel))
dev_model = DeviceModel(
TwoTerminalHVDCDetailedLine,
TwoTerminalVSCLine,
PSI.HVDCTwoTerminalVSCLoss;
attributes = Dict{String, Any}(
"voltage_segments" => 10,
Expand Down

0 comments on commit b92b651

Please sign in to comment.