/** * Dense MNA (Modified Nodal Analysis) matrix + partial-pivot LU solver. * * Rows/columns 0..nodeCount-1 correspond to circuit nodes (ground excluded). * Rows/columns nodeCount..size-1 are extra variables for voltage sources. * * For R1 circuits (< 200 nodes) a dense solver is fast enough at 10 kHz. * Sparse LU can replace this later without changing the stamp API. */ /** * Smallest scale a solve's residual is measured against. Below about 1e-300 * the ratio stops measuring the solve. A circuit coming to rest decays toward * exact zero, and once its values are subnormal (under 2.2e-308) every * operation rounds to a fixed 5e-324 grid instead of to a relative error, so a * correct solve's residual can be one grid step against a 1e-318 scale: 5e-6, * which fails the engine's 1e-8 gate. A failed step commits nothing, so the * next step solves the same state and fails the same way, for good. That * rounding is at most about n * |G|max * 5e-324 in an n-unknown row, so the * gate needs a scale of n * |G|max * 5e-316; 1e-300 covers any n * |G|max * under 2e15 (a thousand nodes with 1 uohm shorts is 1e9). It is also far * below any scale a circuit with a measurable value has: the 1 pS node shunt * at Newton's 1 uV tolerance carries 1e-18 A. So every solve with a scale * above 1e-300, a wrong one included, is judged exactly as before, and the * floor never touches the singular or non-finite checks. */ export declare const RESIDUAL_SCALE_FLOOR = 1e-300; export declare class MNA { readonly size: number; readonly G: Float64Array; readonly b: Float64Array; /** Diagnostics for the most recently factorised matrix. */ lastSolveInfo: MnaSolveInfo; private factorization; private factorizedMatrix; private baseMatrix; private baseRhs; private matrixDirty; /** Monotonic diagnostic counter; never affects factorization validity. */ factorizationCount: number; factorizationReuseCount: number; constructor(size: number); clear(): void; add(row: number, col: number, val: number): void; addB(row: number, val: number): void; /** Save the current matrix/RHS as the immutable per-topology stamp base. */ captureBase(): void; /** Restore the compiled base before adding dynamic/nonlinear overlays. */ resetToBase(): void; /** * Solve G·x = b using equilibrated LU with partial pivoting. * * MNA mixes conductance rows with ideal-source constraint rows, so raw * coefficients can differ by many orders of magnitude. Row and column * equilibration makes the pivot test relative to the matrix instead of an * arbitrary absolute unit. The factorisation is retained so small-signal * probe solves can reuse it without another O(n³) decomposition. */ solve(): Float64Array; /** Solve G·x = rhs, reusing the latest factorisation when G is unchanged. */ solveRhs(rhs: ArrayLike): Float64Array; private factor; /** Exact numeric guard: a stale LU can never be reused on a changed matrix. */ private matrixMatchesFactorized; } export interface MnaSolveInfo { singular: boolean; illConditioned: boolean; rank: number; /** Smallest accepted pivot after row/column equilibration. */ minScaledPivot: number; /** * Backward error in the original, unscaled matrix units: the largest * |G·x - b| over max(|G|max·|x|max + |b|max, RESIDUAL_SCALE_FLOOR). */ relativeResidual: number; nonFinite: boolean; }