A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Instead of nabla_grad we could also just have written grad in the examples<br />
in this tutorial. However, when taking gradients of vector fields, grad and<br />
nabla_grad differ. The latter is consistent with the tensor algebra commonly<br />
used to derive vector and tensor PDEs, where the ”nabla” acts as a vector<br />
operator, and therefore this author prefers to always use nabla_grad.<br />
HavingaandLdefined,andinformationaboutessential(Dirichlet)boundary<br />
conditions in bc, we can compute the solution, a finite element function u, by<br />
u = Function(V)<br />
solve(a == L, u, bc)<br />
Some prefer to replace a and L by an equation variable, which is accomplished<br />
by this equivalent code:<br />
equation = inner(nabla_grad(u), nabla_grad(v))*dx == f*v*dx<br />
u = Function(V)<br />
solve(equation, u, bc)<br />
Note that we first defined the variable u as a TrialFunction and used it<br />
to represent the unknown in the form a. Thereafter, we redefined u to be a<br />
Function object representing the solution, i.e., the computed finite element<br />
function u. This redefinition of the variable u is possible in Python and often<br />
done in <strong>FEniCS</strong> applications. The two types of objects that u refers to are<br />
equal from a mathematical point of view, and hence it is natural to use the<br />
same variable name for both objects. In a program, however, TrialFunction<br />
objects must always be used for the unknowns in the problem specification (the<br />
form a), while Function objects must be used for quantities that are computed<br />
(known).<br />
The simplest way of quickly looking at u and the mesh is to say<br />
plot(u)<br />
plot(mesh)<br />
interactive()<br />
The interactive() call is necessary for the plot to remain on the screen. With<br />
the left, middle, and right mouse buttons you can rotate, translate, and zoom<br />
(respectively) the plotted surface to better examine what the solution looks like.<br />
Figures 1 and 2 display the resulting u function and the finite element mesh,<br />
respectively.<br />
It is also possible to dump the computed solution to file, e.g., in the VTK<br />
format:<br />
file = File(’poisson.pvd’)<br />
file