1D Linear Convection (Grid points)
Objective: Write a MATLAB Code and to solve 1D linear equation
Given Data:
Length( `L` ) = 1m
Convective Coeffieient( `C` ) = 1
Time step( `dt` ) = 0.01
Grid point( `n` ) = [20,40,80,160]
Total simulation time( `t` ) = 0.4 seconds
intial velocity profile is 2 `m/s` between 0.1 and 0.3 and 1 `m/s` everywhere.
Matlab Code:
clear all
close all
clc
% Input Parameters
L = 1; % Length
c = 1; % Convective coefficient
n = [20,40,80,160]; % Grid points
t = 0.4; % Total time
dt = 0.01; % Time step
x_start = 0.1; % Start point of square wave
x_old = 0.3; % End point of square wave
nt = t/dt; % Number of time steps (nt)
% Loop
for i = 1:4
x = linspace(0,L,n(i));
dx = L/(n(i)-1);
u = ones(1,n(i));
n_start(i) = round((x_start/dx)+1);
n_end(i) = round((x_old/dx)+1);
u(:,n_start(i):n_end(i)) = 2 % Defining start and end nodes where velocity is 2m/s
uold=u;
u_initial=u;
for k = 1:nt
for j = 2:n(i)
u(j) = uold(j) - (c*(dt/dx)*(uold(j)-uold(j-1)))
end
uold=u;
% Plotting
figure(i)
plot(x,u_initial,'color','b')
hold on
plot(x,u,'color','g')
xlabel('Length')
xlabel('Velocity')
grid on
title('Velocity profile for various time steps')
axis([0 1.5 0 2.5])
end
end
Plots
Figure 1, n=20
In this plot where n=20, we can see that there is a drastic decrease in the velocity profile
the amplitude of the velocity profile keeps decreasing with length
the minimum velocity is approximately is 1.6 to 1.7`m/s`
Figure 2, n=40
In this plot where n=40, we can see that there is a significant decrease in the velocity profile
the amplitude of the velocity profile keeps decreasing with length
the minimum velocity is approximately is between 1.7 to 1.8`m/s`
Figure 3, n=80
In this plot where n=80, we can see that there is a gradual decrease in the velocity profile, The change in the velocity profile with respect to length is not a major change. Hence we can tell that the amplitude is almost constant.
the min and max velocity very very close 2`m/s`
Figure 4, n=160
In Figure 4, there is a disturbance in the velocity profile. We can see that there is a blow-up and it noticed that ripples are formed in the plot making it unstable.
Conclusion
From the above figures 1,2,3 & 4, we can tell that with the increase in grid spacing may lead to ripples. But at n=80 the optimum results are achieved and then decreases.