[newchem-cpp] Organize collisional reaction rates into an indexable table#411
Conversation
We plan to use `init_reaction_rate` to initialize all of the "ordinary" collisional rates. While I was here, I marked `add_reaction_rate` as `static` (i.e. it isn't used outside of the translation unit corresponding to initialize_rates.cpp)
The code has gotten a lot uglier...
These are now unnecessary. The next step is to actually remove these members from the struct
brittonsmith
left a comment
There was a problem hiding this comment.
This looks like a good refactor to me. I mostly had questions that I am fairly certain you've already thought about. Feel free to merge this and I can have a look at any responses you have after.
| // , my_rates->k125[i] | ||
| // , my_rates->k129[i] | ||
| // , my_rates->k130[i]); | ||
| kcol_rate_tables->data[CollisionalRxnLUT::kz15][i] = 4.98e-11; |
There was a problem hiding this comment.
You mentioned not being a big fan of the add_reaction_rate strategy of defining individual functions for each rate. Do you foresee this getting refactored in another way to unify it with how the rest of the reaction rates are initialized? I actually like the individual rate function strategy for the transparency and ability to provide specific, detailed documentation. Either way, I'm curious where you see this going.
| // TODO: in the future, we should refactor to make this logic look more | ||
| // consistent with the logic for other similar rates in | ||
| // initialize_rates |
There was a problem hiding this comment.
Maybe this answers my previous question about standardizing with the other rates.
| double units, | ||
| chemistry_data *my_chemistry) | ||
| { | ||
| *rate_ptr = (double*)malloc(my_chemistry->NumberOfTemperatureBins |
There was a problem hiding this comment.
Is it worth switching to new at this time?
There was a problem hiding this comment.
I looked into it and in this particular case, it's not worth swapping to new (in the context of the current PR). It turns out that this malloc is being used for allocating all of the species-dependent cooling rates that I didn't touch in this PR. (Consequently, it would involve touching a bunch of new code).
With that said, I change the malloc of gr_opaque_storage to a new and the malloc for the member of gr_opaque_storage to a new
In particular I: - reordered initialization rates - switched from using `malloc` to using `new` for `gr_opaque_storage` and its imediate contents
d4564fc to
ee2822f
Compare
This PR should be reviewed after #378, #401, and #402 are all merged
Importantly, this is all intended as a precursor to transcribing
lookup_cool_rates1d_g.Overview
The primary purpose of this PR is to move all of the ordinary collisional rates from within
chemistry_data_storageinto a single table-like data-structure.lookup_cool_rates1d_g), we will be able to convert a lot of the interpolation logic into for-loopsCollisionalRxnRateCollectionstruct that previously started using within thesolve_rate_coolfunction.gr_opaque_storagestruct. Thechemistry_data_storagestruct holds an opaque pointer to thegr_opaque_storagestruct, and thegr_opaque_storagestruct holds theCollisionalRxnRateCollection.FILE*pointer used for IO in the standard C library (likeFILE*, the definition ofstruct gr_opaque_storage*is never directly exposed to user-code). The docstrings forgr_opaque_storageprovide additional context.CollisionalRxnRateCollectionpointer inside ofchemistry_data_storageand avoided defininggr_opaque_storageentirely. However, I think we will gradually want to migrate more "stuff" inside ofgr_opaque_storage.Reviewing this PR
It might be easiest to go through this commit-by-commit. All of my changes were very atomic (I tried to make the individual commits fairly descriptive)
Why this is a pre-requisite for transcribing
lookup_cool_rates1d_g?This is a prerequisite because the transcription machinery will automatically reference the rate tables in their new locations after transcription. It will save us some duplicate work.
Now that I've done all this work (it was far more involved than I expected), it has become obvious to me that the benefits to doing this work before transcribing
lookup_cool_rates1d_gis actually fairly minimal. (I guess it wasn't obvious to me since its been a while since I last transcribed some routines). In any event, what's done is done