Skip to content

Commit b6cb618

Browse files
authored
Merge pull request #937 from nschloe/vtk-fix2
VTK fix
2 parents 7b74eda + 752dc17 commit b6cb618

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

meshio/vtk/_vtk.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,17 @@ def _read_scalar_field(f, num_data, split, is_ascii):
470470
raise ReadError()
471471

472472
if is_ascii:
473-
data = numpy.fromfile(f, count=num_data, sep=" ", dtype=dtype)
473+
data = numpy.fromfile(f, count=num_data * num_comp, sep=" ", dtype=dtype)
474474
else:
475475
# Binary data is big endian, see
476476
# <https://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python#.22legacy.22>.
477477
dtype = dtype.newbyteorder(">")
478-
data = numpy.fromfile(f, count=num_data, dtype=dtype)
478+
data = numpy.fromfile(f, count=num_data * num_comp, dtype=dtype)
479479
line = f.readline().decode("utf-8")
480480
if line != "\n":
481481
raise ReadError()
482482

483+
data = data.reshape(-1, num_comp)
483484
return {data_name: data}
484485

485486

@@ -488,6 +489,7 @@ def _read_field(f, num_data, split, shape, is_ascii):
488489
data_type = split[2].lower()
489490

490491
dtype = numpy.dtype(vtk_to_numpy_dtype_name[data_type])
492+
# prod()
491493
# <https://stackoverflow.com/q/2104782/353337>
492494
k = reduce((lambda x, y: x * y), shape)
493495

setup.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = meshio
3-
version = 4.2.1
3+
version = 4.2.2
44
author = Nico Schlömer et al.
55
author_email = [email protected]
66
description = I/O for many mesh formats
@@ -24,6 +24,13 @@ classifiers =
2424
Programming Language :: Python :: 3.8
2525
Topic :: Scientific/Engineering
2626
Topic :: Utilities
27+
keywords =
28+
mesh
29+
file formats
30+
scientific
31+
engineering
32+
fem
33+
finite elements
2734

2835
[options]
2936
packages = find:

test/meshes/vtk/gh-935.vtk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:49d09f61cd621a26dcbbd715699462118b9b12cec4c73e64e50365ea0e351a07
3+
size 358

test/test_vtk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test_reference_file(filename, ref_sum, ref_num_cells, binary):
7676
("04_rectilinear.vtk", "quad", 27, 40),
7777
("05_rectilinear.vtk", "quad", 27, 40),
7878
("06_unstructured.vtk", "hexahedron", 12, 42),
79+
("gh-935.vtk", "triangle", 2, 6),
7980
],
8081
)
8182
def test_structured(filename, ref_cells, ref_num_cells, ref_num_pnt):

0 commit comments

Comments
 (0)