当前位置: 首页>>代码示例>>Python>>正文


Python mcni.neutron函数代码示例

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


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

示例1: test2

 def test2(self):
     "neutron"
     # creating instances
     from mcni import neutron
     n = neutron(r=(0,0,0), v=(0,0,3000))
     n = neutron(r=(0,0,0), v=(0,0,3000), time=1000.)
     n = neutron(r=(0,0,0), v=(0,0,3000), time=1000., prob=10.)
     n = neutron(r=(0,0,0), v=(0,0,3000), s=(0,1), time=1000., prob=10.)
     # printing
     print n
     print n.state
     print n.state.velocity
     # setting values
     n.state.position = mcni.position(1,2,3)
     self.assertEqual(tuple(n.state.position), (1,2,3))
     n.state.velocity = mcni.velocity(1,2,3)
     self.assertEqual(tuple(n.state.velocity), (1,2,3))
     n.state.spin = mcni.spin(1,0)
     self.assertEqual(n.state.spin.s1, 1)
     self.assertEqual(n.state.spin.s2, 0)
     n.time = 999
     self.assertEqual(n.time, 999)
     n.probability = 888
     self.assertEqual(n.probability, 888)
     return
开发者ID:mcvine,项目名称:mcvine,代码行数:25,代码来源:neutron_TestCase.py

示例2: test_scatterercopy

    def test_scatterercopy(self):
        '''scatterercopy'''
        # create a weird shape
        from mccomposite.geometry import primitives
        shape = primitives.block( (1,1,1) )

        #create pure python representation of scatterer composite
        composite1 = mccomposite.composite( shape )
        nprinter = NeutronPrinter( shape )
        composite1.addElement( nprinter )
        #create a copy
        copy = mccomposite.scatterercopy( composite1 )
        
        #create a larget composite
        shape = primitives.block( (1,1,2) )
        composite = mccomposite.composite( shape )
        composite.addElement( composite1, (0,0,-0.5) )
        composite.addElement( copy, (0,0,+0.5) )

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine( composite )

        ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
        ccomposite.scatter(ev)
        
        return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:26,代码来源:mccomposite_TestCase.py

示例3: 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

示例4: test3

    def test3(self):
        '''create pure python representation of a homogeneous scatterer with
        composite kernel. render the c++ computation engine of that kernel.
        '''
        #shape
        from mccomposite.geometry import primitives
        shape = primitives.block( (1,1,1) )

        #kernel
        nprinter = NeutronPrinter( )
        
        #composite kernel
        composite_kernel = hs.compositeKernel()
        composite_kernel.addElement( nprinter )

        #scatterer
        scatterer = hs.homogeneousScatterer(
            shape, composite_kernel)

        #render the c++ representation
        cscatterer = hs.scattererEngine( scatterer )

        for i in range(10):
            ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
            cscatterer.scatter(ev)
            continue
        return
开发者ID:McStasMcXtrace,项目名称:MCViNE,代码行数:27,代码来源:homogeneous_scatterer_TestCase.py

示例5: testCompositeScatteringKernel

    def testCompositeScatteringKernel(self):
        'CompositeScatteringKernel'
        shape = mccompositebp.Block(1,1,1)

        from neutron_printer3 import cKernel as Printer
        printer = Printer( )

        kernels = mccomponentsbp.pointer_vector_Kernel(0)
        kernels.append( printer )
        
        weights = mccomponentsbp.vector_double(0)
        weights.append(1.)

        rotmats = mccomponentsbp.vector_rotmat(0)
        rotmat = mcnibp.RotationMatrix_double(1,0,0, 0,1,0, 0,0,1)
        rotmats.append(rotmat)
        
        average=False
        kernelcomposite = mccomponentsbp.CompositeScatteringKernel( 
            kernels, weights, rotmats, average)

        mcweights = mccomponentsbp.MCWeights_AbsorptionScatteringTransmission()
        scatterer = mccomponentsbp.HomogeneousNeutronScatterer(
            shape, kernelcomposite, mcweights )

        for i in range(10):
            ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
            scatterer.scatter(ev)
            continue
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:30,代码来源:homogeneous_scatterer_TestCase.py

示例6: 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

示例7: 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

示例8: process

 def process(self, neutrons):
     import mcni
     for i in range(len(neutrons)):
         info.log("loop #%d" % i)
         neutrons[i] = mcni.neutron( r = ( 0,0,0 ), v = (0,0,random.random()) )
         continue
     return neutrons
开发者ID:mcvine,项目名称:mcvine,代码行数:7,代码来源:journal_test_sim_app.py

示例9: process

    def process(self, neutrons):
        import mcni

        for i in range(len(neutrons)):
            neutrons[i] = mcni.neutron(r=(1, 2, 3), v=(1, 2, 3))
            continue
        return neutrons
开发者ID:mcvine,项目名称:mcvine,代码行数:7,代码来源:ConsoleNeutronTracer_TestCase.py

示例10: 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

示例11: 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

示例12: 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

示例13: test1

    def test1(self):
        'complex. pack, detector, pixel hierarchy'
        
        mca = md.eventModeMCA(
            outfilename,
            (npacks, ndetsperpack, npixelsperdet,) )
        cylinder = operations.subtract( primitives.cylinder( sample2det * 1.1, detlength ),
                                        primitives.cylinder( sample2det * 0.9, detlength ) )
        ds = md.detectorSystem( cylinder, tofparams, mca )

        pack0 = makepack()
        packs = [pack0]
        for i in range(1, npacks):
            packs.append( mccomposite.scatterercopy( pack0, id = i ) )
            continue

        for i in range( npacks ):
            z = 0 * meter
            angle = (i-packindexat0)* 5./180 * N.pi
            x = sample2det * math.cos(angle)
            y = sample2det * math.sin(angle)
            ds.addElement( packs[i], (x,y,z) )
            continue

        cds = mh.scattererEngine( ds, coordinate_system = "InstrumentScientist" )

        for i in range(nevents):
            if i%1000 == 0: print i
            ev = mcni.neutron( r = (-L1,0,0), v = (vi,0,0) )
            cds.scatter(ev)
            continue

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

示例14: test

    def test(self):
        "wrap SNS_source_r1"
        from mcstas2 import componentfactory

        factory = componentfactory(category, componentname)
        component = factory(
            "component",
            S_filename="source_sct521_bu_17_1.dat",
            width=0.1,
            height=0.12,
            dist=2.5,
            xw=0.1,
            yh=0.12,
            Emin=50,
            Emax=70,
        )

        import mcni

        neutrons = mcni.neutron_buffer(5)
        for i in range(5):
            neutrons[i] = mcni.neutron(r=(0, 0, -1), v=(0, 0, 3000), time=0, prob=1)
            continue
        component.process(neutrons)
        print neutrons
        return
开发者ID:mcvine,项目名称:mcvine,代码行数:26,代码来源:SNS_source_r1_TestCase.py

示例15: test

    def test(self):
        E_Q = "Q*Q/3."
        S_Q = "1"
        Qmin = 0; Qmax = 10
        absorption_coefficient = scattering_coefficient = 1.
        kernel = mccomponentsbp.create_E_Q_Kernel(
            E_Q, S_Q,
            Qmin, Qmax,
            absorption_coefficient,
            scattering_coefficient,
            )

        ei = 500 # meV
        from mcni.utils import conversion
        vil = conversion.e2v(ei)
        vi = (0,0,vil)

        import numpy.linalg as nl
        import numpy as np
        for i in range(10):
            event = mcni.neutron( 
                r = (0,0,0), v = vi, 
                prob = 1, time = 0 )
            kernel.scatter( event );
            vf = np.array(event.state.velocity)
            diffv = vi - vf
            Q = conversion.v2k(nl.norm(diffv))
            ef = conversion.v2e(nl.norm(vf))
            E = ei - ef
            # print E, Q, event
            E1 = eval(E_Q)
            self.assertAlmostEqual(E, E1)
            continue

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


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