Skip to content
Advertisement

Python – meshio: How to define vertex cells for point-only data?

Problem

I have a 2D time-series data, and I want to save it as XMDF using meshio. The problem is, my mesh is just an array of points with associated point data, and I don’t have any cell defined. As such, I tried to use the "vertex" cell type, which is a single-point cell, but it doesn’t work. Meshio’s documentation is kind of lacking, so I’m stuck.

Code

Following the two examples on their Github page, I did the following. I’m not sure how to define the cells correctly, as meshio doesn’t document this properly.

JavaScript

Error

The above script produces the following error:

JavaScript

I tried different combinations of converting some of the arrays used to NumPy array, but I couldn’t find out the cause. I ask for your help.

Update:

After changing every used number array to NumPy arrays (credit to comments) – that is, inserting points = np.array(points) directly after points is defined, and changing the cell generator line to cells = [("vertex", np.array([i,])) for i in range(len(points))] – I still have a different error:

JavaScript

(I also note that the documentation does not use NumPy arrays in the examples.)

Advertisement

Answer

The problem was that:

  1. I should’ve use NumPy arrays everywhere: even though meshio’s example use Python lists, the xmdf module apparently can’t handle those; and
  2. I should’ve flatten the data as well (obviously). Also the cells should be be defined in a better way, though the original concept works too.

A working version of my code is:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement