July 20, 2014

1D Burgers Equation

20.7.14 Posted by Florin No comments
This time we will use the last two steps, that is the nonlinear convection and the diffusion only to create the 1D Burgers' equation; as it can be seen this equation is like the Navier Stokes in 1D as it has the accumulation, convection and diffusion terms.
ut+uux=ν2ux2

Using the explanations from step1 and step3, we can discretize this differential
in the following form:
un+1iuniΔt+uniuniuni1Δx=νuni+12uni+uni1Δx2

And after solving for the unknown, we get the scheme to be coded in Python.

un+1i=uniuniΔtΔx(uniuni1)+νΔtΔx2(uni+12uni+uni1)

This time we will not use the same problem setup as before. The initial conditions for the velocities are created using these functions:
u ϕ==2νϕϕx+4exp(x24ν)+exp((x2π)24ν)

The boundary conditions imply periodicity and are given by:
u(0)=u(2π)

For the problem stated like this there is an analytical solution:
u ϕ==2νϕϕx+4exp((x4t)24ν(t+1))+exp((x4t2π)24ν(t+1))

The initial conditions are created using SymPy which is a symbolic math module (similar with Mathematica or MathCad).
In the end of the code, the numerical solution is compared with the analytical solution.

The Python code for solving this problem is given below:
Python code for solving the Burgers' Equation [lines 1-43]
Python code for solving the Burgers' Equation [lines 33-76]
Here you can see the initial conditions:
Initial condition - saw tooth function
And finally, the solution after 100 time steps; a comparison between the analytical and the numerical solution is done.
Comparison between analytical and numerical solutions
The saw tooth function used as initial condition is basically a periodic wave profile; applying the scheme for convection and diffusion in time makes the profile to move in the domain; a change in shape is observed both in the numerical and analytical solutions.

The code and plots can be downloaded from my personal repository on GitHub.

Next time we will make the jump to the 2D dimension and will be solving the linear convection.

If you have any observations or questions do not hesitate to leave a comment below.

0 comments:

Post a Comment