BSplineSolver (degree-d Galerkin, default d=1/2) is the default solver;
HMatrixSolver and ArrayBlockSolver are structural accelerators built on
top of it. SinusoidalSolver and SinusoidalGalerkinSolver reproduce NEC2's
three-term basis (collocation and Galerkin testing respectively) as
in-codebase NEC comparators. RazorSolver is the NEC-5 formulation twin: a
tent basis with razor-blade (RWG mixed-potential path) testing, transcribed
from the NEC-5 Users Manual rather than NEC2's, over every ground, buried
and crossing decks included. Because its
testing rule — not its basis, which it shares with BSplineSolver(degree=1)
— is NEC-5's own, it reproduces NEC-5's characteristic slow O(1/N) impedance
walk without needing the (licensed) NEC-5 binary; see
docs/razor-solver.md (momwire#309).
Ports
Every solver family exposes the same port surface, and it is the surface to
build on: compute_port_solution() runs one fill and one
factorisation over every port at once, so a multi-port structure costs what a
single-port one costs.
Three kinds of port, declared at construction, and they can be mixed:
kwarg
what it is
entry
feeds=
a delta gap at a point along a wire — NEC's EX 0
(wire_index, arclength, voltage)
junction_ports=
a shunt port on a junction NODE's KCL row: the node drives net inflow (the node's row leaves the constraint set)
(junction_index, voltage), or a bare index for 0 V
node_gaps=
a SERIES EMF at a junction node, in series with one named wire end — the apex feed
(wire_index, "start"|"end", voltage)
Ports are numbered [feeds…, junction_ports…, node_gaps…], and that is the
order every port readout is in.
A junction port has one terminal. Its voltage is the node's potential and
its current is the current the port puts into the wires at the node, on every
family that serves it. Nothing in the model carries that current back, so a
junction port on its own is not a one-port in the circuit sense: its
is not a radiation conductance and can be negative. An L of two
wires driven at its corner reads −26.9 − 342.3j Ω on both and
(momwire#1165), and that is not a sign error.
Junction ports are for a network that closes the current: an element between
nodes A and B sees of . That
impedance is passive, its input power is the radiated power, and across two
facing wire ends it tends to a delta gap's as the gap closes.
Re(Y)
BSplineSolver
SinusoidalGalerkinSolver
Z_AA + Z_BB − Z_AB − Z_BA
Z = inv(sol.y)
sol = solver.compute_port_solution() # one fill, one factorisation
sol.y # (n_ports, n_ports) short-circuit Y
sol.coeffs # (n_dof, n_ports) — column j is the
# solution for 1 V at port j
sol.port_currents # the same matrix as `y`, asserted
compute_y_matrix() is compute_port_solution().y, so the two cannot drift.
Any other excitation is coeffs @ V with no second fill — that is the point
of the class. To turn a column into currents on the structure, use the
solver's currents_at_knots(coeffs[:, j]), or element_currents(coeffs[:, j], subdiv=…) for the (mid, moment, nodes, delta) source terms a field
evaluator wants. PortSolution.basis is an opaque per-solve handle — do not
introspect it.
Decks
momwire.deck reads a NEC-2 deck and puts it on a solver. The dialect —
which cards run, which are refused and in exactly what words — is specified
at
momwire.dev/reference/deck-grammar-nec2/;
that page is normative, and the code is tested against its anchors.
from momwire.deck import build_solver, parse
deck = """CM 20 m dipole, 10 m up over average ground
CE
GW 1 21 -5.05 0. 10. 5.05 0. 10. 1.E-3
GE 1
GN 2 0 0 0 13. 0.005
EX 0 1 11 0 1. 0.
FR 0 1 0 0 14.1
XQ
EN
"""
built = build_solver(parse(deck), basis="bs2")
y = built.solver.compute_port_solution().y
port = built.ports.feed_ports[0] # the solver row this EX card drives
print(f"Z = {1.0 / y[port, port]:.1f} ohm") # Z = 67.0-41.1j ohm
parse() returns a dialect-neutral DeckModel; build_solver() maps it onto
one of the eight BASES names (six solver families — "bs2" is the
default, the degree-2 B-spline; the names before momwire#2091, such as
"bspline", still work and warn) and returns the solver together with a
PortPlan. The plan is what makes the solver's ports readable: which row is
which EX or LD card, each load's LoadSpec, and one drive vector per
execute group over a port set that never changes. Stamping a load impedance
is port algebra and stays with the consumer — momwire.deck puts the gap in
the matrix and hands over the spec.
A deck's execute groups are what the model says about running it: one per
execute card, each carrying its own frequency list, kernel flag and
Environment (the ground, its plane and a cliff's second medium). A GN card
arms, so a deck may run once in free space and once over ground and each group
says which; build_solver(model, group=k) builds over group k's, and
frequency_mhz=, extended_kernel= and environment= override it.
Only the operating point moves between those calls, never the geometry, so a
swept caller translates once:
from momwire.deck import prepare_mesh
mesh = prepare_mesh(model) # the polylines, the port plan
solvers = [build_solver(model, mesh=mesh, frequency_mhz=f) for f in sweep]
Every solver built from one handle is given the same coordinate arrays, so a
prepared solve is bit-equal to an unprepared one.
NEC-2 launcher
Installing momwire puts momwire-nec2c on your path — the NEC-2
launcher (momwire-nec2c and its siblings), a resident NEC engine speaking
the protocol SimNEC uses to drive nec2c,
with momwire's solver behind it. Point SimNEC's NEC portal
dialog at that command and its Smith chart, tuner and sweeps run on momwire.
python -m momwire.dropin.nec2c is the long spelling (python -m momwire.portal
still works), and --selftest is the
deployment smoke.
momwire-nec2c -version # NEC2 momwire-nec2c [sb] <version>
momwire-nec2c --selftest # PASS / FAIL, no checkout needed
momwire-nec2c --basis sinusoidal < dipole.nec # or run a deck by hand
SimNEC's NEC-5 slot takes the momwire-nec5[-<basis>] commands instead
(momwire-nec5-razor2p is NEC-5's own formulation): SimNEC picks the deck
syntax from nec2c or nec5 in the engine's path.
momwire.dropin (the Python drop-in engine, NEC-2 / NEC-4.2 / NEC-5 dialects:
momwire.dropin.nec2c and momwire.dropin.nec5) may use the solver API and
momwire.deck; nothing else in momwire may import from it. The hosts'
protocols are the drop-in's business alone, and a test enforces that.
Public names
Everything importable from momwire itself. __all__ is the source of
truth — tests/test_public_surface_954.py fails if this list and __all__
disagree in either direction, so a name promoted without a line here (or a
line here for a name that was never exported) is a red test, not a stale doc.
Solvers — see Solvers above for what distinguishes them:
BSplineSolver — degree-d Galerkin, the default.
HMatrixSolver, ArrayBlockSolver — structural accelerators over it.
RazorSolver — the NEC-5 formulation twin, over every ground, buried and
crossing decks included.
PulseSolver, HarringtonSolver — the textbook pair.
Results and control:
PortSolution — a solved port network's currents, voltages and Z.
PortSites — the configured ports plus point ports that move along one
wire against one factorisation, with ∂Y/∂x (BSplineSolver.port_sites,
momwire#1915).
terminate_ports — a Y matrix with some ports terminated in series loads,
e.g. a load at a PortSites position seen from the feed.
DistributedRLC — a wire's per-metre series or parallel RLC (NEC's LD 2
/ LD 3), the distributed_rlc kwarg every loading family takes beside
wire_conductivity and the insulation pair.
FeedPlacement — where a solver put a feed (or a Razor lumped load): the
arclength asked for, the one used, and the offset between them. Returned
by every solver's feed_placements() (momwire#1059).
Capabilities — what a solver class declares it spans.
CancelToken, SolveAborted — cooperative cancellation for a long solve.
refused_fill_report — the fill_report() shape for a deck that
rotational_symmetry=True refused at construction, from the exception.
LatticeFFTUnavailable — raised when a lattice deck cannot take the FFT path.
accelerated — True iff the C++ accelerator loaded. Assert it rather than
discovering a silent fall-back to pure Python by its runtime.
accelerator_variant — which build of it loaded: "avx2", "sse2",
"legacy" (the single unsuffixed extension macOS and non-x86 still ship),
or None when none did. On x86 the wheel carries the same kernels compiled
twice and picks by CPU feature before importing either, because an
AVX2 binary on an older CPU does not raise ImportError — it kills the
interpreter with an illegal instruction (momwire#1032).
Wire material, for a consumer mirroring the loading into another tool:
wire_internal_impedance, insulation_inductance — the per-metre quantities.
equivalent_radius — the coated-wire pair's effective radius.
Answers a consumer must give IDENTICALLY to momwire, exported so it cannot
answer them differently:
ground_touch_tol — is this wire end on the plane (a per-wire relative
tolerance; an invented absolute one disagrees at the margin).
grounded_crossing_exemption — does this in-plane junction earn the
crossing exemption.
below_reach_refusal — how far a buried structure may span before the
below/below remainder stops being tabulated.
wire_to_element — the geometry conversion the array-block path uses.
SURFACE_HEIGHT_CLASS — the low-stand-off class's measured conditioning,
including the validity floor a consumer refuses against.
Capability axes:
axes_for — every axis of one capability row, declared union derived. The
single derivation point: a consumer re-deriving ground_model from
grounds, or wire_position from buried/contact, is the drift this
exists to prevent.
AXIS_VALUES — the declared vocabulary.
DERIVED_AXES — which axes are computed rather than declared.
macOS: the C++ accelerator uses Homebrew's OpenMP runtime, so brew install libomp is required — both to compile from source and to run the prebuilt
Apple-Silicon wheel. The wheel deliberately does not bundle libomp (it links
Homebrew's by absolute path) so that it shares a single OpenMP runtime with
pynec-accel; two private copies in one process abort with OMP: Error #15 (or
deadlock). Without libomp installed, the accelerator can't load and momwire
warns and falls back to the slower pure-Python path. On Linux the system
libgomp covers this, so no extra step is needed.
The NEC-5 engines on Linux, without Python
Each release also carries momwire-nec5-linux-x86_64.tar.gz: two of
momwire's NEC-5 engines as native programs, with no Python in them. They are
nec5-razor2p (momwire-nec5-razor2p) and nec5-bs2, the default B-spline formulation
(momwire-nec5-bs2). You do not need Python, pip or momwire installed.
Their printouts are byte for byte the Python commands'. Their -version line
is the command's with -standalone and the build added to the name, e.g.
NEC5 momwire-nec5-razor2p-standalone-avx2 [sb] <version>.
tar -xzf momwire-nec5-linux-x86_64.tar.gz
cd momwire-nec5-linux-x86_64
./momwire-nec5-razor2p-linux -version
./momwire-nec5-razor2p-linux deck.nec deck.out # EZNEC's and SimNEC's form
./momwire-nec5-razor2p-linux - - < chain.nec # SimNEC's streaming form
./momwire-nec5-bs2-linux deck.nec deck.out # the same forms, nec5-bs2
For SimNEC, point the NEC-5 engine setting at momwire-nec5-razor2p-linux
or momwire-nec5-bs2-linux in that folder, and keep the folder together:
each command runs its -avx2 build on a processor with AVX2 and FMA, and its
-sse2 build on any other 64-bit x86 processor. They need 64-bit x86 Linux
with glibc 2.28 or newer (RHEL/Alma 8, Debian 10, Ubuntu 18.10 and later);
everything else is built in. A deck an engine does not serve yet is refused
in the printout by name ("not served by this build: ..."), and the Python
command serves it. The other formulations stay Python. The existing Windows
momwire-nec5-razor2p.exe in the EZNEC drop-in zip is unchanged.
The NEC-4.2 sinusoidal engine on Linux, without Python (preview)
Preview: from 0.83.0 the same tarball also carries
momwire-nec42-sinusoidal-linux, the native twin of the Python command
momwire-nec42-sinusoidal for EZNEC's and SimNEC's NEC-4.2 slot, with the
same -avx2 / -sse2 picking and the same three forms. Its printouts are
the Python command's byte for byte, apart from the two lines that report
measured time (FILL= ... SEC. and RUN TIME =). It serves free space, a
perfect ground (GN 1), a Sommerfeld ground (GN 2 / GN 3) with every wire
above it, buried wires (a deck wholly below it, one joined to the wires
above through a crossing junction, as a vertical over a buried radial screen
is, or one beside them with no junction, as a raised antenna over a separate
buried counterpoise is), a GD far-field ground (the second medium's cliff),
wire loading, TL / NT networks, helices and near fields. It still refuses by
name buried wires beside raised ones with no crossing junction when the wires
carry more than one radius, and an insulated wire (IS); the Python command
serves those decks.
The NEC-4.2 slot's default engine on Linux, without Python (preview)
Preview: the same tarball also carries momwire-nec42-linux
(momwire#1607 Phase C), the native twin of the Python command
momwire-nec42, the NEC-4.2 slot's default (nec42-bs2, the B-spline basis), with
the same -avx2 / -sse2 picking and the same three forms. Its printouts
are the Python command's byte for byte, apart from the two lines that report
measured time. It serves free space, a perfect ground (GN 1), a Sommerfeld
ground (GN 2 / GN 3), buried wires (wholly below it, joined to the wires
above through crossing junctions, or beside raised ones with no junction
between them), wire loading, networks (TL / NT) and the extended and exact
kernels. It refuses a near field over a buried wire in the Python command's
own words (the Python command refuses it too), and it still refuses by name an
insulated wire (IS), which the Python command serves.
Radius steps and junctions on the sinusoidal basis: the junction rule
The point-matched sinusoidal basis takes a junction rule,
SinusoidalSolver(junction_rule=...) (momwire#1644). "nec2" is NEC-2's
log rule at every junction, the class default and what the NEC-2 launchers
(momwire-nec2c*) use. "nec42" is NEC-4.2's treatment, from the public
NEC-4 theory manual (UCRL-MA-109338): a small charge solve at each junction
where wires of different radius meet (and at every junction of three or more
wires), with NEC-4's thin-wire kernel and end caps. It is what the NEC-4.2
launchers (momwire-nec42*, and the native momwire-nec42-sinusoidal) use.
On radius steps, T and Y junctions, bends and tapered elements, with the feed
anywhere including the segment beside the junction (momwire#1668), it lands
within a few hundredths of an ohm of licensed NEC-4.2, where the NEC-2 rule
is off by 10 to 200 ohms. At very short segments both codes drift apart by a
few tenths of an ohm, as they do on a uniform wire with no junction at all. A
deck with no such junction solves exactly as before under either rule.
Each launcher's choice is only its default. Set MOMWIRE_JUNCTION_RULE to
nec2 or nec42 in the environment the engine runs in to choose the other
on any launcher. Sin-Galerkin and the other bases take no junction rule.
The NEC-5 engines on Windows, without Python
Each release from 0.79.0 also carries
momwire-nec5-windows-x64.zip, the same two engines as native Windows
programs, signed with momwire's certificate. The zip holds
momwire-nec5-razor2p.exe and momwire-nec5-bs2.exe: each carries an avx2
and an sse2 build and picks, when it starts, the one the processor can run.
A win7 folder holds the same two programs beside the runtime Windows 7 SP1
needs. (Up to 0.96.0 each engine came as an -avx2 and an -sse2 program;
those names are deprecated, still ship at the top of the zip, not in win7,
as copies that run the build they name, and will be removed in a later
release.) The DLLs they load ship beside them, so nothing
needs installing; keep each folder together. A deck an engine does not serve
yet is refused in the printout by name, as on Linux. These programs and the
drop-in,
momwire-windows.zip
(named momwire-eznec-windows.zip before 0.80.0), are the two supported ways
to run momwire under EZNEC, SimNEC or 4nec2 on Windows. CI runs every test
deck through both builds (avx2 and sse2) of each program on every change and checks
their printouts against the Python engine's: they match to the printed digit,
apart from round-off in values that are zero in exact arithmetic.
Preview: one file per engine. A release may also carry
momwire-nec5-windows-x64-single.zip beside that zip, which stays the
default; check the release's assets. It holds momwire-nec5-razor2p.exe and momwire-nec5-bs2.exe,
built with GCC (MSYS2 UCRT64): each file carries an avx2 and an sse2 build and
picks the one the processor can run, with no DLLs beside it. It needs the
Universal C Runtime, which Windows 10 and 11 include; on Windows 7 SP1 or 8.1
install KB2999226 or a Visual C++ 2015 or later redistributable. Its speed
differs from the default zip's from deck to deck, in both directions.
The NEC-5 engines on macOS, without Python (preview)
Preview: each release from 0.79.0 also carries the same two engines for
Apple silicon (macOS 14 or later, arm64), as
momwire-nec5-macos-arm64.tar.gz. The
math library is the system's Accelerate, the one numpy and SciPy use on a
Mac, and the OpenMP runtime is built in, so nothing ships beside the two
programs. Their printouts match the Python commands' on the same Mac.
They are ad-hoc signed only: no Developer ID and no notarisation. A tarball
fetched with curl and unpacked with tar carries no quarantine flag and
runs as it is:
curl -LO <URL of momwire-nec5-macos-arm64.tar.gz>
tar -xzf momwire-nec5-macos-arm64.tar.gz
cd momwire-nec5-macos-arm64
./momwire-nec5-razor2p-macos -version
./momwire-nec5-bs2-macos deck.nec deck.out
A copy downloaded through a web browser is quarantined, and macOS refuses to
open it until the flag is cleared from the whole folder:
Every NEC-5 engine, the standalone programs and the Python commands alike,
reports its timing when the environment variable MOMWIRE_TIMES=1 is set.
It is off by default and changes no result. With it set, the printout's
FILL=/FACTOR= (under MATRIX TIMING) and RUN TIME = lines carry measured
seconds in NEC-5's places instead of zeros. The printout also gains the
environment in effect at the top (threads, build, anchors mode, ground table
cache) and, under each MATRIX TIMING, the run's phases: the ground tables
(computed, read from the disk cache, or anchor-blended), the fill and factor
with their thread counts, the solution, and the far and near fields. Each
answer also writes one line on standard error with every stage in
milliseconds:
Under SimNEC or EZNEC, set it on the command line that starts the program,
so the engine inherits it: MOMWIRE_TIMES=1 <the command that starts SimNEC>. The keys are described in the docs site's
momwire.dev/reference/standalone/.
The ill-conditioning check (MOMWIRE_CONDITION_CHECK=1)
The sinusoidal and pulse solves warn, with scipy's LinAlgWarning, when a
matrix is so close to singular that the currents are numerical noise. That
needs LAPACK's condition estimate (gecon). It costs about five single-threaded
passes over the factors, about 1 s of the ELT whip's 13 frequencies at 4,392
segments, so it does not run on every solve. A free screen on the
factorization's pivots runs instead, and the estimate is taken only when the
pivots look near-singular. Set MOMWIRE_CONDITION_CHECK=1 to take the
estimate on every solve. Neither changes a result. The B-spline and
Sinusoidal-Galerkin solves never run it.
The same answer with or without AVX-512
numpy and OpenBLAS switch to AVX-512 code on a processor that has it, and
that code rounds differently in the last bits. momwire's own entry points
(the momwire-nec5/momwire-nec42/momwire-nec2c-shared commands and the
servers they start, the plain momwire-nec2c and momwire-nec2c-<basis>
commands, the Windows drop-in, the Linux razor2p program and the test suite)
turn it off on such a processor, by setting
NPY_DISABLE_CPU_FEATURES and OPENBLAS_CORETYPE=Haswell before numpy
loads, so the printout doesn't change with the processor. A value you set
yourself is left alone, and on a processor without AVX-512 nothing is set.
This doesn't cover everything. python -m momwire... run by
hand, a resident server one of those started, and a program that imports
numpy before momwire have all loaded numpy before the pin. For those, call
momwire_serve_client.pin_cpu_env() before importing numpy, or set the two
variables in the environment. The Windows razor2p hybrid's own OpenBLAS DLL
picks its kernels before any code can pin it. Even pinned, a value that
cancels to almost nothing can still print differently in its last digits.
Test
pip install -e ".[test]" # core + test deps, and what `make build` needs (pybind11, setuptools, wheel)
pytest tests/
The cross-validation against NEC2 (tests/test_pynec_backend.py) additionally
needs PyNEC — a test-only dependency installed separately from a wheel (see
below). Those tests skip cleanly when it isn't present; everything else runs
without it.
Optional: PyNEC backend (test-only)
momwire can be cross-validated against NEC2 via PyNEC (the tests/test_pynec_backend.py suite); NEC2 also delivers ~5–10× faster single-frequency solves. PyNEC is a test-flow-only dependency — momwire's own solver never imports it.
Install the PyNEC wheel
Install PyNEC from the python-necpp fork's release. The distribution is named pynec-accel (the import name stays PyNEC); the wheels are self-contained — OpenBLAS is vendored (via scipy-openblas32), so no system BLAS, SWIG, or build toolchain is needed — and cover Linux, Windows, and macOS (arm64) on CPython 3.10–3.14:
--no-index ensures pip takes the fork's wheel rather than upstream PyNEC on PyPI (which is broken on current Python and lacks the OpenBLAS/OpenMP work). On macOS the wheel shares Homebrew's libomp (brew install libomp) rather than vendoring its own, so it can coexist with momwire's accelerator in one process. After install, from PyNEC import nec_context works and the cross-validation tests run; without it they're skipped (momwire itself needs no PyNEC).
Runtime thread pinning
The wheel links OpenBLAS and parallelises the NEC2 matrix fill with OpenMP. Pick thread counts up front:
export OMP_NUM_THREADS=$(nproc --all) # PyNEC matrix fill
export OPENBLAS_NUM_THREADS=1 # muzzle numpy/scipy's idle pool
Pinning OPENBLAS_NUM_THREADS=1 stops numpy/scipy from spinning up their own OpenBLAS thread pool that contends with PyNEC's threads on the same cores. On a 100-director Yagi (2142 segs) this is worth ~8% wall time at NP=4.
Works well with
Use together with momwire: extensions, drivers, servers and companion tools.
numpyPythie’s Index: 92Fundamental package for array computing in Python1.2B downloads/mo
scipyPythie’s Index: 86Fundamental algorithms for scientific computing in Python423.2M downloads/mo