예제 #1
0
def test_composite():
    from periodictable.nsf import neutron_composite_sld
    calc = neutron_composite_sld([formula(s) for s in ('HSO4', 'H2O', 'CCl4')],
                                 wavelength=4.75)
    sld = calc(np.array([3, 1, 2]), density=1.2)
    sld2 = neutron_sld('3HSO4+1H2O+2CCl4', density=1.2, wavelength=4.75)
    #print(sld)
    #print(sld2)
    assert all(abs(v - w) < 1e-14 for v, w in zip(sld, sld2))
예제 #2
0
def test_composite():
    from periodictable.nsf import neutron_composite_sld
    calc = neutron_composite_sld([formula(s) for s in ('HSO4','H2O','CCl4')],
                                 wavelength=4.75)
    sld = calc(numpy.array([3,1,2]),density=1.2)
    sld2 = neutron_sld('3HSO4+1H2O+2CCl4',density=1.2,wavelength=4.75)
    #print(sld)
    #print(sld2)
    assert all(abs(v-w)<1e-14 for v,w in zip(sld,sld2))
예제 #3
0
def time_composite():
    from periodictable.nsf import neutron_composite_sld
    import time
    calc = neutron_composite_sld([formula(s) for s in ('HSO4','H2O','CCl4')],
                                 wavelength=4.75)
    q = numpy.array([3,1,2])
    N = 1000
    bits = [formula(s) for s in ('HSO4','H2O','CCl4')]
    tic = time.time()
    for i in range(N):
        sld = calc(q,density=1.2)
    toc = time.time()-tic
    print("composite %.1f us"%(toc/N*1e6))
    tic = time.time()
    for i in range(N):
        sld = neutron_sld(q[0]*bits[0]+q[1]*bits[1]+q[2]*bits[2],
                          density=1.2,wavelength=4.75)
    toc = time.time()-tic
    print("direct %.1f us"%(toc/N*1e6))
예제 #4
0
def time_composite():
    from periodictable.nsf import neutron_composite_sld
    import time
    calc = neutron_composite_sld([formula(s) for s in ('HSO4', 'H2O', 'CCl4')],
                                 wavelength=4.75)
    q = np.array([3, 1, 2])
    N = 1000
    bits = [formula(s) for s in ('HSO4', 'H2O', 'CCl4')]
    tic = time.time()
    for i in range(N):
        sld = calc(q, density=1.2)
    toc = time.time() - tic
    print("composite %.1f us" % (toc / N * 1e6))
    tic = time.time()
    for i in range(N):
        sld = neutron_sld(q[0] * bits[0] + q[1] * bits[1] + q[2] * bits[2],
                          density=1.2,
                          wavelength=4.75)
    toc = time.time() - tic
    print("direct %.1f us" % (toc / N * 1e6))