# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Material data for fused silica: the index, the Kerr index and the Raman fraction.
Only fused silica (SiO2) is supported, with one model of it: the absorbing
fused-silica fit of [optmat](https://github.com/LupoLab/optmat), solprop's default
silica, which models deep-ultraviolet absorption; and optmat's silica nonlinear
bundle (:data:`SILICA_BUNDLE`), the matched triple of the Kerr fit's total n2, its
Raman fraction f_R and the Hollenbeck and Cantrell Raman shape. The Kerr fit is
validated from 350 nm to 3500 nm; at a deep-UV carrier n2 is the fit's
extrapolation, a decided choice that every scan file records (``n2_extrapolated``).
"""
import math
import warnings
from functools import cache
import numpy as np
from jaxtyping import Complex, Float
from optmat.exceptions import ModelRangeWarning
from optmat.solid.bundle import silica_bundle
from scipy.constants import c, epsilon_0
from solprop.physdata.glasses import GlassIndex, OptmatGlass, fused_silica
from solprop.spatial import SpatialMedium
from pnps.exceptions import MaterialError
from pnps.grids import TimeGrid
__all__ = [
"SILICA_BUNDLE",
"beta0_ref",
"beta1_ref",
"chi3_sio2",
"silica_index",
"silica_k2",
"silica_medium",
"silica_n2",
"silica_raman_fraction",
"silica_raman_shape",
]
#: The optmat silica nonlinear bundle this package takes n2, f_R and h_R from:
#: Hollenbeck and Cantrell's Raman shape with the Kerr fit's own f_R. solprop's
#: :meth:`solprop.physdata.glasses.SilicaBundle.resolve` gives the same bundle.
SILICA_BUNDLE = "default"
@cache
def _optmat_silica(absorption: bool) -> GlassIndex:
"""Return solprop's optmat fused silica, built once per process and setting.
Without absorption the glass is optmat's same model with its index taken as
real (solprop's ``as_transparent``): the real part is unchanged and the
extinction coefficient dropped. Dropping it is the configured model here, not
an approximation to warn about, so the warning bound is infinite.
Parameters
----------
absorption : bool
Keep the material loss (the imaginary part of the index).
Returns
-------
solprop.physdata.glasses.GlassIndex
The silica fit of optmat, as solprop's free-space media take it.
Raises
------
MaterialError
If solprop's default silica is not an optmat glass.
"""
glass = fused_silica()
if absorption:
return glass
if not isinstance(glass, OptmatGlass):
raise MaterialError(
f"solprop's default silica is {type(glass).__name__}, not an optmat glass"
)
return glass.as_transparent(absorption_bound=math.inf)
[docs]
def silica_index(
omega: Float[np.ndarray, "*shape"] | float,
*,
absorption: bool = False,
) -> Complex[np.ndarray, "*shape"]:
"""Return the complex refractive index of fused silica.
Parameters
----------
omega : numpy.ndarray or float
Angular frequency in rad/s, positive, any shape.
absorption : bool, optional
Keep optmat's material loss. Default False, a real index.
Returns
-------
numpy.ndarray
``n + i kappa`` with ``kappa >= 0`` the loss (zero without absorption), the
shape of ``omega``.
"""
omega = np.asarray(omega, dtype=float)
return np.asarray(_optmat_silica(absorption).index(omega), dtype=complex)
[docs]
def silica_k2(
tgrid: TimeGrid, *, absorption: bool = False
) -> Complex[np.ndarray, " n_omega"]:
"""Return the slab's material wavenumber squared on the frequency grid.
``(n(omega) omega / c)^2`` on the band (``tgrid.sidx``) and zero off it, where
the index is never evaluated: a placeholder in-band frequency (the carrier) keeps
the fit inside the range it is defined on.
Parameters
----------
tgrid : TimeGrid
The temporal grid.
absorption : bool, optional
Keep optmat's material loss.
Returns
-------
numpy.ndarray
The complex square, ``(nt,)``, rad^2/m^2.
"""
omega = tgrid.omega
omega_band = np.where(tgrid.sidx, omega, tgrid.omega0)
n = silica_index(omega_band, absorption=absorption)
return np.where(tgrid.sidx, (n * omega / c) ** 2, 0.0).astype(complex)
[docs]
def silica_n2(lam0: float) -> tuple[float, bool]:
"""Return optmat's total Kerr index of fused silica at a wavelength.
The n2 of the silica nonlinear bundle (:data:`SILICA_BUNDLE`): the Kerr fit's
total long-pulse value, of which a Raman run gives ``(1 - f_R)`` to the
instantaneous response. The fit is validated from 350 nm to 3500 nm; a deep-UV
carrier evaluates it by its fitted dispersion below that, a decided extrapolation
(``docs/dev/decisions.md``) that this function reports instead of warning about.
Parameters
----------
lam0 : float
Vacuum wavelength in m.
Returns
-------
n2 : float
The total Kerr index in m^2/W.
extrapolated : bool
True when ``lam0`` is outside the fit's validated range.
"""
bundle = silica_bundle(SILICA_BUNDLE)
low, high = bundle.kerr.wavelength_range
with warnings.catch_warnings():
# Reported through the return value instead: the extrapolation is decided.
warnings.simplefilter("ignore", ModelRangeWarning)
n2 = float(bundle.n2(lam0))
extrapolated = not low <= lam0 <= high
return n2, extrapolated
[docs]
def silica_raman_fraction() -> float:
"""Return the Raman fraction ``f_R`` of the silica nonlinear bundle.
Returns
-------
float
The share of the total Kerr index carried by the delayed response, in
``(0, 1)``: 0.2188 for the Hollenbeck and Cantrell shape paired with the
Kerr fit.
"""
return float(silica_bundle(SILICA_BUNDLE).raman_fraction)
[docs]
def silica_raman_shape(
lags: Float[np.ndarray, " n_t"],
) -> Float[np.ndarray, " n_t"]:
"""Sample the Raman shape of the silica nonlinear bundle at non-negative lags.
The copolarised shape ``h_R`` of :data:`SILICA_BUNDLE` (Hollenbeck and
Cantrell's), of unit integral, sampled directly as solprop samples it. It opens
with a sine, so the trapezoid rule's half-weight at zero lag is exactly zero.
Parameters
----------
lags : numpy.ndarray
Non-negative delays in s.
Returns
-------
numpy.ndarray
``h_R`` at the lags, in 1/s.
"""
return np.asarray(silica_bundle(SILICA_BUNDLE).h_r(lags), dtype=float)
[docs]
def chi3_sio2(lam0: float) -> float:
"""Return the third-order susceptibility of fused silica at a carrier.
``chi3 = (4/3) n2 epsilon_0 c n0^2``, with n2 :func:`silica_n2` at the carrier
and n0 the real part of the index there.
Parameters
----------
lam0 : float
Carrier wavelength in m.
Returns
-------
float
The susceptibility chi3, in m^2/V^2.
"""
n2, _ = silica_n2(lam0)
n0 = float(np.real(silica_index(2 * np.pi * c / lam0)))
return 4 / 3 * n2 * epsilon_0 * c * n0**2
[docs]
def beta0_ref(lam0: float) -> float:
"""Carrier propagation constant ``Re n(omega0) * omega0 / c`` in rad/m.
Subtracted from the linear operator so the envelope phase is slowly
varying (the carrier phase is factored out).
Parameters
----------
lam0 : float
Carrier wavelength in m.
Returns
-------
float
The propagation constant at the carrier, in rad/m.
"""
omega0 = 2 * np.pi * c / lam0
return float(np.real(silica_index(omega0))) * omega0 / c
[docs]
def beta1_ref(lam0: float) -> float:
"""Group slowness ``d(beta)/d(omega)`` at the carrier, in s/m.
Defines the co-moving frame: the linear operator subtracts
``beta1 * omega`` so the pulse stays centred in the time window.
Evaluated by a symmetric finite difference of ``beta(omega) = Re n(omega)
omega / c``; with a relative step of 1e-6 the truncation and rounding
errors are both ~1e-12 relative, far below anything the propagation
resolves.
Parameters
----------
lam0 : float
Carrier wavelength in m.
Returns
-------
float
The group slowness ``beta1`` at the carrier, in s/m.
"""
omega0 = 2 * np.pi * c / lam0
d_omega = 1e-6 * omega0
sides = np.array([omega0 + d_omega, omega0 - d_omega])
beta = np.real(silica_index(sides)) * sides / c
return float((beta[0] - beta[1]) / (2 * d_omega))
[docs]
def silica_medium(*, absorption: bool = False) -> SpatialMedium:
"""Return solprop's fused-silica slab, optmat's fit.
Parameters
----------
absorption : bool, optional
Keep optmat's material loss. Default False, a real index.
Returns
-------
solprop.spatial.SpatialMedium
The homogeneous fused-silica medium.
"""
return SpatialMedium(_optmat_silica(absorption))