Refactor Read_Grid_HDF5 to make use of FieldInfo#468
Open
mabruzzo wants to merge 13 commits intocholla-hydro:devfrom
Open
Refactor Read_Grid_HDF5 to make use of FieldInfo#468mabruzzo wants to merge 13 commits intocholla-hydro:devfrom
Read_Grid_HDF5 to make use of FieldInfo#468mabruzzo wants to merge 13 commits intocholla-hydro:devfrom
Conversation
mabruzzo
commented
Jan 28, 2026
Comment on lines
+2633
to
+2663
| // this should work whether Cholla is configured with COOLING_GRACKLE or CHEMISTRY_GPU | ||
| // - earlier versions of this logic wouldn't work with Grackle | ||
| static void cosmo_init_chemical_species_(const Header &H, const FieldInfo &field_info, Real *host_field_ptr) | ||
| { | ||
| if (!field_info.field_id("HI_density").has_value()) { | ||
| CHOLLA_ERROR("This function has been erroneously executed. There are no chemical species"); | ||
| } | ||
|
|
||
| Real *density = &host_field_ptr[H.n_cells * field_info.field_id("density").value()]; | ||
| Real *HI_density = &host_field_ptr[H.n_cells * field_info.field_id("HI_density").value()]; | ||
| Real *HII_density = &host_field_ptr[H.n_cells * field_info.field_id("HII_density").value()]; | ||
| Real *HeI_density = &host_field_ptr[H.n_cells * field_info.field_id("HeI_density").value()]; | ||
| Real *HeII_density = &host_field_ptr[H.n_cells * field_info.field_id("HeII_density").value()]; | ||
| Real *HeIII_density = &host_field_ptr[H.n_cells * field_info.field_id("HeIII_density").value()]; | ||
| Real *e_density = &host_field_ptr[H.n_cells * field_info.field_id("e_density").value()]; | ||
|
|
||
| for (int k = 0; k < H.nz_real; k++) { | ||
| for (int j = 0; j < H.ny_real; j++) { | ||
| for (int i = 0; i < H.nx_real; i++) { | ||
| int id = (i + H.n_ghost) + (j + H.n_ghost) * H.nx + (k + H.n_ghost) * H.nx * H.ny; | ||
| int buf_id = k + j * (H.nz_real) + i * (H.nz_real) * (H.ny_real); | ||
| HI_density[id] = INITIAL_FRACTION_HI * density[id]; | ||
| HII_density[id] = INITIAL_FRACTION_HII * density[id]; | ||
| HeI_density[id] = INITIAL_FRACTION_HEI * density[id]; | ||
| HeII_density[id] = INITIAL_FRACTION_HEII * density[id]; | ||
| HeIII_density[id] = INITIAL_FRACTION_HEIII * density[id]; | ||
| e_density[id] = INITIAL_FRACTION_ELECTRON * density[id]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
The following snippet is more consistent with the original style of the code that we replaced. I'm happy to revert it if that's your preference. But, be aware, I'm 99% that the old version is incompatible with Grackle.
For context, the defined(COOLING_GRACKLE) condition has been inserted for historical consistency, but I'm pretty sure the code won't compile -- Grid3D::Conserved doesn't have data members named HI_density, HII_density, ... in that mode
// this should work whether Cholla is configured with COOLING_GRACKLE or CHEMISTRY_GPU
// - earlier versions of this logic wouldn't work with Grackle
static void cosmo_init_chemical_species_(const Header &H, Grid3D::Conserved& C)
{
#if defined(COOLING_GRACKLE) || defined(CHEMISTRY_GPU)
for (int k = 0; k < H.nz_real; k++) {
for (int j = 0; j < H.ny_real; j++) {
for (int i = 0; i < H.nx_real; i++) {
int id = (i + H.n_ghost) + (j + H.n_ghost) * H.nx + (k + H.n_ghost) * H.nx * H.ny;
int buf_id = k + j * (H.nz_real) + i * (H.nz_real) * (H.ny_real);
C.HI_density[id] = INITIAL_FRACTION_HI * C.density[id];
C.HII_density[id] = INITIAL_FRACTION_HII * C.density[id];
C.HeI_density[id] = INITIAL_FRACTION_HEI * C.density[id];
C.HeII_density[id] = INITIAL_FRACTION_HEII * C.density[id];
C.HeIII_density[id] = INITIAL_FRACTION_HEIII * C.density[id];
C.e_density[id] = INITIAL_FRACTION_ELECTRON * C.density[id];
}
}
}
#endif
}4606463 to
0cb5308
Compare
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 is a followup to #467
Quite simply, this PR refactors
Read_Grid_HDF5to make use of the newly introducedFieldInfotype.