{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nExample of a centrifugal pump being simulated until threshold is met. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from progpy.models import CentrifugalPump\n\ndef run_example(): \n # Step 1: Setup Pump\n pump = CentrifugalPump(process_noise= 0)\n pump.parameters['x0']['wA'] = 0.01 # Set Wear Rate\n\n # Step 2: Setup Future Loading\n cycle_time = 3600\n def future_loading(t, x=None):\n t = t % cycle_time\n if t < cycle_time/2.0:\n V = 471.2389\n elif t < cycle_time/2 + 100:\n V = 471.2389 + (t-cycle_time/2)\n elif t < cycle_time - 100:\n V = 571.2389\n else:\n V = 471.2398 - (t-cycle_time)\n\n return pump.InputContainer({\n 'Tamb': 290,\n 'V': V,\n 'pdisch': 928654, \n 'psuc': 239179, \n 'wsync': V * 0.8\n })\n\n # Step 3: Sim\n first_output = pump.output(pump.initialize(future_loading(0),{}))\n config = {\n 'horizon': 1e5,\n 'save_freq': 1e3,\n 'print': True\n }\n simulated_results = pump.simulate_to_threshold(future_loading, first_output, **config)\n\n # Step 4: Plot Results\n from progpy.visualize import plot_timeseries\n plot_timeseries(simulated_results.times, simulated_results.inputs, options={'compact': False, 'title': 'Inputs',\n 'xlabel': 'time', 'ylabel':{lbl: lbl for lbl in pump.inputs}})\n plot_timeseries(simulated_results.times, simulated_results.states, options={'compact': False, 'title': 'States', 'xlabel': 'time', 'ylabel': ''})\n plot_timeseries(simulated_results.times, simulated_results.outputs, options={'compact': False, 'title': 'Outputs', 'xlabel': 'time', 'ylabel': ''})\n plot_timeseries(simulated_results.times, simulated_results.event_states, options={'compact': False, 'title': 'Events', 'xlabel': 'time', 'ylabel': ''})\n thresholds_met = [pump.threshold_met(x) for x in simulated_results.states]\n plot_timeseries(simulated_results.times, thresholds_met, options={'compact': True, 'title': 'Events', 'xlabel': 'time', 'ylabel': ''}, legend = {'display': True})\n\n import matplotlib.pyplot as plt \n plt.show()\n\n# This allows the module to be executed directly \nif __name__ == '__main__':\n run_example()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 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.9" } }, "nbformat": 4, "nbformat_minor": 0 }