kicad2ems.pcbqs.kernels¶
Kernels with a compiled twin: the dense systems of the frequency loops, filled
in one pass. Each is the compiled core's
(pcbqs._core, core/dense_kernels.hpp) where it is built, and numpy's here
otherwise (no core, PCBQS_NO_CORE set, or a core that predates the kernel);
`numpy=True` asks for the twin, which is how the tests hold the two to each
other.
loop_system(R, L, jw, rows, cols, S) R[rows, cols] + jw L[rows, cols] + S,
complex (rows, cols)
peec_system(R, L, jw, pscale, nl, electro, S) the charge solve's scaled
system and its scale
lu_factor_rows(a), lu_solve_rows(lu, b) LAPACK's LU of a row-major matrix
in place (no copy of it)
solve_symmetric(P, B) P^-1 B for a symmetric P: by Cholesky where it is
real and definite
The numpy twins make a temporary of the whole matrix per operation, which is
what the compiled ones are for: on 18,000 unknowns that was four matrices of 5
GB and several seconds a frequency.
- class kicad2ems.pcbqs.kernels.MixedLU(a)[source]¶
The LU of a complex row-major matrix in single precision, refined to double's accuracy (R-D13). LAPACK's cgetrf is about 2.3 times as fast as zgetrf (6,233 unknowns: 0.57 s for 1.30). Each solve takes the single-precision solution and corrects it by its residual, worked out with the double matrix (kept, so the factor is 1.5 times a double factor's memory), until the residual is a double solve's (1e-12 of b; three or four steps). A system it cannot bring there (single precision's error times the condition number near 1) is factored in double, once, and solved as before.
- class kicad2ems.pcbqs.kernels.Pencil(R, L, P=None)[source]¶
(R + s L + P^T diag(z) P)^-1 for any s from one generalized eigendecomposition (R-D13.2): R and L real symmetric, R positive definite (the loops' DC resistance), P sparse (k, n) (the loops through k parts of impedance z(s)). With R = C C^T and C^-1 L C^-T = W diag(lam) W^T, G = C^-T W puts both on the diagonal: (R + s L)^-1 = G diag(1 / (1 + s lam)) G^T, and the parts come in by Woodbury, a k x k solve. The eigendecomposition costs about as many complex LUs as pencil_pays says, after which a frequency costs three products with G: a sweep of more frequencies than that is quicker. Raises numpy.linalg.LinAlgError where R is not positive definite.
- kicad2ems.pcbqs.kernels.blas_threads()[source]¶
BLAS on the fast physical cores only (emsdev's core_threads), as mom25d's LU: on a hybrid CPU OpenBLAS's 24 threads made an LU of 2,532 unknowns take 0.11-0.88 s, from one call to the next, for 0.041 s on the 8 P-cores. A context manager; MOM25D_BLAS_THREADS / OPENBLAS_NUM_THREADS set by hand are left as they are.
- kicad2ems.pcbqs.kernels.core(name)[source]¶
The compiled core's function of that name, or None (no core built, PCBQS_NO_CORE set, or an older core).
- kicad2ems.pcbqs.kernels.loop_system(R, L, jw, rows, cols, S=None, numpy=False)[source]¶
R[rows, cols] + jw L[rows, cols] + S: the loop impedance on the unknowns kept, complex (len(rows), len(cols)), row-major. R and L are the real loop matrices; S (sparse, of the result's shape, or None) is what changes with frequency: the parts' own impedances and the conductors' resistance.
- kicad2ems.pcbqs.kernels.lu_factor_rows(a, mixed='auto')[source]¶
LAPACK's LU of the square row-major matrix `a`: what lu_solve_rows takes. A complex one of MIXED_MIN unknowns or more is factored in single precision and refined (MixedLU: a is kept, not destroyed) where the copy fits in memory; otherwise in double, in a's own memory (a is destroyed): scipy's lu_factor copies a row-major matrix to column-major first, a second matrix of the same size, so this factors a's transpose, which is a's memory read by columns, and lu_solve_rows solves with the transpose of that, so the answers are a's. PCBQS_LU=double: always double.
- kicad2ems.pcbqs.kernels.lu_solve_rows(lu, b)[source]¶
The solution of a x = b for lu = lu_factor_rows(a).
- kicad2ems.pcbqs.kernels.peec_system(R, L, jw, pscale, nl, electro, S=None, numpy=False)[source]¶
The charge solve's system at one frequency and its scale: (system, zscale). Z = R + jw L + S (S sparse: the parts and the resistance's change), zscale = max |Z|; the first nl columns (the loops' currents) are Z / zscale, the others (the tree's, as charge) jw Z / pscale, with `electro` added to the tree's own block.
- kicad2ems.pcbqs.kernels.pencil_pays(n, frequencies)[source]¶
Whether a sweep of `frequencies` on n loops is quicker by one Pencil than by an LU each, and fits in the memory free (four real matrices of n x n at once). PCBQS_PENCIL=always or never decides it.
- kicad2ems.pcbqs.kernels.solve_symmetric(P, B)[source]¶
P^-1 B for the symmetric matrix P (coefficients of potential): by Cholesky where P is real, or complex with no imaginary part (a layered stack without loss: its images make the matrix complex), which such a matrix is positive definite for; by LAPACK's symmetric indefinite solve where it is complex (a lossy stack) or Cholesky finds it is not definite. That solve is what this always was: 1.7 s on the 6,359 unknowns of two traces on FR4, for Cholesky's 0.6 s.