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

How to get a mesh function from a mesh file

0 votes

I'm generating the XML mesh file using the VMTK, and it creates the mesh and the boundary ids in just one XML file

<?xml version="1.0"?>
 <dolfin xmlns:dolfin="http://www.fenicsproject.org">
  . . . ( Vertices and Cells)
  <domains>
   <mesh_value_collection type="uint" dim="2" size="7136">
     <value cell_index="2" local_entity="3" value="3" />

My questions is if there is a way to get this as a MeshFunction directly form the XML file

I want to calculate the area of the boundaries and doing

area = assemble(Constant(1.0)*ds(domain=mesh,subdomain_id=boundary_id))

keeps returning zero

Thanks in advance

asked Jan 20, 2016 by paulo.yamabe FEniCS Novice (220 points)

1 Answer

+2 votes
 
Best answer

To get a MeshFunction , do:

# Read mesh 
mesh = Mesh("mesh.xml")

# Topological dimension
D = mesh.topology().dim()

# Create FacetFunction from domain data attached to mesh
mf = MeshFunction("size_t", mesh, D - 1, mesh.domains())
answered Jan 21, 2016 by Garth N. Wells FEniCS Expert (35,930 points)
selected Jan 21, 2016 by paulo.yamabe

Thank you, that worked

...