Skip to content

Commit dcd04ef

Browse files
committed
viz: fix ellipsis n_requested count; add 2-rank ghost-cell assembly fixture
1 parent b0acc7c commit dcd04ef

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed
420 Bytes
Binary file not shown.
348 Bytes
Binary file not shown.

toolchain/mfc/viz/test_viz.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
FIX_2D_SILO = os.path.join(FIXTURES, '2d_silo')
2222
FIX_3D_BIN = os.path.join(FIXTURES, '3d_binary')
2323
FIX_3D_SILO = os.path.join(FIXTURES, '3d_silo')
24+
FIX_1D_BIN_2RANK = os.path.join(FIXTURES, '1d_binary_2rank')
2425

2526

2627
# ---------------------------------------------------------------------------
@@ -104,6 +105,14 @@ def test_ellipsis_must_be_second_to_last(self):
104105
with self.assertRaises(MFCException):
105106
self._parse('0,100,...,500,1000', [0, 100, 500, 1000])
106107

108+
def test_ellipsis_n_requested_is_expanded_range(self):
109+
"""Ellipsis n_requested reflects the expanded range, not the matched count."""
110+
from .viz import _parse_steps
111+
# Range 0,100,...,1000 expands to 11 steps; only 3 are available.
112+
matched, n_req = _parse_steps('0,100,...,1000', [0, 200, 1000])
113+
self.assertEqual(n_req, 11)
114+
self.assertEqual(matched, [0, 200, 1000])
115+
107116
def test_invalid_value(self):
108117
"""Non-numeric, non-keyword input raises MFCException."""
109118
from mfc.common import MFCException
@@ -230,6 +239,44 @@ def test_var_filter(self):
230239
self.assertNotIn('vel1', data.variables)
231240

232241

242+
class TestAssembleBinary1DMultiRank(unittest.TestCase):
243+
"""Test multi-rank assembly with overlapping ghost cells (1D, 2 ranks)."""
244+
245+
def test_ndim(self):
246+
"""2-rank 1D fixture assembles with ndim=1."""
247+
from .reader import assemble
248+
data = assemble(FIX_1D_BIN_2RANK, 0, 'binary')
249+
self.assertEqual(data.ndim, 1)
250+
251+
def test_cell_count_after_dedup(self):
252+
"""Ghost cell overlap is deduplicated: 16 unique cells from two overlapping ranks."""
253+
from .reader import assemble
254+
data = assemble(FIX_1D_BIN_2RANK, 0, 'binary')
255+
self.assertEqual(len(data.x_cc), 16)
256+
257+
def test_grid_is_sorted_and_unique(self):
258+
"""Assembled global grid is strictly increasing with no duplicates."""
259+
import numpy as np
260+
from .reader import assemble
261+
data = assemble(FIX_1D_BIN_2RANK, 0, 'binary')
262+
diffs = np.diff(data.x_cc)
263+
self.assertTrue(bool(np.all(diffs > 0)), "x_cc is not strictly increasing")
264+
265+
def test_variable_values_match_position(self):
266+
"""pres values (== x_cc position) are placed at the correct global cells."""
267+
import numpy as np
268+
from .reader import assemble
269+
data = assemble(FIX_1D_BIN_2RANK, 0, 'binary')
270+
np.testing.assert_allclose(data.variables['pres'], data.x_cc, atol=1e-10)
271+
272+
def test_all_vars_present(self):
273+
"""Both variables written by both ranks appear in the assembled output."""
274+
from .reader import assemble
275+
data = assemble(FIX_1D_BIN_2RANK, 0, 'binary')
276+
self.assertIn('pres', data.variables)
277+
self.assertIn('rho', data.variables)
278+
279+
233280
class TestAssembleBinary2D(unittest.TestCase):
234281
"""Test binary reader with 2D fixture data."""
235282

toolchain/mfc/viz/viz.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,15 @@ def _parse_steps(step_arg, available_steps):
168168
# n_requested: count of explicit values (ellipsis form expands to a range)
169169
parts = [p.strip() for p in s.split(',')]
170170
if '...' in parts:
171-
# approximate from the parsed result + unmatched
172-
n_req = len(matched) # conservative; exact count needs re-parsing
171+
# Compute the expanded range length independently of filtering.
172+
try:
173+
idx = parts.index('...')
174+
prefix = [int(p) for p in parts[:idx]]
175+
end_val = int(parts[-1])
176+
stride = prefix[-1] - prefix[-2]
177+
n_req = len(range(prefix[0], end_val + 1, stride)) if stride > 0 else len(matched)
178+
except (ValueError, IndexError):
179+
n_req = len(matched)
173180
else:
174181
n_req = len(parts)
175182
return matched, n_req

0 commit comments

Comments
 (0)