{
"cells": [
{
"cell_type": "markdown",
"id": "1340a80b",
"metadata": {
"Collapsed": "false"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"id": "a4e4cf89",
"metadata": {
"Collapsed": "false"
},
"source": [
"(simple-tunnel)=\n",
"# Basic tunnel modelling\n",
"\n",
"This example is available in the following formats.\n",
"\n",
"- pyshop\n",
" - [tunnel_model.py](tunnel-model-py)\n",
" - [tunnel_gate.py](tunnel-gate-py)\n",
"- YAML\n",
" - [tunnel_model.yaml](tunnel-model-yaml)\n",
" - [tunnel_gate.yaml](tunnel-gate-yaml)\n",
"- ASCII\n",
" - [tunnel_model.ascii](tunnel-model-ascii)\n",
" - [tunnel_gate.ascii](tunnel-gate-ascii)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "46c126e4",
"metadata": {
"Collapsed": "false"
},
"outputs": [],
"source": [
"#Necessary imports used in all examples\n",
"import pandas as pd\n",
"from pyshop import ShopSession\n",
"pd.options.plotting.backend = \"plotly\"\n",
"\n",
"#Functions used in this example for building a tunnel model, adding a gate to a tunnel and running the optimization\n",
"from tunnel_model import build_model, add_gate, run_model"
]
},
{
"cell_type": "markdown",
"id": "6592a4c9",
"metadata": {
"Collapsed": "false"
},
"source": [
"We create a system with three [reservoirs](reservoir), three [tunnels](tunnel) and one [](plant). In the first model, **shop_default**, there are no gates to optimize, and the flow simply follows the physical laws of the tunnel system. Both the start level and the inflow in Reservoir3, the closest reservoir to the plant, is higher than in the other reservoirs. This means, that some of this extra water in Reservoir3 will naturally flow into the other reservoirs."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "88c858bd",
"metadata": {
"Collapsed": "false"
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "variable=Tunnel1
index=%{x}
value=%{y}",
"legendgroup": "Tunnel1",
"line": {
"color": "#636efa",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "Tunnel1",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
"2018-02-27T00:00:00",
"2018-02-27T01:00:00",
"2018-02-27T02:00:00",
"2018-02-27T03:00:00",
"2018-02-27T04:00:00",
"2018-02-27T05:00:00"
],
"xaxis": "x",
"y": [
-46.2897364107514,
-55.13204213710764,
-56.4767921124962,
-54.80144168430949,
-51.95774353943154,
-48.88428299312206
],
"yaxis": "y"
},
{
"hovertemplate": "variable=Tunnel2
index=%{x}
value=%{y}",
"legendgroup": "Tunnel2",
"line": {
"color": "#EF553B",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "Tunnel2",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
"2018-02-27T00:00:00",
"2018-02-27T01:00:00",
"2018-02-27T02:00:00",
"2018-02-27T03:00:00",
"2018-02-27T04:00:00",
"2018-02-27T05:00:00"
],
"xaxis": "x",
"y": [
-144.3465224776095,
-127.82292227204584,
-114.85010924894016,
-104.72468775480226,
-96.87942426893358,
-90.84849622683707
],
"yaxis": "y"
},
{
"hovertemplate": "variable=Tunnel3
index=%{x}
value=%{y}",
"legendgroup": "Tunnel3",
"line": {
"color": "#00cc96",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "Tunnel3",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
"2018-02-27T00:00:00",
"2018-02-27T01:00:00",
"2018-02-27T02:00:00",
"2018-02-27T03:00:00",
"2018-02-27T04:00:00",
"2018-02-27T05:00:00"
],
"xaxis": "x",
"y": [
90.0,
90.0,
90.0,
90.0,
90.0,
90.0
],
"yaxis": "y"
}
],
"layout": {
"legend": {
"title": {
"text": "variable"
},
"tracegroupgap": 0
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
],
"sequentialminus": [
[
0.0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1.0,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "Tunnel flow"
},
"xaxis": {
"anchor": "y",
"domain": [
0.0,
1.0
],
"title": {
"text": "index"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0.0,
1.0
],
"title": {
"text": "value"
}
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#Create a standard ShopSession\n",
"shop_default=ShopSession()\n",
"#Build a simple tunnel model without tunnel gates by calling function \"build_model\" in tunnel_model.py\n",
"build_model(shop_default)\n",
"#Optimize model by calling \"run_model\" in tunnel_model.py\n",
"run_model(shop_default)\n",
"#Display topology to the screen\n",
"display(shop_default.model.build_connection_tree())\n",
"#Display results for reservoir levels\n",
"pd.concat([obj.head.get().rename(obj.get_name()) for obj in shop_default.model.reservoir], axis=1).plot(title=\"Reservoir level\")\n",
"#Display results for tunnel flows\n",
"pd.concat([obj.flow.get().rename(obj.get_name()) for obj in shop_default.model.tunnel], axis=1).plot(title=\"Tunnel flow\")"
]
},
{
"cell_type": "markdown",
"id": "6730762f",
"metadata": {
"Collapsed": "false"
},
"source": [
"The second model is allowed to adjust the gate opening in the tunnel between Reservoir2 and Reservoir3. As we see in the results, SHOP is able to keep more water in Reservoir3, and thus get more energy from the plant, by closing this gate for most of the period. Only at the end of the period it is partially opened to prevent spillage from Reservoir3."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "eddc1274",
"metadata": {
"Collapsed": "false"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Optimization of the gate in Tunnel2 improved the objective with 550.35€\n"
]
}
],
"source": [
"#Create a standard ShopSession\n",
"shop_optimized=ShopSession()\n",
"#Build a simple tunnel model without gates by calling function \"build_model\" in tunnel_model.py\n",
"build_model(shop_optimized)\n",
"#Add a gate between Reservoir2 and Reservoir3 by calling function \"add_gate\" in tunnel_model.py\n",
"add_gate(shop_optimized)\n",
"#Optimize model by calling \"run_model\" in tunnel_model.py\n",
"run_model(shop_optimized)\n",
"#Display results for reservoir levels\n",
"pd.concat([obj.head.get().rename(obj.get_name()) for obj in shop_optimized.model.reservoir], axis=1).plot(title=\"Reservoir level\")\n",
"#Display results for tunnel flows\n",
"pd.concat([obj.flow.get().rename(obj.get_name()) for obj in shop_optimized.model.tunnel], axis=1).plot(title=\"Tunnel flow\")\n",
"#Display results for tunnel opening\n",
"pd.concat([obj.gate_opening.get().rename(obj.get_name()) for obj in shop_optimized.model.tunnel], axis=1).plot(title=\"Gate opening\")\n",
"\n",
"#Compare objective functions to see improvement in result from optimizing the gate\n",
"default_objective=shop_default.model.objective[\"average_objective\"].grand_total.get()\n",
"optimized_objective=shop_optimized.model.objective[\"average_objective\"].grand_total.get()\n",
"print(f\"Optimization of the gate in Tunnel2 improved the objective with {-(optimized_objective-default_objective):.2f}€\")"
]
},
{
"cell_type": "markdown",
"id": "5c873e19",
"metadata": {
"Collapsed": "false"
},
"source": [
"# File contents"
]
},
{
"cell_type": "markdown",
"id": "edadd900",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-model-py)=\n",
"## tunnel_model.py "
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9c9e59dc",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"import pandas as pd\n",
"\n",
"def build_model(shop):\n",
" starttime=pd.Timestamp(\"2018-02-27 00:00:00\")\n",
" endtime=pd.Timestamp(\"2018-02-27 06:00:00\")\n",
" shop.set_time_resolution(starttime=starttime, endtime=endtime, timeunit=\"hour\")\n",
"\n",
" rsv1=shop.model.reservoir.add_object(\"Reservoir1\")\n",
" rsv1.hrl.set(100)\n",
" rsv1.lrl.set(90)\n",
" rsv1.max_vol.set(5)\n",
" rsv1.vol_head.set(pd.Series([90,100,101],index=[0,5,6]))\n",
" rsv1.flow_descr.set(pd.Series([0, 1000], index=[100, 101]))\n",
"\n",
" rsv2=shop.model.reservoir.add_object(\"Reservoir2\")\n",
" rsv2.hrl.set(100)\n",
" rsv2.lrl.set(90)\n",
" rsv2.max_vol.set(5)\n",
" rsv2.vol_head.set(pd.Series([90,100,101],index=[0,5,6]))\n",
" rsv2.flow_descr.set(pd.Series([0, 1000], index=[100, 101]))\n",
"\n",
" rsv3=shop.model.reservoir.add_object(\"Reservoir3\")\n",
" rsv3.hrl.set(100)\n",
" rsv3.lrl.set(90)\n",
" rsv3.max_vol.set(5)\n",
" rsv3.vol_head.set(pd.Series([90,100,101],index=[0,5,6]))\n",
" rsv3.flow_descr.set(pd.Series([0, 1000], index=[100, 101]))\n",
"\n",
" plant1=shop.model.plant.add_object(\"Plant1\")\n",
" plant1.main_loss.set([0.0002])\n",
" plant1.penstock_loss.set([0.0001])\n",
"\n",
" p1g1=shop.model.generator.add_object(\"P1G1\")\n",
" p1g1.connect_to(plant1)\n",
" p1g1.penstock.set(1)\n",
" p1g1.p_min.set(0.1)\n",
" p1g1.p_nom.set(100)\n",
" p1g1.p_max.set(100)\n",
" p1g1.gen_eff_curve.set(pd.Series([95,98], index=[0,100]))\n",
" p1g1.turb_eff_curves.set([pd.Series([80,95,90],index=[1,90,100],name=90),pd.Series([82,98,92],index=[1,90,100],name=100)])\n",
"\n",
" tunnel1=shop.model.tunnel.add_object(\"Tunnel1\")\n",
" tunnel1.loss_factor.set(0.00016)\n",
" tunnel1.start_height.set(90)\n",
" tunnel1.end_height.set(90)\n",
" tunnel1.diameter.set(3)\n",
" tunnel1.length.set(2022)\n",
" \n",
" tunnel2=shop.model.tunnel.add_object(\"Tunnel2\")\n",
" tunnel2.loss_factor.set(0.00015)\n",
" tunnel2.start_height.set(90)\n",
" tunnel2.end_height.set(90)\n",
" tunnel2.diameter.set(3)\n",
" tunnel2.length.set(2022)\n",
"\n",
" tunnel3=shop.model.tunnel.add_object(\"Tunnel3\")\n",
" tunnel3.loss_factor.set(0.00030)\n",
" tunnel3.start_height.set(90)\n",
" tunnel3.end_height.set(90)\n",
" tunnel3.diameter.set(3)\n",
" tunnel3.length.set(2022)\n",
"\n",
" rsv1.connect_to(tunnel1)\n",
" tunnel1.connect_to(rsv2)\n",
" rsv2.connect_to(tunnel2)\n",
" tunnel2.connect_to(rsv3)\n",
" rsv3.connect_to(tunnel3)\n",
" tunnel3.connect_to(plant1)\n",
"\n",
" rsv1.start_head.set(93)\n",
" rsv2.start_head.set(93)\n",
" rsv3.start_head.set(97)\n",
"\n",
" rsv3.inflow.set(200)\n",
"\n",
" rsv1.energy_value_input.set(31.7)\n",
" rsv2.energy_value_input.set(31.7)\n",
" rsv3.energy_value_input.set(31.7)\n",
"\n",
" da=shop.model.market.add_object('1')\n",
" da.sale_price.set(39.99)\n",
" da.buy_price.set(40.01)\n",
" da.max_sale.set(9999)\n",
" da.max_buy.set(9999)\n",
" \n",
"def add_gate(shop):\n",
" tunnel2=shop.model.tunnel[\"Tunnel2\"]\n",
" tunnel2.gate_opening_curve.set(pd.Series([0,1],index=[0,1]))\n",
" tunnel2.continuous_gate.set(1)\n",
" \n",
"def run_model(shop):\n",
" shop.start_sim([],['3'])\n",
" shop.set_code(['inc'],[])\n",
" shop.start_sim([],['3'])\n"
]
}
],
"source": [
"with open('tunnel_model.py', 'r') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"id": "9d6fea41",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-gate-py)=\n",
"## tunnel_gate.py"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "585a69aa",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"import pandas as pd\n",
"\n",
"def add_tunnel_gate(shop):\n",
" tunnel2=shop.model.tunnel[\"Tunnel2\"]\n",
" tunnel2.gate_opening_curve.set(pd.Series([0,1],index=[0,1]))\n",
" tunnel2.continuous_gate.set(1)\n"
]
}
],
"source": [
"with open('tunnel_gate.py', 'r') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"id": "8ca721c9",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-model-yaml)=\n",
"## tunnel_model.yaml "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "9151761a",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"time:\n",
" starttime: 2018-02-27 00:00:00\n",
" endtime: 2018-02-27 06:00:00\n",
" timeunit: hour\n",
" timeresolution:\n",
" 2018-02-27 00:00:00: 1\n",
"model:\n",
" reservoir:\n",
" Reservoir1:\n",
" start_vol: 0\n",
" start_head: 93\n",
" max_vol: 5\n",
" lrl: 90\n",
" hrl: 100\n",
" vol_head:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" - 5\n",
" - 6\n",
" y:\n",
" - 90\n",
" - 100\n",
" - 101\n",
" flow_descr:\n",
" ref: 0\n",
" x:\n",
" - 100\n",
" - 101\n",
" y:\n",
" - 0\n",
" - 1000\n",
" endpoint_desc_nok_mwh:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" y:\n",
" - 31.7\n",
" Reservoir2:\n",
" start_vol: 0\n",
" start_head: 93\n",
" max_vol: 5\n",
" lrl: 90\n",
" hrl: 100\n",
" vol_head:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" - 5\n",
" - 6\n",
" y:\n",
" - 90\n",
" - 100\n",
" - 101\n",
" flow_descr:\n",
" ref: 0\n",
" x:\n",
" - 100\n",
" - 101\n",
" y:\n",
" - 0\n",
" - 1000\n",
" endpoint_desc_nok_mwh:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" y:\n",
" - 31.7\n",
" Reservoir3:\n",
" start_vol: 0\n",
" start_head: 97\n",
" max_vol: 5\n",
" lrl: 90\n",
" hrl: 100\n",
" vol_head:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" - 5\n",
" - 6\n",
" y:\n",
" - 90\n",
" - 100\n",
" - 101\n",
" flow_descr:\n",
" ref: 0\n",
" x:\n",
" - 100\n",
" - 101\n",
" y:\n",
" - 0\n",
" - 1000\n",
" endpoint_desc_nok_mwh:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" y:\n",
" - 31.7\n",
" inflow:\n",
" 2018-02-27 00:00:00: 200\n",
" plant:\n",
" Plant1:\n",
" main_loss:\n",
" - 0.0002\n",
" penstock_loss:\n",
" - 0.0001\n",
" generator:\n",
" P1G1:\n",
" penstock: 1\n",
" p_min: 0.1\n",
" p_max: 100\n",
" p_nom: 100\n",
" gen_eff_curve:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" - 100\n",
" y:\n",
" - 95\n",
" - 98\n",
" turb_eff_curves:\n",
" - ref: 90\n",
" x:\n",
" - 1\n",
" - 90\n",
" - 100\n",
" y:\n",
" - 80\n",
" - 95\n",
" - 90\n",
" - ref: 100\n",
" x:\n",
" - 1\n",
" - 90\n",
" - 100\n",
" y:\n",
" - 82\n",
" - 98\n",
" - 92\n",
" startcost:\n",
" 2018-02-27 00:00:00: 0\n",
" tunnel:\n",
" Tunnel1:\n",
" start_height: 90\n",
" end_height: 90\n",
" diameter: 3\n",
" length: 2022\n",
" loss_factor: 0.00016\n",
" Tunnel2:\n",
" start_height: 90\n",
" end_height: 90\n",
" diameter: 3\n",
" length: 2022\n",
" loss_factor: 0.00015\n",
" Tunnel3:\n",
" start_height: 90\n",
" end_height: 90\n",
" diameter: 3\n",
" length: 2022\n",
" loss_factor: 0.0003\n",
" market:\n",
" 1:\n",
" market_type: ENERGY\n",
" max_buy:\n",
" 2018-02-27 00:00:00: 9999\n",
" max_sale:\n",
" 2018-02-27 00:00:00: 9999\n",
" buy_price:\n",
" 2018-02-27 00:00:00: 40.01\n",
" sale_price:\n",
" 2018-02-27 00:00:00: 39.99\n",
"connections:\n",
" - from: Tunnel1\n",
" to: Reservoir2\n",
" - from: Tunnel2\n",
" to: Reservoir3\n",
" - from: Tunnel3\n",
" to: Plant1\n",
" - from: Plant1\n",
" to: P1G1\n",
" - from: Reservoir1\n",
" to: Tunnel1\n",
" - from: Reservoir2\n",
" to: Tunnel2\n",
" - from: Reservoir3\n",
" to: Tunnel3\n",
"\n"
]
}
],
"source": [
"with open('tunnel_model.yaml', 'r') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"id": "0891be36",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-gate-yaml)=\n",
"## tunnel_gate.yaml "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "ddfff979",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"model:\n",
" tunnel:\n",
" Tunnel2:\n",
" continuous_gate: 1\n",
" gate_opening_curve:\n",
" ref: 0\n",
" x:\n",
" - 0\n",
" - 1\n",
" y:\n",
" - 0\n",
" - 1\n",
"\n"
]
}
],
"source": [
"with open('tunnel_gate.yaml', 'r') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"id": "5a870add",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-model-ascii)=\n",
"## tunnel_model.ascii "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "3619843e",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OPTIMIZATION time \n",
"#Start_time; End_time;\n",
"20180227000000 20180227060000 \n",
"\n",
"#;N_full_iterations;Accuracy;\n",
"OPTIMIZATION 1000 1.00 \n",
"#Time resolution in the optimization;\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 NO_UNIT 7 \n",
"# Time; f(t);\n",
"20180227000000000 1.00000000000000000 \n",
"\n",
"RESERVOIR attributes Reservoir1 \n",
"#ID;Water_course;Type;Maxvol;Lrl;Hrl;\n",
" 0 0 0 5.000 90.000 100.000 \n",
"\n",
"RESERVOIR vol_head Reservoir1\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 3 MM3 METER\n",
"# x_value; y_value;\n",
"0.0000000000 90.0000000000 \n",
"5.0000000000 100.0000000000 \n",
"6.0000000000 101.0000000000 \n",
"\n",
"RESERVOIR flow_descr Reservoir1\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 2 METER M3/S\n",
"# x_value; y_value;\n",
"100.0000000000 0.0000000000 \n",
"101.0000000000 1000.0000000000 \n",
"\n",
"RESERVOIR endpoint_desc Reservoir1\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 1 MM3 NOK/MWH\n",
"# x_value; y_value;\n",
"0.0000000000 31.7000000000 \n",
"\n",
"RESERVOIR attributes Reservoir2 \n",
"#ID;Water_course;Type;Maxvol;Lrl;Hrl;\n",
" 0 0 0 5.000 90.000 100.000 \n",
"\n",
"RESERVOIR vol_head Reservoir2\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 3 MM3 METER\n",
"# x_value; y_value;\n",
"0.0000000000 90.0000000000 \n",
"5.0000000000 100.0000000000 \n",
"6.0000000000 101.0000000000 \n",
"\n",
"RESERVOIR flow_descr Reservoir2\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 2 METER M3/S\n",
"# x_value; y_value;\n",
"100.0000000000 0.0000000000 \n",
"101.0000000000 1000.0000000000 \n",
"\n",
"RESERVOIR endpoint_desc Reservoir2\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 1 MM3 NOK/MWH\n",
"# x_value; y_value;\n",
"0.0000000000 31.7000000000 \n",
"\n",
"RESERVOIR attributes Reservoir3 \n",
"#ID;Water_course;Type;Maxvol;Lrl;Hrl;\n",
" 0 0 0 5.000 90.000 100.000 \n",
"\n",
"RESERVOIR vol_head Reservoir3\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 3 MM3 METER\n",
"# x_value; y_value;\n",
"0.0000000000 90.0000000000 \n",
"5.0000000000 100.0000000000 \n",
"6.0000000000 101.0000000000 \n",
"\n",
"RESERVOIR flow_descr Reservoir3\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 2 METER M3/S\n",
"# x_value; y_value;\n",
"100.0000000000 0.0000000000 \n",
"101.0000000000 1000.0000000000 \n",
"\n",
"RESERVOIR endpoint_desc Reservoir3\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 1 MM3 NOK/MWH\n",
"# x_value; y_value;\n",
"0.0000000000 31.7000000000 \n",
"\n",
"RESERVOIR inflow Reservoir3\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 M3/S 7 \n",
"# Time; f(t);\n",
"20180227000000000 200.00000000000000000 \n",
"\n",
"PLANT attributes Plant1 \n",
"#Id;Water_course;Type;Future_use;Prod_area;Num_gen;Num_pump;\n",
" 0 0 6 0 0 1 0 \n",
"#Num_main_seg;Num_penstock;Time_delay;Read_prod_factor;Outlet_line;\n",
" 1 1 0 0.000000 0.000000 \n",
"0.000200 \n",
"0.000100 \n",
"\n",
"GENERATOR attributes Plant1 1 \n",
"#Id Type Penstock Nom_prod Min_prod Max_prod Start_cost \n",
" 0 7 1 100.00 0.10 100.00 0.00 \n",
"\n",
"GENERATOR gen_eff_curve Plant1 1 \n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 0.00 2 MW %\n",
"# x_value; y_value;\n",
"0.0000000000 95.0000000000 \n",
"100.0000000000 98.0000000000 \n",
"\n",
"GENERATOR turb_eff_curves Plant1 1 \n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 90.00 3 M3/S %\n",
"# x_value; y_value;\n",
"1.0000000000 80.0000000000 \n",
"90.0000000000 95.0000000000 \n",
"100.0000000000 90.0000000000 \n",
"\n",
"GENERATOR turb_eff_curves Plant1 1 \n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
" 0 0 100.00 3 M3/S %\n",
"# x_value; y_value;\n",
"1.0000000000 82.0000000000 \n",
"90.0000000000 98.0000000000 \n",
"100.0000000000 92.0000000000 \n",
"\n",
"#Initial reservoir volumes;\n",
"STARTRES 3 MM3 \n",
"#Name; Volume (Mm3);\n",
"Reservoir1 1.5000 \n",
"Reservoir2 1.5000 \n",
"Reservoir3 3.5000 \n",
"\n",
"MULTI_MARKET price_buy 1 0\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 NOK/MWH 7 \n",
"# Time; f(t);\n",
"20180227000000000 40.01\n",
"\n",
"MULTI_MARKET price_sale 1 0\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 NOK/MWH 7 \n",
"# Time; f(t);\n",
"20180227000000000 39.99\n",
"\n",
"MULTI_MARKET max_buy 1 0\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 MW 7 \n",
"# Time; f(t);\n",
"20180227000000000 9999\n",
"\n",
"MULTI_MARKET max_sale 1 0\n",
"#Id;Number;Start_Time;Time_unit;Period;Data_type;Y_unit;Pts;\n",
" 0 0 20180227000000000 HOUR 0 -1 MW 7 \n",
"# Time; f(t);\n",
"20180227000000000 9999\n",
"\n",
"TUNNEL attributes Tunnel1\n",
"# loss_factor start_height end_height diameter length\n",
"0.00016 90 90 3 2022\n",
" \n",
"TUNNEL attributes Tunnel2\n",
"# loss_factor start_height end_height diameter length\n",
"0.00015 90 90 3 2022\n",
" \n",
"TUNNEL attributes Tunnel3\n",
"# loss_factor start_height end_height diameter length\n",
"0.00030 90 90 3 2022\n",
"\n",
"#Write connection data for the hydro power system\n",
"#; From_type/To_type; From_name; To_name;\n",
"CONNECT RESERVOIR/TUNNEL Reservoir1 Tunnel1\n",
"CONNECT TUNNEL/RESERVOIR Tunnel1 Reservoir2\n",
"CONNECT RESERVOIR/TUNNEL Reservoir2 Tunnel2 \n",
"CONNECT TUNNEL/RESERVOIR Tunnel2 Reservoir3\n",
"CONNECT RESERVOIR/TUNNEL Reservoir3 Tunnel3 \n",
"CONNECT TUNNEL/PLANT Tunnel3 Plant1\n",
"\n",
"\n"
]
}
],
"source": [
"with open('tunnel_model.ascii', 'r') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"id": "3f72a214",
"metadata": {
"Collapsed": "false"
},
"source": [
"(tunnel-gate-ascii)=\n",
"## tunnel_gate.ascii "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b91f8232",
"metadata": {
"Collapsed": "false",
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TUNNEL gate_positions Tunnel2\n",
"#Id;Number;Reference;Pts;X_unit;Y_unit\n",
"10600 0 0.000 4 NO_UNIT PERCENT\n",
"# x_value; y_value;\n",
"0 0.0\n",
"1 1.0\n",
"\n",
"TUNNEL continuous_gate Tunnel2\n",
"1\n"
]
}
],
"source": [
"with open('tunnel_gate.ascii', 'r') as f:\n",
" print(f.read())"
]
}
],
"metadata": {
"jupytext": {
"text_representation": {
"extension": ".md",
"format_name": "myst",
"format_version": 0.13,
"jupytext_version": "1.13.8"
}
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
},
"source_map": [
14,
25,
42,
54,
58,
75,
79,
103,
107,
112,
120,
125,
133,
138,
146,
151,
159,
164,
172,
177
]
},
"nbformat": 4,
"nbformat_minor": 5
}