This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

HDF5File visualization

+3 votes

Which is the currently suggested approach to save in file HDF5 format?

I wish in particular to save multiple functions and multiple time steps to a single file. It seems to me that this is supported looking at the source in dolfin/io/HDF5File.h, e.g.

HDF5File.write(const Function& u, const std::string name, double timestamp)

However, I am not able to visualize the resulting .h5 file in Paraview or Visit. Which viewer do you suggest?

I was used to use the File('u.xdmf') interface, but if I understand correctly the advanced functionality of HDF5File are not supported with this.

I had a look also to the unit tests in dolfin/test/io, but I cannot visualize the resulting .h5 files in paraview. I suppose I miss something. May someone help?

Corrado

asked Jan 21, 2014 by cmaurini FEniCS User (1,130 points)

1 Answer

+5 votes

You can timestamp files in XDMFFile:

File("u.xdmf") << (u,t)

You will not find a viewer to view output from HDF5File directly This is stored in a special way that will allow for loading of data into dolfin, but not compatible with any viewer.

In short:
- To store data for viewing, use xdmf
- To store data for reloading, use HDF5
- To store data for viewing and reloading, use xdmf and HDF5

answered Jan 21, 2014 by Øyvind Evju FEniCS Expert (17,700 points)

Thanks,

Is there a reason for which the same functionalities as in HDF5File are not supported with the xdmf wrapper? Is this an expected development?

I'm not sure which functionality you are referring to? The naming of functions in XDMFFile is taken directly from Function, so if you specify your Function as

u = Function(V, name="Velocity")

before storing u to XDMF, this will be reflected in the XDMF-file (instead of default names such as f_48).

Thanks,

I was referring to the possibility of writing multiple functions to a single file with File("u.xdmf") << (u,t)

If I do it with it with xdmf, the resulting file is not supported by Paraview. Here the message that I obtain in Paraview when I open a file created saving multiple functions:

ERROR: In /Users/kitware/Dashboards/MyTests/NightlyMaster/ParaViewSuperbuild-Release/paraview/src/paraview/VTK/Common/ExecutionModel/vtkExecutive.cxx,

line 754
vtkPVCompositeDataPipeline (0x123558ea0): Algorithm vtkXdmfReader(0x123566640) returned failure for request:
vtkInformation (0x11b3d7a80)
Debug: Off
Modified Time: 856062
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
FORWARD_DIRECTION: 0




Warning: In /Users/kitware/Dashboards/MyTests/NightlyMaster/ParaViewSuperbuild-Release/paraview/src/paraview/VTK/IO/Xdmf2/vtkXdmfReader.cxx,
line 407
vtkXdmfReader (0x10e3e2660): Data type generated (vtkMultiBlockDataSet) does not match data type expected
(vtkUnstructuredGrid). Reader may not produce valid data.

Are you trying to write Functions from different FunctionSpaces/Mesh to the same xdmf file?

If not, it should work fine. The following works for me

mesh = UnitSquareMesh(4,4)
V = FunctionSpace(mesh, "DG", 2)
ufile = File("u.xdmf")
ufile << (Function(V), 0.0)
ufile << (Function(V), 0.1)
ufile << (Function(V), 0.2)
del ufile # Delete file object (or exit program) to avoid data corruption

Using XDMFFile directly will give you access to XDMFFile.parameters, to get better control of the writing.

Yes, I have one function from a scalar-valued field and one function from a vector-valued field, on the same mesh. Is it supposed to be supported?

I delete the file object, otherwise I have a segfault coming from the hdf5 library.

This could be supported, or at least throw an exception.

Please report an issue on https://bitbucket.org/fenics-project/dolfin.

I reported an issue here

There is a problem even with two fields of the same FunctionSpace

Apparently, an XDMFFile doesn't accept the << operator anymore (in Python at least). One has to use the write function, namely

file.write(u, t)
...