(mesh, logger)
| 321 | return pymesh.form_mesh(vertices, mesh.faces); |
| 322 | |
| 323 | def repousse(mesh, logger): |
| 324 | cell_ids = mesh.get_attribute("cell").ravel().astype(int); |
| 325 | mesh.add_attribute("edge_length"); |
| 326 | tol = np.amax(mesh.get_attribute("edge_length")) * 0.1; |
| 327 | |
| 328 | bbox_min, bbox_max = mesh.bbox; |
| 329 | scaling = 2.0 / norm(bbox_max - bbox_min); |
| 330 | |
| 331 | start_time = time(); |
| 332 | num_cells = np.amax(cell_ids)+1; |
| 333 | results = []; |
| 334 | for i in range(num_cells): |
| 335 | to_keep = np.arange(mesh.num_faces, dtype=int)[cell_ids == i]; |
| 336 | if not np.any(to_keep): |
| 337 | continue; |
| 338 | |
| 339 | cut_mesh = pymesh.submesh(mesh, to_keep, 0); |
| 340 | pymesh.save_mesh("debug.msh", cut_mesh); |
| 341 | cut_mesh, __ = pymesh.remove_degenerated_triangles(cut_mesh, 100); |
| 342 | cut_mesh, __ = pymesh.split_long_edges(cut_mesh, tol); |
| 343 | |
| 344 | dof = cut_mesh.num_vertices; |
| 345 | assembler = pymesh.Assembler(cut_mesh); |
| 346 | L = assembler.assemble("laplacian"); |
| 347 | M = assembler.assemble("mass"); |
| 348 | |
| 349 | L_rhs = M * np.ones(dof) * -0.5; |
| 350 | bd_indices = cut_mesh.boundary_vertices; |
| 351 | n = len(bd_indices); |
| 352 | C = scipy.sparse.coo_matrix((np.ones(n), |
| 353 | (np.arange(n, dtype=int), bd_indices)), shape=(n, dof)); |
| 354 | C_rhs = np.zeros(n); |
| 355 | |
| 356 | A = scipy.sparse.bmat([ |
| 357 | [-L, C.T], |
| 358 | [C, None] |
| 359 | ]); |
| 360 | rhs = np.concatenate((L_rhs.ravel(), C_rhs)); |
| 361 | |
| 362 | solver = pymesh.SparseSolver.create("SparseLU"); |
| 363 | solver.compute(A); |
| 364 | x = solver.solve(rhs); |
| 365 | |
| 366 | z = x[:dof].reshape((-1, 1)); |
| 367 | |
| 368 | vertices = np.hstack((cut_mesh.vertices, z)); |
| 369 | out_mesh = pymesh.form_mesh(vertices, cut_mesh.faces); |
| 370 | results.append(out_mesh); |
| 371 | |
| 372 | finish_time = time(); |
| 373 | t = finish_time - start_time; |
| 374 | logger.info("Repousse running time: {}".format(t)); |
| 375 | |
| 376 | mesh = pymesh.merge_meshes(results); |
| 377 | |
| 378 | vertices = mesh.vertices[:,:2]; |
| 379 | mesh_2d = pymesh.form_mesh(vertices, mesh.faces); |
| 380 | pymesh.save_mesh("out_2d.msh", mesh_2d) |
no test coverage detected