diff --git a/src/core/definitions.jl b/src/core/definitions.jl index e6bc76347..1376e7d94 100644 --- a/src/core/definitions.jl +++ b/src/core/definitions.jl @@ -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) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index dee32f0e2..6cf32a5c6 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -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) @@ -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 @@ -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) diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 3bda3b18d..e37c81848 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -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 @@ -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 @@ -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 @@ -269,7 +269,7 @@ get_variable_upper_bound( InterpolationSquaredBilinearVariableFrom, InterpolationSquaredBilinearVariableTo, }, - d::PSY.TwoTerminalHVDCDetailedLine, + d::PSY.TwoTerminalVSCLine, ::HVDCTwoTerminalVSCLoss, ) = 1.0 @@ -281,7 +281,7 @@ get_variable_lower_bound( InterpolationSquaredBilinearVariableFrom, InterpolationSquaredBilinearVariableTo, }, - d::PSY.TwoTerminalHVDCDetailedLine, + d::PSY.TwoTerminalVSCLine, ::HVDCTwoTerminalVSCLoss, ) = 0.0 @@ -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, @@ -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) @@ -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) @@ -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) @@ -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) @@ -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}}() @@ -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}}() @@ -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}}() @@ -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) @@ -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) @@ -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) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index d6ad6f3db..fd8ef08b8 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -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 """ diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 8f4cb45cc..e6128448e 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -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), @@ -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,