Project

Effect of time step size 1D Linear convection

Obejective:

To write a function that accepts time step as an argument & compare the effect of time step on the numerical solution.

Two Dimensional momentum equation:

Effect of different time step

Time steps were used.dt=1e-4,1e-3,1e-2,1e-1

When time step, dt = 1e-4, time n=80,

The velocity profile comes down gradually and its profile sharpness decreases step by step.It means the velocity profile moving down & peakvelocity comes down.

with the help of time marching,dt x nt times the step by step profile was executed.

Similarly for dt = 1e-3,1e-2,1e-1

We can say that our time step(dt) value is small then the sharpness of the velocity profile reducing very slowly and gradually.

if the time step (dt) value increases, the space between the velocity profiles also increase.

Matlab code:

clear all
close all
clc

%defining the square wave
L=1;
c=1;
dt=[1e-4, 1e-3, 1e-2, 1e-1];
n=80;

%Defining grid & mesh size
x=linspace(0,L,n);
dx=x(2)-x(1);

%start Point

stepst=0.1;
[val,idx]=min(abs(x-stepst));
start=x(idx);
n_start = find(x == start);

%stop Point

stepst=0.3;
[val,idx]=min(abs(x-stepst));
stop=x(idx);
n_stop = find(x == stop);
 
%Initial value & boundary condition
u=1*ones(4,n);
u(:,n_start:n_stop)=2;
u(:,1)=1;
uold=u;
u_initial = u;

nt=100;

%Different time steps
for j= 1:length(dt)
    
  %time loop
  for k=1:nt
  
  %space loop

    for i=2:n
    u(j,i)=uold(j,i)-(c*dt(j)/dx)*(uold(j,i)-uold(j,i-1));
    end
    
    %update old velocities
    uold=u;
  
  %plotting velocities
  %figure(j)
  hold on
  plot(x,u_initial(j,:),'r')
  hold on
  plot(x,u(j,:),'b')
  xlabel('Length')
  ylabel('velocity profile')
  pause(0.4); 
  grid on;
  
 
  
  end

end

    figure(2)
    C = [dt(1) dt(2) dt(3) dt(4)];
    bar(C); 
    set(gca,'xticklabel',{'1e-4','1e-3','1e-2','1e-1'});
    xlabel('Time step');
    ylabel('Simulation time');
    title('Bar chart of simulation time vs time step')

Time step, dt =1e-4

Time step,dt=1e-3

Time step,dt=1e-2

Timestep,dt=1e-1

Simulation time

With increase of the time step (dt) the time taken for the simulation also increases

Let's look in to the bar chart.

Conclusion

From this i learned how to manipulate different time steps with fixed time & from the bar chart the learned that simulation time of each time step.

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.