Skip to content

Conversation

mabruzzo
Copy link
Collaborator

@mabruzzo mabruzzo commented Sep 26, 2025

This PR shouldn't be reviewed until after #428 has been merged


Overview

This is the final PR for cleaning up lookup_cool_rate1d (there's obviously more to do, but I'm happy enough to move on)

Description

This PR leverages the GrainSpeciesInfo type introduced in #428 to refactor all of the logic pertaining to the calculation of dust grain rates.

  • Much of the work in this PR focused on replacing sections of code where we repeated identical logic for every know grain species with for-loops (of course I also tried to add in comments to explain what is going on).
  • I also excised all of the dust-logic from lookup_cool_rate1d into a helper function called lookup_dust_rate1d (this helper function is currently called by lookup_cool_rate1d, but an argument could be made that it should maybe get called separately).
  • Additionally, I significantly fleshed out the docstring for lookup_cool_rate1d

Gold Standard Considerations

Importantly, this is going to fail some of the answer tests. (After merging, we'll need to bump the gold standard).

  • This is primarily a consequence of refactoring the logic for computing the H2 formation rate on dust grains for multiple grain-species.
  • I tried multiple things, but it turns out that this was pretty unavoidable. If you look at the commit-history, you can see that I was extremely careful.
  • In fact, I confirmed that the H2 rate was only changing by a factor of ~2e-16 (it may be marginally larger than one might expect because the change affects terms in a summation).

Since we're going to bump the gold standard anyways, I took the opportunity to precompute a constant for the calculation of grain growth rates (i.e. a std::pow call and a division is now called before we "loop over a row" rather than within the loop).1 This change should definitely affect results, (to within machine tolerance), but it's not clear that it significantly shifts rates (with machine looks like this change probably doesn't change things much

Footnotes

  1. By slightly adapting the GrainSpeciesInfo machinery, it would be straightforward to precompute these constants at initialization, but we can leave that for the future.

…re used (to silence unused-variable warnings)
I added a bunch of comments to explain what's actually happenning here
and I slightly refactored the code.

The impetus for doing this was some warnings that the compiler couldn't
tell whether some variables were fully initialized. I'm going to address
that in the next commit
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp October 2, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant