Skip to content

Commit

Permalink
[Fix] eELOSSByZone expr: access before initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Oct 27, 2023
1 parent c7302ad commit b7ab7ee
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Previously there was a typo in this in the multistage code that led to a silent bug, which affects outputs,
for anyone running non-myopic multistage GenX with asymmetric storage.
- Fix computation of cumulative minimum capacity retirements in multistage GenX (#514)
- Fix access of eELOSSByZone expr before initialization (#541)

### Changed
- Use add_to_expression! instead of the += and -= operators for memory performance improvements (#498).
Expand Down
4 changes: 3 additions & 1 deletion src/model/generate_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ function generate_model(setup::Dict,inputs::Dict,OPTIMIZER::MOI.OptimizerWithAtt

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 @@ -128,7 +131,6 @@ function generate_model(setup::Dict,inputs::Dict,OPTIMIZER::MOI.OptimizerWithAtt

co2!(EP, inputs)


if setup["Reserves"] > 0
reserves!(EP, inputs, setup)
end
Expand Down
7 changes: 3 additions & 4 deletions src/model/resources/storage/storage_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ function storage_all!(EP::Model, inputs::Dict, setup::Dict)
end
end

#From CO2 Policy module
@expression(EP, eELOSSByZone[z=1:Z],
sum(EP[:eELOSS][y] for y in intersect(STOR_ALL, dfGen[dfGen[!,:Zone].==z,:R_ID]))
)
# From CO2 Policy module
expr = @expression(EP, [z=1:Z], sum(EP[:eELOSS][y] for y in intersect(STOR_ALL, dfGen[dfGen[!,:Zone].==z,:R_ID])))
add_similar_to_expression!(EP[:eELOSSByZone], expr)

# Capacity Reserve Margin policy
if CapacityReserveMargin > 0
Expand Down
6 changes: 1 addition & 5 deletions src/model/resources/vre_stor/vre_stor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1166,11 +1166,7 @@ function stor_vre_stor!(EP::Model, inputs::Dict, setup::Dict)
# From CO2 Policy module
@expression(EP, eELOSSByZone_VRE_STOR[z=1:Z],
sum(EP[:eELOSS_VRE_STOR][y] for y in intersect(dfVRE_STOR[(dfVRE_STOR[!,:Zone].==z),:R_ID],STOR)))
if !isempty(inputs["STOR_ALL"])
EP[:eELOSSByZone] += eELOSSByZone_VRE_STOR
else
@expression(EP, eELOSSByZone[z=1:Z], eELOSSByZone_VRE_STOR[z])
end
add_similar_to_expression!(EP[:eELOSSByZone], eELOSSByZone_VRE_STOR)

### CONSTRAINTS ###

Expand Down

0 comments on commit b7ab7ee

Please sign in to comment.