Project

Effect of different time steps dt over the time marching solutions using explicit schemes - 1D Wave equation

% Solving 1d Linear wave equation for explicit scheme with 80 grid points
% Defining the inputs for the time marching solutions

L = 1;
n = 80;
dt = [1e-1,1e-2,1e-3,1e-4]
 
for j = 1:4
    tic
    nt(j)= 0.4./dt(j);
x = linspace(0,L,n);
dx = x(2) -x(1);
c =1;


% defining the velocity for the time marching problem

u = ones(1,n);
u(1)= 1;
n_start = 9;
n_stop = 25;
u(n_start:n_stop) = 2 ;
% Assigning the the velocity at intial time period to the new variable uold
uold = u;
u_intial =u;
% For the time =0.4 seconds the total no of time steps would be 

% Explicit scheme for computing velocity at newer time step  

for k =1:nt(j)
    
    for i =2:n
    u(i) = uold(i) -(c*dt(j)/dx)*(uold(i)-uold(i-1));
    end
    uold = u
 
end
simulationtime(j) =toc

 plot(x,u,\'linewidth\',1);
hold on 
axis([0 1 1 2]);
xlabel(\'Position\');
ylabel(\'Velocity\');
title(\'Effect of time step size on the time marching solutions for explicit schemes\'); 

end
plot(x,u_intial,\'black\',\'linewidth\',2)
 legend(\'Velocity at 0.4 secs -time step - 0.1\',\'Velocity at 0.4 secs -time step - 0.01\',\'Velocity at 0.4 secs -time step - 0.001\',\'Velocity at 0.4 secs -time step - 0.0001\',\'Original velocity profile\')

% Bar chart can be framed using the following code which can be done
% seperately  as follows :

 %   c = categorical({\'0.1\',\'0.01\',\'0.001\',\'0.0001\'}); c =c;
 %   simulationtime

 %  bar(c,simulationtime)
 %  legend(\'Simulationtime\')
 %  title(\'Effect of dt over the simulation time for explicit time marching solution\')
 %  xlabel(\'time step - dt\')
 %  ylabel(\'simulation time\')

Explanation for the plots : As we can see from the above plots the effect of dt has a rigorous effect over the solution stability and also over the simulation time .When we calulate the courant number for each of these cases , as follows :

So, from the above values , the Courant condition for the time step 0.0001 is <<<1 ,Thus maintaining a steady ,stable solution (smooth profile as well).Whereas for the time step of 0.1 the value of CFL approaches to be >>1 thus it yields a solution which is unstable .The two scenarios can be easily visualized in the second plot .The explicit schemes are a preferable for transient simulations but with the lower time timesteps so as to maintain the stability in providing the accurate solutions.But the demerit here is the cost of computation .On the other hand , When u prefer to run a transient simulation with large no of time steps ,we can go for implicit scheme ,Because time step effect will not be accounted here as it is unconditionally stable .But the engineers should compromise over the level the accuracy that the implicit scheme provides (less accurate comparing with the explicit ).Also it can be seen that , the simulation time is very high for the lower time step (0.0001) and for the time step 0.1 the simulation time is very very low .Even though it completes in quicker time , it does not provide a steady state solution .

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.