#!/usr/bin/env python # coding: utf-8 # ## Exploring reaching equilibrium # # The system starts out with a pulse in bins near the *left* and the *right* endpoints # ### TAGS : "diffusion 1D", "basic" # In[1]: LAST_REVISED = "May 3, 2025" LIFE123_VERSION = "1.0.0rc3" # 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(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() # In[6]: bio.show_system_snapshot() # In[7]: # Visualize the system's initial state bio.visualize_system(title_prefix="Diffusion") # In[8]: # Show as heatmap bio.system_heatmaps(title_prefix="Diffusion") # In[ ]: # # Start the simulation steps # In[9]: delta_time = 3. # In[10]: 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) # **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** # In[11]: bio.check_mass_conservation(expected=20., chem_label="A") # In[ ]: