twpasolver.cmes.bloch module#

Linear Bloch-mode tables for the coupled mode equations in the Bloch basis.

The standard CMEs treat the periodically loaded line as a homogeneous medium: the supercell only provides the Bloch propagation constant, while the nonlinear coupling of mode n is scaled by its propagation constant (-gamma_n in the kernel). In the Bloch basis the amplitudes are the boundary currents of the forward Bloch modes, and the coupling becomes

dA_n/dx ∋ -(2j omega_n / W_n) * c_q * <L_j phi^-_{n,j} prod_r phi_{p_r,j}>,

where

  • W_n = Zb^+_n + Zb^-_n is the reciprocity invariant <psi^+, psi^-> (the mode power normalization, 2 Re Zb for a lossless line),

  • phi^±_{n,j} is the periodic part of the current of the forward/backward Bloch mode through the series nonlinear inductor j of the supercell, normalized to unit current at the supercell boundary,

  • <...> is the sum over the nonlinear inductors divided by the number of unit cells per supercell (x is measured in unit cells).

For a homogeneous lumped ladder phi = 1 and -2j omega L / W equals -gamma * tanh(gamma/2) / (gamma/2), which tends to the standard -gamma far below the ladder cutoff.

This module provides the linear ingredients: Bloch impedances, W and the intracell current profiles of a supercell (bloch_mode_tables()), the fixed (“edge”) basis for modes close to a stopband edge (edge_basis_tables() and the edge search), and the per-process weights of the stopband guard (process_weights()). The forward-backward solver is in twpasolver.cmes.bloch_fb. Supported unit cells are those whose nonlinearity is a lumped series inductance (LCLfBaseCell, StubBaseCell), or any cell defining a bloch_nl_elements() method (see series_nl_elements()).

Time convention is the package one: exp(+j omega t), forward waves ~ exp(-gamma x) with gamma = alpha + j k.

twpasolver.cmes.bloch.series_nl_elements(cell: Any) → list[tuple[int, float]][source]#

Return the series nonlinear inductors of a unit cell.

Each element is (port, L): the nonlinear inductance L carries the current of the cell’s input (PORT_IN) or output (PORT_OUT) port. Custom cells can define a bloch_nl_elements() method returning the same list to be supported. The package cells scale L by their nl_scale.

twpasolver.cmes.bloch.expand_unit_cells(array: TwoPortArray) → list[tuple[Any, int]][source]#

Expand one period (supercell) of array into ordered runs (cell, count).

The top-level repetition array.N is not applied (it is the number of supercells); nested TwoPortArray instances are expanded recursively.

twpasolver.cmes.bloch.bloch_wavenumber(twpa: TwoPortArray, freqs_hz: ndarray[Any, dtype[float64]], T: ndarray, Z0: complex) → ndarray[source]#

Bloch wavenumber k d per supercell of the forward mode, by winding.

The forward mode is the eigenvector of the supercell ABCD T carrying power along +x (Re Zb > 0) in a passband and decaying along +x (|lambda| > 1) in a stopband. Its forward-wave amplitude a = V + Z0 I is carried from x = d back to x = 0 element by element (series/shunt steps of every unit cell) and k d is the accumulated phase of a. Unlike unwrapping arg lambda along the frequency grid this does not depend on the grid, gives k near 0 above a notch and k < 0 in a left-handed band. The result is snapped to arg lambda modulo 2 pi.

twpasolver.cmes.bloch.bloch_mode_tables(twpa: TwoPortArray, freqs_hz: ndarray[Any, dtype[float64]], gamma_ref: ndarray[Any, dtype[complex128]]) → dict[str, Any][source]#

Compute Bloch impedances, W and intracell current profiles of a supercell.

Parameters:
  • twpa (TwoPortArray) – Non-segmented device; one period is twpa.cells.

  • freqs_hz ((F,) float) – Frequencies in Hz (mode frequencies, flattened).

  • gamma_ref ((F,) complex) – Per-unit-cell propagation constant alpha + j k used by the CME kernel. It selects the forward eigenvalue and the branch of k.

Returns:

  • Zb_plus, Zb_minus, W: (F,) complex.

  • phi_plus, phi_minus: (F, n_nl) complex, periodic profiles of the forward/backward mode current through each nonlinear inductor.

  • L_nl: (n_nl,) nonlinear inductances.

  • n_cells: unit cells per supercell.

  • positions: (n_nl,) position of each nonlinear inductor inside the supercell, in unit cells (the reference used for phi).

  • gamma_exact: (F,) complex, per-unit-cell gamma from the eigenvalue.

  • eig_residual: (F,) float, |I_M * lambda - 1| after propagating the forward mode through one supercell (should be ~machine precision).

  • split: (F,) float, |sinh(gamma d)| = |lambda+ - lambda-| / 2, the normalisation-free splitting of the two Bloch modes (0 at every band edge, the exceptional point of the supercell matrix).

Return type:

dict

twpasolver.cmes.bloch.lossless_copy(model: Any) → Any[source]#

Deep copy of a device model with every loss tangent delta set to zero.

twpasolver.cmes.bloch.supercell_matrix(twpa: TwoPortArray, freqs_hz: ndarray[Any, dtype[float64]]) → ndarray[source]#

ABCD matrix of one supercell, shape (F, 2, 2).

twpasolver.cmes.bloch.logm_unimodular_2x2(Q: ndarray) → ndarray[source]#

Principal logarithm of 2x2 matrices with unit determinant, shape (…, 2, 2).

log Q = (phi / sinh phi) (Q - cosh(phi) I) with cosh phi = tr(Q)/2, regular at the exceptional point Q - I nilpotent (log Q = Q - I). Valid for Q close to the identity (|phi| well below pi).

twpasolver.cmes.bloch.passband_mask(h: ndarray) → ndarray[source]#

Passband points of a scan of the half trace h = tr T / 2.

|h| < 1, except that runs of points with |h| >= 1 whose excess never reaches STOPBAND_TOL (bands touching at a folding point, rounding) are counted as passband.

twpasolver.cmes.bloch.in_stopband(twpa_ll: TwoPortArray, f_hz: ndarray[Any, dtype[float64]]) → ndarray[source]#

True where |tr T / 2| > 1 + STOPBAND_TOL for the (lossless) supercell.

twpasolver.cmes.bloch.gap_ahead(twpa_ll: TwoPortArray, f_hz: ndarray[Any, dtype[float64]], n_sample: int = 16) → ndarray[source]#

Whether a stopband starts close to each frequency, toward increasing |tr T / 2|.

Next to a real edge |h| (h = tr T / 2) crosses 1 almost linearly; at a zone-folding point it only touches 1 (1 - c (f - f0)^2). |h| is sampled from f to three times the distance at which its linear extrapolation reaches 1: past a real edge it exceeds 1 + STOPBAND_TOL, past a folding point it falls back. Two supercell evaluations for all frequencies, so the edge search can skip the folding points.

twpasolver.cmes.bloch.edge_reference_frequency(twpa_ll: TwoPortArray, f_hz: float, e_ref: float, span_hz: float = 500000000.0, n_scan: int = 2001, max_span_hz: float = 8000000000.0) → tuple[float, float, int][source]#

Reference frequency of the fixed basis of a mode near a stopband edge.

Finds the band edge of the lossless supercell closest to f_hz (|tr T / 2| = 1) and, on its passband side, the frequency where the splitting |sinh(gamma d)| = sqrt(1 - (tr T / 2)^2) equals e_ref.

Returns:

  • f_ref, f_edge (float) – Reference and edge frequencies (Hz).

  • parity (int) – (-1)^m = sign(tr T / 2) at the edge.

twpasolver.cmes.bloch.stopband_edges(twpa_ll: TwoPortArray, f_hz: ndarray[Any, dtype[float64]], e_ref: float, span_hz: float = 1000000000.0, step_hz: float = 500000.0) → tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#

Stopband edges of a lossless supercell near a set of frequencies.

Scans |tr T / 2| on a grid of step step_hz over the union of the intervals f +- span_hz and refines every edge, |tr T / 2| = 1, and its reference frequency on the passband side, where the splitting equals e_ref, as edge_reference_frequency() does for a single frequency.

Returns:

  • f_edge, f_ref ((E,) float) – Edge and reference frequencies (Hz), sorted by edge; f_ref is NaN when the passband next to the edge does not reach e_ref within the scanned block.

  • parity ((E,) int) – (-1)^m = sign(tr T / 2) at the edge.

twpasolver.cmes.bloch.edge_basis_tables(twpa: TwoPortArray, twpa_ll: TwoPortArray, f_hz: ndarray[Any, dtype[float64]], f_ref_hz: ndarray[Any, dtype[float64]], m_edge: ndarray) → dict[str, Any][source]#

Fixed-basis tables of modes close to a stopband edge.

Parameters:
  • twpa (TwoPortArray) – Lossy device and its lossless copy (same supercell).

  • twpa_ll (TwoPortArray) – Lossy device and its lossless copy (same supercell).

  • f_hz ((F,) float) – Actual mode frequencies.

  • f_ref_hz ((F,) float) – Reference frequencies (passband side, see edge_reference_frequency()).

  • m_edge ((F,) int) – Edge index, kappa_e d = m pi.

Returns:

  • Zb_plus, Zb_minus: (F,) lossless Bloch impedances at f_ref (the fixed boundary vectors (Zb+, 1), (-Zb-, 1)).

  • W: (F,) real, Zb+ + Zb- (positive).

  • phi_plus, phi_minus: (F, n_nl) periodic profiles of the fixed vectors propagated through the lossy cells at f, with the edge phase exp(+-j kappa_e pos).

  • K, K_lossless: (F, 2, 2) per-unit-cell linear generator of (c+, c-) from the lossy / lossless supercell at f.

  • kappa_e: (F,) edge wavenumber per unit cell.

  • ham_defect: (F,) ||K^dag S + S K|| / ||K|| of the lossless K, S = diag(1, -1); zero to rounding (flux conservation).

Return type:

dict

twpasolver.cmes.bloch.reactive_angle_deg(W: ndarray) → ndarray[source]#

Reactive angle of the Bloch normalisation, arcsin(|Im W| / |W|) in degrees.

0 for a power-carrying travelling Bloch mode (W real in every lossless passband, for any supercell reference plane), 90 for a purely evanescent mode inside a lossless stopband. Unlike arg Zb it does not depend on the supercell boundary chosen for asymmetric cells.

twpasolver.cmes.bloch.process_weights(relations: ndarray, mode_weights: ndarray) → ndarray[source]#

Weight of every relation row: product of the weights of all its modes.

All rows describing the same physical process (one per participating mode, and every direction / reciprocal-vector variant in the FB model) contain the same multiset of modes, so they receive the same real factor and the Manley-Rowe cancellation between them is preserved exactly.

Parameters:
  • relations ((R, 1+p) int) – Rows [target, input_1, ...]; inputs >= n_modes are conjugated.

  • mode_weights ((..., n_modes) float) –

Return type:

(…, R) float