Open In Colab

Burger Equation#

John S Butler john.s.butler@tudublin.ie Course Notes Github#

Overview#

This notebook will implement the Lax-Freidrich numerical method on the the Burger Equation.

The Burger Differential Equation#

Consider the one-dimensional non-linear Burger Equation:

(845)#\[\begin{equation} \frac{\partial u}{\partial t} +u\frac{\partial u}{\partial x}=0,\end{equation}\]

with the initial conditions

(846)#\[\begin{equation} u(x,0)=1-\cos(x), \ \ 0 \leq x \leq 2\pi. \end{equation}\]

and wrap around boundary conditions.

This notebook will implement the Lax-Friedrich method to appoximate the solution of the Burger Equation. The Lax-Fredrich method was designed by Peter Lax (https://en.wikipedia.org/wiki/Peter_Lax) and Kurt Otto Friedrichs (https://en.wikipedia.org/wiki/Kurt_Otto_Friedrichs).

# LIBRARY
# vector manipulation
import numpy as np
# math functions
import math 

# THIS IS FOR PLOTTING
%matplotlib inline
import matplotlib.pyplot as plt # side-stepping mpl backend
import warnings
warnings.filterwarnings("ignore")

Discete Grid#

The region \(\Omega\) is discretised into a uniform mesh \(\Omega_h\). In the space \(x\) direction into \(N\) steps giving a stepsize of

(847)#\[\begin{equation} h=\frac{1-0}{N},\end{equation}\]

resulting in

(848)#\[\begin{equation}x[i]=0+ih, \ \ \ i=0,1,...,N,\end{equation}\]

and into \(N_t\) steps in the time \(t\) direction giving a stepsize of

(849)#\[\begin{equation} k=\frac{1-0}{N_t}\end{equation}\]

resulting in

(850)#\[\begin{equation}t[i]=0+ik, \ \ \ k=0,...,K.\end{equation}\]

The Figure below shows the discrete grid points for \(N=10\) and \(Nt=100\), the known boundary conditions (green), initial conditions (blue) and the unknown values (red) of the Heat Equation.

N=10
Nt=10
h=2*np.pi/N
k=1/Nt
r=k/(h*h)
time_steps=10
time=np.arange(0,(time_steps+.5)*k,k)
x=np.arange(0,2*np.pi+h/2,h)


X, Y = np.meshgrid(x, time)

fig = plt.figure()
plt.plot(X,Y,'ro');
plt.plot(x,0*x,'bo',label='Initial Condition');
plt.xlim((-h,2*np.pi+h))
plt.ylim((-k,max(time)+k))
plt.xlabel('x')
plt.ylabel('time (ms)')
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.title(r'Discrete Grid $\Omega_h$ ',fontsize=24,y=1.08)
plt.show();
../_images/7d6ac694b061306bcd9255bbfab2a2bddcdafc577fee9a6259291f127061bdd4.png

Initial Conditions#

The discrete initial conditions is,

(851)#\[\begin{equation} w[0,j]=1-\cos(x[j]), \ \ 0 \leq x[j] \leq \pi, \end{equation}\]

The Figure below plots values of \(w[0,j]\) for the inital (blue) conditions for \(t[0]=0.\)

w=np.zeros((time_steps+1,N+1))
b=np.zeros(N-1)
# Initial Condition
for j in range (0,N+1):
    w[0,j]=1-np.cos(x[j])
    

fig = plt.figure(figsize=(8,4))
plt.plot(x,w[0,:],'o:',label='Initial Condition')
plt.xlim([-0.1,max(x)+h])
plt.title('Intitial Condition',fontsize=24)
plt.xlabel('x')
plt.ylabel('w')
plt.legend(loc='best')
plt.show()
ipos = np.zeros(N+1)
ineg = np.zeros(N+1)
for i in range(0,N+1):
   ipos[i] = i+1
   ineg[i] = i-1

ipos[N] = 0
ineg[0] = N
../_images/5f784cb13f845cecec2e5063d7e0a1e8b91e28eac9742016169f35e4866e0e35.png

Lax-Friedrichs Method#

The Lax-Friedrichs Method of the Burger Equation is,

(852)#\[\begin{equation} \frac{w_{ij+1}-\frac{w_{ij+1}+w_{ij-1}}{2}}{k}+aw_{ij}\big(\frac{w_{i+1j}-w_{i-1j}}{2h}\big)=0. \end{equation}\]

Rearranging the equation we get

(853)#\[\begin{equation} w_{ij+1}=\frac{w_{ij+1}+w_{ij-1}}{2}-w_{ij}\frac{\lambda}{2} a(w_{i+1j}-w_{i-1j}), \end{equation}\]

for \(i=0,...10\) where \(\lambda=\frac{k}{h}\).

This gives the formula for the unknown term \(w_{ij+1}\) at the \((ij+1)\) mesh points in terms of \(x[i]\) along the jth time row.

lamba=k/h
for j in range(0,time_steps):
    for i in range (0,N+1):
        w[j+1,i]=(w[j,int(ipos[i])]+w[j,int(ineg[i])])/2+lamba*w[j,i]/2*(-(w[j,int(ipos[i])]-w[j,int(ineg[i])]))
        
fig = plt.figure(figsize=(12,6))

plt.subplot(121)
for j in range (1,time_steps+1):
    plt.plot(x,w[j,:],'o:')
plt.xlabel('x')
plt.ylabel('w')

plt.subplot(122)
X, T = np.meshgrid(x, time)
z_min, z_max = np.abs(w).min(), np.abs(w).max()


plt.pcolormesh( X,T, w, vmin=z_min, vmax=z_max)


#plt.imshow(w, aspect='auto')
plt.xlabel('x')
plt.ylabel('time')
clb=plt.colorbar()
clb.set_label('Temperature (w)')
plt.suptitle('Numerical Solution of the  Burger Equation'%(np.round(r,3)),fontsize=24,y=1.08)
fig.tight_layout()
plt.show()
../_images/f312d20a27da83eebf0ea48e9182627773c6ebeeef8a432d1b482c3ad2576093.png