Skip to content

Commit 6d6b051

Browse files
shimwelljon-proximafusionpshriwiseGuySten
authored
avoid need to set particles and batches for dagmc models when calling convert_to_multigroup (#3801)
Co-authored-by: Jon Shimwell <[email protected]> Co-authored-by: Patrick Shriwise <[email protected]> Co-authored-by: GuySten <[email protected]>
1 parent d4dc089 commit 6d6b051

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

openmc/model/model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,9 +2584,16 @@ def convert_to_multigroup(
25842584
# TODO: Can this be done without having to init/finalize?
25852585
for univ in self.geometry.get_all_universes().values():
25862586
if isinstance(univ, openmc.DAGMCUniverse):
2587+
# Initialize in stochastic volume mode (non-transport mode)
2588+
# This mode doesn't require
2589+
# valid transport settings like particles/batches
2590+
original_run_mode = self.settings.run_mode
2591+
self.settings.run_mode = 'volume'
25872592
self.init_lib(directory=tmpdir)
25882593
self.sync_dagmc_universes()
25892594
self.finalize_lib()
2595+
# Restore original run mode
2596+
self.settings.run_mode = original_run_mode
25902597
break
25912598

25922599
# Make sure all materials have a name, and that the name is a valid HDF5
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Test that convert_to_multigroup works with DAGMC models without requiring
2+
particles/batches to be set beforehand.
3+
"""
4+
5+
from pathlib import Path
6+
import pytest
7+
import openmc
8+
import openmc.lib
9+
10+
pytestmark = pytest.mark.skipif(
11+
not openmc.lib._dagmc_enabled(),
12+
reason="DAGMC CAD geometry is not enabled.")
13+
14+
15+
def test_convert_to_multigroup_without_particles_batches(run_in_tmpdir):
16+
"""Test that convert_to_multigroup works with DAGMC model without
17+
setting particles/batches beforehand."""
18+
openmc.reset_auto_ids()
19+
20+
mat = openmc.Material(name="mat")
21+
mat.add_nuclide("Fe56", 1.0)
22+
mat.set_density("g/cm3", 7.0)
23+
24+
# Use minimal tetrahedral DAGMC file
25+
dagmc_file = Path(__file__).parent / "dagmc_tetrahedral_no_graveyard.h5m"
26+
dagmc_univ = openmc.DAGMCUniverse(dagmc_file, auto_geom_ids=True)
27+
bound_dagmc_univ = dagmc_univ.bounded_universe(padding_distance=1)
28+
29+
# Create model WITHOUT setting particles or batches
30+
model = openmc.Model()
31+
model.materials = openmc.Materials([mat])
32+
model.geometry = openmc.Geometry(bound_dagmc_univ)
33+
model.settings = openmc.Settings() # Note: no particles or batches set!
34+
35+
model.settings.run_mode = 'fixed source'
36+
37+
# Create a point source
38+
my_source = openmc.IndependentSource()
39+
my_source.space = openmc.stats.Point((0.25, 0.25, 0.25))
40+
my_source.energy = openmc.stats.delta_function(14e6)
41+
model.settings.source = my_source
42+
43+
# This should work without requiring particles/batches to be set
44+
# convert_to_multigroup handles initialization internally using non-transport mode
45+
model.convert_to_multigroup(
46+
method='material_wise',
47+
groups='CASMO-2',
48+
nparticles=10,
49+
overwrite_mgxs_library=True
50+
)
51+
52+
# Verify the model was converted successfully
53+
assert model.settings.energy_mode == 'multi-group'

0 commit comments

Comments
 (0)