def init_mesh(self, n=1, meshtype='tri'): node = np.array([ (0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) if meshtype == 'tri': cell = np.array([ (1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'quad': nx = 4 ny = 4 mesh = StructureQuadMesh(self.box, nx, ny) mesh.uniform_refine(n) return mesh elif meshtype == 'poly': cell = np.array([ (1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) nmesh = TriangleMeshWithInfinityNode(mesh) pnode, pcell, pcellLocation = nmesh.to_polygonmesh() pmesh = PolygonMesh(pnode, pcell, pcellLocation) return pmesh
def init_mesh(self, n=1, meshtype='tri'): node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float) if meshtype == 'tri': cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int) mesh = TriangleMesh(node, cell) mesh.uniform_refine(n) return mesh elif meshtype == 'quad': nx = 2 ny = 2 mesh = StructureQuadMesh(self.box, nx, ny) mesh.uniform_refine(n) return mesh
q[i] = np.fft.ifftn(q1).real q[i] *= E0 print(q) test = FourierSpaceTest() if True: test.linear_equation_fft_solver_1d_test(10) if True: test.linear_equation_fft_solver_2d_test(6) if True: test.linear_equation_fft_solver_3d_test(6) if True: test.parabolic_equation_solver_test(4, 10) if False: qmesh = StructureQuadMesh(box, N, N) mi = qmesh.multi_index() fig = plt.figure() axes = fig.gca() qmesh.add_plot(axes) qmesh.find_node(axes, showindex=True) plt.show()
def __init__(self): box = [0.0, 1.0, 0.0, 1.0] nx = 8 ny = 8 self.mesh = StructureQuadMesh(box, nx, ny)
class StructureQuadMeshTest: def __init__(self): box = [0.0, 1.0, 0.0, 1.0] nx = 8 ny = 8 self.mesh = StructureQuadMesh(box, nx, ny) def test_cell_location(self): start1 = time.time() mesh = self.mesh p = np.random.rand(10, 2) cidx = mesh.cell_location(p) end1 = time.time() print('cell_location time', end1 - start1) cell = mesh.entity('cell') fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_cell(axes, showindex=True) mesh.find_node(axes, node=p, showindex=True) plt.show() def test_interpolation(self): start2 = time.time() pde = CosCosData() F0 = self.mesh.interpolation(pde.solution, intertype='node') print(F0.shape) F1 = self.mesh.interpolation(pde.solution, intertype='edge') print(F1.shape) F2 = self.mesh.interpolation(pde.solution, intertype='edgex') print(F2.shape) F3 = self.mesh.interpolation(pde.solution, intertype='edgey') print(F3.shape) F4 = self.mesh.interpolation(pde.solution, intertype='cell') print(F4.shape) end2 = time.time() print('time of interpolation', end2 - start2) def test_polation_interoperator(self): pde = CosCosData() maxit = 4 errorType = ['$|u_I - u_h|_{max}$'] Maxerror = np.zeros((len(errorType), maxit), dtype=np.float) NE = np.zeros(maxit, ) for i in range(maxit): start3 = time.time() mesh = self.mesh isBDEdge = mesh.ds.boundary_edge_flag() NE[i] = mesh.number_of_edges() h = mesh.hx bc = mesh.entity_barycenter('cell') ec = mesh.entity_barycenter('edge') uI = mesh.polation_interoperator(pde.solution(bc)) uh = pde.solution(ec) Maxerror[0, i] = np.sqrt(np.sum(h**2 * (uh - uI)**2)) # Maxerror[0, i] = max(abs(uh - uI)) end3 = time.time() print('time of %d iteration' % i, end3 - start3) if i < maxit - 1: mesh.uniform_refine() showmultirate(plt, 0, NE, Maxerror, errorType) print('Maxerror', Maxerror) plt.show() def test_cbar(self): dt = 0 start4 = time.time() mesh = self.mesh pde = CosCosData() bc = mesh.entity_barycenter('cell') ch = pde.solution(bc) NC = mesh.number_of_cells() cellidx = np.arange(NC) xbar = bc - dt cbar = mesh.cbar_interpolation(ch, cellidx, xbar) end4 = time.time() print('test_cbar time', end4 - start4) print('cbar', sum(cbar - ch))