0

I've recently started looking into writing a finite-differences-based solver for the Poisson equation of the form $$\nabla\left(\varepsilon\nabla\varphi\right)=\rho$$ in 2D for arbitrary geometries (some additional details can be found here). However, I've soon discovered that upon imposing pure Neumann boundaries the system no longer can be solved in a straight forward manner, as the problem becomes ill-posed. First I thought the failure to solve the system arises perhaps due to some kind of a limitation of the solver I use (successive relaxation method), but from answer here I learned that the compatibility conditions are not satisfied in my problem (in particular the discrete compatibility condition), on top of the fact that the all Neumann boundaries make it an ill-posed problem (Edit: not sure about the nomenclature here, but the lack of satisfied compatibility condition could be classified as an ill-conditioned problem).

Now, how I understood one can impose the compatibility condition is just to modify the right-hand side (RHS) of the Poisson equation (including both the original $\rho$ and the Neumann boundary conditions that are stored in the RHS vector) by subtracting its mean as: $$\rho_{h}=\rho-mean(\rho),$$ where mean is calculated over all points in the vector $\rho$. This should be trivial enough, right? Well, my implementation of this in C++ did not yield any results and the convergence issues continued. In fact, the solvers I tried out with this (SOR, biCGstat, CG, CGsquare) all failed to converge as their respective residuals either diverged or just get stuck at a particular value and looped around it until the iteration reached maximal allowed iteration count.

I have recently encountered this post, where a user complains about a similar issue. He, luckily, managed to resolve it, but did not go too much into the details (he only explained that something was incorrect with the counter for the mean value calculation/subtraction).

Thus I wanted to ask if somebody can explain the practical implementation details of the discrete compatibility condition. What needs to be taken into account when calculating the average of the RHS vector, and what needs to be taken into account when subtracting the said average from the original RHS?

Akhaim
  • 83
  • 10

2 Answers2

1

It is actually not that complicated, try to think less analytically.

Assume you have already given the ill-posed & ill-conditioned system $A u=f$ of the original Poisson Neumann problem ($\varphi\equiv u,~\rho\equiv f, \epsilon =1).$ All you have to do is to introduce one single constraint

\begin{align} \frac{1}{b-a}\int_a^b u \,\mathrm{d}x&=0, \\ \int_a^b u \,\mathrm{d}x&=0, \end{align}

which can be discretisized with the most simple quadrature rule (rectangle rule)

\begin{align} \sum_{i=1}^N h u_i &=0, \\ u_1 +u_2 + \dots + u_N &= 0 \equiv \lambda. \end{align}

Now add this single line to your system

$$\begin{bmatrix} A \\ 1^T \end{bmatrix} \begin{bmatrix} u \end{bmatrix} = \begin{bmatrix} f \\ 0\end{bmatrix}.$$

At this point your system is still irregular because you have more lines than columns. In order to fix this add a "clever" zero using $\lambda$ resulting in

$$\begin{bmatrix} A & 1 \\ 1^T & 0 \end{bmatrix} \begin{bmatrix} u \\ \lambda \end{bmatrix} = \begin{bmatrix} f \\ 0 \end{bmatrix}$$

which is invertible and solvable by most standard solvers.

Edit: Credits to @Will P. which however is not general at all.

The Poisson equation with Neumann BCs is given by

\begin{align} \Delta u(x) &= f(x),\qquad x\in\Omega\\ \frac{\partial u(x)}{\partial\mathbf n} &= g(x),\qquad x\in\partial\Omega. \end{align}

To actually be well posed the divergence theorem has to be fullfilled

\begin{align} \int_\Omega f(x)\,dV = \int_\Omega \operatorname{div}\nabla u(x) \,dV = \oint_{\partial\Omega}\nabla u(x)\cdot \mathbf n(x)\,dS = \oint_{\partial\Omega} g(x)\,dS, \end{align}

which ultimately results in following condition

\begin{align} \int_\Omega f(x)\,dV = \oint_{\partial\Omega} g(x)\,dS. \end{align}

Note that the answer by @Will P. only covers the case $\oint_{\partial\Omega} g(x) = 0$.

ConvexHull
  • 1,287
  • 1
  • 4
  • 11
  • thanks for the answer. Just to check one thing - the constraint you suggest, it is to ensure the uniqueness of the solution, right? As far as I understand, if the discrete compatibility condition is not satisfied, Poisson-Neumann problem cannot be solved at all, so the uniqueness of the solution is not really a problem at that stage. My understanding is that only when compatibility condition is satisfied one should be concerned with the uniqueness of the solution, and even then depending on the initial condition some of the iterative solvers should still converge to a solution. – Akhaim Nov 13 '22 at 21:35
  • I am not quite sure about your comment. You may confuse the topics ill-posed and ill-conditioned. – ConvexHull Nov 13 '22 at 22:01
  • I am not sure you understood my question properly. Please refer to this link https://scicomp.stackexchange.com/questions/34493/residual-of-poisson-equation-with-periodic-boundaries in order to understand what is meant by the discrete compatibility condition and how it differs from uniqueness constraint you use in your post. – Akhaim Nov 13 '22 at 23:31
  • I am not sure what the link is supposed to tell me. The extra condition for $f$ is not needed (from a numerical point of view) and even wrong for other arbitrary source terms. I removed the term compatibilty condition for $u$ in my answer to avoid confusion. – ConvexHull Nov 14 '22 at 18:34
  • Also note that pure Neumann BCs ist not the same as pure periodic BCs. – ConvexHull Nov 14 '22 at 20:29
  • Despite it being my favorite, one drawback of this Lagrange multiplier approach is that the positive system is now indefinite which can lead to lack of convergence for some solvers. In this case it might be more practical to do the (admittedly hackier) typical solutions: either removing the mean of the forcing data to place it back into the range of the operator (the OP's original line of thought), or introducing an (arbitrary) dirichlet condition that forces the phi=0 at some node as a reference potential. – rchilton1980 Nov 15 '22 at 19:57
  • @rchilton1980 Thanks for your reply. Subtracting the mean is not general at all and even incorrect for inhomogeneous Neumann BCs. See my updated answer. – ConvexHull Nov 15 '22 at 20:03
  • Your updated answer is exactly what I was talking about - this integral is the continuous compatibility condition I am trying to implement (or at least its discrete version). It could be that we had nomenclature miscommunication, as literature sometimes calls the divergence theorem the compatibility condition. In case when I apply Neumann boundaries such that their mean is zero, and if RHS vector $\rho$ is also zero, then my solvers can easily converge without any additional constraint (as the divergence theorem is satisfied)... – Akhaim Nov 15 '22 at 20:29
  • ... However, by introducing NBC such that they do not add up to a zero then the solvers either diverge or stall (dependent on the type of the solver). It is from there where I want to find a solution to always impose a total RHS vector such that it has zero mean value, as this should satisfy the divergence theorem (i.e. the compatibility condition) – Akhaim Nov 15 '22 at 20:30
  • @rchilton1980, introducing the Dirichlet condition at a single point is un-physical and causes a peak in the distribution of $\varphi$. Thus I want to avoid this approach. – Akhaim Nov 15 '22 at 20:38
  • @Akhaim Unfortunately as already mentioned in the other topics, iff the methods are properly implemented you should (in most cases) achieve convergence. The Lagrange multiplier method is generally the cleanest solution. – ConvexHull Nov 15 '22 at 20:53
  • @ConvexHull, perhaps I am too stubborn to see it and I apologize for it, but it seems to me that Lagrange multipliers will only force the solver to pick a solution without a mean value, which is fine. But what if the divergence theorem is not satisfied to begin with? Can such problem be solved then with this formulation? – Akhaim Nov 15 '22 at 20:59
  • The divergence theorem condition is a pre-processing step and only necessary for well-posedness. With the Lagrange multiplier method you can even achieve convergence if the problem is ill-posed. This is non-sense from a modelling or physical point of view. However, does not prevent the numerics to generate a solution. Note that the answer of @lightxbulb is also quite complete, however I see a few things differently. – ConvexHull Nov 15 '22 at 21:35
  • @ConvexHull, yeah, I also checked his answer in the meantime (lightxbulb), and, though more complex, I get the idea now, as he also presents the general form of Lagrange multipliers. I think I see your point now too, where in your case the Lagrange multipliers constraint already assume specific form, if I understand it correctly. On the other hand, the discussion in comments I had with lightxbulb pointed me to try and implement the trick with the mean subtraction from the RHS of the Poisson equation, at least for the case of constant (homogeneous) NBCs. – Akhaim Nov 15 '22 at 21:47
  • ... However, that failed and I wanted to get to the bottom of that. This is why I posed the question here, hoping that perhaps I am overlooking something logically, and not just that I have an error in the code – Akhaim Nov 15 '22 at 21:49
1

The problem $$ \nabla (\varepsilon \nabla u) = \rho $$ with pure Neumann conditions admits a family of solutions that differ by a constant value (i.e. $u + c$ is also a solution, for any constant $c$).

For most numerical methods, after discretizing, you will obtain a linear system $$ L \boldsymbol{u} = \boldsymbol{\rho}, $$ where $L$ is a symmetric matrix with a one-dimensional nullspace spanned by the constants, i.e. $$ L \boldsymbol{1} = \boldsymbol{0}, $$ where $\boldsymbol{1}$ is the vector with 1 in every entry.

In order for the discrete problem to be well posed, you need $\boldsymbol{\rho}$ to be in the range of $L$. Note that for any $\boldsymbol{y} \in \operatorname{Range}(L)$ (i.e. with $\boldsymbol{y} = L \boldsymbol{x}$, we have $$ \boldsymbol{1}^T \boldsymbol{y} = 0, $$ since, by symmetry of $L$, $$ \boldsymbol{1}^T \boldsymbol{y} = \boldsymbol{1}^T L \boldsymbol{x} = \boldsymbol{1}^T L^T \boldsymbol{x} = \boldsymbol{0}^T \boldsymbol{x} = 0. $$

Therefore, the discrete compatibility condition is that the vector $\boldsymbol{1}$ should be orthogonal to your right-hand side.

Assume you are given $\tilde{\boldsymbol{\rho}}$, which may not satisfy this condition. You can set $$ \boldsymbol{\rho} = \tilde{\boldsymbol{\rho}} - \left( \frac{\boldsymbol{1}^T \tilde{\boldsymbol{\rho}}}{n} \right) \boldsymbol{1}, $$ where $n$ is the dimension of the discrete space (i.e. $L \in \mathbb{R}^{n \times n}$). This is what is meant by subtracting off the mean of $\tilde{\boldsymbol{\rho}}$. It is easy to check that this modified vector $\boldsymbol{\rho}$ satisfies the discrete compatibility condition. Then, the linear system $$ L \boldsymbol{u} = \boldsymbol{\rho} $$ will have a solution.

The conjugate gradient method applied to this problem will converge to a solution without performing any special modifications (see this answer).

Note that if you are using preconditioned conjugate gradient, you may need to ensure that the output of the preconditioner remains orthogonal to $\boldsymbol{1}$. This can be achieved by performing an orthogonalization step every preconditioner application (i.e, if $M$ is the preconditioner, first compute $\tilde{\boldsymbol{z}} = M^{-1} \boldsymbol{r}$, and then set $\boldsymbol{z} = \tilde{\boldsymbol{z}} - \left( \frac{\boldsymbol{1}^T \tilde{\boldsymbol{z}}}{n} \right) \boldsymbol{1}$). If you are not using a preconditioner, this is not necessary.

Will P.
  • 821
  • 5
  • 6
  • Your answer only covers the homogeneous case of Neumann BCs. Anyway, thank you for your hint. See my updated answer. – ConvexHull Nov 15 '22 at 19:53
  • Will P., so my problem comes exactly here - I implement the same condition you gave in the form of $\rho_h=\rho-mean(\rho)$, where the mean value is a sum over all points in $\rho$ and scaled by the total number of points in $\rho$ matrix. However, the solver then fails to converge. But if I pick such NBCs so that their mean is zero, and apply them to e.g. Laplace PDF, everything works perfectly, I do not even need to subtract any average from the right hand side vector. From there I am convinced I am doing something wrong when imposing this condition, but I have no idea what it is. – Akhaim Nov 15 '22 at 20:46
  • @Akhaim, can you check that the matrix that results from your discretization is symmetric positive-semidefinite, and has a one-dimensional nullspace spanned by the constants? If those conditions hold, then the described procedure should work. Perhaps something nonstandard in your discretization is causing an issue with the matrix. – Will P. Nov 16 '22 at 19:43
  • @WillP. that could be a good test and I think I can try it out fairly straightforwardly. My discretization scheme is nothing fancy - central differences, applied in a rectangular box with equal grid spacing in $x$ and $y$ directions. For the sake of simplicity, I even set $\varepsilon$ to a constant value, so that it does not contribute to the problem. – Akhaim Nov 18 '22 at 11:39