{
"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: June 23, 2024 (using v. 1.0 beta34.1)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cd32c72b-8bcb-43a5-940f-84f2159de2de",
"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": "7593be7e",
"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": "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": "code",
"execution_count": null,
"id": "0b514690-b0ba-4519-a7e4-e87f6accf19e",
"metadata": {},
"outputs": [],
"source": []
},
{
"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}