• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mcni.neutron_buffer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mcni.neutron_buffer函数的典型用法代码示例。如果您正苦于以下问题:Python neutron_buffer函数的具体用法?Python neutron_buffer怎么用?Python neutron_buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了neutron_buffer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

    def main(self, *args, **kwds):
        if self.inventory.dumpregistry:
            self._dumpRegsitry()
            return
        
        import mcni
        instrument = self._createInstrument()
        
        geometer = self.geometer

        context = self._makeSimContext()
        
        if self.ncount < self.buffer_size:
            self.buffer_size = int(self.ncount)
        n = int(self.ncount / self.buffer_size)
        
        from mcni import journal
        logger = journal.logger(
            'info', 'instrument', header='', footer='', format='-> %s')
        for i in range(n):
            logger("mpi node %s at loop %s" % (self.mpi.rank, i))
            neutrons = mcni.neutron_buffer( self.buffer_size )
            context.iteration_no = i
            mcni.simulate( instrument, geometer, neutrons, context=context)
            continue
        
        remain = int(self.ncount % self.buffer_size)
        if remain:
            logger("mpi node %s at last loop" % (self.mpi.rank,))
            neutrons = mcni.neutron_buffer(remain)
            context.iteration_no = n
            mcni.simulate( instrument, geometer, neutrons, context=context)
            
        print os.times()
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:35,代码来源:Instrument.py


示例2: test4

 def test4(self):
     "neutron buffer: swap"
     from mcni import neutron_buffer
     b1 = neutron_buffer(1)
     b2 = neutron_buffer(2)
     b1.swap(b2)
     self.assertEqual(len(b1), 2)
     self.assertEqual(len(b2), 1)
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:9,代码来源:neutron_TestCase.py


示例3: test5

 def test5(self):
     "neutron buffer: appendNeutrons"
     from mcni import neutron_buffer
     b1 = neutron_buffer(1)
     b2 = neutron_buffer(2)
     
     b1.appendNeutrons(b2, 0, len(b2))
     self.assertEqual(len(b1), 3)
     
     b1.appendNeutrons(b2)
     self.assertEqual(len(b1), 5)
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:12,代码来源:neutron_TestCase.py


示例4: test2a

 def test2a(self):
     'normalize: large buffer'
     import mcni
     # create a dummy input
     neutrons = mcni.neutron_buffer( int(3e6) )
     narr = neutrons.to_npyarr()
     narr[:, -1] = 1
     neutrons.from_npyarr(narr)
     out = 'tmp-nst-test2a.ns'
     mns.dump(neutrons, out)
     del neutrons
     
     # try normalize out-of-place
     out2 = 'tmp-nst-test2a-normalized.ns'
     if os.path.exists(out2): os.remove(out2)
     mns.normalize(out, 10., out2)
     neutrons2 = mns.load(out2)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     del neutrons2, narr
     
     # try normalize in-place
     mns.normalize(out, 10.)
     neutrons2 = mns.load(out)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:29,代码来源:neutron_storage_TestCase.py


示例5: test2

    def test2(self):
        'normalize'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer( 10 )
        for n in neutrons:
            n.probability = 1
            continue
        out = 'tmp-nst-test2.ns'
        mns.dump(neutrons, out)

        # try normalize out-of-place
        out2 = 'tmp-nst-test2-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:29,代码来源:neutron_storage_TestCase.py


示例6: test1

    def test1(self):
        'mccomponents.sample.samplecomponent: IsotropicKernel'
        import mcni
        neutron = mcni.neutron( r = (0,0,0), v = (0,0,3000), time = 0, prob = 1 )
        from mcni.components.MonochromaticSource import MonochromaticSource
        component1 = MonochromaticSource('source', neutron)
        from mccomponents.sample import samplecomponent
        component2 = samplecomponent( 'Al', 'sampleassemblies/Al-isotropickernel/sampleassembly.xml' )
        instrument = mcni.instrument( [component1, component2] )
        
        geometer = mcni.geometer()
        geometer.register( component1, (0,0,0), (0,0,0) )
        geometer.register( component2, (0,0,1), (0,0,0) )

        N0 = 1000
        neutrons = mcni.neutron_buffer(N0)

        mcni.simulate( instrument, geometer, neutrons )

        N = len(neutrons)

        for i in range(10):
            neutron = neutrons[i]
            print neutron
            continue

        # N should be about 2/3 of N0. this is determined by
        # the mc weights in Al-isotropic-kernel-plate-scatterer.xml
        self.assert_( N < 0.72*N0 and N > 0.6*N0)

        return
开发者ID:mcvine,项目名称:mcvine,代码行数:31,代码来源:samplecomponent_IsotropicKernel_TestCase.py


示例7: test

    def test(self):
        'mcni.pyre_components.NeutronsOnCone_FixedQE'
        from mcni.pyre_components.NeutronsOnCone_FixedQE import NeutronsOnCone_FixedQE as factory
        component = factory( 'source' )
        component.inventory.Q = Q
        component.inventory.E = E
        component.inventory.Ei = Ei
        component.inventory.L1 = L1
        component._configure()
        component._init()

        import mcni
        neutrons = mcni.neutron_buffer( 10 )
        component.process( neutrons )
        from numpy.linalg import norm
        from mcni.utils import v2e, e2v, v2k
        vi = e2v( Ei )
        t = L1/vi
        for n in neutrons:
            vv = n.state.velocity
            vQv = -vv[0], -vv[1], vi-vv[2]
            vQ = norm(vQv)
            Q1 = v2k(vQ)
            v = norm( vv )
            self.assertAlmostEqual( v2e(v), Ei-E, 4)
            self.assertAlmostEqual( n.time, t, 4 )
            self.assertAlmostEqual( Q, Q1, 4 )
            continue

        component._fini()
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:31,代码来源:NeutronsOnCone_FixedQE_TestCase.py


示例8: test1

    def test1(self):
        'NDMonitor'
        
        from mcni.components.NDMonitor import NDMonitor, Axis
        xaxis = Axis(
            name = 'x', expression='x',
            bins = 100, range=(0, 1000.),
            unit = 'meter',
            )
        m = NDMonitor('abc', [xaxis])
        
        N = 100
        from mcni import neutron_buffer, neutron
        b = neutron_buffer(N)
        for i in range(N):
            b[i] = neutron()
            continue

        m.process(b)

        self.assertEqual(m.histogram.I[0], N)
        self.assertEqual(m.histogram.E2[0], N)
        self.assertEqual(m.histogram.I[1], 0.)
        self.assertEqual(m.histogram.E2[1], 0.)

        if interactive:
            from histogram.plotter import defaultPlotter as plotter
            plotter.plot(m.histogram)
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:29,代码来源:NDMonitor_TestCase.py


示例9: neutrons_from_npyarr

def neutrons_from_npyarr(arr, neutrons=None):
    """copy data from a numpy array to a boost python instance of
    Neutron::Events.

    arr: the numpy array
    neutrons: the Neutron::Events instance where data will be copied.
      if None, a new instance will be created.
    """
    shape = arr.shape
    assert shape[1] == ndblsperneutron
    n = len(arr)

    if neutrons is None:
        import mcni

        neutrons = mcni.neutron_buffer(n)
        pass

    n = min(n, len(neutrons))

    cevents = binding.cevents_from_npyarr(arr)

    neutrons.fromCevents(cevents, n)

    return neutrons
开发者ID:mcvine,项目名称:mcvine,代码行数:25,代码来源:__init__.py


示例10: test2

 def test2(self):
     'shape positioning: cylinder with axis along beam'
     # source
     from mcni.components.MonochromaticSource import MonochromaticSource
     import mcni
     neutron = mcni.neutron(r=(0,0,-1), v=(0,0,1000), prob=1)
     source = MonochromaticSource('s', neutron, dx=0.09, dy=0.09, dE=0)
     # sample
     from mccomponents.sample import samplecomponent
     scatterer = samplecomponent('sa', 'cyl-along-beam/sampleassembly.xml' )
     # neutrons
     N = 1000
     neutrons = mcni.neutron_buffer(N)
     neutrons = source.process(neutrons)
     # find neutrons out of target
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     missing = x*x+y*y > 0.04**2
     # print neutrons
     scatterer.process(neutrons)
     # print neutrons
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     assert (z[missing] < -.9).all()
     hit = arr[np.logical_not(missing), :3]
     x,y,z = hit.T
     assert (z > -.1).all()
     assert (np.isclose((x*x + y*y)**.5, 0.04) | np.isclose(np.abs(z), 0.005)).all()
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:29,代码来源:cylinder_TestCase.py


示例11: test

    def test(self):
        "Source_simple --> E_monitor"
        from mcstas2 import componentfactory
        ssimplefac = componentfactory( 'sources', 'Source_simple' )
        ssimple = ssimplefac(
            'ssimple',
            radius=0.1, dist=2, xw=0.1, yh=0.1, E0=55, dE=2)
        
        from mcstas2.wrappers import wrap
        wrap( 'E_monitor.comp', 'monitors' ) 
        emonfac = componentfactory( 'monitors', 'E_monitor' )
        emon = emonfac(
            'emon',
            nchan=20, filename="e.dat",
            xmin=-0.2, xmax=0.2,
            ymin=-0.2, ymax=0.2,
            Emin=50, Emax=60)

        import mcni
        instrument = mcni.instrument( [ssimple, emon] )

        geometer = mcni.geometer()
        geometer.register( ssimple, (0,0,0), (0,0,0) )
        geometer.register( emon, (0,0,1), (0,0,0) )

        neutrons = mcni.neutron_buffer( 100 )

        mcni.simulate( instrument, geometer, neutrons )

        return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:30,代码来源:Source_simple_to_E_monitor_TestCase.py


示例12: test3

    def test3(self):
        'neutron_storage.Storage: wrap-reading (nread>ntotal)'

        path = 'test-storage-3'
        if os.path.exists(path):
            os.remove( path )
        
        from mcni.neutron_storage.Storage import Storage

        #open storage for writing
        s = Storage( path, 'w' )

        #create neutrons
        import mcni
        neutrons = mcni.neutron_buffer( 7 )
        for i in range(7):
            neutrons[i] = mcni.neutron( v = (i,0,0) )

        #write 
        s.write( neutrons )

        # flush
        del s
        
        #open the storage for reading
        sr = Storage( path, 'r', packetsize=10)

        neutrons = sr.read()
        self.assertEqual( len(neutrons), 10 )
        self.assertAlmostEqual( neutrons[5].state.velocity[0] , 5 )
        self.assertAlmostEqual( neutrons[9].state.velocity[0] , 2 )

        neutrons = sr.read()
        self.assertAlmostEqual( neutrons[0].state.velocity[0] , 3 )
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:35,代码来源:Storage_TestCase.py


示例13: test

    def test(self):
        'neutron_storage.Storage: write and then read'

        path = 'test-storage'
        if os.path.exists(path):
            os.remove( path )
        
        from mcni.neutron_storage.Storage import Storage

        #open storage for writing
        s = Storage( path, 'w' )

        #create neutrons
        import mcni
        neutrons = mcni.neutron_buffer( 7 )
        neutrons[5] = mcni.neutron( v = (8,9,10) )

        #write neutrons
        s.write( neutrons )

        #delete the storage to make sure it flushes all neutrons
        del s

        #open the storage for reading
        sr = Storage( path, 'r')
        neutrons = sr.read()
        self.assertEqual( len(neutrons), 7 )

        self.assertAlmostEqual( neutrons[5].state.velocity[0] , 8 )
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:30,代码来源:Storage_TestCase.py


示例14: test5

    def test5(self):
        'neutron_storage.Storage: wrap-reading (nread>>ntotal)'

        path = 'test-storage-4'
        if os.path.exists(path):
            os.remove( path )
        
        from mcni.neutron_storage.Storage import Storage

        #open storage for writing
        s = Storage( path, 'w' )

        #create neutrons
        import mcni
        neutrons = mcni.neutron_buffer( 5 )
        for i in range(5):
            neutrons[i] = mcni.neutron( v = (i,0,0) )

        #write 
        s.write( neutrons )

        # flush
        del s
        
        #open the storage for reading
        sr = Storage( path, 'r')

        neutrons = sr.read(100)
        self.assertEqual( len(neutrons), 100 )
        self.assertAlmostEqual( neutrons[3].state.velocity[0] , 3 )
        self.assertAlmostEqual( neutrons[4].state.velocity[0] , 4 )
        self.assertAlmostEqual( neutrons[6].state.velocity[0] , 1 )
        self.assertAlmostEqual( neutrons[7].state.velocity[0] , 2 )

        return
开发者ID:mcvine,项目名称:mcvine,代码行数:35,代码来源:Storage_TestCase.py


示例15: test1

 def test1(self):
     'shape positioning: plate perp to beam'
     # source
     from mcni.components.MonochromaticSource import MonochromaticSource
     import mcni
     neutron = mcni.neutron(r=(0,0,-1), v=(0,0,1000), prob=1)
     source = MonochromaticSource('s', neutron, dx=0.07, dy=0.09, dE=0)
     # sample
     from mccomponents.sample import samplecomponent
     scatterer = samplecomponent('sa', 'plate/sampleassembly.xml' )
     # neutrons
     N = 1000
     neutrons = mcni.neutron_buffer(N)
     neutrons = source.process(neutrons)
     # find neutrons out of target
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     missing = (x>0.03) | (x<-0.03) | (y>0.04) | (y<-0.04)
     # print neutrons
     scatterer.process(neutrons)
     # print neutrons
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     assert (z[missing] < -.9).all()
     hit = arr[np.logical_not(missing), :3]
     x,y,z = hit.T
     assert (z > -.1).all()
     assert (np.isclose(np.abs(x), 0.03) | np.isclose(np.abs(y), 0.04) | np.isclose(np.abs(z), 0.005)).all()
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:29,代码来源:plate_TestCase.py


示例16: _normalize

def _normalize(input, N, output):
    """normalize the neutrons in the given file by the factor N
    and save it in the output
    """
    import os
    input = os.path.abspath(input)
    output = os.path.abspath(output)
    # guards
    assert input != output
    if os.path.exists(output):
        raise IOError('%s already exists' % output)
    # total # of neutrons
    remain = count(input)
    # output storage
    out = storage(output, mode='w')
    # input storage
    input = storage(input)
    #
    chunk = int(1e6)
    # 
    from mcni import neutron_buffer
    nb = neutron_buffer(0)
    while remain:
        n = min(remain, chunk)
        # read
        neutrons = input.read(n, asnpyarr=True)
        # normalize
        neutrons[:, -1] /= N
        # write
        nb.from_npyarr(neutrons)
        out.write(nb)
        #
        remain -= n
        continue
    return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:35,代码来源:__init__.py


示例17: test2

 def test2(self):
     'shape positioning: rotated sphere'
     # source
     from mcni.components.MonochromaticSource import MonochromaticSource
     import mcni
     neutron = mcni.neutron(r=(0,0,-1), v=(0,0,1000), prob=1)
     source = MonochromaticSource('s', neutron, dx=0.10, dy=0.09, dE=0)
     # sample
     from mccomponents.sample import samplecomponent
     scatterer = samplecomponent('sa', 'sphere-rotated-arbitrarily/sampleassembly.xml' )
     # neutrons
     N = 1000
     neutrons = mcni.neutron_buffer(N)
     neutrons = source.process(neutrons)
     # find neutrons out of target
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     missing = x*x+y*y>0.05*0.05
     # print "missed:", missing.sum()
     # print neutrons
     scatterer.process(neutrons)
     # print neutrons
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     assert (z[missing] < -.9).all()
     hit = arr[np.logical_not(missing), :3]
     x,y,z = hit.T
     assert (z > -.1).all()
     assert np.isclose(np.abs(x*x+y*y+z*z), 0.05*0.05).all()
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:30,代码来源:sphere_TestCase.py


示例18: test1

    def test1(self):
        'mccomponents.sample.samplecomponent isotropic kernel, multiple-scattering'
        import mcni
        neutron = mcni.neutron( r = (0,0,0), v = (0,0,3000), time = 0, prob = 1 )
        from mcni.components.MonochromaticSource import MonochromaticSource
        component1 = MonochromaticSource('source', neutron)
        from mccomponents.sample import samplecomponent
        component2 = samplecomponent( 'Al', 'sampleassemblies/Al-isotropickernel/sampleassembly.xml' )
        instrument = mcni.instrument( [component1, component2] )
        
        geometer = mcni.geometer()
        geometer.register( component1, (0,0,0), (0,0,0) )
        geometer.register( component2, (0,0,1), (0,0,0) )

        N0 = 1
        neutrons = mcni.neutron_buffer(N0)

        mcni.simulate( instrument, geometer, neutrons, multiple_scattering=True)

        N = len(neutrons)

        for i in range(N):
            neutron = neutrons[i]
            print neutron
            continue

        return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:27,代码来源:samplecomponent_IsotropicKernel_multiplescattering_TestCase.py


示例19: make_neutrons

 def make_neutrons(N):
     neutrons = mcni.neutron_buffer(N)
     #
     # randomly select E, the energy transfer
     E = core.Emin + np.random.random(N) * (core.Emax-core.Emin)
     # the final energy
     Ef = core.Ei - E
     # the final velocity
     vf = conversion.e2v(Ef)
     # choose cos(theta) between -1 and 1
     cos_t = np.random.random(N) * 2 - 1
     # theta
     theta = np.arccos(cos_t)
     # sin(theta)
     sin_t = np.sin(theta)
     # phi: 0 - 2pi
     phi = np.random.random(N) * 2 * np.pi
     # compute final velocity vector
     vx,vy,vz = vf*sin_t*np.cos(phi), vf*sin_t*np.sin(phi), vf*cos_t
     # neutron position, spin, tof are set to zero
     x = y = z = sx = sy = t = np.zeros(N, dtype="float64")
     # probability
     prob = np.ones(N, dtype="float64") * (vf/vi)
     # XXX: this assumes a specific data layout of neutron struct
     n_arr = np.array([x,y,z,vx,vy,vz, sx,sy, t, prob]).T.copy()
     neutrons.from_npyarr(n_arr)
     return neutrons
开发者ID:mcvine,项目名称:mcvine,代码行数:27,代码来源:IQE_monitor.py


示例20: test1

    def test1(self):
        'mccomponents.sample.samplecomponent'
        import mcni
        neutron = mcni.neutron( r = (0,0,0), v = (0,0,4149.48), time = 0, prob = 1 )
        from mcni.components.MonochromaticSource import MonochromaticSource
        component1 = MonochromaticSource('source', neutron)
        from mccomponents.sample import samplecomponent
        component2 = samplecomponent( 'V-constantE', 'sampleassemblies/V-constantE/sampleassembly.xml' )
        instrument = mcni.instrument( [component1, component2] )
        
        geometer = mcni.geometer()
        geometer.register( component1, (0,0,0), (0,0,0) )
        geometer.register( component2, (0,0,1), (0,0,0) )
        
        neutrons = mcni.neutron_buffer( 1 )
        
        from mcni.pyre_support.ConsoleNeutronTracer import ConsoleNeutronTracer
        tracer = ConsoleNeutronTracer()
        mcni.simulate( 
            instrument, geometer, neutrons, 
            multiple_scattering=True,
            tracer = tracer
            )

        return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:25,代码来源:samplecomponent_multiplescattering_3_TestCase.py



注:本文中的mcni.neutron_buffer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Instrument.Instrument类代码示例发布时间:2022-05-27
下一篇:
Python mcni.neutron函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap