Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lambda f, m: meshio.xdmf.write(f, m, data_format="XML"),
meshio.xdmf.read,
lambda f, m: meshio.xdmf.write(f, m, data_format="HDF", compression=None),
meshio.xdmf.read,
lambda f, m: meshio.xdmf.write(f, m, data_format="XML"),
["out.xdmf"],
lambda f, m: meshio.xdmf.write(f, m, data_format="HDF", compression="gzip"),
["out.xdmf", "out.h5"],
times = numpy.linspace(0.0, 1.0, 5)
point_data = [
{
"phi": numpy.full(n, t),
"u": numpy.full(helpers.tri_mesh_2d.points.shape, t),
}
for t in times
]
for t, pd in zip(times, point_data):
writer.write_data(
t, point_data=pd, cell_data={"a": {"triangle": [3.0, 4.2]}}
)
# read it back in
with meshio.xdmf.TimeSeriesReader(filename) as reader:
points, cells = reader.read_points_cells()
for k in range(reader.num_steps):
t, pd, cd = reader.read_data(k)
assert numpy.abs(times[k] - t) < 1.0e-12
for key, value in pd.items():
assert numpy.all(numpy.abs(value - point_data[k][key]) < 1.0e-12)
def test_xdmf3(mesh, data_format):
def write(*args, **kwargs):
return meshio.xdmf.write(*args, data_format=data_format, **kwargs)
helpers.write_read(write, meshio.xdmf.read, mesh, 1.0e-14)
def test_time_series():
# write the data
filename = "out.xdmf"
with meshio.xdmf.TimeSeriesWriter(filename) as writer:
writer.write_points_cells(helpers.tri_mesh_2d.points, helpers.tri_mesh_2d.cells)
n = helpers.tri_mesh_2d.points.shape[0]
times = numpy.linspace(0.0, 1.0, 5)
point_data = [
{
"phi": numpy.full(n, t),
"u": numpy.full(helpers.tri_mesh_2d.points.shape, t),
}
for t in times
]
for t, pd in zip(times, point_data):
writer.write_data(
t, point_data=pd, cell_data={"a": {"triangle": [3.0, 4.2]}}
)
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"],
),
"XDMF (HDF, uncompressed)": (
lambda f, m: meshio.xdmf.write(f, m, data_format="HDF", compression=None),
meshio.xdmf.read,
["out.xdmf", "out.h5"],
),
"XDMF (XML)": (
lambda f, m: meshio.xdmf.write(f, m, data_format="XML"),
meshio.xdmf.read,
["out.xdmf"],
),
}
# formats = {
# # "VTK (ASCII)": formats["VTK (ASCII)"],
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))
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))