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
 9
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) ->Tensor:
13    '''
14    Propagates transducer phases to points using BEM\n
15    :param activations: Transducer hologram
16    :param points: Points to propagate to
17    :param scatterer: The mesh used (as a `vedo` `mesh` object)
18    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
19    :param H: Precomputed H - if None H will be computed
20    :param E: Precomputed E - if None E will be computed
21    :param path: path to folder containing `BEMCache/ `
22    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
23    :param print_lines: if true prints messages detaling progress
24    :return pressure: complex pressure at points
25    '''
26    if board is None:
27        board = TOP_BOARD
28
29    if E is None:
30        if type(scatterer) == str:
31            scatterer = load_scatterer(scatterer)
32        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines)
33    
34    out = E@activations
35    return out
36
37def propagate_BEM_pressure(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:
38                           Tensor|None=None,E:Tensor|None=None, path:str="Media",use_cache_H:bool=True, print_lines:bool=False) -> Tensor:
39    '''
40    Propagates transducer phases to points using BEM and returns absolute value of complex pressure\n
41    Equivalent to `torch.abs(propagate_BEM(activations,points,scatterer,board,H,E,path))` \n
42    :param activations: Transducer hologram
43    :param points: Points to propagate to
44    :param scatterer: The mesh used (as a `vedo` `mesh` object)
45    :param board: Transducers to use 
46    :param H: Precomputed H - if None H will be computed
47    :param E: Precomputed E - if None E will be computed 
48    :param path: path to folder containing `BEMCache/ `
49    
50    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
51    :param print_lines: if true prints messages detaling progress
52    
53    :return pressure: real pressure at points
54    '''
55    if board is None:
56        board = TOP_BOARD
57
58    point_activations = propagate_BEM(activations,points,scatterer,board,H,E,path,use_cache_H=use_cache_H,print_lines=print_lines)
59    pressures =  torch.abs(point_activations)
60    return pressures
61
62def propagate_BEM_pressure_grad(activations: Tensor, points: Tensor,board: Tensor|None=None, scatterer:Mesh = None, 
63                                path:str='Media', Fx=None, Fy=None, Fz=None, cat=True):
64    '''
65    Propagates a hologram to pressure gradient at points\n
66    :param activations: Hologram to use
67    :param points: Points to propagate to
68    :param board: The Transducer array, default two 16x16 arrays
69    :param Fx: The forward model to us for Fx, if None it is computed using `forward_model_grad`. Default:`None`
70    :param Fy: The forward model to us for Fy, if None it is computed using `forward_model_grad`. Default:`None`
71    :param Fz: The forward model to us for Fz, if None it is computed using `forward_model_grad`. Default:`None`
72    :return: point velocity potential'
73    '''
74    
75    if Fx is None or Fy is None or Fz is None:
76        _Fx,_Fy,_Fz = BEM_forward_model_grad(points, scatterer ,board)
77        if Fx is None: Fx = _Fx
78        if Fy is None: Fy = _Fy
79        if Fz is None: Fz = _Fz
80    
81    Px = Fx@activations
82    Py = Fy@activations
83    Pz = Fz@activations
84
85    if cat: 
86        grad = torch.cat([Px, Py, Pz], dim=2)
87        return grad
88    return Px, Py, Pz
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) -> 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) ->Tensor:
15    '''
16    Propagates transducer phases to points using BEM\n
17    :param activations: Transducer hologram
18    :param points: Points to propagate to
19    :param scatterer: The mesh used (as a `vedo` `mesh` object)
20    :param board: Transducers to use, if `None` then uses `acoustools.Utilities.TOP_BOARD` 
21    :param H: Precomputed H - if None H will be computed
22    :param E: Precomputed E - if None E will be computed
23    :param path: path to folder containing `BEMCache/ `
24    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
25    :param print_lines: if true prints messages detaling progress
26    :return pressure: complex pressure at points
27    '''
28    if board is None:
29        board = TOP_BOARD
30
31    if E is None:
32        if type(scatterer) == str:
33            scatterer = load_scatterer(scatterer)
34        E = compute_E(scatterer,points,board,H=H, path=path,use_cache_H=use_cache_H,print_lines=print_lines)
35    
36    out = E@activations
37    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
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) -> torch.Tensor:
39def propagate_BEM_pressure(activations:Tensor,points:Tensor,scatterer:Mesh|None=None,board:Tensor|None=None,H:
40                           Tensor|None=None,E:Tensor|None=None, path:str="Media",use_cache_H:bool=True, print_lines:bool=False) -> Tensor:
41    '''
42    Propagates transducer phases to points using BEM and returns absolute value of complex pressure\n
43    Equivalent to `torch.abs(propagate_BEM(activations,points,scatterer,board,H,E,path))` \n
44    :param activations: Transducer hologram
45    :param points: Points to propagate to
46    :param scatterer: The mesh used (as a `vedo` `mesh` object)
47    :param board: Transducers to use 
48    :param H: Precomputed H - if None H will be computed
49    :param E: Precomputed E - if None E will be computed 
50    :param path: path to folder containing `BEMCache/ `
51    
52    :param use_cache_H: If True uses the cache system to load and save the H matrix. Default `True`
53    :param print_lines: if true prints messages detaling progress
54    
55    :return pressure: real pressure at points
56    '''
57    if board is None:
58        board = TOP_BOARD
59
60    point_activations = propagate_BEM(activations,points,scatterer,board,H,E,path,use_cache_H=use_cache_H,print_lines=print_lines)
61    pressures =  torch.abs(point_activations)
62    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/

  • 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):
64def propagate_BEM_pressure_grad(activations: Tensor, points: Tensor,board: Tensor|None=None, scatterer:Mesh = None, 
65                                path:str='Media', Fx=None, Fy=None, Fz=None, cat=True):
66    '''
67    Propagates a hologram to pressure gradient at points\n
68    :param activations: Hologram to use
69    :param points: Points to propagate to
70    :param board: The Transducer array, default two 16x16 arrays
71    :param Fx: The forward model to us for Fx, if None it is computed using `forward_model_grad`. Default:`None`
72    :param Fy: The forward model to us for Fy, if None it is computed using `forward_model_grad`. Default:`None`
73    :param Fz: The forward model to us for Fz, if None it is computed using `forward_model_grad`. Default:`None`
74    :return: point velocity potential'
75    '''
76    
77    if Fx is None or Fy is None or Fz is None:
78        _Fx,_Fy,_Fz = BEM_forward_model_grad(points, scatterer ,board)
79        if Fx is None: Fx = _Fx
80        if Fy is None: Fy = _Fy
81        if Fz is None: Fz = _Fz
82    
83    Px = Fx@activations
84    Py = Fy@activations
85    Pz = Fz@activations
86
87    if cat: 
88        grad = torch.cat([Px, Py, Pz], dim=2)
89        return grad
90    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'