本文整理汇总了Python中meshio.read方法的典型用法代码示例。如果您正苦于以下问题:Python meshio.read方法的具体用法?Python meshio.read怎么用?Python meshio.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meshio
的用法示例。
在下文中一共展示了meshio.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cells
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def get_cells(self, indices=[]):
"""Return the cells (connectivities).
Parameters
----------
self : MeshVTK
a MeshVTK object
indices : list
list of the points to extract (optional)
Returns
-------
cells: list
List of cell groups (type + array)
"""
# Read mesh file with meshio (pyvista does not provide the correct cell format)
mesh = read(self.path + "/" + self.name + "." + self.format)
return mesh.cells
示例2: plot_file_sizes
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def plot_file_sizes(names, file_sizes, mem_size):
idx = numpy.argsort(file_sizes)
file_sizes = [file_sizes[i] for i in idx]
names = [names[i] for i in idx]
ax = plt.gca()
y_pos = numpy.arange(len(file_sizes))
ax.barh(y_pos, file_sizes, align="center")
#
ylim = ax.get_ylim()
plt.plot(
[mem_size, mem_size], [-2, len(file_sizes) + 2], "C3", linewidth=2.0, zorder=0
)
ax.set_ylim(ylim)
#
ax.set_yticks(y_pos)
ax.set_yticklabels(names)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel("file size [MB]")
ax.set_title("file sizes")
plt.grid()
# plt.show()
plt.savefig("filesizes.svg", transparent=True, bbox_inches="tight")
plt.close()
示例3: generate_mesh
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def generate_mesh(self, verbose=False):
import meshio
import os
import subprocess
import tempfile
gmsh_executable = 'gmsh'
handle, filename = tempfile.mkstemp(suffix='.geo')
os.write(handle, self.get_code().encode())
os.close(handle)
handle, outname = tempfile.mkstemp(suffix='.msh')
cmd = [gmsh_executable, '-2', filename, '-o', outname]
try:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except:
out = os.system(" ".join(cmd))
if verbose:
print(out.decode())
#points,cells = meshio.read(outname)
mesh = meshio.read(outname)
# ~ print(dir(mesh))
#return points, cells
return mesh.points, mesh.cells["triangle"]
示例4: read_legacy
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def read_legacy(filename):
"""Use VTK's legacy reader to read a file."""
reader = vtk.vtkDataSetReader()
reader.SetFileName(filename)
# Ensure all data is fetched with poorly formatted legacy files
reader.ReadAllScalarsOn()
reader.ReadAllColorScalarsOn()
reader.ReadAllNormalsOn()
reader.ReadAllTCoordsOn()
reader.ReadAllVectorsOn()
# Perform the read
reader.Update()
output = reader.GetOutputDataObject(0)
if output is None:
raise RuntimeError('No output when using VTKs legacy reader')
return pyvista.wrap(output)
示例5: test_reference_file_readonly
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def test_reference_file_readonly(filename, ref_sum, ref_num_cells):
this_dir = pathlib.Path(__file__).resolve().parent
filename = this_dir / "meshes" / "msh" / filename
mesh = meshio.read(filename)
tol = 1.0e-2
s = mesh.points.sum()
assert abs(s - ref_sum) < tol * ref_sum
assert {k: len(v) for k, v in mesh.cells_dict.items()} == ref_num_cells
assert {
k: len(v) for k, v in mesh.cell_data_dict["gmsh:physical"].items()
} == ref_num_cells
num_cells = {k: 0 for k in ref_num_cells}
for vv in mesh.cell_sets_dict.values():
for k, v in vv.items():
num_cells[k] += len(v)
assert num_cells == ref_num_cells
示例6: test_convert
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def test_convert():
input_mesh = helpers.tri_mesh
infile = tempfile.NamedTemporaryFile().name
meshio.write(infile, input_mesh, file_format="gmsh")
outfile = tempfile.NamedTemporaryFile().name
meshio._cli.convert(
[infile, outfile, "--input-format", "gmsh", "--output-format", "vtk"]
)
mesh = meshio.read(outfile, file_format="vtk")
atol = 1.0e-15
assert numpy.allclose(input_mesh.points, mesh.points, atol=atol, rtol=0.0)
for cells0, cells1 in zip(input_mesh.cells, mesh.cells):
assert cells0.type == cells1.type
assert numpy.allclose(cells0.data, cells1.data)
示例7: test_reference_file
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def test_reference_file(filename):
this_dir = pathlib.Path(__file__).resolve().parent
filename = this_dir / "meshes" / "nastran" / filename
mesh = meshio.read(filename)
# points
assert numpy.isclose(mesh.points.sum(), 16.5316866)
# cells
ref_num_cells = {
"line": 241,
"triangle": 171,
"quad": 721,
"pyramid": 1180,
"tetra": 5309,
}
assert {k: v.sum() for k, v in mesh.cells} == ref_num_cells
示例8: _pyramid_volume
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def _pyramid_volume(cell):
"""
Evaluate pyramid volume by splitting it into
two tetrahedra
"""
tet0 = cell[[0, 1, 3, 4]]
tet1 = cell[[1, 2, 3, 4]]
vol = 0.0
vol += _tet_volume(tet0)
vol += _tet_volume(tet1)
return vol
# ugrid node ordering is the same for all elements except the pyramids. In order to make
# sure we got it right read a cube split into pyramids and evaluate its volume
示例9: read
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def read(filename):
"""Reads an unstructured mesh into meshplex format.
:param filenames: The files to read from.
:type filenames: str
:returns mesh{2,3}d: The mesh data.
"""
mesh = meshio.read(filename)
# make sure to include the used nodes only
tetra = mesh.get_cells_type("tetra")
if len(tetra) > 0:
points, cells = _sanitize(mesh.points, tetra)
return MeshTetra(points, cells)
tri = mesh.get_cells_type("triangle")
assert len(tri) > 0
points, cells = _sanitize(mesh.points, tri)
return MeshTri(points, cells)
示例10: get_mesh
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def get_mesh(self, indices=[]):
"""Return the pyvista mesh object (or submesh).
Parameters
----------
self : MeshVTK
a MeshVTK object
indices : list
list of the points to extract (optional)
Returns
-------
mesh : pyvista.core.pointset.UnstructuredGrid
a pyvista UnstructuredGrid object
"""
# Already available => Return
if self.mesh is not None:
return self.mesh
# Read mesh file
else:
if self.format != "vtk":
# Write vtk files with meshio
mesh = read(self.path + "/" + self.name + "." + self.format)
mesh.write(self.path + "/" + self.name + ".vtk")
# Read .vtk file with pyvista
mesh = pv.read(self.path + "/" + self.name + ".vtk")
# Extract submesh
if indices != []:
mesh = mesh.extract_points(indices)
if self.is_pyvista_mesh:
self.mesh = mesh
return mesh
示例11: info
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def info(argv=None):
parser = _get_parser()
args = parser.parse_args(argv)
mesh = meshio.read(args.input_file)
cells = mesh.get_cells_type("triangle")
print("Number of points: {}".format(mesh.points.shape[0]))
print("Number of elements:")
for cell_type, value in mesh.cells:
print(" {}: {}".format(cell_type, value.shape[0]))
mesh = MeshTri(mesh.points, cells)
print_stats(mesh)
示例12: pacman
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def pacman():
this_dir = os.path.dirname(os.path.realpath(__file__))
mesh = meshio.read(os.path.join(this_dir, "meshes", "pacman.vtk"))
return mesh.points[:, :2], mesh.get_cells_type("triangle")
示例13: circle_gmsh
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def circle_gmsh():
this_dir = os.path.dirname(os.path.realpath(__file__))
mesh = meshio.read(os.path.join(this_dir, "meshes", "circle.vtk"))
c = mesh.get_cells_type("triangle")
return mesh.points[:, :2], c
示例14: circle_gmsh2
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def circle_gmsh2():
# import pygmsh
# geom = pygmsh.built_in.Geometry()
# target_edge_length = 2 * numpy.pi / _compute_num_boundary_points(num_points)
# geom.add_circle(
# [0.0, 0.0, 0.0], 1.0, lcar=target_edge_length, num_sections=4, compound=True
# )
# mesh = pygmsh.generate_mesh(geom, remove_lower_dim_cells=True, verbose=False)
# mesh.write("out.vtk")
this_dir = os.path.dirname(os.path.realpath(__file__))
mesh = meshio.read(os.path.join(this_dir, "meshes", "circle-small.vtk"))
c = mesh.get_cells_type("triangle")
return mesh.points[:, :2], c
示例15: generate_mesh_from_file
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import read [as 别名]
def generate_mesh_from_file(self,filename):
mesh = meshio.read(filename)
self.nc = mesh.points
self.x, self.y = self.nc[:,0], self.nc[:,1]
self.ec = mesh.cells["triangle"]
return mesh.points, mesh.cells["triangle"]