Skip to content

Commit

Permalink
Ensure direction vector n is always a unit vector
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Dec 21, 2016
1 parent 77f1349 commit 8a97603
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions sfs/mono/drivingfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _wfs_plane(omega, x0, n0, n=[0, 1, 0], c=None):
"""
x0 = util.asarray_of_rows(x0)
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
k = util.wavenumber(omega, c)
return 2j * k * np.inner(n, n0) * np.exp(-1j * k * np.inner(n, x0))

Expand All @@ -106,7 +106,7 @@ def wfs_25d_plane(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None,
"""
x0 = util.asarray_of_rows(x0)
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
xref = util.asarray_1d(xref)
k = util.wavenumber(omega, c)
return wfs_25d_preeq(omega, omalias, c) * \
Expand Down Expand Up @@ -179,7 +179,7 @@ def wfs_25d_preeq(omega, omalias, c):
def delay_3d_plane(omega, x0, n0, n=[0, 1, 0], c=None):
"""Plane wave by simple delay of secondary sources."""
x0 = util.asarray_of_rows(x0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
k = util.wavenumber(omega, c)
return np.exp(-1j * k * np.inner(n, x0))

Expand All @@ -191,7 +191,7 @@ def source_selection_plane(n0, n):
"""
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
return np.inner(n, n0) >= defs.selection_tolerance


Expand Down Expand Up @@ -225,7 +225,7 @@ def source_selection_focused(ns, x0, xs):
"""
x0 = util.asarray_of_rows(x0)
xs = util.asarray_1d(xs)
ns = util.asarray_1d(ns)
ns = util.normalize_vector(ns)
ds = xs - x0
return inner1d(ns, ds) >= defs.selection_tolerance

Expand All @@ -251,7 +251,7 @@ def nfchoa_2d_plane(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
"""
x0 = util.asarray_of_rows(x0)
k = util.wavenumber(omega, c)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
phi, _, r = util.cart2sph(*n)
phi0 = util.cart2sph(*x0.T)[0]
M = _max_order_circular_harmonics(len(x0), max_order)
Expand Down Expand Up @@ -305,7 +305,7 @@ def nfchoa_25d_plane(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
"""
x0 = util.asarray_of_rows(x0)
k = util.wavenumber(omega, c)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
phi, _, r = util.cart2sph(*n)
phi0 = util.cart2sph(*x0.T)[0]
M = _max_order_circular_harmonics(len(x0), max_order)
Expand Down Expand Up @@ -345,7 +345,7 @@ def sdm_2d_plane(omega, x0, n0, n=[0, 1, 0], c=None):
"""
x0 = util.asarray_of_rows(x0)
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
k = util.wavenumber(omega, c)
return k * n[1] * np.exp(-1j * k * n[0] * x0[:, 0])

Expand All @@ -361,7 +361,7 @@ def sdm_25d_plane(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
"""
x0 = util.asarray_of_rows(x0)
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
xref = util.asarray_1d(xref)
k = util.wavenumber(omega, c)
return 4j * np.exp(-1j*k*n[1]*xref[1]) / hankel2(0, k*n[1]*xref[1]) * \
Expand Down Expand Up @@ -420,6 +420,7 @@ def esa_edge_2d_plane(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None, c=None):
"""
x0 = np.asarray(x0)
n = util.normalize_vector(n)
k = util.wavenumber(omega, c)
phi_s = np.arctan2(n[1], n[0]) + np.pi
L = x0.shape[0]
Expand Down Expand Up @@ -477,6 +478,7 @@ def esa_edge_dipole_2d_plane(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None, c
"""
x0 = np.asarray(x0)
n = util.normalize_vector(n)
k = util.wavenumber(omega, c)
phi_s = np.arctan2(n[1], n[0]) + np.pi
L = x0.shape[0]
Expand Down
2 changes: 1 addition & 1 deletion sfs/mono/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def plane(omega, x0, n0, grid, c=None):
"""
k = util.wavenumber(omega, c)
x0 = util.asarray_1d(x0)
n0 = util.asarray_1d(n0)
n0 = util.normalize_vector(n0)
grid = util.as_xyz_components(grid)
return np.exp(-1j * k * np.inner(grid - x0, n0))

Expand Down
2 changes: 1 addition & 1 deletion sfs/time/drivingfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def wfs_25d_plane(x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
c = defs.c
x0 = util.asarray_of_rows(x0)
n0 = util.asarray_of_rows(n0)
n = util.asarray_1d(n)
n = util.normalize_vector(n)
xref = util.asarray_1d(xref)
g0 = np.sqrt(2 * np.pi * np.linalg.norm(xref - x0, axis=1))
delays = inner1d(n, x0) / c
Expand Down

0 comments on commit 8a97603

Please sign in to comment.