Is the order of `Vector` elements preserved between runs?


I want to store my solution as numpy array (u.vector().get_local()) and later (in another run of the Python interpreter) load it (with u.vector().set_local()).

Is it safe to assume that the order of Vector elements is preserved between runs? Is it safe to assume it is preserved between FEniCS versions?


No, this is not guaranteed.

Usually it will work, if you create function space on a mesh in exactly the same way. But expect problems in parallel, where partitioning also defines ordering of function’s vector.
Safe way is to use XDMFFile.write_checkpoint to store a Function. It stores the vector and degrees-of-freedom mapping (“ordering”) and also how mesh is partitioned.

Also notice, there is a parameter reorder_dofs_serial - to switch reordering of dofs for better data locality.


Do you know, where may I find better documentation of XDMFFile (and other Python objects) than the autogenerated one?

I am unable to find the reorder_dofs_serial parameter.


You can try cpp documentation,

reorder_dofs_serial is maybe not documented, you can also search the source code
or see old