Restarting a simulation saved in .pvd


289
views
1
12 months ago by
Miguel  
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?

Thanks.
Community: FEniCS Project

1 Answer


1
12 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)
cell_f.set_all(1)
facet_f.set_all(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
hdf5_file.close()

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

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

hdf5_file.read(cell_f_, "/cell_function")
hdf5_file.read(facet_f_, "/facet_function")
hdf5_file.read(u_, "/function")

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

Similar posts:
Search »