def boundary(): from pyne import dagmc dagmc.load(path) low, high = dagmc.volume_boundary(2) return [low, high]
def versions(): from pyne import dagmc dagmc.load(path) returned = dagmc.versions() return returned
def ray_iterator(): from pyne import dagmc dagmc.load(path) start = [-2, 0, 0] startvol = dagmc.find_volume(start) assert_equal(startvol, 3) direction = [1, 0, 0] expected_vols = [2, 3, 1, 4] expected_dists = [1, 2, 3.156921938, 0] for i, (vol, dist, surf) in enumerate( dagmc.ray_iterator(startvol, start, direction)): assert_equal(expected_vols[i], vol) if expected_dists[i] != 0: assert_almost_equal(expected_dists[i], dist) assert_equal(i, 3) for i, (vol, dist, surf) in enumerate( dagmc.ray_iterator(startvol, start, direction, dist_limit=4)): assert_equal(expected_vols[i], vol) if expected_dists[i] != 0: assert_almost_equal(expected_dists[i], dist) assert_equal(i, 1)
def failures(): from pyne import dagmc dagmc.load(path) assert_raises(Exception, dagmc.point_in_volume, [100, (0, 0, 0)]) assert_raises(Exception, dagmc.point_in_volume, [1, (0, 0, 0, 0)]) assert_raises(Exception, dagmc.fire_one_ray, [2, (0, 0, 0), 1])
def get_zones_iteration_order(): """Test that _get_zones function gives results in zyx order. """ try: from pyne import dagmc except: raise SkipTest if not HAVE_PYMOAB: raise SkipTest # hdf5 test file THIS_DIR = os.path.dirname(os.path.realpath(__file__)) hdf5 = THIS_DIR + '/files_test_partisn/fractal_box.h5m' data_hdf5path = '/materials' # Load dagmc geometry dagmc.load(hdf5) bounds = [-5., 0., 5.] sc = [bounds] * 3 mesh = Mesh(structured_coords=sc, structured=True) bounds = {'x': bounds, 'y': bounds, 'z': bounds} num_rays = 9 grid = True dg = None mat_assigns = None unique_names = { 'mat:m1': 'M1', 'mat:m2': 'M2', 'mat:m3': 'M3', 'mat:m4': 'M4' } voxel_zones, zones = partisn._get_zones(mesh, hdf5, bounds, num_rays, grid, dg, mat_assigns, unique_names) voxel_zones_expected = np.array([[1, 2], [1, 4], [1, 3], [1, 4]]) zones_expected = { 1: { 'vol_frac': [1.0], 'mat': ['M2'] }, 2: { 'vol_frac': [1.0], 'mat': ['M4'] }, 3: { 'vol_frac': [1.0], 'mat': ['M1'] }, 4: { 'vol_frac': [1.0], 'mat': ['M3'] } } vz_tf = voxel_zones.all() == voxel_zones_expected.all() z_tf = zones == zones_expected return [vz_tf, z_tf]
def ray_iterator(): from pyne import dagmc dagmc.load(path) start = [-2, 0, 0] startvol = dagmc.find_volume(start) direction = [1, 0, 0] expected_vols = [2, 3, 1, 4] expected_dists = [1, 2, 3.156921938, 0] vols1 = [] dists1 = [] surfs1 = [] for i, (vol, dist, surf) in enumerate(dagmc.ray_iterator(startvol, start, direction)): vols1.append(vol) dists1.append(dist) surfs1.append(surf) vols2 = [] dists2 = [] surfs2 = [] for j, (vol, dist, surf) in enumerate( dagmc.ray_iterator(startvol, start, direction, dist_limit=4)): vols2.append(vol) dists2.append(dist) surfs2.append(surf) return [startvol, vols1, dists1, surfs1, i, vols2, dists2, surfs2, j]
def step1(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean("general", "structured") sub_voxel = config.getboolean("general", "sub_voxel") meshtal = config.get("step1", "meshtal") tally_num = config.getint("step1", "tally_num") flux_tag = config.get("step1", "flux_tag") decay_times = config.get("step2", "decay_times").split(",") geom = config.get("step1", "geom") reverse = config.getboolean("step1", "reverse") num_rays = config.getint("step1", "num_rays") grid = config.getboolean("step1", "grid") load(geom) # get meshtal info from meshtal file flux_mesh = resolve_mesh(meshtal, tally_num, flux_tag) # create the cell_fracs array before irradiation_steup if flux_mesh.structured: cell_fracs = discretize_geom(flux_mesh, num_rays=num_rays, grid=grid) # tag cell fracs for both default and subvoxel r2s modes flux_mesh.tag_cell_fracs(cell_fracs) else: cell_fracs = discretize_geom(flux_mesh) cell_mats = cell_materials(geom) irradiation_setup( flux_mesh, cell_mats, cell_fracs, alara_params_filename, tally_num, num_rays=num_rays, grid=grid, reverse=reverse, flux_tag=flux_tag, decay_times=decay_times, sub_voxel=sub_voxel, ) # create a blank mesh for step 2: ves = list(flux_mesh.iter_ve()) tags_keep = ( "cell_number", "cell_fracs", "cell_largest_frac_number", "cell_largest_frac", ) for tag in flux_mesh.get_all_tags(): if tag.name not in tags_keep and isinstance(tag, NativeMeshTag): tag.delete() flux_mesh.write_hdf5("blank_mesh.h5m") print("The file blank_mesh.h5m has been saved to disk.") print("Do not delete this file; it is needed by r2s.py step2.\n") print("R2S step1 complete, run ALARA with the command:") print(">> alara alara_inp > output.txt")
def ray_iterator(): from pyne import dagmc dagmc.load(path) start = [-2, 0, 0] startvol = dagmc.find_volume(start) assert_equal(startvol, 3) direction = [1, 0, 0] expected_vols = [2, 3, 1, 4] expected_dists = [1, 2, 3.156921938, 0] for i, (vol, dist, surf) in enumerate(dagmc.ray_iterator(startvol, start, direction)): assert_equal(expected_vols[i], vol) if expected_dists[i] != 0: assert_almost_equal(expected_dists[i], dist) assert_equal(i, 3) for i, (vol, dist, surf) in enumerate( dagmc.ray_iterator(startvol, start, direction, dist_limit=4)): assert_equal(expected_vols[i], vol) if expected_dists[i] != 0: assert_almost_equal(expected_dists[i], dist) assert_equal(i, 1)
def util_graveyard_bound(): from pyne import dagmc dagmc.load(path) lo, hi = dagmc.find_graveyard_inner_box() return [lo, hi]
def get_zones_iteration_order(): """Test that _get_zones function gives results in zyx order.""" try: from pyne import dagmc except: raise SkipTest if not HAVE_PYMOAB: raise SkipTest # hdf5 test file THIS_DIR = os.path.dirname(os.path.realpath(__file__)) hdf5 = THIS_DIR + "/files_test_partisn/fractal_box.h5m" data_hdf5path = "/materials" # Load dagmc geometry dagmc.load(hdf5) bounds = [-5.0, 0.0, 5.0] sc = [bounds] * 3 mesh = Mesh(structured_coords=sc, structured=True) bounds = {"x": bounds, "y": bounds, "z": bounds} num_rays = 9 grid = True dg = None mat_assigns = None unique_names = { "mat:m1": "M1", "mat:m2": "M2", "mat:m3": "M3", "mat:m4": "M4" } voxel_zones, zones = partisn._get_zones(mesh, hdf5, bounds, num_rays, grid, dg, mat_assigns, unique_names) voxel_zones_expected = np.array([[1, 2], [1, 4], [1, 3], [1, 4]]) zones_expected = { 1: { "vol_frac": [1.0], "mat": ["M2"] }, 2: { "vol_frac": [1.0], "mat": ["M4"] }, 3: { "vol_frac": [1.0], "mat": ["M1"] }, 4: { "vol_frac": [1.0], "mat": ["M3"] }, } vz_tf = voxel_zones.all() == voxel_zones_expected.all() z_tf = zones == zones_expected return [vz_tf, z_tf]
def versions(): from pyne import dagmc dagmc.load(path) returned = dagmc.versions() assert_equal(len(returned), 2) assert_true(isinstance(returned[0], STRING_TYPES)) assert_true(isinstance(returned[1], int))
def boundary(): from pyne import dagmc dagmc.load(path) low, high = dagmc.volume_boundary(2) for i in range(0, 3): assert_true(low[i] <= -1.0) assert_true(high[i] >= 1.0)
def list_functions(): from pyne import dagmc dagmc.load(path) surfs = dagmc.get_surface_list() vols = dagmc.get_volume_list() return [surfs, vols]
def util_matlist(): from pyne import dagmc dagmc.load(path) mats1 = dagmc.get_material_set() mats2 = dagmc.get_material_set(with_rho=True) return [mats1, mats2]
def discretize_non_square(): from pyne import dagmc dagmc.load(path) coords = [0, 1] mesh = Mesh(structured=True, structured_coords=[coords, coords, coords]) assert_raises(ValueError, dagmc.discretize_geom, mesh, num_rays=3, grid=True)
def list_functions(): from pyne import dagmc dagmc.load(path) surfs = dagmc.get_surface_list() assert_equal(set(surfs), set(range(1, 19))) vols = dagmc.get_volume_list() assert_equal(set(vols), set(range(1, 5)))
def metadata(): from pyne import dagmc dagmc.load(path) rets1 = [dagmc.volume_is_graveyard(x) for x in range(1, 5)] rets2 = [dagmc.volume_is_implicit_complement(x) for x in range(1, 5)] md = dagmc.volume_metadata(2) return [rets1, rets2, md]
def discretize_geom_grid(): from pyne import dagmc dagmc.load(path) coords = [-4, -1, 1, 4] mesh = Mesh(structured=True, structured_coords=[coords, coords, coords]) results = dagmc.discretize_geom(mesh, num_rays=49, grid=True) return [results, coords]
def util_matlist(): from pyne import dagmc dagmc.load(path) mats = dagmc.get_material_set() assert_equal(set((0, 5)), mats) mats = dagmc.get_material_set(with_rho=True) assert_equal(set([(0, 0.0), (5, 0.5)]), mats)
def cells_at_ve_centers(): from pyne import dagmc dagmc.load(path) coords = [0, 1] coords2 = [0, 2, 4] mesh = Mesh(structured=True, structured_coords=[coords2, coords, coords]) cells = dagmc.cells_at_ve_centers(mesh) assert_array_equal(cells, [2, 3])
def step1(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean("general", "structured") meshtal = config.get("step1", "meshtal") tally_num = config.getint("step1", "tally_num") flux_tag = config.get("step1", "flux_tag") decay_times = config.get("step2", "decay_times").split(",") geom = config.get("step1", "geom") reverse = config.getboolean("step1", "reverse") num_rays = config.getint("step1", "num_rays") grid = config.getboolean("step1", "grid") responses = config.get("general", "responses").split(",") wdr_file = config.get("general", "wdr_file") load(geom) # get meshtal info from meshtal file flux_mesh = resolve_mesh(meshtal, tally_num, flux_tag) # create the cell_fracs array before irradiation_steup if flux_mesh.structured: cell_fracs = discretize_geom(flux_mesh, num_rays=num_rays, grid=grid) else: cell_fracs = discretize_geom(flux_mesh) cell_mats = cell_materials(geom) irradiation_setup( flux_mesh, cell_mats, cell_fracs, alara_params_filename, tally_num, num_rays=num_rays, grid=grid, reverse=reverse, output_mesh="activation_responses_step1.h5m", flux_tag=flux_tag, decay_times=decay_times, sub_voxel=False, responses=responses, wdr_file=wdr_file, ) # create a blank mesh for step 2: ves = list(flux_mesh.iter_ve()) for tag in flux_mesh.get_all_tags(): tag.delete() flux_mesh.write_hdf5("blank_mesh.h5m") print("The file blank_mesh.h5m has been saved to disk.") print( "Do not delete this file; it is needed by activation_responses.py step2.\n" ) print("Decay_heat step1 complete, run ALARA with the command:") print(">> alara alara_inp > output.txt")
def ray_story(): from pyne import dagmc dagmc.load(path) # Run with `nosetests -s` to see output printed on stdout dagmc.tell_ray_story((0, 0, 0), (1, 1, 0)) dagmc.tell_ray_story((-3, 0, 0), (1, 0, 0)) # tests edge behavior dagmc.tell_ray_story((-3, 0, 0), (1, 0, 0), dist_limit=4) dagmc.tell_ray_story((-3, 0, 0), (1, 0, 0), dist_limit=4.1)
def util_graveyard_bound(): from pyne import dagmc dagmc.load(path) lo, hi = dagmc.find_graveyard_inner_box() grave_diam = 4.15692194 for i in range(0, 3): assert_almost_equal(lo[i], -grave_diam) assert_almost_equal(hi[i], grave_diam)
def cells_at_ve_centers(): from pyne import dagmc dagmc.load(path) coords = [0, 1] coords2 = [0, 2, 4] mesh = Mesh(structured=True, structured_coords=[coords2, coords, coords]) cells = dagmc.cells_at_ve_centers(mesh) return cells
def get_zones_with_void(): """Test the _get_zones function if a void is present. """ try: from pyne import dagmc except: raise SkipTest if not HAVE_PYMOAB: raise SkipTest # hdf5 test file THIS_DIR = os.path.dirname(os.path.realpath(__file__)) hdf5 = THIS_DIR + '/files_test_partisn/partisn_test_geom.h5m' data_hdf5path = '/materials' nuc_hdf5path = '/nucid' dagmc.load(hdf5) # mesh xvals = [-5., 0., 10., 15., 15.1] yvals = [-5., 0., 5.] zvals = [-5., 0., 5.] mesh = Mesh(structured_coords=[xvals, yvals, zvals], structured=True, structured_ordering='xyz') # more inputs bounds = {'x': xvals, 'y': yvals, 'z': zvals} num_rays = 400 grid = True dg = None mat_assigns = None unique_names = {'mat:Helium, Natural': 'HELIUMNA', 'mat:Mercury': 'MERCURY1'} voxel_zones, zones = partisn._get_zones( mesh, hdf5, bounds, num_rays, grid, dg, mat_assigns, unique_names) # expected results voxel_zones_expected = np.array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [0, 0, 0, 0]]) zones_expected = {1: {'vol_frac': [1.0], 'mat': [u'HELIUMNA']}, 2: {'vol_frac': [0.5, 0.5], 'mat': [u'HELIUMNA', u'MERCURY1']}, 3: {'vol_frac': [1.0], 'mat': [u'MERCURY1']}} vz_tf = False z_tf = False if voxel_zones.all() == voxel_zones_expected.all(): vz_tf = True if zones == zones_expected: z_tf = True #assert(voxel_zones.all() == voxel_zones_expected.all()) #assert(zones == zones_expected) return [vz_tf, z_tf]
def step1(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') sub_voxel = config.getboolean('general', 'sub_voxel') meshtal = config.get('step1', 'meshtal') tally_num = config.getint('step1', 'tally_num') flux_tag = config.get('step1', 'flux_tag') decay_times = config.get('step2', 'decay_times').split(',') geom = config.get('step1', 'geom') reverse = config.getboolean('step1', 'reverse') num_rays = config.getint('step1', 'num_rays') grid = config.getboolean('step1', 'grid') load(geom) # get meshtal info from meshtal file flux_mesh = resolve_mesh(meshtal, tally_num, flux_tag) # create the cell_fracs array before irradiation_steup if flux_mesh.structured: cell_fracs = discretize_geom(flux_mesh, num_rays=num_rays, grid=grid) # tag cell fracs for both default and subvoxel r2s modes flux_mesh.tag_cell_fracs(cell_fracs) else: cell_fracs = discretize_geom(flux_mesh) cell_mats = cell_materials(geom) irradiation_setup(flux_mesh, cell_mats, cell_fracs, alara_params_filename, tally_num, num_rays=num_rays, grid=grid, reverse=reverse, flux_tag=flux_tag, decay_times=decay_times, sub_voxel=sub_voxel) # create a blank mesh for step 2: ves = list(flux_mesh.iter_ve()) tags_keep = ("cell_number", "cell_fracs", "cell_largest_frac_number", "cell_largest_frac") for tag in flux_mesh.get_all_tags(): if tag.name not in tags_keep and isinstance(tag, NativeMeshTag): tag.delete() flux_mesh.write_hdf5('blank_mesh.h5m') print('The file blank_mesh.h5m has been saved to disk.') print('Do not delete this file; it is needed by r2s.py step2.\n') print('R2S step1 complete, run ALARA with the command:') print('>> alara alara_inp > output.txt')
def pt_in_vol(): from pyne import dagmc dagmc.load(path) # there are 4 volumes; (0,0,.2) is in volume 2 rets = [dagmc.point_in_volume(x, [0, 0, .2]) for x in range(1, 5)] assert_equal(rets, [False, True, False, False]) # (1.1,0,0) is in volume 3 rets = [dagmc.point_in_volume(x, [1.1, 0, 0]) for x in range(1, 5)] assert_equal(rets, [False, False, True, False])
def pt_in_vol(): from pyne import dagmc dagmc.load(path) # there are 4 volumes; (0,0,.2) is in volume 2 rets1 = [dagmc.point_in_volume(x, [0, 0, .2]) for x in range(1, 5)] # (1.1,0,0) is in volume 3 rets2 = [dagmc.point_in_volume(x, [1.1, 0, 0]) for x in range(1, 5)] return [rets1, rets2]
def failures(): from pyne import dagmc dagmc.load(path) # if Exception is raised, then None is returned, else nothing is returned # and test will fail i = assert_raises(Exception, dagmc.point_in_volume, [100, (0, 0, 0)]) j = assert_raises(Exception, dagmc.point_in_volume, [1, (0, 0, 0, 0)]) k = assert_raises(Exception, dagmc.fire_one_ray, [2, (0, 0, 0), 1]) return [i, j, k]
def step1(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') meshtal = config.get('step1', 'meshtal') tally_num = config.getint('step1', 'tally_num') flux_tag = config.get('step1', 'flux_tag') decay_times = config.get('step2', 'decay_times').split(',') geom = config.get('step1', 'geom') reverse = config.getboolean('step1', 'reverse') num_rays = config.getint('step1', 'num_rays') grid = config.getboolean('step1', 'grid') responses = config.get('general', 'responses').split(',') wdr_file = config.get('general', 'wdr_file') load(geom) # get meshtal info from meshtal file flux_mesh = resolve_mesh(meshtal, tally_num, flux_tag) # create the cell_fracs array before irradiation_steup if flux_mesh.structured: cell_fracs = discretize_geom(flux_mesh, num_rays=num_rays, grid=grid) else: cell_fracs = discretize_geom(flux_mesh) cell_mats = cell_materials(geom) irradiation_setup(flux_mesh, cell_mats, cell_fracs, alara_params_filename, tally_num, num_rays=num_rays, grid=grid, reverse=reverse, output_mesh="activation_responses_step1.h5m", flux_tag=flux_tag, decay_times=decay_times, sub_voxel=False, responses=responses, wdr_file=wdr_file) # create a blank mesh for step 2: ves = list(flux_mesh.iter_ve()) for tag in flux_mesh.get_all_tags(): tag.delete() flux_mesh.write_hdf5('blank_mesh.h5m') print('The file blank_mesh.h5m has been saved to disk.') print( 'Do not delete this file; it is needed by activation_responses.py step2.\n' ) print('Decay_heat step1 complete, run ALARA with the command:') print('>> alara alara_inp > output.txt')
def discretize_geom_mix(): from pyne import dagmc dagmc.load(path) coords = [0, 1] coords2 = [0, 2] mesh = Mesh(structured=True, structured_coords=[coords2, coords, coords]) results1 = dagmc.discretize_geom(mesh, num_rays=100, grid=True) # To to make sure standard error decreases with increasing rays results2 = dagmc.discretize_geom(mesh, num_rays=625, grid=True) return [results1, results2]
def metadata(): from pyne import dagmc dagmc.load(path) rets = [dagmc.volume_is_graveyard(x) for x in range(1, 5)] assert_equal(rets, [True, False, False, False]) rets = [dagmc.volume_is_implicit_complement(x) for x in range(1, 5)] assert_equal(rets, [False, False, False, True]) md = dagmc.volume_metadata(2) assert_equal(md['material'], 5) assert_equal(md['rho'], 0.5) assert_true(all(x in md for x in ['material', 'rho', 'imp']))
def discretize_geom_grid(): from pyne import dagmc dagmc.load(path) coords = [-4, -1, 1, 4] mesh = Mesh(structured=True, structured_coords=[coords, coords, coords]) results = dagmc.discretize_geom(mesh, num_rays=49, grid=True) assert_equal(len(results), (len(coords) - 1)**3) for res in results: if res['idx'] != 13: assert_equal(res['cell'], 3) else: assert_equal(res['cell'], 2) assert_almost_equal(res['vol_frac'], 1.0)
def discretize_geom_centers(): from pyne import dagmc dagmc.load(path) coords = [0, 1] coords2 = [0, 2, 4] mesh = Mesh(structured=True, structured_coords=[coords2, coords, coords]) # explicitly set to unstructured to trigger the ve centers sampling # method mesh.structured = False res = dagmc.discretize_geom(mesh) assert_array_equal(res["idx"], [0, 1]) assert_array_equal(res["cell"], [2, 3]) assert_array_equal(res["vol_frac"], [1.0, 1.0]) assert_array_equal(res["rel_error"], [1.0, 1.0]) # ensure kwargs are not accepted for unstructured mesh assert_raises(ValueError, dagmc.discretize_geom, mesh, num_rays=3, grid=True)
def get_zones_with_void(): """Test the _get_zones function if a void is present. """ # hdf5 test file THIS_DIR = os.path.dirname(os.path.realpath(__file__)) hdf5 = THIS_DIR + '/files_test_partisn/partisn_test_geom.h5m' data_hdf5path = '/materials' nuc_hdf5path = '/nucid' from pyne import dagmc dagmc.load(hdf5) # mesh xvals = [-5., 0., 10., 15., 15.1] yvals = [-5., 0., 5.] zvals = [-5., 0., 5.] mesh=Mesh(structured_coords=[xvals, yvals, zvals], structured=True, structured_ordering='xyz') # more inputs bounds = {'x':xvals, 'y':yvals, 'z':zvals} num_rays = 400 grid = True voxel_zones, zones = partisn._get_zones(mesh, hdf5, bounds, num_rays, grid) # expected results voxel_zones_expected = np.array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [0, 0, 0, 0]]) zones_expected = {1:{'vol_frac':[1.0], 'mat':[u'HeliumNatural']}, 2:{'vol_frac':[0.5, 0.5], 'mat':[u'HeliumNatural', u'Mercury']}, 3:{'vol_frac':[1.0], 'mat':[u'Mercury']}} vz_tf = False z_tf = False if voxel_zones.all() == voxel_zones_expected.all(): vz_tf = True if zones == zones_expected: z_tf = True #assert(voxel_zones.all() == voxel_zones_expected.all()) #assert(zones == zones_expected) return [vz_tf, z_tf]
def discretize_geom_mix(): from pyne import dagmc dagmc.load(path) coords = [0, 1] coords2 = [0, 2] mesh = Mesh(structured=True, structured_coords=[coords2, coords, coords]) results1 = dagmc.discretize_geom(mesh, num_rays=100, grid=True) assert_equal(results1[0]['cell'], 2) assert_almost_equal(results1[0]['vol_frac'], 0.5) assert_equal(results1[1]['cell'], 3) assert_almost_equal(results1[1]['vol_frac'], 0.5) # To to make sure standard error decreases with increasing rays results2 = dagmc.discretize_geom(mesh, num_rays=625, grid=True) assert(results2[0]['rel_error'] < results1[0]['rel_error']) assert(results2[1]['rel_error'] < results1[1]['rel_error'])
def one_ray(): from pyne import dagmc dagmc.load(path) fromcenter = dagmc.fire_one_ray(2, [0, 0, 0], [1, 0, 0]) assert_almost_equal(fromcenter[1], 1.0) fromhalf = dagmc.fire_one_ray(2, [.5, .5, .5], [0, -1, 0]) assert_almost_equal(fromhalf[1], 1.5) # the following is actually a misuse of ray_fire because it should only # be called from inside a volume, but at least verify that a ray is # lost if it 1) starts outside a volume and 2) does not intersect the # volume fromoutside = dagmc.fire_one_ray(2, [0, 1.1, 0], [-1, 0, 0]) assert_equal(fromoutside, None) fromvol3 = dagmc.fire_one_ray(3, [0, 1.1, 0], [0, -1, 0]) assert_almost_equal(fromvol3[1], 0.1) fromvol3 = dagmc.fire_one_ray(3, [0, 1.1, 0], [0, 1, 0]) assert_almost_equal(fromvol3[1], 3.056921938)
def find_volume(): from pyne import dagmc dagmc.load(path) vol = dagmc.find_volume([0, 0, 0]) assert_equal(vol, 2) vol = dagmc.find_volume([.9, .9, .9]) assert_equal(vol, 2) # boundary case -- point [1,.1,.1] is on surface between vols 2 and 3 # the behavior on boundaries will vary with uvw, but ensure that # only the two volumes the touch the location are ever returned. for uvw in [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0)]: vol = dagmc.find_volume([1, .1, .1], uvw) assert_true(vol in (2, 3)) # boundary case-- exiting volume 3 => in volume 3 vol = dagmc.find_volume([1, .1, .1], [-1, 0, 0]) assert_equal(vol, 3) vol = dagmc.find_volume([1.1, 0, 0]) assert_equal(vol, 3)
def load(): from pyne import dagmc # FIXME laoding causes infor to be printied to stderr (or stdout). dagmc.load(path)
def irradiation_setup(flux_mesh, cell_mats, alara_params, tally_num=4, geom=None, num_rays=10, grid=False, flux_tag="n_flux", fluxin="alara_fluxin", reverse=False, alara_inp="alara_geom", alara_matlib="alara_matlib", output_mesh="r2s_step1.h5m", output_material=False): """This function is used to setup the irradiation inputs after the first R2S transport step. Parameters ---------- flux_mesh : PyNE Meshtal object, Mesh object, or str The source of the neutron flux information. This can be a PyNE Meshtal object, a pyne Mesh object, or the filename an MCNP meshtal file, or the filename of an unstructured mesh tagged with fluxes. tally_num : int The MCNP FMESH4 tally number of the neutron flux tally within the meshtal file. cell_mats : dict Maps geometry cell numbers to PyNE Material objects. alara_params : str The ALARA input blocks specifying everything except the geometry and materials. This can either be passed as string or as a file name. geom : str, optional The file name of a DAGMC-loadable faceted geometry. This is only necessary if the geometry is not already loaded into memory. num_rays : int, optional The number of rays to fire down a mesh row for geometry discretization. This number must be a perfect square if grid=True. grid : bool, optional The if False, geometry discretization will be done with randomly fired rays. If true, a grid of sqrt(num_rays) x sqrt(num_rays) rays is used for each mesh row. flux_tag : str, optional The iMesh tag for the neutron flux. fluxin : str, optional The name of the ALARA fluxin file to be created. reverse : bool, optional If True the fluxes in the fluxin file will be printed in the reverse order of how they appear within the flux vector tag. Since MCNP and the Meshtal class order fluxes from low energy to high energy, this option should only be true if the transmutation data being used is ordered from high energy to low energy. alara_inp : str, optional The name of the ALARA input file to be created. alara_matlib : str, optional The name of the alara_matlib file to be created. output_mesh : str, optional A mesh containing all the fluxes and materials used for irradiation setup. output_material : bool, optional If true, output mesh will have materials as determined by dagmc.discretize_geom() """ from pyne.dagmc import load, discretize_geom if geom is not None and isfile(geom): load(geom) # flux_mesh is Mesh object if isinstance(flux_mesh, Mesh): m = flux_mesh # flux_mesh is unstructured mesh file elif isinstance(flux_mesh, str) and isfile(flux_mesh) \ and flux_mesh.endswith(".h5m"): m = Mesh(structured=False, mesh=flux_mesh) # flux_mesh is Meshtal or meshtal file else: # flux_mesh is meshtal file if isinstance(flux_mesh, str) and isfile(flux_mesh): flux_mesh = Meshtal(flux_mesh, {tally_num: (flux_tag, flux_tag + "_err", flux_tag + "_total", flux_tag + "_err_total")}, meshes_have_mats=output_material) m = flux_mesh.tally[tally_num] # flux_mesh is Meshtal object elif isinstance(flux_mesh, Meshtal): m = flux_mesh.tally[tally_num] else: raise ValueError("meshtal argument not a Mesh object, Meshtal" " object, MCNP meshtal file or meshtal.h5m file.") if m.structured: cell_fracs = discretize_geom(m, num_rays=num_rays, grid=grid) else: cell_fracs = discretize_geom(m) if output_material: m.cell_fracs_to_mats(cell_fracs, cell_mats) mesh_to_fluxin(m, flux_tag, fluxin, reverse) record_to_geom(m, cell_fracs, cell_mats, alara_inp, alara_matlib) if isfile(alara_params): with open(alara_params, 'r') as f: alara_params = f.read() with open(alara_inp, 'a') as f: f.write("\n" + alara_params) m.write_hdf5(output_mesh)
def _get_zones(mesh, hdf5, bounds, num_rays, grid): """Get the minimum zone definitions for the geometry. """ # load the geometry from pyne import dagmc dagmc.load(hdf5) # Descretize the geometry and get cell fractions dg = dagmc.discretize_geom(mesh, num_rays=num_rays, grid=grid) # Reorganize dictionary of each voxel's info with the key the voxel number # and values of cell and volume fraction voxel = {} for i in dg: idx = i[0] # voxel number if idx not in voxel: voxel[idx] = {} voxel[idx]['cell'] = [] voxel[idx]['vol_frac'] = [] voxel[idx]['cell'].append(i[1]) voxel[idx]['vol_frac'].append(i[2]) # get material to cell assignments mat_assigns = dagmc.cell_material_assignments(hdf5) # Replace cell numbers with materials, eliminating duplicate materials # within single zone definition zones = {} for z in voxel: zones[z] = {} zones[z]['vol_frac'] = [] zones[z]['mat'] = [] for i, cell in enumerate(voxel[z]['cell']): if mat_assigns[cell] not in zones[z]['mat']: # create new entry zones[z]['mat'].append(mat_assigns[cell]) zones[z]['vol_frac'].append(voxel[z]['vol_frac'][i]) else: # update value that already exists with new volume fraction for j, val in enumerate(zones[z]['mat']): if mat_assigns[cell] == val: vol_frac = zones[z]['vol_frac'][j] + voxel[z]['vol_frac'][i] zones[z]['vol_frac'][j] = vol_frac # Remove vacuum or graveyard from material definition if not vol_frac of 1.0 skip_array = [['mat:Vacuum'], ['mat:vacuum'], ['mat:Graveyard'], ['mat:graveyard']] skip_list = ['mat:Vacuum', 'mat:vacuum', 'mat:Graveyard', 'mat:graveyard'] zones_compressed = {} for z, info in zones.iteritems(): # check first if the definition is 100% void, keep same if is if zones[z]['mat'] in skip_array and zones[z]['vol_frac'] == [1.0]: zones_compressed[z] = info else: # check for partial void zones_compressed[z] = {'mat':[], 'vol_frac':[]} for i, mat in enumerate(zones[z]['mat']): if mat not in skip_list: zones_compressed[z]['mat'].append(mat) zones_compressed[z]['vol_frac'].append(zones[z]['vol_frac'][i]) # Eliminate duplicate zones and assign each voxel a zone number. # Assign zone = 0 if vacuum or graveyard and eliminate material definition. voxel_zone = {} zones_mats = {} z = 0 match = False first = True for i, vals in zones_compressed.iteritems(): # Find if the zone already exists for zone, info in zones_mats.iteritems(): # Iterate through both sets to disregard order match_all = np.empty(len(vals['mat']), dtype=bool) match_all.fill(False) for ii, mat in enumerate(vals['mat']): for jj, mat_info in enumerate(info['mat']): if mat == mat_info and np.allclose(np.array(vals['vol_frac'][ii]), \ np.array(info['vol_frac'][jj]), rtol=1e-5): match_all[ii] = True break if match_all.all() == True: match = True y = zone break else: match = False # Create a new zone if first zone or does not match other zones if first or not match: # Check that the material is not 100% void (assign zone 0 otherwise) if vals['mat'] in skip_array: voxel_zone[i] = 0 else: z += 1 zones_mats[z] = zones_compressed[i] voxel_zone[i] = z first = False else: if vals['mat'] in skip_array: voxel_zone[i] = 0 else: voxel_zone[i] = y # Remove any instances of graveyard or vacuum in zone definitions zones_novoid = {} for z in zones_mats: zones_novoid[z] = {'mat':[], 'vol_frac':[]} for i, mat in enumerate(zones_mats[z]['mat']): if mat not in skip_list: name = strip_mat_name(mat) zones_novoid[z]['mat'].append(name) zones_novoid[z]['vol_frac'].append(zones_mats[z]['vol_frac'][i]) # Put zones into format for PARTISN input if 'x' in bounds: im = len(bounds['x']) - 1 else: im = 1 if 'y' in bounds: jm = len(bounds['y']) - 1 else: jm = 1 if 'z' in bounds: km = len(bounds['z']) - 1 else: km = 1 n = 0 zones_formatted = np.zeros(shape=(jm*km, im), dtype=int) for i in range(im): for jk in range(jm*km): zones_formatted[jk, i] = voxel_zone[n] n += 1 return zones_formatted, zones_novoid
def test__load(self): # FIXME laoding causes infor to be printied to stderr (or stdout). path = os.path.join(os.path.dirname(__file__), 'unitbox.h5m') dagmc.load(path)
vector.append(float(split_str[5])) direction.append(vector) # speed speed.append(float(split_str[6])) return xyz,direction,speed (xyz,direction,speed) = load_input_file("input.txt") mesh = Mesh(mesh="../geom/conv_pipe_mesh.h5m") # load dag geometry load("../geom/conv_pipe_geom.h5m") # discretise geom onto mesh cell_fracs = discretize_geom(mesh) mesh.vol_id = IMeshTag(1,int) mesh.source_strength = IMeshTag(1,float) id_list = [] for element in cell_fracs: id_list.append(element["cell"]) mesh.vol_id[:]=id_list # loop along path, use point in volume to determine the vol id volumes = get_all_cells(xyz,direction,speed)