From 0dfc526e432b06bd6126c990c41157396e141267 Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Thu, 9 Nov 2023 15:28:33 -0500 Subject: [PATCH] Make T an integer again, not UnitRange --- src/model/resources/hydro/hydro_res.jl | 14 +++++------ src/model/resources/storage/storage_all.jl | 24 +++++++++---------- .../resources/storage/storage_asymmetric.jl | 6 ++--- .../resources/storage/storage_symmetric.jl | 4 ++-- src/model/resources/thermal/thermal_commit.jl | 14 +++++------ .../resources/thermal/thermal_no_commit.jl | 14 +++++------ 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/model/resources/hydro/hydro_res.jl b/src/model/resources/hydro/hydro_res.jl index bbd1b88645..b642a533e6 100644 --- a/src/model/resources/hydro/hydro_res.jl +++ b/src/model/resources/hydro/hydro_res.jl @@ -182,7 +182,7 @@ function hydro_res_reserves!(EP::Model, inputs::Dict) dfGen = inputs["dfGen"] - T = 1:inputs["T"] # Number of time steps (hours) + T = inputs["T"] # Number of time steps (hours) HYDRO_RES = inputs["HYDRO_RES"] REG = inputs["REG"] @@ -197,8 +197,8 @@ function hydro_res_reserves!(EP::Model, inputs::Dict) eTotalCap = EP[:eTotalCap] # NOTE the load-bearing 1 * to create AffExpr and not VariableRef - max_up_reserves_lhs = @expression(EP, [y in HYDRO_RES, t in T], 1 * vP[y, t]) - max_dn_reserves_lhs = @expression(EP, [y in HYDRO_RES, t in T], 1 * vP[y, t]) + max_up_reserves_lhs = @expression(EP, [y in HYDRO_RES, t in 1:T], 1 * vP[y, t]) + max_dn_reserves_lhs = @expression(EP, [y in HYDRO_RES, t in 1:T], 1 * vP[y, t]) S = HYDRO_RES_REG add_similar_to_expression!(max_up_reserves_lhs[S, :], vREG[S, :]) @@ -207,9 +207,9 @@ function hydro_res_reserves!(EP::Model, inputs::Dict) S = HYDRO_RES_RSV add_similar_to_expression!(max_up_reserves_lhs[S, :], vRSV[S, :]) - @constraint(EP, [y in HYDRO_RES, t in T], max_up_reserves_lhs[y, t] <= eTotalCap[y]) - @constraint(EP, [y in HYDRO_RES, t in T], max_dn_reserves_lhs[y, t] >= 0) + @constraint(EP, [y in HYDRO_RES, t in 1:T], max_up_reserves_lhs[y, t] <= eTotalCap[y]) + @constraint(EP, [y in HYDRO_RES, t in 1:T], max_dn_reserves_lhs[y, t] >= 0) - @constraint(EP, [y in HYDRO_RES_REG, t in T], vREG[y, t] <= dfGen[y,:Reg_Max]*eTotalCap[y]) - @constraint(EP, [y in HYDRO_RES_RSV, t in T], vRSV[y, t] <= dfGen[y,:Rsv_Max]*eTotalCap[y]) + @constraint(EP, [y in HYDRO_RES_REG, t in 1:T], vREG[y, t] <= dfGen[y,:Reg_Max]*eTotalCap[y]) + @constraint(EP, [y in HYDRO_RES_RSV, t in 1:T], vRSV[y, t] <= dfGen[y,:Rsv_Max]*eTotalCap[y]) end diff --git a/src/model/resources/storage/storage_all.jl b/src/model/resources/storage/storage_all.jl index e81f6fc8bc..914b4fdacd 100644 --- a/src/model/resources/storage/storage_all.jl +++ b/src/model/resources/storage/storage_all.jl @@ -154,7 +154,7 @@ end function storage_all_reserves!(EP::Model, inputs::Dict, setup::Dict) dfGen = inputs["dfGen"] - T = 1:inputs["T"] + T = inputs["T"] p = inputs["hours_per_subperiod"] CapacityReserveMargin = setup["CapacityReserveMargin"] @@ -180,30 +180,30 @@ function storage_all_reserves!(EP::Model, inputs::Dict, setup::Dict) eff_down(y) = dfGen[y, :Eff_Down] # Maximum storage contribution to reserves is a specified fraction of installed capacity - @constraint(EP, [y in STOR_REG, t in T], vREG[y, t] <= dfGen[y,:Reg_Max] * eTotalCap[y]) - @constraint(EP, [y in STOR_RSV, t in T], vRSV[y, t] <= dfGen[y,:Rsv_Max] * eTotalCap[y]) + @constraint(EP, [y in STOR_REG, t in 1:T], vREG[y, t] <= dfGen[y,:Reg_Max] * eTotalCap[y]) + @constraint(EP, [y in STOR_RSV, t in 1:T], vRSV[y, t] <= dfGen[y,:Rsv_Max] * eTotalCap[y]) # Actual contribution to regulation and reserves is sum of auxilary variables for portions contributed during charging and discharging - @constraint(EP, [y in STOR_REG, t in T], vREG[y, t] == vREG_charge[y, t] + vREG_discharge[y, t]) - @constraint(EP, [y in STOR_RSV, t in T], vRSV[y, t] == vRSV_charge[y, t] + vRSV_discharge[y, t]) + @constraint(EP, [y in STOR_REG, t in 1:T], vREG[y, t] == vREG_charge[y, t] + vREG_discharge[y, t]) + @constraint(EP, [y in STOR_RSV, t in 1:T], vRSV[y, t] == vRSV_charge[y, t] + vRSV_discharge[y, t]) # Maximum charging rate plus contribution to reserves up must be greater than zero # Note: when charging, reducing charge rate is contributing to upwards reserve & regulation as it drops net demand - expr = @expression(EP, [y in STOR_ALL, t in T], 1 * vCHARGE[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in STOR_ALL, t in 1:T], 1 * vCHARGE[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[STOR_REG, :], -vREG_charge[STOR_REG, :]) add_similar_to_expression!(expr[STOR_RSV, :], -vRSV_charge[STOR_RSV, :]) - @constraint(EP, [y in STOR_ALL, t in T], expr[y, t] >= 0) + @constraint(EP, [y in STOR_ALL, t in 1:T], expr[y, t] >= 0) # Maximum discharging rate and contribution to reserves down must be greater than zero # Note: when discharging, reducing discharge rate is contributing to downwards regulation as it drops net supply - @constraint(EP, [y in STOR_REG, t in T], vP[y, t] - vREG_discharge[y, t] >= 0) + @constraint(EP, [y in STOR_REG, t in 1:T], vP[y, t] - vREG_discharge[y, t] >= 0) # Maximum charging rate plus contribution to regulation down must be less than available storage capacity - @constraint(EP, [y in STOR_REG, t in T], eff_up(y)*(vCHARGE[y, t]+vREG_charge[y, t]) <= eTotalCapEnergy[y]-vS[y, hoursbefore(p,t,1)]) + @constraint(EP, [y in STOR_REG, t in 1:T], eff_up(y)*(vCHARGE[y, t]+vREG_charge[y, t]) <= eTotalCapEnergy[y]-vS[y, hoursbefore(p,t,1)]) # Note: maximum charge rate is also constrained by maximum charge power capacity, but as this differs by storage type, # this constraint is set in functions below for each storage type - expr = @expression(EP, [y in STOR_ALL, t in T], 1 * vP[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in STOR_ALL, t in 1:T], 1 * vP[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[STOR_REG, :], vREG_discharge[STOR_REG, :]) add_similar_to_expression!(expr[STOR_RSV, :], vRSV_discharge[STOR_RSV, :]) if CapacityReserveMargin > 0 @@ -211,7 +211,7 @@ function storage_all_reserves!(EP::Model, inputs::Dict, setup::Dict) add_similar_to_expression!(expr[STOR_ALL, :], vCAPRES_discharge[STOR_ALL, :]) end # Maximum discharging rate and contribution to reserves up must be less than power rating - @constraint(EP, [y in STOR_ALL, t in T], expr[y, t] <= eTotalCap[y]) + @constraint(EP, [y in STOR_ALL, t in 1:T], expr[y, t] <= eTotalCap[y]) # Maximum discharging rate and contribution to reserves up must be less than available stored energy in prior period - @constraint(EP, [y in STOR_ALL, t in T], expr[y, t] <= vS[y, hoursbefore(p,t,1)] * eff_down(y)) + @constraint(EP, [y in STOR_ALL, t in 1:T], expr[y, t] <= vS[y, hoursbefore(p,t,1)] * eff_down(y)) end diff --git a/src/model/resources/storage/storage_asymmetric.jl b/src/model/resources/storage/storage_asymmetric.jl index 1623abb358..3293a1bb40 100644 --- a/src/model/resources/storage/storage_asymmetric.jl +++ b/src/model/resources/storage/storage_asymmetric.jl @@ -42,7 +42,7 @@ Sets up variables and constraints specific to storage resources with asymmetric """ function storage_asymmetric_reserves!(EP::Model, inputs::Dict, setup::Dict) - T = 1:inputs["T"] + T = inputs["T"] CapacityReserveMargin = setup["CapacityReserveMargin"] > 0 STOR_ASYMMETRIC = inputs["STOR_ASYMMETRIC"] @@ -52,11 +52,11 @@ function storage_asymmetric_reserves!(EP::Model, inputs::Dict, setup::Dict) vREG_charge = EP[:vREG_charge] eTotalCapCharge = EP[:eTotalCapCharge] - expr = @expression(EP, [y in STOR_ASYMMETRIC, t in T], 1 * vCHARGE[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in STOR_ASYMMETRIC, t in 1:T], 1 * vCHARGE[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[STOR_ASYM_REG, :], vREG_charge[STOR_ASYM_REG, :]) if CapacityReserveMargin vCAPRES_charge = EP[:vCAPRES_charge] 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]) + @constraint(EP, [y in STOR_ASYMMETRIC, t in 1:T], expr[y, t] <= eTotalCapCharge[y]) end diff --git a/src/model/resources/storage/storage_symmetric.jl b/src/model/resources/storage/storage_symmetric.jl index 23bbdfac64..f7b241888d 100644 --- a/src/model/resources/storage/storage_symmetric.jl +++ b/src/model/resources/storage/storage_symmetric.jl @@ -65,7 +65,7 @@ function storage_symmetric_reserves!(EP::Model, inputs::Dict, setup::Dict) # Maximum charging rate plus contribution to regulation down must be less than symmetric power rating # Max simultaneous charge and discharge rates cannot be greater than symmetric charge/discharge capacity - expr = @expression(EP, [y in SYMMETRIC, t in T], vP[y, t] + vCHARGE[y, t]) + expr = @expression(EP, [y in SYMMETRIC, t in 1:T], vP[y, t] + vCHARGE[y, t]) add_similar_to_expression!(expr[REG, :], vREG_charge[REG, :]) add_similar_to_expression!(expr[REG, :], vREG_discharge[REG, :]) add_similar_to_expression!(expr[RSV, :], vRSV_discharge[RSV, :]) @@ -75,5 +75,5 @@ function storage_symmetric_reserves!(EP::Model, inputs::Dict, setup::Dict) add_similar_to_expression!(expr[SYMMETRIC, :], vCAPRES_charge[SYMMETRIC, :]) add_similar_to_expression!(expr[SYMMETRIC, :], vCAPRES_discharge[SYMMETRIC, :]) end - @constraint(EP, [y in SYMMETRIC, t in T], expr[y, t] <= eTotalCap[y]) + @constraint(EP, [y in SYMMETRIC, t in 1:T], expr[y, t] <= eTotalCap[y]) end diff --git a/src/model/resources/thermal/thermal_commit.jl b/src/model/resources/thermal/thermal_commit.jl index ae817ee4b8..5a0a7e144b 100644 --- a/src/model/resources/thermal/thermal_commit.jl +++ b/src/model/resources/thermal/thermal_commit.jl @@ -271,7 +271,7 @@ function thermal_commit_reserves!(EP::Model, inputs::Dict) dfGen = inputs["dfGen"] - T = 1:inputs["T"] # Number of time steps (hours) + T = inputs["T"] # Number of time steps (hours) THERM_COMMIT = inputs["THERM_COMMIT"] @@ -287,19 +287,19 @@ function thermal_commit_reserves!(EP::Model, inputs::Dict) max_power(y,t) = inputs["pP_Max"][y,t] # Maximum regulation and reserve contributions - @constraint(EP, [y in REG, t in T], vREG[y, t] <= max_power(y, t) * dfGen[y,:Reg_Max] * commit(y, t)) - @constraint(EP, [y in RSV, t in T], vRSV[y, t] <= max_power(y, t) * dfGen[y,:Rsv_Max] * commit(y, t)) + @constraint(EP, [y in REG, t in 1:T], vREG[y, t] <= max_power(y, t) * dfGen[y,:Reg_Max] * commit(y, t)) + @constraint(EP, [y in RSV, t in 1:T], vRSV[y, t] <= max_power(y, t) * dfGen[y,:Rsv_Max] * commit(y, t)) # Minimum stable power generated per technology "y" at hour "t" and contribution to regulation must be > min power - expr = @expression(EP, [y in THERM_COMMIT, t in T], 1 * vP[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in THERM_COMMIT, t in 1:T], 1 * vP[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[REG, :], -vREG[REG, :]) - @constraint(EP, [y in THERM_COMMIT, t in T], expr[y, t] >= min_power(y) * commit(y, t)) + @constraint(EP, [y in THERM_COMMIT, t in 1:T], expr[y, t] >= min_power(y) * commit(y, t)) # Maximum power generated per technology "y" at hour "t" and contribution to regulation and reserves up must be < max power - expr = @expression(EP, [y in THERM_COMMIT, t in T], 1 * vP[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in THERM_COMMIT, t in 1:T], 1 * vP[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[REG, :], vREG[REG, :]) add_similar_to_expression!(expr[RSV, :], vRSV[RSV, :]) - @constraint(EP, [y in THERM_COMMIT, t in T], expr[y, t] <= max_power(y, t) * commit(y, t)) + @constraint(EP, [y in THERM_COMMIT, t in 1:T], expr[y, t] <= max_power(y, t) * commit(y, t)) end @doc raw""" diff --git a/src/model/resources/thermal/thermal_no_commit.jl b/src/model/resources/thermal/thermal_no_commit.jl index 06f08e3d63..2bcf5b390d 100644 --- a/src/model/resources/thermal/thermal_no_commit.jl +++ b/src/model/resources/thermal/thermal_no_commit.jl @@ -140,7 +140,7 @@ function thermal_no_commit_reserves!(EP::Model, inputs::Dict) dfGen = inputs["dfGen"] - T = 1:inputs["T"] # Number of time steps (hours) + T = inputs["T"] # Number of time steps (hours) THERM_NO_COMMIT = setdiff(inputs["THERM_ALL"], inputs["COMMIT"]) @@ -156,17 +156,17 @@ function thermal_no_commit_reserves!(EP::Model, inputs::Dict) max_power(y,t) = inputs["pP_Max"][y,t] # Maximum regulation and reserve contributions - @constraint(EP, [y in REG, t in T], vREG[y, t] <= max_power(y, t) * dfGen[y,:Reg_Max] * eTotalCap[y]) - @constraint(EP, [y in RSV, t in T], vRSV[y, t] <= max_power(y, t) * dfGen[y,:Rsv_Max] * eTotalCap[y]) + @constraint(EP, [y in REG, t in 1:T], vREG[y, t] <= max_power(y, t) * dfGen[y,:Reg_Max] * eTotalCap[y]) + @constraint(EP, [y in RSV, t in 1:T], vRSV[y, t] <= max_power(y, t) * dfGen[y,:Rsv_Max] * eTotalCap[y]) # Minimum stable power generated per technology "y" at hour "t" and contribution to regulation must be > min power - expr = @expression(EP, [y in THERM_NO_COMMIT, t in T], 1 * vP[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in THERM_NO_COMMIT, t in 1:T], 1 * vP[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[REG, :], -vREG[REG, :]) - @constraint(EP, [y in THERM_NO_COMMIT, t in T], expr[y, t] >= min_power(y) * eTotalCap[y]) + @constraint(EP, [y in THERM_NO_COMMIT, t in 1:T], expr[y, t] >= min_power(y) * eTotalCap[y]) # Maximum power generated per technology "y" at hour "t" and contribution to regulation and reserves up must be < max power - expr = @expression(EP, [y in THERM_NO_COMMIT, t in T], 1 * vP[y, t]) # NOTE load-bearing "1 *" + expr = @expression(EP, [y in THERM_NO_COMMIT, t in 1:T], 1 * vP[y, t]) # NOTE load-bearing "1 *" add_similar_to_expression!(expr[REG, :], vREG[REG, :]) add_similar_to_expression!(expr[RSV, :], vRSV[RSV, :]) - @constraint(EP, [y in THERM_NO_COMMIT, t in T], expr[y, t] <= max_power(y, t) * eTotalCap[y]) + @constraint(EP, [y in THERM_NO_COMMIT, t in 1:T], expr[y, t] <= max_power(y, t) * eTotalCap[y]) end