Ok I see. I was confused by the many boundary cases.
So where else do you suspect the error to be? If there is an index out of bounds, somewhere the shift of indices was apparently not taken into account properly. Or do you have some other idea where the bug could be? Do you notice anything strange if you step through it with the debugger?
Your unit tests worked before you merged Jan's changes, didn't they? And all unit tests worked in Jan's fork. So the error must have been introduced when merging the two? Or not?
But still some issues remain: the interpolator writes to the -1 and numCells+2 components. The -1 component is only accessed if some random grid size is chosen, like 62x81. The numCells+2 component is (nearly) always accessed. Therefore I have to run the loop from -1 to numCells+2...The problem is here:
int xCellPosition = (int) (Math.floor(p.getX() / g.getCellWidth()));
int yCellPosition = (int) (Math.floor(p.getY() / g.getCellHeight()));
My first explanation for the access of numCells+2 was that getX(), getY() are <= width, height respectively. For the case where the = sign applies this would lead to an access of numCells+2. But then I have changed the condition to <= width-0.1 and the componend was still accessed...
But still some issues remain: the interpolator writes to the -1 and numCells+2 components. The -1 component is only accessed if some random grid size is chosen, like 62x81. The numCells+2 component is (nearly) always accessed. Therefore I have to run the loop from -1 to numCells+2...The problem is here:
int xCellPosition = (int) (Math.floor(p.getX() / g.getCellWidth()));
int yCellPosition = (int) (Math.floor(p.getY() / g.getCellHeight()));
My first explanation for the access of numCells+2 was that getX(), getY() are <= width, height respectively. For the case where the = sign applies this would lead to an access of numCells+2. But then I have changed the condition to <= width-0.1 and the componend was still accessed...
I believe we have a serious bug in the grid which is also related to what you are saying.The logical grid has two properties:1) it has cells and these cells are separated by2) grid pointsIf we want a grid with 10 by 10 cells we need 11 by 11 grid points.
I can do the necessary changes in the grid class but I would need Kirill to repair the remaining classes (Interpolators and Field solvers). However, as with the parallelization we would need to change the grid class again it is questionable whether we should do this changes now or later when we come up with the design of grid suitable for parallelization.
Depends on what those grid points mean. If the meaning of the field is, e.g. the charge in the center of each cell then you need as many grid points as cells. I think charges were defined in the center of a cell, and electric fields at the border between two cells (but they are also labelled by simple integers). So the index of a field may mean different things, and this can also depend on the interpolator used.