# Usage
[← Getting started](getting-started.md) · [Index](index.md) · [Next: GUI →](gui.md)
## Running kicad2ems
```bash
kicad2ems board.toml # everything from a config file
kicad2ems board.kicad_pcb --fmin 1 --fmax 6 # no config file
kicad2ems board.kicad_pcb --config run.toml # the board on the command line, options from a file
kicad2ems board.toml --preview # build the model and mesh, don't solve
kicad2ems --init board.kicad_pcb # write a starter config with the ports found
kicad2ems --check # what this Python can run
kicad2ems study board.toml # every question the config's study asks, one run after the other
```
`python -m kicad2ems` does the same with a particular Python.
The exit code is 0 when the run finished, 1 when a solver you named gave no result, and 2 when a setting
is invalid or a named solver cannot run. Settings and solvers are checked before any work starts.
## Choosing solvers
`--solvers` (or `solvers = [...]` in a config) picks the solvers. Each writes `_.sNp`.
| Name | Solver | Needs |
|---|---|---|
| `openems` (or `fdtd`) | openEMS, 3D FDTD | openEMS |
| `gfdtd` | gfdtd, 3D FDTD on the GPU or the CPU: openEMS's model, its own engine ([details](gfdtd.md)) | slangpy (Vulkan) for the GPU, or its compiled core |
| `mom25d` (or `mom`) | mom25d, 2.5D method of moments ([details](mom.md)) | nothing extra |
| `qucs` | the [line model](transmission-lines.md), solved by qucsator | qucsator on PATH |
| `scikit` | the line model, solved by scikit-rf | scikit-rf |
| `lines` | `qucs` if qucsator is installed, otherwise `scikit` | |
| `pcbqs` (or `qs`) | pcbqs, quasi-static: the low end of a band, from DC to about a tenth of a wavelength, with the return current where it flows ([details](pcbqs/sparams.md)) | the `qs` extra; run only when named |
| `auto` | the default: the full-wave solver expected to be fastest, plus the line model | |
| `all` | every solver | |
```bash
kicad2ems board.toml --solvers mom # MoM only
kicad2ems board.toml --solvers openems,lines # openEMS and the line model
kicad2ems board.toml --solvers all # everything, compared in one plot
```
The first solver in the table order is the reference: its plot is `_.png`, and the others
are drawn over it and compared with it in the report.
`--mom` and `--fast` add mom25d or the line model as an extra reference. If a reference can't run, you
get a warning and the run continues. If a solver named in `--solvers` can't run or can't model the
board, the run stops before starting.
Below a few hundred MHz on a board of a few centimetres the full-wave solvers are slow and lose accuracy (an FDTD
run of 100,000 steps or more; mom25d's mixed-precision solves falling back to double precision), and the line
model has no DC resistance and no return path. `--solvers pcbqs` solves the copper's currents there instead,
and its charge where the band asks for it: `--fmin 0.00001 --fmax 0.1 --sweep log` is 10 kHz to 100 MHz, evenly
spaced on a log scale. Its run says to
what frequency it holds on the board, and two ports whose return is not joined (a ground via missing between
two planes) are reported as such.
**One band from both.** With pcbqs and a full-wave solver in one run (`--solvers pcbqs,mom25d
--fmin 0.01 --fmax 6 --sweep log`), the run also writes `_joined.sNp`: pcbqs's answer below a crossover,
mom25d's (else the other full-wave solver's) above it, and across a fifth of a decade each side of it a
raised-cosine blend in log f, so the joined curve has no step. The crossover is where the two agree best, at or
below the frequency pcbqs says it holds to (a rule of thumb: a tenth of a wavelength of the ports' copper). The
log says how far the two disagree there, and warns above 0.1 in |S|. On `demo_transition` pcbqs's estimate is
714 MHz, where they differ by 0.043 (its one-sheet copper reads the matched line's |S11| about 3.5 dB high, as
its docs say); the crossover goes to 17 MHz, where they differ by 0.0012.
Antenna mode (`mode = "antenna"`) needs openEMS, gfdtd or mom25d. mom25d models antennas over an infinite
ground plane, so it suits patches and arrays but not antennas that use the board edge.
### Which solver
gfdtd and mom25d are the working solvers, and the line model is for tuning. openEMS is the slower reference,
for what the other two lack and for checking gfdtd's engine.

*The largest |ΔS| from openEMS over S11 and S21 against the wall time, on eight examples ([benchmarks](benchmarks.md):
24 CPU threads, an RX 7800 XT for gfdtd and mom25d); `python tools/doc_figures.py solvers` draws it.*
- **gfdtd** solves openEMS's model (the same mesh, ports, parts and end
criteria) with its own engine: the fastest full-wave solver on every example,
3–35 times faster than openEMS on the GPU (its CPU core faster too), and
within 0.02 of it on 7 of the 8. It handles what FDTD handles: board edges,
enclosures, antennas with a finite ground, gap ports. Its copper takes
`--sigma` as openEMS's does and `--rough` over the band (openEMS takes it at
the band centre). It has no `--converge`, and its lumped parts are modelled
differently (demo_bandpass's 0.126). Agreeing with openEMS checks its engine,
not the model.
- **mom25d** is a different method, so it is the independent cross-check: no air box or enclosure resonances,
radiation and surface waves in, conductor loss (`--sigma`, `--rough`) and de-embedded wave ports. It is quick on
thin trace filters and slow on large planes with many vias (memory grows with the square of the unknowns, time
with their cube: sma_launch 108 s against gfdtd's 2.8 s). Its dielectric extends sideways forever, so antennas
that use the board edge come out wrong (antenna_ifa and antenna_slot: 1.4 from openEMS); it can't model gap
ports, and its loss tangent doesn't vary with frequency. It lands 0.04–0.3 from openEMS on most boards.
- **openEMS** does the most (conductor loss, phased drive, `--converge`) on the CPU only, and was the slowest
full-wave solver on all but the smallest boards.
- **The line model** is a circuit of line sections, solved in milliseconds: close on plain distributed circuits
(0.06–0.09), 0.4–0.8 off on filters and transitions (no coupling, radiation or parasitics), no antennas.
### `auto`
`auto` drops the solvers that can't run here or can't model the board, estimates
how long each remaining full-wave solver would take, runs the fastest and adds
the line model. gfdtd's estimate is openEMS's mesh and timesteps at gfdtd's
measured speed (about 8 times openEMS's on the GPU, 2 times on its CPU core);
with `--converge` auto leaves gfdtd out, as it would ignore it. mom25d's is the
matrix work for its unknowns on the CPU or GPU; a solver that needs more than
80 % of the RAM is dropped. The log says what it chose:
```
solvers auto: gfdtd + qucs (0.31 M cells, 1 run(s) of ~146,729 timesteps on the GPU, ~13 s); openems not chosen
(0.31 M cells, 1 run(s) of ~146,729 timesteps, ~89 s); mom25d not chosen (4,763 unknowns, ~16 EM solves, ~19 s);
force one with --solvers
```
The estimates are rough: calibrated on the examples, they picked the faster solver on 10 of 13, and the others
were at most 1.6 times slower. With `--preview`, auto only reports what it would run.
## Config files
A config is a TOML file. Every option can be a top-level key, with dashes or underscores (`end-db` or
`end_db`). A solver's own options can also go in a `[solver.]` table under their short names:
```toml
board = "board.kicad_pcb"
nets = ["RF", "GND"]
fmax = 6.0
solvers = ["openems", "mom25d"]
[solver.openems]
excite = "P1"
dump = ["E@F.Cu-0.1@2,6"]
[solver.mom25d]
dmax = 0.4
```
- Lists can be TOML arrays or comma-separated strings (`nets = "RF,GND"`).
- Paths in a config are relative to the config file, so you can run it from any directory.
- Unknown keys are reported, with the option they are probably a typo of.
- Settings are applied in this order: defaults, then the config file, then the command line.
- An invalid value stops the run with a one-line error. Set `KICAD2EMS_TRACEBACK=1` for the traceback.
## A study: several questions of one board
A run of kicad2ems answers one thing, the ports' S-parameters. A study asks more of the same board: the
[crosstalk between traces](si.md) (kicad2ems's own), a rail's drop, the temperature, a circuit on the copper,
each by an engine installed for it (`kicad2ems --check` lists the questions and who answers them). The config says which, and `kicad2ems study` runs them in order:
```toml
board = "board.kicad_pcb"
[study]
run = ["sparams", "dc", "thermal"] # the questions
[study.sparams]
engine = ["mom25d", "pcbqs"] # who answers: one engine, or several to compare; none: the default
[study.thermal]
engine = ["pcbqs", "Elmer"] # by its name (elmer_thermal) or as a list shows it
fields = true # its field dumps too, where the engine can write them
[analysis.pdn] # an engine's own settings: an analysis's under [analysis.],
rail = "+5V" # a solver's under [solver.] or at the top level, as before
```
```bash
kicad2ems study board.toml # all of it
kicad2ems study board.toml --list # the runs it takes, without making them
kicad2ems study board.toml --only thermal # some of its questions (or engines)
kicad2ems study board.toml --preview # the runs that have a preview, without solving
```
The solvers named for S-parameters, an antenna and the line model run first, together, as kicad2ems's own run
(without an `engine`, the solvers the settings name, `auto` by default); then each analysis in its order, so
that the temperature follows the circuit whose losses it takes. An engine that answers two questions answers
them in one run (a rail's drop and its impedance). Each run goes into a folder of its own under the output
folder, `__