photonics

    High-performance Transfer Matrix Method (TMM) library for thin-film, waveguide, and multi-layer photonic structure calculations in MoonBit.

    photonics
    transfer-matrix
    optics
    dispersion
    dbr
    fabry-perot
    thin-film
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    30

    No dependencies

    #MoonBit Photonics

    CI License

    面向薄膜、波导、光子晶体和多层介质结构的 MoonBit 光子学计算库。项目以传输矩阵法(Transfer Matrix Method, TMM)为核心,提供材料色散、器件建模、光谱分析、优化、容差评估与报告导出能力。

    #Features

    • 复数、2×2 与 4×4 矩阵,以及 TE/TM 任意入射角 TMM 求解。
    • 常数、Cauchy、Sellmeier、Drude–Lorentz 和样条插值等色散模型与常用材料目录。
    • DBR、Fabry–Pérot、ARC、Rugate、波导、SPR、光子晶体和定向耦合器等结构模型。
    • 波长/角度/厚度扫描、Monte Carlo 制备容差、场分布与能量守恒诊断。
    • 光谱统计、峰值/带宽/窗口特征、质量门、输入验证和确定性工作流。
    • 有界厚度优化、多目标/Pareto 分析、网格搜索和灵敏度计算。
    • CSV、SVG、Markdown、HTML 和结构化实验产物导出。

    #Package layout

    src/types/ complex numbers, matrices, vectors and units src/dispersion/ dispersive models, material catalogues and interpolation src/layer/ media, layers, stacks and stack builders src/core_tmm/ transfer matrices, fields and numerical diagnostics src/structures/ reusable optical device models src/sweep/ spectral, angular, composition and tolerance sweeps src/analysis/ spectrum statistics, features, windows and uncertainty src/optimization/ bounded search, objectives, sensitivity and Pareto tools src/validation/ physical/input validation and diagnostic reports src/workflow/ reproducible experiments, quality gates and benchmarks src/export/ CSV/SVG/Markdown/HTML and artifact bundles src/main/ executable demonstration and smoke-test workload

    #Quick start

    Install the current stable MoonBit toolchain, then run:

    moon fmt --check moon check --deny-warn --target all moon test --deny-warn --target all moon info moon run src/main

    The executable builds a DBR, Fabry–Pérot cavity and SPR example, performs a 101-point spectrum sweep, evaluates five quality gates, runs bounded thickness optimization and a 100-trial tolerance simulation, and renders report artifacts in memory.

    #Reproducible workflow

    The src/workflow package keeps the numerical workload explicit: wavelength range, sample count, polarization, energy tolerance and response limits are all part of the configuration. run_experiment returns the sweep, summary, quality checks and deterministic checksum inputs. run_benchmark repeats the same workload and reports sample counters and a checksum; wall-clock timing is intentionally measured by the caller.

    Example application flow:

    LayerStack → SpectrumSweepConfig → run_experiment → validate_experiment → optimize_thickness / run_monte_carlo_yield → export_workflow_markdown / export_workflow_csv

    See docs/benchmark.md for the measured workload and timing method.

    #Verification and measurements

    The current local verification measured 8,247 production .mbt lines and 1,985 test .mbt lines across 146 MoonBit source files. The test suite contains 146 test declarations, and the complete target matrix passed for native, WebAssembly, WebAssembly GC and JavaScript.

    On the local Windows development machine, five CLI invocations of moon run src/main measured 155.15–189.68 ms, with a 172.51 ms arithmetic mean. The deterministic workflow benchmark reports 3 repeats × 41 samples and checksum 74450.96259366864; the CLI's maximum energy-balance error was 3.774758283725532e-15.

    These figures are workload measurements, not promises about other machines. Repeat the commands in docs/benchmark.md when comparing toolchains or hardware.

    #Continuous integration

    GitHub Actions installs the official stable MoonBit toolchain on Ubuntu, macOS and Windows. Each matrix job runs formatting, dependency resolution, warning-denying checks, all compilation targets, all tests, package interface generation and a reproducibility diff. An Ubuntu job also runs the executable smoke test.

    #License

    Apache License 2.0. See LICENSE.