sfs.fd.source¶

Compute the sound field generated by a sound source.

import sfs
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = 8, 4.5  # inch

x0 = 1.5, 1, 0
f = 500  # Hz
omega = 2 * np.pi * f

normalization_point = 4 * np.pi
normalization_line = \
np.sqrt(8 * np.pi * omega / sfs.default.c) * np.exp(1j * np.pi / 4)

grid = sfs.util.xyz_grid([-2, 3], [-1, 2], 0, spacing=0.02)

# Grid for vector fields:
vgrid = sfs.util.xyz_grid([-2, 3], [-1, 2], 0, spacing=0.1)


Functions

 line(omega, x0, grid, *[, c]) Line source parallel to the z-axis. line_dipole(omega, x0, n0, grid, *[, c]) Line source with dipole characteristics parallel to the z-axis. line_dirichlet_edge(omega, x0, grid, *[, …]) Line source scattered at an edge with Dirichlet boundary conditions. line_velocity(omega, x0, grid, *[, c, rho0]) Velocity of line source parallel to the z-axis. plane(omega, x0, n0, grid, *[, c]) Plane wave. plane_averaged_intensity(omega, x0, n0, grid, *) Averaged intensity of a plane wave. plane_velocity(omega, x0, n0, grid, *[, c, rho0]) Velocity of a plane wave. point(omega, x0, grid, *[, c]) Sound pressure of a point source. point_averaged_intensity(omega, x0, grid, *) Velocity of a point source. point_dipole(omega, x0, n0, grid, *[, c]) Point source with dipole characteristics. point_image_sources(omega, x0, grid, L, *, …) Point source in a rectangular room using the mirror image source model. point_modal(omega, x0, grid, L, *[, N, …]) Point source in a rectangular room using a modal room model. point_modal_velocity(omega, x0, grid, L, *) Velocity of point source in a rectangular room using a modal room model. point_velocity(omega, x0, grid, *[, c, rho0]) Particle velocity of a point source. pulsating_sphere(omega, center, radius, …) Sound pressure of a pulsating sphere. pulsating_sphere_velocity(omega, center, …) Particle velocity of a pulsating sphere.
sfs.fd.source.point(omega, x0, grid, *, c=None)[source]

Sound pressure of a point source.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid.

Notes

$G(\x-\x_0,\w) = \frac{1}{4\pi} \frac{\e{-\i\wc|\x-\x_0|}}{|\x-\x_0|}$

Examples

p = sfs.fd.source.point(omega, x0, grid)
sfs.plot2d.amplitude(p, grid)
plt.title("Point Source at {} m".format(x0)) Normalization …

sfs.plot2d.amplitude(p * normalization_point, grid,
colorbar_kwargs=dict(label="p / Pa"))
plt.title("Point Source at {} m (normalized)".format(x0)) sfs.fd.source.point_velocity(omega, x0, grid, *, c=None, rho0=None)[source]

Particle velocity of a point source.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. rho0 (float, optional) – Static density of air. XyzComponents – Particle velocity at positions given by grid.

Examples

The particle velocity can be plotted on top of the sound pressure:

v = sfs.fd.source.point_velocity(omega, x0, vgrid)
sfs.plot2d.amplitude(p * normalization_point, grid)
sfs.plot2d.vectors(v * normalization_point, vgrid)
plt.title("Sound Pressure and Particle Velocity") sfs.fd.source.point_averaged_intensity(omega, x0, grid, *, c=None, rho0=None)[source]

Velocity of a point source.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. rho0 (float, optional) – Static density of air. XyzComponents – Averaged intensity at positions given by grid.
sfs.fd.source.point_dipole(omega, x0, n0, grid, *, c=None)[source]

Point source with dipole characteristics.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. n0 ((3,) array_like) – Normal vector (direction) of dipole. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid.

Notes

$G(\x-\x_0,\w) = \frac{1}{4\pi} \left(\i\wc + \frac{1}{|\x-\x_0|}\right) \frac{\scalarprod{\x-\x_0}{\n_\text{s}}}{|\x-\x_0|^2} \e{-\i\wc|\x-\x_0}$

Examples

n0 = 0, 1, 0
p = sfs.fd.source.point_dipole(omega, x0, n0, grid)
sfs.plot2d.amplitude(p, grid)
plt.title("Dipole Point Source at {} m".format(x0)) sfs.fd.source.point_modal(omega, x0, grid, L, *, N=None, deltan=0, c=None)[source]

Point source in a rectangular room using a modal room model.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). L ((3,) array_like) – Dimensionons of the rectangular room. N ((3,) array_like or int, optional) – For all three spatial dimensions per dimension maximum order or list of orders. A scalar applies to all three dimensions. If no order is provided it is approximately determined. deltan (float, optional) – Absorption coefficient of the walls. c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid.
sfs.fd.source.point_modal_velocity(omega, x0, grid, L, *, N=None, deltan=0, c=None)[source]

Velocity of point source in a rectangular room using a modal room model.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). L ((3,) array_like) – Dimensionons of the rectangular room. N ((3,) array_like or int, optional) – Combination of modal orders in the three-spatial dimensions to calculate the sound field for or maximum order for all dimensions. If not given, the maximum modal order is approximately determined and the sound field is computed up to this maximum order. deltan (float, optional) – Absorption coefficient of the walls. c (float, optional) – Speed of sound. XyzComponents – Particle velocity at positions given by grid.
sfs.fd.source.point_image_sources(omega, x0, grid, L, *, max_order, coeffs=None, c=None)[source]

Point source in a rectangular room using the mirror image source model.

Parameters: omega (float) – Frequency of source. x0 ((3,) array_like) – Position of source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). L ((3,) array_like) – Dimensions of the rectangular room. max_order (int) – Maximum number of reflections for each image source. coeffs ((6,) array_like, optional) – Reflection coeffecients of the walls. If not given, the reflection coefficients are set to one. c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid.
sfs.fd.source.line(omega, x0, grid, *, c=None)[source]

Line source parallel to the z-axis.

Note: third component of x0 is ignored.

Notes

$G(\x-\x_0,\w) = -\frac{\i}{4} \Hankel{2}{0}{\wc|\x-\x_0|}$

Examples

p = sfs.fd.source.line(omega, x0, grid)
sfs.plot2d.amplitude(p, grid)
plt.title("Line Source at {} m".format(x0[:2])) Normalization …

sfs.plot2d.amplitude(p * normalization_line, grid,
colorbar_kwargs=dict(label="p / Pa"))
plt.title("Line Source at {} m (normalized)".format(x0[:2])) sfs.fd.source.line_velocity(omega, x0, grid, *, c=None, rho0=None)[source]

Velocity of line source parallel to the z-axis.

Returns: XyzComponents – Particle velocity at positions given by grid.

Examples

The particle velocity can be plotted on top of the sound pressure:

v = sfs.fd.source.line_velocity(omega, x0, vgrid)
sfs.plot2d.amplitude(p * normalization_line, grid)
sfs.plot2d.vectors(v * normalization_line, vgrid)
plt.title("Sound Pressure and Particle Velocity") sfs.fd.source.line_dipole(omega, x0, n0, grid, *, c=None)[source]

Line source with dipole characteristics parallel to the z-axis.

Note: third component of x0 is ignored.

Notes

$G(\x-\x_0,\w) = \frac{\i k}{4} \Hankel{2}{1}{\wc|\x-\x_0|} \cos{\phi}$
sfs.fd.source.line_dirichlet_edge(omega, x0, grid, *, alpha=4.71238898038469, Nc=None, c=None)[source]

Line source scattered at an edge with Dirichlet boundary conditions.

[Mos12], eq.(10.18/19)

Parameters: omega (float) – Angular frequency. x0 ((3,) array_like) – Position of line source. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). alpha (float, optional) – Outer angle of edge. Nc (int, optional) – Number of elements for series expansion of driving function. Estimated if not given. c (float, optional) – Speed of sound numpy.ndarray – Complex pressure at grid positions.
sfs.fd.source.plane(omega, x0, n0, grid, *, c=None)[source]

Plane wave.

Parameters: omega (float) – Frequency of plane wave. x0 ((3,) array_like) – Position of plane wave. n0 ((3,) array_like) – Normal vector (direction) of plane wave. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid.

Notes

$G(\x,\w) = \e{-\i\wc\n\x}$

Examples

direction = 45  # degree
p = sfs.fd.source.plane(omega, x0, n0, grid)
sfs.plot2d.amplitude(p, grid, colorbar_kwargs=dict(label="p / Pa"))
plt.title("Plane wave with direction {} degree".format(direction)) sfs.fd.source.plane_velocity(omega, x0, n0, grid, *, c=None, rho0=None)[source]

Velocity of a plane wave.

Parameters: omega (float) – Frequency of plane wave. x0 ((3,) array_like) – Position of plane wave. n0 ((3,) array_like) – Normal vector (direction) of plane wave. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. rho0 (float, optional) – Static density of air. XyzComponents – Particle velocity at positions given by grid.

Notes

$V(\x,\w) = \frac{1}{\rho c} \e{-\i\wc\n\x} \n$

Examples

The particle velocity can be plotted on top of the sound pressure:

v = sfs.fd.source.plane_velocity(omega, x0, n0, vgrid)
sfs.plot2d.amplitude(p, grid)
sfs.plot2d.vectors(v, vgrid)
plt.title("Sound Pressure and Particle Velocity") sfs.fd.source.plane_averaged_intensity(omega, x0, n0, grid, *, c=None, rho0=None)[source]

Averaged intensity of a plane wave.

Parameters: omega (float) – Frequency of plane wave. x0 ((3,) array_like) – Position of plane wave. n0 ((3,) array_like) – Normal vector (direction) of plane wave. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. rho0 (float, optional) – Static density of air. XyzComponents – Averaged intensity at positions given by grid.

Notes

$I(\x,\w) = \frac{1}{2\rho c} \n$
sfs.fd.source.pulsating_sphere(omega, center, radius, amplitude, grid, *, inside=False, c=None)[source]

Sound pressure of a pulsating sphere.

Parameters: omega (float) – Frequency of pulsating sphere center ((3,) array_like) – Center of sphere. radius (float) – Radius of sphere. amplitude (float) – Amplitude of displacement. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). inside (bool, optional) – As default, numpy.nan is returned for inside the sphere. If inside=True, the sound field inside the sphere is extrapolated. c (float, optional) – Speed of sound. numpy.ndarray – Sound pressure at positions given by grid. If inside=False, numpy.nan is returned for inside the sphere.

Examples

radius = 0.25
amplitude = 1 / (radius * omega * sfs.default.rho0 * sfs.default.c)
p = sfs.fd.source.pulsating_sphere(omega, x0, radius, amplitude, grid)
sfs.plot2d.amplitude(p, grid)
plt.title("Sound Pressure of a Pulsating Sphere") sfs.fd.source.pulsating_sphere_velocity(omega, center, radius, amplitude, grid, *, c=None)[source]

Particle velocity of a pulsating sphere.

Parameters: omega (float) – Frequency of pulsating sphere center ((3,) array_like) – Center of sphere. radius (float) – Radius of sphere. amplitude (float) – Amplitude of displacement. grid (triple of array_like) – The grid that is used for the sound field calculations. See sfs.util.xyz_grid(). c (float, optional) – Speed of sound. XyzComponents – Particle velocity at positions given by grid. numpy.nan is returned for inside the sphere.

Examples

v = sfs.fd.source.pulsating_sphere_velocity(omega, x0, radius, amplitude, vgrid)
sfs.plot2d.amplitude(p, grid)
sfs.plot2d.vectors(v, vgrid)
plt.title("Sound Pressure and Particle Velocity of a Pulsating Sphere") 