/** * MNA stamp functions for each element type. * * Convention: i, j = node indices in the MNA matrix. -1 = ground (excluded * from matrix). k = extra-variable row for voltage sources. * * Capacitor / Inductor use backward-Euler companion models with optional * lumped loss terms: * Cap branch: series ESR + ideal C, with terminal-parallel leakage R. * Ind branch: series winding DCR + ideal L, with terminal-parallel core R. * Absent loss parameters preserve the historical ideal companions exactly. * * The *Trap variants are opt-in trapezoidal companions (engine * integrationMethod "trap"). They are additive: the backward-Euler functions * above them remain the default and are never altered, so default-mode * trajectories stay byte-identical. */ import type { MnaStampSurface } from "./linear-system.js"; export declare function stampResistor(mna: MnaStampSurface, i: number, j: number, R: number): void; /** * Voltage source: k is the extra-variable row allocated by the caller. * Positive current flows i → j through the source. */ export declare function stampVSource(mna: MnaStampSurface, i: number, j: number, k: number, V: number): void; /** * Voltage source with series resistance — Thevenin equivalent. * * When rSeries = 0 this is byte-identical to stampVSource. * * Physical terminal voltage: * V_term = V_i − V_j = Voc − rSeries × I_delivered * * MNA sign note: in the standard vsource stamp, mna.add(i, k, +1) means x[k] * is the current ENTERING the source branch from node i. When the source * delivers current into the external circuit, x[k] < 0 (x[k] = −I_delivered). * Therefore the KVL row that produces the correct sag is: * V_i − V_j − rSeries × x[k] = Voc → G[k][k] = −rSeries * * x[k] is still the branch current variable, so _updateElementI is unchanged. * * Example: Voc = 9, rSeries = 1.5, R_load = 10 → * I_delivered = 9 / (1.5 + 10) = 0.783 A * V_term = 9 − 1.5 × 0.783 = 7.826 V */ export declare function stampVSourceSeriesR(mna: MnaStampSurface, i: number, j: number, k: number, V: number, rSeries: number): void; /** * Independent current source driving current I INTO node i and OUT of node j. * * Standard MNA: only the RHS vector is touched — the conductance matrix has no * off-diagonal entry for an ideal current source. Sign convention follows the * capacitor/inductor companion sources: addB(i, +I) injects current at i, * addB(j, -I) removes it at j, consistent with KCL (current leaving a node is * positive in the conductance-form equation). * * Ground row (index -1) is excluded, mirroring stampResistor. */ export declare function stampCurrentSource(mna: MnaStampSurface, i: number, j: number, I: number): void; export interface CapacitorCompanion { /** Norton conductance of the series ESR + companion capacitor branch. */ conductance: number; /** * G * history voltage from the previous accepted step: the internal * capacitor voltage for backward Euler, augmented with the (h/2C)·iPrev * term for the trapezoidal variant. */ historyCurrent: number; } /** * Backward-Euler companion for an ideal capacitor C in series with ESR. * * Let v be the terminal voltage, vcPrev the prior internal capacitor voltage, * and i positive from pin i to pin j: * i = C/h * (vc - vcPrev) * v = vc + ESR*i * Therefore: * i = G*(v - vcPrev), where G = 1 / (ESR + h/C) */ export declare function capacitorCompanion(C: number, h: number, vcPrev: number, esr?: number): CapacitorCompanion; /** Series-branch current through ESR and C, positive i→j. */ export declare function capacitorSeriesCurrent(terminalVoltage: number, C: number, h: number, vcPrev: number, esr?: number): number; /** * Internal capacitor voltage after the accepted backward-Euler step. * * Advancing vc from i=C·dvc/dt avoids subtracting two nearly equal voltages * when ESR is large compared with h/C. It is algebraically identical to * vc=terminalVoltage-ESR·i for the solved companion branch. */ export declare function capacitorInternalVoltage(vcPrev: number, seriesCurrent: number, C: number, h: number): number; /** Current through an optional terminal-parallel loss resistance. */ export declare function parallelLossCurrent(voltage: number, resistance: number): number; /** * Capacitor companion (backward Euler). * vcPrev is the internal ideal-capacitor voltage from the prior accepted step. * leakageResistance is a physical resistor in parallel with the full terminals. */ export declare function stampCapacitor(mna: MnaStampSurface, i: number, j: number, C: number, h: number, vcPrev: number, esr?: number, leakageResistance?: number): void; /** * Trapezoidal companion for an ideal capacitor C in series with ESR. * * Trapezoidal rule on i = C·dvc/dt averages the endpoint currents: * vc_new = vcPrev + (h/(2C))·(i_new + iPrev) * Substituting the terminal law v = vc + ESR·i and solving for i_new: * v = vcPrev + (h/(2C))·iPrev + (ESR + h/(2C))·i_new * i_new = G·(v - vcPrev - (h/(2C))·iPrev), G = 1/(ESR + h/(2C)) * This is exactly the backward-Euler companion with h replaced by h/2 and the * history voltage augmented to vcPrev + (h/(2C))·iPrev; the extra term carries * the previous accepted branch current that gives second-order accuracy. * * iPrev must be the series-branch current committed at the last ACCEPTED step * (never a Newton iterate), or step-doubling rollback would not be replayable. */ export declare function capacitorCompanionTrap(C: number, h: number, vcPrev: number, iPrev: number, esr?: number): CapacitorCompanion; /** Series-branch current for the trapezoidal companion, positive i→j. */ export declare function capacitorSeriesCurrentTrap(terminalVoltage: number, C: number, h: number, vcPrev: number, iPrev: number, esr?: number): number; /** * Internal capacitor voltage after an accepted trapezoidal step: * vc_new = vcPrev + (h/(2C))·(iNew + iPrev) * Advancing vc from the integrated current mirrors capacitorInternalVoltage's * rationale: it avoids subtracting nearly equal terminal/ESR voltages and is * algebraically identical to vc = terminalVoltage - ESR·iNew for the solved * companion branch. */ export declare function capacitorInternalVoltageTrap(vcPrev: number, iPrev: number, iNew: number, C: number, h: number): number; /** * Capacitor companion (trapezoidal). Identical stamp topology to * stampCapacitor; only the companion coefficients differ. The leakage * resistance stays a plain terminal shunt — it is resistive, so it has no * integration-order dependence. */ export declare function stampCapacitorTrap(mna: MnaStampSurface, i: number, j: number, C: number, h: number, vcPrev: number, iPrev: number, esr?: number, leakageResistance?: number): void; export interface InductorCompanion { /** Norton conductance of the series DCR + companion inductor branch. */ conductance: number; /** * History current flowing i→j: the decayed previous winding current for * backward Euler, plus the averaged previous terminal voltage term for the * trapezoidal variant. */ historyCurrent: number; } /** * Backward-Euler companion for ideal L in series with winding DCR: * v = L/h * (i - iPrev) + DCR*i * i = G*v + I_hist * G = h / (L + DCR*h) * I_hist = L/(L + DCR*h) * iPrev */ export declare function inductorCompanion(L: number, h: number, iPrev: number, dcr?: number): InductorCompanion; /** Winding-branch current through DCR and L, positive i→j. */ export declare function inductorWindingCurrent(terminalVoltage: number, L: number, h: number, iPrev: number, dcr?: number): number; /** * Inductor companion (backward Euler). coreLossResistance is a declared * terminal-parallel approximation; saturation and frequency dependence remain * outside this lumped model. */ export declare function stampInductor(mna: MnaStampSurface, i: number, j: number, L: number, h: number, iPrev: number, dcr?: number, coreLossResistance?: number): void; /** * Trapezoidal companion for ideal L in series with winding DCR. * * Trapezoidal rule on v = L·di/dt + DCR·i averages both endpoint voltages: * (i_new - iPrev)/h = (1/(2L))·((v_new - DCR·i_new) + (vPrev - DCR·iPrev)) * Collecting i_new terms and dividing by h/L: * i_new = [(L/h - DCR/2)·iPrev + (v_new + vPrev)/2] / (L/h + DCR/2) * Stamped as a Norton pair: * G = (1/2)/(L/h + DCR/2) = h/(2L + DCR·h) * I_hist = [(L/h - DCR/2)·iPrev + vPrev/2] / (L/h + DCR/2) * * vPrev is the terminal voltage of the WINDING branch (series DCR + L) at the * last ACCEPTED step. The optional core-loss resistor is a separate terminal * shunt, exactly as in the backward-Euler model, so the same terminal voltage * serves both and no loss-current subtraction is needed. */ export declare function inductorCompanionTrap(L: number, h: number, iPrev: number, vPrev: number, dcr?: number): InductorCompanion; /** Winding-branch current for the trapezoidal companion, positive i→j. */ export declare function inductorWindingCurrentTrap(terminalVoltage: number, L: number, h: number, iPrev: number, vPrev: number, dcr?: number): number; /** * Inductor companion (trapezoidal). Identical stamp topology to stampInductor; * only the companion coefficients differ. coreLossResistance remains the same * declared terminal-parallel approximation. */ export declare function stampInductorTrap(mna: MnaStampSurface, i: number, j: number, L: number, h: number, iPrev: number, vPrev: number, dcr?: number, coreLossResistance?: number): void; export interface CoupledInductorCompanion { /** Self conductance of winding 1 in the inverted 2x2 block. */ g11: number; /** Mutual conductance (symmetric: G12 = G21). */ g12: number; /** Self conductance of winding 2. */ g22: number; /** Norton history current of winding 1, flowing a1 -> b1. */ ih1: number; /** Norton history current of winding 2, flowing a2 -> b2. */ ih2: number; } /** * Backward-Euler companion for two magnetically coupled windings with * series resistances (transformer / coupled inductor). * * Continuous equations (dot convention: a1 and a2 are the dotted terminals, * so positive i1 into a1 and positive i2 into a2 both magnetize the core in * the same sense; v_w = v(a_w) - v(b_w), i_w positive a_w -> b_w): * * v1 = L1·di1/dt + M·di2/dt + DCR1·i1 * v2 = M·di1/dt + L2·di2/dt + DCR2·i2, M = k·sqrt(L1·L2) * * Backward Euler (di/dt -> (i - iPrev)/h) turns both into one linear system * A·[i1, i2]^T = [v1, v2]^T + c with * * A = | L1/h + DCR1 M/h | c = | (L1·i1Prev + M·i2Prev)/h | * | M/h L2/h + DCR2 | | (M·i1Prev + L2·i2Prev)/h | * * Inverting the symmetric 2x2 symbolically (det = a11·a22 - a12²) gives the * Norton form the MNA wants: * * [i1, i2]^T = G·[v1, v2]^T + Ihist, G = A⁻¹, Ihist = A⁻¹·c * G11 = a22/det, G22 = a11/det, G12 = G21 = -a12/det * * so each winding stamps a self conductance across its own node pair, a * cross conductance block against the other pair, and a history current * (positive a -> b, exactly the single-inductor companion's convention — * at k = 0 this degenerates to two independent inductorCompanion() results * up to rounding of the shared division). * * Singularity: det -> 0 when k -> 1 with zero winding resistance * (L1·L2 - M² = L1·L2·(1 - k²) vanishes and an ideal transformer has no * admittance representation). Callers must clamp k below 1; the device * model uses 0.9999, which keeps the leakage inductance ~2e-4·L — far * above f64 noise at every circuit scale while staying visually "ideal". */ export declare function coupledInductorCompanion(l1: number, l2: number, m: number, h: number, i1Prev: number, i2Prev: number, dcr1?: number, dcr2?: number): CoupledInductorCompanion; /** * Trapezoidal companion for the coupled windings. Averaging both endpoint * voltages of each continuous equation (the same step inductorCompanionTrap * documents for one winding): * * (v1 + v1Prev)/2 = L1·(i1 - i1Prev)/h + M·(i2 - i2Prev)/h * + DCR1·(i1 + i1Prev)/2 * * and likewise for winding 2. Collecting new-step terms: * * v1 = (2L1/h + DCR1)·i1 + (2M/h)·i2 * - [(2L1/h - DCR1)·i1Prev + (2M/h)·i2Prev + v1Prev] * * i.e. the SAME 2x2 inversion as backward Euler with * * A_trap = | 2L1/h + DCR1 2M/h | * | 2M/h 2L2/h + DCR2 | * * c_trap = | (2L1/h - DCR1)·i1Prev + (2M/h)·i2Prev + v1Prev | * | (2M/h)·i1Prev + (2L2/h - DCR2)·i2Prev + v2Prev | * * At k = 0 each winding reduces exactly to inductorCompanionTrap's algebra * (conductance 1/(2L/h + DCR), history ((2L/h - DCR)·iPrev + vPrev) * / (2L/h + DCR)). vPrev terms are the winding terminal voltages of the * last ACCEPTED step (never a Newton iterate), the same history contract * as the single-inductor trap companion. */ export declare function coupledInductorCompanionTrap(l1: number, l2: number, m: number, h: number, i1Prev: number, i2Prev: number, v1Prev: number, v2Prev: number, dcr1?: number, dcr2?: number): CoupledInductorCompanion; /** * Stamp the coupled-winding companion between the two node pairs. Self * blocks mirror stampConductance's pattern per pair; the cross block writes * the full 2x2 incidence (row pair 1 x column pair 2 and its transpose, * G12 = G21). History currents flow a -> b in each winding, so the RHS * signs match stampInductor's (-Ihist at a, +Ihist at b). */ export declare function stampCoupledInductor(mna: MnaStampSurface, a1: number, b1: number, a2: number, b2: number, companion: CoupledInductorCompanion): void; /** * New-step winding currents of the coupled companion at the solved terminal * voltages — the commit-side counterpart of stampCoupledInductor, mirroring * inductorWindingCurrent's role for the single coil. */ export declare function coupledInductorWindingCurrents(companion: CoupledInductorCompanion, v1: number, v2: number): { i1: number; i2: number; }; /** * Shockley diode / LED — companion model for Newton-Raphson (R2). * * i_d = Is · (exp(v_d / (n·Vt)) - 1) * g_d = di/dv = (i_d + Is) / (n·Vt) * * Linearise about the last-iteration voltage `vPrev`. Using the * tangent line at `vPrev`: * * i_d(v) ≈ g_d · v + (i_d - g_d · vPrev) * = g_d · v + I_eq * * Stamp as a Norton equivalent: conductance `g_d` between i and j, * plus a current source `I_eq` flowing from i to j (i.e. pulled from * node i and pushed into node j in the KCL sense). * * Returns the scalar current `i_d` at `vPrev` so the caller can record * element current for reporting. Callers that don't need it can ignore * the return value. * * Numerical safety: this stamp does a one-shot `vSat` cap on `vPrev` so * `Math.exp` cannot overflow. Standalone diodes/LEDs in this engine are * current-driven (a series resistor or follow-on conductance always * bounds the loop) and are well-conditioned without inter-iteration * damping, so we deliberately skip SPICE `pnjlim` here. The BJT stamper * does apply `pnjlim` upstream in `SimEngine._stampAll`. */ export declare function stampDiodeShockley(mna: MnaStampSurface, i: number, j: number, vPrev: number, Is?: number, n?: number, Vt?: number, vSatOverride?: number): number; /** * Compute Shockley parameters (Is) from a user-facing (Vf, iRated) * pair. `Vf` is the forward voltage at which the diode passes `iRated` * current; solving i_d(Vf)=iRated for Is gives: * * Is = iRated · exp(-Vf / (n·Vt)) * * Used by SimEngine to turn catalog Vf/iRated values into a Shockley * saturation current so the Newton stamp stays self-consistent with * whatever the user typed in the Inspector. */ export declare function shockleyIsFromVf(Vf: number, iRated?: number, n?: number, Vt?: number): number; /** * Evaluate the same guarded Shockley law used by stampDiodeShockley. * * Above the exponential guard the junction continues along the boundary * tangent. Freezing current while retaining the guarded derivative would make * the MNA branch, telemetry, thermal stress, and failure diagnostics disagree * during exactly the overdrive faults where those values matter most. */ export declare function shockleyDiodeCurrent(voltage: number, Is?: number, n?: number, Vt?: number, vSatOverride?: number): number; /** * NOTE on the reverse-breakdown prefactor: the breakdown term below is written * as an OVERDRIVE exponential, iRev = Is_z * exp(-(v + vz) / (nZ*Vt)), whose * exponent is ZERO at the knee (v = -vz). The knee condition |i(-vz)| = izKnee * therefore pins the prefactor directly: Is_z = izKnee. There is nothing to * solve — unlike the forward Shockley, where the exponent at the anchor point * is vf/(n*Vt) and shockleyIsFromVf back-computes Is. A previous revision * mirrored that derivation here (Is_z = izKnee * exp(-vz/(nZ*Vt)) ~ 1e-117 for * a 6.8 V part), which pushed visible conduction out to v ~ -2*vz — an * apparent breakdown at double the rated voltage. */ /** * Evaluate the breakdown diode i(v) at a given voltage without stamping MNA. * Used by both the stamp and _updateElementI so both paths share identical math. * * Equation (v = vAnode - vCathode): * i(v) = Is_f * (exp(v / (nF * Vt)) - 1) * - Is_z * (exp(-(v + vz) / (nZ * Vt)) - 1) * * The forward term is the standard Shockley diode (positive current for v > 0). * The reverse term activates when v goes below -vz, pulling i negative (cathode * to anode), modelling controlled breakdown. Sign convention: positive i = current * flowing anode → cathode (same as a forward-biased diode). * * Clamp logic matches stampBreakdownDiode below — see that comment for rationale. */ export declare function breakdownDiodeCurrent(v: number, Is_f: number, izKnee: number, nF: number, nZ: number, Vt: number, vz: number, vSatFOverride?: number): number; /** * Reverse-breakdown diode stamp — zener / TVS model (R2 Newton-Raphson). * * Full i(v) equation (v = vAnode - vCathode): * * i(v) = Is_f · (exp(v/(nF·Vt)) − 1) * − izKnee · exp(−(v+vz)/(nZ·Vt)) * * Forward component: standard Shockley, Is_f from shockleyIsFromVf(vf, iRated, nF, Vt). * Reverse component: an OVERDRIVE exponential anchored at the knee — its * exponent is zero at v = -vz, so the prefactor IS the knee current * (|i(-vz)| = izKnee by construction; nothing to back-solve). No "-1" term: * anchored at milliamp scale, a (exp − 1) form would leak a constant * -izKnee at all forward biases. nZ = 1 gives a sharp silicon-zener knee. * * Companion model (Newton-Raphson linearisation about vGuess): * g = di/dv = (Is_f · exp(vF/VtNF)) / VtNF * + (izKnee · exp(revArgClamped/VtNZ)) / VtNZ * Ieq = i(vGuess) − g · vGuess * * Clamp rationale: * Forward side: vSatF = vSatFOverride ?? 40·nF·Vt, mirroring * stampDiodeShockley — callers with high forward Vf (the TVS at 1.1 V) * raise it the same way the LED path does. * * Reverse side: cap the OVERDRIVE -(v+vz) at 5·nZ·Vt (~0.13 V past the * knee). Beyond that the junction is deep in avalanche and the current is * limited by the series circuit, not the junction; the constant-slope * tangent extension keeps Newton well-conditioned. * * Returns the scalar current i(vGuess) at the linearisation point. */ export declare function stampBreakdownDiode(mna: MnaStampSurface, i: number, j: number, vGuess: number, Is_f: number, izKnee: number, nF: number, nZ: number, Vt: number, vz: number, vSatFOverride?: number): number; /** Terminal currents and the full Jacobian of the Ebers-Moll BJT at a bias. */ export interface BjtLinearization { ib: number; ic: number; ie: number; /** Jacobian entries: row = terminal KCL, col = node voltage. */ gbB: number; gbC: number; gbE: number; gcB: number; gcC: number; gcE: number; geB: number; geC: number; geE: number; } /** * Pure Ebers-Moll linearization at a node-voltage triple — the terminal * currents plus the exact Jacobian stampBJT writes into the matrix. Factored * out of stampBJT (Wave A5) so the small-signal AC analysis stamps the * identical conductance entries the Newton solve used at the operating * point; stampBJT's arithmetic (expression order included) is unchanged, it * now just reads these values instead of computing them inline. See * stampBJT's comment for the model derivation and sign conventions. */ export declare function bjtLinearization(vB: number, vC: number, vE: number, polarity: 1 | -1, Is?: number, betaF?: number, betaR?: number, nF?: number, nR?: number, Vt?: number, earlyVoltage?: number): BjtLinearization; /** * BJT — transport-form Ebers-Moll (R2). * * Terminal currents (NPN; polarity flag flips sign for PNP): * * V_BE = V_B - V_E V_BC = V_B - V_C * I_F = Is · (exp(V_BE/(n_F·Vt)) - 1) "forward" BE injection * I_R = Is · (exp(V_BC/(n_R·Vt)) - 1) "reverse" BC injection * g_F = (I_F + Is) / (n_F·Vt) * g_R = (I_R + Is) / (n_R·Vt) * M_E = max(0, 1 + V_CE/V_A) when V_A > 0, otherwise 1 * * I_c = I_F·M_E - I_R·(1 + 1/β_R) * I_b = I_F/β_F + I_R/β_R * I_e = -(I_c + I_b) * * PNP is the same topology with inverted junction biases; we compute * with V_BE/V_BC pre-multiplied by polarity and then multiply the * resulting terminal currents by polarity. * * Conductance entries (the Jacobian of I_terminal wrt V_node) are * identical for NPN and PNP — the two polarity factors cancel through * the chain rule. Only the companion RHS current flips sign. * * Stamps into `mna` and returns the three terminal currents at the * linearisation point so the caller can (a) report element current and * (b) compute the companion RHS without recomputing the exponentials. */ export declare function stampBJT(mna: MnaStampSurface, b: number, c: number, e: number, vBprev: number, vCprev: number, vEprev: number, polarity: 1 | -1, Is?: number, betaF?: number, betaR?: number, nF?: number, nR?: number, Vt?: number, earlyVoltage?: number): { ib: number; ic: number; ie: number; }; /** Pure BJT terminal-current computation — used by `_updateElementI` to * report per-component current at the converged solution without * restamping the matrix. Mirrors the math inside `stampBJT`. */ export declare function bjtCurrents(vB: number, vC: number, vE: number, polarity: 1 | -1, Is?: number, betaF?: number, betaR?: number, nF?: number, nR?: number, Vt?: number, earlyVoltage?: number): { ib: number; ic: number; ie: number; }; /** * MOSFET — Shichman-Hodges level-1 (R2) WITH intrinsic body diode. * * Three terminals (D, G, S); bulk is assumed tied to source. Polarity * flag flips sign for PMOS. VTO is a positive magnitude in both cases — * the polarity flag (not a signed threshold) selects the channel type, * which matches how users think about it in a schematic. * * K = (KP/2)·(W/L) * V_GS = V_G - V_S V_DS = V_D - V_S * V_ov = V_GS - VTO * * cutoff (V_ov ≤ 0): I_d = 0 * triode (V_DS < V_ov): I_d = K·(2·V_ov·V_DS - V_DS²)·(1+λ·V_DS) * saturation (V_DS ≥ V_ov): I_d = K·V_ov²·(1+λ·V_DS) * * Conductances: * g_m = ∂I_d/∂V_GS * g_ds = ∂I_d/∂V_DS * The DC gate is ideal. Optional Cgs/Cgd values are stamped as true * two-terminal backward-Euler companions, so transient gate drive and Miller * coupling conserve charge without a hidden reference node. * * Body diode (intrinsic to all real MOSFETs — bulk tied to source): * NMOS (pol=+1): anode=source, cathode=drain. * Conducts when V_S − V_D > Vf (≈0.7 V), i.e. the device is reverse- * biased or the load is pulling D below S (inductive kick / H-bridge * freewheel). In MNA terms: Shockley stamp with i=source, j=drain. * PMOS (pol=−1): anode=drain, cathode=source (mirror). * Conducts when V_D − V_S > Vf. * Body-diode Is derived from shockleyIsFromVf(0.7, 1.0) → Is_body. * The channel current and body-diode current both sum at d/s nodes. * * BEHAVIOUR CHANGE: a reverse-biased MOSFET now freewheels above ~0.7 V * instead of blocking. Existing NMOS/PMOS fixtures with forward V_DS are * unaffected (body diode reverse-biased → near-zero leakage only). * * Stamp on node indices (d, g, s) with polarity-flipped V_GS / V_DS * (same trick as BJT); the resulting conductance entries are identical * for NMOS and PMOS, only the companion RHS current flips sign. */ export declare function stampMOSFET(mna: MnaStampSurface, d: number, g: number, s: number, vDprev: number, vGprev: number, vSprev: number, polarity: 1 | -1, VTO?: number, K?: number, lambda_?: number, bodyDiodeVf?: number, thermalV?: number, gateDynamics?: { h: number; cgs: number; cgd: number; vgsPrev: number; vgdPrev: number; }): { id: number; }; export interface OpAmpDominantPoleCompanion { /** Open-loop dominant-pole frequency, GBW/A0, in hertz. */ poleHz: number; /** Coefficient multiplying the present input differential. */ differentialGain: number; /** Coefficient multiplying the previous internal gain-stage voltage. */ historyGain: number; /** Coefficient multiplying the DC output offset. */ offsetGain: number; } /** * Backward-Euler companion for a one-pole op-amp gain stage. * * A(s) = A0 / (1 + s/wp), wp = 2*pi*GBW/A0 * du/dt = wp * (A0*vd + offset - u) * * Backward Euler gives: * u[n] = historyGain*u[n-1] * + differentialGain*vd[n] * + offsetGain*offset * * A non-positive GBW intentionally selects the historical instantaneous VCVS. */ export declare function opAmpDominantPoleCompanion(openLoopGain: number, gbwHz: number, h: number): OpAmpDominantPoleCompanion; /** Unconstrained internal gain-stage voltage for one accepted BE step. */ export declare function opAmpTransientTarget(previousInternalVoltage: number, inputDifferential: number, openLoopGain: number, outputOffset: number, gbwHz: number, h: number): number; /** Apply a symmetric large-signal slew ceiling to an internal-voltage step. */ export declare function opAmpSlewLimitedTarget(previousInternalVoltage: number, unconstrainedTarget: number, slewRateVPerSecond: number, h: number): number; export type OpAmpCurrentLimitMode = -1 | 0 | 1; /** * Commit a source (-1), voltage (0), or sink (+1) output-current regime. * naturalCurrent uses stampOpAmp's branch convention: negative sources load * current and positive sinks it. Hysteresis lets a constrained output recover * without chattering at the exact limit. */ export declare function opAmpCurrentLimitMode(previousMode: number, naturalCurrent: number, sourceLimitA: number, sinkLimitA: number): OpAmpCurrentLimitMode; export interface OpAmpTransientStamp { h: number; gbwHz: number; previousInternalVoltage: number; /** Signed branch current constraint; null keeps voltage-source operation. */ currentConstraint?: number | null; } /** * Op-amp macro model — dominant-pole VCVS with rail, slew, and current clamps. * * Three-terminal ideal model: in_minus (-), in_plus (+), out. * The extra-variable row `k` carries the output source current, exactly * like a voltage source. The caller selects the present piecewise-linear * region: dominant-pole voltage operation, a fixed rail/slew target, or a * signed current constraint. * * The stamp is ALWAYS emitted (even when unpowered) so the matrix row is never * all-zero. When unpowered, vHigh ≈ vLow ≈ 0, causing the output to be * clamped to 0 V — a reasonable unpowered model — without any singular row. * The row is non-singular in all regimes: voltage operation writes V_out and * current-limit operation writes x[k]. * * Linear regime (vLow < vOffset + A·(V+ − V−) < vHigh): * KVL row k: V_out − A·(V+ − V−) = vOffset * → G[k][out] += 1, G[k][+] −= A, G[k][−] += A, b[k] = vOffset * * Saturated regime: * KVL row k: V_out = vHigh (or vLow) * → G[k][out] += 1, b[k] = vHigh (or vLow) * * In both regimes the output-source current i_k flows into `out`: * G[out][k] += 1 * * Parameters: * vHigh — upper saturation rail (absolute node volts, e.g. vcc - headroom) * vLow — lower saturation rail (absolute node volts, e.g. gnd + headroom) * vOffset — DC bias added to the VCVS output before clamping; used for the * LM386 mid-supply self-bias. Pass 0 for standard op-amps. * outputResistance — finite closed-loop output-stage resistance. The KVL * row becomes Vout - R_out*i_k = Vtarget. Because i_k is negative * while the amplifier sources a load, this produces the expected * load-dependent droop and prevents an unphysical infinite short- * circuit current. Pass 0 only for an intentionally ideal model. * transient — optional backward-Euler dominant-pole state and signed current * constraint. Omitting it preserves the historical static VCVS. */ export declare function stampOpAmp(mna: MnaStampSurface, inMinus: number, inPlus: number, out: number, k: number, A: number, vOffset: number, saturatedRail: number | null, outputResistance?: number, transient?: OpAmpTransientStamp | null): void; /** * Legacy pure output-saturation state helper, retained for compatibility with * callers of the original static VCVS API. The transient engine now uses the * bounded dominant-pole active set above instead. * * ideal = vOffset + A·(V+ − V−) — the unclamped output the gain stage wants, * reconstructed from the committed input * differential (works for both feedback * op-amps where A is huge and fixed-gain * parts like the LM386 where A is small). * * Transitions (prevRegime: 0 linear, 1 hi-rail, 2 lo-rail; NaN ⇒ linear): * - from linear: enter a rail only if `ideal` exceeds it. * - from a rail: STAY only while `ideal` still exceeds that same rail; * otherwise relax to LINEAR — never jump straight to the opposite rail. * The relax-to-linear step re-solves the unclamped output and the next * commit re-decides cleanly. Jumping rail→rail directly is what oscillates; * staying latched at a rail is what never recovers — this avoids both. */ export declare function opAmpRegime(prevRegime: number, ideal: number, vHigh: number, vLow: number): 0 | 1 | 2; /** * Stamps a 3-terminal linear voltage regulator into the MNA matrix. * * Terminals: inNode (input), refNode (gnd or adj pin), outNode (output). * Branch row k holds the branch current — current flows IN → OUT, so * it is DRAWN from the input and DELIVERED to the output. * * Current coupling: in REG/DROPOUT/CC the branch current i represents physical * current flowing from inNode to outNode. The gnd/adj pin (refNode) carries * negligible current and is used only as a voltage reference. OFF retains the * same matrix topology, but pins i=0 so neither terminal loads the other. * if (outNode >= 0) mna.add(outNode, k, +1) — delivers current to output * if (inNode >= 0) mna.add(inNode, k, -1) — draws current from input * * Four regimes (decided at commit, NEVER re-decided from within-iteration xGuess): * REG (0): V_out − V_ref = Vreg (regulated; ref=gnd for a fixed regulator, * ref=adj for LM317 so V_out−V_adj=1.25 V) * DROPOUT (1): V_out − V_in = −vdropout (pass transistor saturated; output * tracks input minus a fixed drop) * CC (2): i = iLimit (current-limited below compliance; * KCL sets V_out = iLimit * R_load) * OFF (3): i = 0 (pass path disabled; output is high-Z) * * The row k constraint is NEVER all-zero: * REG → row k has +1 on V_out column * DROPOUT → row k has +1 on V_out column * CC → row k has +1 on x[k] itself * OFF → row k has +1 on x[k] itself * * `SimEngine` wraps CC with a monotonic per-solve active set. If the KCL * solution reaches the available REG/DROPOUT voltage, it re-stamps that * compliance branch before accepting the step; this primitive therefore never * leaves an open/light load as a committed unconstrained current source. */ export declare function stampLinearRegulator(mna: MnaStampSurface, inNode: number, refNode: number, outNode: number, k: number, regime: number, Vreg: number, vdropout: number, iLimit: number): void; /** * Regime state machine for a linear voltage regulator. Pure function — call * ONLY at commit (post-solve, stable x), never from within the Newton loop. * * Inputs (all from the committed solution): * prevRegime — NaN on first step; 0=REG, 1=DROPOUT, 2=CC, 3=OFF thereafter. * i — branch current x[k] (positive = flowing in→out). * vIn — committed voltage at the input pin. * vRef — committed voltage at the ref pin (gnd or adj). * Vreg — regulated voltage above vRef (e.g. 5.0 for 7805, 1.25 for LM317). * vdropout — minimum headroom required above the regulated point (e.g. 2.0 V). * iLimit — maximum output current in amps. * complianceSelected — the accepted solve's own current-limit compliance * decision (ctx.currentLimitComplianceClampActive): its CC * candidate reached the REG/DROPOUT voltage, so it stamped * that voltage branch instead of CC. * * Transition table: * prevRegime = NaN/initial * headroom = vIn − vRef * → headroom <= vdropout → OFF (3) * → headroom < Vreg + vdropout → DROPOUT (1) * → else → REG (0) * * from REG (0) * → i > iLimit*1.001 → CC (2) * → headroom < Vreg + vdropout → DROPOUT (1) * → else → REG (0) * * from DROPOUT (1) * → headroom >= Vreg + vdropout → REG (0) * → i > iLimit*1.001 → CC (2) * → else → DROPOUT (1) * * from CC (2) * → complianceSelected and headroom < Vreg + vdropout → DROPOUT (1) * → complianceSelected → REG (0) [load eased, output recovered] * → else → CC (2) * * from OFF (3) * → headroom >= Vreg + vdropout → REG (0) * → headroom > vdropout → DROPOUT (1) * → else → OFF (3) * * (Every regime first goes OFF when headroom <= vdropout.) * * The 1.001 factor keeps REG/DROPOUT from chattering into CC at the limit. * CC needs no margin of its own: it leaves exactly when the solve did. */ export declare function regulatorRegime(prevRegime: number, i: number, vIn: number, vRef: number, Vreg: number, vdropout: number, iLimit: number, complianceSelected: boolean): 0 | 1 | 2 | 3; /** Pure MOSFET drain-current computation — matches `stampMOSFET` math. */ export declare function mosDrainCurrent(vD: number, vG: number, vS: number, polarity: 1 | -1, VTO?: number, K?: number, lambda_?: number): number; /** Drain current and channel small-signal slopes of the JFET law below. */ export interface JfetLinearization { /** Polarity-corrected drain current (positive into the drain terminal). */ id: number; /** dId/dVgs at the bias (polarity-invariant, like the MOSFET Jacobian). */ gm: number; /** dId/dVds at the bias, floored at GMIN so D-S never floats in cutoff. */ gds: number; } /** * Shichman-Hodges JFET channel linearization at a node-voltage triple. * * Same quadratic law as the level-1 MOSFET but in the depletion-mode * convention: `vto` is SIGNED AND NEGATIVE for both channel types (n-JFET * vto = -2 V conducts at vGS = 0 and pinches off at vGS <= -2 V; the p-JFET * uses the same negative number against polarity-flipped voltages, exactly * the MOSFET polarity trick). beta comes from the datasheet pair * (idss, vto) via beta = idss/vto², so Id(vGS = 0) = idss in saturation by * construction. * * vGS' = pol·(vG - vS), vDS' = pol·(vD - vS), vOV = vGS' - vto * cutoff (vOV <= 0): Id = 0 * triode (vDS' < vOV): Id = beta·(2·vOV·vDS' - vDS'²)·(1 + λ·vDS') * saturation (vDS' >= vOV): Id = beta·vOV²·(1 + λ·vDS') * * Like stampMOSFET, the law is valid for forward operation (vDS' >= 0); * gm/gds are the exact partial derivatives of each region and the GMIN * floor mirrors the MOSFET stamp's conditioning guard. No body diode here — * a JFET's gate-channel junctions are stamped separately by the caller. */ export declare function jfetLinearization(vD: number, vG: number, vS: number, polarity: 1 | -1, vto: number, beta: number, lambda_?: number): JfetLinearization; /** * Stamp the JFET channel as the Newton VCCS companion — the identical * matrix/RHS pattern stampMOSFET writes for its channel (the chain-rule * polarity factors cancel in the Jacobian, only the companion current * flips), without the MOSFET's intrinsic body diode or gate charge. The * caller stamps the gate-channel junction diodes on top; the DC gate here * carries no current. Returns the drain current at the linearisation point. */ export declare function stampJFET(mna: MnaStampSurface, d: number, g: number, s: number, vDprev: number, vGprev: number, vSprev: number, polarity: 1 | -1, vto: number, beta: number, lambda_?: number): { id: number; };