{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nExample of a battery being simulated for a set period of time and then till threshold is met.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from progpy.models import BatteryCircuit as Battery\n# VVV Uncomment this to use Electro Chemistry Model VVV\n# from progpy.models import BatteryElectroChem as Battery\n\ndef run_example(): \n # Step 1: Create a model object\n batt = Battery()\n\n # Step 2: Define future loading function \n def future_loading(t, x=None):\n # Variable (piece-wise) future loading scheme \n if (t < 600):\n i = 2\n elif (t < 900):\n i = 1\n elif (t < 1800):\n i = 4\n elif (t < 3000):\n i = 2 \n else:\n i = 3\n return batt.InputContainer({'i': i})\n # simulate for 200 seconds\n print('\\n\\n------------------------------------------------')\n print('Simulating for 200 seconds\\n\\n')\n simulated_results = batt.simulate_to(200, future_loading, print = True, progress = True)\n\n # Simulate to threshold\n print('\\n\\n------------------------------------------------')\n print('Simulating to threshold\\n\\n')\n options = {\n 'save_freq': 100, # Frequency at which results are saved\n 'dt': 2, # Timestep\n 'print': True,\n 'progress': True\n }\n simulated_results = batt.simulate_to_threshold(future_loading, **options)\n\n # Alternately, you can set a max step size and allow step size to be adjusted automatically\n options['dt'] = ('auto', 2) # set step size automatically, with a max of 2 seconds\n options['save_freq'] = 201 # Save every 201 seconds\n options['save_pts'] = [250, 772, 1023] # Special points we sould like to see reported\n simulated_results = batt.simulate_to_threshold(future_loading, **options)\n # Note that even though the step size is 2, the odd points in the save frequency are met perfectly, dt is adjusted automatically to capture the save points\n\n # You can also change the integration method. For example:\n options['integration_method'] = 'rk4' # Using Runge-Kutta 4th order\n simulated_results_rk4 = batt.simulate_to_threshold(future_loading, **options)\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 }