kicad2ems.pcbqs.sparams

python -m kicad2ems.pcbqs.sparams: low-frequency S-parameters of a board's
ports, from the quasi-static currents of its copper.

    python -m kicad2ems.pcbqs.sparams board.kicad_pcb --nets SIG,GND \
        --fmin 1e3 --fmax 1e8 --out lf
    python -m kicad2ems.pcbqs.sparams run/board_board.json --out lf
        # a kicad2ems board file: its ports as they are
    python -m kicad2ems.pcbqs.sparams --describe --json

From DC up to where the board is a tenth of a wavelength, the full-wave solvers
are at their worst (a time-domain run needs millions of steps, a moment method's
matrix loses its conditioning), and what decides the answer is where the current
goes: the resistance of the copper it takes and the area of the loop it makes
with its return. A ground via missing or in the wrong place, a slot under a
trace, a return that has to change planes: each shows as loop inductance and as
impedance two ports share. That is the magneto-quasistatic solve (pcbqs.mqs: the
sheet currents of every layer, the vias, the mutual inductance of all of it),
with a port as it is in a measurement:

    each port: a 1 A source and its reference impedance, both between the
    trace's end and the copper under it; one solve per driven port; S from the
    currents in the terminations:
        S[j, k] = 2 I_j sqrt(z0_j / z0_k) - (j == k)
            I_j: the current in port j's termination

so no impedance matrix is needed (the ports of a board without capacitance have
none: nothing joins a trace to its plane but the other ports).

Resistance and inductance alone hold while the copper's capacitance carries next
to no current: a trace's own capacitance moves S by 0.01 where pi f C z0 = 0.01
(a matched line's S11 first: its capacitance is what cancels its inductance).
Above that frequency the copper's charge is solved with its currents
(pcbqs.peec: one model for R, L and C, in the board's dielectrics, with their
loss), which holds to about a tenth of a wavelength; there is no radiation in
either. `--capacitance auto` (the default) adds the charge when the band reaches
above the first limit; both limits are estimated and written with the result
(`valid_to_Hz`).

It writes <out>/sparams.json (the ports, the frequencies, S, the path between
each two ports as a series R and L, the limits, the notes),
<out>/<name>_pcbqs.s<N>p (Touchstone, with the port names as kicad2ems writes
them) and, where kicad2ems's viewer reads a run, the current of each layer with
one port driven, at a few frequencies of the band
(<out>/sparams/exc_<port>/dump_J_<layer>_fd.npz, per ampere into the port):
where the return goes, and how it moves under the trace as the frequency rises.
kicad2ems.pcbqs.sparams.apart_note(p)[source]
What to say of two ports that nothing joins at DC (paths()'s joined
False).
kicad2ems.pcbqs.sparams.limits(board, ports)[source]
(f_wave, f_cap, C): the frequency where the ports' copper is a tenth of a
wavelength long; the one where its capacitance to the copper nearest above
and below moves S by 0.01, pi f C z0 = 0.01; that capacitance, F (an
estimate: each piece as a line of its mean width over each neighbour,
parallel plates and Wheeler's fringe, three quarters of it where only one
side has copper and part of the field is in the air).
kicad2ems.pcbqs.sparams.model(board, fmax, ports=None, z0=None, dmax=None, fine=None, backend='auto', capacitance='auto', thickness=False, log=<built-in function print>, edge_rings=None)[source]
The ports' model for a band to fmax (Hz), which solve() and sweep()
solve: dict(q (pcbqs.mqs.MQS, the ports a source and a termination each, the
parts elements), ports, charge, info, t0). Arguments: solve()'s.
kicad2ems.pcbqs.sparams.part_elements(board)[source]
(the parts the solve takes: [dict(ref, layer, patches, nets, R, L, C)],
those it leaves out: [(ref, why)]). A part is a series R, L and C between
its two pads, as kicad2ems's other solvers have it (a value of one of them:
that element alone); one with no value, or with a pad that is on no copper
of its layer, is left out.
kicad2ems.pcbqs.sparams.part_patches(p)[source]
The two patches of copper a board's part joins (a kicad2ems board's
`parts`: the gap between its pads, from s to e, along its axis): the copper
at each end of the gap, the gap's width across and half of that (at least
0.2 mm) along.
kicad2ems.pcbqs.sparams.paths(f, S, names, zref)[source]
Each two ports' path as a series R and L: [dict(a, b, joined, R_ohm,
L_H)], per frequency, from the ports' admittance matrix: Z = -1 / Y[b, a],
the element between a and b of the network of two-terminal elements that has
that Y (what capacitance there is goes to the ports' own shunt elements, not
into the path). Exact for ports joined by one path each; a figure to compare
layouts by where paths share copper. joined False (R and L None): no current
gets from one port to the other, the copper of the two, or of their returns,
is not connected. C_F: the capacitance that closes such a path instead,
where the charge is solved (the path is a capacitor at the lowest frequency:
two planes that no via joins); else None.
kicad2ems.pcbqs.sparams.signal_nets(board, ports)[source]
The nets the ports' signals are on: the ports' own, and those a part
joins them to (a filter's inner nodes), but not the ground nets nor the nets
of the copper under the ports.
kicad2ems.pcbqs.sparams.solve(board, freqs, ports=None, z0=None, dmax=None, fine=None, backend='auto', capacitance='auto', thickness=False, log=<built-in function print>, edge_rings=None)[source]
The S-parameters of a board's ports at freqs (Hz, all positive): dict(f,
S (nf, n, n), names, zref, q, drive, info). board: a kicad2ems board dict
(stack, copper, vias, ports, parts); ports: its own unless given, each
dict(name, layer, ref_layer, c, axis, sgn, w, z0, net), single-ended,
between a trace and the copper under it. Its parts are series R, L and C
between their pads (part_elements). capacitance: 'on', 'off' or 'auto' (the
charge solved too when freqs reach above where R and L alone hold).
thickness: the copper as its two faces (MQS's conductor_loss='slab') instead
of one sheet of its DC resistance. edge_rings: with the charge, the graded
cells across the copper's edges (default EDGE_RINGS; 1: none). drive[k]: the
solve with port k driven (pcbqs.mqs.Result) and the current that entered the
port, for the maps. A mesh left to the defaults is made coarser until the
dense solve takes it.
kicad2ems.pcbqs.sparams.sweep(board, grid, points=31, tol=0.002, log=<built-in function print>, **kw)[source]
The S-parameters on `grid` (Hz, ascending) from at most `points` solves:
where a rational model of all the ports' S (emsdev.afs, mom25d's sweep) is
least sure, until two models agree to `tol` on the grid (a filter's
resonance between log-spaced samples had been interpolated across, linearly
in log f). solve()'s dict, its f and S the frequencies solved, with grid and
S_grid (on it) and info['sweep'] = dict(solves, converged, change: the last
two models' largest difference). A grid of `points` or fewer: each solved.
kw: solve()'s.
kicad2ems.pcbqs.sparams.terminal_box(p)[source]
The patch a port takes of its trace and of the copper under it: the
trace's width across, half of it (at least 0.2 mm) along the trace from the
port into the circuit.
kicad2ems.pcbqs.sparams.write_maps(out, board, r, port, freqs, name='sparams', log=<built-in function print>)[source]
The sheet current of each layer with `port` driven, at the frequencies of
the solve nearest to freqs, per ampere into the port, where kicad2ems's
viewer reads a run: <out>/<name>_board.json and
<out>/<name>/exc_<port>/dump_J_<layer>_fd.npz (A/mm; zero off the copper)
with their dump_info.json. Returns dict(board, dumps=[{layer, file}],
frequencies_Hz).