Skip to content

Fix missing volume checks in material activity/decay heat#3939

Merged
paulromano merged 2 commits into
openmc-dev:developfrom
approx-infinity:fix
May 18, 2026
Merged

Fix missing volume checks in material activity/decay heat#3939
paulromano merged 2 commits into
openmc-dev:developfrom
approx-infinity:fix

Conversation

@approx-infinity
Copy link
Copy Markdown
Contributor

Summary

This PR adds explicit validation for Material.volume in total activity (Bq, Ci) and decay heat (W) calculations.

Previously, calling get_activity() or get_decay_heat() without setting a material volume could result in unclear or misleading runtime errors (e.g., TypeError or downstream failures).

This change introduces a clear and early ValueError when volume is not defined, improving error clarity and robustness of the material depletion/decay interface.

Changes

  • Added explicit check for Material.volume before computing:
    -- total activity
    -- total decay heat
  • Raise ValueError with a descriptive message if volume is not set
  • Ensures failure occurs at the correct abstraction level (input validation instead of downstream numerical failure)

Testing

pytest tests/unit_tests/test_material.py -k "get_activity or get_decay_heat"

Result

2 passed, 35 deselected

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)

@approx-infinity approx-infinity changed the title Fix Fix missing volume checks in material activity/decay heat May 16, 2026
Copy link
Copy Markdown
Member

@nuclearkevin nuclearkevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution, and welcome to the OpenMC community @approx-infinity! This looks good to me; if nobody else has any comments I'll merge tomorrow.

@paulromano paulromano merged commit 195dff6 into openmc-dev:develop May 18, 2026
17 checks passed
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.

3 participants