9 Step 7: 2-D Diffusion
And here is the 2D-diffusion equation:
\[\frac{\partial u}{\partial t} = \nu \frac{\partial ^2 u}{\partial x^2} + \nu \frac{\partial ^2 u}{\partial y^2}\]
You will recall that we came up with a method for discretized second order derivatives in Step 3, when investigating 1-D diffusion. We are going to use the same scheme here, with our forward difference in time and two second-order derivatives.
\[\frac{u_{i,j}^{n+1} - u_{i,j}^n}{\Delta t} = \nu \frac{u_{i+1,j}^n - 2 u_{i,j}^n + u_{i-1,j}^n}{\Delta x^2} + \nu \frac{u_{i,j+1}^n-2 u_{i,j}^n + u_{i,j-1}^n}{\Delta y^2}\]
Once again, we reorganize the discretized equation and solve for \(u_{ij}^{n+1}\)
\[\begin{split} u_{i,j}^{n+1} = u_{i,j}^n &+ \frac{\nu \Delta t}{\Delta x^2}(u_{i+1,j}^n - 2 u_{i,j}^n + u_{i-1,j}^n) \\ &+ \frac{\nu \Delta t}{\Delta y^2}(u_{i,j+1}^n-2 u_{i,j}^n + u_{i,j-1}^n) \end{split}\]
9.0.1 Initial Conditions
def nx 31) (
def ny 31) (
def nt 10) (
viscosity
def nu 0.05) (
CFL number
def sigma 0.2) (
def dx (/ 2 (- nx 1))) (
def dy (/ 2 (- ny 1))) (
def init-params
(:nx nx
{:ny ny
:nu nu
:nt nt
:sigma sigma
:dx dx
:dy dy
:dt (* sigma dx dy (/ 1 nu))})
Create spatial grid
def grid-start 0) (
def grid-end 2) (
def spatial-arr (two-d/create-array-2d
(assoc init-params
(:x-start grid-start :x-end grid-end
:y-start grid-start :y-end grid-end)))
Create the initial u with the initial condition:
\[u(x,y) = \begin{cases} \begin{matrix} 2\ \text{for} & 0.5 \leq x, y \leq 1 \cr 1\ \text{for} & \text{everywhere else}\end{matrix}\end{cases}\]
def array-u (two-d/create-init-u init-params spatial-arr)) (
initial plotting goes:
9.0.2 Iterating in 2-D w/ diffusion equation
at \(nt=10\)
at \(nt=14\)
at \(nt=50\)
source: notebooks/steps/step_07.clj