Skip to content

Refactor H isotope charge exchange to use the new reactions framework.#398

Merged
oparry-ukaea merged 111 commits intoboutproject:masterfrom
oparry-ukaea:hcx-refactor
Mar 26, 2026
Merged

Refactor H isotope charge exchange to use the new reactions framework.#398
oparry-ukaea merged 111 commits intoboutproject:masterfrom
oparry-ukaea:hcx-refactor

Conversation

@oparry-ukaea
Copy link
Copy Markdown
Contributor

@oparry-ukaea oparry-ukaea commented Sep 19, 2025

Some implementation details:

  • Reorganises RateHelper to cope with Amjuel fits that are a function of (T) in addition
    to existing (n,T). Placeholder for future (E,T) fits.​
  • RateHelper is templated on the param types, but Reaction::transform_impl()
    decides which to use at runtime. This allows subclasses to (for instance) read the
    type from a json file.​
  • Momentum and energy 'channels' are introduced to allow developers to override the
    default splitting of reactant momentum and energy between products.​
  • HCX sets channels such that all incoming ion [energy|momentum] is transferred to
    the outgoing neutral and vice-versa.​
  • ReactionParser modified to cope with momentum and energy transfer in symmetric
    reactions (e.g. h + h+ -> h+ + h) where pop changes are zero.​
  • 1D-recycling regression data tweaked to accommodate changes due to statement
    reordering, compiler optimisations.​

ToDo:

  • Check that diagnostics values haven't changed for 1D-recyling.
  • Move calculation of collision frequencies into RateHelper and Reaction::transform.
  • Generalise more of HydrogenChargeExchange::transform_additional (hopefully remove completely).
    (moved all but frictional heating)
  • Regression test for non-symmetric CX (not covered by 1D-recycling)
  • Developer documentation

Comment thread include/amjuel_hydrogen.hxx Outdated
Comment thread include/amjuel_reaction.hxx Outdated
Comment thread include/amjueldata.hxx Outdated
Comment thread include/hermes_utils.hxx
* @return std::vector<std::string> vector of keys
*/
template <typename T>
static inline std::vector<std::string> str_keys(const std::map<std::string, T>& map) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++20 has std::views::keys -- not for this PR, but worth thinking if we can move to C++20 @bendudson ?

Comment thread include/reaction.hxx Outdated
@oparry-ukaea
Copy link
Copy Markdown
Contributor Author

oparry-ukaea commented Mar 9, 2026

Tests all passing (after loosening the relative tolerance used in 2D-production slightly).
The format action won't run on forks, but I've applied all of the format actions locally, so it should be fine.
Ready to go otherwise.

Copy link
Copy Markdown
Collaborator

@mikekryjak mikekryjak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oparry-ukaea thanks for the changes. Could you add a simple, high level executive summary at the start of the Reactions section in the dev manual that describes how the different classes interact? It may make it a bit easier to understand the flow.

Comment thread docs/sphinx/developer.rst Outdated
@oparry-ukaea
Copy link
Copy Markdown
Contributor Author

Could you add a simple, high level executive summary at the start of the Reactions section in the dev manual that describes how the different classes interact?

Added something - I'm reluctant to do anything more detailed at the moment because this will change again once the data-decoupling PR is finished...

@mikekryjak
Copy link
Copy Markdown
Collaborator

Could you add a simple, high level executive summary at the start of the Reactions section in the dev manual that describes how the different classes interact?

Added something - I'm reluctant to do anything more detailed at the moment because this will change again once the data-decoupling PR is finished...

Perfect - this is good. The PR is good as far as I'm concerned. @bendudson can you review?

Copy link
Copy Markdown
Collaborator

@dschwoerer dschwoerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things that need to be done to make it more FCI friendly. It also could be cleaned up a tiny bit more.

Comment thread docs/sphinx/developer.rst Outdated
Comment thread docs/sphinx/developer.rst Outdated
Comment thread docs/sphinx/developer.rst
the stoichiometry matrix would be:

.. _fig-stoichiometry_matrix_eg:
.. figure:: figs/stoichiometry_matrix_eg.*
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you convert this to a math block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but it's a bit of a pain. I can't find the latex I originally used to generate this, but I remember it being fiddly to force it to align the column labels the way I wanted...

Comment thread include/hermes_utils.hxx
Comment thread include/hermes_utils.hxx
Comment thread include/rate_helper.hxx Outdated
Comment thread include/rate_helper.hxx Outdated
Comment thread include/reaction.hxx Outdated
Copy link
Copy Markdown
Collaborator

@dschwoerer dschwoerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be merged as is ...

std::string toString(ReactionDiagnosticType diag_type);

static const std::map<ReactionDiagnosticType, std::string> state_labels = {
static const std::map<ReactionDiagnosticType, std::string> sp_data_keys = {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is sp for species?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Happy to change it if you think something else is clearer!

Comment thread include/rate_helper.hxx Outdated
Comment thread include/rate_helper.hxx
Copy link
Copy Markdown
Collaborator

@dschwoerer dschwoerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I nearly forgot, could you ensure CI is passing?
Can you push to this fork?

@oparry-ukaea
Copy link
Copy Markdown
Contributor Author

I nearly forgot, could you ensure CI is passing? Can you push to this fork?

Checks all passing:
#532

Copy link
Copy Markdown
Collaborator

@mikekryjak mikekryjak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as far as I'm concerned. Thanks @oparry-ukaea!

Copy link
Copy Markdown
Collaborator

@bendudson bendudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @oparry-ukaea ! This is quite monumental.

@oparry-ukaea
Copy link
Copy Markdown
Contributor Author

@dschwoerer - Happy for us to merge this?

@oparry-ukaea oparry-ukaea mentioned this pull request Mar 25, 2026
3 tasks
@oparry-ukaea oparry-ukaea dismissed dschwoerer’s stale review March 26, 2026 09:04

@dschwoerer has confirmed offline that he's happy - I'll dismiss his review so that we can expedite this!

@oparry-ukaea oparry-ukaea merged commit e1fe3af into boutproject:master Mar 26, 2026
8 of 9 checks passed
@oparry-ukaea oparry-ukaea deleted the hcx-refactor branch March 26, 2026 09:05
mikekryjak added a commit that referenced this pull request Mar 30, 2026
HCX refactor PR (#398) introduced tiny changes which were merged into master between me shortening the tests and merging the PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants