CasualRCWA.RCWA — Method
RCWA(input::RCWAInput) -> RCWAOutputRun a full RCWA simulation and return an RCWAOutput.
Arguments
input::RCWAInput: Simulation parameters including the incoming wave, layer stack, and number of harmonics.
CasualRCWA._get_block — Method
_get_block(FM, Nx, Ny, Δq, P)Build the Toeplitz block for Y-harmonic difference Δq from the FFT FM of a pattern of native size (Nx, Ny).
Each entry is the exact Fourier coefficient of the piecewise-constant function defined by the pixel grid. This is the raw DFT coefficient multiplied by the rectangular-pixel transfer function h(k, N), which makes the result independent of the input resolution.
CasualRCWA._stabilize_eigenvectors! — Method
Stabilize eigenvectors of nearly-degenerate eigenvalue clusters.
When eigen() encounters degenerate or nearly-degenerate eigenvalues, it returns arbitrary eigenvectors within each degenerate subspace. This causes numerical issues downstream (ill-conditioned W⁻¹ in S-matrix boundary matching).
This function groups nearly-degenerate eigenvalues into clusters and, within each cluster, applies orthogonal Procrustes alignment to rotate the eigenvectors so they best align with the identity matrix (the free-space eigenvector basis).
CasualRCWA.compute_bottom_scattering_matrix — Method
function compute_bottom_scattering_matrix(free_space_modes, bottom_modes)Compute the scattering matrix between bottom (transmissive) homogeneous medium and an empty medium. Equivalently, it may be viewed as a general scattering matrix in the special case where the thickness of the RCWA layer is zero.
Arguments
free_space_modes::LayerModes: Modes associated to free space.bottom_modes::LayerModes: Modes associated to the bottom homogeneous medium.
CasualRCWA.compute_global_scattering_matrix — Method
function compute_global_scattering_matrix(
modes, free_space_modes, wavelength, thicknesses
)Compute the global scattering matrix associated to a stack of RCWA layers.
Arguments
modes::AbstractVector{LayerModes}: Modes associated to each layer, including the top and bottom half-spaces as the first and last elements.free_space_modes::LayerModes: Modes associated to free space.wavelength::Real: Wavelength of the incoming light.thicknesses::AbstractVector{<:Real}: Thicknesses of each layer. The first and last elements must beInf.
CasualRCWA.compute_modes_homogeneous — Method
Compute eigenmodes analytically for a homogeneous layer.
In a homogeneous medium, all spatial harmonics decouple, so the eigenvectors are simply the identity matrix. The eigenvalues are determined by the dispersion relation: λn = sqrt(kxn² + ky_n² - εμ).
CasualRCWA.compute_symmetric_scattering_matrix — Method
function compute_symmetric_scattering_matrix(
layer_modes, free_space_modes, wavelength, layer_thickness
)Compute the scattering matrix associated to an RCWA layer wedged between two empty media.
Arguments
layer_modes::LayerModes: Modes associated to the RCWA layer.free_space_modes::LayerModes: Modes associated to free space.wavelength::Real: Wavelength of the incoming light.layer_thickness::Real: Thickness of the RCWA layer.
CasualRCWA.compute_top_scattering_matrix — Method
function compute_top_scattering_matrix(top_modes, free_space_modes)Compute the scattering matrix between top (reflective) homogeneous medium and an empty medium. Equivalently, it may be viewed as a general scattering matrix in the special case where the thickness of the RCWA layer is zero.
Arguments
top_modes::LayerModes: Modes associated to the top homogeneous medium.free_space_modes::LayerModes: Modes associated to free space.
CasualRCWA.convolve — Method
convolve(layer, number_of_harmonics)Apply a convolution to a given layer. Concretely, this amounts to taking the 2D Fourier transform, and subsequently reordering the elements in a Toeplitz block matrix form.
Arguments
layer::Layer: The layer you want to convolve.number_of_harmonics::Tuple{<:Integer, <:Integer}: Number of harmonics in X and Y, respectively.
CasualRCWA.diffraction_efficiencies — Method
diffraction_efficiencies(output; polarization = :x) -> (DE_ref, DE_trn)Power per diffraction order normalized to the incident power, returned as two P x Q real matrices. In the lossless case, sum(DE_ref) + sum(DE_trn) ≈ 1.
The power is computed from the z-component of the Poynting vector, which for a plane wave with transverse fields (Ex, Ey) and wave vector (kx, ky, kz) is:
Sz = Re(1/(kz* μ*)) x [(kz²+kx²)|Ex|² + 2 kx ky Re(Ex Ey*) + (ky²+kz²)|Ey|²]CasualRCWA.prepare_wave_vectors — Method
function prepare_wave_vectors(
source,
top_medium,
bottom_medium,
period,
number_of_harmonics
)Prepare wave vectors in a format convenient for subsequent RCWA simulation steps.
Arguments
source::Source: Incoming wave as described in a vacuum.top_medium::Layer: Homogeneous reflection region.bottom_medium::Layer: Homogeneous transmission region.period::Tuple{<:Real, <:Real}: Periodicity, or equivalently, size of your unit cells.number_of_harmonics::Tuple{<:Integer, <:Integer}: Number of harmonics to be used in your RCWA simulation.
CasualRCWA.reflection_coefficients — Method
reflection_coefficients(output; polarization = :x) -> (r_x, r_y)Complex reflected field amplitudes per diffraction order, returned as two P x Q matrices (one per polarization component).
CasualRCWA.star_product — Method
function star_product(A, B)Redheffer star product, which may be regarded as the 'plumbing' of a coupled pair of scattering matrices.
Arguments
A::AbstractScatteringMatrixB::AbstractScatteringMatrix
CasualRCWA.transmission_coefficients — Method
transmission_coefficients(output; polarization = :x) -> (t_x, t_y)Complex transmitted field amplitudes per diffraction order, returned as two P x Q matrices (one per polarization component).
CasualRCWA.BTTB — Type
struct BTTBSquare block Toeplitz matrix of square Toeplitz blocks.
CasualRCWA.ConvolvedLayer — Type
struct ConvolvedLayerLayer in which the electric permittivity ε and magnetic permeability μ have been prepared for use in RCWA computation. Specifically, ε and μ have been Fourier transformed, and its Fourier coefficient have been rearranged in a convolution matrix format which is convenient for efficiently performing RCWA.
Properties
conv_eps::BTTB: Convolved electric permittivity.conv_mu::BTTB: Convolved magnetic permeability.
CasualRCWA.Layer — Type
struct LayerLayer described in terms of complex electric permittivity and complex magnetic permeability.
Note that we use the negative sign convention where a wave propagating in the +z-direction is written as exp(-ikz). As such, the imaginary part of the complex permittivity is negative.
The input matrices use Cartesian convention: columns correspond to the X direction, rows to Y, with row 1 being the +Y edge. Internally, the matrices are stored with dim1 = X and dim2 = Y.
Properties
eps::Matrix{ComplexF64}: Complex relative electric permittivity per pixel.mu::Matrix{ComplexF64}: Complex relative magnetic permeability per pixel.
CasualRCWA.Layer — Method
function Layer(nk)Describe a layer in terms of its complex refractive index.
This description may only be used for non-magnetic materials.
Note that we use the negative sign convention where a wave propagating in the +z-direction is written as exp(-ikz). As such, the imaginary part of the complex refractive index is negative.
Arguments
nk::AbstractMatrix{<:Number}: Complex refractive index per pixel.
CasualRCWA.PreparedWaveVectors — Type
struct PreparedWaveVectorsWave vectors presented in a shape convenient for subsequent simulation steps.
Properties
waveVectorsX::Diagonal{ComplexF64}: Diagonal matrix of wave vectors in X.waveVectorsY::Diagonal{ComplexF64}: Diagonal matrix of wave vectors in Y.waveVectorsZReflection::Diagonal{ComplexF64}: Diagonal matrix of wave vectors in reflection region.waveVectorsZTransmission::Diagonal{ComplexF64}: Diagonal matrix of wave vectors in transmission region.
CasualRCWA.RCWAInput — Type
struct RCWAInputAll parameters needed to run an RCWA simulation.
Properties
source::Source: Incoming wave specification (angles, wavelength).stack::Stack: Layer stack including top and bottom half-spaces.order::Tuple{Int64, Int64}: Maximum harmonic order (N, M). The simulation includes orders -N..N and -M..M, for a total of (2N+1)(2M+1) harmonics.
CasualRCWA.RCWAOutput — Type
struct RCWAOutputResult of an RCWA simulation. Holds the global scattering matrix together with all metadata needed to extract reflection/transmission coefficients and diffraction efficiencies.
Use reflection_coefficients, transmission_coefficients, and diffraction_efficiencies to query the result.
Properties
input::RCWAInput: Input that was used to produce this output.waveVectors::PreparedWaveVectors: Wave vectors for all diffraction orders.modes::Vector{LayerModes}: Eigenmodes of each layer (including top and bottom half-spaces as the first and last elements).scatteringMatrix::ScatteringMatrix: Global scattering matrix of the stack.
CasualRCWA.ScatteringMatrix — Type
struct ScatteringMatrixScattering matrix (S-matrix) describing the reflection and transmission of a periodic layer wedged in between two homogeneous media.
Properties
S11::Matrix{ComplexF64}: Reflection in the top medium.S12::Matrix{ComplexF64}: Transmission from the bottom to the top medium.S21::Matrix{ComplexF64}: Transmission from the top to the bottom medium.S22::Matrix{ComplexF64}: Reflection in the bottom medium.
CasualRCWA.Source — Type
struct SourceDescribes incoming wave in a vacuum.
Properties
azimuthalAngle::Float64: Also called ϕ. Some people call it θ.elevationAngle::Float64: Also called θ. Some people call it ϕ.wavelength::Float64: Wavelength in whatever units you like so long as you're being consistent.
CasualRCWA.Stack — Type
struct StackA stack of layers with associated thicknesses. The first and last layers are semi-infinite half-spaces (thickness = Inf) and must be homogeneous.
Properties
layers::Vector{<:AbstractLayer}: All layers, including the top and bottom half-spaces as the first and last elements.thicknesses::Vector{Float64}: Thickness of each layer. The first and last elements must beInf.period::Tuple{Float64, Float64}: Unit cell size in (X, Y).
CasualRCWA.SymmetricScatteringMatrix — Type
struct SymmetricScatteringMatrixScattering matrix of an RCWA layer wedged between identical homogeneous media on both sides. By symmetry, the scattering matrix may be expressed as a block matrix S = [R T; T R], where R and T are reflection and transmission matrices, respectively.
Properties
S11::Matrix{ComplexF64}: Reflection in either homogeneous medium.S12::Matrix{ComplexF64}: Transmission from either homogeneous medium into the periodic layer.