7  Step 5: 2-D Linear Convection

Expanding from 1D to 2D. Following exercises extends firstly to 2D. The expansion simply requires to apply the definition: a partial derivative with respect to \(x\) is the variation in the \(x\) direction at constant \(y\).

In 2D space, a rectangular(uniform) grid is defined by the points with coordinates:

\[x_i = x_0 + i \Delta x\]

\[y_i = y_0 + i \Delta y\]

Then also define $u_{i,j} = u(x_i, y_j) and apply the finite-difference formulas on either variable \(x, y\) acting separately on the \(i\) and \(j\) indices. All derivatives are based on the 2D Taylor expansion of a mesh point value around \(u_{ij}\)

Hence, for a first-order partial derivative in the x-direction, a finite-difference formula is:

\[\frac{\partial u}{\partial x}\biggr\rvert_{i,j} = \frac{u_{i+1,j}-u_{i,j}}{\Delta x}+\mathcal{O}(\Delta x)\]

and similarly in the \(y\) direction. Thus, we can write backward-difference, forward-difference or central difference formulas for Step 5 to 12.

The PDE governing 2-D Linear Convection is written as

\[\frac{\partial u}{\partial t}+c\frac{\partial u}{\partial x} + c\frac{\partial u}{\partial y} = 0\]

This is the same form in 1-D, then added one more dimension to account for as we step forward in time.

We will use: - a forward difference discretization for the timestep - a backward difference discretization for two spatial steps

With 1-D implementations, we used \(i\) subscripts to denote movement in space (e.g. \(u_i^n - u_{i-1}^n\)). Now that we have two dimensions to account for, we need to add a second subscript, \(j\), to account for all the information in the regime.

Here, we’ll again use \(i\) as the index for our \(x\) values, and we’ll add the \(j\) subscript to track our \(y\) values.

With that in mind, our discretization of the PD should be relatively straightforward.

\[\frac{u_{i,j}^{n+1}-u_{i,j}^n}{\Delta t} + c\frac{u_{i, j}^n-u_{i-1,j}^n}{\Delta x} + c\frac{u_{i,j}^n-u_{i,j-1}^n}{\Delta y}=0\]

As before, solve for the only unknown:

\[u_{i,j}^{n+1} = u_{i,j}^n-c \frac{\Delta t}{\Delta x}(u_{i,j}^n-u_{i-1,j}^n)-c \frac{\Delta t}{\Delta y}(u_{i,j}^n-u_{i,j-1}^n)\]

We will solve this equation with the following initial conditions:

\[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}\]

and the boundary conditions:

\[u = 1\ \text{for } \begin{cases} \begin{matrix} x = 0,\ 2 \cr y = 0,\ 2 \end{matrix}\end{cases}\]

We plot here using plotly, then using :mesh3d as the type of the plot. And here’s a reference doc from kindly notebook. The plotting data formats goes like:

_unnamed [6561 3]:

:x :y :z
0.000 0.0 1.0
0.025 0.0 1.0
0.050 0.0 1.0
1.925 2.0 0.0
1.950 2.0 0.0
1.975 2.0 0.0
2.000 2.0 0.0

initial plotting goes:

note: for now, we skip 3d plotting notes from PythonCFD(further TODO)

7.0.1 Iterating in 2-D w/ linear convection equation

source: notebooks/steps/step_05.clj