Skip to content

Commit

Permalink
update energy target to reservoir target
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Oct 10, 2023
1 parent e16cb0e commit 7106ea0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/HydroPowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ export WaterSpillageVariable
export HydroEnergyShortageVariable

######## Hydro parameters #######
export EnergyTargetParameter
export ReservoirTargetParameter

######## Hydro Initial Conditions #######
export InitialHydroEnergyLevelUp
export InitialHydroEnergyLevelDown

######## Hydro feedforwards #######
export ReservoirTargetFeedforward

#################################################################################
# Imports
using PowerSystems
Expand Down
4 changes: 2 additions & 2 deletions src/core/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct OutflowTimeSeriesParameter <: PSI.TimeSeriesParameter end
"""
Parameter to define energy target
"""
struct EnergyTargetParameter <: PSI.VariableValueParameter end
struct ReservoirTargetParameter <: PSI.VariableValueParameter end

PSI.convert_result_to_natural_units(::Type{EnergyTargetTimeSeriesParameter}) = true
PSI.convert_result_to_natural_units(::Type{EnergyBudgetTimeSeriesParameter}) = true
PSI.convert_result_to_natural_units(::Type{EnergyTargetParameter}) = true
PSI.convert_result_to_natural_units(::Type{ReservoirTargetParameter}) = true

Check warning on line 28 in src/core/parameters.jl

View check run for this annotation

Codecov / codecov/patch

src/core/parameters.jl#L28

Added line #L28 was not covered by tests
PSI.convert_result_to_natural_units(::Type{InflowTimeSeriesParameter}) = true # TODO: is this pu?
PSI.convert_result_to_natural_units(::Type{OutflowTimeSeriesParameter}) = true # TODO: is this pu?
50 changes: 44 additions & 6 deletions src/feedforwards.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
"""
Adds a constraint to enforce a minimum reservoir level target with a slack variable associated witha penalty term.
"""
struct ReservoirTargetFeedforward <: PSI.AbstractAffectFeedforward
optimization_container_key::PSI.OptimizationContainerKey
affected_values::Vector{<:PSI.OptimizationContainerKey}
target_period::Int
penalty_cost::Float64
function ReservoirTargetFeedforward(;
component_type::Type{<:PSY.Component},
source::Type{T},
affected_values::Vector{DataType},
target_period::Int,
penalty_cost::Float64,
meta=PSI.CONTAINER_KEY_EMPTY_META,
) where {T}
values_vector = Vector{PSI.VariableKey}(undef, length(affected_values))
for (ix, v) in enumerate(affected_values)
if v <: PSI.VariableType
values_vector[ix] =
PSI.get_optimization_container_key(v(), component_type, meta)
else
error(

Check warning on line 23 in src/feedforwards.jl

View check run for this annotation

Codecov / codecov/patch

src/feedforwards.jl#L23

Added line #L23 was not covered by tests
"ReservoirTargetFeedforward is only compatible with VariableType or ParamterType affected values",
)
end
end
new(
PSI.get_optimization_container_key(T(), component_type, meta),
values_vector,
target_period,
penalty_cost,
)
end
end

PSI.get_default_parameter_type(::ReservoirTargetFeedforward, _) = ReservoirTargetParameter
PSI.get_optimization_container_key(ff::ReservoirTargetFeedforward) =
ff.optimization_container_key

@doc raw"""
add_feedforward_constraints(
container::PSI.OptimizationContainer,
::PSI.DeviceModel,
devices::IS.FlattenIteratorWrapper{T},
ff::EnergyTargetFeedforward,
ff::ReservoirTargetFeedforward,
) where {T <: PSY.Component}
Constructs a equality constraint to a fix a variable in one model using the variable value from other model results.
Expand All @@ -19,13 +59,13 @@ Constructs a equality constraint to a fix a variable in one model using the vari
* container::PSI.OptimizationContainer : the optimization_container model built in PowerSimulations
* model::PSI.DeviceModel : the device model
* devices::IS.FlattenIteratorWrapper{T} : list of devices
* ff::EnergyTargetFeedforward : a instance of the FixValue Feedforward
* ff::ReservoirTargetFeedforward : a instance of the FixValue Feedforward
"""
function PSI.add_feedforward_constraints!(
container::PSI.OptimizationContainer,
::PSI.DeviceModel{T, U},
devices::IS.FlattenIteratorWrapper{T},
ff::PSI.EnergyTargetFeedforward,
ff::ReservoirTargetFeedforward,
) where {T <: PSY.HydroGen, U <: AbstractHydroFormulation}
time_steps = PSI.get_time_steps(container)
parameter_type = PSI.get_default_parameter_type(ff, T)
Expand Down Expand Up @@ -69,7 +109,7 @@ function PSI._add_feedforward_arguments!(
container::PSI.OptimizationContainer,
model::PSI.DeviceModel{T, U},
devices::IS.FlattenIteratorWrapper{T},
ff::PSI.EnergyTargetFeedforward,
ff::ReservoirTargetFeedforward,
) where {T <: PSY.HydroGen, U <: AbstractHydroFormulation}
parameter_type = PSI.get_default_parameter_type(ff, T)
PSI.add_parameters!(container, parameter_type, ff, model, devices)
Expand All @@ -82,5 +122,3 @@ function PSI._add_feedforward_arguments!(
)
return
end

get_default_parameter_type(::PSI.EnergyTargetFeedforward, _) = EnergyTargetParameter
4 changes: 2 additions & 2 deletions test/test_device_hydro_generation_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ end
moi_tests(model, 110, 0, 25, 24, 24, true)
end

@testset "Test EnergyTargetFeedforward to HydroEnergyReservoir models" begin
@testset "Test ReservoirTargetFeedforward to HydroEnergyReservoir models" begin
device_model = PSI.DeviceModel(HydroPumpedStorage, HydroDispatchPumpedStorage)

ff_up = PSI.EnergyTargetFeedforward(;
ff_up = ReservoirTargetFeedforward(;
component_type=HydroPumpedStorage,
source=HydroEnergyVariableUp,
affected_values=[HydroEnergyVariableUp],
Expand Down

0 comments on commit 7106ea0

Please sign in to comment.