{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ea1b88d0233541aa8577b5e29fa150ca", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(VBox(children=(HBox(children=(Dropdown(description='Solver :', options=('Explicit', 'Implicit',…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import main\n", "main.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Program utilizes either an explicit solver, implicit solver or Crank-Nicholson method to solve the diffusion equation for a plate of thickness 1mm, with initial concentration 1wt% of a given substance. Parameters such as initial concentration, end time of animation, animation speed, surface concentration and so on can be easily modified in constants.py, however the analytical function has been simplified to only account for the case where surface concentration is zero. The numerical methods are implemented in matrix form as following.\n", "\n", "Explicit:\n", "\\begin{equation}\n", " \\vec{c}_{i+1} = \\left(I - \\frac{D\\Delta t}{(\\Delta x)^2}A \\right) \\vec{c}_i\n", "\\end{equation}\n", "\n", "Implicit:\n", "\\begin{equation}\n", " \\vec{c}_{i+1} = \\left(I + \\frac{D\\Delta t}{(\\Delta x)^2}A \\right)^{-1} \\vec{c}_i\n", "\\end{equation}\n", "\n", "Crank-Nicholson:\n", "\\begin{equation}\n", " \\vec{c}_{i+1} = \\left(2I + \\frac{D\\Delta t}{(\\Delta x)^2}A \\right)^{-1}\\left(2I - \\frac{D\\Delta t}{(\\Delta x)^2}A \\right) \\vec{c}_i\n", "\\end{equation}\n", "where\n", "\\begin{equation}\n", " \\vec{c}_{i} = \n", " \\begin{pmatrix}\n", " c_{i,0}\\\\\n", " c_{i,1}\\\\\n", " \\vdots\\\\\n", " c_{i,n}\n", " \\end{pmatrix},\n", "\\end{equation}\n", "is a vector containing the concentration at positions $x_0$ through $x_n$, with $x_0$ being at the center of the plate, and $x_n$ at the surface, at timestep $t_i$.\n", "\n", "$A$ is an $(n\\times n)$ matrix of the form \n", "\\begin{equation}\n", " A = \n", " \\begin{pmatrix}\n", " -1 & 2 & -1 & & & & \\\\\n", " -1 & 2 & -1 & & & & \\\\\n", " & -1 & 2 & -1 & & & \\\\\n", " & & -1 & 2 & -1 & & \\\\\n", " & & & \\ddots & \\ddots & \\ddots & \\\\\n", " & & & & -1 & 2 & -1\\\\\n", " & & & & 0 & 0 & 0 \\\\\n", " \\end{pmatrix},\n", "\\end{equation}\n", "Where the first row is equal to the second row to account for the first order condition that the first derivative must be zero at the center of the plate. The final row is equal to zero to account for the boundary condition of constant concentration at the surface. $I$ is an $(n\\times n)$ identity matrix. It can be shown that the explicit method will diverge if \n", "\\begin{equation}\n", " \\Delta x > \\sqrt{2D\\Delta t},\n", "\\end{equation}\n", "for highest possible precision, $\\Delta x$ is locked to exactly $\\sqrt{2D\\Delta t}$ when running the explicit solver." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 2 }