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

attach mesh data to mesh and write to file

+1 vote

Hi all,

In dolfin1.0, to attach the mesh data to a mesh and then write to a single xml file, we can achieve by simply create a mesh function with a given name, but in dolfin1.2, it seems this functionality is lost. Now, if i want to write the information of mesh and the associated mesh data together in a single XML file, how can I achieve this?

asked Jun 30, 2013 by jying FEniCS User (2,020 points)

Could you supply code snippet running in FEniCS 1.0? This should also demonstrate a purpose for what are stored data used then.

the snippet in FEniCS 1.0:

from dolfin import *
mesh = UnitSquare(2,2)
a = mesh.data().create_mesh_function("cells",2)
a.set_all(1)
file=File("mesh.xml")
file<< mesh

Then in the mesh.xml file, not only it includes the vertices and triangle, but also contain the mesh function information with the name cells. In FEniCS, this does not work now.

1 Answer

+1 vote
 
Best answer

Do rather

from dolfin import *
mesh = UnitSquareMesh(2, 2)
a = MeshFunction('size_t', mesh, 2)
a.set_all(1)
File("mesh.xml") << mesh
File("mesh_func.xml") << a

as MeshData.create_mesh_function() will be removed in next release.

To access stored data

mesh = Mesh('mesh.xml')
a = MeshFunction('size_t', mesh, 'mesh_func.xml')

This is more stable solution than storing markers within mesh.

answered Jun 30, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Jun 30, 2013 by jying

Thanks a lot, Jan. But I would like to know how to put these two information in a single XML file instead of two, since this would be more convenient to read in the mesh and mesh data.

I think DOLFIN is no more able to produce XML mesh with markers stored within. Ability of reading such files is kept only for backwards compatibility and also because dolfin-convert script produces such files.

ok, thanks a lot again

It is possible to read mesh XML files with data attached, and the format has not changed for some time.

The recent change was that the data is no longer stored internally as a MeshFunction (which was to remove a circular dependency).

There is a deprecated XML storage format - it is still supported in serial, but deprecated because it is not suitable in parallel.

Ok. A usage of the newly preferred HDF5 format is indicated here http://fenicsproject.org/qa/274/consistent-io-of-mesh-and-function-in-parallel. But note that Function HDF5 I/O is only in development version so far.

...