@@ -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+
623650def 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