## Boundary operators

The principle operator concept in Bempp is that of a boundary operator. A boundary operator

is a mapping from a `domain`

space into a `range`

space , where both and are defined on a given surface grid. Bempp does not directly work with the boundary operator itself but with a weak form

where is the dual space to the range space (in Bempp, we use the keyword dual_to_range for the space ).

Boundary operators are defined in the subpackage bempp.api.operators.boundary. Details of all available boundary operators in Bempp can be found in the available operators tutorial. All boundary operators take three space arguments: domain, range, and dual_to_range, which correspond to the spaces , and . Additionally, Helmholtz and Maxwell operators take the wavenumber of the problem as a fourth argument.

The following code snippet defines the Laplace single layer boundary operator on a space of piecewise constant functions. For simplicity, we choose all three space arguments to be identical.

grid = bempp.api.shapes.regular_sphere(3)

space = bempp.api.function_space(grid, "DP", 0)

slp = bempp.api.operators.boundary.laplace.single_layer(space, space, space)

It is important to note that the above code only sets up data structures. The discretisation is not performed until it is required.

A complete algebra for operators is implemented. We can add operators, multiply them with scalars, and also multiply operators. Hence, the following operations are all valid.

sum_operator = slp + slp

squared_operator = slp * slp

Particularly, interesting is the last step. Assume that the matrix is the Galerkin discretisation of the slp operator with the given space of piecewise constant functions. Then the discretisation of squared_operator is computed as , where is the mass matrix of inner products between functions in the dual_to_range and range spaces of `slp`

. This is done automatically in Bempp so that the user does not have to deal with the correct mass matrix operations manually. More details of the operator algebra in Bempp can be found in Betcke *et al* 2017.

Operators can also be multiplied with grid functions as shown in the following.

import numpy as np

number_of_global_dofs = space.global_dof_count

coeffs = np.ones(number_of_global_dofs)

grid_fun = bempp.api.GridFunction(space, coefficients=coeffs)

# Now apply the operator to the grid function

result_fun = slp * grid_fun

In order to apply the operator slp to the grid function grid_fun, Bempp needs to assemble the operator. This is the first step, where an actual discretisation is computed. However, assembling the operator is not enough. To compute the coefficients of the grid funtion result_fun a mass matrix needs to be assembled since the coefficients of the result are computed as

where is the vector of coefficients of grid_fun. Again, all this is handled automatically by Bempp.

## Discrete boundary operators

Quite often it is necessary to have more direct access to discretisations of boundary operators. For this a boundary operator provides two methods weak_form and strong_form. Given the variational form as defined above the discretisation of this variational form is the matrix defined by

where the are the basis functions of the `dual_to_range`

space and the are the basis functions of the `domain`

space .

Discrete boundary operators give access to the discretised matrix by providing routines to perform matrix-vector products and query the underlying matrix. The following gives an example.

print("Shape of the matrix: {0}".format(slp_discrete.shape))

print("Type of the matrix: {0}".format(slp_discrete.dtype))

x = np.random.rand(slp_discrete.shape[1])

y = slp_discrete * x

Type of the matrix: float64

Discrete boundary operators implement the LinearOperator protocol provided by recent SciPy versions. This means that the standard operations such as multiplications with scalars, addition, and multiplication are available.

It is possible to convert a discrete boundary operator into a standard NumPy array. However, this is not recommended for larger problems. Depending on the discretisation mode a discrete operator may store a matrix only implicitly and not as a dense array. This then needs to be converted to a dense array by multiplication with an identity matrix. The following command turns a discrete boundary operator into a NumPy array.

print(slp_mat)

3.35583598e-05 3.43634489e-05]

[ 1.59811402e-04 6.20059370e-04 1.21665497e-04 …, 3.14103888e-05

3.27991479e-05 3.39030174e-05]

[ 1.60210104e-04 1.21313696e-04 6.20059370e-04 …, 3.33189379e-05

3.55234393e-05 3.65203446e-05]

…,

[ 3.15574627e-05 3.14105754e-05 3.33145031e-05 …, 1.68183155e-03

4.05004969e-04 7.46497936e-04]

[ 3.35100884e-05 3.27972380e-05 3.54902004e-05 …, 4.05005071e-04

1.68183155e-03 7.46490617e-04]

[ 3.43687317e-05 3.39000037e-05 3.65254704e-05 …, 7.46498073e-04

7.46490752e-04 1.79722275e-03]]

While the method weak_form returns a discretisation of the variational form the method strong_form returns a discretisation of the action of the original operator into the range space. Hence, the operators returned by the two methods are as follows:

`weak_form`

:`strong_form`

:

Here, is the mass matrix between the range and dual_to_range spaces of the operator. We note that is never formed explicitly but the corresponding system is solved internally by sparse LU decomposition, where the factorisation is only done once and then stored.

## Potential operators

A potential operator maps from a given space over the boundary grid into a set of external evaluation points . Let us demonstrate at a simple example how to evaluate the Laplace single layer potential operator at certain points away from the boundary.

evaluation_points = np.array([[2, 3],

[1, 0],

[4, 5]])

# Create the Laplace single-layer potential operator

slp_pot = bempp.api.operators.potential.laplace.single_layer(space, evaluation_points)

potential_values = slp_pot * grid_fun

print(potential_values)

Unlike the boundary operators, potentials are assembled immediately when they are instantiated. Potential operators implement a simple algebra, allowing multiplication with scalars and addition with other potentials. To apply a potential to a given surface density it can be multiplied with a grid function as shown above. The result is an array of potential values, in which each column consists of the components of the potential at a given evaluation point. In this case the potential is scalar, hence each column has only one entry.