How to use meshplex - 10 common examples

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 / meshplex / meshplex / mesh_tri.py View on Github external
def _compute_edges_cells(self):
        """This creates interior edge->cells relations. While it's not
        necessary for many applications, it sometimes does come in handy.
        """
        if self.edges is None:
            self.create_edges()

        num_edges = len(self.edges["nodes"])

        count = numpy.bincount(self.cells["edges"].reshape(-1), minlength=num_edges)

        # 
        edges_flat = self.cells["edges"].flat
        idx_sort = numpy.argsort(edges_flat)
        idx_start, count = grp_start_len(edges_flat[idx_sort])
        res1 = idx_sort[idx_start[count == 1]][:, numpy.newaxis]
        idx = idx_start[count == 2]
        res2 = numpy.column_stack([idx_sort[idx], idx_sort[idx + 1]])
        self._edges_cells = [
            [],  # no edges with zero adjacent cells
            res1 // 3,
            res2 // 3,
        ]
        # self._edges_local = [
        #     [],  # no edges with zero adjacent cells
        #     res1 % 3,
        #     res2 % 3,
        #     ]

        # For each edge, store the number of adjacent cells plus the index into
        # the respective edge array.
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 / pyfvm / test / test_bratu.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.cube(
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
        )
        return meshplex.MeshTetra(vertices, cells)
github nschloe / pyfvm / test / helpers.py View on Github external
def get_ball_mesh(k):
    import pygmsh

    h = 0.5 ** (k + 1)
    geom = pygmsh.built_in.Geometry()
    geom.add_ball([0.0, 0.0, 0.0], 1.0, lcar=h)
    mesh = pygmsh.generate_mesh(geom, verbose=False)
    cells = mesh.get_cells_type("tetra")
    # toss away unused points
    uvertices, uidx = numpy.unique(cells, return_inverse=True)
    cells = uidx.reshape(cells.shape)
    points = mesh.points[uvertices]
    return meshplex.MeshTetra(points, cells)
github nschloe / pyfvm / test / test_convection.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.cube(
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
        )
        return meshplex.MeshTetra(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.cube(
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
        )
        return meshplex.MeshTetra(vertices, cells)