## (1) Overview

### Introduction

Multilayered structures have been extensively studied since the beginning of optics. Such structures actually include optical filters, anti-reflective coatings, basic photovoltaic cells, waveguides of many kinds, prism couplers (for the excitation of surface plasmons, for instance) and so on. The invariance of these structures by any translation in two directions makes the solving of Maxwell’s equations particularly easy. From the very dawn of electromagnetic optics, analytical solutions have been exhibited for the simplest of these systems and have inspired quantum physics. These solutions are still taught nowadays and help the students form their physical intuition in many areas of optics and quantum physics. With time and the advent of computers, systematic ways for solving the equations provided by Maxwell’s theory have been proposed like the transfer matrix formalism [1, 2]. Many programs, that are easily available, are based on these principles, like OpenFilters [3]. Many more codes, much more specialized, are written in the secrecy of labs to compute advanced optical properties of these systems as their physics became more complex. In particular, the advent of metamaterials [4], with totally unforeseen phenomena as negative refraction or perfect lensing [5] have opened new perspectives even for the simplest multi-layered structures. Over the years, the authors of the present paper have built a whole set of tools to assess very peculiar optical properties [6] in multilayers with sometimes very exotic responses (like negative magnetic permeability and negative permittivity [7], or metals with spatial dispersion [8]). These tools have been used to study extensively refraction and focusing by metamaterials [9, 10, 11, 15], photovoltaic devices [16], and exotic coupling like in light wheels [12, 13] and guided modes like gap-plasmons [14, 8] or the ones of semi-conductor lasers. We have now chosen to make these numerical tools freely available to any teacher or researcher, hoping they will help the community study the huge number of phenomenon they allow to simulate.

### Implementation and architecture

The implementation of Moosh has actually much to do with a real army knife. A geometrical and an electromagnetic description of the structure are made in a central file structure.m in such a way that it is very simple to describe even very complex multilayers. Many programs are then available that are able to compute various optical properties of the structure described in structure.m. All these programs are shortly described in Table 1 and the structure of the whole code is shown Figure 1.

Table 1

Short description of the files contained in the Moosh directory.

File name Calling Sequence Description

structure.m Describes the whole structure parameters including permittivity and permeability of every materials, how they are stacked and the thickness of every layer.
Beam.m Beam Simulates the propagation of a gaussian beam in the structure and maps the resulting field.
Green.m Green Computes the electromagnetic wave emitted by a source located inside one of the layers.
coefficient.m coefficient (theta,lambda) Computes the reflection and transmission coefficient of the structure.
absorption.m absorption (theta,lambda) Computes the percentage of the incident energy that is absorbed inside each layer, along the with reflection and transmission coefficients when the structure is illuminated with a plane wave.
Angular.m Angular Angular uses absorption to compute the absorption in each layer, the reflection and transmission coefficients as a function of the incidence angle of light, for a plane wave.
Spectrum.m Spectrum Spectrum uses absorption to compute the absorption in each layer, the reflection and transmission coefficients as a function of the wavelength of light in vacuum, for a plane wave.
dispersion.m dispersion (kx,lambda) A function that vanishes whenever a guided mode of the structure has kx as a propagation constant for a given lambda.
The dispersion relation can thus be written as dispersion(kx,lambda)=0
descent.m descent (z0,step,stop) Steepest descent in the kx complex plane, starting at z0 with an initial step step and stopping when the absolute value returned by dispersion is smaller than stop.
Map.m Map This function maps the response of the dispersion function in the complex plan. This function allows visualizing the position of guided modes in the complex plane.
Guidedmodes.m Guidedmodes This function uses descent to found zeros of the dispersion function to find modes of the structure.
Profile.m Profile(kx,lambda) Computes the field profile of a guided mode characterized by its propagation constant kx (computed using descent).
extsqrt.m extsqrt(z) Square root with a different cut from what is used by default in computers – intented for external layers when searching for guided modes.
Photo.m Photo Computes the theoretical short-circuit current, shows the absorption spectrum.
Figure 1

Diagram of Moosh indicating the main programs (bold border) and the functions that are called. Guidedmodes needs to be run before using Profile.

Using Moosh thus means editing the structure.m file, then editing the program file (the part that should be modified is clearly identified and commented) and choosing the right parameters, then running the main program.

#### Supporting functions

Moosh is a matlab directory environment that contains the structure.m file, main codes that can be directly run and whose name begins with a capital letter, and functions that are called by other programs and that a standard user should never have to edit but that can be used as a library.

The directory sources should contain the following files:

#### Outline of the theory and link to Moosh’s structure

In a local, homogeneous and isotropic media, the electric and magnetic fields obey Maxwell’s equations that can be written

where D = ∈0∈ E and B = µ0µH, ∈ and µ being respectively the relative permittivity and permeability of the medium. From now we consider several media separated by interfaces that are all perpendicular to the z axis of the frame we are considering. We moreover assume that no field has any dependency on the y variable and that the time dependency is in e–iwt (with $\omega =\frac{2\pi c}{\lambda },\text{\hspace{0.17em}}\lambda$ being the wavelength in vacuum and c the speed of light). Under these assumptions the whole problem can actually be separated into two totally independent problems that correspond to actual polarizations of the incoming light, called s and p. For the s polarization, the only component of the electric field is Ey while for the p polarization Hy is the only component of the magnetic field. They both satisfy the same Helmholtz equation

$\Delta \psi +\epsilon \mu {\omega }^{2}\psi =0$

so that both can be written under the same form inside the j-th layer (extending from zj to zj+1):

${\psi }_{j}\left(x,z,t\right)=\left({A}_{j}^{+}{e}^{-i{k}_{z,j}\left(z-{z}_{j}\right)}+{B}_{j}^{+}{e}^{{}_{i{k}_{z,j}\left(z-{z}_{j}\right)}}\right)\cdot {e}^{i\left({k}_{x\cdot }x-\omega \cdot t\right)}$

where ${k}_{x}^{2}+{k}_{z}^{2}=\epsilon \mu {k}_{0}^{2}$ with ${k}_{0}=\frac{2\pi }{\lambda }$.

Maxwell’s equations must be satisfied even in the sense of distributions, which leads to the fact that at each interface, two quantities have to remain continuous, that is Ey and $\frac{1}{\mu }{\partial }_{z}{E}_{y}$ (and not just the derivative of Ey) for s-polarization and Hy and $\frac{1}{\in }{\partial }_{z}{H}_{y}$ for the p-polarization. Taking these conditions into account allows considering even the case of negative and µ [4, 5].

This leads to relations between the different Aj+ and Bj+. Solving the whole system using classical methods proves to be generally unstable (especially when evanescent waves with an imaginary kz are involved). Instead, we use scattering matrices [17], well known in quantum mechanics for one-dimensional problems or in the framework of transmission lines. In optics, they have been shown to be a perfectly stable method for almost any kind of problem, provided the determination of the complex square root is chosen for the inner layers so that the imaginary part of kz is always positive [6]. We define Aj and Bj by ${A}_{j}^{+}={e}^{i{k}_{z,j}{h}_{i}}{A}_{j}^{-}$ and ${B}_{j}^{-}={e}^{i{k}_{z,j}{h}_{i}}{B}_{j}^{+}$, where hj is the thickness of layer j. This can be written

$\left[\begin{array}{c}{A}_{j}^{+}\\ {B}_{j}^{-}\end{array}\right]=\left[\begin{array}{c}0\\ {e}^{i.{k}_{z,j}{h}_{i}}\end{array}\text{ }\begin{array}{c}{e}^{i{k}_{z,j}{h}_{i}}\\ 0\end{array}\right]\left[\begin{array}{c}{B}_{j}^{+}\\ {A}_{j}^{-}\end{array}\right]$

which defines a layer scattering matrix. When now considering an interface between medium j and medium j + 1, the continuity conditions lead to

$\left[\begin{array}{c}{A}_{j}^{-}\\ {B}_{j+1}^{+}\end{array}\right]=\frac{1}{{g}_{j+1}+{g}_{j}}\left[\begin{array}{cc}{g}_{j}-{g}_{j+1}& 2.{g}_{j+1}\\ {g}_{j}& {g}_{j+1}-{g}_{j}\end{array}\right]\cdot \left[\begin{array}{c}{B}_{j}^{+}\\ {A}_{j+1}^{-}\end{array}\right]$

where ${g}_{j}=\frac{{k}_{z,j}}{{\mu }_{j}}$ in s-polarization and ${g}_{j}=\frac{{k}_{z,j}}{{\in }_{j}}$ in p-polarization. This defines an interface scattering matrix. All these scattering matrices can be combined together using a cascading formula [14] that is used in the function cascade.m. The scattering matrix corresponding to the whole multilayer simply contains all the reflection and transmission coefficients of the structure.

This method is at the very core of Moosh. The function coefficient.m computes the reflection and transmission coefficients of the whole structure. It is used by Spectrum.m and Angular.m to illustrate how they change when the wavelength resp. the incidence angle is made to vary.

Once the scattering matrix for the whole structure is known, the coefficients Aj± and Bj± can be computed for each layer and then the field Ey or Hy, depending on the polarization, can be computed in each layer. The component of the Poynting vector along the z axis can then be computed at each interface. This vector represents the amount of energy that is crossing the interface. In s-polarization, it is given at the top of each layer by

${P}_{z}=\Re \left[\frac{{k}_{z,j}^{*}}{2.\mu .{\mu }_{0}.\omega }.\left({A}_{j}^{+}+{B}_{j}^{+}\right)\left({A}_{j}^{+*}-{B}_{j}^{+*}\right)\right]$

and in p-polarization by

${P}_{z}=\Re \left[\frac{{k}_{z,j}}{2.\in .{\in }_{0}.\omega }.\left({A}_{j}^{+}+{B}_{j}^{+}\right)\left({A}_{j}^{+*}-{B}_{j}^{+*}\right)\right].$

Making the difference between the Poynting flow at the top and at the bottom of each layer gives access to the quantity of light that has been absorbed by any layer. The function absorption.m computes this absorption and normalizes it by the total amount of energy with which the structure was illuminated, thus returning the percentage of the incoming energy absorbed by each layer.

The study of photovoltaic devices requires specific tools, as the absorption is not sufficient to evaluate the actual efficiency of a device. The spectral density of photons is required, i.e. the number of photons received per wavelength unit. The program Photo.m, when the active layer (converting the photons into current) has been specified, computes the theoretical short-circuit current assuming an illumination by an am1.5 solar spectrum and a quantum efficiency (the conversion of photons into electron-hole pairs) of 1.

In order to simulate the propagation of a beam inside the structure, the incident beam can be decomposed on the plane wave basis using a Fourier transform. A computation of the field inside each layer is done for each plane wave, and the results are multiplied by the amplitude of each plane wave in the decomposition of the incident beam and summed. This is what the program Beam.m does. All the parameters of the incident beam including the angle of incidence, the width and its position with respect to the computation window have to be specified.

Multilayers are very often used as waveguides in optics. The best way to understand the propagation of light in such structures in a direction parallel to the interfaces, is to consider it as the propagation of different guided modes, whose profile remains unchanged when they propagate. It is thus particularly important to be able to find these modes and to compute their propagation constant (giving access to their phase and group velocity, propagation length) and their profile. These modes satisfy a dispersion relation, that can be written f(kx, λ) = 0 with a complex propagation constant kx and a real wavelength λ. The function dispersion(kx,lambda) computes f using a modified scattering matrix formalism. Finding the modes finally reduces to finding the zeros of f, which can be done using a steepest descent method for |f| in the kx complex plane. This is the role of descent.m. The program Guidedmodes.m tries to find all the modes that are quite close to the real axis (which makes them relevant) by performing numerous calls to descent and returning all the different propagation constants (and displaying the effective index kx/k0) corresponding to actual guided modes in the variable guided_modes. The quantity $\frac{1}{|f|}$ can be mapped using Map.m, helping to better understand the results provided by Guidedmodes.m. Note that changing the square root determination for the external layers, which can be done by modifying extsqrt.m, will change the cuts appearing on the map. This can be useful to reveal or hide poles of $\frac{1}{|f|}$. Finally, the function Profile.m computes the profile of the mode characterized by the propagation constant it has been provided with and that can be found with Guidedmodes.m.

The electromagnetic field emitted by a punctual source can be decomposed on the plane wave in the same manner as for a Gaussian beam, the only fundamental difference being that the source is placed inside the structure. The program Green.m computes the field resulting from placing a punctual source inside any layer of the structure.

Moosh comes with material parameters stored in a directory data. This directory contains functions that, provided with a wavelength in vacuum in nanometers, return the value of the relative permittivity for a given material.

Metals, in the above framework, are considered as homogeneous dielectrics characterized by a complex permittivity that can be typically given by a Drude-Lorentz model. But this local description is not fully accurate in some situations when particularly large wavevectors are considered (as is quite common in plasmonics). It is then possible to describe the response of metals using a hydrodynamic model [8]. A semi-analytical method for solving Maxwell’s equation in that case can be devised [18]. We have implemented this method and included it in Moosh in a separate directory nonlocal with an identical structure to that of sources, so that the nonlocal version of Moosh can be used very easily.

### Quality control

Moosh has been widely tested over the years. Its results have been extensively compared to completely analytical solutions as can be found in textbooks (for anti-reflective coatings, Bragg mirrors, waveguides), and compared with all kinds of numerical tools that exist including Fourier Modal Methods or finite elements (COMSOL). The stability of the method itself has been assessed by comparing it to transfer matrix methods and Dirichlet-to-Neuman maps and has been improved by carefully choosing the determination of the complex square root inside the layers [6]. Using Moosh, we have been able to replicate results that have been published by other teams in many areas of optics including metamaterials, nanophotonics, plasmonics and photovoltaics.

## (2) Availability

### Operating system

Moosh needs Octave or Matlab to be installed, which makes it available on Windows (XP SP3 and higher with cygwin), Linux, MacOS X and even Android.

### Programming language

Octave 3.8 and higher, Matlab 7 and higher.

### List of contributors

Fabien Krayzel and Rémi Pollès wrote the very first version of Beam.

### Software location

#### Code repository

Name: Github

Identifier: https://github.com/AnMoreau/Moosh

Licence: GPL 2.0

Date published: October 5, 2015.

## (3) Reuse potential

In order to illustrate the potential of Moosh, a few examples are provided with the code. These include (i) the computation of the absorption in a photovoltaic structure including lossy transparent conducting electrodes, (ii) the reflection corresponding to the excitation of a surface plasmon resonance using a prism coupler and the computation of the corresponding field, as well as the guided modes of the structure (one being actually a leaky mode) (iii) the calculation of the field emitted by a punctual source placed in a contra-directional coupler based on a negative group velocity waveguide, illustrating the light wheel phenomenon in a metamaterial framework. A few output examples are shown Figure 2. The functions provided with Moosh are easy to reuse with optimization techniques, for instance. We are confident that Moosh will be useful to the optics community in the future [19, 20].

Figure 2

Output examples. (a) Reflection by a Bragg mirror, in which the light penetrates before being totally reflected (b) Excitation of a surface plasmon resonance (c) Excitation of a light wheel by a source placed in the dielectric waveguide.

Finally, we underline that the s polarization is actually equivalent to a 1D quantum problem for the wave function of a single particle, if the x coordinate is considered as being the time. Moosh can thus be used to simulate the behaviour of the wavefunction in a piecewise potential.

## Competing Interests

The authors declare that they have no competing interests.