kicad2ems.gfdtd.operator

The FDTD operator: a CSX model and the FDTD settings lowered onto the
rectilinear Yee grid, as openEMS does it.

The fields are kept as edge voltages and currents (V = E dl on the primary
edges, I = H dl' on the dual edges), so the update needs no geometry at run
time:

    I  -= iv * (loop sum of V around the primary face)
        iv = dt l' / (mu A)
    V   = vv * V + vi * (loop sum of I around the dual face)
        vv, vi from the edge's C = eps A' / l, G = kappa A' / l

Arrays are (3, Nx, Ny, Nz): component, then the node (i, j, k). E_x[i, j, k] is
the edge from line i to i+1 at y_j, z_k; H_x[i, j, k] sits at x_i, y_j+1/2,
z_k+1/2. Indices past the last edge hold zero coefficients.

    op = build(csx, fdtd)  # fdtd: dict(bc=[6], f0, fc, nr_ts, end_crit,
                           # oversampling)

Materials are sampled at cell centres (highest priority wins) and averaged over
the four quarter cells around each edge. Metals take the edges whose midpoint is
in a primitive; flat primitives snap to the nearest mesh line. Metal is PEC; a
ConductingSheet on a flat primitive is openEMS's conducting-sheet model
(gfdtd.sheet: a conductance and two R-L branches per edge, fitted to the sheet's
skin-effect impedance up to f0 + fc), PEC on other primitives and next to the
boundaries, as openEMS's. A rough sheet (roughness > 0, gfdtd's) takes a
wideband fit of its rough impedance instead: more R-L branches. Lumped elements
spread their R / L / C over the edges in their box (parallel, or series RLC on
each edge), with metal caps; soft E excitations add exc_val x signal to their
edges.

Debye materials: each pole is a polarisation current i on the edges, tau di/dt +
i = C_p dV/dt (C_p = eps0 eps_delta A' / l), integrated with the trapezoidal
rule at the E update's time, which folds part of it into vv and vi:
unconditionally stable, for any tau. A conducting sheet's R-L branches are poles
too, L di/dt + R i = V, integrated the same way: i' = ka i + kb (V' - sg V), sg
1 for Debye, -1 for R-L. PML_n: the n outermost cells of a side are a
convolutional PML (CPML, kappa 1, no alpha) with a cubic conductivity grading,
ending in PEC. Dumps: DumpBox regions at the cell centres (openEMS's dump mode
2), worked out by the engine.
class kicad2ems.gfdtd.operator.Compressed[source]
The operator without its coefficient arrays, for the compiled kernels
(GPU and CPU core). vi = geoE * s and iv = geoH come from 1-D line arrays:
geoE_a = dt / eps0 * d_a * (1 / dual_b) * (1 / dual_c), geoH_a = dt / mu0 *
dual_a * (1 / d_b) * (1 / d_c). Each node keeps one code into a table of its
three E edges' (vv, s, Debye poles); the nodes of one material (and one
quarter-cell mix at interfaces) share one.

  code    (Nx, Ny, Nz) uint8, uint16 past 255 codes, uint32 past 65535
  vv, s   (ncode, 3) float32;  pole (ncode, 3) int32: row of kbt, or -1 (no
          poles)
  kbt     (nrow, P) float32: each pole's kb~ = kb l / (eps0 A'); ka (P,):
          its ka; h (2P,): (1 + ka) / 2, then its sg (1: Debye, -1: a
          conducting sheet's R-L branch)
  slot    (Nx, Ny, Nz) int32: the node's row in the pole currents (nslot, 3,
          P), -1 elsewhere
  G       float32 [d | 1/d | dual | 1/dual], each [x | y | z] (d and 1/d
          zero past the last line)
  ke, kh  dt / eps0, dt / mu0

Pole currents are kept scaled: i~ = i l / (eps0 A'), so that V' = vv V + vi
c - dt s sum(h i~) and i~' = ka i~ + kb~ (V' - sg V) need no geometry.
class kicad2ems.gfdtd.operator.Ferrite(**kw)[source]
A model's magnetised ferrite (_ferrite): its cells' update and the H
edges they meet, flat arrays. na: the components (2: every cell biased
along +-z, the fast path; 3: along its own direction u, or partly
magnetised). Per cell c (nc): e[c] its 2 na edges (x lower, x upper, y
lower, y upper[, z lower, z upper]: positions in the edge list), k[c]
(na 2: p0, s p1, q0, s q1; na 3: p0, p1, q0, q1, ux, uy, uz, qs), state
(m, the last b: 2 na floats, A/m, zero at the start; faces: and per
component its faces' difference mode m, its partner and the last
difference: 3 na more). Per edge (ne): idx (its flat index into I), lh
(its dual length, m: I = H lh), cells (its two cells' offsets into the
change array dm[rows (nc + 1)]: the component's row, faces: the face's,
the dummy cell nc where there is none), w (their weights).
nbytes()[source]
What its arrays take on the GPU (bytes): per cell the edges,
coefficients, state and change; per edge its index, lengths, cells,
weights and m.
class kicad2ems.gfdtd.operator.Grid(g)[source]
Lines (drawing units and metres), primary / dual lengths, and the points
the tests run on.
class kicad2ems.gfdtd.operator.Operator[source]
What the engine needs: the grid (m), dt, the coefficient arrays and the
sparse extensions.
kicad2ems.gfdtd.operator.build(csx, fdtd, log=None)[source]
The Operator of a ContinuousStructure (gfdtd.csx, or anything with the
same attributes) and the FDTD settings dict(bc, f0, fc, nr_ts, end_crit,
oversampling). The core (everything but the excitations, probes, dumps and
the pulse) is kept for the model's next excitation, which differs only in
those: kicad2ems runs one per port (the coupler: 0.15 s a run, and
compress's 0.2 s on the GPU).
kicad2ems.gfdtd.operator.compress(op)[source]
op.vv / op.vi / op.iv / op.debye as a Compressed operator (exact to 2^-20
in vv and s), the same object for every excitation of one model (it reads
only the core): read only.
kicad2ems.gfdtd.operator.curl_I_part(I, a)[source]
Component a of the loop sum of I around each dual face (the E update's c;
the numpy backend's too).
kicad2ems.gfdtd.operator.curve_edges(q, grid)[source]
find_path over each segment of a Curve primitive.
kicad2ems.gfdtd.operator.edge_mask(q, a, grid)[source]
inside() for the midpoints of the a-edges, on the (Nx, Ny, Nz) node array
(False past the last edge).
kicad2ems.gfdtd.operator.exact_timestep(einv, hk, factor=0.95, tol=0.01)[source]
The leapfrog's own limit for these coefficients (R-D6): the largest
eigenvalue of the curl-curl operator M = E^-1 C^T K C (E^-1 = 1 / C_edge, 0
on PEC edges; K = l' / (mu A) on the dual edges) by Lanczos on its symmetric
form E^-1/2 C^T K C E^-1/2, and dt = factor x 2 / sqrt(lambda). The
materials count (a small cell in a dielectric allows a longer step), which
the vacuum Courant rule of the smallest cells does not: on the examples
1.26-1.35 times its step. Loss, lumped capacitance and the poles only lower
the edges' vi: stabler.
kicad2ems.gfdtd.operator.excitation_signal(kind, f0, fc, dt, nr_ts, function=None)[source]
(signal at the E steps, at the H steps half a step later) of openEMS's
excitation `kind`: 0 the Gaussian pulse (f0, fc), 1 sin(2 pi f0 t), 2 a
Dirac (one step, f_max = fc), 3 a step (f_max = fc), 10 a custom function of
t (f0, f_max = fc). A pulse's signal ends with it; the others last the whole
run (nr_ts steps), so that the end criterion never stops them (as openEMS's:
a sinus runs to its last step).
kicad2ems.gfdtd.operator.find_path(grid, p1, p2)[source]
[(axis, (i, j, k))] of the mesh edges along the segment p1 -> p2 (drawing
units), as openEMS's FindPath: from the line crossing nearest p1, each step
to the neighbouring node closest to the segment and further along it.
kicad2ems.gfdtd.operator.inside(q, pts, grid, flat_snap=True)[source]
Boolean mask (len X, len Y, len Z) of the tensor-grid points pts = [X, Y,
Z] inside primitive q (boundary included). Flat primitives sit on their
nearest mesh line (flat_snap).
kicad2ems.gfdtd.operator.keep_limit(key, dt)[source]
Keep a model's exact limit for its later runs (a few hundred models at
most; the oldest dropped).
kicad2ems.gfdtd.operator.schlomann(fm, f)[source]
Schlomann's demagnetised permeability: 1/3 + 2/3 sqrt(1 - (fm / f)^2)
(fm = gamma Ms, f the frequency; 1/3 where f <= fm, the low-field loss's
band, which it does not hold).
kicad2ems.gfdtd.operator.timestep(grid, factor=0.95)[source]
The largest stable step for vacuum on this grid: 1 / (c sqrt(sum over
axes of the largest 1/(d_i-1 d_i))), the neighbouring primary cells around
each node (half cells at the ends count once, as 1/d^2).