Skip to content

Commit

Permalink
New parameter and constraint: maximal power gradient v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smuellr committed Nov 17, 2015
1 parent 1ad4628 commit 2497cf2
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 38 deletions.
63 changes: 47 additions & 16 deletions doc/mathdoc.rst

Large diffs are not rendered by default.

Binary file modified doc/newsealand/newsealand.xlsx
Binary file not shown.
Binary file modified doc/paradiso/paradiso_2.xlsx
Binary file not shown.
Binary file modified doc/paradiso/paradiso_3.xlsx
Binary file not shown.
12 changes: 12 additions & 0 deletions doc/report.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ To sum over time, method :meth:`~pandas.DataFrame.sum` is called with its
``axis`` argument set to columns (``1``). This yields a DataFrame indexed over
the tuple *(site, process, input commodity, output commodity)* and the
summed emissions as value.

Get timeseries
-------------

.. literalinclude:: ../urbs.py
:pyobject: get_timeseries

With the arguments ``instance``, ``com`` and ``sit`` the function :func:
`get_timeseries` returns :class:`~pandas.DataFrames` of all timeseries that
are referring to the given commodity and site.
This includes the derivative for ``created`` and ``consumed``, which is
calculated and standardized by the power capacity at the end of the function.

Write to Excel
--------------
Expand Down
26 changes: 13 additions & 13 deletions doc/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ to 9 M€/MWh. This yields the following table:
:header-rows: 1
:stub-columns: 2

Site,Process,inst-cap,cap-lo,cap-up,inv-cost,fix-cost,var-cost,wacc,depr.
Jepid Island,Gas plant,25,0,100,450000,6000,1.62,0.07,30
Jepid Island,Slack powerplant,999,999,999,0,0,**9000000.0**,0.07,1
Jepid Island,Wind park,0,0,**250**,900000,30000,0.0,0.07,25
Qlyph Archipelago,Gas plant,0,0,100,450000,6000,1.62,0.07,30
Qlyph Archipelago,Slack powerplant,999,999,999,0,0,**9000000.0**,0.07,1
Qlyph Archipelago,Wind park,0,0,**200**,900000,30000,0.0,0.07,25
Stryworf Key,Gas plant,25,0,100,450000,6000,1.62,0.07,30
Stryworf Key,Slack powerplant,999,999,999,0,0,**9000000**.0,0.07,1
Stryworf Key,Wind park,0,0,**120**,900000,30000,0.0,0.07,25
Vled Haven,Gas plant,0,0,80,450000,6000,1.62,0.07,30
Vled Haven,Slack powerplant,999,999,999,0,0,**9000000.0**,0.07,1
Vled Haven,Wind park,0,0,**80**,900000,30000,0.0,0.07,25
Site,Process,inst-cap,cap-lo,cap-up,max-grad,inv-cost,fix-cost,var-cost,wacc,depr.
Jepid Island,Gas plant,25,0,100,5,450000,6000,1.62,0.07,30
Jepid Island,Slack powerplant,999,999,999,inf,0,0,**9000000.0**,0.07,1
Jepid Island,Wind park,0,0,**250**,inf,900000,30000,0.0,0.07,25
Qlyph Archipelago,Gas plant,0,0,100,5,450000,6000,1.62,0.07,30
Qlyph Archipelago,Slack powerplant,999,999,999,inf,0,0,**9000000.0**,0.07,1
Qlyph Archipelago,Wind park,0,0,**200**,inf,900000,30000,0.0,0.07,25
Stryworf Key,Gas plant,25,0,100,5,450000,6000,1.62,0.07,30
Stryworf Key,Slack powerplant,999,999,999,inf,0,0,**9000000**.0,0.07,1
Stryworf Key,Wind park,0,0,**120**,inf,900000,30000,0.0,0.07,25
Vled Haven,Gas plant,0,0,80,5,450000,6000,1.62,0.07,30
Vled Haven,Slack powerplant,999,999,999,inf,0,0,**9000000.0**,0.07,1
Vled Haven,Wind park,0,0,**80**,inf,900000,30000,0.0,0.07,25


Transmission
Expand Down
Binary file modified mimo-example.xlsx
Binary file not shown.
49 changes: 40 additions & 9 deletions urbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ def create_model(data, timesteps=None, dt=1):
m.tm, m.pro_tuples,
rule=res_process_throughput_by_capacity_rule,
doc='process throughput <= total process capacity')
m.res_process_throughput_gradient = pyomo.Constraint(
m.tm, m.pro_tuples,
rule=res_process_throughput_gradient_rule,
doc='process throughput gradient <= maximal gradient')
m.res_process_capacity = pyomo.Constraint(
m.pro_tuples,
rule=res_process_capacity_rule,
Expand Down Expand Up @@ -704,6 +708,21 @@ def def_intermittent_supply_rule(m, tm, sit, pro, coin):
def res_process_throughput_by_capacity_rule(m, tm, sit, pro):
return (m.tau_pro[tm, sit, pro] <= m.cap_pro[sit, pro])

# absolute process throughput gradient <= maximal gradient
def res_process_throughput_gradient_rule(m, t, sit, pro):
# constraint only effectively restricting if max-grad < 1/dt
if m.process.loc[sit, pro]['max-grad'] < 1/m.dt.value:
if m.cap_pro[sit, pro].value is None:
return pyomo.Constraint.Skip
else:
return (m.tau_pro[t-1, sit, pro] -
m.process.loc[sit, pro]['max-grad'] * m.cap_pro[sit, pro],
m.tau_pro[t, sit, pro],
m.tau_pro[t-1, sit, pro] +
m.process.loc[sit, pro]['max-grad'] * m.cap_pro[sit, pro])
else:
return pyomo.Constraint.Skip

# lower bound <= process capacity <= upper bound
def res_process_capacity_rule(m, sit, pro):
return (m.process.loc[sit, pro]['cap-lo'],
Expand Down Expand Up @@ -1417,7 +1436,7 @@ def get_timeseries(instance, com, sit, timesteps=None):
"""Return DataFrames of all timeseries referring to given commodity
Usage:
create, consume, store, imp, exp = get_timeseries(instance, co,
create, consume, store, imp, exp, der = get_timeseries(instance, co,
sit, timesteps)
Args:
Expand All @@ -1427,8 +1446,8 @@ def get_timeseries(instance, com, sit, timesteps=None):
timesteps: optional list of timesteps, defaults: all modelled timesteps
Returns:
a (created, consumed, storage, imported, exported) tuple of DataFrames
timeseries. These are:
a (created, consumed, storage, imported, exported, derivative) tuple
of DataFrames timeseries. These are:
* created: timeseries of commodity creation, including stock source
* consumed: timeseries of commodity consumption, including demand
Expand Down Expand Up @@ -1503,13 +1522,25 @@ def get_timeseries(instance, com, sit, timesteps=None):
stored = pd.DataFrame(0, index=timesteps,
columns=['Level', 'Stored', 'Retrieved'])

# DERIVATIVE
derivative = created.join(consumed)
derivative = pd.DataFrame(np.diff(derivative.T).T,
index=derivative.index[:-1], columns=derivative.columns)
derivative = derivative.append(pd.DataFrame(np.zeros_like(derivative.tail(1)),
index=derivative.index[-1:]+1, columns=derivative.columns))
# standardizing
caps = get_entities(instance, ['cap_pro', 'cap_pro_new'])
caps = caps.loc[:,'cap_pro_new']
for col in derivative.columns:
derivative[col] = derivative[col] / caps.loc[(sit,col)]

# show stock as created
created = created.join(stock)

# show demand as consumed
consumed = consumed.join(demand)

return created, consumed, stored, imported, exported
return created, consumed, stored, imported, exported, derivative


def report(instance, filename, commodities=None, sites=None):
Expand Down Expand Up @@ -1543,7 +1574,7 @@ def report(instance, filename, commodities=None, sites=None):
# collect timeseries data
for co in commodities:
for sit in sites:
created, consumed, stored, imported, exported = get_timeseries(
created, consumed, stored, imported, exported, derivative = get_timeseries(
instance, co, sit)

overprod = pd.DataFrame(
Expand All @@ -1553,10 +1584,10 @@ def report(instance, filename, commodities=None, sites=None):
stored['Retrieved'] - stored['Stored'])

tableau = pd.concat(
[created, consumed, stored, imported, exported, overprod],
[created, consumed, stored, imported, exported, overprod, derivative],
axis=1,
keys=['Created', 'Consumed', 'Storage',
'Import from', 'Export to', 'Balance'])
keys=['Created', 'Consumed', 'Storage', 'Import from',
'Export to', 'Balance', 'Derivative'])
timeseries[(co, sit)] = tableau.copy()

# timeseries sums
Expand Down Expand Up @@ -1612,7 +1643,7 @@ def plot(prob, com, sit, timesteps=None, power_unit='MW', energy_unit='MWh'):
fig = plt.figure(figsize=(16, 8))
gs = mpl.gridspec.GridSpec(2, 1, height_ratios=[2, 1])

created, consumed, stored, imported, exported = get_timeseries(
created, consumed, stored, imported, exported, derivative = get_timeseries(
prob, com, sit, timesteps)

costs, cpro, ctra, csto = get_constants(prob)
Expand Down

0 comments on commit 2497cf2

Please sign in to comment.