Skip to content

[newchem-cpp] step_rate_newton_raphson cleanup (1/2)#375

Merged
brittonsmith merged 27 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024transcribe/step_rate_newton_raphson-cleanup-1of2
Aug 27, 2025
Merged

[newchem-cpp] step_rate_newton_raphson cleanup (1/2)#375
brittonsmith merged 27 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024transcribe/step_rate_newton_raphson-cleanup-1of2

Conversation

@mabruzzo

Copy link
Copy Markdown
Collaborator

This was originally proposed as brittonsmith#30


This PR must be reviewed after #374 is merged


After PR #374 provided an initial transcription of step_rate_newton_raphson, this does a bunch of cleanup. Most of the work here was focused on preparations for transcribing lookup_cool_rates0d.

Along the way, I discovered a few issues with the logic introduced by the gen2024 PR:

  1. step_rate_newton_raphson doesn't make sensible choices when it coevolves internal energy with the species and iter !=1
  2. the gaussj_g routine takes a bunch of code directly from Numerical Recipes. Due to licensing issues, we cannot distribute this code with Grackle
  3. There are some issues with the way that grain-species destruction is handled. First, there is an inconsistency in how it is handled in 2 different spots. Second, I think the underlying model should be tweaked

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 13, 2025
@mabruzzo mabruzzo changed the title step_rate_newton_raphson cleanup (1/2) [newchem-cpp] step_rate_newton_raphson cleanup (1/2) Aug 13, 2025
@mabruzzo mabruzzo changed the title [newchem-cpp] step_rate_newton_raphson cleanup (1/2) [newchem-cpp] step_rate_newton_raphson cleanup (1/2) Aug 13, 2025
@mabruzzo mabruzzo changed the base branch from newchem-cpp to main August 13, 2025 13:47
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp August 13, 2025 13:47
@mabruzzo mabruzzo force-pushed the gen2024transcribe/step_rate_newton_raphson-cleanup-1of2 branch from cf36ad1 to d750d22 Compare August 19, 2025 20:59
@mabruzzo mabruzzo force-pushed the gen2024transcribe/step_rate_newton_raphson-cleanup-1of2 branch from d750d22 to 10726f8 Compare August 19, 2025 21:04
Comment on lines -532 to +491
dspj = eps * dsp[idsp[jsp-1]-1];
dspj = eps * dsp[idsp[jsp-1]];
for (isp = 1; isp<=(nsp); isp++) {
if(isp == jsp) {
dsp1[idsp[isp-1]-1] = dsp[idsp[isp-1]-1] + dspj;
dsp1[idsp[isp-1]] = dsp[idsp[isp-1]] + dspj;
} else {
dsp1[idsp[isp-1]-1] = dsp[idsp[isp-1]-1];
dsp1[idsp[isp-1]] = dsp[idsp[isp-1]];

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.

Just checking, what's happening here with the removal of the -1s? The for loops are the same, so just want to understand.

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.

It's related to the fact that the idsp array holds indices.

Prior to this pull request, the idsp array held 1-based indices for accessing (which made sense for Fortran).

A major change in this PR is that we now store 0-based indices in idsp

@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.

This looks pretty good to me, but before merging I'd like to clarify the change to the indexing in step_rate_newton_raphson.hpp and discuss the timestep arguments issue. If it's how you say, then there is an argument to considering this a bug and changing it straight away.

@brittonsmith brittonsmith merged commit f907083 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/step_rate_newton_raphson-cleanup-1of2 branch September 12, 2025 18:38
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