kicad2ems.core.viamodel

kicad2ems.core.viamodel - a physics-based model of a group of vias between
reference planes (segment.py's via models without a mesh; prototype,
2026-11-20).

The planes are the circuit's ground. Each signal via is a chain of nodes, one
at every plane it passes through and every signal layer it has a pad on:

  - at each node a capacitance to the planes (the barrel, its pads and the
    antipads: an axisymmetric electrostatic solve per via, `capacitances`), each
    plane's share at the node of the via nearest it;
  - between two nodes inside a cavity (two adjacent planes, height d) a series
    element whose voltage is the cavity's: the parallel-plate (TEM) Green's
    function w u d/4 H0^(2)(k rho) couples every via crossing the cavity, a
    segment of height h weighted h/d (a signal layer inside the cavity splits
    the via there: stripline);
  - between an outer pad and the plane under it, the barrel's inductance;
  - a ground via joining the two planes of a cavity shorts it there (its
    voltage 0): the return current;
  - each port (a trace cut at segment.py's circle) at its layer's node, through
    its stub (the trace from the cut to the pad) as a transmission line.

The planes are infinite (no edge, no cavity resonance of a finite board), a
cavity carries its TEM mode alone (thin against the wavelength), losses are the
dielectric's and, with solve's sigma, the planes' copper (their surface
impedance (1 + j) Rs: k^2 (1 + (1 - j) delta / d), Q_c = d / delta; with rough,
Hammerstad's factor on delta). The stubs' copper is lossless (a millimetre or
so). Unknowns: the vias' nodes and segments, a few hundred at most.

A cavity named in build's `cavities` (a pair of plane layers: segment.py's
--cavities, the board's plane pair solved whole by core.cavities) is the
model's no longer: each of its segments a port instead (its + at the upper
node, the voltage across it the cavity's at the via, its current the barrel's
from the upper plane to the lower), and the box's ground vias in it not
modelled (the board's cavity holds every one). The join then puts the board's
cavity there: its resonances, its coupling to every other via model's vias.
kicad2ems.core.viamodel.build(d, vias, cavities=())[source]
The model of a via piece's board file d (segment._to_dict's) and its
signal vias [dict(x, y, net, pad, r)] (segment.via_groups'): a dict the
solve takes. mm throughout. cavities: plane-layer pairs whose cavity is
left to the join, each segment in it a port (the module's docstring).

Barrels at one place are one (their distance 0 had made the cavity's
H0^(2)(0) infinite and every S NaN): a net's records there one barrel over
all their spans (a via drawn twice, a stack of microvias), ground vias
there one, and a ground via or another net's via in a signal via's barrel
left out (a short in the file). model['notes'] says each.
kicad2ems.core.viamodel.capacitances(a, pads, planes, diel, span, dr=0.02, dz=0.01, rmax=None, air=1.0)[source]
Capacitance (F) from a via (barrel radius a over span (z0, z1), pads
{z: radius}) to each plane [(z, hole radius or None: a full plane)] (mm):
{plane z: C}. Finite volumes on (r, z), r symmetric about the axis.
kicad2ems.core.viamodel.eps_between(diel, za, zb)[source]
The complex permittivity a vertical field sees between za < zb (mm):
the layers in series.
kicad2ems.core.viamodel.planes_of(d, frac=0.5)[source]
The reference planes: layers whose ground copper covers `frac` of the
outline or more, by z (top first).
kicad2ems.core.viamodel.solve(model, freqs, z0=50.0, sigma=None, rough=None)[source]
S (nf, n, n) at z0 of the model's ports, and their names: the trace
ports, then a port for each segment in a cavity left to the join
(model['cavity_ports'] then lists them: dict(name, cavity (the upper
plane, the lower), via (its index in model['sig']), x, y, w (its height's
share of the cavity's))). sigma (S/m; rough, um RMS): the planes' copper
loss in each cavity, else none.