Example #1
0
    def test_shape(self):
        n = np.array([0, 1])
        z = np.linspace(0.1, 5, 10)
        res = special.spherical_hankel(n, z, kind=1, derivative=True)

        shape = (2, 10)
        assert shape == res.shape
Example #2
0
def _modal_strength(n, kr, config):
    """Helper function for the calculation of the modal strength for
    plane waves"""
    if config == 'open':
        ms = 4*np.pi*pow(1.0j, n) * _special.spherical_bessel(n, kr)
    elif config == 'rigid':
        ms = 4*np.pi*pow(1.0j, n+1) / \
            _special.spherical_hankel(n, kr, derivative=True) / (kr)**2
    elif config == 'cardioid':
        ms = 4*np.pi*pow(1.0j, n) * \
            (_special.spherical_bessel(n, kr) -
                1.0j * _special.spherical_bessel(n, kr, derivative=True))
    else:
        raise ValueError("Invalid configuration.")

    return ms
Example #3
0
 def test_val_second_kind(self):
     z = np.linspace(0.1, 5, 25)
     n = [0, 1, 2]
     res = special.spherical_hankel(n, z, kind=2, derivative=True)
     truth = genfromtxt_complex('./tests/data/hankel_2_diff.csv', delimiter=',')
     npt.assert_allclose(res, truth)
Example #4
0
 def test_kind_exception(self):
     with pytest.raises(ValueError):
         special.spherical_hankel([0], [1], kind=3, derivative=True)
Example #5
0
 def test_val_first_kind(self):
     z = np.linspace(0.1, 5, 25)
     n = np.array([0, 1, 2])
     res = special.spherical_hankel(n, z, kind=1)
     truth = genfromtxt_complex('./tests/data/hankel_1.csv', delimiter=',')
     npt.assert_allclose(res, truth)
Example #6
0
def radiation_from_sphere(
        n_max,
        rad_sphere,
        k,
        distance,
        density_medium=1.2,
        speed_of_sound=343.0):
    r"""
    Radiation function in SH for a vibrating sphere including the radiation
    impedance and the propagation to a arbitrary distance from the sphere.
    The sign and phase conventions result in a positive pressure response for
    a positive cap velocity with the intensity vector pointing away from the
    source.

    TODO: This function does not have a test yet.

    References
    ----------
    .. [7]  E. G. Williams, Fourier Acoustics. Academic Press, 1999.
    .. [8]  F. Zotter, A. Sontacchi, and R. Höldrich, “Modeling a spherical
            loudspeaker system as multipole source,” in Proceedings of the 33rd
            DAGA German Annual Conference on Acoustics, 2007, pp. 221–222.


    Parameters
    ----------
    n_max : integer, ndarray
        Maximal spherical harmonic order
    r_sphere : double, ndarray
        Radius of the sphere
    k : double, ndarray
        Wave number
    distance : double
        Distance from the origin
    density_medium : double
        Density of the medium surrounding the sphere. Default is 1.2 for air.
    speed_of_sound : double
        Speed of sound in m/s

    Returns
    -------
    R : double, ndarray
        Radiation function in diagonal matrix form with shape
        :math:`[K \times (n_{max}+1)^2~\times~(n_{max}+1)^2]`

    """
    n_sh = (n_max+1)**2

    k = np.atleast_1d(k)
    n_bins = k.shape[0]
    radiation = np.zeros((n_bins, n_sh, n_sh), dtype=np.complex)

    for n in range(0, n_max+1):
        hankel = _special.spherical_hankel(n, k*distance, kind=2)
        hankel_prime = _special.spherical_hankel(
            n, k*rad_sphere, kind=2, derivative=True)
        radiation_order = -1j * hankel/hankel_prime * \
            density_medium * speed_of_sound
        for m in range(-n, n+1):
            acn = nm2acn(n, m)
            radiation[:, acn, acn] = radiation_order

    return radiation