twpasolver.cmes.prep module#
CME input preparation: relation coefficients, per-segment Bloch tables, stopband treatment.
- class twpasolver.cmes.prep.CMEProblem(mode_labels: list[str], freqs: ndarray, freqs_hz: ndarray, gammas: ndarray, reflections: ndarray, relations_3wm: ndarray, relations_4wm: ndarray, unit_3wm: ndarray, unit_4wm: ndarray, coeffs_3wm: ndarray, coeffs_4wm: ndarray, segments: list, seg_bounds: ndarray, seg_midpoints: ndarray)[source]#
Bases:
objectInputs of the CME solvers for one set of mode frequencies; a uniform device is one segment.
- Variables:
mode_labels (list[str]) – Mode names, in the order of the amplitudes.
freqs (numpy.ndarray) – Signed mode frequencies in the analysis unit, (n_freq, n_modes).
freqs_hz (numpy.ndarray) –
|freqs|in Hz.gammas (numpy.ndarray) – Kernel propagation constants
-alpha - j kper unit cell, (n_freq, n_modes, n_seg).reflections (numpy.ndarray) – Reflection coefficient against
twpa.Z0_ref, (n_freq, n_modes, n_seg).relations_4wm (relations_3wm,) – Mode-index relations, (n_rel, 3) / (n_rel, 4).
unit_4wm (unit_3wm,) – Relation coefficients for unit epsilon / xi, (n_rel,).
coeffs_4wm (coeffs_3wm,) – Coefficients of every segment, (n_rel, n_seg).
segments (list) – Uniform segments (
TWPA), each a whole number of supercells.seg_midpoints (seg_bounds,) – Segment boundaries and midpoints (unit cells).
- freqs: ndarray#
- freqs_hz: ndarray#
- gammas: ndarray#
- reflections: ndarray#
- relations_3wm: ndarray#
- relations_4wm: ndarray#
- unit_3wm: ndarray#
- unit_4wm: ndarray#
- coeffs_3wm: ndarray#
- coeffs_4wm: ndarray#
- seg_bounds: ndarray#
- seg_midpoints: ndarray#
- twpasolver.cmes.prep.prepare_relations_coefficients(terms_3wm, terms_4wm, epsilon, xi)[source]#
Mode-index relations and coefficients of the 3WM and 4WM terms.
- Parameters:
terms_3wm (list) – RWA terms
(mode, (indices...), coefficient)fromModeSet.rwa_terms.terms_4wm (list) – RWA terms
(mode, (indices...), coefficient)fromModeSet.rwa_terms.epsilon (float) – Nonlinearities; the coefficients are scaled by
epsilon / 4andxi / 4. An empty term list gives a single dummy zero relation.xi (float) – Nonlinearities; the coefficients are scaled by
epsilon / 4andxi / 4. An empty term list gives a single dummy zero relation.
- Returns:
relations_3wm (np.ndarray, int64, (n_rel, 3))
relations_4wm (np.ndarray, int64, (n_rel, 4))
coeffs_3wm (np.ndarray, complex128, (n_rel,))
coeffs_4wm (np.ndarray, complex128, (n_rel,))
- twpasolver.cmes.prep.fb_stopbands(bloch: dict[str, Any], problem: CMEProblem, gammas: ndarray, injected: ndarray, bloch_config: BlochSolverConfig) dict[str, Any][source]#
Stopband treatment and harmonic limits of the Bloch forward-backward models.
bloch_config.edge_thresholdmarks the modes close to an edge;bloch_config.simulate_stopband_modeseither expands them, and every mode inside a stopband, on the fixed edge basis (apply_edge_basis_segmented()), or switches their processes off with_stopband_guard_weights(). Modes with an input are never changed.m_max='auto'gives per-mode harmonic limits (_harmonic_limits(), window2 * edge_threshold).Returns a dict with the kernel
gammas,edge(edge-basis tables or None),m_max(int or per-mode table) and the process weightspw3,pw4(None when every process has weight 1).
- twpasolver.cmes.prep.apply_edge_basis_segmented(bloch: dict[str, Any], problem: CMEProblem, injected: ndarray, threshold: float) dict[str, Any] | None[source]#
Fixed (“edge”) Bloch basis for modes close to a stopband edge.
A mode without input whose splitting in segment
sis belowthreshold, or that lies inside a stopband, is expanded there on the lossless Bloch pair of that segment’s supercell, anchored on the passband side of the nearest edge (_edge_basis_entries()). The junction coefficients follow from the overwrittenZb_plusandZb_minusand stay exact. A mode flagged in at least one segment (edge_mode) is solved exactly along the whole line; in its native segments the generator isdiag(-alpha, alpha).Returns None when nothing is flagged, otherwise the kernel gammas (
(n_freq, n_modes, n_seg)),edge_K((n_freq, n_seg, n_modes, 2, 2), per unit cell),edge_flag((n_freq, n_seg, n_modes)) andedge_mode((n_freq, n_modes)); diagnostics are stored inbloch.
- twpasolver.cmes.prep.prepare_bloch_segmented(problem: CMEProblem) dict[str, Any][source]#
Per-segment Bloch tables for the forward-backward solver.
Every segment is a uniform
TWPAof whole supercells; its Bloch modes come frombloch_mode_tables()on its own supercell, with the branch ofkset by its kernel wavenumber. Intracell arrays are zero-padded to the largest number of nonlinear inductors per supercell.- Returns:
W,split,Zb_plus,Zb_minus,prefac: (n_freq, n_seg, n_modes)phi_plus,phi_minus: (n_freq, n_seg, n_modes, n_nl)L_nl,positions: (n_seg, n_nl);n_cells: (n_seg,)base_3wm,base_4wm: (n_seg, n_rel)seg_bounds: (n_seg + 1,) and the diagnosticseig_residual,gamma_mismatch: (n_freq, n_seg, n_modes).- Return type: