COSMIC-PopSynth / COSMIC

COSMIC (Compact Object Synthesis and Monte Carlo Investigation Code)
GNU General Public License v3.0
45 stars 58 forks source link

Add debugging setup, avoid NaNs from timestep issue #647

Open TomWagg opened 1 week ago

TomWagg commented 1 week ago

This PR does two main things:

  1. After a several month long battle, this PR solves #608 with an offensively small number of changes to the code - the change avoids NaN values in particular evolution cases (see below)
  2. It adds debug and .vscode folders so that COSMIC developers can quickly and easily debug the fortran code using vscode

Explanation of the NaNs I was finding that NaNs were occurring during complicated parts of evolution (e.g. He star stellar type changing during stable mass transfer). The reason for this was that there was a part of the code that reverted to using large timesteps if the number of iterations exceeded 1000. This means the star could suddenly jump forward 5 Myr while it was transferring mass...and then everything blows up. As a simple fix for now I've changed 1000 to loop, which is set to 20,000 by default - this makes it more consistent and also clearly increases the limit a lot. This fix removes every case of NaNs that I have in my saved files.

It's important to keep in mind for future reference though this may not be solving the underlying issue. Large timesteps messing with things seems to imply there's some logic that is violating an order-of-operations situation and causing NaNs but we can skirt around it with small enough timesteps. Something to keep in mind if NaNs arise in future 🤷🏻

Debugging details The .vscode folder adds scripts that automatically compile and execute a testing script which takes a binary.in file as input. I've included a python script to auto create these input files from initC rows. When I do the docs PR I'll include a proper tutorial for developers to get this up and running :)