Skip to content

Commit

Permalink
Fix the bug in writing power balance
Browse files Browse the repository at this point in the history
  • Loading branch information
qluo0320github committed Apr 10, 2024
1 parent a047697 commit 0875961
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed outputting capital recovery cost to 0 if the remaining number of years is 0 (#666)
- Updated the docstring for the initialize_cost_to_go function and adjusted the formula for the discount factor to reflect the code implementation (#672).
- Fix write_multi_stage_cost.jl: add discount with OPEX multipliers to cUnmetPolicyPenalty (#679)
- Fix write_power_balance.jl: add additional two columns ("VRE_Storage_Discharge" and "VRE_Storage_Charge") for VRE_STOR

### Changed
- Use add_to_expression! instead of the += and -= operators for memory performance improvements (#498).
Expand Down
31 changes: 22 additions & 9 deletions src/write_outputs/write_power_balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP
if !isempty(ELECTROLYZER)
push!(Com_list, "Electrolyzer_Consumption")
end
if !isempty(VRE_STOR)
push!(Com_list, "VRE_Storage_Discharge")
push!(Com_list, "VRE_Storage_Charge")
end
L = length(Com_list)
dfPowerBalance = DataFrame(BalanceComponent = repeat(Com_list, outer = Z),
Zone = repeat(1:Z, inner = L),
Expand All @@ -37,15 +41,6 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP
:]).data),
dims = 1)
end
if !isempty(intersect(resources_in_zone_by_rid(gen, z), VRE_STOR))
VS_ALL_ZONE = intersect(resources_in_zone_by_rid(gen, z), inputs["VS_STOR"])
powerbalance[(z - 1) * L + 2, :] = sum(value.(EP[:vP][VS_ALL_ZONE, :]),
dims = 1)
powerbalance[(z - 1) * L + 3, :] = (-1) *
sum(value.(EP[:vCHARGE_VRE_STOR][VS_ALL_ZONE,
:]).data,
dims = 1)
end
if !isempty(intersect(resources_in_zone_by_rid(gen, z), FLEX))
FLEX_ZONE = intersect(resources_in_zone_by_rid(gen, z), FLEX)
powerbalance[(z - 1) * L + 4, :] = sum((value.(EP[:vCHARGE_FLEX][FLEX_ZONE,
Expand All @@ -71,6 +66,24 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP
:].data),
dims = 1)
end
if !isempty(intersect(resources_in_zone_by_rid(gen, z), VRE_STOR)) & !isempty(ELECTROLYZER)
VS_ALL_ZONE = intersect(resources_in_zone_by_rid(gen, z), inputs["VS_STOR"])
powerbalance[(z - 1) * L + 12, :] = sum(value.(EP[:vP][VS_ALL_ZONE, :]),
dims = 1)
powerbalance[(z - 1) * L + 13, :] = (-1) *
sum(value.(EP[:vCHARGE_VRE_STOR][VS_ALL_ZONE,
:]).data,
dims = 1)
end
if !isempty(intersect(resources_in_zone_by_rid(gen, z), VRE_STOR)) & isempty(ELECTROLYZER)
VS_ALL_ZONE = intersect(resources_in_zone_by_rid(gen, z), inputs["VS_STOR"])
powerbalance[(z - 1) * L + 11, :] = sum(value.(EP[:vP][VS_ALL_ZONE, :]),
dims = 1)
powerbalance[(z - 1) * L + 12, :] = (-1) *
sum(value.(EP[:vCHARGE_VRE_STOR][VS_ALL_ZONE,
:]).data,
dims = 1)
end
end
if setup["ParameterScale"] == 1
powerbalance *= ModelScalingFactor
Expand Down

0 comments on commit 0875961

Please sign in to comment.