本文整理汇总了Python中meshio.write_points_cells方法的典型用法代码示例。如果您正苦于以下问题:Python meshio.write_points_cells方法的具体用法?Python meshio.write_points_cells怎么用?Python meshio.write_points_cells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meshio
的用法示例。
在下文中一共展示了meshio.write_points_cells方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_srgb_gamut
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def save_srgb_gamut(self, filename, n=50, cut_000=False):
import meshio
import meshzoo
points, cells = meshzoo.cube(nx=n, ny=n, nz=n)
if cut_000:
# cut off [0, 0, 0] to avoid division by 0 in the xyz conversion
points = points[1:]
cells = cells[~numpy.any(cells == 0, axis=1)]
cells -= 1
srgb_linear = SrgbLinear()
pts = self.from_xyz100(srgb_linear.to_xyz100(points.T)).T
assert pts.shape[1] == 3
rgb = srgb_linear.to_srgb1(points)
meshio.write_points_cells(
filename, pts, {"tetra": cells}, point_data={"srgb": rgb}
)
示例2: save_hdr_gamut
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def save_hdr_gamut(self, filename, n=50, cut_000=False):
import meshio
import meshzoo
points, cells = meshzoo.cube(nx=n, ny=n, nz=n)
if cut_000:
# cut off [0, 0, 0] to avoid division by 0 in the xyz conversion
points = points[1:]
cells = cells[~numpy.any(cells == 0, axis=1)]
cells -= 1
hdr = HdrLinear()
pts = self.from_xyz100(hdr.to_xyz100(points.T)).T
rgb = hdr.to_hdr1(points)
meshio.write_points_cells(
filename, pts, {"tetra": cells}, point_data={"hdr-rgb": rgb}
)
示例3: write
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def write(self, filename, point_data=None, cell_data=None, field_data=None):
if self.node_coords.shape[1] == 2:
n = len(self.node_coords)
a = numpy.ascontiguousarray(
numpy.column_stack([self.node_coords, numpy.zeros(n)])
)
else:
a = self.node_coords
if self.cells["nodes"].shape[1] == 3:
cell_type = "triangle"
else:
assert (
self.cells["nodes"].shape[1] == 4
), "Only triangles/tetrahedra supported"
cell_type = "tetra"
meshio.write_points_cells(
filename,
a,
{cell_type: self.cells["nodes"]},
point_data=point_data,
cell_data=cell_data,
field_data=field_data,
)
示例4: circle_rotated
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def circle_rotated():
pts, cells = circle_random()
# <https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula>
theta = numpy.pi / 4
k = numpy.array([1.0, 0.0, 0.0])
pts = (
pts * numpy.cos(theta)
+ numpy.cross(k, pts) * numpy.sin(theta)
+ numpy.outer(numpy.einsum("ij,j->i", pts, k), k) * (1.0 - numpy.cos(theta))
)
meshio.write_points_cells("out.vtk", pts, {"triangle": cells})
return pts, cells
示例5: save_cone_gamut
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def save_cone_gamut(self, filename, observer, max_Y):
import meshio
import pygmsh
geom = pygmsh.built_in.Geometry()
max_stepsize = 4.0e-2
xy, _ = get_mono_outline_xy(observer, max_stepsize=max_stepsize)
# append third component
xy = numpy.column_stack([xy, numpy.full(xy.shape[0], 1.0e-5)])
# Draw a cross.
poly = geom.add_polygon(xy, lcar=max_stepsize)
axis = [0, 0, max_Y]
geom.extrude(poly, translation_axis=axis, point_on_axis=[0, 0, 0])
mesh = pygmsh.generate_mesh(geom, verbose=False)
# meshio.write(filename, mesh)
pts = self.from_xyz100(_xyy_to_xyz100(mesh.points.T)).T
meshio.write_points_cells(
filename, pts, {"tetra": mesh.get_cells_type("tetra")}
)
示例6: test
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def test(mesh):
with tempfile.TemporaryDirectory() as temp_dir:
filepath = os.path.join(temp_dir, "out.svg")
meshio.write_points_cells(filepath, mesh.points, mesh.cells)
示例7: generic_io
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def generic_io(filename):
with tempfile.TemporaryDirectory() as temp_dir:
filepath = os.path.join(temp_dir, filename)
meshio.write_points_cells(filepath, tri_mesh.points, tri_mesh.cells)
out_mesh = meshio.read(filepath)
assert (abs(out_mesh.points - tri_mesh.points) < 1.0e-15).all()
for c0, c1 in zip(tri_mesh.cells, out_mesh.cells):
assert c0.type == c1.type
assert (c0.data == c1.data).all()
示例8: get_poisson_condition
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def get_poisson_condition(pts, cells):
# Still can't initialize a mesh from points, cells
filename = "mesh.xdmf"
meshio.write_points_cells(filename, pts, {"triangle": cells})
mesh = Mesh()
with XDMFFile(filename) as f:
f.read(mesh)
# build Laplace matrix with Dirichlet boundary using dolfin
V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v)) * dx
u0 = Constant(0.0)
bc = DirichletBC(V, u0, "on_boundary")
f = Constant(1.0)
L = f * v * dx
A = assemble(a)
b = assemble(L)
bc.apply(A, b)
# solve(A, x, b, "cg")
solver = KrylovSolver("cg", "none")
x = Function(V)
x_vec = x.vector()
num_steps = solver.solve(A, x_vec, b)
# convert to scipy matrix
A = as_backend_type(A).mat()
ai, aj, av = A.getValuesCSR()
A = scipy.sparse.csr_matrix(
(av, aj, ai), shape=(A.getLocalSize()[0], A.getSize()[1])
)
# ev = eigvals(A.todense())
ev_max = scipy.sparse.linalg.eigs(A, k=1, which="LM")[0][0]
assert numpy.abs(ev_max.imag) < 1.0e-15
ev_max = ev_max.real
ev_min = scipy.sparse.linalg.eigs(A, k=1, which="SM")[0][0]
assert numpy.abs(ev_min.imag) < 1.0e-15
ev_min = ev_min.real
cond = ev_max / ev_min
# solve poisson system, count num steps
# b = numpy.ones(A.shape[0])
# out = pykry.gmres(A, b)
# num_steps = len(out.resnorms)
return cond, num_steps
示例9: save_visible_gamut
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def save_visible_gamut(self, observer, illuminant, filename, cut_000=False):
from scipy.spatial import ConvexHull
import meshio
lmbda, illu = illuminant
values = []
# Iterate over every possible illuminant input and store it in values
n = len(lmbda)
values = numpy.empty((n * (n - 1) + 2, 3))
k = 0
# No light
data = numpy.zeros(n)
values[k] = spectrum_to_xyz100((lmbda, illu * data), observer=observer)
k += 1
# frequency blocks
for width in range(1, n):
data = numpy.zeros(n)
data[:width] = 1.0
for _ in range(n):
values[k] = spectrum_to_xyz100((lmbda, illu * data), observer=observer)
k += 1
data = numpy.roll(data, shift=1)
# Full illuminant
data = numpy.ones(len(lmbda))
values[k] = spectrum_to_xyz100((lmbda, illu * data), observer=observer)
k += 1
# scale the values such that the Y-coordinate of the white point (last entry)
# has value 100.
values *= 100 / values[-1][1]
cells = ConvexHull(values).simplices
if cut_000:
values = values[1:]
cells = cells[~numpy.any(cells == 0, axis=1)]
cells -= 1
pts = self.from_xyz100(values.T).T
meshio.write_points_cells(filename, pts, cells={"triangle": cells})
示例10: RequestData
# 需要导入模块: import meshio [as 别名]
# 或者: from meshio import write_points_cells [as 别名]
def RequestData(self, request, inInfoVec, outInfoVec):
mesh = dsa.WrapDataObject(vtkUnstructuredGrid.GetData(inInfoVec[0]))
# Read points
points = np.asarray(mesh.GetPoints())
# Read cells
# Adapted from test/legacy_reader.py
cell_conn = mesh.GetCells()
cell_offsets = mesh.GetCellLocations()
cell_types = mesh.GetCellTypes()
cells_dict = {}
for vtk_cell_type in np.unique(cell_types):
offsets = cell_offsets[cell_types == vtk_cell_type]
ncells = len(offsets)
npoints = cell_conn[offsets[0]]
array = np.empty((ncells, npoints), dtype=int)
for i in range(npoints):
array[:, i] = cell_conn[offsets + i + 1]
cells_dict[vtk_to_meshio_type[vtk_cell_type]] = array
cells = [meshio.CellBlock(key, cells_dict[key]) for key in cells_dict]
# Read point and field data
# Adapted from test/legacy_reader.py
def _read_data(data):
out = {}
for i in range(data.VTKObject.GetNumberOfArrays()):
name = data.VTKObject.GetArrayName(i)
array = np.asarray(data.GetArray(i))
out[name] = array
return out
point_data = _read_data(mesh.GetPointData())
field_data = _read_data(mesh.GetFieldData())
# Read cell data
cell_data_flattened = _read_data(mesh.GetCellData())
cell_data = {}
for name, array in cell_data_flattened.items():
cell_data[name] = []
for cell_type in cells_dict:
vtk_cell_type = meshio_to_vtk_type[cell_type]
mask_cell_type = cell_types == vtk_cell_type
cell_data[name].append(array[mask_cell_type])
# Use meshio to write mesh
meshio.write_points_cells(
self._filename,
points,
cells,
point_data=point_data,
cell_data=cell_data,
field_data=field_data,
)
return 1