{ "cells": [ { "cell_type": "markdown", "id": "f102f8dc", "metadata": {}, "source": [ "## Carry out a few single indivual steps of diffusion, \n", "### and directly verify that the values satisfy the diffusion equation\n", "\n", "In this \"PART 1\", we'll be looking at a tiny system with just 10 bins, to easily inspect the numbers directly.\n", "We'll use concentrations initialized to an upward-shifted sine wave with 1 cycle over the length system" ] }, { "cell_type": "markdown", "id": "bd4e6241-5025-46e8-90f2-2a4338e1f192", "metadata": {}, "source": [ "### TAGS : \"diffusion 1D\", \"under-the-hood\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "d32124e4-3a7f-4b82-9add-cc8bfe1f6cf8", "metadata": {}, "outputs": [], "source": [ "LAST_REVISED = \"May 3, 2025\"\n", "LIFE123_VERSION = \"1.0.0rc3\" # Library version this experiment is based on" ] }, { "cell_type": "code", "execution_count": 2, "id": "3926f0e9", "metadata": {}, "outputs": [], "source": [ "#import set_path # Using MyBinder? Uncomment this before running the next cell!" ] }, { "cell_type": "code", "execution_count": 3, "id": "f88e0e66-e970-4dbb-907b-80560c2fbf46", "metadata": {}, "outputs": [], "source": [ "#import sys\n", "#sys.path.append(\"C:/some_path/my_env_or_install\") # CHANGE to the folder containing your venv or libraries installation!\n", "# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path \n", "\n", "from life123 import BioSim1D, ChemData, CollectionArray, Numerical, check_version\n", "\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 4, "id": "5c836a9f-3c3b-46d0-987b-9f5e4a7f2008", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OK\n" ] } ], "source": [ "check_version(LIFE123_VERSION)" ] }, { "cell_type": "code", "execution_count": null, "id": "1a8965fb-3801-428b-b4b9-6d8bb931efdb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 5, "id": "6207338f", "metadata": {}, "outputs": [], "source": [ "# We'll be considering just 1 chemical species, \"A\"\n", "diffusion_rate = 10.\n", "\n", "chem_data = ChemData(diffusion_rates=[diffusion_rate], names=[\"A\"])" ] }, { "cell_type": "code", "execution_count": 6, "id": "087caa8d", "metadata": {}, "outputs": [], "source": [ "# Initialize the system with just a few bins\n", "bio = BioSim1D(n_bins=10, chem_data=chem_data)" ] }, { "cell_type": "code", "execution_count": 7, "id": "3f40acb3", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Initialize the concentrations to a sine wave with 1 cycle over the system\n", "# (with a bias to always keep it > 0)\n", "bio.inject_sine_conc(chem_label=\"A\", number_cycles=1, amplitude=10, bias=50)" ] }, { "cell_type": "code", "execution_count": 8, "id": "919ddc99", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SYSTEM SNAPSHOT at time 0:\n" ] }, { "data": { "text/html": [ "
| \n", " | A | \n", "
|---|---|
| 0 | \n", "50.000000 | \n", "
| 1 | \n", "55.877853 | \n", "
| 2 | \n", "59.510565 | \n", "
| 3 | \n", "59.510565 | \n", "
| 4 | \n", "55.877853 | \n", "
| 5 | \n", "50.000000 | \n", "
| 6 | \n", "44.122147 | \n", "
| 7 | \n", "40.489435 | \n", "
| 8 | \n", "40.489435 | \n", "
| 9 | \n", "44.122147 | \n", "