POISSON EQUATIONS À Y stands for an inequality X ¤

advertisement
POISSON EQUATIONS
JEONGHUN LEE
Throughout this note the symbol X À Y stands for an inequality X ¤
CY with some constant C ¡ 0 which is independent of mesh sizes h. However, we will use X ¤ CY when we want to emphasize the constant C ¡ 0
in the context.
1. Mixed form of the Poisson equation
Let Ω € Rn , n 2, 3 be a bounded domain with Lipschitz boundary. For
a given function f : Ω Ñ R, Poisson equation with homogeneous Dirichlet
boundary condition is to find a function u : Ω Ñ R such that
∆u f
(1)
u0
in Ω,
on Γ : B Ω.
Since we will not discuss regularity theory of PDEs in this note, we assume
that B Ω is at least Lipschitz continuous.
For f P H 1 pΩq a variational formulation of (1) is to find u P H01 pΩq such
that
p∇u, ∇vq pf, vq,
(2)
v
P H01pΩq.
One can prove that this problem is well-posed using Poincare inequality and
the Lax–Milgram lemma. Furthermore, there is a constant C ¡ 0 depending
only on Ω such that
}u}1 ¤ C }f }1.
(3)
In mixed formulation of Poisson problems, we introduce σ : ∇u as a new
variable and (1) is rewritten as
(4)
σ
∇u, div σ f
in Ω,
u0
on Γ.
Let H pdiv, Ωq be the subspace of L2 pΩ; Rn q such that their divergence is
also square integrable. For τ P H pdiv, Ωq the } }div norm is defined by
}τ }2div }τ }20 } div τ }20.
Now we derive a variational formulation of (4). By applying the integration
by parts to the first equation in (4) with u 0 on Γ, we have
pσ, τ q p∇u, τ q I.B.P
pu, div τ q,
1
τ
P H pdiv, Ωq.
2
JEONGHUN LEE
Thus a variational formulation of (4) is: find pσ, uq P H pdiv, Ωq L2 pΩq such
that
(5)
(6)
pσ, τ q pu, div τ q 0,
pdiv σ, vq pf, vq,
P H pdiv, Ωq,
v P L2 pΩq.
τ
In the context of abstract formulation,
Σ H pdiv, Ωq,
L2pΩq,
apσ, τ q pσ, τ q,
bpτ, v q pdiv τ, v q.
Let us show that (5–6) is well-posed for f P L2 pΩq V .
V
By the Brezzi’s
theorem it suffices to check the first and second LBB conditions. Here we
will check the coercivity condition and the inf-sup condition. Regarding the
bilinear form bpσ, v q pdiv σ, v q, one sees that the space Z is
Z
tτ P H pdiv, Ωq | div τ 0u.
The Z-coercivity condition (or LBB1 condition) can be checked easily by
apτ, τ q }τ }20
}τ }2div ,
τ
P Z.
To see the inf-sup condition (or LBB2 condition) we need a preliminary
result.
Lemma 1. Let Ω be a bounded domain in Rn , n 2, 3, and v
Then there exists ξ P H 1 pΩ; Rn q such that div τ v in Ω and
P L2pΩq.
}ξ}1 ¤ C }v}0,
with C
¡ 0 depending only on Ω.
Proof. Let B be a ball containing Ω with the smallest radius and define
ṽ P L2 pB q by
ṽ pxq #
v p x q,
0,
if x P Ω,
if x R Ω.
It is obvious that }v }0,Ω }ṽ }0,B . By a well-known theory of elliptic PDEs,
there exists a function w P H 2 pB q such that
∆w ṽ in B, w 0 on BB, }w}2,B ¤ C }ṽ}0,B ,
with some C ¡ 0. Take ξ as the restriction of ∇w on Ω. Then div ξ div ∇w v in Ω, and
}ξ}1,Ω ¤ }∇w}1,B ¤ }w}2,B ¤ C }ṽ}0,B C }v}0,Ω.
Proof is completed.
Remark 1. Here we note that the values of ξ on B Ω are not specified.
POISSON EQUATIONS
3
To check the inf-sup condition, we prove the following claim implying the
inf-sup condition, which is, for any v P L2 pΩq there exists τ P H pdiv, Ωq
such that div τ v and }τ }div ¤ c}v }0 . To prove it, note that, for given
v P L2 pΩq there exists τ P H 1 pΩ; Rn q such that div τ v, }τ }1 ¤ c}v }0 by
the above Lemma. Since }τ }div ¤ }τ }1 , the claim follows.
2. Stable finite elements
In this section we introduce stable mixed finite elements for the Poisson
problems.
Throughout this note, Th will denote the set of triangles/tetrahedra in a
triangulation of Ω. However, we will also use Th to denote the mesh given
by the triangulation. We denote the set of edges/faces by Eh and
Eh
EhB
tE P Eh | E € Γu.
We use Pk pT q to denote the space of polynomials on T P Th of degree ¤ k
for an integer k ¥ 0. The Rn -valued polynomial space pPk pT qqn is denoted
by Pk pT ; Rn q. We define
Pk pTh q tv P L2 pΩq | v |T P Pk pT q, T P Th u,
and Pk pTh ; Rn q is defined in a similar way. For the space of homogeneous
tE P Eh | E € Ωu,
polynomials of degree k we use the symbol Hk . All variations of polynomial
spaces are similarly defined.
In order to find a stable mixed finite elements for the Poisson problems
we need to find two finite element spaces Σh € H pdiv, Ωq, Vh € L2 pΩq
satisfying the (discrete) LBB conditions.
For τ P Pk pTh ; Rn q it is known that τ P H pdiv, Ωq if and only if the normal
components of τ is continuous on every E P Eh . The following theorem gives
a mathematical statement of this claim.
Theorem 1. Suppose that τ P Pk pTh ; Rn q. For and edge/face E P Eh , let
TE , TE be the two distinct triangles/tetrahedra sharing E as the common
boundary and nE , n
E be the unit normal vectors on E coming out from TE ,
TE , respectively. We use τ nE to denote the inner product of the trace
of τ from the interior of TE , and nE . In a similar way, we define τ n
E
with TE , n
E . Then τ P H pdiv, Ωq if and only if τ nE τ nE for every
E P Eh .
P H pdiv, Ωq if there exists v P L2pΩq such that
pτ, ∇φq pv, φq, @φ P C08pΩq,
where C08 pΩq tφ P C 8 pΩq | supp φ € Ωu. Prove the above theorem (Hint
Exercise. Recall that τ
: the integration by parts).
In two and three dimensions, x will denote the column vectors
x
x1
,
x2
x1
x x2 .
x3
4
JEONGHUN LEE
2.1. Two families of mixed finite elements. In this section we introduce
two well-known families of mixed finite elements for the Poisson problems.
We will show precise definition of those elements only for the lowest order case in this section. Complete definitions of higher order elements and
investigation of their properties will be discussed later.
In order to define a finite element space Σh we need the space of shape
functions ΣT on T and local degrees of freedom (DOF).
Definition 1 (Raviart–Thomas–Nedelec (RTN) space). For T
k ¥ 0, the space of shape functions ΣT is
P
Th and
Pk pT ; Rnq x Pk pT̂ q rPk pT̂ qsn ` x Hk pT̂ q.
The DOFs for k 0 is given by
(7)
ΣT
τ
P ΣT ÞÑ
»
E
τ nE ds,
E
€ BT.
Definition 2 (Brezzi–Douglas–Marini (BDM) space). For a triangle/tetrahedron
T and k ¥ 0, the space of shape functions ΣT is
(8)
ΣT
The DOFs for k
τ
0 are
P ΣT ÞÑ
»
E
Pk 1pT ; Rnq.
τ nE q ds,
q
P P1pE q, E P BT.
These shape functions and local DOFs give consistent global DOFs to
define a finite element space Σh on Th .
We have not defined Vh space yet. For Vh we choose
tv P L2pΩq | v|T P Pk pT q, T P Thu.
From now on, when we say pΣh , Vh q, Σh is a RTN or BDM space with shape
functions in (7) or (8), and Vh is the space in (9) with same k ¥ 0. One
can see that div Σh € Vh by checking degrees of piecewise polynomials. Let
Ph : L2 pΩq Ñ Vh be the orthogonal L2 projection.
Now we define interpolation operators mapping H 1 pΩ; Rn q into Σh and
(9)
Vh
introduce useful properties of them. In this section we do not show full
proofs of those properties because we will discuss them later in more detail.
For τ P H 1 pT ; Rn q, the map ΠT : H 1 pT ; Rn q Ñ ΣT is defined by
»
»
E
E
ΠT τ nE ds ΠT τ nE q ds »
»
E
E
τ nE ds,
E
€ BT,
pRTNq
τ nE q ds,
E
€ BT, q P P1pE q.
pBDMq.
From this local interpolation operator we can define Πh : H 1 pΩ; Rn q Ñ Σh
such that Πh |T ΠT for T P Th . Here we summarize some properties of Πh .
POISSON EQUATIONS
For τ
5
P H 1pΩ; Rnq,
}Πhτ }0 ¤ c}τ }1,
div Πh τ Ph div τ,
# k 1
}τ }k
}τ πhτ }0 ¤ ch
k
2
ch }τ }k
(10)
(11)
(12)
pRTNq
pBDMq
1,
2,
Remark 2. The operator Πh is not well-defined on H pdiv, Ωq because the
trace of normal component of H pdiv, T q function belongs to H 1{2 pB T q, so
the integration of normal component of τ on E € B T is not well-defined.
2.2. Stability of RTN and BDM elements.
Theorem 2. The pair pΣh , Vh q is a stable mixed finite element for the Poisson problems.
€ Vh,
Zh tτ P Σh | pdiv τ, v q 0 @v P Vh u tτ P Σh | div τ 0u.
Proof. Since div Σh
The LBB1 condition holds because
pτ, τ q }τ }20 }τ }2div ,
τ
P Zh .
For the inf-sup (LBB2) condition, recall that for any v P Vh there exists
ξ P H 1 pΩ; Rn q such that div ξ v and }ξ }1 ¤ c}v }0 . If we set τ Πh ξ, then
div τ
and
div Πhξ Ph div ξ Phv v, p7 v P Vhq
}τ }div ¤ cp}τ }0 } div τ }0q
¤ cp}Πhξ}0 }v}0q
¤ cp}ξ}1 }v}0q p7 }Πhξ}0 ¤ c}ξ}1q
¤ c}v}0 p7 }ξ}1 ¤ c}v}0q
Thus the inf-sup condition holds.
Remark 3. As a corollary of the inf-sup condition proof, one can see that
div Σh Vh .
3. A priori error analysis
3.1. Improved error estimates. For stable finite elements pΣh , Vh q the
discrete problem
pσh, τ q puh, div τ q 0,
τ P Σh ,
(14)
pdiv σh, vq pf, vq,
v P Vh ,
has a unique solution. Let pσh , uh q be the solution of the above problem. An
(13)
immediate consequence of abstract theory of saddle point problems gives
}σ σh}div }u uh}0 À pτ,vqPinfΣ V p}σ τ }div }u v}0q.
h
h
6
JEONGHUN LEE
By the approximability of BDMk and RTNk ,
}σ σh}div }u uh}0 À hmp} div σ}m }u}mq,
1 ¤ m ¤ k.
Note that this is not fully satisfactory because the full approximability of
Σh in BDMk is not used. Thus we will show an improved error estimate of
}σ σh}0. The difference of (5–6) and (13–14), gives
pσ σh, τ q pu uh, div τ q 0, τ P Σh,
(16)
pdivpσ σhq, vq 0, v P Vh.
Since pdiv σ, v q pPh div σ, v q for v P Vh , (16) implies that div σh Ph div σ.
If we take τ Πh σ σh in (15), then
pσ σh, Πhσ σhq 0,
because divpΠh σ σh q 0. Then
}Πhσ σh}20 pΠhσ σ, Πhσ σhq ¤ }Πhσ σ}0}Πhσ σh}0,
so }Πh σ σh }0 ¤ }σ Πh σ }0 . By the triangle inequality,
}σ σh}0 ¤ }σ Πhσ}0 }Πhσ σh}0
¤ 2}σ Πhσ}0
#
1 ¤ m ¤ k 1, pBDMq
m
À h }σ}m,
1 ¤ m ¤ k,
pRTNq.
3.2. Superconvergence of }Ph u uh }0 . Now we show a superconvergence
result of }Ph u uh }0 . Note that the orthogonality pu Ph u, div τ q 0,
@τ P Σh, allows us to reduce (15) to
(17)
pσ σh, τ q pPhu uh, div τ q 0, τ P Σh.
By the inf-sup condition, there exists τ P Σh such that div τ Ph u uh
and }τ }div ¤ C }Ph u uh }0 . With such τ , we obtain
}Phu uh}20 pσ σh, τ q À }σ σh}0}Phu uh}0,
(15)
therefore
}Phu uh}0 À }σ σh}0 À }σ}m,
1 ¤ m ¤ k.
In case of the Raviart–Thomas elements, the approximation order is same to
that of }u uh }0 . However, in case of BDM elements, }Ph u uh }0 gives an
approximation which is one order higher than }u uh }0 with a sufficiently
high regularity of solution.
If the domain Ω is nice, in the sense that the elliptic regularity property
holds, then there is another technique to obtain superconvergence of }Ph u uh }0 for the RTN element Σh . Consider the solution w of
(18)
Suppose that
∆w
Phu uh,
in Ω,
w
0,
}w}2 À }Phu uh}0,
on B Ω.
POISSON EQUATIONS
7
by assuming that Ω has the elliptic regularity property. Unfortunately, it is
known that this is not the case if Ω is a nonconvex polygon but the elliptic
regularity is true when B Ω is sufficiently regular or Ω is a convex polygonal
domain.
Now we can use the duality argument (or the Aubin–Nitsche trick) to
achieve superconvergence of }Ph u uh }0 . To do it, let ξ ∇w and consider
pξ, τ q pdiv τ, wq 0,
τ P Σ,
pdiv ξ, vq pPhu uh, vq,
(20)
v P V.
If we take τ σ σh , v u uh , and add them, we have
pξ, σ σhq pdivpσ σhq, wq pdiv ξ, u uhq
pPhu uh, u uhq }Phu uh}20.
(19)
By the Galerkin orthogonality in (15–16), we have
pξ Πhξ, σ σhq pdivpσ σhq, w Phwq pdivpξ Πhξq, u uhq
}Phu uh}20.
Observe that divpξ Πh ξ q 0 because div ξ Ph u uh Ph div ξ div Πh ξ. Furthermore, div σ f and div σh Ph div σ Ph f . Hence
(21)
}Phu uh}20 pξ Πhξ, σ σhq pf Phf, w Phwq.
The rate of superconvergence depends on the regularity of f , k, and Σh .
If k 0 and f P H 1 pΩq, then
}ξ Πhξ}0 À h}ξ}1 À h}Phu uh}0,
}w Phw}0 À h}w}1 À h}Phu uh}0,
}f Phf }0 À h}f }1.
Combining these estimates with (21), we have }Ph u uh }0 Oph2 q.
If k 1, f P H 1 pΩq and Σh is the BDM element, then
}w Phw}0 À h2}w}2 À h2}Phu uh}0.
Using this and some estimates we used in k 0 case, we can obtain }Ph u uh }0 Oph3 q from (21).
As a special case, we may consider k 0, Σh BDM1 , and f Ph f 0. In this case, (21) gives }Ph u uh }0 Oph3 q, which is a supersuperconvergence result.
3.3. Post-processing of uh . Based on the superconvergence of }Ph uuh }0 ,
one can use a local post-processing to achieve a numerical solution of u with
higher accuracy. Here we use the Stenberg post-processing. For Vh Pk pTh q
let Vh Pk 2 pTh q, and define a post-processed numerical solution uh by
(22)
(23)
puh, 1qT puh, 1qT ,
p∇uh, ∇vqT pσh, ∇vqT ,
v
P Pk 2pT q,
8
JEONGHUN LEE
for all T P Th . It is not difficult to check that uh is well-defined by this
definition. Note that this post-processing is a local procedure, which has a
very small computational cost. We now prove that }u uh }0 has an accuracy
as good as that of }Ph u uh }0 .
Theorem 3. Suppose that }σ σh }0 À hk l }σ }k l , and }Ph u uh }0
Ophk l 1 q with l 0 or l 1. For the uh defined by (22) and (23),
}u uh}0 À hk l 1.
Proof. Let Vh1 P0 pTh q, Vh Pk l 1 pTh q and define Ṽh be the orthogonal
complement of Vh1 in Vh . Define Ph1 , Ph , P̃h by the orthogonal L2 projections
of L2 pΩq into Vh1 , Vh , Ṽh , respectively.
By the triangle inequality and a result }uPh u}0 À hk l 1 }u}k l 1 of the
Bramble–Hilber lemma, it is enough to estimate }uh Ph u}0 . Decomposing
uh into uh u1h ũh P Vh1 ` Ṽh , we have
pũh P̃huq P Vh1 ` Ṽh.
Since }u1h Ph1 u}0 ¤ }uh Ph u}0 Ophk l 1 q, we only need to take care of
}ũh P̃hu}0 by the triangle inequality.
Now we recall that ∇u σ and on each triangle T ,
p∇u, ∇hwq pσ, ∇hwq, w P Ṽh,
(24)
uh Ph u pu1h Ph1 uq
in which ∇h is the element-wise gradient. Considering the difference of this
equation and (23) on Ω,
p∇hpu uhq, ∇hwq pσ σh, ∇hwq,
w
P Vh,
and using (24), we obtain
p∇hpPhu ũhq, ∇hwq
p∇hpPhuuhq, ∇hwq p∇hpPhuuq, ∇hwq pσσh, ∇hwq, w P Vh.
By taking w Ph u uh , one can obtain
(25) }∇h pPh u uh q}0 ¤ }∇h pPh u uh q}0 }∇h pPh u uq}0 }σ σh }0
À h1}Phu uh}0 hk l }u}k l 1 hk l }σ}k l
À h1}Phu uh}0 hk l }u}k l 1,
where the second inequality is obtained by the inverse inequality, the Bramble–
Hilbert lemma, the assumption on }σ σh }0 , and the last inequality is due to
σ ∇u. Note that ∇h pPh uuh q ∇h pP̃h uũh q because ∇h pPh1 uu1h q 0.
Furthermore,
}P̃hu ũh}0 À h}∇hpP̃hu ũhq}0,
by a variant of the Friedrichs’ inequality, or a scaling argument. Combining
this with (25), we have
}P̃hu ũh}0 À }Phu uh}0
hk
l 1
}u}k
l 1
À hk
l 1
.
POISSON EQUATIONS
9
The assumptions of the above theorem with l 1, hold when Vh Pk pTh q
and Σh is the corresponding stable BDM element. In fact, }σ σh }0 À
hk 2 }σ }k 2 holds in this case. However, one can see that the convergence
order of }u uh }0 is limited by }Ph u uh }0 in the above proof, so this higher
order accuracy of σ error does not improve the accuracy of u error with uh .
The assumptions with l 0 are typically obtained when Σh is the RTN
element, and elliptic regularity for the duality argument is available.
3.4. Inhomogeneous boundary conditions. In this section we consider
mixed Poisson problem with inhomogeneous mixed boundary conditions.
Let ΓD , ΓN be open subsets of B Ω such that ΓD YΓN B Ω, ΓD YΓN H.
Let us consider a problem
∆u f
(26)
in Ω,
Bu
(27)
u gD on ΓD ,
Bn gN on ΓN .
We recall the variational form of this problem in the primal method. Let
tv P H 1pΩq | v|Γ 0u.
Note that, for the solution u of (26–27) and for all v P V0 ,
» Bu
»
pf, vq p∆u, vq p∇u, ∇vq Bn v ds p∇u, ∇vq gN v ds,
BΩ
Γ
because B u{B n gN on ΓN and v |Γ 0. Inspired from this observation,
VD
tv P H 1pΩq | v|Γ gD u,
V0
D
D
N
D
we define
Vh,D
VD Y Pk pThq,
and the variational form is to seek uh
p∇uh, ∇vq pf, vq
»
ΓN
Vh,0
V0 Y Pk pThq,
P Vh,D such that
gN v ds : pf, v q
xgN , vyΓ
N
,
v
P Vh,0.
Here the Dirichlet boundary condition gD is ’essentially’ imposed on the
function space Vh,D whereas the Neumann boundary condition gN is ’naturally’ satisfied by being a solution of the above equation. Thus the Dirichlet
boundary condition is called an essential boundary condition and the Neumann boundary condition is called a natural boundary condition for this
problem.
Now we discuss mixed Poisson problem with these boundary conditions.
We first observe that the Neumann boundary condition is equivalent to
σ n gN . Define
tτ P H pdiv, Ωq | τ n|Γ gN u,
Σ0 tτ P H pdiv, Ωq | τ n|Γ 0u.
ΣN
N
N
10
JEONGHUN LEE
∇u with the solution of (26–27) u, and for all τ P Σ0, we have
»
»
pσ, τ q p∇u, τ q pu, div τ q
uτ n ds pu, div τ q
gD pτ nq ds.
For σ
BΩ
ΓD
Defining
Σh Y ΣN , Σh,0 Σh Y Σ0,
the variational form is to seek pσh , uh q P Σh,N Vh such that
»
pσh, τ q puh, div τ q gD pτ nq ds,
τ P Σh,0 ,
Γ
pdiv σh, vq pf, vq,
v P Vh .
Σh,N
D
In contrast to the primal method, the Neumann boundary condition is an
essential boundary condition and the Dirichlet boundary condition is a natural boundary condition in mixed Poisson problems.
4. Implementation with FEniCS
In this section we show how to implement mixed finite element methods
for the Poisson equation with FEniCS, an open source software for automated finite element computation.
For introduction of FEniCS we recommend the FEniCS tutorial written by H. P. Langtangen. (http://fenicsproject.org/documentation/
tutorial/index.html) A PDF format of the tutorial and all source codes
of examples are also available in the linked site.
In the following code mixed finite element methods of the Poisson problem
with the homogeneous Dirichlet boundary condition is implemented with
Python interface of FEniCS.
"""
Mixed Poisson problem implementation (homogeneous Dirichlet B/C).
Jeonghun J. Lee
Last modified 2013-09-16
"""
# Import dolfin and numpy modules
from dolfin import *
import numpy
# Exact solution
u_ex = Expression(’x[0]*(1-x[0])*sin(pi*x[1])’)
sigma_ex = Expression((’(1 - 2*x[0])*sin(pi*x[1])’, \
’pi*x[0]*(1-x[0])*cos(pi*x[1])’))
f = Expression(’-sin(pi*x[1])*(2+pi*pi*x[0]*(1-x[0]))’)
# L2 norm of error computation
def errnorm(u_exact, u, W):
POISSON EQUATIONS
11
u_W = interpolate(u, W)
u_ex_W = interpolate(u_exact, W)
e_u = Function(W)
e_u.vector()[:] = u_ex_W.vector().array() - u_W.vector().array()
error = e_u**2*dx
return assemble(error, mesh=W.mesh())
# Degree of finite elements for velocity
deg = 1
# Memories for element sizes and errors
h = []
# element sizes
E = []
# errors
# Solve problems with refining mesh sizes
for nx in [2,4,8,16,32]:
# Create mesh and define function spaces
mesh = UnitSquareMesh(nx,nx)
Mh = FunctionSpace(mesh, "RT", deg+1)
Vh = FunctionSpace(mesh, "DG",deg)
V = MixedFunctionSpace([Mh, Vh])
# Build linear system
(tau, v) = TestFunctions(V)
(sigma, u) = TrialFunctions(V)
a = inner(sigma, tau)*dx + u*div(tau)*dx + div(sigma)*v*dx
L = f*v*dx
# Solve linear system
su = Function(V)
solve(a == L, su)
(sigma,u) = su.split()
# Compute L2 errors
W1 = FunctionSpace(mesh, "CG", deg+3)
W2 = VectorFunctionSpace(mesh, "CG", deg+3)
u_error = sqrt(errnorm(u_ex, u, W1))
sigma_error = sqrt(errnorm(sigma_ex, sigma, W2))
# Store errors and mesh data
errors = \{’u’: u_error, ’sigma’: sigma_error\}
h.append(nx)
E.append(errors) # list of dicts
12
JEONGHUN LEE
# Compute convergence rates
from math import log as ln
# log exists in dolfin module
error_types = E[0].keys()
for error_type in sorted(error_types):
l = len(E)
print ’\backslash nL2 norm of’, error_type, ’error’
for i in range(0, l):
if i==0:
print ’Mesh size= 1/%g
Error= %.3e
\
Convergence rate= -- ’
% (h[i], E[i][error_type])
else:
r = ln(E[i][error_type]/E[i-1][error_type])/ln(0.5)
print ’Mesh size= 1/%g
Error= %.3e
\
Convergence rate= %.2f’
% (h[i], E[i][error_type], r)
Here is a code for a problem with inhomogeneous boundary conditions. In
this problem domain is the unit square and exact solutions are
u ex ey
xy
1,
σ
pexey
y, ex ey
x q,
with f A mixed boundary condition is given by the Dirichlet
boundary condition on x 0 part of the boundary and the Neumann boundary condition on the rest of the boundary.
"""
Mixed Poisson problem implementation (inhomogeneous mixed B/C).
Jeonghun J. Lee
Last modified 2013-09-19
"""
# Import dolfin and numpy modules
from dolfin import *
import numpy
2ex ey .
# Exact solution
u_0 = Expression(’exp(x[1]) + 1’)
u_ex = Expression(’exp(x[0])*exp(x[1]) + x[0]*x[1] + 1’)
sigma_ex = Expression((’exp(x[0])*exp(x[1]) + x[1]’, \
’exp(x[0])*exp(x[1]) + x[0]’))
f = Expression(’2*exp(x[0])*exp(x[1])’)
# L2 norm of error computation
def errnorm(u_exact, u, W):
u_W = interpolate(u, W)
u_ex_W = interpolate(u_exact, W)
e_u = Function(W)
e_u.vector()[:] = u_ex_W.vector().array() - u_W.vector().array()
error = e_u**2*dx
return assemble(error, mesh=W.mesh())
POISSON EQUATIONS
# Degree of finite elements for Vh
deg = 1
# Storage for element sizes and errors
h = []
# element sizes
E = []
# errors
tol = 1E-14 # error tolerance
# Solve problems with refining mesh sizes
for nx in [2,4,8,16,32]:
# Create mesh and define function spaces
mesh = UnitSquareMesh(nx,nx)
Mh = FunctionSpace(mesh, "BDM", deg+1)
Vh = FunctionSpace(mesh, "DG",deg)
V = MixedFunctionSpace([Mh, Vh])
# Boundary condition
n = FacetNormal(mesh)
class Nbdy(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and ((abs(x[1]-1.) < tol) \
or (abs(x[0]-1.) < tol) or (abs(x[1]) < tol))
bc = DirichletBC(V.sub(0), sigma_ex, Nbdy())
# Build a linear system
(tau, v) = TestFunctions(V)
(sigma, u) = TrialFunctions(V)
a = inner(sigma, tau)*dx + u*div(tau)*dx + div(sigma)*v*dx
L = f*v*dx + u_0*inner(tau, n)*ds
# Solve the linear system
su = Function(V)
solve(a == L, su, bc)
(sigma, u) = su.split()
# Compute L2 errors
W1 = FunctionSpace(mesh, "CG", deg+3)
W2 = VectorFunctionSpace(mesh, "CG", deg+3)
u_error = sqrt(errnorm(u_ex, u, W1))
up_error = sqrt(errnorm(up, u, W1))
sigma_error = sqrt(errnorm(sigma_ex, sigma, W2))
# Store errors and mesh data
13
14
JEONGHUN LEE
errors = {’u’: u_error, ’Phu - uh’: up_error, ’sigma’: sigma_error}
h.append(nx)
E.append(errors) # list of dicts
# Compute convergence rates
from math import log as ln
# log exists in dolfin module
error_types = E[0].keys()
for error_type in sorted(error_types):
l = len(E)
print ’\backslash nL2 norm of’, error_type, ’error’
for i in range(0, l):
if i==0:
print ’Mesh size= 1/%g
Error= %.3e
\
Convergence rate= -- ’
% (h[i], E[i][error_type])
else:
r = ln(E[i][error_type]/E[i-1][error_type])/ln(0.5)
print ’Mesh size= 1/%g
Error= %.3e
\
Convergence rate= %.2f’
% (h[i], E[i][error_type], r)
(To be appended)
Last updated : 2013, October 1.
Download