Tutorials and Examples Guide
EMUstack v2.0 provides an interactive, notebook-first workflow. All examples are organized into two distinct directories to demonstrate the two supported meshing paradigms:
Classic Mesh Workflow (``EMUstack/examples/`` — 22 Notebooks): Demonstrates the classic EMUstack workflow where 2D nanostructured layers either load pre-generated meshes (
.mail,.msh) or invoke Gmsh on parameterized.geotemplates fromEMUstack/backend/data/meshes/.Native In-Memory Netgen Workflow (``EMUstack/examples_netgen/`` — 23 Notebooks): Demonstrates the modern pure-Python workflow where 2D nanostructured layers generate curved quadratic meshes directly in memory via
geo_paramsdictionaries or Python geometry templates (*_template.py) fromEMUstack/backend/data/meshes/, requiring zero external Gmsh installation or disk files.
Note
Every tutorial notebook is self-contained and pre-executed with inline figures and xarray outputs. They can be viewed directly on GitHub or run interactively in Jupyter Lab / Notebook.
Simulation Workflow
Simulations in EMUstack follow a concise, 5-step pattern. The code blocks below form one
script that runs as written (tests/unit/test_docs_tutorial.py executes it).
1. Define Illumination
A Light object holds one wavelength, the angle of incidence and the number of plane-wave
diffraction orders (max_order_PWs). Spectra are computed by looping over wavelengths
(see Wavelength sweeps below).
import numpy as np
from EMUstack.backend import objects, materials, stack, plotting
light = objects.Light(650.0, theta=0.0, phi=0.0, max_order_PWs=3)
2. Define Materials and Layers
Create homogeneous thin films and periodic nanostructures:
# Homogeneous substrate (semi-infinite glass)
glass = materials.Material(1.52)
sub = objects.ThinFilm(period=600.0, material=glass, loss=False)
# 2D periodic nanostructure: silicon nanopillars, 240 nm diameter, 200 nm tall.
# plotting_fields=1 keeps the mode fields, which the field maps in step 5 need.
meta = objects.NanoStruct(
'2D_array', 600.0, diameter1=240.0,
background=materials.Air, inclusion_a=materials.Si_c, height_nm=200.0,
lc_bkg=0.1, lc2=2.0, plotting_fields=1,
)
# Superstrate (semi-infinite air)
sup = objects.ThinFilm(period=600.0, material=materials.Air, loss=False)
3. Compute Eigenmodes
Solve for the modes of each layer at this wavelength. num_BMs (the number of Bloch modes
kept in the nanostructured layer) must exceed the number of plane waves, 58 for
max_order_PWs=3; its default is twice the number of plane waves plus 20.
modes_sub = sub.calc_modes(light)
modes_meta = meta.calc_modes(light, num_BMs=100)
modes_sup = sup.calc_modes(light)
4. Stack and Calculate Scattering
Assemble the stack and cascade the layers using scattering matrices:
sim_stack = stack.Stack((modes_sub, modes_meta, modes_sup))
sim_stack.calc_scat(pol='TE')
print("T = %.4f, R = %.4f" % (sim_stack.t_list[-1], sim_stack.r_list[-1]))
5. Visualize and Export Data
Plot spectra or inspect local fields inline without disk side effects. The in-plane field interpolators take coordinates normalized to the period (0 to 1).
# Export spectra to xarray Dataset
ds = plotting.spectra_to_xarray([sim_stack])
# Evaluate 3D electromagnetic near-fields on an in-plane slice (xy), mid-height of the pillars
bundle = plotting.fields_interpolator_in_plane(
sim_stack, lay_interest=1, z_value=100.0, return_H=True
)
u = np.linspace(0.0, 1.0, 101)
X, Y = np.meshgrid(u, u)
Ex, Ey, Ez = bundle.Ex(X, Y), bundle.Ey(X, Y), bundle.Ez(X, Y)
# Evaluate vertical cross-sections (xz or yz) across the full stack
cross_bundle = plotting.fields_interpolator_cross_section(
sim_stack, plane="xz", slice_coord=300.0
)
Wavelength sweeps
Repeat steps 1, 3 and 4 for each wavelength; the layer objects are reused. The notebooks run the wavelengths in parallel and choose them adaptively.
stacks = []
for wl in np.linspace(600.0, 700.0, 3):
light = objects.Light(wl, theta=0.0, phi=0.0, max_order_PWs=3)
modes = [sub.calc_modes(light), meta.calc_modes(light, num_BMs=100),
sup.calc_modes(light)]
s = stack.Stack(modes)
s.calc_scat(pol='TE')
stacks.append(s)
spectra = plotting.spectra_to_xarray(stacks)
Available Tutorial Notebooks
Notebook Name |
In |
In |
Physics Topic |
|---|---|---|---|
|
Yes |
Yes |
Single Non-Dispersive Interface: Fresnel transmission/reflection. |
|
Yes |
Yes |
Single Dispersive Interface: Tabulated refractive indices (Si). |
|
Yes |
Yes |
Multilayered Thin-Film Stack: Fabry–Pérot resonance. |
|
Yes |
Yes |
Metallic Back-Reflector: Modeling lossy finite mirrors. |
|
Yes |
Yes |
1D Lamellar Grating: TE vs TM diffraction spectra. |
|
Yes |
Yes |
Multi-Inclusion 1D Grating: Asymmetric diffraction profiles. |
|
Yes |
Yes |
3-Element 1D Grating: Resonance engineering. |
|
Yes |
Yes |
2D Nanowire Array: Photovoltaic absorption and omega-k plots. |
|
Yes |
Yes |
Hybrid 1D/2D Stack: Direct Simmo-to-Simmo mode matching. |
|
Yes |
Yes |
Elliptical Nanohole Array: Circular dichroism under CPL. |
|
Yes |
Yes |
1D Bloch Modes & Field Maps: Near-field visualization. |
|
Yes |
Yes |
2D Array Near-Fields: In-plane and vertical cuts. |
|
Yes |
Yes |
Mode Amplitudes: Bloch and plane-wave coupling strengths. |
|
Yes |
Yes |
In-Plane Momentum Spectrum: Guided-mode coupling. |
|
Yes |
Yes |
Lateral Layer Shifts: S-matrix shear transformations. |
|
Yes |
Yes |
Ultrathin Film Limit: Coherent 50% absorption bound. |
|
Yes |
Yes |
Substrate Sweeps: Reusing layer modes across 100 substrates. |
|
Yes |
Yes |
Grating Convergence: Replication of Handmer et al. (2010). |
|
Yes |
Yes |
Extraordinary Optical Transmission: Liu & Lalanne (2008). |
|
Yes |
Yes |
Guided Slab Modes: Metamaterial dispersion finding. |
|
Yes |
Yes |
Showcase: 3-plane (xy, xz, yz) near-fields of plasmonic disks. |
|
Yes |
Yes |
Showcase: Custom unit-cell templates & 3-plane field maps. |
|
No |
Yes |
Flagship: BIC to quasi-BIC in a bar-dimer metasurface (Gorkunov et al., Fig. 3a): parallel adaptive spectra (520-650 nm), field and optical chirality enhancement at the q-BIC. |
Native Netgen CSG Tutorials (In-Memory Meshing)
- From a BIC to a quasi-BIC: Bar-Dimer Metasurface (Gorkunov et al., Fig. 3a)
- Libraries
- EMUstack: Au Nanodisk array with interpolators
- Libraries
- EMUstack: tilted elliptical au nanohole array using the ‘custom’ target interface
- 1. Single Non-Dispersive Interface: Analytical Fresnel Equations & EMUstack S-Matrix
- 2. Single Dispersive Interface: Wavelength-Dependent Optical Constants
- 3. Multilayered Dispersive Thin-Film Stack: Fabry–Pérot Interference
- 4. Finite Metallic Back-Reflector & Lossless Substrate Invariant
- 5. 1D Lamellar Diffraction Grating: Bloch Modes and Polarization
- 6. 1D Grating with Two Interleaved Inclusions: Unit-Cell Symmetry Breaking
- 7. 1D Grating with Three Inclusions: Compound Grating Resonances
- 8. 2D Silicon Nanowire Array for Photovoltaics: Efficiency and Dispersion
- 9. Combining a 1D Grating and a 2D Array in One Stack
- 10. Elliptical Nanohole Array: In-Plane Anisotropy and Circular Dichroism
- 11. 1D Grating Mode Profiles and Vertical Field Cross-Sections
- 12. 2D Nanostructure Near-Field Visualization (In-Plane and Cross-Sections)
- 13. Modal Expansion Analysis: Bloch Mode & Plane-Wave Coupling Amplitudes
- 14. Reciprocal-Space Momentum Spectrum: \(k_\parallel\) Excitation Distribution
- 15. Shifting Periodic Layers Sideways: Shear Transformations
- 16. Fundamental 50% Absorption Limit in Coherent Ultrathin Films
- 17. S-Matrix Layer Mode Reuse Across Diverse Substrates & Thickness Averaging
- 18. Modal Convergence in Stacked Lamellar Gratings (Handmer et al., 2010)
- 19. Extraordinary Optical Transmission (EOT) in Subwavelength Metallic Hole Arrays
- 20. Metamaterial Slab Waveguide Dispersion via S-Matrix Poles
Classic Gmsh & Pre-Generated Mesh Tutorials
- Libraries
- EMUstack: Au Nanodisk array with interpolators
- Libraries
- EMUstack: tilted elliptical au nanohole array using the ‘custom’ target interface
- 1. Single Non-Dispersive Interface: Analytical Fresnel Equations & EMUstack S-Matrix
- 2. Single Dispersive Interface: Wavelength-Dependent Optical Constants
- 3. Multilayered Dispersive Thin-Film Stack: Fabry–Pérot Interference
- 4. Finite Metallic Back-Reflector & Lossless Substrate Invariant
- 5. 1D Lamellar Diffraction Grating: Bloch Modes and Polarization
- 6. 1D Grating with Two Interleaved Inclusions: Unit-Cell Symmetry Breaking
- 7. 1D Grating with Three Inclusions: Compound Grating Resonances
- 8. 2D Silicon Nanowire Array for Photovoltaics: Efficiency and Dispersion
- 9. Combining a 1D Grating and a 2D Array in One Stack
- 10. Elliptical Nanohole Array: In-Plane Anisotropy and Circular Dichroism
- 11. 1D Grating Mode Profiles and Vertical Field Cross-Sections
- 12. 2D Nanostructure Near-Field Visualization (In-Plane and Cross-Sections)
- 13. Modal Expansion Analysis: Bloch Mode & Plane-Wave Coupling Amplitudes
- 14. Reciprocal-Space Momentum Spectrum: \(k_\parallel\) Excitation Distribution
- 15. Shifting Periodic Layers Sideways: Shear Transformations
- 16. Fundamental 50% Absorption Limit in Coherent Ultrathin Films
- 17. S-Matrix Layer Mode Reuse Across Diverse Substrates & Thickness Averaging
- 18. Modal Convergence in Stacked Lamellar Gratings (Handmer et al., 2010)
- 19. Extraordinary Optical Transmission (EOT) in Subwavelength Metallic Hole Arrays
- 20. Metamaterial Slab Waveguide Dispersion via S-Matrix Poles