1import os
2
3import numpy as np
4
5import openmc
6from openmc.examples import slab_mg
7
8from tests.testing_harness import PyAPITestHarness
9
10
11def create_library():
12    # Instantiate the energy group data and file object
13    groups = openmc.mgxs.EnergyGroups(group_edges=[0.0, 0.625, 20.0e6])
14
15    mg_cross_sections_file = openmc.MGXSLibrary(groups)
16
17    # Make the base, isotropic data
18    nu = [2.50, 2.50]
19    fiss = np.array([0.002817, 0.097])
20    capture = [0.008708, 0.02518]
21    absorption = np.add(capture, fiss)
22    scatter = np.array(
23        [[[0.31980, 0.06694], [0.004555, -0.0003972]],
24         [[0.00000, 0.00000], [0.424100, 0.05439000]]])
25    total = [0.33588, 0.54628]
26    chi = [1., 0.]
27
28    mat_1 = openmc.XSdata('mat_1', groups)
29    mat_1.order = 1
30    mat_1.set_nu_fission(np.multiply(nu, fiss))
31    mat_1.set_absorption(absorption)
32    mat_1.set_scatter_matrix(scatter)
33    mat_1.set_total(total)
34    mat_1.set_chi(chi)
35    mg_cross_sections_file.add_xsdata(mat_1)
36
37    # Write the file
38    mg_cross_sections_file.export_to_hdf5('2g.h5')
39
40
41class MGXSTestHarness(PyAPITestHarness):
42    def _cleanup(self):
43        super()._cleanup()
44        f = '2g.h5'
45        if os.path.exists(f):
46            os.remove(f)
47
48
49def test_mg_survival_biasing():
50    create_library()
51    model = slab_mg()
52    model.settings.survival_biasing = True
53
54    harness = PyAPITestHarness('statepoint.10.h5', model)
55    harness.main()
56