Project

Linear Convection

Linear Convection

Effect of time step size on the solution

Objective:-

Write a function that accepts the time step as an argument and solves the same problem. You will compare the effect of the time step on the numerical solution.

1. Set n = 80

2. Time steps to use = 1e-4, 1e-3, 1e-2, and 1e-1

3. Simulation time = 0.4 seconds

Programe :-

clear all 
close all 
clc

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

% 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);
    dx = L/(n-1);
    u = ones(1,n);

    % space loop
    for j = 1:n
        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
           u(j) = u_old(j)-(c.*dt(i)./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 dt = %d', dt(i));
   title(txt)
     
   
end

Results:-

Explanation on programe:-

  • From the figure 1 we observe that time step (1e-3) the solution tend to become unstable and blowedup .
  • After that next time step of (1e-2, 1e-1) are have minimum amplitude.
  • Then the *(1e-4) have lowest amplitude.
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.