Skip to content

Conversation

mabruzzo
Copy link
Collaborator

@mabruzzo mabruzzo commented Sep 6, 2025

This PR must be reviewed after #411 is merged


Overview

At a high-level this PR:

  • deletes initialize_metal_chemistry_rates.cpp
  • mutates initialize_rates.cpp
  • creates init_misc_species_cool_rates.cpp
  • creates collisional_rate_props.cpp

In more detail, all functionality that was previously in initialize_metal_chemistry_rates.cpp has been split between init_misc_species_cool_rates.cpp and collisional_rate_props.cpp.

  • We moved all logic relating to initializing 2body reaction rates (i.e. for primordial_chemistry 4 & metal chemistry) from initialize_metal_chemistry_rates.cpp into collisional_rate_props.cpp.
  • We moved all other logic (that namely pertains to initializing species-specific cooling) out of initialize_metal_chemistry_rates.cpp and into init_misc_species_cool_rates.cpp. (this file probably needs more cleanup, but that's beyond the scope of this PR

Let's talk more about collisional_rate_props.cpp:

As part of this PR:

  • I broke out the logic for each primordial_chemistry==4 and metal_chemistry collisional rate. These functions are analogous to the existing rate functions (k1_rate, k2_rate, ...)1
  • I created a grackle::impl::visit_rate_props function that effectively iterates through all standardized collisional reaction rate functions. This includes all of the existing primordial_chemistry= 1,2, and 3 functions as well as the new primordial_chemistry=4 and metal_chemistry=1 rates.
  • I have slightly refactored the logic contained within the initialize_rates.cpp to make use of grackle::impl::visit_rate_props to actually initialize the standardized collisional reaction rate functions.

Overall, I think this leads to much cleaner code. Now that we have ~882 of the standardized collisional reaction rate functions. I have structured it in the current manner for reasons that should become apparent once #415 is finished

Footnotes

  1. I left comments that explain the work that should be done before we are ready to expose all the new rate functions as part of the public API

  2. At the moment, I'm taking a very broad definition of "standard". In the future, one might imagine treating a handful of rates more specially again. Examples of such rates include: k13 (due to the existence of k13dd), k56 (since we use it to infer a deuterium rate), as well as the 3 body rates.

These deleted declarations already occur within the grackle.h header.
Some include directives were also deleted that were redundant with
including then grackle.h header
This is important once we start compiling with C++
For context, the historic convention in Grackle project was to use .C as
the suffix for C++ source files. Thus, when we began transcribing files,
we used the .C suffix (even though it is a less common choice than .cpp)

However, it turns out that converting a file named `<prefix>.c` to
`<prefix>.C` causes lots of issues performing Git operations when your
machine has a case-insensitive file-system (common on macOS). This comes
up in operations as simple as changing between 2 branches

Consequently, we will be transitioning to the .cpp suffix
For context, the historic convention in Grackle project was to use .C as
the suffix for C++ source files. Thus, when we began transcribing files,
we used the .C suffix (even though it is a less common choice than .cpp)

However, it turns out that converting a file named `<prefix>.c` to
`<prefix>.C` causes lots of issues performing Git operations when your
machine has a case-insensitive file-system (common on macOS). This comes
up in operations as simple as changing between 2 branches

Consequently, we will be transitioning to the .cpp suffix
I also adjusted the boilerplate at the top of this file and at the top
of solve_rate_cool_g-cpp.h
A few tweaks were necessary:
- I needed to add the `extern "C"` annotation to a number of functions
  that are publicly exposed as the C API
- I removed the leading underscore from some internal helper functions
- I needed to tweak make the group name argument passed to
  initialize_cloudy_data expect a `const char*`, rather than just a
  `char*`. This is essential since we are passing a string literal (this
  was a very minimal change)

I also added to the `static` specifier to some internal functions (this
ensures that these helper functions will not be accessible to external
code)
I also renamed initialize_rates.h to initialize_rates.hpp to denote that
the header is **ONLY** compatible with C++ source files
This information has been formatted into a markdown table (that will be
rendered into a table if/when we use doxygen)
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp September 6, 2025 20:22
@mabruzzo mabruzzo force-pushed the cleanup-kcol_rate_tables_init branch from 6cef850 to 046e49e Compare September 6, 2025 20:25
@mabruzzo mabruzzo changed the title [newchem-cpp] WIP: Cleanup initialization of kcol_rate_tables [newchem-cpp] Cleanup initialization of kcol_rate_tables Sep 9, 2025
@mabruzzo mabruzzo added the refactor internal reorganization or code simplification with no behavior changes label Sep 9, 2025
@mabruzzo mabruzzo marked this pull request as ready for review September 9, 2025 16:14
@mabruzzo mabruzzo moved this to Awaiting Review in New Chemistry and C++ Transcription Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor internal reorganization or code simplification with no behavior changes
Projects
Status: Awaiting Review
Development

Successfully merging this pull request may close these issues.

1 participant