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.
∂u∂t+c∂u∂x=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(x−ct)
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:
∂u∂x≈u(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+1i−uniΔt+cuni−uni−1Δ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
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(x−ct)
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:
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:
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
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 |
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 |
Wave profile - all 50 iteration on the same plot |
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 |
Next step: 1D Nonlinear convection
If you have any questions feel free to leave a comment below.
0 comments:
Post a Comment