8
$\begingroup$

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.

$\endgroup$
7
  • 12
    $\begingroup$ 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. $\endgroup$ Jul 29 '19 at 13:40
  • 4
    $\begingroup$ Use assert. Compile with -Wall -Wextra -Werror -Wpedantic. Test with -fallocate=sanitize. Test on cases with known analytical solutions. $\endgroup$
    – Richard
    Jul 29 '19 at 15:49
  • $\begingroup$ Have a way to compute backwards error pointwise. $\endgroup$
    – user14717
    Jul 30 '19 at 18:00
  • $\begingroup$ @Richard what's that -fallocate=sanitize flag? Do you mean to suggest he can use e.g. -fsanitize=address? $\endgroup$ Aug 1 '19 at 11:04
  • 1
    $\begingroup$ 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. $\endgroup$
    – Kelvin Loh
    Aug 5 '19 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.