From 652787c0c405cdb1d0bd45202bb838aa5a786d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 13 Dec 2018 08:25:36 +0100 Subject: [PATCH 1/3] Add example for activity_costs --- .../activity_costs/activity_costs.py | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 examples/oemof_0.3/activity_costs/activity_costs.py diff --git a/examples/oemof_0.3/activity_costs/activity_costs.py b/examples/oemof_0.3/activity_costs/activity_costs.py new file mode 100644 index 0000000..b96e3b3 --- /dev/null +++ b/examples/oemof_0.3/activity_costs/activity_costs.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- + +""" +General description +------------------- +This example illustrates the effect of activity_costs. + +There are the following components: + + - demand_heat: heat demand (constant, for the sake of simplicity) + - fireplace: wood firing, burns "for free" if somebody is around + - boiler: gas firing, consumes (paid) gas + + +Installation requirements +------------------------- +This example requires version 0.3 of oemof. Install by: + + pip install 'oemof>=0.3' + +""" + +import numpy as np +import pandas as pd +import pprint as pp +import oemof.solph as solph +from oemof.outputlib import processing, views +from oemof.tools import economics + +try: + import matplotlib.pyplot as plt +except ImportError: + plt = None + +########################################################################## +# Calculate parameters and initialize the energy system and +########################################################################## + +periods = 24 +time = pd.date_range('1/1/2018', periods=periods, freq='D') + +at_home = np.zeros(periods) +at_home[10:16] = 1 + +demand_heat = np.zeros(periods) +demand_heat[6:22] = 5 + +es = solph.EnergySystem(timeindex=time) + +b_heat = solph.Bus(label='b_heat') + +es.add(b_heat) + +sink_heat = solph.Sink( + label='demand', + inputs={b_heat: solph.Flow( + fixed=True, + actual_value=demand_heat, + nominal_value=1)}) + +fireplace = solph.Source( + label='fireplace', + outputs={b_heat: solph.Flow(nominal_value=10, activity_costs=1.0-at_home)}) + +boiler = solph.Source( + label='boiler', + outputs={b_heat: solph.Flow(nominal_value=10, variable_costs=0.2)}) + +es.add(sink_heat, fireplace, boiler) + +########################################################################## +# Optimise the energy system +########################################################################## + +# create an optimization problem and solve it +om = solph.Model(es) + +# solve model +om.solve(solver='cbc', solve_kwargs={'tee': True}) + +########################################################################## +# Check and plot the results +########################################################################## + +results = processing.results(om) + +# plot data +if plt is not None: + data = views.node(results, 'b_heat')['sequences'] + ax = data.plot(kind='line', drawstyle='steps-post', grid=True, rot=0) + ax.set_xlabel('Time') + ax.set_ylabel('Heat (arb. units)') + plt.show() From 6938c4707edc153c2f00c8a254e7c8dbf2c50c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 13 Dec 2018 10:37:38 +0100 Subject: [PATCH 2/3] Fully implement example for activity_costs --- .../activity_costs/activity_costs.py | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/oemof_0.3/activity_costs/activity_costs.py b/examples/oemof_0.3/activity_costs/activity_costs.py index b96e3b3..7a22508 100644 --- a/examples/oemof_0.3/activity_costs/activity_costs.py +++ b/examples/oemof_0.3/activity_costs/activity_costs.py @@ -11,6 +11,10 @@ - fireplace: wood firing, burns "for free" if somebody is around - boiler: gas firing, consumes (paid) gas +Notice that activity_costs is an attribute to NonConvex. +This is because it relies on the activity status of a component +which is only available for nonconvex flows. + Installation requirements ------------------------- @@ -37,13 +41,14 @@ ########################################################################## periods = 24 -time = pd.date_range('1/1/2018', periods=periods, freq='D') +time = pd.date_range('1/1/2018', periods=periods, freq='H') -at_home = np.zeros(periods) -at_home[10:16] = 1 +demand_heat = np.full(periods,5) +demand_heat[:4] = 0 +demand_heat[4:18] = 4 -demand_heat = np.zeros(periods) -demand_heat[6:22] = 5 +activity_costs = np.full(periods,5) +activity_costs[18:] = 0 es = solph.EnergySystem(timeindex=time) @@ -60,11 +65,15 @@ fireplace = solph.Source( label='fireplace', - outputs={b_heat: solph.Flow(nominal_value=10, activity_costs=1.0-at_home)}) + outputs={b_heat: solph.Flow(nominal_value=3, + variable_costs=0, + nonconvex=solph.NonConvex( + activity_costs=activity_costs))}) boiler = solph.Source( label='boiler', - outputs={b_heat: solph.Flow(nominal_value=10, variable_costs=0.2)}) + outputs={b_heat: solph.Flow(nominal_value=10, + variable_costs=1)}) es.add(sink_heat, fireplace, boiler) @@ -91,3 +100,4 @@ ax.set_xlabel('Time') ax.set_ylabel('Heat (arb. units)') plt.show() + From 96c40d75ff65864fd69ac9f61eebb90b6e0fd696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 13 Dec 2018 09:42:25 +0100 Subject: [PATCH 3/3] Adhere to PEP8 --- examples/oemof_0.3/activity_costs/activity_costs.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/oemof_0.3/activity_costs/activity_costs.py b/examples/oemof_0.3/activity_costs/activity_costs.py index 7a22508..e84c2d2 100644 --- a/examples/oemof_0.3/activity_costs/activity_costs.py +++ b/examples/oemof_0.3/activity_costs/activity_costs.py @@ -26,10 +26,8 @@ import numpy as np import pandas as pd -import pprint as pp import oemof.solph as solph from oemof.outputlib import processing, views -from oemof.tools import economics try: import matplotlib.pyplot as plt @@ -43,11 +41,11 @@ periods = 24 time = pd.date_range('1/1/2018', periods=periods, freq='H') -demand_heat = np.full(periods,5) +demand_heat = np.full(periods, 5) demand_heat[:4] = 0 demand_heat[4:18] = 4 -activity_costs = np.full(periods,5) +activity_costs = np.full(periods, 5) activity_costs[18:] = 0 es = solph.EnergySystem(timeindex=time) @@ -100,4 +98,3 @@ ax.set_xlabel('Time') ax.set_ylabel('Heat (arb. units)') plt.show() -