Algorithmadvanced
Shooting Newton periodic steady state
Also called Aprille-Trick shooting, periodic steady-state shooting.
Aprille and Trick's method that searches for the initial state whose transient over one period returns to itself, solved by Newton with the sensitivity matrix.
- Time
- O(I S n^3) worst
- Space
- O(n^2 + S n) extra
- Where
- I = the number of Newton iterations; S = the number of time steps per period; n = the number of MNA unknowns
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Thomas J. Aprille, Timothy N. Trick, 1972
Shooting Newton finds the periodic steady state of a circuit with periodic sources by searching for the initial state from which one period of transient analysis returns to the same state. Aprille and Trick (1972) solved this condition, , with Newton's method, and got the Jacobian from the sensitivity of the transient to its initial state, the monodromy matrix. It belongs to the circuit simulation half of the logic and circuit simulation sub-area, next to harmonic balance, and it suits circuits with sharp edges and slow time constants.
In plain words
A circuit with a slow filter can take thousands of periods to settle after power-up. A plain transient run must simulate all of them, even when only the final repeating waveform matters.
Shooting asks a sharper question: from which starting state does one period of simulation end exactly where it started? It guesses a start, simulates one period, and sees how far the end is from the start. It also tracks how the end would move if the start moved a little. With that information it corrects the guess, as a gunner corrects the aim after one shot. For a linear circuit the second guess is right; for a nonlinear one a few more corrections usually suffice, and each costs about one period of simulation.
The problem
The circuit is in modified nodal analysis form, , with , , , and every source has period . A periodic steady state is a solution with . Its initial state is a root of
where is the state at time of the transient that starts at . This is the shooting method for a boundary value problem whose boundary condition is periodicity.
In practice is the transient analysis with fixed steps of size , with the trapezoidal rule () or backward Euler ():
The method finds the exact periodic solution of this discrete map, which differs from the continuous steady state by the integration error. Input: the circuit, , , and a start. Output: and the states of one period. The device equations have fitted parameters: in the example, the diode saturation current and emission coefficient are fitted to measurements.
The algorithm
SHOOT(circuit, T, S, θ)- 1
x₀ ← a start state (zero, or the DC operating point); h ← T/S - 2
repeat - 3
for k = 0, ..., S − 1: x_{k+1} ← one implicit step from x_k at time kh - 4
Φ ← (C_{k+1} + θhG_{k+1})⁻¹ (C_k − (1 − θ)hG_k) Φ, starting from Φ = I - 5
r ← x_S − x₀ - 6
solve (Φ − I)Δ = −r; x₀ ← x₀ + λΔ with a step limit λ ≤ 1 - 7
until λ = 1 and Δ is small - 8
return x₀ and the states x_0, ..., x_S of one period
Line L3 is an ordinary transient step: Newton's method on the step equation, with the matrix of the companion model. Line L4 is the extra work of shooting. Differentiating the step equation with respect to gives , and the matrix on the left is the one the step has just factored. After steps, is the monodromy matrix of the discrete map, and line L6 is exactly Newton's step for . The step limit keeps node voltages from moving more than 1 V per iteration.
The implementation stores as a dense matrix and solves line L6 directly. For large circuits, Telichevesky, Kundert and White (1995) never form : they solve line L6 with GMRES, and each product is one pass of triangular solves with the stored factors of the steps.
Example
An RC circuit, by hand. A current source drives kΩ in parallel with , where MHz and . The continuous steady state is , so . With the trapezoidal rule and , starting from , one period ends at V. Each step multiplies a change of the state by with , so , close to . Newton gives V. A second period from this state returns to it to rounding, so the method stops after one correction. The value is the exact steady state of the discrete map, the AC phasor at the warped frequency , and it differs from 0.5 by , the second-order error of the integration.
A rectifier with a slow load, measured. A 2 V, 1 MHz sine source behind 1 kΩ (with 10 pF at its node) drives a diode into a load of 100 kΩ in parallel with 1 nF, a time constant of 100 periods. The diode has A and , fitted values for a small silicon diode. With the trapezoidal rule and , shooting from zero needs 7 Newton iterations. The residual of the successive iterations was:
| iteration | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| residual (V) | 0.286 | 0.0503 | 0.00745 | 4.97e-4 | 3.27e-6 | 1.47e-10 | 8.9e-16 |
The last steps show the quadratic convergence of Newton's method: from iteration 4 to 6, each residual is about 13 times the square of the one before, and iteration 7 reaches rounding. The output settles at a mean of 1.2569 V with a ripple of 10.7 mV. The plain transient from zero with the same steps needs 155 periods before changes by less than 1 nV in one period, and it then stops V from the shooting result. The dominant eigenvalue of at the steady state is 0.8906, which is the factor by which the transient's error falls in each period. Measured with Python's process time on one machine, shooting took 0.04 s and the transient 0.69 s. With and the iteration counts and residuals are the same, and the output voltage at changes by V and then V, a factor of 4 per halving of .
Correctness
The proof in proofs/correctness.md shows:
- A periodic steady state is a root of . The sources repeat after steps, so the step maps repeat, and a solution with repeats forever. The same argument holds for the exact flow when its initial value problem has unique solutions.
- Shooting Newton uses the monodromy matrix. By implicit differentiation of each step and the chain rule, the product of line L4 is , so is the Jacobian of and line L6 is Newton's step; it converges quadratically near a root where is nonsingular.
- Linear circuits. is affine, so one Newton step solves it, and the discrete steady state for a sinusoidal source is the AC phasor at the frequency (trapezoidal) or (backward Euler), within or of the exact one.
- The trapezoidal rule and algebraic rows. For a row with no charge term, such as a voltage source, the trapezoidal rule gives , so is singular for even ; backward Euler gives .
The discretization error for nonlinear circuits and the convergence rate of the plain transient are measured, not proved.
The tests check, with fixed seeds:
- A parallel RLC circuit with the trapezoidal rule at : one Newton step, and every state equal to the warped-frequency phasor to .
- An RC circuit with a voltage source and backward Euler: the same against its discrete phasor.
- The error against the analytic steady state: , and V, a ratio of 4.0 per halving.
- against central differences of the period map for random starts (seed 61), to a relative error of .
- The rectifier against the long transient, and the quadratic decrease of the residuals.
- The identity for and for with the trapezoidal rule, and with backward Euler. With , the Newton matrix has an exactly zero pivot.
Proof: A periodic steady state is a root of x(T) − x(0), and shooting Newton uses the monodromy matrixfull
We use the notation of the page. The circuit is with unknowns, and continuously differentiable with Jacobians and , and . The step is , , , and (trapezoidal rule) or (backward Euler). One step from to solves
Put and , so that and . We assume that every met is nonsingular and that (1) has exactly one solution in the region where the iterates stay. Then (1) defines a step map , and by the implicit function theorem is continuously differentiable with . The period map is .
Fixed points are periodic steady states
Theorem 1. Let solve (1) for every . The sequence is periodic with period (that is, for all ) if and only if , that is, if and only if is a root of .
Proof. If the sequence is -periodic, then . Conversely, , and and do not depend on time, so and for every . Suppose . By induction on , if then .
The same argument holds for the exact solution. If the initial value problem has a unique solution from every consistent state, the solution from satisfies for all if and only if , because solves the same equation with the same value at . So the periodic steady state of the circuit is a root of , and the discrete problem replaces by .
The Newton matrix is the monodromy matrix minus the identity
Theorem 2. Let and . Then , and the step of line L6, , is the Newton step for .
Proof. By the chain rule, , with . So for every by induction, and .
is the monodromy matrix of the discrete map: it carries a small change of the state at to its change one period later. The cost of is small next to the transient itself, because is the matrix that the last Newton iteration of step has already factored.
Corollary 1 (local convergence). If and are twice continuously differentiable and is nonsingular at a root , then the full-step iteration converges quadratically from every start close enough to . This is the local theorem for Newton's method for systems applied to , whose derivative is Lipschitz near under these assumptions.
Linear circuits
Theorem 3. Let and with constant matrices, and let be nonsingular. Then:
- is affine, so Newton reaches its unique root in one step from any start.
- If with , the discrete steady state is , where and, with ,
provided and are nonsingular.
- For the trapezoidal rule , so differs from the AC phasor by ; for backward Euler .
Proof. 1. Each is affine, with constant and , so and are affine and ; the Newton step makes this zero.
-
Put , so . For , the step (1) applied to with the complex source reads . Divide by , which is nonzero because , to get . For , ; divide by . The recurrence is real and linear, so the real part of a complex solution is a solution for the real source. The sequence is -periodic because , so by Theorem 1 and the uniqueness in 1 it is the discrete steady state. Finally for .
-
gives . For backward Euler, . Near the map is differentiable when is nonsingular, so .
Algebraic rows and the trapezoidal rule
MNA equations are differential-algebraic: the row of a voltage source, for example, is and has no charge term.
Lemma 4. Let row of be zero for every and let row of be linear, . Then for the trapezoidal rule, and for backward Euler. So for the trapezoidal rule with even , and the Newton matrix is singular.
Proof. Row of is and row of is . Row of gives . For this is , and steps from give . For it is .
The cause is that the trapezoidal rule does not damp the algebraic part: an error in changes sign at every step and never decays. The remedies are backward Euler or another damped method, an odd , or shooting on the state variables only (capacitor charges and inductor fluxes), which is the form in which Aprille and Trick stated the method.
What is not proved
- Existence and uniqueness of a periodic steady state, and the nonsingularity of at the root, are assumed. A Floquet multiplier (an eigenvalue of ) equal to 1 makes the Newton matrix singular; this is always the case for an autonomous oscillator, which needs the period as an extra unknown.
- Nonlinear discretization error. Theorem 3 gives the error of the trapezoidal rule only for linear circuits. For nonlinear circuits the error is measured on the page.
- Global convergence. The step limit is a heuristic; Newton can fail from a poor start.
- The speed of plain transient analysis. Near the steady state the error of a plain transient run is multiplied by about each period, so it falls like the th power of the spectral radius of , as for any fixed-point iteration. The page measures this; it is not proved here for the nonlinear map.
- Matrix-free Krylov solvers for are not covered.
Complexity
One Newton iteration is one transient period of steps plus the sensitivity. With dense matrices, each step costs for its own Newton solves and for the product in line L4, so iterations cost time; the states of one period take space and takes . With sparse factors, the sensitivity costs sparse solves per step, which is still too much for large . The matrix-free form replaces it by GMRES on line L6, where one product costs solves with stored factors, so an iteration costs about one transient period plus one period of solves per GMRES step. Compared with a plain transient, shooting costs periods instead of the number of periods the circuit needs to settle, which grows with its slowest time constant.
Properties
- Time-domain accuracy. The waveform is computed by the same integration method as a transient run, so sharp edges, switching and strongly nonlinear devices cost no more than in transient analysis.
- Independent of slow time constants. The number of Newton iterations does not grow with the settling time, unlike a plain transient.
- Quadratic convergence near a root, as in the measured residuals.
- Floquet information. The eigenvalues of at the solution are the Floquet multipliers of the discrete steady state; one with magnitude above 1 shows that the steady state is unstable.
- Exact for the discrete map. The result is the steady state of the integration method, with its error.
Variants and improvements
- Matrix-free Krylov shooting. GMRES with products from stored step factors, as above; this makes shooting practical for large integrated circuits.
- Autonomous circuits. For an oscillator the period is unknown. Add as an unknown and a phase condition, such as fixing one node voltage at ; the extended Newton matrix uses and the derivative . The result feeds phase noise analysis.
- Multiple shooting. Split the period into segments with their own start states, which helps when is badly conditioned.
- Damped integrators. Backward Euler, Gear's methods or TR-BDF2 avoid the singular algebraic rows of the trapezoidal rule.
- Periodic small-signal analysis. The step matrices of the converged period give the periodic AC, transfer function and noise analyses of mixers and switched-capacitor circuits.
When to use it
Use shooting for the periodic steady state of circuits with sharp edges or strong nonlinearity: switching power converters, switched-capacitor filters, frequency dividers and digital or sampling circuits, and any circuit with a slow bias or filter network that makes plain transient runs long. Use harmonic balance when the waveforms are nearly sinusoidal or when the circuit has distributed elements known only in the frequency domain.
Pitfalls
- Trapezoidal rule with algebraic unknowns. With MNA unknowns and an even number of steps, is singular for every voltage source row; the measured Newton matrix had an exactly zero pivot at . Use a damped method, an odd , or shoot on the state variables only.
- Multiplier near 1. If a Floquet multiplier is close to 1, as for a lightly damped resonance or an oscillator, is nearly singular and Newton is slow or fails.
- Fixed steps. The method needs the same steps in every period, or at least the same discrete map. Adaptive step control between iterations changes the map and can stop convergence; production codes fix the time points before the final iterations.
- Cost of a dense . Forming costs solves per step. Use the matrix-free form for more than a few hundred unknowns.
- Discretization error is not reported. The method returns the exact periodic solution of the discrete map; refine to check it, as in the example.
- Fitted parameters. The rectified output depends on the diode's fitted and ; the steady state is only as good as the model.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/shooting-newton-steady-state/. The authors are listed in prov/FS9DNT.jsonl.
"""Shooting Newton for the periodic steady state of a circuit.
The circuit equations are f(x) + d/dt q(x) = u(t), with x = (e_1..e_n, j_1..j_m):
node voltages first (node 0 is ground), then the currents of voltage sources
and inductors. The sources have period T. One period of transient analysis
with S fixed steps is a map x0 -> x_S; shooting finds a fixed point of that
map with Newton's method, using the sensitivity (monodromy) matrix dx_S/dx0
that the transient steps give at little extra cost.
"""
import math
import sim3dense
VT_300 = 1.380649e-23 * 300.0 / 1.602176634e-19 # kT/q at 300 K, in volts
THETA = {"trap": 0.5, "be": 1.0} # trapezoidal rule and backward Euler
class NoConvergence(RuntimeError):
pass
def _wave(w):
return w if callable(w) else (lambda t, c=float(w): c)
class Netlist:
"""Elements between nodes; node 0 is ground. Stamps follow the MNA page."""
def __init__(self, nodes):
self.n = nodes
self.m = 0
self.el = []
def _branch(self):
self.m += 1
return self.m - 1
def resistor(self, p, q, r):
self.el.append(("R", p, q, 1.0 / r))
def capacitor(self, p, q, c):
self.el.append(("C", p, q, c))
def inductor(self, p, q, l):
self.el.append(("L", p, q, l, self._branch()))
def vsource(self, p, q, wave):
"""Voltage source e_p - e_q = wave(t); wave is a function of t or a constant."""
self.el.append(("V", p, q, _wave(wave), self._branch()))
def isource(self, p, q, wave):
"""Current source that moves wave(t) out of p and into q."""
self.el.append(("I", p, q, _wave(wave)))
def diode(self, a, c, i_s, n=1.0, tt=0.0):
"""Junction diode from a to c with diffusion charge tt * i.
The saturation current i_s, the emission coefficient n and the transit
time tt are fitted model parameters.
"""
self.el.append(("D", a, c, (i_s, n, tt)))
@property
def size(self):
return self.n + self.m
def evaluate(self, x):
"""Return f(x), G = df/dx, q(x), C = dq/dx."""
N = self.size
f, q = [0.0] * N, [0.0] * N
G = [[0.0] * N for _ in range(N)]
C = [[0.0] * N for _ in range(N)]
def e(node):
return x[node - 1] if node else 0.0
def branch(vec, mat, p, qn, val, dval):
"""Add val leaving p and entering qn; dval = d val / d(e_p - e_q)."""
rp, rq = p - 1, qn - 1
for r, s in ((rp, 1.0), (rq, -1.0)):
if r < 0:
continue
vec[r] += s * val
if rp >= 0:
mat[r][rp] += s * dval
if rq >= 0:
mat[r][rq] -= s * dval
for el in self.el:
kind = el[0]
if kind in "RC":
_, p, qn, val = el
v = e(p) - e(qn)
if kind == "R":
branch(f, G, p, qn, val * v, val)
else:
branch(q, C, p, qn, val * v, val)
elif kind in "LV":
p, qn, k = el[1], el[2], self.n + el[4]
for r, s in ((p - 1, 1.0), (qn - 1, -1.0)):
if r >= 0:
f[r] += s * x[k]
G[r][k] += s
G[k][r] += s
f[k] += e(p) - e(qn)
if kind == "L":
q[k] -= el[3] * x[k]
C[k][k] -= el[3]
elif kind == "D":
_, a, c, (i_s, n, tt) = el
nvt = n * VT_300
v, vmax = e(a) - e(c), 40.0 * nvt
if v <= vmax:
ex = math.exp(v / nvt)
i, g = i_s * (ex - 1.0), i_s * ex / nvt
else:
ex = math.exp(40.0)
i, g = i_s * (ex * (1.0 + (v - vmax) / nvt) - 1.0), i_s * ex / nvt
branch(f, G, a, c, i, g)
branch(q, C, a, c, tt * i, tt * g)
return f, G, q, C
def sources(self, t):
"""The source vector u(t)."""
u = [0.0] * self.size
for el in self.el:
if el[0] == "V":
u[self.n + el[4]] += el[3](t)
elif el[0] == "I":
val = el[3](t)
if el[1]:
u[el[1] - 1] -= val
if el[2]:
u[el[2] - 1] += val
return u
def step(net, x, t, h, method, ev=None, tol=1e-13, max_iter=50):
"""One step from (t, x) to t + h; returns (x_new, ev_new, A, B).
The step solves q(y) - q(x) + h [theta (f(y) - u(t+h)) + (1 - theta)(f(x) - u(t))] = 0
by Newton. A = C(y) + theta h G(y) and B = C(x) - (1 - theta) h G(x) are the
matrices of the sensitivity recurrence A dy/dx0 = B dx/dx0.
"""
th = THETA[method]
N = net.size
f, G, q, C = ev if ev else net.evaluate(x)
u, un = net.sources(t), net.sources(t + h)
y = list(x)
for _ in range(max_iter):
fn, Gn, qn, Cn = net.evaluate(y)
r = [qn[a] - q[a] + h * (th * (fn[a] - un[a]) + (1 - th) * (f[a] - u[a])) for a in range(N)]
A = [[Cn[a][b] + th * h * Gn[a][b] for b in range(N)] for a in range(N)]
dy = sim3dense.solve(A, [-v for v in r])
y = [y[a] + dy[a] for a in range(N)]
if max(abs(v) for v in dy) <= tol * (1 + max(abs(v) for v in y)):
break
else:
raise NoConvergence("transient step")
evn = net.evaluate(y)
fn, Gn, qn, Cn = evn
A = [[Cn[a][b] + th * h * Gn[a][b] for b in range(N)] for a in range(N)]
B = [[C[a][b] - (1 - th) * h * G[a][b] for b in range(N)] for a in range(N)]
return y, evn, A, B
def period_map(net, x0, T, S, method="trap", sensitivity=True):
"""One period of S fixed steps from x0; returns (x_S, Phi, states).
Phi = d x_S / d x0 is the monodromy matrix of the discrete map (None when
sensitivity is False), and states are x_0, ..., x_S.
"""
h = T / S
N = net.size
x, ev = list(x0), None
Phi = sim3dense.identity(N, 1.0) if sensitivity else None
states = [list(x)]
for k in range(S): # @line L3
x, ev, A, B = step(net, x, k * h, h, method, ev)
if sensitivity:
Phi = sim3dense.solve(A, sim3dense.matmul(B, Phi)) # @line L4
states.append(list(x))
return x, Phi, states
def shooting(net, T, S, x0=None, method="trap", tol=1e-11, max_iter=50, step_limit=1.0):
"""Initial state of the periodic steady state of the S-step discrete map.
Returns (x0, iterations, residual history, states of one period). Newton
steps are scaled so that no node voltage moves more than step_limit volts.
"""
N = net.size
x = list(x0) if x0 else [0.0] * N # @line L1
history = []
for it in range(1, max_iter + 1): # @line L2
xT, Phi, states = period_map(net, x, T, S, method)
r = [xT[a] - x[a] for a in range(N)] # @line L5
history.append(max(abs(v) for v in r))
J = [[Phi[a][b] - (1.0 if a == b else 0.0) for b in range(N)] for a in range(N)]
dx = sim3dense.solve(J, [-v for v in r]) # @line L6
big = max((abs(v) for v in dx[: net.n]), default=0.0)
lam = min(1.0, step_limit / big) if big > 0 else 1.0
x = [x[a] + lam * dx[a] for a in range(N)]
if lam == 1.0 and max(abs(v) for v in dx) <= tol * (1 + max(abs(v) for v in x)): # @line L7
_, _, states = period_map(net, x, T, S, method, sensitivity=False)
return x, it, history, states # @line L8
raise NoConvergence("shooting")
def transient_until_periodic(net, T, S, x0=None, method="trap", tol=1e-9, max_periods=100000):
"""Plain transient, period after period, until x(kT) changes by at most tol.
Returns (x at the last period start, number of periods). This is what
shooting replaces.
"""
x = list(x0) if x0 else [0.0] * net.size
for p in range(1, max_periods + 1):
xT, _, _ = period_map(net, x, T, S, method, sensitivity=False)
if max(abs(a - b) for a, b in zip(xT, x)) <= tol:
return xT, p
x = xT
raise NoConvergence("transient did not settle")
sim3dense.py 70 lines
# SPDX-License-Identifier: MIT
# Shared helper of the sim3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra for Fraction, float or complex entries.
The circuit pages of group sim3 use this module as a reference solver and for
the small dense systems inside their tests. It holds no sparse method and no
circuit method. Matrices are lists of rows.
"""
from fractions import Fraction
class SingularMatrixError(ValueError):
"""The matrix has no inverse (a zero pivot in exact arithmetic)."""
def _exact(x):
return Fraction(x) if isinstance(x, int) else x
def solve(a, b, tol=0.0):
"""Solve a x = b by Gaussian elimination with partial pivoting.
With Fraction entries the result is exact. b is a vector or a matrix
(a list of rows); the result has the same shape.
"""
n = len(a)
m = [[_exact(x) for x in row] for row in a]
vec = not (b and isinstance(b[0], list))
rhs = [[_exact(x)] for x in b] if vec else [[_exact(x) for x in row] for row in b]
for k in range(n):
p = max(range(k, n), key=lambda i: abs(m[i][k]))
if abs(m[p][k]) <= tol:
raise SingularMatrixError(f"zero pivot in column {k}")
m[k], m[p] = m[p], m[k]
rhs[k], rhs[p] = rhs[p], rhs[k]
for i in range(k + 1, n):
if m[i][k] != 0:
f = m[i][k] / m[k][k]
for j in range(k, n):
m[i][j] -= f * m[k][j]
for j in range(len(rhs[i])):
rhs[i][j] -= f * rhs[k][j]
x = [[0] * len(rhs[0]) for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(len(rhs[0])):
s = rhs[i][j] - sum(m[i][k] * x[k][j] for k in range(i + 1, n))
x[i][j] = s / m[i][i]
return [r[0] for r in x] if vec else x
def transpose(a):
return [list(r) for r in zip(*a)]
def matvec(a, x):
return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]
def matmul(a, b):
bt = transpose(b)
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def identity(n, one=1):
return [[one if i == j else 0 * one for j in range(n)] for i in range(n)]
def inverse(a):
return solve(a, identity(len(a)))
test_shooting_newton_steady_state.py 141 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/shooting-newton-steady-state/. The authors are listed in prov/FS9DNT.jsonl.
import cmath
import math
import random
import sim3dense
from shooting_newton_steady_state import Netlist, period_map, shooting, transient_until_periodic
F0 = 1e6
W = 2 * math.pi * F0
T = 1 / F0
# Diode parameters: the saturation current IS and the emission coefficient N
# are fitted model parameters (typical values for a small silicon diode).
IS, N = 1e-14, 1.0
def rectifier():
"""2 V, 1 MHz source behind 1 kOhm (Norton form), diode, 100 kOhm || 1 nF load."""
net = Netlist(2)
net.isource(0, 1, lambda t: 2e-3 * math.sin(W * t))
net.resistor(1, 0, 1e3)
net.capacitor(1, 0, 10e-12)
net.diode(1, 2, IS, N)
net.resistor(2, 0, 100e3)
net.capacitor(2, 0, 1e-9)
return net
def parallel_rlc(r=200.0, l=10e-6, c=2e-9):
"""1 mA cosine source into R, L and C in parallel; unknowns e1 and the L current."""
net = Netlist(1)
net.isource(0, 1, lambda t: 1e-3 * math.cos(W * t))
net.resistor(1, 0, r)
net.inductor(1, 0, l)
net.capacitor(1, 0, c)
return net, r, l, c
def phasor(r, l, c, s):
"""Node voltage phasor of parallel_rlc for the complex frequency s (source phasor 1 mA)."""
return 1e-3 / (1 / r + 1 / (s * l) + s * c)
def test_linear_trapezoidal_is_exact_for_the_discrete_map_in_one_newton_step():
net, r, l, c = parallel_rlc()
for S in (40, 80, 160):
h = T / S
x, it, hist, states = shooting(net, T, S, method="trap")
assert it == 2 # the first step solves the affine problem
# the trapezoidal recurrence has the periodic solution of the frequency
# s_d = j (2/h) tan(w h / 2), the warped frequency of the bilinear map
sd = 2j / h * math.tan(W * h / 2)
v = phasor(r, l, c, sd)
for k in range(S + 1):
assert abs(states[k][0] - (v * cmath.exp(1j * W * k * h)).real) < 1e-12
def test_linear_backward_euler_matches_its_discrete_phasor():
net = Netlist(2) # voltage source with an algebraic row, R, C
net.vsource(1, 0, lambda t: math.cos(W * t))
net.resistor(1, 2, 1e3)
net.capacitor(2, 0, 100e-12)
S = 64
h = T / S
x, it, _, states = shooting(net, T, S, method="be")
assert it == 2
z = cmath.exp(1j * W * h)
sd = (1 - 1 / z) / h # backward Euler: (x_k - x_{k-1}) / h
v2 = 1 / (1 + sd * 1e3 * 100e-12)
for k in range(S + 1):
assert abs(states[k][1] - (v2 * cmath.exp(1j * W * k * h)).real) < 1e-12
def test_error_against_the_analytic_steady_state_is_second_order():
net, r, l, c = parallel_rlc()
exact = phasor(r, l, c, 1j * W)
errs = []
for S in (40, 80, 160):
x, _, _, _ = shooting(net, T, S, method="trap")
errs.append(abs(x[0] - exact.real))
# measured ratios: about 4 per halving of the step
assert 3.8 < errs[0] / errs[1] < 4.2 and 3.8 < errs[1] / errs[2] < 4.2
def test_monodromy_matches_finite_differences():
rng = random.Random(61)
net = rectifier()
for _ in range(3):
x0 = [rng.uniform(-0.5, 0.5), rng.uniform(0.5, 1.5)]
_, Phi, _ = period_map(net, x0, T, 50)
eps = 1e-6
for b in range(2):
xp, xm = list(x0), list(x0)
xp[b] += eps
xm[b] -= eps
fp, _, _ = period_map(net, xp, T, 50, sensitivity=False)
fm, _, _ = period_map(net, xm, T, 50, sensitivity=False)
for a in range(2):
fd = (fp[a] - fm[a]) / (2 * eps)
assert abs(fd - Phi[a][b]) < 1e-6 * (1 + abs(Phi[a][b]))
def test_rectifier_agrees_with_a_long_transient_and_converges_quadratically():
net = rectifier()
S = 100
x, it, hist, _ = shooting(net, T, S)
xt, periods = transient_until_periodic(net, T, S, tol=1e-9)
# measured: 7 Newton iterations against 155 periods of plain transient
assert it <= 8 and periods > 100
# the transient stops 1e-9 per period from its limit, which is about 1e-8 away
assert max(abs(a - b) for a, b in zip(x, xt)) < 2e-8
# quadratic convergence: each residual is at most about the square of the last
tail = [h for h in hist if h < 1e-2]
for a, b in zip(tail, tail[1:]):
assert b < 50 * a * a + 1e-14
def test_trapezoidal_rule_makes_algebraic_rows_singular_for_even_step_counts():
net = Netlist(2)
net.vsource(1, 0, lambda t: math.cos(W * t))
net.resistor(1, 2, 1e3)
net.capacitor(2, 0, 100e-12)
x0 = [0.3, 0.1, -1e-4]
_, G, _, _ = net.evaluate(x0)
row = G[2] # the source row e_1 = v(t) has no charge term
for S, sign in ((64, 1.0), (65, -1.0)):
_, Phi, _ = period_map(net, x0, T, S, method="trap")
# proved: row^T Phi = (-1)^S row^T, so row^T (Phi - I) is 0 or -2 row^T
prod = [sum(row[a] * (Phi[a][b] - (a == b)) for a in range(3)) for b in range(3)]
target = [0.0 if sign > 0 else -2 * v for v in row]
assert max(abs(p - t) for p, t in zip(prod, target)) < 1e-9
_, Phi, _ = period_map(net, x0, T, 64, method="be")
prod = [sum(row[a] * (Phi[a][b] - (a == b)) for a in range(3)) for b in range(3)]
assert max(abs(p + v) for p, v in zip(prod, row)) < 1e-9 # backward Euler: row^T Phi = 0
try:
sim3dense.solve([[Phi[a][b] - (a == b) for b in range(3)] for a in range(3)], [1.0, 0.0, 0.0])
except sim3dense.SingularMatrixError:
raise AssertionError("backward Euler should give a nonsingular Newton matrix")
History
Aprille and Trick (1972) formulated the periodic steady state of a nonlinear circuit as the boundary value problem and solved it with Newton's method, computing the needed sensitivity matrix along the transient. Colon and Trick (1973) made the method faster for large-signal circuits. The book of Kundert, White and Sangiovanni-Vincentelli (1990) described shooting next to harmonic balance as one of the two main steady-state methods. Telichevesky, Kundert and White (1995) removed the dense sensitivity matrix with a matrix-free Krylov solver, which made shooting usable on large RF integrated circuits.
References
- Thomas J. Aprille and Timothy N. Trick, Steady-state analysis of nonlinear circuits with periodic inputs, Proceedings of the IEEE 60(1), 108 to 114, 1972, the formulation of the periodic steady state as x(T) = x(0), the Newton iteration and the sensitivity (state transition) matrix computed along the transient
- F. R. Colon and Timothy N. Trick, Fast periodic steady-state analysis for large-signal electronic circuits, IEEE Journal of Solid-State Circuits 8(4), 260 to 269, 1973, the faster computation of the periodic steady state that followed the 1972 method
- Ricardo Telichevesky, Kenneth S. Kundert and Jacob K. White, Efficient steady-state analysis based on matrix-free Krylov-subspace methods, Proceedings of the 32nd Design Automation Conference, 480 to 484, 1995, the solution of the shooting Newton equations with GMRES and matrix-vector products from the stored step matrices
- Kenneth S. Kundert, Jacob K. White and Alberto Sangiovanni-Vincentelli, Steady-State Methods for Simulating Analog and Microwave Circuits, Kluwer, 1990, the chapter Time-Domain Methods, pages 55 to 79, on shooting methods for circuits
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag FS9DNT Edit this page History Report an error Markdown