Skip to content

Commit

Permalink
Make T an integer again, not UnitRange
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Nov 9, 2023
1 parent 6bbeb20 commit 0dfc526
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
14 changes: 7 additions & 7 deletions src/model/resources/hydro/hydro_res.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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, :])
Expand All @@ -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
24 changes: 12 additions & 12 deletions src/model/resources/storage/storage_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -180,38 +180,38 @@ 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
vCAPRES_discharge = EP[:vCAPRES_discharge]
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
6 changes: 3 additions & 3 deletions src/model/resources/storage/storage_asymmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/model/resources/storage/storage_symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, :])
Expand All @@ -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
14 changes: 7 additions & 7 deletions src/model/resources/thermal/thermal_commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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"""
Expand Down
14 changes: 7 additions & 7 deletions src/model/resources/thermal/thermal_no_commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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

0 comments on commit 0dfc526

Please sign in to comment.