def test_material2(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename, '/materials') # create the material for the test Nitrogen = Material({70140000: 0.99636, 70150000: 0.00364}) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Nitrogen': assert_almost_equal(material[1].comp, Nitrogen.comp, places=4)
def test_material2(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename,'/materials') # create the material for the test Nitrogen = Material({70140000: 0.99636, 70150000: 0.00364}) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Nitrogen': assert_almost_equal(material[1].comp, Nitrogen.comp, places=4)
def test_material1(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename,'/materials') # create the material for the test Lead = Material({822040000: 0.013999999999999999, 822060000: 0.24100000000000002, 822070000: 0.22100000000000003, 822080000: 0.524}) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Lead': assert_almost_equal(material[1].comp, Lead.comp, places=4)
def test_material4(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename,'/materials') # create the material for the test Steel = Material({60120000: 0.10992222222222224, 60130000: 0.0011888888888888893, 140280000: 0.10247000000000002, 140290000: 0.005205555555555556, 140300000: 0.0034355555555555563, 150310000: 0.11111111111111112, 160320000: 0.10554444444444445, 160330000: 0.0008333333333333334, 160340000: 0.004722222222222223, 160360000: 1.1111111111111113e-05, 220460000: 0.009166666666666668, 220470000: 0.008266666666666669, 220480000: 0.08191111111111112, 220490000: 0.006011111111111112, 220500000: 0.005755555555555556, 240500000: 0.004827777777777778, 240520000: 0.09309888888888891, 240530000: 0.010556666666666667, 240540000: 0.002627777777777779, 250550000: 0.11111111111111112, 260540000: 0.006494444444444446, 260560000: 0.10194888888888891, 260570000: 0.0023544444444444455, 260580000: 0.0003133333333333333, 280580000: 0.07564111111111112, 280600000: 0.029136666666666672, 280610000: 0.0012665555555555557, 280620000: 0.004038444444444445, 280640000: 0.0010283333333333336}) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Steel, Stainless 321': assert_almost_equal(material[1].comp, Steel.comp, places=4)
def test_material3(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename,'/materials') # create the material for the test Mercury = Material({801960000: 0.0015, 801980000: 0.09970000000000001, 801990000: 0.16870000000000002, 802000000: 0.231, 802010000: 0.1318, 802020000: 0.2986, 802040000: 0.0687}) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Mercury': assert_almost_equal(material[1].comp, Mercury.comp, places=4)
def write_mats_h5m(materials_list, filename): """ Function that writes material objects to output .h5m file ------- material_list: list of materials found on tags of the model filename: filename to write the objects to """ new_matlib = MaterialLibrary() for material in materials_list: # using fluka name as index since this is unique new_matlib[material.metadata['fluka_name']] = material new_matlib.write_hdf5(filename, datapath='/materials', nucpath='/nucid')
def test_material1(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename, '/materials') # create the material for the test Lead = Material({ 822040000: 0.013999999999999999, 822060000: 0.24100000000000002, 822070000: 0.22100000000000003, 822080000: 0.524 }) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Lead': assert_almost_equal(material[1].comp, Lead.comp, places=4)
def uwuw_matlib(inp, out): mats = mats_from_inp(inp) uwuw_mats = {} for mat in mats.values(): if isinstance(mat, MultiMaterial): m = mat._mats.keys()[0] else: m = mat mat_name = "m{0}".format(m.metadata["mat_number"]) m.metadata["name"] = mat_name uwuw_mats[mat_name] = m ml = MaterialLibrary(uwuw_mats) ml.write_hdf5(out, datapath='/material_library/materials', nucpath='/material_library/nucid')
def _get_material_lib(hdf5, data_hdf5path, nuc_hdf5path, **kwargs): """Read material properties from the loaded dagmc geometry. """ # If a set of nuc_names is provided, then collapse elements if 'nuc_names' in kwargs: nuc_names = kwargs['nuc_names'] collapse = True # set of exception nuclides for collapse_elements mat_except = set(nuc_names.keys()) else: collapse = False # collapse isotopes into elements (if required) mats = MaterialLibrary(hdf5, datapath=data_hdf5path, nucpath=nuc_hdf5path) mats_collapsed = {} for mat_name in mats: if collapse: mats_collapsed[mat_name] = mats[mat_name].collapse_elements( mat_except) else: mats_collapsed[mat_name] = mats[mat_name] # convert mass fraction to atom density in units [at/b-cm] mat_lib = {} for mat_name in mats_collapsed: comp = mats_collapsed[mat_name] atom_dens_dict = comp.to_atom_dens() comp_list = {} for nucid, dens in atom_dens_dict.iteritems(): # convert from [at/cc] to [at/b-cm] comp_list[nucid] = dens * 10.**-24 mat_lib[mat_name] = comp_list return mat_lib
def test_against_nuc_data(): nuc_data = pyne_conf.NUC_DATA_PATH if not os.path.isfile(nuc_data): raise RuntimeError("Tests require nuc_data.h5. Please run nuc_data_make.") obs_matslib = MaterialLibrary(nuc_data, datapath="/material_library/materials", nucpath="/material_library/nucid") gasoline = Material({ "H": 0.157000, "C": 0.843000, }, density=0.721, metadata={"name": "Gasoline"}).expand_elements() pubr3 = Material({ "Br": 0.500617, "Pu-238": 0.000250, "Pu-239": 0.466923, "Pu-240": 0.029963, "Pu-241": 0.001998, "Pu-242": 0.000250 }, density=6.75, metadata={"name": "Plutonium Bromide"}).expand_elements() obs_gasoline = obs_matslib["Gasoline"] assert_equal(set(obs_gasoline.comp.items()), set(gasoline.comp.items())) assert_equal(obs_gasoline.density, gasoline.density) assert_equal(obs_gasoline.metadata["name"], gasoline.metadata["name"]) obs_pubr3 = obs_matslib["Plutonium Bromide"] assert_equal(set(obs_pubr3.comp.items()), set(pubr3.comp.items())) assert_equal(obs_pubr3.density, pubr3.density) assert_equal(obs_pubr3.metadata["name"], pubr3.metadata["name"])
def make_matslib(fname): """Make a pyne.material.MaterialLibrary. First makes elements, then materials from compendium. Parameters ---------- fname : str Path to materials compendium. Returns ------- matslib : pyne.material.MaterialLibrary All the materials you could want, in a handy MaterialLibrary instance. """ matslib = MaterialLibrary(make_elements()) matsdict = grab_materials_compendium(fname) matslib.update(matsdict) return matslib
def test_material3(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename, '/materials') # create the material for the test Mercury = Material({ 801960000: 0.0015, 801980000: 0.09970000000000001, 801990000: 0.16870000000000002, 802000000: 0.231, 802010000: 0.1318, 802020000: 0.2986, 802040000: 0.0687 }) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Mercury': assert_almost_equal(material[1].comp, Mercury.comp, places=4)
def test_material4(): # load the material library output_lib = MaterialLibrary() output_lib.from_hdf5(filename, '/materials') # create the material for the test Steel = Material({ 60120000: 0.10992222222222224, 60130000: 0.0011888888888888893, 140280000: 0.10247000000000002, 140290000: 0.005205555555555556, 140300000: 0.0034355555555555563, 150310000: 0.11111111111111112, 160320000: 0.10554444444444445, 160330000: 0.0008333333333333334, 160340000: 0.004722222222222223, 160360000: 1.1111111111111113e-05, 220460000: 0.009166666666666668, 220470000: 0.008266666666666669, 220480000: 0.08191111111111112, 220490000: 0.006011111111111112, 220500000: 0.005755555555555556, 240500000: 0.004827777777777778, 240520000: 0.09309888888888891, 240530000: 0.010556666666666667, 240540000: 0.002627777777777779, 250550000: 0.11111111111111112, 260540000: 0.006494444444444446, 260560000: 0.10194888888888891, 260570000: 0.0023544444444444455, 260580000: 0.0003133333333333333, 280580000: 0.07564111111111112, 280600000: 0.029136666666666672, 280610000: 0.0012665555555555557, 280620000: 0.004038444444444445, 280640000: 0.0010283333333333336 }) for material in output_lib.iteritems(): if material[1].metadata['original_name'] == 'Steel, Stainless 321': assert_almost_equal(material[1].comp, Steel.comp, places=4)
def test_matlib_json(): filename = "matlib.json" water = Material() water.from_atom_frac({10000000: 2.0, 80000000: 1.0}) water.metadata["name"] = "Aqua sera." lib = {"leu": Material(leu), "nucvec": nucvec, "aqua": water} wmatlib = MaterialLibrary(lib) wmatlib.write_json(filename) rmatlib = MaterialLibrary() rmatlib.from_json(filename) assert_equal(set(wmatlib), set(rmatlib)) for key in rmatlib: assert_mat_almost_equal(wmatlib[key], rmatlib[key]) os.remove(filename)
def setup(): global MATS, O2HLS o2benchurl = 'http://data.pyne.io/' + H5NAME if not os.path.exists(H5NAME): sys.stderr.write("\nDownloading " + o2benchurl + ": ") sys.stderr.flush() urlretrieve(o2benchurl, H5NAME) sys.stderr.write("done.\n") sys.stderr.flush() MATS = MaterialLibrary(H5NAME) with open('o2hls.json', 'r') as f: O2HLS = json.load(f) O2HLS = {int(nuc): v for nuc, v in O2HLS.items()}
def test_uwuw_matlib(): inp = "test.inp" out = "out.h5m" if os.path.exists(out): os.remove(out) uwuw_matlib(inp, out) ml = MaterialLibrary() ml.from_hdf5(out, datapath='/material_library/materials', nucpath='/material_library/nucid') mats = ml.values() assert_equal(len(mats), 2) assert_equal(mats[0].metadata["mat_number"], "1") assert_equal(mats[0].metadata["name"], "m1") assert_almost_equal(mats[0].density, 9.0) assert_equal(mats[0].comp, {10010000: 1.0}) assert_equal(mats[1].metadata["mat_number"], "2") assert_equal(mats[1].metadata["name"], "m2") assert_almost_equal(mats[1].density, 21.0) assert_equal(mats[1].comp, {10020000: 1.0}) os.remove(out)
def build_pyne_matlib(nucdata_file=None): """Fetch pyne material from compendium. This function builds PyNE material library for UWNR non-fuel components defined in reactor_data.py Arguments: nucdata_file (str)[-]: Filename 'nuc_data.h5' with its full path. """ h5path = "/home/alex/.local/lib/python3.5/site-packages/pyne/nuc_data.h5" if nucdata_file: h5path = nucdata_file # Initialize material libraries. raw_matlib = MaterialLibrary() # Write entire PyNE material library. raw_matlib.from_hdf5(h5path, datapath="/material_library/materials", nucpath="/material_library/nucid") return raw_matlib
def test_matlib_hdf5(): filename = "matlib.h5" if filename in os.listdir('.'): os.remove(filename) water = Material() water.from_atom_frac({10000000: 2.0, 80000000: 1.0}) water.metadata["name"] = "Aqua sera." lib = {"leu": Material(leu), "nucvec": nucvec, "aqua": water} wmatlib = MaterialLibrary(lib) wmatlib.write_hdf5(filename) rmatlib = MaterialLibrary() rmatlib.from_hdf5(filename) os.remove(filename) # Round trip! rmatlib.write_hdf5(filename) wmatlib = MaterialLibrary(filename) assert_equal(set(wmatlib), set(rmatlib)) for key in rmatlib: assert_mat_almost_equal(wmatlib[key], rmatlib[key]) os.remove(filename)
def test_match_1(): air_1 = material.Material( { 60120000: 0.24732500000000002, 60130000: 0.0026750000000000003, 70140000: 0.24909, 70150000: 0.00091, 80160000: 0.24939250000000002, 80170000: 9.5e-05, 80180000: 0.0005124999999999999, 180360000: 0.000834, 180380000: 0.00015725, 180400000: 0.24900875 }, 1.0, 0.001205, -1.0, {"name": "Air (dry, near sea level)"}) air_2 = material.Material( { 10010000: 0.19997700000000002, 10020000: 2.3e-05, 60120000: 0.19786, 60130000: 0.0021400000000000004, 80160000: 0.19951400000000002, 80170000: 7.6e-05, 80180000: 0.00040999999999999994, 90190000: 0.2, 140280000: 0.184446, 140290000: 0.00937, 140300000: 0.006184 }, 1.0, 1.76, -1.0, {"name": "C-552 Air-Equivalent Plastic"}) list_of_matches = [ 'C-552 Air-Equivalent Plastic', 'Air (dry, near sea level)' ] material_library = MaterialLibrary() material_library[air_1.metadata['name']] = air_1 material_library[air_2.metadata['name']] = air_2 assert_equal(gtag.print_near_match('air', material_library), list_of_matches)
def step5(cfg, cfg2, cfg5): """ This function creates the adjoint neutron source and writes the PARTISN input file for adjoint neutron transport. Parameters ---------- cfg : dictionary User input from 'general' section of config.yml file cfg2 : dictionary User input for step 2 from the config.yml file cfg5 : dictionary User input for step 3 from the config.yml file """ # Get user-input from config file num_n_groups = cfg['n_groups'] num_p_groups = cfg['p_groups'] n_geom = cfg2['n_geom_file'] decay_times = str(cfg2['decay_times']).split(' ') meshflux = cfg5['meshflux'] # Base of geometry file name basename = n_geom.split("/")[-1].split(".")[0] # The total number of photon and neutron energy groups total_num_groups = num_n_groups + num_p_groups # Read given flux file and tag to a mesh if meshflux: # Adjoint flux file is an hdf5 mesh file fw_n_err = meshflux m = Mesh(structured=True, mesh=fw_n_err, mats=None) else: raise RuntimeError("No neutron flux file given") # Size of flux tag is equal to the total number of energy groups m.ERROR_TAG = NativeMeshTag(num_n_groups, name="ERROR_TAG") fw_n_err = m.ERROR_TAG[:] # Load geometry and get material assignments load(n_geom) ml = MaterialLibrary(n_geom) mat_names = list(ml.keys()) cell_mats = cell_material_assignments(n_geom) # Load T matrix if not os.path.exists('step2_T.npy'): raise RuntimeError("T matrix from step 2 (step2_T.npy) not found") T = np.load('step2_T.npy') # Loop over mesh voxels and calculate the error in the photon source by multiplying neutron flux and T matrix dg = discretize_geom(m) for t, dt in enumerate(decay_times): temp = np.zeros(shape=(len(m), num_p_groups)) for i in range(len(m)): for row in np.atleast_1d(dg[dg["idx"] == i]): cell = row[1] if not cell_mats[cell] in mat_names: continue vol_frac = row[2] mat = mat_names.index(cell_mats[cell]) for h in range(num_p_groups): for g in range(num_n_groups): temp[i, h] += (fw_n_err[i, g]**2) * T[mat, t, g, h] * vol_frac print("err ", temp[i, h]) # Tag the mesh with the squared error in the photon source values tag_name = "sq_err_q_src_{0}".format(dt) m.err_q_src = NativeMeshTag(num_p_groups, name=tag_name) m.err_q_src[:] = temp # Save adjoint neutron source mesh file tagged with values for all decay times m.save("sq_err_q_src.h5m")
concrete_boronated_heavy = Material({ 'H': 0.0052, 'O': 0.3258, 'B': 0.003, 'C': 0.004, 'Si': 0.0223, 'Ca': 0.0655, 'Mg': 0.0021, 'Al': 0.0038, 'Fe': 0.5667, 'P': 0.0015, }) concrete_boronated_heavy.density = 3.6 concrete_boronated_heavy = concrete_boronated_heavy.expand_elements() mat_lib = MaterialLibrary() mat_lib["eurofer"] = eurofer mat_lib["Austenitic_steel_316L_N_IG"] = Austenitic_steel_316L_N_IG mat_lib["Pb15.8Li"] = Pb_15_8_Li mat_lib["Li4SiO4"] = Li4SiO4 mat_lib["beryllium"] = beryllium mat_lib["tungsten"] = tungsten mat_lib["CuCrZr"] = CuCrZr mat_lib["concrete_ordinary"] = concrete_ordinary mat_lib["concrete_heavy"] = concrete_heavy mat_lib["concrete_boronated_heavy"] = concrete_boronated_heavy os.system('rm materials.h5') mat_lib.write_hdf5("materials.h5") print('Finished creating Pyne materials, materials saved as "materials.h5"')
def merge_material_library(merged_libname, matlibs, datapaths=[], nucpaths=[]): """ Merge the different hdf5 PyNE material libraries into a single one and write the merged library in hdf5 format Parameters: merged_libname (str): name of the new library matlibs ([str]): list of the material library name to be merged datapaths ([str] -- optional ): list of the datapath for each library to merge, using \"/materials\" as default nucpaths ([str] -- optional ): list of the nucpath for each library to merge, using \"/nucid\" as default """ if len(datapaths) == 0: print("No datapaths provided, using \"/Materials\" as default.") for i in range(0, len(matlibs)): datapaths.append("/Materials") elif len(datapaths) != len(matlibs): print("!Error! Number of matlibs does not match number of datapaths") if len(nucpaths) == 0: print("No nucpaths provided, using \"/nucid\" as default.") for i in range(0, len(matlibs)): nucpaths.append("/nucpaths") elif len(nucpaths) != len(matlibs): print("!Error! Number of matlibs does not match number of nucpaths") merged_mat_library = MaterialLibrary() for index, (filename, datapath, nucpath) in enumerate(zip(matlibs, datapaths, nucpaths)): mat_lib = MaterialLibrary() mat_lib.from_hdf5(filename, datapath, nucpath) for item in mat_lib.items(): merged_mat_library.__setitem__(item[0], item[1]) merged_mat_library.write_hdf5(merged_libname, datapath="/materials", nucpath="/nucid")
def test_matlib_hdf5_nuc_data(): matlib = MaterialLibrary() matlib.from_hdf5(nuc_data, datapath="/material_library/materials", nucpath="/material_library/nucid")
# Return the material return material ############################## # Import materials from MCNP # ############################## mat = pyne_mcnp.mats_from_inp(input_mcnp_file) ################################### # Update materials for PyNE/DAGMC # ################################### # Add necessary data to the MCNP materials mat[1].density = 8.9 mat[1].metadata = {"name": "CuCrZr", "density_unit": "g/cm3"} mat[1] = set_xs_library(mat[1], fendl3) # Remove the pre-existing library file os.system('rm Materials.h5m -f') # Create a PyNE materials library object mat_lib = MaterialLibrary(mat) # Write the PyNE materials library to an HDF5 file for use in # DAGMC. Note that the datapath and nucpath must have the fixed # directory structure in order for DAGMC to find the materials mat_lib.write_hdf5(output_hdf5_file, datapath='/materials', nucpath='/nucid')
def write_mats_h5m(materials_list, filename): new_matlib = MaterialLibrary() for material in materials_list: # using fluka name as index since this is unique new_matlib[material.metadata['name']] = material new_matlib.write_hdf5(filename)
parser = argparse.ArgumentParser() parser.add_argument('-of', '--output_filename', type=str, default='materials.h5') args = parser.parse_args() output_filename = args.output_filename mcnp_lib_nbi_2017 = mats_from_inp("mcnp_models/DEMO_NBI_.i") mcnp_lib = mats_from_inp("mcnp_models/demo.inp") mcnp_lib_generic = mats_from_inp( "mcnp_models/2017_Generic_DEMO_MCNP_22_5deg_v1_1.txt") my_material_library = MaterialLibrary() #check_materials_are_the_same(mat1=mcnp_lib_generic[25],mat2=mcnp_lib_nbi_2017[25]) my_material_library['homogenised_magnet'] = mcnp_lib_generic[ 25].expand_elements() #my_material_library['homogenised_magnet'].metadata='homogenised_magnet used in the central sol, poloidal and toroidal magnets' my_material_library['SS-316L(N)-IG'] = mcnp_lib_generic[50].expand_elements() # my_material_library['SS-316L(N)-IG'].metadata='SS-316L(N)-IG used in the magnet casing and vacuum vessel skin, cyrostat and NBI vessel' my_material_library['SS316_vol_60_and_H2O_vol_40'] = mcnp_lib_generic[ 60].expand_elements() # my_material_library['SS316_vol_0.6_and_H2O_vol_0.4'].metadata='SS316 - 60%, H2O - 40% vacuum vessel middle section' materials = split_multimaterial_into_materials(mcnp_lib_generic[15])
#/usr/env python from pyne.material import Material, MaterialLibrary, MultiMaterial import os matlib = MaterialLibrary() Lead = Material({'Pb': 1.00}) Lead = Lead.expand_elements() Lead.name = "Lead" Lead.density = 11.36 matlib["Lead"] = Lead print Lead Iron = Material({'Fe': 1.00}) Iron = Iron.expand_elements() Iron.name = "Iron" Iron.density = 7.87 matlib["Iron"] = Iron print Iron #espi metals ss316 = Material({'Fe': 65.34, 'Cr': 17, 'Ni': 12, 'Mo': 2.5, 'Mn': 2.0, 'Si':1.00, 'C12':0.08, 'P':0.05, 'S': 0.03 }) ss316 = ss316.expand_elements() #ss316.name = "ss316" ss316.name = "m1" ss316.density = 8.03 #matlib["ss316"] = ss316 matlib["m1"] = ss316 print ss316
#!/usr/bin/python # from pyne.material import Material, MaterialLibrary print "Welcome!" mat_lib = MaterialLibrary() # # define iron for a shield ironvec = {260000: 1} # pure iron iron = Material() iron.density = 7.86 iron.from_atom_frac(ironvec) iron = iron.expand_elements() # to write out an mcnp material card iron.metadata['mat_number'] = 101 iron.write_mcnp('twoslab_mcard.txt', 'atom') # # # define a simple water since O-18 not in mcnp xs libs watervec = {10010000: 2, 80160000: 1} # simple water water = Material() water.density = 1.0 water.from_atom_frac(watervec) # to write out an mcnp material card water.metadata['mat_number'] = 102 water.write_mcnp('twoslab_mcard.txt', 'atom') # # define a low density simple water since O-18 not in mcnp xs libs watervec = {10010000: 2, 80160000: 1} # simple water lowdensitywater = Material() lowdensitywater.density = 0.9 lowdensitywater.from_atom_frac(watervec)