From b88ca26e9ac80ab5fb77f4f2519f7b1d3e45ba82 Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Fri, 13 Oct 2023 10:43:22 -0400 Subject: [PATCH] Refactor storage_asymmetric --- .../resources/storage/storage_asymmetric.jl | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/model/resources/storage/storage_asymmetric.jl b/src/model/resources/storage/storage_asymmetric.jl index 3f4a4e6c3a..4149afec55 100644 --- a/src/model/resources/storage/storage_asymmetric.jl +++ b/src/model/resources/storage/storage_asymmetric.jl @@ -42,35 +42,21 @@ Sets up variables and constraints specific to storage resources with asymmetric """ function storage_asymmetric_reserves!(EP::Model, inputs::Dict, setup::Dict) - dfGen = inputs["dfGen"] - T = inputs["T"] - CapacityReserveMargin = setup["CapacityReserveMargin"] + T = 1:inputs["T"] + CapacityReserveMargin = setup["CapacityReserveMargin"] > 0 STOR_ASYMMETRIC = inputs["STOR_ASYMMETRIC"] - STOR_ASYM_REG = intersect(STOR_ASYMMETRIC, inputs["REG"]) # Set of asymmetric storage resources with REG reserves - STOR_ASYM_NO_REG = setdiff(STOR_ASYMMETRIC, STOR_ASYM_REG) # Set of asymmetric storage resources without REG reserves - - if !isempty(STOR_ASYM_REG) - if CapacityReserveMargin > 0 - # Storage units charging can charge faster to provide reserves down and charge slower to provide reserves up - # Maximum charging rate plus contribution to regulation down must be less than charge power rating - @constraint(EP, [y in STOR_ASYM_REG, t in 1:T], EP[:vCHARGE][y,t]+EP[:vREG_charge][y,t]+EP[:vCAPRES_charge][y,t] <= EP[:eTotalCapCharge][y]) - else - # Storage units charging can charge faster to provide reserves down and charge slower to provide reserves up - # Maximum charging rate plus contribution to regulation down must be less than charge power rating - @constraint(EP, [y in STOR_ASYM_REG, t in 1:T], EP[:vCHARGE][y,t]+EP[:vREG_charge][y,t]<= EP[:eTotalCapCharge][y]) - end - else - if CapacityReserveMargin > 0 - # Storage units charging can charge faster to provide reserves down and charge slower to provide reserves up - # Maximum charging rate plus contribution to regulation down must be less than charge power rating - @constraint(EP, [y in STOR_ASYM_NO_REG, t in 1:T], EP[:vCHARGE][y,t]+EP[:vCAPRES_charge][y,t] <= EP[:eTotalCapCharge][y]) - else - # Storage units charging can charge faster to provide reserves down and charge slower to provide reserves up - # Maximum charging rate plus contribution to regulation down must be less than charge power rating - @constraint(EP, [y in STOR_ASYM_NO_REG, t in 1:T], EP[:vCHARGE][y,t]<= EP[:eTotalCapCharge][y]) - end - end + vCHARGE = EP[:vCHARGE] + vREG_charge = EP[:vREG_charge] + vCAPRES_charge = EP[:vCAPRES_charge] + eTotalCapCharge = EP[:eTotalCapCharge] + + expr = @expression(EP, [y in STOR_ASYMMETRIC, t in T], 1 * vCHARGE[y, t]) # NOTE load-bearing "1 *" + add_similar_to_expression!(expr[STOR_ASYM_REG, :], vREG_charge[STOR_ASYM_REG, :]) + if CapacityReserveMargin + add_similar_to_expression!(expr[STOR_ASYMMETRIC, :], vCAPRES_charge[STOR_ASYMMETRIC, :]) + end + @constraint(EP, [y in STOR_ASYMMETRIC, t in T], expr[y, t] <= eTotalCapCharge[y]) end