Sei sulla pagina 1di 7

EME 451 Computational Fluid Dynamics CFD

Homework Set 1

EME 451 Computational Fluid Dynamics CFD


Homework Set 1 Question 2

Name
Chan Min Xhao
Chin Mun Xue
Foong XiPeng

Matric Number
125190
125192
125194

School
Aerospace Engineering

Date of Submission
26th of September 2017

Page | 1
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

Ordinary Differential Equation

𝑢𝑡 = 𝑎𝑢 (1)

The problem requires us to find the solution to the ordinary differential equation (ODE), Equation (1)
which has the initial condition, u(0) = 1 at t = 2. The equation has the exact solution shown below as
in Equation (2).

𝑢 = 𝑢0 𝑒 𝑎𝑡 (2)

There are 2 numerical methods: Taylor series and Runge-Kutta used in order to solve the given ODE.

Taylor series (1st order)

𝑢𝑛+1 = 𝑢𝑛 (1 + 𝛼𝛥𝑡 𝑝 ) (3)

Manipulating Variable p
Figure 1 shows the graph of u against t with manipulating variable p. The p is set to 0.9 (<1), 1 (=1)
and 1.1 (>1). It is clearly shown that when p is equal to 1 (=1), the solution of the numerical method
approaches that of the analytical method.

When p is equal to 0.9 (<1) or 1.1 (>1), the solution of the numerical method deviates from that of the
analytical method. For the former, there is a sudden surge or spike while the latter takes a very long
time to get close to the curve of analytical solution.

In conclusion, the numerical method is only valid when p is equal to 1.

Figure 1: u against t with Manipulating Variable p

Page | 2
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

Manipulating Variable a

Figure 2: u against t with Manipulating Variable a

Figure 2 shows the graph of u against t with manipulating variable a. The a is set to 2 (>0), 1/2 (>0)
and -1/2 (<0). It is clearly shown that only when a is equal to 2 (>0), the solution of the numerical
method approaches that of the analytical method.

When a is equal to 1/2 (>0), the solution of the numerical method approaches the solution of the
analytical method extremely slowly. When a is equal to -1/2 (<0), the solution of the numerical
method approaches the x- axis (y=0) but will never equal to 0. It has deviated from the actual solution.

In conclusion, the numerical method is only valid when α is equal to a.

Page | 3
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

Manipulating Variable Δt

Figure 3: u against t with Manipulating Variable Δt

Figure 2 shows the graph of u against t with manipulating variable Δt. The Δt is set to 1, 0.01 and
0.001. It is clearly shown with a smaller time step, the curve of numerical solutions is closer to that of
analytical solution.

In conclusion, the smaller the time step, the more accurate the numerical solutions. However, it should
be mentioned that a smaller time step will result in a longer computation time.

Page | 4
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

Runge-Kutta (2nd order)

𝛥𝑡 (4)
𝑢∗ = 𝑢𝑛 (1 + 𝛼 )
2

𝑢𝑛+1 = 𝑢𝑛 + 𝛼𝛥𝑡𝑢∗ (5)

Comparison of Numerical Methods with Exact Solution and Verification of Order of Accuracy
The table below lists the amount of numerical work required for both first order and second order
methods to achieve 1% and 0.01% accuracy, represented in number of intervals required and their
corresponding time step. The calculated results for verifying the order of accuracy are listed as well.

Table 1: Full Results of Accuracy Calculation and Order of Accuracy Verification


First Order Second Order
Accuracy 1% 0.01% 1% 0.01%
Number of Intervals 794 79994 32 326
Time Step 2.51889×10-3 2.50019×10-5 0.0625 6.13497×10-3
Order of Accuracy 0.76973 0.86918 1.68160 1.80926

The difference in the number of intervals between the first order and second order methods is
astounding. Even at 1% accuracy, the first order method requires at least 794 intervals between 0 and
2, compared to a merely 32 by the second order method. This means it takes almost 25 times as much
interval for the first order method to achieve 1% accuracy compared to the second order method.

Moving up to 0.01% accuracy, the difference is even ginormous. Now the first order method requires
almost 80,000 intervals to reach within 0.01% range of the actual solution, whereas the second order
method needs just 326 intervals. This time, the first order method takes about 245 times as much
intervals as the second order method.

The time steps are calculated by formula below:

2 (6)
𝑇𝑖𝑚𝑒 𝑆𝑡𝑒𝑝, ∆𝑡 =
𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝐼𝑛𝑡𝑒𝑟𝑣𝑎𝑙𝑠, 𝑁

To verify the order of accuracy of the numerical methods, calculations are performed for both
methods at the two accuracies using the error value (not percentage) and the time step:

log10 𝑒𝑟𝑟𝑜𝑟 (7)


𝑂𝑟𝑑𝑒𝑟 𝑜𝑓 𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
log10 ∆𝑡

For both cases, the calculated order of accuracy is close to their actual values (first order ≈ 1, second
order ≈ 2). Therefore, it can be safely verified that the numerical methods used in this analysis are
indeed first and second order methods. One thing worth mentioning is that as the accuracy is
improved, the calculated value approaches closer to the actual value.

Page | 5
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

MATLAB Codes

1. Verifying the Correct Choices for Variables p and a, plus the Effects of Δt on Accuracy
clc;clear all;close all; legend({'p=0.9','p=1','p=1.1','Analytical'},'location','northwest')
title('Manipulating variable p')
%Given conditions xlabel('time,t');ylabel('u')
t0 = 0; hold off
u0 = 1;
tEnd=2; %Manipulating variable 'a'
delta_t = 0.01; figure(2)
changing_a = [2 1/2 -1/2]; hold on
changing_delta_t = [1 0.1 0.01];
changing_p = [0.9 1 1.1]; for j = 1:3
a = 2; for i = 1:N_a
p = 1; U_a(i+1) = U_a(i)+delta_t*changing_a(j)*U_a(i)^p;
end
%Initializing solutions plot(T,U_a,plotstyle{j})
N = (tEnd-t0)/delta_t; end
N_p = (tEnd-t0)/delta_t;
N_a = (tEnd-t0)/delta_t; plot(T,U_True,'r')
N_t = (tEnd-t0)./changing_delta_t; legend({'a=2','a=1/2','a=-1/2','Analytical'},'location','northwest')
T = t0:delta_t:tEnd; title('Manipulating variable a')
U_1(1) = u0; xlabel('time,t');ylabel('u')
U_2(1) = u0; hold off
U_p(1) = u0;
U_a(1) = u0; %Manipulating variable 'delta t'
U_t(1) = u0; figure(3)
plotstyle = {'-k','-b','-g'}; hold on
U_True=u0*exp(a*T);
for j = 1:3
%Solving using Euler's explicit method changing_T = t0:changing_delta_t(j):tEnd;
%Manipulating variable 'p' for i = 1:N_t(j)
figure(1) U_t(i+1) = U_t(i)+changing_delta_t(j)*a*U_t(i)^p;
hold on end
plot(changing_T,U_t,plotstyle{j})
for j = 1:3 end
for i = 1:N_p
U_p(i+1) = U_p(i)+delta_t*a*U_p(i)^changing_p(j); plot(T,U_True,'r')
end legend({'delta t = 1','delta t = 0.01','delta t =
plot(T,U_p,plotstyle{j}) 0.001','Analytical'},'location','northwest')
end title('Manipulating variable delta t')
xlabel('time,t');ylabel('u')
plot(T,U_True,'r') hold off

Page | 6
EME 451 Computational Fluid Dynamics CFD
Homework Set 1

2. Comparison of Numerical Methods, and the Verification of Order of Accuracy


clc;clear all;close all;
N1b = N1;
%Given conditions error1b = error1;
t0 = 0; delta_t1b = delta_t1;
u0 = 1; OOA1b = log10(error1)/log10(delta_t1);
tEnd=2;
a = 2; %Initializing second order solutions
p = 1; N2 = 1;
U_2(1) = u0;
%Analytical solution error2 = 1;
U_True=u0*exp(a*tEnd);
%1% accuracy
%Initializing first order solutions while error2>0.01
N1 = 1; N2 = N2+1;
U_1(1) = u0; delta_t2 = (tEnd-t0)/N2;
error1 = 1; for i = 1:N2
U_2(i+1) = U_2(i)*(1+delta_t2*a*(1+delta_t2*a/2));
%1% accuracy end
while error1>0.01 error2 = abs((U_True-U_2(end))/U_True);
N1 = N1+1; end
delta_t1 = (tEnd-t0)/N1;
for i = 1:N1 N2a = N2;
U_1(i+1) = U_1(i)*(1+delta_t1^p*a); error2a = error2;
end delta_t2a = delta_t2;
error1 = abs((U_True-U_1(end))/U_True); OOA2a = log10(error2)/log10(delta_t2);
end
%0.01% accuracy
N1a = N1; while error2>0.0001
error1a = error1; N2 = N2+1;
delta_t1a = delta_t1; delta_t2 = (tEnd-t0)/N2;
OOA1a = log10(error1)/log10(delta_t1); for i = 1:N2
U_2(i+1) = U_2(i)*(1+delta_t2*a*(1+delta_t2*a/2));
%0.01% accuracy end
while error1>0.0001 error2 = abs((U_True-U_2(end))/U_True);
N1 = N1+1; end
delta_t1 = (tEnd-t0)/N1;
for i = 1:N1 N2b = N2;
U_1(i+1) = U_1(i)*(1+delta_t1^p*a); error2b = error2;
end delta_t2b = delta_t2;
error1 = abs((U_True-U_1(end))/U_True); OOA2b = log10(error2)/log10(delta_t2);
end

Page | 7

Potrebbero piacerti anche