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

read mesh from h5 file format

0 votes

one more question; if i use this code (for read a h5 file);

f = HDF5File('input_6x4_mesh.h5', 'r')
mesh = Mesh()
f.read(mesh, 'mesh')
V = FunctionSpace(mesh, 'Lagrange', 1)

i got this error again;

new_HDF5File expected 3 arguments, got 2

but if i add "mesh.mpi_comm()" for above code i get;

'module' object has no attribute 'mpi_comm'

any idea for this?

thanks

related to an answer for: writing h5 file
asked Jun 28, 2014 by BA FEniCS Novice (240 points)

1 Answer

+2 votes
 
Best answer

Use mpi_comm_world() instead, like this:

f = HDF5File(mpi_comm_world(), 'input_6x4_mesh.h5', 'r')
answered Jun 30, 2014 by johannr FEniCS Expert (17,350 points)
selected Jul 1, 2014 by Garth N. Wells

Hi

I added "mpi_comm_world()" into my code and there is an error;

TypeError Traceback (most recent call
last) /usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in
execfile(fname, *where)
176 else:
177 filename = fname
--> 178 builtin.execfile(filename, *where)

/home/burak/Documents/MATLAB/git öncesi test/read_h5.py in ()
4
5 mesh = Mesh()
----> 6 f.read(mesh, 'mesh')
7
8 V = FunctionSpace(mesh, 'CG', 1)

TypeError: in method 'dolfin::MeshValueCollection< bool > &', argument
2 of type 'HDF5File_read'

I think there is problem with MeshValueCollection class. Any idea for that?

Thanks

You are missing the third argument in HDF5File.read. This should work:

f.read(mesh, 'mesh', False)

See also the documentation.

Hi

if i put this in a python module, like this;

def write_solution(ouput_filename):
    g = HDF5File(mesh.mpi_comm(),ouput_filename,'w')
    g.write(u,'u')
    return u

i have an error;

AttributeError: 'module' object has no attribute 'mpi_comm'

any idea for this?

thanks

Burak

Please include a complete but minimal script that reproduces the error.

...