For a simulation I need to integrate in a spherical coordinate system. Currently I check my code by performing the integral on the analytic case. But I failed to calculate the correct solution. The analytic function is defined as $f(r,\theta,\phi)=\frac{1}{r^2}$. Since the analytical integral would be:
$\int_0^{2\pi}\int_0^\pi\frac{1}{r^2}r^2\sin \theta d\theta d\phi=\int_0^{2\pi}2 d\phi=4\pi$.
Now the numerical integral. Say we place us on $r=2$. The sphere is discretized by 100x100 equidistant arc element. Since my element $f_i=0.25$, $\Delta\theta=\frac{r \pi}{100} =0.06346652$, $\Delta\phi=\frac{r 2\pi}{100} =0.12693304$.
For a numerical integral I would use the trapeze rule: $\sum_i^{100}f_i\Delta\theta\Delta\phi$ but this completely wrong and cannot figure out what is the correct proceeding.
The error is that the numerical integral do not provide a discrete sphere surface element. As described here Surface Element in Spherical Coordinates the integral $\int\int f(r,\theta,\phi) r^2 \sin(\theta)d\theta d\phi$. As we see the surface vanishes on both poles. My numerical definition do not take in account that the surface decrease, instead it assume that the sphere surface is composed of square tiles.
$\Delta \theta$ and $\Delta \phi$ are arc elements. Numerically the sum $\sum_i^{100} f_i \Delta \theta$ can be refereed to arc integration such as $\int f(r,\theta,\phi) r d\theta$. There I get the correct solution.
For numerical surface integration I first need a mesh, where the tiles have a specific surface.
https://i.stack.imgur.com/3LPIA.jpg