|
| 1 | +import openmc |
| 2 | +import numpy as np |
| 3 | +import pytest |
| 4 | + |
| 5 | +@pytest.fixture |
| 6 | +def one_group_lib(): |
| 7 | + groups = openmc.mgxs.EnergyGroups([0.0, 20.0e6]) |
| 8 | + xsdata = openmc.XSdata('slab_mat', groups) |
| 9 | + xsdata.order = 0 |
| 10 | + xsdata.set_total([0.0]) |
| 11 | + xsdata.set_absorption([0.0]) |
| 12 | + xsdata.set_scatter_matrix([[[0.0]]]) |
| 13 | + |
| 14 | + mg_library = openmc.MGXSLibrary(groups) |
| 15 | + mg_library.add_xsdata(xsdata) |
| 16 | + name = 'mgxs.h5' |
| 17 | + mg_library.export_to_hdf5(name) |
| 18 | + yield name |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def slab_model(one_group_lib): |
| 22 | + model = openmc.Model() |
| 23 | + mat = openmc.Material(name='slab_material') |
| 24 | + mat.set_density('macro', 1.0) |
| 25 | + mat.add_macroscopic('slab_mat') |
| 26 | + |
| 27 | + model.materials = openmc.Materials([mat]) |
| 28 | + model.materials.cross_sections = one_group_lib |
| 29 | + |
| 30 | + x_min = openmc.XPlane(x0=0.0, boundary_type='vacuum') |
| 31 | + x_max = openmc.XPlane(x0=10.0, boundary_type='vacuum') |
| 32 | + |
| 33 | + y_min = openmc.YPlane(y0=-10.0, boundary_type='vacuum') |
| 34 | + y_max = openmc.YPlane(y0=10.0, boundary_type='vacuum') |
| 35 | + z_min = openmc.ZPlane(z0=-10.0, boundary_type='vacuum') |
| 36 | + z_max = openmc.ZPlane(z0=19.0, boundary_type='vacuum') |
| 37 | + |
| 38 | + cell = openmc.Cell(fill=mat, region=+z_min & -x_max & +y_min & -y_max & +z_min & -z_max) |
| 39 | + model.geometry = openmc.Geometry([cell]) |
| 40 | + |
| 41 | + model.settings = openmc.Settings() |
| 42 | + model.settings.energy_mode = 'multi-group' |
| 43 | + model.settings.run_mode = 'fixed source' |
| 44 | + model.settings.batches = 3 |
| 45 | + model.settings.particles = 10 |
| 46 | + |
| 47 | + source = openmc.IndependentSource() |
| 48 | + source.space = openmc.stats.Point((5.0, 0.0, 0.0)) |
| 49 | + model.settings.source = source |
| 50 | + return model |
| 51 | + |
| 52 | +def test_inverse_velocity(run_in_tmpdir, slab_model): |
| 53 | + tally = openmc.Tally() |
| 54 | + tally.scores = ['flux','inverse-velocity'] |
| 55 | + slab_model.tallies = [tally] |
| 56 | + slab_model.run(apply_tally_results=True) |
| 57 | + inverse_velocity = tally.mean.squeeze()[1]/tally.mean.squeeze()[0] |
| 58 | + |
| 59 | + assert inverse_velocity == pytest.approx(1.6144e-5, rel=1e-4) |
0 commit comments