-> When the time step = (0.5 / diffusion rate),
a 2-bin system equilibrates in a single step,
and some 3-bin systems can over-shoot equilibrium!
-> When the time step = (0.33333 / diffusion rate),
some 3-bin systems equilibrate in a single step
So, (0.33333 / diffusion rate) is a - rather lax - upper bound for sensible single time steps!
IMPORTANT: The above is for delta_x = 1; in general, multiply by delta_x**2
The "Von Neumann stability analysis", which provides a slighly looser max value of time steps, is also discussed.
That value of 0.33333 is saved in the Class variable "time_step_threshold"
LAST_REVISED = "May 27, 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, os
#os.getcwd()
#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 ChemData, BioSim1D, check_version
check_version(LIFE123_VERSION)
OK
chem_data = ChemData(diffusion_rates=10.)
bio = BioSim1D(n_bins=2, chem_data=chem_data)
bio.inject_conc_to_bin(bin_address=0, delta_conc=100., chem_index=0)
bio.describe_state()
SYSTEM STATE at Time t = 0: 2 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | |
|---|---|---|---|---|
| 0 | A | 10.0 | 100.0 | 0.0 |
bio.time_step_threshold = 0.51 # TO BYPASS THE SAFETY LIMIT
# (for the allowed maximum delta Time) that is typically in place
# When the time step is (0.5 / diffusion rate),
# a 2-bin system equilibrates in a single step!
bio.diffuse(time_step=0.05, n_steps=1)
bio.describe_state()
SYSTEM STATE at Time t = 0.05: 2 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | |
|---|---|---|---|---|
| 0 | A | 10.0 | 50.0 | 50.0 |
Note the [50. 50.] values : the two bins have equilibratedin a single simulation step!
Mighty suspicious!!
bio = BioSim1D(n_bins=3, chem_data=chem_data)
bio.inject_conc_to_bin(bin_address=1, delta_conc=100., chem_index=0)
bio.describe_state()
SYSTEM STATE at Time t = 0: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 0.0 | 100.0 | 0.0 |
bio.time_step_threshold = 0.51 # TO BYPASS THE SAFETY LIMIT
# (for the allowed maximum delta Time) that is typically in place
# When the time step is (0.5 / diffusion rate),
# a 3-bin system can overshoot equilibrium!
bio.diffuse(time_step=0.05, n_steps=1)
bio.describe_state()
SYSTEM STATE at Time t = 0.05: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 50.0 | 0.0 | 50.0 |
Note the concentrations of [50. 0. 50.] : the diffusion has over-shot equilibrium!!!
bio = BioSim1D(n_bins=3, chem_data=chem_data)
bio.inject_conc_to_bin(bin_address=1, delta_conc=100., chem_index=0)
bio.describe_state()
SYSTEM STATE at Time t = 0: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 0.0 | 100.0 | 0.0 |
bio.time_step_threshold = 0.34 # TO slightly BYPASS THE SAFETY LIMIT
# (for the allowed maximum delta Time) that is typically in place
bio.diffuse(time_step=0.033333, n_steps=1)
bio.describe_state()
SYSTEM STATE at Time t = 0.033333: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 33.333 | 33.334 | 33.333 |
bio = BioSim1D(n_bins=3, chem_data=chem_data)
bio.inject_conc_to_bin(bin_address=1, delta_conc=100., chem_index=0)
bio.describe_state()
SYSTEM STATE at Time t = 0: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 0.0 | 100.0 | 0.0 |
bio.time_step_threshold = 0.34 # TO slightly BYPASS THE SAFETY LIMIT
# (for the allowed maximum delta Time) that is typically in place
# When the time step is (delta_x**2 * 0.33333 / diffusion rate),
# a 3-bin system, configured as above, equilibrates in a single step!
bio.diffuse(time_step=3.3333, n_steps=1, delta_x=10)
bio.describe_state()
SYSTEM STATE at Time t = 3.3333: 3 bins and 1 chemical species
| Species | Diff rate | Bin 0 | Bin 1 | Bin 2 | |
|---|---|---|---|---|---|
| 0 | A | 10.0 | 33.333 | 33.334 | 33.333 |
delta_t < delta_x**2 * 0.33333 / diffusion rate¶delta_t < delta_x*2 0.5 / diffusion rate
BioSim1D.diffuse_step() enforces the stricter upper bound¶diffuse_step() method.¶An explanation can be found at: https://www.youtube.com/watch?v=QUiUGNwNNmo