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.

The resulting program has the name d6_p2D.py and computes error norms in<br />

various ways. Running this program for elements of first degree and ω = 1<br />

yields the output<br />

h=1.25E-01 E=3.25E-02 r=1.83<br />

h=6.25E-02 E=8.37E-03 r=1.96<br />

h=3.12E-02 E=2.11E-03 r=1.99<br />

h=1.56E-02 E=5.29E-04 r=2.00<br />

h=7.81E-03 E=1.32E-04 r=2.00<br />

h=3.79E-03 E=3.11E-05 r=2.00<br />

That is, we approach the expected second-order convergence of linear Lagrange<br />

elements as the meshes become sufficiently fine.<br />

Running the program for second-degree elements results in the expected<br />

value r = 3,<br />

h=1.25E-01 E=5.66E-04 r=3.09<br />

h=6.25E-02 E=6.93E-05 r=3.03<br />

h=3.12E-02 E=8.62E-06 r=3.01<br />

h=1.56E-02 E=1.08E-06 r=3.00<br />

h=7.81E-03 E=1.34E-07 r=3.00<br />

h=3.79E-03 E=1.53E-08 r=3.00<br />

However, using (u - u_e)**2 for the error computation, which implies interpolating<br />

u_e onto the same space as u, results in r = 4 (!). This is an example<br />

where it is important to interpolate u_e to a higher-order space (polynomials<br />

of degree 3 are sufficient here) to avoid computing a too optimistic convergence<br />

rate.<br />

Running the program for third-degree elements results in the expected value<br />

r = 4:<br />

h= 1.25E-01 r=4.09<br />

h= 6.25E-02 r=4.03<br />

h= 3.12E-02 r=4.01<br />

h= 1.56E-02 r=4.00<br />

h= 7.81E-03 r=4.00<br />

Checking convergence rates is the next best method for verifying PDE codes<br />

(the best being exact recovery of a solution as in Section 1.6 and many other<br />

places in this tutorial).<br />

Flux Functionals. To compute flux integrals like (29) we need to define the<br />

n vector, referred to as facet normal in <strong>FEniCS</strong>. If Γ is the complete boundary<br />

we can perform the flux computation by<br />

n = FacetNormal(mesh)<br />

flux = -p*dot(nabla_grad(u), n)*ds<br />

total_flux = assemble(flux)<br />

Although nabla_grad(u) and grad(u) are interchangeable in the above expression<br />

when u is a scalar function, we have chosen to write nabla_grad(u)<br />

because this is the right expression if we generalize the underlying equation<br />

to a vector Laplace/Poisson PDE. With grad(u) we must in that case write<br />

dot(n, grad(u)).<br />

34

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

Saved successfully!

Ooh no, something went wrong!