[newchem-cpp] Transcribe calc_tdust_1d_g#516
Conversation
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
…transcribe_calc_tdust_1d_g
|
Wait, does this include transcriptions for both |
|
Never mind -- I see that |
|
@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) |
|
@mabruzzo I tried to replace strcpy with memcpy, I will revert this proposed change and merge newchem-cpp |
…transcribe_calc_tdust_1d_g
mabruzzo
left a comment
There was a problem hiding this comment.
I made a few very minor suggestions. Feel free to push back on whatever you want. Afterwards, this is good to go
| // 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; |
| /// @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 |
There was a problem hiding this comment.
| /// @param[in] kgr Array to hold computed grain opacities | |
| /// @param[out] kgr Array to hold computed grain opacities |
| std::vector<gr_mask_type> nm_itmask(in); | ||
| std::vector<gr_mask_type> bi_itmask(in); |
There was a problem hiding this comment.
Relatively unimportant suggestion: (feel free to ignore it)
| 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); |
|
|
||
| c_done = 0; | ||
| nm_done = 0; | ||
| c_total = idx_range.i_end - idx_range.i_start + 1; |
There was a problem hiding this comment.
| c_total = idx_range.i_end - idx_range.i_start + 1; | |
| c_total = idx_range.i_stop - idx_range.i_start; |
|
|
||
| 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 |
There was a problem hiding this comment.
| // Use Newton's method to solve for Tdust | |
| // check if the solution has converged (if not prepare the next guess) |
| trad = std::fmax( | ||
| 1., | ||
| trad); // TODO: do we really want to write in a passed by copy input par? |
There was a problem hiding this comment.
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
| std::vector<double> tdplus(in); | ||
| std::vector<double> tdustnow(in); | ||
| std::vector<double> tdustold(in); | ||
| std::vector<double> pert(in); |
There was a problem hiding this comment.
Relatively unimportant suggestion: (feel free to ignore it)
| 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); |
| if (nm_itmask[i] != MASK_FALSE) { | ||
| // Use Newton's method to solve for Tdust | ||
|
|
||
| slope[i] = (solplus[i] - sol[i]) / (pert[i] * tdustnow[i]); |
There was a problem hiding this comment.
| 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]); |
There was a problem hiding this comment.
@mabruzzo should we do it now or maybe you prefer to do the change in a later code optimization/refactoring step?
| /// 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, |
There was a problem hiding this comment.
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)
|
pre-commit.ci autofix |
No description provided.