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 # Make a version of mat-1 which has a tabular representation of the 38 # scattering vice Legendre with 33 points 39 mat_2 = mat_1.convert_scatter_format('tabular', 33) 40 mat_2.name = 'mat_2' 41 mg_cross_sections_file.add_xsdata(mat_2) 42 43 # Make a version of mat-1 which has a histogram representation of the 44 # scattering vice Legendre with 33 bins 45 mat_3 = mat_1.convert_scatter_format('histogram', 33) 46 mat_3.name = 'mat_3' 47 mg_cross_sections_file.add_xsdata(mat_3) 48 49 # Make a version which uses a fission matrix vice chi & nu-fission 50 mat_4 = openmc.XSdata('mat_4', groups) 51 mat_4.order = 1 52 mat_4.set_nu_fission(np.outer(np.multiply(nu, fiss), chi)) 53 mat_4.set_absorption(absorption) 54 mat_4.set_scatter_matrix(scatter) 55 mat_4.set_total(total) 56 mg_cross_sections_file.add_xsdata(mat_4) 57 58 # Make an angle-dependent version of mat_1 with 2 polar and 2 azim. angles 59 mat_5 = mat_1.convert_representation('angle', 2, 2) 60 mat_5.name = 'mat_5' 61 mg_cross_sections_file.add_xsdata(mat_5) 62 63 # Make a copy of mat_1 for testing microscopic cross sections 64 mat_6 = openmc.XSdata('mat_6', groups) 65 mat_6.order = 1 66 mat_6.set_nu_fission(np.multiply(nu, fiss)) 67 mat_6.set_absorption(absorption) 68 mat_6.set_scatter_matrix(scatter) 69 mat_6.set_total(total) 70 mat_6.set_chi(chi) 71 mg_cross_sections_file.add_xsdata(mat_6) 72 73 # Write the file 74 mg_cross_sections_file.export_to_hdf5('2g.h5') 75 76 77class MGXSTestHarness(PyAPITestHarness): 78 def _cleanup(self): 79 super()._cleanup() 80 f = '2g.h5' 81 if os.path.exists(f): 82 os.remove(f) 83 84 85def test_mg_basic(): 86 create_library() 87 mat_names = ['base leg', 'base tab', 'base hist', 'base matrix', 88 'base ang', 'micro'] 89 model = slab_mg(num_regions=6, mat_names=mat_names) 90 # Modify the last material to be a microscopic combination of nuclides 91 model.materials[-1] = openmc.Material(name='micro', material_id=6) 92 model.materials[-1].set_density("sum") 93 model.materials[-1].add_nuclide("mat_1", 0.5) 94 model.materials[-1].add_nuclide("mat_6", 0.5) 95 96 harness = PyAPITestHarness('statepoint.10.h5', model) 97 harness.main() 98