Project

Linear Convection Basics : Effect of Time Step on Solution

The 1-D Linear Convention Equation is given by

A Time-Marching solution was deployed to solve the above-mentioned solutions using the conditions given in the question which were as follows:

Initial Conditions of the Problem

a) Grid points n = 80
b) Time steps used are 1e-4,1e-3,1e-2 and 1e-1
c) Numerical solution compared at t = 0.4 seconds

Code:

Main Code for executing the function

clear all 
close all
clc
for w=1:4
    if w==1
        now1=tic();
        dt=1e-4;
        Onedimensional_linear_convection_time_step(dt)
        timeelapsed1=toc(now1);
    elseif w==2
        now2=tic();
        dt=1e-3;
        Onedimensional_linear_convection_time_step(dt)
        timeelapsed2=toc(now2);
    elseif w==3
        now3 = tic();
        dt=1e-2;
        Onedimensional_linear_convection_time_step(dt)
        timeelapsed3 = toc(now3);
        
    elseif w==4
        now4=tic();
        dt=1e-1;
        Onedimensional_linear_convection_time_step(dt)
        timeelapsed4=toc(now4);
    end
end
figure(2)
time_steps=categorical({'1e-4','1e-3','1e-2','1e-1'});
time_elapsed=[timeelapsed1;timeelapsed2;timeelapsed3;timeelapsed4];
bar(time_steps,time_elapsed)
ylabel('Time Elapsed')
xlabel('Time Steps')
legend('Stimulation time  for 80 grid points')

A function that accepts time step as an argument

function Onedimensional_linear_convection_time_step(dt)

L = 1; % Length = 1 metre
C = 1; % coefficient
n = 81; % number of grid points
t = 0.4; % total time
nt = t/dt; % number of time steps

% grid or mesh
x = linspace(0,L,n); % creates a mesh of equal spacing
dx = x(2) - x(1); % grid spacing

% Boundary conditions
u = ones(1,n);

x_start = 0.1; % length from which velocity becomes 2 m/s
x_stop = 0.3; % upto which velocity is 2 m/s

n_start = round((x_start/dx)+1); 
n_stop = round((x_stop/dx)+1);

u(n_start:n_stop) = 2; % square wave

u_old = u;

% Time marching

  % time loop 
  
     for k = 1:nt
         
         % space loop 
         
         for i = 2:n
             
             u(i) = u_old(i) - (C*(dt/dx)*(u_old(i)-u_old(i-1))); % Backwarddifferencing
             
         end 
         
         % update velocity 
         u_old = u;
         
     end 
     figure(1)
     plot(x,u,'linewidth',1.5)
     grid on
     axis([0 1 0 3])
     xlabel('Time(s)');
     ylabel('Velocity (m/s) ');
     legend('Time Step 1e-1','Time Step 1e-2','Time Step 1e-3','Time Step 1e-4')
     hold on
end

Results and Conclusions:

1) Plot Comparing the Numerical solutions at t=0.4 seconds for different values of time steps

The above graph represents the velocity profiles at different time steps. We see for the value of 'dt = 1e-1', the solution blows up and this due to the instability. For a value of 'dt = 1e-2', it is very close to the initial profile, but over time it loses shape. The profiles for '1e-3' and '1e-4' time steps are similar. The peak velocity is not reached

2) The plot of Stimulation time as a function of Time Step

It is found that the smaller the timestep, the longer the computational time as 1e-4 m=has the largest computational time.However, 1e-1 has the lowest computational time but this is not the correct time step to be chosen as on choosing 1e-1 as the time step the solution blows up. Thus an optimal value of time step has to be decided such that correct results are obtained and also the time required for processing is also optimal.

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.