{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chlorine Injection 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 to add a chlorine injection to a scenario simulation." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install epyt-flow --quiet" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy\n", "from epyt_flow.data.networks import load_hanoi\n", "from epyt_flow.simulation import ScenarioSimulator, EpanetConstants\n", "from epyt_flow.utils import to_seconds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the Hanoi network by calling [load_hanoi()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.html#epyt_flow.data.networks.load_hanoi):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network_config = load_hanoi(verbose=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new simulation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = ScenarioSimulator(scenario_config=network_config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set simulation duration to 12 hours:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_general_parameters(simulation_duration=to_seconds(hours=12))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Enable chemical analysis by calling [enable_chemical_analysis()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.enable_chemical_analysis):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.enable_chemical_analysis()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the concentration at node \"1\" (reservoir) to 1.0 for all time steps by calling [add_quality_source()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.add_quality_source) -- this creates a new source of the chemical being analyzed:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.add_quality_source(node_id=\"1\",\n", " pattern=numpy.array([1.]),\n", " source_type=EpanetConstants.EN_CONCEN)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Places quality sensors at all nodes -- i.e. measuring the chemical concentration at all nodes:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_node_quality_sensors(sensor_locations=sim.sensor_config.nodes)" ] }, { "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 how the simulated chemical concentrations at the first 5 nodes -- note the transport delay!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data.plot_nodes_quality()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the simulation!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Close simulator\n", "sim.close()" ] } ], "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 }