def testSquare(): ptlist = { "vertices": np.array( ((0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (0.0, 0.5), (0.5, 0.5), (1.0, 0.5), (0.0, 1.0), (0.5, 1.0), (1.0, 1.0)) ) } t = triangle.triangulate(ptlist) t1 = triangle.triangulate(ptlist, "qa0.001") triangle.plot.compare(plt, t, t1) # plt.show() L, M = FE.assembleMatrices(t) # print L # print '\n\n' # print M np.savetxt("textL", L) np.savetxt("textM", M) eig = FE.eigenvalues(L, M) elist = eig[0] efunc = eig[1] print elist[0] print elist[1] print elist[2] # vertices = np.asarray(t['vertices']) # faces = np.asarray(t['triangles']) # x = vertices[:,0] # y = vertices[:,1] # z = efunc[1] # plt.figure() # plt.tricontourf(x,y,faces,z,cmap='afmhot') # plt.show() print "****************************" L, M = FE.assembleMatrices(t1) eig = FE.eigenvalues(L, M) elist = eig[0] efunc = eig[1] for j in range(10): print elist[j] vertices = np.asarray(t1["vertices"]) faces = np.asarray(t1["triangles"]) x = vertices[:, 0] y = vertices[:, 1] z = efunc[:, 5] plt.figure() plt.tricontourf(x, y, z, 100, cmap="afmhot") plt.show() print "***************************\n\n\n\n\n"
def testFE(): ptlist = {"vertices": np.array(((0, 0), (1, 0), (1, 1), (0, 1)))} triang = triangle.triangulate(ptlist) print triang print "\n\n" print triang["vertices"] print triang["triangles"] triangle.plot.compare(plt, ptlist, triang) plt.show() print "\n\nNow testing the FE assembly ..." L, M = FE.assembleMatrices(triang) elist = FE.eigenvalues(L, M)[0] elist.sort() print "eigenvalues:" for j in elist: print j triangle.plot.compare(plt, ptlist, triang) plt.show() triang = triangle.triangulate(triang, "rqa0.1") L, M = FE.assembleMatrices(triang) elist = FE.eigenvalues(L, M)[0] elist.sort() print "\n\neigenvalues:" for j in elist: print j triangle.plot.compare(plt, ptlist, triang) plt.show() triang = triangle.triangulate(triang, "rqa0.01") L, M = FE.assembleMatrices(triang) elist = FE.eigenvalues(L, M)[0] elist.sort() print "\n\neigenvalues:" for j in elist: print j triangle.plot.compare(plt, ptlist, triang) plt.show()
def testSubdivide(): g = Mesh() g.addVertex(0, 0) g.addVertex(1, 0) g.addVertex(0, 1) g.addFace(0, 1, 2) L, M = FE.assembleMatrices(g) # print L # print M elist = FE.eigenvalues(L, M) print "\n\n\n" # print elist g.plot() g.subdivide(0) L, M = FE.assembleMatrices(g) # print '\n\n' # print L # print M # print '\n\n' elist = FE.eigenvalues(L, M) # print '\n\n\n' # print elist # g.plot() # g.subdivide(0) # g.plot() # g.subdivide(0) # g.plot() # for k in range(10): # j = np.random.choice( range(len(g.face_list)) ) # g.subdivide(j) g.subdivide_all() g.plot() g.subdivide_all() g.subdivide_all() g.plot() L, M = FE.assembleMatrices(g) elist = FE.eigenvalues(L, M)[0] elist.sort() print elist
import FE import triangle import numpy as np import matplotlib.pyplot as plt from pylab import * tri = {'vertices':np.array([[0.,0.],[1.,0.],[0.7,0.05]]),'triangles':np.array([[0,1,2]])} tri_mesh = triangle.triangulate(tri,'qa0.000005') print str(len(tri_mesh['vertices'])) + ' nodes' L,M = FE.assembleMatrices(tri_mesh) eig = FE.eigenvalues(L,M) elist = eig[0] efunc = eig[1] for j in range(10): print elist[j] fig = plt.figure() vertices = np.asarray(tri_mesh['vertices']) faces = np.asarray(tri_mesh['triangles']) x = vertices[:,0] y = vertices[:,1] for j in range(5): z = efunc[:,j] plt.tricontourf(x,y,z,100,cmap='afmhot') axes().set_aspect('equal') plt.show()