From 13996a3bbf6b265c5a35e618bff206c75a58f188 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 13:55:24 -0700 Subject: [PATCH 01/73] many renames --- src/core/optimization_container.jl | 12 +++---- .../device_constructors/branch_constructor.jl | 22 ++++++------ src/devices_models/devices/AC_branches.jl | 4 +-- src/devices_models/devices/DC_branches.jl | 4 +-- .../devices/common/add_constraint_dual.jl | 4 +-- .../devices/common/add_to_expression.jl | 36 +++++++++---------- src/network_models/area_balance_model.jl | 2 +- src/network_models/network_constructor.jl | 10 +++--- src/network_models/network_slack_variables.jl | 30 ++++++++-------- src/network_models/pm_translator.jl | 28 +++++++-------- src/network_models/powermodels_interface.jl | 30 ++++++++-------- src/operation/operation_model_interface.jl | 2 +- src/operation/operation_problem_templates.jl | 2 +- src/utils/powersystems_utils.jl | 4 +-- test/test_network_constructors.jl | 14 ++++---- 15 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 23a7a8daaf..efe7647ac1 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -396,9 +396,9 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), - ExpressionKey(ReactivePowerBalance, PSY.Bus) => + ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -411,7 +411,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -439,7 +439,7 @@ function _make_system_expressions!( container.expressions = Dict( ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(time_steps), - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -450,7 +450,7 @@ function initialize_system_expressions!( ::Type{T}, system::PSY.System, ) where {T <: PM.AbstractPowerModel} - bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.Bus, system)]) + bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)]) _make_system_expressions!(container, bus_numbers, T) return end @@ -1226,7 +1226,7 @@ function get_expression( ::Type{U}, meta=CONTAINER_KEY_EMPTY_META, ) where {T <: SystemBalanceExpressions, U <: PM.AbstractPowerModel} - return get_expression(container, ExpressionKey(T, PSY.Bus, meta)) + return get_expression(container, ExpressionKey(T, PSY.ACBus, meta)) end function get_expression( diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 48752fb889..a73f1770d5 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -344,7 +344,7 @@ function construct_device!( model::DeviceModel{B, U}, ::NetworkModel{S}, ) where { - B <: PSY.HVDCLine, + B <: PSY.TwoTerminalHVDCLine, U <: HVDCP2PLossless, S <: Union{StandardPTDFModel, PTDFPowerModel}, } @@ -358,10 +358,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{StandardPTDFModel}, ) - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) add_variables!(container, HVDCLosses, devices, HVDCP2PDispatch()) @@ -397,10 +397,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{StandardPTDFModel}, ) - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, StandardPTDFModel) add_constraints!(container, FlowRateConstraintToFrom, devices, model, StandardPTDFModel) add_constraints!(container, HVDCPowerBalance, devices, model, StandardPTDFModel) @@ -413,10 +413,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) @@ -443,10 +443,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, T) add_constraints!(container, FlowRateConstraintToFrom, devices, model, T) add_constraints!(container, HVDCPowerBalance, devices, model, T) @@ -459,7 +459,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ArgumentConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return @@ -469,7 +469,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ModelConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index c085d9dbb4..e5a2482150 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -304,7 +304,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.Bus) + nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) @@ -499,7 +499,7 @@ function add_constraints!( time_steps = get_time_steps(container) flow_variables = get_variable(container, FlowActivePowerVariable(), T) ps_angle_variables = get_variable(container, PhaseShifterAngle(), T) - bus_angle_variables = get_variable(container, VoltageAngle(), PSY.Bus) + bus_angle_variables = get_variable(container, VoltageAngle(), PSY.ACBus) jump_model = get_jump_model(container) branch_flow = add_constraints_container!( container, diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/DC_branches.jl index 474536866b..fd96866788 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/DC_branches.jl @@ -78,10 +78,10 @@ end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.HVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## -function _get_flow_bounds(d::PSY.HVDCLine) +function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) check_hvdc_line_limits_consistency(d) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min diff --git a/src/devices_models/devices/common/add_constraint_dual.jl b/src/devices_models/devices/common/add_constraint_dual.jl index 89db2d59a8..3a152f92d2 100644 --- a/src/devices_models/devices/common/add_constraint_dual.jl +++ b/src/devices_models/devices/common/add_constraint_dual.jl @@ -18,7 +18,7 @@ function add_constraint_dual!( model::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} if !isempty(get_duals(model)) - devices = PSY.get_components(PSY.Bus, sys) + devices = PSY.get_components(PSY.ACBus, sys) for constraint_type in get_duals(model) assign_dual_variable!(container, constraint_type, devices, T) end @@ -95,7 +95,7 @@ function assign_dual_variable!( constraint_type::Type{<:ConstraintType}, devices::U, ::Type{<:PM.AbstractPowerModel}, -) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.Bus} +) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.ACBus} @assert !isempty(devices) time_steps = get_time_steps(container) add_dual_container!( diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 91586c1763..5b2a45ed38 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -171,7 +171,7 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.HVDCLine, W <: HVDCP2PDispatch} +) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -415,7 +415,7 @@ function add_to_expression!( parameter = get_parameter_array(container, U(), V) multiplier = get_parameter_multiplier_array(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -445,7 +445,7 @@ function add_to_expression!( } parameter = get_parameter_array(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -475,7 +475,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -509,7 +509,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -581,7 +581,7 @@ function add_to_expression!( W <: StandardPTDFModel, } var = get_variable(container, U(), PSY.PhaseShiftingTransformer) - expression = get_expression(container, T(), PSY.Bus) + expression = get_expression(container, T(), PSY.ACBus) for d in devices for t in get_time_steps(container) flow_variable = var[PSY.get_name(d), t] @@ -787,14 +787,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } - variable = get_variable(container, U(), PSY.Bus) - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus) + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -812,14 +812,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "P") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "P") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -837,14 +837,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "Q") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "Q") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return diff --git a/src/network_models/area_balance_model.jl b/src/network_models/area_balance_model.jl index 7c8a8d325c..f9e0057e9e 100644 --- a/src/network_models/area_balance_model.jl +++ b/src/network_models/area_balance_model.jl @@ -1,7 +1,7 @@ function area_balance( container::OptimizationContainer, expression::ExpressionKey, - area_mapping::Dict{String, Array{PSY.Bus, 1}}, + area_mapping::Dict{String, Array{PSY.ACBus, 1}}, branches, ) time_steps = get_time_steps(container) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 7e0f93f1d0..2b16e6aff3 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -56,7 +56,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.Bus), + ExpressionKey(ActivePowerBalance, PSY.ACBus), area_mapping, branches, ) @@ -160,7 +160,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -223,7 +223,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -286,7 +286,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -348,7 +348,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = diff --git a/src/network_models/network_slack_variables.jl b/src/network_models/network_slack_variables.jl index 0da08779f2..424e29bf61 100644 --- a/src/network_models/network_slack_variables.jl +++ b/src/network_models/network_slack_variables.jl @@ -1,6 +1,6 @@ #! format: off -get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = 1.0 -get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = -1.0 +get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = 1.0 +get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = -1.0 #! format: on function add_variables!( @@ -35,8 +35,8 @@ function add_variables!( U <: PM.AbstractActivePowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) - variable = add_variable_container!(container, T(), PSY.Bus, bus_numbers, time_steps) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) + variable = add_variable_container!(container, T(), PSY.ACBus, bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable[n, t] = JuMP.@variable( @@ -58,11 +58,11 @@ function add_variables!( U <: PM.AbstractPowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) variable_active = - add_variable_container!(container, T(), PSY.Bus, "P", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "P", bus_numbers, time_steps) variable_reactive = - add_variable_container!(container, T(), PSY.Bus, "Q", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "Q", bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable_active[n, t] = JuMP.@variable( @@ -99,12 +99,12 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, model::NetworkModel{T}, S::Type{T}, ) where {T <: PM.AbstractActivePowerModel} - variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus) - variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus) + variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus) + variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus) bus_numbers = axes(variable_up)[1] @assert_op bus_numbers == axes(variable_dn)[1] for t in get_time_steps(container), n in bus_numbers @@ -118,14 +118,14 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, model::NetworkModel{T}, S::Type{T}, ) where {T <: PM.AbstractPowerModel} - variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "P") - variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "P") - variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "Q") - variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "Q") + variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "P") + variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "P") + variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "Q") + variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "Q") bus_numbers = axes(variable_p_up)[1] @assert_op bus_numbers == axes(variable_q_dn)[1] for t in get_time_steps(container), n in bus_numbers diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index e664dba207..40c9c903fa 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -2,7 +2,7 @@ const PM_MAP_TUPLE = NamedTuple{(:from_to, :to_from), Tuple{Tuple{Int, Int, Int}, Tuple{Int, Int, Int}}} struct PMmap - bus::Dict{Int, PSY.Bus} + bus::Dict{Int, PSY.ACBus} arcs::Dict{PM_MAP_TUPLE, <:PSY.ACBranch} arcs_dc::Dict{PM_MAP_TUPLE, <:PSY.DCBranch} end @@ -258,7 +258,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, ) @@ -296,7 +296,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractPowerModel}, ) @@ -335,7 +335,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{<:AbstractBranchFormulation}, ::Type{<:PM.AbstractPowerModel}, ) @@ -411,16 +411,16 @@ function get_branches_to_pm( return PM_branches, PMmap_br end -function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.Bus}) +function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.ACBus}) PM_buses = Dict{String, Any}() - PMmap_buses = Dict{Int, PSY.Bus}() + PMmap_buses = Dict{Int, PSY.ACBus}() - pm_bustypes = Dict{PSY.BusTypes, Int}( - PSY.BusTypes.ISOLATED => 4, - PSY.BusTypes.PQ => 1, - PSY.BusTypes.PV => 2, - PSY.BusTypes.REF => 3, - PSY.BusTypes.SLACK => 3, + pm_bustypes = Dict{PSY.ACBusTypes, Int}( + PSY.ACBusTypes.ISOLATED => 4, + PSY.ACBusTypes.PQ => 1, + PSY.ACBusTypes.PV => 2, + PSY.ACBusTypes.REF => 3, + PSY.ACBusTypes.SLACK => 3, ) for bus in buses @@ -441,7 +441,7 @@ function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.Bus}) "name" => PSY.get_name(bus), ) PM_buses["$(number)"] = PM_bus - if PSY.get_bustype(bus) != PSY.BusTypes.ISOLATED::PSY.BusTypes + if PSY.get_bustype(bus) != PSY.ACBusTypes.ISOLATED::PSY.ACBusTypes PMmap_buses[number] = bus end end @@ -462,7 +462,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In template.branches, length(ac_lines), ) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) pm_buses, PMmap_buses = get_buses_to_pm(buses) PM_translation = Dict{String, Any}( "bus" => pm_buses, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 701a460b6b..5e9d2edc36 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -287,13 +287,13 @@ function powermodels_network!( ) where {S <: PM.AbstractPowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = - container.expressions[ExpressionKey(ReactivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, t, ] @@ -315,11 +315,11 @@ function powermodels_network!( ) where {S <: PM.AbstractActivePowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ PSY.get_number(bus), t, ] @@ -338,7 +338,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractDCPModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => (from_to=FlowActivePowerVariable(), to_from=nothing)) pm_variable_map[PSY.DCBranch] = @@ -350,7 +350,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => FlowActivePowerFromToVariable()) pm_variable_map[PSY.DCBranch] = Dict( :p_dc => ( @@ -365,7 +365,7 @@ end function PMvarmap(::Type{PTDFPowerModel}) pm_variable_map = Dict{Type, Dict{Symbol, Union{String, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict() + pm_variable_map[PSY.ACBus] = Dict() pm_variable_map[PSY.ACBranch] = Dict() pm_variable_map[PSY.DCBranch] = Dict() @@ -375,7 +375,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) pm_variable_map[PSY.ACBranch] = Dict( :p => ( from_to=FlowActivePowerFromToVariable(), @@ -400,14 +400,14 @@ end function PMconmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, <:ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) + pm_constraint_map[PSY.ACBus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) return pm_constraint_map end function PMconmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict( + pm_constraint_map[PSY.ACBus] = Dict( :power_balance_p => NodalBalanceActiveConstraint(), :power_balance_q => NodalBalanceReactiveConstraint(), ) @@ -459,10 +459,10 @@ function add_pm_variable_refs!( pm_variable_map = PMvarmap(system_formulation) bus_names = [PSY.get_name(b) for b in values(bus_dict)] - for (pm_v, ps_v) in pm_variable_map[PSY.Bus] + for (pm_v, ps_v) in pm_variable_map[PSY.ACBus] if pm_v in pm_variable_types var_container = - add_variable_container!(container, ps_v, PSY.Bus, bus_names, time_steps) + add_variable_container!(container, ps_v, PSY.ACBus, bus_names, time_steps) for t in time_steps, (pm_bus, bus) in bus_dict name = PSY.get_name(bus) var_container[name, t] = PM.var(container.pm, t, pm_v)[pm_bus] # pm_vars[pm_v][pm_bus] @@ -536,12 +536,12 @@ function add_pm_constraint_refs!( [k for k in keys(PM.con(container.pm, 1)) if !isempty(PM.con(container.pm, 1, k))] pm_constraint_map = PMconmap(system_formulation) - for (pm_v, ps_v) in pm_constraint_map[PSY.Bus] + for (pm_v, ps_v) in pm_constraint_map[PSY.ACBus] if pm_v in pm_constraint_names cons_container = add_constraints_container!( container, ps_v, - PSY.Bus, + PSY.ACBus, [PSY.get_name(b) for b in values(bus_dict)], time_steps, ) diff --git a/src/operation/operation_model_interface.jl b/src/operation/operation_model_interface.jl index 18402fff0d..5e30152d71 100644 --- a/src/operation/operation_model_interface.jl +++ b/src/operation/operation_model_interface.jl @@ -216,7 +216,7 @@ function validate_template(model::OperationModel) modeled_types = get_component_types(template) system = get_system(model) system_component_types = PSY.get_existing_component_types(system) - exclusions = [PSY.Arc, PSY.Area, PSY.Bus, PSY.LoadZone] + exclusions = [PSY.Arc, PSY.Area, PSY.ACBus, PSY.LoadZone] for m in setdiff(modeled_types, system_component_types) @warn "The system data doesn't include components of type $(m), consider changing the models in the template" _group = LOG_GROUP_MODELS_VALIDATION diff --git a/src/operation/operation_problem_templates.jl b/src/operation/operation_problem_templates.jl index 5a60c03c52..ebee30ff2a 100644 --- a/src/operation/operation_problem_templates.jl +++ b/src/operation/operation_problem_templates.jl @@ -15,7 +15,7 @@ function _default_devices_uc() DeviceModel(PSY.Line, StaticBranch), DeviceModel(PSY.Transformer2W, StaticBranch), DeviceModel(PSY.TapTransformer, StaticBranch), - DeviceModel(PSY.HVDCLine, HVDCP2PDispatch), + DeviceModel(PSY.TwoTerminalHVDCLine, HVDCP2PDispatch), ] end diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index 8419408ed0..e0eddda63c 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -16,7 +16,7 @@ end make_system_filename(sys::PSY.System) = "system-$(IS.get_uuid(sys)).json" make_system_filename(sys_uuid::Union{Base.UUID, AbstractString}) = "system-$(sys_uuid).json" -function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) +function check_hvdc_line_limits_consistency(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max @@ -38,7 +38,7 @@ function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) return end -function check_hvdc_line_limits_unidirectional(d::PSY.HVDCLine) +function check_hvdc_line_limits_unidirectional(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index c875f55024..41ee1388e5 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -202,7 +202,7 @@ end constraint_keys = [ PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "ub"), PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "lb"), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [384, 0, 408, 408, 288], @@ -248,8 +248,8 @@ end constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, PSY.Line), PSI.ConstraintKey(RateLimitConstraintToFrom, PSY.Line), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [1056, 0, 384, 384, 264], @@ -291,7 +291,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] objfuncs = [GAEVF, GQEVF, GQEVF] - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_results = Dict{System, Vector{Int}}( c_sys5 => [264, 0, 264, 264, 120], c_sys14 => [600, 0, 600, 600, 336], @@ -336,8 +336,8 @@ end systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Voltages, etc. constraint_keys = [ - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] ACR_test_results = Dict{System, Vector{Int}}( c_sys5 => [1056, 0, 240, 240, 264], @@ -376,7 +376,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Bi-directional flows etc - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_obj_values = IdDict{System, Float64}( c_sys5 => 340000.0, c_sys14 => 142000.0, From d819b96b733e0681499b75ea749cf271cb104315 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:29:52 -0700 Subject: [PATCH 02/73] more rename --- test/test_device_branch_constructors.jl | 62 +++++++++---------- test/test_device_hvdc.jl | 0 .../operations_problem_templates.jl | 4 +- 3 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 test/test_device_hvdc.jl diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index e2a9626a28..eb9c2dee76 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -81,7 +81,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), @@ -90,7 +90,7 @@ end ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -106,7 +106,7 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -120,7 +120,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -144,9 +144,9 @@ end end end -@testset "DC Power Flow Models for Unbounded HVDCLine, and StaticBranchBounds for TapTransformer & Transformer2W" begin +@testset "DC Power Flow Models for Unbounded TwoTerminalHVDCLine , and StaticBranchBounds for TapTransformer & Transformer2W" begin system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -162,13 +162,13 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PUnbounded)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PUnbounded)) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT - @test check_variable_unbounded(model_m, FlowActivePowerVariable, HVDCLine) + @test check_variable_unbounded(model_m, FlowActivePowerVariable, TwoTerminalHVDCLine ) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @@ -177,7 +177,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -208,7 +208,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine( + hvdc = TwoTerminalHVDCLine ( name=get_name(line), available=true, active_power_flow=0.0, @@ -229,7 +229,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model = DecisionModel( template_uc, @@ -242,7 +242,7 @@ end solve!(model; output_dir=mktempdir()) ptdf_vars = get_variable_values(ProblemResults(model)) ptdf_values = - ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] ptdf_objective = model.internal.container.optimizer_stats.objective_value set_network_model!(template_uc, NetworkModel(DCPPowerModel)) @@ -258,7 +258,7 @@ end solve!(model; output_dir=mktempdir()) dcp_vars = get_variable_values(ProblemResults(model)) dcp_values = - dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] dcp_objective = model.internal.container.optimizer_stats.objective_value @test isapprox(dcp_objective, ptdf_objective; atol=0.1) @@ -272,7 +272,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine( + hvdc = TwoTerminalHVDCLine ( name=get_name(line), available=true, active_power_flow=0.0, @@ -297,7 +297,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_ref = DecisionModel( template_uc, @@ -312,7 +312,7 @@ end ref_values = ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, Line}("")] hvdc_ref_values = - ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}( + ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }( "", )] ref_objective = model_ref.internal.container.optimizer_stats.objective_value @@ -328,7 +328,7 @@ end ) ), ) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PDispatch)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PDispatch)) model = DecisionModel( template_uc, @@ -346,13 +346,13 @@ end )] hvdc_ft_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] hvdc_tf_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -400,13 +400,13 @@ end dispatch_vars = get_variable_values(ProblemResults(model_wl)) dispatch_values_ft = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] dispatch_values_tf = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -435,7 +435,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Line, "ub"), @@ -443,8 +443,8 @@ end PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "lb"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -464,7 +464,7 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -479,7 +479,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) @@ -555,14 +555,14 @@ end ) end -@testset "AC Power Flow Models for HVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin +@testset "AC Power Flow Models for TwoTerminalHVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, Transformer2W), PSI.ConstraintKey(RateLimitConstraintToFrom, Transformer2W), PSI.ConstraintKey(RateLimitConstraintFromTo, TapTransformer), PSI.ConstraintKey(RateLimitConstraintToFrom, TapTransformer), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -580,7 +580,7 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -597,7 +597,7 @@ end model_m, FlowActivePowerVariable, FlowReactivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index 6b478b0764..74b32c5b0d 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network=CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network=StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end From 77a0f7bf70b252e0262aec5dd42f57bae6dbbb59 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:30:02 -0700 Subject: [PATCH 03/73] add new formulations --- src/core/formulations.jl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 07cb154896..30c31ea3d8 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -169,7 +169,7 @@ struct MyCustomBranchFormulation <: PSI.AbstractDeviceFormulation # Generic Branch Models abstract type AbstractBranchFormulation <: AbstractDeviceFormulation end -############################### AC Branch Formulations ##################################### +############################### AC/DC Branch Formulations ##################################### """ Branch type to add unbounded flow variables and use flow constraints """ @@ -188,21 +188,33 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractDCLineFormulation end +struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractDCLineFormulation end +struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractDCLineFormulation end +# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end + +############################### AC/DC Converter Formulations ##################################### +abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end + +""" +LossLess InterconnectingConverter Model +""" +struct LossLessConverter <: AbstractConverterFormulation end + +# TODO: Think if this an ok abstraction for future use cases +struct LossLessLine <: AbstractBranchFormulation end + ############################## Network Model Formulations ################################## # These formulations are taken directly from PowerModels From aa31db80444b8c343cc636f8cd7c551f48c08633 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:32:38 -0700 Subject: [PATCH 04/73] WIP add test --- test/test_device_hvdc.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index e69de29bb2..6ca37ba9e8 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -0,0 +1,30 @@ +@testset "HVDC System Tests" begin + sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc"; force_build = true) + template_uc = ProblemTemplate(NetworkModel( + DCPPowerModel, + #use_slacks=true, + PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], +)) + + #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) + set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) + set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) + set_device_model!(template_uc, PowerLoad, StaticPowerLoad) + set_device_model!(template_uc, DeviceModel( + Line, + StaticBranch, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + InterconnectingConverter, + LossLessConverter, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + TModelHVDCLine , + LossLessLine, + #duals=[NetworkFlowConstraint] + )) + +end From 148b6069c97bcaa759b60e9dde6af09e3eaf9817 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:14:35 -0700 Subject: [PATCH 05/73] add methods and renames --- src/PowerSimulations.jl | 6 ++- src/core/expressions.jl | 2 +- src/core/formulations.jl | 10 ++-- src/core/optimization_container.jl | 10 ++-- .../device_constructors/branch_constructor.jl | 18 +++---- .../hvdcsystems_constructor.jl | 41 +++++++++++++++ .../hybridgeneration_constructor.jl | 16 +++--- .../hydrogeneration_constructor.jl | 36 ++++++------- .../device_constructors/load_constructor.jl | 16 +++--- .../regulationdevice_constructor.jl | 6 +-- .../renewablegeneration_constructor.jl | 8 +-- .../storage_constructor.jl | 24 ++++----- .../thermalgeneration_constructor.jl | 52 +++++++++---------- src/devices_models/devices/AC_branches.jl | 4 +- src/devices_models/devices/HVDCsystems.jl | 46 ++++++++++++++++ ..._branches.jl => TwoTerminalDC_branches.jl} | 24 ++++----- .../devices/common/add_to_expression.jl | 30 +++++------ .../devices/thermal_generation.jl | 2 +- src/network_models/copperplate_model.jl | 2 +- src/network_models/network_constructor.jl | 26 +++++----- src/network_models/powermodels_interface.jl | 4 +- test/test_device_branch_constructors.jl | 4 +- 22 files changed, 238 insertions(+), 149 deletions(-) create mode 100644 src/devices_models/device_constructors/hvdcsystems_constructor.jl create mode 100644 src/devices_models/devices/HVDCsystems.jl rename src/devices_models/devices/{DC_branches.jl => TwoTerminalDC_branches.jl} (95%) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 41833f32e6..c0061b7969 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -346,7 +346,7 @@ export SystemBalanceExpressions export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions -export ActivePowerBalance +export ActivePowerBalanceAC export ReactivePowerBalance export EmergencyUp export EmergencyDown @@ -546,7 +546,8 @@ include("devices_models/devices/renewable_generation.jl") include("devices_models/devices/thermal_generation.jl") include("devices_models/devices/electric_loads.jl") include("devices_models/devices/AC_branches.jl") -include("devices_models/devices/DC_branches.jl") +include("devices_models/devices/TwoTerminalDC_branches.jl") +include("devices_models/devices/HVDCsystems.jl") include("devices_models/devices/storage.jl") include("devices_models/devices/hydro_generation.jl") include("devices_models/devices/regulation_device.jl") @@ -572,6 +573,7 @@ include("initial_conditions/initialization.jl") include("devices_models/device_constructors/constructor_validations.jl") include("devices_models/device_constructors/thermalgeneration_constructor.jl") include("devices_models/device_constructors/hydrogeneration_constructor.jl") +include("devices_models/device_constructors/hvdcsystems_constructor.jl") include("devices_models/device_constructors/branch_constructor.jl") include("devices_models/device_constructors/renewablegeneration_constructor.jl") include("devices_models/device_constructors/load_constructor.jl") diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 0f337b1119..61f55d0b97 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -33,7 +33,7 @@ abstract type SystemBalanceExpressions <: ExpressionType end abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end -struct ActivePowerBalance <: SystemBalanceExpressions end +struct ActivePowerBalanceAC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 30c31ea3d8..dff51633f5 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -188,21 +188,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end +# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index efe7647ac1..63654744ea 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -396,7 +396,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), @@ -411,7 +411,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -424,7 +424,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), ) return @@ -437,9 +437,9 @@ function _make_system_expressions!( ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index a73f1770d5..08b9d5da94 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -265,7 +265,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -327,7 +327,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -368,7 +368,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -384,7 +384,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, HVDCLosses, devices, model, @@ -422,7 +422,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -430,7 +430,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -489,7 +489,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -510,7 +510,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PhaseShifterAngle, devices, model, diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl new file mode 100644 index 0000000000..5ad6bc3cfa --- /dev/null +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -0,0 +1,41 @@ +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.InterconnectingConverter, sys) + add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) + add_to_expression!( + container, + ActivePowerBalanceAC, + ActivePowerVariable, + devices, + model, + S, + ) + add_to_expression!( + container, + ActivePowerBalanceDC, + ActivePowerVariable, + devices, + model, + S, + ) + + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end diff --git a/src/devices_models/device_constructors/hybridgeneration_constructor.jl b/src/devices_models/device_constructors/hybridgeneration_constructor.jl index 0bc0d14e78..c0656f00a7 100644 --- a/src/devices_models/device_constructors/hybridgeneration_constructor.jl +++ b/src/devices_models/device_constructors/hybridgeneration_constructor.jl @@ -30,7 +30,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -39,7 +39,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -212,7 +212,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -221,7 +221,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -379,7 +379,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -388,7 +388,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -532,7 +532,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -540,7 +540,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/hydrogeneration_constructor.jl b/src/devices_models/device_constructors/hydrogeneration_constructor.jl index d88cb7e5a9..62ce0119bc 100644 --- a/src/devices_models/device_constructors/hydrogeneration_constructor.jl +++ b/src/devices_models/device_constructors/hydrogeneration_constructor.jl @@ -16,7 +16,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -89,7 +89,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -291,7 +291,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -392,7 +392,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -502,7 +502,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -624,7 +624,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroDispatchReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -719,7 +719,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -824,7 +824,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -911,7 +911,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -919,7 +919,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1017,7 +1017,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1136,7 +1136,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroCommitmentReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1144,7 +1144,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1270,7 +1270,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1381,7 +1381,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -1389,7 +1389,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/load_constructor.jl b/src/devices_models/device_constructors/load_constructor.jl index 679c05c935..8c9834c945 100644 --- a/src/devices_models/device_constructors/load_constructor.jl +++ b/src/devices_models/device_constructors/load_constructor.jl @@ -17,7 +17,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -94,7 +94,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -152,7 +152,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -222,7 +222,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -274,7 +274,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -304,7 +304,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -343,7 +343,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/regulationdevice_constructor.jl b/src/devices_models/device_constructors/regulationdevice_constructor.jl index e537934a6f..d30c9c27be 100644 --- a/src/devices_models/device_constructors/regulationdevice_constructor.jl +++ b/src/devices_models/device_constructors/regulationdevice_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -66,7 +66,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -115,7 +115,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 45b128f27b..2d56d0ae9f 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -21,7 +21,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -126,7 +126,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -207,7 +207,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -236,7 +236,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/storage_constructor.jl b/src/devices_models/device_constructors/storage_constructor.jl index 33888fc06a..af36004557 100644 --- a/src/devices_models/device_constructors/storage_constructor.jl +++ b/src/devices_models/device_constructors/storage_constructor.jl @@ -19,7 +19,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -27,7 +27,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -111,7 +111,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -119,7 +119,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -204,7 +204,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -293,7 +293,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -301,7 +301,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -369,7 +369,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -377,7 +377,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -467,7 +467,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -475,7 +475,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 03a8f5d449..83b7e32a39 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -9,7 +9,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -175,7 +175,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -271,7 +271,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -463,7 +463,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -565,7 +565,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -651,7 +651,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -752,7 +752,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -855,13 +855,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -973,13 +973,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1081,13 +1081,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1184,13 +1184,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1282,13 +1282,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1381,13 +1381,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1468,7 +1468,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1485,7 +1485,7 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1494,7 +1494,7 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ActivePowerRangeExpressionLB, @@ -1576,14 +1576,14 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index e5a2482150..795b40b8f8 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -265,7 +265,7 @@ function add_constraints!( time_steps, ) nodal_balance_expressions = - get_expression(container, ActivePowerBalance(), StandardPTDFModel) + get_expression(container, ActivePowerBalanceAC(), StandardPTDFModel) flow_variables = get_variable(container, FlowActivePowerVariable(), B) jump_model = get_jump_model(container) @@ -304,7 +304,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) + nodal_balance_expressions = get_expression(container, ActivePowerBalanceAC(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl new file mode 100644 index 0000000000..9fc5e0ccc2 --- /dev/null +++ b/src/devices_models/devices/HVDCsystems.jl @@ -0,0 +1,46 @@ +#! format: off +requires_initialization(::AbstractConverterFormulation) = false +requires_initialization(::LossLessLine) = false + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.InterconnectingConverter, <:AbstractConverterFormulation}, +) + return model +end + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, +) + return model +end + + +function get_default_time_series_names( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_time_series_names( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_attributes( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{String, Any}() +end + +function get_default_attributes( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{String, Any}() +end diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl similarity index 95% rename from src/devices_models/devices/DC_branches.jl rename to src/devices_models/devices/TwoTerminalDC_branches.jl index fd96866788..3da031de90 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,10 +1,10 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractDCLineFormulation) = false +get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractP2PDCLineFormulation) = false get_variable_binary( ::HVDCFlowDirectionVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = true get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = NaN @@ -12,13 +12,13 @@ get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = get_variable_multiplier( ::FlowActivePowerFromToVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = 1.0 function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) @@ -40,13 +40,13 @@ get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUn get_variable_lower_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_lower_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) = 0.0 @@ -64,21 +64,21 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{String, Any}() end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) @@ -131,7 +131,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::IS.FlattenIteratorWrapper{U}, - ::DeviceModel{U, <:AbstractDCLineFormulation}, + ::DeviceModel{U, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, ) where {T <: FlowRateConstraint, U <: PSY.DCBranch} time_steps = get_time_steps(container) @@ -272,7 +272,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCPowerBalance}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} time_steps = get_time_steps(container) @@ -355,7 +355,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCLossesAbsoluteValue}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} 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 5b2a45ed38..77c7e65be2 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -109,7 +109,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -171,7 +171,7 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} +) where {T <: ActivePowerBalanceAC, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -198,7 +198,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerFromToVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -231,7 +231,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerToFromVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -319,7 +319,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -349,7 +349,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -376,7 +376,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -437,7 +437,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -467,7 +467,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -501,7 +501,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -538,7 +538,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerVariable, V <: PSY.Branch, W <: AbstractBranchFormulation, @@ -575,7 +575,7 @@ function add_to_expression!( ::DeviceModel{PSY.PhaseShiftingTransformer, V}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: PhaseShifterAngle, V <: PhaseAngleControl, W <: StandardPTDFModel, @@ -759,7 +759,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: Union{CopperPlatePowerModel, StandardPTDFModel}, } @@ -783,7 +783,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } @@ -808,7 +808,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index aba7c12e59..46fd154d5e 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -57,7 +57,7 @@ get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::AbstractCompactUnitCommitment) = 0.0 get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = PSY.get_active_power_limits(d).max - PSY.get_active_power_limits(d).min get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = 0.0 -get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalance, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min +get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalanceAC, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min #################### Initial Conditions for models ############### initial_condition_default(::DeviceStatus, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_status(d) diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 657f44c51d..5273caa6f5 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -10,7 +10,7 @@ function add_constraints!( V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel}, } time_steps = get_time_steps(container) - expressions = get_expression(container, ActivePowerBalance(), U) + expressions = get_expression(container, ActivePowerBalanceAC(), U) constraint = add_constraints_container!(container, T(), U, time_steps) for t in time_steps constraint[t] = JuMP.@constraint(container.JuMPmodel, expressions[t] == 0) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 2b16e6aff3..d22a0d0023 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -9,7 +9,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -17,7 +17,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -56,7 +56,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.ACBus), + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus), area_mapping, branches, ) @@ -81,7 +81,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -89,7 +89,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -146,7 +146,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -154,7 +154,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -193,7 +193,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -201,7 +201,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -256,7 +256,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -264,7 +264,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -318,7 +318,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -326,7 +326,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 5e9d2edc36..3e12b19108 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -291,7 +291,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, @@ -319,7 +319,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ PSY.get_number(bus), t, ] diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index eb9c2dee76..c01a4e1832 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -208,7 +208,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine ( + hvdc = TwoTerminalHVDCLine( name=get_name(line), available=true, active_power_flow=0.0, @@ -272,7 +272,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine ( + hvdc = TwoTerminalHVDCLine( name=get_name(line), available=true, active_power_flow=0.0, From cead4c376f1407be7a681651a5a8cd9fed70151c Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:29:50 -0700 Subject: [PATCH 06/73] implement additional expressions --- src/PowerSimulations.jl | 1 + src/core/expressions.jl | 1 + src/core/optimization_container.jl | 29 ++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index c0061b7969..50377a6647 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -347,6 +347,7 @@ export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions export ActivePowerBalanceAC +export ActivePowerBalanceDC export ReactivePowerBalance export EmergencyUp export EmergencyDown diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 61f55d0b97..3857ebfc2a 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -34,6 +34,7 @@ abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end struct ActivePowerBalanceAC <: SystemBalanceExpressions end +struct ActivePowerBalanceDC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 63654744ea..2552570daf 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -391,28 +391,34 @@ end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractPowerModel}, ) time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), ) return end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractActivePowerModel}, ) time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ) return end @@ -420,6 +426,7 @@ end function _make_system_expressions!( container::OptimizationContainer, ::Vector{Int}, + ::Vector{Int}, ::Type{CopperPlatePowerModel}, ) time_steps = get_time_steps(container) @@ -432,15 +439,18 @@ end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{T}, ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), ) return end @@ -450,8 +460,9 @@ function initialize_system_expressions!( ::Type{T}, system::PSY.System, ) where {T <: PM.AbstractPowerModel} - bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)]) - _make_system_expressions!(container, bus_numbers, T) + ac_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)] + dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)] + _make_system_expressions!(container, sort(ac_bus_numbers), sort(dc_bus_numbers), T) return end From 1b122dffd25a39f4bd377fe519beaf6326a64207 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:42:27 -0700 Subject: [PATCH 07/73] methods converter dc balance --- src/devices_models/devices/HVDCsystems.jl | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 9fc5e0ccc2..69a8a48d25 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -1,4 +1,10 @@ #! format: off +get_variable_binary(::ActivePowerVariable, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = false +get_variable_warm_start_value(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power(d) +get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).min +get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max +get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -44,3 +50,31 @@ function get_default_attributes( ) return Dict{String, Any}() end + +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices, t in get_time_steps(container) + name = PSY.get_name(d) + bus_number = PSY.get_number(PSY.get_dc_bus(d)) + _add_to_jump_expression!( + expression[bus_number, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + end + return +end From ca151fdffde5d9720e1fc045d61566fd23126ee1 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:04:52 -0700 Subject: [PATCH 08/73] add line argument stage --- .../hvdcsystems_constructor.jl | 33 ++++++++++++++ src/devices_models/devices/HVDCsystems.jl | 43 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 5ad6bc3cfa..457bd291ac 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,6 +33,39 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.TModelHVDCLine, sys) + add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) + add_to_expression!( + container, + ActivePowerBalanceDC, + FlowActivePowerVariable, + devices, + model, + S, + ) + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 69a8a48d25..d0396f231b 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -5,6 +5,12 @@ get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 +get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false +get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -51,6 +57,43 @@ function get_default_attributes( return Dict{String, Any}() end +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: FlowActivePowerVariable, + V <: PSY.TModelHVDCLine, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices + arc = PSY.get_arc(d) + to_bus_number = PSY.get_number(PSY.get_to(arc)) + from_bus_number = PSY.get_number(PSY.get_from(arc)) + for t in get_time_steps(container) + name = PSY.get_name(d) + _add_to_jump_expression!( + expression[to_bus_number, t], + variable[name, t], + 1.0, + ) + _add_to_jump_expression!( + expression[from_bus_number, t], + variable[name, t], + -1.0, + ) + end + end + return +end + function add_to_expression!( container::OptimizationContainer, ::Type{T}, From 1311675cd433edc045928b6d13374a43c4da7ba8 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:12:35 -0700 Subject: [PATCH 09/73] setup model construct stage --- .../device_constructors/hvdcsystems_constructor.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 457bd291ac..e083275d37 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,10 +33,10 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::NetworkModel{S}, + ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) + devices = get_available_components(PSY.InterconnectingConverter, sys) + error("here") return end From f438eae9c78b826e07b03378255c8df89119268a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:14:23 -0700 Subject: [PATCH 10/73] add hint --- src/core/optimization_container.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 2552570daf..64668cf279 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -551,6 +551,7 @@ function build_impl!(container::OptimizationContainer, template, sys::PSY.System @debug "Building $(transmission) network formulation" _group = LOG_GROUP_OPTIMIZATION_CONTAINER construct_network!(container, sys, transmission_model, template) + error("Here we build the constraints to connect the AC and DC networks") @debug "Problem size:" get_problem_size(container) _group = LOG_GROUP_OPTIMIZATION_CONTAINER end From 1d60fdc69ad9f22479a645e40ee0f443cb67b262 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 13:55:24 -0700 Subject: [PATCH 11/73] many renames --- src/core/optimization_container.jl | 12 +++---- .../device_constructors/branch_constructor.jl | 22 ++++++------ src/devices_models/devices/AC_branches.jl | 4 +-- src/devices_models/devices/DC_branches.jl | 4 +-- .../devices/common/add_constraint_dual.jl | 4 +-- .../devices/common/add_to_expression.jl | 36 +++++++++---------- src/network_models/area_balance_model.jl | 2 +- src/network_models/network_constructor.jl | 10 +++--- src/network_models/network_slack_variables.jl | 30 ++++++++-------- src/network_models/pm_translator.jl | 28 +++++++-------- src/network_models/powermodels_interface.jl | 30 ++++++++-------- src/operation/operation_model_interface.jl | 2 +- src/operation/operation_problem_templates.jl | 2 +- src/utils/powersystems_utils.jl | 4 +-- test/test_network_constructors.jl | 14 ++++---- 15 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index c94391bbf8..84d6b82a1b 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -396,9 +396,9 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), - ExpressionKey(ReactivePowerBalance, PSY.Bus) => + ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -411,7 +411,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -439,7 +439,7 @@ function _make_system_expressions!( container.expressions = Dict( ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(time_steps), - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -450,7 +450,7 @@ function initialize_system_expressions!( ::Type{T}, system::PSY.System, ) where {T <: PM.AbstractPowerModel} - bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.Bus, system)]) + bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)]) _make_system_expressions!(container, bus_numbers, T) return end @@ -1241,7 +1241,7 @@ function get_expression( ::Type{U}, meta=CONTAINER_KEY_EMPTY_META, ) where {T <: SystemBalanceExpressions, U <: PM.AbstractPowerModel} - return get_expression(container, ExpressionKey(T, PSY.Bus, meta)) + return get_expression(container, ExpressionKey(T, PSY.ACBus, meta)) end function get_expression( diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 48752fb889..a73f1770d5 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -344,7 +344,7 @@ function construct_device!( model::DeviceModel{B, U}, ::NetworkModel{S}, ) where { - B <: PSY.HVDCLine, + B <: PSY.TwoTerminalHVDCLine, U <: HVDCP2PLossless, S <: Union{StandardPTDFModel, PTDFPowerModel}, } @@ -358,10 +358,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{StandardPTDFModel}, ) - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) add_variables!(container, HVDCLosses, devices, HVDCP2PDispatch()) @@ -397,10 +397,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{StandardPTDFModel}, ) - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, StandardPTDFModel) add_constraints!(container, FlowRateConstraintToFrom, devices, model, StandardPTDFModel) add_constraints!(container, HVDCPowerBalance, devices, model, StandardPTDFModel) @@ -413,10 +413,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) @@ -443,10 +443,10 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} - devices = get_available_components(PSY.HVDCLine, sys) + devices = get_available_components(PSY.TwoTerminalHVDCLine, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, T) add_constraints!(container, FlowRateConstraintToFrom, devices, model, T) add_constraints!(container, HVDCPowerBalance, devices, model, T) @@ -459,7 +459,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ArgumentConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return @@ -469,7 +469,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ModelConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index c085d9dbb4..e5a2482150 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -304,7 +304,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.Bus) + nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) @@ -499,7 +499,7 @@ function add_constraints!( time_steps = get_time_steps(container) flow_variables = get_variable(container, FlowActivePowerVariable(), T) ps_angle_variables = get_variable(container, PhaseShifterAngle(), T) - bus_angle_variables = get_variable(container, VoltageAngle(), PSY.Bus) + bus_angle_variables = get_variable(container, VoltageAngle(), PSY.ACBus) jump_model = get_jump_model(container) branch_flow = add_constraints_container!( container, diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/DC_branches.jl index 474536866b..fd96866788 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/DC_branches.jl @@ -78,10 +78,10 @@ end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.HVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## -function _get_flow_bounds(d::PSY.HVDCLine) +function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) check_hvdc_line_limits_consistency(d) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min diff --git a/src/devices_models/devices/common/add_constraint_dual.jl b/src/devices_models/devices/common/add_constraint_dual.jl index 89db2d59a8..3a152f92d2 100644 --- a/src/devices_models/devices/common/add_constraint_dual.jl +++ b/src/devices_models/devices/common/add_constraint_dual.jl @@ -18,7 +18,7 @@ function add_constraint_dual!( model::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} if !isempty(get_duals(model)) - devices = PSY.get_components(PSY.Bus, sys) + devices = PSY.get_components(PSY.ACBus, sys) for constraint_type in get_duals(model) assign_dual_variable!(container, constraint_type, devices, T) end @@ -95,7 +95,7 @@ function assign_dual_variable!( constraint_type::Type{<:ConstraintType}, devices::U, ::Type{<:PM.AbstractPowerModel}, -) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.Bus} +) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.ACBus} @assert !isempty(devices) time_steps = get_time_steps(container) add_dual_container!( diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index da588c5ea5..f84455094b 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -171,7 +171,7 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.HVDCLine, W <: HVDCP2PDispatch} +) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -415,7 +415,7 @@ function add_to_expression!( param_container = get_parameter(container, U(), V) multiplier = get_multiplier_array(param_container) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -442,7 +442,7 @@ function add_to_expression!( } parameter = get_parameter_array(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -472,7 +472,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -506,7 +506,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -578,7 +578,7 @@ function add_to_expression!( W <: StandardPTDFModel, } var = get_variable(container, U(), PSY.PhaseShiftingTransformer) - expression = get_expression(container, T(), PSY.Bus) + expression = get_expression(container, T(), PSY.ACBus) for d in devices for t in get_time_steps(container) flow_variable = var[PSY.get_name(d), t] @@ -784,14 +784,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } - variable = get_variable(container, U(), PSY.Bus) - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus) + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -809,14 +809,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "P") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "P") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -834,14 +834,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "Q") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "Q") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return diff --git a/src/network_models/area_balance_model.jl b/src/network_models/area_balance_model.jl index 7c8a8d325c..f9e0057e9e 100644 --- a/src/network_models/area_balance_model.jl +++ b/src/network_models/area_balance_model.jl @@ -1,7 +1,7 @@ function area_balance( container::OptimizationContainer, expression::ExpressionKey, - area_mapping::Dict{String, Array{PSY.Bus, 1}}, + area_mapping::Dict{String, Array{PSY.ACBus, 1}}, branches, ) time_steps = get_time_steps(container) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 7e0f93f1d0..2b16e6aff3 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -56,7 +56,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.Bus), + ExpressionKey(ActivePowerBalance, PSY.ACBus), area_mapping, branches, ) @@ -160,7 +160,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -223,7 +223,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -286,7 +286,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -348,7 +348,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model, T) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = diff --git a/src/network_models/network_slack_variables.jl b/src/network_models/network_slack_variables.jl index 0da08779f2..424e29bf61 100644 --- a/src/network_models/network_slack_variables.jl +++ b/src/network_models/network_slack_variables.jl @@ -1,6 +1,6 @@ #! format: off -get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = 1.0 -get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = -1.0 +get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = 1.0 +get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = -1.0 #! format: on function add_variables!( @@ -35,8 +35,8 @@ function add_variables!( U <: PM.AbstractActivePowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) - variable = add_variable_container!(container, T(), PSY.Bus, bus_numbers, time_steps) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) + variable = add_variable_container!(container, T(), PSY.ACBus, bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable[n, t] = JuMP.@variable( @@ -58,11 +58,11 @@ function add_variables!( U <: PM.AbstractPowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(PSY.get_components(PSY.Bus, sys)) + bus_numbers = PSY.get_number.(PSY.get_components(PSY.ACBus, sys)) variable_active = - add_variable_container!(container, T(), PSY.Bus, "P", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "P", bus_numbers, time_steps) variable_reactive = - add_variable_container!(container, T(), PSY.Bus, "Q", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "Q", bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable_active[n, t] = JuMP.@variable( @@ -99,12 +99,12 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, model::NetworkModel{T}, S::Type{T}, ) where {T <: PM.AbstractActivePowerModel} - variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus) - variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus) + variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus) + variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus) bus_numbers = axes(variable_up)[1] @assert_op bus_numbers == axes(variable_dn)[1] for t in get_time_steps(container), n in bus_numbers @@ -118,14 +118,14 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, model::NetworkModel{T}, S::Type{T}, ) where {T <: PM.AbstractPowerModel} - variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "P") - variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "P") - variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "Q") - variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "Q") + variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "P") + variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "P") + variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "Q") + variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "Q") bus_numbers = axes(variable_p_up)[1] @assert_op bus_numbers == axes(variable_q_dn)[1] for t in get_time_steps(container), n in bus_numbers diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index e664dba207..40c9c903fa 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -2,7 +2,7 @@ const PM_MAP_TUPLE = NamedTuple{(:from_to, :to_from), Tuple{Tuple{Int, Int, Int}, Tuple{Int, Int, Int}}} struct PMmap - bus::Dict{Int, PSY.Bus} + bus::Dict{Int, PSY.ACBus} arcs::Dict{PM_MAP_TUPLE, <:PSY.ACBranch} arcs_dc::Dict{PM_MAP_TUPLE, <:PSY.DCBranch} end @@ -258,7 +258,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, ) @@ -296,7 +296,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractPowerModel}, ) @@ -335,7 +335,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{<:AbstractBranchFormulation}, ::Type{<:PM.AbstractPowerModel}, ) @@ -411,16 +411,16 @@ function get_branches_to_pm( return PM_branches, PMmap_br end -function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.Bus}) +function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.ACBus}) PM_buses = Dict{String, Any}() - PMmap_buses = Dict{Int, PSY.Bus}() + PMmap_buses = Dict{Int, PSY.ACBus}() - pm_bustypes = Dict{PSY.BusTypes, Int}( - PSY.BusTypes.ISOLATED => 4, - PSY.BusTypes.PQ => 1, - PSY.BusTypes.PV => 2, - PSY.BusTypes.REF => 3, - PSY.BusTypes.SLACK => 3, + pm_bustypes = Dict{PSY.ACBusTypes, Int}( + PSY.ACBusTypes.ISOLATED => 4, + PSY.ACBusTypes.PQ => 1, + PSY.ACBusTypes.PV => 2, + PSY.ACBusTypes.REF => 3, + PSY.ACBusTypes.SLACK => 3, ) for bus in buses @@ -441,7 +441,7 @@ function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.Bus}) "name" => PSY.get_name(bus), ) PM_buses["$(number)"] = PM_bus - if PSY.get_bustype(bus) != PSY.BusTypes.ISOLATED::PSY.BusTypes + if PSY.get_bustype(bus) != PSY.ACBusTypes.ISOLATED::PSY.ACBusTypes PMmap_buses[number] = bus end end @@ -462,7 +462,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In template.branches, length(ac_lines), ) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) pm_buses, PMmap_buses = get_buses_to_pm(buses) PM_translation = Dict{String, Any}( "bus" => pm_buses, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 701a460b6b..5e9d2edc36 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -287,13 +287,13 @@ function powermodels_network!( ) where {S <: PM.AbstractPowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = - container.expressions[ExpressionKey(ReactivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, t, ] @@ -315,11 +315,11 @@ function powermodels_network!( ) where {S <: PM.AbstractActivePowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = PSY.get_components(PSY.Bus, sys) + buses = PSY.get_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ PSY.get_number(bus), t, ] @@ -338,7 +338,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractDCPModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => (from_to=FlowActivePowerVariable(), to_from=nothing)) pm_variable_map[PSY.DCBranch] = @@ -350,7 +350,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => FlowActivePowerFromToVariable()) pm_variable_map[PSY.DCBranch] = Dict( :p_dc => ( @@ -365,7 +365,7 @@ end function PMvarmap(::Type{PTDFPowerModel}) pm_variable_map = Dict{Type, Dict{Symbol, Union{String, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict() + pm_variable_map[PSY.ACBus] = Dict() pm_variable_map[PSY.ACBranch] = Dict() pm_variable_map[PSY.DCBranch] = Dict() @@ -375,7 +375,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) pm_variable_map[PSY.ACBranch] = Dict( :p => ( from_to=FlowActivePowerFromToVariable(), @@ -400,14 +400,14 @@ end function PMconmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, <:ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) + pm_constraint_map[PSY.ACBus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) return pm_constraint_map end function PMconmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict( + pm_constraint_map[PSY.ACBus] = Dict( :power_balance_p => NodalBalanceActiveConstraint(), :power_balance_q => NodalBalanceReactiveConstraint(), ) @@ -459,10 +459,10 @@ function add_pm_variable_refs!( pm_variable_map = PMvarmap(system_formulation) bus_names = [PSY.get_name(b) for b in values(bus_dict)] - for (pm_v, ps_v) in pm_variable_map[PSY.Bus] + for (pm_v, ps_v) in pm_variable_map[PSY.ACBus] if pm_v in pm_variable_types var_container = - add_variable_container!(container, ps_v, PSY.Bus, bus_names, time_steps) + add_variable_container!(container, ps_v, PSY.ACBus, bus_names, time_steps) for t in time_steps, (pm_bus, bus) in bus_dict name = PSY.get_name(bus) var_container[name, t] = PM.var(container.pm, t, pm_v)[pm_bus] # pm_vars[pm_v][pm_bus] @@ -536,12 +536,12 @@ function add_pm_constraint_refs!( [k for k in keys(PM.con(container.pm, 1)) if !isempty(PM.con(container.pm, 1, k))] pm_constraint_map = PMconmap(system_formulation) - for (pm_v, ps_v) in pm_constraint_map[PSY.Bus] + for (pm_v, ps_v) in pm_constraint_map[PSY.ACBus] if pm_v in pm_constraint_names cons_container = add_constraints_container!( container, ps_v, - PSY.Bus, + PSY.ACBus, [PSY.get_name(b) for b in values(bus_dict)], time_steps, ) diff --git a/src/operation/operation_model_interface.jl b/src/operation/operation_model_interface.jl index 18402fff0d..5e30152d71 100644 --- a/src/operation/operation_model_interface.jl +++ b/src/operation/operation_model_interface.jl @@ -216,7 +216,7 @@ function validate_template(model::OperationModel) modeled_types = get_component_types(template) system = get_system(model) system_component_types = PSY.get_existing_component_types(system) - exclusions = [PSY.Arc, PSY.Area, PSY.Bus, PSY.LoadZone] + exclusions = [PSY.Arc, PSY.Area, PSY.ACBus, PSY.LoadZone] for m in setdiff(modeled_types, system_component_types) @warn "The system data doesn't include components of type $(m), consider changing the models in the template" _group = LOG_GROUP_MODELS_VALIDATION diff --git a/src/operation/operation_problem_templates.jl b/src/operation/operation_problem_templates.jl index 5a60c03c52..ebee30ff2a 100644 --- a/src/operation/operation_problem_templates.jl +++ b/src/operation/operation_problem_templates.jl @@ -15,7 +15,7 @@ function _default_devices_uc() DeviceModel(PSY.Line, StaticBranch), DeviceModel(PSY.Transformer2W, StaticBranch), DeviceModel(PSY.TapTransformer, StaticBranch), - DeviceModel(PSY.HVDCLine, HVDCP2PDispatch), + DeviceModel(PSY.TwoTerminalHVDCLine, HVDCP2PDispatch), ] end diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index 8419408ed0..e0eddda63c 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -16,7 +16,7 @@ end make_system_filename(sys::PSY.System) = "system-$(IS.get_uuid(sys)).json" make_system_filename(sys_uuid::Union{Base.UUID, AbstractString}) = "system-$(sys_uuid).json" -function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) +function check_hvdc_line_limits_consistency(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max @@ -38,7 +38,7 @@ function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) return end -function check_hvdc_line_limits_unidirectional(d::PSY.HVDCLine) +function check_hvdc_line_limits_unidirectional(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index c875f55024..41ee1388e5 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -202,7 +202,7 @@ end constraint_keys = [ PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "ub"), PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "lb"), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [384, 0, 408, 408, 288], @@ -248,8 +248,8 @@ end constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, PSY.Line), PSI.ConstraintKey(RateLimitConstraintToFrom, PSY.Line), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [1056, 0, 384, 384, 264], @@ -291,7 +291,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] objfuncs = [GAEVF, GQEVF, GQEVF] - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_results = Dict{System, Vector{Int}}( c_sys5 => [264, 0, 264, 264, 120], c_sys14 => [600, 0, 600, 600, 336], @@ -336,8 +336,8 @@ end systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Voltages, etc. constraint_keys = [ - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] ACR_test_results = Dict{System, Vector{Int}}( c_sys5 => [1056, 0, 240, 240, 264], @@ -376,7 +376,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Bi-directional flows etc - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_obj_values = IdDict{System, Float64}( c_sys5 => 340000.0, c_sys14 => 142000.0, From cc3347b834dcc38b99f5037e5cadd8e98c60e53f Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:29:52 -0700 Subject: [PATCH 12/73] more rename --- test/test_device_branch_constructors.jl | 62 +++++++++---------- test/test_device_hvdc.jl | 0 .../operations_problem_templates.jl | 4 +- 3 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 test/test_device_hvdc.jl diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 0d7d289190..46f850427d 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -81,7 +81,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), @@ -90,7 +90,7 @@ end ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -106,7 +106,7 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -120,7 +120,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -144,9 +144,9 @@ end end end -@testset "DC Power Flow Models for Unbounded HVDCLine, and StaticBranchBounds for TapTransformer & Transformer2W" begin +@testset "DC Power Flow Models for Unbounded TwoTerminalHVDCLine , and StaticBranchBounds for TapTransformer & Transformer2W" begin system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -162,13 +162,13 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PUnbounded)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PUnbounded)) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT - @test check_variable_unbounded(model_m, FlowActivePowerVariable, HVDCLine) + @test check_variable_unbounded(model_m, FlowActivePowerVariable, TwoTerminalHVDCLine ) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @@ -177,7 +177,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -208,7 +208,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine( + hvdc = TwoTerminalHVDCLine ( name=get_name(line), available=true, active_power_flow=0.0, @@ -229,7 +229,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model = DecisionModel( template_uc, @@ -242,7 +242,7 @@ end solve!(model; output_dir=mktempdir()) ptdf_vars = get_variable_values(ProblemResults(model)) ptdf_values = - ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] ptdf_objective = model.internal.container.optimizer_stats.objective_value set_network_model!(template_uc, NetworkModel(DCPPowerModel)) @@ -258,7 +258,7 @@ end solve!(model; output_dir=mktempdir()) dcp_vars = get_variable_values(ProblemResults(model)) dcp_values = - dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] dcp_objective = model.internal.container.optimizer_stats.objective_value @test isapprox(dcp_objective, ptdf_objective; atol=0.1) @@ -272,7 +272,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine( + hvdc = TwoTerminalHVDCLine ( name=get_name(line), available=true, active_power_flow=0.0, @@ -297,7 +297,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_ref = DecisionModel( template_uc, @@ -312,7 +312,7 @@ end ref_values = ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, Line}("")] hvdc_ref_values = - ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}( + ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }( "", )] ref_objective = model_ref.internal.container.optimizer_stats.objective_value @@ -328,7 +328,7 @@ end ), ), ) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PDispatch)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PDispatch)) model = DecisionModel( template_uc, @@ -346,13 +346,13 @@ end )] hvdc_ft_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] hvdc_tf_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -400,13 +400,13 @@ end dispatch_vars = get_variable_values(ProblemResults(model_wl)) dispatch_values_ft = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] dispatch_values_tf = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -435,7 +435,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Line, "ub"), @@ -443,8 +443,8 @@ end PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "lb"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -464,7 +464,7 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -479,7 +479,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) @@ -555,14 +555,14 @@ end ) end -@testset "AC Power Flow Models for HVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin +@testset "AC Power Flow Models for TwoTerminalHVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, Transformer2W), PSI.ConstraintKey(RateLimitConstraintToFrom, Transformer2W), PSI.ConstraintKey(RateLimitConstraintFromTo, TapTransformer), PSI.ConstraintKey(RateLimitConstraintToFrom, TapTransformer), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -580,7 +580,7 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -597,7 +597,7 @@ end model_m, FlowActivePowerVariable, FlowReactivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index 6b478b0764..74b32c5b0d 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network=CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network=StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end From e35133c1a5a2f883b2bbfebcca3b400b40fd83f5 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:30:02 -0700 Subject: [PATCH 13/73] add new formulations --- src/core/formulations.jl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index daa300da11..c5a69f0f97 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -163,7 +163,7 @@ struct MyCustomBranchFormulation <: PSI.AbstractDeviceFormulation # Generic Branch Models abstract type AbstractBranchFormulation <: AbstractDeviceFormulation end -############################### AC Branch Formulations ##################################### +############################### AC/DC Branch Formulations ##################################### """ Branch type to add unbounded flow variables and use flow constraints """ @@ -182,21 +182,33 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractDCLineFormulation end +struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractDCLineFormulation end +struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractDCLineFormulation end +# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end + +############################### AC/DC Converter Formulations ##################################### +abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end + +""" +LossLess InterconnectingConverter Model +""" +struct LossLessConverter <: AbstractConverterFormulation end + +# TODO: Think if this an ok abstraction for future use cases +struct LossLessLine <: AbstractBranchFormulation end + ############################## Network Model Formulations ################################## # These formulations are taken directly from PowerModels From 0fd9d5a4f05109f75f4af335109ff24af31d80ff Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:32:38 -0700 Subject: [PATCH 14/73] WIP add test --- test/test_device_hvdc.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index e69de29bb2..6ca37ba9e8 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -0,0 +1,30 @@ +@testset "HVDC System Tests" begin + sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc"; force_build = true) + template_uc = ProblemTemplate(NetworkModel( + DCPPowerModel, + #use_slacks=true, + PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], +)) + + #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) + set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) + set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) + set_device_model!(template_uc, PowerLoad, StaticPowerLoad) + set_device_model!(template_uc, DeviceModel( + Line, + StaticBranch, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + InterconnectingConverter, + LossLessConverter, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + TModelHVDCLine , + LossLessLine, + #duals=[NetworkFlowConstraint] + )) + +end From 0516fe64147195098b40646f5eaf693b1451fc83 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:14:35 -0700 Subject: [PATCH 15/73] add methods and renames --- src/PowerSimulations.jl | 6 ++- src/core/expressions.jl | 2 +- src/core/formulations.jl | 10 ++-- src/core/optimization_container.jl | 10 ++-- .../device_constructors/branch_constructor.jl | 18 +++---- .../hvdcsystems_constructor.jl | 41 +++++++++++++++ .../hybridgeneration_constructor.jl | 16 +++--- .../hydrogeneration_constructor.jl | 36 ++++++------- .../device_constructors/load_constructor.jl | 16 +++--- .../regulationdevice_constructor.jl | 6 +-- .../renewablegeneration_constructor.jl | 8 +-- .../storage_constructor.jl | 24 ++++----- .../thermalgeneration_constructor.jl | 52 +++++++++---------- src/devices_models/devices/AC_branches.jl | 4 +- src/devices_models/devices/HVDCsystems.jl | 46 ++++++++++++++++ ..._branches.jl => TwoTerminalDC_branches.jl} | 24 ++++----- .../devices/common/add_to_expression.jl | 30 +++++------ .../devices/thermal_generation.jl | 2 +- src/network_models/copperplate_model.jl | 2 +- src/network_models/network_constructor.jl | 26 +++++----- src/network_models/powermodels_interface.jl | 4 +- test/test_device_branch_constructors.jl | 4 +- 22 files changed, 238 insertions(+), 149 deletions(-) create mode 100644 src/devices_models/device_constructors/hvdcsystems_constructor.jl create mode 100644 src/devices_models/devices/HVDCsystems.jl rename src/devices_models/devices/{DC_branches.jl => TwoTerminalDC_branches.jl} (95%) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 6f8f7d00f9..a9f6f62ad0 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -342,7 +342,7 @@ export SystemBalanceExpressions export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions -export ActivePowerBalance +export ActivePowerBalanceAC export ReactivePowerBalance export EmergencyUp export EmergencyDown @@ -542,7 +542,8 @@ include("devices_models/devices/renewable_generation.jl") include("devices_models/devices/thermal_generation.jl") include("devices_models/devices/electric_loads.jl") include("devices_models/devices/AC_branches.jl") -include("devices_models/devices/DC_branches.jl") +include("devices_models/devices/TwoTerminalDC_branches.jl") +include("devices_models/devices/HVDCsystems.jl") include("devices_models/devices/storage.jl") include("devices_models/devices/hydro_generation.jl") include("devices_models/devices/regulation_device.jl") @@ -567,6 +568,7 @@ include("initial_conditions/initialization.jl") include("devices_models/device_constructors/constructor_validations.jl") include("devices_models/device_constructors/thermalgeneration_constructor.jl") include("devices_models/device_constructors/hydrogeneration_constructor.jl") +include("devices_models/device_constructors/hvdcsystems_constructor.jl") include("devices_models/device_constructors/branch_constructor.jl") include("devices_models/device_constructors/renewablegeneration_constructor.jl") include("devices_models/device_constructors/load_constructor.jl") diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 0f337b1119..61f55d0b97 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -33,7 +33,7 @@ abstract type SystemBalanceExpressions <: ExpressionType end abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end -struct ActivePowerBalance <: SystemBalanceExpressions end +struct ActivePowerBalanceAC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/formulations.jl b/src/core/formulations.jl index c5a69f0f97..75c12b98ad 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -182,21 +182,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end +# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 84d6b82a1b..dcdb23e75d 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -396,7 +396,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), @@ -411,7 +411,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -424,7 +424,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), ) return @@ -437,9 +437,9 @@ function _make_system_expressions!( ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index a73f1770d5..08b9d5da94 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -265,7 +265,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -327,7 +327,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -368,7 +368,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -384,7 +384,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, HVDCLosses, devices, model, @@ -422,7 +422,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -430,7 +430,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -489,7 +489,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -510,7 +510,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PhaseShifterAngle, devices, model, diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl new file mode 100644 index 0000000000..5ad6bc3cfa --- /dev/null +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -0,0 +1,41 @@ +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.InterconnectingConverter, sys) + add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) + add_to_expression!( + container, + ActivePowerBalanceAC, + ActivePowerVariable, + devices, + model, + S, + ) + add_to_expression!( + container, + ActivePowerBalanceDC, + ActivePowerVariable, + devices, + model, + S, + ) + + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end diff --git a/src/devices_models/device_constructors/hybridgeneration_constructor.jl b/src/devices_models/device_constructors/hybridgeneration_constructor.jl index 0bc0d14e78..c0656f00a7 100644 --- a/src/devices_models/device_constructors/hybridgeneration_constructor.jl +++ b/src/devices_models/device_constructors/hybridgeneration_constructor.jl @@ -30,7 +30,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -39,7 +39,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -212,7 +212,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -221,7 +221,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -379,7 +379,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -388,7 +388,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -532,7 +532,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -540,7 +540,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/hydrogeneration_constructor.jl b/src/devices_models/device_constructors/hydrogeneration_constructor.jl index d88cb7e5a9..62ce0119bc 100644 --- a/src/devices_models/device_constructors/hydrogeneration_constructor.jl +++ b/src/devices_models/device_constructors/hydrogeneration_constructor.jl @@ -16,7 +16,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -89,7 +89,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -291,7 +291,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -392,7 +392,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -502,7 +502,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -624,7 +624,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroDispatchReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -719,7 +719,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -824,7 +824,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -911,7 +911,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -919,7 +919,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1017,7 +1017,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1136,7 +1136,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroCommitmentReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1144,7 +1144,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1270,7 +1270,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1381,7 +1381,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -1389,7 +1389,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/load_constructor.jl b/src/devices_models/device_constructors/load_constructor.jl index 679c05c935..8c9834c945 100644 --- a/src/devices_models/device_constructors/load_constructor.jl +++ b/src/devices_models/device_constructors/load_constructor.jl @@ -17,7 +17,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -94,7 +94,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -152,7 +152,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -222,7 +222,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -274,7 +274,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -304,7 +304,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -343,7 +343,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/regulationdevice_constructor.jl b/src/devices_models/device_constructors/regulationdevice_constructor.jl index e537934a6f..d30c9c27be 100644 --- a/src/devices_models/device_constructors/regulationdevice_constructor.jl +++ b/src/devices_models/device_constructors/regulationdevice_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -66,7 +66,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -115,7 +115,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 45b128f27b..2d56d0ae9f 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -21,7 +21,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -126,7 +126,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -207,7 +207,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -236,7 +236,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/storage_constructor.jl b/src/devices_models/device_constructors/storage_constructor.jl index 33888fc06a..af36004557 100644 --- a/src/devices_models/device_constructors/storage_constructor.jl +++ b/src/devices_models/device_constructors/storage_constructor.jl @@ -19,7 +19,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -27,7 +27,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -111,7 +111,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -119,7 +119,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -204,7 +204,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -293,7 +293,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -301,7 +301,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -369,7 +369,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -377,7 +377,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, @@ -467,7 +467,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -475,7 +475,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 03a8f5d449..83b7e32a39 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -9,7 +9,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -175,7 +175,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -271,7 +271,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -463,7 +463,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -565,7 +565,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -651,7 +651,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -752,7 +752,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -855,13 +855,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -973,13 +973,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1081,13 +1081,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1184,13 +1184,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1282,13 +1282,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1381,13 +1381,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1468,7 +1468,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1485,7 +1485,7 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1494,7 +1494,7 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ActivePowerRangeExpressionLB, @@ -1576,14 +1576,14 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index e5a2482150..795b40b8f8 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -265,7 +265,7 @@ function add_constraints!( time_steps, ) nodal_balance_expressions = - get_expression(container, ActivePowerBalance(), StandardPTDFModel) + get_expression(container, ActivePowerBalanceAC(), StandardPTDFModel) flow_variables = get_variable(container, FlowActivePowerVariable(), B) jump_model = get_jump_model(container) @@ -304,7 +304,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) + nodal_balance_expressions = get_expression(container, ActivePowerBalanceAC(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl new file mode 100644 index 0000000000..9fc5e0ccc2 --- /dev/null +++ b/src/devices_models/devices/HVDCsystems.jl @@ -0,0 +1,46 @@ +#! format: off +requires_initialization(::AbstractConverterFormulation) = false +requires_initialization(::LossLessLine) = false + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.InterconnectingConverter, <:AbstractConverterFormulation}, +) + return model +end + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, +) + return model +end + + +function get_default_time_series_names( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_time_series_names( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_attributes( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{String, Any}() +end + +function get_default_attributes( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{String, Any}() +end diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl similarity index 95% rename from src/devices_models/devices/DC_branches.jl rename to src/devices_models/devices/TwoTerminalDC_branches.jl index fd96866788..3da031de90 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,10 +1,10 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractDCLineFormulation) = false +get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractP2PDCLineFormulation) = false get_variable_binary( ::HVDCFlowDirectionVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = true get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = NaN @@ -12,13 +12,13 @@ get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = get_variable_multiplier( ::FlowActivePowerFromToVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = 1.0 function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) @@ -40,13 +40,13 @@ get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUn get_variable_lower_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_lower_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) = 0.0 @@ -64,21 +64,21 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{String, Any}() end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) @@ -131,7 +131,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::IS.FlattenIteratorWrapper{U}, - ::DeviceModel{U, <:AbstractDCLineFormulation}, + ::DeviceModel{U, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, ) where {T <: FlowRateConstraint, U <: PSY.DCBranch} time_steps = get_time_steps(container) @@ -272,7 +272,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCPowerBalance}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} time_steps = get_time_steps(container) @@ -355,7 +355,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCLossesAbsoluteValue}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} 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 f84455094b..7009051764 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -109,7 +109,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -171,7 +171,7 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} +) where {T <: ActivePowerBalanceAC, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -198,7 +198,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerFromToVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -231,7 +231,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerToFromVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -319,7 +319,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -349,7 +349,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -376,7 +376,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -434,7 +434,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -464,7 +464,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -498,7 +498,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -535,7 +535,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerVariable, V <: PSY.Branch, W <: AbstractBranchFormulation, @@ -572,7 +572,7 @@ function add_to_expression!( ::DeviceModel{PSY.PhaseShiftingTransformer, V}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: PhaseShifterAngle, V <: PhaseAngleControl, W <: StandardPTDFModel, @@ -756,7 +756,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: Union{CopperPlatePowerModel, StandardPTDFModel}, } @@ -780,7 +780,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } @@ -805,7 +805,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index aba7c12e59..46fd154d5e 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -57,7 +57,7 @@ get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::AbstractCompactUnitCommitment) = 0.0 get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = PSY.get_active_power_limits(d).max - PSY.get_active_power_limits(d).min get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = 0.0 -get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalance, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min +get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalanceAC, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min #################### Initial Conditions for models ############### initial_condition_default(::DeviceStatus, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_status(d) diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 657f44c51d..5273caa6f5 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -10,7 +10,7 @@ function add_constraints!( V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel}, } time_steps = get_time_steps(container) - expressions = get_expression(container, ActivePowerBalance(), U) + expressions = get_expression(container, ActivePowerBalanceAC(), U) constraint = add_constraints_container!(container, T(), U, time_steps) for t in time_steps constraint[t] = JuMP.@constraint(container.JuMPmodel, expressions[t] == 0) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 2b16e6aff3..d22a0d0023 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -9,7 +9,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -17,7 +17,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -56,7 +56,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.ACBus), + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus), area_mapping, branches, ) @@ -81,7 +81,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -89,7 +89,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -146,7 +146,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -154,7 +154,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -193,7 +193,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -201,7 +201,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -256,7 +256,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -264,7 +264,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -318,7 +318,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -326,7 +326,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 5e9d2edc36..3e12b19108 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -291,7 +291,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, @@ -319,7 +319,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ PSY.get_number(bus), t, ] diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 46f850427d..3150b2ed3a 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -208,7 +208,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine ( + hvdc = TwoTerminalHVDCLine( name=get_name(line), available=true, active_power_flow=0.0, @@ -272,7 +272,7 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine ( + hvdc = TwoTerminalHVDCLine( name=get_name(line), available=true, active_power_flow=0.0, From 8765fc3c8a5e83583866fead459627c691a9b8ac Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:29:50 -0700 Subject: [PATCH 16/73] implement additional expressions --- src/PowerSimulations.jl | 1 + src/core/expressions.jl | 1 + src/core/optimization_container.jl | 29 ++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index a9f6f62ad0..19bfd1c7f1 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -343,6 +343,7 @@ export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions export ActivePowerBalanceAC +export ActivePowerBalanceDC export ReactivePowerBalance export EmergencyUp export EmergencyDown diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 61f55d0b97..3857ebfc2a 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -34,6 +34,7 @@ abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end struct ActivePowerBalanceAC <: SystemBalanceExpressions end +struct ActivePowerBalanceDC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index dcdb23e75d..f423e6d5ae 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -391,28 +391,34 @@ end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractPowerModel}, ) time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), ) return end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractActivePowerModel}, ) time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ) return end @@ -420,6 +426,7 @@ end function _make_system_expressions!( container::OptimizationContainer, ::Vector{Int}, + ::Vector{Int}, ::Type{CopperPlatePowerModel}, ) time_steps = get_time_steps(container) @@ -432,15 +439,18 @@ end function _make_system_expressions!( container::OptimizationContainer, - bus_numbers::Vector{Int}, + ac_bus_numbers::Vector{Int}, + dc_bus_numbers::Vector{Int}, ::Type{T}, ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), ) return end @@ -450,8 +460,9 @@ function initialize_system_expressions!( ::Type{T}, system::PSY.System, ) where {T <: PM.AbstractPowerModel} - bus_numbers = sort([PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)]) - _make_system_expressions!(container, bus_numbers, T) + ac_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.ACBus, system)] + dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)] + _make_system_expressions!(container, sort(ac_bus_numbers), sort(dc_bus_numbers), T) return end From aa747e698a8f64d536b13c22acb7a7cd3471f7d1 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:42:27 -0700 Subject: [PATCH 17/73] methods converter dc balance --- src/devices_models/devices/HVDCsystems.jl | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 9fc5e0ccc2..69a8a48d25 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -1,4 +1,10 @@ #! format: off +get_variable_binary(::ActivePowerVariable, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = false +get_variable_warm_start_value(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power(d) +get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).min +get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max +get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -44,3 +50,31 @@ function get_default_attributes( ) return Dict{String, Any}() end + +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices, t in get_time_steps(container) + name = PSY.get_name(d) + bus_number = PSY.get_number(PSY.get_dc_bus(d)) + _add_to_jump_expression!( + expression[bus_number, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + end + return +end From 5f27c2a4bf85c14ed4e7561c26b03ea79f99b41f Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:04:52 -0700 Subject: [PATCH 18/73] add line argument stage --- .../hvdcsystems_constructor.jl | 33 ++++++++++++++ src/devices_models/devices/HVDCsystems.jl | 43 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 5ad6bc3cfa..457bd291ac 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,6 +33,39 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.TModelHVDCLine, sys) + add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) + add_to_expression!( + container, + ActivePowerBalanceDC, + FlowActivePowerVariable, + devices, + model, + S, + ) + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 69a8a48d25..d0396f231b 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -5,6 +5,12 @@ get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 +get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false +get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -51,6 +57,43 @@ function get_default_attributes( return Dict{String, Any}() end +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: FlowActivePowerVariable, + V <: PSY.TModelHVDCLine, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices + arc = PSY.get_arc(d) + to_bus_number = PSY.get_number(PSY.get_to(arc)) + from_bus_number = PSY.get_number(PSY.get_from(arc)) + for t in get_time_steps(container) + name = PSY.get_name(d) + _add_to_jump_expression!( + expression[to_bus_number, t], + variable[name, t], + 1.0, + ) + _add_to_jump_expression!( + expression[from_bus_number, t], + variable[name, t], + -1.0, + ) + end + end + return +end + function add_to_expression!( container::OptimizationContainer, ::Type{T}, From 6053b261809269393b91e57f4c286ae19dcbad2d Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:12:35 -0700 Subject: [PATCH 19/73] setup model construct stage --- .../device_constructors/hvdcsystems_constructor.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 457bd291ac..e083275d37 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,10 +33,10 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::NetworkModel{S}, + ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) + devices = get_available_components(PSY.InterconnectingConverter, sys) + error("here") return end From 64bce1cd2ecde06700bcf66def1cc29a793f9f3f Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:14:23 -0700 Subject: [PATCH 20/73] add hint --- src/core/optimization_container.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index f423e6d5ae..e9af34d677 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -551,6 +551,7 @@ function build_impl!(container::OptimizationContainer, template, sys::PSY.System @debug "Building $(transmission) network formulation" _group = LOG_GROUP_OPTIMIZATION_CONTAINER construct_network!(container, sys, transmission_model, template) + error("Here we build the constraints to connect the AC and DC networks") @debug "Problem size:" get_problem_size(container) _group = LOG_GROUP_OPTIMIZATION_CONTAINER end From 31f836d4bb3eec7eb168ce483118570b1849ebc4 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 14 Feb 2023 16:20:34 -0700 Subject: [PATCH 21/73] add model for lossless HVDC system --- src/PowerSimulations.jl | 4 ++ src/core/formulations.jl | 1 - src/core/optimization_container.jl | 1 - .../hvdcsystems_constructor.jl | 6 +- .../thermalgeneration_constructor.jl | 27 ++++++- src/devices_models/devices/HVDCsystems.jl | 34 ++++++++- .../devices/TwoTerminalDC_branches.jl | 3 +- .../devices/common/add_to_expression.jl | 7 +- src/network_models/pm_translator.jl | 14 ++-- src/network_models/powermodels_interface.jl | 5 +- test/test_device_branch_constructors.jl | 72 +++++++++++-------- test/test_device_hvdc.jl | 38 +++++----- .../operations_problem_templates.jl | 4 +- 13 files changed, 144 insertions(+), 72 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 19bfd1c7f1..1af2d9fc02 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -44,6 +44,10 @@ export HVDCP2PDispatch export HVDCP2PUnbounded export PhaseAngleControl # export VoltageSourceDC + +######## HVDC models ######## +export LossLessConverter +export LossLessLine ######## Load Models ######## export StaticPowerLoad export PowerLoadInterruption diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 75c12b98ad..31218016e5 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -209,7 +209,6 @@ struct LossLessConverter <: AbstractConverterFormulation end # TODO: Think if this an ok abstraction for future use cases struct LossLessLine <: AbstractBranchFormulation end - ############################## Network Model Formulations ################################## # These formulations are taken directly from PowerModels diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index e9af34d677..f423e6d5ae 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -551,7 +551,6 @@ function build_impl!(container::OptimizationContainer, template, sys::PSY.System @debug "Building $(transmission) network formulation" _group = LOG_GROUP_OPTIMIZATION_CONTAINER construct_network!(container, sys, transmission_model, template) - error("Here we build the constraints to connect the AC and DC networks") @debug "Problem size:" get_problem_size(container) _group = LOG_GROUP_OPTIMIZATION_CONTAINER end diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index e083275d37..94fa7c1714 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -36,7 +36,7 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) - error("here") + add_constraints!(container, NodalBalanceActiveConstraint, devices, model, S) return end @@ -66,9 +66,7 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, - ::Type{S}, + ::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) return end diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 83b7e32a39..142268ccff 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1485,7 +1485,14 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) + add_to_expression!( + container, + ActivePowerBalanceAC, + OnStatusParameter, + devices, + model, + S, + ) add_to_expression!( container, ReactivePowerBalance, @@ -1494,7 +1501,14 @@ function construct_device!( model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) + add_to_expression!( + container, + ActivePowerBalanceAC, + OnStatusParameter, + devices, + model, + S, + ) add_to_expression!( container, ActivePowerRangeExpressionLB, @@ -1583,7 +1597,14 @@ function construct_device!( S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) + add_to_expression!( + container, + ActivePowerBalanceAC, + OnStatusParameter, + devices, + model, + S, + ) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index d0396f231b..184871b1c1 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -7,8 +7,8 @@ get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConve get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) -get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing -get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = -PSY.get_rate(d) +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_rate(d) get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 requires_initialization(::AbstractConverterFormulation) = false @@ -121,3 +121,33 @@ function add_to_expression!( end return end + + +# This method might need to be moved to support Meshed HVDC to the network constructor file +function add_constraints!( + container::OptimizationContainer, + ::Type{NodalBalanceActiveConstraint}, + devices::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{<:PM.AbstractActivePowerModel}, +) + time_steps = get_time_steps(container) + dc_expr = get_expression(container, ActivePowerBalanceDC(), PSY.DCBus) + balance_constraint = add_constraints_container!( + container, + NodalBalanceActiveConstraint(), + PSY.DCBus, + axes(dc_expr)[1], + time_steps, + ) + for d in devices + dc_bus_no = PSY.get_number(PSY.get_dc_bus(d)) + for t in time_steps + balance_constraint[dc_bus_no, t] = JuMP.@constraint( + get_jump_model(container), + dc_expr[dc_bus_no, t] == 0 + ) + end + end + return +end diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 3da031de90..0a89f41eb6 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -78,7 +78,8 @@ end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = + DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 7009051764..394d303d1b 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -171,7 +171,12 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalanceAC, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} +) where { + T <: ActivePowerBalanceAC, + U <: HVDCLosses, + V <: PSY.TwoTerminalHVDCLine, + W <: HVDCP2PDispatch, +} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 40c9c903fa..0feddfd8ff 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -4,7 +4,7 @@ const PM_MAP_TUPLE = struct PMmap bus::Dict{Int, PSY.ACBus} arcs::Dict{PM_MAP_TUPLE, <:PSY.ACBranch} - arcs_dc::Dict{PM_MAP_TUPLE, <:PSY.DCBranch} + arcs_dc::Dict{PM_MAP_TUPLE, PSY.TwoTerminalHVDCLine} end function get_branch_to_pm( @@ -377,7 +377,7 @@ function get_branches_to_pm( ::Type{T}, branch_template::BranchModelContainer, start_idx=0, -) where {T <: PSY.Branch, S <: PM.AbstractPowerModel} +) where {T <: PSY.ACBranch, S <: PM.AbstractPowerModel} PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() @@ -402,10 +402,10 @@ end function get_branches_to_pm( ::PSY.System, ::Type{PTDFPowerModel}, - ::Type{T}, + ::Type{PSY.TwoTerminalHVDCLine}, branch_template::BranchModelContainer, start_idx=0, -) where {T <: PSY.DCBranch} +) PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() return PM_branches, PMmap_br @@ -455,10 +455,10 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In PSY.ACBranch, template.branches, ) - dc_lines, PMmap_dc = get_branches_to_pm( + two_terminal_dc_lines, PMmap_dc = get_branches_to_pm( sys, get_network_formulation(template), - PSY.DCBranch, + PSY.TwoTerminalHVDCLine, template.branches, length(ac_lines), ) @@ -470,7 +470,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In "baseMVA" => PSY.get_base_power(sys), "per_unit" => true, "storage" => Dict{String, Any}(), - "dcline" => dc_lines, + "dcline" => two_terminal_dc_lines, "gen" => Dict{String, Any}(), "switch" => Dict{String, Any}(), "shunt" => Dict{String, Any}(), diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 3e12b19108..242fe5d540 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -291,7 +291,10 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + bus.number, + t, + ] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 3150b2ed3a..f85e4e0642 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -90,7 +90,7 @@ end ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -106,7 +106,7 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -120,7 +120,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_min, limits_max, @@ -146,7 +146,7 @@ end @testset "DC Power Flow Models for Unbounded TwoTerminalHVDCLine , and StaticBranchBounds for TapTransformer & Transformer2W" begin system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -162,13 +162,17 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PUnbounded)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PUnbounded)) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT - @test check_variable_unbounded(model_m, FlowActivePowerVariable, TwoTerminalHVDCLine ) + @test check_variable_unbounded( + model_m, + FlowActivePowerVariable, + TwoTerminalHVDCLine, + ) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @@ -177,7 +181,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_min, limits_max, @@ -229,7 +233,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model = DecisionModel( template_uc, @@ -242,7 +246,9 @@ end solve!(model; output_dir=mktempdir()) ptdf_vars = get_variable_values(ProblemResults(model)) ptdf_values = - ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] + ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine}( + "", + )] ptdf_objective = model.internal.container.optimizer_stats.objective_value set_network_model!(template_uc, NetworkModel(DCPPowerModel)) @@ -258,7 +264,9 @@ end solve!(model; output_dir=mktempdir()) dcp_vars = get_variable_values(ProblemResults(model)) dcp_values = - dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] + dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine}( + "", + )] dcp_objective = model.internal.container.optimizer_stats.objective_value @test isapprox(dcp_objective, ptdf_objective; atol=0.1) @@ -297,7 +305,10 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!( + template_uc, + DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless), + ) model_ref = DecisionModel( template_uc, @@ -311,10 +322,12 @@ end ref_vars = get_variable_values(ProblemResults(model_ref)) ref_values = ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, Line}("")] - hvdc_ref_values = - ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }( - "", - )] + hvdc_ref_values = ref_vars[PowerSimulations.VariableKey{ + FlowActivePowerVariable, + TwoTerminalHVDCLine, + }( + "", + )] ref_objective = model_ref.internal.container.optimizer_stats.objective_value ref_total_gen = sum( sum.( @@ -328,7 +341,10 @@ end ), ), ) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PDispatch)) + set_device_model!( + template_uc, + DeviceModel(TwoTerminalHVDCLine, HVDCP2PDispatch), + ) model = DecisionModel( template_uc, @@ -346,13 +362,13 @@ end )] hvdc_ft_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] hvdc_tf_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] @@ -400,13 +416,13 @@ end dispatch_vars = get_variable_values(ProblemResults(model_wl)) dispatch_values_ft = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] dispatch_values_tf = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] @@ -443,8 +459,8 @@ end PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "lb"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -464,7 +480,7 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix=PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -479,7 +495,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_max, ) @@ -561,8 +577,8 @@ end PSI.ConstraintKey(RateLimitConstraintToFrom, Transformer2W), PSI.ConstraintKey(RateLimitConstraintFromTo, TapTransformer), PSI.ConstraintKey(RateLimitConstraintToFrom, TapTransformer), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -580,7 +596,7 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -597,7 +613,7 @@ end model_m, FlowActivePowerVariable, FlowReactivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_max, ) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index 6ca37ba9e8..c75dbf5e75 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -1,30 +1,26 @@ @testset "HVDC System Tests" begin - sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc"; force_build = true) + sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc") template_uc = ProblemTemplate(NetworkModel( - DCPPowerModel, - #use_slacks=true, - PTDF_matrix=PTDF(sys_5), - #duals=[CopperPlateBalanceConstraint], -)) + DCPPowerModel, + #use_slacks=true, + #PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], + )) #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) - set_device_model!(template_uc, DeviceModel( - Line, - StaticBranch, - #duals=[NetworkFlowConstraint] - )) - set_device_model!(template_uc, DeviceModel( - InterconnectingConverter, - LossLessConverter, - #duals=[NetworkFlowConstraint] - )) - set_device_model!(template_uc, DeviceModel( - TModelHVDCLine , - LossLessLine, - #duals=[NetworkFlowConstraint] - )) + set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) + set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) + set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) + model = DecisionModel( + template_uc, + sys_5; + name="UC", + optimizer=HiGHS_optimizer, + direct_mode_optimizer=true, + ) + @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT end diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index 74b32c5b0d..f39b9762aa 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network=CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network=StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) return template end From 791d9cb23186ce6eecd5a0f57c993f11a62f91dd Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 09:19:49 -0700 Subject: [PATCH 22/73] updates to expression types --- src/PowerSimulations.jl | 4 +- src/core/expressions.jl | 3 +- src/core/optimization_container.jl | 16 +++--- .../device_constructors/branch_constructor.jl | 18 +++---- .../hvdcsystems_constructor.jl | 7 ++- .../hybridgeneration_constructor.jl | 16 +++--- .../hydrogeneration_constructor.jl | 36 ++++++------- .../device_constructors/load_constructor.jl | 16 +++--- .../regulationdevice_constructor.jl | 6 +-- .../renewablegeneration_constructor.jl | 8 +-- .../storage_constructor.jl | 24 ++++----- .../thermalgeneration_constructor.jl | 52 +++++++++---------- src/devices_models/devices/AC_branches.jl | 4 +- src/devices_models/devices/HVDCsystems.jl | 36 ++----------- .../devices/common/add_to_expression.jl | 32 ++++++------ .../devices/thermal_generation.jl | 3 +- src/network_models/copperplate_model.jl | 5 +- src/network_models/hvdc_networks.jl | 33 ++++++++++++ src/network_models/network_constructor.jl | 44 ++++++++++------ src/network_models/powermodels_interface.jl | 4 +- test/test_device_hvdc.jl | 2 +- 21 files changed, 190 insertions(+), 179 deletions(-) create mode 100644 src/network_models/hvdc_networks.jl diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 1af2d9fc02..bca982afe4 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -346,8 +346,7 @@ export SystemBalanceExpressions export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions -export ActivePowerBalanceAC -export ActivePowerBalanceDC +export ActivePowerBalance export ReactivePowerBalance export EmergencyUp export EmergencyDown @@ -566,6 +565,7 @@ include("network_models/powermodels_interface.jl") include("network_models/pm_translator.jl") include("network_models/network_slack_variables.jl") include("network_models/area_balance_model.jl") +include("network_models/hvdc_networks.jl") include("initial_conditions/initialization.jl") diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 3857ebfc2a..0f337b1119 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -33,8 +33,7 @@ abstract type SystemBalanceExpressions <: ExpressionType end abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end -struct ActivePowerBalanceAC <: SystemBalanceExpressions end -struct ActivePowerBalanceDC <: SystemBalanceExpressions end +struct ActivePowerBalance <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index f423e6d5ae..dfbe47243d 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -397,9 +397,9 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), @@ -415,9 +415,9 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), ) return @@ -431,7 +431,7 @@ function _make_system_expressions!( ) time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.System) => + ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(time_steps), ) return @@ -445,11 +445,11 @@ function _make_system_expressions!( ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.System) => + ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), ) return diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 08b9d5da94..a73f1770d5 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -265,7 +265,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -327,7 +327,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -368,7 +368,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerToFromVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerFromToVariable, devices, model, @@ -384,7 +384,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, HVDCLosses, devices, model, @@ -422,7 +422,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerToFromVariable, devices, model, @@ -430,7 +430,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerFromToVariable, devices, model, @@ -489,7 +489,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -510,7 +510,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PhaseShifterAngle, devices, model, diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 94fa7c1714..898beb44c7 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -9,7 +9,7 @@ function construct_device!( add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -17,7 +17,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceDC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -36,7 +36,6 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) - add_constraints!(container, NodalBalanceActiveConstraint, devices, model, S) return end @@ -51,7 +50,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) add_to_expression!( container, - ActivePowerBalanceDC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, diff --git a/src/devices_models/device_constructors/hybridgeneration_constructor.jl b/src/devices_models/device_constructors/hybridgeneration_constructor.jl index c0656f00a7..0bc0d14e78 100644 --- a/src/devices_models/device_constructors/hybridgeneration_constructor.jl +++ b/src/devices_models/device_constructors/hybridgeneration_constructor.jl @@ -30,7 +30,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -39,7 +39,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -212,7 +212,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -221,7 +221,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -379,7 +379,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -388,7 +388,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -532,7 +532,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -540,7 +540,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/hydrogeneration_constructor.jl b/src/devices_models/device_constructors/hydrogeneration_constructor.jl index 62ce0119bc..d88cb7e5a9 100644 --- a/src/devices_models/device_constructors/hydrogeneration_constructor.jl +++ b/src/devices_models/device_constructors/hydrogeneration_constructor.jl @@ -16,7 +16,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -89,7 +89,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -291,7 +291,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -392,7 +392,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -502,7 +502,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -624,7 +624,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroDispatchReservoirStorage()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -719,7 +719,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -824,7 +824,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -911,7 +911,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -919,7 +919,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ReactivePowerVariable, devices, model, @@ -1017,7 +1017,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1136,7 +1136,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroCommitmentReservoirStorage()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1144,7 +1144,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ReactivePowerVariable, devices, model, @@ -1270,7 +1270,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1381,7 +1381,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -1389,7 +1389,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/load_constructor.jl b/src/devices_models/device_constructors/load_constructor.jl index 8c9834c945..679c05c935 100644 --- a/src/devices_models/device_constructors/load_constructor.jl +++ b/src/devices_models/device_constructors/load_constructor.jl @@ -17,7 +17,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -94,7 +94,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -152,7 +152,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -222,7 +222,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -274,7 +274,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -304,7 +304,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -343,7 +343,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/regulationdevice_constructor.jl b/src/devices_models/device_constructors/regulationdevice_constructor.jl index d30c9c27be..e537934a6f 100644 --- a/src/devices_models/device_constructors/regulationdevice_constructor.jl +++ b/src/devices_models/device_constructors/regulationdevice_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -66,7 +66,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -115,7 +115,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 2d56d0ae9f..45b128f27b 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -21,7 +21,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -126,7 +126,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -207,7 +207,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -236,7 +236,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/storage_constructor.jl b/src/devices_models/device_constructors/storage_constructor.jl index af36004557..33888fc06a 100644 --- a/src/devices_models/device_constructors/storage_constructor.jl +++ b/src/devices_models/device_constructors/storage_constructor.jl @@ -19,7 +19,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -27,7 +27,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -111,7 +111,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -119,7 +119,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -196,7 +196,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -204,7 +204,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -293,7 +293,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -301,7 +301,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -369,7 +369,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -377,7 +377,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, @@ -467,7 +467,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -475,7 +475,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 142268ccff..5bf53d714d 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -9,7 +9,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -59,7 +59,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -175,7 +175,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -271,7 +271,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -376,7 +376,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -463,7 +463,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -565,7 +565,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -651,7 +651,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -752,7 +752,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -855,13 +855,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -973,13 +973,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1081,13 +1081,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1184,13 +1184,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1282,13 +1282,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1381,13 +1381,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, S, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!(container, ActivePowerBalance, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1468,7 +1468,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1487,7 +1487,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, @@ -1503,7 +1503,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, @@ -1590,7 +1590,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1599,7 +1599,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index 795b40b8f8..e5a2482150 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -265,7 +265,7 @@ function add_constraints!( time_steps, ) nodal_balance_expressions = - get_expression(container, ActivePowerBalanceAC(), StandardPTDFModel) + get_expression(container, ActivePowerBalance(), StandardPTDFModel) flow_variables = get_variable(container, FlowActivePowerVariable(), B) jump_model = get_jump_model(container) @@ -304,7 +304,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalanceAC(), PSY.ACBus) + nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 184871b1c1..93a014c9dc 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -65,10 +65,10 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceDC, + T <: ActivePowerBalance, U <: FlowActivePowerVariable, V <: PSY.TModelHVDCLine, - W <: AbstractDeviceFormulation, + W <: LossLessLine, X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) @@ -102,7 +102,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceDC, + T <: ActivePowerBalance, U <: ActivePowerVariable, V <: PSY.InterconnectingConverter, W <: AbstractDeviceFormulation, @@ -121,33 +121,3 @@ function add_to_expression!( end return end - - -# This method might need to be moved to support Meshed HVDC to the network constructor file -function add_constraints!( - container::OptimizationContainer, - ::Type{NodalBalanceActiveConstraint}, - devices::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, - model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::Type{<:PM.AbstractActivePowerModel}, -) - time_steps = get_time_steps(container) - dc_expr = get_expression(container, ActivePowerBalanceDC(), PSY.DCBus) - balance_constraint = add_constraints_container!( - container, - NodalBalanceActiveConstraint(), - PSY.DCBus, - axes(dc_expr)[1], - time_steps, - ) - for d in devices - dc_bus_no = PSY.get_number(PSY.get_dc_bus(d)) - for t in time_steps - balance_constraint[dc_bus_no, t] = JuMP.@constraint( - get_jump_model(container), - dc_expr[dc_bus_no, t] == 0 - ) - end - end - return -end diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 394d303d1b..3d899998ce 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -109,7 +109,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -172,7 +172,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch, @@ -203,7 +203,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerFromToVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -236,7 +236,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerToFromVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -324,7 +324,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -354,7 +354,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -381,7 +381,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -439,7 +439,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -469,7 +469,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -503,7 +503,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -540,9 +540,9 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerVariable, - V <: PSY.Branch, + V <: PSY.ACBranch, W <: AbstractBranchFormulation, X <: PM.AbstractActivePowerModel, } @@ -577,7 +577,7 @@ function add_to_expression!( ::DeviceModel{PSY.PhaseShiftingTransformer, V}, ::Type{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: PhaseShifterAngle, V <: PhaseAngleControl, W <: StandardPTDFModel, @@ -761,7 +761,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: Union{CopperPlatePowerModel, StandardPTDFModel}, } @@ -785,7 +785,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } @@ -810,7 +810,7 @@ function add_to_expression!( ::NetworkModel{W}, ::Type{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index 46fd154d5e..437245446f 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -27,6 +27,7 @@ get_variable_upper_bound(::PowerAboveMinimumVariable, d::PSY.ThermalGen, ::Abstr ############## ReactivePowerVariable, ThermalGen #################### get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false +get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false get_variable_warm_start_value(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_reactive_power(d) get_variable_lower_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).max @@ -57,7 +58,7 @@ get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::AbstractCompactUnitCommitment) = 0.0 get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = PSY.get_active_power_limits(d).max - PSY.get_active_power_limits(d).min get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = 0.0 -get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalanceAC, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min +get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalance, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min #################### Initial Conditions for models ############### initial_condition_default(::DeviceStatus, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_status(d) diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 5273caa6f5..c23c5aa221 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -3,17 +3,16 @@ function add_constraints!( ::Type{T}, sys::U, ::NetworkModel{V}, - S::Type{V}, ) where { T <: CopperPlateBalanceConstraint, U <: PSY.System, V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel}, } time_steps = get_time_steps(container) - expressions = get_expression(container, ActivePowerBalanceAC(), U) + expressions = get_expression(container, ActivePowerBalance(), U) constraint = add_constraints_container!(container, T(), U, time_steps) for t in time_steps - constraint[t] = JuMP.@constraint(container.JuMPmodel, expressions[t] == 0) + constraint[t] = JuMP.@constraint(get_jump_model(container), expressions[t] == 0) end return diff --git a/src/network_models/hvdc_networks.jl b/src/network_models/hvdc_networks.jl new file mode 100644 index 0000000000..43544864c3 --- /dev/null +++ b/src/network_models/hvdc_networks.jl @@ -0,0 +1,33 @@ +function add_constraints!( + container::OptimizationContainer, + ::Type{NodalBalanceActiveConstraint}, + sys::PSY.System, + model::NetworkModel{V}, +) where { + V <: PM.AbstractPowerModel, +} + dc_buses = PSY.get_components(PSY.DCBus, sys) + if isempty(dc_buses) + return + end + + time_steps = get_time_steps(container) + dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) + balance_constraint = add_constraints_container!( + container, + NodalBalanceActiveConstraint(), + PSY.DCBus, + axes(dc_expr)[1], + time_steps, + ) + for d in dc_buses + dc_bus_no = PSY.get_number(d) + for t in time_steps + balance_constraint[dc_bus_no, t] = JuMP.@constraint( + get_jump_model(container), + dc_expr[dc_bus_no, t] == 0 + ) + end + end + return +end diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index d22a0d0023..6b4d3d6aaa 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -9,7 +9,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -17,7 +17,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -56,7 +56,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus), + ExpressionKey(ActivePowerBalance, PSY.ACBus), area_mapping, branches, ) @@ -81,7 +81,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, CopperPlatePowerModel) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -89,7 +89,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -98,8 +98,9 @@ function construct_network!( objective_function!(container, PSY.System, model, StandardPTDFModel) end - add_constraints!(container, CopperPlateBalanceConstraint, sys, model, StandardPTDFModel) - + add_constraints!(container, CopperPlateBalanceConstraint, sys, model) + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_constraint_dual!(container, sys, model) return end @@ -120,9 +121,10 @@ function construct_network!( add_pm_expr_refs!(container, T, sys) - add_constraints!(container, CopperPlateBalanceConstraint, sys, model, PTDFPowerModel) + add_constraints!(container, CopperPlateBalanceConstraint, sys, model) + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_constraint_dual!(container, sys, model) - return end @@ -146,7 +148,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -154,7 +156,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -166,6 +168,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION powermodels_network!(container, T, sys, template, instantiate_model) + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -193,7 +197,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -201,7 +205,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -228,6 +232,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -256,7 +262,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -264,7 +270,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -291,6 +297,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -318,7 +326,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -326,7 +334,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -353,6 +361,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 242fe5d540..eaa6047d77 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -291,7 +291,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ bus.number, t, ] @@ -322,7 +322,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ PSY.get_number(bus), t, ] diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index c75dbf5e75..b50325652c 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -7,7 +7,6 @@ #duals=[CopperPlateBalanceConstraint], )) - #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) @@ -23,4 +22,5 @@ direct_mode_optimizer=true, ) @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT + end From 3be8a91e084ba43fd8370d27ed30876d190da4ad Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 09:25:33 -0700 Subject: [PATCH 23/73] remove duplicate --- src/devices_models/devices/thermal_generation.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index 437245446f..aba7c12e59 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -27,7 +27,6 @@ get_variable_upper_bound(::PowerAboveMinimumVariable, d::PSY.ThermalGen, ::Abstr ############## ReactivePowerVariable, ThermalGen #################### get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false -get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false get_variable_warm_start_value(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_reactive_power(d) get_variable_lower_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).max From 6c21b006e67afed0d6f20a199e33f75d0aad070a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 09:57:21 -0700 Subject: [PATCH 24/73] fix tests --- .../thermalgeneration_constructor.jl | 27 +------- src/devices_models/devices/HVDCsystems.jl | 36 +++++++++- .../devices/TwoTerminalDC_branches.jl | 67 +++++++++++-------- src/network_models/hvdc_networks.jl | 12 ++-- src/network_models/pm_translator.jl | 2 +- test/test_device_hvdc.jl | 12 +--- 6 files changed, 86 insertions(+), 70 deletions(-) diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 5bf53d714d..03a8f5d449 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1485,14 +1485,7 @@ function construct_device!( model, S, ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - S, - ) + add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1501,14 +1494,7 @@ function construct_device!( model, S, ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - S, - ) + add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) add_to_expression!( container, ActivePowerRangeExpressionLB, @@ -1597,14 +1583,7 @@ function construct_device!( S, ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - S, - ) + add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 93a014c9dc..c97cafbc74 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -105,7 +105,7 @@ function add_to_expression!( T <: ActivePowerBalance, U <: ActivePowerVariable, V <: PSY.InterconnectingConverter, - W <: AbstractDeviceFormulation, + W <: AbstractConverterFormulation, X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) @@ -121,3 +121,37 @@ function add_to_expression!( end return end + +function add_to_expression!( + ::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalance, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractConverterFormulation, + X <: CopperPlatePowerModel, +} + return +end + +function add_to_expression!( + ::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalance, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractConverterFormulation, + X <: Union{PTDFPowerModel, StandardPTDFModel}, +} + return +end diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 0a89f41eb6..29f0ba1d9f 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,27 +1,30 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractP2PDCLineFormulation) = false - get_variable_binary( ::HVDCFlowDirectionVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = true -get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = NaN +get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, _) = + NaN get_variable_multiplier( ::FlowActivePowerFromToVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = 1.0 -function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) +function get_variable_multiplier( + ::HVDCLosses, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PDispatch, +) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 if l1 == 0.0 && l0 == 0.0 @@ -31,27 +34,37 @@ function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatc end end -get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUnbounded) = - nothing +get_variable_lower_bound( + ::FlowActivePowerVariable, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PUnbounded, +) = nothing -get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUnbounded) = - nothing +get_variable_upper_bound( + ::FlowActivePowerVariable, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PUnbounded, +) = nothing get_variable_lower_bound( ::FlowActivePowerVariable, - d::PSY.DCBranch, + d::PSY.TwoTerminalHVDCLine, ::AbstractP2PDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, - d::PSY.DCBranch, + d::PSY.TwoTerminalHVDCLine, ::AbstractP2PDCLineFormulation, ) = nothing -get_variable_lower_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) = 0.0 +get_variable_lower_bound(::HVDCLosses, d::PSY.TwoTerminalHVDCLine, ::HVDCP2PDispatch) = 0.0 -function get_variable_upper_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) +function get_variable_upper_bound( + ::HVDCLosses, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PDispatch, +) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 if l1 == 0.0 && l0 == 0.0 @@ -64,14 +77,14 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} return Dict{String, Any}() end @@ -115,16 +128,16 @@ end add_constraints!( ::OptimizationContainer, ::Type{<:Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom}}, - ::IS.FlattenIteratorWrapper{<:PSY.DCBranch}, - ::DeviceModel{<:PSY.DCBranch, HVDCP2PUnbounded}, + ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, ::Type{<:PM.AbstractPowerModel}, ) = nothing add_constraints!( ::OptimizationContainer, ::Type{FlowRateConstraint}, - ::IS.FlattenIteratorWrapper{<:PSY.DCBranch}, - ::DeviceModel{<:PSY.DCBranch, HVDCP2PUnbounded}, + ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, ::Type{<:PM.AbstractPowerModel}, ) = nothing @@ -134,7 +147,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, -) where {T <: FlowRateConstraint, U <: PSY.DCBranch} +) where {T <: FlowRateConstraint, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -165,7 +178,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, -) where {T <: FlowRateConstraintFromTo, U <: PSY.DCBranch} +) where {T <: FlowRateConstraintFromTo, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -196,7 +209,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, -) where {T <: FlowRateConstraintToFrom, U <: PSY.DCBranch} +) where {T <: FlowRateConstraintToFrom, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -227,7 +240,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, -) where {T <: HVDCDirection, U <: PSY.DCBranch} +) where {T <: HVDCDirection, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -275,7 +288,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{T}, ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, -) where {T <: PSY.DCBranch} +) where {T <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] tf_var = get_variable(container, FlowActivePowerToFromVariable(), T) @@ -358,7 +371,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{T}, ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractDCPModel}, -) where {T <: PSY.DCBranch} +) where {T <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] losses = get_variable(container, HVDCLosses(), T) diff --git a/src/network_models/hvdc_networks.jl b/src/network_models/hvdc_networks.jl index 43544864c3..555c6b5858 100644 --- a/src/network_models/hvdc_networks.jl +++ b/src/network_models/hvdc_networks.jl @@ -3,16 +3,14 @@ function add_constraints!( ::Type{NodalBalanceActiveConstraint}, sys::PSY.System, model::NetworkModel{V}, -) where { - V <: PM.AbstractPowerModel, -} +) where {V <: PM.AbstractPowerModel} dc_buses = PSY.get_components(PSY.DCBus, sys) if isempty(dc_buses) return end time_steps = get_time_steps(container) - dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) + dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) balance_constraint = add_constraints_container!( container, NodalBalanceActiveConstraint(), @@ -23,10 +21,8 @@ function add_constraints!( for d in dc_buses dc_bus_no = PSY.get_number(d) for t in time_steps - balance_constraint[dc_bus_no, t] = JuMP.@constraint( - get_jump_model(container), - dc_expr[dc_bus_no, t] == 0 - ) + balance_constraint[dc_bus_no, t] = + JuMP.@constraint(get_jump_model(container), dc_expr[dc_bus_no, t] == 0) end end return diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 0feddfd8ff..19e9644460 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -336,7 +336,7 @@ end function get_branch_to_pm( ix::Int, branch::PSY.TwoTerminalHVDCLine, - ::Type{<:AbstractBranchFormulation}, + ::Type{<:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, ) PM_branch = Dict{String, Any}( diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index b50325652c..1d4548c714 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -13,14 +13,8 @@ set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) - - model = DecisionModel( - template_uc, - sys_5; - name="UC", - optimizer=HiGHS_optimizer, - direct_mode_optimizer=true, - ) + model = DecisionModel(template_uc, sys_5; name="UC", optimizer=HiGHS_optimizer) @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT - + moi_tests(model, 1656, 0, 1536, 816, 888, true) + @test solve!(model) == RunStatus.SUCCESSFUL end From a1963455316905c0f51158bbb88d5412b1c1182a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 10:36:00 -0700 Subject: [PATCH 25/73] add missing function calls --- .../device_constructors/hvdcsystems_constructor.jl | 3 +++ src/devices_models/devices/HVDCsystems.jl | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 898beb44c7..cf130449ee 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -36,6 +36,9 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) + add_feedforward_constraints!(container, model, devices) + objective_function!(container, devices, model, S) + add_constraint_dual!(container, sys, model) return end diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index c97cafbc74..f0323ed564 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -155,3 +155,12 @@ function add_to_expression!( } return end + +function objective_function!( + ::OptimizationContainer, + ::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, + ::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{<:PM.AbstractPowerModel}, +) + return +end From 8109c5f443314db579ce2c8b7e2bbbdbce25f298 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 10:38:09 -0700 Subject: [PATCH 26/73] remove unused arguments --- .../device_constructors/hvdcsystems_constructor.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index cf130449ee..6712e9fb7b 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -64,8 +64,8 @@ function construct_device!( end function construct_device!( - container::OptimizationContainer, - sys::PSY.System, + ::OptimizationContainer, + ::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::NetworkModel{S}, From 8b8de2c92a004226327c3b7fa6f75ec656123026 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Jun 2023 12:19:33 -0700 Subject: [PATCH 27/73] fix expression additions --- src/devices_models/devices/HVDCsystems.jl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index f0323ed564..01e848d94c 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -109,14 +109,21 @@ function add_to_expression!( X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) - expression = get_expression(container, T(), PSY.DCBus) + expression_dc = get_expression(container, T(), PSY.DCBus) + expression_ac = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) - bus_number = PSY.get_number(PSY.get_dc_bus(d)) + bus_number_dc = PSY.get_number(PSY.get_dc_bus(d)) + bus_number_ac = PSY.get_number(PSY.get_bus(d)) + _add_to_jump_expression!( + expression_ac[bus_number_ac, t], + variable[name, t], + 1.0, + ) _add_to_jump_expression!( - expression[bus_number, t], + expression_dc[bus_number_dc, t], variable[name, t], - get_variable_multiplier(U(), V, W()), + -1.0, ) end return From ceeb00e3c6b8b1da340b66c422945144f1568181 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Jun 2023 12:27:45 -0700 Subject: [PATCH 28/73] fix duplicate call --- .../device_constructors/hvdcsystems_constructor.jl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 6712e9fb7b..5f9647a0a3 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -15,15 +15,6 @@ function construct_device!( model, S, ) - add_to_expression!( - container, - ActivePowerBalance, - ActivePowerVariable, - devices, - model, - S, - ) - add_feedforward_arguments!(container, model, devices) return end From 9dbc558fbd0ddda85ecf5e9c361eeda9d0479d32 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 10:54:28 -0700 Subject: [PATCH 29/73] many renames --- src/core/optimization_container.jl | 10 +++--- .../device_constructors/branch_constructor.jl | 24 +++++++------ src/devices_models/devices/AC_branches.jl | 4 +-- src/devices_models/devices/DC_branches.jl | 4 +-- .../devices/common/add_constraint_dual.jl | 4 +-- .../devices/common/add_to_expression.jl | 34 +++++++++---------- src/network_models/area_balance_model.jl | 2 +- src/network_models/network_constructor.jl | 10 +++--- src/network_models/network_slack_variables.jl | 29 ++++++++-------- src/network_models/pm_translator.jl | 16 ++++----- src/network_models/powermodels_interface.jl | 30 ++++++++-------- src/operation/operation_model_interface.jl | 2 +- src/operation/operation_problem_templates.jl | 2 +- src/utils/powersystems_utils.jl | 4 +-- test/test_network_constructors.jl | 14 ++++---- 15 files changed, 95 insertions(+), 94 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 08130009f5..b0bd31c9ac 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -413,9 +413,9 @@ function _make_system_expressions!( time_steps = get_time_steps(container) bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), - ExpressionKey(ReactivePowerBalance, PSY.Bus) => + ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -429,7 +429,7 @@ function _make_system_expressions!( time_steps = get_time_steps(container) bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -460,7 +460,7 @@ function _make_system_expressions!( container.expressions = Dict( ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(subnetworks, time_steps), - ExpressionKey(ActivePowerBalance, PSY.Bus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -1308,7 +1308,7 @@ function get_expression( ::Type{U}, meta = CONTAINER_KEY_EMPTY_META, ) where {T <: SystemBalanceExpressions, U <: PM.AbstractPowerModel} - return get_expression(container, ExpressionKey(T, PSY.Bus, meta)) + return get_expression(container, ExpressionKey(T, PSY.ACBus, meta)) end function get_expression( diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index e5cd948924..c006c6ddcc 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -506,9 +506,12 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{T, U}, - network_model::NetworkModel{<:Union{StandardPTDFModel, PTDFPowerModel}}, -) where {T <: PSY.HVDCLine, U <: HVDCP2PLossless} + model::DeviceModel{PSY.TwoTerminalHVDCLine, T}, + network_model::NetworkModel{U}, +) where { + T <: HVDCP2PLossless, + U <: Union{StandardPTDFModel, PTDFPowerModel}, +} devices = get_available_components(T, sys, get_attribute(model, "filter_function")) add_constraints!(container, FlowRateConstraint, devices, model, network_model) @@ -520,7 +523,7 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, network_model::NetworkModel{StandardPTDFModel}, ) devices = @@ -560,8 +563,8 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, - network_model::NetworkModel{StandardPTDFModel}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, + ::NetworkModel{StandardPTDFModel}, ) devices = get_available_components(PSY.HVDCLine, sys, get_attribute(model, "filter_function")) @@ -569,7 +572,6 @@ function construct_device!( add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) add_constraints!(container, HVDCPowerBalance, devices, model, network_model) add_constraints!(container, HVDCLossesAbsoluteValue, devices, model, network_model) - add_constraint_dual!(container, sys, model) return end @@ -577,7 +579,7 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, network_model::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} devices = @@ -608,7 +610,7 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, network_model::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} devices = @@ -625,7 +627,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ArgumentConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return @@ -635,7 +637,7 @@ function construct_device!( ::OptimizationContainer, ::PSY.System, ::ModelConstructStage, - ::DeviceModel{PSY.HVDCLine, HVDCP2PDispatch}, + ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, ::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} return diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index 191c7d1727..a5f5cd4252 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -339,7 +339,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.Bus) + nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) @@ -546,7 +546,7 @@ function add_constraints!( time_steps = get_time_steps(container) flow_variables = get_variable(container, FlowActivePowerVariable(), T) ps_angle_variables = get_variable(container, PhaseShifterAngle(), T) - bus_angle_variables = get_variable(container, VoltageAngle(), PSY.Bus) + bus_angle_variables = get_variable(container, VoltageAngle(), PSY.ACBus) jump_model = get_jump_model(container) branch_flow = add_constraints_container!( container, diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/DC_branches.jl index 23cbba14f9..81d62e9ed2 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/DC_branches.jl @@ -83,10 +83,10 @@ end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.HVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## -function _get_flow_bounds(d::PSY.HVDCLine) +function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) check_hvdc_line_limits_consistency(d) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min diff --git a/src/devices_models/devices/common/add_constraint_dual.jl b/src/devices_models/devices/common/add_constraint_dual.jl index 5527c48315..1d5e9111bd 100644 --- a/src/devices_models/devices/common/add_constraint_dual.jl +++ b/src/devices_models/devices/common/add_constraint_dual.jl @@ -19,7 +19,7 @@ function add_constraint_dual!( model::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} if !isempty(get_duals(model)) - devices = get_available_components(PSY.Bus, sys) + devices = PSY.get_components(PSY.ACBus, sys) for constraint_type in get_duals(model) assign_dual_variable!(container, constraint_type, devices, model) end @@ -96,7 +96,7 @@ function assign_dual_variable!( constraint_type::Type{<:ConstraintType}, devices::U, ::NetworkModel{<:PM.AbstractPowerModel}, -) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.Bus} +) where {U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}}} where {D <: PSY.ACBus} @assert !isempty(devices) time_steps = get_time_steps(container) add_dual_container!( diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index ba24c91f15..1729a9b426 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -171,7 +171,7 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, network_model::NetworkModel{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.HVDCLine, W <: HVDCP2PDispatch} +) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -429,7 +429,7 @@ function add_to_expression!( param_container = get_parameter(container, U(), V) multiplier = get_multiplier_array(param_container) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices name = PSY.get_name(d) device_bus = PSY.get_bus(d) @@ -460,7 +460,7 @@ function add_to_expression!( } parameter = get_parameter_array(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) bus_no = PSY.get_number(PSY.get_bus(d)) @@ -492,7 +492,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices name = PSY.get_name(d) device_bus = PSY.get_bus(d) @@ -530,7 +530,7 @@ function add_to_expression!( } variable = get_variable(container, U(), V) sys_expr = get_expression(container, T(), PSY.System) - nodal_expr = get_expression(container, T(), PSY.Bus) + nodal_expr = get_expression(container, T(), PSY.ACBus) for d in devices name = PSY.get_name(d) device_bus = PSY.get_bus(d) @@ -682,7 +682,7 @@ function add_to_expression!( network_model::NetworkModel{StandardPTDFModel}, ) where {T <: ActivePowerBalance, U <: PhaseShifterAngle, V <: PhaseAngleControl} var = get_variable(container, U(), PSY.PhaseShiftingTransformer) - expression = get_expression(container, T(), PSY.Bus) + expression = get_expression(container, T(), PSY.ACBus) for d in devices for t in get_time_steps(container) flow_variable = var[PSY.get_name(d), t] @@ -887,14 +887,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } - variable = get_variable(container, U(), PSY.Bus) - expression = get_expression(container, T(), PSY.Bus) + variable = get_variable(container, U(), PSY.ACBus) + expression = get_expression(container, T(), PSY.ACBus) @assert_op length(axes(variable, 1)) == length(axes(expression, 1)) for t in get_time_steps(container), n in axes(variable, 1) _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -911,14 +911,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "P") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(get_available_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "P") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(get_available_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return @@ -935,14 +935,14 @@ function add_to_expression!( U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } - variable = get_variable(container, U(), PSY.Bus, "Q") - expression = get_expression(container, T(), PSY.Bus) - bus_numbers = PSY.get_number.(get_available_components(PSY.Bus, sys)) + variable = get_variable(container, U(), PSY.ACBus, "Q") + expression = get_expression(container, T(), PSY.ACBus) + bus_numbers = PSY.get_number.(get_available_components(PSY.ACBus, sys)) for t in get_time_steps(container), n in bus_numbers _add_to_jump_expression!( expression[n, t], variable[n, t], - get_variable_multiplier(U(), PSY.Bus, W), + get_variable_multiplier(U(), PSY.ACBus, W), ) end return diff --git a/src/network_models/area_balance_model.jl b/src/network_models/area_balance_model.jl index 612bb7bee1..04d6ffa3e0 100644 --- a/src/network_models/area_balance_model.jl +++ b/src/network_models/area_balance_model.jl @@ -1,7 +1,7 @@ function area_balance( container::OptimizationContainer, expression::ExpressionKey, - area_mapping::Dict{String, Array{PSY.Bus, 1}}, + area_mapping::Dict{String, Array{PSY.ACBus, 1}}, branches, ) time_steps = get_time_steps(container) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 547ddc5af2..65a08586e3 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -42,7 +42,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.Bus), + ExpressionKey(ActivePowerBalance, PSY.ACBus), area_mapping, branches, ) @@ -124,7 +124,7 @@ function construct_network!( sys, model, ) - objective_function!(container, PSY.Bus, model) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -177,7 +177,7 @@ function construct_network!( sys, model, ) - objective_function!(container, PSY.Bus, model) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -240,7 +240,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = @@ -302,7 +302,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.Bus, model) + objective_function!(container, PSY.ACBus, model, T) end @debug "Building the $T network with $instantiate_model method" _group = diff --git a/src/network_models/network_slack_variables.jl b/src/network_models/network_slack_variables.jl index a40a16a25d..a3b32f3036 100644 --- a/src/network_models/network_slack_variables.jl +++ b/src/network_models/network_slack_variables.jl @@ -1,6 +1,6 @@ #! format: off -get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = 1.0 -get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.Bus, PSY.System}}, _) = -1.0 +get_variable_multiplier(::SystemBalanceSlackUp, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = 1.0 +get_variable_multiplier(::SystemBalanceSlackDown, ::Type{<: Union{PSY.ACBus, PSY.System}}, _) = -1.0 #! format: on function add_variables!( @@ -37,9 +37,8 @@ function add_variables!( U <: PM.AbstractActivePowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(get_available_components(PSY.Bus, sys)) + bus_numbers = PSY.get_number.(get_available_components(PSY.accessBus, sys)) variable = add_variable_container!(container, T(), PSY.Bus, bus_numbers, time_steps) - for t in time_steps, n in bus_numbers variable[n, t] = JuMP.@variable( get_jump_model(container), @@ -60,11 +59,11 @@ function add_variables!( U <: PM.AbstractPowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(get_available_components(PSY.Bus, sys)) + bus_numbers = PSY.get_number.(get_available_components(PSY.ACBus, sys)) variable_active = - add_variable_container!(container, T(), PSY.Bus, "P", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "P", bus_numbers, time_steps) variable_reactive = - add_variable_container!(container, T(), PSY.Bus, "Q", bus_numbers, time_steps) + add_variable_container!(container, T(), PSY.ACBus, "Q", bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable_active[n, t] = JuMP.@variable( @@ -101,11 +100,11 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, network_model::NetworkModel{T}, ) where {T <: PM.AbstractActivePowerModel} - variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus) - variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus) + variable_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus) + variable_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus) bus_numbers = axes(variable_up)[1] @assert_op bus_numbers == axes(variable_dn)[1] for t in get_time_steps(container), n in bus_numbers @@ -119,13 +118,13 @@ end function objective_function!( container::OptimizationContainer, - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, network_model::NetworkModel{T}, ) where {T <: PM.AbstractPowerModel} - variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "P") - variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "P") - variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.Bus, "Q") - variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.Bus, "Q") + variable_p_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "P") + variable_p_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "P") + variable_q_up = get_variable(container, SystemBalanceSlackUp(), PSY.ACBus, "Q") + variable_q_dn = get_variable(container, SystemBalanceSlackDown(), PSY.ACBus, "Q") bus_numbers = axes(variable_p_up)[1] @assert_op bus_numbers == axes(variable_q_dn)[1] for t in get_time_steps(container), n in bus_numbers diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index b311268033..0b87ef2374 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -1,7 +1,7 @@ const PM_MAP_TUPLE = NamedTuple{(:from_to, :to_from), Tuple{Tuple{Int, Int, Int}, Tuple{Int, Int, Int}}} -const PM_BUSTYPES = Dict{PSY.BusTypes, Int}( +const PM_BUSTYPES = Dict{PSY.ACBusTypes, Int}( PSY.BusTypes.ISOLATED => 4, PSY.BusTypes.PQ => 1, PSY.BusTypes.PV => 2, @@ -10,7 +10,7 @@ const PM_BUSTYPES = Dict{PSY.BusTypes, Int}( ) struct PMmap - bus::Dict{Int, PSY.Bus} + bus::Dict{Int, PSY.ACBus} arcs::Dict{PM_MAP_TUPLE, <:PSY.ACBranch} arcs_dc::Dict{PM_MAP_TUPLE, <:PSY.DCBranch} end @@ -266,7 +266,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractDCPModel}, ) @@ -304,7 +304,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{HVDCP2PDispatch}, ::Type{<:PM.AbstractPowerModel}, ) @@ -343,7 +343,7 @@ end function get_branch_to_pm( ix::Int, - branch::PSY.HVDCLine, + branch::PSY.TwoTerminalHVDCLine, ::Type{<:AbstractBranchFormulation}, ::Type{<:PM.AbstractPowerModel}, ) @@ -420,9 +420,9 @@ function get_branches_to_pm( return PM_branches, PMmap_br end -function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.Bus}) +function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.ACBus}) PM_buses = Dict{String, Any}() - PMmap_buses = Dict{Int, PSY.Bus}() + PMmap_buses = Dict{Int, PSY.ACBus}() for bus in buses if PSY.get_bustype(bus) == PSY.BusTypes.ISOLATED @@ -464,7 +464,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In template.branches, length(ac_lines), ) - buses = get_available_components(PSY.Bus, sys) + buses = get_available_components(PSY.ACBus, sys) pm_buses, PMmap_buses = get_buses_to_pm(buses) PM_translation = Dict{String, Any}( "bus" => pm_buses, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 263844772e..38a4c716a2 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -291,13 +291,13 @@ function powermodels_network!( ) where {S <: PM.AbstractPowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = get_available_components(PSY.Bus, sys) + buses = get_available_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = - container.expressions[ExpressionKey(ReactivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, t, ] @@ -319,11 +319,11 @@ function powermodels_network!( ) where {S <: PM.AbstractActivePowerModel} time_steps = get_time_steps(container) pm_data, PM_map = pass_to_pm(sys, template, time_steps[end]) - buses = get_available_components(PSY.Bus, sys) + buses = get_available_components(PSY.ACBus, sys) for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.Bus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ PSY.get_number(bus), t, ] @@ -342,7 +342,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractDCPModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => (from_to = FlowActivePowerVariable(), to_from = nothing)) pm_variable_map[PSY.DCBranch] = @@ -354,7 +354,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => FlowActivePowerFromToVariable()) pm_variable_map[PSY.DCBranch] = Dict( :p_dc => ( @@ -369,7 +369,7 @@ end function PMvarmap(::Type{PTDFPowerModel}) pm_variable_map = Dict{Type, Dict{Symbol, Union{String, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict() + pm_variable_map[PSY.ACBus] = Dict() pm_variable_map[PSY.ACBranch] = Dict() pm_variable_map[PSY.DCBranch] = Dict() @@ -379,7 +379,7 @@ end function PMvarmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}() - pm_variable_map[PSY.Bus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) + pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle(), :vm => VoltageMagnitude()) pm_variable_map[PSY.ACBranch] = Dict( :p => ( from_to = FlowActivePowerFromToVariable(), @@ -404,14 +404,14 @@ end function PMconmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, <:ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) + pm_constraint_map[PSY.ACBus] = Dict(:power_balance_p => NodalBalanceActiveConstraint()) return pm_constraint_map end function PMconmap(::Type{S}) where {S <: PM.AbstractPowerModel} pm_constraint_map = Dict{Type, Dict{Symbol, ConstraintType}}() - pm_constraint_map[PSY.Bus] = Dict( + pm_constraint_map[PSY.ACBus] = Dict( :power_balance_p => NodalBalanceActiveConstraint(), :power_balance_q => NodalBalanceReactiveConstraint(), ) @@ -463,10 +463,10 @@ function add_pm_variable_refs!( pm_variable_map = PMvarmap(system_formulation) bus_names = [PSY.get_name(b) for b in values(bus_dict)] - for (pm_v, ps_v) in pm_variable_map[PSY.Bus] + for (pm_v, ps_v) in pm_variable_map[PSY.ACBus] if pm_v in pm_variable_types var_container = - add_variable_container!(container, ps_v, PSY.Bus, bus_names, time_steps) + add_variable_container!(container, ps_v, PSY.ACBus, bus_names, time_steps) for t in time_steps, (pm_bus, bus) in bus_dict name = PSY.get_name(bus) var_container[name, t] = PM.var(container.pm, t, pm_v)[pm_bus] # pm_vars[pm_v][pm_bus] @@ -540,12 +540,12 @@ function add_pm_constraint_refs!( [k for k in keys(PM.con(container.pm, 1)) if !isempty(PM.con(container.pm, 1, k))] pm_constraint_map = PMconmap(system_formulation) - for (pm_v, ps_v) in pm_constraint_map[PSY.Bus] + for (pm_v, ps_v) in pm_constraint_map[PSY.ACBus] if pm_v in pm_constraint_names cons_container = add_constraints_container!( container, ps_v, - PSY.Bus, + PSY.ACBus, [PSY.get_name(b) for b in values(bus_dict)], time_steps, ) diff --git a/src/operation/operation_model_interface.jl b/src/operation/operation_model_interface.jl index ecd0b99d7a..94132b0216 100644 --- a/src/operation/operation_model_interface.jl +++ b/src/operation/operation_model_interface.jl @@ -216,7 +216,7 @@ function validate_template(model::OperationModel) modeled_types = get_component_types(template) system = get_system(model) system_component_types = PSY.get_existing_component_types(system) - exclusions = [PSY.Arc, PSY.Area, PSY.Bus, PSY.LoadZone] + exclusions = [PSY.Arc, PSY.Area, PSY.ACBus, PSY.LoadZone] for m in setdiff(modeled_types, system_component_types) @warn "The system data doesn't include components of type $(m), consider changing the models in the template" _group = LOG_GROUP_MODELS_VALIDATION diff --git a/src/operation/operation_problem_templates.jl b/src/operation/operation_problem_templates.jl index 5a60c03c52..ebee30ff2a 100644 --- a/src/operation/operation_problem_templates.jl +++ b/src/operation/operation_problem_templates.jl @@ -15,7 +15,7 @@ function _default_devices_uc() DeviceModel(PSY.Line, StaticBranch), DeviceModel(PSY.Transformer2W, StaticBranch), DeviceModel(PSY.TapTransformer, StaticBranch), - DeviceModel(PSY.HVDCLine, HVDCP2PDispatch), + DeviceModel(PSY.TwoTerminalHVDCLine, HVDCP2PDispatch), ] end diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index 2af80e6319..bd3ade1e1e 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -41,7 +41,7 @@ end make_system_filename(sys::PSY.System) = "system-$(IS.get_uuid(sys)).json" make_system_filename(sys_uuid::Union{Base.UUID, AbstractString}) = "system-$(sys_uuid).json" -function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) +function check_hvdc_line_limits_consistency(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max @@ -63,7 +63,7 @@ function check_hvdc_line_limits_consistency(d::PSY.HVDCLine) return end -function check_hvdc_line_limits_unidirectional(d::PSY.HVDCLine) +function check_hvdc_line_limits_unidirectional(d::PSY.TwoTerminalHVDCLine) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index 7e362df29c..fffd5eba49 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -262,7 +262,7 @@ end constraint_keys = [ PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "ub"), PSI.ConstraintKey(PSI.RateLimitConstraint, PSY.Line, "lb"), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [384, 0, 408, 408, 288], @@ -309,8 +309,8 @@ end constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, PSY.Line), PSI.ConstraintKey(RateLimitConstraintToFrom, PSY.Line), - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] test_results = IdDict{System, Vector{Int}}( c_sys5 => [1056, 0, 384, 384, 264], @@ -353,7 +353,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] objfuncs = [GAEVF, GQEVF, GQEVF] - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_results = Dict{System, Vector{Int}}( c_sys5 => [264, 0, 264, 264, 120], c_sys14 => [600, 0, 600, 600, 336], @@ -400,8 +400,8 @@ end systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Voltages, etc. constraint_keys = [ - PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus), - PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.Bus), + PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus), + PSI.ConstraintKey(PSI.NodalBalanceReactiveConstraint, PSY.ACBus), ] ACR_test_results = Dict{System, Vector{Int}}( c_sys5 => [1056, 0, 240, 240, 264], @@ -441,7 +441,7 @@ end c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc") systems = [c_sys5, c_sys14, c_sys14_dc] # TODO: add model specific constraints to this list. Bi-directional flows etc - constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.Bus)] + constraint_keys = [PSI.ConstraintKey(PSI.NodalBalanceActiveConstraint, PSY.ACBus)] test_obj_values = IdDict{System, Float64}( c_sys5 => 340000.0, c_sys14 => 142000.0, From d31c9106d67bfbeffc668987a64abba5fba3f489 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 10:56:49 -0700 Subject: [PATCH 30/73] more rename --- test/test_device_branch_constructors.jl | 87 +++++++++---------- test/test_device_hvdc.jl | 0 .../operations_problem_templates.jl | 4 +- 3 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 test/test_device_hvdc.jl diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 3a6f7eebf6..0d489cfd70 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -85,7 +85,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine with with Line Flow Constraints, TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), @@ -94,7 +94,7 @@ end ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -110,10 +110,9 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, HVDCLine, HVDCP2PLossless) - model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) - @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == - PSI.BuildStatus.BUILT + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) + @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @test check_variable_unbounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_unbounded(model_m, FlowActivePowerVariable, Transformer2W) @@ -125,7 +124,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -149,9 +148,9 @@ end end end -@testset "DC Power Flow Models for Unbounded HVDCLine, and StaticBranchBounds for TapTransformer & Transformer2W" begin +@testset "DC Power Flow Models for Unbounded TwoTerminalHVDCLine , and StaticBranchBounds for TapTransformer & Transformer2W" begin system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -167,14 +166,14 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PUnbounded)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PUnbounded)) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT - @test check_variable_unbounded(model_m, FlowActivePowerVariable, HVDCLine) + @test check_variable_unbounded(model_m, FlowActivePowerVariable, TwoTerminalHVDCLine ) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @@ -183,7 +182,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_min, limits_max, @@ -214,10 +213,10 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine(; - name = get_name(line), - available = true, - active_power_flow = 0.0, + hvdc = TwoTerminalHVDCLine( + name=get_name(line), + available=true, + active_power_flow=0.0, # Force the flow in the opposite direction for testing purposes active_power_limits_from = (min = -0.5, max = -0.5), active_power_limits_to = (min = -3.0, max = 2.0), @@ -237,7 +236,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model = DecisionModel( template_uc, @@ -252,7 +251,7 @@ end ptdf_vars = get_variable_values(ProblemResults(model)) ptdf_values = - ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] ptdf_objective = model.internal.container.optimizer_stats.objective_value set_network_model!(template_uc, NetworkModel(DCPPowerModel)) @@ -268,7 +267,7 @@ end solve!(model; output_dir = mktempdir()) dcp_vars = get_variable_values(ProblemResults(model)) dcp_values = - dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}("")] + dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] dcp_objective = model.internal.container.optimizer_stats.objective_value @test isapprox(dcp_objective, ptdf_objective; atol = 0.1) @@ -282,10 +281,10 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = HVDCLine(; - name = get_name(line), - available = true, - active_power_flow = 0.0, + hvdc = TwoTerminalHVDCLine( + name=get_name(line), + available=true, + active_power_flow=0.0, # Force the flow in the opposite direction for testing purposes active_power_limits_from = (min = -2.0, max = -2.0), active_power_limits_to = (min = -3.0, max = 2.0), @@ -307,7 +306,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) model_ref = DecisionModel( template_uc, @@ -322,7 +321,7 @@ end ref_values = ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, Line}("")] hvdc_ref_values = - ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, HVDCLine}( + ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }( "", )] ref_objective = model_ref.internal.container.optimizer_stats.objective_value @@ -338,7 +337,7 @@ end ), ), ) - set_device_model!(template_uc, DeviceModel(HVDCLine, HVDCP2PDispatch)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PDispatch)) model = DecisionModel( template_uc, @@ -356,13 +355,13 @@ end )] hvdc_ft_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] hvdc_tf_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -410,13 +409,13 @@ end dispatch_vars = get_variable_values(ProblemResults(model_wl)) dispatch_values_ft = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] dispatch_values_tf = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , }( "", )] @@ -445,7 +444,7 @@ end end end -@testset "DC Power Flow Models for HVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin +@testset "DC Power Flow Models for TwoTerminalHVDCLine Dispatch and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "ub"), PSI.ConstraintKey(RateLimitConstraint, Line, "ub"), @@ -453,8 +452,8 @@ end PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "lb"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -474,9 +473,9 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) - model_m = DecisionModel(template, system; optimizer = HiGHS_optimizer) - @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) + @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @test !check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test !check_variable_bounded(model_m, FlowActivePowerVariable, Transformer2W) @@ -489,7 +488,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) @@ -565,14 +564,14 @@ end ) end -@testset "AC Power Flow Models for HVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin +@testset "AC Power Flow Models for TwoTerminalHVDCLine Flow Constraints and TapTransformer & Transformer2W Unbounded" begin ratelimit_constraint_keys = [ PSI.ConstraintKey(RateLimitConstraintFromTo, Transformer2W), PSI.ConstraintKey(RateLimitConstraintToFrom, Transformer2W), PSI.ConstraintKey(RateLimitConstraintFromTo, TapTransformer), PSI.ConstraintKey(RateLimitConstraintToFrom, TapTransformer), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "ub"), - PSI.ConstraintKey(FlowRateConstraint, HVDCLine, "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -590,9 +589,9 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(HVDCLine, HVDCP2PLossless)) - model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) - @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) + @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @test check_variable_bounded(model_m, FlowActivePowerFromToVariable, TapTransformer) @test check_variable_unbounded(model_m, FlowReactivePowerFromToVariable, TapTransformer) @@ -607,7 +606,7 @@ end model_m, FlowActivePowerVariable, FlowReactivePowerToFromVariable, - HVDCLine, + TwoTerminalHVDCLine , "DCLine3", limits_max, ) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index c08eabc94b..8401a62834 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network = CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network = StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, HVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) return template end From 6f8070814d9ef4ef5cc4be1e14724904abc58e16 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:30:02 -0700 Subject: [PATCH 31/73] add new formulations --- src/core/formulations.jl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index dedffc553a..e666130f3e 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -143,7 +143,7 @@ struct MyCustomBranchFormulation <: PSI.AbstractDeviceFormulation # Generic Branch Models abstract type AbstractBranchFormulation <: AbstractDeviceFormulation end -############################### AC Branch Formulations ##################################### +############################### AC/DC Branch Formulations ##################################### """ Branch type to add unbounded flow variables and use flow constraints """ @@ -162,21 +162,33 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractDCLineFormulation end +struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractDCLineFormulation end +struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractDCLineFormulation end +# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end + +############################### AC/DC Converter Formulations ##################################### +abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end + +""" +LossLess InterconnectingConverter Model +""" +struct LossLessConverter <: AbstractConverterFormulation end + +# TODO: Think if this an ok abstraction for future use cases +struct LossLessLine <: AbstractBranchFormulation end + ############################## Network Model Formulations ################################## # These formulations are taken directly from PowerModels From c3df0642b43a9f91dad1d5664afe92d7a804ab9a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 14:32:38 -0700 Subject: [PATCH 32/73] WIP add test --- test/test_device_hvdc.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index e69de29bb2..6ca37ba9e8 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -0,0 +1,30 @@ +@testset "HVDC System Tests" begin + sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc"; force_build = true) + template_uc = ProblemTemplate(NetworkModel( + DCPPowerModel, + #use_slacks=true, + PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], +)) + + #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) + set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) + set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) + set_device_model!(template_uc, PowerLoad, StaticPowerLoad) + set_device_model!(template_uc, DeviceModel( + Line, + StaticBranch, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + InterconnectingConverter, + LossLessConverter, + #duals=[NetworkFlowConstraint] + )) + set_device_model!(template_uc, DeviceModel( + TModelHVDCLine , + LossLessLine, + #duals=[NetworkFlowConstraint] + )) + +end From 8eef0b397add370a597a570160da45266c7e8cf5 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:05:45 -0700 Subject: [PATCH 33/73] add methods and renames --- src/PowerSimulations.jl | 6 ++- src/core/expressions.jl | 2 +- src/core/formulations.jl | 10 ++-- src/core/optimization_container.jl | 10 ++-- .../device_constructors/branch_constructor.jl | 18 +++---- .../hvdcsystems_constructor.jl | 41 +++++++++++++++ .../hydrogeneration_constructor.jl | 36 ++++++------- .../device_constructors/load_constructor.jl | 16 +++--- .../regulationdevice_constructor.jl | 6 +-- .../renewablegeneration_constructor.jl | 8 +-- .../thermalgeneration_constructor.jl | 51 ++++++++++--------- src/devices_models/devices/AC_branches.jl | 4 +- src/devices_models/devices/HVDCsystems.jl | 46 +++++++++++++++++ ..._branches.jl => TwoTerminalDC_branches.jl} | 24 ++++----- .../devices/common/add_to_expression.jl | 38 +++++++------- .../devices/thermal_generation.jl | 2 +- src/network_models/copperplate_model.jl | 2 +- src/network_models/network_constructor.jl | 26 +++++----- src/network_models/powermodels_interface.jl | 4 +- 19 files changed, 220 insertions(+), 130 deletions(-) create mode 100644 src/devices_models/device_constructors/hvdcsystems_constructor.jl create mode 100644 src/devices_models/devices/HVDCsystems.jl rename src/devices_models/devices/{DC_branches.jl => TwoTerminalDC_branches.jl} (95%) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index b1e31398f6..f3e9b42dcf 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -333,7 +333,7 @@ export SystemBalanceExpressions export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions -export ActivePowerBalance +export ActivePowerBalanceAC export ReactivePowerBalance export EmergencyUp export EmergencyDown @@ -532,7 +532,8 @@ include("devices_models/devices/renewable_generation.jl") include("devices_models/devices/thermal_generation.jl") include("devices_models/devices/electric_loads.jl") include("devices_models/devices/AC_branches.jl") -include("devices_models/devices/DC_branches.jl") +include("devices_models/devices/TwoTerminalDC_branches.jl") +include("devices_models/devices/HVDCsystems.jl") include("devices_models/devices/hydro_generation.jl") include("devices_models/devices/regulation_device.jl") @@ -556,6 +557,7 @@ include("initial_conditions/initialization.jl") include("devices_models/device_constructors/constructor_validations.jl") include("devices_models/device_constructors/thermalgeneration_constructor.jl") include("devices_models/device_constructors/hydrogeneration_constructor.jl") +include("devices_models/device_constructors/hvdcsystems_constructor.jl") include("devices_models/device_constructors/branch_constructor.jl") include("devices_models/device_constructors/renewablegeneration_constructor.jl") include("devices_models/device_constructors/load_constructor.jl") diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 89c6a8df15..6a11e1a07a 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -33,7 +33,7 @@ abstract type SystemBalanceExpressions <: ExpressionType end abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end -struct ActivePowerBalance <: SystemBalanceExpressions end +struct ActivePowerBalanceAC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/formulations.jl b/src/core/formulations.jl index e666130f3e..3406315b0b 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -162,21 +162,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end +# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index b0bd31c9ac..7073111353 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -413,7 +413,7 @@ function _make_system_expressions!( time_steps = get_time_steps(container) bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), @@ -429,7 +429,7 @@ function _make_system_expressions!( time_steps = get_time_steps(container) bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return @@ -443,7 +443,7 @@ function _make_system_expressions!( time_steps = get_time_steps(container) subnetworks_ref_buses = collect(keys(subnetworks)) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(subnetworks_ref_buses, time_steps), ) return @@ -458,9 +458,9 @@ function _make_system_expressions!( bus_numbers = sort!(collect(Iterators.flatten(values(subnetworks)))) subnetworks = collect(keys(subnetworks)) container.expressions = Dict( - ExpressionKey(ActivePowerBalance, PSY.System) => + ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(subnetworks, time_steps), - ExpressionKey(ActivePowerBalance, PSY.ACBus) => + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => _make_container_array(bus_numbers, time_steps), ) return diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index c006c6ddcc..f1961b215f 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -432,7 +432,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -492,7 +492,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -534,7 +534,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -542,7 +542,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -550,7 +550,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, HVDCLosses, devices, model, @@ -589,7 +589,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerToFromVariable, devices, model, @@ -597,7 +597,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerFromToVariable, devices, model, @@ -661,7 +661,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, FlowActivePowerVariable, devices, model, @@ -686,7 +686,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PhaseShifterAngle, devices, model, diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl new file mode 100644 index 0000000000..5ad6bc3cfa --- /dev/null +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -0,0 +1,41 @@ +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.InterconnectingConverter, sys) + add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) + add_to_expression!( + container, + ActivePowerBalanceAC, + ActivePowerVariable, + devices, + model, + S, + ) + add_to_expression!( + container, + ActivePowerBalanceDC, + ActivePowerVariable, + devices, + model, + S, + ) + + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end diff --git a/src/devices_models/device_constructors/hydrogeneration_constructor.jl b/src/devices_models/device_constructors/hydrogeneration_constructor.jl index a2483f8e70..04336ec9ec 100644 --- a/src/devices_models/device_constructors/hydrogeneration_constructor.jl +++ b/src/devices_models/device_constructors/hydrogeneration_constructor.jl @@ -17,7 +17,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -61,7 +61,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -92,7 +92,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -201,7 +201,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -298,7 +298,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -401,7 +401,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -513,7 +513,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -637,7 +637,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroDispatchReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -734,7 +734,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -841,7 +841,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -930,7 +930,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -938,7 +938,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1038,7 +1038,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1159,7 +1159,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroCommitmentReservoirStorage()) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1167,7 +1167,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ReactivePowerVariable, devices, model, @@ -1295,7 +1295,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -1408,7 +1408,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerInVariable, devices, model, @@ -1416,7 +1416,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/load_constructor.jl b/src/devices_models/device_constructors/load_constructor.jl index 61af8d4198..67efdd744c 100644 --- a/src/devices_models/device_constructors/load_constructor.jl +++ b/src/devices_models/device_constructors/load_constructor.jl @@ -18,7 +18,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -97,7 +97,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -157,7 +157,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -229,7 +229,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -283,7 +283,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -314,7 +314,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -354,7 +354,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -388,7 +388,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/regulationdevice_constructor.jl b/src/devices_models/device_constructors/regulationdevice_constructor.jl index b4535006ff..18df09955c 100644 --- a/src/devices_models/device_constructors/regulationdevice_constructor.jl +++ b/src/devices_models/device_constructors/regulationdevice_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -66,7 +66,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -115,7 +115,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 34a8edd469..58a674f81b 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -22,7 +22,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -137,7 +137,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -228,7 +228,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -258,7 +258,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 06a3dee262..e38a8d969e 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerTimeSeriesParameter, devices, model, @@ -61,7 +61,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -179,7 +179,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -277,7 +277,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -384,7 +384,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -473,7 +473,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -577,7 +577,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -665,7 +665,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -768,7 +768,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, ActivePowerVariable, devices, model, @@ -871,7 +871,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -885,6 +885,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1007,7 +1008,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1021,6 +1022,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1135,7 +1137,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1149,6 +1151,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1247,7 +1250,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1261,6 +1264,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1354,7 +1358,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1368,6 +1372,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1462,7 +1467,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1476,6 +1481,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1558,7 +1564,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, @@ -1583,6 +1589,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1599,6 +1606,7 @@ function construct_device!( model, network_model, ) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ActivePowerRangeExpressionLB, @@ -1682,21 +1690,14 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, PowerAboveMinimumVariable, devices, model, network_model, ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - network_model, - ) + add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index a5f5cd4252..31575439cb 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -300,7 +300,7 @@ function add_constraints!( time_steps, ) nodal_balance_expressions = - get_expression(container, ActivePowerBalance(), StandardPTDFModel) + get_expression(container, ActivePowerBalanceAC(), StandardPTDFModel) flow_variables = get_variable(container, FlowActivePowerVariable(), B) jump_model = get_jump_model(container) @@ -339,7 +339,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) + nodal_balance_expressions = get_expression(container, ActivePowerBalanceAC(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl new file mode 100644 index 0000000000..9fc5e0ccc2 --- /dev/null +++ b/src/devices_models/devices/HVDCsystems.jl @@ -0,0 +1,46 @@ +#! format: off +requires_initialization(::AbstractConverterFormulation) = false +requires_initialization(::LossLessLine) = false + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.InterconnectingConverter, <:AbstractConverterFormulation}, +) + return model +end + +function get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, +) + return model +end + + +function get_default_time_series_names( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_time_series_names( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{Type{<:TimeSeriesParameter}, String}() +end + +function get_default_attributes( + ::Type{PSY.InterconnectingConverter}, + ::Type{<:AbstractConverterFormulation}, +) + return Dict{String, Any}() +end + +function get_default_attributes( + ::Type{PSY.TModelHVDCLine}, + ::Type{<:AbstractBranchFormulation}, +) + return Dict{String, Any}() +end diff --git a/src/devices_models/devices/DC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl similarity index 95% rename from src/devices_models/devices/DC_branches.jl rename to src/devices_models/devices/TwoTerminalDC_branches.jl index 81d62e9ed2..a474a5f1ed 100644 --- a/src/devices_models/devices/DC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,15 +1,15 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractDCLineFormulation) = false +get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractP2PDCLineFormulation) = false get_variable_binary( ::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = false get_variable_binary( ::HVDCFlowDirectionVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = true get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = NaN @@ -17,13 +17,13 @@ get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = get_variable_multiplier( ::FlowActivePowerFromToVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, ::Type{<:PSY.DCBranch}, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = 1.0 function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) @@ -45,13 +45,13 @@ get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUn get_variable_lower_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, d::PSY.DCBranch, - ::AbstractDCLineFormulation, + ::AbstractP2PDCLineFormulation, ) = nothing get_variable_lower_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) = 0.0 @@ -69,21 +69,21 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractDCLineFormulation} +) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} return Dict{String, Any}() end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) @@ -304,7 +304,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCPowerBalance}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} time_steps = get_time_steps(container) @@ -387,7 +387,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCLossesAbsoluteValue}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractDCLineFormulation}, + ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: PSY.DCBranch} 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 1729a9b426..65cb1437c0 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -109,7 +109,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -170,8 +170,8 @@ function add_to_expression!( ::Type{U}, devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, - network_model::NetworkModel{StandardPTDFModel}, -) where {T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} + ::Type{StandardPTDFModel}, +) where {T <: ActivePowerBalanceAC, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices @@ -200,7 +200,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerFromToVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -233,7 +233,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerToFromVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -326,7 +326,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -357,7 +357,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{CopperPlatePowerModel}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -387,7 +387,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{CopperPlatePowerModel}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -452,7 +452,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -484,7 +484,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -522,7 +522,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -563,7 +563,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: FlowActivePowerVariable, V <: PSY.Branch, W <: AbstractBranchFormulation, @@ -600,10 +600,10 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{StandardPTDFModel}, ) where { - T <: ActivePowerBalance, - U <: FlowActivePowerVariable, - V <: PSY.Branch, - W <: AbstractBranchFormulation, + T <: ActivePowerBalanceAC, + U <: PhaseShifterAngle, + V <: PhaseAngleControl, + W <: StandardPTDFModel, } var = get_variable(container, U(), V) nodal_expr = get_expression(container, T(), StandardPTDFModel) @@ -859,7 +859,7 @@ function add_to_expression!( ::PSY.System, network_model::NetworkModel{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: Union{CopperPlatePowerModel, StandardPTDFModel}, } @@ -883,7 +883,7 @@ function add_to_expression!( sys::PSY.System, ::NetworkModel{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } @@ -907,7 +907,7 @@ function add_to_expression!( sys::PSY.System, ::NetworkModel{W}, ) where { - T <: ActivePowerBalance, + T <: ActivePowerBalanceAC, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index 3e8b333652..0f2aaea699 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -57,7 +57,7 @@ get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::AbstractCompactUnitCommitment) = 0.0 get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = PSY.get_active_power_limits(d).max - PSY.get_active_power_limits(d).min get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = 0.0 -get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalance, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min +get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalanceAC, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min #################### Initial Conditions for models ############### initial_condition_default(::DeviceStatus, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_status(d) diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 3d4c12b01b..017f58b47a 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -9,7 +9,7 @@ function add_constraints!( V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel}, } time_steps = get_time_steps(container) - expressions = get_expression(container, ActivePowerBalance(), U) + expressions = get_expression(container, ActivePowerBalanceAC(), U) subnets = collect(keys(model.subnetworks)) constraint = add_constraints_container!(container, T(), U, subnets, time_steps) for t in time_steps, k in keys(model.subnetworks) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 65a08586e3..05a87abe7f 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -7,10 +7,10 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -42,7 +42,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalance, PSY.ACBus), + ExpressionKey(ActivePowerBalanceAC, PSY.ACBus), area_mapping, branches, ) @@ -59,10 +59,10 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -116,10 +116,10 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -155,10 +155,10 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -210,7 +210,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -218,7 +218,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, @@ -272,7 +272,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model, @@ -280,7 +280,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, SystemBalanceSlackDown, sys, model, diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 38a4c716a2..654f829124 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -295,7 +295,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][bus.number, t] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, @@ -323,7 +323,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ PSY.get_number(bus), t, ] From 6a453628c7213bf306c6d618cf6be2aa839374c1 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:09:36 -0700 Subject: [PATCH 34/73] implement additional expressions --- src/PowerSimulations.jl | 1 + src/core/expressions.jl | 1 + src/core/optimization_container.jl | 25 ++++++++++++++++--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index f3e9b42dcf..a0178c8969 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -334,6 +334,7 @@ export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions export ActivePowerBalanceAC +export ActivePowerBalanceDC export ReactivePowerBalance export EmergencyUp export EmergencyDown diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 6a11e1a07a..1c64a4854e 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -34,6 +34,7 @@ abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end struct ActivePowerBalanceAC <: SystemBalanceExpressions end +struct ActivePowerBalanceDC <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 7073111353..4b4f3103c9 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -408,15 +408,18 @@ end function _make_system_expressions!( container::OptimizationContainer, subnetworks::Dict{Int, Set{Int}}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractPowerModel}, ) time_steps = get_time_steps(container) - bus_numbers = collect(Iterators.flatten(values(subnetworks))) + ac_bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), ) return end @@ -424,13 +427,16 @@ end function _make_system_expressions!( container::OptimizationContainer, subnetworks::Dict{Int, Set{Int}}, + dc_bus_numbers::Vector{Int}, ::Type{<:PM.AbstractActivePowerModel}, ) time_steps = get_time_steps(container) - bus_numbers = collect(Iterators.flatten(values(subnetworks))) + ac_bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + _make_container_array(ac_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ) return end @@ -452,16 +458,16 @@ end function _make_system_expressions!( container::OptimizationContainer, subnetworks::Dict{Int, Set{Int}}, + dc_bus_numbers::Vector{Int}, ::Type{T}, ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) - bus_numbers = sort!(collect(Iterators.flatten(values(subnetworks)))) subnetworks = collect(keys(subnetworks)) container.expressions = Dict( ExpressionKey(ActivePowerBalanceAC, PSY.System) => _make_container_array(subnetworks, time_steps), - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => - _make_container_array(bus_numbers, time_steps), + ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + _make_container_array(dc_bus_numbers, time_steps), ) return end @@ -471,7 +477,8 @@ function initialize_system_expressions!( ::Type{T}, subnetworks::Dict{Int, Set{Int}}, ) where {T <: PM.AbstractPowerModel} - _make_system_expressions!(container, subnetworks, T) + dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)] + _make_system_expressions!(container, subnetworks, dc_bus_numbers, T) return end From aa0acac44a38db33aa62e74c373726c6d883fca5 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 15:42:27 -0700 Subject: [PATCH 35/73] methods converter dc balance --- src/devices_models/devices/HVDCsystems.jl | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 9fc5e0ccc2..69a8a48d25 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -1,4 +1,10 @@ #! format: off +get_variable_binary(::ActivePowerVariable, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = false +get_variable_warm_start_value(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power(d) +get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).min +get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max +get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -44,3 +50,31 @@ function get_default_attributes( ) return Dict{String, Any}() end + +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices, t in get_time_steps(container) + name = PSY.get_name(d) + bus_number = PSY.get_number(PSY.get_dc_bus(d)) + _add_to_jump_expression!( + expression[bus_number, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + end + return +end From 42dc8f2f54eaaf866e654a2c1e246eefe6cf06d5 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:04:52 -0700 Subject: [PATCH 36/73] add line argument stage --- .../hvdcsystems_constructor.jl | 33 ++++++++++++++ src/devices_models/devices/HVDCsystems.jl | 43 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 5ad6bc3cfa..457bd291ac 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,6 +33,39 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.TModelHVDCLine, sys) + add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) + add_to_expression!( + container, + ActivePowerBalanceDC, + FlowActivePowerVariable, + devices, + model, + S, + ) + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 69a8a48d25..d0396f231b 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -5,6 +5,12 @@ get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 +get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false +get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 + requires_initialization(::AbstractConverterFormulation) = false requires_initialization(::LossLessLine) = false @@ -51,6 +57,43 @@ function get_default_attributes( return Dict{String, Any}() end +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalanceDC, + U <: FlowActivePowerVariable, + V <: PSY.TModelHVDCLine, + W <: AbstractDeviceFormulation, + X <: PM.AbstractPowerModel, +} + variable = get_variable(container, U(), V) + expression = get_expression(container, T(), PSY.DCBus) + for d in devices + arc = PSY.get_arc(d) + to_bus_number = PSY.get_number(PSY.get_to(arc)) + from_bus_number = PSY.get_number(PSY.get_from(arc)) + for t in get_time_steps(container) + name = PSY.get_name(d) + _add_to_jump_expression!( + expression[to_bus_number, t], + variable[name, t], + 1.0, + ) + _add_to_jump_expression!( + expression[from_bus_number, t], + variable[name, t], + -1.0, + ) + end + end + return +end + function add_to_expression!( container::OptimizationContainer, ::Type{T}, From 34b8e0da9306a63a52c471368a79ec4d9365aa9d Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:12:35 -0700 Subject: [PATCH 37/73] setup model construct stage --- .../device_constructors/hvdcsystems_constructor.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 457bd291ac..e083275d37 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,10 +33,10 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::NetworkModel{S}, + ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) + devices = get_available_components(PSY.InterconnectingConverter, sys) + error("here") return end From 303781f7c1b470c2b73a6e756524c15865d6fa85 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:14:23 -0700 Subject: [PATCH 38/73] add hint --- src/core/optimization_container.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 4b4f3103c9..6476d5ee15 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -567,6 +567,7 @@ function build_impl!(container::OptimizationContainer, template, sys::PSY.System @debug "Building $(transmission) network formulation" _group = LOG_GROUP_OPTIMIZATION_CONTAINER construct_network!(container, sys, transmission_model, template) + error("Here we build the constraints to connect the AC and DC networks") @debug "Problem size:" get_problem_size(container) _group = LOG_GROUP_OPTIMIZATION_CONTAINER end From 90fc7f542648999c2681557aaebd9de12e1d6d7c Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 13:55:24 -0700 Subject: [PATCH 39/73] many renames --- src/network_models/network_slack_variables.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network_models/network_slack_variables.jl b/src/network_models/network_slack_variables.jl index a3b32f3036..0b35557ca6 100644 --- a/src/network_models/network_slack_variables.jl +++ b/src/network_models/network_slack_variables.jl @@ -38,7 +38,7 @@ function add_variables!( } time_steps = get_time_steps(container) bus_numbers = PSY.get_number.(get_available_components(PSY.accessBus, sys)) - variable = add_variable_container!(container, T(), PSY.Bus, bus_numbers, time_steps) + variable = add_variable_container!(container, T(), PSY.ACBus, bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable[n, t] = JuMP.@variable( get_jump_model(container), From 5351802350478311f73ce9df5c12474e0b6fffd3 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:15:54 -0700 Subject: [PATCH 40/73] add new formulations --- src/core/formulations.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 3406315b0b..e666130f3e 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -162,21 +162,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end +struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end +struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end +# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end From ef0d640ef35903509cc433cf117f48013a509a13 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:21:45 -0700 Subject: [PATCH 41/73] add methods and renames --- src/core/formulations.jl | 10 ++++----- .../thermalgeneration_constructor.jl | 21 +++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index e666130f3e..3406315b0b 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -162,21 +162,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractTwoTerminalDCLineFormulation end +struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end +# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index e38a8d969e..886c01778b 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -885,7 +885,7 @@ function construct_device!( model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_to_expression!( container, ReactivePowerBalance, @@ -1016,13 +1016,13 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnVariable, devices, model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) + add_expressions!(container, ProductionCostExpression, devices, model) @@ -1145,13 +1145,12 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnVariable, devices, model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1258,13 +1257,12 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnVariable, devices, model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1372,7 +1370,6 @@ function construct_device!( model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1481,7 +1478,6 @@ function construct_device!( model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnVariable, devices, model, S) add_expressions!(container, ProductionCostExpression, devices, model) @@ -1583,13 +1579,12 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnStatusParameter, devices, model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) add_to_expression!( container, ReactivePowerBalance, @@ -1600,13 +1595,13 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnStatusParameter, devices, model, network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) + add_to_expression!( container, ActivePowerRangeExpressionLB, From a9ed97ebca50d141e684656997a97b9c4f2dd2ee Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:04:52 -0700 Subject: [PATCH 42/73] add line argument stage --- .../hvdcsystems_constructor.jl | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index e083275d37..77c7356ca2 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,6 +33,39 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + + devices = get_available_components(T, sys) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, + ::NetworkModel{S}, +) where {S <: PM.AbstractActivePowerModel} + devices = get_available_components(PSY.TModelHVDCLine, sys) + add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) + add_to_expression!( + container, + ActivePowerBalanceDC, + FlowActivePowerVariable, + devices, + model, + S, + ) + add_feedforward_arguments!(container, model, devices) + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) From af96ad12e8f6ddb6774205bd12b7a9b6b1452897 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Sun, 5 Feb 2023 16:12:35 -0700 Subject: [PATCH 43/73] setup model construct stage --- .../device_constructors/hvdcsystems_constructor.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 77c7356ca2..4037afd48a 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -33,10 +33,10 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::NetworkModel{S}, + ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) + devices = get_available_components(PSY.InterconnectingConverter, sys) + error("here") return end From f5f0224bfc3d3bc3ac2b56331e3ec5c905d416ca Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:23:41 -0700 Subject: [PATCH 44/73] add model for lossless HVDC system --- src/PowerSimulations.jl | 4 ++ src/core/formulations.jl | 1 - src/core/optimization_container.jl | 1 - .../hvdcsystems_constructor.jl | 4 +- .../thermalgeneration_constructor.jl | 9 ++- src/devices_models/devices/HVDCsystems.jl | 34 ++++++++- .../devices/TwoTerminalDC_branches.jl | 3 +- .../devices/common/add_to_expression.jl | 7 +- src/network_models/pm_translator.jl | 10 +-- src/network_models/powermodels_interface.jl | 5 +- test/test_device_branch_constructors.jl | 72 +++++++++++-------- test/test_device_hvdc.jl | 38 +++++----- .../operations_problem_templates.jl | 4 +- 13 files changed, 126 insertions(+), 66 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index a0178c8969..3910f56696 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -44,6 +44,10 @@ export HVDCP2PDispatch export HVDCP2PUnbounded export PhaseAngleControl # export VoltageSourceDC + +######## HVDC models ######## +export LossLessConverter +export LossLessLine ######## Load Models ######## export StaticPowerLoad export PowerLoadInterruption diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 3406315b0b..9bf849e38f 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -189,7 +189,6 @@ struct LossLessConverter <: AbstractConverterFormulation end # TODO: Think if this an ok abstraction for future use cases struct LossLessLine <: AbstractBranchFormulation end - ############################## Network Model Formulations ################################## # These formulations are taken directly from PowerModels diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 6476d5ee15..4b4f3103c9 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -567,7 +567,6 @@ function build_impl!(container::OptimizationContainer, template, sys::PSY.System @debug "Building $(transmission) network formulation" _group = LOG_GROUP_OPTIMIZATION_CONTAINER construct_network!(container, sys, transmission_model, template) - error("Here we build the constraints to connect the AC and DC networks") @debug "Problem size:" get_problem_size(container) _group = LOG_GROUP_OPTIMIZATION_CONTAINER end diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 4037afd48a..48c0a6f5ed 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -36,7 +36,7 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) - error("here") + add_constraints!(container, NodalBalanceActiveConstraint, devices, model, S) return end @@ -66,7 +66,7 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, - ::Type{S}, + ::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) error("here") diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 886c01778b..e104f92b49 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1692,7 +1692,14 @@ function construct_device!( network_model, ) - add_to_expression!(container, ActivePowerBalanceAC, OnStatusParameter, devices, model, S) + add_to_expression!( + container, + ActivePowerBalanceAC, + OnStatusParameter, + devices, + model, + S, + ) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index d0396f231b..184871b1c1 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -7,8 +7,8 @@ get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConve get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) -get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing -get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = nothing +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = -PSY.get_rate(d) +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_rate(d) get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 requires_initialization(::AbstractConverterFormulation) = false @@ -121,3 +121,33 @@ function add_to_expression!( end return end + + +# This method might need to be moved to support Meshed HVDC to the network constructor file +function add_constraints!( + container::OptimizationContainer, + ::Type{NodalBalanceActiveConstraint}, + devices::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, + model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{<:PM.AbstractActivePowerModel}, +) + time_steps = get_time_steps(container) + dc_expr = get_expression(container, ActivePowerBalanceDC(), PSY.DCBus) + balance_constraint = add_constraints_container!( + container, + NodalBalanceActiveConstraint(), + PSY.DCBus, + axes(dc_expr)[1], + time_steps, + ) + for d in devices + dc_bus_no = PSY.get_number(PSY.get_dc_bus(d)) + for t in time_steps + balance_constraint[dc_bus_no, t] = JuMP.@constraint( + get_jump_model(container), + dc_expr[dc_bus_no, t] == 0 + ) + end + end + return +end diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index a474a5f1ed..f57a6e498e 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -83,7 +83,8 @@ end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = DeviceModel(T, U) +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = + DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## function _get_flow_bounds(d::PSY.TwoTerminalHVDCLine) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 65cb1437c0..ecebb091dd 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -171,7 +171,12 @@ function add_to_expression!( devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, -) where {T <: ActivePowerBalanceAC, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch} +) where { + T <: ActivePowerBalanceAC, + U <: HVDCLosses, + V <: PSY.TwoTerminalHVDCLine, + W <: HVDCP2PDispatch, +} variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) for d in devices diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 0b87ef2374..ccf6e08c5f 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -12,7 +12,7 @@ const PM_BUSTYPES = Dict{PSY.ACBusTypes, Int}( struct PMmap bus::Dict{Int, PSY.ACBus} arcs::Dict{PM_MAP_TUPLE, <:PSY.ACBranch} - arcs_dc::Dict{PM_MAP_TUPLE, <:PSY.DCBranch} + arcs_dc::Dict{PM_MAP_TUPLE, PSY.TwoTerminalHVDCLine} end function get_branch_to_pm( @@ -411,7 +411,7 @@ end function get_branches_to_pm( ::PSY.System, ::Type{PTDFPowerModel}, - ::Type{T}, + ::Type{PSY.TwoTerminalHVDCLine}, branch_template::BranchModelContainer, start_idx = 0, ) where {T <: PSY.DCBranch} @@ -457,10 +457,10 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In PSY.ACBranch, template.branches, ) - dc_lines, PMmap_dc = get_branches_to_pm( + two_terminal_dc_lines, PMmap_dc = get_branches_to_pm( sys, get_network_formulation(template), - PSY.DCBranch, + PSY.TwoTerminalHVDCLine, template.branches, length(ac_lines), ) @@ -472,7 +472,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In "baseMVA" => PSY.get_base_power(sys), "per_unit" => true, "storage" => Dict{String, Any}(), - "dcline" => dc_lines, + "dcline" => two_terminal_dc_lines, "gen" => Dict{String, Any}(), "switch" => Dict{String, Any}(), "shunt" => Dict{String, Any}(), diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 654f829124..23c75e651a 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -295,7 +295,10 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][bus.number, t] + container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + bus.number, + t, + ] pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_q"] = container.expressions[ExpressionKey(ReactivePowerBalance, PSY.ACBus)][ bus.number, diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 0d489cfd70..4ff5798060 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -94,7 +94,7 @@ end ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -110,7 +110,7 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -124,7 +124,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_min, limits_max, @@ -150,7 +150,7 @@ end @testset "DC Power Flow Models for Unbounded TwoTerminalHVDCLine , and StaticBranchBounds for TapTransformer & Transformer2W" begin system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(TwoTerminalHVDCLine , system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -166,14 +166,18 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PUnbounded)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PUnbounded)) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT - @test check_variable_unbounded(model_m, FlowActivePowerVariable, TwoTerminalHVDCLine ) + @test check_variable_unbounded( + model_m, + FlowActivePowerVariable, + TwoTerminalHVDCLine, + ) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @@ -182,7 +186,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_min, limits_max, @@ -236,7 +240,7 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model = DecisionModel( template_uc, @@ -251,7 +255,9 @@ end ptdf_vars = get_variable_values(ProblemResults(model)) ptdf_values = - ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] + ptdf_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine}( + "", + )] ptdf_objective = model.internal.container.optimizer_stats.objective_value set_network_model!(template_uc, NetworkModel(DCPPowerModel)) @@ -267,7 +273,9 @@ end solve!(model; output_dir = mktempdir()) dcp_vars = get_variable_values(ProblemResults(model)) dcp_values = - dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }("")] + dcp_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine}( + "", + )] dcp_objective = model.internal.container.optimizer_stats.objective_value @test isapprox(dcp_objective, ptdf_objective; atol = 0.1) @@ -306,7 +314,10 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!( + template_uc, + DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless), + ) model_ref = DecisionModel( template_uc, @@ -320,10 +331,12 @@ end ref_vars = get_variable_values(ProblemResults(model_ref)) ref_values = ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, Line}("")] - hvdc_ref_values = - ref_vars[PowerSimulations.VariableKey{FlowActivePowerVariable, TwoTerminalHVDCLine }( - "", - )] + hvdc_ref_values = ref_vars[PowerSimulations.VariableKey{ + FlowActivePowerVariable, + TwoTerminalHVDCLine, + }( + "", + )] ref_objective = model_ref.internal.container.optimizer_stats.objective_value ref_total_gen = sum( sum.( @@ -337,7 +350,10 @@ end ), ), ) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine , HVDCP2PDispatch)) + set_device_model!( + template_uc, + DeviceModel(TwoTerminalHVDCLine, HVDCP2PDispatch), + ) model = DecisionModel( template_uc, @@ -355,13 +371,13 @@ end )] hvdc_ft_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] hvdc_tf_no_loss_values = no_loss_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] @@ -409,13 +425,13 @@ end dispatch_vars = get_variable_values(ProblemResults(model_wl)) dispatch_values_ft = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerFromToVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] dispatch_values_tf = dispatch_vars[PowerSimulations.VariableKey{ FlowActivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, }( "", )] @@ -452,8 +468,8 @@ end PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "ub"), PSI.ConstraintKey(RateLimitConstraint, Transformer2W, "lb"), PSI.ConstraintKey(RateLimitConstraint, TapTransformer, "lb"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -473,7 +489,7 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -488,7 +504,7 @@ end @test check_flow_variable_values( model_m, FlowActivePowerVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_max, ) @@ -570,8 +586,8 @@ end PSI.ConstraintKey(RateLimitConstraintToFrom, Transformer2W), PSI.ConstraintKey(RateLimitConstraintFromTo, TapTransformer), PSI.ConstraintKey(RateLimitConstraintToFrom, TapTransformer), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "ub"), - PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine , "lb"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "ub"), + PSI.ConstraintKey(FlowRateConstraint, TwoTerminalHVDCLine, "lb"), ] system = PSB.build_system(PSITestSystems, "c_sys14_dc") @@ -589,7 +605,7 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine , HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT @@ -606,7 +622,7 @@ end model_m, FlowActivePowerVariable, FlowReactivePowerToFromVariable, - TwoTerminalHVDCLine , + TwoTerminalHVDCLine, "DCLine3", limits_max, ) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index 6ca37ba9e8..c75dbf5e75 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -1,30 +1,26 @@ @testset "HVDC System Tests" begin - sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc"; force_build = true) + sys_5 = build_system(PSISystems, "sys10_pjm_ac_dc") template_uc = ProblemTemplate(NetworkModel( - DCPPowerModel, - #use_slacks=true, - PTDF_matrix=PTDF(sys_5), - #duals=[CopperPlateBalanceConstraint], -)) + DCPPowerModel, + #use_slacks=true, + #PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], + )) #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) - set_device_model!(template_uc, DeviceModel( - Line, - StaticBranch, - #duals=[NetworkFlowConstraint] - )) - set_device_model!(template_uc, DeviceModel( - InterconnectingConverter, - LossLessConverter, - #duals=[NetworkFlowConstraint] - )) - set_device_model!(template_uc, DeviceModel( - TModelHVDCLine , - LossLessLine, - #duals=[NetworkFlowConstraint] - )) + set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) + set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) + set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) + model = DecisionModel( + template_uc, + sys_5; + name="UC", + optimizer=HiGHS_optimizer, + direct_mode_optimizer=true, + ) + @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT end diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index 8401a62834..6f9a3f7921 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network = CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network = StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine , HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) return template end From 28098bf3ad81ebe38d494e95419fb5335a455079 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:25:51 -0700 Subject: [PATCH 45/73] updates to expression types --- src/PowerSimulations.jl | 4 +- src/core/expressions.jl | 3 +- src/core/optimization_container.jl | 8 ++-- .../device_constructors/branch_constructor.jl | 18 ++++---- .../hvdcsystems_constructor.jl | 7 ++-- .../hydrogeneration_constructor.jl | 36 ++++++++-------- .../device_constructors/load_constructor.jl | 16 +++---- .../regulationdevice_constructor.jl | 6 +-- .../renewablegeneration_constructor.jl | 8 ++-- .../thermalgeneration_constructor.jl | 42 +++++++++---------- src/devices_models/devices/AC_branches.jl | 4 +- src/devices_models/devices/HVDCsystems.jl | 36 ++-------------- .../devices/common/add_to_expression.jl | 32 +++++++------- .../devices/thermal_generation.jl | 3 +- src/network_models/hvdc_networks.jl | 33 +++++++++++++++ src/network_models/network_constructor.jl | 28 ++++++++----- src/network_models/powermodels_interface.jl | 4 +- test/test_device_hvdc.jl | 2 +- 18 files changed, 149 insertions(+), 141 deletions(-) create mode 100644 src/network_models/hvdc_networks.jl diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 3910f56696..b0c6c46281 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -337,8 +337,7 @@ export SystemBalanceExpressions export RangeConstraintLBExpressions export RangeConstraintUBExpressions export CostExpressions -export ActivePowerBalanceAC -export ActivePowerBalanceDC +export ActivePowerBalance export ReactivePowerBalance export EmergencyUp export EmergencyDown @@ -555,6 +554,7 @@ include("network_models/powermodels_interface.jl") include("network_models/pm_translator.jl") include("network_models/network_slack_variables.jl") include("network_models/area_balance_model.jl") +include("network_models/hvdc_networks.jl") include("initial_conditions/initialization.jl") diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 1c64a4854e..89c6a8df15 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -33,8 +33,7 @@ abstract type SystemBalanceExpressions <: ExpressionType end abstract type RangeConstraintLBExpressions <: ExpressionType end abstract type RangeConstraintUBExpressions <: ExpressionType end abstract type CostExpressions <: ExpressionType end -struct ActivePowerBalanceAC <: SystemBalanceExpressions end -struct ActivePowerBalanceDC <: SystemBalanceExpressions end +struct ActivePowerBalance <: SystemBalanceExpressions end struct ReactivePowerBalance <: SystemBalanceExpressions end struct EmergencyUp <: ExpressionType end struct EmergencyDown <: ExpressionType end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 4b4f3103c9..ee32666f4f 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -414,9 +414,9 @@ function _make_system_expressions!( time_steps = get_time_steps(container) ac_bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), ExpressionKey(ReactivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), @@ -433,9 +433,9 @@ function _make_system_expressions!( time_steps = get_time_steps(container) ac_bus_numbers = collect(Iterators.flatten(values(subnetworks))) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus) => + ExpressionKey(ActivePowerBalance, PSY.ACBus) => _make_container_array(ac_bus_numbers, time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), ) return diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index f1961b215f..c006c6ddcc 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -432,7 +432,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -492,7 +492,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, U()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -534,7 +534,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerToFromVariable, devices, model, @@ -542,7 +542,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerFromToVariable, devices, model, @@ -550,7 +550,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, HVDCLosses, devices, model, @@ -589,7 +589,7 @@ function construct_device!( add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerToFromVariable, devices, model, @@ -597,7 +597,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerFromToVariable, devices, model, @@ -661,7 +661,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, @@ -686,7 +686,7 @@ function construct_device!( add_variables!(container, PhaseShifterAngle, devices, PhaseAngleControl()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PhaseShifterAngle, devices, model, diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 48c0a6f5ed..71cac7d576 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -9,7 +9,7 @@ function construct_device!( add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -17,7 +17,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceDC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -36,7 +36,6 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) - add_constraints!(container, NodalBalanceActiveConstraint, devices, model, S) return end @@ -51,7 +50,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) add_to_expression!( container, - ActivePowerBalanceDC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, diff --git a/src/devices_models/device_constructors/hydrogeneration_constructor.jl b/src/devices_models/device_constructors/hydrogeneration_constructor.jl index 04336ec9ec..a2483f8e70 100644 --- a/src/devices_models/device_constructors/hydrogeneration_constructor.jl +++ b/src/devices_models/device_constructors/hydrogeneration_constructor.jl @@ -17,7 +17,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -61,7 +61,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -92,7 +92,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -201,7 +201,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -298,7 +298,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -401,7 +401,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -513,7 +513,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -637,7 +637,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroDispatchReservoirStorage()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -734,7 +734,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -841,7 +841,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -930,7 +930,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -938,7 +938,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ReactivePowerVariable, devices, model, @@ -1038,7 +1038,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, D()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1159,7 +1159,7 @@ function construct_device!( add_variables!(container, EnergyOutput, devices, HydroCommitmentReservoirStorage()) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1167,7 +1167,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ReactivePowerVariable, devices, model, @@ -1295,7 +1295,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -1408,7 +1408,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerInVariable, devices, model, @@ -1416,7 +1416,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerOutVariable, devices, model, diff --git a/src/devices_models/device_constructors/load_constructor.jl b/src/devices_models/device_constructors/load_constructor.jl index 67efdd744c..61af8d4198 100644 --- a/src/devices_models/device_constructors/load_constructor.jl +++ b/src/devices_models/device_constructors/load_constructor.jl @@ -18,7 +18,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -97,7 +97,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -157,7 +157,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -229,7 +229,7 @@ function construct_device!( # Add Variables to expressions add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -283,7 +283,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -314,7 +314,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -354,7 +354,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -388,7 +388,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/regulationdevice_constructor.jl b/src/devices_models/device_constructors/regulationdevice_constructor.jl index 18df09955c..b4535006ff 100644 --- a/src/devices_models/device_constructors/regulationdevice_constructor.jl +++ b/src/devices_models/device_constructors/regulationdevice_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -66,7 +66,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -115,7 +115,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 58a674f81b..34a8edd469 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -22,7 +22,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -137,7 +137,7 @@ function construct_device!( # Expression add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -228,7 +228,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -258,7 +258,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index e104f92b49..9ad1f89e24 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -10,7 +10,7 @@ function construct_device!( add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerTimeSeriesParameter, devices, model, @@ -61,7 +61,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -179,7 +179,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -277,7 +277,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -384,7 +384,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -473,7 +473,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -577,7 +577,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -665,7 +665,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -768,7 +768,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, ActivePowerVariable, devices, model, @@ -871,7 +871,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1008,12 +1008,13 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, network_model, ) + add_to_expression!( container, ActivePowerBalanceAC, @@ -1023,7 +1024,6 @@ function construct_device!( network_model, ) - add_expressions!(container, ProductionCostExpression, devices, model) add_to_expression!( @@ -1137,7 +1137,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1249,7 +1249,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1364,7 +1364,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalance, + ActivePowerBalanceAC, OnVariable, devices, model, @@ -1464,7 +1464,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1560,7 +1560,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1579,7 +1579,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, @@ -1595,7 +1595,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, @@ -1685,7 +1685,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1694,7 +1694,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnStatusParameter, devices, model, diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index 31575439cb..a5f5cd4252 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -300,7 +300,7 @@ function add_constraints!( time_steps, ) nodal_balance_expressions = - get_expression(container, ActivePowerBalanceAC(), StandardPTDFModel) + get_expression(container, ActivePowerBalance(), StandardPTDFModel) flow_variables = get_variable(container, FlowActivePowerVariable(), B) jump_model = get_jump_model(container) @@ -339,7 +339,7 @@ function add_constraints!( branches, time_steps, ) - nodal_balance_expressions = get_expression(container, ActivePowerBalanceAC(), PSY.ACBus) + nodal_balance_expressions = get_expression(container, ActivePowerBalance(), PSY.ACBus) flow_variables = get_variable(container, FlowActivePowerVariable(), T) angle_variables = get_variable(container, PhaseShifterAngle(), T) jump_model = get_jump_model(container) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 184871b1c1..93a014c9dc 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -65,10 +65,10 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceDC, + T <: ActivePowerBalance, U <: FlowActivePowerVariable, V <: PSY.TModelHVDCLine, - W <: AbstractDeviceFormulation, + W <: LossLessLine, X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) @@ -102,7 +102,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{X}, ) where { - T <: ActivePowerBalanceDC, + T <: ActivePowerBalance, U <: ActivePowerVariable, V <: PSY.InterconnectingConverter, W <: AbstractDeviceFormulation, @@ -121,33 +121,3 @@ function add_to_expression!( end return end - - -# This method might need to be moved to support Meshed HVDC to the network constructor file -function add_constraints!( - container::OptimizationContainer, - ::Type{NodalBalanceActiveConstraint}, - devices::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, - model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::Type{<:PM.AbstractActivePowerModel}, -) - time_steps = get_time_steps(container) - dc_expr = get_expression(container, ActivePowerBalanceDC(), PSY.DCBus) - balance_constraint = add_constraints_container!( - container, - NodalBalanceActiveConstraint(), - PSY.DCBus, - axes(dc_expr)[1], - time_steps, - ) - for d in devices - dc_bus_no = PSY.get_number(PSY.get_dc_bus(d)) - for t in time_steps - balance_constraint[dc_bus_no, t] = JuMP.@constraint( - get_jump_model(container), - dc_expr[dc_bus_no, t] == 0 - ) - end - end - return -end diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index ecebb091dd..461307470f 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -109,7 +109,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -172,7 +172,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::Type{StandardPTDFModel}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: HVDCLosses, V <: PSY.TwoTerminalHVDCLine, W <: HVDCP2PDispatch, @@ -205,7 +205,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerFromToVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -238,7 +238,7 @@ function add_to_expression!( ::DeviceModel{V, W}, ::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerToFromVariable, V <: PSY.Branch, W <: AbstractDeviceFormulation, @@ -331,7 +331,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -362,7 +362,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{CopperPlatePowerModel}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -392,7 +392,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{CopperPlatePowerModel}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -457,7 +457,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnStatusParameter, V <: PSY.ThermalGen, W <: AbstractDeviceFormulation, @@ -489,7 +489,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: VariableType, V <: PSY.StaticInjection, W <: AbstractDeviceFormulation, @@ -527,7 +527,7 @@ function add_to_expression!( device_model::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: OnVariable, V <: PSY.ThermalGen, W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, @@ -568,9 +568,9 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{X}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: FlowActivePowerVariable, - V <: PSY.Branch, + V <: PSY.ACBranch, W <: AbstractBranchFormulation, X <: PM.AbstractActivePowerModel, } @@ -605,7 +605,7 @@ function add_to_expression!( ::DeviceModel{V, W}, network_model::NetworkModel{StandardPTDFModel}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: PhaseShifterAngle, V <: PhaseAngleControl, W <: StandardPTDFModel, @@ -864,7 +864,7 @@ function add_to_expression!( ::PSY.System, network_model::NetworkModel{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: Union{CopperPlatePowerModel, StandardPTDFModel}, } @@ -888,7 +888,7 @@ function add_to_expression!( sys::PSY.System, ::NetworkModel{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractActivePowerModel, } @@ -912,7 +912,7 @@ function add_to_expression!( sys::PSY.System, ::NetworkModel{W}, ) where { - T <: ActivePowerBalanceAC, + T <: ActivePowerBalance, U <: Union{SystemBalanceSlackUp, SystemBalanceSlackDown}, W <: PM.AbstractPowerModel, } diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index 0f2aaea699..2d12a46ecc 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -27,6 +27,7 @@ get_variable_upper_bound(::PowerAboveMinimumVariable, d::PSY.ThermalGen, ::Abstr ############## ReactivePowerVariable, ThermalGen #################### get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false +get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false get_variable_warm_start_value(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_reactive_power(d) get_variable_lower_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).max @@ -57,7 +58,7 @@ get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::AbstractCompactUnitCommitment) = 0.0 get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionUB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = PSY.get_active_power_limits(d).max - PSY.get_active_power_limits(d).min get_expression_multiplier(::OnStatusParameter, ::ActivePowerRangeExpressionLB, d::PSY.ThermalGen, ::ThermalCompactDispatch) = 0.0 -get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalanceAC, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min +get_expression_multiplier(::OnStatusParameter, ::ActivePowerBalance, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min #################### Initial Conditions for models ############### initial_condition_default(::DeviceStatus, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_status(d) diff --git a/src/network_models/hvdc_networks.jl b/src/network_models/hvdc_networks.jl new file mode 100644 index 0000000000..43544864c3 --- /dev/null +++ b/src/network_models/hvdc_networks.jl @@ -0,0 +1,33 @@ +function add_constraints!( + container::OptimizationContainer, + ::Type{NodalBalanceActiveConstraint}, + sys::PSY.System, + model::NetworkModel{V}, +) where { + V <: PM.AbstractPowerModel, +} + dc_buses = PSY.get_components(PSY.DCBus, sys) + if isempty(dc_buses) + return + end + + time_steps = get_time_steps(container) + dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) + balance_constraint = add_constraints_container!( + container, + NodalBalanceActiveConstraint(), + PSY.DCBus, + axes(dc_expr)[1], + time_steps, + ) + for d in dc_buses + dc_bus_no = PSY.get_number(d) + for t in time_steps + balance_constraint[dc_bus_no, t] = JuMP.@constraint( + get_jump_model(container), + dc_expr[dc_bus_no, t] == 0 + ) + end + end + return +end diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 05a87abe7f..0e5f953e4a 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -10,7 +10,7 @@ function construct_network!( add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -42,7 +42,7 @@ function construct_network!( area_balance( container, - ExpressionKey(ActivePowerBalanceAC, PSY.ACBus), + ExpressionKey(ActivePowerBalance, PSY.ACBus), area_mapping, branches, ) @@ -62,7 +62,7 @@ function construct_network!( add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -71,7 +71,6 @@ function construct_network!( end add_constraints!(container, CopperPlateBalanceConstraint, sys, model) - add_constraint_dual!(container, sys, model) return end @@ -94,7 +93,6 @@ function construct_network!( add_constraints!(container, CopperPlateBalanceConstraint, sys, model) add_constraint_dual!(container, sys, model) - return end @@ -119,7 +117,7 @@ function construct_network!( add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -130,6 +128,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION powermodels_network!(container, T, sys, template, instantiate_model) + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -158,7 +158,7 @@ function construct_network!( add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -182,6 +182,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -210,7 +212,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -218,7 +220,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -245,6 +247,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) @@ -272,7 +276,7 @@ function construct_network!( add_variables!(container, SystemBalanceSlackDown, sys, T) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackUp, sys, model, @@ -280,7 +284,7 @@ function construct_network!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, @@ -307,6 +311,8 @@ function construct_network!( @debug "Building the $T network with $instantiate_model method" _group = LOG_GROUP_NETWORK_CONSTRUCTION + #Constraints in case the model has DC Buses + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) powermodels_network!(container, T, sys, template, instantiate_model) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 23c75e651a..8046d74ad6 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -295,7 +295,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(bus.number)"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ bus.number, t, ] @@ -326,7 +326,7 @@ function powermodels_network!( for t in time_steps, bus in buses pm_data["nw"]["$(t)"]["bus"]["$(PSY.get_number(bus))"]["inj_p"] = - container.expressions[ExpressionKey(ActivePowerBalanceAC, PSY.ACBus)][ + container.expressions[ExpressionKey(ActivePowerBalance, PSY.ACBus)][ PSY.get_number(bus), t, ] diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index c75dbf5e75..b50325652c 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -7,7 +7,6 @@ #duals=[CopperPlateBalanceConstraint], )) - #set_device_model!(template_uc, ThermalMultiStart, ThermalCompactUnitCommitment) set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) @@ -23,4 +22,5 @@ direct_mode_optimizer=true, ) @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT + end From ffcc583128719b2d5d3a3bc03757770db22af84b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 09:25:33 -0700 Subject: [PATCH 46/73] remove duplicate --- src/devices_models/devices/thermal_generation.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devices_models/devices/thermal_generation.jl b/src/devices_models/devices/thermal_generation.jl index 2d12a46ecc..3e8b333652 100644 --- a/src/devices_models/devices/thermal_generation.jl +++ b/src/devices_models/devices/thermal_generation.jl @@ -27,7 +27,6 @@ get_variable_upper_bound(::PowerAboveMinimumVariable, d::PSY.ThermalGen, ::Abstr ############## ReactivePowerVariable, ThermalGen #################### get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false -get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ThermalGen}, ::AbstractThermalFormulation) = false get_variable_warm_start_value(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_reactive_power(d) get_variable_lower_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).min get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ThermalGen, ::AbstractThermalFormulation) = PSY.get_active_power_limits(d).max From ab17ae632a31539bbdf1deeceaf5ce09ad601985 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 11:28:07 -0700 Subject: [PATCH 47/73] fix tests --- .../thermalgeneration_constructor.jl | 9 +-- src/devices_models/devices/HVDCsystems.jl | 36 +++++++++- .../devices/TwoTerminalDC_branches.jl | 71 +++++++++++-------- src/network_models/hvdc_networks.jl | 12 ++-- src/network_models/pm_translator.jl | 2 +- test/test_device_hvdc.jl | 12 +--- 6 files changed, 87 insertions(+), 55 deletions(-) diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 9ad1f89e24..2fc70d845f 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1692,14 +1692,7 @@ function construct_device!( network_model, ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - S, - ) + add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 93a014c9dc..c97cafbc74 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -105,7 +105,7 @@ function add_to_expression!( T <: ActivePowerBalance, U <: ActivePowerVariable, V <: PSY.InterconnectingConverter, - W <: AbstractDeviceFormulation, + W <: AbstractConverterFormulation, X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) @@ -121,3 +121,37 @@ function add_to_expression!( end return end + +function add_to_expression!( + ::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalance, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractConverterFormulation, + X <: CopperPlatePowerModel, +} + return +end + +function add_to_expression!( + ::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::IS.FlattenIteratorWrapper{V}, + ::DeviceModel{V, W}, + ::Type{X}, +) where { + T <: ActivePowerBalance, + U <: ActivePowerVariable, + V <: PSY.InterconnectingConverter, + W <: AbstractConverterFormulation, + X <: Union{PTDFPowerModel, StandardPTDFModel}, +} + return +end diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index f57a6e498e..1945ccb172 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,32 +1,37 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.DCBranch}, ::AbstractP2PDCLineFormulation) = false +get_variable_binary(_, ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation) = false get_variable_binary( ::FlowActivePowerVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = false get_variable_binary( ::HVDCFlowDirectionVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = true -get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.DCBranch}, _) = NaN +get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, _) = + NaN get_variable_multiplier( ::FlowActivePowerFromToVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, - ::Type{<:PSY.DCBranch}, + ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation, ) = 1.0 -function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) +function get_variable_multiplier( + ::HVDCLosses, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PDispatch, +) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 if l1 == 0.0 && l0 == 0.0 @@ -36,27 +41,37 @@ function get_variable_multiplier(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatc end end -get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUnbounded) = - nothing +get_variable_lower_bound( + ::FlowActivePowerVariable, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PUnbounded, +) = nothing -get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.DCBranch, ::HVDCP2PUnbounded) = - nothing +get_variable_upper_bound( + ::FlowActivePowerVariable, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PUnbounded, +) = nothing get_variable_lower_bound( ::FlowActivePowerVariable, - d::PSY.DCBranch, + d::PSY.TwoTerminalHVDCLine, ::AbstractP2PDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, - d::PSY.DCBranch, + d::PSY.TwoTerminalHVDCLine, ::AbstractP2PDCLineFormulation, ) = nothing -get_variable_lower_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) = 0.0 +get_variable_lower_bound(::HVDCLosses, d::PSY.TwoTerminalHVDCLine, ::HVDCP2PDispatch) = 0.0 -function get_variable_upper_bound(::HVDCLosses, d::PSY.DCBranch, ::HVDCP2PDispatch) +function get_variable_upper_bound( + ::HVDCLosses, + d::PSY.TwoTerminalHVDCLine, + ::HVDCP2PDispatch, +) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 if l1 == 0.0 && l0 == 0.0 @@ -69,14 +84,14 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.DCBranch, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} return Dict{String, Any}() end @@ -120,16 +135,16 @@ end add_constraints!( ::OptimizationContainer, ::Type{<:Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom}}, - ::IS.FlattenIteratorWrapper{<:PSY.DCBranch}, - ::DeviceModel{<:PSY.DCBranch, HVDCP2PUnbounded}, + ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, ::NetworkModel{<:PM.AbstractPowerModel}, ) = nothing add_constraints!( ::OptimizationContainer, ::Type{FlowRateConstraint}, - ::IS.FlattenIteratorWrapper{<:PSY.DCBranch}, - ::DeviceModel{<:PSY.DCBranch, HVDCP2PUnbounded}, + ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, ::NetworkModel{<:PM.AbstractPowerModel}, ) = nothing @@ -139,7 +154,7 @@ function add_constraints!( devices::Union{Vector{U}, IS.FlattenIteratorWrapper{U}}, ::DeviceModel{U, HVDCP2PLossless}, ::NetworkModel{<:PM.AbstractPowerModel}, -) where {T <: FlowRateConstraint, U <: PSY.DCBranch} +) where {T <: FlowRateConstraint, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -170,7 +185,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{T}, model::DeviceModel{T, HVDCP2PLossless}, network_model::NetworkModel{CopperPlatePowerModel}, -) where {T <: PSY.DCBranch} +) 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) @@ -197,7 +212,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, -) where {T <: FlowRateConstraintFromTo, U <: PSY.DCBranch} +) where {T <: FlowRateConstraintFromTo, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -228,7 +243,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, -) where {T <: FlowRateConstraintToFrom, U <: PSY.DCBranch} +) where {T <: FlowRateConstraintToFrom, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -259,7 +274,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{U}, ::DeviceModel{U, HVDCP2PDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, -) where {T <: HVDCDirection, U <: PSY.DCBranch} +) where {T <: HVDCDirection, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] @@ -307,7 +322,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{T}, ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, -) where {T <: PSY.DCBranch} +) where {T <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] tf_var = get_variable(container, FlowActivePowerToFromVariable(), T) @@ -390,7 +405,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{T}, ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, -) where {T <: PSY.DCBranch} +) where {T <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) names = [PSY.get_name(d) for d in devices] losses = get_variable(container, HVDCLosses(), T) diff --git a/src/network_models/hvdc_networks.jl b/src/network_models/hvdc_networks.jl index 43544864c3..555c6b5858 100644 --- a/src/network_models/hvdc_networks.jl +++ b/src/network_models/hvdc_networks.jl @@ -3,16 +3,14 @@ function add_constraints!( ::Type{NodalBalanceActiveConstraint}, sys::PSY.System, model::NetworkModel{V}, -) where { - V <: PM.AbstractPowerModel, -} +) where {V <: PM.AbstractPowerModel} dc_buses = PSY.get_components(PSY.DCBus, sys) if isempty(dc_buses) return end time_steps = get_time_steps(container) - dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) + dc_expr = get_expression(container, ActivePowerBalance(), PSY.DCBus) balance_constraint = add_constraints_container!( container, NodalBalanceActiveConstraint(), @@ -23,10 +21,8 @@ function add_constraints!( for d in dc_buses dc_bus_no = PSY.get_number(d) for t in time_steps - balance_constraint[dc_bus_no, t] = JuMP.@constraint( - get_jump_model(container), - dc_expr[dc_bus_no, t] == 0 - ) + balance_constraint[dc_bus_no, t] = + JuMP.@constraint(get_jump_model(container), dc_expr[dc_bus_no, t] == 0) end end return diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index ccf6e08c5f..65bd1a4861 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -344,7 +344,7 @@ end function get_branch_to_pm( ix::Int, branch::PSY.TwoTerminalHVDCLine, - ::Type{<:AbstractBranchFormulation}, + ::Type{<:AbstractP2PDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, ) PM_branch = Dict{String, Any}( diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index b50325652c..1d4548c714 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -13,14 +13,8 @@ set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) - - model = DecisionModel( - template_uc, - sys_5; - name="UC", - optimizer=HiGHS_optimizer, - direct_mode_optimizer=true, - ) + model = DecisionModel(template_uc, sys_5; name="UC", optimizer=HiGHS_optimizer) @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT - + moi_tests(model, 1656, 0, 1536, 816, 888, true) + @test solve!(model) == RunStatus.SUCCESSFUL end From 349a6821e39cba14e320b82054ac6b2b76001f8b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 10:36:00 -0700 Subject: [PATCH 48/73] add missing function calls --- .../device_constructors/hvdcsystems_constructor.jl | 3 +++ src/devices_models/devices/HVDCsystems.jl | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 71cac7d576..12947700df 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -36,6 +36,9 @@ function construct_device!( ::Type{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) + add_feedforward_constraints!(container, model, devices) + objective_function!(container, devices, model, S) + add_constraint_dual!(container, sys, model) return end diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index c97cafbc74..f0323ed564 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -155,3 +155,12 @@ function add_to_expression!( } return end + +function objective_function!( + ::OptimizationContainer, + ::IS.FlattenIteratorWrapper{PSY.InterconnectingConverter}, + ::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, + ::Type{<:PM.AbstractPowerModel}, +) + return +end From 17c5dc07da6dba040070463b02650dd611a69427 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 23 Feb 2023 10:38:09 -0700 Subject: [PATCH 49/73] remove unused arguments --- .../device_constructors/hvdcsystems_constructor.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 12947700df..e09af640b7 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -64,8 +64,8 @@ function construct_device!( end function construct_device!( - container::OptimizationContainer, - sys::PSY.System, + ::OptimizationContainer, + ::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::NetworkModel{S}, From 257cef64f910d700d524eb01f4c53b4d41707e95 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Jun 2023 12:19:33 -0700 Subject: [PATCH 50/73] fix expression additions --- src/devices_models/devices/HVDCsystems.jl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index f0323ed564..01e848d94c 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -109,14 +109,21 @@ function add_to_expression!( X <: PM.AbstractPowerModel, } variable = get_variable(container, U(), V) - expression = get_expression(container, T(), PSY.DCBus) + expression_dc = get_expression(container, T(), PSY.DCBus) + expression_ac = get_expression(container, T(), PSY.ACBus) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) - bus_number = PSY.get_number(PSY.get_dc_bus(d)) + bus_number_dc = PSY.get_number(PSY.get_dc_bus(d)) + bus_number_ac = PSY.get_number(PSY.get_bus(d)) + _add_to_jump_expression!( + expression_ac[bus_number_ac, t], + variable[name, t], + 1.0, + ) _add_to_jump_expression!( - expression[bus_number, t], + expression_dc[bus_number_dc, t], variable[name, t], - get_variable_multiplier(U(), V, W()), + -1.0, ) end return From 3d664ccd6975c518238ba3c261c10bb2caaafdcc Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Jun 2023 12:27:45 -0700 Subject: [PATCH 51/73] fix duplicate call --- .../device_constructors/hvdcsystems_constructor.jl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index e09af640b7..00493a9923 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -15,15 +15,6 @@ function construct_device!( model, S, ) - add_to_expression!( - container, - ActivePowerBalance, - ActivePowerVariable, - devices, - model, - S, - ) - add_feedforward_arguments!(container, model, devices) return end From c7226a86222c925a7a592bf0ecd7ad6c2c0f263a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 13:27:00 -0700 Subject: [PATCH 52/73] update code --- src/devices_models/devices/common/add_to_expression.jl | 2 +- src/network_models/pm_translator.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 461307470f..52edcc63f2 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -645,7 +645,7 @@ function add_to_expression!( ) where { T <: ActivePowerBalance, U <: FlowActivePowerVariable, - V <: PSY.Branch, + V <: PSY.ACBranch, W <: AbstractBranchFormulation, } inter_network_branches = V[] diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 77e90409ea..f1fcf54e57 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -2,11 +2,11 @@ const PM_MAP_TUPLE = NamedTuple{(:from_to, :to_from), Tuple{Tuple{Int, Int, Int}, Tuple{Int, Int, Int}}} const PM_BUSTYPES = Dict{PSY.ACBusTypes, Int}( - PSY.BusTypes.ISOLATED => 4, - PSY.BusTypes.PQ => 1, - PSY.BusTypes.PV => 2, - PSY.BusTypes.REF => 3, - PSY.BusTypes.SLACK => 3, + PSY.ACBusTypes.ISOLATED => 4, + PSY.ACBusTypes.PQ => 1, + PSY.ACBusTypes.PV => 2, + PSY.ACBusTypes.REF => 3, + PSY.ACBusTypes.SLACK => 3, ) struct PMmap From aa2c8d2d49c06e807669098f3adcccbc4b8617b9 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 3 Jul 2023 13:31:20 -0700 Subject: [PATCH 53/73] update bustypes --- src/network_models/pm_translator.jl | 2 +- src/utils/powersystems_utils.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index f1fcf54e57..635d616ce4 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -425,7 +425,7 @@ function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.ACBus}) PMmap_buses = Dict{Int, PSY.ACBus}() for bus in buses - if PSY.get_bustype(bus) == PSY.BusTypes.ISOLATED + if PSY.get_bustype(bus) == PSY.ACBusTypes.ISOLATED continue end number = PSY.get_number(bus) diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index bd3ade1e1e..6dbfabc780 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -20,7 +20,7 @@ function get_available_components( ::Nothing = nothing, ) return PSY.get_components( - x -> PSY.get_bustype(x) != PSY.BusTypes.ISOLATED, + x -> PSY.get_bustype(x) != PSY.ACBusTypes.ISOLATED, PSY.Bus, sys, ) From a096566c00b4e0500cc8bd7e35b6ebe75491a563 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 5 Jul 2023 13:47:03 -0600 Subject: [PATCH 54/73] fix some types --- src/core/network_model.jl | 8 ++++---- src/core/optimization_container.jl | 9 +++++---- .../device_constructors/hvdcsystems_constructor.jl | 2 +- .../thermalgeneration_constructor.jl | 10 +++++----- src/network_models/copperplate_model.jl | 2 +- src/network_models/network_constructor.jl | 10 +++++----- src/utils/powersystems_utils.jl | 4 ++-- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/core/network_model.jl b/src/core/network_model.jl index 07b514fd76..426a74643f 100644 --- a/src/core/network_model.jl +++ b/src/core/network_model.jl @@ -30,7 +30,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel} use_slacks::Bool PTDF_matrix::Union{Nothing, PNM.PowerNetworkMatrix} subnetworks::Dict{Int, Set{Int}} - bus_area_map::Dict{PSY.Bus, Int} + bus_area_map::Dict{PSY.ACBus, Int} duals::Vector{DataType} function NetworkModel( @@ -41,7 +41,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel} duals = Vector{DataType}(), ) where {T <: PM.AbstractPowerModel} _check_pm_formulation(T) - new{T}(use_slacks, PTDF_matrix, subnetworks, Dict{PSY.Bus, Int}(), duals) + new{T}(use_slacks, PTDF_matrix, subnetworks, Dict{PSY.ACBus, Int}(), duals) end end @@ -113,7 +113,7 @@ function _assign_subnetworks_to_buses( ) where {T <: Union{CopperPlatePowerModel, StandardPTDFModel}} subnetworks = model.subnetworks temp_bus_map = Dict{Int, Int}() - for bus in get_available_components(PSY.Bus, sys) + for bus in get_available_components(PSY.ACBus, sys) bus_no = PSY.get_number(bus) if haskey(temp_bus_map, bus_no) model.bus_area_map[bus] = temp_bus_map[bus_no] @@ -137,7 +137,7 @@ _assign_subnetworks_to_buses( function get_reference_bus( model::NetworkModel{T}, - b::PSY.Bus, + b::PSY.ACBus, )::Int where {T <: PM.AbstractPowerModel} if isempty(model.bus_area_map) return first(keys(model.subnetworks)) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index ee32666f4f..8acd6cfc78 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -449,7 +449,7 @@ function _make_system_expressions!( time_steps = get_time_steps(container) subnetworks_ref_buses = collect(keys(subnetworks)) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.System) => + ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(subnetworks_ref_buses, time_steps), ) return @@ -464,9 +464,9 @@ function _make_system_expressions!( time_steps = get_time_steps(container) subnetworks = collect(keys(subnetworks)) container.expressions = Dict( - ExpressionKey(ActivePowerBalanceAC, PSY.System) => + ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(subnetworks, time_steps), - ExpressionKey(ActivePowerBalanceDC, PSY.DCBus) => + ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), ) return @@ -476,6 +476,7 @@ function initialize_system_expressions!( container::OptimizationContainer, ::Type{T}, subnetworks::Dict{Int, Set{Int}}, + system::PSY.System ) where {T <: PM.AbstractPowerModel} dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)] _make_system_expressions!(container, subnetworks, dc_bus_numbers, T) @@ -485,7 +486,7 @@ end function build_impl!(container::OptimizationContainer, template, sys::PSY.System) transmission = get_network_formulation(template) transmission_model = get_network_model(template) - initialize_system_expressions!(container, transmission, transmission_model.subnetworks) + initialize_system_expressions!(container, transmission, transmission_model.subnetworks, sys) # Order is required for device_model in values(template.devices) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index 00493a9923..fee96955c6 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -77,7 +77,7 @@ function construct_device!( add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) add_to_expression!( container, - ActivePowerBalanceDC, + ActivePowerBalance, FlowActivePowerVariable, devices, model, diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 2fc70d845f..7d911c49d1 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1017,7 +1017,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnVariable, devices, model, @@ -1145,7 +1145,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnVariable, devices, model, @@ -1257,7 +1257,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnVariable, devices, model, @@ -1356,7 +1356,7 @@ function construct_device!( add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, PowerAboveMinimumVariable, devices, model, @@ -1364,7 +1364,7 @@ function construct_device!( ) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, OnVariable, devices, model, diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 017f58b47a..3d4c12b01b 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -9,7 +9,7 @@ function add_constraints!( V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel}, } time_steps = get_time_steps(container) - expressions = get_expression(container, ActivePowerBalanceAC(), U) + expressions = get_expression(container, ActivePowerBalance(), U) subnets = collect(keys(model.subnetworks)) constraint = add_constraints_container!(container, T(), U, subnets, time_steps) for t in time_steps, k in keys(model.subnetworks) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index e4176ec270..51f64cfbb7 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -7,7 +7,7 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) add_to_expression!( container, ActivePowerBalance, @@ -59,7 +59,7 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) add_to_expression!( container, ActivePowerBalance, @@ -114,7 +114,7 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) add_to_expression!( container, ActivePowerBalance, @@ -155,10 +155,10 @@ function construct_network!( if get_use_slacks(model) add_variables!(container, SystemBalanceSlackUp, sys, model) add_variables!(container, SystemBalanceSlackDown, sys, model) - add_to_expression!(container, ActivePowerBalanceAC, SystemBalanceSlackUp, sys, model) + add_to_expression!(container, ActivePowerBalance, SystemBalanceSlackUp, sys, model) add_to_expression!( container, - ActivePowerBalanceAC, + ActivePowerBalance, SystemBalanceSlackDown, sys, model, diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index 6dbfabc780..0e5a33ef08 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -15,13 +15,13 @@ function get_available_components( end function get_available_components( - ::Type{PSY.Bus}, + ::Type{PSY.ACBus}, sys::PSY.System, ::Nothing = nothing, ) return PSY.get_components( x -> PSY.get_bustype(x) != PSY.ACBusTypes.ISOLATED, - PSY.Bus, + PSY.ACBus, sys, ) end From 01bad33d85d7b8e51d5692000d77b26855dc19dc Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 6 Jul 2023 18:08:59 -0600 Subject: [PATCH 55/73] correct PTDF model --- src/core/optimization_container.jl | 12 +++- .../hvdcsystems_constructor.jl | 46 ++----------- src/devices_models/devices/HVDCsystems.jl | 65 +++++++++++++++++-- .../devices/TwoTerminalDC_branches.jl | 3 +- src/network_models/network_constructor.jl | 3 +- src/network_models/pm_translator.jl | 4 +- test/test_device_branch_constructors.jl | 29 +++++---- test/test_device_hvdc.jl | 4 +- 8 files changed, 97 insertions(+), 69 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 8acd6cfc78..d9bfe99af7 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -462,12 +462,15 @@ function _make_system_expressions!( ::Type{T}, ) where {T <: Union{PTDFPowerModel, StandardPTDFModel}} time_steps = get_time_steps(container) + ac_bus_numbers = sort!(collect(Iterators.flatten(values(subnetworks)))) subnetworks = collect(keys(subnetworks)) container.expressions = Dict( ExpressionKey(ActivePowerBalance, PSY.System) => _make_container_array(subnetworks, time_steps), ExpressionKey(ActivePowerBalance, PSY.DCBus) => _make_container_array(dc_bus_numbers, time_steps), + ExpressionKey(ActivePowerBalance, PSY.ACBus) => + _make_container_array(ac_bus_numbers, time_steps), ) return end @@ -476,7 +479,7 @@ function initialize_system_expressions!( container::OptimizationContainer, ::Type{T}, subnetworks::Dict{Int, Set{Int}}, - system::PSY.System + system::PSY.System, ) where {T <: PM.AbstractPowerModel} dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)] _make_system_expressions!(container, subnetworks, dc_bus_numbers, T) @@ -486,7 +489,12 @@ end function build_impl!(container::OptimizationContainer, template, sys::PSY.System) transmission = get_network_formulation(template) transmission_model = get_network_model(template) - initialize_system_expressions!(container, transmission, transmission_model.subnetworks, sys) + initialize_system_expressions!( + container, + transmission, + transmission_model.subnetworks, + sys, + ) # Order is required for device_model in values(template.devices) diff --git a/src/devices_models/device_constructors/hvdcsystems_constructor.jl b/src/devices_models/device_constructors/hvdcsystems_constructor.jl index fee96955c6..cd176bb292 100644 --- a/src/devices_models/device_constructors/hvdcsystems_constructor.jl +++ b/src/devices_models/device_constructors/hvdcsystems_constructor.jl @@ -3,7 +3,7 @@ function construct_device!( sys::PSY.System, ::ArgumentConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::Type{S}, + network_model::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) add_variables!(container, ActivePowerVariable, devices, LossLessConverter()) @@ -13,7 +13,7 @@ function construct_device!( ActivePowerVariable, devices, model, - S, + network_model, ) add_feedforward_arguments!(container, model, devices) return @@ -24,7 +24,7 @@ function construct_device!( sys::PSY.System, ::ModelConstructStage, model::DeviceModel{PSY.InterconnectingConverter, LossLessConverter}, - ::Type{S}, + ::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.InterconnectingConverter, sys) add_feedforward_constraints!(container, model, devices) @@ -38,7 +38,7 @@ function construct_device!( sys::PSY.System, ::ArgumentConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, - ::NetworkModel{S}, + network_model::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.TModelHVDCLine, sys) add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) @@ -48,7 +48,7 @@ function construct_device!( FlowActivePowerVariable, devices, model, - S, + network_model, ) add_feedforward_arguments!(container, model, devices) return @@ -56,45 +56,11 @@ end function construct_device!( ::OptimizationContainer, - ::PSY.System, - ::ModelConstructStage, - model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, - ::NetworkModel{S}, -) where {S <: PM.AbstractActivePowerModel} - devices = get_available_components(PSY.InterconnectingConverter, sys) - error("here") - return -end - -function construct_device!( - container::OptimizationContainer, sys::PSY.System, - ::ArgumentConstructStage, + ::ModelConstructStage, model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, ::NetworkModel{S}, ) where {S <: PM.AbstractActivePowerModel} devices = get_available_components(PSY.TModelHVDCLine, sys) - add_variables!(container, FlowActivePowerVariable, devices, LossLessLine()) - add_to_expression!( - container, - ActivePowerBalance, - FlowActivePowerVariable, - devices, - model, - S, - ) - add_feedforward_arguments!(container, model, devices) - return -end - -function construct_device!( - container::OptimizationContainer, - sys::PSY.System, - ::ModelConstructStage, - model::DeviceModel{PSY.TModelHVDCLine, LossLessLine}, - ::Type{S}, -) where {S <: PM.AbstractActivePowerModel} - - devices = get_available_components(T, sys) return end diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 01e848d94c..a2fe15b82b 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -63,7 +63,7 @@ function add_to_expression!( ::Type{U}, devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, - ::Type{X}, + network_model::NetworkModel{X}, ) where { T <: ActivePowerBalance, U <: FlowActivePowerVariable, @@ -100,7 +100,7 @@ function add_to_expression!( ::Type{U}, devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, - ::Type{X}, + network_model::NetworkModel{X}, ) where { T <: ActivePowerBalance, U <: ActivePowerVariable, @@ -134,8 +134,8 @@ function add_to_expression!( ::Type{T}, ::Type{U}, ::IS.FlattenIteratorWrapper{V}, - ::DeviceModel{V, W}, - ::Type{X}, + devices::DeviceModel{V, W}, + network_model::NetworkModel{X}, ) where { T <: ActivePowerBalance, U <: ActivePowerVariable, @@ -143,16 +143,38 @@ function add_to_expression!( W <: AbstractConverterFormulation, X <: CopperPlatePowerModel, } + + variable = get_variable(container, U(), V) + expression_dc = get_expression(container, T(), PSY.DCBus) + sys_expr = get_expression(container, T(), PSY.System) + for d in devices, t in get_time_steps(container) + name = PSY.get_name(d) + device_bus = PSY.get_bus(d) + ref_bus = get_reference_bus(network_model, device_bus) + bus_number_dc = PSY.get_number(PSY.get_dc_bus(d)) + for t in get_time_steps(container) + _add_to_jump_expression!( + sys_expr[ref_bus, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + _add_to_jump_expression!( + expression_dc[bus_number_dc, t], + variable[name, t], + -1.0, + ) + end + end return end function add_to_expression!( - ::OptimizationContainer, + container::OptimizationContainer, ::Type{T}, ::Type{U}, - ::IS.FlattenIteratorWrapper{V}, + devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, - ::Type{X}, + network_model::NetworkModel{X}, ) where { T <: ActivePowerBalance, U <: ActivePowerVariable, @@ -160,6 +182,35 @@ function add_to_expression!( W <: AbstractConverterFormulation, X <: Union{PTDFPowerModel, StandardPTDFModel}, } + variable = get_variable(container, U(), V) + expression_dc = get_expression(container, T(), PSY.DCBus) + expression_ac = get_expression(container, T(), PSY.ACBus) + sys_expr = get_expression(container, T(), PSY.System) + for d in devices + name = PSY.get_name(d) + device_bus = PSY.get_bus(d) + bus_number_ac = PSY.get_number(device_bus) + ref_bus = get_reference_bus(network_model, device_bus) + bus_number_dc = PSY.get_number(PSY.get_dc_bus(d)) + for t in get_time_steps(container) + _add_to_jump_expression!( + sys_expr[ref_bus, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + _add_to_jump_expression!( + expression_ac[bus_number_ac, t], + variable[name, t], + get_variable_multiplier(U(), V, W()), + ) + _add_to_jump_expression!( + expression_dc[bus_number_dc, t], + variable[name, t], + -1.0, + ) + end + end + return end diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 1945ccb172..5e131dc399 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,5 +1,6 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation) = false +get_variable_binary(_, ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation) = + false get_variable_binary( ::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 51f64cfbb7..6378a34e89 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -69,8 +69,8 @@ function construct_network!( ) objective_function!(container, PSY.System, model) end - add_constraints!(container, CopperPlateBalanceConstraint, sys, model) + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_constraint_dual!(container, sys, model) return end @@ -92,6 +92,7 @@ function construct_network!( add_pm_expr_refs!(container, T, sys) add_constraints!(container, CopperPlateBalanceConstraint, sys, model) + add_constraints!(container, NodalBalanceActiveConstraint, sys, model) add_constraint_dual!(container, sys, model) return end diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 635d616ce4..0704473850 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -384,7 +384,7 @@ function get_branches_to_pm( ::Type{S}, ::Type{T}, branch_template::BranchModelContainer, - start_idx=0, + start_idx = 0, ) where {T <: PSY.ACBranch, S <: PM.AbstractPowerModel} PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() @@ -413,7 +413,7 @@ function get_branches_to_pm( ::Type{PTDFPowerModel}, ::Type{PSY.TwoTerminalHVDCLine}, branch_template::BranchModelContainer, - start_idx=0, + start_idx = 0, ) PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index 4ff5798060..d1d3bc419b 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -111,8 +111,9 @@ end NetworkModel(model; PTDF_matrix = PTDF(system)), ) set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) - model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) - @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT + model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) + @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == + PSI.BuildStatus.BUILT @test check_variable_unbounded(model_m, FlowActivePowerVariable, TapTransformer) @test check_variable_unbounded(model_m, FlowActivePowerVariable, Transformer2W) @@ -217,10 +218,10 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine( - name=get_name(line), - available=true, - active_power_flow=0.0, + hvdc = TwoTerminalHVDCLine(; + name = get_name(line), + available = true, + active_power_flow = 0.0, # Force the flow in the opposite direction for testing purposes active_power_limits_from = (min = -0.5, max = -0.5), active_power_limits_to = (min = -3.0, max = 2.0), @@ -289,10 +290,10 @@ end line = get_component(Line, sys_5, "1") remove_component!(sys_5, line) - hvdc = TwoTerminalHVDCLine( - name=get_name(line), - available=true, - active_power_flow=0.0, + hvdc = TwoTerminalHVDCLine(; + name = get_name(line), + available = true, + active_power_flow = 0.0, # Force the flow in the opposite direction for testing purposes active_power_limits_from = (min = -2.0, max = -2.0), active_power_limits_to = (min = -3.0, max = 2.0), @@ -490,8 +491,8 @@ end NetworkModel(StandardPTDFModel; PTDF_matrix = PTDF(system)), ) set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) - model_m = DecisionModel(template, system; optimizer=HiGHS_optimizer) - @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT + model_m = DecisionModel(template, system; optimizer = HiGHS_optimizer) + @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT @test !check_variable_bounded(model_m, FlowActivePowerVariable, TapTransformer) @test !check_variable_bounded(model_m, FlowActivePowerVariable, Transformer2W) @@ -606,8 +607,8 @@ end template = get_template_dispatch_with_network(ACPPowerModel) set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) - model_m = DecisionModel(template, system; optimizer=ipopt_optimizer) - @test build!(model_m; output_dir=mktempdir(cleanup=true)) == PSI.BuildStatus.BUILT + model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) + @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT @test check_variable_bounded(model_m, FlowActivePowerFromToVariable, TapTransformer) @test check_variable_unbounded(model_m, FlowReactivePowerFromToVariable, TapTransformer) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index 1d4548c714..eca31998a4 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -13,8 +13,8 @@ set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) - model = DecisionModel(template_uc, sys_5; name="UC", optimizer=HiGHS_optimizer) - @test build!(model; output_dir=mktempdir()) == PSI.BuildStatus.BUILT + model = DecisionModel(template_uc, sys_5; name = "UC", optimizer = HiGHS_optimizer) + @test build!(model; output_dir = mktempdir()) == PSI.BuildStatus.BUILT moi_tests(model, 1656, 0, 1536, 816, 888, true) @test solve!(model) == RunStatus.SUCCESSFUL end From 0f7539def7d5a5fddb9004dd32ffbbbfd7a018f6 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 7 Jul 2023 10:41:59 -0600 Subject: [PATCH 56/73] bump project toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ba7107aaa8..e15994f581 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PowerSimulations" uuid = "e690365d-45e2-57bb-ac84-44ba829e73c4" authors = ["Jose Daniel Lara", "Clayton Barrows", "Daniel Thom", "Dheepak Krishnamurthy", "Sourabh Dalvi"] -version = "0.20.3" +version = "0.21.0" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" From 38930dcb5bd1833b57a2da60508debc9829e3755 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 15:41:02 -0600 Subject: [PATCH 57/73] bump deps --- Project.toml | 4 ++-- test/Project.toml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 87d2f3cebc..b8c2d935ca 100644 --- a/Project.toml +++ b/Project.toml @@ -42,8 +42,8 @@ JSON3 = "1" JuMP = "1" MathOptInterface = "1" PowerModels = "~0.19" -PowerNetworkMatrices = "^0.8" -PowerSystems = "^2.6" +PowerNetworkMatrices = "^0.9" +PowerSystems = "^3" PrettyTables = "^1.3, 2" ProgressMeter = "^1.5" TimeSeries = "~0.23" diff --git a/test/Project.toml b/test/Project.toml index 2b72548673..65541b2c64 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -7,7 +7,6 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" -HydroPowerSimulations = "fc1677e0-6ad7-4515-bf3a-bd6bf20a0b1b" InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1" Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" @@ -32,5 +31,5 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] HiGHS = "=1.1.2" Ipopt = "=1.4.0" -PowerSystemCaseBuilder = "~1.0.2" +PowerSystemCaseBuilder = "^1.2.0" julia = "^1.6" From a7527bff91b88547f1bef6516c549423a03e7c63 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 15:41:51 -0600 Subject: [PATCH 58/73] remove bad reference file --- src/PowerSimulations.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 611de39c3c..6ef3222e92 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -517,7 +517,6 @@ include("devices_models/devices/electric_loads.jl") include("devices_models/devices/AC_branches.jl") include("devices_models/devices/TwoTerminalDC_branches.jl") include("devices_models/devices/HVDCsystems.jl") -include("devices_models/devices/DC_branches.jl") include("devices_models/devices/regulation_device.jl") # Services Models From 698d0d538bd9e444bf2d6feaa44ecfb4b2515f7f Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 15:43:38 -0600 Subject: [PATCH 59/73] add HPS to tests --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index 65541b2c64..5e338be182 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -7,6 +7,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" +HydroPowerSimulations = "fc1677e0-6ad7-4515-bf3a-bd6bf20a0b1b" InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1" Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" From 39aa50ae5da8ac0520122ee17d9779c0af48bf54 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 18:32:02 -0600 Subject: [PATCH 60/73] many fixes --- docs/src/formulation_library/Branch.md | 12 +- src/PowerSimulations.jl | 6 +- src/core/definitions.jl | 1 + src/core/formulations.jl | 10 +- src/core/optimization_container.jl | 1 + src/core/variables.jl | 2 +- .../device_constructors/branch_constructor.jl | 234 ++++++++++-------- .../thermalgeneration_constructor.jl | 9 +- src/devices_models/devices/HVDCsystems.jl | 3 +- .../devices/TwoTerminalDC_branches.jl | 56 +++-- .../devices/common/add_to_expression.jl | 10 +- src/network_models/network_constructor.jl | 8 +- src/network_models/network_slack_variables.jl | 2 +- src/network_models/pm_translator.jl | 42 +++- src/network_models/powermodels_interface.jl | 17 +- src/operation/operation_problem_templates.jl | 2 +- test/test_device_branch_constructors.jl | 26 +- test/test_model_decision.jl | 4 +- test/test_network_constructors.jl | 12 +- test/test_utils/mock_operation_models.jl | 5 +- .../operations_problem_templates.jl | 4 +- 21 files changed, 271 insertions(+), 195 deletions(-) diff --git a/docs/src/formulation_library/Branch.md b/docs/src/formulation_library/Branch.md index cb41d19e72..f55d6c37e7 100644 --- a/docs/src/formulation_library/Branch.md +++ b/docs/src/formulation_library/Branch.md @@ -44,24 +44,24 @@ StaticBranchUnbounded --- -## `HVDCP2PLossless` +## `HVDCTwoTerminalLossless` ```@docs -HVDCP2PLossless +HVDCTwoTerminalLossless ``` --- -## `HVDCP2PDispatch` +## `HVDCTwoTerminalDispatch` ```@docs -HVDCP2PDispatch +HVDCTwoTerminalDispatch ``` --- -## `HVDCP2PUnbounded` +## `HVDCTwoTerminalUnbounded` ```@docs -HVDCP2PUnbounded +HVDCTwoTerminalUnbounded ``` diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 6ef3222e92..8afece5303 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -41,9 +41,9 @@ export ConstantMaxInterfaceFlow export StaticBranch export StaticBranchBounds export StaticBranchUnbounded -export HVDCP2PLossless -export HVDCP2PDispatch -export HVDCP2PUnbounded +export HVDCTwoTerminalLossless +export HVDCTwoTerminalDispatch +export HVDCTwoTerminalUnbounded export PhaseAngleControl # export VoltageSourceDC diff --git a/src/core/definitions.jl b/src/core/definitions.jl index 8d726d7ba7..1900cf773f 100644 --- a/src/core/definitions.jl +++ b/src/core/definitions.jl @@ -27,6 +27,7 @@ const JuMPVariableMatrix = DenseAxisArray{ const JuMPFloatArray = DenseAxisArray{Float64} const JuMPVariableArray = DenseAxisArray{JuMP.VariableRef} +const TwoTerminalHVDCTypes = Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCDCLine} # Settings constants const UNSET_HORIZON = 0 const UNSET_INI_TIME = Dates.DateTime(0) diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 6e825b1e0c..6070734baf 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -121,21 +121,21 @@ Branch formulation for PhaseShiftingTransformer flow control struct PhaseAngleControl <: AbstractBranchFormulation end ############################### DC Branch Formulations ##################################### -abstract type AbstractP2PDCLineFormulation <: AbstractBranchFormulation end +abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end """ Branch type to avoid flow constraints """ -struct HVDCP2PUnbounded <: AbstractP2PDCLineFormulation end +struct HVDCTwoTerminalUnbounded <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossless power flow on DC lines """ -struct HVDCP2PLossless <: AbstractP2PDCLineFormulation end +struct HVDCTwoTerminalLossless <: AbstractTwoTerminalDCLineFormulation end """ Branch type to represent lossy power flow on DC lines """ -struct HVDCP2PDispatch <: AbstractP2PDCLineFormulation end +struct HVDCTwoTerminalDispatch <: AbstractTwoTerminalDCLineFormulation end # Not Implemented -# struct VoltageSourceDC <: AbstractP2PDCLineFormulation end +# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end ############################### AC/DC Converter Formulations ##################################### abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index d0c5609bfe..7c2f0c441e 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -461,6 +461,7 @@ end function _make_system_expressions!( container::OptimizationContainer, subnetworks::Dict{Int, Set{Int}}, + ::Vector{Int}, ::Type{CopperPlatePowerModel}, ) time_steps = get_time_steps(container) diff --git a/src/core/variables.jl b/src/core/variables.jl index 083fa93f84..a4f228bdd4 100644 --- a/src/core/variables.jl +++ b/src/core/variables.jl @@ -172,7 +172,7 @@ struct FlowReactivePowerToFromVariable <: VariableType end struct PhaseShifterAngle <: VariableType end -# Necessary as a work around for HVDCP2P models with losses +# Necessary as a work around for HVDCTwoTerminal models with losses struct HVDCLosses <: VariableType end struct HVDCFlowDirectionVariable <: VariableType end diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index c006c6ddcc..b827207ce8 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -152,57 +152,6 @@ function construct_device!( return end -function construct_device!( - container::OptimizationContainer, - sys::PSY.System, - ::ArgumentConstructStage, - device_model::DeviceModel{T, HVDCP2PLossless}, - network_model::NetworkModel{CopperPlatePowerModel}, -) where {T <: PSY.DCBranch} - if has_subnetworks(network_model) - devices = - get_available_components(T, sys, get_attribute(device_model, "filter_function")) - add_variables!( - container, - FlowActivePowerVariable, - network_model, - devices, - HVDCP2PLossless(), - ) - add_to_expression!( - container, - ActivePowerBalance, - FlowActivePowerVariable, - devices, - device_model, - network_model, - ) - end - return -end - -function construct_device!( - container::OptimizationContainer, - sys::PSY.System, - ::ModelConstructStage, - device_model::DeviceModel{T, HVDCP2PLossless}, - network_model::NetworkModel{CopperPlatePowerModel}, -) where {T <: PSY.DCBranch} - if has_subnetworks(network_model) - devices = - get_available_components(T, sys, get_attribute(device_model, "filter_function")) - add_constraints!( - container, - FlowRateConstraint, - devices, - device_model, - network_model, - ) - add_constraint_dual!(container, sys, device_model) - end - return -end - construct_device!( ::OptimizationContainer, ::PSY.System, @@ -396,14 +345,69 @@ function construct_device!( return end -################################### P2P HVDC Line Models ################################### +################################### TwoTerminal HVDC Line Models ################################### +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ArgumentConstructStage, + device_model::DeviceModel{T, HVDCTwoTerminalLossless}, + network_model::NetworkModel{CopperPlatePowerModel}, +) where {T <: TwoTerminalHVDCTypes} + if has_subnetworks(network_model) + devices = + get_available_components(T, sys, get_attribute(device_model, "filter_function")) + add_variables!( + container, + FlowActivePowerVariable, + network_model, + devices, + HVDCTwoTerminalLossless(), + ) + add_to_expression!( + container, + ActivePowerBalance, + FlowActivePowerVariable, + devices, + device_model, + network_model, + ) + end + return +end + +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + device_model::DeviceModel{T, HVDCTwoTerminalLossless}, + network_model::NetworkModel{CopperPlatePowerModel}, +) where {T <: TwoTerminalHVDCTypes} + if has_subnetworks(network_model) + devices = + get_available_components(T, sys, get_attribute(device_model, "filter_function")) + add_constraints!( + container, + FlowRateConstraint, + devices, + device_model, + network_model, + ) + add_constraint_dual!(container, sys, device_model) + end + return +end + function construct_device!( ::OptimizationContainer, ::PSY.System, ::ArgumentConstructStage, ::DeviceModel{T, F}, ::NetworkModel{S}, -) where {T <: PSY.DCBranch, F <: HVDCP2PUnbounded, S <: PM.AbstractPowerModel} end +) where { + T <: TwoTerminalHVDCTypes, + F <: HVDCTwoTerminalUnbounded, + S <: PM.AbstractPowerModel, +} end function construct_device!( container::OptimizationContainer, @@ -411,11 +415,15 @@ function construct_device!( ::ModelConstructStage, model::DeviceModel{T, U}, ::NetworkModel{S}, -) where {T <: PSY.DCBranch, U <: HVDCP2PUnbounded, S <: PM.AbstractPowerModel} +) where { + T <: TwoTerminalHVDCTypes, + U <: HVDCTwoTerminalUnbounded, + S <: PM.AbstractPowerModel, +} add_constraint_dual!(container, sys, model) end -# Repeated method to avoid ambiguity between HVDCP2PUnbounded and HVDCP2PLossless +# Repeated method to avoid ambiguity between HVDCTwoTerminalUnbounded and HVDCTwoTerminalLossless function construct_device!( container::OptimizationContainer, sys::PSY.System, @@ -423,8 +431,8 @@ function construct_device!( model::DeviceModel{T, U}, network_model::NetworkModel{S}, ) where { - T <: PSY.DCBranch, - U <: HVDCP2PUnbounded, + T <: TwoTerminalHVDCTypes, + U <: HVDCTwoTerminalUnbounded, S <: Union{StandardPTDFModel, PTDFPowerModel}, } devices = @@ -441,7 +449,7 @@ function construct_device!( return end -# Repeated method to avoid ambiguity between HVDCP2PUnbounded and HVDCP2PLossless +# Repeated method to avoid ambiguity between HVDCTwoTerminalUnbounded and HVDCTwoTerminalLossless function construct_device!( container::OptimizationContainer, sys::PSY.System, @@ -449,8 +457,8 @@ function construct_device!( model::DeviceModel{T, U}, network_model::NetworkModel{S}, ) where { - T <: PSY.DCBranch, - U <: HVDCP2PUnbounded, + T <: TwoTerminalHVDCTypes, + U <: HVDCTwoTerminalUnbounded, S <: Union{StandardPTDFModel, PTDFPowerModel}, } add_constraint_dual!(container, sys, model) @@ -463,7 +471,11 @@ function construct_device!( ::ArgumentConstructStage, ::DeviceModel{T, F}, ::NetworkModel{S}, -) where {T <: PSY.DCBranch, F <: HVDCP2PLossless, S <: PM.AbstractPowerModel} end +) where { + T <: TwoTerminalHVDCTypes, + F <: HVDCTwoTerminalLossless, + S <: PM.AbstractPowerModel, +} end function construct_device!( container::OptimizationContainer, @@ -471,7 +483,11 @@ function construct_device!( ::ModelConstructStage, model::DeviceModel{T, U}, network_model::NetworkModel{S}, -) where {T <: PSY.DCBranch, U <: HVDCP2PLossless, S <: PM.AbstractPowerModel} +) where { + T <: TwoTerminalHVDCTypes, + U <: HVDCTwoTerminalLossless, + S <: PM.AbstractPowerModel, +} devices = get_available_components(T, sys, get_attribute(model, "filter_function")) add_constraints!(container, FlowRateConstraint, devices, model, network_model) @@ -479,14 +495,14 @@ function construct_device!( return end -# Repeated method to avoid ambiguity between HVDCP2PUnbounded and HVDCP2PLossless +# Repeated method to avoid ambiguity between HVDCTwoTerminalUnbounded and HVDCTwoTerminalLossless function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, model::DeviceModel{T, U}, network_model::NetworkModel{<:Union{StandardPTDFModel, PTDFPowerModel}}, -) where {T <: PSY.DCBranch, U <: HVDCP2PLossless} +) where {T <: TwoTerminalHVDCTypes, U <: HVDCTwoTerminalLossless} devices = get_available_components(T, sys, get_attribute(model, "filter_function")) add_variables!(container, FlowActivePowerVariable, devices, U()) @@ -501,15 +517,15 @@ function construct_device!( return end -# Repeated method to avoid ambiguity between HVDCP2PUnbounded and HVDCP2PLossless +# Repeated method to avoid ambiguity between HVDCTwoTerminalUnbounded and HVDCTwoTerminalLossless function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.TwoTerminalHVDCLine, T}, + model::DeviceModel{T, HVDCTwoTerminalLossless}, network_model::NetworkModel{U}, ) where { - T <: HVDCP2PLossless, + T <: TwoTerminalHVDCTypes, U <: Union{StandardPTDFModel, PTDFPowerModel}, } devices = @@ -523,15 +539,25 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, + model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{StandardPTDFModel}, -) +) where {T <: TwoTerminalHVDCTypes} devices = - get_available_components(PSY.HVDCLine, sys, get_attribute(model, "filter_function")) - add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) - add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) - add_variables!(container, HVDCLosses, devices, HVDCP2PDispatch()) - add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) + get_available_components(T, sys, get_attribute(model, "filter_function")) + add_variables!( + container, + FlowActivePowerToFromVariable, + devices, + HVDCTwoTerminalDispatch(), + ) + add_variables!( + container, + FlowActivePowerFromToVariable, + devices, + HVDCTwoTerminalDispatch(), + ) + add_variables!(container, HVDCLosses, devices, HVDCTwoTerminalDispatch()) + add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCTwoTerminalDispatch()) add_to_expression!( container, ActivePowerBalance, @@ -563,11 +589,11 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, - ::NetworkModel{StandardPTDFModel}, -) + model::DeviceModel{T, HVDCTwoTerminalDispatch}, + network_model::NetworkModel{StandardPTDFModel}, +) where {T <: TwoTerminalHVDCTypes} devices = - get_available_components(PSY.HVDCLine, sys, get_attribute(model, "filter_function")) + get_available_components(T, sys, get_attribute(model, "filter_function")) add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model) add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) add_constraints!(container, HVDCPowerBalance, devices, model, network_model) @@ -579,14 +605,24 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ArgumentConstructStage, - model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, - network_model::NetworkModel{T}, -) where {T <: PM.AbstractActivePowerModel} + model::DeviceModel{T, HVDCTwoTerminalDispatch}, + network_model::NetworkModel{U}, +) where {T <: TwoTerminalHVDCTypes, U <: PM.AbstractActivePowerModel} devices = - get_available_components(PSY.HVDCLine, sys, get_attribute(model, "filter_function")) - add_variables!(container, FlowActivePowerToFromVariable, devices, HVDCP2PDispatch()) - add_variables!(container, FlowActivePowerFromToVariable, devices, HVDCP2PDispatch()) - add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCP2PDispatch()) + get_available_components(T, sys, get_attribute(model, "filter_function")) + add_variables!( + container, + FlowActivePowerToFromVariable, + devices, + HVDCTwoTerminalDispatch(), + ) + add_variables!( + container, + FlowActivePowerFromToVariable, + devices, + HVDCTwoTerminalDispatch(), + ) + add_variables!(container, HVDCFlowDirectionVariable, devices, HVDCTwoTerminalDispatch()) add_to_expression!( container, ActivePowerBalance, @@ -610,11 +646,11 @@ function construct_device!( container::OptimizationContainer, sys::PSY.System, ::ModelConstructStage, - model::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, - network_model::NetworkModel{T}, -) where {T <: PM.AbstractActivePowerModel} + model::DeviceModel{T, HVDCTwoTerminalDispatch}, + network_model::NetworkModel{U}, +) where {T <: TwoTerminalHVDCTypes, U <: PM.AbstractActivePowerModel} devices = - get_available_components(PSY.HVDCLine, sys, get_attribute(model, "filter_function")) + get_available_components(T, sys, get_attribute(model, "filter_function")) add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model) add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) add_constraints!(container, HVDCPowerBalance, devices, model, network_model) @@ -623,26 +659,6 @@ function construct_device!( return end -function construct_device!( - ::OptimizationContainer, - ::PSY.System, - ::ArgumentConstructStage, - ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, - ::NetworkModel{T}, -) where {T <: PM.AbstractPowerModel} - return -end - -function construct_device!( - ::OptimizationContainer, - ::PSY.System, - ::ModelConstructStage, - ::DeviceModel{PSY.TwoTerminalHVDCLine, HVDCP2PDispatch}, - ::NetworkModel{T}, -) where {T <: PM.AbstractPowerModel} - return -end - ############################# Phase Shifter Transformer Models ############################# function construct_device!( diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 96317b323a..721d21b619 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1690,7 +1690,14 @@ function construct_device!( network_model, ) - add_to_expression!(container, ActivePowerBalance, OnStatusParameter, devices, model, S) + add_to_expression!( + container, + ActivePowerBalance, + OnStatusParameter, + devices, + model, + network_model, + ) initial_conditions!(container, devices, ThermalCompactDispatch()) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index a2fe15b82b..2fd09d3881 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -135,13 +135,12 @@ function add_to_expression!( ::Type{U}, ::IS.FlattenIteratorWrapper{V}, devices::DeviceModel{V, W}, - network_model::NetworkModel{X}, + network_model::NetworkModel{CopperPlatePowerModel}, ) where { T <: ActivePowerBalance, U <: ActivePowerVariable, V <: PSY.InterconnectingConverter, W <: AbstractConverterFormulation, - X <: CopperPlatePowerModel, } variable = get_variable(container, U(), V) diff --git a/src/devices_models/devices/TwoTerminalDC_branches.jl b/src/devices_models/devices/TwoTerminalDC_branches.jl index 5e131dc399..5483ac226f 100644 --- a/src/devices_models/devices/TwoTerminalDC_branches.jl +++ b/src/devices_models/devices/TwoTerminalDC_branches.jl @@ -1,16 +1,20 @@ #################################### Branch Variables ################################################## -get_variable_binary(_, ::Type{<:PSY.TwoTerminalHVDCLine}, ::AbstractP2PDCLineFormulation) = +get_variable_binary( + _, + ::Type{<:PSY.TwoTerminalHVDCLine}, + ::AbstractTwoTerminalDCLineFormulation, +) = false get_variable_binary( ::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = false get_variable_binary( ::HVDCFlowDirectionVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = true get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, _) = @@ -19,19 +23,19 @@ get_variable_multiplier(::FlowActivePowerVariable, ::Type{<:PSY.TwoTerminalHVDCL get_variable_multiplier( ::FlowActivePowerFromToVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = -1.0 get_variable_multiplier( ::FlowActivePowerToFromVariable, ::Type{<:PSY.TwoTerminalHVDCLine}, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = 1.0 function get_variable_multiplier( ::HVDCLosses, d::PSY.TwoTerminalHVDCLine, - ::HVDCP2PDispatch, + ::HVDCTwoTerminalDispatch, ) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 @@ -45,33 +49,37 @@ end get_variable_lower_bound( ::FlowActivePowerVariable, d::PSY.TwoTerminalHVDCLine, - ::HVDCP2PUnbounded, + ::HVDCTwoTerminalUnbounded, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, d::PSY.TwoTerminalHVDCLine, - ::HVDCP2PUnbounded, + ::HVDCTwoTerminalUnbounded, ) = nothing get_variable_lower_bound( ::FlowActivePowerVariable, d::PSY.TwoTerminalHVDCLine, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = nothing get_variable_upper_bound( ::FlowActivePowerVariable, d::PSY.TwoTerminalHVDCLine, - ::AbstractP2PDCLineFormulation, + ::AbstractTwoTerminalDCLineFormulation, ) = nothing -get_variable_lower_bound(::HVDCLosses, d::PSY.TwoTerminalHVDCLine, ::HVDCP2PDispatch) = 0.0 +get_variable_lower_bound( + ::HVDCLosses, + d::PSY.TwoTerminalHVDCLine, + ::HVDCTwoTerminalDispatch, +) = 0.0 function get_variable_upper_bound( ::HVDCLosses, d::PSY.TwoTerminalHVDCLine, - ::HVDCP2PDispatch, + ::HVDCTwoTerminalDispatch, ) l1 = PSY.get_loss(d).l1 l0 = PSY.get_loss(d).l0 @@ -85,21 +93,21 @@ end function get_default_time_series_names( ::Type{U}, ::Type{V}, -) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractTwoTerminalDCLineFormulation} return Dict{Type{<:TimeSeriesParameter}, String}() end function get_default_attributes( ::Type{U}, ::Type{V}, -) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractP2PDCLineFormulation} +) where {U <: PSY.TwoTerminalHVDCLine, V <: AbstractTwoTerminalDCLineFormulation} return Dict{String, Any}() end get_initial_conditions_device_model( ::OperationModel, ::DeviceModel{T, U}, -) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractP2PDCLineFormulation} = +) where {T <: PSY.TwoTerminalHVDCLine, U <: AbstractTwoTerminalDCLineFormulation} = DeviceModel(T, U) #################################### Rate Limits Constraints ################################################## @@ -137,7 +145,7 @@ add_constraints!( ::OptimizationContainer, ::Type{<:Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom}}, ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, - ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCTwoTerminalUnbounded}, ::NetworkModel{<:PM.AbstractPowerModel}, ) = nothing @@ -145,7 +153,7 @@ add_constraints!( ::OptimizationContainer, ::Type{FlowRateConstraint}, ::IS.FlattenIteratorWrapper{<:PSY.TwoTerminalHVDCLine}, - ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCP2PUnbounded}, + ::DeviceModel{<:PSY.TwoTerminalHVDCLine, HVDCTwoTerminalUnbounded}, ::NetworkModel{<:PM.AbstractPowerModel}, ) = nothing @@ -153,7 +161,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::Union{Vector{U}, IS.FlattenIteratorWrapper{U}}, - ::DeviceModel{U, HVDCP2PLossless}, + ::DeviceModel{U, HVDCTwoTerminalLossless}, ::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: FlowRateConstraint, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) @@ -184,7 +192,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{FlowRateConstraint}, devices::IS.FlattenIteratorWrapper{T}, - model::DeviceModel{T, HVDCP2PLossless}, + model::DeviceModel{T, HVDCTwoTerminalLossless}, network_model::NetworkModel{CopperPlatePowerModel}, ) where {T <: PSY.TwoTerminalHVDCLine} inter_network_branches = T[] @@ -211,7 +219,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::IS.FlattenIteratorWrapper{U}, - ::DeviceModel{U, HVDCP2PDispatch}, + ::DeviceModel{U, HVDCTwoTerminalDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: FlowRateConstraintFromTo, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) @@ -242,7 +250,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::IS.FlattenIteratorWrapper{U}, - ::DeviceModel{U, HVDCP2PDispatch}, + ::DeviceModel{U, HVDCTwoTerminalDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: FlowRateConstraintToFrom, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) @@ -273,7 +281,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{T}, devices::IS.FlattenIteratorWrapper{U}, - ::DeviceModel{U, HVDCP2PDispatch}, + ::DeviceModel{U, HVDCTwoTerminalDispatch}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: HVDCDirection, U <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) @@ -321,7 +329,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCPowerBalance}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, + ::DeviceModel{T, <:AbstractTwoTerminalDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: PSY.TwoTerminalHVDCLine} time_steps = get_time_steps(container) @@ -404,7 +412,7 @@ function add_constraints!( container::OptimizationContainer, ::Type{HVDCLossesAbsoluteValue}, devices::IS.FlattenIteratorWrapper{T}, - ::DeviceModel{T, <:AbstractP2PDCLineFormulation}, + ::DeviceModel{T, <:AbstractTwoTerminalDCLineFormulation}, ::NetworkModel{<:PM.AbstractDCPModel}, ) where {T <: PSY.TwoTerminalHVDCLine} 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 07d4507734..19bbb8ed23 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -170,12 +170,12 @@ function add_to_expression!( ::Type{U}, devices::IS.FlattenIteratorWrapper{V}, ::DeviceModel{V, W}, - ::Type{StandardPTDFModel}, + network_model::NetworkModel{StandardPTDFModel}, ) where { T <: ActivePowerBalance, U <: HVDCLosses, - V <: PSY.TwoTerminalHVDCLine, - W <: HVDCP2PDispatch, + V <: TwoTerminalHVDCTypes, + W <: HVDCTwoTerminalDispatch, } variable = get_variable(container, U(), V) expression = get_expression(container, T(), PSY.System) @@ -368,7 +368,7 @@ function add_to_expression!( W <: AbstractDeviceFormulation, } variable = get_variable(container, U(), V) - expression = get_expression(container, T(), CopperPlatePowerModel) + expression = get_expression(container, T(), PSY.System) for d in devices device_bus = PSY.get_bus(d) ref_bus = get_reference_bus(network_model, device_bus) @@ -398,7 +398,7 @@ function add_to_expression!( W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch}, } variable = get_variable(container, U(), V) - expression = get_expression(container, T(), CopperPlatePowerModel) + expression = get_expression(container, T(), PSY.System) for d in devices name = PSY.get_name(d) device_bus = PSY.get_bus(d) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 6378a34e89..e2d4a5d850 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -123,7 +123,7 @@ function construct_network!( sys, model, ) - objective_function!(container, PSY.ACBus, model, T) + objective_function!(container, PSY.ACBus, model) end @debug "Building the $T network with $instantiate_model method" _group = @@ -171,7 +171,7 @@ function construct_network!( sys, model, ) - objective_function!(container, PSY.ACBus, model, T) + objective_function!(container, PSY.ACBus, model) end @debug "Building the $T network with $instantiate_model method" _group = @@ -236,7 +236,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.ACBus, model, T) + objective_function!(container, PSY.ACBus, model) end @debug "Building the $T network with $instantiate_model method" _group = @@ -300,7 +300,7 @@ function construct_network!( model, T, ) - objective_function!(container, PSY.ACBus, model, T) + objective_function!(container, PSY.ACBus, model) end @debug "Building the $T network with $instantiate_model method" _group = diff --git a/src/network_models/network_slack_variables.jl b/src/network_models/network_slack_variables.jl index 0b35557ca6..619aeab047 100644 --- a/src/network_models/network_slack_variables.jl +++ b/src/network_models/network_slack_variables.jl @@ -37,7 +37,7 @@ function add_variables!( U <: PM.AbstractActivePowerModel, } time_steps = get_time_steps(container) - bus_numbers = PSY.get_number.(get_available_components(PSY.accessBus, sys)) + bus_numbers = PSY.get_number.(get_available_components(PSY.ACBus, sys)) variable = add_variable_container!(container, T(), PSY.ACBus, bus_numbers, time_steps) for t in time_steps, n in bus_numbers variable[n, t] = JuMP.@variable( diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index 0704473850..d684df49b3 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -267,7 +267,7 @@ end function get_branch_to_pm( ix::Int, branch::PSY.TwoTerminalHVDCLine, - ::Type{HVDCP2PDispatch}, + ::Type{HVDCTwoTerminalDispatch}, ::Type{<:PM.AbstractDCPModel}, ) PM_branch = Dict{String, Any}( @@ -305,7 +305,7 @@ end function get_branch_to_pm( ix::Int, branch::PSY.TwoTerminalHVDCLine, - ::Type{HVDCP2PDispatch}, + ::Type{HVDCTwoTerminalDispatch}, ::Type{<:PM.AbstractPowerModel}, ) check_hvdc_line_limits_unidirectional(branch) @@ -344,7 +344,7 @@ end function get_branch_to_pm( ix::Int, branch::PSY.TwoTerminalHVDCLine, - ::Type{<:AbstractP2PDCLineFormulation}, + ::Type{<:AbstractTwoTerminalDCLineFormulation}, ::Type{<:PM.AbstractPowerModel}, ) PM_branch = Dict{String, Any}( @@ -389,6 +389,38 @@ function get_branches_to_pm( PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() + for (d, device_model) in branch_template + comp_type = get_component_type(device_model) + if comp_type <: TwoTerminalHVDCTypes + continue + end + !(comp_type <: T) && continue + start_idx += length(PM_branches) + filter_func = get_attribute(device_model, "filter_function") + for (i, branch) in enumerate(get_available_components(comp_type, sys, filter_func)) + ix = i + start_idx + PM_branches["$(ix)"] = + get_branch_to_pm(ix, branch, get_formulation(device_model), S) + if PM_branches["$(ix)"]["br_status"] == true + f = PM_branches["$(ix)"]["f_bus"] + t = PM_branches["$(ix)"]["t_bus"] + PMmap_br[(from_to = (ix, f, t), to_from = (ix, t, f))] = branch + end + end + end + return PM_branches, PMmap_br +end + +function get_branches_to_pm( + sys::PSY.System, + ::Type{S}, + ::Type{T}, + branch_template::BranchModelContainer, + start_idx = 0, +) where {T <: TwoTerminalHVDCTypes, S <: PM.AbstractPowerModel} + PM_branches = Dict{String, Any}() + PMmap_br = Dict{PM_MAP_TUPLE, T}() + for (d, device_model) in branch_template comp_type = get_component_type(device_model) !(comp_type <: T) && continue @@ -411,10 +443,10 @@ end function get_branches_to_pm( ::PSY.System, ::Type{PTDFPowerModel}, - ::Type{PSY.TwoTerminalHVDCLine}, + ::Type{T}, branch_template::BranchModelContainer, start_idx = 0, -) +) where {T <: TwoTerminalHVDCTypes} PM_branches = Dict{String, Any}() PMmap_br = Dict{PM_MAP_TUPLE, T}() return PM_branches, PMmap_br diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index 8046d74ad6..009c4369d2 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -334,7 +334,11 @@ function powermodels_network!( end container.pm = - instantiate_model(pm_data, system_formulation; jump_model = container.JuMPmodel) + instantiate_model( + pm_data, + system_formulation; + jump_model = get_jump_model(container), + ) container.pm.ext[:PMmap] = PM_map return @@ -348,7 +352,7 @@ function PMvarmap(::Type{S}) where {S <: PM.AbstractDCPModel} pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => (from_to = FlowActivePowerVariable(), to_from = nothing)) - pm_variable_map[PSY.DCBranch] = + pm_variable_map[TwoTerminalHVDCTypes] = Dict(:p_dc => (from_to = FlowActivePowerVariable(), to_from = nothing)) return pm_variable_map @@ -359,7 +363,7 @@ function PMvarmap(::Type{S}) where {S <: PM.AbstractActivePowerModel} pm_variable_map[PSY.ACBus] = Dict(:va => VoltageAngle()) pm_variable_map[PSY.ACBranch] = Dict(:p => FlowActivePowerFromToVariable()) - pm_variable_map[PSY.DCBranch] = Dict( + pm_variable_map[TwoTerminalHVDCTypes] = Dict( :p_dc => ( from_to = FlowActivePowerFromToVariable(), to_from = FlowActivePowerToFromVariable(), @@ -374,7 +378,7 @@ function PMvarmap(::Type{PTDFPowerModel}) pm_variable_map[PSY.ACBus] = Dict() pm_variable_map[PSY.ACBranch] = Dict() - pm_variable_map[PSY.DCBranch] = Dict() + pm_variable_map[TwoTerminalHVDCTypes] = Dict() return pm_variable_map end @@ -393,7 +397,7 @@ function PMvarmap(::Type{S}) where {S <: PM.AbstractPowerModel} to_from = FlowReactivePowerToFromVariable(), ), ) - pm_variable_map[PSY.DCBranch] = Dict( + pm_variable_map[TwoTerminalHVDCTypes] = Dict( :p_dc => (from_to = FlowActivePowerVariable(), to_from = nothing), :q_dc => ( from_to = FlowReactivePowerFromToVariable(), @@ -488,7 +492,7 @@ function add_pm_variable_refs!( ) add_pm_variable_refs!( container, - PSY.DCBranch, + TwoTerminalHVDCTypes, DCbranch_types, DCbranch_dict, pm_variable_map, @@ -529,6 +533,7 @@ function add_pm_variable_refs!( end end end + return end function add_pm_constraint_refs!( diff --git a/src/operation/operation_problem_templates.jl b/src/operation/operation_problem_templates.jl index 2b11c3fd04..1eb7e928f4 100644 --- a/src/operation/operation_problem_templates.jl +++ b/src/operation/operation_problem_templates.jl @@ -13,7 +13,7 @@ function _default_devices_uc() DeviceModel(PSY.Line, StaticBranch), DeviceModel(PSY.Transformer2W, StaticBranch), DeviceModel(PSY.TapTransformer, StaticBranch), - DeviceModel(PSY.TwoTerminalHVDCLine, HVDCP2PDispatch), + DeviceModel(PSY.TwoTerminalHVDCLine, HVDCTwoTerminalDispatch), ] end diff --git a/test/test_device_branch_constructors.jl b/test/test_device_branch_constructors.jl index d1d3bc419b..af47085b41 100644 --- a/test/test_device_branch_constructors.jl +++ b/test/test_device_branch_constructors.jl @@ -110,7 +110,7 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCTwoTerminalLossless) model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT @@ -167,7 +167,10 @@ end template = get_template_dispatch_with_network( NetworkModel(model; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PUnbounded)) + set_device_model!( + template, + DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalUnbounded), + ) set_device_model!(template, DeviceModel(TapTransformer, StaticBranchBounds)) set_device_model!(template, DeviceModel(Transformer2W, StaticBranchBounds)) model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) @@ -211,7 +214,7 @@ end end end -@testset "HVDCP2PLossless values check between network models" begin +@testset "HVDCTwoTerminalLossless values check between network models" begin # Test to compare lossless models with lossless formulation sys_5 = build_system(PSITestSystems, "c_sys5_uc") @@ -241,7 +244,10 @@ end set_device_model!(template_uc, RenewableDispatch, FixedOutput) set_device_model!(template_uc, PowerLoad, StaticPowerLoad) set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) - set_device_model!(template_uc, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) + set_device_model!( + template_uc, + DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalLossless), + ) model = DecisionModel( template_uc, @@ -317,7 +323,7 @@ end set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) set_device_model!( template_uc, - DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless), + DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalLossless), ) model_ref = DecisionModel( @@ -353,7 +359,7 @@ end ) set_device_model!( template_uc, - DeviceModel(TwoTerminalHVDCLine, HVDCP2PDispatch), + DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalDispatch), ) model = DecisionModel( @@ -475,7 +481,7 @@ end system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -490,7 +496,7 @@ end template = get_template_dispatch_with_network( NetworkModel(StandardPTDFModel; PTDF_matrix = PTDF(system)), ) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalLossless)) model_m = DecisionModel(template, system; optimizer = HiGHS_optimizer) @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT @@ -593,7 +599,7 @@ end system = PSB.build_system(PSITestSystems, "c_sys14_dc") - hvdc_line = PSY.get_component(HVDCLine, system, "DCLine3") + hvdc_line = PSY.get_component(TwoTerminalHVDCLine, system, "DCLine3") limits_from = PSY.get_active_power_limits_from(hvdc_line) limits_to = PSY.get_active_power_limits_to(hvdc_line) limits_min = min(limits_from.min, limits_to.min) @@ -606,7 +612,7 @@ end rate_limit2w = PSY.get_rate(tap_transformer) template = get_template_dispatch_with_network(ACPPowerModel) - set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCP2PLossless)) + set_device_model!(template, DeviceModel(TwoTerminalHVDCLine, HVDCTwoTerminalLossless)) model_m = DecisionModel(template, system; optimizer = ipopt_optimizer) @test build!(model_m; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT diff --git a/test/test_model_decision.jl b/test/test_model_decision.jl index 3af76fc801..4137c9fe23 100644 --- a/test/test_model_decision.jl +++ b/test/test_model_decision.jl @@ -181,7 +181,7 @@ end if network == StandardPTDFModel push!(LMPs, abs.(psi_ptdf_lmps(res, ptdf))) else - duals = read_dual(res, NodalBalanceActiveConstraint, Bus) + duals = read_dual(res, NodalBalanceActiveConstraint, ACBus) duals = abs.(duals[:, propertynames(duals) .!== :DateTime]) push!(LMPs, duals[!, sort(propertynames(duals))]) end @@ -622,7 +622,7 @@ end @testset "Test for isolated buses" begin c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") add_component!(c_sys5, - Bus( + ACBus( 10, "node_none", "ISOLATED", diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index fffd5eba49..4de655700b 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -519,7 +519,7 @@ end psi_checksolve_test(ps_model, [MOI.OPTIMAL], 480288, 100) results = ProblemResults(ps_model) - hvdc_flow = read_variable(results, "FlowActivePowerVariable__HVDCLine") + hvdc_flow = read_variable(results, "FlowActivePowerVariable__TwoTerminalHVDCLine") @test all(hvdc_flow[!, "nodeC-nodeC2"] .<= 200) @test all(hvdc_flow[!, "nodeC-nodeC2"] .>= -200) @@ -556,7 +556,7 @@ end ) # Test forcing flows to 0.0 - hvdc_link = get_component(PSY.HVDCLine, c_sys5, "nodeC-nodeC2") + hvdc_link = get_component(TwoTerminalHVDCLine, c_sys5, "nodeC-nodeC2") set_active_power_limits_from!(hvdc_link, (min = 0.0, max = 0.0)) set_active_power_limits_to!(hvdc_link, (min = 0.0, max = 0.0)) @@ -572,7 +572,7 @@ end PSI.get_constraint(opt_container, CopperPlateBalanceConstraint(), PSY.System) results = ProblemResults(ps_model) - hvdc_flow = read_variable(results, "FlowActivePowerVariable__HVDCLine") + hvdc_flow = read_variable(results, "FlowActivePowerVariable__TwoTerminalHVDCLine") @test all(hvdc_flow[!, "nodeC-nodeC2"] .== 0.0) @test all(hvdc_flow[!, "nodeC-nodeC2"] .== 0.0) @@ -619,7 +619,7 @@ end psi_checksolve_test(ps_model, [MOI.OPTIMAL], 684763, 100) results = ProblemResults(ps_model) - hvdc_flow = read_variable(results, "FlowActivePowerVariable__HVDCLine") + hvdc_flow = read_variable(results, "FlowActivePowerVariable__TwoTerminalHVDCLine") @test all(hvdc_flow[!, "nodeC-nodeC2"] .<= 200) @test all(hvdc_flow[!, "nodeC-nodeC2"] .>= -200) @@ -656,7 +656,7 @@ end ) # Test forcing flows to 0.0 - hvdc_link = get_component(PSY.HVDCLine, c_sys5, "nodeC-nodeC2") + hvdc_link = get_component(PSY.TwoTerminalHVDCLine, c_sys5, "nodeC-nodeC2") set_active_power_limits_from!(hvdc_link, (min = 0.0, max = 0.0)) set_active_power_limits_to!(hvdc_link, (min = 0.0, max = 0.0)) @@ -672,7 +672,7 @@ end PSI.get_constraint(opt_container, CopperPlateBalanceConstraint(), PSY.System) results = ProblemResults(ps_model) - hvdc_flow = read_variable(results, "FlowActivePowerVariable__HVDCLine") + hvdc_flow = read_variable(results, "FlowActivePowerVariable__TwoTerminalHVDCLine") @test all(hvdc_flow[!, "nodeC-nodeC2"] .== 0.0) @test all(hvdc_flow[!, "nodeC-nodeC2"] .== 0.0) diff --git a/test/test_utils/mock_operation_models.jl b/test/test_utils/mock_operation_models.jl index f1166c01cb..a41128efb5 100644 --- a/test/test_utils/mock_operation_models.jl +++ b/test/test_utils/mock_operation_models.jl @@ -44,7 +44,7 @@ end function PSI.DecisionModel(::Type{MockOperationProblem}; name = nothing, kwargs...) sys = System(100.0) - add_component!(sys, Bus(nothing)) + add_component!(sys, ACBus(nothing)) l = PowerLoad(nothing) gen = ThermalStandard(nothing) set_bus!(l, get_component(Bus, sys, "init")) @@ -71,7 +71,7 @@ end function PSI.EmulationModel(::Type{MockEmulationProblem}; name = nothing, kwargs...) sys = System(100.0) - add_component!(sys, Bus(nothing)) + add_component!(sys, ACBus(nothing)) l = PowerLoad(nothing) gen = ThermalStandard(nothing) set_bus!(l, get_component(Bus, sys, "init")) @@ -116,6 +116,7 @@ function mock_construct_device!( PSI.get_optimization_container(problem), PSI.get_network_formulation(template), PSI.get_network_model(template).subnetworks, + PSI.get_system(problem), ) if PSI.validate_available_devices(model, PSI.get_system(problem)) PSI.construct_device!( diff --git a/test/test_utils/operations_problem_templates.jl b/test/test_utils/operations_problem_templates.jl index 6f9a3f7921..43c1e5bd1a 100644 --- a/test/test_utils/operations_problem_templates.jl +++ b/test/test_utils/operations_problem_templates.jl @@ -13,7 +13,7 @@ function get_thermal_dispatch_template_network(network = CopperPlatePowerModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCTwoTerminalLossless) return template end @@ -70,6 +70,6 @@ function get_template_dispatch_with_network(network = StandardPTDFModel) set_device_model!(template, Line, StaticBranch) set_device_model!(template, Transformer2W, StaticBranch) set_device_model!(template, TapTransformer, StaticBranch) - set_device_model!(template, TwoTerminalHVDCLine, HVDCP2PLossless) + set_device_model!(template, TwoTerminalHVDCLine, HVDCTwoTerminalLossless) return template end From 9ac586cb6d6510c92e9c369ea66edbb80a114e5e Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 23:13:12 -0600 Subject: [PATCH 61/73] fix test --- src/network_models/pm_translator.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index d684df49b3..627a5b7cf0 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -492,7 +492,7 @@ function pass_to_pm(sys::PSY.System, template::ProblemTemplate, time_periods::In two_terminal_dc_lines, PMmap_dc = get_branches_to_pm( sys, get_network_formulation(template), - PSY.TwoTerminalHVDCLine, + TwoTerminalHVDCTypes, template.branches, length(ac_lines), ) From 5c944b1923375351da6c716fd6e2c4eec0a00298 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 6 Sep 2023 23:36:34 -0600 Subject: [PATCH 62/73] fix some tests --- src/devices_models/devices/HVDCsystems.jl | 36 +++++++++++++++++++++-- src/utils/powersystems_utils.jl | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 2fd09d3881..82620634ff 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -5,10 +5,42 @@ get_variable_lower_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, get_variable_upper_bound(::ActivePowerVariable, d::PSY.InterconnectingConverter, ::AbstractConverterFormulation) = PSY.get_active_power_limits(d).max get_variable_multiplier(_, ::Type{PSY.InterconnectingConverter}, ::AbstractConverterFormulation) = 1.0 + +function _get_flow_bounds(d::PSY.TModelHVDCLine) + check_hvdc_line_limits_consistency(d) + from_min = PSY.get_active_power_limits_from(d).min + to_min = PSY.get_active_power_limits_to(d).min + from_max = PSY.get_active_power_limits_from(d).max + to_max = PSY.get_active_power_limits_to(d).max + + if from_min >= 0.0 && to_min >= 0.0 + min_rate = min(from_min, to_min) + elseif from_min <= 0.0 && to_min <= 0.0 + min_rate = max(from_min, to_min) + elseif from_min <= 0.0 && to_min >= 0.0 + min_rate = from_min + elseif to_min <= 0.0 && from_min >= 0.0 + min_rate = to_min + end + + if from_max >= 0.0 && to_max >= 0.0 + max_rate = min(from_max, to_max) + elseif from_max <= 0.0 && to_max <= 0.0 + max_rate = max(from_max, to_max) + elseif from_max <= 0.0 && to_max >= 0.0 + max_rate = from_max + elseif from_max >= 0.0 && to_max <= 0.0 + max_rate = to_max + end + + return min_rate, max_rate +end + + get_variable_binary(::FlowActivePowerVariable, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = false get_variable_warm_start_value(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_active_power_flow(d) -get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = -PSY.get_rate(d) -get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = PSY.get_rate(d) +get_variable_lower_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = _get_flow_bounds(d)[1] +get_variable_upper_bound(::FlowActivePowerVariable, d::PSY.TModelHVDCLine, ::AbstractBranchFormulation) = _get_flow_bounds(d)[2] get_variable_multiplier(_, ::Type{PSY.TModelHVDCLine}, ::AbstractBranchFormulation) = 1.0 requires_initialization(::AbstractConverterFormulation) = false diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index 0e5a33ef08..b2b306261f 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -41,7 +41,7 @@ end make_system_filename(sys::PSY.System) = "system-$(IS.get_uuid(sys)).json" make_system_filename(sys_uuid::Union{Base.UUID, AbstractString}) = "system-$(sys_uuid).json" -function check_hvdc_line_limits_consistency(d::PSY.TwoTerminalHVDCLine) +function check_hvdc_line_limits_consistency(d::Union{PSY.TwoTerminalHVDCLine, PSY.TModelHVDCLine}) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max From 07c629443db82ce1b4e5c6c5c2f76d5aca97d239 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 7 Sep 2023 18:17:03 -0600 Subject: [PATCH 63/73] fixes to reserves --- src/devices_models/devices/common/add_variable.jl | 6 +++--- src/services_models/reserves.jl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devices_models/devices/common/add_variable.jl b/src/devices_models/devices/common/add_variable.jl index c9bb403fe3..a0053104b5 100644 --- a/src/devices_models/devices/common/add_variable.jl +++ b/src/devices_models/devices/common/add_variable.jl @@ -135,13 +135,13 @@ function add_service_variable!( binary = binary ) - ub = get_variable_upper_bound(variable_type, service, d, container.settings) + ub = get_variable_upper_bound(variable_type, service, d, formulation) ub !== nothing && JuMP.set_upper_bound(variable[name, t], ub) - lb = get_variable_lower_bound(variable_type, service, d, container.settings) + lb = get_variable_lower_bound(variable_type, service, d, formulation) lb !== nothing && !binary && JuMP.set_lower_bound(variable[name, t], lb) - init = get_variable_warm_start_value(variable_type, d, container.settings) + init = get_variable_warm_start_value(variable_type, d, formulation) init !== nothing && JuMP.set_start_value(variable[name, t], init) end diff --git a/src/services_models/reserves.jl b/src/services_models/reserves.jl index 8f84022c0d..cee5ef7f5b 100644 --- a/src/services_models/reserves.jl +++ b/src/services_models/reserves.jl @@ -4,15 +4,15 @@ get_variable_multiplier(_, ::Type{<:PSY.Reserve}, ::AbstractReservesFormulation) = NaN ############################### ActivePowerReserveVariable, Reserve ######################################### get_variable_binary(::ActivePowerReserveVariable, ::Type{<:PSY.Reserve}, ::AbstractReservesFormulation) = false -function get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.Reserve, d::PSY.Device, _) +function get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.Reserve, d::PSY.Device, ::AbstractReservesFormulation) return PSY.get_max_output_fraction(r) * PSY.get_max_active_power(d) end -get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.ReserveDemandCurve, d::PSY.Device, _) = PSY.get_max_active_power(d) +get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.ReserveDemandCurve, d::PSY.Device, ::AbstractReservesFormulation) = PSY.get_max_active_power(d) get_variable_lower_bound(::ActivePowerReserveVariable, ::PSY.Reserve, ::PSY.Device, _) = 0.0 ############################### ActivePowerReserveVariable, ReserveNonSpinning ######################################### get_variable_binary(::ActivePowerReserveVariable, ::Type{<:PSY.ReserveNonSpinning}, ::AbstractReservesFormulation) = false -function get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.ReserveNonSpinning, d::PSY.Device, _) +function get_variable_upper_bound(::ActivePowerReserveVariable, r::PSY.ReserveNonSpinning, d::PSY.Device, ::AbstractReservesFormulation) return PSY.get_max_output_fraction(r) * PSY.get_max_active_power(d) end get_variable_lower_bound(::ActivePowerReserveVariable, ::PSY.ReserveNonSpinning, ::PSY.Device, _) = 0.0 From f4ebc6423dde6f576bf9f5e288276c013904bbc9 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 11 Sep 2023 14:04:27 -0600 Subject: [PATCH 64/73] address Dan's comment --- src/devices_models/devices/HVDCsystems.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index 82620634ff..ee20e478f6 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -21,6 +21,8 @@ function _get_flow_bounds(d::PSY.TModelHVDCLine) min_rate = from_min elseif to_min <= 0.0 && from_min >= 0.0 min_rate = to_min + else + @assert false end if from_max >= 0.0 && to_max >= 0.0 @@ -31,6 +33,8 @@ function _get_flow_bounds(d::PSY.TModelHVDCLine) max_rate = from_max elseif from_max >= 0.0 && to_max <= 0.0 max_rate = to_max + else + @assert false end return min_rate, max_rate From 3e4ef49b0d294d38f04bf43f92edb6791687c48a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 11 Sep 2023 14:04:34 -0600 Subject: [PATCH 65/73] use getters --- src/core/optimization_container.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 7c2f0c441e..c98d22c284 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -267,7 +267,7 @@ end function is_milp(container::OptimizationContainer)::Bool !supports_milp(container) && return false if !isempty( - JuMP.all_constraints(container.JuMPmodel, JuMP.VariableRef, JuMP.MOI.ZeroOne), + JuMP.all_constraints(PSI.get_jump_model(container), JuMP.VariableRef, JuMP.MOI.ZeroOne), ) return true end @@ -307,10 +307,10 @@ function _finalize_jump_model!(container::OptimizationContainer, settings::Setti @debug "The optimization model has no optimizer attached" _group = LOG_GROUP_OPTIMIZATION_CONTAINER else - JuMP.set_optimizer(container.JuMPmodel, get_optimizer(settings)) + JuMP.set_optimizer(PSI.get_jump_model(container), get_optimizer(settings)) end - JuMPmodel = container.JuMPmodel + JuMPmodel = PSI.get_jump_model(container) warm_start_enabled = get_warm_start(settings) solver_supports_warm_start = _validate_warm_start_support(JuMPmodel, warm_start_enabled) set_warm_start!(settings, solver_supports_warm_start) @@ -386,7 +386,7 @@ function reset_optimization_model!(container::OptimizationContainer) container.initial_conditions_data = InitialConditionsData() container.objective_function = ObjectiveFunction() container.primal_values_cache = PrimalValuesCache() - JuMP.empty!(container.JuMPmodel) + JuMP.empty!(PSI.get_jump_model(container)) return end @@ -624,7 +624,7 @@ function build_impl!( @debug "Building Objective" _group = LOG_GROUP_OPTIMIZATION_CONTAINER update_objective_function!(container) end - @debug "Total operation count $(container.JuMPmodel.operator_counter)" _group = + @debug "Total operation count $(PSI.get_jump_model(container).operator_counter)" _group = LOG_GROUP_OPTIMIZATION_CONTAINER check_optimization_container(container) From 35ae6c72479382a1bfa093b0cee8707b3cfb66fa Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 14:30:28 -0600 Subject: [PATCH 66/73] bump hdf5 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b8c2d935ca..2186c0dbb8 100644 --- a/Project.toml +++ b/Project.toml @@ -35,7 +35,7 @@ CSV = "~0.10" DataFrames = "1" DataStructures = "~0.18" DocStringExtensions = "~v0.9" -HDF5 = "~0.16" +HDF5 = "~0.17" InfrastructureSystems = "^1.21" JSON = "0.21" JSON3 = "1" From e18c78b6db0b604a8b855a626ec8a4a9b1fc0bca Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:28:34 -0600 Subject: [PATCH 67/73] fix bad merge --- .../device_constructors/branch_constructor.jl | 8 ++++++-- src/devices_models/devices/common/add_to_expression.jl | 9 ++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index b827207ce8..10745b9882 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -407,7 +407,9 @@ function construct_device!( T <: TwoTerminalHVDCTypes, F <: HVDCTwoTerminalUnbounded, S <: PM.AbstractPowerModel, -} end +} +return +end function construct_device!( container::OptimizationContainer, @@ -475,7 +477,9 @@ function construct_device!( T <: TwoTerminalHVDCTypes, F <: HVDCTwoTerminalLossless, S <: PM.AbstractPowerModel, -} end +} +return +end function construct_device!( container::OptimizationContainer, diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 19bbb8ed23..5146cf131c 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -606,13 +606,12 @@ function add_to_expression!( network_model::NetworkModel{StandardPTDFModel}, ) where { T <: ActivePowerBalance, - U <: PhaseShifterAngle, - V <: PhaseAngleControl, - W <: StandardPTDFModel, + U <: FlowActivePowerVariable, + V <: PSY.ACBranch, + W <: AbstractBranchFormulation, } var = get_variable(container, U(), V) - nodal_expr = get_expression(container, T(), StandardPTDFModel) - var = get_variable(container, U(), V) + nodal_expr = get_expression(container, T(), PSY.ACBus) sys_expr = get_expression(container, T(), PSY.System) for d in devices bus_no_from = PSY.get_number(PSY.get_arc(d).from) From cbf552fe3d34f6438619fce9557789bdb14501a6 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:31:31 -0600 Subject: [PATCH 68/73] add additional test --- test/test_device_hvdc.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index eca31998a4..98446f701f 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -17,4 +17,22 @@ @test build!(model; output_dir = mktempdir()) == PSI.BuildStatus.BUILT moi_tests(model, 1656, 0, 1536, 816, 888, true) @test solve!(model) == RunStatus.SUCCESSFUL + + template_uc = ProblemTemplate(NetworkModel( + StandardPTDFModel, + #use_slacks=true, + PTDF_matrix=PTDF(sys_5), + #duals=[CopperPlateBalanceConstraint], + )) + + set_device_model!(template_uc, ThermalStandard, ThermalCompactUnitCommitment) + set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) + set_device_model!(template_uc, PowerLoad, StaticPowerLoad) + set_device_model!(template_uc, DeviceModel(Line, StaticBranch)) + set_device_model!(template_uc, DeviceModel(InterconnectingConverter, LossLessConverter)) + set_device_model!(template_uc, DeviceModel(TModelHVDCLine, LossLessLine)) + model = DecisionModel(template_uc, sys_5; name = "UC", optimizer = HiGHS_optimizer) + @test build!(model; output_dir = mktempdir()) == PSI.BuildStatus.BUILT + moi_tests(model, 1416, 0, 1248, 528, 672, true) + @test solve!(model) == RunStatus.SUCCESSFUL end From 40fed26388663816d26dfc5964dba5cd50bdfefa Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:32:24 -0600 Subject: [PATCH 69/73] formatter --- src/core/optimization_container.jl | 6 +++++- .../device_constructors/branch_constructor.jl | 4 ++-- src/utils/powersystems_utils.jl | 4 +++- test/test_device_hvdc.jl | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index c98d22c284..7f62169581 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -267,7 +267,11 @@ end function is_milp(container::OptimizationContainer)::Bool !supports_milp(container) && return false if !isempty( - JuMP.all_constraints(PSI.get_jump_model(container), JuMP.VariableRef, JuMP.MOI.ZeroOne), + JuMP.all_constraints( + PSI.get_jump_model(container), + JuMP.VariableRef, + JuMP.MOI.ZeroOne, + ), ) return true end diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 10745b9882..6566bb9a1a 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -408,7 +408,7 @@ function construct_device!( F <: HVDCTwoTerminalUnbounded, S <: PM.AbstractPowerModel, } -return + return end function construct_device!( @@ -478,7 +478,7 @@ function construct_device!( F <: HVDCTwoTerminalLossless, S <: PM.AbstractPowerModel, } -return + return end function construct_device!( diff --git a/src/utils/powersystems_utils.jl b/src/utils/powersystems_utils.jl index b2b306261f..b50f676fbe 100644 --- a/src/utils/powersystems_utils.jl +++ b/src/utils/powersystems_utils.jl @@ -41,7 +41,9 @@ end make_system_filename(sys::PSY.System) = "system-$(IS.get_uuid(sys)).json" make_system_filename(sys_uuid::Union{Base.UUID, AbstractString}) = "system-$(sys_uuid).json" -function check_hvdc_line_limits_consistency(d::Union{PSY.TwoTerminalHVDCLine, PSY.TModelHVDCLine}) +function check_hvdc_line_limits_consistency( + d::Union{PSY.TwoTerminalHVDCLine, PSY.TModelHVDCLine}, +) from_min = PSY.get_active_power_limits_from(d).min to_min = PSY.get_active_power_limits_to(d).min from_max = PSY.get_active_power_limits_from(d).max diff --git a/test/test_device_hvdc.jl b/test/test_device_hvdc.jl index 98446f701f..42ce383876 100644 --- a/test/test_device_hvdc.jl +++ b/test/test_device_hvdc.jl @@ -19,9 +19,9 @@ @test solve!(model) == RunStatus.SUCCESSFUL template_uc = ProblemTemplate(NetworkModel( - StandardPTDFModel, + StandardPTDFModel; #use_slacks=true, - PTDF_matrix=PTDF(sys_5), + PTDF_matrix = PTDF(sys_5), #duals=[CopperPlateBalanceConstraint], )) From 894238f34ee12fe8ca5586cf8ac947b0cf0ce90b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:43:58 -0600 Subject: [PATCH 70/73] fix undefined variable --- src/feedforward/feedforward_arguments.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/feedforward/feedforward_arguments.jl b/src/feedforward/feedforward_arguments.jl index abfadf8214..20fdd57767 100644 --- a/src/feedforward/feedforward_arguments.jl +++ b/src/feedforward/feedforward_arguments.jl @@ -40,7 +40,7 @@ function _add_feedforward_arguments!( contributing_devices::Vector, ff::AbstractAffectFeedforward, ) where {T <: PSY.AbstractReserve, U <: AbstractServiceFormulation} - parameter_type = get_default_parameter_type(ff, SR) + parameter_type = get_default_parameter_type(ff, U) add_parameters!(container, parameter_type, ff, model, contributing_devices) return end From 59a22a42bb8eda40089b266099da631c70747ea1 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:45:08 -0600 Subject: [PATCH 71/73] fix feedforwards --- src/feedforward/feedforwards.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/feedforward/feedforwards.jl b/src/feedforward/feedforwards.jl index a5f3bb4729..b832117f62 100644 --- a/src/feedforward/feedforwards.jl +++ b/src/feedforward/feedforwards.jl @@ -26,7 +26,7 @@ function attach_feedforward!( ff_ = T(; component_type = get_component_type(ff), source = get_entry_type(get_optimization_container_key(ff)), - affected_values = [get_entry_type(get_optimization_container_key(ff))], + affected_values = affected_values = get_entry_type.(get_affected_values(ff)), meta = model.service_name, ) end @@ -132,7 +132,7 @@ function attach_feedforward!( ff_ = T(; component_type = get_component_type(ff), source = get_entry_type(get_optimization_container_key(ff)), - affected_values = [get_entry_type(get_optimization_container_key(ff))], + affected_values = get_entry_type.(get_affected_values(ff)), meta = model.service_name, add_slacks = ff.add_slacks, ) From 81a66528cdf29f9e0265e3423ea288d5779e9eea Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:55:45 -0600 Subject: [PATCH 72/73] fix call to update parameter values --- src/parameters/update_parameters.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parameters/update_parameters.jl b/src/parameters/update_parameters.jl index a9c738087b..671c1b59d7 100644 --- a/src/parameters/update_parameters.jl +++ b/src/parameters/update_parameters.jl @@ -594,7 +594,9 @@ function update_parameter_values!( # if the keys have strings in the meta fields parameter_array = get_parameter_array(optimization_container, key) parameter_attributes = get_parameter_attributes(optimization_container, key) - _update_parameter_values!(parameter_array, parameter_attributes, T, model, input) + service = PSY.get_component(T, get_system(model), key.meta) + @assert service !== nothing + _update_parameter_values!(parameter_array, parameter_attributes, service, model, input) _fix_parameter_value!(optimization_container, parameter_array, parameter_attributes) IS.@record :execution ParameterUpdateEvent( FixValueParameter, From 370cdbc4cf7e5cc172eebee76fd2cb9d372ed80b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Sep 2023 15:58:51 -0600 Subject: [PATCH 73/73] formatter --- src/feedforward/feedforwards.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/feedforward/feedforwards.jl b/src/feedforward/feedforwards.jl index b832117f62..82f4220b25 100644 --- a/src/feedforward/feedforwards.jl +++ b/src/feedforward/feedforwards.jl @@ -26,7 +26,8 @@ function attach_feedforward!( ff_ = T(; component_type = get_component_type(ff), source = get_entry_type(get_optimization_container_key(ff)), - affected_values = affected_values = get_entry_type.(get_affected_values(ff)), + affected_values = affected_values = + get_entry_type.(get_affected_values(ff)), meta = model.service_name, ) end