transcribe: solve_rate_cool_g to C++#24
Closed
mabruzzo wants to merge 252 commits into
Closed
Conversation
Unlike other cases where we replaced ``logical`` with ``MASK_TYPE``, I replaced it with ``integer*8`` for the sake of consistency with the grackle-project#160 PR (I plan to use the transcription of interpolators_g.F from that PR in the future).
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.
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.
…for transcribing)
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.
…arts of the code.
`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)
Warn about usage of deprecated headers
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
…cribe/solve_rate_cool_g
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"
…core-lib test-suite
…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
…cribe/solve_rate_cool_g
Author
|
superseded by grackle-project#331 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR needs to be reviewed after PRs #19 - #21 and #23
High-level Summary
This PR transcribes
solve_rate_cool_gfrom Fortran to C++ (the helper functions withinsolve_rate_cool_g.Fwere not transcribed). I think the following table is somewhat instructive about the significance of this PROverview
At its core, this PR is a straight-forward one-to-one from transcription from Fortran to C++. This is plainly visible in the first couple of commits. All of the subsequent commits correspond to efforts to essentially "polish" the code
All of this polishing was primarily motivated by a desire to minimize unnecessary future work and this routine's status as the lowest common ancestor of the call-graphs of every non-trivial Fortran subroutine. In more detail:
solve_rate_cool_g's arguments and hundreds of local variablesPolishing the code also made it easier to understand the general control flow (and how the routines are all inter-related), but that's honestly a secondary motivation
Important
To be clear:
More About Polishing:
enforce_max_heatcool_subcycle_dt_,select_chem_scheme_update_masks_,calc_Heq_div_dHeqdt_, &set_subcycle_dt_from_chemistry_scheme_Important new types:
IndexRange:index_helper.hfor use with transcribed routines (and general C++ compatibility) #23InternalGrUnits:code_units. I was EXTREMELY careful to make sure I preserved the original logic and make sure we used the right version of all of the constants (The value of pi differs between the C and Fortran cases and the default precision various constants differ)code_unitsin the future. For no, this simplifies a lot of transcriptionSpeciesRateSolverScratchBuf:solve_rate_cool_g(i.e. it provides a clear distinction between local variables required for cooling and variables needed for species chemistry)Places where logic changed/relocated:
gotostatement into abreakstatementierrhas been tweaked slightly. (the actual logic is all the same, but now we directly return the value)InternalGrUnitstype. But the logic has been perfectly preserved.j,kindex-pairs) was converted to use theindex_helpermachinery used in our other existing C routines (the logic is exactly equivalent and this was necessary to useInternalGrUnits)coupled_rt_modify_itmask_local function. There was a minor tweak: I moved the statement checked by both inner if-statements to the outer if-statementAssorted Closing Thoughts
The scope of this PR definitely ballooned, but I think it's worth it. All of the commits were logically ordered and have a somewhat descriptive commit message (the ordering got a little more chaotic near the end as I kept finding things that I forgot to address).
If it would make things easier, I could divide this PR into smaller parts. But you would need to be okay with merging very messy looking code into the branch.
Note
PRs for other transcribed routines should all be a lot simpler to review. As noted earlier, there were unique and strong incentives to do a lot of "polishing" in this PR.
As should be clear, I have verified that all the tests pass! (they do so after every commit)
OpenMP should now work. I still can't haven't tested it yet since it's broken in the untranslated top-level subroutines (since Gen didn't keep the lists of private local variables up to date)
Brief Thoughts for the future:
Footnotes
The groupings of local variables don't have to be perfect, we can always adjust them later. But, the process of aggregating them will never be easier than it is right now ↩
Additionally, there were a couple spots that had large "if-conditions" where I pre-computed parts of the conditions and temporarily stored them within local variables to simply improve legibility. The logic did not change ↩