From d20061c6f990a9d2fd6dd533da9ca40e5bba602e Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Wed, 16 Oct 2024 20:58:55 -0700 Subject: [PATCH] add expressions for all formulations --- .../thermalgeneration_constructor.jl | 145 +++++++++++++++++- .../devices/common/add_to_expression.jl | 90 ++++++++++- 2 files changed, 231 insertions(+), 4 deletions(-) diff --git a/src/devices_models/device_constructors/thermalgeneration_constructor.jl b/src/devices_models/device_constructors/thermalgeneration_constructor.jl index 6d5d19fa6..37a5332e2 100644 --- a/src/devices_models/device_constructors/thermalgeneration_constructor.jl +++ b/src/devices_models/device_constructors/thermalgeneration_constructor.jl @@ -78,6 +78,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -95,6 +96,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return end @@ -193,6 +201,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -210,6 +219,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -307,6 +323,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -324,6 +341,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -419,6 +443,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -436,6 +461,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -524,6 +556,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -541,6 +574,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -618,6 +658,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -635,6 +676,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -711,6 +759,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -728,6 +777,13 @@ function construct_device!( model, network_model, ) + add_to_expression!( + container, + FuelConsumptionExpression, + ActivePowerVariable, + devices, + model, + ) add_feedforward_arguments!(container, model, devices) return @@ -803,7 +859,6 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) - add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( @@ -931,6 +986,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -948,6 +1004,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return @@ -1073,6 +1139,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1090,6 +1157,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return @@ -1213,6 +1290,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1230,6 +1308,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return @@ -1337,6 +1425,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1354,6 +1443,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return end @@ -1456,6 +1555,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1473,6 +1573,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return @@ -1576,6 +1686,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1593,6 +1704,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# add_feedforward_arguments!(container, model, devices) return end @@ -1672,6 +1793,7 @@ function construct_device!( ) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1705,6 +1827,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# return end @@ -1789,6 +1921,7 @@ function construct_device!( initial_conditions!(container, devices, ThermalCompactDispatch()) add_expressions!(container, ProductionCostExpression, devices, model) + add_expressions!(container, FuelConsumptionExpression, devices, model) add_to_expression!( container, @@ -1806,6 +1939,16 @@ function construct_device!( model, network_model, ) + #TODO: Implement for AbovePowerMinimum + #= + add_to_expression!( + container, + FuelConsumptionExpression, + PowerAboveMinimumVariable,, + devices, + model, + ) + =# return end diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index 9c053de1e..b0a74234d 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -41,7 +41,9 @@ function add_expressions!( PSY.get_name(d) for d in devices if PSY.get_variable(PSY.get_operation_cost(d)) isa PSY.FuelCurve ] - add_expression_container!(container, T(), D, names, time_steps) + if !isempty(names) + add_expression_container!(container, T(), D, names, time_steps) + end return end @@ -1562,9 +1564,86 @@ function add_to_expression!( T <: FuelConsumptionExpression, U <: ActivePowerVariable, V <: PSY.ThermalGen, - W <: AbstractThermalDispatchFormulation, + W <: AbstractDeviceFormulation, +} + variable = get_variable(container, U(), V) + time_steps = get_time_steps(container) + base_power = get_base_power(container) + resolution = get_resolution(container) + dt = Dates.value(resolution) / MILLISECONDS_IN_HOUR + for d in devices + var_cost = PSY.get_variable(PSY.get_operation_cost(d)) + if !(var_cost isa PSY.FuelCurve) + continue + end + expression = get_expression(container, T(), V) + name = PSY.get_name(d) + device_base_power = PSY.get_base_power(d) + value_curve = PSY.get_value_curve(var_cost) + if value_curve isa PSY.LinearCurve + power_units = PSY.get_power_units(var_cost) + proportional_term = PSY.get_proportional_term(value_curve) + prop_term_per_unit = get_proportional_cost_per_system_unit( + proportional_term, + power_units, + base_power, + device_base_power, + ) + for t in time_steps + fuel_expr = variable[name, t] * prop_term_per_unit * dt + JuMP.add_to_expression!( + expression[name, t], + fuel_expr, + ) + end + elseif value_curve isa PSY.QuadraticCurve + power_units = PSY.get_power_units(var_cost) + proportional_term = PSY.get_proportional_term(value_curve) + quadratic_term = PSY.get_quadratic_term(value_curve) + prop_term_per_unit = get_proportional_cost_per_system_unit( + proportional_term, + power_units, + base_power, + device_base_power, + ) + quad_term_per_unit = get_quadratic_cost_per_system_unit( + quadratic_term, + power_units, + base_power, + device_base_power, + ) + # TODO: Fix this FuelConsumptionExpression AffExpr to QuadExpr + #= + for t in time_steps + fuel_expr = + ( + variable[name, t] .^ 2 * quad_term_per_unit + + variable[name, t] * prop_term_per_unit + ) * dt + JuMP.add_to_expression!( + expression[name, t], + fuel_expr, + ) + end + =# + end + end +end + +#TODO: FuelConsumption for PowerAboveMinimumVariable +#= +function add_to_expression!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + devices::IS.FlattenIteratorWrapper{V}, + model::DeviceModel{V, W}, +) where { + T <: FuelConsumptionExpression, + U <: PowerAboveMinimumVariable, + V <: PSY.ThermalGen, + W <: AbstractDeviceFormulation, } - expression = get_expression(container, T(), V) variable = get_variable(container, U(), V) time_steps = get_time_steps(container) base_power = get_base_power(container) @@ -1575,6 +1654,7 @@ function add_to_expression!( if !(var_cost isa PSY.FuelCurve) continue end + expression = get_expression(container, T(), V) name = PSY.get_name(d) device_base_power = PSY.get_base_power(d) value_curve = PSY.get_value_curve(var_cost) @@ -1610,6 +1690,8 @@ function add_to_expression!( base_power, device_base_power, ) + # TODO: Fix this FuelConsumptionExpression AffExpr to QuadExpr + #= for t in time_steps fuel_expr = ( @@ -1621,9 +1703,11 @@ function add_to_expression!( fuel_expr, ) end + =# end end end +=# #= function add_to_expression!(