{ "cells": [ { "cell_type": "markdown", "id": "0f1fbed2", "metadata": {}, "source": [ "## Exploring reaching equilibrium, first on a shorter timescale and then a longer one \n", "### (but both with identical time steps.)\n", "\n", "The system starts out with a \"concentration pulse\" in bin 2 (the 3rd bin from the left) - i.e. that bin is initially the only one with a non-zero concentration of the only chemical species.\n", "\n", "Notice the diffusing pulse \"bouncing\" off the left wall after total time 30.\n", "\n", "Then the system is left undisturbed, and followed to equilibrium.\n", "\n", "*NO log file.*\n", "\n", "LAST REVISED: July 14, 2023" ] }, { "cell_type": "code", "execution_count": 1, "id": "c62d121f-74e7-4951-b2be-2353d3710224", "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": "b72ad9b1", "metadata": {}, "outputs": [], "source": [ "from src.modules.chemicals.chem_data import ChemData as chem\n", "from src.life_1D.bio_sim_1d import BioSim1D" ] }, { "cell_type": "code", "execution_count": 3, "id": "0cb73921", "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", "bio.set_uniform_concentration(species_index=0, conc=0.)\n", "bio.inject_conc_to_bin(species_index=0, bin_address=2, delta_conc=10.)\n", "\n", "bio.describe_state()" ] }, { "cell_type": "code", "execution_count": 4, "id": "deb3e562", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "STARTING on SHORTER time scales. Dtime=10, with time steps of 0.1 ...\n" ] } ], "source": [ "print(\"\\n\\nSTARTING on SHORTER time scales. Dtime=10, with time steps of 0.1 ...\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "7b240389", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 10:\n", "[[1.22598070e+00 2.22414009e+00 3.08221111e+00 2.15823525e+00\n", " 9.37782076e-01 2.88503658e-01 6.79378836e-02 1.28711509e-02\n", " 2.03304706e-03 3.05037621e-04]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 20:\n", "[[1.79154498 2.04604996 2.15752876 1.81408657 1.18572897 0.61493163\n", " 0.26031377 0.09234937 0.02835038 0.00911562]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 30:\n", "[[1.908894 1.93254508 1.86205856 1.60230147 1.1912129 0.75904212\n", " 0.41665574 0.19951697 0.08641213 0.04136102]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 40:\n", "[[1.89162641 1.84625985 1.72030668 1.48693078 1.1664388 0.82118645\n", " 0.51779486 0.29499154 0.15846579 0.09599884]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 50:\n", "[[1.83433746 1.76930884 1.63070397 1.41626323 1.14422761 0.85269498\n", " 0.58491221 0.37309998 0.2318666 0.16258513]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 60:\n", "[[1.76697624 1.69877596 1.56309588 1.36661912 1.12701103 0.87222369\n", " 0.63367319 0.43785006 0.30151635 0.23225847]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 70:\n", "[[1.69980096 1.63420894 1.50697719 1.32775575 1.11331789 0.8864918\n", " 0.67231694 0.49325804 0.36586375 0.30000873]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 80:\n", "[[1.63637931 1.57533401 1.45817295 1.29515888 1.10189171 0.89806096\n", " 0.7048592 0.54188555 0.42468407 0.36357336]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 90:\n", "[[1.57781285 1.52179206 1.41478512 1.26674457 1.09200065 0.90798758\n", " 0.73325992 0.58522943 0.47821243 0.42217538]]\n", "\n", "After Delta time 10.0. (100 steps taken):\n", "SYSTEM STATE at Time t = 100:\n", "[[1.5242553 1.47317189 1.37581121 1.2414767 1.08324636 0.91675072\n", " 0.75852442 0.6241924 0.52682923 0.47574177]]\n" ] } ], "source": [ "for i in range(10):\n", " delta_time = 10.\n", " status = bio.diffuse(total_duration=delta_time, time_step=0.1)\n", " print(f\"\\nAfter Delta time {delta_time}. ({status['steps']} steps taken):\")\n", " bio.describe_state(concise=True)" ] }, { "cell_type": "markdown", "id": "9195602b", "metadata": {}, "source": [ "*Notice the diffusing pulse \"bounces\" off the left wall after total time 30:* \n", "the concentration at cell 0 increases from t=0 to 30, and then it's coming down by t=40" ] }, { "cell_type": "code", "execution_count": 6, "id": "c653235c", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "REPEATING to LONGER time scales. Dtime=100, again with time steps of 0.1 ...\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 200:\n", "[[1.5242553 1.47317189 1.37581121 1.2414767 1.08324636 0.91675072\n", " 0.75852442 0.6241924 0.52682923 0.47574177]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 300:\n", "[[1.19700758 1.17772317 1.14104198 1.09055457 1.03120299 0.96879701\n", " 0.90944543 0.85895802 0.82227683 0.80299242]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 400:\n", "[[1.07398731 1.06674491 1.05296906 1.03400823 1.01171844 0.98828156\n", " 0.96599177 0.94703094 0.93325509 0.92601269]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 500:\n", "[[1.02778634 1.02506642 1.01989282 1.01277198 1.00440092 0.99559908\n", " 0.98722802 0.98010718 0.97493358 0.97221366]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 600:\n", "[[1.01043531 1.00941383 1.00747086 1.00479659 1.00165279 0.99834721\n", " 0.99520341 0.99252914 0.99058617 0.98956469]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 700:\n", "[[1.00391904 1.00353542 1.00280572 1.00180138 1.00062071 0.99937929\n", " 0.99819862 0.99719428 0.99646458 0.99608096]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 800:\n", "[[1.00147182 1.00132774 1.0010537 1.00067652 1.00023311 0.99976689\n", " 0.99932348 0.9989463 0.99867226 0.99852818]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 900:\n", "[[1.00055275 1.00049864 1.00039572 1.00025407 1.00008755 0.99991245\n", " 0.99974593 0.99960428 0.99950136 0.99944725]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,000:\n", "[[1.00020759 1.00018727 1.00014862 1.00009542 1.00003288 0.99996712\n", " 0.99990458 0.99985138 0.99981273 0.99979241]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,100:\n", "[[1.00007796 1.00007033 1.00005581 1.00003583 1.00001235 0.99998765\n", " 0.99996417 0.99994419 0.99992967 0.99992204]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,200:\n", "[[1.00002928 1.00002641 1.00002096 1.00001346 1.00000464 0.99999536\n", " 0.99998654 0.99997904 0.99997359 0.99997072]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,300:\n", "[[1.000011 1.00000992 1.00000787 1.00000505 1.00000174 0.99999826\n", " 0.99999495 0.99999213 0.99999008 0.999989 ]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,400:\n", "[[1.00000413 1.00000373 1.00000296 1.0000019 1.00000065 0.99999935\n", " 0.9999981 0.99999704 0.99999627 0.99999587]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,500:\n", "[[1.00000155 1.0000014 1.00000111 1.00000071 1.00000025 0.99999975\n", " 0.99999929 0.99999889 0.9999986 0.99999845]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,600:\n", "[[1.00000058 1.00000053 1.00000042 1.00000027 1.00000009 0.99999991\n", " 0.99999973 0.99999958 0.99999947 0.99999942]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,700:\n", "[[1.00000022 1.0000002 1.00000016 1.0000001 1.00000003 0.99999997\n", " 0.9999999 0.99999984 0.9999998 0.99999978]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,800:\n", "[[1.00000008 1.00000007 1.00000006 1.00000004 1.00000001 0.99999999\n", " 0.99999996 0.99999994 0.99999993 0.99999992]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 1,900:\n", "[[1.00000003 1.00000003 1.00000002 1.00000001 1. 1.\n", " 0.99999999 0.99999998 0.99999997 0.99999997]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 2,000:\n", "[[1.00000001 1.00000001 1.00000001 1.00000001 1. 1.\n", " 0.99999999 0.99999999 0.99999999 0.99999999]]\n", "\n", "After Delta time 100.0. (1000 steps taken):\n", "SYSTEM STATE at Time t = 2,100:\n", "[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]\n" ] } ], "source": [ "print(\"\\n\\nREPEATING to LONGER time scales. Dtime=100, again with time steps of 0.1 ...\")\n", "\n", "# Reset the concentrations\n", "bio.set_uniform_concentration(species_index=0, conc=0.)\n", "bio.inject_conc_to_bin(species_index=0, bin_address=2, delta_conc=10.)\n", "\n", "#total_time = 0.\n", "for i in range(20):\n", " delta_time = 100.\n", " status = bio.diffuse(total_duration=delta_time, time_step=0.1)\n", " print(f\"\\nAfter Delta time {delta_time}. ({status['steps']} steps taken):\")\n", " bio.describe_state(concise=True)" ] }, { "cell_type": "markdown", "id": "e724daca", "metadata": {}, "source": [ "## The system has now reached equilibrium" ] }, { "cell_type": "code", "execution_count": null, "id": "fce9b0d7", "metadata": {}, "outputs": [], "source": [] } ], "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 }