Qeustion using @bempp.api.complex_callable

91 views
Skip to first unread message

Sangwoo Kang

unread,
Jun 17, 2020, 8:06:56 PM6/17/20
to bempp
Dear all

Hello. I try to translate my bempp code as bempp-cl to solve large problem in windows. 
But I got the error messages when I define the Gridfunction . 
My incident field is generated by surface currents J_DUT, M_DUT. 
It is working in the bempp 3.3.4 version with docker. 
But the following code is not working in bempp-cl when I define the IncidentEfiled function as the following: 


case1. 
def IncidentEfield(point):
    temppoint = point.reshape((3,1))
    PropLpart = bempp.api.operators.potential.maxwell.electric_field(div_space_DUT, temppoint,k0)
    PropKpart = bempp.api.operators.potential.maxwell.magnetic_field(div_space_DUT, temppoint,k0)
    JJ = J_DUT*eta0
    MM = M_DUT
    tempresult = (PropLpart*JJ - PropKpart*MM)
    value = tempresult.reshape(-1)
    return value


@bempp.api.complex_callable
def tangential_trace(point, n, domain_index, result):
    value = IncidentEfield(point)
    result[:] = np.cross(value, n)

I got a error message TypingError: cannot determine Numba type of <class 'function'>.

case2. 
@numba.jit
def IncidentEfield(point):
    temppoint = point.reshape((3,1))
    PropLpart = bempp.api.operators.potential.maxwell.electric_field(div_space_DUT, temppoint,k0)
    PropKpart = bempp.api.operators.potential.maxwell.magnetic_field(div_space_DUT, temppoint,k0)
    JJ = J_DUT*eta0
    MM = M_DUT
    tempresult = (PropLpart*JJ - PropKpart*MM)
    value = tempresult.reshape(-1)
    return value

@bempp.api.complex_callable
def tangential_trace(point, n, domain_index, result):
    value = IncidentEfield(point)
    result[:] = np.cross(value, n)

In this case, I got a message 
TypingError: Invalid use of type(CPUDispatcher(<function IncidentEfield at 0x000001E6EE592DC8>)) with parameters (array(float64, 1d, A))
 * parameterized During: resolving callee type: type(CPUDispatcher(<function IncidentEfield at 0x000001E6EE592DC8>))


Please let me know if you have any idea to handle this issue. 
Thank you in advance. 

BR,
Sangwoo Kang

Matthew Scroggs

unread,
Jun 22, 2020, 9:36:14 AM6/22/20
to bempp
Hello,

Numba can's compile your function, and I think it would be very difficult or even impossible to rewrite it in a way that numba could compile it.

Currently, Bempp-cl always uses Numba when assembling a GridFunction from a callable. I've added a pull request (https://github.com/bempp/bempp-cl/pull/17) to allow the user to change this. Once this is merged (or if you check out the mscroggs/no_jit branch), you should be able to make your GridFunction using:

bempp.api.GridFunction(space, fun=tangential_trace, jit=False, function_type='complex')

Timo Betcke

unread,
Jun 23, 2020, 4:18:09 PM6/23/20
to bempp
Hi,

there is a way around this. You can use the  objmode context manager within your grid function code to denote a block that should not be compiled with Numba.

However, be warned. This slows down the grid function generation significantly as the corresponding code now needs to go through the Python interpreter.

Best wishes

Timo
Reply all
Reply to author
Forward
0 new messages