Skip to content

Transcribe of cool1d_multi_g#39

Open
ChristopherBignamini wants to merge 779 commits into
brittonsmith:gen2024from
ChristopherBignamini:gen2024_transcribe_cool1d_multi_g
Open

Transcribe of cool1d_multi_g#39
ChristopherBignamini wants to merge 779 commits into
brittonsmith:gen2024from
ChristopherBignamini:gen2024_transcribe_cool1d_multi_g

Conversation

@ChristopherBignamini

Copy link
Copy Markdown

This branch has been created from @mabruzzo gen2024-transcribe branch (https://github.com/mabruzzo/grackle/tree/gen2024-transcribe)

@mabruzzo mabruzzo mentioned this pull request Mar 3, 2025

@mabruzzo mabruzzo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I meant to review this a little sooner -- sorry!

This looks fantastic! Thank you so much for doing this!

There are handful of things that need to be addressed before this can be merged into either gen2024 or gen2024-transcribe. The vast majority of these things are stuff things that I didn't tell you about ahead of time (and they have to do with some basic conventions I have started following, or lessons that I've learned while transcribing)

I left a handful of comments requesting changes (a bunch of them are things that I didn't really document, but are conventions that I have been following).

There are 3 other larger-scale changes that would be useful:

  1. could you please remove cool1d_multi_g.F from the repository?

  2. Would you mind creating a commit that remove as many references relating to addition/subtraction an offset of 1 and the j and k indices?

    • I think we actually talked about doing this. I was probably much too vague
    • For context: the j and k variables are tracked by idx_range. As you may recall, the struct members idx_range.jp1 and idx_range.kp1 are abbreviations for "j plus 1" and "k plus 1". This was all done to reduce zero-indexed variables (and we don't think about adding/subtracting one)
    • this can base that just consists of performing search-and-replace that performs the substitutions idx_range.jp1-1 -> idx_range.j and idx_range.kp1-1 -> idx_range.k.
    • It will be a lot easier to do now, than if we wait until later since the formatting of the strings of text that need to be replaced are currently very consistent (they were auto-generated).
    • If transcription worked properly, there should no longer be any references to idx_range.kp1 or idx_range.jp1 (if any references persist, that may be a sign that something went wrong during transcription. Alternatively this could just happen in places where you modified the code)
  3. Remove all occurrences of i-1 from from cool1d_multi_g-cpp.C. This is going to involve modifying the for-loops so that i is a 0-based index.

    • this can all be accomplished via search-and-replace operations.
    • In case you find it useful, I wrote a simple command-line tool to help do this (it requires a little manual intervention). You can find it here. I think the --help command does a reasonable job explaining how to use the tool (but, if you're interested I can provide more elaboration)
  4. After you merge in the latest changes from gen2024-transcribe, it would be great if you could replacing invocations of Fortran routines with wrapper functions. There are some minor differences in the wrapper function's interface (to reflect the planned C++ function's interface), but most should be fairly to straightforward to understand. The easiest functions to replace are:

    • grackle::impl::fortran_wrapper::calc_temp1d_cloudy_g easily replaces FORTRAN_NAME(calc_temp1d_cloudy_g)
    • grackle::impl::fortran_wrapper::interpolate_2d_g easily replaces FORTRAN_NAME(interpolate_2d_g)
    • grackle::impl::fortran_wrapper::interpolate_3d_g easily replaces each occurrence of FORTRAN_NAME(interpolate_3d_g)
    • as an aside: whenever I have a function that calls multiple wrapper functions, I commonly add namespace f_wrap = ::grackle::impl::fortran_wrapper; near the start of the function (i.e. the wrapper-namespace is shortened to f_wrap within the function's scope). But obviously, this isn't necessary (you should do whatever you find most useful)

    I left comments that describe the order in which you should replace FORTRAN_NAME(calc_grain_size_increment_1d) and FORTRAN_NAME(calc_all_tdust_gasgr_1d_g).1 I think that this should cover all fortran functions with C++ wrappers.2

Again, this looks great! I really appreciate the help! This goes without saying, but If you disagree with any of my suggestions, you should obviously feel free to push back!

Footnotes

  1. these 2 routines are little more tricky to replace since they require the use of a datatype that doesn't exist yet in your current version of cool1d_multi_g

  2. If you think it would be useful, you should obviously feel free to add more wrapper functions.

Comment thread src/clib/cool1d_multi_g-cpp.h
Comment thread src/clib/cool1d_multi_g-cpp.h Outdated
Comment thread src/clib/cool1d_multi_g-cpp.h Outdated
grackle::impl::CoolHeatScratchBuf coolingheating_buf
);

#endif /* MY_FILE_CPP_H */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
#endif /* MY_FILE_CPP_H */
#endif /* COOL_1D_MULTI_G_HPP */

Comment thread src/clib/Make.config.objects Outdated
@@ -23,7 +23,7 @@ OBJS_CONFIG_LIB = \
cool1d_cloudy_g.lo \
cool1d_cloudy_old_tables_g.lo \
cool1d_multi_g.lo \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change is required to avoid breaking the classic build-system

Suggested change
cool1d_multi_g.lo \

Comment thread src/clib/cool1d_multi_g-cpp.C Outdated
#include "fortran_func_decls.h"
#include "utils-cpp.hpp"

void cool1d_multi_g(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Related to the earlier namespace suggestion I made:

Suggested change
void cool1d_multi_g(
void grackle::impl::cool1d_multi_g(

Comment thread src/clib/cool1d_multi_g-cpp.C Outdated
Comment on lines +1129 to +1131
// Add dust opacity.
// if (idspecies .eq. 0), dust opacity is overestimated at Td > 50 K
// We better not include dust opacity.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
// Add dust opacity.
// if (idspecies .eq. 0), dust opacity is overestimated at Td > 50 K
// We better not include dust opacity.
// Add contributions from dust opacity to alpha, the linear absorption coefficient
//
// The original Fortran version of this function had the following 2 comments:
// ! if (idspecies .eq. 0), dust opacity is overestimated at Td > 50 K
// ! We better not include dust opacity.
// It's a little unclear how relevant these comments actually are.

Comment thread src/clib/cool1d_multi_g-cpp.C
Comment thread src/clib/cool1d_multi_g-cpp.C Outdated
Comment on lines +255 to +260
dom = internalu.urho*(std::pow(internalu.a_value,3))/mh_local_var;
dom_inv = 1./dom;
tbase1 = internalu.tbase1;
xbase1 = internalu.uxyz/(internalu.a_value*internalu.a_units); // uxyz is [x]*a = [x]*[a]*a' '
dbase1 = internalu.urho*std::pow((internalu.a_value*internalu.a_units),3); // urho is [dens]/a^3 = [dens]/([a]*a')^3 '
coolunit = (std::pow(internalu.a_units,5) * std::pow(xbase1,2) * std::pow(mh_local_var,2)) / (std::pow(tbase1,3) * dbase1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This particular logic had been duplicated between 4 or 5 different Fortran files. I designed the internalu related functionality to factor out this exact functionality (I took care to preserve the order of operations to prevent drift in answer-test results). I think it is probably worth doing this before the logic is able to start diverging.

The following suggestion shows how to integrate the internalu logic (if you want to do this). If you choose to make this change, you should remove the declaration of xbase1 and dbase1 variables, and explicitly confirm that this doesn't break any tests.

Suggested change
dom = internalu.urho*(std::pow(internalu.a_value,3))/mh_local_var;
dom_inv = 1./dom;
tbase1 = internalu.tbase1;
xbase1 = internalu.uxyz/(internalu.a_value*internalu.a_units); // uxyz is [x]*a = [x]*[a]*a' '
dbase1 = internalu.urho*std::pow((internalu.a_value*internalu.a_units),3); // urho is [dens]/a^3 = [dens]/([a]*a')^3 '
coolunit = (std::pow(internalu.a_units,5) * std::pow(xbase1,2) * std::pow(mh_local_var,2)) / (std::pow(tbase1,3) * dbase1);
dom = internalu_calc_dom_(internalu);
dom_inv = 1./dom;
tbase1 = internalu.tbase1;
coolunit = internalu.coolunit;

Comment thread src/clib/cool1d_multi_g-cpp.C Outdated
Comment thread src/clib/cool1d_multi_g-cpp.C Outdated
brittonsmith and others added 27 commits May 22, 2025 11:54
…tweak

cython does not need to be a runtime-dependency
…nstruction-tweaks

Pygrackle test instruction tweaks
…Warnings

Enable Compiler Warnings in a CI job
…lding_length_fix

H2 self shielding length scale factor fix
Superficial Website Documentation Tweaks
[newchem-cpp] Minor model test refactor and adding model comparison option
…eaks

address the remaining compiler warnings
Relocated all CMake-dependency-information into dependencies.cmake
…' into gen2024transcribe/solve_rate_cool-refactor
…' into gen2024transcribe/lookup_cool_rates0d
…2024transcribe/calc_temp_cloudy_g

I needed to introduce the bugfix from PR grackle-project#367.
mabruzzo and others added 8 commits August 20, 2025 13:13
Background
----------

Previously we had replaced 99% uses of the Flake8 linter with the Ruff
linter (not to be confused with the Ruff formatter). We had continued to
use the Flake8 linter to deal with the following 2 files:

1. **gracklepy/utilities/testing.py**
2. **gracklepy/__init__.py**

In more detail, we were suppressing certain warnings in these 2 files
from Flake8, and transistioning to using the Ruff formatter for these
files would involve making a few changes.

More recently PRs grackle-project#368 and grackle-project#369 introduced the required changes into the
main branch. Now that those changes have been ported to the newchem-cpp
branch, we are able to make this change.

What Changed
------------

I essentially changed 3 things:

1. We no longer install and use flake8 in the continuous integration
2. I removed the **setup.cfg** file (it was **only** being used to track
   flake8 configuration information
3. I needed to tweak **pyproject.toml** to both:
   - stop excluding the **gracklepy/utilities/testing.py** and
     **gracklepy/__init__.py** files from the linter
   - stop listing flake8 as a development dependency
…e/step_rate_newton_raphson-cleanup-1of2

[newchem-cpp] `step_rate_newton_raphson` cleanup (1/2)
…e/solve_rate_cool-refactor

[newchem-cpp] light refactoring of `solve_rate_cool`
[newchem-cpp] Remove last references to `Flake8`
…_dust' into gen2024_transcribe_cool1d_multi_g
@ChristopherBignamini

Copy link
Copy Markdown
Author

Moved to main grackle repo as PR to the newchem_cpp branch:
grackle-project#405

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.

4 participants