
This demo illustrates how to solve Poisson equation using an
alternative mixed formulation. In particular, it illustrates how to

* Use mixed and non-continuous finite element spaces
* Set essential boundary conditions for subspaces

Equation and problem definition
-------------------------------

A formulation of Poisson equation involves introducing an additional
(vector) variable, namely the (negative) flux: :math:`\sigma = -
\nabla u`. The partial differential equations then read

.. math::
   \sigma + \nabla u &= 0 \quad {\rm in} \ \Omega, \\
   \nabla \cdot \sigma &= f \quad {\rm in} \ \Omega,

with boundary conditions

.. math::
   u = u_0 \quad {\rm on} \ \Gamma_{D},  \\
   - \sigma \cdot n = g \quad {\rm on} \ \Gamma_{N}.

The same equations arise in connection with flow in porous media,
where thery are referred to as Darcy flow.

After multiplying by test functions :math:`\tau` and :math:`v`,
integrating over the domain, and integrating term :math:`\nabla \cdot
\sigma \ v` by parts, one obtains the following variational
formulation: find :math:`\sigma \in \Sigma` and :math:`v \in V`
satisfying

.. math::
   \int_{\Omega} (\sigma \cdot \tau + \nabla u \cdot \ \tau) \ {\rm d} x
   &= 0
   \quad \forall \ \tau \in \Sigma, \\

   \int_{\Omega} \sigma \cdot \nabla v \ {\rm d} x
   &= - \int_{\Omega}     f \ v \ {\rm d} x
      - \int_{\Gamma_{N}} g \ v \ {\rm d} x
   \quad \forall \ v \in V.

Compared to classical mixed formulation used in demo `Mixed
formulation for Poisson equation`, the Dirichlet condition is here
essential one and Neumann condition is natural.

To discretize the above formulation, two discrete function spaces
:math:`\Sigma_h \subset \Sigma` and :math:`V_h \subset V` are needed
to form a mixed function space :math:`\Sigma_h \times V_h`. A stable
choice of finite element spaces is to let :math:`\Sigma_h` be the
discontinuous Raviart-Thomas elements of polynomial order :math:`k`
and let :math:`V_h` be Lagrange elements of polynomial order
:math:`k+1`.

We will use the same definitions of functions and boundaries as in the
demo for Poisson's equation. These are:

* :math:`\Omega = [0,1] \times [0,1]` (a unit square)
* :math:`\Gamma_{D} = \{(0, y) \cup (1, y) \in \partial \Omega\}`
* :math:`\Gamma_{N} = \{(x, 0) \cup (x, 1) \in \partial \Omega\}`
* :math:`u_0 = 0`
* :math:`g = \sin(5x)`   (flux)
* :math:`f = 10\exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)`   (source term)

With the above input the solution for :math:`u` and :math:`\sigma`
will look as follows:

.. image:: ../mixed-poisson-dual_u.png
    :scale: 75
    :align: center

.. image:: ../mixed-poisson-dual_sigma.png
    :scale: 75
    :align: center
