{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic Usage Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "hide_input": true }, "outputs": [], "source": [ "from IPython.display import display, HTML\n", "display(HTML('\"Open'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example demonstrates how to load an .inp file, retrieving some basic information, and running a hydraulic simulation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[EPANET-PLUS](https://github.com/WaterFutures/EPANET-PLUS) is available on [PyPI](https://pypi.org/project/epanet-plus/) and can be installed via `pip install epanet-plus`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install epanet-plus --quiet" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from epanet_plus import EPyT, EpanetConstants\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load an .inp file in EPANET using the toolkit class [EPyT](https://epanet-plus.readthedocs.io/en/stable/epanet_plus.epanet_toolkit.html#epanet_plus.epanet_toolkit.EPyT):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "epanet_api = EPyT(\"net2-cl2.inp\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Listing all nodes and links:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"All nodes: {epanet_api.get_all_nodes_id()}\")\n", "print(f\"All links: {epanet_api.get_all_links_id()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Retrieving the simulation duration and hydraulic time step:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"Simulation duration in seconds: {epanet_api.get_simulation_duration()}\")\n", "print(f\"Hydraulic time step in seconds: {epanet_api.get_hydraulic_time_step()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Retrieving the demand model:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"Demand model: {epanet_api.get_demand_model()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run hydraulic simulation and plot pressure at each node (at every simulation step):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "epanet_api.openH()\n", "epanet_api.initH(EpanetConstants.EN_NOSAVE)\n", "\n", "tstep = 1\n", "r = []\n", "while tstep > 0:\n", " t = epanet_api.runH()\n", "\n", " r.append(epanet_api.getnodevalues(EpanetConstants.EN_PRESSURE))\n", "\n", " tstep = epanet_api.nextH()\n", "\n", "epanet_api.closeH()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "plt.plot(range(len(r)), r)\n", "plt.xlabel(\"Time steps\")\n", "plt.ylabel(\"Presssure (PSI)\")\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the EPANET by calling [close()](https://epanet-plus.readthedocs.io/en/stable/epanet_plus.epanet_toolkit.html#epanet_plus.epanet_toolkit.EPyT.close):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "epanet_api.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "epanetplus", "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.10.18" } }, "nbformat": 4, "nbformat_minor": 2 }