The system starts out with a pulse in bins near the left and the right endpoints
LAST_REVISED = "May 3, 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
# Initialize the system
chem_data = ChemData(names="A", diffusion_rates=0.1)
bio = BioSim1D(n_bins=9, chem_data=chem_data)
# Start out with a pulse in bins near the *left* and the *right* endpoints.
# A total of 20 "units of concentration" is injected
bio.inject_conc_to_bin(chem_label="A", bin_address=2, delta_conc=10.)
bio.inject_conc_to_bin(chem_label="A", bin_address=6, delta_conc=10.)
bio.describe_state()
SYSTEM STATE at Time t = 0: 9 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 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 0.1 | 0.0 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 10.0 | 0.0 | 0.0 |
bio.show_system_snapshot()
SYSTEM SNAPSHOT at time 0:
| A | |
|---|---|
| 0 | 0.0 |
| 1 | 0.0 |
| 2 | 10.0 |
| 3 | 0.0 |
| 4 | 0.0 |
| 5 | 0.0 |
| 6 | 10.0 |
| 7 | 0.0 |
| 8 | 0.0 |
# Visualize the system's initial state
bio.visualize_system(title_prefix="Diffusion")
# Show as heatmap
bio.system_heatmaps(title_prefix="Diffusion")
delta_time = 3.
for i in range(15):
status = bio.diffuse(total_duration=delta_time, time_step=0.1)
print(f"\nAfter Delta time {delta_time}. TOTAL TIME {bio.system_time} ({status['steps']} steps taken):")
bio.describe_state(concise=True)
bio.visualize_system(title_prefix="Diffusion", show=True)
bio.system_heatmaps(title_prefix="Diffusion", show=True)
After Delta time 3.0. TOTAL TIME 3.0000000000000013 (30 steps taken): SYSTEM STATE at Time t = 3: [[0.27757451 1.74303541 5.96050983 1.76527256 0.5072154 1.76527256 5.96050983 1.74303541 0.27757451]]
After Delta time 3.0. TOTAL TIME 5.999999999999995 (30 steps taken): SYSTEM STATE at Time t = 6: [[0.73152765 2.1834153 4.18877184 2.28238941 1.22779161 2.28238941 4.18877184 2.1834153 0.73152765]]
After Delta time 3.0. TOTAL TIME 8.999999999999984 (30 steps taken): SYSTEM STATE at Time t = 9: [[1.12120196 2.24355388 3.33164561 2.4287678 1.7496615 2.4287678 3.33164561 2.24355388 1.12120196]]
After Delta time 3.0. TOTAL TIME 11.999999999999973 (30 steps taken): SYSTEM STATE at Time t = 12: [[1.40992642 2.21285813 2.88112821 2.46180799 2.06855851 2.46180799 2.88112821 2.21285813 1.40992642]]
After Delta time 3.0. TOTAL TIME 14.999999999999963 (30 steps taken): SYSTEM STATE at Time t = 15: [[1.61375804 2.17517282 2.62918072 2.4582931 2.24719065 2.4582931 2.62918072 2.17517282 1.61375804]]
After Delta time 3.0. TOTAL TIME 17.999999999999986 (30 steps taken): SYSTEM STATE at Time t = 18: [[1.75622069 2.14971234 2.4820061 2.44230075 2.33952022 2.44230075 2.4820061 2.14971234 1.75622069]]
After Delta time 3.0. TOTAL TIME 21.00000000000003 (30 steps taken): SYSTEM STATE at Time t = 21: [[1.8567287 2.13705992 2.39331754 2.42217874 2.38143019 2.42217874 2.39331754 2.13705992 1.8567287 ]]
After Delta time 3.0. TOTAL TIME 24.00000000000007 (30 steps taken): SYSTEM STATE at Time t = 24: [[1.92909045 2.13366871 2.33854991 2.40125523 2.39487141 2.40125523 2.33854991 2.13366871 1.92909045]]
After Delta time 3.0. TOTAL TIME 27.000000000000114 (30 steps taken): SYSTEM STATE at Time t = 27: [[1.98256145 2.13602714 2.30397039 2.38102863 2.39282476 2.38102863 2.30397039 2.13602714 1.98256145]]
After Delta time 3.0. TOTAL TIME 30.000000000000156 (30 steps taken): SYSTEM STATE at Time t = 30: [[2.0231929 2.14155643 2.28163209 2.3622001 2.38283695 2.3622001 2.28163209 2.14155643 2.0231929 ]]
After Delta time 3.0. TOTAL TIME 33.0000000000002 (30 steps taken): SYSTEM STATE at Time t = 33: [[2.05491235 2.14857175 2.26683188 2.34506617 2.36923571 2.34506617 2.26683188 2.14857175 2.05491235]]
After Delta time 3.0. TOTAL TIME 36.00000000000024 (30 steps taken): SYSTEM STATE at Time t = 36: [[2.0802789 2.15604676 2.2567439 2.32970151 2.35445786 2.32970151 2.2567439 2.15604676 2.0802789 ]]
After Delta time 3.0. TOTAL TIME 39.000000000000284 (30 steps taken): SYSTEM STATE at Time t = 39: [[2.1009805 2.16339318 2.24965092 2.31605836 2.33983408 2.31605836 2.24965092 2.16339318 2.1009805 ]]
After Delta time 3.0. TOTAL TIME 42.00000000000033 (30 steps taken): SYSTEM STATE at Time t = 42: [[2.11815199 2.1702984 2.24449902 2.30402493 2.32605132 2.30402493 2.24449902 2.1702984 2.11815199]]
After Delta time 3.0. TOTAL TIME 45.00000000000037 (30 steps taken): SYSTEM STATE at Time t = 45: [[2.13257541 2.1766169 2.24063469 2.29346029 2.31342543 2.29346029 2.24063469 2.1766169 2.13257541]]
All cells now have essentially uniform concentration
The "20 units of concentration" are now uniformly spread across the 9 bins, leading to a near-constant concentration of 20/9 = 2.22
bio.check_mass_conservation(expected=20., chem_label="A")
True