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

Create write_operating_reserve_price_revenue.jl #611

Merged
merged 33 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b01c606
Create write_operating_reserve_price_revenue.jl
sambuddhac Jan 11, 2024
012959f
Update write_operating_reserve_price_revenue.jl
sambuddhac Jan 11, 2024
87fe00c
Update write_operating_reserve_price_revenue.jl
sambuddhac Jan 24, 2024
962f18f
Moved wrtiting of operating reserve revenue from capacity reserve mar…
sambuddhac Jan 24, 2024
e89b0bf
Modified write__operating_reserve_price_revenue
sambuddhac Jan 29, 2024
6c9dfdd
Updated operating reserve and regulation revenue categorized accordin…
sambuddhac Feb 5, 2024
6ec3a46
Updated operating reserve and regulation revenue doc pages
sambuddhac Feb 5, 2024
435bbe0
Updated CHANGELOG.md
sambuddhac Feb 5, 2024
df459bc
Modified the write_net_revenue.jl to take into account the addition o…
sambuddhac Feb 5, 2024
7c12325
Update write_net_revenue.jl
sambuddhac Feb 5, 2024
848b192
Code refactoring for only selecting RSV and REG rows
sambuddhac Feb 5, 2024
1ffe28a
Code refactoring for only selecting RSV and REG rows
sambuddhac Feb 5, 2024
ee76261
Create write_operating_reserve_price_revenue.jl
sambuddhac Jan 11, 2024
f522df7
Update write_operating_reserve_price_revenue.jl
sambuddhac Jan 11, 2024
bae5fee
Update write_operating_reserve_price_revenue.jl
sambuddhac Jan 24, 2024
3ac2cce
Moved wrtiting of operating reserve revenue from capacity reserve mar…
sambuddhac Jan 24, 2024
63e4ed8
Modified write__operating_reserve_price_revenue
sambuddhac Jan 29, 2024
36c439b
Updated operating reserve and regulation revenue categorized accordin…
sambuddhac Feb 5, 2024
c0644e5
Updated operating reserve and regulation revenue doc pages
sambuddhac Feb 5, 2024
c5d0371
Updated CHANGELOG.md
sambuddhac Feb 5, 2024
34adab3
Modified the write_net_revenue.jl to take into account the addition o…
sambuddhac Feb 5, 2024
d777c1b
Code refactoring for only selecting RSV and REG rows
sambuddhac Feb 5, 2024
2fbd18f
Clean and fix notation
lbonaldo Feb 5, 2024
5c3cca5
Clean write_energy_revenue
lbonaldo Feb 5, 2024
a334250
Update write_operating_reserve_price_revenue.jl
sambuddhac Feb 6, 2024
475aa47
Update write_net_revenue.jl
sambuddhac Feb 6, 2024
3b35243
Update write_outputs.jl
sambuddhac Feb 6, 2024
1f4a7f6
Update write_operating_reserve_price_revenue.jl
sambuddhac Feb 6, 2024
d763f73
Minor typo fix and successful run
sambuddhac Feb 6, 2024
99af8ba
Updated CHANGELOG.md
sambuddhac Feb 6, 2024
3cee2c0
Updated CHANGELOG.md to eliminate unnecessary entries in Fix, since t…
sambuddhac Feb 6, 2024
6503a17
Cleanup
lbonaldo Feb 8, 2024
4469420
Merge branch 'develop' into sambuddhac-patch-3
lbonaldo Feb 11, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Maintenance formulation for thermal-commit plants (#556).
- Add new tests for GenX: three-zone, multi-stage, electrolyzer, VRE+storage,
piecewise_fuel+CO2, and TDR (#563 and #578).
- Added write_operating_reserve_price_revenue.jl to compute annual operating reserve and regulation revenue (PR # 611)
- Added the operating reserve and regulation revenue to net revenue


### Fixed
Expand All @@ -40,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Correctly scale total reserves column (in reg_dn.csv) (#594)
- Add validation for `Reg_Max` and `Rsv_Max` columns in `Generators_data.csv` when `MUST_RUN` is set to 1 (#576)
- Fix scaling of transmission losses in write_transmission_losses.jl (#621)
- Fixes issue #46 (#611)

### Changed
- Use add_to_expression! instead of the += and -= operators for memory performance improvements (#498).
Expand Down
5 changes: 5 additions & 0 deletions docs/src/write_outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Pages = ["write_energy_revenue.jl"]
Modules = [GenX]
Pages = ["write_subsidy_revenue.jl"]
```
## Write Operating Reserve and Regulation Revenue
```@autodocs
Modules = [GenX]
Pages = ["write_operating_reserve_price_revenue.jl"]
```

## Write Capacity Revenue
```@autodocs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@doc raw"""
write_operating_reserve_price_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)

Function for reporting the operating reserve prices and revenue earned by generators listed in the input file.
GenX will print this file only when operating reserve is modeled and the shadow price can be obtained form the solver.
The revenue is calculated as the operating reserve contribution of each time steps multiplied by the shadow price, and then the sum is taken over all modeled time steps.
The last column is the total revenue received from all operating reserve constraints.
As a reminder, GenX models the operating reserve at the time-dependent level, and each constraint either stands for an overall market or a locality constraint.
"""
function write_operating_reserve_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
dfGen = inputs["dfGen"]
RSV = inputs["RSV"]
REG = inputs["REG"]

dfOpRsvRevenue = DataFrame(Region = dfGen[RSV, :region], Resource = dfGen[RSV, :Resource], Zone = dfGen[RSV, :Zone], Cluster = dfGen[RSV, :cluster], AnnualSum = Array{Float64}(undef, length(RSV)),)
dfOpRegRevenue = DataFrame(Region = dfGen[REG, :region], Resource = dfGen[REG, :Resource], Zone = dfGen[REG, :Zone], Cluster = dfGen[REG, :cluster], AnnualSum = Array{Float64}(undef, length(REG)),)

weighted_reg_price = operating_regulation_price(EP, inputs, setup)
weighted_rsv_price = operating_reserve_price(EP, inputs, setup)

rsvrevenue = value.(EP[:vRSV][RSV, :].data).* transpose(weighted_rsv_price)
regrevenue = value.(EP[:vREG][REG, :].data) .* transpose(weighted_reg_price)

if setup["ParameterScale"] == 1
rsvrevenue *= scale_factor
regrevenue *= scale_factor
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be wrapped with the if statement since scale_factor is always defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cfe316 . Addressed this.


dfOpRsvRevenue.AnnualSum .= rsvrevenue * inputs["omega"]
dfOpRegRevenue.AnnualSum .= regrevenue * inputs["omega"]
write_simple_csv(joinpath(path, "OperatingReserveRevenue.csv"), dfOpRsvRevenue)
write_simple_csv(joinpath(path, "OperatingRegulationRevenue.csv"), dfOpRegRevenue)
return dfOpRegRevenue, dfOpRsvRevenue
end

@doc raw"""
operating_regulation_price(EP::Model,
inputs::Dict,
setup::Dict)::Vector{Float64}

Operating regulation price for each time step.
This is equal to the dual variable of the regulatin requirement constraint.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: regulatin > regulation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "can be obtained form the solver." -> "can be obtained from the solver."

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "of each time steps" --> "in each time step"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cfe316 . Addressed these.


Returns a vector, with units of $/MW
"""

function operating_regulation_price(EP::Model, inputs::Dict, setup::Dict)::Vector{Float64}
ω = inputs["omega"]
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
return dual.(EP[:cReg]) ./ ω * scale_factor
end

@doc raw"""
operating_reserve_price(EP::Model,
inputs::Dict,
setup::Dict)::Vector{Float64}

Operating reserve price for each time step.
This is equal to the dual variable of the reserve requirement constraint.

Returns a vector, with units of $/MW
"""

function operating_reserve_price(EP::Model, inputs::Dict, setup::Dict)::Vector{Float64}
ω = inputs["omega"]
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
return dual.(EP[:cRsvReq]) ./ ω * scale_factor
end
4 changes: 2 additions & 2 deletions src/write_outputs/write_energy_revenue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function write_energy_revenue(path::AbstractString, inputs::Dict, setup::Dict, E
NONFLEX = setdiff(collect(1:G), FLEX)
dfEnergyRevenue = DataFrame(Region = dfGen.region, Resource = inputs["RESOURCES"], Zone = dfGen.Zone, Cluster = dfGen.cluster, AnnualSum = Array{Float64}(undef, G),)
energyrevenue = zeros(G, T)
price = locational_marginal_price(EP, inputs, setup)
energyrevenue[NONFLEX, :] = value.(EP[:vP][NONFLEX, :]) .* transpose(price)[dfGen[NONFLEX, :Zone], :]
price = locational_marginal_price(EP, inputs, setup)
energyrevenue[NONFLEX, :] = value.(EP[:vP][NONFLEX, :]) .* transpose(price)[dfGen[NONFLEX, :Zone], :]
if !isempty(FLEX)
energyrevenue[FLEX, :] = value.(EP[:vCHARGE_FLEX][FLEX, :]).data .* transpose(price)[dfGen[FLEX, :Zone], :]
end
Expand Down
18 changes: 14 additions & 4 deletions src/write_outputs/write_net_revenue.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@doc raw"""
write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame)
write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame, dfOpRegRevenue::DataFrame, dfOpRsvRevenue::DataFrame)

Function for writing net revenue of different generation technologies.
"""
function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame)
function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame, dfOpRegRevenue::DataFrame, dfOpRsvRevenue::DataFrame)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a comment. We should really have an "outputs" dictionary so that we don't have this huge list of dataframes.

dfGen = inputs["dfGen"]
T = inputs["T"] # Number of time steps (hours)
Z = inputs["Z"] # Number of zones
G = inputs["G"] # Number of generators
G = inputs["G"]
RSV = inputs["RSV"]
REG = inputs["REG"] # Number of generators
COMMIT = inputs["COMMIT"] # Thermal units for unit commitment
STOR_ALL = inputs["STOR_ALL"]
VRE_STOR = inputs["VRE_STOR"]
Expand Down Expand Up @@ -129,6 +131,14 @@ function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::
dfNetRevenue.SubsidyRevenue = dfSubRevenue[1:G,:SubsidyRevenue] # Unit is confirmed to be US$
end

# Add energy and subsidy revenue to the dataframe
dfNetRevenue.OperatingReserveRevenue = zeros(nrow(dfNetRevenue))
dfNetRevenue.OperatingRegulationRevenue = zeros(nrow(dfNetRevenue))
if setup["Reserves"] > 0 && has_duals(EP) == 1
dfNetRevenue.OperatingReserveRevenue[RSV] = dfOpRsvRevenue.AnnualSum # Unit is confirmed to be US$
dfNetRevenue.OperatingRegulationRevenue[REG] = dfOpRegRevenue.AnnualSum # Unit is confirmed to be US$
end

# Add capacity revenue to the dataframe
dfNetRevenue.ReserveMarginRevenue = zeros(nrow(dfNetRevenue))
if setup["CapacityReserveMargin"] > 0 && has_duals(EP) == 1 # The unit is confirmed to be $
Expand Down Expand Up @@ -170,7 +180,7 @@ function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::
dfNetRevenue.RegSubsidyRevenue = dfRegSubRevenue[1:G,:SubsidyRevenue]
end

dfNetRevenue.Revenue = dfNetRevenue.EnergyRevenue .+ dfNetRevenue.SubsidyRevenue .+ dfNetRevenue.ReserveMarginRevenue .+ dfNetRevenue.ESRRevenue .+ dfNetRevenue.RegSubsidyRevenue
dfNetRevenue.Revenue = dfNetRevenue.EnergyRevenue .+ dfNetRevenue.SubsidyRevenue .+ dfNetRevenue.ReserveMarginRevenue .+ dfNetRevenue.ESRRevenue .+ dfNetRevenue.RegSubsidyRevenue .+ dfNetRevenue.OperatingReserveRevenue .+ dfNetRevenue.OperatingRegulationRevenue
dfNetRevenue.Cost = (dfNetRevenue.Inv_cost_MW
.+ dfNetRevenue.Inv_cost_MWh
.+ dfNetRevenue.Inv_cost_charge_MW
Expand Down
10 changes: 9 additions & 1 deletion src/write_outputs/write_outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic
dfResMar_slack = write_reserve_margin_slack(path, inputs, setup, EP)
end
end

if setup["Reserves"]==1 && has_duals(EP) == 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this code is duplicated from elsewhere in the file, but has_duals returns a boolean, so it's a bit redundant to use an == 1. You can just do if setup["Reserves"]==1 && has_duals(EP).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cfe316 . Addressed these in all the instances

dfOpRegRevenue, dfOpRsvRevenue = write_operating_reserve_revenue(path, inputs, setup, EP)
elapsed_time_op_res_rev = @elapsed write_operating_reserve_revenue(path, inputs, setup, EP)
println("Time elapsed for writing oerating reserve price is")
println(elapsed_time_op_res_rev)
end

if setup["CO2Cap"]>0 && has_duals(EP) == 1
dfCO2Cap = write_co2_cap(path, inputs, setup, EP)
end
Expand All @@ -198,7 +206,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic
end


elapsed_time_net_rev = @elapsed write_net_revenue(path, inputs, setup, EP, dfCap, dfESRRev, dfResRevenue, dfChargingcost, dfPower, dfEnergyRevenue, dfSubRevenue, dfRegSubRevenue, dfVreStor)
elapsed_time_net_rev = @elapsed write_net_revenue(path, inputs, setup, EP, dfCap, dfESRRev, dfResRevenue, dfChargingcost, dfPower, dfEnergyRevenue, dfSubRevenue, dfRegSubRevenue, dfVreStor, dfOpRegRevenue, dfOpRsvRevenue)
println("Time elapsed for writing net revenue is")
println(elapsed_time_net_rev)
end
Expand Down
Loading