Skip to content

[newchem-cpp] light refactoring of solve_rate_cool#377

Merged
brittonsmith merged 36 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024transcribe/solve_rate_cool-refactor
Aug 27, 2025
Merged

[newchem-cpp] light refactoring of solve_rate_cool#377
brittonsmith merged 36 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024transcribe/solve_rate_cool-refactor

Conversation

@mabruzzo

Copy link
Copy Markdown
Collaborator

originally proposed as brittonsmith#42


This PR must be reviewed after #375 is merged


This did a little bit of cleanup in solve_rate_cool_g. I telegraphed in some comments a while back that I wanted to improve the mask behavior to make it a little more logical. We introduce itmask_gs, to replace the practice of temporarily overwriting itmask and then reverting it later. I think the resulting code is a lot more logical.

While I was doing this, I realized that I could slightly refactor the logic where we set the values of itmask_gs and itmask_nr. This is more concise and I think the logic is a little more clean

The idea is for this struct to aggregate as many arguments for the time
derivative as possible. This initial series of patches focuses on
aggregating the non-evolved fields
The idea is to collect args that are forwarded to the time-derivative
calculation and are effectively frozen between various calls

I also converted some of the arguments passed into lookup_cool_rates0d
to read from this pack of args. But, I haven't done it for the really
large structs (e.g. my_chemistry). I think those will be easier to
change later
…s0d from a struct

Great effort was made to maintain consistency with historical behavior.
Potential issues and ideas for refactoring were highlighted in comments
…onsistency that needs to be addressed in the future
The idea is to reduce the number of arguments that we manually pass
through
…o gen2024transcribe/step_rate_newton_raphson-cleanup-1of2
@mabruzzo mabruzzo added the refactor internal reorganization or code simplification with no behavior changes label Aug 20, 2025
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp August 20, 2025 01:27
@mabruzzo mabruzzo moved this to Awaiting Review in New Chemistry and C++ Transcription Aug 20, 2025

@brittonsmith brittonsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this refactor. The logic of the itmasks and the use of a temp itmask always bothered me.

Comment on lines +143 to +144
itmask_gs[i] = (!is_hi_dens) ? MASK_TRUE : MASK_FALSE;
itmask_nr[i] = (is_hi_dens) ? MASK_TRUE : MASK_FALSE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a borderline trivial comment, but would it make sense to make it clear that boolean-wise, itmask_gs should explicitly have the opposite value to itmask_nr? Doing a one-line statement like this that sets one itmask on the other may end up looking a bit clunky, so this might be the simplest after all.

has_nr_coevolve_eint_prereqs && (ddom[i] > 1.e7) && (tgas[i] > 1650.0)
);
// we don't care about imp_eng[i] where itmask_nr[i] == MASK_FALSE
imp_eng[i] = (nr_coevolve_energy) ? 1 : 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this is in your stated plans and I missed it, but can we rename this variable? I've never liked it as it explains nothing about what its purpose is.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

use nr_coevolve_energy

@brittonsmith brittonsmith merged commit 29ac009 into grackle-project:newchem-cpp Aug 27, 2025
5 checks passed
@github-project-automation github-project-automation Bot moved this from Awaiting Review to Done in New Chemistry and C++ Transcription Aug 27, 2025
@mabruzzo mabruzzo deleted the gen2024transcribe/solve_rate_cool-refactor branch September 12, 2025 18:36
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

Development

Successfully merging this pull request may close these issues.

2 participants