Skip to content

Commit

Permalink
relation_storage added as an option (relation_equality removed)
Browse files Browse the repository at this point in the history
  • Loading branch information
behnam-zakeri committed May 13, 2019
1 parent 01fb55a commit 15dc540
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
8 changes: 8 additions & 0 deletions message_ix/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def init_storage(scen, *args, **kwargs):
# Initiating a parameter to specify the order of sub-annual time steps
scen.init_par('time_seq', idx_sets=['time'])

# Initiating a parameter for relating the content f storage in two
# different time steps (in even in two periods) together
scen.init_par('relation_storage',
idx_sets=['node', 'technology', 'level', 'year', 'year',
'time', 'time'],
idx_names=['node', 'technology', 'level', 'year_first',
'year_last', 'time_first', 'time_last'])

# Initiating two parameters for specifying lower and upper bounds of
# storage reservoir, and storage losses all as % of installed capacity
# (values should be between 0 and 1)
Expand Down
2 changes: 1 addition & 1 deletion message_ix/model/MESSAGE/data_load.gms
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $LOAD inv_tec, renewable_tec
$LOAD shares
$LOAD addon, type_addon, cat_addon, map_tec_addon
* Added for storage
$LOAD storage_tec, level_storage, map_tec_storage
$LOAD storage_tec, level_storage, map_tec_storage, relation_storage
$GDXIN

Execute_load '%in%'
Expand Down
9 changes: 4 additions & 5 deletions message_ix/model/MESSAGE/model_core.gms
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Equations
* Added for storage
STORAGE_CHANGE change in the content of storage
STORAGE_BALANCE storage commodity (content) balance
STORAGE_EQUALITY equality in the content of storage in two different time steps (like first and last timesteps)
STORAGE_REL relation between the content of storage in two different time steps (time_first * value = time_last)
STORAGE_BOUND_LO lower bound of the content of storage
STORAGE_BOUND_UP upper bound of the content of storage
;
Expand Down Expand Up @@ -1992,15 +1992,14 @@ STORAGE_BALANCE(node,storage_tec,level,year,time2)$ ( storage_loss(node,storage_
(1 - storage_loss(node,storage_tec,level,year,time) ) ) ;

***
* Equation STORAGE_EQUALITY
* Equation STORAGE_RELATION
* """""""""""""""""""""""""""""""
* .. math::
* STORAGE_{n,t,l,y,h} \eq ... (math notation to be added)
***
* We can add a test to check if the storage bounds defined by the user in first and last time period doesn't violate this equation
STORAGE_EQUALITY(node,storage_tec,level_storage,year,time)$(SUM(commodity, storage_loss(node,storage_tec,commodity,level_storage,year,time) ) AND
SUM((time2,year2), map_time_first_last(year,year2,time,time2) ) )..
STORAGE(node,storage_tec,level_storage,year,time) =E= SUM( (time2,year2)$map_time_first_last(year,year2,time,time2), STORAGE(node,storage_tec,level_storage,year,time2) );
STORAGE_REL(node,storage_tec,level_storage,year,year2,time,time2)$(relation_storage(node,storage_tec,level_storage,year,year2,time,time2) )..
STORAGE(node,storage_tec,level_storage,year,time) =L= relation_storage(node,storage_tec,level_storage,year,year2,time,time2) * STORAGE(node,storage_tec,level_storage,year2,time2);

***
* Equation STORAGE_BOUND_UP
Expand Down
1 change: 1 addition & 0 deletions message_ix/model/MESSAGE/parameter_def.gms
Original file line number Diff line number Diff line change
Expand Up @@ -707,5 +707,6 @@ Parameters
bound_storage_lo(node,tec,level,year_all,time) lower bound of storage content (percentage of capacity)
bound_storage_up(node,tec,level,year_all,time) upper bound of storage content (percentage of capacity)
storage_loss(node,tec,level,year_all,time) storage loss per timestep (percentage of capacity)
relation_storage(node,tec,level,year_all,year_all,time,time) relation between the content of storage in two time steps (and two periods) (a value between -1 and +1)
time_seq(time) sequence of subannual timesteps
;
6 changes: 0 additions & 6 deletions message_ix/model/includes/period_parameter_assignment.gms
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Sets
macro_base_period(year_all) flag for base year period in model horizon (period prior to first model period) - used in MACRO
* Added for storage
map_time_period(year_all,year_all2,time,time2) mapping of one sub-annual timestep (time) to the next (time2)
map_time_first_last(year_all,year_all2,time,time2) mapping of the first and last sub-annual timesteps in one period

;

Expand Down Expand Up @@ -50,11 +49,6 @@ map_period(year_all,year_all2)$( ORD(year_all) <= ORD(year_all2) ) = yes ;
map_time_period(year_all,year_all2,time,time2)$( ORD(year_all) = ORD(year_all2) AND time_seq(time) AND
(time_seq(time) + 1 = time_seq(time2) ) ) = yes;

* mapping of first and last time steps in a period
map_time_first_last(year_all,year_all2,time,time2)$( ( ORD(year_all) = ORD(year_all2)) AND
(time_seq(time) = smin(time3$time_seq(time3),time_seq(time3) ) AND
time_seq(time2) = smax(time3$time_seq(time3),time_seq(time3) ) ) ) = yes;

* dynamic sets (singleton) with first and last periods in model horizon of MESSAGEix (for easier reference)
first_period(year_all) = no ;
first_period(year_all)$( cat_year("firstmodelyear",year_all) ) = yes ;
Expand Down
8 changes: 8 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def add_storage_data(scen, time_order):
for h in time_order.keys():
scen.add_par('time_seq', h, time_order[h], '-')

# Adding a relation between storage content of two time steps (optional)
yr_first = yr_last = scen.set('year').tolist()[0]
time_first = 'a'
time_last = 'd'
scen.add_par('relation_storage', ['node', 'dam', 'storage',
yr_first, yr_last,
time_first, time_last], 1.25, '%')

# Adding minimum and maximum bound, and losses for storage (percentage)
for year, h in product(set(scen.set('year')), time_order.keys()):
storage_spec = ['node', 'dam', 'storage', year, h]
Expand Down

0 comments on commit 15dc540

Please sign in to comment.