Exemplo n.º 1
0
def _init():
    neutrons = mcni.neutron_buffer(ntotneutrons)
    for i in range(ntotneutrons):
        neutrons[i] = mcni.neutron(r=(0, 0, i), )
        continue

    from mcni.utils import mpiutil
    global mpirank
    mpirank = mpiutil.rank
    mpisize = mpiutil.world.size
    if mpisize != 3:
        raise RuntimeError, __doc__

    import os
    channel = 1000
    if mpirank == 0:
        if os.path.exists(neutron_storage_path):
            os.remove(neutron_storage_path)
        from mcni.neutron_storage.Storage import Storage
        storage = Storage(neutron_storage_path, 'w')
        storage.write(neutrons)
        del storage
        for i in range(1, mpisize):
            mpiutil.send(0, i, channel)
            continue
    else:
        mpiutil.receive(0, channel)
Exemplo n.º 2
0
def _init():
    neutrons = mcni.neutron_buffer(ntotneutrons)
    for i in range(ntotneutrons):
        neutrons[i] = mcni.neutron(
            r = (0,0,i),
            )
        continue

    from mcni.utils import mpiutil
    global mpirank
    mpirank = mpiutil.rank
    mpisize = mpiutil.world.size
    if mpisize != 3:
        raise RuntimeError, __doc__

    import os
    channel = 1000
    if mpirank == 0:
        if os.path.exists(neutron_storage_path):
            os.remove(neutron_storage_path)
        from mcni.neutron_storage.Storage import Storage
        storage = Storage(neutron_storage_path, 'w')
        storage.write(neutrons)
        del storage
        for i in range(1, mpisize):
            mpiutil.send(0, i, channel)
            continue
    else:
        mpiutil.receive(0, channel)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    def test2(self):
        'neutron_storage.Storage: write 2 packets'

        path = 'test-storage-2'
        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 packet 1
        s.write( neutrons )

        #write packet 2
        s.write( neutrons )

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

        neutrons = sr.read()
        self.assertEqual( len(neutrons), 7 )
        self.assertAlmostEqual( neutrons[5].state.velocity[0] , 8 )
        
        neutrons = sr.read()
        self.assertEqual( len(neutrons), 7 )
        self.assertAlmostEqual( neutrons[5].state.velocity[0] , 8 )
        return