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.

FunctionSpace, etc.). Many use instance and object as interchangeable terms.<br />

In other computer programming languages one may also use the term variable<br />

for the same thing. We mostly use the well-known term object in this text.<br />

A subclass of SubDomain with an inside method offers functionality for<br />

marking parts of the domain or the boundary. Now we need to define one class<br />

for the subdomain Ω 0 where y ≤ 1/2 and another for the subdomain Ω 1 where<br />

y ≥ 1/2:<br />

class Omega0(SubDomain):<br />

def inside(self, x, on_boundary):<br />

return True if x[1] = 0.5 else False<br />

Notice the use of = in both tests. For a cell to belong to, e.g., Ω 1 ,<br />

the inside method must return True for all the vertices x of the cell. So to<br />

make the cells at the internal boundary y = 1/2 belong to Ω 1 , we need the test<br />

x[1] >= 0.5.<br />

The next task is to use a MeshFunction to mark all cells in Ω 0 with the<br />

subdomain number 0 and all cells in Ω 1 with the subdomain number 1. Our<br />

convention is to number subdomains as 0,1,2,....<br />

A MeshFunction is a discrete function that can be evaluated at a set of socalled<br />

mesh entities. Examples of mesh entities are cells, facets, and vertices. A<br />

MeshFunction over cells is suitable to represent subdomains (materials), while<br />

a MeshFunction over facets is used to represent pieces of external or internal<br />

boundaries. Mesh functions over vertices can be used to describe continuous<br />

fields.<br />

Since we need to define subdomains of Ω in the present example, we must<br />

make use of a MeshFunction over cells. The MeshFunction constructor is fed<br />

with three arguments: 1) the type of value: ’int’ for integers, ’uint’ for<br />

positive (unsigned) integers, ’double’ for real numbers, and ’bool’ for logical<br />

values; 2) a Mesh object, and 3) the topological dimension of the mesh entity in<br />

question: cells have topological dimension equal to the number of space dimensions<br />

in the PDE problem, and facets have one dimension lower. Alternatively,<br />

the constructor can take just a filename and initialize the MeshFunction from<br />

data in a file.<br />

We start with creating a MeshFunction whose values are non-negative integers<br />

(’uint’) for numbering the subdomains. The mesh entities of interest are<br />

the cells, which have dimension 2 in a two-dimensional problem (1 in 1D, 3 in<br />

3D). The appropriate code for defining the MeshFunction for two subdomains<br />

then reads<br />

subdomains = MeshFunction(’uint’, mesh, 2)<br />

# Mark subdomains with numbers 0 and 1<br />

subdomain0 = Omega0()<br />

subdomain0.mark(subdomains, 0)<br />

76

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

Saved successfully!

Ooh no, something went wrong!