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

MeshFunction from MeshValueCollection in a file?

0 votes

Hi - I've got an external program that generates a triangular mesh as a FEniCS XML file, and a MeshValueCollection file that is supposed to represent the boundary condition locations for the same mesh. Is there a way to load the MeshValueCollection into FEniCS and convert it to a MeshFunction using the Python interface? (It seemed like in the C interface there was a constructor for MeshFunction that took a mesh and a MeshValueCollection).

I'm using FEniCS 1.2.0, and both the mesh and the mesh value collection load without error.

asked Nov 5, 2013 by timm FEniCS User (2,100 points)

1 Answer

+1 vote
 
Best answer

Hi,

If the XML file contains the MeshValueCollection in the 'right' format, then you can load in as a mesh function in python:

mesh=Mesh("mesh_file_name")
mvc = MeshValueCollection("size_t", mesh, "test_mesh_bcs.xml", 1)

Then you need convert to mesh function. The problem is how to find the global index of facets based on the local index.

mvc.values() # this would return a dictionary to indicate the local index and values

I know there is function in DOLFIN to find the connection between local index and global index for vertices in the GENERICDOFMAP class, but i do not know if there exists such a function to find the map between local index and global one for facets.

But I think you can find that through the following way: (mvs.values() contains the cell index and local index in that cell)

  1. Based on the cell index, find the connectivity of the cell with the facets. Then with that connectivity, we get the global index of facets for each local one

  2. Create the mesh function on facets and then we just need to assignment the corresponding value to finish the construction of the mesh function you want.

Hope it is not a mess. And if anyone better way to find the connection between local and global index for facets, that would be great and be beneficial to me also.

answered Nov 6, 2013 by jying FEniCS User (2,020 points)
selected Nov 8, 2013 by timm

Ok - I think that I have the file in the right format. There are about 2800 edges in the mesh, but the mesh value collection that I am using to try to mark where the boundary conditions are is just a small fraction of them (56):

<?xml version="1.0" encoding="UTF-8"?>
<dolfin xmlns:dolfin="http://fenicsproject.org">
  <mesh_value_collection name="boundary_markers" type="uint" dim="1" size="56">
    <value cell_index="225" local_entity="2" value="2" />
    <value cell_index="530" local_entity="0" value="2" />
   … stuff removed to save space … 
    <value cell_index="230" local_entity="2" value="1" />
    <value cell_index="420" local_entity="2" value="1" />
    <value cell_index="269" local_entity="0" value="1" />
  </mesh_value_collection>
</dolfin>

I can then load the mesh and the mesh value collection like this:

from dolfin import *    
mesh = Mesh("test_mesh.xml")
mvc = MeshValueCollection("size_t", mesh, "test_mesh_bcs.xml", 1)

The mesh value collection seems to be loading without raising an error - but the mesh data doesn't seem to know anything about it. This is probably because I don't really know what I am doing …

[mvc.empty(), mvc.size(), mvc.name()]
[False, 56, 'boundary_markers']
mesh.data().mesh_function("boundary_markers")
mesh.data().mesh_function("something_not_there")
Is there a mapping of (cell number, local entity) to global edge index?
...