Project

Linear convection (time marching and simulation time) is solved for 1 dimensional problem using 80 nodes for different time steps

Following time steps (seconds) were used for calculations:

a)1e-4

b)1e-3

c)1e-2

d)1e-1

The time marching was done for a domain of 1 m. 80 nodes were set on the domain and time marching calculations were performed.

Artificial diffusion error and stability

Time step of 1e-4 showed the the maximum deflection of peak velocity after 4seconds.

Time step of 1e-1 caused the solution to blew up. Tremendous error is introduced when this time step is used.

Time step of 1e-2 showed the minium artificial diffusion error. Peak velocity was around 2m/s even after 4seconds.

Calculation Time

Time step with 1e-4 took the highest time for calculation whereas time step of 1e-1 took the least.

It's evident that as dt is decreased calculation time taken will be more.

clear all
close all
clc

graphics_toolkit('gnuplot');
output_precision(4);

#square wave activation points
wave_start = 0.1;
wave_end   = 0.3;

#length of domain
l = 1;

#time step
dt = [ 1e-1,1e-2,1e-3,1e-4];
c=1;

#for changing color every graph
k=1;


for  d = 1:length(dt);
    
#number of nodes
   n = 80;
  #distance between nodes
  dx = l/(n-1);
  
  
  #domain discritization
  nodes_position= linspace(0,1,n);
  

  
  [~,index_wave_starts]=min(abs(nodes_position - wave_start));
  #node_start_real=nodes_position(index_wave_starts)
  [~,index_wave_ends]=min(abs(nodes_position - wave_end));
  #node_end_real=nodes_position(index_wave_ends)
  
  
  t=0.4;
  cycle = t/dt(d);
  
  
  u=1*ones(1,n);
  #boundary condition assumption at node 1
  u(1) = 1;
  u(index_wave_starts:index_wave_ends) = 2;
  uold = u;
  u_initial = u;
  tic
  #total time where cycle is t/dt
  for j = 1:cycle
    
    for i = 2:n
      u(i) = uold(i) - (c*dt(d)/dx)* (uold(i) - uold(i-1));
    endfor
    uold = u;
   

   endfor
   simulation_time(d)=toc;


figure(1)
color =['r','b','k','c'];
plot(nodes_position,u,num2str(color(k)),'linewidth',4) 
k = k+1;

pause(0.002)
axis ([0 1 0 2])
hold on
#xticks(nodes_position)
ylabel('velocity in m/s')
xlabel('Domain length (m')

if d == length(dt)
 legend(num2str(dt(d-3)),num2str(dt(d-2)),num2str(dt(d-1)),num2str(dt(d)))
 text=sprintf("Time Marching result of square wave using %d nodes for different Time Steps after 4 seconds",n);
 title(text)
 figure(2)
 h = bar(simulation_time,'barwidth',0.51)
 title('Simulation time taken for various time steps')
 ylabel('Time taken for calculation in seconds');
 xlabel('Time step in seconds');
 set(gca,'xticklabel',{'1e-1','1e-2','1e-3','1e-4'});
 
end

endfor
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.