# Imposing zero mean condition in FEM

I wanted to solve a periodic elliptic equation of the form $$-\nabla\cdot(A\nabla u)=-\nabla\cdot F$$ on $$Y=[0,2\pi)^d$$ using FreeFem++, where $$A$$ and $$F$$ are $$Y$$-periodic. The space of solutions is $$H^1_{per}(Y)/\mathbb{R}$$, which can also be seen as the space of periodic $$H^1$$ functions with zero mean. How does one typically impose the zero mean condition in FEM?

The second approach, which may be easier, is to modify the system so that one nodal value inside the domain is clamped to zero, i.e., you impose $$u_{i^*} = 0$$ for some index $$i^*$$, where $$\mathbf{u} = (u_1, \ldots, u_N)^\top$$ is the vector of nodal values of your discrete solution $$u_h$$. This is obtained by replacing an equation $$u_{i^*} = 0$$ on the $$i^*$$-th line of your FEM linear system. Then, your final solution $$u_h$$ is obtained as $$u_h \leftarrow u_h - \frac{1}{|Y|}\int_{Y} u_h,$$ where $$|Y| = (2\pi)^d$$, which is trivially zero-mean.