I have been working on the PoissonSolver. You can check my progress in my PoissonSolver branch.
It now calculates the electric field and saves it in the Ex and Ey
arrays of the grid. I am currently testing it...Here you can see the
potential and electric field of a point charge:
http://htu.at/~kirill/bak/potential.jpg
http://htu.at/~kirill/bak/efield.png
The transformation assumes that periodic boundaries are present
http://htu.at/~kirill/bak/potential-linecharge.png
therefore I have made the class non static and renamed it to PoissonSolverPediodic.
As we discussed a while ago there is still a problem with the poisson
equation in fourier space, which corresponds to these lines
//solve Poisson equation in Fourier space
for(int i = 0; i < columns; i++) {
for(int j = 0; j < rows; j++) {
double d = (4 - 2 * Math.cos((2 * Math.PI * i) / g.numCellsX) - 2 * Math.cos((2 * Math.PI * j) / g.numCellsY));
if (d != 0) {
phi[i][2*j] = (cellArea * trho[i][2*j]) / d;
phi[i][2*j+1] = (cellArea * trho[i][2*j+1]) / d;
} else {
// phi[i][2*j] = trho[i][2*j];
// phi[i][2*j+1] = trho[i][2*j+1];
phi[i][2*j] = cellArea * trho[i][2*j];
phi[i][2*j+1] = cellArea * trho[i][2*j+1];
// phi[i][2*j] = 0;
// phi[i][2*j+1] = 0;
}
}
}
There are three possibilities for the case where the denominator is 0.
Here
(
http://www.physics.buffalo.edu/phy410-505-2004/Chapter6/ch6-lec2.pdf)
they use the first version. Here are the plots of a point charge for
each version:
http://htu.at/~kirill/bak/potential1.jpghttp://htu.at/~kirill/bak/potential2.jpghttp://htu.at/~kirill/bak/potential3.jpgAs
you can see the second and third version are a bit darker but equal to
each other. The indices in the fourier space correspond to the
frequecies of the fields. The only case where the denominator is 0 is
for i,j=0 which corresponds to the lowest frequencies and therefore
energies.(I will remove the if from the for loop and treat this case
separately) In the plotted case the following grid parameters were used
s.width = 10;
s.height = 6;
g.numCellsX = 100;
g.numCellsY = 100;
therefore cellArea < 1. My interpretation of the result is that the
lowest energies were filtered out and therefore the total potential is a
bit lower. But I am not sure if the filtering of the LOWEST energies
can have such a visible effect...
Anyway, none of these versions makes sense mathematically! Analytically
one would "make a circle" around this sigularity and then take a limes
but we cant do that int the descrete case...An other option would be to
use forward difference for the case i,j=0. The "problem" here would be
that we would get imaginary parts and therefore a bit more code...
I am thinking about how to make a unit test that creates a lot of plots
for different charge distributions and code versions... Does anyone know
a good way to plot a potential with gnuplot? Currently I plot just a
lot of small circles (does not look good if there only a few grid
points)...
I have hardcoded the gnuplot commands and the output path for windows.
This will cause assertion errors if gnuplot is not installed but the
test will still pass. Is it ok if I include it in the pull request in
this form?