@@ -32,7 +32,6 @@ def plot(d, selection, secondary_source):
32
32
33
33
"""
34
34
import numpy as _np
35
- from numpy .core .umath_tests import inner1d as _inner1d
36
35
from scipy .special import hankel2 as _hankel2
37
36
38
37
from . import secondary_source_line as _secondary_source_line
@@ -91,7 +90,7 @@ def line_2d(omega, x0, n0, xs, *, c=None):
91
90
k = _util .wavenumber (omega , c )
92
91
ds = x0 - xs
93
92
r = _np .linalg .norm (ds , axis = 1 )
94
- d = - 1j / 2 * k * _inner1d ( ds , n0 ) / r * _hankel2 (1 , k * r )
93
+ d = - 1j / 2 * k * _np . einsum ( 'ij,ij->i' , ds , n0 ) / r * _hankel2 (1 , k * r )
95
94
selection = _util .source_selection_line (n0 , x0 , xs )
96
95
return d , selection , _secondary_source_line (omega , c )
97
96
@@ -147,7 +146,8 @@ def _point(omega, x0, n0, xs, *, c=None):
147
146
k = _util .wavenumber (omega , c )
148
147
ds = x0 - xs
149
148
r = _np .linalg .norm (ds , axis = 1 )
150
- d = 1j * k * _inner1d (ds , n0 ) / r ** (3 / 2 ) * _np .exp (- 1j * k * r )
149
+ d = 1j * k * _np .einsum ('ij,ij->i' , ds , n0 ) / r ** (3 / 2 ) * _np .exp (
150
+ - 1j * k * r )
151
151
selection = _util .source_selection_point (n0 , x0 , xs )
152
152
return d , selection , _secondary_source_point (omega , c )
153
153
@@ -234,7 +234,7 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
234
234
preeq_25d (omega , omalias , c ) *
235
235
_np .sqrt (8 * _np .pi ) *
236
236
_np .sqrt ((r * s ) / (r + s )) *
237
- _inner1d ( n0 , ds ) / s *
237
+ _np . einsum ( 'ij,ij->i' , ds , n0 ) / s *
238
238
_np .exp (- 1j * k * s ) / (4 * _np .pi * s ))
239
239
selection = _util .source_selection_point (n0 , x0 , xs )
240
240
return d , selection , _secondary_source_point (omega , c )
@@ -316,8 +316,8 @@ def point_25d_legacy(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
316
316
r = _np .linalg .norm (ds , axis = 1 )
317
317
d = (
318
318
preeq_25d (omega , omalias , c ) *
319
- _np .sqrt (_np .linalg .norm (xref - x0 )) * _inner1d ( ds , n0 ) /
320
- r ** (3 / 2 ) * _np .exp (- 1j * k * r ))
319
+ _np .sqrt (_np .linalg .norm (xref - x0 )) * _np . einsum ( 'ij,ij->i' , ds , n0 ) /
320
+ r ** (3 / 2 ) * _np .exp (- 1j * k * r ))
321
321
selection = _util .source_selection_point (n0 , x0 , xs )
322
322
return d , selection , _secondary_source_point (omega , c )
323
323
@@ -499,7 +499,8 @@ def _focused(omega, x0, n0, xs, ns, *, c=None):
499
499
k = _util .wavenumber (omega , c )
500
500
ds = x0 - xs
501
501
r = _np .linalg .norm (ds , axis = 1 )
502
- d = 1j * k * _inner1d (ds , n0 ) / r ** (3 / 2 ) * _np .exp (1j * k * r )
502
+ d = 1j * k * _np .einsum ('ij,ij->i' , ds , n0 ) / r ** (3 / 2 ) * _np .exp (
503
+ 1j * k * r )
503
504
selection = _util .source_selection_focused (ns , x0 , xs )
504
505
return d , selection , _secondary_source_point (omega , c )
505
506
@@ -569,8 +570,8 @@ def focused_25d(omega, x0, n0, xs, ns, *, xref=[0, 0, 0], c=None,
569
570
r = _np .linalg .norm (ds , axis = 1 )
570
571
d = (
571
572
preeq_25d (omega , omalias , c ) *
572
- _np .sqrt (_np .linalg .norm (xref - x0 )) * _inner1d ( ds , n0 ) /
573
- r ** (3 / 2 ) * _np .exp (1j * k * r ))
573
+ _np .sqrt (_np .linalg .norm (xref - x0 )) * _np . einsum ( 'ij,ij->i' , ds , n0 ) /
574
+ r ** (3 / 2 ) * _np .exp (1j * k * r ))
574
575
selection = _util .source_selection_focused (ns , x0 , xs )
575
576
return d , selection , _secondary_source_point (omega , c )
576
577
@@ -682,22 +683,22 @@ def soundfigure_3d(omega, x0, n0, figure, npw=[0, 0, 1], *, c=None):
682
683
figure = _np .fft .fftshift (figure , axes = (0 , 1 )) # sign of spatial DFT
683
684
figure = _np .fft .fft2 (figure )
684
685
# wavenumbers
685
- kx = _np .fft .fftfreq (nx , 1. / nx )
686
- ky = _np .fft .fftfreq (ny , 1. / ny )
686
+ kx = _np .fft .fftfreq (nx , 1. / nx )
687
+ ky = _np .fft .fftfreq (ny , 1. / ny )
687
688
# shift spectrum due to desired plane wave
688
- figure = _np .roll (figure , int (k * npw [0 ]), axis = 0 )
689
- figure = _np .roll (figure , int (k * npw [1 ]), axis = 1 )
689
+ figure = _np .roll (figure , int (k * npw [0 ]), axis = 0 )
690
+ figure = _np .roll (figure , int (k * npw [1 ]), axis = 1 )
690
691
# search and iterate over propagating plane wave components
691
692
kxx , kyy = _np .meshgrid (kx , ky , sparse = True )
692
- rho = _np .sqrt ((kxx ) ** 2 + (kyy ) ** 2 )
693
+ rho = _np .sqrt ((kxx )** 2 + (kyy )** 2 )
693
694
d = 0
694
695
for n in range (nx ):
695
696
for m in range (ny ):
696
- if (rho [n , m ] < k ):
697
+ if (rho [n , m ] < k ):
697
698
# dispertion relation
698
699
kz = _np .sqrt (k ** 2 - rho [n , m ]** 2 )
699
700
# normal vector of plane wave
700
- npw = 1 / k * _np .asarray ([kx [n ], ky [m ], kz ])
701
+ npw = 1 / k * _np .asarray ([kx [n ], ky [m ], kz ])
701
702
npw = npw / _np .linalg .norm (npw )
702
703
# driving function of plane wave with positive kz
703
704
d_component , selection , secondary_source = plane_3d (
0 commit comments