Anisotropic Solver
The general 4×4 transfer matrix method, which handles both isotropic and
anisotropic (birefringent) media. Use it when one or more layers have
direction-dependent refractive index; each such layer is given as a
(mat_x, mat_y, mat_z) tuple of per-axis indices. It is more general (and
heavier) than the isotropic 2×2 solver — for fully isotropic
stacks, prefer the isotropic solver for speed and lower memory.
AnisotropicFilmSolver is an alias
difftmm.AnisotropicFilmSolver is an alias for FilmSolver; both names refer
to the same class. The two share the constructor and simulate(theta, wvln)
signature of the isotropic solver, returning complex (ts, tp, rs, rp).
difftmm.FilmSolver
FilmSolver(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 physical film solver using transfer matrix method.
This solver calculates (ts, tp, rs, rp) with phase shifts using rigorous electromagnetic wave propagation through multi-layer coating stacks.
Initialize the anisotropic 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. Each element is either a float/complex scalar or str material name (isotropic layer), or a 3-tuple of those types for (nx, ny, nz) birefringent layers. |
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_anisotropic.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
to
Move tensors to specified device.
Source code in difftmm-src/difftmm/film_solver_anisotropic.py
load_ckpt
Load thicknesses (and spec metadata) from a checkpoint.
Source code in difftmm-src/difftmm/film_solver_anisotropic.py
save_ckpt
Save thicknesses and material specs to a checkpoint.
Source code in difftmm-src/difftmm/film_solver_anisotropic.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_anisotropic.py
simulate
Calculate (ts, tp, rs, rp) using 4x4 TMM for specified angles and wavelengths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
Incident angles in radians. Can be: - 1D tensor of shape (n_angles,) - 2D tensor of shape (batch_size, n_angles) |
required | |
wvln
|
Wavelengths in micrometers. Can be: - List or 1D tensor of shape (n_wvlns,) - Scalar or 0D tensor |
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_anisotropic.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
Functional API
Lower-level entry point used by FilmSolver.simulate(). It builds the 4×4 Jones
matrix for an anisotropic stack expressed in the angle-of-incidence / azimuth
(AOIAz) frame.
difftmm.create_jones_matrix_AOIAz
Calculate the Jones matrix for reflected and transmitted light.
Optimized: Vectorized AOI/Az setup, batched eigenvalue decomposition, and using torch.linalg.solve instead of torch.inverse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a_2d
|
azimuth angle of materials in each layer, shape (batchsize, n_layer, 3). Complex. |
required | |
n_2d
|
refractive index of each layer. Accepts: - 3-D shape (batchsize, n_layer, 3): non-dispersive, broadcast across wvlns. - 4-D shape (batchsize, num_wv, n_layer, 3): dispersive per wavelength. Complex. |
required | |
d_1d
|
thicknesses of all layers, shape (batchsize, n_layer). Complex. |
required | |
wv_1d
|
wavelengths of simulations, shape (batchsize, n_wls). Real |
required | |
n_in
|
incident media refractive index. Accepts Python scalar or tensor of shape (batchsize, num_wv) for per-wavelength values. |
required | |
n_out
|
transmit media refractive index. Same accepted shapes as n_in. |
required | |
theta_x_1d
|
incident Zenith angle, shape (batchsize, n_aoi_angles). Real |
required | |
theta_y_1d
|
azimuth angle of incident light, shape (batchsize, n_az_angles). Real. |
required |
Returns:
| Type | Description |
|---|---|
|
Jones_trn, Jones_ref: Jones matrices, each with shape (batchsize, n_wls, n_aoi_angles, n_az_angles, 2, 2). Complex |
Source code in difftmm-src/difftmm/film_solver_anisotropic.py
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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |