19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

polynomial approximations over each cell are trivially obtained by increasing<br />

the third parameter in FunctionSpace. Changing the second parameter to<br />

’DG’ creates a function space for discontinuous Galerkin methods.<br />

In mathematics, we distinguish between the trial and test spaces V and<br />

ˆV. The only difference in the present problem is the boundary conditions. In<br />

<strong>FEniCS</strong> we do not specify the boundary conditions as part of the function space,<br />

so it is sufficient to work with one common space V for the and trial and test<br />

functions in the program:<br />

u = TrialFunction(V)<br />

v = TestFunction(V)<br />

The next step is to specify the boundary condition: u = u 0 on ∂Ω. This is<br />

done by<br />

bc = DirichletBC(V, u0, u0_boundary)<br />

where u0 is an instance holding the u 0 values, and u0_boundary is a function<br />

(or object) describing whether a point lies on the boundary where u is specified.<br />

Boundary conditions of the type u = u 0 are known as Dirichlet conditions,<br />

and also as essential boundary conditions in a finite element context. Naturally,<br />

thenameoftheDOLFINclassholdingtheinformationaboutDirichletboundary<br />

conditions is DirichletBC.<br />

The u0 variable refers to an Expression object, which is used to represent<br />

a mathematical function. The typical construction is<br />

u0 = Expression(formula)<br />

whereformula is a string containing the mathematical expression. This formula<br />

is written with C++ syntax (the expression is automatically turned into an efficient,<br />

compiled C++ function, see Section 7.3 for details on the syntax). The<br />

independent variables in the function expression are supposed to be available as<br />

a point vector x, where the first element x[0] corresponds to the x coordinate,<br />

the second element x[1] to the y coordinate, and (in a three-dimensional problem)<br />

x[2] to the z coordinate. With our choice of u 0 (x,y) = 1+x 2 +2y 2 , the<br />

formula string must be written as 1 + x[0]*x[0] + 2*x[1]*x[1]:<br />

u0 = Expression(’1 + x[0]*x[0] + 2*x[1]*x[1]’)<br />

Theinformationaboutwheretoapplytheu0functionasboundarycondition<br />

is coded in a function u0_boundary:<br />

def u0_boundary(x, on_boundary):<br />

return on_boundary<br />

A function like u0_boundary for marking the boundary must return a boolean<br />

value: True if the given point x lies on the Dirichlet boundary and False<br />

11

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

Saved successfully!

Ooh no, something went wrong!