def test3(self):
        'MonochromaticSource - energy spread'

        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0, 0, 3000), r=(0.3, 0.4, 1.5))
        dx = 0.1
        dy = 0.8
        dE = 5
        s = MonochromaticSource("name", neutron0, dx=0, dy=0, dE=dE)

        # neutron buffer
        N = 100000
        b = neutron_buffer(N)

        # process
        s.process(b)

        #
        E0 = neutron0.energy()
        #
        n_in_onesigma = 0
        n_in_twosigma = 1
        for n in b:

            E = n.energy()
            # print n
            # print E, E0
            # not always true but usually true
            self.assertNotEqual(E, E0)

            #
            if abs(E - E0) < dE:
                n_in_onesigma += 1
            if abs(E - E0) < 2 * dE:
                n_in_twosigma += 1

            self.assertEqual(
                tuple(n.state.position),
                tuple(neutron0.state.position),
            )
            self.assertEqual(
                n.time,
                neutron0.time,
            )
            self.assertEqual(
                n.probability,
                neutron0.probability,
            )

            continue

        self.assert_(abs(n_in_onesigma * 1. / N - 0.68) < 0.01)
        self.assert_(abs(n_in_twosigma * 1. / N - 0.95) < 0.01)
        return
Пример #2
0
    def test3(self):
        'MonochromaticSource - energy spread'
        
        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0,0,3000), r=(0.3, 0.4, 1.5))
        dx=0.1; dy=0.8; dE = 5
        s = MonochromaticSource("name", neutron0, dx=0, dy=0, dE=dE)
        
        # neutron buffer
        N = 100000
        b = neutron_buffer(N)
        
        # process
        s.process(b)

        #
        E0 = neutron0.energy()
        #
        n_in_onesigma = 0
        n_in_twosigma = 1
        for n in b:

            E = n.energy()
            # print n
            # print E, E0
            # not always true but usually true
            self.assertNotEqual(E, E0)

            #
            if abs(E-E0) < dE:
                n_in_onesigma += 1
            if abs(E-E0) < 2*dE:
                n_in_twosigma += 1

            self.assertEqual(
                tuple(n.state.position),
                tuple(neutron0.state.position),
                )
            self.assertEqual(
                n.time,
                neutron0.time,
                )
            self.assertEqual(
                n.probability,
                neutron0.probability,
                )

            continue

        self.assert_( abs(n_in_onesigma*1./N-0.68) < 0.01)
        self.assert_( abs(n_in_twosigma*1./N-0.95) < 0.01)
        return
    def test2(self):
        'MonochromaticSource - x-y spread'

        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0, 0, 1000), r=(0.3, 0.4, 1.5))
        dx = 0.1
        dy = 0.8
        s = MonochromaticSource("name", neutron0, dx=dx, dy=dy)

        # neutron buffer
        N = 10
        b = neutron_buffer(N)

        # process
        s.process(b)

        #
        for n in b:

            # print n
            r = n.state.position
            # not always true but usually true
            r0 = neutron0.state.position
            self.assert_(r[0] != r0[0])
            self.assert_(r[1] != r0[1])
            # always true
            self.assert_(abs(r[0] - r0[0]) <= dx / 2)
            self.assert_(abs(r[1] - r0[1]) <= dy / 2)
            self.assert_(abs(r[2]) == r0[2])

            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
            )
            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
            )
            self.assertEqual(
                n.time,
                neutron0.time,
            )
            self.assertEqual(
                n.probability,
                neutron0.probability,
            )

        return
Пример #4
0
    def test2(self):
        'MonochromaticSource - x-y spread'
        
        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0,0,1000), r=(0.3, 0.4, 1.5))
        dx=0.1; dy=0.8
        s = MonochromaticSource("name", neutron0, dx=dx, dy=dy)
        
        # neutron buffer
        N = 10
        b = neutron_buffer(N)
        
        # process
        s.process(b)

        #
        for n in b:

            # print n
            r = n.state.position
            # not always true but usually true
            r0 = neutron0.state.position
            self.assert_(r[0]!=r0[0])
            self.assert_(r[1]!=r0[1])
            # always true
            self.assert_(abs(r[0]-r0[0])<=dx/2)
            self.assert_(abs(r[1]-r0[1])<=dy/2)
            self.assert_(abs(r[2])==r0[2])

            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
                )
            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
                )
            self.assertEqual(
                n.time,
                neutron0.time,
                )
            self.assertEqual(
                n.probability,
                neutron0.probability,
                )

        return
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
 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
    def test1(self):
        'MonochromaticSource'

        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0, 0, 1000))
        s = MonochromaticSource("name", neutron0)

        # neutron buffer
        N = 100
        b = neutron_buffer(N)

        # process
        s.process(b)

        #
        for n in b:
            self.assertEqual(
                tuple(n.state.position),
                tuple(neutron0.state.position),
            )
            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
            )
            self.assertEqual(
                n.time,
                neutron0.time,
            )
            self.assertEqual(
                n.probability,
                neutron0.probability,
            )

        return
Пример #9
0
    def test1(self):
        'MonochromaticSource'
        
        # source component
        from mcni.components.MonochromaticSource import MonochromaticSource
        from mcni import neutron_buffer, neutron
        neutron0 = neutron(v=(0,0,1000))
        s = MonochromaticSource("name", neutron0)
        
        # neutron buffer
        N = 100
        b = neutron_buffer(N)
        
        # process
        s.process(b)

        #
        for n in b:
            self.assertEqual(
                tuple(n.state.position),
                tuple(neutron0.state.position),
                )
            self.assertEqual(
                tuple(n.state.velocity),
                tuple(neutron0.state.velocity),
                )
            self.assertEqual(
                n.time,
                neutron0.time,
                )
            self.assertEqual(
                n.probability,
                neutron0.probability,
                )

        return
Пример #10
0
 def test1(self):
     'shape positioning: hollow cylinder'
     # source
     from mcni.components.MonochromaticSource import MonochromaticSource
     import mcni
     neutron = mcni.neutron(r=(0,0,0), v=(0,0,1000), prob=1)
     source = MonochromaticSource('s', neutron, dx=0.01, dy=0.015, dE=0)
     # sample
     from mccomponents.sample import samplecomponent
     scatterer = samplecomponent('sa', 'sphere-shell/sampleassembly.xml' )
     # neutrons
     N = 1000
     neutrons = mcni.neutron_buffer(N)
     neutrons = source.process(neutrons)
     # print neutrons
     scatterer.process(neutrons)
     # print neutrons
     arr = neutrons.to_npyarr()
     x,y,z = arr[:, :3].T
     assert np.allclose((x*x + y*y + z*z)**.5, 0.10)
     return
Пример #11
0
 def test1(self):
     'kernel orientation'
     # source
     from mcni.components.MonochromaticSource import MonochromaticSource
     import mcni, numpy as np
     Ei = 100
     from mcni.utils import conversion as Conv
     ki = Conv.e2k(Ei)
     vi = Conv.e2v(Ei)
     Qdir = np.array([np.sqrt(3)/2, 0, -1./2])
     Q = Qdir * 2
     kf = np.array([0,0,ki]) - Q
     Ef = Conv.k2e(np.linalg.norm(kf))
     E  = Ei-Ef
     dv = Qdir * Conv.k2v(Q)
     vf = np.array([0,0,vi]) - dv
     # print ki, Q, kf
     # print Ei, Ef, E
     neutron = mcni.neutron(r=(0,0,-1), v=(0,0,vi), prob=1)
     source = MonochromaticSource('s', neutron, dx=0.001, dy=0.001, dE=0)
     # sample
     from mccomponents.sample import samplecomponent
     scatterer = samplecomponent('sa', 'cyl/sampleassembly.xml' )
     # incident
     N = 1000
     neutrons = mcni.neutron_buffer(N)
     neutrons = source.process(neutrons)
     # print neutrons
     # scatter
     scatterer.process(neutrons)
     # print neutrons
     self.assertEqual(len(neutrons), N)
     for neutron in neutrons:
         np.allclose(neutron.state.velocity, vf)
         self.assert_(neutron.probability > 0)
         continue
     return