Behaviour Of Velocity in Linear Convection equation for a range of time step.
The objective of this challenge is to solve a linear convection equation and to determine its behaviour for final velocity profile by varying the time steps.
Here, my initial velocity profile is fixed to 2m/s between 0.1 - 0.3 in my domain.
LINEAR CONVECTION EQUATION:
`(∂u)/(∂t)+c⋅(∂u)/(∂x)=0`
We can say that the linear convection equation is a snippet from the Navier stokes equation.
The output of the equation is a straight line. But for our observation, we limit it to 0.4s to see how it behaves. So the number of time steps becomes 0.4/dt
Here my domain x varies from 0 - 1m for grid points(n=80)
To perform the simulation in Matlab we need to discretize it.
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.
`(u^(n+1) - u^n) / (Deltat) + C [(u _i - u_(i-1))/( Deltax)] = 0`
`(u^(n+1) ) = u^n - C (Deltat) /( Deltax) [(u _i - u_(i-1))/( Deltax)]`
FIXING THE INITIAL VELOCITY PROFILE:
It is clear that we want a profile of velocity 2m/s at 0.1 -0.3 m.
Since the x is divided into n number of grid points, we need to locate the grid point number where the x is 0.1 - 0.3. If we do so, we can fix its velocity to 2m/s.
The index at which the grid points(n) of x varies from 0.1-0.3 is identified and the Velocity is set to 2 at those grids points.
Here we have a varying grid point so, the function
n_start = (x_start/dx) + 1;
n_stop = (x_stop/dx) + 1;
is introduced. This could identify the index of x that's varying from 0.1 - 0.3 for any number of grid points.
FINAL VELOCITY PROFILE:
The final profile is calculated by the linear convection equation we will use the Forward Difference scheme for time derivative and Backward Difference scheme for space derivative.
Here the number of timesteps(nt) is based on nt = 0.4/dt. Since t=0.4s.
FUNCTION CODE FOR LINEAR CONVECTION PROBLEM:
[x,u] = timesteplinear(1e-2);
figure(1)
plot(x,u,'b')
hold on
plot(x,u_orginal,'r')
legend('Final Velocity' , 'Initial Velocity')
xlabel('x axis')
ylabel('Velocity')
title('Effect of Velocity Proife on time step 1e-2')
grid on
[x,u] = timesteplinear(1e-3);
figure(2)
plot(x,u,'b')
hold on
plot(x,u_orginal,'r')
xlabel('x axis')
ylabel('Velocity')
legend('Final Velocity' , 'Initial Velocity')
title('Effect of Velocity Proife on time step 1e-3')
grid on
[x,u] = timesteplinear(1e-4);
figure(3)
plot(x,u,'b')
hold on
plot(x,u_orginal,'r')
xlabel('x axis')
ylabel('Velocity')
legend('Final Velocity' , 'Initial Velocity')
title('Effect of Velocity Proife on time step 1e-4')
grid on
[x,u] = timesteplinear(1e-01);
figure(4)
plot(x,u,'b')
hold on
plot(x,u_orginal,'r')
xlabel('x axis')
ylabel('Velocity')
axis([0 1 1 2]);
legend('Final Velocity' , 'Initial Velocity')
title('Effect of Velocity Proife on time step 1e-1')
grid on
MAIN CODE FOR VARYING TIME STEP:
function [x,u] = timesteplinear(dt)
%linear convection problem
L = 1;
c = 1;
n = (80);
x = linspace(0,1,n);
dx = x(2) - x(1);
%Length at which velocity should step
x_start = 0.1;
x_stop = 0.3;
%Assigning Index value for my step to start and stop
n_start = (x_start/dx) + 1;
n_stop = (x_stop/dx) + 1;
% u=2 at x= 0.1 to 0.3.
u = ones(1, n);
u(n_start:n_stop) = 2;
uold = u;
u_orginal= u;
nt = 0.4/dt;
for k = 1:nt %Time marching solution
for i = 2:n %Space marching solution
u(i) = uold(i) - (c*(dt/dx)*(uold(i)-uold(i-1)));
end
uold = u;
end
end
OBTAINED RESULTS:
For timestep dt = 1e-2:
For timestep dt = 1e-3:
For timestep dt = 1e-4:
For timestep dt = 1e-1:
CONCLUSIONS:
- We could conclude that the larger number of time steps makes the solution stable and a small number of time steps blows up the solution as in dt = 1e-1.
- The timestep 1e-2 almost matches my initial profile.
- When the timesteps become more smaller the solution is more likely to diffuse.
- We could notice a diffusion taking place in all time-steps except for dt = 1e-1. This is called artificial Diffusion.