tips: - If everything was doing what you think it is, your program would work. Do not just assume that any line of code does what you intended for it to do. You must find other ways to check if it is doing what you meant. You will very probably not find your own mistakes by reading your code. - Compile with all warnings turned on. Fix all of the warnings. This takes a little extra time to do, but will save you time later. - Be systematic. - Always check energy conservation. - Reduce the parameters to a simple (limiting) case where you know exactly what will happen: one-dimensional, only 2 particles, particular initial conditions (such as those that will lead to head on collisions), etc. This way, you can see more easily what is going wrong. - Print lots of different things (time, positions, velocities, etc.) to check that they make sense and plot lots of things. This will help you identify the symptoms of the bug. - Narrow down where in your code the problem is by checking small parts of it manually numerically. - Check if your problem depends on the time-step size. - Use programs like valgrind or cachegrind to search for errors. - If you are truly stuck, come to us for help. Make sure to investigate as much as possible of the symptoms of your bugs beforehand, plot things, try things. But do ask for help. Do not allow yourself to be stuck for a long time. This is frustrating and unproductive. common bugs: - missing/extra minus signs (for example when applying a force to a particle) - messing up the order of the indices of a high-dimensional array - typo: something*2 instead of something**2 - typo: "=" instead of "+=", "-=", or "*=" - forgetting to divide forces by the mass - implementing the nearest image convention only for the force, not the potential energy (or the other way around, or only for one direction) - mixed-up units - forgetting to free allocated memory - forgotting type declarations (this should produce compiler errors) - neglecting to set the box size correctly - reading/writing beyond the end of an array - setting a sum to zero at the wrong point in a (double) loop other problems that could lead to strange results: - not enough statistics: not enough particles or only taking statistics once, not a few times during the simulation - funny initial conditions, such as particles placed on top of eachother (at the periodic boundary for instance) - simulation box too small for the length scales you are looking at - system not equilibrated properly yet