From b7ab7ee9448373aab484713f0f80062fa4d39d13 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 27 Oct 2023 17:50:21 -0400 Subject: [PATCH] [Fix] eELOSSByZone expr: access before initialization --- CHANGELOG.md | 1 + src/model/generate_model.jl | 4 +++- src/model/resources/storage/storage_all.jl | 7 +++---- src/model/resources/vre_stor/vre_stor.jl | 6 +----- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a36a453fe0..83710c9a69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/model/generate_model.jl b/src/model/generate_model.jl index 2577313df3..45c964c776 100644 --- a/src/model/generate_model.jl +++ b/src/model/generate_model.jl @@ -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)) @@ -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 diff --git a/src/model/resources/storage/storage_all.jl b/src/model/resources/storage/storage_all.jl index 4f5fd7424f..c9d69da1d1 100644 --- a/src/model/resources/storage/storage_all.jl +++ b/src/model/resources/storage/storage_all.jl @@ -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 diff --git a/src/model/resources/vre_stor/vre_stor.jl b/src/model/resources/vre_stor/vre_stor.jl index b3842571cf..6ddeca045b 100644 --- a/src/model/resources/vre_stor/vre_stor.jl +++ b/src/model/resources/vre_stor/vre_stor.jl @@ -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 ###