| 1 |
UFL input for the Biharmonic equation |
| 2 |
===================================== |
| 3 |
|
| 4 |
Import required classes:: |
| 5 |
|
| 6 |
from ufl_legacy import (avg, CellDiameter, Coefficient, |
| 7 |
div, dot, dS, dx, |
| 8 |
FacetNormal, FiniteElement, grad, |
| 9 |
inner, jump, |
| 10 |
TestFunction, TrialFunction, triangle) |
| 11 |
|
| 12 |
The finite element space is defined:: |
| 13 |
|
| 14 |
element = FiniteElement("Lagrange", triangle, 2) |
| 15 |
|
| 16 |
On the space ``element``, trial and test functions, and the source |
| 17 |
term are defined:: |
| 18 |
|
| 19 |
# Trial and test functions |
| 20 |
u = TrialFunction(element) |
| 21 |
v = TestFunction(element) |
| 22 |
f = Coefficient(element) |
| 23 |
|
| 24 |
|
| 25 |
Next, the outward unit normal to cell boundaries and a measure of the |
| 26 |
cell size are defined. The average size of cells sharing a facet will |
| 27 |
be used (``h_avg``). The UFL syntax ``('+')`` and ``('-')`` restricts |
| 28 |
a function to the ``('+')`` and ``('-')`` sides of a facet, |
| 29 |
respectively. The penalty parameter ``alpha`` is made a |
| 30 |
:cpp:class:`Constant` so that it can be changed in the program without |
| 31 |
regenerating the code. :: |
| 32 |
|
| 33 |
# Normal component, mesh size and right-hand side |
| 34 |
n = FacetNormal(triangle) |
| 35 |
h = CellDiameter(triangle) |
| 36 |
h_avg = (h('+') + h('-'))/2 |
| 37 |
|
| 38 |
# Parameters |
| 39 |
alpha = Coefficient(FiniteElement("Real", triangle, 0)) |
| 40 |
|
| 41 |
Finally the bilinear and linear forms are defined. Integrals over |
| 42 |
internal facets are indicated by ``*dS``. :: |
| 43 |
|
| 44 |
# Bilinear form |
| 45 |
a = inner(div(grad(u)), div(grad(v)))*dx \ |
| 46 |
- inner(avg(div(grad(u))), jump(grad(v), n))*dS \ |
| 47 |
- inner(jump(grad(u), n), avg(div(grad(v))))*dS \ |
| 48 |
+ alpha/h_avg*inner(jump(grad(u), n), jump(grad(v),n))*dS |
| 49 |
|
| 50 |
# Linear form |
| 51 |
L = f*v*dx |
| 52 |
|
| 53 |
Before the form file can be used in the C++ program, it must be |
| 54 |
compiled using FFC by running (on the command-line): |
| 55 |
|
| 56 |
.. code-block:: sh |
| 57 |
|
| 58 |
ffc -l dolfin Biharmonic.ufl |