Skip to content

Commit

Permalink
Merge pull request #102 from oemof/Feature/Add_discrete_pipe_example
Browse files Browse the repository at this point in the history
Add example with discrete DN numbers
  • Loading branch information
joroeder committed Dec 9, 2022
2 parents a441eee + a71de8c commit 4b1ef8f
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 8 deletions.
15 changes: 8 additions & 7 deletions docs/optimization_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,27 +279,28 @@ everybody is free to choose his own units (energy, mass flow, etc.).
* **label_3**: Label of the third tag. See :ref:`Label system <Label system>`.
* **active**: (0/1). If *active* is 0, this heatpipeline component is not considered. This attribute helps
for easy selecting and deselecting different investment options.
* **nonconvex**: (0/1). Choose whether a convex or a nonconvex investment should be performed. This leads
to a different meaning of the minimum heat transport capacity (*cap_min*). See
*P_heat_max* is given, the maximum heat load is calculated from the heat
demand series (see `consumers-heat_flow.csv`). Depending on the optimisation
setting, *P_heat_max* or the demand series is used for the optimisation
(see `oemof-solph documentation <https://oemof-solph.readthedocs.io/en/latest/usage.html#using-the-investment-mode>`_
for further information).
* **nonconvex**: (0/1). Choose whether a convex or a nonconvex investment should be performed.
With `nonconvex` set to 1, fix losses and fix costs independent of the
dimension of the pipelines capacity can be considered. It is recommended to
set `nonconvex` to 1, as the construction of DHS pipelines is usually
characterized by a high share of fixed costs.
If `nonconvex` is 0, the costs-curve is a line through origin.
* **l_factor**: Relative thermal loss per length unit (e.g. [kW_loss/(m*kW_installed)].
Defines the loss factor depending on the installed heat transport capacity of the
pipe. The *l_factor* is multiplied by the invested capacity in investment case, and by the given
*capacity* for a specific pipe in case of existing DHS pipes.
* **l_factor_fix**: Absolute thermal loss per length unit (e.g. [kW/m]).
In case of *nonconvex* is 1, the *l_factor_fix* is zero if no investement in a specific pipe
element is done. Be careful, if *nonconvex* is 0, this creates a fixed thermal loss.
Recommended to use with `nonconvex` is `True`.
* **cap_max**: Maximum installable capacity (e.g. [kW]).
* **cap_min**: Minimum installable capacity (e.g. [kW]). Note that there is a difference if a
*nonconvex* investment is applied (see `oemof-solph documentation <https://oemof-solph.readthedocs.io/en/latest/usage.html#using-the-investment-mode>`_
for further information).
* **capex_pipes**: Variable investment costs depending on the installed heat transport capacity
(e.g. [€/kW]).
* **fix_costs**: Fix investment costs independent of the installed capacity (e.g. [€])
This attribute requires `nonconvex` is set to `True`.

See the *Heatpipeline* API for further details about the attributes.

Expand Down
78 changes: 78 additions & 0 deletions examples/optimisation/discrete_DN_numbers/discrete_DN_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
Discrete DN number examples.
This examples shows how to perform an optimisation with an investment
in discrete DN numbers.
Please see the `pipes.csv` in the invest_data/network.
For each of the DN numbers a separate row is given in the table.
"""
import matplotlib.pyplot as plt
import dhnx

# Initialize thermal network
network = dhnx.network.ThermalNetwork()
network = network.from_csv_folder('twn_data')

# Load investment parameter
invest_opt = dhnx.input_output.load_invest_options('invest_data')

# plot network
static_map = dhnx.plotting.StaticMap(network)
static_map.draw(background_map=False)
plt.title('Given network')
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'],
color='tab:green', label='consumers', zorder=2.5, s=50)
plt.scatter(network.components.producers['lon'], network.components.producers['lat'],
color='tab:red', label='producers', zorder=2.5, s=50)
plt.scatter(network.components.forks['lon'], network.components.forks['lat'],
color='tab:grey', label='forks', zorder=2.5, s=50)
plt.text(-2, 32, 'P0', fontsize=14)
plt.legend()
plt.show()

# Execute investment optimization
network.optimize_investment(invest_options=invest_opt)

# ####### Postprocessing and Plotting ###########

# get results
results_edges = network.results.optimization['components']['pipes']
print(results_edges[['from_node', 'to_node', 'hp_type', 'capacity',
'direction', 'costs', 'losses']])

# print(results_edges[['invest_costs[€]']].sum())
print('Objective value: ', network.results.optimization['oemof_meta']['objective'])

# assign new ThermalNetwork with invested pipes
twn_results = network
twn_results.components['pipes'] = results_edges[results_edges['capacity'] > 0.001]

# plot invested edges
static_map_2 = dhnx.plotting.StaticMap(twn_results)
static_map_2.draw(background_map=False)
plt.title('Result network')
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'],
color='tab:green', label='consumers', zorder=2.5, s=50)
plt.scatter(network.components.producers['lon'], network.components.producers['lat'],
color='tab:red', label='producers', zorder=2.5, s=50)
plt.scatter(network.components.forks['lon'], network.components.forks['lat'],
color='tab:grey', label='forks', zorder=2.5, s=50)
plt.text(-2, 32, 'P0', fontsize=14)
for r, c in twn_results.components['pipes'].iterrows():
size = c["hp_type"]
type = c["from_node"].split("-")[0]
id = c["from_node"].split("-")[1]
lat_0 = twn_results.components[type].loc[id].lat
lon_0 = twn_results.components[type].loc[id].lon
type = c["to_node"].split("-")[0]
id = c["to_node"].split("-")[1]
lat_1 = twn_results.components[type].loc[id].lat
lon_1 = twn_results.components[type].loc[id].lon
lat_mid = lat_0 + 0.5 * (lat_1 - lat_0)
lon_mid = lon_0 + 0.5 * (lon_1 - lon_0)
plt.text(lon_mid, lat_mid, size, va="center", ha="center")

plt.legend()
plt.show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label_2,active,excess,shortage,shortage costs,excess costs
heat,1,0,0,999999,9999
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label_2,active,nominal_value
heat,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
label_3,active,nonconvex,l_factor,l_factor_fix,cap_max,cap_min,capex_pipes,fix_costs
DN-25,1,1,0,0.007656,28,27,0,466
DN-32,1,1,0,0.0086405,54,53,0,491
DN-40,1,1,0,0.0095755,98,97,0,522
DN-50,1,1,0,0.009141,179,178,0,563
DN-63,1,1,0,0.0114125,335,334,0,620
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,label_2,active,excess,shortage,shortage costs,excess costs
1,heat,1,0,0,9999,9999
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label_2,active
heat,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id,lat,lon,P_heat_max
0,30,40,15
1,10,40,18
2,10,60,25
3,30,70,36
4,50,60,25
5,90,40,12
6,60,10,50
7,60,30,20
12 changes: 12 additions & 0 deletions examples/optimisation/discrete_DN_numbers/twn_data/forks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id,lat,lon
0,30,20
1,20,20
2,20,40
3,20,60
4,20,70
5,20,80
6,40,90
7,60,70
8,80,40
9,80,20
10,60,20
21 changes: 21 additions & 0 deletions examples/optimisation/discrete_DN_numbers/twn_data/pipes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
id,from_node,to_node,length
0,producers-0,forks-0,20
2,forks-0,forks-1,10
3,forks-1,forks-2,20
4,forks-2,forks-3,20
5,forks-3,forks-4,10
6,forks-4,forks-5,10
7,forks-5,forks-6,30
8,forks-6,forks-7,30
9,forks-7,forks-8,30
10,forks-8,forks-9,20
11,forks-9,forks-10,10
12,forks-10,forks-0,30
13,forks-2,consumers-0,10
14,forks-2,consumers-1,10
15,forks-3,consumers-2,10
16,forks-4,consumers-3,10
17,forks-7,consumers-4,10
18,forks-8,consumers-5,10
19,forks-10,consumers-7,10
20,forks-10,consumers-6,10
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,lat,lon,active
0,30,0,1
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ passenv =
*
deps =
pytest
pytest-travis-fold
.[tests]
commands =
{posargs:pytest -vv --ignore=src}
Expand Down

0 comments on commit 4b1ef8f

Please sign in to comment.