From 5dc59d1cd1866ec72db8bdd6b441b8bf26423e6d Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Tue, 5 Nov 2024 09:50:47 -0800 Subject: [PATCH] update name of variable to DC send --- src/core/variables.jl | 20 +++-- .../device_constructors/branch_constructor.jl | 15 +--- .../devices/TwoTerminalDC_branches.jl | 50 +++++++++--- .../devices/common/add_to_expression.jl | 78 ++++++++++++++++++- 4 files changed, 133 insertions(+), 30 deletions(-) diff --git a/src/core/variables.jl b/src/core/variables.jl index d181b4aa0..0f1400536 100644 --- a/src/core/variables.jl +++ b/src/core/variables.jl @@ -230,12 +230,6 @@ Docs abbreviation: ``\\nu_c^`` """ struct ConverterCurrentDirection <: VariableType end -""" -Struct to dispatch the creation of DC Converter Binary for Absolute Value Current Variables for DC formulations -Docs abbreviation: `\\nu_c`` -""" -struct ConverterBinaryAbsoluteValueCurrent <: VariableType end - """ Struct to dispatch the creation of Binary Variable for Converter Power Direction Docs abbreviation: ``\\kappa_c^{dc}`` @@ -338,6 +332,20 @@ Docs abbreviation: ``z_c^{\\gamma}`` """ struct InterpolationBinarySquaredBilinearVariableTo <: SparseVariableType end +""" +Struct to dispatch the creation of HVDC Received Flow at From Bus Variables for PWL formulations + +Docs abbreviation: ``x`` +""" +struct HVDCActiveDCPowerSentFromVariable <: VariableType end + +""" +Struct to dispatch the creation of HVDC Received Flow at To Bus Variables for PWL formulations + +Docs abbreviation: ``y`` +""" +struct HVDCActiveDCPowerSentToVariable <: VariableType end + """ Struct to dispatch the creation of bidirectional Active Power Flow Variables diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index ac6c38dbb..617e0237c 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -913,8 +913,8 @@ function construct_device!( ##################### V = HVDCTwoTerminalVSCLoss # Add Power Variable - add_variables!(container, HVDCActivePowerReceivedFromVariable, devices, V()) # p_c^{ac,from} - add_variables!(container, HVDCActivePowerReceivedToVariable, devices, V()) # p_c^{ac,from} + add_variables!(container, HVDCActiveDCPowerSentFromVariable, devices, V()) # p_c^{ac,from} + add_variables!(container, HVDCActiveDCPowerSentToVariable, devices, V()) # p_c^{ac,from} add_variables!(container, ConverterPowerDirection, devices, V()) #κ # Add Voltage Variables: v_dc, v^sq, δ^v, z^v add_variables!(container, DCVoltageFrom, devices, V()) # v_dc^{from} @@ -931,13 +931,6 @@ function construct_device!( add_variables!(container, ConverterCurrentDirection, devices, V()) add_variables!(container, HVDCLosses, devices, V()) - add_variables!( - container, - ConverterBinaryAbsoluteValueCurrent, - devices, - V(), - ) # ν - # Add Bilinear Variables: γ, γ^{sq} add_variables!( container, @@ -973,7 +966,7 @@ function construct_device!( add_to_expression!( container, ActivePowerBalance, - HVDCActivePowerReceivedFromVariable, + HVDCActiveDCPowerSentFromVariable, devices, model, network_model, @@ -982,7 +975,7 @@ function construct_device!( add_to_expression!( container, ActivePowerBalance, - HVDCActivePowerReceivedToVariable, + HVDCActiveDCPowerSentToVariable, devices, model, network_model, diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 366659194..3bda3b18d 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -18,7 +18,28 @@ get_variable_binary( ) = true get_variable_binary( - _, + ::Union{ + HVDCActiveDCPowerSentFromVariable, + HVDCActiveDCPowerSentToVariable, + DCVoltageFrom, + DCVoltageTo, + SquaredDCVoltageFrom, + SquaredDCVoltageTo, + ConverterCurrent, + SquaredConverterCurrent, + ConverterPositiveCurrent, + ConverterNegativeCurrent, + HVDCLosses, + AuxBilinearConverterVariableFrom, + AuxBilinearSquaredConverterVariableFrom, + AuxBilinearConverterVariableTo, + AuxBilinearSquaredConverterVariableTo, + InterpolationSquaredVoltageVariableFrom, + InterpolationSquaredVoltageVariableTo, + InterpolationSquaredCurrentVariable, + InterpolationSquaredBilinearVariableFrom, + InterpolationSquaredBilinearVariableTo, + }, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, ::HVDCTwoTerminalVSCLoss, ) = false @@ -32,6 +53,11 @@ get_variable_binary( ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, ::HVDCTwoTerminalVSCLoss, ) = true +get_variable_binary( + ::InterpolationBinarySquaredCurrentVariable, + ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, + ::HVDCTwoTerminalVSCLoss, +) = true get_variable_binary( ::InterpolationBinarySquaredBilinearVariableFrom, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, @@ -149,25 +175,25 @@ get_variable_lower_bound( ) = PSY.get_active_power_limits_to(d).min get_variable_upper_bound( - ::HVDCActivePowerReceivedFromVariable, + ::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable}, d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine}, ::AbstractTwoTerminalDCLineFormulation, ) = PSY.get_active_power_limits_from(d).max get_variable_lower_bound( - ::HVDCActivePowerReceivedFromVariable, + ::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable}, d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine}, ::AbstractTwoTerminalDCLineFormulation, ) = PSY.get_active_power_limits_from(d).min get_variable_upper_bound( - ::HVDCActivePowerReceivedToVariable, + ::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable}, d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine}, ::AbstractTwoTerminalDCLineFormulation, ) = PSY.get_active_power_limits_to(d).max get_variable_lower_bound( - ::HVDCActivePowerReceivedToVariable, + ::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable}, d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine}, ::AbstractTwoTerminalDCLineFormulation, ) = PSY.get_active_power_limits_to(d).min @@ -613,6 +639,8 @@ function _add_hvdc_flow_constraints!( FlowActivePowerToFromVariable, HVDCActivePowerReceivedFromVariable, HVDCActivePowerReceivedToVariable, + HVDCActiveDCPowerSentFromVariable, + HVDCActiveDCPowerSentToVariable, }, constraint::Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom}, ) where {T <: PSY.TwoTerminalHVDCLine} @@ -896,8 +924,8 @@ function add_constraints!( time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] # power vars # - from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U) - to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U) + from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U) + to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U) # voltage vars # from_voltage_var = get_variable(container, DCVoltageFrom(), U) to_voltage_var = get_variable(container, DCVoltageTo(), U) @@ -994,8 +1022,8 @@ function add_constraints!( names = [PSY.get_name(d) for d in devices] JuMPmodel = get_jump_model(container) # power vars # - from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U) - to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U) + from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U) + to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U) # current vars # current_var = get_variable(container, ConverterCurrent(), U) # From direction direction_var = get_variable(container, ConverterPowerDirection(), U) @@ -1099,8 +1127,8 @@ function add_constraints!( names = [PSY.get_name(d) for d in devices] JuMPmodel = get_jump_model(container) # power vars # - from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U) - to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U) + from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U) + to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U) # current vars # current_var = get_variable(container, ConverterCurrent(), U) # From direction # voltage vars # diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 16c1e23ba..d6ad6f3db 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -393,7 +393,7 @@ function add_to_expression!( T <: ActivePowerBalance, U <: HVDCActivePowerReceivedFromVariable, V <: TwoTerminalHVDCTypes, - W <: Union{HVDCTwoTerminalPiecewiseLoss, HVDCTwoTerminalVSCLoss}, + W <: HVDCTwoTerminalPiecewiseLoss, X <: AbstractPTDFModel, } var = get_variable(container, U(), V) @@ -430,7 +430,7 @@ function add_to_expression!( T <: ActivePowerBalance, U <: HVDCActivePowerReceivedToVariable, V <: TwoTerminalHVDCTypes, - W <: Union{HVDCTwoTerminalPiecewiseLoss, HVDCTwoTerminalVSCLoss}, + W <: HVDCTwoTerminalPiecewiseLoss, X <: AbstractPTDFModel, } var = get_variable(container, U(), V) @@ -453,6 +453,80 @@ function add_to_expression!( return end +""" +PWL implementation to add FromTo branch variables to SystemBalanceExpressions +""" +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 <: HVDCActiveDCPowerSentFromVariable, + 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) + 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) + flow_variable = var[PSY.get_name(d), t] + _add_to_jump_expression!(nodal_expr[bus_no_from, t], flow_variable, -1.0) + if ref_bus_from != ref_bus_to + _add_to_jump_expression!(sys_expr[ref_bus_from, t], flow_variable, -1.0) + end + end + end + return +end + +""" +PWL implementation to add FromTo branch variables to SystemBalanceExpressions +""" +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 <: HVDCActiveDCPowerSentToVariable, + 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_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) + flow_variable = var[PSY.get_name(d), t] + _add_to_jump_expression!(nodal_expr[bus_no_to, t], flow_variable, -1.0) + if ref_bus_from != ref_bus_to + _add_to_jump_expression!(sys_expr[ref_bus_to, t], flow_variable, -1.0) + end + end + end + return +end + """ Default implementation to add branch variables to SystemBalanceExpressions """