def irradiation_setup_unstructured(flux_tag="n_flux"): meshtal_filename = "meshtal_2x2x1" meshtal_file = os.path.join(thisdir, "files_test_r2s", meshtal_filename) meshtal = Meshtal( meshtal_file, { 4: (flux_tag, flux_tag + "_err", flux_tag + "_total", flux_tag + "_err_total") }) # Explicitly make this mesh unstructured, it will now iterate in yxz # order which is MOAB structured mesh creation order. meshtal = Mesh(structured=False, mesh=meshtal.tally[4].mesh) meshtal_mesh_file = os.path.join(thisdir, "meshtal.h5m") meshtal.write_hdf5(meshtal_mesh_file, write_mats=False) if flux_tag != "n_flux": # if not using n_flux makes a mesh containing n_flux tag, and then # makes a new tag called flux_tag, to use later in the test flux_tag_name = "n_flux" meshtal = Meshtal( meshtal_file, { 4: (flux_tag_name, flux_tag_name + "_err", flux_tag_name + "_total", flux_tag_name + "_err_total") }) # Explicitly make this mesh unstructured, it will now iterate in yxz # order which is MOAB structured mesh creation order. meshtal = Mesh(structured=False, mesh=meshtal.tally[4].mesh) meshtal_mesh_file = os.path.join(thisdir, "meshtal.h5m") meshtal.write_hdf5(meshtal_mesh_file, write_mats=False) new_mesh = Mesh(structured=False, mesh=meshtal_mesh_file) new_mesh.TALLY_TAG = NativeMeshTag(2, float) # 2 egroups new_mesh.TALLY_TAG = meshtal.n_flux[:] # overwrite the mesh file new_mesh.write_hdf5(meshtal_mesh_file, write_mats=False) cell_mats = { 2: Material({2004: 1.0}, density=1.0, metadata={'name': 'mat_11'}), 3: Material({ 3007: 0.4, 3006: 0.6 }, density=2.0, metadata={'name': 'mat_12'}) } alara_params = "Bogus line for testing\n" geom = os.path.join(thisdir, "unitbox.h5m") fluxin = os.path.join(os.getcwd(), "alara_fluxin") reverse = True alara_inp = os.path.join(os.getcwd(), "alara_inp") alara_matlib = os.path.join(os.getcwd(), "alara_matlib") output_mesh = os.path.join(os.getcwd(), "r2s_step1.h5m") output_material = True cell_fracs = np.zeros(4, dtype=[('idx', np.int64), ('cell', np.int64), ('vol_frac', np.float64), ('rel_error', np.float64)]) cell_fracs[:] = [(0, 3, 1.0, 1.0), (1, 3, 1.0, 1.0), (2, 3, 1.0, 1.0), (3, 3, 1.0, 1.0)] irradiation_setup(flux_mesh=meshtal_mesh_file, cell_mats=cell_mats, cell_fracs=cell_fracs, alara_params=alara_params, flux_tag=flux_tag, fluxin=fluxin, reverse=reverse, alara_inp=alara_inp, alara_matlib=alara_matlib, output_mesh=output_mesh, output_material=output_material) # expected output files exp_alara_inp = os.path.join(thisdir, "files_test_r2s", "exp_alara_inp_un") exp_alara_matlib = os.path.join(thisdir, "files_test_r2s", "exp_alara_matlib") exp_fluxin = os.path.join(thisdir, "files_test_r2s", "exp_fluxin_un") # test files f1 = filecmp.cmp(alara_inp, exp_alara_inp) f2 = filecmp.cmp(alara_matlib, exp_alara_matlib) f3 = filecmp.cmp(fluxin, exp_fluxin) m = Mesh(structured=True, mesh=output_mesh, mats=output_mesh) m_out = [ m.n_flux[:].tolist(), m.n_flux_err[:].tolist(), m.n_flux_total[:].tolist(), m.n_flux_err_total[:].tolist(), [x.comp.items() for y, x, z in m], [x.density for y, x, z in m] ] os.remove(meshtal_mesh_file) os.remove(alara_inp) os.remove(alara_matlib) os.remove(fluxin) os.remove(output_mesh) return [m_out, f1, f2, f3]
def irradiation_setup_unstructured(flux_tag="n_flux"): meshtal_filename = "meshtal_2x2x1" meshtal_file = os.path.join(thisdir, "files_test_r2s", meshtal_filename) meshtal = Meshtal( meshtal_file, { 4: (flux_tag, flux_tag + "_err", flux_tag + "_total", flux_tag + "_err_total") }) # Explicitly make this mesh unstructured, it will now iterate in yxz # order which is MOAB structured mesh creation order. meshtal = Mesh(structured=False, mesh=meshtal.tally[4].mesh) meshtal_mesh_file = os.path.join(thisdir, "meshtal.h5m") meshtal.write_hdf5(meshtal_mesh_file, write_mats=False) if flux_tag != "n_flux": # if not using n_flux makes a mesh containing n_flux tag, and then # makes a new tag called flux_tag, to use later in the test flux_tag_name = "n_flux" meshtal = Meshtal( meshtal_file, { 4: (flux_tag_name, flux_tag_name + "_err", flux_tag_name + "_total", flux_tag_name + "_err_total") }) # Explicitly make this mesh unstructured, it will now iterate in yxz # order which is MOAB structured mesh creation order. meshtal = Mesh(structured=False, mesh=meshtal.tally[4].mesh) meshtal_mesh_file = os.path.join(thisdir, "meshtal.h5m") meshtal.write_hdf5(meshtal_mesh_file, write_mats=False) new_mesh = Mesh(structured=False, mesh=meshtal_mesh_file) new_mesh.TALLY_TAG = NativeMeshTag(2, float) # 2 egroups new_mesh.TALLY_TAG = meshtal.n_flux[:] # overwrite the mesh file new_mesh.write_hdf5(meshtal_mesh_file, write_mats=False) cell_mats = { 2: Material({2004: 1.0}, density=1.0, metadata={'name': 'mat_11'}), 3: Material({ 3007: 0.4, 3006: 0.6 }, density=2.0, metadata={'name': 'mat_12'}) } alara_params = "Bogus line for testing\n" geom = os.path.join(thisdir, "unitbox.h5m") fluxin = os.path.join(os.getcwd(), "alara_fluxin") reverse = True alara_inp = os.path.join(os.getcwd(), "alara_inp") alara_matlib = os.path.join(os.getcwd(), "alara_matlib") output_mesh = os.path.join(os.getcwd(), "r2s_step1.h5m") output_material = True cell_fracs = np.zeros(4, dtype=[('idx', np.int64), ('cell', np.int64), ('vol_frac', np.float64), ('rel_error', np.float64)]) cell_fracs[:] = [(0, 3, 1.0, 1.0), (1, 3, 1.0, 1.0), (2, 3, 1.0, 1.0), (3, 3, 1.0, 1.0)] irradiation_setup(flux_mesh=meshtal_mesh_file, cell_mats=cell_mats, cell_fracs=cell_fracs, alara_params=alara_params, flux_tag=flux_tag, fluxin=fluxin, reverse=reverse, alara_inp=alara_inp, alara_matlib=alara_matlib, output_mesh=output_mesh, output_material=output_material) # expected output files exp_alara_inp = os.path.join(thisdir, "files_test_r2s", "exp_alara_inp_un") exp_alara_matlib = os.path.join(thisdir, "files_test_r2s", "exp_alara_matlib") exp_fluxin = os.path.join(thisdir, "files_test_r2s", "exp_fluxin_un") # test files f1 = filecmp.cmp(alara_inp, exp_alara_inp) f2 = filecmp.cmp(alara_matlib, exp_alara_matlib) f3 = filecmp.cmp(fluxin, exp_fluxin) m = Mesh(structured=True, mesh=output_mesh, mats=output_mesh) out = [ m.n_flux[:].tolist(), m.n_flux_err[:].tolist(), m.n_flux_total[:].tolist(), m.n_flux_err_total[:].tolist(), [x.comp.items() for y, x, z in m], [x.density for y, x, z in m] ] n_flux = out[0] n_flux_err = out[1] n_flux_total = out[2] n_flux_err_total = out[3] densities = out[5] comps = np.zeros(shape=(len(out[4])), dtype=dict) for i, comp in enumerate(out[4]): comps[i] = {} for nucid in comp: comps[i][nucid[0]] = nucid[1] # test r2s step 1 output mesh fluxes = [[6.93088E-07, 1.04838E-06], [6.36368E-07, 9.78475E-07], [5.16309E-07, 9.86586E-07], [6.36887E-07, 9.29879E-07]] errs = [[9.67452E-02, 7.55950E-02], [9.88806E-02, 7.61482E-02], [1.04090E-01, 7.69284E-02], [9.75826E-02, 7.54181E-02]] tot_fluxes = [1.74147E-06, 1.61484E-06, 1.50290E-06, 1.56677E-06] tot_errs = [6.01522E-02, 6.13336E-02, 6.19920E-02, 5.98742E-02] i = 0 for nf, nfe, nft, nfte, comp, density in izip(n_flux, n_flux_err, n_flux_total, n_flux_err_total, comps, densities): assert_almost_equal(density, 2.0) assert_equal(len(comp), 2) assert_almost_equal(comp[30060000], 0.6) assert_almost_equal(comp[30070000], 0.4) assert_array_equal(nf, fluxes[i]) assert_array_equal(nfe, errs[i]) assert_almost_equal(nft, tot_fluxes[i]) assert_almost_equal(nfte, tot_errs[i]) i += 1 os.remove(meshtal_mesh_file) os.remove(alara_inp) os.remove(alara_matlib) os.remove(fluxin) os.remove(output_mesh) return [f1, f2, f3]