twpasolver.cmes.bloch_fb module#
Forward-backward coupled mode equations in the Bloch-mode basis.
Extension of twpasolver.cmes.bloch to counter-propagating waves,
reflections at the device terminations and segmented (piecewise-uniform)
devices. A segmented device is a chain of uniform segments, each made of whole
supercells of its own; a uniform device is the one-segment case of
bloch_fb_segmented_cmes_solve().
Physics summary (package convention exp(+j omega t), forward ~ exp(-gamma x))#
Inside a segment every mode is expanded exactly as
psi_n = A+_n psi+_n + A-_n psi-_non that segment’s Bloch modes, withpsi+_n(0) = (Zb+_n, 1)andpsi-_n(0) = (-Zb-_n, 1). Both amplitudes are currents referenced to +x, so the total current through a nonlinear inductor isA+ phi+ e^{-gamma x} + A- phi- e^{+gamma x}.Projecting the nonlinear series source with the reciprocity invariant
W_n = <psi+_n, psi-_n> = Zb+_n + Zb-_ngivesdA+_n/dx = -(j omega_n / W_n) <L Pi_n phi-_n> e^{+gamma x}anddA-_n/dx = +(j omega_n / W_n) <L Pi_n phi+_n> e^{-gamma x}. The backward solve runs in the mirrored coordinate s = L - x, which flips the sign of the second equation: both solves use the prefactor-2j omega_n / W_n(times the RWA multiplicity/4 and epsilon or xi), and differ only in the partner profile (phi- for the forward target, phi+ for the backward one) and in which profile each input carries (own direction vs counter direction). Reciprocal vectors2 pi m / d_s, term selection and stopband-edge treatment are those of each segment.Because the expansion fixes voltage and current at every supercell boundary (
phi = 1there),V = Zb+ A+ - Zb- A-andI = A+ + A-hold exactly, with the nonlinearity on, at the device ends and at every junction. The boundary coefficients are therefore constant (no derivative correction, no damping of a self-consistent update):- input (x=0): A+ = t_in a_in + rho_in A-,
t_in = 2 Ze / (apcz_in (Zb+ + Zout_in)), rho_in = (Zb- - Zout_in) / (Zb+ + Zout_in), b_in = tof_in (1 + rho_in) A-
- output (x=L): A- = -t_out a_out + rho_out A+,
t_out = 2 Ze / (apcz_out (Zb- + Zout_out)), rho_out = (Zb+ - Zout_out) / (Zb- + Zout_out), b_out = -tof_out (1 + rho_out) A+
where
a/bare the incident/outgoing currents in the external line,apcz = A + C Ze,Zout = (B + D Ze)/(A + C Ze)andtof = det/apczof each connector (port 2 facing the device). The minus signs at the output end come from referencing the backward current to +x.
Junction conditions#
Every junction lies on a supercell boundary of both neighbours. Continuity of (V, I) and the projection with the reciprocity invariant give, for the junction between a left segment L and a right segment R:
A+_R = t A+_L + rho_R A-_R, t = W_L / (Zb+_R + Zb-_L),
A-_L = t' A-_R + rho_L A+_L, t' = W_R / (Zb+_R + Zb-_L),
rho_R = (Zb-_R - Zb-_L) / (Zb+_R + Zb-_L),
rho_L = (Zb+_L - Zb+_R) / (Zb+_R + Zb-_L).
The input boundary above is the special case Zb-_L -> Zout. Identical
neighbours give t = t' = 1, rho = 0. In flux variables
(a ∝ sqrt(W) A) the junction map is reciprocal, and unitary for lossless
passbands, so energy and Manley-Rowe conservation survive composition.
Phases and coordinates#
Only the propagation phase is factored out of the integration variables; the
loss stays in the envelope through the alpha * A term. With the
piecewise-constant wavenumber the phase is
Phi_f(x) = integral_0^x kappa(x’) dx’ (forward, physical x), Phi_b(s) = Phi_f(L) - Phi_f(L - s) (backward, mirrored s = L - x),
and the fields entering the products are B+ e^{j Phi_f}, B- e^{j Phi_b}.
Reciprocal-vector phases are referred to the origin of each segment
(exp(j G_m (x - x_s)) in the solve coordinate), which is exact in both
directions because every segment holds a whole number of its supercells.
Grid#
Envelopes are discontinuous at junctions. The solver works on an internal grid made of one sub-grid per segment, each containing both segment ends (junction positions appear twice: left and right limits). Counter-propagating fields are interpolated only inside the segment being integrated, and the integrator is restarted at every junction. Results are returned on the caller’s grid (the left limit is used at a junction position).
Iteration#
One pass is a forward sweep over the segments (junction steps use the current
backward estimate) followed by a backward sweep (junction steps use the
forward fields just computed). The pass is a map u -> G(u) on the backward
envelopes u on the internal grid. Strong counter-propagating coupling (e.g. a
Bragg-matched forward/backward pair near a stopband, or internal reflections)
puts eigenvalues of this map outside the unit circle and the plain iteration
diverges even though the boundary-value problem has a regular solution.
Anderson acceleration (anderson_depth previous passes, per-mode weighted
least squares) solves for the fixed point instead. It cannot cure an
instability inside a single sweep (a mode close to a stopband edge whose
forward-only subsystem grows exponentially); such modes are solved exactly on
a fixed edge basis (edge_K, edge_mode).
- twpasolver.cmes.bloch_fb.junction_coefficients(Zb_plus: ndarray[Any, dtype[complex128]], Zb_minus: ndarray[Any, dtype[complex128]]) tuple[numpy.ndarray[Any, numpy.dtype[numpy.complex128]], numpy.ndarray[Any, numpy.dtype[numpy.complex128]], numpy.ndarray[Any, numpy.dtype[numpy.complex128]], numpy.ndarray[Any, numpy.dtype[numpy.complex128]]][source]#
Exact junction coefficients between consecutive segments.
- Parameters:
Zb_plus ((..., n_seg, n_modes) complex) – Bloch impedances of every segment (forward / backward mode), referred to the supercell boundary that sits at the junction.
Zb_minus ((..., n_seg, n_modes) complex) – Bloch impedances of every segment (forward / backward mode), referred to the supercell boundary that sits at the junction.
- Returns:
t, t_prime, rho_L, rho_R – Entry
jdescribes the junction between segmentsj - 1(left) andj(right). Entry 0 is the identity (no junction).- Return type:
(…, n_seg, n_modes) complex
- twpasolver.cmes.bloch_fb.build_segment_grid(x_array: ndarray[Any, dtype[float64]], seg_bounds: ndarray[Any, dtype[float64]]) tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray, numpy.ndarray][source]#
Internal grid with both ends of every segment, and the map to
x_array.- Returns:
x_int ((n_int,) float) – Concatenation of the per-segment grids
[x_s, interior x_array points, x_{s+1}]; junction positions appear twice.offsets ((n_seg + 1,) int) – Segment
soccupiesx_int[offsets[s]:offsets[s+1]].take ((n_x,) int) – Index into
x_intof the value reported at eachx_arraypoint (left limit at a junction, segment 0 atx = 0).
- twpasolver.cmes.bloch_fb.segment_phases(kappas: ndarray[Any, dtype[float64]], seg_bounds: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]][source]#
Accumulated forward phase at the segment boundaries, shape (…, n_seg + 1).
kappas(…, n_seg): kernel wavenumbers of every segment. The kernel andsegmented_phase()both use this table.
- twpasolver.cmes.bloch_fb.segmented_phase(kappas: ndarray[Any, dtype[float64]], cum: ndarray[Any, dtype[float64]], seg_bounds: ndarray[Any, dtype[float64]], x: ndarray[Any, dtype[float64]])[source]#
Exact cumulative propagation phase for piecewise-constant wavenumbers.
- Parameters:
kappas ((..., n_seg) float) – Kernel wavenumbers (
Imof the kernel gammas) of every segment.cum ((..., n_seg + 1) float) – Their
segment_phases().seg_bounds ((n_seg + 1,) float) –
x ((n_x,) float) –
- Returns:
(Phi_f, Phi_b) – Forward phase at physical
xand backward phase at mirrored coordinates = x(i.e. physical positionL - x).- Return type:
(…, n_x) float
- twpasolver.cmes.bloch_fb.bloch_fb_segment_rhs(x, currents, alphas, kappas, rows_3wm, rows_4wm, row_coeffs_3wm, row_coeffs_4wm, row_g_3wm, row_g_4wm, x0, phi0, ctr_x, ctr_vals, ctr_y0, ctr_phi0, end)[source]#
RHS of the Bloch forward/backward CMEs inside one segment.
Field bookkeeping as described in the module docstring, with segment-local phases:
own carrier
exp(j (phi0 + kappa (x - x0))),x0the start of the segment in the solve coordinate andphi0the accumulated phase there;counter field read at
y = end - xfromctr_valssampled onctr_x(the same physical segment in the counter coordinate, whose start isctr_y0with phasectr_phi0);reciprocal-vector phase
exp(j G (x - x0)).
- twpasolver.cmes.bloch_fb.bloch_fb_segment_rhs_edge(x, currents, alphas, kappas, rows_3wm, rows_4wm, row_coeffs_3wm, row_coeffs_4wm, row_g_3wm, row_g_4wm, x0, phi0, ctr_x, ctr_vals, ctr_y0, ctr_phi0, end, edge_code, own_x, own_vals, lin_own, lin_ctr, ctr_phase)[source]#
bloch_fb_segment_rhs()with the edge-basis modes of one solve direction.edge_code[i]: 0 ordinary mode; 1 frozen (own field read fromown_valsonown_x, zero derivative); 2 integrated with the extra linear termslin_own[i] c + lin_ctr[i] ctr_phase[i] u_i(end - x), withu_ithe counter envelope of the segment (ctr_valsonctr_x).
- twpasolver.cmes.bloch_fb.bloch_fb_segmented_cmes_solve(x_array: ndarray[Any, dtype[float64]], seg_bounds: ndarray[Any, dtype[float64]], y0_array_fwd: ndarray[Any, dtype[complex128]], y0_array_bwd: ndarray[Any, dtype[complex128]], gammas_seg: ndarray[Any, dtype[complex128]], relations_3wm: ndarray, relations_4wm: ndarray, base_3wm: ndarray[Any, dtype[complex128]], base_4wm: ndarray[Any, dtype[complex128]], prefac: ndarray[Any, dtype[complex128]], phi_plus: ndarray[Any, dtype[complex128]], phi_minus: ndarray[Any, dtype[complex128]], L_nl: ndarray[Any, dtype[float64]], positions: ndarray[Any, dtype[float64]], n_cells: ndarray, Zb_plus: ndarray[Any, dtype[complex128]], Zb_minus: ndarray[Any, dtype[complex128]], passes: int = 30, kappa_cutoff: float = 0.2, m_max: int | ndarray = 1, convergence_threshold: float = 0.01, save_all_passes: bool = False, anderson_depth: int = 20, process_weights_3wm: ndarray[Any, dtype[float64]] | None = None, process_weights_4wm: ndarray[Any, dtype[float64]] | None = None, Ze: float | ndarray[Any, dtype[complex128]] = 50.0, Zout_in: ndarray[Any, dtype[complex128]] | None = None, Zout_out: ndarray[Any, dtype[complex128]] | None = None, abcd_in: ndarray[Any, dtype[complex128]] | None = None, abcd_out: ndarray[Any, dtype[complex128]] | None = None, rk_config: RKSolverConfig | None = None, edge_K: ndarray[Any, dtype[complex128]] | None = None, edge_mode: ndarray | None = None, diagnostics: dict | None = None) dict[str, numpy.ndarray][source]#
Solve the forward/backward Bloch CMEs of a segmented device.
- Parameters:
x_array ((n_x,) float) – Output grid on
[0, L]; must be symmetric underx -> L - x(e.g.linspace(0, L, n)).seg_bounds ((n_seg + 1,) float) – Segment boundaries in unit cells,
seg_bounds[-1] = L. Every segment must hold a whole number of its own supercells.gammas_seg ((n_freq, n_seg, n_modes) complex) – Kernel propagation constants (
-alpha - j k) of every segment.base_3wm ((n_seg, n_rel)) – RWA multiplicity/4 times the segment’s epsilon / xi.
base_4wm ((n_seg, n_rel)) – RWA multiplicity/4 times the segment’s epsilon / xi.
prefac ((n_freq, n_seg, n_modes)) –
-2j omega / Wof every segment.phi_plus ((n_freq, n_seg, n_modes, n_nl)) – Intracell current profiles (padded with zeros to the largest
n_nl).phi_minus ((n_freq, n_seg, n_modes, n_nl)) – Intracell current profiles (padded with zeros to the largest
n_nl).L_nl ((n_seg, n_nl)) – Nonlinear inductances (0 for padding) and positions inside the segment’s supercell (unit cells).
positions ((n_seg, n_nl)) – Nonlinear inductances (0 for padding) and positions inside the segment’s supercell (unit cells).
n_cells ((n_seg,) int) – Unit cells per supercell of every segment.
Zb_plus ((n_freq, n_seg, n_modes)) – Bloch impedances of every segment; consecutive segments define the junction coefficients (
junction_coefficients()), the first and last ones the end boundaries.Zb_minus ((n_freq, n_seg, n_modes)) – Bloch impedances of every segment; consecutive segments define the junction coefficients (
junction_coefficients()), the first and last ones the end boundaries.process_weights_3wm ((n_freq, n_seg, n_rel), optional) – Real factors of every relation row per segment; default 1.
process_weights_4wm ((n_freq, n_seg, n_rel), optional) – Real factors of every relation row per segment; default 1.
edge_K ((n_freq, n_seg, n_modes, 2, 2) complex, optional) – Per-unit-cell linear generator of
(c+, c-)of every edge mode in every segment: the fixed-basisKwhere the mode is flagged,diag(-alpha, alpha)in its native segments.edge_mode ((n_freq, n_modes) bool, optional) – Modes solved exactly across the line (flagged in at least one segment). Their tables,
prefacand kernel gammas must already be the edge-basis ones where flagged. Default: none.rk_config (RKSolverConfig, optional) – Settings of the RK45 integrator (default
RKSolverConfig()).m_max (int or (n_freq, n_seg, n_modes) int array) – Harmonic limit, global or per frequency, segment and mode (a process uses the largest limit among its modes). Default: the base limit of
m_max='auto', which the analysis layer resolves per mode.passes – As in
BlochSolverConfig, whose defaults they take.kappa_cutoff – As in
BlochSolverConfig, whose defaults they take.convergence_threshold – As in
BlochSolverConfig, whose defaults they take.save_all_passes – As in
BlochSolverConfig, whose defaults they take.anderson_depth – As in
BlochSolverConfig, whose defaults they take.diagnostics (dict, optional) – If given, filled with
convergedandresiduals(n_freq,).
- Returns:
I_fwd,I_bwd(n_saved, n_freq, n_modes, n_x)Forward and backward mode currents (with the propagation phase) on
x_array;n_savedispasseswithsave_all_passes, else 1.a_in,a_out(n_freq, n_modes)Currents incident from the external lines at x=0 and x=L.
b_in,b_out(n_saved, n_freq, n_modes)Currents going out into the external lines at x=0 and x=L: the transmitted device wave plus the prompt reflection of the incident one.
- Return type: