{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pump State Events 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 pump state events to a scenario simulation -- more information about actuator events can be found in the [documentation](https://epyt-flow.readthedocs.io/en/stable/tut.events.html#actuator-events)." ] }, { "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_net1\n", "from epyt_flow.simulation import ScenarioSimulator\n", "from epyt_flow.utils import to_seconds\n", "from epyt_flow.simulation.events import PumpStateEvent, ActuatorConstants" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create new simulation based on [Net1](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.data.html#epyt_flow.data.networks.load_net1):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = ScenarioSimulator(scenario_config=load_net1(verbose=False))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set simulation duration to 40 hours:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_general_parameters(simulation_duration=to_seconds(hours=40))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Monitor states of tank \"2\" and pump \"9\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.set_tank_sensors(sensor_locations=[\"2\"])\n", "sim.set_pump_state_sensors(sensor_locations=[\"9\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remove all existing controls:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.remove_all_simple_controls()\n", "sim.remove_all_complex_controls()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Deactivate pump \"9\" at 14h after simulation start by creating an actuator event [PumpStateEvent](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.events.html#epyt_flow.simulation.events.actuator_events.PumpStateEvent) and adding to the simulation by calling [add_actuator_event()](https://epyt-flow.readthedocs.io/en/stable/epyt_flow.simulation.html#epyt_flow.simulation.scenario_simulator.ScenarioSimulator.add_actuator_event):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.add_actuator_event(PumpStateEvent(pump_id=\"9\",\n", " pump_state=ActuatorConstants.EN_CLOSED,\n", " time=to_seconds(hours=14)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Re-activate pump \"9\" at 25h after simulation start:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.add_actuator_event(PumpStateEvent(pump_id=\"9\",\n", " pump_state=ActuatorConstants.EN_OPEN,\n", " time=to_seconds(hours=25)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the entire simulation and show sensor readings over time:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scada_data = sim.run_simulation()\n", "\n", "scada_data.plot_pumps_state()\n", "scada_data.plot_tanks_water_volume()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not forget to close the simulation!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "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 }