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.

It is possible to restrict the integration to a part of the boundary using a<br />

mesh function to mark the relevant part, as explained in Section 5.3. Assuming<br />

that the part corresponds to subdomain number i, the relevant form for the<br />

flux is -p*inner(grad(u), n)*ds(i).<br />

1.12 Visualization of Structured Mesh Data<br />

When finite element computations are done on a structured rectangular mesh,<br />

maybe with uniform partitioning, VTK-based tools for completely unstructured<br />

2D/3D meshes are not required. Instead we can use visualization and data<br />

analysis tools for structured data. Such data typically appear in finite difference<br />

simulations and image analysis. Analysis and visualization of structured data<br />

arefasterandeasierthandoingthesamewithdataonunstructuredmeshes, and<br />

the collection of tools to choose among is much larger. We shall demonstrate the<br />

potential of such tools and how they allow for tailored and flexible visualization<br />

and data analysis.<br />

A necessary first step is to transform our mesh object to an object representing<br />

a rectangle with equally-shaped rectangular cells. The Python package<br />

scitools (code.google.com/p/scitools) has this type of structure, called a<br />

UniformBoxGrid. The second step is to transform the one-dimensional array<br />

of nodal values to a two-dimensional array holding the values at the corners of<br />

the cells in the structured grid. In such grids, we want to access a value by its<br />

i and j indices, i counting cells in the x direction, and j counting cells in the y<br />

direction. This transformation is in principle straightforward, yet it frequently<br />

leads to obscure indexing errors. The BoxField object in scitools takes conveniently<br />

care of the details of the transformation. With a BoxField defined on<br />

a UniformBoxGrid it is very easy to call up more standard plotting packages<br />

to visualize the solution along lines in the domain or as 2D contours or lifted<br />

surfaces.<br />

Let us go back to the vcp2D.py code from Section 1.10 and map u onto a<br />

BoxField object:<br />

import scitools.BoxField<br />

u2 = u if u.ufl_element().degree() == 1 else \<br />

interpolate(u, FunctionSpace(mesh, ’Lagrange’, 1))<br />

u_box = scitools.BoxField.dolfin_function2BoxField(<br />

u2, mesh, (nx,ny), uniform_mesh=True)<br />

The function dolfin_function2BoxField can only work with finite element<br />

fields with linear (degree 1) elements, so for higher-degree elements we here<br />

simply interpolate the solution onto a mesh with linear elements. We could also<br />

interpolate/project onto a finer mesh in the higher-degree case. Such transformations<br />

to linear finite element fields are very often needed when calling up<br />

plotting packages or data analysis tools. The u.ufl_element() method returns<br />

an object holding the element type, and this object has a method degree() for<br />

returning the element degree as an integer. The parameters nx and ny are<br />

the number of divisions in each space direction that were used when calling<br />

35

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

Saved successfully!

Ooh no, something went wrong!