{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Abrupt Leakage Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, HTML\n", "display(HTML('\"Open'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example demonstrates how add an abrupt leakage to a scenario -- more information can be found in the [documentation](https://epyt-flow.readthedocs.io/en/stable/tut.events.html#leakages)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install epyt-flow --quiet" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from epyt_flow.data.networks import load_hanoi\n", "from epyt_flow.simulation import ScenarioSimulator, AbruptLeakage, EpanetConstants\n", "from epyt_flow.utils import to_seconds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the [Hanoi network](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.html#epyt_flow.data.networks.load_hanoi) with a default sensor placement:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hanoi_network_config = load_hanoi(include_default_sensor_placement=True, verbose=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new simulation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = ScenarioSimulator(scenario_config=hanoi_network_config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set simulation duration to 7 days:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_general_parameters(simulation_duration=to_seconds(days=7))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that leakages are only modeled for two flow units. We therefore change the flow units to cubic meter per hour by calling [set_general_parameters()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.set_general_parameters) -- could also be done when loading the network!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_general_parameters(flow_units_id=EpanetConstants.EN_CMH)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add an abrupt leakage at link/pipe \"14\" -- the leakage is active for 18 hours and starts at 10 hours after simulation begin -- recall that the time arguments are seconds!\n", "\n", "We create an abrupt leakage by creating an instance of the [AbruptLeakage](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.events.html#epyt_flow.simulation.events.leakages.AbruptLeakage) class and add the leakage to the scenario by calling [add_leakage()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.add_leakage):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "leak = AbruptLeakage(link_id=\"14\", diameter=0.1,\n", " start_time=to_seconds(hours=10),\n", " end_time=to_seconds(hours=28))\n", "\n", "sim.add_leakage(leak)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the entire simulation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data = sim.run_simulation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Retrieve and show pressure at node \"13\" over time:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data.plot_pressures(sensor_locations=['13'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the simulator!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "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.9.20" } }, "nbformat": 4, "nbformat_minor": 2 }