From bc66c61e3f6601f26b295b6e77dab5788c149ba8 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 16 Jul 2024 17:24:06 -0600 Subject: [PATCH 01/33] allow inter-area models for other network models --- .../device_constructors/branch_constructor.jl | 7 +++---- src/devices_models/devices/area_interchange.jl | 4 ++-- src/devices_models/devices/common/add_to_expression.jl | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index baa4768200..7e6b909919 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -867,9 +867,8 @@ function construct_device!( ::PSY.System, ::ArgumentConstructStage, model::DeviceModel{PSY.AreaInterchange, U}, - network_model::NetworkModel{T}, -) where {T <: PM.AbstractPowerModel, U <: Union{StaticBranchUnbounded, StaticBranch}} - error("AreaInterchange is not yet implemented for $T") + network_model::NetworkModel{CopperPlatePowerModel}, +) where {U <: Union{StaticBranchUnbounded, StaticBranch}} return end @@ -881,7 +880,7 @@ function construct_device!( network_model::NetworkModel{U}, ) where { T <: Union{StaticBranchUnbounded, StaticBranch}, - U <: Union{AreaBalancePowerModel, AreaPTDFPowerModel}, + U <: PM.AbstractActivePowerModel } if get_use_slacks(model) add_variables!( diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index 4233f9c7c0..f610601ea9 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -26,7 +26,7 @@ function add_variables!( model::NetworkModel{T}, devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, formulation::AbstractBranchFormulation, -) where {T <: Union{AreaBalancePowerModel, AreaPTDFPowerModel}} +) where {T <: PM.AbstractActivePowerModel} time_steps = get_time_steps(container) variable = add_variable_container!( @@ -56,7 +56,7 @@ function add_constraints!( devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, model::DeviceModel{PSY.AreaInterchange, StaticBranch}, ::NetworkModel{T}, -) where {T <: Union{AreaBalancePowerModel, AreaPTDFPowerModel}} +) where {T <: PM.AbstractActivePowerModel} time_steps = get_time_steps(container) device_names = [PSY.get_name(d) for d in devices] diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index eb7702ed08..efbda4845c 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -933,7 +933,7 @@ function add_to_expression!( network_model::NetworkModel{U}, ) where { T <: ActivePowerBalance, - U <: Union{AreaBalancePowerModel, AreaPTDFPowerModel}, + U <: PM.AbstractActivePowerModel, W <: AbstractBranchFormulation, } flow_variable = get_variable(container, FlowActivePowerVariable(), PSY.AreaInterchange) From 57af12e5020b653342593ba25af41af3bf066c18 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 17 Jul 2024 09:53:48 -0600 Subject: [PATCH 02/33] add missing code for initialization --- .../device_constructors/branch_constructor.jl | 4 ++-- src/devices_models/devices/area_interchange.jl | 10 ++++++++-- src/initial_conditions/initialization.jl | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 7e6b909919..7aa4cfe093 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -950,7 +950,7 @@ end function _get_branch_map( container::OptimizationContainer, - network_model::NetworkModel{AreaPTDFPowerModel}, + network_model::NetworkModel, sys::PSY.System, ) @assert !isempty(network_model.modeled_branch_types) @@ -993,7 +993,7 @@ function construct_device!( ::ModelConstructStage, model::DeviceModel{PSY.AreaInterchange, StaticBranch}, network_model::NetworkModel{T}, -) where {T <: AreaPTDFPowerModel} +) where {T <: PSI.AbstractPTDFModel} devices = get_available_components(model, sys) add_constraints!(container, FlowLimitConstraint, devices, model, network_model) # Not ideal to do this here, but it is a not terrible workaround diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index f610601ea9..b01df8fdfb 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -1,6 +1,12 @@ #! format: off get_multiplier_value(::FromToFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = -1.0 * PSY.get_from_to_flow_limit(d) get_multiplier_value(::ToFromFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = PSY.get_to_from_flow_limit(d) + +get_initial_conditions_device_model( + ::OperationModel, + model::DeviceModel{PSY.AreaInterchange, T}, +) where {T <: AbstractBranchFormulation} = DeviceModel(PSY.AreaInterchange, T) + #! format: on function get_default_time_series_names( @@ -139,12 +145,12 @@ function add_constraints!( ::Type{LineFlowBoundConstraint}, devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, model::DeviceModel{PSY.AreaInterchange, <:AbstractBranchFormulation}, - network_model::NetworkModel{AreaPTDFPowerModel}, + network_model::NetworkModel{T}, inter_area_branch_map::Dict{ Tuple{PSY.Area, PSY.Area}, Dict{DataType, Vector{<:PSY.ACBranch}}, }, -) +) where {T <: AbstractPTDFModel} @assert !isempty(inter_area_branch_map) time_steps = get_time_steps(container) device_names = [PSY.get_name(d) for d in devices] diff --git a/src/initial_conditions/initialization.jl b/src/initial_conditions/initialization.jl index e375b25c12..b597e1eb15 100644 --- a/src/initial_conditions/initialization.jl +++ b/src/initial_conditions/initialization.jl @@ -13,10 +13,11 @@ function get_initial_conditions_template(model::OperationModel) get_radial_network_reduction(get_network_model(model.template)) network_model.subnetworks = get_subnetworks(get_network_model(model.template)) bus_area_map = get_bus_area_map(get_network_model(model.template)) + if !isempty(bus_area_map) network_model.bus_area_map = get_bus_area_map(get_network_model(model.template)) end - + network_model.modeled_branch_types = get_network_model(model.template).modeled_branch_types ic_template = ProblemTemplate(network_model) for device_model in values(model.template.devices) base_model = get_initial_conditions_device_model(model, device_model) From a6a90848d0fa03010c38c607701397ffbf9948d4 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 17 Jul 2024 09:53:56 -0600 Subject: [PATCH 03/33] improve error message --- src/simulation/initial_condition_update_simulation.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/simulation/initial_condition_update_simulation.jl b/src/simulation/initial_condition_update_simulation.jl index 7d444cf609..5a0b6b2f6a 100644 --- a/src/simulation/initial_condition_update_simulation.jl +++ b/src/simulation/initial_condition_update_simulation.jl @@ -89,7 +89,11 @@ function update_initial_conditions!( $(comp_type)-$(comp_name) is out of bounds [$(min), $(max)].") end else - @assert isapprox(var_val, 0.0, atol = ABSOLUTE_TOLERANCE) "status and power don't match" + if !isapprox(var_val, 0.0, atol = ABSOLUTE_TOLERANCE) + error("Status and Power variables don't match for $comp_name. \\ + ActivePowerVariable: $(var_val)\\ + Status value: $(status_val) for OnVariable") + end set_ic_quantity!(ic, 0.0) end end From 1c388a0e90411c022d966937c9319bbd36bea19a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:03:41 -0400 Subject: [PATCH 04/33] add missing feedforward calls --- .../device_constructors/branch_constructor.jl | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 7aa4cfe093..8a53545399 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -46,6 +46,7 @@ function construct_device!( network_model, ) end + add_feedforward_arguments!(container, model, devices) return end @@ -71,6 +72,7 @@ function construct_device!( ) add_constraint_dual!(container, sys, model) end + add_feedforward_constraints!(container, model, devices) return end @@ -106,6 +108,7 @@ function construct_device!( network_model, ) end + add_feedforward_arguments!(container, model, devices) return end @@ -129,6 +132,7 @@ function construct_device!( network_model, ) end + add_feedforward_constraints!(container, model, devices) return end @@ -161,6 +165,7 @@ function construct_device!( network_model, ) end + add_feedforward_arguments!(container, model, devices) return end @@ -174,6 +179,7 @@ function construct_device!( NetworkModel{AreaBalancePowerModel}, }, ) + add_feedforward_constraints!(container, model, devices) return end @@ -217,8 +223,7 @@ function construct_device!( ) end add_feedforward_arguments!(container, device_model, devices) - - add_feedforward_arguments!(container, device_model, devices) + return end # For DC Power only. Implements constraints @@ -272,6 +277,7 @@ function construct_device!( devices, StaticBranch(), ) + add_feedforward_arguments!(container, model, devices) return end @@ -285,6 +291,7 @@ function construct_device!( devices = get_available_components(model, sys) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) add_constraints!(container, RateLimitConstraint, devices, model, network_model) + add_feedforward_constraints!(container, model, devices) objective_function!(container, devices, model, PTDFPowerModel) add_constraint_dual!(container, sys, model) return @@ -310,6 +317,7 @@ function construct_device!( devices, StaticBranchBounds(), ) + add_feedforward_arguments!(container, model, devices) return end @@ -329,6 +337,7 @@ function construct_device!( model, network_model, ) + add_feedforward_constraints!(container, model, devices) add_constraint_dual!(container, sys, model) return end @@ -349,6 +358,7 @@ function construct_device!( devices, StaticBranchUnbounded(), ) + add_feedforward_arguments!(container, model, devices) return end @@ -361,7 +371,7 @@ function construct_device!( ) where {T <: PSY.ACBranch} devices = get_available_components(model, sys) - + add_feedforward_constraints!(container, model, devices) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) return @@ -386,7 +396,7 @@ function construct_device!( StaticBranch(), ) end - + add_feedforward_arguments!(container, device_model, devices) return end @@ -400,7 +410,7 @@ function construct_device!( devices = get_available_components(model, sys) branch_rate_bounds!(container, devices, model, network_model) - + add_feedforward_constraints!(container, model, devices) add_constraints!(container, RateLimitConstraintFromTo, devices, model, network_model) add_constraints!(container, RateLimitConstraintToFrom, devices, model, network_model) add_constraint_dual!(container, sys, model) @@ -880,8 +890,10 @@ function construct_device!( network_model::NetworkModel{U}, ) where { T <: Union{StaticBranchUnbounded, StaticBranch}, - U <: PM.AbstractActivePowerModel + U <: PM.AbstractActivePowerModel, } + devices = get_available_components(model, sys) + has_ts = PSY.has_time_series.(devices) if get_use_slacks(model) add_variables!( container, @@ -898,8 +910,6 @@ function construct_device!( T(), ) end - devices = get_available_components(model, sys) - has_ts = PSY.has_time_series.(devices) if any(has_ts) && !all(has_ts) error( "Not all AreaInterchange devices have time series. Check data to complete (or remove) time series.", From f1323c2e80e963fec886712cd0e39f59eec84efb Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:03:49 -0400 Subject: [PATCH 05/33] add missing getters --- src/devices_models/devices/AC_branches.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index fc7b1e1e51..e6cb1c74dc 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -21,9 +21,14 @@ get_variable_binary(::FlowActivePowerVariable, ::Type{<:PSY.ACBranch}, ::AbstractBranchFormulation,) = false get_variable_binary(::PhaseShifterAngle, ::Type{PSY.PhaseShiftingTransformer}, ::AbstractBranchFormulation,) = false -get_parameter_multiplier(::FixValueParameter, ::PSY.ACBranch, ::StaticBranch) = 1.0 +get_parameter_multiplier(::FixValueParameter, ::PSY.ACBranch, ::AbstractBranchFormulation) = 1.0 +get_parameter_multiplier(::LowerBoundValueParameter, ::PSY.ACBranch, ::AbstractBranchFormulation) = 1.0 +get_parameter_multiplier(::UpperBoundValueParameter, ::PSY.ACBranch, ::AbstractBranchFormulation) = 1.0 + get_variable_multiplier(::PhaseShifterAngle, d::PSY.PhaseShiftingTransformer, ::PhaseAngleControl) = 1.0/PSY.get_x(d) + + get_initial_conditions_device_model(::OperationModel, ::DeviceModel{T, U}) where {T <: PSY.ACBranch, U <: AbstractBranchFormulation} = DeviceModel(T, U) #### Properties of slack variables From a9baa62a3d100439d3f4d38749df7d8ba0624a1c Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:04:04 -0400 Subject: [PATCH 06/33] fix implementation errors in ff slacks --- src/feedforward/feedforward_arguments.jl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/feedforward/feedforward_arguments.jl b/src/feedforward/feedforward_arguments.jl index 20fdd57767..25e40081b9 100644 --- a/src/feedforward/feedforward_arguments.jl +++ b/src/feedforward/feedforward_arguments.jl @@ -109,9 +109,10 @@ function _add_feedforward_slack_variables!( var_type = get_entry_type(var) variable = add_variable_container!( container, - T, + T(), U, - [PSY.get_name(d) for d in devices]; + [PSY.get_name(d) for d in devices], + time_steps; meta = "$(var_type)", ) @@ -135,11 +136,12 @@ function _add_feedforward_arguments!( parameter_type = get_default_parameter_type(ff, T) add_parameters!(container, parameter_type, ff, model, devices) if get_slacks(ff) - add_feedforward_slack_variables!( + _add_feedforward_slack_variables!( container, - UpperBoundFeedForwardSlack, - devices, + UpperBoundFeedForwardSlack(), + ff, model, + devices, ) end return @@ -154,11 +156,12 @@ function _add_feedforward_arguments!( parameter_type = get_default_parameter_type(ff, SR) add_parameters!(container, parameter_type, ff, model, contributing_devices) if get_slacks(ff) - add_feedforward_slack_variables!( + _add_feedforward_slack_variables!( container, - UpperBoundFeedForwardSlack, - contributing_devices, + UpperBoundFeedForwardSlack(), + ff, model, + contributing_devices, ) end return @@ -175,7 +178,7 @@ function _add_feedforward_arguments!( if get_slacks(ff) _add_feedforward_slack_variables!( container, - LowerBoundFeedForwardSlack, + LowerBoundFeedForwardSlack(), ff, model, devices, From 9f3e4add635fcfe6cad1710cf35cba5c10b89602 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:04:38 -0400 Subject: [PATCH 07/33] remove assertion not required anymore --- src/feedforward/feedforward_constraints.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/feedforward/feedforward_constraints.jl b/src/feedforward/feedforward_constraints.jl index 2acac1dfb7..a85333b85f 100644 --- a/src/feedforward/feedforward_constraints.jl +++ b/src/feedforward/feedforward_constraints.jl @@ -456,7 +456,6 @@ function add_feedforward_constraints!( devices::Union{Vector{T}, IS.FlattenIteratorWrapper{T}}, ff::FixValueFeedforward, ) where {T <: PSY.Component} - time_steps = get_time_steps(container) parameter_type = get_default_parameter_type(ff, T) source_key = get_optimization_container_key(ff) var_type = get_entry_type(source_key) @@ -466,7 +465,6 @@ function add_feedforward_constraints!( variable = get_variable(container, var) set_name, set_time = JuMP.axes(variable) IS.@assert_op set_name == [PSY.get_name(d) for d in devices] - #IS.@assert_op set_time == time_steps for t in set_time, name in set_name JuMP.fix(variable[name, t], param[name, t] * multiplier[name, t]; force = true) From 222a4e6d284f97cdf3f63b32143cc0901af3e727 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:05:10 -0400 Subject: [PATCH 08/33] fix template for initialization --- src/initial_conditions/initialization.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/initial_conditions/initialization.jl b/src/initial_conditions/initialization.jl index b597e1eb15..cff6e81ed0 100644 --- a/src/initial_conditions/initialization.jl +++ b/src/initial_conditions/initialization.jl @@ -17,7 +17,8 @@ function get_initial_conditions_template(model::OperationModel) if !isempty(bus_area_map) network_model.bus_area_map = get_bus_area_map(get_network_model(model.template)) end - network_model.modeled_branch_types = get_network_model(model.template).modeled_branch_types + network_model.modeled_branch_types = + get_network_model(model.template).modeled_branch_types ic_template = ProblemTemplate(network_model) for device_model in values(model.template.devices) base_model = get_initial_conditions_device_model(model, device_model) From 169bc1939095056f9d0148e2dd220a62959abf1d Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:05:38 -0400 Subject: [PATCH 09/33] parameter update bug fix --- src/parameters/update_parameters.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parameters/update_parameters.jl b/src/parameters/update_parameters.jl index 39e4b8f996..3a659129dc 100644 --- a/src/parameters/update_parameters.jl +++ b/src/parameters/update_parameters.jl @@ -403,7 +403,7 @@ function update_container_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) + _update_parameter_values!(parameter_array, parameter_attributes, U, model, input) _fix_parameter_value!(optimization_container, parameter_array, parameter_attributes) return end @@ -418,7 +418,13 @@ function update_container_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) + _update_parameter_values!( + parameter_array, + parameter_attributes, + FixValueParameter, + model, + input, + ) _fix_parameter_value!(optimization_container, parameter_array, parameter_attributes) return end From bd97b54aaf7ab7034a1e964183b496699a51396e Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 19 Jul 2024 09:05:52 -0400 Subject: [PATCH 10/33] change assertion for error message --- src/simulation/initial_condition_update_simulation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/initial_condition_update_simulation.jl b/src/simulation/initial_condition_update_simulation.jl index 5a0b6b2f6a..4f4a46559e 100644 --- a/src/simulation/initial_condition_update_simulation.jl +++ b/src/simulation/initial_condition_update_simulation.jl @@ -89,7 +89,7 @@ function update_initial_conditions!( $(comp_type)-$(comp_name) is out of bounds [$(min), $(max)].") end else - if !isapprox(var_val, 0.0, atol = ABSOLUTE_TOLERANCE) + if !isapprox(var_val, 0.0; atol = ABSOLUTE_TOLERANCE) error("Status and Power variables don't match for $comp_name. \\ ActivePowerVariable: $(var_val)\\ Status value: $(status_val) for OnVariable") From 3581adc2d261ab4b82acc0b63063116692139f69 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 29 Jul 2024 17:09:48 -0600 Subject: [PATCH 11/33] add devices in the correct spot --- src/devices_models/device_constructors/branch_constructor.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 8a53545399..54c968959b 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -10,8 +10,8 @@ function construct_device!( NetworkModel{AreaBalancePowerModel}, }, ) where {T <: PSY.ACBranch} + devices = get_available_components(model, sys) if has_subnetworks(network_model) - devices = get_available_components(model, sys) if get_use_slacks(model) add_variables!( From c357684b9a8cbc371404a057b4241575388a0ed8 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Mon, 29 Jul 2024 16:47:44 -0700 Subject: [PATCH 12/33] add devices missing --- src/devices_models/device_constructors/branch_constructor.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 54c968959b..704e5935ad 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -60,6 +60,7 @@ function construct_device!( NetworkModel{AreaBalancePowerModel}, }, ) where {T <: PSY.ACBranch} + devices = get_available_components(model, sys) if has_subnetworks(network_model) devices = get_available_components(model, sys) From 950fdb0237dd7818edf1279e35e6f5e9228b4ef9 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Mon, 29 Jul 2024 16:50:06 -0700 Subject: [PATCH 13/33] formatter --- src/devices_models/device_constructors/branch_constructor.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 704e5935ad..99d70fc46c 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -12,7 +12,6 @@ function construct_device!( ) where {T <: PSY.ACBranch} devices = get_available_components(model, sys) if has_subnetworks(network_model) - if get_use_slacks(model) add_variables!( container, From e5b304df47b28163bd5f7fb9589e748228f43168 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 29 Jul 2024 18:18:17 -0600 Subject: [PATCH 14/33] add subsystem to parameter attributes --- src/core/parameters.jl | 9 +++++++++ src/operation/time_series_interface.jl | 4 ++-- src/parameters/add_parameters.jl | 2 ++ src/parameters/update_parameters.jl | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/parameters.jl b/src/core/parameters.jl index 7e2e60afe2..2946dd68fe 100644 --- a/src/core/parameters.jl +++ b/src/core/parameters.jl @@ -6,6 +6,7 @@ struct TimeSeriesAttributes{T <: PSY.TimeSeriesData} <: ParameterAttributes name::String multiplier_id::Base.RefValue{Int} component_name_to_ts_uuid::Dict{String, String} + subsystem::Base.RefValue{String} end function TimeSeriesAttributes( @@ -18,6 +19,7 @@ function TimeSeriesAttributes( name, Base.RefValue{Int}(multiplier_id), component_name_to_ts_uuid, + Base.RefValue{String}(""), ) end @@ -29,6 +31,13 @@ function set_time_series_multiplier_id!(attr::TimeSeriesAttributes, val::Int) return end +get_subsystem(attr::TimeSeriesAttributes) = attr.subsystem[] +function set_subsystem!(attr::TimeSeriesAttributes, val::String) + attr.subsystem[] = val + return +end +set_subsystem!(::TimeSeriesAttributes, ::Nothing) = nothing + function add_component_name!(attr::TimeSeriesAttributes, name::String, uuid::String) if haskey(attr.component_name_to_ts_uuid, name) throw(ArgumentError("$name is already stored")) diff --git a/src/operation/time_series_interface.jl b/src/operation/time_series_interface.jl index 040f7b2e1d..990e6dff7f 100644 --- a/src/operation/time_series_interface.jl +++ b/src/operation/time_series_interface.jl @@ -2,9 +2,9 @@ function get_time_series_values!( time_series_type::Type{T}, model::DecisionModel, component, - name, + name::String, multiplier_id::Int, - initial_time, + initial_time::Dates.DateTime, horizon::Int; ignore_scaling_factors = true, ) where {T <: PSY.Forecast} diff --git a/src/parameters/add_parameters.jl b/src/parameters/add_parameters.jl index b581893ed0..4d3e1cf2a5 100644 --- a/src/parameters/add_parameters.jl +++ b/src/parameters/add_parameters.jl @@ -216,6 +216,7 @@ function _add_time_series_parameters!( time_steps, ) set_time_series_multiplier_id!(get_attributes(param_container), time_series_mult_id) + set_subsystem!(get_attributes(param_container), get_subsystem(model)) jump_model = get_jump_model(container) for (ts_uuid, ts_values) in initial_values @@ -282,6 +283,7 @@ function _add_parameters!( ) set_time_series_multiplier_id!(get_attributes(parameter_container), time_series_mult_id) + set_subsystem!(get_attributes(param_container), get_subsystem(model)) jump_model = get_jump_model(container) ts_vector = get_time_series(container, service, T(), name) multiplier = get_multiplier_value(T(), service, V()) diff --git a/src/parameters/update_parameters.jl b/src/parameters/update_parameters.jl index 3a659129dc..64abfa1159 100644 --- a/src/parameters/update_parameters.jl +++ b/src/parameters/update_parameters.jl @@ -40,8 +40,13 @@ function _update_parameter_values!( horizon = get_time_steps(get_optimization_container(model))[end] ts_name = get_time_series_name(attributes) multiplier_id = get_time_series_multiplier_id(attributes) + subsystem = get_subsystem(attributes) template = get_template(model) - device_model = get_model(template, V) + if isempty(subsystem) + device_model = get_model(template, V) + else + device_model = get_model(template, V, subsystem) + end components = get_available_components(device_model, get_system(model)) ts_uuids = Set{String}() for component in components From 8e4ed7bc42b7217012fa7b021c91d4789aa8cce4 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 29 Jul 2024 18:23:54 -0600 Subject: [PATCH 15/33] fix bad naming --- src/parameters/add_parameters.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parameters/add_parameters.jl b/src/parameters/add_parameters.jl index 4d3e1cf2a5..6261ded49c 100644 --- a/src/parameters/add_parameters.jl +++ b/src/parameters/add_parameters.jl @@ -283,7 +283,7 @@ function _add_parameters!( ) set_time_series_multiplier_id!(get_attributes(parameter_container), time_series_mult_id) - set_subsystem!(get_attributes(param_container), get_subsystem(model)) + set_subsystem!(get_attributes(parameter_container), get_subsystem(model)) jump_model = get_jump_model(container) ts_vector = get_time_series(container, service, T(), name) multiplier = get_multiplier_value(T(), service, V()) From b6c8219f5e80636920108447bb539e5c0a2396b5 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 31 Jul 2024 13:02:34 -0600 Subject: [PATCH 16/33] add missing constraints and arguments --- .../device_constructors/branch_constructor.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 99d70fc46c..aba7e29ed4 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -458,6 +458,7 @@ function construct_device!( network_model, ) add_constraint_dual!(container, sys, device_model) + return end @@ -808,6 +809,7 @@ function construct_device!( model, network_model, ) + add_feedforward_arguments!(container, model, devices) return end @@ -832,6 +834,7 @@ function construct_device!( model, network_model, ) + add_feedforward_arguments!(container, model, devices) return end @@ -850,6 +853,7 @@ function construct_device!( add_constraints!(container, PhaseAngleControlLimit, devices, model, network_model) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) + add_feedforward_constraints!(container, model, devices) return end @@ -868,6 +872,7 @@ function construct_device!( add_constraints!(container, PhaseAngleControlLimit, devices, model, network_model) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) + add_feedforward_constraints!(container, model, devices) return end @@ -879,6 +884,7 @@ function construct_device!( model::DeviceModel{PSY.AreaInterchange, U}, network_model::NetworkModel{CopperPlatePowerModel}, ) where {U <: Union{StaticBranchUnbounded, StaticBranch}} + add_feedforward_arguments!(container, model, devices) return end @@ -943,6 +949,7 @@ function construct_device!( add_parameters!(container, FromToFlowLimitParameter, devices, model) add_parameters!(container, ToFromFlowLimitParameter, devices, model) end + add_feedforward_arguments!(container, model, devices) return end @@ -955,6 +962,7 @@ function construct_device!( ) where {T <: AreaBalancePowerModel} devices = get_available_components(model, sys) add_constraints!(container, FlowLimitConstraint, devices, model, network_model) + add_feedforward_constraints!(container, model, devices) return end @@ -1019,6 +1027,7 @@ function construct_device!( network_model, inter_area_branch_map, ) + add_feedforward_constraints!(container, model, devices) return end @@ -1029,6 +1038,7 @@ function construct_device!( model::DeviceModel{PSY.AreaInterchange, StaticBranchUnbounded}, network_model::NetworkModel{AreaBalancePowerModel}, ) + add_feedforward_constraints!(container, model, devices) return end @@ -1051,5 +1061,6 @@ function construct_device!( network_model, inter_area_branch_map, ) + add_feedforward_constraints!(container, model, devices) return end From 07b8f2bb7de5c96b36447d3802b4d892b8392b96 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 31 Jul 2024 14:27:42 -0600 Subject: [PATCH 17/33] fix FF problems --- .../device_constructors/branch_constructor.jl | 14 ++++++-------- src/devices_models/devices/area_interchange.jl | 12 +++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index aba7e29ed4..d0cdf897b9 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -89,9 +89,8 @@ function construct_device!( if get_use_slacks(model) throw(ArgumentError("StaticBranchBounds is not compatible with the use of slacks")) end + devices = get_available_components(model, sys) if has_subnetworks(network_model) - devices = - get_available_components(model, sys) add_variables!( container, FlowActivePowerVariable, @@ -122,9 +121,8 @@ function construct_device!( NetworkModel{AreaBalancePowerModel}, }, ) where {T <: PSY.ACBranch} + devices = get_available_components(model, sys) if has_subnetworks(network_model) - devices = - get_available_components(model, sys) branch_rate_bounds!( container, devices, @@ -146,9 +144,8 @@ function construct_device!( NetworkModel{AreaBalancePowerModel}, }, ) where {T <: PSY.ACBranch} + devices = get_available_components(model, sys) if has_subnetworks(network_model) - devices = - get_available_components(model, sys) add_variables!( container, FlowActivePowerVariable, @@ -171,14 +168,15 @@ end function construct_device!( ::OptimizationContainer, - ::PSY.System, + sys::PSY.System, ::ModelConstructStage, - ::DeviceModel{<:PSY.ACBranch, StaticBranchUnbounded}, + model::DeviceModel{<:PSY.ACBranch, StaticBranchUnbounded}, network_model::Union{ NetworkModel{CopperPlatePowerModel}, NetworkModel{AreaBalancePowerModel}, }, ) + devices = get_available_components(model, sys) add_feedforward_constraints!(container, model, devices) return end diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index b01df8fdfb..1fdde8cee0 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -32,7 +32,7 @@ function add_variables!( model::NetworkModel{T}, devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, formulation::AbstractBranchFormulation, -) where {T <: PM.AbstractActivePowerModel} +) where {T <: PM.AbstractPowerModel} time_steps = get_time_steps(container) variable = add_variable_container!( @@ -53,6 +53,16 @@ function add_variables!( return end +function add_variables!( + container::OptimizationContainer, + ::Type{FlowActivePowerVariable}, + model::NetworkModel{CopperPlatePowerModel}, + devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, + formulation::AbstractBranchFormulation, +) + @warn("CopperPlatePowerModel ignores AreaInterchanges. Instead use AreaBalancePowerModel.") +end + """ Add flow constraints for area interchanges """ From 6eaef2f450afc9353f51b85d4494d00f591a0878 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 31 Jul 2024 14:46:56 -0600 Subject: [PATCH 18/33] add missing method --- src/devices_models/devices/area_interchange.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index 1fdde8cee0..0d7d933235 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -2,6 +2,8 @@ get_multiplier_value(::FromToFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = -1.0 * PSY.get_from_to_flow_limit(d) get_multiplier_value(::ToFromFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = PSY.get_to_from_flow_limit(d) +get_parameter_multiplier(::FixValueParameter, ::AreaInterchange, ::StaticBranch) = 1.0 + get_initial_conditions_device_model( ::OperationModel, model::DeviceModel{PSY.AreaInterchange, T}, From 5b5bd742dc1ffa0e78ac33dd18e72dfdf4cf314d Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 31 Jul 2024 14:51:26 -0600 Subject: [PATCH 19/33] add PSY predicate --- src/devices_models/devices/area_interchange.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index 0d7d933235..8c60313d52 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -2,7 +2,7 @@ get_multiplier_value(::FromToFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = -1.0 * PSY.get_from_to_flow_limit(d) get_multiplier_value(::ToFromFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = PSY.get_to_from_flow_limit(d) -get_parameter_multiplier(::FixValueParameter, ::AreaInterchange, ::StaticBranch) = 1.0 +get_parameter_multiplier(::FixValueParameter, ::PSY.AreaInterchange, ::StaticBranch) = 1.0 get_initial_conditions_device_model( ::OperationModel, From 466362d260f0698fb1363f8003b32435f4e33e5b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 31 Jul 2024 15:00:09 -0600 Subject: [PATCH 20/33] formatter --- src/devices_models/devices/area_interchange.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index 8c60313d52..8e5160c9f4 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -62,7 +62,9 @@ function add_variables!( devices::IS.FlattenIteratorWrapper{PSY.AreaInterchange}, formulation::AbstractBranchFormulation, ) - @warn("CopperPlatePowerModel ignores AreaInterchanges. Instead use AreaBalancePowerModel.") + @warn( + "CopperPlatePowerModel ignores AreaInterchanges. Instead use AreaBalancePowerModel." + ) end """ From 228ff3cb0cb81da05714d0fa20b107f6eafd6578 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 1 Aug 2024 12:07:16 -0600 Subject: [PATCH 21/33] add missing methods --- .../device_constructors/branch_constructor.jl | 14 +++++++++++++- src/devices_models/devices/area_interchange.jl | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index d0cdf897b9..92b8b1b6a4 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -886,6 +886,18 @@ function construct_device!( return end +function construct_device!( + container::OptimizationContainer, + sys::PSY.System, + ::ModelConstructStage, + model::DeviceModel{PSY.AreaInterchange, StaticBranchUnbounded}, + network_model::NetworkModel{T}, +) where {T <: PM.AbstractActivePowerModel} + devices = get_available_components(model, sys) + add_feedforward_constraints!(container, model, devices) + return +end + function construct_device!( container::OptimizationContainer, sys::PSY.System, @@ -957,7 +969,7 @@ function construct_device!( ::ModelConstructStage, model::DeviceModel{PSY.AreaInterchange, StaticBranch}, network_model::NetworkModel{T}, -) where {T <: AreaBalancePowerModel} +) where {T <: PM.AbstractActivePowerModel} devices = get_available_components(model, sys) add_constraints!(container, FlowLimitConstraint, devices, model, network_model) add_feedforward_constraints!(container, model, devices) diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index 8e5160c9f4..ac763f3f18 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -2,7 +2,9 @@ get_multiplier_value(::FromToFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = -1.0 * PSY.get_from_to_flow_limit(d) get_multiplier_value(::ToFromFlowLimitParameter, d::PSY.AreaInterchange, ::AbstractBranchFormulation) = PSY.get_to_from_flow_limit(d) -get_parameter_multiplier(::FixValueParameter, ::PSY.AreaInterchange, ::StaticBranch) = 1.0 +get_parameter_multiplier(::FixValueParameter, ::PSY.AreaInterchange, ::AbstractBranchFormulation) = 1.0 +get_parameter_multiplier(::LowerBoundValueParameter, ::PSY.AreaInterchange, ::AbstractBranchFormulation) = 1.0 +get_parameter_multiplier(::UpperBoundValueParameter, ::PSY.AreaInterchange, ::AbstractBranchFormulation) = 1.0 get_initial_conditions_device_model( ::OperationModel, From 5662db18283073521339d1a5987fa5965b990574 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 6 Aug 2024 13:03:28 -0600 Subject: [PATCH 22/33] formatter --- .../device_constructors/branch_constructor.jl | 39 +++------ .../renewablegeneration_constructor.jl | 18 ++-- .../thermalgeneration_constructor.jl | 87 +++++++------------ 3 files changed, 48 insertions(+), 96 deletions(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 92b8b1b6a4..87546cfe9d 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -326,8 +326,7 @@ function construct_device!( model::DeviceModel{T, StaticBranchBounds}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: PSY.ACBranch} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) branch_rate_bounds!( container, @@ -347,8 +346,7 @@ function construct_device!( model::DeviceModel{T, StaticBranchUnbounded}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: PSY.ACBranch} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, FlowActivePowerVariable, @@ -367,8 +365,7 @@ function construct_device!( model::DeviceModel{T, StaticBranchUnbounded}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: PSY.ACBranch} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_feedforward_constraints!(container, model, devices) add_constraints!(container, NetworkFlowConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) @@ -405,8 +402,7 @@ function construct_device!( model::DeviceModel{T, StaticBranch}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ACBranch} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) branch_rate_bounds!(container, devices, model, network_model) add_feedforward_constraints!(container, model, devices) add_constraints!(container, RateLimitConstraintFromTo, devices, model, network_model) @@ -553,8 +549,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalUnbounded}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, FlowActivePowerVariable, devices, HVDCTwoTerminalUnbounded()) add_to_expression!( container, @@ -596,8 +591,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalLossless}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!(container, FlowRateConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) return @@ -611,8 +605,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalLossless}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, FlowActivePowerVariable, devices, HVDCTwoTerminalLossless()) add_to_expression!( container, @@ -635,8 +628,7 @@ function construct_device!( ) where { T <: TwoTerminalHVDCTypes, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!(container, FlowRateConstraint, devices, model, network_model) add_constraint_dual!(container, sys, model) return @@ -649,8 +641,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, FlowActivePowerToFromVariable, @@ -699,8 +690,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{<:AbstractPTDFModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model) add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) add_constraints!(container, HVDCPowerBalance, devices, model, network_model) @@ -715,8 +705,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, FlowActivePowerToFromVariable, @@ -757,8 +746,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{CopperPlatePowerModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) @warn "CopperPlatePowerModel models with HVDC ignores inter-area losses" add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model) add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) @@ -773,8 +761,7 @@ function construct_device!( model::DeviceModel{T, HVDCTwoTerminalDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: TwoTerminalHVDCTypes} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!(container, FlowRateConstraintFromTo, devices, model, network_model) add_constraints!(container, FlowRateConstraintToFrom, devices, model, network_model) add_constraints!(container, HVDCPowerBalance, devices, model, network_model) diff --git a/src/devices_models/device_constructors/renewablegeneration_constructor.jl b/src/devices_models/device_constructors/renewablegeneration_constructor.jl index 7c05d30ceb..10939d52ea 100644 --- a/src/devices_models/device_constructors/renewablegeneration_constructor.jl +++ b/src/devices_models/device_constructors/renewablegeneration_constructor.jl @@ -8,8 +8,7 @@ function construct_device!( R <: PSY.RenewableGen, D <: AbstractRenewableDispatchFormulation, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) add_variables!(container, ReactivePowerVariable, devices, D()) @@ -62,8 +61,7 @@ function construct_device!( model::DeviceModel{R, <:AbstractRenewableDispatchFormulation}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {R <: PSY.RenewableGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) if has_service_model(model) add_constraints!( @@ -119,8 +117,7 @@ function construct_device!( R <: PSY.RenewableGen, D <: AbstractRenewableDispatchFormulation, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) @@ -164,8 +161,7 @@ function construct_device!( model::DeviceModel{R, <:AbstractRenewableDispatchFormulation}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {R <: PSY.RenewableGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) if has_service_model(model) add_constraints!( @@ -210,8 +206,7 @@ function construct_device!( model::DeviceModel{R, FixedOutput}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {R <: PSY.RenewableGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_parameters!(container, ReactivePowerTimeSeriesParameter, devices, model) @@ -242,8 +237,7 @@ function construct_device!( model::DeviceModel{R, FixedOutput}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {R <: PSY.RenewableGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_parameters!(container, ActivePowerTimeSeriesParameter, devices, model) add_to_expression!( diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index f24d154b08..8831cd3aa4 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -5,8 +5,7 @@ function construct_device!( device_model::DeviceModel{T, FixedOutput}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_parameters!(container, ActivePowerTimeSeriesParameter, devices, device_model) add_to_expression!( container, @@ -44,8 +43,7 @@ function construct_device!( T <: PSY.ThermalGen, D <: AbstractStandardUnitCommitment, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) add_variables!(container, ReactivePowerVariable, devices, D()) @@ -107,8 +105,7 @@ function construct_device!( model::DeviceModel{T, <:AbstractStandardUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -155,8 +152,7 @@ function construct_device!( model::DeviceModel{T, D}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen, D <: AbstractStandardUnitCommitment} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) add_variables!(container, OnVariable, devices, D()) @@ -210,8 +206,7 @@ function construct_device!( model::DeviceModel{T, <:AbstractStandardUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, ActivePowerVariableLimitsConstraint, @@ -251,8 +246,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, ThermalBasicUnitCommitment()) add_variables!(container, ReactivePowerVariable, devices, ThermalBasicUnitCommitment()) @@ -312,8 +306,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -359,8 +352,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, ThermalBasicUnitCommitment()) add_variables!(container, OnVariable, devices, ThermalBasicUnitCommitment()) @@ -411,8 +403,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -450,8 +441,7 @@ function construct_device!( model::DeviceModel{T, ThermalStandardDispatch}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, ThermalStandardDispatch()) add_variables!(container, ReactivePowerVariable, devices, ThermalStandardDispatch()) @@ -508,8 +498,7 @@ function construct_device!( model::DeviceModel{T, ThermalStandardDispatch}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -555,8 +544,7 @@ function construct_device!( model::DeviceModel{T, ThermalStandardDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, ThermalStandardDispatch()) @@ -604,8 +592,7 @@ function construct_device!( model::DeviceModel{T, ThermalStandardDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -643,8 +630,7 @@ function construct_device!( T <: PSY.ThermalGen, D <: AbstractThermalDispatchFormulation, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) add_variables!(container, ReactivePowerVariable, devices, D()) @@ -696,8 +682,7 @@ function construct_device!( model::DeviceModel{T, <:AbstractThermalDispatchFormulation}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -742,8 +727,7 @@ function construct_device!( T <: PSY.ThermalGen, D <: AbstractThermalDispatchFormulation, } - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, ActivePowerVariable, devices, D()) @@ -786,8 +770,7 @@ function construct_device!( model::DeviceModel{T, <:AbstractThermalDispatchFormulation}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1085,8 +1068,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, @@ -1157,8 +1139,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1203,8 +1184,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, @@ -1268,8 +1248,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1306,8 +1285,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, @@ -1376,8 +1354,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1420,8 +1397,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!( container, @@ -1483,8 +1459,7 @@ function construct_device!( model::DeviceModel{T, ThermalBasicCompactUnitCommitment}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1519,8 +1494,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactDispatch}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, PowerAboveMinimumVariable, devices, ThermalCompactDispatch()) add_variables!(container, ReactivePowerVariable, devices, ThermalCompactDispatch()) @@ -1603,8 +1577,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactDispatch}, network_model::NetworkModel{<:PM.AbstractPowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, @@ -1647,8 +1620,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_variables!(container, PowerAboveMinimumVariable, devices, ThermalCompactDispatch()) @@ -1706,8 +1678,7 @@ function construct_device!( model::DeviceModel{T, ThermalCompactDispatch}, network_model::NetworkModel{<:PM.AbstractActivePowerModel}, ) where {T <: PSY.ThermalGen} - devices = - get_available_components(model, sys) + devices = get_available_components(model, sys) add_constraints!( container, From 682d6a7e914d6419e19d5c37691d4354619b4125 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Aug 2024 13:11:20 -0600 Subject: [PATCH 23/33] fix missing devices --- src/devices_models/device_constructors/branch_constructor.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 87546cfe9d..e6c93daef5 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -1046,6 +1046,7 @@ function construct_device!( model::DeviceModel{PSY.AreaInterchange, StaticBranchUnbounded}, network_model::NetworkModel{AreaPTDFPowerModel}, ) + devices = get_available_components(model, sys) inter_area_branch_map = _get_branch_map(container, network_model, sys) # Not ideal to do this here, but it is a not terrible workaround # The area interchanges are like a services/device mix. From 24368a91cbcb8a2a6de6a78062d662842df515fe Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Fri, 30 Aug 2024 12:34:17 -0700 Subject: [PATCH 24/33] remove duplicate add expression --- .../thermalgeneration_constructor.jl | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 8831cd3aa4..5225586c43 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -1534,23 +1534,6 @@ function construct_device!( model, network_model, ) - add_to_expression!( - container, - ReactivePowerBalance, - ReactivePowerVariable, - devices, - model, - network_model, - ) - add_to_expression!( - container, - ActivePowerBalance, - OnStatusParameter, - devices, - model, - network_model, - ) - add_to_expression!( container, ActivePowerRangeExpressionLB, From 93624fb549c3d63e76fdf5059427643d3adde91a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Aug 2024 13:46:26 -0600 Subject: [PATCH 25/33] add missing arguments --- src/devices_models/device_constructors/branch_constructor.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index e6c93daef5..8f5d3c87fc 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -863,12 +863,13 @@ end ################################# AreaInterchange Models ################################ function construct_device!( - ::OptimizationContainer, + container::OptimizationContainer, ::PSY.System, ::ArgumentConstructStage, model::DeviceModel{PSY.AreaInterchange, U}, network_model::NetworkModel{CopperPlatePowerModel}, ) where {U <: Union{StaticBranchUnbounded, StaticBranch}} + devices = get_available_components(model, sys) add_feedforward_arguments!(container, model, devices) return end From 390123b2e76bb140d73d6deab8e0f0a1c1fb708e Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Fri, 30 Aug 2024 12:49:44 -0700 Subject: [PATCH 26/33] remove unavailable services from constructor --- src/services_models/services_constructor.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/services_models/services_constructor.jl b/src/services_models/services_constructor.jl index 09d9c9d2ec..6deb80d300 100644 --- a/src/services_models/services_constructor.jl +++ b/src/services_models/services_constructor.jl @@ -104,6 +104,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return add_parameters!(container, RequirementTimeSeriesParameter, service, model) contributing_devices = get_contributing_devices(model) @@ -130,6 +131,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_constraints!(container, RequirementConstraint, service, contributing_devices, model) @@ -160,6 +162,7 @@ function construct_service!( ) where {SR <: PSY.ConstantReserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_variables!( @@ -185,6 +188,7 @@ function construct_service!( ) where {SR <: PSY.ConstantReserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_constraints!(container, RequirementConstraint, service, contributing_devices, model) @@ -214,6 +218,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_variable!(container, ServiceRequirementVariable(), service, StepwiseCostReserve()) add_variables!( @@ -239,6 +244,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_constraints!(container, RequirementConstraint, service, contributing_devices, model) @@ -251,6 +257,7 @@ function construct_service!( return end +#= function construct_service!( container::OptimizationContainer, sys::PSY.System, @@ -343,6 +350,7 @@ function construct_service!( objective_function!(container, services, model) return end +=# """ Constructs a service for ConstantReserveGroup. @@ -358,6 +366,7 @@ function construct_service!( ) where {SR <: PSY.ConstantReserveGroup} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_services = PSY.get_contributing_services(service) # check if variables exist check_activeservice_variables(container, contributing_services) @@ -376,6 +385,7 @@ function construct_service!( ) where {SR <: PSY.ConstantReserveGroup} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_services = PSY.get_contributing_services(service) add_constraints!( @@ -401,6 +411,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_parameters!(container, RequirementTimeSeriesParameter, service, model) @@ -427,6 +438,7 @@ function construct_service!( ) where {SR <: PSY.Reserve} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_constraints!(container, RequirementConstraint, service, contributing_devices, model) @@ -458,6 +470,7 @@ function construct_service!( ) where {SR <: PSY.ReserveNonSpinning} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_parameters!(container, RequirementTimeSeriesParameter, service, model) @@ -483,6 +496,7 @@ function construct_service!( ) where {SR <: PSY.ReserveNonSpinning} name = get_service_name(model) service = PSY.get_component(SR, sys, name) + !PSY.get_available(service) && return contributing_devices = get_contributing_devices(model) add_constraints!(container, RequirementConstraint, service, contributing_devices, model) @@ -549,6 +563,7 @@ function construct_service!( ) where {T <: PSY.TransmissionInterface} name = get_service_name(model) service = PSY.get_component(T, sys, name) + !PSY.get_available(service) && return add_to_expression!( container, @@ -640,6 +655,7 @@ function construct_service!( ) where {T <: PSY.TransmissionInterface} name = get_service_name(model) service = PSY.get_component(T, sys, name) + !PSY.get_available(service) && return add_to_expression!( container, From 666ec920731feccf35bcc5e5e1437d1c708388aa Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 30 Aug 2024 13:53:08 -0600 Subject: [PATCH 27/33] add missing argument --- src/devices_models/device_constructors/branch_constructor.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 8f5d3c87fc..9aff973682 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -864,7 +864,7 @@ end ################################# AreaInterchange Models ################################ function construct_device!( container::OptimizationContainer, - ::PSY.System, + sys::PSY.System, ::ArgumentConstructStage, model::DeviceModel{PSY.AreaInterchange, U}, network_model::NetworkModel{CopperPlatePowerModel}, From a1f762ff4b02a363b19407ef48d44ed91e308f84 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Fri, 30 Aug 2024 12:57:05 -0700 Subject: [PATCH 28/33] fix upper bound and lower bound --- src/devices_models/devices/electric_loads.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices_models/devices/electric_loads.jl b/src/devices_models/devices/electric_loads.jl index 2452b18f7d..6725b2bd3e 100644 --- a/src/devices_models/devices/electric_loads.jl +++ b/src/devices_models/devices/electric_loads.jl @@ -7,14 +7,14 @@ get_variable_multiplier(_, ::Type{<:PSY.ElectricLoad}, ::AbstractLoadFormulation get_variable_binary(::ActivePowerVariable, ::Type{<:PSY.ElectricLoad}, ::AbstractLoadFormulation) = false get_variable_lower_bound(::ActivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = 0.0 -get_variable_upper_bound(::ActivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = PSY.get_active_power(d) +get_variable_upper_bound(::ActivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = PSY.get_max_active_power(d) ########################### ReactivePowerVariable, ElectricLoad #################################### get_variable_binary(::ReactivePowerVariable, ::Type{<:PSY.ElectricLoad}, ::AbstractLoadFormulation) = false get_variable_lower_bound(::ReactivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = 0.0 -get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = PSY.get_reactive_power(d) +get_variable_upper_bound(::ReactivePowerVariable, d::PSY.ElectricLoad, ::AbstractLoadFormulation) = PSY.get_max_reactive_power(d) ########################### ReactivePowerVariable, ElectricLoad #################################### From b3634e8fe09ccb54b51c4fbd13d07c9aa535536a Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Fri, 30 Aug 2024 13:44:24 -0700 Subject: [PATCH 29/33] fix pwl nomin --- .../objective_function/piecewise_linear.jl | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/devices_models/devices/common/objective_function/piecewise_linear.jl b/src/devices_models/devices/common/objective_function/piecewise_linear.jl index 37ae04b62d..7292be3c03 100644 --- a/src/devices_models/devices/common/objective_function/piecewise_linear.jl +++ b/src/devices_models/devices/common/objective_function/piecewise_linear.jl @@ -408,13 +408,20 @@ function _add_pwl_term!( end # Compact PWL data does not exists anymore - - if slopes[1] != 0.0 - @debug "PWL has no 0.0 intercept for generator $(component_name)" - # adds a first intercept a x = 0.0 and y below the intercept of the first tuple to make convex equivalent - intercept_point = (x = 0.0, y = first(data).y - COST_EPSILON) - data = PSY.PiecewiseLinearData(vcat(intercept_point, get_points(data))) - @assert PSY.is_convex(slopes) + x_coords = PSY.get_x_coords(data) + if x_coords[1] != 0.0 + y_coords = PSY.get_y_coords(data) + x_first = round(x_coords[1]; digits = 3) + y_first = round(y_coords[1]; digits = 3) + slope_first = round(slopes[1]; digits = 3) + guess_y_zero = y_coords[1] - slopes[1] * x_coords[1] + @warn( + "PWL has no 0.0 intercept for generator $(name). First point is given at (x = $(x_first), y = $(y_first)). Adding a first intercept at (x = 0.0, y = $(round(guess_y_zero, digits = 3)) to have equal initial slope $(slope_first)" + ) + # adds a first intercept a x = 0.0 and y above the intercept of the first tuple to make convex equivalent (avoid floating point issues of almost equal slopes) + intercept_point = (x = 0.0, y = guess_y_zero + COST_EPSILON) + data = PSY.PiecewiseLinearData(vcat(intercept_point, PSY.get_points(data))) + @assert PSY.is_convex(data) end time_steps = get_time_steps(container) @@ -422,7 +429,7 @@ function _add_pwl_term!( break_points = PSY.get_x_coords(data) sos_val = _get_sos_value(container, V, component) for t in time_steps - _add_pwl_variables!(container, T, component_name, t, data) + _add_pwl_variables!(container, T, name, t, data) _add_pwl_constraint!(container, component, U(), break_points, sos_val, t) pwl_cost = _get_pwl_cost_expression(container, component, t, cost_function, U(), V()) From bd8b9581b0f27cf6ae3efe31eb505b47b75b4256 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Fri, 30 Aug 2024 14:00:48 -0700 Subject: [PATCH 30/33] add error for negative intercept --- .../devices/common/objective_function/piecewise_linear.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/devices_models/devices/common/objective_function/piecewise_linear.jl b/src/devices_models/devices/common/objective_function/piecewise_linear.jl index 7292be3c03..bc184fb972 100644 --- a/src/devices_models/devices/common/objective_function/piecewise_linear.jl +++ b/src/devices_models/devices/common/objective_function/piecewise_linear.jl @@ -418,6 +418,11 @@ function _add_pwl_term!( @warn( "PWL has no 0.0 intercept for generator $(name). First point is given at (x = $(x_first), y = $(y_first)). Adding a first intercept at (x = 0.0, y = $(round(guess_y_zero, digits = 3)) to have equal initial slope $(slope_first)" ) + if guess_y_zero < 0.0 + error( + "Added zero intercept has negative cost for generator $(name). Consider using other formulation or improve data.", + ) + end # adds a first intercept a x = 0.0 and y above the intercept of the first tuple to make convex equivalent (avoid floating point issues of almost equal slopes) intercept_point = (x = 0.0, y = guess_y_zero + COST_EPSILON) data = PSY.PiecewiseLinearData(vcat(intercept_point, PSY.get_points(data))) From d3203e339389e0bc3b3e25d9b47548525d0a83a1 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 3 Sep 2024 22:53:09 -0600 Subject: [PATCH 31/33] fix interchange overwrite --- .../devices/area_interchange.jl | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/devices_models/devices/area_interchange.jl b/src/devices_models/devices/area_interchange.jl index ac763f3f18..84c953e54b 100644 --- a/src/devices_models/devices/area_interchange.jl +++ b/src/devices_models/devices/area_interchange.jl @@ -168,6 +168,7 @@ function add_constraints!( }, ) where {T <: AbstractPTDFModel} @assert !isempty(inter_area_branch_map) + time_steps = get_time_steps(container) device_names = [PSY.get_name(d) for d in devices] @@ -195,13 +196,16 @@ function add_constraints!( inter_change_name = PSY.get_name(area_interchange) area_from = PSY.get_from_area(area_interchange) area_to = PSY.get_to_area(area_interchange) + direction_branch_map = Dict{Float64, Dict{DataType, Vector{<:PSY.ACBranch}}}() if haskey(inter_area_branch_map, (area_from, area_to)) - inter_area_branches = inter_area_branch_map[(area_from, area_to)] - mult = 1.0 - elseif haskey(inter_area_branch_map, (area_to, area_from)) - inter_area_branches = inter_area_branch_map[(area_to, area_from)] - mult = -1.0 - else + # 1 is the multiplier + direction_branch_map[1.0] = inter_area_branch_map[(area_from, area_to)] + end + if haskey(inter_area_branch_map, (area_to, area_from)) + # -1 is the multiplier because the direction is reversed + direction_branch_map[-1.0] = inter_area_branch_map[(area_to, area_from)] + end + if isempty(direction_branch_map) @warn( "There are no branches modeled in Area InterChange $(summary(area_interchange)) \ LineFlowBoundConstraint not created" @@ -211,11 +215,13 @@ function add_constraints!( for t in time_steps sum_of_flows = JuMP.AffExpr() - for (type, branches) in inter_area_branches - flow_vars = get_variable(container, FlowActivePowerVariable(), type) - for b in branches - b_name = PSY.get_name(b) - _add_to_jump_expression!(sum_of_flows, flow_vars[b_name, t], mult) + for (mult, inter_area_branches) in direction_branch_map + for (type, branches) in inter_area_branches + flow_vars = get_variable(container, FlowActivePowerVariable(), type) + for b in branches + b_name = PSY.get_name(b) + _add_to_jump_expression!(sum_of_flows, flow_vars[b_name, t], mult) + end end end con_ub[inter_change_name, t] = From 192dc3c02a1fbc41631abf9d6f41fca946efd826 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 3 Sep 2024 23:23:52 -0600 Subject: [PATCH 32/33] add missing tests --- test/test_simulation_build.jl | 108 ++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/test/test_simulation_build.jl b/test/test_simulation_build.jl index 0b3f2e4d7c..d6d4293cab 100644 --- a/test/test_simulation_build.jl +++ b/test/test_simulation_build.jl @@ -212,3 +212,111 @@ end ) @test !isempty(c) end + +@testset "Test Upper/Lower Bound Feedforwards" begin + template_uc = get_template_basic_uc_simulation() + set_network_model!(template_uc, NetworkModel(PTDFPowerModel; use_slacks = true)) + set_device_model!(template_uc, DeviceModel(Line, StaticBranchUnbounded)) + template_ed = + get_template_nomin_ed_simulation(NetworkModel(PTDFPowerModel; use_slacks = true)) + set_device_model!(template_ed, DeviceModel(Line, StaticBranchUnbounded)) + c_sys5_hy_uc = PSB.build_system(PSITestSystems, "c_sys5_hy_uc") + c_sys5_hy_ed = PSB.build_system(PSITestSystems, "c_sys5_hy_ed") + models = SimulationModels(; + decision_models = [ + DecisionModel( + template_uc, + c_sys5_hy_uc; + name = "UC", + optimizer = HiGHS_optimizer, + initialize_model = false, + ), + DecisionModel( + template_ed, + c_sys5_hy_ed; + name = "ED", + optimizer = ipopt_optimizer, + initialize_model = false, + ), + ], + ) + + sequence = SimulationSequence(; + models = models, + feedforwards = Dict( + "ED" => [ + SemiContinuousFeedforward(; + component_type = ThermalStandard, + source = OnVariable, + affected_values = [ActivePowerVariable], + ), + LowerBoundFeedforward(; + component_type = Line, + source = FlowActivePowerVariable, + affected_values = [FlowActivePowerVariable], + add_slacks = true, + ), + UpperBoundFeedforward(; + component_type = Line, + source = FlowActivePowerVariable, + affected_values = [FlowActivePowerVariable], + add_slacks = true, + ), + ], + ), + ini_cond_chronology = InterProblemChronology(), + ) + + sim = Simulation(; + name = "reactive_feedforward", + steps = 2, + models = models, + sequence = sequence, + simulation_folder = mktempdir(; cleanup = true), + ) + build_out = build!(sim) + @test build_out == PSI.SimulationBuildStatus.BUILT + ed_power_model = PSI.get_simulation_model(PSI.get_models(sim), :ED) + c = PSI.get_constraint( + PSI.get_optimization_container(ed_power_model), + FeedforwardSemiContinuousConstraint(), + ThermalStandard, + "ActivePowerVariable_ub", + ) + @test !isempty(c) + c = PSI.get_constraint( + PSI.get_optimization_container(ed_power_model), + FeedforwardSemiContinuousConstraint(), + ThermalStandard, + "ActivePowerVariable_lb", + ) + @test !isempty(c) + c = PSI.get_constraint( + PSI.get_optimization_container(ed_power_model), + FeedforwardLowerBoundConstraint(), + Line, + "FlowActivePowerVariablelb", + ) + @test !isempty(c) + c = PSI.get_constraint( + PSI.get_optimization_container(ed_power_model), + FeedforwardUpperBoundConstraint(), + Line, + "FlowActivePowerVariableub", + ) + @test !isempty(c) + c = PSI.get_variable( + PSI.get_optimization_container(ed_power_model), + UpperBoundFeedForwardSlack(), + Line, + "FlowActivePowerVariable", + ) + @test !isempty(c) + c = PSI.get_variable( + PSI.get_optimization_container(ed_power_model), + LowerBoundFeedForwardSlack(), + Line, + "FlowActivePowerVariable", + ) + @test !isempty(c) +end From 53fc0900f0852c89adaf96b03d3f3d18761ee801 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 4 Sep 2024 17:15:04 -0600 Subject: [PATCH 33/33] fix tests --- test/test_network_constructors.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index 62be7f13f6..28e40011c8 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -964,7 +964,7 @@ end PSI.get_constraint(opt_container, CopperPlateBalanceConstraint(), PSY.Area) @test size(copper_plate_constraints) == (2, 24) - psi_checksolve_test(ps_model, [MOI.OPTIMAL], 662467, 1) + psi_checksolve_test(ps_model, [MOI.OPTIMAL], 671937, 1) results = OptimizationProblemResults(ps_model) interarea_flow = read_variable(results, "FlowActivePowerVariable__AreaInterchange")