pybind11 binding for BoundaryMesh::entity_map missing. moving boundary facet marker to submesh

5 months ago by
Sa Wu  

With the latest pull from git, 2018.1.0.dev0, BoundaryMesh.entity_map is not known in the Python Interface.

Lines 218-222 python/src/mesh.cpp

    // dolfin::BoundaryMesh
    py::class_<dolfin::BoundaryMesh, std::shared_ptr<dolfin::BoundaryMesh>, dolfin::Mesh>
      (m, "BoundaryMesh", "DOLFIN BoundaryMesh object")
      .def(py::init<const dolfin::Mesh&, std::string, bool>(),
           py::arg("mesh"), py::arg("type"), py::arg("order")=true);

It's still there in the the 'dolfin/mesh/BoundaryMesh.h' header, lines 65-71.

    /// Get index map for entities of dimension d in the boundary mesh
    /// to the entity in the original full mesh
    MeshFunction<std::size_t>& entity_map(std::size_t d);

    /// Get index map for entities of dimension d in the boundary mesh
    /// to the entity in the original full mesh (const version)
    const MeshFunction<std::size_t>& entity_map(std::size_t d) const;

I'm using the map, to transfer interface markers from the boundary of a domain to the boundary of a submesh:

I got this from an answer to another question but can't find it right now.

I'll gladly take alternative ways to do this more or less efficiently with the new/abridged python bindings.

from dolfin import *

extended_mesh = UnitSquareMesh(10,10)
extended_bmesh = BoundaryMesh(extended_mesh, 'exterior')

top = AutoSubDomain(lambda xx, on: on and near(xx[1], 1))
right = AutoSubDomain(lambda xx, on: on and near(xx[0], 1))
extended_facets = MeshFunction('size_t', extended_mesh, 1, 0)
top.mark(extended_facets, 1)
right.mark(extended_facets, 2)

extended_domains = MeshFunction('size_t', extended_mesh, 2, 0)
fine_marker = AutoSubDomain(lambda xx, on: xx[0] > 0.5 and xx[1] > 0.5)
fine_marker.mark(extended_domains, 1)
fine_mesh = SubMesh(extended_mesh, extended_domains, 1)
fine_bmesh = BoundaryMesh(fine_mesh, 'exterior')

extended_bmap = extended_bmesh.entity_map(basedim-1)
fine_bmap = fine_bmesh.entity_map(basedim-1)
facets_array = extended_facets.array()
fine_facets = MeshFunction('size_t', fine_mesh, basedim-1, 0)
fine_facets_array = fine_facets.array()
vmap ='parent_vertex_indices', 0)
for fine_cell in cells(fine_bmesh):
    fine_facet = Facet(fine_mesh, fine_bmap[fine_cell.index()])
    fine_facet_vertices_set = set(vmap[fine_facet.entities(0)])
    for extended_cell in cells(extended_bmesh):
        extended_facet = Facet(extended_mesh, extended_bmap[extended_cell.index()])
        if set(extended_facet.entities(0)) == fine_facet_vertices_set:
            fine_facets_array[fine_facet.index()] = facets_array[extended_facet.index()]
    del fine_facet_vertices_set
Community: FEniCS Project
You could implement the missing pybind11 interface and a test in a branch and submit a pull request.
written 5 months ago by Nate  

2 Answers

5 months ago by
We discussed this today and we would support this being added through a pull request. Let us know on our Slack if you need any assistance.
5 months ago by
Sa Wu  

Thanks, added few lines for the interface. would have to think about reliable test though.

Please login to add an answer/comment or follow this question.

Similar posts:
Search »