Skip to content

Commit 77db770

Browse files
For MuliFab indexing, () means all cells in all dimension, valid and ghost (#438)
This PR clarifies the use of the empty tuple index, `()`, for MultiFabs. Giving the empty tuple as the only index of a MultiFab will return the full array, both valid and ghost cells. This is in contrast to the `Ellipsis` that will return the array with only value cells. For example ``` mf = MultiFab() mf[()] # returns valid and ghost cells mf[...] # returns only valid cells ``` --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8e51bf0 commit 77db770

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/amrex/extensions/MultiFab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def _process_index(self, index):
317317
index = [index]
318318
elif isinstance(index, tuple):
319319
if len(index) == 0:
320-
# The empty tuple specifies all valid and ghost cells
321-
index = [index]
320+
# The empty tuple specifies all valid and ghost cells for all axis
321+
index = dims * [index]
322322
else:
323323
index = list(index)
324324
for i in range(len(index)):

tests/test_multifab.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def test_mfab_numpy(mfab):
7777
# Config = sim.extension.Config
7878

7979
# Using global indexing
80-
# Set all valid cells (and internal ghost cells)
80+
# Set all cells, valid and ghost cells, using the empty tuple
81+
mfab[()] = np.pi
82+
83+
# Set all valid cells (and ghost cells overlapping valid cells), using the Ellipsis
8184
mfab[...] = 42.0
8285

8386
# Set a range of cells. Indices are in Fortran order.
@@ -87,7 +90,7 @@ def test_mfab_numpy(mfab):
8790
# Third dimension, sets all valid and ghost cells
8891
# - The empty tuple is used to specify the range to include all valid and ghost cells.
8992
# Components dimension, sets first component.
90-
mfab[-1j:2j, :, (), 0] = 42.0
93+
mfab[-1j:2j, :, (), 0] = 37.0
9194

9295
# Get a range of cells
9396
# Get the data along the valid cells in the first dimension (gathering data across blocks

0 commit comments

Comments
 (0)