Problems converting external data into a .vtk file
Railon69 opened this issue · comments
Dear Madam or Sir,
I am using meshio to convert node and element information from another program into a .vtk file for further use. I am stuck at the very last point, i.e. the file generation.
My code is the following:
import os
import meshio
import numpy as np
os.chdir("workingdirectory")
# Node information
points = node_coords
points = points.tolist()
# Element information
# 1. Quad Mesh
ele_vi = np.asarray(ele[:,1:5]).ravel()
ele_vi = ele_vi.tolist()
n_b = 4 # Block size
ele_vl = []
for i in range(0, len(ele_vi)):
ele_vl.append(ele_vi[i:i+n_b])
# Initialize the cells list with the first entry as "quad"
cells = [("quad", ele_vl)]
#print(cells)
# Generate Mesh
mesh = meshio.Mesh(points, cells)
The following manipulation is done:
- Variable node_coords (array of float integers size n x 3) --> Conversion to variable points (type: list)
- Element information extraction, resulting in ele_vl (resulting in a list variable)
The entire procedure follows exactly the example on: https://libraries.io/pypi/meshio
The example on the website works perfectly well. My script drops out the following error:
C:path\Python\Python310\site-packages\meshio_mesh.py:150: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
data if cell_type.startswith("polyhedron") else np.asarray(data),
Traceback (most recent call last):
File C:\ProgramData\anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\path.spyder-py3\main.py:20
mesh_file_gen(wdir, node_coords, ele)
File ~.spyder-py3\mesh_file_gen.py:40 in mesh_file_gen
mesh.write("foo2.vtk")
File ~\path\Python\Python310\site-packages\meshio_mesh.py:241 in write
write(path_or_buf, self, file_format, **kwargs)
File ~\path\Python\Python310\site-packages\meshio_helpers.py:177 in write
if value.shape[1] != num_nodes_per_cell[key]:
IndexError: tuple index out of range
Can anyone help me figuring out the root cause or even fix this problem. Every help will be really much appreciated!
Nvm, the problem was from my side!