Effect of time-step on solution of 1st order wave equation
The 1D Linear convection equation is given as:
The first step to solve the problem is to discretize the equation. The time derivative is discretized using a first-order approximation forward difference scheme, whereas a first-order approximation backward difference scheme is used to discretize the space derivative.
Substituting these equations in the main equation,
Simplifying the above equation, we get a generalized form which is used to obtain the velocity at a particular node at a particular time-step.
In the given problem, the initial velocity profile is given, and also the boundary condition is provided.
So, for a given time-step, first we calculate velocities at all the nodes. It is done as follows-
...and so on until we obtain the velocity at all nodes.
Once this is done, we advance to the next value of time step and follow the above procedure to calculate velocities in the domain at that time.
In this project, the size of time step is kept constant as 0.01 sec. While we check the effect of varying number of nodes on the velocity profile in the domain.
The Matlab code to follow out the above mentioned algorithm is given below-
clc
clear all
close all
%length of domain
L=1;
%constant
c=1;
%number of nodes,(n-1)=number of divisions
n=80;
%step-size
delta_x=linspace(0,L,n);
dx=delta_x(2)-delta_x(1);
%boundary condition, u=1
u=ones(1,n);
%location of step in velocity profile (length-wise)
x_start=0.1;
x_stop=0.3;
%finding the node where velocity profile changes
B=find(delta_x>0.1 & delta_x<0.3);
%corresponding location of step in velocity profile (node-wise)
n_start=B(1,1);
n_stop=B(end);
u(n_start:n_stop)=2;
u_old=u;
u_initial=u;
%time of analysis
t_initial=0;
t_final=0.4;
%time step size
dt=[1e-4 1e-3 1e-2 1e-1];
for k=1:length(dt)
u=u_initial;
%number of time-steps
n_t=((t_final-t_initial)/dt(k))+1;
for i=1:n_t
u_old=u;
for j=2:n
u(j)=u_old(j)-(c*(dt(k)/dx)*(u_old(j)-u_old(j-1)));
end
end
u_final(k,:)=u;
end
plot(delta_x,u_final(1,:),'r')
hold on
plot(delta_x,u_final(2,:),'g')
hold on
plot(delta_x,u_final(3,:),'b')
hold on
plot(delta_x,u_final(4,:),'k')
xlabel('Length of domain (m)')
ylabel('Velocity(m/s)')
axis([0 1 -3 3])
legend('Time-step=1e-4','Time-step=1e-3','Time-step=1e-2','Time-step=1e-1','Location','best')
title('Comparision of velocity profile for various size of time steps')
RESULTS-
The zoomed-in image:
CONCLUSION:
The stability criteria for a 1st order wave equation is: c*(dt/dx)<1
It is observed that as the size of time-step is decreased, the velocity profile becomes much smoother. But it has a limitation- values of dt and dx should satisfy the stability criteria. In case 4, where the time-step is 1e-1. The dt term here is large which make the solution unstable.