Add test for openmc.lib.sample_external_source

This commit is contained in:
Paul Romano 2022-07-15 19:57:58 -05:00
parent b1267f0544
commit ba5f6f58fa

View file

@ -807,3 +807,44 @@ def test_cell_rotation(pincell_model_w_univ, mpi_intracomm):
cell.rotation = (180., 0., 0.)
assert cell.rotation == pytest.approx([180., 0., 0.])
openmc.lib.finalize()
def test_sample_external_source(run_in_tmpdir, mpi_intracomm):
# Define a simple model and export
mat = openmc.Material()
mat.add_nuclide('U235', 1.0e-2)
sph = openmc.Sphere(r=100.0, boundary_type='vacuum')
cell = openmc.Cell(fill=mat, region=-sph)
model = openmc.Model()
model.geometry = openmc.Geometry([cell])
model.settings.source = openmc.Source(
space=openmc.stats.Box([-5., -5., -5.], [5., 5., 5.]),
angle=openmc.stats.Monodirectional((0., 0., 1.)),
energy=openmc.stats.Discrete([1.0e5], [1.0])
)
model.settings.particles = 1000
model.settings.batches = 10
model.export_to_xml()
# Sample some particles and make sure they match specified source
openmc.lib.init()
particles = openmc.lib.sample_external_source(10, prn_seed=3)
for p in particles:
assert -5. < p.r[0] < 5.
assert -5. < p.r[1] < 5.
assert -5. < p.r[2] < 5.
assert p.u[0] == 0.0
assert p.u[1] == 0.0
assert p.u[2] == 1.0
assert p.E == 1.0e5
# Using the same seed should produce the same particles
other_particles = openmc.lib.sample_external_source(10, prn_seed=3)
for p1, p2 in zip(particles, other_particles):
assert p1.r == p2.r
assert p1.u == p2.u
assert p1.E == p2.E
assert p1.time == p2.time
assert p1.wgt == p2.wgt
openmc.lib.finalize()