Skip to content

Commit ffd78f4

Browse files
gridleypshriwise
authored andcommitted
Merge pull request openmc-dev#1809 from pshriwise/rotation_fix
Fix segfault from unreset particle coordinates in `neighbor_list_find_cell`
2 parents 763817d + de8fb35 commit ffd78f4

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

src/geometry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list)
247247

248248
bool neighbor_list_find_cell(Particle& p)
249249
{
250+
251+
// Reset all the deeper coordinate levels.
252+
for (int i = p.n_coord_; i < p.coord_.size(); i++) {
253+
p.coord_[i].reset();
254+
}
255+
250256
// Get the cell this particle was in previously.
251257
auto coord_lvl = p.n_coord_ - 1;
252258
auto i_cell = p.coord_[coord_lvl].cell;

tests/regression_tests/adj_cell_rotation/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<geometry>
3+
<cell id="1" material="1" region="-1" universe="1" />
4+
<cell id="2" material="2" region="1" universe="1" />
5+
<cell fill="1" id="3" region="2 -3 4 -5 6 -8" rotation="10 20 30" universe="2" />
6+
<cell fill="1" id="4" region="2 -3 4 -5 8 -7" translation="0 0 15" universe="2" />
7+
<surface coeffs="1.0 0.0 0.0 5.0" id="1" type="sphere" />
8+
<surface boundary="vacuum" coeffs="-7.5" id="2" name="minimum x" type="x-plane" />
9+
<surface boundary="vacuum" coeffs="7.5" id="3" name="maximum x" type="x-plane" />
10+
<surface boundary="vacuum" coeffs="-7.5" id="4" name="minimum y" type="y-plane" />
11+
<surface boundary="vacuum" coeffs="7.5" id="5" name="maximum y" type="y-plane" />
12+
<surface boundary="vacuum" coeffs="-7.5" id="6" type="z-plane" />
13+
<surface boundary="vacuum" coeffs="22.5" id="7" type="z-plane" />
14+
<surface coeffs="7.5" id="8" type="z-plane" />
15+
</geometry>
16+
<?xml version='1.0' encoding='utf-8'?>
17+
<materials>
18+
<material depletable="true" id="1">
19+
<density units="g/cc" value="10.0" />
20+
<nuclide ao="1.0" name="U235" />
21+
</material>
22+
<material id="2">
23+
<density units="g/cc" value="0.1" />
24+
<nuclide ao="0.1" name="H1" />
25+
</material>
26+
</materials>
27+
<?xml version='1.0' encoding='utf-8'?>
28+
<settings>
29+
<run_mode>eigenvalue</run_mode>
30+
<particles>10000</particles>
31+
<batches>10</batches>
32+
<inactive>5</inactive>
33+
<source strength="1.0">
34+
<space type="box">
35+
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
36+
</space>
37+
</source>
38+
</settings>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
k-combined:
2+
4.453328E-01 5.918369E-03
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
import openmc
3+
4+
from tests.testing_harness import PyAPITestHarness
5+
6+
7+
@pytest.fixture
8+
def model():
9+
model = openmc.model.Model()
10+
11+
fuel = openmc.Material()
12+
fuel.set_density('g/cc', 10.0)
13+
fuel.add_nuclide('U235', 1.0)
14+
15+
h1 = openmc.Material()
16+
h1.set_density('g/cc', 0.1)
17+
h1.add_nuclide('H1', 0.1)
18+
19+
inner_sphere = openmc.Sphere(x0=1.0, r=5.0)
20+
21+
fuel_cell = openmc.Cell(fill=fuel, region=-inner_sphere)
22+
hydrogen_cell = openmc.Cell(fill=h1, region=+inner_sphere)
23+
univ = openmc.Universe(cells=[fuel_cell, hydrogen_cell])
24+
25+
# Create one cell on top of the other. Only one
26+
# has a rotation
27+
box = openmc.rectangular_prism(15., 15., 'z', boundary_type='vacuum')
28+
lower_z = openmc.ZPlane(-7.5, boundary_type='vacuum')
29+
upper_z = openmc.ZPlane(22.5, boundary_type='vacuum')
30+
middle_z = openmc.ZPlane(7.5)
31+
32+
lower_cell = openmc.Cell(fill=univ, region=box & +lower_z & -middle_z)
33+
lower_cell.rotation = (10, 20, 30)
34+
upper_cell = openmc.Cell(fill=univ, region=box & +middle_z & -upper_z)
35+
upper_cell.translation = (0, 0, 15)
36+
37+
model.geometry = openmc.Geometry(root=[lower_cell, upper_cell])
38+
39+
model.settings.particles = 10000
40+
model.settings.inactive = 5
41+
model.settings.batches = 10
42+
source_box = openmc.stats.Box((-4., -4., -4.), (4., 4., 4.))
43+
model.settings.source = openmc.Source(space=source_box)
44+
45+
return model
46+
47+
48+
def test_rotation(model):
49+
harness = PyAPITestHarness('statepoint.10.h5', model)
50+
harness.main()

0 commit comments

Comments
 (0)