Restarting a simulation saved in .pvd

7 months ago by
I have a simulation saved in .pvd files, I would like to read its content and restart the simulation using the final step of the saved .pvd files as initial condition.

  • Is it possible to do this with .pvd files? I also have the mesh saved separately.
  • What is the alternative if it's not possible?

Community: FEniCS Project

1 Answer

7 months ago by

I think that it's possible but you need to create your own code to read correctly the files. Maybe a better choice is to use the hdf5 format (see here), which works also for parallel I/O.

A minimal example about how to use it is the next:

from dolfin import *

# Simple mesh
mesh = UnitSquareMesh(10,10)

# Fuction space and function
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
u.vector()[:] = 1.5

# Some mesh functions
cell_f  = MeshFunction("size_t", mesh, mesh.geometry().dim())
facet_f = MeshFunction("size_t", mesh, mesh.geometry().dim()-1)

# Create hdf5 file
hdf5_file = HDF5File(mesh.mpi_comm(), "results.h5", "w")

# Export everything
hdf5_file.write(mesh, "/mesh")
hdf5_file.write(cell_f, "/cell_function")
hdf5_file.write(facet_f, "/facet_function")
hdf5_file.write(u, "/function")

# close file

# Import everything
mesh_ = Mesh(mpi_comm_world())
hdf5_file = HDF5File(mesh_.mpi_comm(), "results.h5", "r"), "/mesh", False)

cell_f_  = MeshFunction("size_t", mesh_, mesh_.geometry().dim())
facet_f_ = MeshFunction("size_t", mesh_, mesh_.geometry().dim()-1)
u_ = Function(V), "/cell_function"), "/facet_function"), "/function")

plot(mesh_, title="mesh")
plot(cell_f_, title="cell function")
plot(facet_f_, title="facet function")
plot(u_, title="function")
Please login to add an answer/comment or follow this question.

Similar posts:
Search »