Project

Numerical solution to the one-dimensional Linear Convection equation.

Numerical solution to the one dimensional Linear Convection equation:

The one dimensional linear convection equation for which we gonna find the numerical solution is,

`du/dt + [c] dx/dt = 0`

Where u is the initial velocity

This equation is computed at nth step. so using explicit method, we get the simplified equation as below,

`u(i) = uold(i) - (c*dt/dx)*(uold(i)-uold(i-1))`

For the given problem, we have

Domain Length, L = 1m

Constant Velocity, C = 1

Set time step, dt = 0.01

the velocity profile is a step function where equal to 2m/s at x=0.1 & 0.3 and rest 1m/s

Time = 0.4 seconds

Time loop, nt = 0.4/dt = 40

calculation for number of grid points are: 20,40,80,160

A velocity plot is being compared between the initial velocity and final velocity in the following code below:

clear all;
close all
clc


%inputs for linear convection problem
L = 1;   %domain lenghth
n = [20,40,80,160];  %nymber if grid points
c = 1;   %constant velocity
dt = 1e-2; %time step

for f = 1:length(n)
    
%calculations
x = linspace(0,L,n(f));
dx = x(2) - x(1);


%initialize arrays and apply boundary conditions
u = ones(1,n(f));

for j= 1:length(x);
if (x(j) >=0.1 && x(j)<=0.3)
    u(j) = 2;
else
    u(j) =1;
end
end

%BC
u(1) = 1;
uold = u;
u_initial= u;


%time loop
nt=40; % nt = t/dt
for k= 1:nt
   
%space loop;
   for i =2:n(f)
    u(i) = uold(i) - (c*dt/dx)*(uold(i)-uold(i-1));
   end

   uold = u; 
   
     
end

%plot
figure(f)
plot(x,u_initial,'b') %plot for intitial velocity
hold on
plot(x,u,'r')  %plot for final velocity
axis([0 1 0 2])   
pause(0.3)
legend('initial velocity profile','final velocity profile')
    
    
end   
    

Output:

This will generate 4 plots for each set of grid points. the results are:

1. velocity plot for 20 grid points(n):

2.velocity plot for 40 grid points(n):

3. velocity plot for 80 grid points(n):

4. velocity plot for 160 grid points(n):

Observation:

  • From the above plots, we can observe that as the grid points increases, the profile looks much sharper and cleaner.
  • The rate of diffusion also increases when the grip points increase from the 20 to 40, which is also called Numerical diffusion.
  • Since we are making the dx smaller by increasing grid points, the error reduces.
  • and the sharpness of the curve decreases at n=80.
  • But when we look at the n = 160, there is a Gibbs phenomenon as these are oscillations in the solution.
  • therefore, for the n=180 plot, the solution is unstable, as we are using a first-order approximation.
  • The stability of the solution can be determined by Von Neumann stability analysis.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.