evaluation a drag over a pre-designed model of a car using CFD
numerical solution a t=0.4seconds for different values of dt
dt is the interval between the time step. Has the value of dt becomes smaller the accuracy increases and error decreses. For dt = 1e-1 the product (c*dt/dx) is greater than 1 and the solution is blowing up.
clear all
close all
clc
%defining all the constant values
L = 1;
n = 81;
c = 1;
%calculation
x = linspace(0,L,n);
dx = L/(n-1);
x_start = find(x==0.1);
x_stop = find(x==0.3);
%initialize arrays and apply boundary conditions
u = ones(1,n);
%u(1) = 1;
u(x_start:x_stop) = 2;
uold = u;
u_initial = u;
nt = 40;
%time loop
for k = 1:nt
%space loop
dt = 1e-4;
for i=2:n
u(i)=uold(i)-(((c*dt)/dx)*(uold(i)-uold(i-1)));
end
uold = u;
end
subplot(1,4,1)
plot(x,u_initial,\'b\');
hold on
plot(x,u,\'r\');
title(\'For dt=1e-4\');
for k = 1:nt
%space loop
dt = 1e-3;
for i=2:n
u(i)=uold(i)-(((c*dt)/dx)*(uold(i)-uold(i-1)));
end
uold = u;
end
subplot(1,4,2)
plot(x,u_initial,\'b\');
hold on
plot(x,u,\'r\');
title(\'For dt=1e-3\');
for k = 1:nt
%space loop
dt = 1e-2;
for i=2:n
u(i)=uold(i)-(((c*dt)/dx)*(uold(i)-uold(i-1)));
end
uold = u;
end
subplot(1,4,3)
plot(x,u_initial,\'b\');
hold on
plot(x,u,\'r\');
title(\'For dt=1e-2\');
for k = 1:nt
%space loop
dt = 1e-1;
for i=2:n
u(i)=uold(i)-(((c*dt)/dx)*(uold(i)-uold(i-1)));
end
uold = u;
end
subplot(1,4,4)
plot(x,u_initial,\'b\');
hold on
plot(x,u,\'r\');
title(\'For dt=1e-1\');