Skip to content

Add multi-index support to d1s.apply_time_correction (sequence in, list out)#105

Open
shimwell wants to merge 2 commits into
developfrom
d1s-multi-index-sequence
Open

Add multi-index support to d1s.apply_time_correction (sequence in, list out)#105
shimwell wants to merge 2 commits into
developfrom
d1s-multi-index-sequence

Conversation

@shimwell

@shimwell shimwell commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

apply_time_correction now takes a sequence of time indices and returns a list of derived tallies, one per index. The tally arrays are read and reshaped once and shared across all indices, so post-processing a D1S mesh tally at many shutdown times no longer re-reads and re-reshapes the data on every call.

The per-index math is unchanged from develop, so each derived tally is bit-for-bit identical to the previous single-index result.

API change (small, intentional break)

This favours a clean, type-stable signature over a polymorphic int | Sequence[int]Tally | list[Tally] API:

  • index is now an iterable of ints; the default is (-1,) (was -1).
  • The function always returns list[openmc.Tally], one per index, in order.

Callers that want a single time unpack the one-element list:

tally, = d1s.apply_time_correction(dose_tally, factors, [-1])

The existing test, the user-guide example, and a new multi-index test are updated accordingly. A .. versionchanged:: 0.16.0 note documents the break in the docstring.

Testing

Adds test_apply_time_correction_multi_index, which checks that each element of a multi-index call matches the corresponding single-index call (mean, std_dev, filters, and sum/sum_sq), that unordered/partial index sequences are honored in order, and that the original tally is left unmodified. The existing test_apply_time_correction is updated to unpack the list.

Note: the D1S unit tests call model.run() and require a compiled OpenMC plus nuclear data, so they were not executed locally — CI will cover them.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

apply_time_correction now takes a sequence of time indices and returns a
list of derived tallies, one per index. The tally arrays are read and
reshaped once and shared across all indices, so post-processing a D1S mesh
tally at many shutdown times no longer re-reads and re-reshapes the data on
every call. The per-index math is unchanged, so each derived tally is
bit-for-bit identical to the previous single-index result.

This is a small breaking change: the function always returns a list (one
tally per index) and the default index is now (-1,) rather than -1. The
existing test, docs example, and the new multi-index test are updated to
unpack the returned list.
@shimwell shimwell force-pushed the d1s-multi-index-sequence branch from d37ecee to e535e66 Compare June 1, 2026 09:49
Comment thread openmc/deplete/d1s.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants