Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(mesh, data_type):
binary, compression = data_type
def writer(*args, **kwargs):
return meshio.vtu.write(*args, binary=binary, compression=compression, **kwargs)
# ASCII files are only meant for debugging, VTK stores only 11 digits
#
tol = 1.0e-15 if binary else 1.0e-10
helpers.write_read(writer, meshio.vtu.read, mesh, tol)
def writer(*args, **kwargs):
return meshio.vtu.write(*args, binary=binary, compression=compression, **kwargs)
"Permas": (meshio.permas.write, meshio.permas.read, ["out.dato"]),
# # "wkt": ".wkt",
"TetGen": (meshio.tetgen.write, meshio.tetgen.read, ["out.node", "out.ele"],),
"VTK (binary)": (
lambda f, m: meshio.vtk.write(f, m, binary=True),
meshio.vtk.read,
["out.vtk"],
),
"VTK (ASCII)": (
lambda f, m: meshio.vtk.write(f, m, binary=False),
meshio.vtk.read,
["out.vtk"],
),
"VTU (binary)": (
lambda f, m: meshio.vtu.write(f, m, binary=True),
meshio.vtu.read,
["out.vtu"],
),
"VTU (ASCII)": (
lambda f, m: meshio.vtu.write(f, m, binary=False),
meshio.vtu.read,
["out.vtu"],
),
"XDMF (binary)": (
lambda f, m: meshio.xdmf.write(f, m, data_format="Binary"),
meshio.xdmf.read,
["out.xdmf", "out0.bin", "out1.bin"],
),
"XDMF (HDF, GZIP)": (
lambda f, m: meshio.xdmf.write(f, m, data_format="HDF", compression="gzip"),
meshio.xdmf.read,
["out.xdmf", "out.h5"],
lambda f, m: meshio.vtu.write(f, m, binary=True),
meshio.vtu.read,
if fmt == "ansys":
ansys.write(args.infile, mesh, binary=False)
elif fmt == "flac3d":
flac3d.write(args.infile, mesh, binary=False)
elif fmt == "gmsh":
gmsh.write(args.infile, mesh, binary=False)
elif fmt == "mdpa":
mdpa.write(args.infile, mesh, binary=False)
elif fmt == "ply":
ply.write(args.infile, mesh, binary=False)
elif fmt == "stl":
stl.write(args.infile, mesh, binary=False)
elif fmt == "vtk":
vtk.write(args.infile, mesh, binary=False)
elif fmt == "vtu":
vtu.write(args.infile, mesh, binary=False)
elif fmt == "xdmf":
xdmf.write(args.infile, mesh, data_format="XML")
else:
print("Don't know how to convert {} to ASCII format.".format(args.infile))
exit(1)
size = os.stat(args.infile).st_size
print("File size after: {:.2f} MB".format(size / 1024 ** 2))
args.infile, mesh, compression="gzip", compression_opts=9 if args.max else 4
)
elif fmt == "mdpa":
mdpa.write(args.infile, mesh, binary=True)
elif fmt == "med":
med.write(
args.infile, mesh, compression="gzip", compression_opts=9 if args.max else 4
)
elif fmt == "ply":
ply.write(args.infile, mesh, binary=True)
elif fmt == "stl":
stl.write(args.infile, mesh, binary=True)
elif fmt == "vtk":
vtk.write(args.infile, mesh, binary=True)
elif fmt == "vtu":
vtu.write(
args.infile, mesh, binary=True, compression="lzma" if args.max else "zlib"
)
elif fmt == "xdmf":
xdmf.write(
args.infile,
mesh,
data_format="HDF",
compression="gzip",
compression_opts=9 if args.max else 4,
)
else:
print("Don't know how to compress {}.".format(args.infile))
exit(1)
size = os.stat(args.infile).st_size
print("File size after: {:.2f} MB".format(size / 1024 ** 2))
size = os.stat(args.infile).st_size
print("File size before: {:.2f} MB".format(size / 1024 ** 2))
mesh = read(args.infile, file_format=args.input_format)
# # Some converters (like VTK) require `points` to be contiguous.
# mesh.points = numpy.ascontiguousarray(mesh.points)
# write it out
if fmt == "cgns":
cgns.write(args.infile, mesh, compression=None)
elif fmt == "h5m":
h5m.write(args.infile, mesh, compression=None)
elif fmt == "med":
med.write(args.infile, mesh, compression=None)
elif fmt == "vtu":
vtu.write(args.infile, mesh, binary=True, compression=None)
elif fmt == "xdmf":
xdmf.write(args.infile, mesh, data_format="HDF", compression=None)
else:
print("Don't know how to decompress {}.".format(args.infile))
exit(1)
size = os.stat(args.infile).st_size
print("File size after: {:.2f} MB".format(size / 1024 ** 2))
if fmt == "ansys":
ansys.write(args.infile, mesh, binary=True)
elif fmt == "flac3d":
flac3d.write(args.infile, mesh, binary=True)
elif fmt == "gmsh":
gmsh.write(args.infile, mesh, binary=True)
elif fmt == "mdpa":
mdpa.write(args.infile, mesh, binary=True)
elif fmt == "ply":
ply.write(args.infile, mesh, binary=True)
elif fmt == "stl":
stl.write(args.infile, mesh, binary=True)
elif fmt == "vtk":
vtk.write(args.infile, mesh, binary=True)
elif fmt == "vtu":
vtu.write(args.infile, mesh, binary=True)
elif fmt == "xdmf":
xdmf.write(args.infile, mesh, data_format="HDF")
else:
print("Don't know how to convert {} to binary format.".format(args.infile))
exit(1)
size = os.stat(args.infile).st_size
print("File size after: {:.2f} MB".format(size / 1024 ** 2))