Modified Green's function

Hi Matthew and Timo,

there is a new problem for me to solve and so a new question for you :slight_smile:

I would like to consider an integral operator which is not implemented yet, so e.g. something like

(K\phi)(x) = \int_\varGamma k(x,y)\phi(y) d(y)

with k(x,y)= \sin(|x-y|)/|x-y| or even more complicated

(K\phi)(x)=\int_\varGamma k(x,y, \phi(y)) d(y)

with k(x,y,\phi)= \sin(|x-y|)/|x-y| ((x-y)\cdot \phi )\phi.
Do you know a possibility to implement sth like that? For a start the easier version would be ok.
Probably an efficient way to implement this would be to define my own integral operator, how would that work?
I already tried sth inefficient like

phi=bempp.api.GridFunction(rwg_space, fun=phi_fun, dual_space=rwg_space) 
mass = bempp.api.operators.boundary.sparse.identity(rwg_space, rwg_space, rwg_space).weak_form()

def operator_fun(x, n, domain_index, result):
    def kernel_fun(xx,n,domain_index,result):
        result[:]= np.array([np.sin(np.abs(x-xx))/np.abs(x-xx),0,0])
    kernel=bempp.api.GridFunction(rwg_space, fun=kernel_function, dual_space=rwg_space)*phi.coefficients)
    result[:] = np.array([res,0,0])
operator_applied = bempp.api.GridFunction(rwg_space, fun=operator_fun, dual_space=rwg_space) 

But it throws the error

TypingError: Failed in nopython mode pipeline (step: convert make_function into JIT functions)
TypingError: Failed in nopython mode pipeline (step: convert make_function into JIT functions)
Cannot capture the non-constant value associated with variable 'x' in a function that will escape.

File "<ipython-input-67-74e0f7e2f0e4>", line 4:
def operator_fun(x, n, domain_index, result):
    <source elided>

and if I replace xx by x only in line 4

def kernel_fun(x,n,domain_index,result): 

it throws

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'rwg_space': cannot determine Numba type of <class ''>

Am I not allowed to use bempp commands inside a bempp.api.complex_callable ?

Thank you very much for some hints and help,

Hi Jan,

definining operators is very different from the grid function mechanics. Operators are hard coded in Bempp-cl in the sense that we have files with dictionaries of operator identifiers that link to the corresponding function implementations. The only way to change this at the moment is to dive into this and modify the Bempp-cl source code itself.

Best wishes