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.
Notice the diffusing pulse "bouncing" off the left wall after total time 30.
Then the system is left undisturbed, and followed to equilibrium.
LAST_REVISED = "May 2, 2025"
LIFE123_VERSION = "1.0.0rc3" # Library version this experiment is based on
#import set_path # Using MyBinder? Uncomment this before running the next cell!
#import sys
#sys.path.append("C:/some_path/my_env_or_install") # CHANGE to the folder containing your venv or libraries installation!
# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path
from life123 import BioSim1D, ChemData, check_version
check_version(LIFE123_VERSION)
OK
chem_data = ChemData(diffusion_rates=0.1)
bio = BioSim1D(n_bins=10, chem_data=chem_data)
bio.set_uniform_concentration(chem_index=0, conc=0.)
bio.inject_conc_to_bin(chem_index=0, bin_address=2, delta_conc=10.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 10 bins and 1 chemical species:
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | Bin 3 | Bin 4 | Bin 5 | Bin 6 | Bin 7 | Bin 8 | Bin 9 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Chemical 1 | 0.1 | 0.0 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
print("\n\nSTARTING on SHORTER time scales. Dtime=10, with time steps of 0.1 ...")
STARTING on SHORTER time scales. Dtime=10, with time steps of 0.1 ...
for i in range(10):
delta_time = 10.
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
print(f"\nAfter Delta time {delta_time}. ({status['steps']} steps taken):")
bio.describe_state(concise=True)
After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 10: [[1.22598070e+00 2.22414009e+00 3.08221111e+00 2.15823525e+00 9.37782076e-01 2.88503658e-01 6.79378836e-02 1.28711509e-02 2.03304706e-03 3.05037621e-04]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 20: [[1.79154498 2.04604996 2.15752876 1.81408657 1.18572897 0.61493163 0.26031377 0.09234937 0.02835038 0.00911562]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 30: [[1.908894 1.93254508 1.86205856 1.60230147 1.1912129 0.75904212 0.41665574 0.19951697 0.08641213 0.04136102]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 40: [[1.89162641 1.84625985 1.72030668 1.48693078 1.1664388 0.82118645 0.51779486 0.29499154 0.15846579 0.09599884]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 50: [[1.83433746 1.76930884 1.63070397 1.41626323 1.14422761 0.85269498 0.58491221 0.37309998 0.2318666 0.16258513]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 60: [[1.76697624 1.69877596 1.56309588 1.36661912 1.12701103 0.87222369 0.63367319 0.43785006 0.30151635 0.23225847]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 70: [[1.69980096 1.63420894 1.50697719 1.32775575 1.11331789 0.8864918 0.67231694 0.49325804 0.36586375 0.30000873]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 80: [[1.63637931 1.57533401 1.45817295 1.29515888 1.10189171 0.89806096 0.7048592 0.54188555 0.42468407 0.36357336]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 90: [[1.57781285 1.52179206 1.41478512 1.26674457 1.09200065 0.90798758 0.73325992 0.58522943 0.47821243 0.42217538]] After Delta time 10.0. (100 steps taken): SYSTEM STATE at Time t = 100: [[1.5242553 1.47317189 1.37581121 1.2414767 1.08324636 0.91675072 0.75852442 0.6241924 0.52682923 0.47574177]]
Notice the diffusing pulse "bounces" off the left wall after total time 30:
the concentration at cell 0 increases from t=0 to 30, and then it's coming down by t=40
print("\n\nREPEATING to LONGER time scales. Dtime=100, again with time steps of 0.1 ...")
# Reset the concentrations
bio.set_uniform_concentration(chem_index=0, conc=0.)
bio.inject_conc_to_bin(chem_index=0, bin_address=2, delta_conc=10.)
#total_time = 0.
for i in range(20):
delta_time = 100.
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
print(f"\nAfter Delta time {delta_time}. ({status['steps']} steps taken):")
bio.describe_state(concise=True)
REPEATING to LONGER time scales. Dtime=100, again with time steps of 0.1 ... After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 200: [[1.5242553 1.47317189 1.37581121 1.2414767 1.08324636 0.91675072 0.75852442 0.6241924 0.52682923 0.47574177]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 300: [[1.19700758 1.17772317 1.14104198 1.09055457 1.03120299 0.96879701 0.90944543 0.85895802 0.82227683 0.80299242]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 400: [[1.07398731 1.06674491 1.05296906 1.03400823 1.01171844 0.98828156 0.96599177 0.94703094 0.93325509 0.92601269]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 500: [[1.02778634 1.02506642 1.01989282 1.01277198 1.00440092 0.99559908 0.98722802 0.98010718 0.97493358 0.97221366]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 600: [[1.01043531 1.00941383 1.00747086 1.00479659 1.00165279 0.99834721 0.99520341 0.99252914 0.99058617 0.98956469]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 700: [[1.00391904 1.00353542 1.00280572 1.00180138 1.00062071 0.99937929 0.99819862 0.99719428 0.99646458 0.99608096]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 800: [[1.00147182 1.00132774 1.0010537 1.00067652 1.00023311 0.99976689 0.99932348 0.9989463 0.99867226 0.99852818]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 900: [[1.00055275 1.00049864 1.00039572 1.00025407 1.00008755 0.99991245 0.99974593 0.99960428 0.99950136 0.99944725]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,000: [[1.00020759 1.00018727 1.00014862 1.00009542 1.00003288 0.99996712 0.99990458 0.99985138 0.99981273 0.99979241]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,100: [[1.00007796 1.00007033 1.00005581 1.00003583 1.00001235 0.99998765 0.99996417 0.99994419 0.99992967 0.99992204]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,200: [[1.00002928 1.00002641 1.00002096 1.00001346 1.00000464 0.99999536 0.99998654 0.99997904 0.99997359 0.99997072]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,300: [[1.000011 1.00000992 1.00000787 1.00000505 1.00000174 0.99999826 0.99999495 0.99999213 0.99999008 0.999989 ]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,400: [[1.00000413 1.00000373 1.00000296 1.0000019 1.00000065 0.99999935 0.9999981 0.99999704 0.99999627 0.99999587]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,500: [[1.00000155 1.0000014 1.00000111 1.00000071 1.00000025 0.99999975 0.99999929 0.99999889 0.9999986 0.99999845]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,600: [[1.00000058 1.00000053 1.00000042 1.00000027 1.00000009 0.99999991 0.99999973 0.99999958 0.99999947 0.99999942]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,700: [[1.00000022 1.0000002 1.00000016 1.0000001 1.00000003 0.99999997 0.9999999 0.99999984 0.9999998 0.99999978]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,800: [[1.00000008 1.00000007 1.00000006 1.00000004 1.00000001 0.99999999 0.99999996 0.99999994 0.99999993 0.99999992]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 1,900: [[1.00000003 1.00000003 1.00000002 1.00000001 1. 1. 0.99999999 0.99999998 0.99999997 0.99999997]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 2,000: [[1.00000001 1.00000001 1.00000001 1.00000001 1. 1. 0.99999999 0.99999999 0.99999999 0.99999999]] After Delta time 100.0. (1000 steps taken): SYSTEM STATE at Time t = 2,100: [[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]