# The \(R\) space¶

The function space \(R\) (for “Real”) is the space of functions which are constant over the whole domain. It is employed to model concepts such as global constraints.

## An example:¶

Warning

This section illustrates the use of the Real space using the simplest example. This is usually not the optimal approach for removing the nullspace of an operator. If that is your only goal then you are probably better placed removing the null space in the linear solver using the facilities documented in the section Solving singular systems.

Consider a Poisson equation in weak form, find \(u\in V\) such that:

where \(\Gamma(3)\) and \(\Gamma(4)\) are domain boundaries over which the boundary conditions \(\nabla u \cdot n = -1\) and \(\nabla u \cdot n = 1\) are applied respectively. This system has a null space composed of the constant functions. One way to remove this is to add a Lagrange multiplier from the space \(R\) and use the resulting constraint equation to enforce that the integral of \(u\) is zero. The resulting system is find \(u\in V\), \(r\in R\) such that:

The corresponding Python code is:

```
from firedrake import *
m = UnitSquareMesh(25, 25)
V = FunctionSpace(m, 'CG', 1)
R = FunctionSpace(m, 'R', 0)
W = V * R
u, r = TrialFunctions(W)
v, s = TestFunctions(W)
a = inner(grad(u), grad(v))*dx + u*s*dx + v*r*dx
L = -v*ds(3) + v*ds(4)
w = Function(W)
solve(a == L, w)
u, s = split(w)
exact = Function(V)
exact.interpolate(Expression('x[1] - 0.5'))
print sqrt(assemble((u - exact)*(u - exact)*dx))
```

## Representing matrices involving \(R\)¶

Functions in the space \(R\) are different from other finite element functions in that their support extends to the whole domain. To illustrate the consequences of this, we can represent the matrix in the Poisson problem above as:

where:

where \(\{\phi_i\}\) is the basis for \(V\) and \(\{\psi_i\}\) is the basis for \(R\). Note that there is only a single basis function for \(R\) and \(\psi_i \equiv 1\) hence:

with the result that \(K\) is a single dense matrix column. Similiarly, \(K^T\) is a single dense matrix row.

Using the CSR matrix format typically employed by Firedrake, each matrix row is stored on a single processor. Were this carried through to \(K^T\), both the assembly and action of this row would require the entire system state to be gathered onto one MPI process. This is clearly a horribly non-performant option.

Instead, we observe that a dense matrix row (or column) is isomorphic
to a `Function`

and implement these matrix
blocks accordingly.

## Assembling matrices involving \(R\)¶

Assembling the column block is implemented by replacing the trial function with the constant 1, thereby transforming a 2-form into a 1-form, and assembling. Similarly, assembling the row block simply requires the replacement of the test function with the constant 1, and assembling.

The one by one block in the corner is assembled by replacing both the test and trial functions of the corresponding form with 1 and assembling. The remaining block does not involve \(R\) and is assembled as usual.