{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nExample of a pneumatic valve being simulated until threshold is met. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from progpy.models.pneumatic_valve import PneumaticValve\n\ndef run_example(): \n # Create a model object\n valv = PneumaticValve(process_noise= 0)\n\n # Define future loading function\n cycle_time = 20\n def future_loading(t, x=None):\n t = t % cycle_time\n if t < cycle_time/2:\n return valv.InputContainer({\n 'pL': 3.5e5,\n 'pR': 2.0e5,\n # Open Valve\n 'uTop': False,\n 'uBot': True\n })\n return valv.InputContainer({\n 'pL': 3.5e5,\n 'pR': 2.0e5,\n # Close Valve\n 'uTop': True,\n 'uBot': False\n })\n\n # Simulate to threshold\n print('\\n\\n------------------------------------------------')\n print('Simulating to threshold\\n\\n')\n # Configure options\n config = {\n 'dt': 0.01,\n 'horizon': 800,\n 'save_freq': 60,\n 'print': True,\n 'progress': True,\n }\n # Set wear parameter for spring to 1\n valv.parameters['x0']['wk'] = 1\n\n # Define first measured output. This is needed by the simulat_to_threshold method to initialize state\n first_output = valv.output(valv.initialize(future_loading(0)))\n # Simulate\n simulated_results = valv.simulate_to_threshold(future_loading, first_output, **config)\n\n # Simulate to threshold again but with a different wear mode\n print('\\n\\n------------------------------------------------')\n print('Simulating to threshold\\n\\n')\n # Configure options\n config = {\n 'dt': 0.01,\n 'horizon': 800,\n 'save_freq': 60,\n 'print': True,\n 'progress': True\n }\n # Reset wear parameter for spring to 0, set wear parameter for friction to 1\n valv.parameters['x0']['wk'] = 0\n valv.parameters['x0']['wr'] = 1\n\n # Define first measured output. This is needed by the simulat_to_threshold method to initialize state\n first_output = valv.output(valv.initialize(future_loading(0)))\n # Simulate\n simulated_results = valv.simulate_to_threshold(future_loading, first_output, **config)\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 }