From f852af23e7118dca4e4a6aa85159fcce0f5d9d99 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Thu, 25 Jan 2024 16:24:29 -0700 Subject: [PATCH 1/5] fix bug in ramp rates --- .../common/rateofchange_constraints.jl | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/devices_models/devices/common/rateofchange_constraints.jl b/src/devices_models/devices/common/rateofchange_constraints.jl index ba134bd175..c5e442f6b7 100644 --- a/src/devices_models/devices/common/rateofchange_constraints.jl +++ b/src/devices_models/devices/common/rateofchange_constraints.jl @@ -91,25 +91,24 @@ function add_linear_ramp_constraints!( ramp_limits = PSY.get_ramp_limits(get_component(ic)) ic_power = get_value(ic) @debug "add rate_of_change_constraint" name ic_power - @assert (parameters && isa(ic_power, JuMP.VariableRef)) || !parameters con_up[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), expr_up[name, 1] - ic_power <= ramp_limits.up * minutes_per_period ) con_down[name, 1] = JuMP.@constraint( - container.JuMPmodel, - ic_power - expr_dn[name, 1] >= -1 * ramp_limits.down * minutes_per_period + get_jump_model(container), + ic_power - expr_dn[name, 1] <= ramp_limits.down * minutes_per_period ) for t in time_steps[2:end] con_up[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), expr_up[name, t] - variable[name, t - 1] <= ramp_limits.up * minutes_per_period ) con_down[name, t] = JuMP.@constraint( - container.JuMPmodel, - variable[name, t - 1] - expr_dn[name, t] >= - -1 * ramp_limits.down * minutes_per_period + get_jump_model(container), + variable[name, t - 1] - expr_dn[name, t] <= + ramp_limits.down * minutes_per_period ) end end @@ -147,21 +146,21 @@ function add_linear_ramp_constraints!( @debug "add rate_of_change_constraint" name ic_power @assert (parameters && isa(ic_power, JuMP.VariableRef)) || !parameters con_up[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, 1] - ic_power <= ramp_limits.up * minutes_per_period ) con_down[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), ic_power - variable[name, 1] <= ramp_limits.down * minutes_per_period ) for t in time_steps[2:end] con_up[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, t] - variable[name, t - 1] <= ramp_limits.up * minutes_per_period ) con_down[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, t - 1] - variable[name, t] <= ramp_limits.down * minutes_per_period ) @@ -234,23 +233,23 @@ function add_semicontinuous_ramp_constraints!( @debug "add rate_of_change_constraint" name ic_power con_up[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), expr_up[name, 1] - ic_power <= ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, 1] ) con_down[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), ic_power - expr_dn[name, 1] <= ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, 1] ) for t in time_steps[2:end] con_up[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), expr_up[name, t] - variable[name, t - 1] <= ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, t] ) con_down[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, t - 1] - expr_dn[name, t] <= ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, t] ) @@ -295,23 +294,23 @@ function add_semicontinuous_ramp_constraints!( @debug "add rate_of_change_constraint" name ic_power @assert (parameters && isa(ic_power, JuMP.VariableRef)) || !parameters con_up[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, 1] - ic_power <= ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, 1] ) con_down[name, 1] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), ic_power - variable[name, 1] <= ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, 1] ) for t in time_steps[2:end] con_up[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, t] - variable[name, t - 1] <= ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, t] ) con_down[name, t] = JuMP.@constraint( - container.JuMPmodel, + get_jump_model(container), variable[name, t - 1] - variable[name, t] <= ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, t] ) From 2e5be0ebe68ae42454e481c7808d55e0e240fdc7 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 26 Jan 2024 14:21:41 -0700 Subject: [PATCH 2/5] WIP: fix ramp --- src/PowerSimulations.jl | 2 -- src/core/expressions.jl | 2 -- src/devices_models/devices/common/add_to_expression.jl | 9 ++++++--- .../devices/common/rateofchange_constraints.jl | 5 ++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index 7dca8191ef..e7e9a7a7a0 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -319,9 +319,7 @@ export EmergencyDown export RawACE export ProductionCostExpression export ActivePowerRangeExpressionLB -export ReserveRangeExpressionLB export ActivePowerRangeExpressionUB -export ReserveRangeExpressionUB ################################################################################# # Imports diff --git a/src/core/expressions.jl b/src/core/expressions.jl index ab981f4f45..9698a05ac9 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -41,9 +41,7 @@ struct RawACE <: ExpressionType end struct ProductionCostExpression <: CostExpressions end struct ActivePowerRangeExpressionLB <: RangeConstraintLBExpressions end struct ComponentActivePowerRangeExpressionLB <: RangeConstraintLBExpressions end -struct ReserveRangeExpressionLB <: RangeConstraintLBExpressions end struct ActivePowerRangeExpressionUB <: RangeConstraintUBExpressions end -struct ReserveRangeExpressionUB <: RangeConstraintUBExpressions end struct ComponentActivePowerRangeExpressionUB <: RangeConstraintUBExpressions end struct ComponentReserveUpBalanceExpression <: ExpressionType end struct ComponentReserveDownBalanceExpression <: ExpressionType end diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 29bd067dd9..5ad1d10058 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -975,7 +975,7 @@ function add_to_expression!( devices::Union{Vector{V}, IS.FlattenIteratorWrapper{V}}, model::ServiceModel{X, W}, ) where { - T <: Union{ActivePowerRangeExpressionLB, ReserveRangeExpressionLB}, + T <: ActivePowerRangeExpressionLB, U <: VariableType, V <: PSY.Component, X <: PSY.Reserve{PSY.ReserveDown}, @@ -989,7 +989,7 @@ function add_to_expression!( expression = get_expression(container, T(), V) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) - _add_to_jump_expression!(expression[name, t], variable[name, t], -1.0) + _add_to_jump_expression!(expression[name, t], variable[name, t], 1.0) end return end @@ -1011,7 +1011,8 @@ function add_to_expression!( add_expressions!(container, T, devices, model) end expression = get_expression(container, T(), V) - for d in devices, mult in get_expression_multiplier(U(), T(), d, W()) + for d in devices + mult in get_expression_multiplier(U(), T(), d, W()) for t in get_time_steps(container) name = PSY.get_name(d) _add_to_jump_expression!( @@ -1037,6 +1038,8 @@ function add_to_expression!( V <: PSY.ThermalGen, W <: AbstractThermalDispatchFormulation, } + @show "here" + error() parameter_array = get_parameter_array(container, U(), V) if !has_container_key(container, T, V) add_expressions!(container, T, devices, model) diff --git a/src/devices_models/devices/common/rateofchange_constraints.jl b/src/devices_models/devices/common/rateofchange_constraints.jl index c5e442f6b7..df0ba96cc8 100644 --- a/src/devices_models/devices/common/rateofchange_constraints.jl +++ b/src/devices_models/devices/common/rateofchange_constraints.jl @@ -62,13 +62,12 @@ function add_linear_ramp_constraints!( U::Type{S}, devices::IS.FlattenIteratorWrapper{V}, model::DeviceModel{V, W}, - X::Type{<:PM.AbstractPowerModel}, + ::Type{<:PM.AbstractPowerModel}, ) where { S <: Union{PowerAboveMinimumVariable, ActivePowerVariable}, V <: PSY.Component, W <: AbstractDeviceFormulation, } - parameters = built_for_recurrent_solves(container) time_steps = get_time_steps(container) variable = get_variable(container, U(), V) ramp_devices = _get_ramp_constraint_devices(container, devices) @@ -90,7 +89,7 @@ function add_linear_ramp_constraints!( name ∉ set_name && continue ramp_limits = PSY.get_ramp_limits(get_component(ic)) ic_power = get_value(ic) - @debug "add rate_of_change_constraint" name ic_power + @error "add rate_of_change_constraint" name ic_power con_up[name, 1] = JuMP.@constraint( get_jump_model(container), expr_up[name, 1] - ic_power <= ramp_limits.up * minutes_per_period From dd7a4c98c0d82a064ad723c2819edd1d99e64588 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 26 Jan 2024 17:02:41 -0700 Subject: [PATCH 3/5] remove more unused types --- src/core/expressions.jl | 2 -- src/devices_models/devices/common/add_to_expression.jl | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/expressions.jl b/src/core/expressions.jl index 9698a05ac9..985e53844b 100644 --- a/src/core/expressions.jl +++ b/src/core/expressions.jl @@ -40,9 +40,7 @@ struct EmergencyDown <: ExpressionType end struct RawACE <: ExpressionType end struct ProductionCostExpression <: CostExpressions end struct ActivePowerRangeExpressionLB <: RangeConstraintLBExpressions end -struct ComponentActivePowerRangeExpressionLB <: RangeConstraintLBExpressions end struct ActivePowerRangeExpressionUB <: RangeConstraintUBExpressions end -struct ComponentActivePowerRangeExpressionUB <: RangeConstraintUBExpressions end struct ComponentReserveUpBalanceExpression <: ExpressionType end struct ComponentReserveDownBalanceExpression <: ExpressionType end struct InterfaceTotalFlow <: ExpressionType end diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 5ad1d10058..c93083bb8b 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -903,7 +903,7 @@ function add_to_expression!( devices::Union{Vector{V}, IS.FlattenIteratorWrapper{V}}, model::ServiceModel{X, W}, ) where { - T <: Union{ActivePowerRangeExpressionUB, ReserveRangeExpressionUB}, + T <: ActivePowerRangeExpressionUB, U <: VariableType, V <: PSY.Component, X <: PSY.Reserve{PSY.ReserveUp}, @@ -989,7 +989,7 @@ function add_to_expression!( expression = get_expression(container, T(), V) for d in devices, t in get_time_steps(container) name = PSY.get_name(d) - _add_to_jump_expression!(expression[name, t], variable[name, t], 1.0) + _add_to_jump_expression!(expression[name, t], variable[name, t], -1.0) end return end From a809ea0a7d5886204a143b11047b70c66d9497d2 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 26 Jan 2024 17:34:49 -0700 Subject: [PATCH 4/5] remove debugging code --- src/devices_models/devices/common/add_to_expression.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index c93083bb8b..c3127f79ba 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -1038,8 +1038,6 @@ function add_to_expression!( V <: PSY.ThermalGen, W <: AbstractThermalDispatchFormulation, } - @show "here" - error() parameter_array = get_parameter_array(container, U(), V) if !has_container_key(container, T, V) add_expressions!(container, T, devices, model) From bcc2316a8c6036044de80b76a17aa4ceb0343b5a Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Fri, 26 Jan 2024 17:34:59 -0700 Subject: [PATCH 5/5] remove repeated code --- .../common/rateofchange_constraints.jl | 61 ------------------- 1 file changed, 61 deletions(-) diff --git a/src/devices_models/devices/common/rateofchange_constraints.jl b/src/devices_models/devices/common/rateofchange_constraints.jl index df0ba96cc8..7f9ec2a5d5 100644 --- a/src/devices_models/devices/common/rateofchange_constraints.jl +++ b/src/devices_models/devices/common/rateofchange_constraints.jl @@ -256,64 +256,3 @@ function add_semicontinuous_ramp_constraints!( end return end - -function add_semicontinuous_ramp_constraints!( - container::OptimizationContainer, - T::Type{<:ConstraintType}, - U::Type{<:VariableType}, - devices::IS.FlattenIteratorWrapper{V}, - model::DeviceModel{V, W}, - X::Type{<:PM.AbstractPowerModel}, -) where {V <: PSY.Component, W <: AbstractDeviceFormulation} - parameters = built_for_recurrent_solves(container) - time_steps = get_time_steps(container) - variable = get_variable(container, U(), V) - varstart = get_variable(container, StartVariable(), V) - varstop = get_variable(container, StopVariable(), V) - - ramp_devices = _get_ramp_constraint_devices(container, devices) - minutes_per_period = _get_minutes_per_period(container) - IC = _get_initial_condition_type(T, V, W) - initial_conditions_power = get_initial_condition(container, IC(), V) - - set_name = [PSY.get_name(r) for r in ramp_devices] - con_up = - add_constraints_container!(container, T(), V, set_name, time_steps; meta = "up") - con_down = - add_constraints_container!(container, T(), V, set_name, time_steps; meta = "dn") - - for ic in initial_conditions_power - name = get_component_name(ic) - # This is to filter out devices that dont need a ramping constraint - name ∉ set_name && continue - device = get_component(ic) - ramp_limits = PSY.get_ramp_limits(device) - power_limits = PSY.get_active_power_limits(device) - ic_power = get_value(ic) - @debug "add rate_of_change_constraint" name ic_power - @assert (parameters && isa(ic_power, JuMP.VariableRef)) || !parameters - con_up[name, 1] = JuMP.@constraint( - get_jump_model(container), - variable[name, 1] - ic_power <= - ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, 1] - ) - con_down[name, 1] = JuMP.@constraint( - get_jump_model(container), - ic_power - variable[name, 1] <= - ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, 1] - ) - for t in time_steps[2:end] - con_up[name, t] = JuMP.@constraint( - get_jump_model(container), - variable[name, t] - variable[name, t - 1] <= - ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, t] - ) - con_down[name, t] = JuMP.@constraint( - get_jump_model(container), - variable[name, t - 1] - variable[name, t] <= - ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, t] - ) - end - end - return -end