{
"cells": [
{
"cell_type": "markdown",
"id": "a40f6857",
"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 2\", we quickly repeat all the steps discussed at length in part1,\n",
"but using a much-finer resolution.\n",
"This time, we'll start with slightly more complex initial concentrations built from 2 superposed sine waves.\n",
"\n",
"**We'll also explore the effects of:** \n",
"-Spatial resolution (\"delta x\") \n",
"-Temporal resolution (\"delta t\") \n",
"-Alternate methods of estimating numerical derivatives\n",
"\n",
"LAST REVISED: July 14, 2023"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "30dffc16-7072-4a62-b606-642138990e5f",
"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": "a1bc9cbe",
"metadata": {},
"outputs": [],
"source": [
"\n",
"from src.life_1D.bio_sim_1d import BioSim1D\n",
"from src.modules.chemicals.chem_data import ChemData as chem\n",
"from src.modules.movies.movies import MovieArray\n",
"from src.modules.numerical.numerical import Numerical as num\n",
"\n",
"import numpy as np\n",
"\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0c291bcf-fd3a-443d-9df1-1b8ce9fefcae",
"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": "markdown",
"id": "82504138-da32-486a-930d-bc9419cb1dc2",
"metadata": {},
"source": [
"# BASELINE\n",
"This will be our initial system, whose adherence to the diffusion equation we'll test.\n",
"Afterwards, we'll tweak individual parameters - and observed their effect on the closeness of the approximation"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bca9a060-f62d-433a-9924-1fb2314870f3",
"metadata": {},
"outputs": [],
"source": [
"# Parameters of the simulation run (the diffusion rate got set earlier, and will never vary)\n",
"delta_t = 0.01\n",
"n_bins = 300\n",
"delta_x = 2 # Note that the number of bins also define the fraction of the sine wave cycle in each bin\n",
"algorithm = None # \"Explicit, with 3+1 stencil\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "696122b0-c8c4-4d43-a4fc-319f95221602",
"metadata": {},
"outputs": [],
"source": [
"# Initialize the system\n",
"bio = BioSim1D(n_bins=n_bins, chem_data=chem_data)\n",
"\n",
"# Initialize the concentrations to 2 superposed sine waves\n",
"bio.inject_sine_conc(species_name=\"A\", frequency=1, amplitude=10, bias=50)\n",
"bio.inject_sine_conc(species_name=\"A\", frequency=2, amplitude=8)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "338bd51c-6b12-4cf0-8526-797389fbc55c",
"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}