Simulations of optical phenomena where diffraction is essential
LightPipes is a set of functions written in C++. It is designed to model coherent optical devices when the diffraction is essential.
The toolbox consists of a number of functions. Each function represents an optical element or a step in the light propagation. There are apertures, intensity filters, beam-splitters, lenses and models of free space diffraction. There are also more advanced tools for manipulating the phase and amplitude of the light. The program operates on a large data structure, containing square two-dimensional arrays of complex amplitudes of the optical field of the propagating light beam.
The LightPipes routines are modifications of the LightPipes C routines written by Gleb Vdovin for Unix, Linux, DOS and OS2 workstations.
Visit the website of Flexible Optical: http://www.okotech.com, where you can find the source code of LightPipes and a manual.
LightPipes support Windows 32bit and 64bit, Macintosh OSX, Linux 32bit and 64bit. It support python 2.7, 3.4, 3.5, 3.6 currently.
The packages is on PyPi, so simply open a terminal window and type at the prompt:
pip install LightPipes
You can also download packages from Releases.
http://pythonhosted.org/LightPipes/
A plane wave is diffracted by two small holes, separated a distance, d. So two more or less spherical waves will propagate from these holes.
The resulting interference pattern on a screen at distance z looks like:
The Python program Young.py described in detail.
The first step in Python is to import the LightPipes library:
import LightPipes
If the LightPipes library is successful installed on your computer Python can proceed with the next step. You probably want to plot the results, so import matplotlib:
import matplotlib.pyplot as plt
I like to work with units. So define them:
m = 1.0
cm = 1e-2*m
mm = 1e-3*m
um = 1e-6*m
nm = 1e-9*m
We have to initiate LightPipes. This is done with the following command:
LP = LightPipes.Init()
Next we define some variables: a wavelength of 20 micrometer , a 30 x 30 mm2 square grid with 250 x 250 pixels.
wavelength = 20*um
size = 30.0*mm
N = 500
Now we are ready to start the simulation. The Begin command generates a field with amplitude 1.0 and phase zero, a plane wave. So, all the 250 x 250 elements of array, F, contain the complex number: 1.0 + j0.0. The next commands generate two waves, F1 and F2, which are apertured by the two circular apertures and combined (simply added) by the BeamMix command. The combined wavefront is propagated a distance z=30 cm by the Fresnel command. After that the intensity is caculated and normalized to 255 (2 -> 255, 1 -> 1.0, 0 -> not normalized) by the Intensity command.
F = LP.Begin(size,wavelength,N)
F1 = LP.CircAperture(0.15*mm, -0.6*mm,0, F)
F2 = LP.CircAperture(0.15*mm, 0.6*mm,0, F)
F = LP.BeamMix(F1,F2)
F = LP.Fresnel(10*cm,F)
I = LP.Intensity(2,F)
The result is plotted using the fantastic matplot routines. We are not interested in axis around the pattern and we like to write a title above the plot.
plt.imshow(I);
plt.axis('off');
plt.title('intensity pattern')
plt.show()
- install docker from https://www.docker.com/products/docker
cd tools/linux
- build for linux 32bit:
bash build-linux-x32.sh
- build for linux 64bit:
bash build-linux-x64.sh
- install Miniconda3 from https://conda.io/miniconda.html
- install fftw:
brew install fftw
- install invoke and delocate:
pip install invoke delocate
cd tools/macos
theninv build_all
- install Miniconda3 32bit(name it
Miniconda32
) and Miniconda3 64 bit(name itMiniconda64
), they can be downloaded from https://conda.io/miniconda.html - install invoke:
pip install invoke
cd tools/windows
theninv build_all