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

writing h5 file

0 votes

Hello

I want to write mesh in h5 file format. There is an explanation for this;

http://fenicsproject.org/qa/274/consistent-io-of-mesh-and-function-in-parallel

when I use this commend i get this error;

In 1: from dolfin import *
In [2]: mesh = UnitSquareMesh(5, 5)
In [3]: V = FunctionSpace(mesh, 'CG', 1)
In [4]: u = project(Expression('x[0]'), V)
Solving linear system of size 36 x 36 (PETSc Krylov solver).

In [5]: f = HDF5File('u.h5', 'w')

TypeError Traceback (most recent call last)
in ()
----> 1 f = HDF5File('u.h5', 'w')

/usr/lib/python2.7/dist-packages/dolfin/cpp/io.pyc in init(self, args)
909
910 """
--> 911 _io.HDF5File_swiginit(self,_io.new_HDF5File(
args))
912 swig_destroy = _io.delete_HDF5File
913 def close(self):

TypeError: new_HDF5File expected 3 arguments, got 2

In [6]: f.write(mesh, 'mesh')

NameError Traceback (most recent call last)
in ()
----> 1 f.write(mesh, 'mesh')
NameError: name 'f' is not defined

In [7]: f.write(u, 'u')

NameError Traceback (most recent call last)
in ()
----> 1 f.write(u, 'u')
NameError: name 'f' is not defined

Any idea for this?
Thanks

asked Jun 27, 2014 by BA FEniCS Novice (240 points)

1 Answer

+3 votes

Hi, try

f = HDF5File(mesh.mpi_comm(), 'u.h5', 'w')

The error message

TypeError: new_HDF5File expected 3 arguments, got 2

tells you that in call to HDF5File()you were missing one argument. Check out constructor's
signature here to see that the first argument must by MPI communicator.

answered Jun 28, 2014 by MiroK FEniCS Expert (80,920 points)

thanks, it works now!

read mesh from h5 file format

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

Check the type of mesh in my code and your code

print type(mesh)

In my previous post it yields <class 'dolfin.cpp.mesh.UnitSquareMesh'>. In your case now, the answer is most likely <type module> and that's the cause of error.

Hi

Type of the mesh is;

<class 'dolfin.cpp.mesh.Mesh'>

I also try to do something like Mesh.mpi_comm() or **mesh.Mesh.mpi_comm()**** but both do not work. Any idea for this?

Thanks

Burak

...