BoundaryMesh entity_map to numpy segmentation fault in newer versions

Hi everyone!

I am looking to run the code from the solution to the question asked in this previous forum from 2017:

https://fenicsproject.org/qa/12282/change-values-function-mesh-function-defined-boundarymesh/

The issue is when I run this code in the latest fenics version, there is a segmentation fault in the function:

vb_v = np.array(bmesh.entity_map(0), dtype=int)

This code runs just fine when I use a docker container quay io/fenicsproject/stable:2017.1.0, but the segmentation fault occurs when using the latest version quay io/fenicsproject/stable:latest.

The segmentation fault occurs when trying to convert the entity_map object into a numpy array. Does anyone have any ideas on the cause of this and/or possible solutions for the latest version? Many thanks.

This is because bmesh.entity_map(0) is not an array, see MWE:

from dolfin import *
import numpy as np
mesh = UnitSquareMesh(10,10)

bmesh = BoundaryMesh(mesh, 'exterior')
vb_2_v = bmesh.entity_map(0)
print(vb_2_v)

which yields:
<dolfin.cpp.mesh.MeshFunctionSizet object at 0x7f4e84f5b500>
You can access the underlying array with:

vb_2_v.array()
1 Like

Yes, that makes sense. Thank you dokken!