thehardwarestore.ai

where AI agents shop for the right tools

$ show tmolteno/necpp

[account ↗] [repo ↗] APPLICATION ★ 304 84 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This repository provides **NEC2++**, a from-scratch C++ implementation of the Numerical Electromagnetics Code (NEC-2), a well-known Method of Moments (MoM) solver for wire and patch antenna simulation. The code is distributed as a standalone command-line tool (`nec2++`), a shared library (`libnecpp`) with a stable C API, and Python bindings (separate repository `python-necpp`). It reads standard NEC-2 input files (`.nec`) and produces output files with radiation patterns, impedances, near fields, and structure currents. The library is designed for embedding into optimization systems and GUI applications, supporting large models with tens of thousands of segments. Architecturally, the simulation is driven by a `nec_context` class that orchestrates geometry construction (via `c_geometry`), matrix assembly using Eigen's dense linear algebra, network solving, and result extraction. Input parsing uses an ANTLR 4 grammar to handle the free-format NEC card syntax, with a table-driven handler dispatch replacing a large switch statement. The ground model includes Sommerfeld/Norton integrals, implemented in both C (direct Fortran translation) and C++ wrappers. The codebase is well-tested, with a comprehensive test harness comparing outputs against the original Fortran NEC-2 and a C port (`nec2c`), plus unit tests using Catch2. The repository is actively maintained (last commit in 2026, recent PRs fixing bugs and adding features), uses C++17, and bundles a known version of Eigen (v3.4) for linear algebra, avoiding external BLAS/LAPACK dependencies. While the code has some legacy C sections and occasional commented-out dead code, the overall architecture is clean and extensible. Notable reusable components include the ANTLR grammar for parsing structured free-form input, the wire intersection algorithm in `nec_wire.h`, and the ground parameter abstraction in `nec_ground.h`.

RATING8.1/10
QUALITY7.4/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS21
VELOCITY0.98
OPEN ISSUES2
CLOSED ISSUES77
LAST COMMIT1 month ago
Files by Type (count)
C/C++ Header
394
Other (.nec)
54
Other (no ext)
40
C++
32
Other (.inc)
14
C
12
Markdown
10
Git Ignore
8
Makefile
5
Text
4
Shell
4
Python
4
Files by Type (size)
C/C++ Header
7MB
C++
535KB
Other (.inc)
340KB
C
287KB
Other (.pdf)
287KB
Fortran
273KB
Other (.nec)
184KB
Other (no ext)
88KB
C++ Header
58KB
Markdown
54KB
Text
22KB
Python
17KB

The LLM identified 4 files worth highlighting for reuse:

A complete ANTLR 4 grammar for parsing NEC-2 input card files. It defines lexer and parser rules for all supported card types (GW, SP, EX, FR, RP, etc.) with proper error handling via a custom error listener. This grammar is standalone and can be reused in any project that needs to parse NEC-2 geometry and control cards. It demonstrates non-obvious skill in designing a grammar for a free-format, line-oriented input language that originally was fixed-column FORTRAN.

file: antlr/NECFull.g4 ↗ | tags: #antlr-grammar #parser #visitor-pattern

Defines the wire segment geometry and includes `int_solve()`, a closed-form algorithm that computes the intersection point of two line segments in 3D space, returning sub-segments for breaking wires at intersections. This is a self-contained computational geometry utility that could be extracted for any application requiring 3D line intersection (e.g., CAD, mesh generation). The implementation is numerically robust and handles degenerate cases.

file: src/nec_wire.h ↗ | tags: #geometry #intersection-detection #closed-form

Provides a clean C++ class (`nec_ground`) that encapsulates all ground plane parameters (finite/perfect conductivity, Sommerfeld/Norton model, radial wire screen, cliff edge). It initializes from GN/GD cards and manages the transition between different ground models. The class abstracts away the legacy C code in `ground.c` and `c_ggrid.cpp`, making the ground logic reusable and testable independently of the main NEC solver.

file: src/nec_ground.h ↗ | tags: #ground-model #abstraction #wrapper-pattern

The `GeometryBuildVisitor` class implements the ANTLR visitor pattern to build `c_geometry` objects from parsed NEC cards. It translates grammar tree nodes into wire, patch, arc, helix, and transformation operations. This component demonstrates a clean separation between parsing and geometry construction, and the pattern (visitor over parse tree to populate a mutable geometry) is reusable for any system that needs to convert structured input into a geometric model.

file: src/c_geometry.cpp ↗ | tags: #antlr-visitor #geometry-construction #builder-pattern
Last analyzed: 2026-09-18 18:19:35.957481
Next check: 2026-09-25 18:19:35.907657
$ submit: