Skip to content

Commit

Permalink
Add necessary data to prepare multi-year transport (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawin authored Sep 24, 2024
1 parent a125be7 commit ddb20d9
Show file tree
Hide file tree
Showing 26 changed files with 1,524 additions and 985 deletions.
792 changes: 396 additions & 396 deletions benchmark/EU/flows-data.csv

Large diffs are not rendered by default.

792 changes: 396 additions & 396 deletions benchmark/EU/graph-flows-data.csv

Large diffs are not rendered by default.

396 changes: 396 additions & 0 deletions benchmark/EU/vintage-flows-data.csv

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/constraints/transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.from, row.to].initial_export_capacity[row.year] +
graph[row.from, row.to].capacity *
) *
graph[row.from, row.to].capacity *
(
graph[row.from, row.to].initial_export_units[row.year] +
flows_investment[row.year, (row.from, row.to)]
)
)
Expand All @@ -39,7 +40,9 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * graph[row.from, row.to].initial_export_capacity[row.year]
) *
graph[row.from, row.to].capacity *
graph[row.from, row.to].initial_export_units[row.year]
)
end for row in eachrow(df_flows)
]
Expand All @@ -57,9 +60,10 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.from, row.to].initial_import_capacity[row.year] +
graph[row.from, row.to].capacity *
) *
graph[row.from, row.to].capacity *
(
graph[row.from, row.to].initial_import_units[row.year] +
flows_investment[row.year, (row.from, row.to)]
)
)
Expand All @@ -74,7 +78,9 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * graph[row.from, row.to].initial_import_capacity[row.year]
) *
graph[row.from, row.to].capacity *
graph[row.from, row.to].initial_import_units[row.year]
)
end for row in eachrow(df_flows)
]
Expand Down
23 changes: 18 additions & 5 deletions src/input-schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const schemas = (
:from_asset => "VARCHAR", # Name of Asset
:to_asset => "VARCHAR", # Name of Asset
:carrier => "VARCHAR", # (Optional?) Energy carrier
:capacity => "DOUBLE", # MW
:capacity => "DOUBLE",
:technical_lifetime => "INTEGER",
:economic_lifetime => "INTEGER",
:discount_rate => "DOUBLE",
),
),
assets = (
Expand Down Expand Up @@ -56,13 +59,22 @@ const schemas = (
),

# Schema for the vintage-assets-data.csv
vintage_data = OrderedDict(
vintage_assets_data = OrderedDict(
:name => "VARCHAR",
:commission_year => "INTEGER", # Year of commissioning
:fixed_cost => "DOUBLE",
:investment_cost => "DOUBLE", # kEUR/MW/year
),

# Schema for the vintage-flows-data.csv
vintage_flows_data = OrderedDict(
:from_asset => "VARCHAR", # Name of Asset
:to_asset => "VARCHAR", # Name of Asset
:commission_year => "INTEGER", # Year of commissioning
:fixed_cost => "DOUBLE",
:investment_cost => "DOUBLE", # kEUR/MW/year
),

# Schema for the assets-profiles.csv and assets-timeframe-profiles.csv file.
profiles_reference = OrderedDict(
:asset => "VARCHAR", # Asset name
Expand Down Expand Up @@ -111,8 +123,8 @@ const schemas = (
:variable_cost => "DOUBLE", # kEUR/MWh
:investment_cost => "DOUBLE", # kEUR/MW/year
:investment_limit => "DOUBLE", # MW
:initial_export_capacity => "DOUBLE", # MW
:initial_import_capacity => "DOUBLE", # MW
:initial_export_units => "DOUBLE", # MW
:initial_import_units => "DOUBLE", # MW
:efficiency => "DOUBLE", # p.u. (per unit)
),

Expand Down Expand Up @@ -196,6 +208,7 @@ const schema_per_table_name = OrderedDict(
"profiles_rep_periods" => schemas.rep_periods.profiles_data,
"rep_periods_data" => schemas.rep_periods.data,
"rep_periods_mapping" => schemas.rep_periods.mapping,
"vintage_assets_data" => schemas.assets.vintage_data,
"vintage_assets_data" => schemas.assets.vintage_assets_data,
"vintage_flows_data" => schemas.assets.vintage_flows_data,
"year_data" => schemas.year.data,
)
27 changes: 18 additions & 9 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ function create_internal_structures(connection)
return result_dict
end

_query_vintage_year(col; where_pairs...) = begin
_q = "SELECT commission_year, $col FROM vintage_assets_data"
_query_vintage_year(table_name, col; where_pairs...) = begin
_q = "SELECT commission_year, $col FROM $table_name"
if length(where_pairs) > 0
_q *=
" WHERE " *
Expand All @@ -125,8 +125,8 @@ function create_internal_structures(connection)
DuckDB.query(connection, _q)
end

function _get_stuff_vintage_year(col; where_pairs...)
result = _query_vintage_year(col; where_pairs...)
function _get_stuff_vintage_year(table_name, col; where_pairs...)
result = _query_vintage_year(table_name, col; where_pairs...)
Dict(row.commission_year => getproperty(row, Symbol(col)) for row in result)
end

Expand All @@ -142,8 +142,8 @@ function create_internal_structures(connection)
row.technical_lifetime,
row.economic_lifetime,
row.discount_rate,
_get_stuff_vintage_year("investment_cost"; name = row.name),
_get_stuff_vintage_year("fixed_cost"; name = row.name),
_get_stuff_vintage_year("assets_data", "investment_cost"; name = row.name),
_get_stuff_vintage_year("assets_data", "fixed_cost"; name = row.name),
_get_stuff_year("assets_data", "investment_limit"; name = row.name),
row.capacity,
_get_stuff_commission_year("assets_data", "initial_units"; name = row.name),
Expand Down Expand Up @@ -208,18 +208,27 @@ function create_internal_structures(connection)
from_asset = row.from_asset,
to_asset = row.to_asset,
),
row.technical_lifetime,
row.economic_lifetime,
row.discount_rate,
_get_stuff_year(
"flows_data",
"variable_cost";
from_asset = row.from_asset,
to_asset = row.to_asset,
),
_get_stuff_year(
_get_stuff_vintage_year(
"flows_data",
"investment_cost";
from_asset = row.from_asset,
to_asset = row.to_asset,
),
_get_stuff_vintage_year(
"flows_data",
"fixed_cost";
from_asset = row.from_asset,
to_asset = row.to_asset,
),
_get_stuff_year(
"flows_data",
"investment_limit";
Expand All @@ -229,13 +238,13 @@ function create_internal_structures(connection)
row.capacity,
_get_stuff_year(
"flows_data",
"initial_export_capacity";
"initial_export_units";
from_asset = row.from_asset,
to_asset = row.to_asset,
),
_get_stuff_year(
"flows_data",
"initial_import_capacity";
"initial_import_units";
from_asset = row.from_asset,
to_asset = row.to_asset,
),
Expand Down
24 changes: 18 additions & 6 deletions src/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,16 @@ mutable struct GraphFlowData
is_transport::Dict{Int,Bool}
investable::Dict{Int,Bool}
investment_integer::Dict{Int,Bool}
technical_lifetime::Float64
economic_lifetime::Float64
discount_rate::Float64
variable_cost::Dict{Int,Float64}
investment_cost::Dict{Int,Float64}
fixed_cost::Dict{Int,Float64}
investment_limit::Dict{Int,Union{Missing,Float64}}
capacity::Float64
initial_export_capacity::Dict{Int,Float64}
initial_import_capacity::Dict{Int,Float64}
initial_export_units::Dict{Int,Float64}
initial_import_units::Dict{Int,Float64}
efficiency::Dict{Int,Float64}
timeframe_profiles::Dict{Int,Dict{String,Vector{Float64}}}
rep_periods_profiles::Dict{Int,Dict{Tuple{String,Int},Vector{Float64}}}
Expand All @@ -224,12 +228,16 @@ function GraphFlowData(
is_transport,
investable,
investment_integer,
technical_lifetime,
economic_lifetime,
discount_rate,
variable_cost,
investment_cost,
fixed_cost,
investment_limit,
capacity,
initial_export_capacity,
initial_import_capacity,
initial_export_units,
initial_import_units,
efficiency,
)
return GraphFlowData(
Expand All @@ -238,12 +246,16 @@ function GraphFlowData(
is_transport,
investable,
investment_integer,
technical_lifetime,
economic_lifetime,
discount_rate,
variable_cost,
investment_cost,
fixed_cost,
investment_limit,
capacity,
initial_export_capacity,
initial_import_capacity,
initial_export_units,
initial_import_units,
efficiency,
Dict{Int,Dict{String,Vector{Float64}}}(),
Dict{Int,Dict{Tuple{String,Int},Vector{Float64}}}(),
Expand Down
33 changes: 17 additions & 16 deletions test/inputs/Multi-year Investments/flows-data.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
asset_name,asset_name,{true;false},,{true;false},{true;false},{true;false},kEUR/MWh,kEUR/MW/year,MW,MW,MW,p.u.
from_asset,to_asset,active,year,is_transport,investable,investment_integer,variable_cost,investment_cost,investment_limit,initial_export_capacity,initial_import_capacity,efficiency
ocgt,demand,true,2030,false,false,false,0.07,0,,0,0,0
ccgt,demand,true,2030,false,false,false,0.05,0,,0,0,0
battery,demand,true,2030,false,false,false,0.0,0,,0,0,0.95
demand,battery,true,2030,false,false,false,0.0,0,,0,0,0.95
wind,demand,true,2030,false,false,false,0.001,0,,0,0,0
solar,demand,true,2030,false,false,false,0,0,,0,0,0
ens,demand,true,2030,false,false,false,0.18,0,,0,0,0
ocgt,demand,true,2050,false,false,false,0.07,0,,0,0,0
ccgt,demand,true,2050,false,false,false,0.05,0,,0,0,0
battery,demand,true,2050,false,false,false,0.0,0,,0,0,0.95
demand,battery,true,2050,false,false,false,0.0,0,,0,0,0.95
wind,demand,true,2050,false,false,false,0.001,0,,0,0,0
solar,demand,true,2050,false,false,false,0,0,,0,0,0
ens,demand,false,2050,false,false,false,0.18,0,,0,0,0
asset_name,asset_name,{true;false},,year,{true;false},{true;false},{true;false},kEUR/MWh,kEUR/MW/year,kEUR/MW/year,MW,MW,MW,p.u.
from_asset,to_asset,active,year,commission_year,is_transport,investable,investment_integer,variable_cost,investment_cost,fixed_cost,investment_limit,initial_export_units,initial_import_units,efficiency
ocgt,demand,true,2030,2030,false,false,false,0.07,0,0.1,,0,0,0
ccgt,demand,true,2030,2025,true,false,false,0.05,0,0.1,,1,1,0
ccgt,demand,true,2030,2030,true,true,false,0.05,0,0.1,,0,0,0
battery,demand,true,2030,2030,false,false,false,0.0,0,0.1,,0,0,0.95
demand,battery,true,2030,2030,false,false,false,0.0,0,0.1,,0,0,0.95
wind,demand,true,2030,2030,false,false,false,0.001,0,0.1,,0,0,0
solar,demand,true,2030,2030,false,false,false,0,0,0.1,,0,0,0
ens,demand,true,2030,2030,false,false,false,0.18,0,0.1,,0,0,0
ocgt,demand,true,2050,2030,false,false,false,0.07,0,0.1,,0,0,0
ccgt,demand,true,2050,2030,false,false,false,0.05,0,0.1,,0,0,0
battery,demand,true,2050,2030,false,false,false,0.0,0,0.1,,0,0,0.95
demand,battery,true,2050,2030,false,false,false,0.0,0,0.1,,0,0,0.95
wind,demand,true,2050,2030,false,false,false,0.001,0,0.1,,0,0,0
solar,demand,true,2050,2030,false,false,false,0,0,0.1,,0,0,0
ens,demand,false,2050,2030,false,false,false,0.18,0,0.1,,0,0,0
18 changes: 9 additions & 9 deletions test/inputs/Multi-year Investments/graph-flows-data.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
asset_name,asset_name,,MW
from_asset,to_asset,carrier,capacity
ocgt,demand,electricity,0
ccgt,demand,electricity,0
battery,demand,electricity,0
demand,battery,electricity,0
wind,demand,electricity,0
solar,demand,electricity,0
ens,demand,electricity,0
asset_name,asset_name,,MW,year,year,
from_asset,to_asset,carrier,capacity,technical_lifetime,economic_lifetime,discount_rate
ocgt,demand,electricity,0,10,1,0.02
ccgt,demand,electricity,100,10,1,0.02
battery,demand,electricity,0,10,1,0.02
demand,battery,electricity,0,10,1,0.02
wind,demand,electricity,0,10,1,0.02
solar,demand,electricity,0,10,1,0.02
ens,demand,electricity,0,10,1,0.02
16 changes: 16 additions & 0 deletions test/inputs/Multi-year Investments/vintage-flows-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
asset_name,asset_name,year,kEUR/MW/year,kEUR/MW
from_asset,to_asset,commission_year,fixed_cost,investment_cost
ocgt,demand,2030,0.1,350
ccgt,demand,2030,0.1,350
battery,demand,2030,0.1,350
demand,battery,2030,0.1,350
wind,demand,2030,0.1,350
solar,demand,2030,0.1,350
ens,demand,2030,0.1,350
ocgt,demand,2050,0.1,350
ccgt,demand,2050,0.1,350
battery,demand,2050,0.1,350
demand,battery,2050,0.1,350
wind,demand,2030,0.1,350
solar,demand,2050,0.1,350
ens,demand,2050,0.1,350
68 changes: 34 additions & 34 deletions test/inputs/Norse/flows-data.csv
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
asset_name,asset_name,{true;false},,{true;false},{true;false},{true;false},kEUR/MWh,kEUR/MW/year,MW,MW,MW,p.u.
from_asset,to_asset,active,year,is_transport,investable,investment_integer,variable_cost,investment_cost,investment_limit,initial_export_capacity,initial_import_capacity,efficiency
Asgard_Battery,Asgard_E_demand,true,2030,false,false,false,0.003,0,0,0,0,0.95
Asgard_Solar,Asgard_Battery,true,2030,false,false,false,0.001,0,0,0,0,0.95
Asgard_Solar,Asgard_E_demand,true,2030,false,false,false,0.001,0,0,0,0,1
Asgard_CCGT,Asgard_E_demand,true,2030,false,false,false,0,0,0,0,0,0.55
G_imports,Asgard_CCGT,true,2030,false,false,false,0.0015,0,0,0,0,1
G_imports,Midgard_CCGT,true,2030,false,false,false,0.0015,0,0,0,0,1
G_imports,Valhalla_GT,true,2030,false,false,false,0.0015,0,0,0,0,1
G_imports,Valhalla_H2_generator,true,2030,false,false,false,0.0015,0,0,0,0,1
Asgard_E_demand,Midgard_E_demand,true,2030,true,true,true,0,2000,50000,0,0,1
Asgard_E_demand,Valhalla_E_balance,true,2030,true,true,false,0,5000,,1000,1000,1
Midgard_E_demand,Valhalla_E_balance,true,2030,true,true,true,0,3500,,0,0,1
Midgard_Wind,Midgard_E_demand,true,2030,false,false,false,0.002,0,0,0,0,0
Midgard_Nuclear_SMR,Midgard_E_demand,true,2030,false,false,false,0.015,0,0,0,0,1
Midgard_E_imports,Midgard_E_demand,true,2030,false,false,false,0.02,0,0,0,0,1
Midgard_CCGT,Midgard_E_demand,true,2030,false,false,false,0,0,0,0,0,0.5
Midgard_Hydro,Midgard_E_demand,true,2030,false,false,false,0,0,0,0,0,1
Midgard_E_demand,Midgard_Hydro,true,2030,false,false,false,0,0,0,0,0,0.7
Midgard_PHS,Midgard_E_demand,true,2030,false,false,false,0.004,0,0,0,0,0.85
Midgard_E_demand,Midgard_PHS,true,2030,false,false,false,0.002,0,0,0,0,0.85
Valhalla_GT,Valhalla_E_balance,true,2030,false,false,false,0,0,0,0,0,0.42
Valhalla_Fuel_cell,Valhalla_E_balance,true,2030,false,false,false,0,0,0,0,0,0.5
Valhalla_E_balance,Valhalla_E_exports,true,2030,false,false,false,0,0,0,0,0,1
Valhalla_E_balance,Valhalla_Electrolyser,true,2030,false,false,false,0,0,0,0,0,1
Valhalla_E_balance,Valhalla_Heat_pump,true,2030,false,false,false,0,0,0,0,0,4
Valhalla_Waste_heat,Valhalla_Heat_pump,true,2030,false,false,false,0.0025,0,0,0,0,1
Valhalla_Heat_pump,Valhalla_Heat_demand,true,2030,false,false,false,0,0,0,0,0,1
Valhalla_Fuel_cell,Valhalla_Heat_demand,true,2030,false,false,false,0,0,0,0,0,0.5
Valhalla_H2_demand,Valhalla_Fuel_cell,true,2030,false,false,false,0,0,0,0,0,1
Valhalla_Electrolyser,Valhalla_H2_demand,true,2030,false,false,false,0,0,0,0,0,0.7
Valhalla_H2_storage,Valhalla_H2_demand,true,2030,false,false,false,0,0,0,0,0,0.98
Valhalla_H2_demand,Valhalla_H2_storage,true,2030,false,false,false,0,0,0,0,0,0.98
Valhalla_H2_generator,Valhalla_H2_demand,true,2030,false,false,false,0,0,0,0,0,0.6
asset_name,asset_name,{true;false},,year,{true;false},{true;false},{true;false},kEUR/MWh,kEUR/MW/year,kEUR/MW/year,MW,MW,MW,p.u.
from_asset,to_asset,active,year,commission_year,is_transport,investable,investment_integer,variable_cost,investment_cost,fixed_cost,investment_limit,initial_export_units,initial_import_units,efficiency
Asgard_Battery,Asgard_E_demand,true,2030,2030,false,false,false,0.003,0,0.1,0,0,0,0.95
Asgard_Solar,Asgard_Battery,true,2030,2030,false,false,false,0.001,0,0.1,0,0,0,0.95
Asgard_Solar,Asgard_E_demand,true,2030,2030,false,false,false,0.001,0,0.1,0,0,0,1
Asgard_CCGT,Asgard_E_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.55
G_imports,Asgard_CCGT,true,2030,2030,false,false,false,0.0015,0,0.1,0,0,0,1
G_imports,Midgard_CCGT,true,2030,2030,false,false,false,0.0015,0,0.1,0,0,0,1
G_imports,Valhalla_GT,true,2030,2030,false,false,false,0.0015,0,0.1,0,0,0,1
G_imports,Valhalla_H2_generator,true,2030,2030,false,false,false,0.0015,0,0.1,0,0,0,1
Asgard_E_demand,Midgard_E_demand,true,2030,2030,true,true,true,0,2000,0.1,50000,0,0,1
Asgard_E_demand,Valhalla_E_balance,true,2030,2030,true,true,false,0,5000,0.1,,1000,1000,1
Midgard_E_demand,Valhalla_E_balance,true,2030,2030,true,true,true,0,3500,0.1,,0,0,1
Midgard_Wind,Midgard_E_demand,true,2030,2030,false,false,false,0.002,0,0.1,0,0,0,0
Midgard_Nuclear_SMR,Midgard_E_demand,true,2030,2030,false,false,false,0.015,0,0.1,0,0,0,1
Midgard_E_imports,Midgard_E_demand,true,2030,2030,false,false,false,0.02,0,0.1,0,0,0,1
Midgard_CCGT,Midgard_E_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.5
Midgard_Hydro,Midgard_E_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,1
Midgard_E_demand,Midgard_Hydro,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.7
Midgard_PHS,Midgard_E_demand,true,2030,2030,false,false,false,0.004,0,0.1,0,0,0,0.85
Midgard_E_demand,Midgard_PHS,true,2030,2030,false,false,false,0.002,0,0.1,0,0,0,0.85
Valhalla_GT,Valhalla_E_balance,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.42
Valhalla_Fuel_cell,Valhalla_E_balance,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.5
Valhalla_E_balance,Valhalla_E_exports,true,2030,2030,false,false,false,0,0,0.1,0,0,0,1
Valhalla_E_balance,Valhalla_Electrolyser,true,2030,2030,false,false,false,0,0,0.1,0,0,0,1
Valhalla_E_balance,Valhalla_Heat_pump,true,2030,2030,false,false,false,0,0,0.1,0,0,0,4
Valhalla_Waste_heat,Valhalla_Heat_pump,true,2030,2030,false,false,false,0.0025,0,0.1,0,0,0,1
Valhalla_Heat_pump,Valhalla_Heat_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,1
Valhalla_Fuel_cell,Valhalla_Heat_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.5
Valhalla_H2_demand,Valhalla_Fuel_cell,true,2030,2030,false,false,false,0,0,0.1,0,0,0,1
Valhalla_Electrolyser,Valhalla_H2_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.7
Valhalla_H2_storage,Valhalla_H2_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.98
Valhalla_H2_demand,Valhalla_H2_storage,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.98
Valhalla_H2_generator,Valhalla_H2_demand,true,2030,2030,false,false,false,0,0,0.1,0,0,0,0.6
Loading

0 comments on commit ddb20d9

Please sign in to comment.