1D LINEAR CONVECTION SIMULATION IN MATLAB
AIM:
To solve 1 dimension linear convection equation in matlab by finite difference method and observe the propagation of wave with increasing time and also compare the effect of grids in the stability of the wave propagation.
INTRODUCTION:
1D Linear Wave Equation:
`∂u/∂t+c ∂u/∂x=0`
The above equation is discretized using forward differencing for time derivative and backward differencing for space derivative.
where 'n' is the current time step and 'i' is the current point.
Δt=time interval between two time step
Δx=step length
where,
L=1 m (domain length)
C=1
Δt=0.01
u(t=0)=2m/s for x=0.1 to 0.3
The effect of grid points on the stability of the flow is being observed in this project, hence we have taken the number of grid points as 20,40,80,160.
The total time for the solution to run is taken as T=0.4 seconds.
The program snippet for 1D linear convection is :
clear all
close all
clc
%inputs for linear convection
L=1; %domain length
c=1; %constant
n=[21 41 81 161]; %number of grid points
dt=1e-2; %time interval between two time steps
%loop for the number of grid points
for g=1:4
%calculations
x=linspace(0,L,n(g));
dx=x(2)-x(1);
n_start=(0.1/dx)+1; %start and end point of the square wave
n_end=(0.3/dx)+1;
%Initialize and apply boundary conditions
u=ones(1,n(g));
u(n_start:n_end)=2;
%Boundary Conditions
u(1)=1;
uold=u;
u_initial=u;
nt=40; %no of time steps
%Time loop
for k=1:nt
%space loop
for i=2:n(g)
u(i)=uold(i)-(c*dt/dx)*(uold(i)-uold(i-1));
end
%updating values
uold=u;
%plotting the velocity
figure(g)
hold all
plot(x,u_initial,'r','linewidth',3)
plot(x,u,'b','linewidth',1)
xlabel('domain length')
ylabel('velocity')
axis([0 1.2 0.8 2])
pause(0.3)
end
end
PLOTS:
1.For grid size= 20.
The red square wave is the initial velocity profile and the blue lines indicate the manner of propagation of wave.
2.For grid size= 40.
The red square wave is the initial velocity profile and the blue lines indicate the manner of propagation of wave.
3.For grid size= 80.
The red square wave is the initial velocity profile and the blue lines indicate the manner of propagation of wave.
4.For grid size= 160.
The red square wave is the initial velocity profile and the blue lines indicate the manner of propagation of wave.
CONCLUSION OF THE RESULTS:
1.With the incresing number of grid points, the diffusion which can be seen in blue wave gradually slows down.
2.Also with increasing time step, the solution gets more stable but with a much finer mesh like with n=160, the solution blew up.
Hence with increasing number of grid points the diffusion slows down but at higher values it gets distorted.
3.As the grid point increses, the time of computation also increases.