Poisson equation in 1D - TU Dortmund · Poisson equation in 1D Dirichlet problem (−∂2u ∂x2 =...
Transcript of Poisson equation in 1D - TU Dortmund · Poisson equation in 1D Dirichlet problem (−∂2u ∂x2 =...
Poisson equation in 1D
Dirichlet problem −∂2u
∂x2 = f in Ω = (0, 1)
u(0) = 0, u(1) = 0
Central difference discretization−ui−1−2ui+ui+1
(∆x)2 = fi, i = 1, . . . , N − 1u0 = uN = 0
Au = f, A = 1(∆x)2
2 −1−1 2 −1−1 2 −1
. . .−1 2
Error analysis
Let u(xi) be the exact solution at the mesh point xi. The localtruncation error of the CD approximation is O(∆x)2, i.e.,
−u(xi−1)− 2u(xi) + u(xi+1)(∆x)2 = fi + (∆x)2pi
The solution vectors u = ui and uex = u(xi) satisfy
Au = f, Auex = f + (∆x)2p
The error e = uex − u satisfies the linear system
Ae = (∆x)2p, ei = u(xi)− ui
Error analysis
The global error is measured using a norm, e.g., the Euclidean norm
‖v‖ =
√√√√ n∑j=1
v2j , v ∈ Rn
The CD discretization of the 1D Poisson equation is consistent
∆x→ 0 ⇒ ‖Auex − f‖ = (∆x)2‖p‖ → 0
The discretization is stable if there exists a constant C > 0 s.t.
‖uex − u‖ ≤ C‖Auex − f‖
Error analysis
The matrix A is non-singular and symmetric. The natural norminduced by the Euclidean vector norm ‖ · ‖ is the spectral norm
∥∥A−1∥∥ = 1λmin
, λmin = min|λ1|, . . . , |λN−1|
Ae = (∆x)2p ⇒ ‖e‖ = (∆x)2 ∥∥A−1p∥∥
≤ (∆x)2 ∥∥A−1∥∥ ‖p‖ =∥∥A−1∥∥ ‖Auex − f‖
The finite difference discretization Au = f is stable if
∃C > 0 s.t. ‖A−1‖ ≤ C
Error analysis
The CD approximation of ∂xx yields
λj = 4(∆x)2 sin2
(π
2N − jN
), λmin = λN−1
For large N (on a fine mesh) we have
λN−1 = 4(∆x)2 sin2
( π
2N
)≈ 4
(∆x)2
( π
2N
)2= π2
This proves stability and convergence
‖uex − u‖ ≤1π2 ‖Auex − f‖ = 1
π2 (∆x)2‖p‖
Error analysis
Assume that there is an error δf in the right-hand side f
The resulting solution u+ δu satisfies the linear system
A(u+ δu) = f + δf, Au = f
Similarly to the analysis of the approximation error, we have
Aδu = δf, ‖δu‖ ≤ 1π2 ‖δf‖
The system is well-conditioned w.r.t. the absolute error
Error analysis
To estimate the relative error, divide by ‖u‖
‖δu‖‖u‖
≤ 1π2‖δf‖‖u‖
= 1π2
(‖f‖‖u‖
)‖δf‖‖f‖
The ratio of ‖f‖ and ‖u‖ determines the sensitivity of the relativeerror to relative changes in f
It is possible that the problem is well-conditioned w.r.t. absoluteerror but ill-conditioned w.r.t. relative error
Other boundary conditions
Dirichlet-Neumann problem−∂2u
∂x2 = f in Ω = (0, 1)
u(0) = 0, ∂u∂x (1) = 0
Central difference discretization of the Poisson equation
−ui−1 − 2ui + ui+1
(∆x)2 = fi, i = 1, . . . , N
Discretization of the Neumann boundary condition
uN+1 − uN−1
2∆x = 0 ⇒ −uN−1 − uN
(∆x)2 = 12fN
Other boundary conditions
The matrix form of the linear algebraic system becomes
Au = f, A ∈ RN×N , u, f ∈ RN
The matrix A is tridiagonal, symmetric positive-definite
A = 1(∆x)2
2 −1−1 2 −1−1 2 −1
. . .−1 2 −1−1 1
The smallest eigenvalue λmin is again O(1)
Local error analysis
Consider the Taylor expansion about the point x = 1
u(x) = u(1) + (x− 1)∂u∂x
(1) + (x− 1)2
2∂2u
∂x2 (1)
+ (x− 1)3
6∂3u
∂x3 (1) + . . .
The local truncation error is given by O(∆x)
∂2u
∂x2 (1) = −2u(xN−1)− u(xN )(∆x)2 +O(∆x)
How does it influence the global error?
Global error analysis
Let u(xi) be the exact solution at xi. We have
−u(xi−1)− 2u(xi) + u(xi+1)(∆x)2 = fi + (∆x)2pi
for i = 1, . . . , N − 1. The last equation is
−u(xN−1)− u(xN )(∆x)2 = 1
2fN + ∆xqN
Let u = ui and uex = u(xi) be solutions of
Au = f, Auex = f + (∆x)2p+ ∆xq
Global error analysis
The approximation error e = uex − u satisfies
Ae = (∆x)2p+ ∆xq
Let e(p) and e(q) be solutions of
Ae(p) = (∆x)2p
Ae(q) = ∆xq
By linearity, we have Ae = A(e(p) + e(q)) and therefore
e = e(p) + e(q)
Global error analysis
The approximation error e(p) arises at inner points
‖e(p)‖ ≤ C(∆x)2‖p‖, C = 1λmin
= O(1)
The approximation error e(q) arises at the point xN = 1
− e(q)i−1−2e
(q)i
+e(q)i+1
(∆x)2 = 0, i = 1, . . . , N − 1
− e(q)N−1−e
(q)N
(∆x)2 = ∆xqN
The exact solution of the linear system is
e(q)i = i(∆x)3qN , i = 1, . . . , N
Global error analysis
Substituting e(q)i = i(∆x)3qN into the linear system, we obtain
−e
(q)i−1 − 2e(q)
i + e(q)i+1
(∆x)2 = −(i− 1− 2i+ i+ 1)(∆x)qN = 0
−e
(q)N−1 − e
(q)N
(∆x)2 = −(N − 1−N)(∆x)qN = ∆xqN
Since xi = i∆x, we have e(q)i = (∆x)2xiqN . It follows that
‖e‖ = ‖e(p) + e(q)‖ ≤ (∆x)2(C‖p‖+ qN‖x‖)
Inhomogeneous boundary conditions
Consider the Dirichlet boundary condition
u(0) = g1
Substitution into the first equation yields−u0−2u1+u2
(∆x)2 = f1
u0 = g1⇒ 2u1 − u2
(∆x)2 = f1 + g1
(∆x)2
The first component of the right-hand side f changes
The matrix A is the same as in the case g1 = 0
Inhomogeneous boundary conditions
Consider the Neumann boundary condition
∂u
∂x(1) = g2,
uN+1 − uN−1
2∆x = g2
Substitution into the first equation yields−uN−1−2uN +uN+1
(∆x)2 = fN
uN+1 = uN−1 + 2∆xg2⇒ −uN−1 − uN
(∆x)2 = 12fN + g2
∆x
The first component of the right-hand side f changes
The matrix A is the same as in the case g2 = 0
Inhomogeneous boundary conditions
Consider the Robin boundary condition
∂u
∂x(1) + αu(1) = g3
uN+1 − uN−1
2∆x + αuN = g3
Substitution into the last equation yields
−uN−1 − (1 + α∆x)uN
(∆x)2 = 12fN + g3
∆x
The matrix A and the right-hand side f change
Convection-diffusion in 1D
Dirichlet problem−∂2u
∂x2 = −Pe∂u∂x in (0, 1)
u(0) = 0, u(1) = 1
For the time being let Pe ≥ 00 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Pe=0Pe=10Pe=100
Exact solution and its derivative
u(x) = eP e x − 1eP e − 1 ,
dudx = Pe eP e x
eP e − 1
Convection-diffusion in 1D
The exact solution satisfies the maximum principle
0 ≤ u(x) ≤ 1 ∀x ∈ (0, 1)
A boundary layer forms near x = 1 at large Peclet numbers
Pe 1 ⇒ dudx (1) = Pe eP e
eP e − 1 ≈ Pe
This is an example of a singularly perturbed problem
Convection-diffusion in 1D
First-order BD-CD discretization
Peui − ui−1
∆x − ui−1 − 2ui + ui+1
(∆x)2 = 0
Second-order CD-CD discretization
Peui+1 − ui−1
2∆x − ui−1 − 2ui + ui+1
(∆x)2 = 0
Dirichlet boundary conditions
u0 = 0, uN = 1
Convection-diffusion in 1D
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
1.2
Pe=100, exact
h=10−1, 1st−order
h=10−1, 2nd−order
h=10−2, 1st−order
h=10−2, 2nd−order
Convection-diffusion in 1D
The CD solution oscillates and the sign changes at each node
The BD gradient is not as steep as that of the exact solution
As the mesh is refined, oscillations in the CD solution disappearand the slopes of the BD solution become steeper
The error of the CD approximation decreases quadratically
The error of the BD approximation decreases linearly
Convection-diffusion in 1D
Finite difference discretization
aui−1 + bui + cui+1
(∆x)2 = 0, i = 1, . . . , N − 1
uN = 1 ⇒ auN−2 + buN−1
(∆x)2 = − c
(∆x)2
Coefficients of the linear system
a b cBD-CD −1− Pe∆x 2 + Pe∆x −1CD-CD −1− P e∆x
2 2 −1 + P e∆x2
Convection-diffusion in 1D
Matrix form of the linear system Au = f
A = 1(∆x)2
b ca b ca b c
. . .a b
, f =
000·
− c(∆x)2
The entries of the coefficient matrix A satisfy
a < 0, b > 0, a+ b+ c = 0
A is tridiagonal but not symmetric for Pe > 0
Analysis of the discrete problem
Consider a discretization leading to the linear system
aui−1 + bui + cui+1 = 0, i = 1, . . . , N − 1
The solution of this discrete problem is a polynomial of the form
ui = α+ βri, i = 0, 1, . . . , N
The constants are determined using the boundary conditions
u0 = 0, uN = 1
Analysis of the discrete problem
Substitution of ui = α+ βri into the i-th equation yields
α(a+ b+ c) + β(ari−1 + bri + cri+1) = 0
wherea+ b+ c = 0 ⇒ cr2 − (a+ c)r + a = 0
The roots of this quadratic equation are
r1,2 =(a+ c)±
√(a+ c)2 − 4ac2c = (a+ c)± (a− c)
2c
Analysis of the discrete problem
The equation cr2 − (a+ c)r + a = 0 has two roots
r1 = a
c, r2 = 1
The root r = r2 does not satisfy the boundary conditions for
ui = α+ βri
Substituting r = r1 into this formula, we obtain
ui = α+ β(ac
)i
Analysis of the discrete problem
The Dirichlet boundary conditions are given by
u0 = α+ β = 0, uN = α+ β(ac
)N
= 1
The corresponding values of α and β are
α = − 11−
(ac
)N, β = 1
1−(
ac
)N
The solution of the discrete problem is
ui =1−
(ac
)i
1−(
ac
)N, i = 1, . . . , N
Analysis of the discrete problem
Solution of the difference equations
ui = P
Q, P = 1−
(ac
)i
, Q = 1−(ac
)N
a < 0, b > 0, a+ b+ c = 0
In the case c < 0, we have ac > 0
ac > 1 ⇒ P < 0, Q < 0, 0 < ui < 1
ac < 1 ⇒ P > 0, Q > 0, 0 < ui < 1
The solution satisfies the maximum principle
Analysis of the discrete problem
Solution of the difference equations
ui = P
Q, P = 1−
(ac
)i
, Q = 1−(ac
)N
a < 0, b > 0, a+ b+ c = 0
In the case c > 0, we have ac < 0
a+ c = −b < 0 ⇒ c < −a ⇒ ac < −1
Alternating signs: if ui > 0 then ui±1 < 0
The solution violates the maximum principle
Analysis of the discrete problem
In the case c = 0, the difference equations reduce to
ui = −abui−1 = 0, i = 1, . . . , N − 1
Invoking the Dirichlet boundary conditions, we find that
u0 = u1 = · · · = uN−1 = 0, uN = 1
The maximum principle holds but the solution is inaccurate
Summary
In the case c > 0, violations of the maximum principle are possible;the matrix A is not diagonally dominant
a < 0, b > 0, b = −a− c ⇒ |b| < |a|+ |c|
In the case c ≤ 0, violations of the maximum principle are ruled out;the matrix A is diagonally dominant
a < 0, b = −(a+ c) ⇒ |b| = |a|+ |c|
The case c = 0 should be avoided for accuracy reasons
Analysis of the CD-CD scheme
Equations of the difference scheme
Peui+1 − ui−1
2∆x − ui−1 − 2ui + ui+1
(∆x)2 = 0
This discretization corresponds to c = −1 + P e∆x2 . The sufficient
(not necessary) condition of the maximum principle is
c ≤ 0 ⇔ Pe∆x ≤ 2
If Pe is very large, the mesh size ∆x must be very small
It is worthwhile to refine the mesh just in subdomains whereviolations of the maximum principle would occur otherwise
Analysis of the BD-CD scheme
Equations of the difference scheme
Peui − ui−1
∆x − ui−1 − 2ui + ui+1
(∆x)2 = 0
For this discretization c = −1 regardless of the mesh size
The maximum principle is satisfied but the error is O(∆x)
For accuracy reasons ∆x must be chosen very small; otherwisethe solution will be strongly smeared by numerical diffusion
In contrast to CD-CD local mesh refinement is insufficient
Analysis of the BD-CD scheme
Taylor expansions for ui±1 = u(xi±1)
ui±1 = ui ±∆x(∂u
∂x
)i
+ (∆x)2
2
(∂2u
∂x2
)i
± (∆x)3
6
(∂3u
∂x3
)i
+ . . .
Residual of the difference equation
Peui − ui−1
∆x − ui−1 − 2ui + ui+1
(∆x)2 = Pe
(∂u
∂x
)i
−(∂2u
∂x2
)i︸ ︷︷ ︸
=0
− Pe∆x2
(∂2u
∂x2
)i
+O(∆x)2 = O(∆x)
Analysis of the BD-CD scheme
The BD-CD scheme is a first-order accurate approximation to
Pe∂u
∂x− ∂2u
∂x2 = 0
but a second-order accurate approximation to
Pe∂u
∂x−(
1 + Pe∆x2
)∂2u
∂x2 = 0
The numerical diffusion coefficient P e∆x2 is proportional to the
mesh size ∆x and tends to zero very slowly
Upwind difference scheme
The analysis of the BD-CD scheme was performed for Pe > 0
If Pe < 0, then a = −1− Pe∆x may assume positive values
The maximum principle holds for any ∆x if the convective term isdiscretized using the first-order upwind difference approximation
upwind difference =
backward difference, P e > 0forward difference, P e < 0
Upwind difference approximations of second and higher order mayproduce oscillations in the vicinity of steep gradients
Adaptive schemes
Equations of the difference scheme
Pe(1 + ωi−1/2)(ui − ui−1) + (1− ωi+1/2)(ui+1 − ui)
2∆x−ui−1 − 2ui + ui+1
(∆x)2 = 0, i = 1, . . . , N − 1
backward difference for ωi±1/2 = 1, central difference forωi±1/2 = 0, forward difference for ωi±1/2 = −1
optimal choice of ωi±1/2 depends on the solution
Nonuniform meshes
So far we considered difference approximations on uniform meshes
For accuracy and efficiency reasons, it is worthwhile to use meshesdesigned to equidistribute local truncation errors
εi ≈ ε, i = 1, . . . , N − 1
Taylor expansion reveals that εi depends not only on ∆x but also onthe derivatives of the exact solution at xi
Hence, the use of nonuniform meshes is generally required to achievea (nearly) uniform distribution of local errors
Nonuniform meshes
To balance εi, the local mesh size ∆xi = xi − xi−1 should be smallif derivatives of u are large and large if derivatives are small
Since the exact solution is unknown, the magnitude of the derivativesneeds to be estimated in terms of approximate solution values
The location of boundary layers is usually known a priori but largederivatives are also found in internal layers and moving fronts
If the mesh is nonuniform, the finite difference approximationsconsidered so far require generalization and further analysis