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.

dev = numpy.abs(w_e.vector().array() - w.vector().array()).max()<br />

print ’sigma=%g: max deviation=%e’ % (sigma, dev)<br />

# Should be at the end<br />

interactive()<br />

Choosing a small width σ (say 0.01) and a location (x 0 ,y 0 ) toward the<br />

circular boundary (say (0.6Rcosθ,0.6Rsinθ) for any θ ∈ [0,2π]), may produce<br />

an exciting visual comparison of w and f that demonstrates the very smoothed<br />

elastic response to a peak force (or mathematically, the smoothing properties<br />

of the inverse of the Laplace operator). One needs to experiment with the<br />

mesh resolution to get a smooth visual representation of f. You are strongly<br />

encouraged to play around with the plots and different mesh resolutions.<br />

1.8 Quick Visualization with VTK<br />

As we go along with examples it is fun to play around with plot commands<br />

and visualize what is computed. This section explains some useful visualization<br />

features.<br />

The plot(u) command launches a <strong>FEniCS</strong> component called Viper, which<br />

applies the VTK package to visualize finite element functions. Viper is not a<br />

full-fledged, easy-to-use front-end to VTK (like Mayavi2, ParaView or, VisIt),<br />

but rather a thin layer on top of VTK’s Python interface, allowing us to quickly<br />

visualize a DOLFIN function or mesh, or data in plain Numerical Python arrays,<br />

within a Python program. Viper is ideal for debugging, teaching, and<br />

initial scientific investigations. The visualization can be interactive, or you can<br />

steer and automate it through program statements. More advanced and professional<br />

visualizations are usually better done with advanced tools like Mayavi2,<br />

ParaView, or VisIt.<br />

We have made a program membrane1v.py for the membrane deflection problem<br />

in Section 1.7 and added various demonstrations of Viper capabilities. You<br />

are encouraged to play around with membrane1v.py and modify the code as you<br />

read about various features.<br />

The plot function can take additional arguments, such as a title of the plot,<br />

or a specification of a wireframe plot (elevated mesh) instead of a colored surface<br />

plot:<br />

plot(mesh, title=’Finite element mesh’)<br />

plot(w, wireframe=True, title=’solution’)<br />

The three mouse buttons can be used to rotate, translate, and zoom the<br />

surface. Pressing h in the plot window makes a printout of several key bindings<br />

that are available in such windows. For example, pressing m in the mesh plot<br />

window dumps the plot of the mesh to an Encapsulated PostScript (.eps) file,<br />

while pressing i saves the plot in PNG format. All plotfile names are automatically<br />

generated as simulationX.eps, where X is a counter 0000, 0001, 0002,<br />

etc., being increased every time a new plot file in that format is generated (the<br />

24

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

Saved successfully!

Ooh no, something went wrong!