{ "cells": [ { "cell_type": "markdown", "id": "d31149d6-a2ab-45e8-a465-6428937e2086", "metadata": {}, "source": [ "### Exploring effect of Time Resolution on accuracy\n", "\n", "In the examples below, the _time advance_ always remains constant,\n", "but the _number of steps_ used to arrive there vary\n", "\n", "NO log file.\n", "\n", "LAST REVISED: June 23, 2024 (using v. 1.0 beta34.1)" ] }, { "cell_type": "code", "execution_count": 1, "id": "f594d956", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added 'D:\\Docs\\- MY CODE\\BioSimulations\\life123-Win7' to sys.path\n" ] } ], "source": [ "import set_path # Importing this module will add the project's home directory to sys.path" ] }, { "cell_type": "code", "execution_count": 2, "id": "5755befb-8156-43cc-bef9-c742a3498e6e", "metadata": {}, "outputs": [], "source": [ "from life123 import ChemData as chem\n", "from life123 import BioSim1D" ] }, { "cell_type": "code", "execution_count": 3, "id": "baf827af-6cad-4ffb-a7a8-af415113345d", "metadata": {}, "outputs": [], "source": [ "def set_initial_condition():\n", " # Set or reset the initial concentrations\n", " bio.set_uniform_concentration(species_index=0, conc=0.)\n", " bio.inject_conc_to_bin(bin_address=2, species_index=0, delta_conc=10.)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e20f3dd6-f5b3-47b7-8846-122ae250640e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM STATE at Time t = 0:\n", "10 bins and 1 species:\n", " Species 0 (Chemical 1). Diff rate: 0.1. Conc: [ 0. 0. 10. 0. 0. 0. 0. 0. 0. 0.]\n" ] } ], "source": [ "chem_data = chem(diffusion_rates=[0.1])\n", "bio = BioSim1D(n_bins=10, chem_data=chem_data)\n", "\n", "set_initial_condition()\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 5, "id": "7dc6d6a4-a607-4660-87b5-7612501f0f00", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 8...\n", " Performing diffusion step 9...\n", "\n", "System after Delta time 33.3, at end of 10 steps of size 3.3299999999999996:\n", "SYSTEM STATE at Time t = 33.3:\n", "[[1.94849832 1.89701268 1.76252648 1.51861039 1.18134438 0.81185766\n", " 0.48398585 0.24587699 0.10558355 0.04470372]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 18...\n", " Performing diffusion step 19...\n", "\n", "System after Delta time 33.3, at end of 20 steps of size 1.6649999999999998:\n", "SYSTEM STATE at Time t = 66.6:\n", "[[1.93083096 1.89918952 1.78309085 1.53809527 1.18379901 0.79887357\n", " 0.46852318 0.23832707 0.10742893 0.05184163]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 28...\n", " Performing diffusion step 29...\n", "\n", "System after Delta time 33.3, at end of 30 steps of size 1.1099999999999999:\n", "SYSTEM STATE at Time t = 99.9:\n", "[[1.92418469 1.90022582 1.79079709 1.54473636 1.18398957 0.79411327\n", " 0.46362705 0.23627042 0.10813759 0.05391814]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 48...\n", " Performing diffusion step 49...\n", "\n", "System after Delta time 33.3, at end of 50 steps of size 0.6659999999999999:\n", "SYSTEM STATE at Time t = 133.2:\n", "[[1.91860809 1.90117398 1.79725968 1.55006867 1.18390667 0.79018989\n", " 0.45982272 0.23476444 0.10871741 0.05548847]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 98...\n", " Performing diffusion step 99...\n", "\n", "System after Delta time 33.3, at end of 100 steps of size 0.33299999999999996:\n", "SYSTEM STATE at Time t = 166.5:\n", "[[1.91428037 1.90195278 1.80227809 1.55407026 1.18370653 0.78719167\n", " 0.45703829 0.2337084 0.10915577 0.05661783]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 998...\n", " Performing diffusion step 999...\n", "\n", "System after Delta time 33.3, at end of 1000 steps of size 0.033299999999999996:\n", "SYSTEM STATE at Time t = 199.8:\n", "[[1.9102833 1.90270095 1.80691952 1.55766816 1.18342551 0.78445907\n", " 0.45458379 0.23280741 0.10955101 0.05760128]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 9998...\n", " Performing diffusion step 9999...\n", "\n", "System after Delta time 33.3, at end of 10000 steps of size 0.0033299999999999996:\n", "SYSTEM STATE at Time t = 233.1:\n", "[[1.90987842 1.90277812 1.80739016 1.5580276 1.18339217 0.78418423\n", " 0.45434105 0.23271976 0.10959052 0.05769798]]\n", "\n", " Performing diffusion step 0...\n", " Performing diffusion step 1...\n", " ...\n", " Performing diffusion step 99998...\n", " Performing diffusion step 99999...\n", "\n", "System after Delta time 33.3, at end of 100000 steps of size 0.00033299999999999996:\n", "SYSTEM STATE at Time t = 266.4:\n", "[[1.90983788 1.90278586 1.80743729 1.55806354 1.18338878 0.78415673\n", " 0.4543168 0.23271101 0.10959447 0.05770763]]\n", "\n" ] }, { "data": { "text/plain": [ "{'steps': 100000}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_final = 33.3\n", "\n", "bio.debug = True\n", "\n", "bio.diffuse(total_duration=t_final, n_steps=10)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=20)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=30)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=50)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=100)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=1000)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=10000)\n", "\n", "set_initial_condition() # Reset the concentrations\n", "bio.diffuse(total_duration=t_final, n_steps=100000)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10" } }, "nbformat": 4, "nbformat_minor": 5 }