Skip to content

Commit

Permalink
Output energy storage investment to the solution (#627)
Browse files Browse the repository at this point in the history
* Add assets_investment_energy solution to the output

* Update Norse case to consider the new options in the inputs
  • Loading branch information
datejada committed May 8, 2024
1 parent 9aa3270 commit 40e326c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ The following files are created:
- `assets-investment.csv`: The format of each row is `a,v,p*v`, where `a` is the asset name,
`v` is the corresponding asset investment value, and `p` is the corresponding
capacity value. Only investable assets are included.
- `assets-investments-energy.csv`: The format of each row is `a,v,p*v`, where `a` is the asset name,
`v` is the corresponding asset investment value on energy, and `p` is the corresponding
energy capacity value. Only investable assets with a `storage_method_energy` set to `true` are included.
- `flows-investment.csv`: Similar to `assets-investment.csv`, but for flows.
- `flows.csv`: The value of each flow, per `(from, to)` flow, `rp` representative period
and `timestep`. Since the flow is in power, the value at a timestep is equal to the value
Expand All @@ -369,6 +372,25 @@ function save_solution_to_file(output_folder, graph, dataframes, solution)
end
CSV.write(output_file, output_table)

output_file = joinpath(output_folder, "assets-investments-energy.csv")
output_table = DataFrame(;
asset = Symbol[],
InstalEnergyUnits = Float64[],
InstalEnergyCap_MWh = Float64[],
)
for a in MetaGraphsNext.labels(graph)
if !graph[a].investable || !graph[a].storage_method_energy
continue
end
energy_units_investmented = solution.assets_investment_energy[a]
energy_capacity = graph[a].capacity_storage_energy
push!(
output_table,
(a, energy_units_investmented, energy_capacity * energy_units_investmented),
)
end
CSV.write(output_file, output_table)

output_file = joinpath(output_folder, "flows-investments.csv")
output_table = DataFrame(;
from_asset = Symbol[],
Expand Down
28 changes: 23 additions & 5 deletions src/solve-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ function solve_model!(
energy_problem.objective_value = JuMP.objective_value(model)

graph = energy_problem.graph
# rps = energy_problem.representative_periods
for a in MetaGraphsNext.labels(graph)
if graph[a].investable
if graph[a].investment_integer
graph[a].investment = round(Int, energy_problem.solution.assets_investment[a])
asset = graph[a]
if asset.investable
if asset.investment_integer
asset.investment = round(Int, energy_problem.solution.assets_investment[a])
else
graph[a].investment = energy_problem.solution.assets_investment[a]
asset.investment = energy_problem.solution.assets_investment[a]
end
if asset.storage_method_energy
if asset.investment_integer_storage_energy
asset.investment_energy =
round(Int, energy_problem.solution.assets_investment_energy[a])
else
asset.investment_energy = energy_problem.solution.assets_investment_energy[a]
end
end
end
end
Expand Down Expand Up @@ -110,6 +118,12 @@ The `solution` object is a mutable struct with the following fields:
```
[solution.assets_investment[a] for a in labels(graph) if graph[a].investable]
```
- `assets_investment_energy[a]`: The investment on energy component for each asset, indexed on the investable asset `a` with a `storage_method_energy` set to `true`.
To create a traditional array in the order given by the investable assets, one can run
```
[solution.assets_investment_energy[a] for a in labels(graph) if graph[a].investable && graph[a].storage_method_energy
```
- `flows_investment[u, v]`: The investment for each flow, indexed on the investable flow `(u, v)`.
To create a traditional array in the order given by the investable flows, one can run
Expand Down Expand Up @@ -170,6 +184,10 @@ function solve_model(
Dict(
a => JuMP.value(model[:assets_investment][a]) for a in model[:assets_investment].axes[1]
),
Dict(
a => JuMP.value(model[:assets_investment_energy][a]) for
a in model[:assets_investment_energy].axes[1]
),
Dict(
uv => JuMP.value(model[:flows_investment][uv]) for
uv in model[:flows_investment].axes[1]
Expand Down
3 changes: 3 additions & 0 deletions src/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mutable struct GraphAssetData
rep_periods_partitions::Dict{Int,Vector{TimestepsBlock}}
# Solution
investment::Float64
investment_energy::Float64 # for storage assets with energy method
storage_level_intra_rp::Dict{Tuple{Int,TimestepsBlock},Float64}
storage_level_inter_rp::Dict{PeriodsBlock,Float64}

Expand Down Expand Up @@ -146,6 +147,7 @@ mutable struct GraphAssetData
timeframe_partitions,
rep_periods_partitions,
-1,
-1,
Dict{Tuple{Int,TimestepsBlock},Float64}(),
Dict{TimestepsBlock,Float64}(),
)
Expand Down Expand Up @@ -215,6 +217,7 @@ end

mutable struct Solution
assets_investment::Dict{Symbol,Float64}
assets_investment_energy::Dict{Symbol,Float64} # for storage assets with energy method
flows_investment::Dict{Tuple{Symbol,Symbol},Float64}
storage_level_intra_rp::Vector{Float64}
storage_level_inter_rp::Vector{Float64}
Expand Down
1 change: 1 addition & 0 deletions test/inputs/Norse/assets-data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Asgard_CCGT,conversion,true,true,true,650,,500,0,0,,false,0,0,0,0,false,0,,0,fal
G_imports,producer,true,false,false,0,0,0,75000,0,,false,0,0,0,0,false,0,,0,false
Midgard_Wind,producer,true,true,true,1300,80000,3,0,0,,false,0,0,0,0,false,0,,0,false
Midgard_Hydro,storage,true,false,false,1600,0,0,250,0,,true,10000,50000,25000,0,false,0,,0,false
Midgard_PHS,storage,true,true,true,800,,200,0,0,,false,0,0,,1,true,500,1000,100,false
Midgard_Nuclear_SMR,producer,true,true,false,6000,,150,1000,0,,false,0,0,0,0,false,0,,0,false
Midgard_E_imports,producer,true,false,false,0,0,0,500,0,,false,0,0,0,0,false,0,,0,false
Midgard_CCGT,conversion,true,true,true,650,,500,0,0,,false,0,0,0,0,false,0,,0,false
Expand Down
2 changes: 2 additions & 0 deletions test/inputs/Norse/flows-data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ electricity,Midgard_Nuclear_SMR,Midgard_E_demand,true,false,false,false,0.015,0,
electricity,Midgard_E_imports,Midgard_E_demand,true,false,false,false,0.02,0,0,0,0,0,1
electricity,Midgard_CCGT,Midgard_E_demand,true,false,false,false,0,0,0,0,0,0,0.5
electricity,Midgard_Hydro,Midgard_E_demand,true,false,false,false,0,0,0,0,0,0,1
electricity,Midgard_PHS,Midgard_E_demand,true,false,false,false,0.004,0,0,0,0,0,0.85
electricity,Midgard_E_demand,Midgard_PHS,true,false,false,false,0.002,0,0,0,0,0,0.85
electricity,Valhalla_GT,Valhalla_E_balance,true,false,false,false,0,0,0,0,0,0,0.42
electricity,Valhalla_Fuel_cell,Valhalla_E_balance,true,false,false,false,0,0,0,0,0,0,0.5
electricity,Valhalla_E_balance,Valhalla_E_exports,true,false,false,false,0,0,0,0,0,0,1
Expand Down

0 comments on commit 40e326c

Please sign in to comment.