What is the current “best practice” for parallel exporting and then importing of solution functions in dolfinx? Seems like a simple enough question, but I got lost trying to find my way through earlier posts on the topic. I’m looking for something supported in the core package, preferably without the need to rely on add-ons, numpy, petsc, MPI.File etc.
I’d hoped for something like:
from dolfinx import fem, io, mesh
from mpi4py import MPI
Point1 = (0,0,0)
Point2 = (1,2,1)
domain = mesh.create_box(MPI.COMM_WORLD,[Point1,Point2],[4,4,4],mesh.CellType.hexahedron)
V = fem.FunctionSpace(domain, ("Lagrange", 1))
u_output = fem.Function(V)
# output function
with io.XDMFFile(domain.comm,"myfile.xdmf",'w') as ofile:
ofile.write_mesh(domain)
ofile.write_function(u_output)
# followed by input
with io.XDMFFile(domain.comm,"myfile.xdmf",'r',encoding=io.XDMFFile.Encoding.HDF5) as ifile:
u_input = ifile.read_function(V)
Right. But it seems weird to me that an external module is required to achieve something so trivial. This seems exactly what the dolfinx io submodule is for (that’s what the i stands for right ). Is this still work in progress then?
Since you are using dolfinx v0.6.0 and the supplied docker images, you can just add: export PYTHONPATH=/usr/local/lib/python3/dist-packages:$PYTHONPATH
which has been fixed in the dolfinx v0.7.0 release (compatible with adios4dolfinx v0.7.1).
The big thing that is holding this off from the main code is a discussion regarding file specifications (what file format to use, how should a checkpoint be maintained across versions of DOLFINx, etc).
The code I’ve written is not super-complicated, but I would say it is far from trivial, as you need to consider that this should work in parallel for any kind of finite element.
Reading and writing arbitrary Functions and their degree of freedom maps from local to global entities and their inverse is very far from trivial. Particularly in the case of parallel computation.
Please excuse my ignorance then. It seemed to me that it’s just parallel export/import of the underlying dof-vector, which should just require forwarding to the right PETSc function calls. Of course I understand there are file-specification/maintenance/architecture considerations involved.
Maybe my use of the phrase “trivial” was indeed unfortunate. Probably “crucial” was more appropriate.
Changing the PYTHONPATH does solve the adios2 import error, so I think I’ll take that route for now. Thanks @dokken. And I will stay on the look-out for a dolfinx native implementation.
That is simple if you are reading and writing in the same script (same partition and ghost ownership).
I covered this at the FEniCS 23 conference: checkpointing slides