Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Enzo-E simulations with 0 ghost zones #4932

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion yt/frontends/enzo_e/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def _parse_parameter_file(self):
self.parameters["current_cycle"] = ablock.attrs["cycle"][0]
gsi = ablock.attrs["enzo_GridStartIndex"]
gei = ablock.attrs["enzo_GridEndIndex"]
self.ghost_zones = gsi[0]
assert len(gsi) == len(gei) == 3 # sanity check
# Enzo-E technically allows each axis to have different ghost zone
# depths (this feature is not really used in practice)
self.ghost_zones = gsi
Copy link
Member

Choose a reason for hiding this comment

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

although technically not backward compatible, I don't expect anyone to rely on the old behavior so I'm tempted to just let this change in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely agree, especially because pool of enzo-e users is currently very small. (At most, there are maybe 5 people who regularly use the yt-frontend right now)

But, let me know if you would prefer I change it (and whether there is an obvious preferred way to do it)

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine as is. I'll just give it a couple weeks before merging in case anyone objects.

assert (self.ghost_zones[self.dimensionality :] == 0).all() # sanity check
self.root_block_dimensions = root_blocks
self.active_grid_dimensions = gei - gsi + 1
self.grid_dimensions = ablock.attrs["enzo_GridDimension"]
Expand Down
15 changes: 12 additions & 3 deletions yt/frontends/enzo_e/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ class EnzoEIOHandler(BaseIOHandler):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._base = self.ds.dimensionality * (
slice(self.ds.ghost_zones, -self.ds.ghost_zones),

# precompute the indexing specifying each field's active zone
# -> this assumes that each field in Enzo-E shares the same number of
# ghost-zones. Technically, Enzo-E allows each field to have a
# different number of ghost zones (but this feature isn't currently
# used & it currently doesn't record this information)
# -> our usage of a negative stop value ensures compatability with
# both cell-centered and face-centered fields
self._activezone_idx = tuple(
slice(num_zones, -num_zones) if num_zones > 0 else slice(None)
for num_zones in self.ds.ghost_zones[: self.ds.dimensionality]
)

# Determine if particle masses are actually masses or densities.
Expand Down Expand Up @@ -186,7 +195,7 @@ def _read_obj_field(self, obj, field, fid_data):
dg.read(h5py.h5s.ALL, h5py.h5s.ALL, rdata)
if close:
fid.close()
data = rdata[self._base].T
data = rdata[self._activezone_idx].T
if self.ds.dimensionality < 3:
nshape = data.shape + (1,) * (3 - self.ds.dimensionality)
data = np.reshape(data, nshape)
Expand Down
Loading