{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Cellular automata I: Heat diffusion\n", "\n", "---\n", "\n", "\n", "\n", "This notebook is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "from pathlib import Path\n", "\n", "import matplotlib.pyplot as plt\n", "from matplotlib import animation, rc\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sns\n", "from IPython.display import HTML\n", "\n", "rc(\"animation\", html=\"html5\")\n", "\n", "np.random.seed(1189773503)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Background: Heat Diffusion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will be building a cellular automata simulation of the diffusion of heat within a bar. Unlike a system dynamics model, this simulation will allow us to observe the heat flow at different positions within the bar. In effect, we will be able to simulate what the temperature of the bar will be not only at a given time, but at a given position in the bar.\n", "\n", "The general idea of what we want to do is to to scale down **Newton's law of heating and cooling**. This states that the rate of change of the temperature with respect to time of an object is proportional to the difference between the temperature of the object and temperature of its surroundings. In the context of cellular automata, a cell's *surroundings* is defined by its surrounding neighbors in a grid." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There's different ways to define a cell's surroundings, or neighborhood. For our purposes, we will use the so-called **Moore neighborhood**, which consists of a cell's NW, N, NE, W, E, SW, S, and SE neighbors:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
| NW | \n", "N | \n", "NE | \n", "
| W | \n", "site | \n", "E | \n", "
| SW | \n", "S | \n", "SE | \n", "