Clarifying the purpose of "poisson2d", choosing clear convergence criteria, adding tests #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #23, it would be good to have tests in order to be sure the codes converge correctly. Indeed, on adding a sensible check for the end result, I was able to make all the codes run with the exact same number of iterations. This seems like a pretty strong indication of algorithmic parity.
To get a sensible test, I changed the "source term", i.e. "rho", to an analytical form that also has a pen-and-paper solution. Then anyone can easily implement a function that checks whether the numerical solution is "close enough", for which I chose that the average absolute difference between the grid points of the analytical vs. numerical solution is less than 5.0e-3.
Other than that, this branch adds the modern Fortran version of @rouson and also separates the Fortran calculations in to functions and modules. Though I agree that it would be good to have a single file from which to run all the benchmarks, I wasn't sure what would be the best way to do it, so I left it out for now pending further discussion.
One interesting thing that happened is that what was previously called "optimized.f90" (I've now changed my fortran codes to traditional1.f90 and traditional2.f90) is somehow slower than the "naive.f90" version. Hence the name change: it's hardly optimized if it is slower in the end! Also, @rouson 's modern version blows both of mine out of the water in terms of performance (and prettiness :) ) showing that indeed utilizing modern features can cause performance speedups. For some reason, though, it doesn't converge for M=200, but does converge in the exact same number of iterations as the other codes for the M=100 and M=300 cases. Beats me.. if anyone has any ideas, I'll be glad to hear them.
I also added a numpy-vectorized Python code for fun.
There's now also a pdf giving a problem description (from which you can see the analytical source term and solution as well).
edit: also, the code that was pulled from me last time gave non-deterministic answers as per the comments of @certik . I didn't notice the later comments in the pull request. This shouldn't happen with these codes, either. If anyone can test, that would be great.