Example #1
0
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)
Example #2
0
def test_setitem_str():
    mat = Material(nucvec)
    assert_equal(mat.mass, 9.0)
    assert_equal(mat[922350], 1.0)
    mat['U235'] = 2.0
    assert_equal(mat.mass, 10.0)
    assert_equal(mat[922350], 2.0)

    mat = Material(leu)
    assert_equal(mat.mass, 1.0)
    assert_equal(mat[922350], 0.04)
    assert_equal(mat[922380], 0.96)
    assert_raises(KeyError, lambda: mat[922340])
    mat['U234'] = 17.0
    assert_equal(mat.mass, 18.0)
    assert_equal(mat[922340], 17.0)
    assert_equal(mat[922350], 0.04)
    assert_equal(mat[922380], 0.96)
Example #3
0
def test_natural_elements():
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    expected_comp = {
        10000000: 0.11189838783149784,
        80000000: 0.8881016121685023
    }
    for key in expected_comp:
        assert_almost_equal(water.comp[key], expected_comp[key])
Example #4
0
def test_getitem_sequence():
    mat = Material(nucvec)
    mat1 = mat[922380, 922350]
    assert_equal(mat1.mass, 2.0)
    assert_equal(set(mat1.keys()), set([922380, 922350]))

    mat1 = mat[922380, 'H2', 'h1']
    assert_equal(mat1.mass, 2.0)
    assert_equal(set(mat1.keys()), set([922380, 10010]))
Example #5
0
 def __init__(self, mass_msol, composition):
     self.mass_g = mass_msol * msun_to_cgs
     self.material = Material(self._normalize_composition(composition))
     self._pad_material()
     atomic_masses = self.get_masses()
     self.n_per_g = [
         1 / atomic_masses[item]
         for item in self.get_all_children_nuc_name()
     ]
Example #6
0
    def transmute(self,
                  x,
                  t=None,
                  phi=None,
                  tol=None,
                  log=None,
                  *args,
                  **kwargs):
        """Transmutes a material into its daughters.

        Parameters
        ----------
        x : Material or similar
            Input material for transmutation.
        t : float
            Transmutations time [sec].
        phi : float or array of floats
            Neutron flux vector [n/cm^2/sec].  Currently this must either be 
            a scalar or match the group structure of EAF.
        tol : float
            Tolerance level for chain truncation.
        log : file-like or None
            The log file object should be written. A None imples the log is 
            not desired.

        Returns
        -------
        y : Material
            The output material post-transmutation.

        """
        if not isinstance(x, Material):
            x = Material(x)
        if t is not None:
            self.t = t
        if phi is not None:
            self.phi = phi
        if log is not None:
            self.log = log
        if tol is not None:
            self.tol = tol

        x_atoms = x.to_atom_frac()
        y_atoms = {}
        for nuc, adens in x_atoms.items():
            # Find output for root of unit density and scale all output by
            # actual nuclide density and add to final output.
            partial = self._transmute_partial(nuc)
            for part_nuc, part_adens in partial.items():
                y_atoms[part_nuc] = part_adens * adens + y_atoms.get(
                    part_nuc, 0.0)
        mw_x = x.molecular_mass()
        y = from_atom_frac(y_atoms, atoms_per_molecule=x.atoms_per_molecule)
        # even though it doesn't look likt it, the following line is actually
        #   mass_y = MW_y * mass_x / MW_x
        y.mass *= x.mass / mw_x
        return y
Example #7
0
def test_metadatatag():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)
    m.doc = MetadataTag(m, 'doc', doc="extra documentaion")
    m.doc[:] = ['write', 'awesome', 'code', 'now']

    # Getting tags
    assert_equal(m.doc[0], 'write')
    assert_equal(m.doc[::2], ['write', 'code'])
    mask = np.array([True, False, True, True], dtype=bool)
    assert_equal(m.doc[mask], ['write', 'code', 'now'])
    assert_equal(m.doc[1, 0, 1, 3], ['awesome', 'write', 'awesome', 'now'])

    # setting tags
    m.doc[0] = 65.0
    assert_equal(m.doc[0], 65.0)

    m.doc[::2] = 18.0
    m.doc[1::2] = [36.0, 54.0]
    assert_array_equal(m.doc[:], np.array([18.0, 36.0, 18.0, 54.0]))

    mask = np.array([True, False, True, True], dtype=bool)
    m.doc[mask] = 9.0
    mask = np.array([True, True, False, False], dtype=bool)
    m.doc[mask] = (19.0, 29.0)
    assert_array_equal(m.doc[:], np.array([19.0, 29.0, 9.0, 9.0]))

    m.doc[[2]] = 28.0
    m.doc[3, 1] = 6.0, 4128.0
    assert_array_equal(m.doc[1:], np.array([4128.0, 28.0, 6.0]))

    # deleting tag
    del m.doc[:]
Example #8
0
def test_nativetag():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)
    m.f = NativeMeshTag(mesh=m, name='f')
    m.f[:] = [1.0, 2.0, 3.0, 4.0]

    # Getting tags
    assert_equal(m.f[0], 1.0)
    assert_array_equal(m.f[::2], [1.0, 3.0])
    mask = np.array([True, False, True, True], dtype=bool)
    assert_array_equal(m.f[mask], [1.0, 3.0, 4.0])
    assert_array_equal(m.f[1, 0, 1, 3], [2.0, 1.0, 2.0, 4.0])

    # setting tags
    m.f[0] = 65.0
    assert_equal(m.f[0], 65.0)

    m.f[::2] = 18.0
    m.f[1::2] = [36.0, 54.0]
    assert_array_equal(m.f[:], np.array([18.0, 36.0, 18.0, 54.0]))

    mask = np.array([True, False, True, True], dtype=bool)
    m.f[mask] = 9.0
    mask = np.array([True, True, False, False], dtype=bool)
    m.f[mask] = (19.0, 29.0)
    assert_array_equal(m.f[:], np.array([19.0, 29.0, 9.0, 9.0]))

    m.f[[2]] = 28.0
    m.f[3, 1] = 6.0, 4128.0
    assert_array_equal(m.f[1:], np.array([4128.0, 28.0, 6.0]))

    # deleting tag
    del m.f[:]
Example #9
0
def test_del_nativetag():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)
    m.f = NativeMeshTag(mesh=m, name='f')
    m.f[:] = [1.0, 2.0, 3.0, 4.0]
    m.g = NativeMeshTag(mesh=m, name='g')
    m.g[:] = [1.0, 2.0, 3.0, 4.0]

    assert_raises(ValueError, m.delete_tag, -12)

    import sys

    # make a new reference to the tag that will not
    # be deleted
    tag_ref = m.f

    # deleting tag by tag name
    m.delete_tag('f')

    # ensure that there are only 2 references to this tag
    # 1. is the tag_ref created above
    # 2. is the one that automatically is the temporary
    #    reference created as the argument to getrefcount
    assert_equal(2, sys.getrefcount(tag_ref))

    assert_raises(RuntimeError, m.mesh.tag_get_handle, 'f')

    # deleting tag by tag handle
    tag_ref = m.g
    m.delete_tag(m.g)
    assert_equal(2, sys.getrefcount(tag_ref))

    assert_raises(RuntimeError, m.mesh.tag_get_handle, 'g')
Example #10
0
def test_write_tape4():
    mat = Material({"U235": 0.95, 80160000: 0.05})
    tape4 = StringIO()
    origen22.write_tape4(mat, tape4)
    tape4.seek(0)
    observed = tape4.read()
    expected = ("1 80160 5.0000000000E-02   0 0   0 0   0 0\n"
                "2 922350 9.5000000000E-01   0 0   0 0   0 0\n"
                "0 0 0 0\n")
    assert_equal(observed, expected)
Example #11
0
 def test_act_2(self):
     mat = Material(nucvec)
     mat1 = mat.sub_act()
     assert_equal(mat1.comp[922350], 1.0 / 6.0)
     assert_equal(mat1.comp[922380], 1.0 / 6.0)
     assert_equal(mat1.comp[942390], 1.0 / 6.0)
     assert_equal(mat1.comp[942410], 1.0 / 6.0)
     assert_equal(mat1.comp[952420], 1.0 / 6.0)
     assert_equal(mat1.comp[962440], 1.0 / 6.0)
     assert_equal(mat1.mass, 6.0)
Example #12
0
def test_mat4():
    mat = Material({
        922350000: 0.05,
        922380000: 0.95
    },
                   15,
                   metadata={'units': 'kg'})
    assert_equal(mat.comp, {922350000: 0.05, 922380000: 0.95})
    assert_equal(mat.mass, 15.0)
    assert_equal(mat.metadata['units'], 'kg')
Example #13
0
def test_mesh_to_geom():

    if not HAVE_PYMOAB:
        raise SkipTest

    expected_geom = os.path.join(thisdir, "files_test_alara", "alara_geom.txt")
    expected_matlib = os.path.join(thisdir, "files_test_alara",
                                   "alara_matlib.txt")
    geom = os.path.join(os.getcwd(), "alara_geom")
    matlib = os.path.join(os.getcwd(), "alara_matlib")

    mats = {
        0: Material({'H1': 1.0, 'K39': 1.0}, density=1.1),
        1: Material({'H1': 0.1, 'O16': 1.0}, density=1.2),
        2: Material({'He4': 42.0}, density=1.3),
        3: Material({'Tm171': 171.0}, density=1.4),
    }
    m = Mesh(structured_coords=[[-1, 0, 1], [-1, 0, 1], [0, 1]], structured=True,
             mats=mats)
    mesh_to_geom(m, geom, matlib)

    with open(expected_geom) as f:
        written = f.readlines()

    with open(geom) as f:
        expected = f.readlines()

    assert_equal(written, expected)

    if os.path.isfile(geom):
        os.remove(geom)

    with open(expected_matlib) as f:
        written = f.readlines()

    with open(matlib) as f:
        expected = f.readlines()

    assert_equal(written, expected)

    if os.path.isfile(matlib):
        os.remove(matlib)
Example #14
0
def test_dump_json():
    leu = {"U238": 0.96, "U235": 0.04}
    exp = jsoncpp.Value({
        "mass": 1.0,
        "comp": leu,
        "density": -1.0,
        "metadata": {},
        "atoms_per_molecule": -1.0
    })
    obs = Material(leu).dump_json()
    assert_equal(exp, obs)
Example #15
0
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, "/mats1")
    rmatlib = MaterialLibrary()
    rmatlib.from_hdf5(filename, "/mats1")
    os.remove(filename)
    # Round trip!
    rmatlib.write_hdf5(filename, "/mats1")
    wmatlib = MaterialLibrary(filename, "/mats1")
    assert_equal(set(wmatlib), set(rmatlib))
    for key in rmatlib:
        assert_mat_almost_equal(wmatlib[key], rmatlib[key])
    os.remove(filename)
Example #16
0
def AtomicDensityToMassDensity(heu_atom):
    print "\n\n",heu_atom
    print "========heu_atom molecular mass ",heu_atom.molecular_mass()
    heu=Material()
    heu.from_atom_frac(heu_atom)
    print "\n\n",heu
    print "ERROR:  heu molecular mass is not correct heu.molecular_mass() = ", heu.molecular_mass()
    heu.metadata=heu_atom.metadata
    heu.metadata['density_g_per_cc']=heu.mass
    heu.normalize()
    return heu
Example #17
0
    def test_sub_range(self):
        mat = Material(nucvec)
        mat1 = mat.sub_range(920000, 930000)
        assert_equal(mat1.mass, 2.0)
        for nuc in mat1:
            assert_true(920000 <= nuc < 930000)

        mat1 = mat.sub_range(upper="U238")
        assert_equal(mat1.mass, 4.0)
        for nuc in mat1:
            assert_true(nuc < 922380)
Example #18
0
def test_matlib_query():
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."
    mat_nucvec = Material(nucvec)
    mat_nucvec.metadata["name"] = "nucvec"
    lib = {"nucvec": nucvec, "aqua": water}
    matlib = MaterialLibrary(lib)

    matlib_aqua = matlib["aqua"]
    assert_mat_almost_equal(water, matlib_aqua)

    matlib_nucvec = matlib["nucvec"]
    assert_mat_almost_equal(mat_nucvec, matlib_nucvec)

    mat_leu = Material(leu)
    mat_leu.metadata["name"] = "leu"
    matlib["leu"] = mat_leu
    matlib_leu = matlib["leu"]
    assert_mat_almost_equal(mat_leu, matlib_leu)
Example #19
0
def test_iter():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)
    j = 0
    idx_tag = m.mesh.getTagHandle('idx')
    for i, mat, ve in m:
        assert_equal(j, i)
        assert_is(mats[i], mat)
        assert_equal(j, idx_tag[ve])
        j += 1
Example #20
0
def test_with_external_data():

    mat = Material(nucvec, density=7.8)
    mat = mat.expand_elements()

    assert_equal(id("He3") in mat.comp, False)
    assert_equal(id("Co58") in mat.comp, False)
    assert_equal(id("Ni58") in mat.comp, False)

    assert_equal(id("H1") in mat.comp, True)
    assert_equal(id("Fe56") in mat.comp, True)
    assert_equal(id("Mn55") in mat.comp, True)
def test_with_external_data():

    mat = Material(nucvec, density=7.8)
    mat = mat.expand_elements()

    assert_equal(id('He3') in mat.comp, False)
    assert_equal(id('Co58') in mat.comp, False)
    assert_equal(id('Ni58') in mat.comp, False)

    assert_equal(id('H1') in mat.comp, True)
    assert_equal(id('Fe56') in mat.comp, True)
    assert_equal(id('Mn55') in mat.comp, True)
Example #22
0
def test_iter():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)
    j = 0
    idx_tag = m.mesh.tag_get_handle('idx')
    for i, mat, ve in m:
        assert_equal(j, i)
        assert_is(mats[i], mat)
        assert_equal(j, m.mesh.tag_get_data(idx_tag, ve, flat=True)[0])
        j += 1
Example #23
0
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"])
Example #24
0
def test_mesh_to_geom():
    if not HAVE_PYTAPS:
        raise SkipTest

    mats = {
        0: Material({'H1': 1.0, 'K39': 1.0}, density=42.0),
        1: Material({'H1': 0.1, 'O16': 1.0}, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
        4: Material({'C12': 1.0}, density=47.0),
        5: Material({'1002': 1.0}, density=5.0),
    }

    m = Mesh(structured_coords=[[0, 1, 2, 3], [0, 1, 2], [0, 1]], mats=mats,
             structured=True)

    geom = mcnp.mesh_to_geom(m)

    exp_geom = (
        "Generated from PyNE Mesh\n"
        "1 1 42.0 1 -2 5 -6 8 -9\n"
        "2 2 43.0 1 -2 6 -7 8 -9\n"
        "3 3 44.0 2 -3 5 -6 8 -9\n"
        "4 4 45.0 2 -3 6 -7 8 -9\n"
        "5 5 47.0 3 -4 5 -6 8 -9\n"
        "6 6 5.0 3 -4 6 -7 8 -9\n"
        "7 0 -1:4:-5:7:-8:9\n"
        "\n"
        "1 px 0.0\n"
        "2 px 1.0\n"
        "3 px 2.0\n"
        "4 px 3.0\n"
        "5 py 0.0\n"
        "6 py 1.0\n"
        "7 py 2.0\n"
        "8 pz 0.0\n"
        "9 pz 1.0\n"
        "\n"
        "C density = 42.0\n"
        "m1\n"
        "     1001 -5.0000e-01\n"
        "     19039 -5.0000e-01\n"
        "C density = 43.0\n"
        "m2\n"
        "     1001 -9.0909e-02\n"
        "     8016 -9.0909e-01\n"
        "C density = 44.0\n"
        "m3\n"
        "     2004 -1.0000e+00\n"
        "C density = 45.0\n"
        "m4\n"
        "     69171 -1.0000e+00\n"
        "C density = 47.0\n"
        "m5\n"
        "     6012 -1.0000e+00\n"
        "C density = 5.0\n"
        "m6\n"
        "     1002 -1.0000e+00\n")

    assert_equal(geom, exp_geom)
Example #25
0
def test_matproptag():
    mats = {
        0: Material({
            'H1': 1.0,
            'K39': 1.0
        }, density=42.0),
        1: Material({
            'H1': 0.1,
            'O16': 1.0
        }, density=43.0),
        2: Material({'He4': 42.0}, density=44.0),
        3: Material({'Tm171': 171.0}, density=45.0),
    }
    m = gen_mesh(mats=mats)

    # Getting tags
    assert_equal(m.density[0], 42.0)
    assert_array_equal(m.density[::2], np.array([42.0, 44.0]))
    mask = np.array([True, False, True, True], dtype=bool)
    assert_array_equal(m.density[mask], np.array([42.0, 44.0, 45.0]))
    assert_array_equal(m.density[1, 0, 1, 3],
                       np.array([43.0, 42.0, 43.0, 45.0]))

    # setting tags
    m.density[0] = 65.0
    assert_equal(m.density[0], 65.0)

    m.density[::2] = 18.0
    m.density[1::2] = [36.0, 54.0]
    assert_array_equal(m.density[:], np.array([18.0, 36.0, 18.0, 54.0]))

    mask = np.array([True, False, True, True], dtype=bool)
    m.density[mask] = 9.0
    mask = np.array([True, True, False, False], dtype=bool)
    m.density[mask] = (19.0, 29.0)
    assert_array_equal(m.density[:], np.array([19.0, 29.0, 9.0, 9.0]))

    m.density[[2]] = 28.0
    m.density[3, 1] = 6.0, 4128.0
    assert_array_equal(m.density[1:], np.array([4128.0, 28.0, 6.0]))
Example #26
0
def test_expand_elements1():
    natmat = Material({
        'C': 1.0,
        902320000: 0.5,
        'PU': 4.0,
        'U': 3.0
    },
                      metadata={'y': 1.0})
    expmat = natmat.expand_elements()
    assert_true(60120000 in expmat.comp)
    assert_false(60000000 in expmat.comp)
    assert_true(natmat.metadata == expmat.metadata)
    assert_false(natmat.metadata is expmat.metadata)
Example #27
0
def test_default_uranium_cascade():
    casc = enr.default_uranium_cascade()
    assert_equal(casc.alpha, 1.05)
    assert_equal(casc.Mstar, 236.5)
    assert_equal(casc.j, 922350)
    assert_equal(casc.k, 922380)
    assert_equal(casc.N, 30.0)
    assert_equal(casc.M, 10.0)
    assert_equal(casc.x_feed_j, 0.0072)
    assert_equal(casc.x_prod_j, 0.05)
    assert_equal(casc.x_tail_j, 0.0025)
    assert_equal(casc.mat_feed, Material({922340: 5.5e-05, 922350: 0.0072, 
                                922380: 0.992745}, 1.0, 1.0))
Example #28
0
def test_map_str_material():
    m = MapStrMaterial()
    m['leu'] = Material(leu)
    m['heu'] = Material({'U238': 0.01, 'U235': 0.99}, 42.0)
    assert_equal(len(m), 2)
    assert_equal(m['leu'].mass, 1.0)
    assert_equal(m['leu']['U235'], 0.04)
    assert_equal(m['heu'].mass, 42.0)
    assert_equal(m['heu']['U238'], 0.42)

    m = MapStrMaterial({
        'leu': Material(leu),
        'heu': Material({
            'U238': 0.01,
            'U235': 0.99
        }, 42.0)
    })
    assert_equal(len(m), 2)
    assert_equal(m['leu'].mass, 1.0)
    assert_equal(m['leu']['U235'], 0.04)
    assert_equal(m['heu'].mass, 42.0)
    assert_equal(m['heu']['U238'], 0.42)

    n = MapStrMaterial(m, False)
    assert_equal(len(n), 2)
    assert_equal(n['leu'].mass, 1.0)
    assert_equal(n['leu']['U235'], 0.04)
    assert_equal(n['heu'].mass, 42.0)
    assert_equal(n['heu']['U238'], 0.42)

    # points to the same underlying map
    n['other'] = Material({'PU239': 15.0})
    assert_equal(m['other'].mass, 15.0)
    assert_equal(m['other']['PU239'], 15.0)

    assert_equal(n['leu'].mass, 1.0)
    assert_equal(n['leu']['U235'], 0.04)
    assert_equal(n['heu'].mass, 42.0)
    assert_equal(n['heu']['U238'], 0.42)
def test_with_internal_data():
    orig = pyne_conf.NUC_DATA_PATH
    pyne_conf.NUC_DATA_PATH = b'thisisanonsensedatapath'

    mat = Material(nucvec, density=7.8)
    mat = mat.expand_elements()
    assert_equal(id('He3') in mat.comp, False)
    assert_equal(id('Co58') in mat.comp, False)
    assert_equal(id('Ni58') in mat.comp, False)

    assert_equal(id('H1') in mat.comp, True)
    assert_equal(id('Fe56') in mat.comp, True)
    assert_equal(id('Mn55') in mat.comp, True)
Example #30
0
def test_write_mcnp():
    if 'mcnp_mass_fracs.txt' in os.listdir('.'):
        os.remove('mcnp_mass_fracs.txt')

    leu = Material(nucvec={
        'U235': 0.04,
        'U238': 0.96
    },
                   metadata={
                       'mat_number':
                       2,
                       'table_ids': {
                           '92235': '15c',
                           '92238': '25c'
                       },
                       'mat_name':
                       'LEU',
                       'source':
                       'Some URL',
                       'comments':
                       ('this is a long comment that will definitly '
                        'go over the 80 character limit, for science'),
                       'name':
                       'leu'
                   },
                   density=19.1)

    leu.write_mcnp('mcnp_mass_fracs.txt')
    leu.write_mcnp('mcnp_mass_fracs.txt', frac_type='atom')

    with open('mcnp_mass_fracs.txt') as f:
        written = f.read()
    expected = (
        'C name: leu\n'
        'C density = 19.1\n'
        'C source: Some URL\n'
        'C comments: this is a long comment that will definitly go over the 80 character\n'
        'C  limit, for science\n'
        'm2\n'
        '     92235.15c -4.0000E-02\n'
        '     92238.25c -9.6000E-01\n'
        'C name: leu\n'
        'C density = 19.1\n'
        'C source: Some URL\n'
        'C comments: this is a long comment that will definitly go over the 80 character\n'
        'C  limit, for science\n'
        'm2\n'
        '     92235.15c 4.0491E-02\n'
        '     92238.25c 9.5951E-01\n')
    assert_equal(written, expected)
    os.remove('mcnp_mass_fracs.txt')