Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-unit direction vectors #34

Merged
merged 2 commits into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions sfs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def rotation_matrix(n1, n2):
Rotation matrix.

"""
n1 = normal_vector(n1)
n2 = normal_vector(n2)
n1 = normalize_vector(n1)
n2 = normalize_vector(n2)
I = np.identity(3)
if np.all(n1 == n2):
return I # no rotation
Expand Down Expand Up @@ -218,7 +218,7 @@ def broadcast_zip(*args):
return zip(*np.broadcast_arrays(*args))


def normal_vector(x):
def normalize_vector(x):
"""Normalize a 1D vector."""
x = asarray_1d(x)
return x / np.linalg.norm(x)
Expand Down