Skip to content

Commit a50ca73

Browse files
committed
xref array handling nicer
mgeier suggested to improve np.array([[0, 0, 0]]*array.x.shape[0]) and np.array([xref]*array.x.shape[0]) by a handling in sound_field()
1 parent 5391c0e commit a50ca73

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

doc/examples/wfs-referencing.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"outputs": [],
4040
"source": [
4141
"R = 1.5 # radius [m] of circular loudspeaker array\n",
42-
"array = sfs.array.circular(N=64, R=R) # with N loudspeakers\n",
42+
"N = 64 # loudspeakers\n",
43+
"array = sfs.array.circular(N=N, R=R)\n",
4344
"grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)\n",
4445
"\n",
4546
"xs = -4, 0, 0 # virtual point source on negative x-axis\n",
@@ -59,6 +60,8 @@
5960
" sfs.plot2d.amplitude(p, grid, vmax=2, vmin=-2, ax=ax_amp)\n",
6061
" sfs.plot2d.level(p, grid, vmax=6, vmin=-6, ax=ax_lvl)\n",
6162
" sfs.plot2d.level_contour(p, grid, levels=[0], colors='w', ax=ax_lvl)\n",
63+
" if xref.shape[0] != N:\n",
64+
" xref = np.broadcast_to(xref, (N, 3))\n",
6265
" for ax in ax_amp, ax_lvl:\n",
6366
" sfs.plot2d.loudspeakers(array.x, array.n, selection, size=0.125, ax=ax)\n",
6467
" ax_lvl.scatter(*xref[selection, :2].T, marker='o', s=20, c='lightsalmon',\n",
@@ -174,7 +177,7 @@
174177
" omega, array.x, array.n, xs)\n",
175178
"p_point = sound_field(\n",
176179
" d * normalize_gain, selection, array, secondary_source,\n",
177-
" grid, np.array([[0, 0, 0]]*array.x.shape[0]))"
180+
" grid, np.array([[0, 0, 0]]))"
178181
]
179182
},
180183
{
@@ -205,7 +208,7 @@
205208
" omega, array.x, array.n, xs, xref=xref)\n",
206209
"p_point = sound_field(\n",
207210
" d * normalize_gain, selection, array, secondary_source,\n",
208-
" grid, np.array([xref]*array.x.shape[0]))\n",
211+
" grid, np.array([xref]))\n",
209212
"\n",
210213
"# plot stationary phase rays\n",
211214
"# one ray connects the virtual source with one activate loudspeaker\n",

0 commit comments

Comments
 (0)