twpasolver.cmes.solver_config module#
Settings of the RK45 integrator and of the forward-backward Bloch solver.
- pydantic model twpasolver.cmes.solver_config.RKSolverConfig[source]#
Bases:
BaseModelSettings of the adaptive RK45 integrator used by every CME kernel.
They are passed to the Numba kernels as arguments, so changing them takes effect at once (no recompilation, no stale cache).
Show JSON schema
{ "title": "RKSolverConfig", "description": "Settings of the adaptive RK45 integrator used by every CME kernel.\n\nThey are passed to the Numba kernels as arguments, so changing them takes\neffect at once (no recompilation, no stale cache).", "type": "object", "properties": { "atol": { "default": 1e-12, "description": "Absolute tolerance.", "exclusiveMinimum": 0, "title": "Atol", "type": "number" }, "rtol": { "default": 1e-08, "description": "Relative tolerance.", "exclusiveMinimum": 0, "title": "Rtol", "type": "number" }, "first_step": { "default": 10, "description": "Initial step, in unit cells.", "exclusiveMinimum": 0, "title": "First Step", "type": "number" }, "max_steps_per_cell": { "default": 2, "description": "Cap on the accepted steps per unit cell of the integration interval (device or segment length): ceil(length * max_steps_per_cell) + 1. The CME envelopes vary slowly on the scale of a cell, so a run that needs more is running away; it is stopped and its unreached points are NaN (reported as a warning). 0 disables the cap.", "minimum": 0, "title": "Max Steps Per Cell", "type": "number" } }, "additionalProperties": false }
- field max_steps_per_cell: float = 2#
Cap on the accepted steps per unit cell of the integration interval (device or segment length): ceil(length * max_steps_per_cell) + 1. The CME envelopes vary slowly on the scale of a cell, so a run that needs more is running away; it is stopped and its unreached points are NaN (reported as a warning). 0 disables the cap.
- Constraints:
ge = 0
- pydantic model twpasolver.cmes.solver_config.BlochSolverConfig[source]#
Bases:
BaseModelSettings of the forward-backward Bloch CME solver (
model="bloch").Convergence of the forward-backward iteration, selection of the mixing terms and treatment of the modes close to a stopband edge.
Show JSON schema
{ "title": "BlochSolverConfig", "description": "Settings of the forward-backward Bloch CME solver (``model=\"bloch\"``).\n\nConvergence of the forward-backward iteration, selection of the mixing\nterms and treatment of the modes close to a stopband edge.", "type": "object", "properties": { "passes": { "default": 30, "description": "Maximum number of forward-backward passes.", "minimum": 1, "title": "Passes", "type": "integer" }, "kappa_cutoff": { "default": 0.2, "description": "Phase-mismatch cutoff used to filter 3WM/4WM terms: a term is kept when its residual mismatch ``|dk + G_m|`` after a reciprocal vector is below kappa_cutoff times the largest wavenumber of its process, capped at the zone edge pi / d (the largest wavenumber the supercell-averaged envelopes resolve), so no kept term advances more than kappa_cutoff * pi per supercell.", "exclusiveMinimum": 0, "title": "Kappa Cutoff", "type": "number" }, "convergence_threshold": { "default": 0.01, "description": "Relative change below which forward/backward waves are considered converged.", "exclusiveMinimum": 0, "title": "Convergence Threshold", "type": "number" }, "save_all_passes": { "default": false, "description": "Whether to store intermediate results for every pass.", "title": "Save All Passes", "type": "boolean" }, "m_max": { "anyOf": [ { "type": "integer" }, { "const": "auto", "type": "string" } ], "default": "auto", "description": "Largest ``|m|`` of the reciprocal lattice vectors G_m = 2 pi m / d whose intracell Fourier components couple quasi-phase-matched terms. Only terms whose residual mismatch ``|dk + G_m|`` passes kappa_cutoff are kept; 0 keeps cell averages only. 'auto': 1 for every mode, raised to the Bragg order m (k d = m pi) of a mode that lies inside a stopband or whose splitting is below twice edge_threshold, at the frequencies (and in the segments) where it does; a process uses the largest limit among its modes, so partner terms stay together. The counter-propagating component of a mode at the m-th edge is reached only through G_m. Both m and the pi / d cap of kappa_cutoff count per supercell (one repetition of ``twpa.cells``): build it from a single period. A supercell of q identical periods needs m_max and kappa_cutoff scaled by q to keep the same terms, which 'auto' does not do.", "title": "M Max" }, "anderson_depth": { "default": 20, "description": "Number of previous passes used by Anderson acceleration of the forward-backward iteration. convergence_threshold applies to the relative fixed-point residual of the backward envelopes; a point whose residual turns NaN/inf is stopped at once and reported as not converged.", "minimum": 1, "title": "Anderson Depth", "type": "integer" }, "edge_threshold": { "anyOf": [ { "exclusiveMaximum": 1, "exclusiveMinimum": 0, "type": "number" }, { "type": "null" } ], "default": 0.1, "description": "A mode is close to a stopband edge when its Bloch splitting ``|sinh(gamma d)|`` is below this value. What happens to the modes close to an edge or inside a stopband is set by simulate_stopband_modes. Modes with an input are never changed. None: no stopband treatment (native Bloch basis everywhere, which fails at the edges).", "title": "Edge Threshold" }, "simulate_stopband_modes": { "default": true, "description": "True: modes without input close to an edge or inside a stopband are expanded on a fixed Bloch pair, the lossless pair on the passband side of the nearest edge where the splitting equals edge_threshold, and their Bragg coupling between the two directions is solved exactly once per pass (see twpasolver.cmes.bloch_fb); their processes are kept and conserve the photon fluxes. False (faster): their processes are switched off, with a smoothstep weight in the splitting that falls from 1 at edge_threshold to 0 at the edge on the passband side, and weight 0 throughout the stopband; every process is scaled by the product of the weights of its modes, so what is kept still conserves the fluxes.", "title": "Simulate Stopband Modes", "type": "boolean" } }, "additionalProperties": false }
- Fields:
- Validators:
_check_m_max»m_max
- field kappa_cutoff: float = 0.2#
Phase-mismatch cutoff used to filter 3WM/4WM terms: a term is kept when its residual mismatch
|dk + G_m|after a reciprocal vector is below kappa_cutoff times the largest wavenumber of its process, capped at the zone edge pi / d (the largest wavenumber the supercell-averaged envelopes resolve), so no kept term advances more than kappa_cutoff * pi per supercell.- Constraints:
gt = 0
- field convergence_threshold: float = 0.01#
Relative change below which forward/backward waves are considered converged.
- Constraints:
gt = 0
- field m_max: int | Literal['auto'] = 'auto'#
Largest
|m|of the reciprocal lattice vectors G_m = 2 pi m / d whose intracell Fourier components couple quasi-phase-matched terms. Only terms whose residual mismatch|dk + G_m|passes kappa_cutoff are kept; 0 keeps cell averages only. ‘auto’: 1 for every mode, raised to the Bragg order m (k d = m pi) of a mode that lies inside a stopband or whose splitting is below twice edge_threshold, at the frequencies (and in the segments) where it does; a process uses the largest limit among its modes, so partner terms stay together. The counter-propagating component of a mode at the m-th edge is reached only through G_m. Both m and the pi / d cap of kappa_cutoff count per supercell (one repetition oftwpa.cells): build it from a single period. A supercell of q identical periods needs m_max and kappa_cutoff scaled by q to keep the same terms, which ‘auto’ does not do.- Validated by:
_check_m_max
- field anderson_depth: int = 20#
Number of previous passes used by Anderson acceleration of the forward-backward iteration. convergence_threshold applies to the relative fixed-point residual of the backward envelopes; a point whose residual turns NaN/inf is stopped at once and reported as not converged.
- Constraints:
ge = 1
- field edge_threshold: float | None = 0.1#
A mode is close to a stopband edge when its Bloch splitting
|sinh(gamma d)|is below this value. What happens to the modes close to an edge or inside a stopband is set by simulate_stopband_modes. Modes with an input are never changed. None: no stopband treatment (native Bloch basis everywhere, which fails at the edges).- Constraints:
gt = 0
lt = 1
- field simulate_stopband_modes: bool = True#
True: modes without input close to an edge or inside a stopband are expanded on a fixed Bloch pair, the lossless pair on the passband side of the nearest edge where the splitting equals edge_threshold, and their Bragg coupling between the two directions is solved exactly once per pass (see twpasolver.cmes.bloch_fb); their processes are kept and conserve the photon fluxes. False (faster): their processes are switched off, with a smoothstep weight in the splitting that falls from 1 at edge_threshold to 0 at the edge on the passband side, and weight 0 throughout the stopband; every process is scaled by the product of the weights of its modes, so what is kept still conserves the fluxes.