A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
important extension of our first program is therefore to examine the computed<br />
values of the solution, which is the focus of the present section.<br />
A finite element function like u is expressed as a linear combination of basis<br />
functions φ j , spanning the space V:<br />
N∑<br />
U j φ j . (13)<br />
j=1<br />
By writing solve(a == L, u, bc) in the program, a linear system will be<br />
formed from a and L, and this system is solved for the U 1 ,...,U N values. The<br />
U 1 ,...,U N values are known as degrees of freedom of u. For Lagrange elements<br />
(and many other element types) U k is simply the value of u at the node with<br />
global number k. (The nodes and cell vertices coincide for linear Lagrange<br />
elements, while for higher-order elements there may be additional nodes at the<br />
facets and in the interior of cells.)<br />
Having u represented as a Function object, we can either evaluate u(x) at<br />
any vertex x in the mesh, or we can grab all the values U j directly by<br />
u_nodal_values = u.vector()<br />
The result is a DOLFIN Vector object, which is basically an encapsulation<br />
of the vector object used in the linear algebra package that is used to solve<br />
the linear system arising from the variational problem. Since we program in<br />
Python it is convenient to convert the Vector object to a standard numpy array<br />
for further processing:<br />
u_array = u_nodal_values.array()<br />
With numpy arrays we can write ”MATLAB-like” code to analyze the data.<br />
Indexing is done with square brackets: u_array[i], where the index i always<br />
starts at 0.<br />
Mesh information can be gathered from the mesh object, e.g.,<br />
• mesh.coordinates() returns the coordinates of the vertices as an M ×d<br />
numpy array, M being the number of vertices in the mesh and d being the<br />
number of space dimensions,<br />
• mesh.num_cells() returns the number of cells (triangles) in the mesh,<br />
• mesh.num_vertices() returns the number of vertices in the mesh (with<br />
our choice of linear Lagrange elements this equals the number of nodes),<br />
Writing print mesh dumps a short, ”pretty print” description of the mesh<br />
(print mesh actually displays the result of str(mesh)‘, which defines the pretty<br />
print):<br />
<br />
18