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

#1

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?

#2

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.

#3

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.

#4

You can try cpp documentation, https://fenicsproject.org/docs/dolfin/2018.1.0/cpp/de/d71/classdolfin_1_1XDMFFile.html#a9ef9031aec7bfec8f289d5210a1c811c

reorder_dofs_serial is maybe not documented, you can also search the source code https://bitbucket.org/fenics-project/dolfin/src/428803dd39dee5dc511863a004e832e09dcb7931/dolfin/parameter/GlobalParameters.h?at=master#GlobalParameters.h-80
or see old
https://fenicsproject.org/qa/6439/are-there-only-two-allowed-orders-of-degrees-of-freedom/