Skip to content

Commit

Permalink
Apply DRY to vre_stor pb calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Apr 11, 2024
1 parent 0875961 commit 27f484c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/write_outputs/write_power_balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,17 @@ 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)
# VRE storage discharge and charge
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 + 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)

# if ELECTROLYZER is empty, increase indices by 1
is_electrolyzer_empty = isempty(ELECTROLYZER)
discharge_idx = is_electrolyzer_empty ? 11 : 12
charge_idx = is_electrolyzer_empty ? 12 : 13

powerbalance[(z - 1) * L + discharge_idx, :] = sum(value.(EP[:vP][VS_ALL_ZONE, :]), dims = 1)
powerbalance[(z - 1) * L + charge_idx, :] = (-1) * sum(value.(EP[:vCHARGE_VRE_STOR][VS_ALL_ZONE, :]).data, dims = 1)
end
end
if setup["ParameterScale"] == 1
Expand Down

0 comments on commit 27f484c

Please sign in to comment.