This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

read function from vtk

0 votes

Dear all,

I need to read an unstructured mesh and vertex data from a VTK file into fenics.
I can convert the mesh to a format that fenics understands, but how can I load the velocity data? Is there a better way than to somehow manually writing the data into a hdf5 file, i.e. imitating the HDF5File.write function?
I know hdf5 is the only supported format for function I/O but this is externally generated data, I have to deal with it.

Thanks!
David

asked Mar 9, 2017 by dajuno FEniCS User (4,140 points)

1 Answer

0 votes
 
Best answer

I'll answer my own question.
Just convert the vtk mesh to hdf5 with gmsh/meshio, dolfin-convert and a fenics script for xml->hdf5. Setting parameters['reorder_dofs_serial'] = False retains the dof ordering of the mesh and the (now matching!) VTK node data can simply be written into a P1 function u with u.vector()[:] = data, assuming that data is an array with a scalar value in every node. If you have a vector function, data needs to be reshaped and flattened correspondingly. (Say $u=(u_1, u_2, u_3)$, then u.vector() has the entries $[u_{1_1},u_{1_2},...,u_{1_N}, u_{2_1},u_{2_2},...,u_{2_N}, u_{3_1},u_{3_2},...,u_{3_N}]$.)

answered Mar 9, 2017 by dajuno FEniCS User (4,140 points)
...