Skip to content

Commit 66359e5

Browse files
paulromanoGuySten
andauthored
Fix surface tally crash on lattice crossings (#3993)
Co-authored-by: GuySten <guyste@post.bgu.ac.il>
1 parent 97e04c4 commit 66359e5

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/particle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,14 @@ void Particle::event_cross_surface()
338338
boundary().lattice_translation()[2] != 0) {
339339
// Particle crosses lattice boundary
340340

341+
int i_lattice = coord(boundary().coord_level() - 1).lattice();
341342
bool verbose = settings::verbosity >= 10 || trace();
342343
cross_lattice(*this, boundary(), verbose);
343344
event() = TallyEvent::LATTICE;
344345

345346
// Score cell to cell partial currents
346347
if (!model::active_surface_tallies.empty()) {
347-
auto& lat {*model::lattices[lowest_coord().lattice()]};
348+
auto& lat {*model::lattices[i_lattice]};
348349
bool is_valid;
349350
Direction normal =
350351
lat.get_normal(boundary().lattice_translation(), is_valid);

tests/unit_tests/test_surface_flux.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,50 @@ def test_surface_filter_flux_angled(two_cell_model, run_in_tmpdir):
9898
assert flux_mean == pytest.approx(1.0 / mu)
9999

100100

101+
def test_surface_tally_during_lattice_crossing(run_in_tmpdir):
102+
openmc.reset_auto_ids()
103+
model = openmc.Model()
104+
105+
xmin = openmc.XPlane(-1.0, boundary_type="vacuum")
106+
xmax = openmc.XPlane(1.0, boundary_type="vacuum")
107+
ymin = openmc.YPlane(-1.0, boundary_type="vacuum")
108+
ymax = openmc.YPlane(1.0, boundary_type="vacuum")
109+
zmin = openmc.ZPlane(-1.0, boundary_type="vacuum")
110+
zmax = openmc.ZPlane(1.0, boundary_type="vacuum")
111+
112+
inner_cell = openmc.Cell()
113+
inner_univ = openmc.Universe(cells=[inner_cell])
114+
115+
tile_cell = openmc.Cell(fill=inner_univ)
116+
tile_univ = openmc.Universe(cells=[tile_cell])
117+
118+
lattice = openmc.RectLattice()
119+
lattice.lower_left = (-1.0, -1.0)
120+
lattice.pitch = (1.0, 2.0)
121+
lattice.universes = [[tile_univ, tile_univ]]
122+
123+
root_cell = openmc.Cell(
124+
fill=lattice, region=+xmin & -xmax & +ymin & -ymax & +zmin & -zmax)
125+
model.geometry = openmc.Geometry([root_cell])
126+
127+
src = openmc.IndependentSource()
128+
src.space = openmc.stats.Point((-0.5, 0.0, 0.0))
129+
src.angle = openmc.stats.Monodirectional((1.0, 0.0, 0.0))
130+
131+
model.settings.run_mode = 'fixed source'
132+
model.settings.batches = 1
133+
model.settings.particles = 5
134+
model.settings.source = src
135+
136+
current_tally = openmc.Tally()
137+
current_tally.filters = [openmc.SurfaceFilter(xmax)]
138+
current_tally.scores = ['current']
139+
model.tallies = [current_tally]
140+
141+
model.run(apply_tally_results=True)
142+
assert current_tally.mean.flat[0] == pytest.approx(1.0)
143+
144+
101145
def test_cellfrom_filter_flux_directional(two_cell_model, run_in_tmpdir):
102146
"""SurfaceFilter + CellFromFilter + flux scores only the correct direction."""
103147
model, xmid, cell1, cell2 = two_cell_model

0 commit comments

Comments
 (0)