Вы находитесь на странице: 1из 7

Computational PDEs II Tutorial Prof.

Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus

Tutorial 1
Goals
+

Basics to nite element methods

Download and run the programs FEM15.m and FEM50.m. Understand the implementation and data structures of FEM15.m. + Learn to use Octave to implement a FE method. + Learn how to solve and display examples for dierent domains. + Learn how to compute and display basis functions.

1.1

Continuous formulations

The weak formulation of a PDE reads: Given a bounded linear functional b V in some Hilbert space V with scalar product a, seek its Riesz representation u, namely u V with a(u, v ) = b(v ) for all v V. The Laplace Problem In this tutorial, we will demonstrate the procedure of solving a PDE with FEM for the following model problem. Strong formulation Find u H 2 () such that u=f in , u = 0 on .

1 Weak formulation Find u V := H0 () such that 1 a(u, v ) = b(v ) for all v H0 ()

with a(u, v ) =

u v dx and b(v ) =

f v dx.

1.2

Approximation in nite-dimensional subspace

Let V = span {1 , 2 , . . . , m } be a nite-dimensional subspace of the Hilbert space V . Thus V is also a Hilbert space. Let {k }kK , with K = {1, . . . , m}, denote a set of basis functions of V . Thus a|V V : V V is bilinear and V -elliptic, and b|V V . The discrete solution u V satises

a(u , v ) = b(v ) for all v V . This reads a(u , ) = b( ) for all k K and is equivalent to u=
j K

(1)

xj j and b(k ) =
j K

xj a(j , k ) for all k K,

AIMS

2007/12/10-2007/12/15

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus i.e. A x1 x2 . . . xm b(1 ) b(2 ) . . . b(m ) with A := (Ajk ) = (a(j , k ))j,k=1, ,m .

Since a(, ) is bilinear, bounded, and V -elliptic, there exists a unique discrete solution u V satisfying (1), i.e. the stiness matrix A is positive denite and regular.
1 1 For Laplace problem V = S0 (T ) H0 () is the set of piecewise linear functions on the triangulation T of , being zero at the boundary. Let N denote the set of all inner nodes of the triangulation T . The nodal basis functions {z }zN are given by

z (p) =

1 for p = z, for all p N , 0 else,

such that z is an ane function on each element T T .

1.3

Stiness matrix for the Laplace problem

The entries of the stiness matrix can be determined by Ajk = a(j , k ) =

j k dx =
T zj zk T

j k dx,

(2)

where zj denotes the patch of the node zj , more precisely zj :=


T Tj , zj | T /0 1 Choosing V = S0 (T ) as above, there are three nodal basis functions on each triangle, which are not identically zero and their gradients are constant here. For xed T T , let {z1 , z2 , z3 } := T N denote the nodes of T . The gradients can be computed by 0 0 1 1 1 z1 Q := z2 = P 1 1 0 where P := xz1 xz2 xz3 . y z1 y z2 y z3 z3 0 1

T.

AIMS

2007/12/10-2007/12/15

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus Thus, the local stiness matrix AT for the triangle T = conv {z1 , z2 , z3 } is given by dx dx dx z z z z z z 1 1 1 2 1 3 T T T . . ... . . AT = . . z3 z1 dx z3 z3 dx T T 1 =|T | QQT = det(P ) QQT . 2 According to (2), the stiness matrix can be computed by summing the corresponding entries of the local stiness matrices. This can be done in a loop over the elements of the triangulation T as in FEM15.

1.4

Computation of right-hand side (RHS)

We need to compute the values of b(j ), j = 1, . . . , m b(j ) =

f j dx =
T T j |T /0 T

f j dx.

In the Laplace problem the basis functions are dened above and f 1, thus f j dx =
T T

j dx = |T |/3 = det(P )/6.

The RHS can be computed analogously by summing up the corresponding local values. See FEM15 line 12.

1.5

Boundary conditions

Boundary conditions are constraints to u or its derivative Du on the boundary of . Conditions for u on and for Du on are called Dirichlet boundary conditions and Neumann boundary conditions, respectively.

1.6

Example

The implementation of boundary conditions will be explained with respect to the following example. u=f u = uD u =g AIMS in , on D , on N = \D , (3) (4) (5) 3

2007/12/10-2007/12/15

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus where (4) and (5) represent the boundary conditions. To guarantee the existence and uniqueness of a solution (in a weak sense), D has to be a nonempty, relatively open set compared to .

1.7

Dirichlet boundary conditions

The realisation of Dirichlet boundary conditions is done with a partition of the unknown solution u. Assuming there exists a u D H 1 () which realises the Dirichlet boundary condition ( uD )|D = uD , where : H 1 () L2 ( ) is the trace operator, then u=w+u D
1 for w HD () = v H 1 () with (v )|D = 0 .

(6)

The choice of the function space H 1 () stems from the theory of weak solutions.

1.8

Weak formulation with Neumann boundary conditions

Multiplying (3) by an arbitrary test function v C (), integrating over the domain , and then integrating by parts, leads to u v dx =

f v dx +

u dx.

Hence, w v dx =

f v dx +

u dx

u D v dx

(7)

1 for all v C (). Since the unknown is w HD (), such a solution w is uniquely dened if (7) is satised for all test functions with zero boundary values on D . Hence

w v dx =

f v dx +

u dx

u D v dx for all v CD ().

Since the test function v vanishes on the Dirichlet part of the boundary, and the gradient of u is known in direction of the outer unit normal through (5), 1 we obtain the weak formulation of (3): Find w HD () such that w v dx =

f v dx +
N

vg dx

1 u D v dx for all v HD (),

(8) AIMS 2007/12/10-2007/12/15 4

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus
1 i.e. nd w V = HD () such that a(w, v ) = b(v ) for all v V , where

a(w, v ) :=

w v dx f v dx +
N

b(v ) :=

vg dx

u D v dx.

Note that a(, ) is a bounded, V -elliptic bilinear form on V and b V .

1.9

Boundary conditions in FEM

As before, the corresponding formulation for an approximation of w in a 1 nite-dimensional subspace V reads: Find w V = SD (T ) such that a(w , v ) = b(v ) for all v V , where a(w , v ) =

w v dx, f v dx +
N

b(v ) =

v g dx,

u D v dx.

For simplicity we assume the Dirichlet boundary values to be piecewise ane on the outer edges. In this case u D = u D S 1 (T ). In general, the quality of u D S 1 (T ) realising the Dirichlet boundary condition u D |D uD has an eect on the quality of u = w + u D approximating u.

1.10

Linear system of equations

As before we obtain a linear system of equations w=


j N

xj j ,

u D =
zj ND

xj j ,

x1 x2 . . . xm

b(1 ) b(2 ) = . . . b(m )

with A = (Ajk ) = (a (j , k ))1j,km .

Here the nodes 1, 2, . . . , m are the inner nodes, j are nodal basis functions and ND the set of nodes at the Dirichlet boundary. The coecients {xj }zj ND have to be determined with respect to the boundary values.

AIMS

2007/12/10-2007/12/15

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus

Exercises
E 1.1 Getting to know Octave
If you are short in experience with the programming languages Octave and Matlab, go through the short introduction linked on the website, start Octave on your computer and use the short introduction about Octave for getting familiar with that language.

E 1.2

Start rst example

Download archive FEM15.tar.gz to a new directory called CPDE2 and extract the archive by using the command tar -xvzf FEM15.tar.gz on your terminal. Change to the new directory FEM15, start octave on your computer by typing octave e.g. in the embedded terminal of gedit. Execute the script FEM15example.m by typing FEM15example on the Octave prompt.

E 1.3

Understand the program FEM15.m

Open the le FEM15.m with your favourite editor and have a look at the code. Make sure, that you understand each line of FEM15.m.

P3 Note the special structure of the data: Each vertex corresponds to one row of coordinates in c4n. Each triangle corresponds to one row of three vertices in n4e, numbered counterclockwise, starting with the vertices of the reference edge. E3 P1
d d E2 d d d

P2

E1

To understand line 10 you may execute the following lines on the command line of Octave. A=[0,1,2;3,4,5] A(2,1)=10 A=zeros(4,4) A([4,2],[3,1])=[5,6;7,8] Observe how the last example acts on selected entries of A. AIMS 2007/12/10-2007/12/15 6

Computational PDEs II Tutorial Prof. Carsten Carstensen Humboldt-Universit at zu Berlin, Germany Hella Rabus

E 1.4

Create triangulation

Modify the program FEM15example.m such that the solution of the problem u = 1 in , u = 0 on with as shown in Figure 1 will be computed.

0.5

E 1.5

P1 basis function

Write an m-le program that plots a P1 -basis function on a given grid and for a given node using triplot3 (see help triplot3 for usage).

0.5

0.5

0.5

E 1.6

50 lines of FEM code

Figure 1: L-shaped domain

1. Download the archive FEM50.tar.gz to your CPDE2 directory and extract it. 2. Run fem_50 and examine the output. 3. Create data for an initial grid on an L-shaped domain (cf. Figure 1), which can be used by fem_50. Then, solve the model problem 2 on that grid using fem_50. For better approximations use red_refine34.m to rene your mesh. Be aware of the correct structure of the geometric data, explained in exercise E 1.3.

AIMS

2007/12/10-2007/12/15

Вам также может понравиться