Skip to content

[newchem-cpp] Transcribe calc_tdust_1d_g#516

Merged
brittonsmith merged 19 commits into
grackle-project:newchem-cppfrom
ChristopherBignamini:newchem-cpp_transcribe_calc_tdust_1d_g
Apr 13, 2026
Merged

[newchem-cpp] Transcribe calc_tdust_1d_g#516
brittonsmith merged 19 commits into
grackle-project:newchem-cppfrom
ChristopherBignamini:newchem-cpp_transcribe_calc_tdust_1d_g

Conversation

@ChristopherBignamini

Copy link
Copy Markdown
Contributor

No description provided.

@ChristopherBignamini

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@ChristopherBignamini ChristopherBignamini changed the title [newchem-cpp] Transcribe calc tdust 1d g [newchem-cpp] Transcribe calc_tdust_1d_g Mar 12, 2026
@ChristopherBignamini

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@mabruzzo mabruzzo changed the base branch from newchem-cpp to main April 2, 2026 12:31
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp April 2, 2026 12:31
@mabruzzo

mabruzzo commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

Wait, does this include transcriptions for both calc_tdust_1d_g and calc_all_tdust_gasgr_1d_g? Or is there a separate PR where you transcribed calc_all_tdust_gasgr_1d_g?

@mabruzzo

mabruzzo commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

Never mind -- I see that calc_all_tdust_gasgr_1d_g was transcribed in #485

@mabruzzo

mabruzzo commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

@ChristopherBignamini, can you merge in the recent changes from newchem-cpp (I suspect that a lot of these conflicts will go away if you perform the merge on your local machine)

@ChristopherBignamini

Copy link
Copy Markdown
Contributor Author

@mabruzzo I tried to replace strcpy with memcpy, I will revert this proposed change and merge newchem-cpp

@mabruzzo mabruzzo left a comment

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.

I made a few very minor suggestions. Feel free to push back on whatever you want. Afterwards, this is good to go

Comment on lines -79 to -82
// NOTE: gr_N and gr_Size are historical names
// -> they are pretty uninformative and should be changed!
// NOTE: gr_N is a historical names
// -> it is pretty uninformative and should be changed!
int gr_N[2] = {0, 0};
int gr_Size = 0;

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.

Nice!

Comment thread src/clib/dust/calc_tdust_1d_g.hpp Outdated
/// @param[in] gr_dT Temperature spacing of the grain opacity table
/// @param[in] gr_Td Temperature values of the grain opacity table
/// @param[in] alsp_data_ Grain opacity table data
/// @param[in] kgr Array to hold computed grain opacities

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.

Suggested change
/// @param[in] kgr Array to hold computed grain opacities
/// @param[out] kgr Array to hold computed grain opacities

Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated
Comment on lines +80 to +81
std::vector<gr_mask_type> nm_itmask(in);
std::vector<gr_mask_type> bi_itmask(in);

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.

Relatively unimportant suggestion: (feel free to ignore it)

Suggested change
std::vector<gr_mask_type> nm_itmask(in);
std::vector<gr_mask_type> bi_itmask(in);
// iteration mask specifies where we use newton's method with finite
// differences (aka the secant method)
std::vector<gr_mask_type> nm_itmask(in);
// iteration mask specifies where we use bisection
std::vector<gr_mask_type> bi_itmask(in);

Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated

c_done = 0;
nm_done = 0;
c_total = idx_range.i_end - idx_range.i_start + 1;

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.

Suggested change
c_total = idx_range.i_end - idx_range.i_start + 1;
c_total = idx_range.i_stop - idx_range.i_start;

Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated

for (i = idx_range.i_start; i <= idx_range.i_end; i++) {
if (nm_itmask[i] != MASK_FALSE) {
// Use Newton's method to solve for Tdust

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.

Suggested change
// Use Newton's method to solve for Tdust
// check if the solution has converged (if not prepare the next guess)

Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated
Comment on lines +85 to +87
trad = std::fmax(
1.,
trad); // TODO: do we really want to write in a passed by copy input par?

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.

Good Point! Maybe we rename the value used throughout the function floored_trad or something? (or maybe we rename the input parameter). I trust your judgement

Comment thread src/clib/dust/calc_tdust_1d_g.cpp
Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated
Comment on lines +74 to +77
std::vector<double> tdplus(in);
std::vector<double> tdustnow(in);
std::vector<double> tdustold(in);
std::vector<double> pert(in);

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.

Relatively unimportant suggestion: (feel free to ignore it)

Suggested change
std::vector<double> tdplus(in);
std::vector<double> tdustnow(in);
std::vector<double> tdustold(in);
std::vector<double> pert(in);
// holds dust temperature guess from the last root-finding iteration
std::vector<double> tdustold(in);
// holds dust temperature guess for the current root-finding iteration
std::vector<double> tdustnow(in);
// holds a value offset from the current dust temperature (tdustnow)
// it is used to get a finite difference estimate for the derivative
std::vector<double> tdplus(in);
// relative finite difference step size
std::vector<double> pert(in);

Comment thread src/clib/dust/calc_tdust_1d_g.cpp Outdated
if (nm_itmask[i] != MASK_FALSE) {
// Use Newton's method to solve for Tdust

slope[i] = (solplus[i] - sol[i]) / (pert[i] * tdustnow[i]);

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.

Suggested change
slope[i] = (solplus[i] - sol[i]) / (pert[i] * tdustnow[i]);
// todo: convert slope to a local variable (there's no reason for it to be a vector)
slope[i] = (solplus[i] - sol[i]) / (pert[i] * tdustnow[i]);

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.

@mabruzzo should we do it now or maybe you prefer to do the change in a later code optimization/refactoring step?

Comment thread src/clib/dust/calc_tdust_1d_g.hpp Outdated
/// modified: January, 2026 by Christopher Bignamini & Matthew Abruzzo; C++ port
void calc_tdust_1d_g(double* tdust, double* tgas, double* nh, double* gasgr,
const double* gamma_isrfa, const double* isrf,
const gr_mask_type* itmask, double trad, int in, int gr_N,

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.

Would you mind changing the name of the in parameter to something more descriptive, like buf_len or add a todo note to the docstring to remind us to do that?

For context, each of the 1d arrays holds in elements. The name is left over from when we previously passed around in, jn, kn as arguments (i.e. lengths along i-axis, j-axis, & k-axis)

@ChristopherBignamini

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@brittonsmith brittonsmith merged commit 5b7052e into grackle-project:newchem-cpp Apr 13, 2026
5 checks passed
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.

3 participants