grackle-project / grackle

The Grackle chemistry and cooling library for astrophysical simulations and models.
Other
26 stars 50 forks source link

Add error-check on `grackle_field_data.grid_dx` #190

Closed mabruzzo closed 7 months ago

mabruzzo commented 7 months ago

The grid_dx field is only needed for a subset of grackle operations and it sometimes doesn't make sense for a downstream application to properly set the value (e.g. where cells are not perfect cubes or if the code isn't grid-based).

I also tweaked the documentation to recommend that downstream applications set grackle_field_data.grid_dx to something -1 in cases where it's not applicable (if the value is not initialized at all, the new error check might not work...)

As part of this commit, I actually factored the error-check out into it's own function (as well as another related check) in order to make sure that we apply the same test in both the calculate_cooling_time and solve_chemistry functions.

I placed that function inside of a newly created file called utils.c. I think that could be a good place to place functions that represent duplicated logic present in more than 1 c-routine (e.g. resetting the UVbackground rates, calculating comoving length/density units) and maybe some other basic error checks