Files
Python-DT_Slot_3/Ausgleichsbecken/Ausgleichsbecken_test_steady_state.ipynb
Georg ´Brantegger dc5bcfe7f8 fixed a coding mistake that lead to
a missbehavior in the time evolution of the
reservoir
2022-07-28 16:26:04 +02:00

199 lines
6.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from Ausgleichsbecken_class_file import Ausgleichsbecken_class\n",
"import matplotlib.pyplot as plt\n",
"\n",
"#importing pressure conversion function\n",
"import sys\n",
"import os\n",
"current = os.path.dirname(os.path.realpath('Main_Programm.ipynb'))\n",
"parent = os.path.dirname(current)\n",
"sys.path.append(parent)\n",
"from functions.pressure_conversion import pressure_conversion"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"L = 1000.\n",
"n = 10000 # number of pipe segments in discretization\n",
"c = 400. \n",
"dx = L/n # length of each pipe segment\n",
"dt = dx/c \n",
"\n",
"# # define constants\n",
"# initial_level = 10.1 # m\n",
"# initial_influx = 0.8 # m³/s\n",
"# conversion_pressure_unit = 'mWS'\n",
"\n",
"# area_base = 75. # m²\n",
"# area_outflux = (0.9/2)**2*np.pi # m²\n",
"# critical_level_low = 0. # m\n",
"# critical_level_high = 10. # m\n",
"# simulation_timestep = dt # s\n",
"\n",
"# # for while loop\n",
"# total_min_level = 0.01 # m\n",
"# total_max_time = 100 # s\n",
"\n",
"# nt = int(total_max_time//simulation_timestep)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# define constants\n",
"initial_level = 10.1 # m\n",
"initial_influx = 1. # m³/s\n",
"# initial_outflux = 1. # m³/s\n",
"# initial_pipeline_pressure = 10.\n",
"# initial_pressure_unit = 'mWS'\n",
"conversion_pressure_unit = 'mWS'\n",
"\n",
"area_base = 75. # m²\n",
"area_outflux = 2. # m²\n",
"critical_level_low = 0. # m\n",
"critical_level_high = 10. # m\n",
"simulation_timestep = dt # s\n",
"\n",
"# for while loop\n",
"total_min_level = 0.01 # m\n",
"total_max_time = 100 # s\n",
"\n",
"nt = int(total_max_time//simulation_timestep)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib qt\n",
"\n",
"V = Ausgleichsbecken_class(area_base,area_outflux,critical_level_low,critical_level_high,simulation_timestep)\n",
"# V.set_initial_level(initial_level) \n",
"# V.set_influx(initial_influx)\n",
"# V.set_outflux(initial_outflux)\n",
"# V.set_initial_pressure(pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 'Pa'),conversion_pressure_unit)\n",
"# V.pressure = converted_pressure\n",
"V.set_steady_state(initial_influx,initial_level,conversion_pressure_unit)\n",
"\n",
"time_vec = np.arange(0,nt+1,1)*simulation_timestep\n",
"outflux_vec = np.zeros_like(time_vec)\n",
"outflux_vec[0] = V.get_current_outflux()\n",
"level_vec = np.zeros_like(time_vec)\n",
"level_vec[0] = V.get_current_level()\n",
"pressure_vec = np.zeros_like(time_vec)\n",
"pressure_vec[0] = V.get_current_pressure()\n",
"\n",
"# pressure_vec = np.full_like(time_vec,converted_pressure)*((np.sin(time_vec)+1)*np.exp(-time_vec/50))\n",
" \n",
"i_max = -1\n",
"\n",
"for i in range(1,nt+1):\n",
" V.set_pressure(pressure_vec[i-1])\n",
" V.set_outflux(outflux_vec[i-1])\n",
" V.timestep_reservoir_evolution()\n",
" outflux_vec[i] = V.get_current_outflux()\n",
" level_vec[i] = V.get_current_level()\n",
" pressure_vec[i] = V.get_current_pressure()\n",
" if V.level < total_min_level:\n",
" i_max = i\n",
" break\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"\n",
"fig1, (ax1, ax2, ax3) = plt.subplots(3, 1)\n",
"fig1.set_figheight(10)\n",
"fig1.suptitle('Ausgleichsbecken')\n",
"\n",
"ax1.plot(time_vec[:i_max],level_vec[:i_max], label='Water level')\n",
"ax1.set_ylabel(r'$h$ ['+V.level_unit+']')\n",
"ax1.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax1.legend()\n",
"\n",
"ax2.plot(time_vec[:i_max],outflux_vec[:i_max], label='Outflux')\n",
"ax2.set_ylabel(r'$Q_{out}$ ['+V.flux_unit+']')\n",
"ax2.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax2.legend()\n",
"\n",
"ax3.plot(time_vec[:i_max],pressure_conversion(pressure_vec[:i_max],'Pa',conversion_pressure_unit), label='Pipeline pressure at reservoir')\n",
"ax3.set_ylabel(r'$p_{pipeline}$ ['+conversion_pressure_unit+']')\n",
"ax3.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax3.legend()\n",
"\n",
"\n",
"fig1.tight_layout() "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.1"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"V.get_current_level()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.13 ('DT_Slot_3')",
"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.8.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}