Exemplo n.º 1
0

    vstart = comm.exscan(vAssigned)
    if comm.rank == 0:
        vstart = 0
    for MBlock in MBlocklist:
        opt = {'M':MBlock,'m':5,'d':2}
        surface = Sphere(center=sp.array([0.0, 0.0]))
        
        band = Band(surface,comm,opt)
        la,lv,gv,wv = band.createGLVectors()
        v = band.getCoordinates() 
        dt = 0.1*band.dx**2
        vv = sp.array([[0,0],[1,0],[-1,0],[0,1],[0,-1]])
        weights = sp.array([-4,1,1,1,1])*(dt/band.dx**2)
        L = band.createAnyMat(vv, weights, (5,2))
        PETSc.Sys.Print('Laplacian')
    
        
        M = band.createExtensionMat()
        PETSc.Sys.Print('ExtensionMat built')
    
        band.initialu(initialu)
        PETSc.Sys.Print('Initial')
        nextt = 0.1
        PETSc.Sys.Print('Begin to solve')
        t = 0
        for t in sp.arange(0,1,dt):
            L.multAdd(gv,gv,wv)
            M.mult(wv,gv)
            if t > nextt:
Exemplo n.º 2
0
#    z /= z.max()
    pl.figure()
    pl.points3d(x[:,0],x[:,1],x[:,2],c,mode='point')

if __name__ == '__main__':
    opt = {'M':50,'m':10,'d':3}
    surface = MeshWrapper()
    pl.triangular_mesh(surface.v[:,0],surface.v[:,1],surface.v[:,2],surface.f,opacity = 0.2)
    comm = MPI.COMM_WORLD
    band = Band(surface,comm,opt)
    la,lv,gv,wv = band.createGLVectors()
    v = band.getCoordinates() 
    dt = 0.3*band.dx**2
    vv = sp.array([[0,0,0],[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]])
    weights = sp.array([-6,1,1,1,1,1,1])*(dt/band.dx**2)
    L = band.createAnyMat(vv, weights, (7,3))
    PETSc.Sys.Print('Laplacian')
    band.test_initialu(test_initialu)
    L.mult(gv,wv)
    c = wv.getArray()
#    wv.view()
    plot3d(v,c,title='Lu')
#    wv.view()
    
    M = band.createExtensionMat()
    PETSc.Sys.Print('ExtensionMat built')
#    band.initialu(initialu)
    
    M.mult(gv,wv)
    c = wv.getArray()
    plot3d(v,c,title='Mu')
Exemplo n.º 3
0
    opt = {'M':100,'m':5,'d':3}
    try:
        surface = MeshWrapper('eight.ply')
        #surface = MeshWrapper('eight_refined.ply')
    except IOError:
        surface = MeshWrapper('cp/tests/data/eight.ply')
        #surface = MeshWrapper('cp/tests/data/eight_refined.ply')
    comm = MPI.COMM_WORLD
    band = Band(surface,comm,opt)
    la,lv,gv,wv = band.createGLVectors()
    v = band.getCoordinates()
    centers = band.BlockInd2CenterCarWithoutBand(band.gindBlockWBand.getArray())
    dt = 0.1*band.dx**2
    vv = sp.array([[0,0,0],[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]])
    weights = sp.array([-6,1,1,1,1,1,1])*(dt/band.dx**2)
    L = band.createAnyMat(vv, weights, (7,3))
    PETSc.Sys.Print('Laplacian')

    M = band.createExtensionMatForLoop()
    band.initialu(initialu)
    PETSc.Sys.Print('Initial')
    plot3d_total(v,gv)
    nextt = 0.01
    PETSc.Sys.Print('Begin to solve.\n dt is {0}'.format(dt))
    for t in sp.arange(0,0.2,dt):
        L.multAdd(gv,gv,wv)
        M.mult(wv,gv)
        if t > nextt:
            nextt += 0.01
            PETSc.Sys.Print('time is {0}'.format(t))
            
Exemplo n.º 4
0
    vAssigned = vsize // comm.size + int(comm.rank < (vsize % comm.size))

    vstart = comm.exscan(vAssigned)
    if comm.rank == 0:
        vstart = 0
    for MBlock in MBlocklist:
        opt = {'M': MBlock, 'm': 5, 'd': 2}
        surface = Sphere(center=sp.array([0.0, 0.0]))

        band = Band(surface, comm, opt)
        la, lv, gv, wv = band.createGLVectors()
        v = band.getCoordinates()
        dt = 0.1 * band.dx**2
        vv = sp.array([[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]])
        weights = sp.array([-4, 1, 1, 1, 1]) * (dt / band.dx**2)
        L = band.createAnyMat(vv, weights, (5, 2))
        PETSc.Sys.Print('Laplacian')

        M = band.createExtensionMat()
        PETSc.Sys.Print('ExtensionMat built')

        band.initialu(initialu)
        PETSc.Sys.Print('Initial')
        nextt = 0.1
        PETSc.Sys.Print('Begin to solve')
        t = 0
        for t in sp.arange(0, 1, dt):
            L.multAdd(gv, gv, wv)
            M.mult(wv, gv)
            if t > nextt:
                nextt += 0.1
Exemplo n.º 5
0
class TestBand(unittest.TestCase):


    def setUp(self):
        self.comm = MPI.COMM_WORLD
        surface = Surface()
        self.bnd = Band(surface,self.comm)
        self.bnd.createGLVectors()

    def tearDown(self):
        pass


    def testBlockInd2SubWithoutBand(self):
        '''test BlockInd2SubWithoutBand'''
        if 1 == 1:return 
        example = ( (5, a([5,0,0]) ),
                    (21,a([1,1,0]) ),
                    (a([401,402]),a([[1,0,1],[2,0,1]])) )
        for ind,sub in example:
            result = self.bnd.BlockInd2SubWithoutBand(ind)
            npt.assert_array_equal(result,sub,'{0} is wrong '.format(ind))
        ExceptionExample = (10000,8000)
        for i in ExceptionExample:
            self.assertRaises(exceptions.IndexError, self.bnd.BlockInd2SubWithoutBand,i)
            
    def testBlockSub2CenterCarWithoutBand(self):
        '''test BlockSub2CenterCarWithoutBand'''
        if 1 == 1: return
        example = ( ( 0, a([-1.9,-1.9,-1.9])), 
                    ( 1, a([-1.7,-1.9,-1.9])) )
        for ind,right in example:
            sub = self.bnd.BlockInd2SubWithoutBand(ind)
            rslt = self.bnd.BlockSub2CenterCarWithoutBand(sub)
            npt.assert_array_equal(rslt, right)

   
    @attr(visual=1)
    def testVisually(self):
        '''blocks selected visually.'''
#        if self.comm.rank == 0:
        g2z,zvec = PETSc.Scatter().toZero(self.bnd.gindBlockWBand)
        g2z.scatter(self.bnd.gindBlockWBand,zvec, PETSc.InsertMode.INSERT)
        x = self.bnd.BlockSub2CenterCarWithoutBand(\
                                                   self.bnd.BlockInd2SubWithoutBand(zvec.getArray()) )
        lx = self.bnd.BlockSub2CenterCarWithoutBand(\
                                                    self.bnd.BlockInd2SubWithoutBand(self.bnd.gindBlockWBand.getArray()))
        try:
            try:
                from mayavi import mlab
            except ImportError:
                from enthought.mayavi import mlab

            if self.comm.rank == 0:
                mlab.figure()
                mlab.points3d(x[:,0],x[:,1],x[:,2])
            mlab.figure()
            mlab.points3d(lx[:,0],lx[:,1],lx[:,2])
            mlab.show()
            #fig.add(pts1)
            #fig.add(pts2)
        except ImportError:
            import pylab as pl
            from mpl_toolkits.mplot3d import Axes3D #@UnusedImport
            fig = pl.figure()
            ax = fig.add_subplot(111, projection='3d')
            ax.scatter3D(x[:,0],x[:,1],x[:,2],c='blue',marker='o')
            ax.scatter3D(lx[:,0],lx[:,1],lx[:,2],c='red',marker='D')
            pl.savefig('testVis{0}.png'.format(self.comm.rank))
            pl.show()
        
    def testNorm1(self):
        '''test Norm1.'''
        example = ( ( a( [1,1,1] ), 1 ) ,
                    ( a( [[1,3,4],[2,-2,1]] ), a( [4,2] )) 
                   )
        for x,y in example:
            rslt = Band.norm1(x)
            npt.assert_allclose(rslt, y)
            
            
    def testgetCoordinatesWithGhost(self):
        '''What the return values of this function look like.'''
        #This test takes time.
        if 1 == 1 :return
        x = self.bnd.getCoordinatesWithGhost()
        try:
            from mayavi import mlab
            mlab.figure()
            mlab.points3d(x[:,0],x[:,1],x[:,2])
            #fig.add(pts)
            mlab.show()
            
        except ImportError:
            import pylab as pl
            from mpl_toolkits.mplot3d import Axes3D #@UnusedImport
            fig = pl.figure()
            ax = fig.add_subplot(111, projection='3d')
            ax.scatter3D(x[:,0],x[:,1],x[:,2])
            pl.savefig('x{0}.png'.format(self.comm.rank))
            pl.show()
            
    def testgetCoordinates(self):
        '''What the return values of this function look like.'''
        #This test takes time.
        if 1 == 1 :return
        x = self.bnd.getCoordinates()
        try:
            from mayavi import mlab
            mlab.figure()
            mlab.points3d(x[:,0],x[:,1],x[:,2])
            #fig.add(pts)
            mlab.show()
            
        except ImportError:
            import pylab as pl
            from mpl_toolkits.mplot3d import Axes3D #@UnusedImport
            fig = pl.figure()
            ax = fig.add_subplot(111, projection='3d')
            ax.scatter3D(x[:,0],x[:,1],x[:,2])
            pl.savefig('x{0}.png'.format(self.comm.rank))
            pl.show()
        
    def testBuildExtMat(self):
        self.bnd.createExtensionMat()
        
    def testCreateAnyMat(self):
        v = a([[0,0,0],[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]])
        weights = a([-6,1,1,1,1,1,1])
        self.bnd.createAnyMat(v, weights, (7,3))