Project

Linear convection - Effect of Time Step on the Numerical Solution

REPORT:

AIM:

To see the effect of time step size in the 1D Linear wave equation,by using time marching method of finite difference method.

EXPLANATION:

The governing equation of 1D linear wave equation is given as,

`frac{delu}{delt} = c.frac{delu}{delx}`.............(1)

Here, c is the constant

`frac{delu}{delt}` = Time derivative

`frac{delu}{delx}` = Space derivative

In this code wew have to solve 1D Linear wave equation by discretizing the eq(1).In discretization, we discretize the time derivative term by using first order forward differencing scheme and first order backward scheme for the space term and solve them using time marching method in the form of dt, By using the function code we call this code in the main code to see the effect of time step size of the solution of 1D linear wave equation.

MATLAB CODE:

MAIN CODE:

clear all
close all  
clc

dt = [1e-1,1e-2,1e-3,1e-4];
tic
[x1,uold1] = timestep(1e-1); 
toc
t1 = toc;

tic
[x2,uold2] = timestep(1e-2);
toc
t2 = toc;

tic
[x3,uold3] = timestep(1e-3);
toc
t3 = toc;

tic
[x4,uold4] = timestep(1e-4);
toc
t4 = toc;

figure(1)
    plot(x1,uold1,'linewidth',1,'color', 'r') 
    hold on
    plot(x2,uold2,'linewidth',1,'color', 'b')
    hold on
    plot(x3,uold3,'linewidth',1,'color', 'g') 
    hold on
    plot(x4,uold4,'linewidth',1,'color', 'r')
    hold on
    xlabel('x axis')
    ylabel('y axis')
    title({'1 D Linear convection'}) 
    legend('1e-1','1e-2','1e-3','1e-4')
    axis ([0 1 0 2.5])
    grid on
    
    
   simulation_time = [t1,t2,t3,t4] 
   h = categorical({'1e-1','1e-2','1e-3','1e-4'})
   figure(2)
   bar(h,simulation_time,'b')
   xlabel('Time steps')
   ylabel('Simulation time')
  

FUNCTION CODE:

function [x,uold] = timestep(dt)
    
 L = 1;
C = 1;
t = 0.4;
n = 80;
nt = t/dt;

 x = linspace(0,L,n);
 dx = L/(n-1);
 u = ones(1,n);
  k=1;

 for p = 1:n
     
 if (x(p) >= 0.1) && (x(p) <= 0.3)
     a(k) = p;
     k = k+1;
      
 end
 
 end
 
 nstart = a(1);
 nend=a(end);
 
 u(nstart:nend) = 2;
 

uold = u;


 
 for j = 1:nt
    for l = 2:n
    u(l) = uold(l) - (C*dt/dx)*(uold(l) - uold(l-1));    
    end   
    uold = u;

end
end
    


OUTPUT:

PLOT:

Comparision of velocity profile at different time steps and at t = 0.4s

OBSERVATION:

  • The velocity profile for dt = 1e-1 shows most unstable solution, as we can see many wiggles this due to gibbs phenomenon
  • The velocity profile for dt = 1e-2 showa the most stable solution,the velocity profile is much closer to the original velocity profile(square wave).
  • The velocity profile for dt = 1e-3 and dt = 1e-4 is almost same, this profile gets diffuse from its original profile.

BAR GRAPH:

Comparision of simulation time for different time steps at t = 0.4s.

OBSERVATION:

  • The 1e-1 takes more time as the solution gets blow up in the plot.
  • The 1e-2 and 1e-3 gives a better plot as the give a better solution.
  • The 1e-4 take smore time compared to 1e-2 and 1e-3, because it is a small time step and it takes more time to travel all grids.

CONCLUSION:

After observing above plot and graph,we can conclude that larger value of dt gives most unstable solution and simulation time.And as we decrease the value dt the solution and the simulation time gets low.But when we decrease to a certian value the solution gets diffused and the simulation increase as per the CFL number.

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.