Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.
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",
)
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)
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)
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)
# 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
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)
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)
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)
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)