Skip to content

Commit

Permalink
BUG: fix ds.all_data() for spherical AMReX datasets
Browse files Browse the repository at this point in the history
`ds.index.level_dds` was being overwritten in `_parse_index()`, which
breaks the `all_data()` region selector. This commit instead updates
`domain_right_edge` in `_parse_header_file()`, like we do for
cylindrical datasets.
  • Loading branch information
yut23 committed Oct 10, 2024
1 parent 5f44989 commit f2ed2fc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
11 changes: 6 additions & 5 deletions yt/frontends/amrex/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,9 @@ def _parse_index(self):
default_ybounds = (0.0, 1.0)
default_zbounds = (0.0, 1.0)
elif self.ds.geometry == "cylindrical":
self.level_dds[:, 2] = 2 * np.pi
default_ybounds = (0.0, 1.0)
default_zbounds = (0.0, 2 * np.pi)
elif self.ds.geometry == "spherical":
# BoxLib only supports 1D spherical, so ensure
# the other dimensions have the right extent.
self.level_dds[:, 1] = np.pi
self.level_dds[:, 2] = 2 * np.pi
default_ybounds = (0.0, np.pi)
default_zbounds = (0.0, 2 * np.pi)
else:
Expand Down Expand Up @@ -908,6 +903,12 @@ def _parse_header_file(self):
dre = self.domain_right_edge.copy()
dre[2] = 2.0 * np.pi
self.domain_right_edge = dre
if self.geometry == "spherical" and self.dimensionality < 3:
dre = self.domain_right_edge.copy()
if self.dimensionality < 2:
dre[1] = np.pi
dre[2] = 2.0 * np.pi
self.domain_right_edge = dre

header_file.close()

Expand Down
57 changes: 57 additions & 0 deletions yt/frontends/amrex/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,60 @@ def test_maestro_parameters():
# Check an int parameter
assert ds.parameters["s0_interp_type"] == 3
assert type(ds.parameters["s0_interp_type"]) is int # noqa: E721


# test loading non-Cartesian coordinate systems in different dimensionalities


def check_coordsys_data(ds):
# check that level_dds is consistent with domain_width
assert_allclose(
ds.index.level_dds[0] * ds.domain_dimensions,
ds.domain_width.to_value("code_length"),
rtol=1e-12,
atol=0.0,
)

# check that we get the expected number of data points when selecting the
# entire domain
expected_size = sum(np.count_nonzero(g.child_mask) for g in ds.index.grids)
ad = ds.all_data()
assert ad["boxlib", "Temp"].size == expected_size


cyl_1d = "castro_sedov_1d_cyl_plt00150"
cyl_2d = "castro_sedov_2d_sph_in_cyl_plt00130"
sph_1d = "sedov_1d_sph_plt00120"
sph_2d = "xrb_spherical_smallplt00010"


@requires_file(cyl_1d)
def test_coordsys_1d_cylindrical():
ds = data_dir_load(cyl_1d)
assert ds.geometry == "cylindrical"
assert ds.dimensionality == 1
check_coordsys_data(ds)


@requires_file(cyl_2d)
def test_coordsys_2d_cylindrical():
ds = data_dir_load(cyl_2d)
assert ds.geometry == "cylindrical"
assert ds.dimensionality == 2
check_coordsys_data(ds)


@requires_file(sph_1d)
def test_coordsys_1d_spherical():
ds = data_dir_load(sph_1d)
assert ds.geometry == "spherical"
assert ds.dimensionality == 1
check_coordsys_data(ds)


@requires_file(sph_2d)
def test_coordsys_2d_spherical():
ds = data_dir_load(sph_2d)
assert ds.geometry == "spherical"
assert ds.dimensionality == 2
check_coordsys_data(ds)

0 comments on commit f2ed2fc

Please sign in to comment.