8  Step 6: 2-D Convection

Now we solve 2D Convection, represented by the pair of coupled partial differential equations below:

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

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

Descretizing these equations using the methods we’ve applied previously yields:

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

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

Rearranging both equations, we solve for \(u_{i,j}^{n+1}\) and \(v_{i,j}^{n+1}\), respectively. Note that these equations are also coupled.

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

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

8.0.1 Initial Conditions

The initial conditions are the same that we used for 1D convection, applied in both the \(x\) and \(y\) directions.

\[u,\ v\ = \begin{cases}\begin{matrix} 2 & \text{for } x,y \in (0.5, 1)\times(0.5,1) \cr 1 & \text{everywhere else} \end{matrix}\end{cases}\]

8.0.2 Boundary Conditions

The boundary conditions hold \(u\) and \(v\) equal to 1 along the boundaries of the grid.

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

number of x grid points

(def nx 101)

number of y grid points

(def ny 101)

number of time steps

(def nt 80)

CFL number

(def sigma 0.2)

Define initial parameters

(def init-params
  {:nx    nx
   :ny    ny
   :nt    nt
   :c     1
   :dx    (/ 2 (- nx 1))
   :dy    (/ 2 (- ny 1))
   :sigma sigma
   :dt    (* sigma (/ 2 (- nx 1)))})

Create the 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 and v arrays

(def array-u (two-d/create-init-u init-params spatial-arr))
(def array-v (two-d/create-init-u init-params spatial-arr))

_unnamed [10201 3]:

:x :y :z
0.00 0.0 1.0
0.02 0.0 1.0
0.04 0.0 1.0
1.94 2.0 0.0
1.96 2.0 0.0
1.98 2.0 0.0
2.00 2.0 0.0

initial plotting w/ \(x\), \(y\), \(u\) goes:

8.0.3 Iterating in 2-D w/ nonlinear convection equation

u

(two-d/sim->plotly-plot-it! spatial-arr (:array-u simulated-result))

v

(two-d/sim->plotly-plot-it! spatial-arr (:array-v simulated-result))
source: notebooks/steps/step_06.clj