def photon_sampling_setup(mesh, phtn_src, tags): """This function reads in an ALARA photon source file and creates and tags photon source densities onto a Mesh object for the second R2S transport step. Parameters ---------- mesh : PyNE Mesh The object containing the iMesh instance to be tagged. phtn_src : str The path of the ALARA phtn_file. tags: dict A dictionary were the keys are tuples with two values. The first is a string denoting an nuclide in any form that is understood by pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all nuclides. The second is a string denoting the decay time as it appears in the phtn_src file (e.g. 'shutdown', '1 h' '3 d'). The values of the dictionary are the requested tag names for the combination of nuclide and decay time. These tag names should be the tag names that are read by the sampling subroutine. For example: tags = {('U-235', 'shutdown'): 'tag1', ('TOTAL', '1 h'): 'tag2'} """ photon_source_to_hdf5(phtn_src) h5_file = phtn_src + ".h5" photon_source_hdf5_to_mesh(mesh, h5_file, tags)
def test_photon_source_hdf5_to_mesh(): """Tests the function photon source_h5_to_mesh.""" if not HAVE_PYTAPS: raise SkipTest filename = os.path.join(thisdir, "files_test_alara", "phtn_src") photon_source_to_hdf5(filename, chunkshape=(10, )) assert_true(os.path.exists(filename + '.h5')) mesh = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 2], [0, 1]]) tags = {('1001', 'shutdown'): 'tag1', ('TOTAL', '1 h'): 'tag2'} photon_source_hdf5_to_mesh(mesh, filename + '.h5', tags) # create lists of lists of expected results tag1_answers = [[1] + [0] * 41, [2] + [0] * 41, [3] + [0] * 41, [4] + [0] * 41] tag2_answers = [[5] + [0] * 41, [6] + [0] * 41, [7] + [0] * 41, [8] + [0] * 41] ves = list(mesh.structured_iterate_hex("xyz")) for i, ve in enumerate(ves): assert_array_equal(mesh.mesh.getTagHandle("tag1")[ve], tag1_answers[i]) assert_array_equal(mesh.mesh.getTagHandle("tag2")[ve], tag2_answers[i]) if os.path.isfile(filename + '.h5'): os.remove(filename + '.h5')
def photon_sampling_setup(mesh, phtn_src, tags): """This function reads in an ALARA photon source file and creates and tags photon source densities onto a Mesh object for the second R2S transport step. Parameters ---------- mesh : PyNE Mesh The object containing the mesh instance to be tagged. phtn_src : str The path of the ALARA phtn_file. tags: dict A dictionary were the keys are tuples with two values. The first is a string denoting an nuclide in any form that is understood by pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all nuclides. The second is a string denoting the decay time as it appears in the phtn_src file (e.g. 'shutdown', '1 h' '3 d'). The values of the dictionary are the requested tag names for the combination of nuclide and decay time. These tag names should be the tag names that are read by the sampling subroutine. For example: tags = {('U-235', 'shutdown'): 'tag1', ('TOTAL', '1 h'): 'tag2'} """ photon_source_to_hdf5(phtn_src) h5_file = phtn_src + ".h5" photon_source_hdf5_to_mesh(mesh, h5_file, tags)
def test_photon_source_hdf5_to_mesh(): """Tests the function photon source_h5_to_mesh.""" if not HAVE_PYTAPS: raise SkipTest filename = os.path.join(thisdir, "files_test_alara", "phtn_src") photon_source_to_hdf5(filename, chunkshape=(10,)) assert_true(os.path.exists(filename + ".h5")) mesh = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 2], [0, 1]]) tags = {("1001", "shutdown"): "tag1", ("TOTAL", "1 h"): "tag2"} photon_source_hdf5_to_mesh(mesh, filename + ".h5", tags) # create lists of lists of expected results tag1_answers = [[1] + [0] * 41, [2] + [0] * 41, [3] + [0] * 41, [4] + [0] * 41] tag2_answers = [[5] + [0] * 41, [6] + [0] * 41, [7] + [0] * 41, [8] + [0] * 41] ves = list(mesh.structured_iterate_hex("xyz")) for i, ve in enumerate(ves): assert_array_equal(mesh.mesh.getTagHandle("tag1")[ve], tag1_answers[i]) assert_array_equal(mesh.mesh.getTagHandle("tag2")[ve], tag2_answers[i]) if os.path.isfile(filename + ".h5"): os.remove(filename + ".h5")
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean("general", "structured") sub_voxel = config.getboolean("general", "sub_voxel") decay_times = config.get("step2", "decay_times").split(",") output = config.get("step2", "output") tot_phtn_src_intensities = config.get("step2", "tot_phtn_src_intensities") tag_name = "source_density" if sub_voxel: geom = config.get("step1", "geom") load(geom) cell_mats = cell_materials(geom) else: cell_mats = None h5_file = "phtn_src.h5" if not isfile(h5_file): photon_source_to_hdf5(filename="phtn_src", nucs="total") intensities = "Total photon source intensities (p/s)\n" e_bounds = phtn_src_energy_bounds("alara_inp") for i in range(len(e_bounds)): e_bounds[i] /= 1.0e6 # convert unit from eV to MeV for i, dt in enumerate(decay_times): print("Writing source for decay time: {0} to mesh".format(dt)) mesh = Mesh(structured=structured, mesh="blank_mesh.h5m") tags = {("TOTAL", dt): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel, cell_mats=cell_mats) p_src_filename = "{0}_{1}.h5m".format(output, i + 1) intensity = total_photon_source_intensity(mesh, tag_name, sub_voxel=sub_voxel) mesh = tag_e_bounds(mesh, e_bounds) mesh = tag_source_intensity(mesh, intensity) # get and tag decay time decay_time = to_sec(float(dt.split()[0]), dt.split()[1]) mesh = tag_decay_time(mesh, decay_time) # set version manually when changing the information of source.h5m mesh = tag_version(mesh) mesh.write_hdf5("{0}_{1}.h5m".format(output, i + 1)) intensities += "{0}: {1}\n".format(dt, intensity) with open(tot_phtn_src_intensities, "w") as f: f.write(intensities) print("R2S step2 complete.")
def test_photon_source_hdf5_to_mesh_subvoxel(): """Tests the function photon source_h5_to_mesh under sub-voxel r2s condition.""" if not HAVE_PYMOAB: raise SkipTest filename = os.path.join(thisdir, "files_test_alara", "phtn_src") photon_source_to_hdf5(filename, chunkshape=(10, )) assert_true(os.path.exists(filename + '.h5')) sub_voxel = True mesh = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 2], [0, 1]]) cell_fracs = np.zeros(6, dtype=[('idx', np.int64), ('cell', np.int64), ('vol_frac', np.float64), ('rel_error', np.float64)]) cell_fracs[:] = [(0, 11, 1.0, 0.0), (1, 11, 0.5, 0.0), (1, 12, 0.5, 0.0), (2, 11, 0.5, 0.0), (2, 13, 0.5, 0.0), (3, 13, 1.0, 0.0)] cell_mats = { 11: Material({'H': 1.0}, density=1.0), 12: Material({'He': 1.0}, density=1.0), 13: Material({}, density=0.0, metadata={'name': 'void'}) } mesh.tag_cell_fracs(cell_fracs) tags = {('1001', 'shutdown'): 'tag1', ('TOTAL', '1 h'): 'tag2'} photon_source_hdf5_to_mesh(mesh, filename + '.h5', tags, sub_voxel=sub_voxel, cell_mats=cell_mats) # create lists of lists of expected results tag1_answers = [[1.0] + [0.0] * 41 + [0.0] * 42, [2.0] + [0.0] * 41 + [3.0] + [0.0] * 41, [4.0] + [0.0] * 41 + [0.0] * 42, [0.0] * 42 * 2] tag2_answers = [[5.0] + [0.0] * 41 + [0.0] * 42, [6.0] + [0.0] * 41 + [7.0] + [0.0] * 41, [8.0] + [0.0] * 41 + [0.0] * 42, [0.0] * 42 * 2] for i, _, ve in mesh: assert_array_equal(mesh.tag1[ve], tag1_answers[i]) assert_array_equal(mesh.tag2[ve], tag2_answers[i]) if os.path.isfile(filename + '.h5'): os.remove(filename + '.h5')
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') sub_voxel = config.getboolean('general', 'sub_voxel') decay_times = config.get('step2', 'decay_times').split(',') output = config.get('step2', 'output') tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities') tag_name = "source_density" if sub_voxel: geom = config.get('step1', 'geom') load(geom) cell_mats = cell_materials(geom) else: cell_mats = None h5_file = 'phtn_src.h5' if not isfile(h5_file): photon_source_to_hdf5('phtn_src') intensities = "Total photon source intensities (p/s)\n" for i, dc in enumerate(decay_times): print('Writing source for decay time: {0}'.format(dc)) mesh = Mesh(structured=structured, mesh='blank_mesh.h5m') tags = {('TOTAL', dc): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel, cell_mats=cell_mats) mesh.write_hdf5('{0}_{1}.h5m'.format(output, i + 1)) intensity = total_photon_source_intensity(mesh, tag_name, sub_voxel=sub_voxel) intensities += "{0}: {1}\n".format(dc, intensity) with open(tot_phtn_src_intensities, 'w') as f: f.write(intensities) e_bounds = phtn_src_energy_bounds("alara_inp") e_bounds_str = "" for e in e_bounds: e = e / 1e6 # convert unit to MeV e_bounds_str += "{0}\n".format(e) with open("e_bounds", 'w') as f: f.write(e_bounds_str) print('R2S step2 complete.')
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') sub_voxel = config.getboolean('general', 'sub_voxel') decay_times = config.get('step2', 'decay_times').split(',') output = config.get('step2', 'output') tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities') tag_name = "source_density" if sub_voxel: geom = config.get('step1', 'geom') load(geom) cell_mats = cell_materials(geom) else: cell_mats = None h5_file = 'phtn_src.h5' if not isfile(h5_file): photon_source_to_hdf5(filename='phtn_src', nucs='total') intensities = "Total photon source intensities (p/s)\n" e_bounds = phtn_src_energy_bounds("alara_inp") for i in range(len(e_bounds)): e_bounds[i] /= 1.0e6 # convert unit from eV to MeV for i, dt in enumerate(decay_times): print('Writing source for decay time: {0} to mesh'.format(dt)) mesh = Mesh(structured=structured, mesh='blank_mesh.h5m') tags = {('TOTAL', dt): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel, cell_mats=cell_mats) intensity = total_photon_source_intensity(mesh, tag_name, sub_voxel=sub_voxel) mesh = tag_e_bounds(mesh, e_bounds) mesh = tag_source_intensity(mesh, intensity) # get and tag decay time decay_time = to_sec(float(dt.split()[0]), dt.split()[1]) mesh = tag_decay_time(mesh, decay_time) # set version manually when changing the information of source.h5m mesh = tag_version(mesh) mesh.write_hdf5('{0}_{1}.h5m'.format(output, i+1)) intensities += "{0}: {1}\n".format(dt, intensity) with open(tot_phtn_src_intensities, 'w') as f: f.write(intensities) print('R2S step2 complete.')
def test_photon_source_hdf5_to_mesh_subvoxel_size1(): """Tests the function photon source_h5_to_mesh under sub-voxel r2s condition.""" if not HAVE_PYMOAB: raise SkipTest filename = os.path.join(thisdir, "files_test_alara", "phtn_src") photon_source_to_hdf5(filename, chunkshape=(10, )) assert_true(os.path.exists(filename + ".h5")) sub_voxel = True mesh = Mesh(structured=True, structured_coords=[[0, 1, 2], [0, 1, 2], [0, 1]]) cell_fracs = np.zeros( 4, dtype=[ ("idx", np.int64), ("cell", np.int64), ("vol_frac", np.float64), ("rel_error", np.float64), ], ) cell_fracs[:] = [ (0, 11, 1.0, 0.0), (1, 12, 1.0, 0.0), (2, 13, 1.0, 0.0), (3, 14, 1.0, 0.0), ] cell_mats = { 11: Material({"H": 1.0}, density=1.0), 12: Material({"He": 1.0}, density=1.0), 13: Material({"He": 1.0}, density=1.0), 14: Material({}, density=0.0, metadata={"name": "void"}), } mesh.tag_cell_fracs(cell_fracs) tags = {("1001", "shutdown"): "tag1", ("TOTAL", "1 h"): "tag2"} photon_source_hdf5_to_mesh(mesh, filename + ".h5", tags, sub_voxel=sub_voxel, cell_mats=cell_mats) # create lists of lists of expected results tag1_answers = [ [1.0] + [0.0] * 41, [2.0] + [0.0] * 41, [3.0] + [0.0] * 41, [0.0] * 42, ] tag2_answers = [ [5.0] + [0.0] * 41, [6.0] + [0.0] * 41, [7.0] + [0.0] * 41, [0.0] * 42, ] for i, _, ve in mesh: assert_array_equal(mesh.tag1[ve], tag1_answers[i]) assert_array_equal(mesh.tag2[ve], tag2_answers[i]) if os.path.isfile(filename + ".h5"): os.remove(filename + ".h5")