I’m announcing my first Julia package, TransferMatrix.jl, a general 4 x 4 transfer matrix implementation in Julia.
The transfer matrix method propagates an electric field through a multi-layered medium. The results are the transmitted and reflected light for a given wavelength, and the electric field profile may also be calculated.
There are a lot of transfer matrix implementations on the web. It seems any graduate student in thin-films or optics writes a transfer matrix program. Why make another one? Many of these programs are one-offs with little documentation and are not very reusable. It is often difficult to get the program up and running or extend the code for a new research idea. Further, most use the 2 x 2 method and do not strive for full generality.
This implementation includes several key features:
The code is broken into small functions so that the user can easily implement their own solution at any step in the transfer matrix calculation by swapping out one or more functions.
This is a 4 x 4 transfer matrix based on the latest research trying to create a general implementation with broad applicability that is numerically stable and avoids singularities, a well-known problem for transfer matrix algorithms historically (a reference list is on the package website).
Everything is fully documented and each piece of code that comes from a paper includes the reference and DOI at the function level. Furthermore, step-by-step tutorials are given to get the user running right away. All of the code on the tutorial website is runnable as-is.
It is very easy to build a multi-layered structure layer by layer. I have tried to make the boiler-plate code very low. This includes functionality to read refractive index files downloaded from refractiveindex.info. Complicated simulations are also easy to build and share with a YAML file. And together with Julia’s speed, it is fast and easy to create a transmittance / reflectance spectrum as a function of both wavelength and angle with respect to the incident light to produce 2D contour plots.
It is easy to make a complicated structure and share it with others with a YAML file. You can specify all of the simulation parameters (wavelength range, refractive indices, files, device angle range, etc.). It is simple to set up a periodic structure with an arbitrary number of periods in the file. This facilitates reproducibility and also makes it easy to try several variations and save them as separate config files.
My goal is for this transfer matrix program is to be readily reusable and extensible. While it may be instructive to create one’s own implementation, there is a lot of redundancy out there. I would hope that this package becomes at least a first stop for someone looking for a transfer matrix algorithm. If the Julia community thinks it is robust and useful, then I would like to see it become part of a set of synergistic science, physics, or optics packages in the ecosystem.
This is my first package written with a broad audience in mind. Everything else I’ve written has basically been just for me. I want as much feedback as I can get. In particular:
- I’m not certain that I’m taking full advantage of Julia’s multiple dispatch
- I’m not sure if the current way I’m using types is appropriate
- Can this code be made even more reusable by other researchers? What have I missed?
I would be very thankful to anyone generous enough to give their time to provide feedback. Check out the tutorials and documentation on the package website, built with Documenter.jl.
I could not find similar packages in Julia, but there are two that seem popular in Python:
- pyGTM (TransferMatrix.jl is based on the paper associated with this code. Generalized 4 × 4 matrix formalism for light propagation in anisotropic stratified media: study of surface phonon polaritons in polar dielectric heterostructures)
- MATLAB GTM (The MATLAB version of pyGTM)
- tmm by Steven Byrnes (I have seen this package cited in some papers. [1603.02720v5] Multilayer optical calculations )