{
"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\n",
"\n",
"LAST REVISED: June 23, 2024 (using v. 1.0 beta34.1)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3926f0e9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Added 'D:\\Docs\\- MY CODE\\BioSimulations\\life123-Win7' to sys.path\n"
]
}
],
"source": [
"import set_path # Importing this module will add the project's home directory to sys.path"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bf6d4c37",
"metadata": {},
"outputs": [],
"source": [
"\n",
"from life123 import BioSim1D\n",
"from life123 import ChemData as chem\n",
"from life123 import MovieArray\n",
"from life123 import Numerical as num\n",
"\n",
"import numpy as np\n",
"\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6207338f",
"metadata": {},
"outputs": [],
"source": [
"# We'll be considering just 1 chemical species, \"A\"\n",
"diffusion_rate = 10.\n",
"\n",
"chem_data = chem(diffusion_rates=[diffusion_rate], names=[\"A\"])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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": 5,
"id": "3f40acb3",
"metadata": {},
"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(species_name=\"A\", frequency=1, amplitude=10, bias=50)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "919ddc99",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SYSTEM SNAPSHOT at time 0:\n",
" A\n",
"0 50.000000\n",
"1 55.877853\n",
"2 59.510565\n",
"3 59.510565\n",
"4 55.877853\n",
"5 50.000000\n",
"6 44.122147\n",
"7 40.489435\n",
"8 40.489435\n",
"9 44.122147\n"
]
}
],
"source": [
"bio.show_system_snapshot()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "43e30fba",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "Chemical=A
Bin number=%{x}
concentration=%{y}