Simple trap optimization.

A very basic use-case, finding the correct phases to levitate a bead centered 5 cm above a 9x9 element rectangular array, then inspecting the resultant field.

[1]:
import numpy as np
import levitate

We define a target trap position and a transducer array. The optimizaiton typically converges from random initialization, but we can help it on the way by initializing close to a known nice solution.

[2]:
pos = np.array([0, 0, 80e-3])
array = levitate.arrays.RectangularArray(9)
phases = array.focus_phases(pos) + array.signature(stype='twin') + 0.2 * np.random.uniform(-np.pi, np.pi, array.num_transducers)
start = levitate.complex(phases)

To find the suitable state of the transducer array, we define a cost function that we minimize with a BFGS-variant optimization.

[3]:
point = (levitate.fields.GorkovLaplacian(array) * (-100, -100, -1)).sum() + abs(levitate.fields.Pressure(array))**2 * 1e-3
results = levitate.optimization.minimize(point@pos, array, start_values=start)

Finally, we visualize the sound field.

[4]:
array.visualize[0] = ['Signature', pos]
array.visualize.append('Pressure')
array.visualize(results).show()