Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've spent far too much time coding and debugging multigrid. While I clearly can't post all of my code as it would be silly to ask someone to go through all that code, is there anything I should pay special attention to?

Note: I'm posting this because I don't want people to have to waste the time I had. This may not be completely relevant to computational science, but I thought it could be helpful for any beginners (as I certainly still am one).

share|improve this question
What language are you using? Would a simple working Python 1D multigrid code be of any use for comparison? – David Ketcheson Feb 17 '13 at 19:16
@DavidKetcheson I'm using Matlab. There's so many ways to code MG though, so I don't know how comparable it would be. (Thank you though). My thoughts are that I'm missing a scaling factor somewhere. According to my norm plots, it runs for a few iterations, then the error just kinks like crazy. But the fact that it works for a few iterations suggests that I'm missing a scaling factor (or need to remove one). But I'm no expert; that's just my interpretation. – AlanH Feb 18 '13 at 23:06
up vote 4 down vote accepted

The smoother, restriction and prolongation can be tested independently. In essence, take a periodic domain, put in a particular Fourier mode and see if the code behaves in accordance with Fourier analysis. Also, in Briggs, Henson and McCormick's A Multigrid Tutorial you will find a section called Diagnostic tools (Chapter 4). That should help you with systematic debugging.

share|improve this answer

We have collected a great deal of experience on how to debug finite element codes here:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.