Пример #1
0
def test_material_add():
    matfile = get_user_materialsfile()
    savefile = matfile + '_Save'
    had_matfile = False
    if os.path.exists(matfile):
        had_matfile = True
        shutil.move(matfile, savefile)

    assert get_material('caffeine') is None

    add_material('caffeine', 'C8H10N4O2', density=1.23)
    assert get_material('caffeine') is not None

    time.sleep(2.0)

    add_material('rutile', 'TiO2', density=4.23)

    with open(matfile, 'r') as fh:
        text = fh.read()

    assert 'caffeine' in text
    assert 'rutile' in text

    if had_matfile:
        shutil.move(savefile, matfile)
Пример #2
0
def test_material_get():
    mat_  = {'kapton': ('C22H10N2O5', 1.43),
             'lead': ('Pb', 11.34),
             'aluminum': ('Al', 2.72),
             'water': ('H2O', 1.0)}

    for mname in mat_.keys():
        formula, density = get_material(mname)
        f1 = chemparse(formula)
        f2 = chemparse(mat_[mname][0])
        for k, v in f2.items():
            assert v == f1[k]
        assert_allclose(density, mat_[mname][1], rtol=0.1)
Пример #3
0
def test_material_get():
    mat_ = {
        'kapton': ('C22H10N2O5', 1.43),
        'lead': ('Pb', 11.34),
        'aluminum': ('Al', 2.72),
        'water': ('H2O', 1.0)
    }

    for mname in mat_.keys():
        formula, density = get_material(mname)
        f1 = chemparse(formula)
        f2 = chemparse(mat_[mname][0])
        for k, v in f2.items():
            assert v == f1[k]
        assert_allclose(density, mat_[mname][1], rtol=0.1)

    for formula, density in mat_.values():
        _f, _d = get_material(formula)
        assert _f == formula
        assert_allclose(density, _d, rtol=0.1)

    for formula in ('WSO3', 'CdAs140CO3', 'KAs'):
        out = get_material(formula)
        assert out == None
Пример #4
0
def test_material_mu2():
    en = np.linspace(5000, 10000, 21)
    known_mu = np.array([
        0.04934, 0.04267, 0.03715, 0.03254, 0.02866, 0.02538, 0.02257, 0.02016,
        0.01809, 0.01629, 0.01472, 0.01334, 0.01214, 0.01108, 0.01014, 0.00930,
        0.00856, 0.00789, 0.00729, 0.00675, 0.00626
    ])

    mu = material_mu('air', en)
    assert_allclose(mu, known_mu, rtol=0.05)

    air_formula, air_density = get_material('air')

    air_comps = chemparse(air_formula)

    assert air_comps['Ar'] < 0.013
    assert air_comps['Ar'] > 0.007

    mu = material_mu('air', en, density=2.0 * air_density)
    assert_allclose(mu, 2.0 * known_mu, rtol=0.05)