Professional Documents
Culture Documents
Finite Diff Methods
Finite Diff Methods
= (0, X),
grid points
x0 x1
ui u(xi ),
xi = ix
xi
i = 0, 1, . . . , N
mesh size
xi xi+1
x =
X
N
xN 1 xN
First-order derivatives
u
(
x)
x
u(
x + x) u(
x)
u(
x) u(
x x)
= lim
x0
x0
x
x
u(
x + x) u(
x x)
(by definition)
= lim
x0
2x
=
lim
forward ba
kward
entral
ui+1 ui
x
forward difference
ui ui1
x
backward difference
ui+1 ui1
2x
central difference
u
x i
exa t
x x
u
x i
u
x i
x
xi 1 xi xi+1
P
Taylor series expansion
u(x) =
n=0
T1 :
ui+1
T2 :
ui1
(xxi )n
n!
nu
xn i
u C ([0, X])
(x)3 3 u
(x)2 2 u
+ ...
= ui + x
+
+
2
3
2
x
6
x
i
i
i
u
(x)2 2 u
(x)3 3 u
= ui x
+
+ ...
x i
2
x2 i
6
x3 i
u
x
T2
u
x
u
x
ui+1 ui x
=
x
2
forward difference
ui ui1 x
+
=
x
2
backward difference
T1 T2
u
x
2u
x2
2u
x2
(x)2
(x)2
3u
x3
3u
x3
=
2x
6
central difference
3u
x3
+ ...
i
+ ...
i
+ ...
i
2u
x2
=
i
Alternative derivation
2
u
u
=
= lim
x2 i
x x i x0
Variable coefficients
f
x i
=
ui+1 ui
x
u
x i+1/2
u
x i1/2
i1
ui u
ui+1 2ui + ui1
x
=
x
(x)2
f (x) = d(x) u
x
diffusive flux
ui
i1
di1/2 ui u
fi+1/2 fi1/2
di+1/2 ui+1
x
x
=
x
x
2u
xy
u
y
u
y
u
x
u
y
2u
xy
u
y
ui+1,j+1 ui+1,j1
+ O(y)2
2y
u
y
ui1,j+1 ui1,j1
+ O(y)2
2y
i,j
2x
i1,j
+ O(x)2
yj +1
yj
i+1,j
i1,j
i+1,j
yj 1
xi 1
xi
xi+1
x0
x1
x2
u
x
=
0
u1 u0
+ O(x) forward difference
x
u
x
x2
+
2
0
2u
x2
x3
+
6
0
u
b + 2cx,
x
u(x) a + bx + cx2 ,
3u
+ ...
x3 0
u
b
x 0
u0 = a
u1 = a + bx + cx2
u2 = a + 2bx + 4cx2
b=
3u0 + 4u1 u2
2x
ui+1
ui+2
u
x
ui + ui+1 + ui+2
x
(x)2 2 u
(x)3 3 u
u
+
+
+ ...
= ui + x
x i
2
x2 i
6
x3 i
2
3
2
3
u
(2x)
(2x)
u
u
= ui + 2x
+
+
+ ...
x i
2
x2 i
6
x3 i
ui +ui+1 +ui+2
x
++
x ui
Second-order accurate if
= 23 ,
= 2,
+ ( + 2)
u
x i
+ + = 0,
= 21
u
x i
x
2 (
+ 4)
+ 2 = 1,
=
2u
x2
+ O(x2 )
+ 4 = 0
+ O(x2 )
One-sided approximation
ui+1
ui+2
ui + ui+1 + ui+2
x2
(x)3 3 u
(x)2 2 u
u
+
+ ...
+
= ui + x
x i
2
x2 i
6
x3 i
2
3
2
3
u
(2x)
(2x)
u
u
= ui + 2x
+
+
+ ...
x i
2
x2 i
6
x3 i
ui +ui+1 +ui+2
x2
++
x2 ui
First-order accurate if
= 1,
2u
x2
= 2,
+2
x
u
x i
+ + = 0,
=1
u
x i
+4
2
2u
x2
+ 2 = 0,
ui 2ui+1 +ui+2
x2
+ O(x)
+ 4 = 2
+ O(x)
High-order approximations
u
x
u
x
u
x
2u
x2
forward difference
central difference
=
i
backward difference
central difference
in = (0, 1),
x0
fi = f (xi )
x1
xi 1
xi = ix,
u(0) = u(1) = 0
xi
xi+1
x =
xN 1 xN
1
,
N
i = 0, 1, . . . , N
i+1
ui1 2ui +u
= fi ,
i = 1, . . . , N 1
(x)2
u0 = uN = 0
Result: the original PDE is replaced by a linear system for nodal values
u0 2u1 +u2
i
=
1
(x)2
2 +u3
u1 2u
(x)2
i=2
3 +u4
i=3
u2 2u
2
(x)
...
uN 2 2uN 1 +uN
i=N 1
Matrix form
Au = F
(x)2
A RN 1N 1
2 1
1 2 1
1
2
1
A=
,
(x)2
...
1 2
= f1
= f2
= f3
= fN 1
u, F RN 1
u=
u1
u2
u3
uN 1
F =
f1
f2
f3
fN 1
u(0) =
u
x (1)
uN +1 uN 1
=0
2x
u0 = 0,
=0
uN +1 = uN 1
central difference
uN 1 2uN + uN +1
= fN
(x)2
A RN N
Au = F
2 1
1 2 1
1
1 2 1
A=
...
(x)2
uN 1 + uN
1
=
fN
(x)2
2
2 1
1 1
u, F RN
u=
u1
u2
u3
N 1
uN
F =
f1
f2
f3
N 1
1
2 fN
u(0) = g0
2u1 u2
g0
=
f
+
1
(x)2
(x)2
u
x (1)
Non-homogeneous Neumann BC
uN +1 uN 1
= g1
2x
uN 1 2uN + uN +1
= fN
(x)2
Non-homogeneous Robin BC
uN +1 uN 1
+ uN = g2
2x
only F changes
uN 1 2uN + uN +1
= fN
(x)2
= g1
only F changes
uN +1 = uN 1 + 2xg1
u
x (1)
first equation
uN 1 + uN
1
g1
=
f
+
N
(x)2
2
x
+ u(1) = g2
A and F change
uN +1 = uN 1 2xuN + 2xg2
uN 1 + (1 + x)uN
1
g2
=
f
+
N
(x)2
2
x
2 u2 2 u2 = f in = (0, 1) (0, 1)
x
y
u=0
ui,j u(xi , yj ),
N=
h
h
yj 1
xi 1
+ui+1,j +ui,j+1
ui1,j +ui,j1 4ui,j
= fi,j ,
h2
ve-point sten il
yj
1
h
fi,j = f (xi , yj ),
yj +1
on =
Uniform mesh: x = y = h,
xi
xi+1
i, j = 0, 1, . . . , N
i, j = 1, . . . , N 1
i, j = 0, 1, . . . , N
(N 1)2
u, F R(N 1)
Linear system
Au = F
row-by-row
node numbering
B I
I B I
... ...
A=
I=
1
1
1
1
,
B I
I B
4 1
1 4 1
... ...
B=
4 1
1 4
|max |
= O(h2 )
|min |
2 u2 2 u2 = f
x
y
u = g0
in
on
Difference equation
u1 + u2 4u0 + u3 + u4
= f0
h2
4
Q
0 Q
h
P
stencil of Q
curvilinear boundary
Linear interpolation
u4 (h ) + u0
h
= g0 (R) u4 = u0
+ g0 (R)
h
h
h
h
Grid transformations
Purpose: to provide a simple treatment of curvilinear boundaries
d
nozzle
dire t mapping
re tangle
P
inverse mapping
a
x
physi
al domain
body-tted grid
a
omputational domain
artesian grid
u u
,
,...
x y
|
{z
}
difficult to compute
u u
,
,...
|
{z
}
easy to compute
= (x, y),
= (x, y)
u
u
u
=
+
,
x
x x
2u
u 2
u 2
=
+
x2
x2
x2
2u
u 2
u 2
=
+
y 2
y 2
y 2
u
u
u
=
+
y
y
y
2
2
2 u
2 u
2 u
+ 2
+2
+ 2
x x
x
2
2
2 u
2 u 2 u
+ 2
+2
+ 2
y y
u = f
turns into
Example: 2D Poisson equation
"
"
2 #
2 #
2
2
2
2
u
u
2 u
2
+
+
+
2
2
x
y
x
y
x x y y
2
2
2
2
u
u
transformed equations
+
+
=
f
contain many more terms
x2
y 2
x2
y 2
The metrics need to be determined (approximated by finite differences)
x = x(, )
Metrics transformations
,
,
,
x y x y
|
{z
}
unknown
Chain rule
u
where J =
y = y(, )
u x
x
u x
x
(x,y)
(,)
u y
y
u y
y
x x y y
,
,
,
|
{z
}
known
{z
J
u
x
u
y
Derivative transformations
u
1
u y
u y
=
,
x
det J
u
1
=
y
det J
u x u x
x dx
d =
x dx
y dy
dx =
x
d
x
d
y
d
d =
dy =
y dy
y
d
x
1 y
=
,
x
det J
1 y
=
,
x
det J
d
d
dx
dy
1
det J
x
x
1 x
=
,
y
det J
y
x
dx
dy
d
d
1 x
=
y
det J