bempp / bempp-cl

A fast Python based just-in-time compiling boundary element library
http://www.bempp.com
MIT License
146 stars 38 forks source link

Bessel function use in the definition of the incident field #158

Open nazalli-choucha opened 2 years ago

nazalli-choucha commented 2 years ago

Hello,

I'm trying to define an incident acoustic field with a directivity function :

from scipy.special import j1
k = 2.
R = 0.1
@bempp.api.complex_callable
def p_inc_callable(x, n, domain_index, result):
    r = np.sqrt(np.power(x[0],2)+np.power(x[1],2)+np.power(x[2]-1,2))
    rho = np.sqrt(np.power(x[0],2) + np.power(x[1],2))
    val = k * R * rho / r
    d = j1(val) / val
    theta = np.arcsin(rho / r)
    result[0] = (np.exp(-1j * k * r) / r) * directivity * np.cos(rho / r)

I got the following error :

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'j1': Cannot determine Numba type of <class 'numpy.ufunc'>

File "../../tmp/ipykernel_4292/2670867267.py", line 62:
<source missing, REPL/exec in use?>
evantwout commented 2 years ago

The Numba library does not recognise all special functions. You can switch off the Numba JIT acceleration: @bempp.api.complex_callable(jit=False) See http://bempp.com/handbook/api/grid_functions.html#disabling-just-in-time-compilation

The code runs fine with Numba disabled (also change d in directivity).

nazalli-choucha commented 2 years ago

Thank you for your help. It worked fine.