# How to export potential operator as matrix

**URL:** <https://bempp.discourse.group/t/how-to-export-potential-operator-as-matrix/202>\
**Category:** Bempp\
**Created:** [11 July 2023 06:41 UTC](https://bempp.discourse.group/t/how-to-export-potential-operator-as-matrix/202 "2023-07-11T06:41:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Marco](https://bempp.discourse.group/u/Marco)\
**Post date:** [11 July 2023 06:41 UTC](https://bempp.discourse.group/t/how-to-export-potential-operator-as-matrix/202/1 "2023-07-11T06:41:46Z")

</div>

Hi, I want to construct an “acoustic transfer matrix”, which maps source pressure on the boundary to the field points. Construction of the transfer matrix requires operator inverse on the boundary operator. Yes, I can convert boundary operator into matrix. However, I can’t find a way to convert potential operator into a (strong form) matrix.

---

<div class="post-metadata">

**Author:** ![hkutschka](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hkutschka](https://bempp.discourse.group/u/hkutschka)\
**Post date:** [26 March 2024 22:31 UTC](https://bempp.discourse.group/t/how-to-export-potential-operator-as-matrix/202/2 "2024-03-26T22:31:00Z")

</div>

Hi Marco,

unfortunately, I cannot answer your question but I have basically the same question for the Laplace single layer or double layer potential operators. In the past, there was a discrete\_operator member in the bempp.api.assembly.PotentialOperator class: [Operator concepts — The BEM++ Project](http://www.bempp.org/operators_and_potentials.html)  
But I did not find an equivalent in the current bempp-cl. I am curious about the reasons for not offering a matrix representation of potential operators. If I find a solution, I will post it here.

---

<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:** [26 April 2024 13:28 UTC](https://bempp.discourse.group/t/how-to-export-potential-operator-as-matrix/202/3 "2024-04-26T13:28:04Z")

</div>

The bempp-cl library provides functionality to export the boundary integral operators as Numpy matrices (`bempp.api.as_matrix()`). However, the potential integral operators can currently not be exported as matrices. They need to be evaluated on a `GridFunction`.

A trick that may serve you is to create a `GridFunction` with a single dof excited, that is, a `GridFunction` with coefficients all set to zero but one index set to one. Applying the potential operator to such a GridFunction will evaluate the field emitted from a single dof.

Here is a minimal working example.

```auto
import bempp.api
import numpy as np

grid = bempp.api.shapes.sphere(h=.5)
space = bempp.api.function_space(grid, "P", 1)

my_dofid = 0 # select dof id
my_gridcoef = np.zeros(space.global_dof_count)
my_gridcoef[my_dofid] = 1
my_gridfun = bempp.api.GridFunction(space, coefficients=my_gridcoef)

evaluation_points = np.array([[1.1,2,10],[0,0,0],[0,0,0]])
slp_pot = bempp.api.operators.potential.laplace.single_layer(space, evaluation_points)
field_values = slp_pot.evaluate(my_gridfun)
print(field_values)

```

You can loop over different dofs, but this may become computationally expensive for large grids.
