Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
87814e0
Model Type I SHG in a uniaxial crystal
chrisbrahms Nov 12, 2026
40899d4
Test the crystal forward models against the exact pair sum
chrisbrahms Nov 12, 2026
1ebf2b2
Estimate the signal tilt over the pulse's band, and warn from check_tilt
chrisbrahms Nov 12, 2026
5890ef0
Document SHG in a Type I crystal
chrisbrahms Nov 12, 2026
f4480de
Test the two-beam geometry's validation
chrisbrahms Nov 12, 2026
015e864
Address review of the crystal core
chrisbrahms Nov 12, 2026
97bfcf4
Cover the tilt check's absorbed signal bins
chrisbrahms Nov 12, 2026
f3a4c44
Model the signal's tilt in the principal plane as the arms' delay drift
chrisbrahms Nov 12, 2026
e27d04b
Address the crystal core's re-review
chrisbrahms Nov 12, 2026
17e9693
Restore the 5 fs figure and state the arms' delays in the manual
chrisbrahms Nov 12, 2026
edd43c9
Explain the arms' delay drift as the SH's walk-off
chrisbrahms Nov 12, 2026
b919f55
Name the crystal module's validity section uniquely
chrisbrahms Nov 13, 2026
e766187
Reference the arms' delay drift to mid-depth
chrisbrahms Nov 13, 2026
0ddef60
State the full-field check at three crossing depths
chrisbrahms Nov 13, 2026
a9b7b5f
Check the arm-drift rate with no absolute tolerance
chrisbrahms Nov 13, 2026
6800603
Keep the signal-grid edge pairs independent of rounding
chrisbrahms Nov 13, 2026
da1da60
Validate crystal inputs and count the arms' drift in the depth rule
chrisbrahms Nov 17, 2026
cb0c332
Return the gate propagator from the JAX model's props
chrisbrahms Nov 17, 2026
59880ad
Build the pair-sum test reference from the index functions
chrisbrahms Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/shg-crystal.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SHG in a Type I crystal: `croak.crystals.CrystalSetup` (cut angle with an external tilt or the wavelength the crystal was tuned to, the crossing geometry from `croak.geometry.TwoBeamGeometry`, and the fundamental's polarisation relative to the crossing plane), passed as `material` to the forward models for SHG, propagates the signal near 2ω0 as the extraordinary wave and so models phase matching, group-velocity mismatch and the ω/n generation prefactor. `croak.crystals.depth_points` gives the depth nodes the phase mismatch needs. With the beams crossing in the crystal's principal plane the signal's tilt makes the trace asymmetric in delay; the model includes it, to first order, as opposite delay drifts of the two arms, referenced to mid-depth so that the trace keeps its delay origin (`delayed_beam` sets its sign, which flipping mirrors the trace in delay), and `check_tilt` warns where the remainder matters (#24).
1,175 changes: 1,175 additions & 0 deletions croak/crystals.py

Large diffs are not rendered by default.

74 changes: 47 additions & 27 deletions croak/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from numpy.polynomial.legendre import leggauss
from numpy.typing import ArrayLike, NDArray

from . import materials
from . import crystals
from .crystals import CrystalSetup
from .interactions import Interaction, get_interaction
from .smearing import SmearingKernel, delay_frequency_grid

Expand Down Expand Up @@ -88,7 +89,7 @@ def quadrature_nodes_weights(


class ForwardModel:
"""Nonlinear-process forward map and adjoint for fixed grid/delays/interaction.
r"""Nonlinear-process forward map and adjoint for fixed grid/delays/interaction.

Parameters
----------
Expand All @@ -98,13 +99,19 @@ class ForwardModel:
Delay axis (s).
interaction : str or Interaction
Nonlinear interaction (``"shg"``, ``"sd"``, ``"pg"``).
material : str or None, optional
Dispersive material for the slab (e.g. ``"SiO2"``); ``None`` (default)
is a thin, dispersionless medium.
material : str, CrystalSetup or None, optional
The medium: a material name for a PG/SD slab (e.g. ``"SiO2"``), whose
fundamental and signal share one propagation constant; a
:class:`~croak.crystals.CrystalSetup` for SHG in a Type I crystal, whose
signal propagates as the extraordinary wave near :math:`2\omega_0`
(see :mod:`croak.crystals`); or ``None`` (default), a thin,
dispersionless medium.
thickness : float, optional
Slab thickness (m). Default ``0``.
Slab thickness (m), along the face normal for a tilted crystal. Default
``0``.
npoints : int, optional
Number of depth quadrature points (default ``1``).
Number of depth quadrature points (default ``1``). A crystal needs at
least :func:`croak.crystals.depth_points`.
omega0 : float, optional
Carrier angular frequency (rad/s), used to build ``beta``.
quadrature : str, optional
Expand All @@ -130,7 +137,7 @@ def __init__(
delays: ArrayLike,
interaction: str | Interaction,
*,
material: str | None = None,
material: str | CrystalSetup | None = None,
thickness: float = 0.0,
npoints: int = 1,
omega0: float = 0.0,
Expand All @@ -147,30 +154,43 @@ def __init__(
self.thickness = float(thickness)
self.omega0 = float(omega0)

# The slab propagation phase β(ω) is built at the *fundamental* carrier,
# but the SHG signal lives near 2ω0 — propagating it with β(ω) is
# physically inconsistent. Dispersive propagation is only meaningful for
# interactions whose signal stays at the fundamental (PG, SD).
if material is not None and thickness and self.interaction.omega0_scale != 1.0:
raise ValueError(
f"dispersive propagation is not supported for the "
f"{self.interaction.name.upper()} interaction (its signal is not at "
f"the fundamental frequency); use a thin medium (material=None)"
)
# An SHG signal lives near 2ω0, so it needs its own propagation constant:
# only a crystal supplies one (croak.crystals). PG/SD share the material's.
crystals.check_medium(
self.interaction,
material,
self.thickness,
npoints,
self.omega,
omega0,
quadrature,
)
prop = crystals.propagation(material, self.omega, omega0, self.thickness)
self.path_length = prop.path_length

# Work internally in DFT-bin order.
self.omega_bin = scipy.fft.ifftshift(self.omega)
beta = materials.beta(material, self.omega, omega0)
beta_bin = scipy.fft.ifftshift(beta)
beta_in_bin = scipy.fft.ifftshift(prop.beta_in)
beta_sig_bin = scipy.fft.ifftshift(prop.beta_sig)
sig_amp_bin = scipy.fft.ifftshift(prop.sig_amp)

nodes, weights = quadrature_nodes_weights(self.thickness, npoints, quadrature)
# Depth runs along the beams' path, longer than the plate in a tilted crystal.
nodes, weights = quadrature_nodes_weights(self.path_length, npoints, quadrature)
self.nodes = nodes
self.weights = weights
self.q = nodes.size

# Propagation phase matrices, shape (N, Q), in DFT-bin order.
self.input_prop = np.exp(1j * np.outer(beta_bin, nodes))
self.signal_prop = np.exp(1j * np.outer(beta_bin, self.thickness - nodes))
# Propagation phase matrices, shape (N, Q), in DFT-bin order: the field
# travels to depth z_q, the signal born there travels the rest of the path.
# The two arms differ only for a crystal crossed in its principal plane,
# where their delays drift apart with depth (crystals.CrystalSetup.arm_shift);
# otherwise gate_prop is input_prop.
self.input_prop, self.gate_prop = prop.arm_props(
beta_in_bin, self.omega_bin, nodes
)
self.signal_prop = sig_amp_bin[:, None] * np.exp(
1j * np.outer(beta_sig_bin, self.path_length - nodes)
)

# Geometric smearing. The (p, delta) statistics are independent of depth — the
# pulse-front tilts are set before the medium and the longitudinal walk-off
Expand Down Expand Up @@ -214,7 +234,7 @@ def signal_single(
phase = np.exp(1j * self.omega_bin * tau)
# (N, Q) propagated input spectra for test (undelayed) and gate (delayed)
e0 = ew_bin[:, None] * self.input_prop
etau = (ew_bin * phase)[:, None] * self.input_prop
etau = (ew_bin * phase)[:, None] * self.gate_prop
test = _fft0(e0)
gate = _fft0(etau)
sig = self.interaction.signal(test, gate)
Expand Down Expand Up @@ -351,7 +371,7 @@ def adjoint_single(self, psi_bar: Complex, tau: float) -> Complex:
phase = np.exp(1j * self.omega_bin * tau)
ew_bar_bin = (
np.conj(self.input_prop) * e0_bar
+ np.conj(phase[:, None] * self.input_prop) * etau_bar
+ np.conj(phase[:, None] * self.gate_prop) * etau_bar
).sum(axis=1)
return scipy.fft.fftshift(ew_bar_bin)

Expand All @@ -362,7 +382,7 @@ def maketrace(
ew: Complex,
interaction: str | Interaction,
*,
material: str | None = None,
material: str | CrystalSetup | None = None,
thickness: float = 0.0,
npoints: int = 1,
omega0: float = 0.0,
Expand Down
Loading
Loading