Skip to content

Commit 3665090

Browse files
authored
Do not apply boundary conditions when initialized in volume calculation mode (#3562)
1 parent 5918564 commit 3665090

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/particle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ void Particle::cross_surface(const Surface& surf)
544544
#endif
545545

546546
// Handle any applicable boundary conditions.
547-
if (surf.bc_ && settings::run_mode != RunMode::PLOTTING) {
547+
if (surf.bc_ && settings::run_mode != RunMode::PLOTTING &&
548+
settings::run_mode != RunMode::VOLUME) {
548549
surf.bc_->handle_particle(*this, surf);
549550
return;
550551
}

tests/unit_tests/test_mesh.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,33 @@ def test_mesh_material_volumes_serialize():
620620
assert new_volumes.by_element(3) == [(2, 1.0)]
621621

622622

623+
def test_mesh_material_volumes_boundary_conditions(sphere_model):
624+
"""Test the material volumes method using a regular mesh
625+
that overlaps with a vacuum boundary condition."""
626+
627+
mesh = openmc.SphericalMesh.from_domain(sphere_model.geometry, dimension=(1, 1, 1))
628+
# extend mesh beyond the outer sphere surface to test rays crossing the boundary condition
629+
mesh.r_grid[-1] += 5.0
630+
631+
# add a new cell to the modelthat occupies the outside of the sphere
632+
sphere_surfaces = list(filter(lambda s: isinstance(s, openmc.Sphere),
633+
sphere_model.geometry.get_all_surfaces().values()))
634+
outer_cell = openmc.Cell(region=+sphere_surfaces[0])
635+
sphere_model.geometry.root_universe.add_cell(outer_cell)
636+
637+
volumes = mesh.material_volumes(sphere_model, (0, 100, 100))
638+
sphere_volume = 4/3*np.pi*25**3
639+
mats = sphere_model.materials
640+
expected_volumes = [(mats[0].id, 0.25*sphere_volume),
641+
(mats[1].id, 0.25*sphere_volume),
642+
(mats[2].id, 0.5*sphere_volume),
643+
(None, 4/3*np.pi*mesh.r_grid[-1]**3 - sphere_volume)]
644+
645+
for evaluated, expected in zip(volumes.by_element(0), expected_volumes):
646+
assert evaluated[0] == expected[0]
647+
assert evaluated[1] == pytest.approx(expected[1], rel=1e-2)
648+
649+
623650
def test_raytrace_mesh_infinite_loop(run_in_tmpdir):
624651
# Create a model with one large spherical cell
625652
sphere = openmc.Sphere(r=100, boundary_type='vacuum')

0 commit comments

Comments
 (0)