Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
labels[0] = "None"
if field_data:
labels.update({v[0]: k for k, v in field_data.items() if v[1] == 3})
return zgroups, labels
def _write_table(f, data, ncol=20):
"""Write zone group data table."""
nrow = len(data) // ncol
lines = numpy.split(data, numpy.full(nrow, ncol).cumsum())
for line in lines:
if len(line):
f.write(" {}\n".format(" ".join([str(l) for l in line])))
register("flac3d", [".f3grid"], read, {"flac3d": write})
return zgroups, labels
def _write_zgroup(f, data, ncol=20):
"""
Write zone group data.
"""
nrow = len(data) // ncol
lines = numpy.reshape(data[: nrow * ncol], (nrow, ncol)).tolist()
if data[nrow * ncol :]:
lines.append(data[nrow * ncol :])
for line in lines:
f.write(" {}\n".format(" ".join([str(l) for l in line])))
register("flac3d", [".f3grid"], read, {"flac3d": write})
)
offset += len(mesh.cells[ic].data)
for k, v in mesh.point_sets.items():
nds = [str(i + 1) for i in v]
f.write("*NSET, NSET={}\n".format(k))
f.write(
",\n".join(",".join(nds[i : i + nnl]) for i in range(0, len(nds), nnl))
+ "\n"
)
# https://github.com/nschloe/meshio/issues/747#issuecomment-643479921
# f.write("*END")
register("abaqus", [".inp"], read, {"abaqus": write})
else:
raise WriteError(
"DOLFIN XML only supports triangles and tetrahedra. "
"Consider using XDMF instead."
)
_write_mesh(filename, mesh.points, cell_type, mesh.cells)
for name, lst in mesh.cell_data.items():
for data in lst:
cell_data_filename = "{}_{}.xml".format(os.path.splitext(filename)[0], name)
dim = 2 if mesh.points.shape[1] == 2 or all(mesh.points[:, 2] == 0) else 3
_write_cell_data(cell_data_filename, dim, numpy.array(data))
register("dolfin-xml", [".xml"], read, {"dolfin-xml": write})
"({} (1 {:x} {:x} 1 {})(\n".format(
key, first_index, last_index, meshio_to_ansys_type[cell_type]
)
).encode("utf8")
)
if binary:
(values + first_node_index).tofile(fh)
fh.write(b"\n)")
fh.write(("End of Binary Section {})\n".format(key)).encode("utf8"))
else:
numpy.savetxt(fh, values + first_node_index, fmt="%x")
fh.write(b"))\n")
first_index = last_index + 1
register("ansys", [], read, {"ansys": write})
tmp_array[col_type] = data[:, i] + 1
i += 1
tmp_array[dtype.names[-1]] = labels
tmp_array.tofile(fh)
pos = 0
field = 54 # GmfEnd
header_type = numpy.dtype(",".join([keytype, postype]))
tmp_array = numpy.empty(1, dtype=header_type)
tmp_array["f0"] = field
tmp_array["f1"] = pos
tmp_array.tofile(fh)
register("medit", [".mesh", ".meshb"], read, {"medit": write})
# add cell data
for cell_type, cd in mesh.cell_data.items():
if cd:
tags = elem_group.create_group("tags")
for key, value in cd.items():
tags.create_dataset(key, data=value)
# add empty set -- MOAB wants this
sets = tstt.create_group("sets")
sets.create_group("tags")
# set max_id
tstt.attrs.create("max_id", global_id, dtype="u8")
register("moab", [".h5m"], read, {"moab": write})
"ns_names", "S1", ("num_node_sets", "len_string")
)
for k, name in enumerate(mesh.point_sets.keys()):
data[k] = k
for i, letter in enumerate(name):
data_names[k, i] = letter.encode("utf-8")
for k, (key, values) in enumerate(mesh.point_sets.items()):
dim1 = "num_nod_ns{}".format(k + 1)
rootgrp.createDimension(dim1, values.shape[0])
dtype = numpy_to_exodus_dtype[values.dtype.name]
data = rootgrp.createVariable("node_ns{}".format(k + 1), dtype, (dim1,))
# Exodus is 1-based
data[:] = values + 1
register("exodus", [".e", ".exo", ".ex2"], read, {"exodus": write})
# 80 character header data
msg = "This file was generated by meshio v{}.".format(__version__)
msg += (79 - len(msg)) * "X"
msg += "\n"
fh.write(msg.encode("utf-8"))
for c in filter(lambda c: c.type == "triangle", cells):
pts = points[c.data]
normals = _compute_normals(pts)
fh.write(numpy.uint32(len(c.data)))
for pt, normal in zip(pts, normals):
fh.write(normal.astype(numpy.float32))
fh.write(pt.astype(numpy.float32))
fh.write(numpy.uint16(0))
register("stl", [".stl"], read, {"stl": write})
"TetGen only supports tetrahedra, but mesh has {}. Skipping those.".format(
", ".join([c.type for c in mesh.cells if c.type != "tetra"])
)
)
# write cells
# TODO remove .as_posix when requiring Python 3.6
with open(ele_filename.as_posix(), "w") as fh:
fh.write("# This file was created by meshio v{}\n".format(__version__))
for cell_type, data in filter(lambda c: c.type == "tetra", mesh.cells):
fh.write("{} {} {}\n".format(data.shape[0], 4, 0))
for k, tet in enumerate(data):
fh.write("{} {} {} {} {}\n".format(k, tet[0], tet[1], tet[2], tet[3]))
register("tetgen", [".ele", ".node"], read, {"tetgen": write})