# Importing a 2D mesh from FEniCSx

**URL:** <https://bempp.discourse.group/t/importing-a-2d-mesh-from-fenicsx/335>\
**Category:** Applications\
**Created:** [8 July 2025 15:48 UTC](https://bempp.discourse.group/t/importing-a-2d-mesh-from-fenicsx/335 "2025-07-08T15:48:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://bempp.discourse.group/u/EDE)\
**Post date:** [8 July 2025 15:48 UTC](https://bempp.discourse.group/t/importing-a-2d-mesh-from-fenicsx/335/1 "2025-07-08T15:48:16Z")

</div>

Dear Bempp users,

I am trying to implement a vibroacoustics FEM-BEM coupled model using FEniCSx and Bempp.  
The model is simplified to a box with only one surface vibrates to produce sound into the exterior (the rest is rigid), and I would like to model the box in FEM and the vibrating surface in BEM.  
The FEM part is already implemented, but I am struggling to import the surface mesh into Bempp side.

`fenicsx.fenics_to_bempp_trace_data` would create a function space for the boundary of the mesh given, so I can’t directly give the 2D submesh of the vibrating surface created in FEniCSx.

Meanwhile, even if I give `fenicsx.fenics_to_bempp_trace_data` the whole cube to create a function space for the all 6 surfaces, I am under the impression that I would not be able to use gmsh Physical tags to selectively choose and access the vibrating surface.

Ideally, I would like to create the trace space specifically for this one vibrating surface without dealing with coordinates to identify which surface is which.

Does anyone have any idea of how I might be able to do this?

Thank you in advance for your time, and I am looking forward to your advice.

---

<div class="post-metadata">

**Author:** ![Elwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bempp.discourse.group/elwin/32/38_2.png) [@Elwin](https://bempp.discourse.group/u/Elwin)\
**Post date:** [15 September 2025 12:20 UTC](https://bempp.discourse.group/t/importing-a-2d-mesh-from-fenicsx/335/2 "2025-09-15T12:20:42Z")

</div>

Hi,

The function `trace_space, trace_matrix = fenicsx.fenics_to_bempp_trace_data(fenics_space)` returns the variable `trace_space`, which is a bempp-cl `FunctionSpace`. You can access its grid with the attribute `trace_space.grid`.

Indeed, when extracting a surface mesh from a fenics mesh, the gmsh physical tags are not used, which you can check by accessing `trace_space.grid.domain_indices`. They are all zero.

For simple structures like cubes, you can find subsets of the grid manually, e.g., finding a face of a cube as `face_elements = np.isclose(trace_space.grid.centroids[:,0], 0)` to find the face at x=0, up to rounding errors.

With this information, you can overwrite the `domain_indices` attribute, create a new mesh, or create a new function space as `face_space = bempp_cl.api.function_space(trace_space.grid, support_elements=face_elements, kind="DP", degree=0)`.

I hope these ideas will help you move forward.

Best,  
Elwin
