Isotropic Solver
The standard 2×2 transfer matrix method for isotropic multi-layer films. This
is the fastest solver in DiffTMM (~190× faster than NumPy TMM) and the right
default whenever every layer is isotropic. It computes the complex Fresnel
coefficients (ts, tp, rs, rp) with full phase, and supports bidirectional
propagation — angles in [0, π/2] are forward (top → bottom), angles in
[π/2, π] are reverse (bottom → top).
difftmm.IsotropicFilmSolver
IsotropicFilmSolver(mat_in, mat_out, mat_ls, thickness_ls=None, thickness_min=0.0, thickness_max=0.2, batch_size=1, sigmoid_param=False, device=torch.device('cuda'))
Multi-layer coating film solver for isotropic materials.
Uses the standard 2x2 transfer matrix method which is much faster than the general 4x4 anisotropic formulation. This solver calculates (ts, tp, rs, rp) with phase shifts using rigorous electromagnetic wave propagation through multi-layer coating stacks.
Initialize the isotropic film solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat_in
|
Refractive index of incident medium. float, complex, or str material name. |
required | |
mat_out
|
Refractive index of exit medium. Same types as mat_in. |
required | |
mat_ls
|
Refractive indices of interior layers. List of float/complex scalars or str material names. |
required | |
thickness_ls
|
Thicknesses of interior layers in um, list or tensor of length N. If None, randomly initializes thicknesses. |
None
|
|
thickness_min
|
Minimum layer thickness in um. |
0.0
|
|
thickness_max
|
Maximum layer thickness in um. |
0.2
|
|
batch_size
|
Number of film stacks in the batch dimension. |
1
|
|
sigmoid_param
|
If True, use sigmoid parameterization for thickness. |
False
|
|
device
|
PyTorch device. |
device('cuda')
|
Source code in difftmm-src/difftmm/film_solver_isotropic.py
to
Move tensors to specified device.
Source code in difftmm-src/difftmm/film_solver_isotropic.py
load_ckpt
Load thicknesses (and spec metadata) from a checkpoint.
Source code in difftmm-src/difftmm/film_solver_isotropic.py
save_ckpt
Save thicknesses and material specs to a checkpoint.
Material objects are persisted by name; scalars are persisted by value. Per-axis 3-tuples are persisted element-wise.
Source code in difftmm-src/difftmm/film_solver_isotropic.py
get_film_thickness
Convert optimization-friendly film parameters to real film thickness.
Returns:
| Name | Type | Description |
|---|---|---|
film_thickness |
tensor of shape (batch_size, num_layers), in [um]. |
Source code in difftmm-src/difftmm/film_solver_isotropic.py
simulate
Calculate (ts, tp, rs, rp) using TMM for specified angles and wavelengths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
Incident angles in radians. Can be: - 1D tensor of shape (n_angles,): same angles for all mirrors - 2D tensor of shape (batch_size, n_angles): different angles per film stack |
required | |
wvln
|
Wavelengths in micrometers. Can be: - List or 1D tensor of shape (n_wvlns,) - Scalar or 0D tensor: single wavelength |
required |
Returns:
| Type | Description |
|---|---|
|
ts, tp, rs, rp: Complex transmission/reflection coefficients. Shape: (batch_size, n_wvlns, n_angles) |
Source code in difftmm-src/difftmm/film_solver_isotropic.py
Functional API
The solver is a thin wrapper around a pure function. Use create_jones_matrix_isotropic
directly when you want to differentiate through the film stack without holding
solver state — for example, when the thicknesses are an external
torch.nn.Parameter in an inverse-design loop.
difftmm.create_jones_matrix_isotropic
Fast Jones matrix calculation for isotropic multi-layer films.
Uses the standard 2x2 transfer matrix method which is much faster than the general 4x4 anisotropic formulation when materials are isotropic. Avoids eigenvalue decomposition entirely.
Supports bidirectional propagation: - theta in [0, pi/2]: Forward direction (top to bottom, n_in -> layers -> n_out) - theta in [pi/2, pi]: Reverse direction (bottom to top, n_out -> layers -> n_in) Internally converts to equivalent forward problem with swapped media and reversed layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_layers_1d
|
refractive index of each layer. Shape (batchsize, n_layer) — wavelength-independent, OR shape (batchsize, n_wls, n_layer) — dispersive per wavelength. Complex. |
required | |
d_1d
|
thicknesses of all layers, shape (batchsize, n_layer). Real or Complex. |
required | |
wv_1d
|
wavelengths of simulations, shape (batchsize, n_wls). Real. |
required | |
n_in
|
incident media refractive index (top medium). Scalar (Python float/complex), OR tensor of shape (batchsize, n_wls) for per-wavelength dispersive incident medium. |
required | |
n_out
|
transmit media refractive index (bottom medium). Scalar (Python float/complex), OR tensor of shape (batchsize, n_wls) for per-wavelength dispersive exit medium. |
required | |
theta_1d
|
incident angles, shape (batchsize, n_angles). Real. Range [0, pi]. Angles > pi/2 represent reverse propagation. |
required |
Returns:
| Type | Description |
|---|---|
|
ts, tp, rs, rp: complex transmission/reflection coefficients each with shape (batchsize, n_wls, n_angles) |
Source code in difftmm-src/difftmm/film_solver_isotropic.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |