Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
while len(line) == 0 or line[0] == "#":
line = f.readline().strip()
num_tets, num_points_per_tet, num_attrs = [
int(item) for item in line.strip().split(" ") if item != ""
]
if num_points_per_tet != 4:
raise ReadError()
cells = numpy.fromfile(
f, dtype=int, count=(5 + num_attrs) * num_tets, sep=" "
).reshape(num_tets, 5 + num_attrs)
# remove the leading index column and the attributes
cells = cells[:, 1:5]
cells -= node_index_base
return Mesh(points, [CellBlock("tetra", cells)])
line = line.strip()
if len(line) == 0:
continue
info.split = line.split()
info.section = info.split[0].upper()
if info.section in vtk_sections:
_read_section(f, info)
else:
_read_subsection(f, info)
_check_mesh(info)
cells, cell_data = translate_cells(info.c, info.ct, info.cell_data_raw)
return Mesh(
info.points,
cells,
point_data=info.point_data,
cell_data=cell_data,
field_data=info.field_data,
)
# int16 (attribute count)
out = numpy.fromfile(
f,
count=num_triangles,
dtype=numpy.dtype(
[("normal", "f4", (3,)), ("facet", "f4", (3, 3)), ("attr count", "i2")]
),
)
# discard normals, attribute count
facets = out["facet"]
# if not numpy.all(out["attr count"] == 0):
# print(out["attr count"])
# raise ReadError("Nonzero attr count")
points, cells = data_from_facets(facets)
return Mesh(points, cells)
# Parse cell sets defined in ELEMENT
for i, name in enumerate(cell_sets_element_order):
# Not sure whether this case would ever happen
if name in cell_sets.keys():
cell_sets[name][i] = cell_sets_element[name]
else:
cell_sets[name] = []
for ic in range(len(cells)):
cell_sets[name].append(
cell_sets_element[name]
if i == ic
else numpy.array([], dtype="int32")
)
return Mesh(
points,
cells,
point_data=point_data,
cell_data=cell_data,
field_data=field_data,
point_sets=point_sets,
cell_sets=cell_sets,
)
def read(filename):
points, cells, cell_type = _read_mesh(filename)
cell_data = _read_cell_data(filename, cell_type)
return Mesh(points, cells, cell_data=cell_data)
name = params_map["NSET"]
if name not in nsets:
nsets[name] = []
nsets[name].append(setids)
elif keyword.startswith("ESET"):
params_map = get_param_map(keyword, required_keys=["ESET"])
setids = read_set(f, params_map)
name = params_map["ESET"]
if name not in elsets:
elsets[name] = []
elsets[name].append(setids)
else:
# There are just too many PERMAS keywords to explicitly skip them.
pass
return Mesh(
points, cells, point_data=point_data, cell_data=cell_data, field_data=field_data
)
def write_points_cells(
filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None,
file_format=None,
**kwargs
):
mesh = Mesh(
points, cells, point_data=point_data, cell_data=cell_data, field_data=field_data
)
return write(filename, mesh, file_format=file_format, **kwargs)
def write_points_cells(
filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None,
point_sets=None,
cell_sets=None,
file_format=None,
**kwargs,
):
points = numpy.asarray(points)
cells = [(key, numpy.asarray(value)) for key, value in cells]
mesh = Mesh(
points,
cells,
point_data=point_data,
cell_data=cell_data,
field_data=field_data,
point_sets=point_sets,
cell_sets=cell_sets,
)
return write(filename, mesh, file_format=file_format, **kwargs)