Skip to main content

Nonlinear transfer matrix method

Project description

PyPI version Python License: MIT Pytest Pre-commit Build and upload to PyPI

NonlinearTMM: Nonlinear Transfer-Matrix Method

A Python library for optical simulations of multilayer structures using the transfer-matrix method, extended to support nonlinear processes (SHG, SFG, DFG) and Gaussian beam propagation.

Gaussian beam exciting surface plasmon polaritons

See also: GeneralTmm — a 4×4 TMM for anisotropic (birefringent) multilayer structures.

Table of Contents

Features

  • Standard TMM — reflection, transmission, absorption for p- and s-polarized plane waves at arbitrary angles
  • Parameter sweeps — over wavelength, angle of incidence, layer thickness, or any other parameter
  • 1D and 2D electromagnetic field profiles — E and H field distributions through the structure
  • Field enhancement — calculation of field enhancement factors (e.g. for SPP excitation)
  • Gaussian beam propagation — any beam profile through layered structures, not just plane waves
  • Second-order nonlinear processes — SHG, SFG, DFG in multilayer structures
  • Wavelength-dependent materials — interpolated from measured optical data (YAML format)
  • High performance — C++ core (Eigen) with Cython bindings, OpenMP parallelization
  • Cross-platform wheels — Linux (x86_64), Windows (x64, ARM64), macOS (ARM64); Python 3.10–3.14

Installation

pip install NonlinearTMM

Pre-built wheels are available for most platforms. A C++ compiler is only needed when installing from source.

API Overview

The library exposes three main classes: Material, TMM, and SecondOrderNLTMM.

Class / method Purpose
Material(wls, ns) Wavelength-dependent material from arrays of λ and complex n
Material.Static(n) Constant refractive index (shortcut)
TMM(wl=…, pol=…, I0=…) Create a solver; wl = wavelength (m), pol = "p" or "s"
tmm.AddLayer(d, mat) Append layer (d in m, inf for semi-infinite)
tmm.Sweep(param, values) Solve for an array of values of any parameter
tmm.GetFields(zs) E, H field profiles along the layer normal
tmm.GetFields2D(zs, xs) E, H on a 2-D grid
tmm.GetEnhancement(layerNr) Field enhancement in a given layer
tmm.wave Access _Wave parameters for Gaussian beam calculations
tmm.WaveSweep(param, values) Parameter sweep for beam calculations
tmm.WaveGetFields2D(zs, xs) 2-D field map for beam excitation
SecondOrderNLTMM(…) Second-order nonlinear TMM (SHG, SFG, DFG)

For the full API, see the reference documentation.

Examples

Surface Plasmon Polaritons — ExampleTMM.py

Kretschmann configuration (prism | 50 nm Ag | air) at 532 nm. Demonstrates reflection sweeps, field enhancement, and 1D/2D field visualization of surface plasmon polaritons.

import math
import numpy as np
from NonlinearTMM import TMM, Material

# Materials
prism = Material.Static(1.5)
ag = Material.Static(0.054007 + 3.4290j)  # Silver @ 532nm
air = Material.Static(1.0)

# Set up TMM (Kretschmann configuration)
tmm = TMM(wl=532e-9, pol="p", I0=1.0)
tmm.AddLayer(math.inf, prism)
tmm.AddLayer(50e-9, ag)
tmm.AddLayer(math.inf, air)

# Sweep angle of incidence
betas = np.sin(np.radians(np.linspace(0, 80, 500))) * 1.5
result = tmm.Sweep("beta", betas, outEnh=True, layerNr=2)

SPP reflection, enhancement, and field profiles

Gaussian Beam Excitation — ExampleTMMForWaves.py

The same Kretschmann structure excited by a 10 mW Gaussian beam (waist 10 μm). Shows how finite beam width affects resonance depth and field enhancement.

Gaussian beam SPP excitation

Second-Harmonic Generation — ExampleSecondOrderNonlinearTmm.py

Second-harmonic generation (SHG) in a 1 mm nonlinear crystal with χ⁽²⁾ nonlinearity. Two s-polarized pump beams at 1000 nm generate a second-harmonic signal at 500 nm. The SecondOrderNLTMM class also supports sum-frequency generation (SFG) and difference-frequency generation (DFG).

SHG reflected and transmitted intensity vs beta

References

Loot, A., & Hizhnyakov, V. (2017). Extension of standard transfer-matrix method for three-wave mixing for plasmonic structures. Applied Physics A, 123(3), 152. doi:10.1007/s00339-016-0733-0

Loot, A., & Hizhnyakov, V. (2018). Modeling of enhanced spontaneous parametric down-conversion in plasmonic and dielectric structures with realistic waves. Journal of Optics, 20, 055502. doi:10.1088/2040-8986/aab6c0

Documentation

Full documentation is available at https://ardiloot.github.io/NonlinearTMM/.

Development

Setup

git clone --recurse-submodules https://github.com/ardiloot/NonlinearTMM.git
cd NonlinearTMM

# Install uv if not already installed:
# https://docs.astral.sh/uv/getting-started/installation/

# Create venv, build the C++ extension, and install all dependencies
uv sync

Running tests

uv run pytest -v

Code formatting and linting

Pre-commit hooks are configured to enforce formatting (ruff, clang-format) and catch common issues. To install the git hook locally:

uv run pre-commit install

To run all checks manually:

uv run pre-commit run --all-files

CI overview

Workflow Trigger What it does
Pytest Push to master / PRs Tests on {ubuntu, windows, macos} × Python {3.10–3.14}
Pre-commit Push to master / PRs Runs ruff, clang-format, ty, and other checks
Publish to PyPI Release published Builds wheels + sdist via cibuildwheel, uploads to PyPI
Publish docs Release published Builds Sphinx docs and deploys to GitHub Pages

Releasing

Versioning is handled automatically by setuptools-scm from git tags.

  1. Ensure CI is green on the master branch.
  2. Create a new release on GitHub:
    • Go to ReleasesDraft a new release
    • Create a new tag following PEP 440 (e.g. v1.2.0)
    • Target the master branch (or a specific commit on master)
    • Click Generate release notes for an auto-generated changelog
    • For pre-releases (e.g. v1.2.0rc1), check Set as a pre-release — these upload to TestPyPI instead of PyPI
  3. Publish the release — the workflow builds wheels for Linux (x86_64), Windows (x64, ARM64), and macOS (ARM64), and uploads to PyPI.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonlineartmm-1.4.1.tar.gz (2.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nonlineartmm-1.4.1-cp314-cp314-win_arm64.whl (404.6 kB view details)

Uploaded CPython 3.14Windows ARM64

nonlineartmm-1.4.1-cp314-cp314-win_amd64.whl (437.3 kB view details)

Uploaded CPython 3.14Windows x86-64

nonlineartmm-1.4.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

nonlineartmm-1.4.1-cp314-cp314-macosx_11_0_arm64.whl (459.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

nonlineartmm-1.4.1-cp313-cp313-win_arm64.whl (395.2 kB view details)

Uploaded CPython 3.13Windows ARM64

nonlineartmm-1.4.1-cp313-cp313-win_amd64.whl (427.3 kB view details)

Uploaded CPython 3.13Windows x86-64

nonlineartmm-1.4.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

nonlineartmm-1.4.1-cp313-cp313-macosx_11_0_arm64.whl (452.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nonlineartmm-1.4.1-cp312-cp312-win_arm64.whl (395.3 kB view details)

Uploaded CPython 3.12Windows ARM64

nonlineartmm-1.4.1-cp312-cp312-win_amd64.whl (427.6 kB view details)

Uploaded CPython 3.12Windows x86-64

nonlineartmm-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

nonlineartmm-1.4.1-cp312-cp312-macosx_11_0_arm64.whl (453.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nonlineartmm-1.4.1-cp311-cp311-win_amd64.whl (431.0 kB view details)

Uploaded CPython 3.11Windows x86-64

nonlineartmm-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

nonlineartmm-1.4.1-cp311-cp311-macosx_11_0_arm64.whl (451.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

nonlineartmm-1.4.1-cp310-cp310-win_amd64.whl (431.0 kB view details)

Uploaded CPython 3.10Windows x86-64

nonlineartmm-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

nonlineartmm-1.4.1-cp310-cp310-macosx_11_0_arm64.whl (451.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file nonlineartmm-1.4.1.tar.gz.

File metadata

  • Download URL: nonlineartmm-1.4.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nonlineartmm-1.4.1.tar.gz
Algorithm Hash digest
SHA256 70f2e5a58a1f4fa25bdcc6e68fd6204fae926d3e521250ce05b14bf2decede1a
MD5 f3bc3033f9c5f39e8c8eb801eb46bda3
BLAKE2b-256 938c3052c61e9a8f12d7b85cb4d052813ce2404e0614da25eafdbab57847c39d

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp314-cp314-win_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp314-cp314-win_arm64.whl
Algorithm Hash digest
SHA256 d2a490d9fa3abdc66b554092a43ae65c6ed14ba993d268d1cc633a361b9f10cd
MD5 135230626c0b8dbd7a6ebca023fa8fc2
BLAKE2b-256 26b99ae782b36219242d73d2912b15f2c87fed6c76e542ea9bc73c64deec15b1

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 cc190148484591f47f859d03a3a3de312052bb1bc6ea796c98174038b56b5886
MD5 13bee6696114f5b467ccfb7c26efa2ed
BLAKE2b-256 6c757024b88c96bd13c71aacae8aecf22ee9bfb4ef6ce25446d489003a946df7

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee929344de92087b425ca48cd7fba00e64d0a873eab263557e3ae548364c8228
MD5 389705aacdfa68e61436a9e42b53bc14
BLAKE2b-256 1d626dc6cb9a55788cf1adb8fe54c17ee1a50efa62a161086524d8481885238a

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7185957369e2c3ad0a8019f1afe230446cc73f1f6854491a39656c3abd235678
MD5 07fbc77ddf4bf11fba468dae276a7886
BLAKE2b-256 1ffbd39d768a0344a50569198c8a078a61e8271b7938c0d44592dc15667aaf2d

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp313-cp313-win_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 8ba794618152bdef6fb340f333ac42846d00087c8acd4feac304f8bd8ecfb5d1
MD5 398a166962a71b7fed559f82f0243320
BLAKE2b-256 6684342b0692faf7a973bcaa74b32be795908af475d894557d602a722f3fd0bc

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fc9078e2ac9466f8b8a239b89bf9dd80e9af5de7753e307b853c39a6d00cf4bc
MD5 41368fac1a9e78e6c2232d82510c514c
BLAKE2b-256 7517953efe81be1cad3f1c5fad022523ed11301c4163be3d56eb12166bd1ef08

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 07a56e464b1cc151891306e495040b44cd5443589607346527462c2ce21e8a20
MD5 d5d034199200257416dc379c27bfd52e
BLAKE2b-256 76b02ec976373d97a0f6bb5af468ea4328a3997bbecc8c31e6711a3acf97aa7b

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 854be15c7e1c2ce5778282823dafc8db4867d33686fec4de8fc3e42caccfa69f
MD5 787557a548c5419cfd1b379ae35a3cbe
BLAKE2b-256 ec2f8245b7955f2b549e322413a6a11e33d77b4c52f684a5ed2469d78a82160d

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp312-cp312-win_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp312-cp312-win_arm64.whl
Algorithm Hash digest
SHA256 a6fdd21e15c342b688df7a0d22b90fd59cc9d165b16fb36642e476d18c9b1eca
MD5 f638a49476e000d44d0fc1f5774fbe75
BLAKE2b-256 a177128e8b12184dc7ca197032287a763d5b735b7772d912cee2bafe60506972

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5e974938aa785b23ae957b2d90fc9465b31b0ca582b3486221dacd8b0f34ec70
MD5 3610e6c7b555ad3e5a17654aac9b5c7f
BLAKE2b-256 0e4caa6968229ca60998b728c21fac4de05b521d565c617e84e1ede4d5aa0b55

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fbb739debefaf653af00cf7bf2125ff707f9903726d140343493996eb2b49128
MD5 7e86680fd59857b98a724f761c997713
BLAKE2b-256 16c416df446a60cefb58d7f4f53492b36fb73f34dc1fa7bc01ed4dbf12a45215

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b2843ef34e5bd162ba84d9a0cc891b63efae3d9f4cf6e5fca191f7609b90cba
MD5 a241c4705ba711cb577d6583d6d5f2cd
BLAKE2b-256 9795bf5bb15622f2bf8e2f656fa36483aa21bec1c8ba20b9a51f5d94d4c8ed91

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 26a85585ba538ea54d063038597020953c8429a00c0def5b4a9d4be8697e80d8
MD5 c77388ec3d5f34bbfe2b632ab4dbcddc
BLAKE2b-256 9744f77320378945b14c08e5eb8aa3d4f16426d2af95d5cff3c454002ff82374

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d7b3d92e0e689ec69d191c40e91446697325a088f4f88eab7d723da87e4499b3
MD5 06245877946c1ed402b75a41b3b45f65
BLAKE2b-256 669719ed514b0a306d34897f52c102b3f9d862b575e6a399115ec3d4c62697ca

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8492cf6b0f5f8d873e3d114f5044bd92936ff6534298ff888f52a2eea0f7eac3
MD5 1fa39d5c4e999e4d3368fc1615dacabb
BLAKE2b-256 deacceac80e203f01071dcf6f11d6fe3ea98357f804a7fe9fab77fc7885e86cb

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d046c3a511ebd470e95891d7cd187ffcb27a51e11282a8298eefbb935e3822b2
MD5 fcfdbcda7181021b2cb10921ececa02e
BLAKE2b-256 7f9fd27d9aa1096decdfbb01ae9a972f5e8982730b0357f59e8d3748a64fb98b

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 514a40754ef9004f6a92cff140646fe3f54e03bd9e11e6521278478e4295ab97
MD5 2c77434c6ef0b0891e7c3ec61f91830d
BLAKE2b-256 6dc3e3706f03663b5c5491c431ed728255f8acf1654eaff2092f2551d1d4b2ba

See more details on using hashes here.

File details

Details for the file nonlineartmm-1.4.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonlineartmm-1.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10f793e019b56603dd2a7696dd13e3ee0afc9686f0ed7b70efb2f33d0ef97839
MD5 384ae2471ac530a1cafc4eb0b1ef861b
BLAKE2b-256 0400ac2e27cdff550cfb77cb4fe96ecf7f29a76dbeeb7191209cf91591cb9509

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page