Project

Linear Convection

Linear Convection

Introduction:-

In 1D linear convection equation to observed the propagation of a square wave with time.

Here, c is the velocity of propagation. The above equation is discretized using first order forward differencing in time (time-marching) and first order backaward differencing in space . after applying the numerical schemes to corresponding in space . After applyingthe numerical shemes to the corresponding partal derivatives, we obtain the follwing explicit numerical solutionto the above equation.

Programe :-

%programe for linear convection

clear all 
close all 
clc

% inputs for linear convection
L = 1;
n = [20 40 80 160];
c = 1;
t = 0.4;
dt = 1e-2;

% calculations 
x = zeros(1,160);
dx = zeros(1,160);
%x_start = 0.1;
%x_stop = 0.3;


for i = 1:4
     
    %Initialise array and apply boundary conditions 
    x = linspace(0,L,n(i));
    dx = L/(n(i)-1);
    u = ones(1,n(i));

    % space loop
    for j = 1:n(i)
        if (x(j)>=0.1 && x(j)<0.3)
            u(j) = 2;
        else
            u(j) = 1;
        end 
    end
        
   % time integration
   u_old = u;
   u_initial = u;
   % number of time steps 
   nt = t/dt;
   
   for k = 1:nt
       for j = 2:n(i)
           u(j) = u_old(j)-(c*dt/dx)*(u_old(j)-u_old(j-1));
       end
       
   % updating old values
   u_old = u;
   end
   %plotting the velocities
   figure(i)
   plot(x,u_initial, 'r')
   hold on
   plot(x,u,'b')
   grid on
   xlabel('Domain length (m)')
   ylabel('velocity ms^-1')
   legend('Initial Velocity','Final Velocity')
   axis([0 1 0.5 2.5])
   pause(0.3)
   txt = sprintf('Initial and Final Velocity for n = %d', n(i));
   title(txt)
     
   
end

Results :-

Explanation for velocity profile for different grid points :-

  • In the first and second pot where the grid pointsare minimum and grid size is maximum comared to third and fourtgh plots, we can observe that square wave is losing its sharpness and gradients dying down.
  • Here, it will drop in peak velocity is because of diffusion phenomenon which is occursing due to erroe term from the numerical approximation ofe PDE.
  • When the grid size(dx) is reduced in third and fourth plots we can obsereve the velocirty profile beibg covected at 2m/s in the third plot and the same for few moments initially in the fourth plots and later the solution is being blownup due to minimal grid size.
  • So we can reduce the diffusion phenomenonby decresing the dx value which is directly proportional to the reduction in error value which is inducting this artifical diffusion into the convection.
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.