wpi computational fluid dynamics iphoenics/site_phoenics/apostilas/cfd... · 2003-09-23 · wpipi...
TRANSCRIPT
Computational Fluid Dynamics IPPPPIIIIWWWW
ElementaryNumerical Analysis:
Finite Difference Approximations-II
Instructor: Hong G. ImUniversity of Michigan
Fall 2001
Computational Fluid Dynamics IPPPPIIIIWWWW• The linear advection-diffusion equation• Finite difference approximations• Finite Difference Approximation of the linear
advection-diffusion equation• Accuracy• Stability• Consistency• Higher order finite difference approximations in
space• Time integration: implicit versus explicit and higher
accuracy • Finite Volume Approximations
Outline
Computational Fluid Dynamics IPPPPIIIIWWWW
Solving a partial differential
equation
Computational Fluid Dynamics IPPPPIIIIWWWW
∂f∂t
+ U∂f∂x
= D∂ 2 f∂x 2
We will use the model equation:
Although this equation is much simpler than the full Navier Stokes equations, it has both an advection term and a diffusion term. Before attempting to solve the equation, it is useful to understand how the analytical solution behaves.
to demonstrate how to solve a partial differential equation numerically.
Model Equations
Computational Fluid Dynamics IPPPPIIIIWWWWFor initial conditions of the form:
)2sin()0,( kxAtxf π==
))(2sin(),(2)2( UtxkAetxf tkD −= − ππ
It can be verified by direct substitution that the solution is given by:
which is a decaying traveling wave
Model Equations
k = 1.0U = 1.0D = 0.05A = 1.0
Computational Fluid Dynamics IPPPPIIIIWWWW
Finite Difference Approximations of
the Derivatives
Computational Fluid Dynamics IPPPPIIIIWWWWDerive a numerical approximation to the governing equation, replacing a relation between the derivatives by a relation between the discrete nodal values.
h h
f(t,x-h) f(t,x) f(t,x+h)∆ t
∆ t
f (t)
f (t + ∆t)
f (t + 2∆t)
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
The Time Derivative is found using a FORWARD EULER method. The approximation can be found by using a Taylor series
h h
f(x-h) f(x) f(x+h)∆ t
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
TheTime Derivative
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
f (t + ∆t) = f (t) +∂f (t)
∂t∆t +
∂ 2 f (t)∂t2
∆t2
2+"
∂f (t)∂t
=f (t + ∆t) − f (t)
∆t+
∂ 2 f (t)∂t 2
∆t2
+"
Solving this equation for the time derivative gives:
Time derivative
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
TheSpatial Derivative:
First Order
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
When using FINITE DIFFERENCE approximations, the values of f are stored at discrete points.
h h
f(x-h) f(x) f(x+h)
The derivatives of the function are approximated using a Taylor series:
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
Subtracting the second equation from the first:
f ( x + h) = f (x) +∂f (x)
∂xh +
∂ 2 f (x)∂x 2
h2
2+
∂ 3 f (x)∂x3
h3
6+
∂ 4 f (x)∂x 4
h4
24+"
f ( x − h) = f (x) −∂f (x)
∂xh +
∂ 2 f (x)∂x 2
h2
2−
∂ 3 f ( x)∂x3
h3
6+
∂ 4 f (x)∂x 4
h4
24−"
!!f (x + h) − f (x − h) = 2 ∂f (x)
∂xh + 2 ∂ 3 f (x)
∂x3h3
6+"
Start by expressing the value of f(x+h) and f(x-h) in terms of f(x)
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
!!
∂f (x)∂x
=f (x + h) − f (x − h)
2h+
∂ 3 f (x)∂x3
h2
6+"
Rearranging this equation to isolate the first derivative:
f (x + h) − f (x − h) = 2 ∂f (x)∂x
h + 2 ∂ 3 f (x)∂x3
h3
6+"
Finite Difference Approximations
The result is:
Computational Fluid Dynamics IPPPPIIIIWWWW
TheSpatial Derivative:
Second Order
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
!!f ( x + h) = f (x) +
∂f (x)∂x
h +∂ 2 f (x)
∂x 2h2
2+
∂ 3 f (x)∂x3
h3
6+
∂ 4 f (x)∂x 4
h4
24+"
f ( x − h) = f (x) −∂f (x)
∂xh +
∂ 2 f (x)∂x 2
h2
2−
∂ 3 f ( x)∂x3
h3
6+
∂ 4 f (x)∂x 4
h4
24−"
Start by expressing the value of f(x+h) and f(x-h) in terms of f(x)
Adding the second equation to the first:
!!f (x + h) + f (x − h) = 2 f (x) + 2 ∂f 2(x)
∂x2h2
2+ 2 ∂ 4 f (x)
∂x4h4
24+"
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
!!
∂ 2 f (x)∂x2 =
f (x + h) − 2 f + f (x − h)h2 +
∂ 4 f (x)∂x4
h2
12+"
f (x + h) + f (x − h) = 2 f (x) + 2 ∂f 2(x)∂x2
h2
2+ 2 ∂ 4 f (x)
∂x4
h4
24+"
Rearranging this equation to isolate the second derivative:
The result is:
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
Solving the partial differential equation
Finite Difference Approximations
Computational Fluid Dynamics IPPPPIIIIWWWW
∂f∂t
+ U∂f∂x
= D∂ 2 f∂x 2
A numerical approximation to
Is found by replacing the derivatives by the following approximations
Finite Difference Approximations
∂f∂t
j
n
+ U ∂f∂x
j
n
= D ∂ 2 f∂x2
j
n
h h
fjn+1
fjn fj +1
nfj −1n ∆t
Computational Fluid Dynamics IPPPPIIIIWWWW
f jn = f (t, x j )
f jn+1 = f (t + ∆t, x j )
f j +1n = f (t, x j + h)
f j −1n = f (t, x j − h)
Using the shorthand notation
Finite Difference Approximations
∂f∂t
j
n
=fj
n+1 − fjn
∆t+ O(∆t)
∂f∂x
j
n
=fj +1
n − fj −1n
2h+ O(h2 )
∂ 2 f∂x 2
j
n
=fj +1
n − 2 fjn + fj −1
n
h2 + O(h2 )
gives
Computational Fluid Dynamics IPPPPIIIIWWWWSubstituting these approximations into:
gives
∂f∂t
+ U∂f∂x
= D∂ 2 f∂x 2
Finite Difference Approximations
f jn+1 − fj
n
∆t+ U
f j +1n − fj −1
n
2h= D
fj +1n − 2 f j
n + f j −1n
h2 + O(∆t, h2)
fjn+1 = fj
n − U∆t2h
( fj +1n − fj −1
n ) + D∆th2 ( fj +1
n − 2 f jn + fj −1
n )
Solving for the new value and dropping the error terms yields
Computational Fluid Dynamics IPPPPIIIIWWWW
fjn+1 = fj
n − U∆t2h
( fj +1n − fj −1
n ) + D∆th2 ( fj +1
n − 2 f jn + fj −1
n )
The value of every point at level n+1 is given explicitly in terms of the values at the level n
h h
fjn+1
fjn fj +1
nfj −1n ∆t
Finite Difference Approximations
Thus, given f at one time (or time level), f at the next time level is given by:
Computational Fluid Dynamics IPPPPIIIIWWWW
Example
Computational Fluid Dynamics IPPPPIIIIWWWW
A short MATLAB programThe evolution of a sine wave is followed as it is advected and diffused. Two waves of the infinite wave train are simulated in a domain of length 2. To model the infinite train, periodic boundary conditions are used. Compare the numerical results with the exact solution.
Computational Fluid Dynamics IPPPPIIIIWWWW% one-dimensional advection-diffusion by the FTCS schemen=21; nstep=100; length=2.0; h=length/(n-1); dt=0.05; D=0.05;f=zeros(n,1); y=zeros(n,1); ex=zeros(n,1); time=0.0;for i=1:n, f(i)=0.5*sin(2*pi*h*(i-1)); end; % initial conditionsfor m=1:nstep, m, time
for i=1:n, ex(i)=exp(-4*pi*pi*D*time)*...0.5*sin(2*pi*(h*(i-1)-time)); end; % exact solution
hold off; plot(f,'linewidt',2); axis([1 n -2.0, 2.0]); % plot solutionhold on; plot(ex,'r','linewidt',2);pause; % plot exact solutiony=f; % store the solutionfor i=2:n-1,
f(i)=y(i)-0.5*(dt/h)*(y(i+1)-y(i-1))+...D*(dt/h^2)*(y(i+1)-2*y(i)+y(i-1)); % advect by centered differences
end;f(n)=y(n)-0.5*(dt/h)*(y(2)-y(n-1))+...
D*(dt/h^2)*(y(2)-2*y(n)+y(n-1)); % do endpoints forf(1)=f(n); % periodic boundariestime=time+dt;
end;
Computational Fluid Dynamics IPPPPIIIIWWWW
Evolution forU=1; D=0.05; k=1
N=21∆t=0.05
Exact
Numerical
Computational Fluid Dynamics IPPPPIIIIWWWW
Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWWIt is clear that although the numerical solution is qualitatively similar to the analytical solution, there are significant quantitative differences.
The derivation of the numerical approximations for the derivatives showed that the error depends on the size of h and ∆t.
First we test for different ∆t.
Number of time steps= T/ ∆t
Computational Fluid Dynamics IPPPPIIIIWWWW
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1m = 10, time = 0.50Evolution
forU=1; D=0.05; k=1
N=21∆t=0.05
Exact
Numerical
Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWW
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1m = 20, time = 0.50Repeat with
a smaller time-step∆t=0.025
Exact
Numerical
Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWW
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1m = 40, time = 0.50Repeat with
a smaller time-step∆t=0.0125
Exact
Numerical
Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWW
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1
x
f(x,t)
0 0.5 1 1.5 2
-1
-0.5
0
0.5
1m = 1000, time = 0.50
U=1; D=0.05; k=1
N=201∆t=0.0005
Exact
Numerical
Accuracy
Very fine spatial resolution and a small time step
Computational Fluid Dynamics IPPPPIIIIWWWW
Quantifying the ErrorI. Order of Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWW
E = h ( fj − fexact )2
j =1
N
∑
n=11; E = 0.1633n=21; E = 0.0403n=41; E = 0.0096n=61; E = 0.0041n=81; E = 0.0022n=101; E = 0.0015n=121; E = 0.0011n=161; E = 9.2600e-04
Exact
Numerical
Order of Accuracy
time=0.50
Computational Fluid Dynamics IPPPPIIIIWWWW
100 101 10210-4
10-3
10-2
10-1
100
Accuracy. Effect ofspatial resolution
1/ h
dt=0.0005N=11 to N=161 E
Order of Accuracy
time=0.50
Computational Fluid Dynamics IPPPPIIIIWWWW
E = Ch2 = CLn
2
= CL2n−2
E = ˜ C n−2
ln E = ln ˜ C n−2( )= ln ˜ C − 2ln n
On a log-log plot, the E versus n curve should therefore have a slope -n
If the error is of second order:
Order of Accuracy
Computational Fluid Dynamics IPPPPIIIIWWWW
100 101 10210-4
10-3
10-2
10-1
100Accuracy. Effect ofspatial resolution
21
1/ h
dt=0.0005
N=11 to N=161E
Order of Accuracy
time=0.50
?
Computational Fluid Dynamics IPPPPIIIIWWWW
Why is does the error deviate from the line for the highest values of N?
Number of Steps, N = 1/h
Erro
r Total
Roundoff
Truncation
Computational Fluid Dynamics IPPPPIIIIWWWW
Quantifying the ErrorII. Modified Wave Number
Computational Fluid Dynamics IPPPPIIIIWWWW
Order of Accuracy
- how mesh refinement improves the accuracy
Modified Wave Number
- how the difference scheme maintains accuracy at high wave numbers
Modified Wave Number
Computational Fluid Dynamics IPPPPIIIIWWWW
ikxexf =)(
Consider a pure harmonic of period L
where k can take on any of the following values
2/,22/,12/2 NNNnnL
k "+−+−== π
Modified Wave Number
The exact derivative isikxikexf =′ )(
We now ask how the second order central difference computes the derivative of f
Computational Fluid Dynamics IPPPPIIIIWWWW
.1,2,1,0, −== NjjNLx j "
Discretize the x axis with a uniform mesh
Substituting
Modified Wave Number
NLff
xf jj
j
/,2
11 =∆∆−
= −+
δδ
Finite-difference approximation:
,)( /2 Nnjiikx eexf π==
Computational Fluid Dynamics IPPPPIIIIWWWWModified Wave Number
Modified Wave Number:
∆−=
−+
2
/)1(2/)1(2 NjniNjni
j
eexf ππ
δδ
jj
j
NniNni
fkifNni
fee
′=∆
=
∆−=
−
)/2sin(2
/2/2
π
ππ
∆=′ )/2sin( Nnk π
Computational Fluid Dynamics IPPPPIIIIWWWWModified Wave Number
Summary:
)2sin(;)/2sin(
2;2
NnkNnk
Nnkn
Lk
ππ
ππ
=′∆∆
=′
=∆=
Computational Fluid Dynamics IPPPPIIIIWWWW
k∆
k'∆
0 1 2 30
1
2
3 Exact2nd Order Central4th Order Central6th Order Central4th Order Pade6th Order Pade
Modified Wave Number
Computational Fluid Dynamics IPPPPIIIIWWWWEnhancing Accuracy - Padé Scheme
4th Order Padé Scheme:v
jjjjjj fhffh
fff30
)(344
1111 +−=′+′+′ −+−+
2nd Order Central Difference:
jjjj fhffh
f ′′′−−=′ −+ 6)(
21 2
11
4th Order Central Difference:
)()88(12
1 42112 hOffff
hf jjjjj +′−+−=′ ++−−
Tridiagonal system of equations for jf ′