src.acoustools.BEM.Propagator

  1import torch
  2from torch import Tensor
  3
  4from vedo import Mesh
  5
  6from acoustools.Utilities import TOP_BOARD
  7from acoustools.BEM.Forward_models import compute_E
  8from acoustools.BEM.Gradients import BEM_forward_model_grad, BEM_laplacian
  9import acoustools.Constants as Constants
 10
 11def propagate_BEM(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
 12                  E:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False, 
 13                  p_ref=Constants.P_ref,k:float=Constants.k, betas:float|Tensor = 0, alphas:float|Tensor=1, a=None,c=None, 
 14                  internal_points=None,smooth_distance=0, h=None, BM_alpha=None,
 15                  transducer_radius = Constants.radius) ->Tensor:
 16    '''
 17    Propagates transducer phases to points using BEM\n
 18    :param activations: Transducer hologram
 19    :param points: Points to propagate to
 20    :param scatterer: The mesh used (as a `vedo` `mesh` object)
 21    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
 22    :param H: Precomputed H - if None H will be computed
 23    :param E: Precomputed E - if None E will be computed
 24    :param path: path to folder containing `BEMCache/ `
 25    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
 26    :param print_lines: if true prints messages detaling progress
 27    :param k: wavenumber
 28    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
 29    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
 30    :param internal_points: The internal points to use for CHIEF based BEM
 31    :param smooth_distance: amount to add to distances to avoid explosion over small values
 32    :param h: finite difference step for Burton-Miller BEM
 33    :param BM_alpha: constant alpha to use in Burton-Miller BEM
 34
 35    :return pressure: complex pressure at points
 36    '''
 37    if board is None:
 38        board = TOP_BOARD
 39
 40    if E is None:
 41        if type(scatterer) == str:
 42            scatterer = load_scatterer(scatterer)
 43        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines,p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
 44    
 45    out = E@activations
 46    return out
 47
 48def propagate_BEM_pressure(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:
 49                           Tensor|None=None,E:Tensor|None=None, path:str="Media",use_cache_H:bool=True, print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, betas = 0, alphas:float|Tensor=1, a=None,c=None, internal_points=None,smooth_distance=0, h=None, BM_alpha=None, transducer_radius = Constants.radius) -> Tensor:
 50    '''
 51    Propagates transducer phases to points using BEM and returns absolute value of complex pressure\n
 52    Equivalent to `torch.abs(propagate_BEM(activations,points,scatterer,board,H,E,path))` \n
 53    :param activations: Transducer hologram
 54    :param points: Points to propagate to
 55    :param scatterer: The mesh used (as a `vedo` `mesh` object)
 56    :param board: Transducers to use 
 57    :param H: Precomputed H - if None H will be computed
 58    :param E: Precomputed E - if None E will be computed 
 59    :param path: path to folder containing `BEMCache/ `
 60    :param k: wavenumber
 61    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
 62    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
 63    :param internal_points: The internal points to use for CHIEF based BEM
 64    :param smooth_distance: amount to add to distances to avoid explosion over small values
 65    :param h: finite difference step for Burton-Miller BEM
 66    :param BM_alpha: constant alpha to use in Burton-Miller BEM
 67
 68    
 69    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
 70    :param print_lines: if true prints messages detaling progress
 71    
 72    :return pressure: real pressure at points
 73    '''
 74    if board is None:
 75        board = TOP_BOARD
 76
 77    point_activations = propagate_BEM(activations,points,scatterer,board,H,E,path,use_cache_H=use_cache_H,print_lines=print_lines,p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
 78    pressures =  torch.abs(point_activations)
 79    return pressures
 80
 81def propagate_BEM_pressure_grad(activations: Tensor, points: Tensor,board: Tensor|None=None, scatterer:Mesh = None, 
 82                                path:str='Media', Fx=None, Fy=None, Fz=None, cat=True,p_ref=Constants.P_ref, k=Constants.k, transducer_radius = Constants.radius):
 83    '''
 84    Propagates a hologram to pressure gradient at points\n
 85    :param activations: Hologram to use
 86    :param points: Points to propagate to
 87    :param board: The Transducer array, default two 16x16 arrays
 88    :param Fx: The forward model to us for Fx, if None it is computed using `forward_model_grad`. Default:`None`
 89    :param Fy: The forward model to us for Fy, if None it is computed using `forward_model_grad`. Default:`None`
 90    :param Fz: The forward model to us for Fz, if None it is computed using `forward_model_grad`. Default:`None`
 91    :return: point velocity potential'
 92    '''
 93    
 94    if Fx is None or Fy is None or Fz is None:
 95        _Fx,_Fy,_Fz = BEM_forward_model_grad(points, scatterer ,board, p_ref=p_ref, k=k, transducer_radius=transducer_radius)
 96        if Fx is None: Fx = _Fx
 97        if Fy is None: Fy = _Fy
 98        if Fz is None: Fz = _Fz
 99    
100    Px = Fx@activations
101    Py = Fy@activations
102    Pz = Fz@activations
103
104    if cat: 
105        grad = torch.cat([Px, Py, Pz], dim=2)
106        return grad
107    return Px, Py, Pz
108
109def propagate_BEM_phase(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
110                  E:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, betas = 0, alphas:float|Tensor=1, a=None,c=None, internal_points=None,smooth_distance=0, h=None, BM_alpha=None, transducer_radius=Constants.radius) ->Tensor:
111    '''
112    Propagates transducer phases to phases at points using BEM\n
113    :param activations: Transducer hologram
114    :param points: Points to propagate to
115    :param scatterer: The mesh used (as a `vedo` `mesh` object)
116    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
117    :param H: Precomputed H - if None H will be computed
118    :param E: Precomputed E - if None E will be computed
119    :param path: path to folder containing `BEMCache/ `
120    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
121    :param print_lines: if true prints messages detaling progress
122    :param k: wavenumber
123    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
124    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
125    :param internal_points: The internal points to use for CHIEF based BEM
126    :param smooth_distance: amount to add to distances to avoid explosion over small values
127    :param h: finite difference step for Burton-Miller BEM
128    :param BM_alpha: constant alpha to use in Burton-Miller BEM
129
130    :return pressure: phase at points
131    '''
132    if board is None:
133        board = TOP_BOARD
134
135    if E is None:
136        if type(scatterer) == str:
137            scatterer = load_scatterer(scatterer)
138        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
139    
140    out = E@activations
141    return torch.angle(out)
142
143
144def propagate_BEM_laplacian(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
145                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
146    '''
147    Propagate transducer hologram to the laplacian of pressure at points
148    
149    :param activations: Transducer hologram
150    :param points: Points to propagate to
151    :param scatterer: The mesh used (as a `vedo` `mesh` object)
152    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
153    :param H: Precomputed H - if None H will be computed
154    :param E: Precomputed E - if None E will be computed
155    :param path: path to folder containing `BEMCache/ `
156    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
157    :param print_lines: if true prints messages detaling progress
158    :param k: wavenumber
159    :param internal_points: The internal points to use for CHIEF based BEM
160
161    :return pressure: laplacian at points
162    '''
163    
164    if board is None:
165        board = TOP_BOARD
166
167    if E_lap is None:
168        if type(scatterer) == str:
169            scatterer = load_scatterer(scatterer)
170        E_lap = BEM_laplacian(points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius)
171
172
173    lap = E_lap @ activations
174
175    return lap
176    
177
178def propagate_BEM_laplacian_abs(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
179                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
180    '''
181    Propagate transducer hologram to the absolute value of the laplacian of pressure at points
182
183    :param activations: Transducer hologram
184    :param points: Points to propagate to
185    :param scatterer: The mesh used (as a `vedo` `mesh` object)
186    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
187    :param H: Precomputed H - if None H will be computed
188    :param E: Precomputed E - if None E will be computed
189    :param path: path to folder containing `BEMCache/ `
190    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
191    :param print_lines: if true prints messages detaling progress
192    :param k: wavenumber
193    :param internal_points: The internal points to use for CHIEF based BEM
194
195    :return pressure: laplacian at points
196    '''
197    
198    lap = propagate_BEM_laplacian(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap)
199
200    return torch.abs(lap)
201
202def propagate_BEM_helmholtz(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None, E:Tensor|None=None,
203                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
204    '''
205    Computes the Helmholtz eq. at points given a hologram
206
207    :param activations: Transducer hologram
208    :param points: Points to propagate to
209    :param scatterer: The mesh used (as a `vedo` `mesh` object)
210    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
211    :param H: Precomputed H - if None H will be computed
212    :param E: Precomputed E - if None E will be computed
213    :param path: path to folder containing `BEMCache/ `
214    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
215    :param print_lines: if true prints messages detaling progress
216    :param k: wavenumber
217    :param internal_points: The internal points to use for CHIEF based BEM
218
219    :return pressure: laplacian at points
220    '''
221    
222    lap = propagate_BEM_laplacian(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap)
223    pressure = propagate_BEM(activations=activations,points=points, scatterer=scatterer,board=board, H=H, E=E, use_cache_H=use_cache_H, path=path, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius)
224
225
226    return lap + k**2 * pressure
227
228
229def propagate_BEM_helmholtz_abs(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None, E:Tensor|None=None,
230                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
231    
232    '''
233    Computes the absolute value of the Helmholtz eq. at points given a hologram
234
235    :param activations: Transducer hologram
236    :param points: Points to propagate to
237    :param scatterer: The mesh used (as a `vedo` `mesh` object)
238    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
239    :param H: Precomputed H - if None H will be computed
240    :param E: Precomputed E - if None E will be computed
241    :param path: path to folder containing `BEMCache/ `
242    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
243    :param print_lines: if true prints messages detaling progress
244    :param k: wavenumber
245    :param internal_points: The internal points to use for CHIEF based BEM
246
247    :return pressure: laplacian at points
248    '''
249    
250    helmholtz = propagate_BEM_helmholtz(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap, E=E)
251    
252    return torch.abs(helmholtz)
def propagate_BEM( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, betas: float | torch.Tensor = 0, alphas: float | torch.Tensor = 1, a=None, c=None, internal_points=None, smooth_distance=0, h=None, BM_alpha=None, transducer_radius=0.0045) -> torch.Tensor:
13def propagate_BEM(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
14                  E:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False, 
15                  p_ref=Constants.P_ref,k:float=Constants.k, betas:float|Tensor = 0, alphas:float|Tensor=1, a=None,c=None, 
16                  internal_points=None,smooth_distance=0, h=None, BM_alpha=None,
17                  transducer_radius = Constants.radius) ->Tensor:
18    '''
19    Propagates transducer phases to points using BEM\n
20    :param activations: Transducer hologram
21    :param points: Points to propagate to
22    :param scatterer: The mesh used (as a `vedo` `mesh` object)
23    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
24    :param H: Precomputed H - if None H will be computed
25    :param E: Precomputed E - if None E will be computed
26    :param path: path to folder containing `BEMCache/ `
27    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
28    :param print_lines: if true prints messages detaling progress
29    :param k: wavenumber
30    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
31    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
32    :param internal_points: The internal points to use for CHIEF based BEM
33    :param smooth_distance: amount to add to distances to avoid explosion over small values
34    :param h: finite difference step for Burton-Miller BEM
35    :param BM_alpha: constant alpha to use in Burton-Miller BEM
36
37    :return pressure: complex pressure at points
38    '''
39    if board is None:
40        board = TOP_BOARD
41
42    if E is None:
43        if type(scatterer) == str:
44            scatterer = load_scatterer(scatterer)
45        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines,p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
46    
47    out = E@activations
48    return out

Propagates transducer phases to points using BEM

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
  • betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
  • internal_points: The internal points to use for CHIEF based BEM
  • smooth_distance: amount to add to distances to avoid explosion over small values
  • h: finite difference step for Burton-Miller BEM
  • BM_alpha: constant alpha to use in Burton-Miller BEM
Returns

complex pressure at points

def propagate_BEM_pressure( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, betas=0, alphas: float | torch.Tensor = 1, a=None, c=None, internal_points=None, smooth_distance=0, h=None, BM_alpha=None, transducer_radius=0.0045) -> torch.Tensor:
50def propagate_BEM_pressure(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:
51                           Tensor|None=None,E:Tensor|None=None, path:str="Media",use_cache_H:bool=True, print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, betas = 0, alphas:float|Tensor=1, a=None,c=None, internal_points=None,smooth_distance=0, h=None, BM_alpha=None, transducer_radius = Constants.radius) -> Tensor:
52    '''
53    Propagates transducer phases to points using BEM and returns absolute value of complex pressure\n
54    Equivalent to `torch.abs(propagate_BEM(activations,points,scatterer,board,H,E,path))` \n
55    :param activations: Transducer hologram
56    :param points: Points to propagate to
57    :param scatterer: The mesh used (as a `vedo` `mesh` object)
58    :param board: Transducers to use 
59    :param H: Precomputed H - if None H will be computed
60    :param E: Precomputed E - if None E will be computed 
61    :param path: path to folder containing `BEMCache/ `
62    :param k: wavenumber
63    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
64    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
65    :param internal_points: The internal points to use for CHIEF based BEM
66    :param smooth_distance: amount to add to distances to avoid explosion over small values
67    :param h: finite difference step for Burton-Miller BEM
68    :param BM_alpha: constant alpha to use in Burton-Miller BEM
69
70    
71    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
72    :param print_lines: if true prints messages detaling progress
73    
74    :return pressure: real pressure at points
75    '''
76    if board is None:
77        board = TOP_BOARD
78
79    point_activations = propagate_BEM(activations,points,scatterer,board,H,E,path,use_cache_H=use_cache_H,print_lines=print_lines,p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
80    pressures =  torch.abs(point_activations)
81    return pressures

Propagates transducer phases to points using BEM and returns absolute value of complex pressure

Equivalent to torch.abs(propagate_BEM(activations,points,scatterer,board,H,E,path))

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • k: wavenumber
  • alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
  • betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
  • internal_points: The internal points to use for CHIEF based BEM
  • smooth_distance: amount to add to distances to avoid explosion over small values
  • h: finite difference step for Burton-Miller BEM
  • BM_alpha: constant alpha to use in Burton-Miller BEM

  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True

  • print_lines: if true prints messages detaling progress
Returns

real pressure at points

def propagate_BEM_pressure_grad( activations: torch.Tensor, points: torch.Tensor, board: torch.Tensor | None = None, scatterer: vedo.mesh.Mesh = None, path: str = 'Media', Fx=None, Fy=None, Fz=None, cat=True, p_ref=3.4000000000000004, k=732.7329804081634, transducer_radius=0.0045):
 83def propagate_BEM_pressure_grad(activations: Tensor, points: Tensor,board: Tensor|None=None, scatterer:Mesh = None, 
 84                                path:str='Media', Fx=None, Fy=None, Fz=None, cat=True,p_ref=Constants.P_ref, k=Constants.k, transducer_radius = Constants.radius):
 85    '''
 86    Propagates a hologram to pressure gradient at points\n
 87    :param activations: Hologram to use
 88    :param points: Points to propagate to
 89    :param board: The Transducer array, default two 16x16 arrays
 90    :param Fx: The forward model to us for Fx, if None it is computed using `forward_model_grad`. Default:`None`
 91    :param Fy: The forward model to us for Fy, if None it is computed using `forward_model_grad`. Default:`None`
 92    :param Fz: The forward model to us for Fz, if None it is computed using `forward_model_grad`. Default:`None`
 93    :return: point velocity potential'
 94    '''
 95    
 96    if Fx is None or Fy is None or Fz is None:
 97        _Fx,_Fy,_Fz = BEM_forward_model_grad(points, scatterer ,board, p_ref=p_ref, k=k, transducer_radius=transducer_radius)
 98        if Fx is None: Fx = _Fx
 99        if Fy is None: Fy = _Fy
100        if Fz is None: Fz = _Fz
101    
102    Px = Fx@activations
103    Py = Fy@activations
104    Pz = Fz@activations
105
106    if cat: 
107        grad = torch.cat([Px, Py, Pz], dim=2)
108        return grad
109    return Px, Py, Pz

Propagates a hologram to pressure gradient at points

Parameters
  • activations: Hologram to use
  • points: Points to propagate to
  • board: The Transducer array, default two 16x16 arrays
  • Fx: The forward model to us for Fx, if None it is computed using forward_model_grad. Default: None
  • Fy: The forward model to us for Fy, if None it is computed using forward_model_grad. Default: None
  • Fz: The forward model to us for Fz, if None it is computed using forward_model_grad. Default: None
Returns

point velocity potential'

def propagate_BEM_phase( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, betas=0, alphas: float | torch.Tensor = 1, a=None, c=None, internal_points=None, smooth_distance=0, h=None, BM_alpha=None, transducer_radius=0.0045) -> torch.Tensor:
111def propagate_BEM_phase(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
112                  E:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, betas = 0, alphas:float|Tensor=1, a=None,c=None, internal_points=None,smooth_distance=0, h=None, BM_alpha=None, transducer_radius=Constants.radius) ->Tensor:
113    '''
114    Propagates transducer phases to phases at points using BEM\n
115    :param activations: Transducer hologram
116    :param points: Points to propagate to
117    :param scatterer: The mesh used (as a `vedo` `mesh` object)
118    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
119    :param H: Precomputed H - if None H will be computed
120    :param E: Precomputed E - if None E will be computed
121    :param path: path to folder containing `BEMCache/ `
122    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
123    :param print_lines: if true prints messages detaling progress
124    :param k: wavenumber
125    :param alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
126    :param betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
127    :param internal_points: The internal points to use for CHIEF based BEM
128    :param smooth_distance: amount to add to distances to avoid explosion over small values
129    :param h: finite difference step for Burton-Miller BEM
130    :param BM_alpha: constant alpha to use in Burton-Miller BEM
131
132    :return pressure: phase at points
133    '''
134    if board is None:
135        board = TOP_BOARD
136
137    if E is None:
138        if type(scatterer) == str:
139            scatterer = load_scatterer(scatterer)
140        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, betas=betas, alphas=alphas, a=a, c=c, internal_points=internal_points, smooth_distance=smooth_distance, h=h, BM_alpha=BM_alpha, transducer_radius=transducer_radius)
141    
142    out = E@activations
143    return torch.angle(out)

Propagates transducer phases to phases at points using BEM

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • alphas: Absorbance of each element, can be Tensor for element-wise attribution or a number for all elements
  • betas: Ratio of impedances of medium and scattering material for each element, can be Tensor for element-wise attribution or a number for all elements
  • internal_points: The internal points to use for CHIEF based BEM
  • smooth_distance: amount to add to distances to avoid explosion over small values
  • h: finite difference step for Burton-Miller BEM
  • BM_alpha: constant alpha to use in Burton-Miller BEM
Returns

phase at points

def propagate_BEM_laplacian( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E_lap: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, internal_points=None, transducer_radius=0.0045):
146def propagate_BEM_laplacian(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
147                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
148    '''
149    Propagate transducer hologram to the laplacian of pressure at points
150    
151    :param activations: Transducer hologram
152    :param points: Points to propagate to
153    :param scatterer: The mesh used (as a `vedo` `mesh` object)
154    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
155    :param H: Precomputed H - if None H will be computed
156    :param E: Precomputed E - if None E will be computed
157    :param path: path to folder containing `BEMCache/ `
158    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
159    :param print_lines: if true prints messages detaling progress
160    :param k: wavenumber
161    :param internal_points: The internal points to use for CHIEF based BEM
162
163    :return pressure: laplacian at points
164    '''
165    
166    if board is None:
167        board = TOP_BOARD
168
169    if E_lap is None:
170        if type(scatterer) == str:
171            scatterer = load_scatterer(scatterer)
172        E_lap = BEM_laplacian(points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius)
173
174
175    lap = E_lap @ activations
176
177    return lap

Propagate transducer hologram to the laplacian of pressure at points

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • internal_points: The internal points to use for CHIEF based BEM
Returns

laplacian at points

def propagate_BEM_laplacian_abs( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E_lap: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, internal_points=None, transducer_radius=0.0045):
180def propagate_BEM_laplacian_abs(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None,
181                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
182    '''
183    Propagate transducer hologram to the absolute value of the laplacian of pressure at points
184
185    :param activations: Transducer hologram
186    :param points: Points to propagate to
187    :param scatterer: The mesh used (as a `vedo` `mesh` object)
188    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
189    :param H: Precomputed H - if None H will be computed
190    :param E: Precomputed E - if None E will be computed
191    :param path: path to folder containing `BEMCache/ `
192    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
193    :param print_lines: if true prints messages detaling progress
194    :param k: wavenumber
195    :param internal_points: The internal points to use for CHIEF based BEM
196
197    :return pressure: laplacian at points
198    '''
199    
200    lap = propagate_BEM_laplacian(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap)
201
202    return torch.abs(lap)

Propagate transducer hologram to the absolute value of the laplacian of pressure at points

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • internal_points: The internal points to use for CHIEF based BEM
Returns

laplacian at points

def propagate_BEM_helmholtz( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E: torch.Tensor | None = None, E_lap: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, internal_points=None, transducer_radius=0.0045):
204def propagate_BEM_helmholtz(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None, E:Tensor|None=None,
205                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
206    '''
207    Computes the Helmholtz eq. at points given a hologram
208
209    :param activations: Transducer hologram
210    :param points: Points to propagate to
211    :param scatterer: The mesh used (as a `vedo` `mesh` object)
212    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
213    :param H: Precomputed H - if None H will be computed
214    :param E: Precomputed E - if None E will be computed
215    :param path: path to folder containing `BEMCache/ `
216    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
217    :param print_lines: if true prints messages detaling progress
218    :param k: wavenumber
219    :param internal_points: The internal points to use for CHIEF based BEM
220
221    :return pressure: laplacian at points
222    '''
223    
224    lap = propagate_BEM_laplacian(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap)
225    pressure = propagate_BEM(activations=activations,points=points, scatterer=scatterer,board=board, H=H, E=E, use_cache_H=use_cache_H, path=path, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius)
226
227
228    return lap + k**2 * pressure

Computes the Helmholtz eq. at points given a hologram

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • internal_points: The internal points to use for CHIEF based BEM
Returns

laplacian at points

def propagate_BEM_helmholtz_abs( activations: torch.Tensor, points: torch.Tensor, scatterer: vedo.mesh.Mesh | None = None, board: torch.Tensor | None = None, H: torch.Tensor | None = None, E: torch.Tensor | None = None, E_lap: torch.Tensor | None = None, path: str = 'Media', use_cache_H: bool = True, print_lines: bool = False, p_ref=3.4000000000000004, k: float = 732.7329804081634, internal_points=None, transducer_radius=0.0045):
231def propagate_BEM_helmholtz_abs(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:Tensor|None=None, E:Tensor|None=None,
232                  E_lap:Tensor|None=None,path:str="Media", use_cache_H: bool=True,print_lines:bool=False,p_ref=Constants.P_ref,k:float=Constants.k, internal_points=None, transducer_radius=Constants.radius):
233    
234    '''
235    Computes the absolute value of the Helmholtz eq. at points given a hologram
236
237    :param activations: Transducer hologram
238    :param points: Points to propagate to
239    :param scatterer: The mesh used (as a `vedo` `mesh` object)
240    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
241    :param H: Precomputed H - if None H will be computed
242    :param E: Precomputed E - if None E will be computed
243    :param path: path to folder containing `BEMCache/ `
244    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
245    :param print_lines: if true prints messages detaling progress
246    :param k: wavenumber
247    :param internal_points: The internal points to use for CHIEF based BEM
248
249    :return pressure: laplacian at points
250    '''
251    
252    helmholtz = propagate_BEM_helmholtz(activations,points, scatterer ,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines, p_ref=p_ref, k=k, internal_points=internal_points, transducer_radius=transducer_radius, E_lap=E_lap, E=E)
253    
254    return torch.abs(helmholtz)

Computes the absolute value of the Helmholtz eq. at points given a hologram

Parameters
  • activations: Transducer hologram
  • points: Points to propagate to
  • scatterer: The mesh used (as a vedo mesh object)
  • board: Transducers to use, if None then uses acoustools.Utilities.TOP_BOARD
  • H: Precomputed H - if None H will be computed
  • E: Precomputed E - if None E will be computed
  • path: path to folder containing BEMCache/
  • use_cache_H: If True uses the cache system to load and save the H matrix. Default True
  • print_lines: if true prints messages detaling progress
  • k: wavenumber
  • internal_points: The internal points to use for CHIEF based BEM
Returns

laplacian at points