# What are some good debugging habits for numerical simulation?

I'm currently writing a lid drive cavity CFD code on python. Currently, my code has some issues (values jumping bear b.c). I was wondering what are some good habits in debugging numerical codes. Hopefully, I would be able to learn some which I may apply to my future projects.

• Write unit tests. Verify each piece of code before writing anything new. Devise simple tests that will clearly tell you if your code is buggy. And above all else, make sure you understand to a reasonable degree the mathematics of whatever you are trying to implement before implementing it. Jul 29 '19 at 13:40
• Use assert. Compile with -Wall -Wextra -Werror -Wpedantic. Test with -fallocate=sanitize. Test on cases with known analytical solutions. Jul 29 '19 at 15:49
• Have a way to compute backwards error pointwise. Jul 30 '19 at 18:00
• @Richard what's that -fallocate=sanitize flag? Do you mean to suggest he can use e.g. -fsanitize=address? Aug 1 '19 at 11:04
• Thanks all! I started to unit test components of my code and was able to verify my code and debug more efficiently. However, due to not having actual analytical data for "assert", I just have to use the best of my effort to make the code clean. Aug 5 '19 at 15:31