1D Non-linear Convection

The Inviscid Burgers' Equation

  • Understand the Problem
  • Formulate the Problem
  • Design Algorithm
  • Implement Algorithm
  • Conclusions
  • n and n+1 are two consecutive steps in time, while i−1 and i are two neighboring points of the discretized x coordinate
$$\frac{\partial{u}}{\partial{t}} + u\frac{\partial{u}}{\partial{x}}=0$$
In [1]:
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
#%matplotlib inline
In [2]:
def nonlinear_convection(nt, nx, tmax, xmax, c):
    """
    Returns the velocity field and distance for 1D non-linear convection
    """
    # Inrements in space and time
    dt = tmax/(nt-1)
    dx = xmax/(nx-1)
    
    # Initialization of data structures
    u = np.zeros((nx, nt))
    x = np.zeros(nx)
    
    # BCs
    u[0, :] = u[nx-1, :] = 1
    
    # ICs
    for i in range(1, nx-1):
        if(i > (nx-1)/4 and i < (nx-1)/2):
            u[i, 0] = 2
        else:
            u[i, 0] = 1
            
    # Loop
    for n in range(0, nt-1):
        for i in range(1, nx-1):
            u[i, n+1] = u[i, n] - u[i, n]*(dt/dx)*(u[i, n]-u[i-1, n])
    
    # Loop
    for i in range(0, nx):
        x[i] = i*dx
        
    return u, x

def plot(u, x, nt, title):
    """
    Plots the Velocity Field Results in 1D
    """
    plt.figure()
    plt.show()
    colour=iter(cm.rainbow(np.linspace(0,10,nt)))
    for i in range(0, nt, 10):
        c=next(colour)
        plt.plot(x, u[:,i], c=c)
        plt.xlabel('x [m]')
        plt.ylabel('u [m/s]')
        plt.ylim([0, 2.2])
        plt.title(title)
        plt.grid(True, linestyle='-.', linewidth='0.5', color='black')
In [4]:
u,x = nonlinear_convection(151, 51, 0.5, 2.0, 0.5)
plot(u,x,151,'Figure 1: c=0.5m/s, nt=151, nx=51, tmax=0.5s')
<Figure size 432x288 with 0 Axes>
In [5]:
u,x = nonlinear_convection(151, 302, 0.5, 2.0, 0.5)
plot(u,x,151,'Figure 2: c=0.5m/s, nt=151, nx=302, tmax=0.5s')

u,x = nonlinear_convection(151, 51, 2.0, 2.0, 0.5)
plot(u,x,151,'Figure 3: c=0.5m/s, nt=151, nx=51, tmax=2s')
<Figure size 432x288 with 0 Axes>
<Figure size 432x288 with 0 Axes>

Conclusions

  • Why isn’t the square wave maintained?

    • The first order backward differencing scheme in space still creates false diffusion as before. However, due to the non-linearity in the governing equation, if the spatial step is reduced, the solution can develop shocks, see Figure 2. Clearly a square wave is not best represented with the inviscid Burgers Equation.
  • Why does the wave shift to the right?

    • The square wave is being convected by the velocity, u which is not constant.The greatest shift is where the velocity is greatest, see Figure 1.
  • What happens at the wall?

    • As there is no viscosity, there is a non-physical change in the profile near the wall, see Figure 3.Comparing this with the linear example, there is clearly much more numerical diffusion in the non-linear example, perhaps due to the convective term being larger, causing a greater magnitude in numerical diffusion.
In [ ]: