Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Define mesh attributes on root processor
t0 = clock()
t = clock()
gpoints = np.zeros(1)
if MPIrank == 0:
cells = np.asarray(self.mdata.cells['triangle'], dtype=np.int32)
coords = np.asarray(self.mdata.points, dtype=np.double)
MPIcomm.bcast(cells.shape, root=0)
MPIcomm.bcast(coords.shape, root=0)
elev = self.mdata.point_data[filename[1]]
gpoints[0] = len(coords)
if self.verbose:
print('Extract information (%0.02f seconds)'% (clock() - t))
t = clock()
Gmesh = meshplex.mesh_tri.MeshTri(coords, cells)
if self.verbose:
print('Reading meshplex meshtri (%0.02f seconds)'% (clock() - t))
t = clock()
Gmesh.mark_boundary()
if self.verbose:
print('Mark boundary TIN (%0.02f seconds)'% (clock() - t))
ids = np.arange(0, len(Gmesh.node_coords), dtype=int)
self.boundGlob = ids[Gmesh._is_boundary_node]
t = clock()
Gmesh.create_edges()
if self.verbose:
print('Defining edges TIN (%0.02f seconds)'% (clock() - t))
t = clock()
self.Gmesh_ngbNbs, self.Gmesh_ngbID = defineGTIN(gpoints[0], Gmesh.cells['nodes'], Gmesh.edges['nodes'])
if self.verbose:
print('Defining global TIN (%0.02f seconds)'% (clock() - t))
def _main():
points = numpy.array([[0.0, 0.0], [1.0, 0.0], [0.3, 0.8]])
# points = numpy.array([[0.0, 0.0], [1.0, 0.0], [0.5, numpy.sqrt(3) / 2]])
cells = numpy.array([[0, 1, 2]])
mesh = meshplex.mesh_tri.MeshTri(points, cells)
lw = 5.0
col = "0.6"
ax = plt.gca()
# circumcircle
circle1 = plt.Circle(
mesh.cell_circumcenters[0],
mesh.circumradius[0],
color=col,
fill=False,
linewidth=lw,
)
ax.add_artist(circle1)
# Define local vertex & cells
t = clock()
cStart, cEnd = self.dm.getHeightStratum(0)
# Dealing with triangular cells only
self.lcells = np.zeros((cEnd-cStart,3), dtype=PETSc.IntType)
for c in range(cStart, cEnd):
point_closure = self.dm.getTransitiveClosure(c)[0]
self.lcells[c,:] = point_closure[-3:]-cEnd
del point_closure
if MPIrank == 0 and self.verbose:
print('Defining local DMPlex (%0.02f seconds)'% (clock() - t))
# Create mesh structure with meshplex
t = clock()
# Define mesh characteristics
Tmesh = meshplex.mesh_tri.MeshTri(self.lcoords, self.lcells)
self.FVmesh_area = np.abs(Tmesh.control_volumes)
self.FVmesh_area[np.isnan(self.FVmesh_area)] = 1.
self.boundary, self.localboundIDs = self._get_boundary()
self.gbds = self.boundary.astype(int)
# Voronoi and simplices declaration
coords = Tmesh.node_coords
Tmesh.create_edges()
cc = Tmesh.cell_circumcenters
edges_nodes = Tmesh.edges['nodes']
cells_nodes = Tmesh.cells['nodes']
cells_edges = Tmesh.cells['edges']
if MPIrank == 0 and self.verbose:
print('Voronoi creation (%0.02f seconds)'% (clock() - t))