src.acoustools.Stiffness
1import torch 2from acoustools.Force import compute_force 3from acoustools.Utilities import create_points, TRANSDUCERS 4 5from torch import Tensor 6 7def stiffness_finite_differences(activation:Tensor, points:Tensor, board:Tensor|None=None, delta= 0.001): 8 ''' 9 Computes the stiffness at a point as the gradient of the force. Force computed analytically and then finite differences used to find the gradient \n 10 Computed as `-1* (Fx + Fy + Fz)` where `Fa` is the gradient of force in that direction \n 11 :param activation: Hologram 12 :param points: Points of interest 13 :param board: Transducers to use 14 :param delta: finite differences step size 15 16 ''' 17 18 if board is None: 19 board = TRANSDUCERS 20 21 dx = create_points(1,1,delta,0,0) 22 dy = create_points(1,1,0,delta,0) 23 dz = create_points(1,1,0,0,delta) 24 25 26 27 Fx1 = compute_force(activation,points + dx,board=board)[0] 28 Fx2 = compute_force(activation,points - dx,board=board)[0] 29 30 Fx = ((Fx1 - Fx2) / (2*delta)) 31 32 Fy1 = compute_force(activation,points + dy,board=board)[1] 33 Fy2 = compute_force(activation,points - dy,board=board)[1] 34 35 Fy = ((Fy1 - Fy2) / (2*delta)) 36 37 Fz1 = compute_force(activation,points + dz,board=board)[2] 38 Fz2 = compute_force(activation,points - dz,board=board)[2] 39 40 Fz = ((Fz1 - Fz2) / (2*delta)) 41 42 return -1* (Fx + Fy + Fz)
def
stiffness_finite_differences( activation: torch.Tensor, points: torch.Tensor, board: torch.Tensor | None = None, delta=0.001):
8def stiffness_finite_differences(activation:Tensor, points:Tensor, board:Tensor|None=None, delta= 0.001): 9 ''' 10 Computes the stiffness at a point as the gradient of the force. Force computed analytically and then finite differences used to find the gradient \n 11 Computed as `-1* (Fx + Fy + Fz)` where `Fa` is the gradient of force in that direction \n 12 :param activation: Hologram 13 :param points: Points of interest 14 :param board: Transducers to use 15 :param delta: finite differences step size 16 17 ''' 18 19 if board is None: 20 board = TRANSDUCERS 21 22 dx = create_points(1,1,delta,0,0) 23 dy = create_points(1,1,0,delta,0) 24 dz = create_points(1,1,0,0,delta) 25 26 27 28 Fx1 = compute_force(activation,points + dx,board=board)[0] 29 Fx2 = compute_force(activation,points - dx,board=board)[0] 30 31 Fx = ((Fx1 - Fx2) / (2*delta)) 32 33 Fy1 = compute_force(activation,points + dy,board=board)[1] 34 Fy2 = compute_force(activation,points - dy,board=board)[1] 35 36 Fy = ((Fy1 - Fy2) / (2*delta)) 37 38 Fz1 = compute_force(activation,points + dz,board=board)[2] 39 Fz2 = compute_force(activation,points - dz,board=board)[2] 40 41 Fz = ((Fz1 - Fz2) / (2*delta)) 42 43 return -1* (Fx + Fy + Fz)
Computes the stiffness at a point as the gradient of the force. Force computed analytically and then finite differences used to find the gradient
Computed as -1* (Fx + Fy + Fz)
where Fa
is the gradient of force in that direction
Parameters
- activation: Hologram
- points: Points of interest
- board: Transducers to use
- delta: finite differences step size