kicad2ems.core.cavities

kicad2ems.core.cavities - the resonances of a board's plane-pair cavities: the
dielectric between two adjacent reference planes (a stripline layer's, a
microstrip's under its plane), its modes set by the planes' shape and the
ground vias that tie them, and the signal vias that drive them.

While the planes are close against the wavelength (d << lambda) the field
between them is the cavity's TEM one: V(x, y), the voltage between the
planes, with

    -div grad V = k^2 V,   k^2 = w^2 mu0 eps0 er (er: the series one of the
                                                   dielectrics between)

over the area both planes cover (their antipads and small holes filled: a hole
changes the plane's inductance little), the edges open (dV/dn = 0: no current
out; their radiation left out). A via joining the two planes (its barrel on
both planes' copper, not in antipads: a ground via) holds V = 0 on its
barrel's disc; a via through the cavity otherwise (a signal via in its
antipads, a via to one plane) is where a current enters it: its disc one voltage, its coupling to a
mode the mode's voltage there. Linear triangles (pcbqs.pdn.mesh: the vias'
discs as rings of the mesh), the consistent mass matrix, the modes below fmax
by shift-invert Lanczos. Each mode's Q from the dielectric's loss tangent and
the planes' skin depth, 1/Q = tan d + delta / d (radiation from the edges not
counted: an upper bound on Q).

What it answers: where a signal via passes a plane pair, the cavity's modes in
the signal's band and the via's coupling to each (|V| at the via over the
mode's RMS: 1 an average place, 2-3 a mode's peak); the via's distance to its
nearest ground via (a return path close to it keeps the cavity's modes away
from it). The segment study's via models leave exactly this out: the physics-
based model's planes are infinite, a meshed model's a box round the via.

    board = load_board('b.kicad_pcb')         # pcbqs._cli: a board.json dict
    for cav in cavities(board):
        res = cav.modes(10e9)                  # dict: f, Q, couplings, ...
    python -m kicad2ems.core.cavities b.kicad_pcb --fmax 10 --out cav
class kicad2ems.core.cavities.Cavity(board, layers, zs, geom, d, er, tand, index, inside, log=<built-in function print>)[source]
A plane pair (bottom, top): its geometry (mm), dielectric (d mm, er,
tand), the signal layers inside it, and the vias through it: shorts (V = 0:
a via whose barrel touches both planes' copper) and ports (the others).
build(fmax, dmax=None, cells=12)[source]
Mesh the cavity for modes up to fmax (Hz), `cells` a wavelength
there (or dmax mm), and assemble K (the stiffness, dimensionless) and
M (the mass, m2) on the free unknowns: the shorts' discs out (V = 0),
each port's disc one unknown. M is the consistent and the lumped mass
averaged: their dispersion errors cancel (a rectangle's 60 modes at
lambda / 10, 1.1 % high with either alone, 0.03 % so; 2026-11-24).
impedance(freqs, which=None, sigma_cu=58000000.0, log=None)[source]
The cavity's impedance matrix (nf, k, k) between its ports `which`
(indices into self.ports; default all) at freqs (Hz): the voltage
between the planes at port i per current through port j's via (from
the top plane to the bottom: segment.py's via models' convention),
the other ports open, the shorts (ground vias) at V = 0:
    Z = j w mu0 d (K - k^2 M)^-1 at the ports' discs,
    k^2 = w^2 mu0 eps0 er (1 - j tan d) (1 - j delta / d)
(the modal sum of `modes` with every mode, and the losses its Q
has). A port merged with a short (its disc on one) is 0. The mesh
`build`'s, for max(freqs) where not built.
modes(fmax, dmax=None, max_modes=600, sigma_cu=58000000.0)[source]
The cavity's modes below fmax (Hz): dict(f (Hz), Q, k2 (1/m2),
V (unknowns x modes, each mode's RMS 1 over the cavity), pr (the
participation ratio: 1 a mode over the whole cavity, small a local
one), coupling (ports x modes: |V| at each port's disc, RMS units),
more (True where max_modes cut the list short)).
nearest_short()[source]
Each port's distance (mm) to the cavity's nearest ground via
(np.inf: none).
vertex_field(V, m)[source]
Mode m's voltage at every mesh vertex (0 on the shorts).
kicad2ems.core.cavities.cavities(board, frac=0.4, hole_fill=2.0, planes=None, log=<built-in function print>)[source]
The board's plane-pair cavities (adjacent reference planes, any signal
layers between them inside): [Cavity], bottom first.
kicad2ems.core.cavities.coverage(board)[source]
{layer: the fraction of the outline its ground nets' copper covers}
(the board's ground_nets: ground and the power nets it treats as AC
ground).
kicad2ems.core.cavities.ground_spot(cav, x, y, rmin=0.5, rmax=5.0, clear=0.3, step=0.1)[source]
The nearest place (x, y, distance mm) from (x, y), rmin to rmax mm
away, where a ground via's disc of radius `clear` lies on both planes'
copper (not in an antipad or void, clear of the other vias), or None.
kicad2ems.core.cavities.plane_layers(board, frac=0.4, planes=None)[source]
The reference planes: copper layers whose ground copper covers `frac`
of the outline or more (or the layers named in `planes`). [(layer, z)],
bottom first.
kicad2ems.core.cavities.plot_mode(cav, res, m, path, title=None)[source]
Mode m's |V| over the cavity (shorts black dots, ports red crosses),
KiCad's y down.
kicad2ems.core.cavities.study(board, fmax, nets=None, frac=0.4, dmax=None, planes=None, suggest=False, log=<built-in function print>)[source]
Every cavity's modes and the vias that drive them: [dict(cavity,
layers, inside, d, er, area, shorts, ports, static, modes [dict(f, Q, pr,
top [(port index, coupling, z_peak ohm)])], vias [dict(net, x, y,
nearest_ground_via mm, peaks [(f Hz, z_peak ohm, coupling)] at least
Z_FLAG, the largest first)])]. nets (fnmatch patterns): the vias reported
(default every via that is no ground via). suggest: for each via with a
peak, a ground via at the nearest place on both planes' copper
(ground_spot), the cavity solved again with all of them: each one's
'fix' dict(x, y, distance, z_peak, f) (KiCad mm, the peak then).