#!/usr/bin/env python # coding: utf-8 # ## A strong, localized transient concentration becomes irrelevant with distance # # Diffusion of a narrow, bell-shaped, initial concentration of a single chemical. # With increasing distance from the initial location of the transient signal, hardly any change with time is detected as the system goes to equilibrium # ### TAGS : "diffusion 1D" # In[1]: LAST_REVISED = "Aug. 10, 2025" LIFE123_VERSION = "1.0.0rc6" # Library version this experiment is based on # In[2]: #import set_path # Using MyBinder? Uncomment this before running the next cell! # In[3]: #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 # In[4]: check_version(LIFE123_VERSION) # In[ ]: # In[5]: # Initialize the system chem_data = ChemData(diffusion_rates=10.) # Name "A" automatically assigned to only chemical bio = BioSim1D(n_bins=500, chem_data=chem_data) # In[6]: # Set up the initial bell-shape concentration, with the very narrow peak close to one end of the system, # centered at 1/10 of the width of the system, i.e. at bin 50 bio.inject_bell_curve(chem_label="A", center=0.1, sd=0.005, amplitude=0.1, bias=10.) # In[ ]: # In[7]: df = bio.describe_state() df # In[8]: df[df.columns[38:62:2]] # Zoom in where the action is # In[ ]: # In[9]: # Visualize the system state so far bio.visualize_system(title_prefix="Initial strong, localized transient") # In[10]: # Show as heatmap bio.system_heatmaps(title_prefix="Initial strong, localized transient") # In[ ]: # ## Request history-keeping for some bins # In[11]: # Request to save the concentration history at the bins with the initial concentration injection, # and the bins at, or near, both ends of the system bio.enable_history(bins=[0, 25, 48, 50, 100, 200, 400], frequency=25, take_snapshot=True) # In[ ]: # In[ ]: # ## Start the diffusion # In[12]: bio.diffuse(total_duration=5, time_step=0.01) # In[13]: bio.visualize_system() # In[14]: bio.system_heatmaps() # In[ ]: # ### Scrutinize the changes with time, at bins increasingly further away from the transient peak of bin 50 # In[15]: bio.plot_history_single_bin(title_prefix="Bin with the concentration injection.", bin_address=50) # In[16]: bio.plot_history_single_bin(title_prefix="Bin very close to the location of the concentration injection.", bin_address=48) # In[17]: bio.plot_history_single_bin(title_prefix="Bin relatively far from the location of the concentration injection.", bin_address=25) # In[ ]: # ### Continue the diffusion, to equilibrium # In[18]: # Do several rounds of diffusion, over relatively small time steps for _ in range(5): bio.diffuse(total_duration=25, time_step=0.02) bio.visualize_system(show=True) # #### Notice how the wave of diffusion hits the left edge of the system # In[ ]: # In[19]: # Do more rounds of diffusion, over larger time steps for _ in range(5): bio.diffuse(total_duration=400, time_step=0.025) bio.visualize_system(show=True) # In[20]: bio.system_heatmaps() # #### We're now close to equilibrium # In[ ]: # ### Scrutinize the changes with time, at bins increasingly further away from the transient peak of bin 50 # In[21]: bio.plot_history_single_bin(title_prefix="Bin with the concentration injection.", bin_address=50) # In[22]: bio.plot_history_single_bin(title_prefix="Bin very close to the location of the concentration injection.", bin_address=48) # In[23]: bio.plot_history_single_bin(title_prefix="Bin relatively far from the location of the concentration injection.", bin_address=25) # In[24]: bio.plot_history_single_bin(title_prefix="Bin also relatively far from the location of the concentration injection (but on opposite side).", bin_address=0) # In[25]: bio.plot_history_single_bin(title_prefix="Bin quite far from the location of the concentration injection.", bin_address=100) # In[26]: bio.plot_history_single_bin(title_prefix="Bin very far from the location of the concentration injection.", bin_address=200) # In[27]: bio.plot_history_single_bin(title_prefix="Bin hugely far from the location of the concentration injection.", bin_address=400) # # Notice how faraway locations (such as bin 400) barely register that the distant transient ever happened! # #### **VARIATION:** # Transients that never make it far from their origin, because of _chemical reactions consuming them_, are explored in the experiment `1D/reaction_diffusion/transient_getting_mopped_up` # In[ ]: