From c44d2f0b433157b43087d5f5fdbcce6787b6ac73 Mon Sep 17 00:00:00 2001 From: Christopher Ashe <91618944+chris-ashe@users.noreply.github.com> Date: Thu, 12 Mar 2026 19:47:47 +0000 Subject: [PATCH] Allow groups to be passed as sequence of floats in `convert_to_multigroup` (#3873) Co-authored-by: Jonathan Shimwell Co-authored-by: Paul Romano --- openmc/model/model.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index 67a8495ee7..884e3ff6f9 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -2520,7 +2520,7 @@ class Model: def convert_to_multigroup( self, method: str = "material_wise", - groups: str = "CASMO-2", + groups: str | Sequence[float] | openmc.mgxs.EnergyGroups = "CASMO-2", nparticles: int = 2000, overwrite_mgxs_library: bool = False, mgxs_path: PathLike = "mgxs.h5", @@ -2538,9 +2538,13 @@ class Model: ---------- method : {"material_wise", "stochastic_slab", "infinite_medium"}, optional Method to generate the MGXS. - groups : openmc.mgxs.EnergyGroups or str, optional - Energy group structure for the MGXS or the name of the group - structure (based on keys from openmc.mgxs.GROUP_STRUCTURES). + groups : openmc.mgxs.EnergyGroups, str, or sequence of float, optional + Energy group structure for the MGXS. Can be an + :class:`openmc.mgxs.EnergyGroups` object, a string name of a + predefined group structure from :data:`openmc.mgxs.GROUP_STRUCTURES` + (e.g., ``"CASMO-2"``), or a sequence of floats specifying energy + bin boundaries in eV (e.g., ``[0.0, 1e6]`` for a single group). + Defaults to ``"CASMO-2"``. nparticles : int, optional Number of particles to simulate per batch when generating MGXS. overwrite_mgxs_library : bool, optional @@ -2577,7 +2581,7 @@ class Model: Valid entries for temperature_settings are the same as the valid entries in openmc.Settings.temperature_settings. """ - if isinstance(groups, str): + if not isinstance(groups, openmc.mgxs.EnergyGroups): groups = openmc.mgxs.EnergyGroups(groups) # Do all work (including MGXS generation) in a temporary directory