From fdd267d1eed54654916a11854d39ee7db27c3ac1 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Mon, 28 Oct 2024 17:22:32 -0700 Subject: [PATCH] add pwl variables --- src/core/variables.jl | 24 +++--- .../devices/TwoTerminalDC_branches.jl | 84 +++++++++++++++---- 2 files changed, 81 insertions(+), 27 deletions(-) diff --git a/src/core/variables.jl b/src/core/variables.jl index 413020aa8..6d215c754 100644 --- a/src/core/variables.jl +++ b/src/core/variables.jl @@ -1,3 +1,5 @@ +abstract type SparseVariableType <: VariableType end + """ Struct to dispatch the creation of Active Power Variables @@ -265,70 +267,70 @@ Struct to dispatch the creation of Continuous Interpolation Variable for Squared Docs abbreviation: ``\\delta_c^{v,from}`` """ -struct InterpolationSquaredVoltageVariableFrom <: VariableType end +struct InterpolationSquaredVoltageVariableFrom <: SparseVariableType end """ Struct to dispatch the creation of Continuous Interpolation Variable for Squared Converter Voltage Docs abbreviation: ``\\delta_c^{v,to}`` """ -struct InterpolationSquaredVoltageVariableTo <: VariableType end +struct InterpolationSquaredVoltageVariableTo <: SparseVariableType end """ Struct to dispatch the creation of Binary Interpolation Variable for Squared Converter Voltage Docs abbreviation: ``z_c^{v,from}`` """ -struct InterpolationBinarySquaredVoltageVariableFrom <: VariableType end +struct InterpolationBinarySquaredVoltageVariableFrom <: SparseVariableType end """ Struct to dispatch the creation of Binary Interpolation Variable for Squared Converter Voltage Docs abbreviation: ``z_c^{v,to}`` """ -struct InterpolationBinarySquaredVoltageVariableTo <: VariableType end +struct InterpolationBinarySquaredVoltageVariableTo <: SparseVariableType end """ Struct to dispatch the creation of Continuous Interpolation Variable for Squared Converter Current Docs abbreviation: ``\\delta_c^{i}`` """ -struct InterpolationSquaredCurrentVariable <: VariableType end +struct InterpolationSquaredCurrentVariable <: SparseVariableType end """ Struct to dispatch the creation of Binary Interpolation Variable for Squared Converter Current Docs abbreviation: ``z_c^{i}`` """ -struct InterpolationBinarySquaredCurrentVariable <: VariableType end +struct InterpolationBinarySquaredCurrentVariable <: SparseVariableType end """ Struct to dispatch the creation of Continuous Interpolation Variable for Squared Converter AuxVar Docs abbreviation: ``\\delta_c^{\\gamma}`` """ -struct InterpolationSquaredBilinearVariableFrom <: VariableType end +struct InterpolationSquaredBilinearVariableFrom <: SparseVariableType end """ Struct to dispatch the creation of Binary Interpolation Variable for Squared Converter AuxVar Docs abbreviation: ``z_c^{\\gamma}`` """ -struct InterpolationBinarySquaredBilinearVariableFrom <: VariableType end +struct InterpolationBinarySquaredBilinearVariableFrom <: SparseVariableType end """ Struct to dispatch the creation of Continuous Interpolation Variable for Squared Converter AuxVar Docs abbreviation: ``\\delta_c^{\\gamma}`` """ -struct InterpolationSquaredBilinearVariableTo <: VariableType end +struct InterpolationSquaredBilinearVariableTo <: SparseVariableType end """ Struct to dispatch the creation of Binary Interpolation Variable for Squared Converter AuxVar Docs abbreviation: ``z_c^{\\gamma}`` """ -struct InterpolationBinarySquaredBilinearVariableTo <: VariableType end +struct InterpolationBinarySquaredBilinearVariableTo <: SparseVariableType end """ Struct to dispatch the creation of bidirectional Active Power Flow Variables @@ -404,8 +406,6 @@ Docs abbreviation: ``y`` """ struct HVDCActivePowerReceivedToVariable <: VariableType end -abstract type SparseVariableType <: VariableType end - """ Struct to dispatch the creation of HVDC Piecewise Loss Variables diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index caa245ff6..09f736beb 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -20,32 +20,32 @@ get_variable_binary( get_variable_binary( _, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = false get_variable_binary( ::InterpolationBinarySquaredVoltageVariableFrom, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = true get_variable_binary( ::InterpolationBinarySquaredVoltageVariableTo, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = true get_variable_binary( ::InterpolationBinarySquaredBilinearVariableFrom, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = true get_variable_binary( ::InterpolationBinarySquaredBilinearVariableTo, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = true get_variable_binary( ::ConverterPowerDirection, ::Type{<:PSY.TwoTerminalHVDCDetailedLine}, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = true get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, _) = @@ -203,25 +203,25 @@ get_variable_lower_bound( get_variable_upper_bound( ::Union{DCVoltageFrom, DCVoltageTo}, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = PSY.get_voltage_limits(d).max get_variable_lower_bound( ::Union{DCVoltageFrom, DCVoltageTo}, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = PSY.get_voltage_limits(d).min get_variable_upper_bound( ::Union{SquaredDCVoltageFrom, SquaredDCVoltageTo}, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = PSY.get_voltage_limits(d).max^2 get_variable_lower_bound( ::Union{SquaredDCVoltageFrom, SquaredDCVoltageTo}, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = 0.0 get_variable_upper_bound( @@ -233,7 +233,7 @@ get_variable_upper_bound( InterpolationSquaredBilinearVariableTo, }, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = 1.0 get_variable_lower_bound( @@ -245,7 +245,7 @@ get_variable_lower_bound( InterpolationSquaredBilinearVariableTo, }, d::PSY.TwoTerminalHVDCDetailedLine, - ::HVDCTwoTerminalPhysicalLoss, + ::HVDCTwoTerminalVSCLoss, ) = 0.0 function get_default_time_series_names( @@ -268,6 +268,60 @@ get_initial_conditions_device_model( ) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractTwoTerminalDCLineFormulation} = DeviceModel(T, U) +#### PWL Variables #### + +function _add_sparse_pwl_interpolation_variables!( + container::OptimizationContainer, + devices, + ::DeviceModel{D, HVDCTwoTerminalVSCLoss}, +) where {D <: PSY.TwoTerminalHVDCDetailedLine} + # TODO: Implement approach for deciding segment length + # Create Variables + time_steps = get_time_steps(container) + formulation = HVDCTwoTerminalVSCLoss() + len_segments = DEFAULT_INTERPOLATION_LENGTH + vars_vector = [ + # Voltage v # + InterpolationSquaredVoltageVariableFrom, + InterpolationSquaredVoltageVariableTo, + InterpolationBinarySquaredVoltageVariableFrom, + InterpolationBinarySquaredVoltageVariableTo, + # Current i # + InterpolationSquaredCurrentVariable, + InterpolationBinarySquaredCurrentVariable, + # Bilinear γ # + InterpolationSquaredBilinearVariableFrom, + InterpolationSquaredBilinearVariableTo, + InterpolationBinarySquaredBilinearVariableFrom, + InterpolationBinarySquaredBilinearVariableTo, + ] + for T in vars_vector + var_container = lazy_container_addition!(container, T(), D) + binary_flag = get_variable_binary(T(), D, formulation) + + for d in devices + name = PSY.get_name(d) + for t in time_steps + pwlvars = Array{JuMP.VariableRef}(undef, len_segments) + for i in 1:len_segments + pwlvars[i] = + var_container[(name, i, t)] = JuMP.@variable( + get_jump_model(container), + base_name = "$(T)_$(name)_{pwl_$(i), $(t)}", + binary = binary_flag + ) + ub = get_variable_upper_bound(T(), d, formulation) + ub !== nothing && JuMP.set_upper_bound(var_container[name, i, t], ub) + + lb = get_variable_lower_bound(T(), d, formulation) + lb !== nothing && JuMP.set_lower_bound(var_container[name, i, t], lb) + end + end + end + end + return +end + ####################################### PWL Constraints ####################################################### function _get_range_segments(::PSY.TwoTerminalHVDCLine, loss::PSY.LinearCurve) @@ -811,7 +865,7 @@ function add_constraints!( ) where { T <: ConverterPowerCalculationConstraint, U <: PSY.TwoTerminalHVDCDetailedLine, - V <: HVDCTwoTerminalPhysicalLoss, + V <: HVDCTwoTerminalVSCLoss, } time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -908,7 +962,7 @@ function add_constraints!( ) where { T <: ConverterDirectionConstraint, U <: PSY.TwoTerminalHVDCDetailedLine, - V <: HVDCTwoTerminalPhysicalLoss, + V <: HVDCTwoTerminalVSCLoss, } time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -1013,7 +1067,7 @@ function add_constraints!( ) where { T <: ConverterMcCormickEnvelopes, U <: PSY.TwoTerminalHVDCDetailedLine, - V <: HVDCTwoTerminalPhysicalLoss, + V <: HVDCTwoTerminalVSCLoss, } time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices]