{
"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 3\", we perform all the steps done in part2,\n",
"with an even finer resolution, and more complex initial concentrations,\n",
"repeated for 2 different diffusion algorithms.\n",
"\n",
"LAST REVISED: May 27, 2023"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d142d450-f2af-42fa-9026-2b44919c5b40",
"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": "9897632a-191c-4cdc-9bc2-a1143c2f0d36",
"metadata": {},
"outputs": [],
"source": [
"from experiments.get_notebook_info import get_notebook_basename\n",
"\n",
"from src.life_1D.bio_sim_1d import BioSim1D\n",
"from src.modules.reactions.reaction_data import ReactionData 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\n",
"import plotly.graph_objects as go"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0c291bcf-fd3a-443d-9df1-1b8ce9fefcae",
"metadata": {},
"outputs": [],
"source": [
"# Parameters of the simulation run. We'll be considering just 1 chemical species, \"A\"\n",
"diffusion_rate = 10.\n",
"delta_t = 0.01\n",
"n_bins = 5000\n",
"delta_x = 2 # Note that the number of bins also define the fraction of the sine wave cycle in each bin"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "53d302cc-b017-4104-8689-96a038234be9",
"metadata": {},
"outputs": [],
"source": [
"chem_data = chem(diffusion_rates=[diffusion_rate], names=[\"A\"])"
]
},
{
"cell_type": "markdown",
"id": "82504138-da32-486a-930d-bc9419cb1dc2",
"metadata": {},
"source": [
"# ALGORITHM 1"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e7a18dc8-1ae7-48d4-b557-0c7512f651c6",
"metadata": {},
"outputs": [],
"source": [
"algorithm = None # \"Explicit, with 3+1 stencil\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"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=12, bias=40)\n",
"bio.inject_sine_conc(species_name=\"A\", frequency=2, amplitude=10)\n",
"bio.inject_sine_conc(species_name=\"A\", frequency=16, amplitude=5)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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}