Reloading and viewing data


788
views
1
13 months ago by
I want to be able to restart a simulation and viewing the entire history of a field (dolfin Function) with ParaView. From this post, it seems that it is not possible because the only format that allows for reloading a function time history (HDF5) cannot be viewed on paraview. I want to make a movie with the whole simulation in paraview. This whole simulation would involve several restarts. I could save several xdmf, one for each time I restart, and then stitch them all in paraview. Is there any other more practical solution?

3 Answers


5
13 months ago by

In the development version of dolfin you can find good improvements (very useful for what you want) in the XDMFFile class (see here). In particular take a look to the write_checkpoint() and read_checkpoint() functions. The below example ( the generated .xdmf file is also suitable for visualization (I used paraview 5.4.1)) shows you how to use this functions for I/O and restarts:

 

from dolfin import *

# Mesh and function spaces
mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh, "CG", 1)

# Time steping parameters
dt = 0.1
t  = 0
T  = 1.0

# Output Function
u = Function(V)

# Output xdmf file
o_xdmf_file = XDMFFile(mesh.mpi_comm(), "data.xdmf")

# Write checkpoints
while t <= T:
  # Change values in u
  u.vector()[:] += 1 
  # Write checkpoints
  o_xdmf_file.write_checkpoint(u, "function", t)
  # Update time
  t += dt

# Close output xdmf file
o_xdmf_file.close()

##############################

# Counter
i = 0
I = 10

# Input function  
v = Function(V)

# Input xdmf file
i_xdmf_file = XDMFFile(mesh.mpi_comm(), "data.xdmf")

# Read checkpoints
while i <= I:
  # Read checkpoints
  i_xdmf_file.read_checkpoint(v, "function", i)
  # Update counter
  i += 1
  
# Close input file
i_xdmf_file.close()


This class also will allow to continue writing results appending new outputs to the existing file (this is what you want).

Thank you. Is it any specific branch? or just master?
written 13 months ago by Miguel 
Just master (I forgot the link to the XDMFFile class (sorry for that), so I have edited my answer)
written 13 months ago by Hernán Mella 
Hernán, is it necessary to specify mesh.mpi_comm() when initiating a XDMFFile in parallel?
written 6 months ago by David Nolte 
Hi David,

I think that it's not necessary. The same code works fine for me removing the communicator from the initialization of the XDMFFile (I ran the writing process in parallel and reading in serial).
written 6 months ago by Hernán Mella 
Exactly, mpi communicator is not needed. As you can see here, https://bitbucket.org/fenics-project/dolfin/src/609df06d235028f97e73b2069b078606dd15a70f/dolfin/io/XDMFFile.h?at=master&fileviewer=file-view-default#XDMFFile.h-93 if only filename is provided then MPI_COMM_WORLD is used.
written 6 months ago by Michal Habera 
0
13 months ago by
The easiest way to do this with no additional coding is, I assume, is to store the time series of .pvd files with different names (i.e. 'flow' + str(timeStepCount) + '.pvd') and then work out how to plot these files in paraview.

I used this:

	def store_State(self):
		#Saves current flow state in .pvd and .xml formats for visualisation and further processing
		assign(self.visU,[self.Ub[0], self.Ub[1]]); self.visU.rename('ub','ub')

		convergenceVisU   = File('BaseFlow/ub_' + str(self.timeCounter) + '.pvd')
		convergenceVisU << self.visU​
A new .pvd for each time step? Is this feasible?
written 13 months ago by Miguel 
I'm sorry didn't quite follow your question. In which sense do you mean 'feasible'?
written 13 months ago by Corwinpro 
Creating and opening a new file in each timestep. Usually, with a *.pvd file you open it at the beginning and add the functions at each time step.
written 13 months ago by Miguel 
0
13 months ago by
pf4d 
say you have a Function ``u``

in your script, create a pvd file:

    ``f = File('out.pvd')``

then at each timestep ``t`` of your simulation, write to the file:

    ``f << (u, t)``
Please login to add an answer/comment or follow this question.

Similar posts:
Search »