Skip to content

Consistency tweaks: GrainSpeciesCollection and cool_multi_time_g#25

Closed
mabruzzo wants to merge 261 commits into
brittonsmith:gen2024from
mabruzzo:gen2024transcribe/consistency-tweaks
Closed

Consistency tweaks: GrainSpeciesCollection and cool_multi_time_g#25
mabruzzo wants to merge 261 commits into
brittonsmith:gen2024from
mabruzzo:gen2024transcribe/consistency-tweaks

Conversation

@mabruzzo

@mabruzzo mabruzzo commented Jan 28, 2025

Copy link
Copy Markdown

To be reviewed after #24 is merged (i.e. the PR where solve_rate_cool_g was transcribed)


This PR essentially goes back and makes some tweaks to the internal GrainSpeciesCollection helper-type and the C++ version of the cool_multi_time_g function, both introduced in PR #19, to achieve consistency with some of choices made in #241

This is actually a fairly small PR. The changes include:

  1. Switching the GrainSpeciesCollection to be more consistent with the similar, but more generic SpeciesCollection type. For concreteness:
    • when I created the SpeciesCollection type, I designed it to use enumerators defined within the SpLUT pseudo-namespace as a compile-time lookup table (mapping species names to an index)
    • this PR's 1st commit refactors GrainSpeciesCollection so that it uses the the enumerators within the newly-defined OnlyGrainSpLUT pseudo-namespace as a lookup-table.2
  2. Various superficial tweaks to the cool_multi_time_g function:
    • it now uses the InternalGrUnits type instead of manually tracking the utem, urho & uxyz floating point values and an instance of the code_units struct (this also removes some boiler-plate from local_calculate_temperature)
    • modified the j,k loop to use grackle_index_helper and IndexRange (the latter helps removes some ambiguities about 0-based and 1-based indexing when calling routines that are not yet transcribed)
    • thanks to the previous two changes in the last 2 bullets, I was able to replace all FORTRAN_NAME({subroutine}) occurrences with the nicer, C++ wrapper functions. Recall that these wrappers take shorter argument lists, mostly composed of structs, and internally forward the struct-members on to the underlying routine. This is important for the future process of transcribing a routine like cool1d_multi_g, which is called from multiple other transcribed routines.3
    • I also made some superficial tweaks to the 2 for-loops within cool_multi_time_g. The variables holding variable values now only hold the 0-based index values (rather than 1-based index values that we adjust every time that they are used). This was not strictly essential to this PR
    • we now pass 2 arguments by value instead of by pointer (for consistency with solve_rate_cool_g). This was not strictly essential to this PR

I have manually confirmed that all tests successfully pass

Footnotes

  1. To put it another way, PR Gen2024 transcribe cool_multi_time_g #19 was my first attempt at transcribing a top-level function. PR transcribe: solve_rate_cool_g to C++ #24 was my second attempt at doing so. I learned a lot while working on transcribe: solve_rate_cool_g to C++ #24 and established some conventions that improved quality and made transcription of certain aspects of the code a lot easier. Now I'm going back and applying this experience to improve the quality of the code written as part of my first transcription attempt.

  2. In the future, this change is going to significantly simplify the C++ versions of calc_all_tdust_gasgr_1d_g and calc_grain_size_increment_1d. Currently these routines have multiple instances where the same exact logic is repeated 12 times (once per dust grain species). This change should help us replace instances of this code-duplication with for-loops.

  3. Essentially, we want there to be just 1 location in the entire codebase where we directly reference any given Fortran routine before we transcribe that routine. (there are a couple of reasons for this that I could go into if you want)

mabruzzo and others added 30 commits December 27, 2024 11:16
To aide with transcription to C/C++ I made the following tweaks to
`calc_grain_size_increment_1d.F`:
- Within `calc_grain_size_increment_1d`, I broke lines similar to
    `SN_i(nSN) =  1; SN_metal(:,nSN) = metal_loc(:,j,k)`
  into 2 separate lines.
  - Prior to this commit, there were essentially 2 statements on each
    of these lines (the statements are delimited by `;`)
  - The transcription routines can't currently handle cases like this
    (it assumes that there is only 1 statement on each line)
  - I made changes like this in 12 locations.
- I inserted `#include "grackle_fortran_types.def"` into
  `solve_cubic_equation` to declare the ``pi_val`` macro inside of the
  subroutine's parameter declarations.
  - This is a convention followed by nearly every subroutine
    declaration in Fortran and it simplifies the process of
    transcription.
  - A standard Fortran compiler does not technically require this change
    since the header is already included within the body of different
    subroutine earlier in the file and the macro definition carries over
    from there.
A handful of c functions had a `[-Wreturn-type]` compiler warning where
a function was supposed to return a value but had at least 1 control
flow branch where we didn't return anything.

Also fixed a spot in `c_local_example` where we were passing a
`chemistry_data**` ptr to `local_free_chemistry_data` rather than a
`chemistry_data*` ptr.
this parallel clause is used when converting from comoving to proper
this parallel clause is used when converting from proper to comoving
Removed unused local variables from `calc_tdust_3d_g` that followed the
naming scheme used in solve_rate_cool for tracking the mass density for
the mass densities of various metal species used in dust chemistry.

There was logic to convert between proper and comoving units for each of
these variables, but they were not actually used for anything (which is
a good thing since they were never initialized).

These variable declarations were probably blindly copied from somewhere
else and were never removed.
Removed unused local variables from `calc_tdust_3d_g` that followed the
naming scheme used in solve_rate_cool for tracking the mass density for
tracking the mass densities of various metal species used in metal
chemistry.

There was logic to convert between proper and comoving units for each of
these variables, but they were not actually used for anything (which is
a good thing since they were never initialized).

These variable declarations were probably blindly copied from somewhere
else and were never removed.
`make dep` previously didn't work correctly with some of the C++ files
(I think because I changed the suffix of the names of some headers)
This is the last commit in a sequence where we were refactoring the
local variable declarations. The routine should now work properly with
OpenMP, but we can't test that since OpenMP-support was broken in
earlier commits to the gen2024 branch (before we began the
transcription).

More simplifications can certainly be made, but it is worth holding off
on that until after we have transcribed more of Grackle.
mabruzzo and others added 27 commits April 9, 2025 12:41
Originally I tried to fix the problem properly, by having
grackle_macros.h directly include grackle.h. But, this produced
problems related to the fact that some function are redeclared slightly
differently between grackle.h and within the source files (the
difference is OK since it is just related to the appearance of `const`).
A number of pending PRs gradually fix this disagreement throughtout the
codebase. Thus, we are going to hold off on "fixing it properly" until
those other PRs are merged
[newchem-cpp] Reverting minor changes to abundance corrections
[newchem-cpp] 2 minor bugfixes following last week's merge
I a prior merge, I accidently duplicated "initialize_rates.lo" in
``src/clib/Make.config.objects``. This caused obviously introduced some
linking problems with the classic build-system
While it looks like there is a large deviation from the older results,
Britton previously did a lot of work investigating this. It turns out
that the example is in the regime where Grackle keeps overshooting the
equlibrium state. We just aren't at the "same point of overshoot"
…d-standard

Register temporary gold standard
When I changed the type of `end_int` argument of ``interpolate_3Dz_g``
to use a 64-bit integer, I forgot to modify the declaration used within
the InterpolationTest.Interpolate3Dz unit-test
@mabruzzo

Copy link
Copy Markdown
Author

superseded by grackle-project#332

@mabruzzo mabruzzo closed this May 18, 2025
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.

5 participants