Linear Convection Basics: Effect of grid Points on Solution
The 1-D Linear Convention Equation is given by
A Time-Marching solution was deployed to solve the above-mentioned solutions using the conditions given in the question which were as follows:
Initial Conditions of the Problem
L=1
Velocity Profile is a step function with a velocity of 2m/s between 0.1 and 0.3 seconds and 1m.s everywhere else
n=20,40,80,160
C=1
Time Step=0.01
Time =0.4
Code:
clear all
close all
clc
% Inputs for Linear Convection Problem
L = 1; % Domain length
n = [20 40 80 160]; %Number of Grid Numbers
c = 1; % Constant in the equation
dt = 0.01; % Time step
x = zeros(1,160); % All variabled preallocate to save time
dx = zeros(1,160);
nstart = zeros(1,4);
nstop = zeros(1,4);
t = 0.4; % Given Time Taken
for i=1:4 % This for loop is used to implement the array of grid values
% Calculation
x=linspace(0,L,n(i));
dx= L/(n(i)-1);
u=ones(1,n(i));
% Initialize arrays and apply boundary conditions
for j=1:n(i)
if(x(j)>=0.1 && x(j)<=0.3)
u(j)=2; % Given condition for velocity in square wave
else
u(j)=1;
end
end
% Copies
uold = u;
uini = u;
% Time loop
nt=t/dt; % Number of Time Steps Required
for k=1:nt
% Space Loop
for a=2:n(i)
u(a)=uold(a)-(c*dt/dx)*(uold(a)-uold(a-1));
end
% Updating Old Velocities
uold = u;
% Plotting the Velcities Calculated
figure(i)
plot(x,uini,'r','linewidth',1.5);
hold on
plot(x,u,'g');
xlabel('Domain Length (m) ');
ylabel('Velocity (m/s) ');
legend('Initial Velocity','Final Velocities')
text = sprintf('Initial and Final Velocity values for n=%d',n(i));
title(text)
axis([0 1 0 3]) % For better Graphical Limits
grid on
pause(0.01) % Interval between Consecutive Plots
end
end
Plots and Explanation:
1. For n=20
The graph represents the initial and final velocity profiles when the number of grid points is 20. The accuracy of the final velocity profile depends on the number of grid points since 'dt' is constant, We see that the profile loses its square wave type shape and does not reach the peak velocity. This is due to the artificial diffusion that takes place over time which is nothing but the error term.
2. For n=40
This represents the velocity profile when the number of grid points is increased to 40. Here, there is an improvement in the shape of the profile. This is due to the increase in the number of grid points. Also, the peak velocity is closer to the actual velocity value.
3. For n=80
For the number of grid points equal to 80, the profile is more accurate. The peak velocity is very close to the actual value. But there is a loss of shape as the wave progresses in time. The accuracy of the solution is increases and the diffusion is reduced. The solution is stable.
4. For n=160
For this graph, we see that the solution is blown up. This is due to the fact that there is a high number of grid points. The solution is not stable and it produces oscillations even though the diffusion is reduced. The peak velocity is also not visible.
Conclusion:
This implies that the solution cannot be segmented or discretized more than a certain number of times for the accuracy, or else it results in a broken or spoilt solution. This is a particular type of phenomenon that we will be learning about and should be aware of because of an unstable solution like this of no use for our analytical purposes. We need to come up with stable solutions, with the right grid size and the right type of discretization scheme that will result in accurate and stable solutions for optimum efficiency.