July 20, 2014

2D Linear Convection

20.7.14 Posted by Florin No comments
A previous post showed how to solve the 1D linear convection problem. This time we will add another dimension and try to solve the same problem:
ut+cux+cuy=0

In order to discretize this equation we will use the same method as in the 1D problem:

un+1i,juni,jΔt+cuni,juni1,jΔx+cuni,juni,j1Δy=0

Solving for the unknown, we get the scheme we will implement in Python:
un+1i,j=uni,jcΔtΔx(uni,juni1,j)cΔtΔy(uni,juni,j1)

The initial conditions are similar; the domain will be a square of size 2; this will be divided in grid points; all points will be assigned with a starting velocity of 1, except for the points that have the x and y coordinates between 0.5 and 1; these will have an initial velocity of 2. You can see a representation of the initial conditions below:
Initial condition
A boundary condition is applied on the grid points at the limits of the domain: u = 1 if x = 0, 2 and y = 0, 2.
The resulted code is given below:
Python code for 2D Linear Convection [lines 1-44]
Python code for 2D Linear Convection [lines 33-76]
The solution is given in the following plot:
Solution after 100 iterations

The behavior is the same as for the 1D problem: the wave is moving without change in the shape of the profile.
The difficulty of this problem lies in the coding of the second dimension.
The code and plots can be downloaded from GitHub.

In the next post we will be solving the nonlinear 2D problem.

If you have questions or observations, feel free to leave a comment below.

0 comments:

Post a Comment