# Invert DL matrix in single step to compute full surface impedance matrix

**URL:** https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302
**Category:** Applications
**Created:** [9 December 2024 15:58 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302 "2024-12-09T15:58:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hambricacoustics](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hambricacoustics](https://bempp.discourse.group/u/hambricacoustics)
#### Post date: [9 December 2024 15:58 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302/1 "2024-12-09T15:58:26Z")

</div>

Hi, I am exploring the use of BEMPP for computing surface impedance matrices [Z] (an NxN matrix of columns of surface pressures induced by individual velocity sources). This requires inverting the DL operator matrix. All the examples I have seen only solve for a single RHS using GMRES. Doing this for every source point is computationally exorbitant. Does BEMPP have a function to simply invert the DL matrix and output it? Or, can I call GMRES once with multiple RHS (I got an error when I tried it, which isn’t surprising). Or perhaps there are other inversion functions that work with BEMPP. Thanks,

---

<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: [16 December 2024 21:01 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302/2 "2024-12-16T21:01:29Z")

</div>

The discrete boundary operators in Bempp are linear operators that implement a matrix-vector multiplication and are compatible with the iterative linear solvers in SciPy. If you want direct access to the matrix and use custom linear solvers or inversion techniques, you can use the function `bempp.api.as_matrix()`. This function creates a dense matrix in NumPy format.

---

<div class="post-metadata">

### Author: ![hambricacoustics](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hambricacoustics](https://bempp.discourse.group/u/hambricacoustics)
#### Post date: [17 December 2024 15:31 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302/3 "2024-12-17T15:31:29Z")

</div>

Thanks for the answer. Does bempp still support h-matrix methods or have they been dropped?

---

<div class="post-metadata">

### Author: ![hambricacoustics](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hambricacoustics](https://bempp.discourse.group/u/hambricacoustics)
#### Post date: [17 December 2024 19:56 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302/4 "2024-12-17T19:56:54Z")

</div>

I tried the .as\_matrix function but get the error: AttributeError: ‘BoundaryOperatorWithAssembler’ has no attribute ‘to-dense’. Here’s how I assemble the operators:

grid = bempp.api.Grid(vertices, elements)  
space = bempp.api.function\_space(grid,“P”,1) # piecewise linear  
Lk = bempp.api.operators.boundary.helmholtz.single\_layer(space, space, space, k)  
Mk = bempp.api.operators.boundary.helmholtz.double\_layer(space, space, space, k)  
Lkout = bempp.api.as\_matrix(Lk)  
Mkout = bempp.api.as\_matrix(Mk)

Any suggestions? Thanks again,

-S. Hambric

---

<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: [18 December 2024 12:35 UTC](https://bempp.discourse.group/t/invert-dl-matrix-in-single-step-to-compute-full-surface-impedance-matrix/302/5 "2024-12-18T12:35:30Z")

</div>

In your example code, `Lk` and `Mk` are continuous operators. You need to assemble the discrete operator first. Try `Lkout = bempp.api.as_matrix(Lk.weak_form())` to assemble the weak form. Alternatively, use `strong_form()` to assemble the strong form.

The legacy bempp v.3 has H-matrix compression but bempp-cl has not. It has an interface to ExaFMM for fast matrix-vector products.
