July 18, 2014

1D Linear Convection

18.7.14 Posted by Florin No comments
This equation is the most accessible equation in CFD; from the Navier Stokes equation we kept only the accumulation and convection terms for the x component of the velocity (as we already know, in CFD the variables to be computed are velocities); to make things even simpler, the coefficient of the first derivative of the velocity is constant, making the equation linear.

ut+cux=0

This equation represents the propagation of a wave without
change of shape; the speed of the wave is c and with the initial condition given by
u(x,0)=u0(x)
the exact solution is
u(x,t)=u0(xct)
This means that on a axis with the positive direction to the right, the wave will move from left to right with the speed c.

To discretize this equation in space and time we will use the Forward Difference scheme for time derivative and Backward Difference scheme for space derivative.

The partial derivative can be approximated using the derivative definition, removing the limit operator:

uxu(x+Δx)u(x)Δx

This approach will be applied both for space and time; for time steps we will use the superscript n and for space steps (grid cells) we will use the subscript i:

un+1iuniΔt+cuniuni1Δx=0

where n+1 and n are two consecutive steps in time and i and i-1 are two neighboring points of the discretized x coordinate (grid points).
The only unknown in the equation written in this way is
un+1i. We must solve for this unknown to get an equation that allows us to advance in time, as follows:
un+1i=unicΔtΔx(uniuni1)

Before writing the code some clarifications are needed for the problem statement; the domain for this problem will be a line of length 2, that is the problem is solved on the x axis.
The initialization is made with a velocity of 1 all over the grid points, except those that lie between x=0.5 and x=1; on these points the velocity is 2.
Initial conditions - the hat function
This is an approximation of the wave profile with a hat function; after some iterations the correct shape of the wave will be apparent; the wave will be moving to right with a speed of c=1.

The code used to solve this is the following; push the arrow to run it.



The wave profile after 50 iterations looks like this:
Wave profile after 50 iterations
Plotting all steps on the same graph one can see the evolution of the wave profile.
Wave profile - all 50 iteration on the same plot
It is clear that the wave is traveling to the positive direction, with no change in shape; the high of the wave is changed until solution reaches convergence.
With the values D=30, T=25, nx=301, nt=500, it can be seen the plot below (500 iterations); this shows that the amplitude of the wave will slowly decay until it would reach the value 1.

Wave profile - 500 iteration on the same plot
The code and plot are also available on GitHub, here.

Next step: 1D Nonlinear convection

If you have any questions feel free to leave a comment below.

0 comments:

Post a Comment