generated from NREL-Sienna/SiennaTemplate.jl
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
restore ff code #13
Merged
Merged
restore ff code #13
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -83,58 +83,112 @@ function PSI.add_feedforward_constraints!( | |||||
return | ||||||
end | ||||||
|
||||||
#= | ||||||
# TODO: Check if this is should be restored | ||||||
function PSI._add_variable_cost_to_objective!( | ||||||
container::PSI.OptimizationContainer, | ||||||
::T, | ||||||
component::U, | ||||||
op_cost::PSY.MarketBidCost, | ||||||
::V, | ||||||
) where {T <: PSI.EnergySurplusVariable, U <: PSY.Storage, V <: EnergyValueCurve} | ||||||
component_name = PSY.get_name(component) | ||||||
@debug "Market Bid" _group = PSI.LOG_GROUP_COST_FUNCTIONS component_name | ||||||
time_steps = PSI.get_time_steps(container) | ||||||
initial_time = PSI.get_initial_time(container) | ||||||
variable_cost_forecast = PSY.get_variable_cost( | ||||||
component, | ||||||
op_cost; | ||||||
start_time=initial_time, | ||||||
len=length(time_steps), | ||||||
) | ||||||
variable_cost_forecast_values = TimeSeries.values(variable_cost_forecast) | ||||||
parameter_container = PSI._get_cost_function_parameter_container( | ||||||
container, | ||||||
PSI.CostFunctionParameter(), | ||||||
component, | ||||||
T(), | ||||||
V(), | ||||||
eltype(variable_cost_forecast_values), | ||||||
) | ||||||
pwl_cost_expressions = | ||||||
PSI._add_pwl_term!(container, component, variable_cost_forecast_values, T(), V()) | ||||||
jump_model = PSI.get_jump_model(container) | ||||||
for t in time_steps | ||||||
PSI.set_parameter!( | ||||||
parameter_container, | ||||||
jump_model, | ||||||
PSY.get_cost(variable_cost_forecast_values[t]), | ||||||
# Using 1.0 here since we want to reuse the existing code that adds the mulitpler | ||||||
# of base power times the time delta. | ||||||
1.0, | ||||||
component_name, | ||||||
t, | ||||||
""" | ||||||
Adds a constraint to limit the sum of a variable over the number of periods to the source value | ||||||
""" | ||||||
struct EnergyLimitFeedforward <: PSI.AbstractAffectFeedforward | ||||||
optimization_container_key::PSI.OptimizationContainerKey | ||||||
affected_values::Vector{<:PSI.OptimizationContainerKey} | ||||||
number_of_periods::Int | ||||||
function EnergyLimitFeedforward(; | ||||||
component_type::Type{<:PSY.Component}, | ||||||
source::Type{T}, | ||||||
affected_values::Vector{DataType}, | ||||||
number_of_periods::Int, | ||||||
meta = CONTAINER_KEY_EMPTY_META, | ||||||
) where {T} | ||||||
values_vector = Vector{VariableKey}(undef, length(affected_values)) | ||||||
for (ix, v) in enumerate(affected_values) | ||||||
if v <: VariableType | ||||||
values_vector[ix] = | ||||||
PSI.get_optimization_container_key(v(), component_type, meta) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
else | ||||||
error( | ||||||
"EnergyLimitFeedforward is only compatible with VariableType or ParamterType affected values", | ||||||
) | ||||||
end | ||||||
end | ||||||
new( | ||||||
PSI.get_optimization_container_key(T(), component_type, meta), | ||||||
values_vector, | ||||||
number_of_periods, | ||||||
) | ||||||
PSI.add_to_expression!( | ||||||
end | ||||||
end | ||||||
|
||||||
PSI.get_default_parameter_type(::EnergyLimitFeedforward, _) = EnergyLimitParameter | ||||||
PSI.get_optimization_container_key(ff) = ff.optimization_container_key | ||||||
PSI.get_number_of_periods(ff) = ff.number_of_periods | ||||||
|
||||||
@doc raw""" | ||||||
add_feedforward_constraints(container::OptimizationContainer, | ||||||
cons_name::Symbol, | ||||||
param_reference, | ||||||
var_key::VariableKey) | ||||||
|
||||||
Constructs a parameterized integral limit constraint to implement feedforward from other models. | ||||||
The Parameters are initialized using the upper boundary values of the provided variables. | ||||||
|
||||||
|
||||||
``` sum(variable[var_name, t] for t in 1:affected_periods)/affected_periods <= param_reference[var_name] ``` | ||||||
|
||||||
# LaTeX | ||||||
|
||||||
`` \sum_{t} x \leq param^{max}`` | ||||||
|
||||||
# Arguments | ||||||
* container::OptimizationContainer : the optimization_container model built in PowerSimulations | ||||||
* model::DeviceModel : the device model | ||||||
* devices::IS.FlattenIteratorWrapper{T} : list of devices | ||||||
* ff::FixValueFeedforward : a instance of the FixValue Feedforward | ||||||
""" | ||||||
function add_feedforward_constraints!( | ||||||
container::OptimizationContainer, | ||||||
::DeviceModel, | ||||||
devices::IS.FlattenIteratorWrapper{T}, | ||||||
ff::EnergyLimitFeedforward, | ||||||
) where {T <: PSY.Component} | ||||||
time_steps = get_time_steps(container) | ||||||
parameter_type = get_default_parameter_type(ff, T) | ||||||
param = get_parameter_array(container, parameter_type(), T) | ||||||
multiplier = get_parameter_multiplier_array(container, parameter_type(), T) | ||||||
affected_periods = get_number_of_periods(ff) | ||||||
for var in get_affected_values(ff) | ||||||
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 | ||||||
|
||||||
if affected_periods > set_time[end] | ||||||
error( | ||||||
"The number of affected periods $affected_periods is larger than the periods available $(set_time[end])", | ||||||
) | ||||||
end | ||||||
no_trenches = set_time[end] ÷ affected_periods | ||||||
var_type = get_entry_type(var) | ||||||
con_ub = add_constraints_container!( | ||||||
container, | ||||||
PSI.ProductionCostExpression, | ||||||
pwl_cost_expressions[t], | ||||||
component, | ||||||
t, | ||||||
FeedforwardIntegralLimitConstraint(), | ||||||
T, | ||||||
set_name, | ||||||
1:no_trenches; | ||||||
meta = "$(var_type)integral", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
) | ||||||
PSI.add_to_objective_variant_expression!(container, pwl_cost_expressions[t]) | ||||||
end | ||||||
|
||||||
for name in set_name, i in 1:no_trenches | ||||||
con_ub[name, i] = JuMP.@constraint( | ||||||
container.JuMPmodel, | ||||||
sum( | ||||||
variable[name, t] for | ||||||
t in (1 + (i - 1) * affected_periods):(i * affected_periods) | ||||||
) <= sum( | ||||||
param[name, t] * multiplier[name, t] for | ||||||
t in (1 + (i - 1) * affected_periods):(i * affected_periods) | ||||||
) | ||||||
) | ||||||
end | ||||||
end | ||||||
return | ||||||
end | ||||||
=# | ||||||
|
||||||
# TODO: It also needs the add parameters code |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶