Matrices or arrays are widely used in Lumerical scripting, to store the results of a simulation
or post-process these results.
For instance, each component of the electric field obtained from a field monitor is stored
as a 4 dimension matrix (position x,y,z and frequency f), even if the monitor is 2D or
stores only 1 frequency point.
In such case, it can be useful to remove the singletons using the “pinch” command.
It can also be used to extract a submatrix by removing a specific dimension and selecting
the index of the removed dimension.
In this example, we remove the fourth dimension and select the second index of that dimension.
If we don’t specify the index of the removed dimension, the first index will be selected.
The “meshgridx” and “meshgridy” will create a 2D meshgrid, respectively in the
x and y direction from 2 single column vectors.
In this example, we use these functions to create an image of a 2D Gaussian function.
Another useful function is the “integrate” function, that will return the integral of
a matrix over a specific dimension or list of dimensions.
In this example, we calculate the power flowing through a monitor “R” by integrating the
Poynting vector over the dimension of the monitor plane.
Note we use the “.” operator to access the elements of the dataset P: the Poynting
vector component Py, the x vector and the frequency vector f).
Integrals over singleton dimensions will return zero (i.e. the area under a single point is
If you use the “integrate2” function, the singleton dimensions will be ignored.
It is possible to perform search operation on arrays.
You can search for entries meeting some conditions using the find function.
It will return the indices of the entries meeting the condition.
The condition can be a specific value.
In this example, it will return the index of M whose element is closest to 5e-6.
Or you can search for entries meeting a more generic condition.
In this example we search for the values of N that are greater than 5 and lower or equal
There are 2 elements, 6 and 7, that meet this condition and the find command will return
7 and 8, the indices of these elements.
You can search for local maxima using the findpeaks function.
Findpeaks(y,n) will return the n largest peaks.
In this example, we are searching for the first 2 local maxima of the array y.
These 2 maxima are located at x=18.92 and x=-15.76.
You can also search for the peak of maximum value, using findpeaks(y).
Here we are searching for the wavelength of maximum transmission.
The maximum is found at 471.4nm.
Many other array functions are available.
You can find all the information on the Knowledge Base.
In the next unit, we will review how to use mathematical functions in scripts.