Example #1
0
def test_diff():
    assert besselj(n, z).diff(z) == besselj(n - 1, z)/2 - besselj(n + 1, z)/2
    assert bessely(n, z).diff(z) == bessely(n - 1, z)/2 - bessely(n + 1, z)/2
    assert besseli(n, z).diff(z) == besseli(n - 1, z)/2 + besseli(n + 1, z)/2
    assert besselk(n, z).diff(z) == -besselk(n - 1, z)/2 - besselk(n + 1, z)/2
    assert hankel1(n, z).diff(z) == hankel1(n - 1, z)/2 - hankel1(n + 1, z)/2
    assert hankel2(n, z).diff(z) == hankel2(n - 1, z)/2 - hankel2(n + 1, z)/2
Example #2
0
def test_diff():
    assert besselj(n, z).diff(z) == besselj(n - 1, z)/2 - besselj(n + 1, z)/2
    assert bessely(n, z).diff(z) == bessely(n - 1, z)/2 - bessely(n + 1, z)/2
    assert besseli(n, z).diff(z) == besseli(n - 1, z)/2 + besseli(n + 1, z)/2
    assert besselk(n, z).diff(z) == -besselk(n - 1, z)/2 - besselk(n + 1, z)/2
    assert hankel1(n, z).diff(z) == hankel1(n - 1, z)/2 - hankel1(n + 1, z)/2
    assert hankel2(n, z).diff(z) == hankel2(n - 1, z)/2 - hankel2(n + 1, z)/2
Example #3
0
def test_bessel_rand():
    assert td(besselj(randcplx(), z), z)
    assert td(bessely(randcplx(), z), z)
    assert td(besseli(randcplx(), z), z)
    assert td(besselk(randcplx(), z), z)
    assert td(hankel1(randcplx(), z), z)
    assert td(hankel2(randcplx(), z), z)
    assert td(jn(randcplx(), z), z)
    assert td(yn(randcplx(), z), z)
Example #4
0
def test_bessel_rand():
    assert td(besselj(randcplx(), z), z)
    assert td(bessely(randcplx(), z), z)
    assert td(besseli(randcplx(), z), z)
    assert td(besselk(randcplx(), z), z)
    assert td(hankel1(randcplx(), z), z)
    assert td(hankel2(randcplx(), z), z)
    assert td(jn(randcplx(), z), z)
    assert td(yn(randcplx(), z), z)
Example #5
0
def test_meromorphic():
    assert besselj(2, x).is_meromorphic(x, 1) == True
    assert besselj(2, x).is_meromorphic(x, 0) == True
    assert besselj(2, x).is_meromorphic(x, oo) == False
    assert besselj(S(2) / 3, x).is_meromorphic(x, 1) == True
    assert besselj(S(2) / 3, x).is_meromorphic(x, 0) == False
    assert besselj(S(2) / 3, x).is_meromorphic(x, oo) == False
    assert besselj(x, 2 * x).is_meromorphic(x, 2) == False
    assert besselk(0, x).is_meromorphic(x, 1) == True
    assert besselk(2, x).is_meromorphic(x, 0) == True
    assert besseli(0, x).is_meromorphic(x, 1) == True
    assert besseli(2, x).is_meromorphic(x, 0) == True
    assert bessely(0, x).is_meromorphic(x, 1) == True
    assert bessely(0, x).is_meromorphic(x, 0) == False
    assert bessely(2, x).is_meromorphic(x, 0) == True
    assert hankel1(3, x**2 + 2 * x).is_meromorphic(x, 1) == True
    assert hankel1(0, x).is_meromorphic(x, 0) == False
    assert hankel2(11, 4).is_meromorphic(x, 5) == True
    assert hn1(6, 7 * x**3 + 4).is_meromorphic(x, 7) == True
    assert hn2(3, 2 * x).is_meromorphic(x, 9) == True
    assert jn(5, 2 * x + 7).is_meromorphic(x, 4) == True
    assert yn(8, x**2 + 11).is_meromorphic(x, 6) == True
Example #6
0
def test_conjugate():
    n = Symbol('n')
    z = Symbol('z', extended_real=False)
    x = Symbol('x', extended_real=True)
    y = Symbol('y', real=True, positive=True)
    t = Symbol('t', negative=True)

    for f in [besseli, besselj, besselk, bessely, hankel1, hankel2]:
        assert f(n, -1).conjugate() != f(conjugate(n), -1)
        assert f(n, x).conjugate() != f(conjugate(n), x)
        assert f(n, t).conjugate() != f(conjugate(n), t)

    rz = randcplx(b=0.5)

    for f in [besseli, besselj, besselk, bessely]:
        assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I)
        assert f(n, 0).conjugate() == f(conjugate(n), 0)
        assert f(n, 1).conjugate() == f(conjugate(n), 1)
        assert f(n, z).conjugate() == f(conjugate(n), conjugate(z))
        assert f(n, y).conjugate() == f(conjugate(n), y)
        assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz)))

    assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I)
    assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0)
    assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1)
    assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y)
    assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z))
    assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz)))

    assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I)
    assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0)
    assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1)
    assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y)
    assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z))
    assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
Example #7
0
def test_conjugate():
    from sympy import conjugate, I, Symbol
    n, z, x = Symbol('n'), Symbol('z', real=False), Symbol('x', real=True)
    y, t = Symbol('y', real=True, positive=True), Symbol('t', negative=True)

    for f in [besseli, besselj, besselk, bessely, hankel1, hankel2]:
        assert f(n, -1).conjugate() != f(conjugate(n), -1)
        assert f(n, x).conjugate() != f(conjugate(n), x)
        assert f(n, t).conjugate() != f(conjugate(n), t)

    rz = randcplx(b=0.5)

    for f in [besseli, besselj, besselk, bessely]:
        assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I)
        assert f(n, 0).conjugate() == f(conjugate(n), 0)
        assert f(n, 1).conjugate() == f(conjugate(n), 1)
        assert f(n, z).conjugate() == f(conjugate(n), conjugate(z))
        assert f(n, y).conjugate() == f(conjugate(n), y)
        assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz)))

    assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I)
    assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0)
    assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1)
    assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y)
    assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z))
    assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz)))

    assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I)
    assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0)
    assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1)
    assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y)
    assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z))
    assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
Example #8
0
def test_conjugate():
    from sympy import conjugate, I, Symbol

    n = Symbol("n")
    z = Symbol("z", extended_real=False)
    x = Symbol("x", extended_real=True)
    y = Symbol("y", real=True, positive=True)
    t = Symbol("t", negative=True)

    for f in [besseli, besselj, besselk, bessely, hankel1, hankel2]:
        assert f(n, -1).conjugate() != f(conjugate(n), -1)
        assert f(n, x).conjugate() != f(conjugate(n), x)
        assert f(n, t).conjugate() != f(conjugate(n), t)

    rz = randcplx(b=0.5)

    for f in [besseli, besselj, besselk, bessely]:
        assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I)
        assert f(n, 0).conjugate() == f(conjugate(n), 0)
        assert f(n, 1).conjugate() == f(conjugate(n), 1)
        assert f(n, z).conjugate() == f(conjugate(n), conjugate(z))
        assert f(n, y).conjugate() == f(conjugate(n), y)
        assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz)))

    assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I)
    assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0)
    assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1)
    assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y)
    assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z))
    assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz)))

    assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I)
    assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0)
    assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1)
    assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y)
    assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z))
    assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
Example #9
0
def test_conjugate():
    from sympy import conjugate, I, Symbol
    n, z, x = Symbol('n'), Symbol('z', real=False), Symbol('x', real=True)
    y, t = Symbol('y', real=True, positive=True), Symbol('t', negative=True)

    for f in [besseli, besselj, besselk, bessely, jn, yn, hankel1, hankel2]:
        assert f(n, -1).conjugate() != f(conjugate(n), -1)
        assert f(n, x).conjugate() != f(conjugate(n), x)
        assert f(n, t).conjugate() != f(conjugate(n), t)

    rz = randcplx(b=0.5)

    for f in [besseli, besselj, besselk, bessely, jn, yn]:
        assert f(n, 1 + I).conjugate() == f(conjugate(n), 1 - I)
        assert f(n, 0).conjugate() == f(conjugate(n), 0)
        assert f(n, 1).conjugate() == f(conjugate(n), 1)
        assert f(n, z).conjugate() == f(conjugate(n), conjugate(z))
        assert f(n, y).conjugate() == f(conjugate(n), y)
        assert tn(f(n, rz).conjugate(), f(conjugate(n), conjugate(rz)))

    assert hankel1(n, 1 + I).conjugate() == hankel2(conjugate(n), 1 - I)
    assert hankel1(n, 0).conjugate() == hankel2(conjugate(n), 0)
    assert hankel1(n, 1).conjugate() == hankel2(conjugate(n), 1)
    assert hankel1(n, y).conjugate() == hankel2(conjugate(n), y)
    assert hankel1(n, z).conjugate() == hankel2(conjugate(n), conjugate(z))
    assert tn(hankel1(n, rz).conjugate(), hankel2(conjugate(n), conjugate(rz)))

    assert hankel2(n, 1 + I).conjugate() == hankel1(conjugate(n), 1 - I)
    assert hankel2(n, 0).conjugate() == hankel1(conjugate(n), 0)
    assert hankel2(n, 1).conjugate() == hankel1(conjugate(n), 1)
    assert hankel2(n, y).conjugate() == hankel1(conjugate(n), y)
    assert hankel2(n, z).conjugate() == hankel1(conjugate(n), conjugate(z))
    assert tn(hankel2(n, rz).conjugate(), hankel1(conjugate(n), conjugate(rz)))
def eval_sp_dp_QBX(order, k):
    """
    evaluates single layer, double layer and corr QBX coeffs for Helmholtz
    calculates image potential for y = -y - eta as well
    """
    x_1, y_1, x_2, y_2, eta = symbols("x_1, y_1, x_2, y_2, eta")
    nx_1, nx_2, ny_1, ny_2, r = symbols("nx_1, nx_2, ny_1, ny_2, r")
    dist = sqrt((x_1 - y_1)**2 + (x_2 - y_2)**2)
    kernel = I / 4 * hankel1(0, k * dist)
    single_layer = lambdify([x_1, x_2, y_1, y_2], kernel)
    green_normal_der = ny_1 * diff(kernel, y_1) + ny_2 * diff(kernel, y_2)
    double_layer = lambdify([x_1, x_2, y_1, y_2, ny_1, ny_2], green_normal_der)
    # image in y=0 calculations
    image_dist = sqrt((x_1 - y_1)**2 + (x_2 + y_2 + eta)**2)
    image_kernel = I / 4 * hankel1(0, k * image_dist)
    image_single_layer = lambdify([x_1, x_2, y_1, y_2, eta], image_kernel)
    image_green_normal_der = ny_1 * diff(image_kernel, y_1) + ny_2 * diff(
        image_kernel, y_2)
    image_double_layer = lambdify([x_1, x_2, y_1, y_2, eta, ny_1, ny_2],
                                  image_green_normal_der)
    # Grafs theorem term evaluations
    c_1 = x_1 + nx_1 * r
    c_2 = x_2 + nx_2 * r
    xc = sqrt((x_1 - c_1)**2 + (x_2 - c_2)**2)
    yc = sqrt((y_1 - c_1)**2 + (y_2 - c_2)**2)
    x_theta = atan2((x_2 - c_2), (x_1 - c_1))
    y_theta = atan2((y_2 - c_2), (y_1 - c_1))
    img_yc = sqrt((y_1 - c_1)**2 + (-(y_2 + eta) - c_2)**2)
    img_y_theta = atan2((-(y_2 + eta) - c_2), (y_1 - c_1))
    # single layer expansion zeroth order term
    qbx_exp_slp = I / 4 * hankel1(0, k * yc) * besselj(0, k * xc)
    img_qbx_exp_slp = I / 4 * hankel1(0, k * img_yc) * besselj(0, k * xc)
    for i in range(1, order + 1):
        qbx_exp_slp += (I / 4 * (hankel1(i, k * yc) * exp(I * i * y_theta) *
                                 besselj(i, k * xc) * exp(-I * i * x_theta)))
        qbx_exp_slp += (I / 4 * (hankel1(-i, k * yc) * exp(-I * i * y_theta) *
                                 besselj(-i, k * xc) * exp(I * i * x_theta)))
        img_qbx_exp_slp += (
            I / 4 * (hankel1(i, k * img_yc) * exp(I * i * img_y_theta) *
                     besselj(i, k * xc) * exp(-I * i * x_theta)))
        img_qbx_exp_slp += (
            I / 4 * (hankel1(-i, k * img_yc) * exp(-I * i * img_y_theta) *
                     besselj(-i, k * xc) * exp(I * i * x_theta)))
    qbx_exp_dlp = ny_1 * diff(qbx_exp_slp, y_1) + ny_2 * diff(qbx_exp_slp, y_2)
    exp_term_slp = lambdify([x_1, x_2, y_1, y_2, nx_1, nx_2, ny_1, ny_2, r],
                            qbx_exp_slp)
    exp_term_dlp = lambdify([x_1, x_2, y_1, y_2, nx_1, nx_2, ny_1, ny_2, r],
                            qbx_exp_dlp)
    img_qbx_exp_dlp = ny_1 * diff(img_qbx_exp_slp, y_1) + ny_2 * diff(
        img_qbx_exp_slp, y_2)
    img_exp_term_slp = lambdify(
        [x_1, x_2, y_1, y_2, eta, nx_1, nx_2, ny_1, ny_2, r], img_qbx_exp_slp)
    img_exp_term_dlp = lambdify(
        [x_1, x_2, y_1, y_2, eta, nx_1, nx_2, ny_1, ny_2, r], img_qbx_exp_dlp)
    return (
        single_layer,
        double_layer,
        exp_term_slp,
        exp_term_dlp,
        image_single_layer,
        image_double_layer,
        img_exp_term_slp,
        img_exp_term_dlp,
    )