RasmahRasmah

Electromagnetic Inverse Design

Overview

Photonic inverse design asks: given a desired field (a guided mode, a focused spot), what dielectric layout produces it? ElectromagneticInverseDesignTopOpt minimizes the L² mismatch ‖E − E_target‖² between the Helmholtz field and a target field, distributing the dielectric ε(ρ) (Molesky et al. 2018; Jensen & Sigmund 2011). The material supplies the refractive index; ω sets the wave number k = ω/c.

using Rasmah

Match a plane wave

Pick a frequency near the first cavity resonance (k ≈ π), set a cosine target field, and let the optimizer shape the dielectric to reproduce it.

m = tetrahedralize_box(1.0, 1.0, 1.0, 3, 3, 3)
n = size(m.nodes, 2)
mat = Material(youngs_modulus = 1e9, poisson_ratio = 0.3, density = 1.0, refractive_index = 2.0)

c = sound_speed(mat)
ω = π * c                                   # k = π, one half-wavelength
k = ω / c
target = [cos(k * m.nodes[1, i]) for i in 1:n]

x, hist = solve(ElectromagneticInverseDesignTopOpt(), m, mat;
                target = target, ω = ω, volfrac = 0.5, max_iter = 20)
([0.001, 1.0, 1.0, 1.0, 1.0, 0.001, 0.001, 0.001, 0.001, 0.001  …  1.0, 1.0, 1.0, 1.0, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001], [65.65051449652155, 62.47823765382355, 58.45365008820855, 54.07066666172078, 49.79606816812365, 46.45464164436771, 44.599427171128326, 43.36618808541692, 42.76765654108035, 42.16108195906513, 41.6354899786129, 41.14327048565375, 40.78277759069987, 40.58124403325681, 40.54350326732027, 40.49904985766822, 40.473064482659424, 40.46739104324544, 40.39903446146093, 40.38958160874048])

Verification — the field mismatch shrinks

The objective ‖E − E_target‖² must fall as the dielectric is shaped:

println("field mismatch: ", round(hist[1]; digits = 2), " → ", round(hist[end]; digits = 2))
println("mismatch decreases: ", hist[end] < hist[1])
println("density in [0,1]:   ", all(0 .<= x .<= 1))
field mismatch: 65.65 → 40.39
mismatch decreases: true
density in [0,1]:   true
vtk(m; field = x, fieldname = "dielectric density", edges = true)

Next steps