{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nExample using simulate_to_threshold with vectorized states. In this example we are using the thrown_object model to simulate multiple thrown objects\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from prog_models.models.thrown_object import ThrownObject\nfrom numpy import array, all\n\ndef run_example():\n # Step 1: Setup object\n m = ThrownObject()\n def future_load(t, x=None):\n return {} # No load for thrown objects\n\n # Step 2: Setup vectorized initial state\n # For this example we are saying there are 4 throwers of various strengths and heights\n first_state = {\n 'x': array([1.75, 1.8, 1.85, 1.9]),\n 'v': array([35, 39, 22, 47])\n }\n\n # Step 3: Simulate to threshold\n # Here we are simulating till impact using the first state defined above\n (times, inputs, states, outputs, event_states) = m.simulate_to_threshold(future_load, x = first_state, threshold_keys=['impact'], print = True, dt=0.1, save_freq=2)\n\n # Now lets do the same thing but only stop when all hit the ground\n def thresholds_met_eqn(thresholds_met):\n return all(thresholds_met['impact']) # Stop when all impact ground\n\n simulated_results = m.simulate_to_threshold(future_load, x = first_state, thresholds_met_eqn=thresholds_met_eqn, print = True, dt=0.1, save_freq=2)\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 }