/** # Convergence of the Poisson solver in 1D On this page we try to find some of the convergence properties of the Basilisk poisson solver. The used solver is of the 'multi-grid' type and untilizes an iterative scheme to arrive at an converged solution. By default the solver iterates untill the maximum residual is below some set tolerance. On this page we solve a Poisson problem on 11 different grids with various levels of refinement and let the solver iterate (i.e. Cycle) ten times. We will check the convergence properties with respect to the cycles applied and the resolution. The goal is to check if we obtain sensible results so we can extend our analysis to grids generated according to an adaptive algorithm. ## The chosen Problem The Poisson problem we will be solving for reads, $$\frac{\partial^2 a}{\partial x^2}=e^{-x^2}.$$ According to [Wolfram|Alpha](https://www.wolframalpha.com/input/?i=int+int+exp(-x%5E2)) the corresponding solution is, $$a=c_2+c_1x+\frac{\sqrt{\pi}}{2}\mathrm{erf}(x)+\frac{e^{-x^2}}{2},$$ with constants $c_1$ and $c_2$ determined by the boundary conditions. ## The script The Poisson solver is included and we opt for a one dimensional tree grid. The tree functionality will be usefull later. */ #include "grid/bitree.h" #include "poisson.h" /** The analyical solution can be evaluated to check the numerical solution. Furthermore, we initialize some usefull stuff. */ #define sol(x,c1,c2) ((c1*x)+c2+(pow(M_PI,0.5)*(x)*erf(x)/2)+(exp(-(x*x))/2)) double c1,c2; scalar b[],a[]; mgstats mg; FILE * fp1; FILE * fp2; char name[100]; /** Since our solution represents volume averaged values we need to translate the analytical solution to a locally averaged one. Unfortunately, Wolfram Alpha was unable to provide me with the the integal form of the solution. Therefore a numerical integrator of the analytical solution is defined */ double numintsol(double tol,double xi, double D,double c1,double c2){ //A Riemann integrator double into=5; double intn=1; double integral; double j=10; while ((fabs(into-intn)/fabs(intn))>tol){ // Perform the integration untill the integral has converged into=intn; intn=0.; integral=0; for (int m=0;m