The mqwgain command calculates stimulated and spontaneous emission coefficients in the multiplequantum well (MQW) structure. These results can be used as inputs to the travelling wave laser model (TWLM) to calculate LI curves and laser spectra. They can also be used to calculate the absorption due to the quantum confined Stark effect (QCSE) in electroabsorption modulators (EAM). A detailed description of the inputs and outputs for this command can be found here. A related command to generate the material parameters that mqwgain requires is buildmqwmaterial.
Note: The graphical user interface (GUI) will not be responsive while running mqwgain command. This is not cause for alarm and the GUI will become responsive again after the command is executed, which can take from several minutes to several tens of minutes depending on the problem size.
Overview
The MQW gain calculation is based on the 4x4 k.p method as given in references [13]. The method is mainly suitable for IIIV materials with Zincblende crystal structure. Specifically, the list of materials supported by our default database is given in the documentation. In addition, other materials may be used by providing all required material properties.
The main steps necessary for using mqwgain command are:
 Create material parameters.
 Create inputs for mqwgain command (mqwgain).
 Run mqwgain.
Internally, the gain of the MQW structure is calculated using the following algorithm:
 Electronic band structure is calculated using the 4x4 k.p method. One eigenproblem in the valence band is solved for each transverse wave vector, while in the conduction band only one eigenproblem is solved in total at zero wave vector using the parabolic band assumption. The result of this step is the electronic wave functions and subbands in the conduction and valence bands of the quantum wells. These represent states confined in the quantum wells.
 Fermi level calculation. This energy level controls the occupation probability for each confined state through the FermiDirac distribution function. Its value depends on the band structure (calculated in step 1) and on the charge density (input parameter).
 Stimulated and spontaneous emission calculation. These emissions depend on the occupation of quantum well levels (step 2) and the overlap of wave functions between conduction and valence bands. The stimulated emission corresponds to gain, while the spontaneous emission mainly contributes to optical loss (it also seeds lasing when gain becomes larger than all loss mechanisms). Negative gain is equivalent to absorption that can be used in the simulations of EAMs based on the quantum confined Stark effect.
Obtaining Material Properties
The material properties have significant effects on the final results. While there are many published works listing important material properties for semiconductors of interest, it can be challenging to find accurate properties for certain ternary and quaternary materials. We allow several methods to define the material properties and customizing them:

By specifying materials and compositions directly at the input of mqwgain script command:
materials = cell(3);
#...
materials{2} = struct;
materials{2}.database_material = "AlGaAs";
materials{2}.x = 0.41;
The material properties will be defined based on our default material database. To customize, the users can provide their own database, which should be in the correct format of the default database:config.materialdb = "/home/auser/myfolder/my_material_db.json";
For more details please check the documentatio . 
By first calling buildmqwmaterial command, which returns the material properties as a struct that can be directly used as an input to mqwgain.
materials = cell(3);
#...
materials{2} = buildmqwmaterial("/home/auser/myfolder/my_material_db.json", 300, "InAlAs", 0.47);
To customize properties, this method provides direct access to all of the material properties from the script. For more details please check the mqwgain and buildmqwmaterial documentation. 
The users can also provide all material properties on their own. The properties should be provided as a struct with specific fields. For more details about the required fields please check the mqwgain or buildmqwmaterial documentation.
Adjusting Input Parameters and Configuration
 Relevant electron and hole states in the MQW structure are confined to the quantum wells. For physically meaningful results all other states should be filtered out. This is controlled at input by setting the boundary conditions. There are two types of boundary conditions: hard wall (wave function drops to zero at the boundary) and perfectly matched layer (PML). They are selected by the option pmlactive = true or false. For both types of boundary conditions it is best to extend the simulation region by a uniform potential to ensure that the wave function decays sufficiently towards the boundaries (~10nm is usually enough on each side). For hard wall boundaries and PML, the selection of confined states is governed by a threshold on the magnitude of the wave function derivative at the boundaries (option hwcutoff) or a threshold on the total probability density inside the PML, respectively. Sometimes it may be necessary to adjust these parameters from their default values to ensure that only confined states or enough confined states are selected. Whether a state is confined can be confirmed visually by inspecting the probability density near the boundaries (it should be vanishing).
 The electronic band structure (E,k) calculation is 1D, since the two inplane directions (transverse to the growth direction) are considered rotationally symmetric: wavevector k corresponds to the radial component. In order to accurately calculate the Fermi level for the given charge density it is necessary to include enough (E,k) states in the calculation. This is especially important if the simulation temperature is much higher than the room temperature, when larger k values contribute nonnegligibly to the density according to the FermiDirac distribution. It is usually enough to include 10% of the Brillouin zone (i.e. 2π/a*0.1, where a is the lattice constant) at room temperature and up to 20% at high temperatures. This is set by the option kt.
Input Charge Density and Output Emission Coefficients
One detail to note is the definition of charge density and emission coefficients (stimulated and spontaneous emission) used in the MQW gain solver. This may be important when comparing results from the solver with other results in the literature or with measurements.
In a MQW gain simulation, the carrier density input is a scalar that is averaged over the total simulation span. Typically, the carrier density in the quantum wells is larger than this. To convert to the quantum well density we can approximately assume that the charge is all confined in the quantum wells and then multiply the averaged density by the ratio of total thickness and quantum well thickness (taking all quantum wells into account).
The emission coefficients at the output are also calculated relative to the total simulation span. To convert to emission considering quantum wells only, we can again multiply by the ratio of total thickness to quantum well thickness. Note that the definition of thickness is consistent: for example, when using the gain and spontaneous emission from mqwgain in the travelling wave laser model, the mode confinement factor will also be calculated over the total thickness, so that the mode overlap with the active region will be larger than the overlap with the quantum wells only, but the emission coefficients are proportionally smaller by the same factor.
 D. Ahn et al., J. Appl. Phys. 64, 4056 (1988)
 S. L. Chuang, Physics of Optoelectronic Devices
 Chuang, Phys. Rev. B, 43, 9649 (1991)
Benchmark results and example scripts
The following two references implement the same method as mqwgain and are used here for benchmarking purposes as well as to provide example scripts. Since the cited papers define most of their parameters we use those custom parameters instead of our default database in order to ensure fair comparison. The custom material parameters are defined in mqw_material_build_functions.lsf, mqw_material_database.lsf which should be placed in the same folder as the main script.
 For benchmarking stimulated and spontaneous emission coefficients and temperature dependence: mqwgain_hardwall_0kVpercm_sqw_Ahn1988_gain.lsf, mqwgain_hardwall_50kVpercm_sqw_Ahn1988_gain.lsf mqwgain_pml_0kVpercm_sqw_Ahn1988_maxgain_vs_temperature.lsf:
D. Ahn, S. L. Chuang, and Y.C. Chang, Valenceband mixing effects on the gain and the refractive index change of quantumwell lasers, J. Appl. Phys. 64, 4056 (1988).
 For benchmarking strain effects:
mqwgain_hardwall_0kVpercm_sqw_Chuang1991_strain.lsf:
S. L. Chuang, Efficient bandstructure calculations of strained quantum wells, Phys. Rev. B, vol. 43, no. 12, 1991.
Gain at 0 zero electric field:
Gain at 50kV/cm electric field:
Maximum gain vs temperature:
Effects of strain due to varying material composition on the band gaps between the lowest conduction band (C1) and the highest light hole (LH1) and heavy hole (HH1) valence bands:
C1HH1 band gap  x=0.37  x=0.47  x=0.57 

mqwgain  0.729  0.802  0.874 
Chuang 1991  0.727  0.8  0.872 
C1LH1 band gap  x=0.37  x=0.47  x=0.57 

mqwgain  0.824  0.842  0.862 
Chuang 1991  0.827  0.845  0.867 
Example: Calculating Gain Spectra vs. Temperature
In this example, based on the device described in Ref. 1, we demonstrate the calculation of gain spectra with respect to temperature. Material model parameters for the quantum well and barrier materials, quaternary InGaAsP grown on an InP substrate, are extracted from the material database included with the solver, but some parameters are modified to use corresponding values from Ref. 1 to obtain good agreement with the published results.
The following figure compares gain vs temperature at fixed charge density with the spectra reported in Ref. 1.
To improve the agreement between results, some material parameters from our default material database were customized:
• The valence band offsets from Ref. 1 were used
• The band gap from Ref. 2 was used
• The temperature and carrier densitydependent correction models from Ref 1. were applied to the band gap
• The average carrier density used in mqwgain was obtained from the quantum well density reported in Ref. 1 according to the method explained above in section Input Charge Density and Output Emission Coefficients. The same conversion is done to the gain curves before comparing them with the reference.
Note that the gain spectra from the mqwgain command are broader than those reported in Ref. 1. This is likely due to the calculation of the states from coupled (rather than independent) quantum wells, which results in subband splitting. This splitting increases the span of the energy range for the subband states, which leads to a broadening of the gain response. While it is difficult to determine which set of gain curves is more accurate due to the lack of measurement data, this level of discrepancy is not expected to cause major differences in the measurable quantities, like laser LI curves.
For an example how to set up gain simulation using uncoupled quantum well approximation for the same structure as shown in the figure refer to the next section. This approach is recommended whenever applicable, as it leads to much faster simulation.
The following scripts can be used to reproduce the figure: mqwgain_InGaAsP_laser.lsf, piprek2000_fig7.lsf. The resulting gain spectra can be used as inputs into the travelling wave laser compact model to build a comprehensive circuit model of the light source.
The mqwgain command outputs four datasets contained in a struct. Please see the mqwgain documentation for more details. To visualize mqwgain output datasets, use the script command visualize(x), where x is the dataset. For example, to visualize the probability density (wave function magnitude squared), run visualize(out.wavefunction), where out is the name of the variable to which the output of mqwgain is assigned.
The first visualization window shows the probability density corresponding to the wave function of the first basis vector of the lower Hamiltonian, while the second visualizer window corresponds to the second basis vector of the lower Hamiltonian. The 4x4 k.p basis used by the solver is based on a unitary transformation that splits the 4x4 Hamiltonian into two 2x2 Hamiltonians (lower and upper) for which the eigenproblem solution is more efficient [2,3]. The probability densities are plotted against the transverse wave vector (yaxis) for the first subband and show that the corresponding (E,k) states in the band structure are states confined to the MQW region, since the probability density decays at the boundaries.
 J. Piprek, P. Abraham, and John E. Bowers, SelfConsistent Analysis of HighTemperature Effects on StrainedLayer MultiquantumWell InGaAsP–InP Lasers, IEEE Journal of Quantum Electronics, vol. 36, no. 3, March 2000.
 S. L. Chuang, Physics of Photonic Devices, 2009
 D. Ahn, S. L. Chuang, and Y.C. Chang, Valenceband mixing effects on the gain and the refractive index change of quantumwell lasers, J. Appl. Phys. 64, 4056 (1988).
For the full laser diode simulation workflow see simulation of LI curves for InGaAsP/InP MQW ridge laser.
Uncoupled MQW approximation for faster gain simulation
If the barriers in the multiple quantum well structure are thick enough, it is a good approximation to consider quantum wells uncoupled, that is, to solve for the wave functions considering one quantum well at a time. This can significantly reduce the length of the simulation domain and make the gain simulation much faster, while producing similar results as in the full MQW structure.
If all quantum wells in a multiple quantum well structure have the same geometry and material composition and there is no potential drop across the active region, which is a good approximation for laser simulations, it is possible to simply define geometry with a single quantum well instead of multiple quantum wells. Now we can perform the gain simulation on a single quantum well. The average charge density at the input to the gain simulation should be scaled accordingly, in order to represent the same local charge density as in the full MQW structure. Similarly, the final single quantum well gain and spontaneous emission results should be scaled onto the full MQW structure.
Here is the script file with an MQW gain example that allows easy switching between coupled and uncoupled cases and their comparison: mqwgain_InGaAsP_laser_uncoupled.lsf. The control option (boolean) is named uncoupled_wells and defined near the top of the file. The figure comparing the fully coupled simulation to the uncoupled well simulation (several times faster) is shown below. We can see that the gain curves are approximately similar, where the coupled case curves are a bit wider, which is due to the miniband formation in a multiple quantum well structure. This miniband is wider in energy comparing to the single energy state in a single quantum well.