All Courses
All Courses
Aim: To Derive 4th order approximations for second-order derivative. Theory: the taylor series for function is written as, f(x+δx)=f(x)+∂f∂x.(δx)+∂2f∂x2.(δx22)+f(x+δx)=f(x)+∂f∂x.(δx)+∂2f∂x2.(δx22)+........(1) the abvoe equation is valid only if : if the number of terms are infinite and the…
Himanshu Chavan
updated on 02 Jul 2021
Aim: To Derive 4th order approximations for second-order derivative.
Theory:
the taylor series for function is written as,
f(x+δx)=f(x)+∂f∂x.(δx)+∂2f∂x2.(δx22)+f(x+δx)=f(x)+∂f∂x.(δx)+∂2f∂x2.(δx22)+........(1)
the abvoe equation is valid only if :
If u(i,j) is the x component of velocity at point u(i,j ); u(i+1,j) is x component of velocity at pount(i+1,j)
Then from equation 1:
u(i+1,j)=u(i,j)+∂u∂x∂u∂x(i,j).δxδx+δ2uδx2δ2uδx2(i,j).(δx22)(δx22)+.........(2)
solving for ∂u∂x(i,j)∂u∂x(i,j) we get;
∂u∂x(i,j)=u(i+1,j)-u(i,j)∂x-∂2u∂x2(i,j).(∂x2)+∂u∂x(i,j)=u(i+1,j)−u(i,j)∂x−∂2u∂x2(i,j).(∂x2)+.................(3)
Then term in the RHS of equation 3 containing u(i+j) - u(i,j) is the finite-difference. The other term that is neglected is the truncation error.
Since in the majority of the CFD, a first-order approximation is not sufficient. WE turn our heads to central difference schemes.
∂2u∂x(x2)=u(i+j,j)-2.u(i,j)+u(i-j,j)δx2+∂2u∂x(x2)=u(i+j,j)−2.u(i,j)+u(i−j,j)δx2+errors ....................(4)
Taylor table is a method that comes up with schemes that meet the targeted accuracy.
The formula for several nodes is as follow:
Since the order is second and the order of approximation is 4, the number of nodes in the central difference scheme is 5, and the number of nodes is skewed right-sided, and skewed left-sided schemes are 6.
CENTRAL DIFFERENCING SCHEME:
We take up a hypothetical equation like:
(∂2u∂x2)x2=a.f(i-2)+b.f(i-1)+c.f(i)+d.f(i+1)+e.f(i+2)(∂2u∂x2)x2=a.f(i−2)+b.f(i−1)+c.f(i)+d.f(i+1)+e.f(i+2) ................(5)
Here the a,b,c,d,e are coefficients, The values of these coefficients are need to be found out.
The mode of Operandi will be like this:
From Equation 5:
a.f(i - 2) = a.f(i) +a.∂u∂x.(-2.δx1)∂u∂x.(−2.δx1) + a.(∂2u∂x2).((-2.δx)24)(∂2u∂x2).((−2.δx)24) + a.∂3u∂x3.((-2.δx)36)+a.∂4u∂x4.(-2.δx424)∂3u∂x3.((−2.δx)36)+a.∂4u∂x4.(−2.δx424).........(6)
b.f(i-1) = b.f(i) + b.∂u∂x.(-δx1)+b.∂2u∂x2.((-δx)22)+b.∂3u∂x3.((-δx)36)b.∂u∂x.(−δx1)+b.∂2u∂x2.((−δx)22)+b.∂3u∂x3.((−δx)36)+b.∂4u∂x4.((-δx)424)b.∂4u∂x4.((−δx)424)..............(7)
c.f(i) = c.f(i).......................(8)
d. f(i+1) = d.f(i) +d.∂u∂x.δx+d.∂2x∂x2.((δx)22)+d.∂3u∂x3.((δx)36)+d.∂4u∂x4.((δx)424)d.∂u∂x.δx+d.∂2x∂x2.((δx)22)+d.∂3u∂x3.((δx)36)+d.∂4u∂x4.((δx)424)..............(9)
e.f(i+2) = e.f(i) + e.∂u∂x.(2.δx)+e.∂2u∂x2.((2.δx)22)+e.∂3u∂x3.((2.δx)36)+e.∂4u∂x4.((2.δx)424)e.∂u∂x.(2.δx)+e.∂2u∂x2.((2.δx)22)+e.∂3u∂x3.((2.δx)36)+e.∂4u∂x4.((2.δx)424)..................(10)
Rearranging, we get:
∂2u∂x2∂2u∂x2 = f(i)(a+b+c+d+e) + ∂u∂x.δx∂u∂x.δx.(-2.a + (-b) + d +2.e) +∂2u∂x2.(δx)2∂2u∂x2.(δx)2.(2a+b2+d2+2e+b2+d2+2e) + ∂3u∂x3.(δx3).((-8a6)+(-b6)+d6+8e6)∂3u∂x3.(δx3).((−8a6)+(−b6)+d6+8e6) + ∂4u∂x4.(δx4).(16a24+b24+d24+16e24)∂4u∂x4.(δx4).(16a24+b24+d24+16e24).......................(11)
Now writting equation 11 in tabular form, we get the Taylor Table as follow:
f(i) ∂u∂x.δx∂u∂x.δx ∂2u∂x2.(δx2)∂2u∂x2.(δx2) ∂3u∂x3.(δx3)∂3u∂x3.(δx3) ∂4u∂x4.(δx4)∂4u∂x4.(δx4)
a.f(i-2) a -2a 2a -8a68a6 16a2416a24
b.f(i-1) b -b b2b2 -(b6)−(b6) b24b24
c.f(i) c 0 0 0 0
d.f(i+1) d d d/2` b6b6 d24d24
e.f(i+2) e 2e 2e 8e68e6 16e2416e24
Aprroximating and adding up the coefficient with the logic of the terms f(i),∂u∂x,∂3u∂x3,∂4u∂x4∂u∂x,∂3u∂x3,∂4u∂x4will be approximated to 0 and the coefficients of ∂2u∂x2∂2u∂x2will be approximated to 1 , we get the following set of equation:
a+b+c+d+e =0
-2a-b+d+2e=0
2a+b/2+d/2+2e=1
-(8/6)*a-b/6+d/6+(8e/6)=0
(16a/24)+b/24+d/24+(16e/24)=0
Here we have 5 eqautions and 5 unknown
To solve this we we will write this in matrix form:
[11111-2-10122120122-86-1601686162412401241624]⋅[abcd]=[00100]⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣11111−2−10122120122−86−1601686162412401241624⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦⋅⎡⎢ ⎢ ⎢ ⎢⎣abcd⎤⎥ ⎥ ⎥ ⎥⎦=⎡⎢ ⎢ ⎢ ⎢ ⎢ ⎢⎣00100⎤⎥ ⎥ ⎥ ⎥ ⎥ ⎥⎦
Solving thr above matrix we get a=(-1/12), b=(4/3), c=(-5/2), d=(4/3), e=(-1/12)
So by inserting the above values of the coefficients in the main equation:
∂2u∂x2=(-112).f(i-2)+(43).f(i-1)+(-52).f(i)+(43).f(i+1)+(-112).f.(i+2)∂2u∂x2=(−112).f(i−2)+(43).f(i−1)+(−52).f(i)+(43).f(i+1)+(−112).f.(i+2)..................(**)
Nownfor skewed right sided and skewed left sided schemes the same above way is followed to create the Taylor table. Herenwe directly input the table by not repeating the procedure:
SKEWED RIGHT SIDED DIFFERENCE:
The hypothetical equation is:
∂2u∂x2∂2u∂x2=a.f(i) + b. f(i+1) + c. f(i+2) + d. f(i+3) + e. f(i+4) + g.f(i+5)
Expanding each of the above terms in the order of taylor series ; we obtain the Taylor table as :
f(i) ∂u∂x.δx∂u∂x.δx ∂2u∂x2.(δx2)∂2u∂x2.(δx2) ∂3u∂x3.(δx3)∂3u∂x3.(δx3) ∂4u∂x4.(δx4)∂4u∂x4.(δx4) ∂5u∂x5.(δx5)∂5u∂x5.(δx5)
a.f(i) a 0 0 0 0 0
b.f(i+1) b b b/2 b/6 b/24 b/120
c.f(i+2) c 2c 2c 8/6*c 16/24*c 32/12*c
d.f(i+3) d 3d 9/2*d 27/6*d 81/24*d 243/120*d
e.f(i+4) e 4e 8*e 64/6*e 256/24*e 1024/120*e
g.f(i+5) g 5g 25/2*g 125/6*g 625/24*g 3125/120*g
Solving the above equation by applying the same logic that the term containing second order derivative is approximated to 1 and all others are 0, we get the coefficients as:
a=154,b=(-776),c=(1076),d=(-13),e=(6112),g=(-56)154,b=(−776),c=(1076),d=(−13),e=(6112),g=(−56)
Inserting the values in the parent equation we get:
∂2u∂x2=(154).f(i)+(-776).f(i+1)+(1076).f(i+2)+(-13).f(i+3)+(6112).f(i+4)+(-56).f(i+5)∂2u∂x2=(154).f(i)+(−776).f(i+1)+(1076).f(i+2)+(−13).f(i+3)+(6112).f(i+4)+(−56).f(i+5)
SKEWED LEFT-SIDED DIFFERENCING:
In this scheme we will consider the discretization points at the left side. The hypothetical equation for this scheme is written as :
∂2u∂x2∂2u∂x2=a.f(i) + b.f(i-1) + c.f(i-2) + d.f(i-3) + e.f(i-4) + g.f(i-5)
By expanding each and every terms of the RHS according to the taylor series we get:
f(i) ∂u∂x.δx∂u∂x.δx ∂2u∂x2.(δx2)∂2u∂x2.(δx2) ∂3u∂x3.(δx3)∂3u∂x3.(δx3) ∂4u∂x4.(δx4)∂4u∂x4.(δx4) ∂5u∂x5.(δx5)∂5u∂x5.(δx5)
a.f(i) a 0 0 0 0 0
b.f(i-1) b -b b2b2 -b6 -b24 -b120
c.f(i-2) c -2c 2c -86c 1624c -32120c
d.f(i-3) d -3d 92d -276d 8124d -243120d
e.f(i-4) e -4e 8e -646e 25624e -1024120e
g.f(i-5) g -5g 252g -1256g 32524g -3125120g
In matrix form the equations stand as:
[1111110-1-2-3-4-501229282520-16-86-276-246-125601241624812425624625240-112-32120-243120-1024120-3125120]⋅[abcdeg] =[001000]
Solving it by matrix inversion method in matlab, we get the coefficients as:
a= 3.75 b= -12.8333 c=17.8333 d=13.000 e=5.083 g=-0.8333
Inserting the values of coefficients:
∂2u∂x2=3.75.f(i) + (-12.833).f(i-1) + 17.8333.f(i-2) + 13.00.f(i-3) + 5.083.f(i-4) + (-0.8333).f(i-5)
CODE EXPLANATION:
We aim to compare the errors calculated through the three different schemes.
Function Codes:
function left_error = left_skewed_difference(x,dx)
% analytical deivative
analytical_derivative = -2*exp(x)*sin(x);
a= (15/4);
b= (-77/6);
c= (107/6);
d= (-13);
e= (61/12);
g= (-5/6);
left_scheme= (a*exp(x)*cos(x)+ b*exp(x-dx)*cos(x-dx)+ c*exp(x-2*dx)*cos(x-2*dx)+d*exp(x-3*dx)*cos(x-3*dx)+e*exp(x-4*dx)*cos(x-4*dx)+g*exp(x-5*dx)*cos(x-5*dx))/(dx^2);
left_error= abs(left_scheme-analytical_derivative);
end
function right_error = right_skewed_difference(x,dx)
% analytical deivative
analytical_derivative = -2*exp(x)*sin(x);
a= (15/4);
b= (-77/6);
c= (107/6);
d= (-13);
e= (61/12);
g= (-5/6);
right_scheme= (a*exp(x)*cos(x)+b*exp(x+dx)*cos(x+dx)+c*exp(x+2*dx)*cos(x+2*dx)+d*exp(x+3*dx)*cos(x+3*dx)+e*exp(x+4*dx)*cos(x+4*dx)+g*exp(x+5*dx)*cos(x+5*dx))/(dx^2);
right_error= abs(right_scheme-analytical_derivative);
end
function central_error = central_skewed_difference(x,dx)
% analytical deivative
analytical_derivative = -2*exp(x)*sin(x);
a= (-1/12);
b= (4/3);
c= (-5/2);
d= (4/3);
e= (-1/12);
central_difference_scheme= (a*exp(x-2*dx)*cos(x-2*dx) + b*exp(x-dx)*cos(x-dx)+c*exp(x)*cos(x)+d*exp(x+dx)*cos(x+dx)+e*exp(x+2*dx)*cos(x+2*dx))/(dx^2);
central_error= abs(central_difference_scheme-analytical_derivative);
end
MATLAB CODE:
clear all
close all
clc
%analytical function =exp(x)*cos(x)
%analytical derivative =-2*exp(x)*sin(x)
x= pi/3;
dx= linspace(pi/400,pi/4,50);
for i= 1:length(dx)
central_difference_scheme_error(i) = central_skewed_difference(x,dx(i));
right_skewed_scheme_error(i) = right_skewed_difference(x,dx(i));
left_skewed_scheme_error(i) = left_skewed_difference(x,dx(i));
end
%plotting the error graphs
figure(1)
loglog(dx,right_skewed_scheme_error,'color','b','marker','diamond')
hold on
loglog(dx,left_skewed_scheme_error, 'color','g','marker','*')
hold on
loglog(dx,central_difference_scheme_error, 'color','r','marker','.')
grid on
xlabel('grid size')
ylabel('error')
legend('skewed right sided ','skewed left sided', 'central difference schmene')
OUTPUT:
CONCLUSION:
For the same value of dx, the central difference scheme gives a minimum error than the other two schemes.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Simulation Of A 1D Super-sonic Nozzle Using Macormack Method
AIM: To simulate the isentropic flow through a Quasi 1D subsonic - supersinic nozzle by deriving both the conservation and non-conservation forms of the governing equations and solve them by implementing Macormacks's technique using MATLAB. Objective: Determine the steady-state temperature distribution for the flow field…
19 Oct 2021 11:02 AM IST
Project 1 : CFD Meshing for Tesla Cyber Truck
ADVANCED CFD MESHING OF THE TESLA CYBER TRUCK l. OBJECTIVE 1. Geometry Clean-up of the model 2. Generation of surface mesh on the model. 3. Analyze and correct the quality of the mesh. 4. Setting…
08 Oct 2021 10:34 PM IST
Week 4 Challenge : CFD Meshing for BMW car
ADVANCED CFD MESHING OF THE BMW M6 MODEL USING ANSA l. OBJECTIVE 1. Detailed geometry clean-up of the BMW M6 Model. 2. Generation of a surface mesh on the model. 3. Analyze and correct the quality of the mesh. 4. Setting up a wind…
29 Sep 2021 10:51 PM IST
Related Courses