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

Initialize mesh from vertices, connectivities at once

+4 votes

Given vertex coordinates and connectivity table, I would like to create a FEniCS mesh. From here, I gather that this is actually possible via

editor = MeshEditor()
# [...]
editor.add_vertex(0, np.array([0.0, 0.0]))
editor.add_vertex(1, np.array([0.1, 0.2]))
# [...]
editor.add_vertex(123456, np.array([1.0, 0.1]))

editor.add_cell(0, np.array([0, 1, 3], dtype=np.uintp))
# [...]

However, this takes a really long time if the mesh is large -- Python loops take their toll.

Is it possible to initialize a mesh with vertices and connectivities _in bulk_?

asked Mar 30, 2017 by nschloe FEniCS User (7,120 points)

Judging from the number of upvotes, you could consider putting it up as a feature request.

Perhaps the quick'n'dirty fix could be to export the mesh data to dolfin XML format?

That's what I'm doing right now via

meshio.write('test.xml', points, cells)
return Mesh('test.xml')
...