19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>FEniCS</strong> is quite limited. And Python is an easy-to-learn language that you<br />

certainly will love and use far beyond <strong>FEniCS</strong> programming.) Section 7.9 lists<br />

some relevant Python books.<br />

The listed <strong>FEniCS</strong> program defines a finite element mesh, the discrete function<br />

spaces V and ˆV correspondingto this mesh and the element type, boundary<br />

conditions for u (the function u 0 ), a(u,v), and L(v). Thereafter, the unknown<br />

trial function u is computed. Then we can investigate u visually or analyze the<br />

computed values.<br />

The first line in the program,<br />

from dolfin import *<br />

imports the key classes UnitSquare, FunctionSpace, Function, and so forth,<br />

from the DOLFIN library. All <strong>FEniCS</strong> programs for solving PDEs by the finite<br />

element method normally start with this line. DOLFIN is a software library<br />

with efficient and convenient C++ classes for finite element computing, and<br />

dolfin is a Python package providing access to this C++ library from Python<br />

programs. You can think of <strong>FEniCS</strong> as an umbrella, or project name, for a<br />

set of computational components, where DOLFIN is one important component<br />

for writing finite element programs. The from dolfin import * statement<br />

imports other components too, but newcomers to <strong>FEniCS</strong> programming do not<br />

need to care about this.<br />

The statement<br />

mesh = UnitSquare(6, 4)<br />

defines a uniform finite element mesh over the unit square [0,1] × [0,1]. The<br />

mesh consists of cells, which are triangles with straight sides. The parameters<br />

6 and 4 tell that the square is first divided into 6 × 4 rectangles, and then<br />

each rectangle is divided into two triangles. The total number of triangles then<br />

becomes 48. The total number of vertices in this mesh is 7·5 = 35. DOLFIN<br />

offers some classes for creating meshes over very simple geometries. For domains<br />

of more complicated shape one needs to use a separate preprocessor program to<br />

create the mesh. The <strong>FEniCS</strong> program will then read the mesh from file.<br />

Having a mesh, we can define a discrete function space V over this mesh:<br />

V = FunctionSpace(mesh, ’Lagrange’, 1)<br />

The second argument reflects the type of element, while the third argument is<br />

the degree of the basis functions on the element. The type of element is here<br />

”Lagrange”, implying thestandard Lagrangefamily of elements. (Some <strong>FEniCS</strong><br />

programs use ’CG’, for Continuous Galerkin, as a synonym for ’Lagrange’.)<br />

With degree 1, we simply get the standard linear Lagrange element, which is a<br />

triangle with nodes at the three vertices. Some finite element practitioners refer<br />

to this element as the ”linear triangle”. The computed u will be continuous<br />

and linearly varying in x and y over each cell in the mesh. Higher-degree<br />

10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!