Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate reserves into creation and constraints #580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions src/model/core/reserves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@

REG = inputs["REG"]
RSV = inputs["RSV"]
STOR_ALL = inputs["STOR_ALL"]

pDemand = inputs["pD"]
pP_Max(y, t) = inputs["pP_Max"][y, t]

systemwide_hourly_demand = sum(pDemand, dims=2)
must_run_vre_generation(t) = sum(pP_Max(y, t) * EP[:eTotalCap][y] for y in intersect(inputs["VRE"], inputs["MUST_RUN"]); init=0)

### Variables ###

Expand All @@ -228,27 +235,27 @@

# Storage techs have two pairs of auxilary variables to reflect contributions to regulation and reserves
# when charging and discharging (primary variable becomes equal to sum of these auxilary variables)
@variable(EP, vREG_discharge[y in intersect(inputs["STOR_ALL"], REG), t=1:T] >= 0) # Contribution to regulation (primary reserves) (mirrored variable used for storage devices)
@variable(EP, vRSV_discharge[y in intersect(inputs["STOR_ALL"], RSV), t=1:T] >= 0) # Contribution to operating reserves (secondary reserves) (mirrored variable used for storage devices)
@variable(EP, vREG_charge[y in intersect(inputs["STOR_ALL"], REG), t=1:T] >= 0) # Contribution to regulation (primary reserves) (mirrored variable used for storage devices)
@variable(EP, vRSV_charge[y in intersect(inputs["STOR_ALL"], RSV), t=1:T] >= 0) # Contribution to operating reserves (secondary reserves) (mirrored variable used for storage devices)
@variable(EP, vREG_discharge[y in intersect(STOR_ALL, REG), t=1:T] >= 0) # Contribution to regulation (primary reserves) (mirrored variable used for storage devices)
@variable(EP, vRSV_discharge[y in intersect(STOR_ALL, RSV), t=1:T] >= 0) # Contribution to operating reserves (secondary reserves) (mirrored variable used for storage devices)
@variable(EP, vREG_charge[y in intersect(STOR_ALL, REG), t=1:T] >= 0) # Contribution to regulation (primary reserves) (mirrored variable used for storage devices)
@variable(EP, vRSV_charge[y in intersect(STOR_ALL, RSV), t=1:T] >= 0) # Contribution to operating reserves (secondary reserves) (mirrored variable used for storage devices)

@variable(EP, vUNMET_RSV[t=1:T] >= 0) # Unmet operating reserves penalty/cost

### Expressions ###
## Total system reserve expressions
# Regulation requirements as a percentage of demand and scheduled variable renewable energy production in each hour
# Reg up and down requirements are symmetric
@expression(EP, eRegReq[t=1:T], inputs["pReg_Req_Demand"]*sum(inputs["pD"][t,z] for z=1:Z) +
inputs["pReg_Req_VRE"]*sum(inputs["pP_Max"][y,t]*EP[:eTotalCap][y] for y in intersect(inputs["VRE"], inputs["MUST_RUN"])))
@expression(EP, eRegReq[t=1:T], inputs["pReg_Req_Demand"] * systemwide_hourly_demand[t] +
inputs["pReg_Req_VRE"] * must_run_vre_generation(t))
# Operating reserve up / contingency reserve requirements as ˚a percentage of demand and scheduled variable renewable energy production in each hour
# and the largest single contingency (generator or transmission line outage)
@expression(EP, eRsvReq[t=1:T], inputs["pRsv_Req_Demand"]*sum(inputs["pD"][t,z] for z=1:Z) +
inputs["pRsv_Req_VRE"]*sum(inputs["pP_Max"][y,t]*EP[:eTotalCap][y] for y in intersect(inputs["VRE"], inputs["MUST_RUN"])))
@expression(EP, eRsvReq[t=1:T], inputs["pRsv_Req_Demand"] * systemwide_hourly_demand[t] +
inputs["pRsv_Req_VRE"] * must_run_vre_generation(t))

# N-1 contingency requirement is considered only if Unit Commitment is being modeled
if UCommit >= 1 && (inputs["pDynamic_Contingency"] >= 1 || inputs["pStatic_Contingency"] > 0)
EP[:eRsvReq] = EP[:eRsvReq] + EP[:eContingencyReq]
add_to_expression!(EP[:eRsvReq], EP[:eContingencyReq])

Check warning on line 258 in src/model/core/reserves.jl

View check run for this annotation

Codecov / codecov/patch

src/model/core/reserves.jl#L258

Added line #L258 was not covered by tests
end

## Objective Function Expressions ##
Expand All @@ -259,17 +266,29 @@
sum(dfGen[y,:Reg_Cost]*vRSV[y,t] for y in RSV, t=1:T) +
sum(dfGen[y,:Rsv_Cost]*vREG[y,t] for y in REG, t=1:T) )
add_to_expression!(EP[:eObj], eTotalCRsvPen)
end

### Constraints ###

## Total system reserve constraints
# Regulation requirements as a percentage of demand and scheduled variable renewable energy production in each hour
# Note: frequencty regulation up and down requirements are symmetric and all resources contributing to regulation are assumed to contribute equal capacity to both up and down directions
if !isempty(REG)
@constraint(EP, cReg[t=1:T], sum(vREG[y,t] for y in REG) >= EP[:eRegReq][t])
end
if !isempty(RSV)
@constraint(EP, cRsvReq[t=1:T], sum(vRSV[y,t] for y in RSV) + vUNMET_RSV[t] >= EP[:eRsvReq][t])
end

function reserves_constraints!(EP, inputs)
T = inputs["T"] # Number of time steps (hours)

REG = inputs["REG"]
RSV = inputs["RSV"]
vREG = EP[:vREG]
vRSV = EP[:vRSV]
vUNMET_RSV = EP[:vUNMET_RSV]
eRegulationRequirement = EP[:eRegReq]
eReserveRequirement = EP[:eRsvReq]

## Total system reserve constraints
# Regulation requirements as a percentage of demand and scheduled
# variable renewable energy production in each hour.
# Note: frequency regulation up and down requirements are symmetric and all resources
# contributing to regulation are assumed to contribute equal capacity to both up
# and down directions
if !isempty(REG)
@constraint(EP, cReg[t=1:T], sum(vREG[y,t] for y in REG) >= eRegulationRequirement[t])
end
if !isempty(RSV)
@constraint(EP, cRsvReq[t=1:T], sum(vRSV[y,t] for y in RSV) + vUNMET_RSV[t] >= eReserveRequirement[t])
end
end
10 changes: 7 additions & 3 deletions src/model/generate_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ function generate_model(setup::Dict,inputs::Dict,OPTIMIZER::MOI.OptimizerWithAtt
EP[:eObj] = AffExpr(0.0)

create_empty_expression!(EP, :eGenerationByZone, (Z, T))

# Energy losses related to technologies
create_empty_expression!(EP, :eELOSSByZone, Z)

# Initialize Capacity Reserve Margin Expression
if setup["CapacityReserveMargin"] > 0
create_empty_expression!(EP, :eCapResMarBalance, (inputs["NCapacityReserveMargin"], T))
Expand Down Expand Up @@ -191,6 +191,10 @@ function generate_model(setup::Dict,inputs::Dict,OPTIMIZER::MOI.OptimizerWithAtt

# Policies

if setup["Reserves"] > 0
reserves_constraints!(EP, inputs)
end

# CO2 emissions limits
if setup["CO2Cap"] > 0
co2_cap!(EP, inputs, setup)
Expand Down Expand Up @@ -236,4 +240,4 @@ function generate_model(setup::Dict,inputs::Dict,OPTIMIZER::MOI.OptimizerWithAtt
end

return EP
end
end