Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent segfault in distance to boundary calculation #2659

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,14 @@ BoundaryInfo distance_to_boundary(Particle& p)
double& d = info.distance;
if (d_surf < d_lat - FP_COINCIDENT) {
if (d == INFINITY || (d - d_surf) / d >= FP_REL_PRECISION) {
// Update closest distance
d = d_surf;

// If the cell is not simple, it is possible that both the negative and
// positive half-space were given in the region specification. Thus, we
// have to explicitly check which half-space the particle would be
// traveling into if the surface is crossed
if (c.is_simple()) {
if (c.is_simple() || d == INFTY) {
info.surface_index = level_surf_cross;
} else {
Position r_hit = r + d_surf * u;
Expand Down
30 changes: 30 additions & 0 deletions tests/unit_tests/test_no_visible_boundary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import openmc


def test_no_visible_boundary(run_in_tmpdir):
copper = openmc.Material()
copper.add_nuclide('Cu63', 1.0)
copper.set_density('g/cm3', 0.3)
air = openmc.Material()
air.add_nuclide('N14', 1.0)
air.set_density('g/cm3', 0.0012)

# Create a simple model of a neutron source directly impinging on a thin
# disc of copper. Neutrons leaving the back of the disc see no surfaces in
# front of them.
disc = openmc.model.RightCircularCylinder((0., 0., 1.), 0.1, 1.2)
box = openmc.rectangular_prism(width=10, height=10, boundary_type='vacuum')
c1 = openmc.Cell(fill=copper, region=-disc)
c2 = openmc.Cell(fill=air, region=+disc & box)
model = openmc.Model()
model.geometry = openmc.Geometry([c1, c2])
model.settings.run_mode = 'fixed source'
model.settings.particles = 1000
model.settings.batches = 5
model.settings.source = openmc.IndependentSource(
space=openmc.stats.Point(),
angle=openmc.stats.Monodirectional((0., 0., 1.))
)

# Run model to ensure it doesn't segfault
model.run()