Skip to content

Commit

Permalink
refactor therm_no_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Oct 26, 2023
1 parent 82248c3 commit d383b91
Showing 1 changed file with 22 additions and 61 deletions.
83 changes: 22 additions & 61 deletions src/model/resources/thermal/thermal_no_commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,72 +140,33 @@ function thermal_no_commit_reserves!(EP::Model, inputs::Dict)

dfGen = inputs["dfGen"]

T = inputs["T"] # Number of time steps (hours)

THERM_NO_COMMIT = setdiff(inputs["THERM_ALL"], inputs["COMMIT"])

# Constraints on contribution to regulation and reserves
# Thermal units without commitment constraints assumed to be quick-start units, so can contribute a specified fraction of their
# total installed capacity to reserves

THERM_NO_COMMIT_REG_RSV = intersect(THERM_NO_COMMIT, inputs["REG"], inputs["RSV"]) # Set of thermal resources with both regulation and spinning reserves
T = 1:inputs["T"] # Number of time steps (hours)

THERM_NO_COMMIT_REG = intersect(THERM_NO_COMMIT, inputs["REG"]) # Set of thermal resources with regulation reserves
THERM_NO_COMMIT_RSV = intersect(THERM_NO_COMMIT, inputs["RSV"]) # Set of thermal resources with spinning reserves
THERM_NO_COMMIT = setdiff(inputs["THERM_ALL"], inputs["COMMIT"])

THERM_NO_COMMIT_NO_RES = setdiff(THERM_NO_COMMIT, THERM_NO_COMMIT_REG, THERM_NO_COMMIT_RSV) # Set of thermal resources with no reserves
REG = intersect(THERM_NO_COMMIT, inputs["REG"]) # Set of thermal resources with regulation reserves
RSV = intersect(THERM_NO_COMMIT, inputs["RSV"]) # Set of thermal resources with spinning reserves

THERM_NO_COMMIT_REG_ONLY = setdiff(THERM_NO_COMMIT_REG, THERM_NO_COMMIT_RSV) # Set of thermal resources only with regulation reserves
THERM_NO_COMMIT_RSV_ONLY = setdiff(THERM_NO_COMMIT_RSV, THERM_NO_COMMIT_REG) # Set of thermal resources only with spinning reserves
vP = EP[:vP]
vREG = EP[:vREG]
vRSV = EP[:vRSV]
eTotalCap = EP[:eTotalCap]

if !isempty(THERM_NO_COMMIT_REG_RSV)
@constraints(EP, begin

[y in THERM_NO_COMMIT_REG_RSV, t=1:T], EP[:vREG][y,t] <= inputs["pP_Max"][y,t]*dfGen[y,:Reg_Max]*EP[:eTotalCap][y]
[y in THERM_NO_COMMIT_REG_RSV, t=1:T], EP[:vRSV][y,t] <= inputs["pP_Max"][y,t]*dfGen[y,:Rsv_Max]*EP[:eTotalCap][y]
min_power(y) = dfGen[y, :Min_Power]
max_power(y,t) = inputs["pP_Max"][y,t]

# Minimum stable power generated per technology "y" at hour "t" and contribution to regulation down must be > min power
[y in THERM_NO_COMMIT_REG_RSV, t=1:T], EP[:vP][y,t]-EP[:vREG][y,t] >= dfGen[y,:Min_Power]*EP[:eTotalCap][y]
# 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])

# Maximum power generated per technology "y" at hour "t" and contribution to regulation and reserves must be < max power
[y in THERM_NO_COMMIT_REG_RSV, t=1:T], EP[:vP][y,t]+EP[:vREG][y,t]+EP[:vRSV][y,t] <= inputs["pP_Max"][y,t]*EP[:eTotalCap][y]
end)
end

if !isempty(THERM_NO_COMMIT_REG)
@constraints(EP, begin

[y in THERM_NO_COMMIT_REG, t=1:T], EP[:vREG][y,t] <= inputs["pP_Max"][y,t]*dfGen[y,:Reg_Max]*EP[:eTotalCap][y]

# Minimum stable power generated per technology "y" at hour "t" and contribution to regulation down must be > min power
[y in THERM_NO_COMMIT_REG, t=1:T], EP[:vP][y,t]-EP[:vREG][y,t] >= dfGen[y,:Min_Power]*EP[:eTotalCap][y]

# Maximum power generated per technology "y" at hour "t" and contribution to regulation and reserves must be < max power
[y in THERM_NO_COMMIT_REG, t=1:T], EP[:vP][y,t]+EP[:vREG][y,t] <= inputs["pP_Max"][y,t]*EP[:eTotalCap][y]
end)
end

if !isempty(THERM_NO_COMMIT_RSV)
@constraints(EP, begin

[y in THERM_NO_COMMIT_RSV, t=1:T], EP[:vRSV][y,t] <= inputs["pP_Max"][y,t]*dfGen[y,:Rsv_Max]*EP[:eTotalCap][y]

# Minimum stable power generated per technology "y" at hour "t" and contribution to regulation down must be > min power
[y in THERM_NO_COMMIT_RSV, t=1:T], EP[:vP][y,t] >= dfGen[y,:Min_Power]*EP[:eTotalCap][y]

# Maximum power generated per technology "y" at hour "t" and contribution to regulation and reserves must be < max power
[y in THERM_NO_COMMIT_RSV, t=1:T], EP[:vP][y,t]+EP[:vRSV][y,t] <= inputs["pP_Max"][y,t]*EP[:eTotalCap][y]
end)
end

if !isempty(THERM_NO_COMMIT_NO_RES)
@constraints(EP, begin
# Minimum stable power generated per technology "y" at hour "t" Min_Power
[y in THERM_NO_COMMIT_NO_RES, t=1:T], EP[:vP][y,t] >= dfGen[y,:Min_Power]*EP[:eTotalCap][y]

# Maximum power generated per technology "y" at hour "t"
[y in THERM_NO_COMMIT_NO_RES, t=1:T], EP[:vP][y,t] <= inputs["pP_Max"][y,t]*EP[:eTotalCap][y]
end)
end
# 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 *"
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])

# 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 *"
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])
end

0 comments on commit d383b91

Please sign in to comment.