sfstoolbox/sfs-python

Handling of directional vector for plane waves

hagenw opened this issue · 5 comments

At the moment we can change the frequency of the resulting sound field of a plane wave by using non unity vectors for specifying the direction. I don't know if this is desired behavior, but I would suggest to change it to at least raise a warning or an error. Or maybe to some automatic normalization of the directional vector.

import numpy as np
import matplotlib.pyplot as plt
import sfs

grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.01)
x0 = 0, 0, 0
npw = 0, -1, 0
f = 1000
omega = 2 * np.pi * f
p_plane = sfs.mono.source.plane(omega, x0, npw, grid);
sfs.plot.soundfield(p_plane, grid);
plt.title('Plane wave with npw = {}'.format(npw));
plt.savefig('pw1.png')

npw = 0, -2, 0
p_plane = sfs.mono.source.plane(omega, x0, npw, grid);
sfs.plot.soundfield(p_plane, grid);
plt.title('Plane wave with npw = {}'.format(npw));
plt.savefig('pw2.png')

pw1

pw2

Related: n0 scales amplitude of dipole sources.

I'm quite sure that this is not intended behavior. The normal vectors are supposed to have unit length. But as a convenience for our users, I think we should normalize them within each function where they are used.

I agree, and it looks like we have already a function for this: https://github.com/sfstoolbox/sfs-python/blob/master/sfs/util.py#L221

Indeed! Confusingly, we also have sfs.util.normalize(), which does something completely different.

Do you want to make a PR for this?

This could take a few days, but I will do it.