How to use the meshplex.MeshTri function in meshplex

To help you get started, we’ve selected a few meshplex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / dmsh / test / helpers.py View on Github external
def save(filename, X, cells):
    import meshplex

    mesh = meshplex.MeshTri(X, cells)
    mesh.save(
        filename, show_coedges=False, show_axes=False, nondelaunay_edge_color="k",
    )
github nschloe / pyfvm / test / test_bratu.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.rectangle(
            0.0, 1.0, 0.0, 1.0, n + 1, n + 1, zigzag=True
        )
        return meshplex.MeshTri(vertices, cells)
github nschloe / pyfvm / test / test_reaction.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.rectangle(
            0.0, 1.0, 0.0, 1.0, n + 1, n + 1, zigzag=True
        )
        return meshplex.MeshTri(vertices, cells)
github nschloe / pyfvm / test / test_neumann.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.rectangle(
            0.0, 1.0, 0.0, 1.0, n + 1, n + 1, zigzag=True
        )
        return meshplex.MeshTri(vertices, cells)
github nschloe / optimesh / test / meshes.py View on Github external
# generate random points in circle; 
    numpy.random.seed(0)
    r = numpy.random.rand(m)
    alpha = 2 * numpy.pi * numpy.random.rand(m)

    interior_pts = numpy.column_stack(
        [numpy.sqrt(r) * numpy.cos(alpha), numpy.sqrt(r) * numpy.sin(alpha)]
    )

    pts = numpy.concatenate([boundary_pts, interior_pts])

    tri = Delaunay(pts)
    pts = numpy.column_stack([pts[:, 0], pts[:, 1], numpy.zeros(pts.shape[0])])

    # Make sure there are exactly `n` boundary points
    mesh = MeshTri(pts, tri.simplices)
    assert numpy.sum(mesh.is_boundary_node) == n

    return pts, tri.simplices
github nschloe / optimesh / examples / compare-gmsh-quality.py View on Github external
kwargs = {
    "show_coedges": False,
    "cell_quality_coloring": ("viridis", 0.7, 1.0, False),
    "show_axes": False,
}
pts, cells = create_circle.gmsh(num_points)
mesh = meshplex.MeshTri(pts, cells)
mesh.save("out0.png", **kwargs)
#
pts, cells = optimesh.cvt.quasi_newton_uniform_blocks(
    pts, cells, tol=1.0e-6, max_num_steps=numpy.inf
)
pts, cells = optimesh.cvt.quasi_newton_uniform_full(
    pts, cells, tol=1.0e-4, max_num_steps=100
)
mesh = meshplex.MeshTri(pts, cells)
mesh.save("out1.png", **kwargs)
#
pts, cells = create_circle.dmsh(num_points)
pts, cells = optimesh.cvt.quasi_newton_uniform_blocks(
    pts, cells, tol=1.0e-6, max_num_steps=numpy.inf
)
# pts, cells = optimesh.cvt.quasi_newton_uniform_full(
#     pts, cells, tol=1.0e-4, max_num_steps=100
# )
mesh = meshplex.MeshTri(pts, cells)
mesh.show(**kwargs)
mesh.save("out2.png", **kwargs)

exit(1)
github nschloe / optimesh / optimesh / cvt / _lloyd.py View on Github external
# There are other possible heuristics too. For example, one could restrict the
        # mask to cells at or near the boundary.
        mask = numpy.any(mesh.ce_ratios < -0.5, axis=0)

        x = mesh.get_control_volume_centroids(cell_mask=mask)
        # reset boundary points
        idx = mesh.is_boundary_node
        x[idx] = mesh.node_coords[idx]
        # When using a cell mask, it can happen that some nodes don't get any
        # contribution at all because they are adjacent only to masked cells. Reset
        # those, too.
        idx = numpy.any(numpy.isnan(x), axis=1)
        x[idx] = mesh.node_coords[idx]
        return x

    mesh = MeshTri(points, cells)

    method_name = "Lloyd's algorithm"
    runner(get_new_points, mesh, *args, **kwargs, method_name=method_name)

    return mesh.node_coords, mesh.cells["nodes"]
github nschloe / optimesh / optimesh / laplace.py View on Github external
#     idx = mesh.is_boundary_node
    #     new_points[idx] = mesh.node_coords[idx]
    #     return new_points

    def get_new_points(mesh):
        matrix = build_adjacency_matrix(mesh)
        # compute average
        num_neighbors = matrix * numpy.ones(matrix.shape[1], dtype=int)
        new_points = matrix * mesh.node_coords
        new_points /= num_neighbors[:, None]
        # don't move boundary nodes
        idx = mesh.is_boundary_node
        new_points[idx] = mesh.node_coords[idx]
        return new_points

    mesh = MeshTri(points, cells)
    runner(get_new_points, mesh, *args, **kwargs)
    return mesh.node_coords, mesh.cells["nodes"]
github nschloe / optimesh / optimesh / cvt / ghosted_mesh.py View on Github external
def __init__(self, points, cells):
        # Add ghost points and cells for boundary facets
        msh = MeshTri(points, cells)
        ghosts = []
        ghost_cells = []
        k = points.shape[0]
        for i in [[0, 1, 2], [1, 2, 0], [2, 0, 1]]:
            bf = msh.is_boundary_facet[i[0]]
            c = msh.cells["nodes"][bf].T
            ghosts.append(c[i])
            n = c.shape[1]
            p = numpy.arange(k, k + n)
            ghost_cells.append(numpy.column_stack([p, c[i[1]], c[i[2]]]))
            k += n

        self.num_boundary_cells = numpy.sum(msh.is_boundary_facet)

        self.is_ghost_point = numpy.zeros(
            points.shape[0] + self.num_boundary_cells, dtype=bool
github nschloe / optimesh / examples / compare-gmsh-quality.py View on Github external
def process(name, t):
    show_meshes = False
    cond, num_steps = get_poisson_condition(pts, cells)
    data[name]["n"].append(len(pts))
    data[name]["cond"].append(cond)
    data[name]["cg"].append(num_steps)
    mesh = meshplex.MeshTri(pts, cells)
    avg_q = numpy.sum(mesh.cell_quality) / len(mesh.cell_quality)
    data[name]["q"].append(avg_q)
    print("{:.2e}".format(cond), num_steps, f"{avg_q:.2f}", f"({t:.2f}s)")
    if show_meshes:
        mesh.show()
    return