From 72ce65c11d241ef42f02995e0a2f23d623322fe0 Mon Sep 17 00:00:00 2001 From: David Grote Date: Wed, 23 Apr 2025 11:24:37 -0700 Subject: [PATCH 1/2] For MuliFab indexing, () means all cells in all dimension, valid and ghost --- src/amrex/extensions/MultiFab.py | 6 +++--- tests/test_multifab.py | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/amrex/extensions/MultiFab.py b/src/amrex/extensions/MultiFab.py index 8cae31d6..4a630544 100644 --- a/src/amrex/extensions/MultiFab.py +++ b/src/amrex/extensions/MultiFab.py @@ -316,9 +316,9 @@ def _process_index(self, index): # If only one slice or integer passed in, it was not wrapped in a tuple index = [index] elif isinstance(index, tuple): - if len(index) == 0: - # The empty tuple specifies all valid and ghost cells - index = [index] + if len(index) == 0: + # The empty tuple specifies all valid and ghost cells for all axis + index = dims*[index] else: index = list(index) for i in range(len(index)): diff --git a/tests/test_multifab.py b/tests/test_multifab.py index 88b0b1d8..692ee4ba 100644 --- a/tests/test_multifab.py +++ b/tests/test_multifab.py @@ -77,7 +77,10 @@ def test_mfab_numpy(mfab): # Config = sim.extension.Config # Using global indexing - # Set all valid cells (and internal ghost cells) + # Set all cells, valid and ghost cells, using the empty tuple + mfab[()] = np.pi + + # Set all valid cells (and ghost cells overlapping valid cells), using the Ellipsis mfab[...] = 42.0 # Set a range of cells. Indices are in Fortran order. @@ -87,7 +90,7 @@ def test_mfab_numpy(mfab): # Third dimension, sets all valid and ghost cells # - The empty tuple is used to specify the range to include all valid and ghost cells. # Components dimension, sets first component. - mfab[-1j:2j, :, (), 0] = 42.0 + mfab[-1j:2j, :, (), 0] = 37.0 # Get a range of cells # Get the data along the valid cells in the first dimension (gathering data across blocks From 65e8bf7f1cee673417df530214c5ca1198e30520 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 18:30:01 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/amrex/extensions/MultiFab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amrex/extensions/MultiFab.py b/src/amrex/extensions/MultiFab.py index 4a630544..a3863103 100644 --- a/src/amrex/extensions/MultiFab.py +++ b/src/amrex/extensions/MultiFab.py @@ -316,9 +316,9 @@ def _process_index(self, index): # If only one slice or integer passed in, it was not wrapped in a tuple index = [index] elif isinstance(index, tuple): - if len(index) == 0: + if len(index) == 0: # The empty tuple specifies all valid and ghost cells for all axis - index = dims*[index] + index = dims * [index] else: index = list(index) for i in range(len(index)):