Save only DOFs and coordinates


If I have a function f(x), I want to store only the dof-coordinates, and the corresponding node values into a single file (.txt or something similar) such that I can load that data for analysing. There is no need to visualize the function in Paraview, and I will have thousands of functions, which means VTK or XDMF may not be suitable.

In the old fenics, there is the “XYZ” file that could be used, and I’m wondering is there anything similar in DOLFINx? Thanks!

Your question depends on the function space that you are using.
If you are using a function space where all dofs are defined through point evaluations, you can simply use dolfinx::fem::FunctionSpace::tabulate_dof_coordinates() (Finite element (dolfinx::fem) — DOLFINx 0.3.1 documentation)
to get the coordinates of all dofs on the process.
Then, you can use dolfinx::fem::FunctionSpace::dofmap()::index_map():size_local (Common (dolfinx::common) — DOLFINx 0.3.1 documentation)
and dolfinx::fem::FunctionSpace::dofmap()::index_map_bs() (Finite element (dolfinx::fem) — DOLFINx 0.3.1 documentation)
to avoid writing any duplicate dofs from dolfinx::fem::Function::x()::array() (Linear algebra (dolfinx::la) — DOLFINx 0.3.1 documentation) to get the dof data.

Note that for blocked spaces (vector or tensor spaces) you need to unroll the dof coordinates for block size.
The references to the documentation is based on your previous posts using C++.