1D linear convection for varying grid points.
1D linear convection plot for varying grid points.
Aim: To study the variation of the 1D linear convection plot for varying grid points.
This equation is tends to be quite similar to the Navier Stroke's equation. The equation is represented as follows:
`(delu)/(delt) +c(delu)/(delx)=0`
The above is the 1D linear convection equation. It is known as a one dimension because it has terms in one spacial axis and convection because of the similarity of the second term to the convective term of the Navier Strokes equation.
Through this assignment we can understand the influence of grid size on the solution of the linear convection plot. The following are the initial conditions given.
- Domain length is L = 1m
- The initial velocity profile is a step function. It is equal to 2m/s between x= 0.1 and 0.3 and 1m/s everywhere else
- Number of grid points for comparison are 20, 40, 80, 160
- Constant Velocity, C = 1
- Set time step = 0.01
PROGRAM LISTING
% linear convection program
clear all
close all
clc
% inputs
L=1;
n=[20 40 80 160];
c=1;
dt=1e-2; % in sec
t=0.4;
%calculation
for f=1:length(n)
x=linspace(0,L,n(f));
%dx= x(2)-x(1);
dx(f)=L/(n(f)-1);
%initializing array and boundary conditions
u=ones(1,n(f));
u(1)=1;
for j=1:length(x)
if x(j)>=0.1 && x(j)<=0.3
u(j)=2;
else
u(j)=1;
endif
end
%u(n_start:n_stop)=2;
uold=u;
u_initial=u;
%time marching solution
nt=50;
for z= 1:nt %time loop
for i=2:n(f) %space loop
u(i)= uold(i)-(c*dt/dx(f))*(uold(i)-uold(i-1));
end
uold=u;
figure(f)
plot(x,u_initial,'c')
hold on
plot(x,u)
xlabel('domain length')
ylabel('velocity')
title({'Initial vs Final velocity profile',['time =',num2str(t)],['Grid point=',num2str(n(f))],['number of timesteps=',num2str(nt)]})
axis([0 1 0 3])
grid on
pause(0.01)
end
end
PLOTS
Plot for N=20
Here we can observe that as the wave progresses, the value of the velocity changes this happens due to artificial diffusion error. For N=20, the change is significant. This implies the solution is
PLOT for N=40
Now for this plot the we can observe the rate of diffusion had decreased compared to the previous plot.
PLOT for N=80
In this graph it can be observed that, the diffusion rate is zero and the velocity curve had maintaine the same peak throughout the length of the domain.
PLOT for N=160
For N=160, the solution blows up. This implies that the solution is unstable for 160 grid points.
Conclusion
- From the above results, we can understand that, the number of grid points plays a significant role in achieving the perfect solution.
- As described above, for N=20, we can infer that the effect of diffusion was maximum.
- Whereas, for N=80, we can infer that the effect of diffusion was non existant.
- For N=160, the solution blows up.