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.

1.11 Computing Functionals<br />

After the solution u of a PDE is computed, we occasionally want to compute<br />

functionals of u, for example,<br />

1<br />

2 ||∇u||2 ≡ 1 ∫<br />

∇u·∇udx, (27)<br />

2<br />

which often reflects some energy quantity. Another frequently occurring functional<br />

is the error<br />

(∫ 1/2<br />

||ue −u|| = (ue −u) dx) 2 , (28)<br />

Ω<br />

where u e is the exact solution. The error is of particular interest when studying<br />

convergence properties. Sometimes the interest concerns the flux out of a part<br />

Γ of the boundary ∂Ω, ∫<br />

F = − p∇u·nds, (29)<br />

Γ<br />

where n is an outward unit normal at Γ and p is a coefficient (see the problem in<br />

Section 1.10 for a specific example). All these functionals are easy to compute<br />

with <strong>FEniCS</strong>, and this section describes how it can be done.<br />

Energy Functional. The integrand of the energy functional (27) is described<br />

in the UFL language in the same manner as we describe weak forms:<br />

energy = 0.5*inner(grad(u), grad(u))*dx<br />

E = assemble(energy)<br />

The assemble call performs the integration. It is possible to restrict the integration<br />

to subdomains, or parts of the boundary, by using a mesh function to<br />

mark the subdomains as explained in Section 5.3. The program membrane2.py<br />

carries out the computation of the elastic energy<br />

1<br />

2 ||T∇D||2 = 1 2<br />

Ω<br />

( AR<br />

8πσ<br />

in the membrane problem from Section 1.7.<br />

) 2<br />

||∇w|| 2<br />

Convergence Estimation. Toillustrateerrorcomputationsandconvergence<br />

of finite element solutions, we modify the d5_p2D.py program from Section 1.9<br />

and specify a more complicated solution,<br />

u(x,y) = sin(ωπx)sin(ωπy)<br />

on the unit square. This choice implies f(x,y) = 2ω 2 π 2 u(x,y). With ω restricted<br />

to an integer it follows that u 0 = 0.<br />

We need to define the appropriate boundary conditions, the exact solution,<br />

and the f function in the code:<br />

31

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

Saved successfully!

Ooh no, something went wrong!