# The Clear BSD License
#
# Copyright (c) 2026 Tobias Heibges
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
# THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""
Factory Functions for Creating Materials
Provides convenience functions for creating materials with dispersion models.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from .dispersion import sellmeier_refractive_index, cauchy_refractive_index
if TYPE_CHECKING:
from ..base import HomogeneousMaterial
[docs]
def create_sellmeier_material(
name: str,
B1: float,
B2: float,
B3: float,
C1: float,
C2: float,
C3: float,
absorption_coef: float = 0.0,
) -> HomogeneousMaterial:
"""
Create a material with Sellmeier dispersion.
Parameters
----------
name : str
Material name.
B1, B2, B3 : float
Sellmeier B coefficients (dimensionless).
C1, C2, C3 : float
Sellmeier C coefficients in μm².
absorption_coef : float, optional
Absorption coefficient in m⁻¹. Default is 0.
Returns
-------
material : HomogeneousMaterial
Material with wavelength-dependent refractive index.
Examples
--------
>>> # Create N-BK7 glass with Sellmeier dispersion
>>> bk7 = create_sellmeier_material(
... "N-BK7",
... B1=1.03961212, B2=0.231792344, B3=1.01046945,
... C1=6.00069867e-3, C2=2.00179144e-2, C3=1.03560653e2,
... )
"""
from ..base import HomogeneousMaterial
def n_func(wavelength: float) -> float:
return sellmeier_refractive_index(wavelength, B1, B2, B3, C1, C2, C3)
return HomogeneousMaterial(
name=name,
refractive_index=n_func,
absorption_coef=absorption_coef,
)
[docs]
def create_cauchy_material(
name: str,
A: float,
B: float,
C: float = 0.0,
absorption_coef: float = 0.0,
) -> HomogeneousMaterial:
"""
Create a material with Cauchy dispersion.
Parameters
----------
name : str
Material name.
A : float
Constant term.
B : float
First-order dispersion coefficient in μm².
C : float, optional
Second-order dispersion coefficient in μm⁴. Default is 0.
absorption_coef : float, optional
Absorption coefficient in m⁻¹. Default is 0.
Returns
-------
material : HomogeneousMaterial
Material with wavelength-dependent refractive index.
Examples
--------
>>> # Create simple glass with Cauchy dispersion
>>> glass = create_cauchy_material("Glass", A=1.52, B=0.004)
"""
from ..base import HomogeneousMaterial
def n_func(wavelength: float) -> float:
return cauchy_refractive_index(wavelength, A, B, C)
return HomogeneousMaterial(
name=name,
refractive_index=n_func,
absorption_coef=absorption_coef,
)