| 1 |
UFL input for mixed formulation of Poisson Equation |
| 2 |
=================================================== |
| 3 |
|
| 4 |
First we define the variational problem in UFL which we save in the |
| 5 |
file called :download:`MixedPoisson.ufl`. |
| 6 |
|
| 7 |
We begin by defining the finite element spaces. We define two finite |
| 8 |
element spaces :math:`\Sigma_h = BDM` and :math:`V_h = DG` separately, |
| 9 |
before combining these into a mixed finite element space: :: |
| 10 |
|
| 11 |
from ufl_legacy import (Coefficient, div, dot, dx, FiniteElement, |
| 12 |
TestFunctions, TrialFunctions, triangle) |
| 13 |
|
| 14 |
BDM = FiniteElement("BDM", triangle, 1) |
| 15 |
DG = FiniteElement("DG", triangle, 0) |
| 16 |
W = BDM * DG |
| 17 |
|
| 18 |
The first argument to :py:class:`FiniteElement` specifies the type of |
| 19 |
finite element family, while the third argument specifies the |
| 20 |
polynomial degree. The UFL user manual contains a list of all |
| 21 |
available finite element families and more details. The * operator |
| 22 |
creates a mixed (product) space ``W`` from the two separate spaces |
| 23 |
``BDM`` and ``DG``. Hence, |
| 24 |
|
| 25 |
.. math:: |
| 26 |
|
| 27 |
W = \{ (\tau, v) \ \text{such that} \ \tau \in BDM, v \in DG \}. |
| 28 |
|
| 29 |
Next, we need to specify the trial functions (the unknowns) and the |
| 30 |
test functions on this space. This can be done as follows :: |
| 31 |
|
| 32 |
(sigma, u) = TrialFunctions(W) |
| 33 |
(tau, v) = TestFunctions(W) |
| 34 |
|
| 35 |
Further, we need to specify the source :math:`f` (a coefficient) that |
| 36 |
will be used in the linear form of the variational problem. This |
| 37 |
coefficient needs be defined on a finite element space, but none of |
| 38 |
the above defined elements are quite appropriate. We therefore define |
| 39 |
a separate finite element space for this coefficient. :: |
| 40 |
|
| 41 |
CG = FiniteElement("CG", triangle, 1) |
| 42 |
f = Coefficient(CG) |
| 43 |
|
| 44 |
Finally, we define the bilinear and linear forms according to the equations: :: |
| 45 |
|
| 46 |
a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx |
| 47 |
L = - f*v*dx |