From c5df45af2376c2fb626bc3e7b4cfd4a6ce0f58f0 Mon Sep 17 00:00:00 2001 From: sigmundholm Date: Sun, 3 Mar 2024 10:57:23 +0100 Subject: [PATCH] Move the constraint defining curtailment for NonDisRES to the constraints_capacity method. (#10) This will make it easier to rewrite this constraint for other packages, and also allows simplifying the code by removing the create_node method for NonDisRES entirely, since it is now identical to the create_node method defined for a general Source node in EMB. --- src/constraint_functions.jl | 24 ++++++++++++++++++++++++ src/model.jl | 35 ++--------------------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/constraint_functions.jl b/src/constraint_functions.jl index f85f500..5565ba5 100644 --- a/src/constraint_functions.jl +++ b/src/constraint_functions.jl @@ -1,4 +1,28 @@ #! format: off + +""" + constraints_capacity(m, n::NonDisRES, ๐’ฏ::TimeStructure, modeltype::EnergyModel) + +Function for creating the constraint on the maximum capacity of a `NonDisRES`. +Also sets the constraint defining curtailment. +""" +function EMB.constraints_capacity(m, n::NonDisRES, ๐’ฏ::TimeStructure, modeltype::EnergyModel) + @constraint(m, [t โˆˆ ๐’ฏ], + m[:cap_use][n, t] <= m[:cap_inst][n, t] + ) + + # Non dispatchable renewable energy sources operate at their max + # capacity with repsect to the current profile (e.g. wind) at every time. + @constraint( + m, + [t โˆˆ ๐’ฏ], + m[:cap_use][n, t] + m[:curtailment][n, t] == profile(n, t) * m[:cap_inst][n, t] + ) + + constraints_capacity_installed(m, n, ๐’ฏ, modeltype) +end + + """ EMB.constraints_level_aux(m, n::HydroStorage, ๐’ฏ, ๐’ซ, modeltype) diff --git a/src/model.jl b/src/model.jl index 37cb8ee..27a7383 100644 --- a/src/model.jl +++ b/src/model.jl @@ -8,39 +8,8 @@ function EMB.variables_node(m, ๐’ฉโฟแตˆสณ::Vector{NonDisRES}, ๐’ฏ, modeltype: @variable(m, curtailment[๐’ฉโฟแตˆสณ, ๐’ฏ] >= 0) end -""" - EMB.create_node(m, n::NonDisRES, ๐’ฏ, ๐’ซ, modeltype::EnergyModel) - -Sets all constraints for a non-dispatchable renewable energy source. -""" -function EMB.create_node(m, n::NonDisRES, ๐’ฏ, ๐’ซ, modeltype::EnergyModel) - - # Declaration of the required subsets. - ๐’ฏแดตโฟแต› = strategic_periods(๐’ฏ) - - # Non dispatchable renewable energy sources operate at their max - # capacity with repsect to the current profile (e.g. wind) at every time. - @constraint( - m, - [t โˆˆ ๐’ฏ], - m[:cap_use][n, t] + m[:curtailment][n, t] == profile(n, t) * m[:cap_inst][n, t] - ) - - # Call of the function for the outlet flow from the `Source` node - constraints_flow_out(m, n, ๐’ฏ, modeltype) - - # Call of the function for limiting the capacity to the maximum installed capacity - constraints_capacity(m, n, ๐’ฏ, modeltype) - - # Call of the functions for both fixed and variable OPEX constraints introduction - constraints_opex_fixed(m, n, ๐’ฏแดตโฟแต›, modeltype) - constraints_opex_var(m, n, ๐’ฏแดตโฟแต›, modeltype) - - # Iterate through all data and set up the constraints corresponding to the data - for data โˆˆ node_data(n) - constraints_data(m, n, ๐’ฏ, ๐’ซ, modeltype, data) - end -end +# NB: note that the create_node method that will run for a node n::NonDisRES, is the +# method defined for a general Source node, which is located in EnergyModelsBase. """ EMB.variables_node(m, ๐’ฉ::Vector{HydroStorage}, ๐’ฏ, modeltype::EnergyModel)