Numerical Electromagnetics Code
The Numerical Electromagnetics Code, or NEC, is a popular antenna modeling system for wire and surface antennas. It was originally written in FORTRAN in the 1970s by Gerald Burke and Andrew Poggio of the Lawrence Livermore National Laboratory. The code was made publicly available for general use and has subsequently been distributed for many computer platforms from mainframes to PCs.
NEC is widely used for modelling antenna designs, particularly for common designs like television and radio antennas, shortwave and ham radio, and similar examples. Examples of practically any common antenna type can be found in NEC format on the internet. While highly adaptable, NEC has its limits, and other systems are commonly used for very large or complex antennas, or special cases like microwave antennas.
By far the most common version is NEC-2, the last to be released in fully public form. There is a wide and varied market of applications that embed the NEC-2 code within frameworks to simplify or automate common tasks. Later versions, NEC-3 and NEC-4, are freely available as compiled binaries but have not been nearly as popular.
The code traces its history to an earlier program, BRACT, which was used to analyze antennas consisting of many thin wires in free space. It was useful for modeling certain common types of antennas used on aircraft or spacecraft or other examples where the ground was far enough away that it did not affect the signals. BRACT was developed in the early 1970s by MBAssociates for the US Air Force's Space and Missile Systems Center. MBAssociates, named after the founding partners of Bob Mainhardt and Art Biehl, are better known for the development of the Gyrojet rocket gun. 
BRACT's success led to a second contract with MBAssociates, this time by the Naval Research Laboratory and USAF Rome Air Development Center, to adapt the BRACT code to consider the effect of the ground. This produced the Antenna Modeling Program, or AMP, which was extensively modified to support disk based files, simplify the input and output to make it easier to use, and extensively documented. A follow-up, AMP2, added calculations for extended surfaces like reflectors.
NEC is an advanced version of AMP2, with more options and features. It was written by programmers at Lawrence Livermore National Laboratory (LLNL) under contract to the Naval Ocean Systems Center and the Air Force Weapons Laboratory. The original NEC added a more accurate system for calculating currents along the wires, and at junctions between them, as well as an option that increased the accuracy when the wire was thick, with a low aspect ratio compared to its length. NEC-2 added two major features, a numerical Green's function for working with large planes, and an expansion of the ground-plane code to deal with partially lossy materials that are more realistic for antennas near the ground. With the release of NEC-2, the original became known as NEC-1.
All of these programs originated in the mainframe era, originally running on Control Data machines and later ported to the VAX. The code was written in FORTRAN and designed to take input from punch card stacks in column-delimited format and then print the results on a line printer. These early versions were widely ported to a number of other big-iron platforms, and a profusion of slightly different versions resulted.
A variety of microcomputer based versions using FORTRAN compilers appeared during the late 1980s, often limited by the need to fit into the MS-DOS 640 kB memory footprint. Modern versions normally port the original code to the C programming language, either using automated tools or hand-converted code. C versions have formed the basis for most modern microcomputer versions, and runs on a wide variety of platforms. Modern programs using the nec2 code generally use a graphical user interface (GUI) to provide an editor system that then converts the user's input into a virtual deck of punch cards, passes that as input to the otherwise unchanged nec2 code, and the parses the output to turn it back into GUI output.
How it works
The code is based on the method of moments solution of the electric field integral equation (EFIE) for thin wires and the magnetic field integral equation (MFIE) for closed, conducting surfaces. It uses an iterative method to calculate the currents in a set of wires, and the fields that result.
For receivers, the calculation starts by calculating the electrical field in space for a radio signal of a given frequency travelling along the X axis in three dimensions. This field is uniform in Y and Z, but varies along the X axis; the signal's magnitude at any point along X is defined by the phase at that instant. Antennas work because the field changes over time, which induces current in conductors (or elements), the voltage being defined by the magnitude of the field at that point. An antenna consists of extended but finite length conductors, so the pattern of the field results in different voltages at different points around the antenna.
To calculate the net result, NEC breaks continuous conductors, like rods or wires, into a number of sampled points. It uses simple calculations based on the diameter of the conductor and the wavelength of the signal to determine the induced voltage at each of these locations. Depending on the arrangement of the wires, the voltages in some points will reinforce or resist the voltages at others. NEC sums all of these to determine the net current in each of the conductors.
When a current flows in a conductor it creates a magnetic field. In multi-element antennas, this induces additional voltages in the other elements. Antennas are non-linear in this respect; their elements reradiate the signal and that mixes with the original radio signal being studied. NEC calculates the field resulting from these contributions, adds it to the original radio signal, and then runs the entire calculation again with this modified field. Because the reradiated signal is normally small compared to the original signal, it has a limited perturbative effect that produces an output not that different from the original run. It then feeds that new result back in again, and repeats this process until the system converges.
NEC uses a separate method to calculate the contribution of extended planes of material, like a wire mesh reflector. In this case the plane is considered as a unit and the magnetic contribution is calculated directly and fed back into the calculation once the contributions from the individual wires are considered. Similar integral solutions are used to calculate the effects of the ground plane.
The calculations normally converge rapidly. The output is then sampled at a user-defined point, the load. In a real antenna, this is normally where the wire attaches for connection to the transmitter or receiver. The result is a value that indicates the energy delivered to the load on reception, or the amount of energy absorbed by the antenna during broadcast.
NEC then repeats this entire series of calculations while changing the signal so it approaches the antenna from different angles along the X and Y axes, writing down the results for each combination of angles. The results are then normalized to the strongest signal received (almost always at X and Y = 0, or "head on") to produce a 3D pattern illustrating the relative gain for every angle. The gain relative to an isotropic antenna (dBi), front-to-back ratio, standing wave ratio and the general reception pattern are all evident from these numbers. Programs often process this into more common forms like Smith charts.
The algorithm has no theoretical size limit and can be applied to very large arrays or for detailed modeling of very small antenna systems, but the implementation has many practical limits. NEC models can include wires buried in a homogeneous ground, insulated wires and impedance loads. The algorithm has proven reliable (likely to converge to a solution) and accurate (likely to produce results comparable to measured performance) at modeling 'pipelike' structures like Yagi antennas and radiating towers. The NEC engine provides support for modeling patch antennas as well. It can be used, but is not well suited to, designs like slotted waveguides, fractal patterns or similar designs that are not effectively pipelike.
The method of moments algorithm has practical limitations as well—the number of calculations required to model a three-dimensional structure of N radiating elements is roughly proportional to the cube of the number of elements—i.e. modeling an antenna with 100 wire segments requires 1003 = 1 million calculations. Increasing the number of elements by a factor of 10 requires 10003 = 1 billion calculations, increasing the computing time by a factor of 1000, assuming the simulation completes at all. Consequently, there are other approaches such as geometric optics which are preferred for modeling large structures.
Most programs using NEC include features that run batches of NEC calculations to produce a composite output. A common example is to run the entire calculation suite for different input frequencies, and then plot samples on a single chart. One might use this to sample through the UHF television frequencies for instance, producing a diagram that illustrates the gain across the band. Another common feature is an iterative solver that adjusts a given parameter between runs, say the spacing between elements, in order to maximize performance. These operations are highly independent and can be trivially paralleled on modern machines.
Inputs to the NEC system consist of a series of cards, which in modern systems are represented virtually as individual lines in an ASCII file. Initially the 80-column cards were fixed-format, but modifications allow a more free-format input. The cards start with one of several dozen identifiers that indicate how the card should be interpreted. One of the most common identifiers found in NEC codes is
GW, which defines a single wire (element) in the antenna. Its definition is:
Cols Parameter ---------------- 1- 2 GW 3- 5 I1 - ITG 6-10 I2 - NS 11-20 F1 - XW1 21-30 F2 - YW1 31-40 F3 - ZW1 41-50 F4 - XW2 51-60 F5 - YW2 61-70 F6 - ZW2 71-80 F7 - RAD
The GW in columns 1 and 2 is a literal string, "GW", which the NEC parser uses to identify the type of data on the card. The ITG is a tag, an arbitrary number assigned to this element that is used purely to identify it. Leaving these columns empty defaults to the tag to "0". NS defines the number of segments the wire should be divided into during the calculation, larger numbers break the wire into smaller parts and may produce more accurate results at the cost of increased calculation time. The series of six following numbers defines the endpoints of the wire in X, Y and Z. Finally the RAD input is the radius of the wire. If this is set to zero it indicates that the next card will be a GC card, which includes additional information to define tapering rods.
The following example of a complete input "deck" models a log-periodic antenna, like those used for VHF television reception:
TESTEX5 CM 12 ELEMENT LOG PERIODIC ANTENNA IN FREE SPACE CM 78 SEGMENTS. SIGMA=O/L RECEIVING AND TRANS. PATTERNS. CM DIPOLE LENGTH TO DIAMETER RATIO=150. CE TAU=0.93. SIGMA=0.70. BOOM IMPEDANCE=50. OHMS. GW 1 5 0.0000 -1.0000 0.0000000 0.00000 1.0000 0.000 .00667 GW 2 5 -.7527 -1.0753 0. -.7527 1.0753 0. .00717 GW 3 5 -1.562 -1.1562 0. -1.562 1.1562 0. .00771 GW 4 5 -2.4323 -1.2432 0. -2.4323 1.2432 0. .00829 GW 5 5 -3.368 -1.3368 0. -3.368 1.3368 0. .00891 GW 6 7 -4.3742 -1.4374 0. -4.3742 1.4374 0. .00958 GW 7 7 -5.4562 -1.5456 0. -5.4562 1.5456 0. .0103 GW 8 7 -6.6195 -1.6619 0. -6.6195 1.6619 0. .01108 GW 9 7 -7.8705 -1.787 0. -7.8705 1.787 0. .01191 GW 10 7 -9.2156 -1.9215 0. -9.2156 1.9215 0. .01281 GW 11 9 -10.6619 -2.0662 0. -10.6619 2.0662 0. .01377 GW 12 9 -12.2171 -2.2217 0. -12.2171 2.2217 0. .01481 GE FR 0 0 0 0 46.29 0. TL 1 3 2 3 -50. TL 2 3 3 3 -50. TL 3 3 4 3 -50. TL 4 3 5 3 -50. TL 5 3 6 4 -50. TL 6 4 7 4 -50. TL 7 4 8 4 -50. TL 8 4 9 4 -50. TL 9 4 10 4 -50. TL 10 4 11 5 -50. TL 11 5 12 5 -50. ,0.,0.,0.,.02 EX 0 1 3 10 1 RP 0 37 1 1110 90. 0. -5. 0. EN
The example starts with several CM (comment) cards followed by the last comment on a CE card (comment end). CE cards must be followed by geometry cards, any card starting with a G.
In this case the CE is followed by the twelve GW elements making up the antenna. Each one is longer than the last, and to maintain accuracy, the number of segments increases down the list. All measurements in NEC are given in metres, so the first element is 2 metres wide, running from -1 to 1. The GE card indicates the end of the geometry cards, which causes the NEC code to scan the geometry for overlapping endpoints, which it then connects together to make a single longer conductor. The GE card also has a single input that indicates whether a ground plane is present; in this example it is not specified, so the antenna is in free space.
The FR card then sets the test frequency to 46.29 MHz. FR cards can optionally define the number and magnitude of the frequency steps if the system is being used to analyze the performance across a range of frequencies, but this is not being used in this case. The TL cards (transmission line) connect the various elements together. These can be seen on most log-periodic designs in the form of two thin rods running down the boom between the main antenna elements, although some designs use the boom itself, or hide the wires within the boom. The EX (excitation) card indicates the location of the energy supplied to the design, in this case an incoming plane wave being captured on segment 10, while the RP (radiation pattern) sets up some specifics of the signal.
Finally the EN card (end of run) indicates the stack is complete, at which point the NEC code runs and generates the reports. The reports start by re-printing much of the input, which allows the user to check for errors. It then includes lengthy sections showing how the system broke the antenna down into segments. Finally it begins to list calculated values, in tabular format. A small sample of the output from the sample above includes:
- - - RADIATION PATTERNS - - - - - ANGLES - - - DIRECTIVE GAINS - - - POLARIZATION - - - - E(THETA) - - - - - E(PHI) - - - THETA PHI VERT. HOR. TOTAL AXIAL TILT SENSE MAGNITUDE PHASE MAGNITUDE PHASE DEGREES DEGREES DB DB DB RATIO DEG. VOLTS/M DEGREES VOLTS/M DEGREES 90.00 .00 -999.99 9.75 9.75 .00000 90.00 LINEAR 0.00000E+00 .00 2.46922E+00 -66.00 85.00 .00 -999.99 9.70 9.70 .00000 90.00 LINEAR 0.00000E+00 .00 2.45352E+00 -65.20 [many lines removed] 30.00 .00 -999.99 2.10 2.10 .00000 90.00 LINEAR 0.00000E+00 .00 1.02313E+00 38.02 25.00 .00 -999.99 -.14 -.14 .00000 90.00 LINEAR 0.00000E+00 .00 7.90310E-01 59.26 [more lines removed]
The output indicates that the antenna has a maximum gain of 9.75 dBi, a little over three times the gain of an isotropic antenna. However, as the signal moves even five degrees to the side, this has dropped to 9.5. When you reach 75 degrees off the front, the antenna begins to have negative gain. This indicates that this antenna is fairly directional, and one would expect it to have a high front-to-back ratio.
BRACT was a pure method of moments implementation, suitable for use on antennas consisting of uniform diameter conductors arranged in free space and connected to each other at their ends (if at all). It did not model the contributions of the ground (or water) and was primarily useful for aircraft and spacecraft type applications.
AMP modified BRACT by adding a system for calculating the effects of ground planes.
AMP2 added the ability to model extended closed surfaces.
NEC, or NEC-1
The original NEC, later known as NEC-1 when NEC-2 was introduced, was a modification of the earlier AMP2, adding a more accurate current expansion along wires and at multiple wire junctions, and an option in the wire modeling for far greater accuracy on thick wires. A new model for a voltage source was added and several other modifications made for increased accuracy.
NEC-2 is the highest version of the code within the public domain without a license.
- NEC-2 does not model tapered elements such as those made of telescoping aluminum.
- NEC-2 does not model buried radials or ground stakes.
NEC-3 modified NEC-2 to include a Sommerfeld model to properly model wires buried in or close to the ground.
NEC-4 modified NEC-3 to better model very small antennas, like those on cell phones and WiFi routers. The most recent version, 4.2, includes a better version of the Sommerfeld model used in NEC-3 for in- and near-ground wires, added current sources instead of just voltage sources as in earlier models, and used a new memory management system that allows arbitrarily large designs.
MININEC is an independent implementation the concepts in NEC and uses the same method of moments algorithm to calculate the outcomes. However, the MININEC code is entirely original. The first versions were written in 1980 in BASIC for 32 kB Apple II computers, and after following some advice from Professor Wilton at the University of Mississippi, the first public release was made in 1982 for 64 kB machines. An improved version, MININEC2, was released in 1984, followed by a port to the IBM PC as MININEC3 in 1986. Like the original NEC, MININEC now runs on many platforms, although its popularity has fallen with the more widespread availability of the original NEC codes in C form.
MININEC suffers from some known flaws compared to NEC, the best known being that resonant frequencies may be slightly in error. However, MININEC handles different wire diameters better than NEC-2 and probably NEC-4; this includes different diameter parallel wires, different diameter wires joined at an angle, and tapered diameter antenna elements. Placing sources at an intersection of two wires is a problem for NEC-2 but not MININEC. MININEC converges more slowly (requires more segments) when wires join at an angle, when wire segments of significantly different length are adjacent, and has a weaker ground model.
- PartI 1981, p. 1.
- PartI 1981, p. 2.
- Adler 1993, p. 8.
- PartI 1981, p. 3.
- PartII 1981, pp. 3-5.
- PartI 1981, p. 12.
- PartI 1981, pp. 12-13.
- PartI 1981, pp. 20-36.
- PartI 1981, pp. 18-20.
- PartI 1981, pp. 37-61.
- PartI 1981, pp. 62.
- PartIII 1981, p. 1.
- Adler 1993.
- PartIII 1981, pp. 28-30.
- PartIII 1981, pp. 115-122.
- Chen, Kok (22 May 2012). "Using NEC-4 with cocoaNEC". cocoaNEC.
- "NEC". Lawrence Livermore National Laboratory.
- Olson, Robert (Spring 2003). "EMC Applications for Expert MININEC". IEEE EMC Society Newsletter.
- Lewallen 1991.
- Adler, Dick (November 1993). "Information on the History and Availability of NEC-MOM Codes for PC's & Unix". Applied Computational Electromagnetics Society Newsletter: 8–10.
- Burke, Gerald; Poggio, Andrew (January 1981). NEC Part I: Program Description - Theory (PDF) (Technical report). Lawrence Livermore Laboratory.
- Burke, Gerald; Poggio, Andrew (January 1981). NEC Part II: Program Description - Code (PDF) (Technical report). Lawrence Livermore Laboratory.
- Burke, Gerald; Poggio, Andrew (January 1981). NEC Part III: User's Guide (PDF) (Technical report). Lawrence Livermore Laboratory.
- Lewallen, Roy (February 1991). "MININEC: The Other Edge of The Sword" (PDF). QST Magazine: 18–22.
- This article has an excellent illustrated explanation of the NEC method of moments concepts.
- nec2++ - an extensive rewrite of NEC-2 in C++ licensed under GPLv2, with a C/C++ interface and python bindings. It can easily be incorporated into automatic optimizers.
- 4nec2 - A free NEC2/NEC4 implementation for Microsoft Windows. It is a tool for designing 2D and 3D antennas and modeling their near-field/far-field radiation patterns.
- L. B. Cebik's Antennas, Service and Education - A great repository of antenna modeling and related information, particularly including the survey Some Antenna Modeling Programs.
- Numerical Electromagnetics Code NEC2 unofficial home page - NEC2 documentation and code examples
- MMANA-GAL basic - A free antenna modeling program based on MININEC.
- Xnec2c - A translation of NEC2 into C, NEC2C, and a GTK2 based GUI, Xnec2c.
- NEC Lab - NEC Lab is a powerful tool that uses Numerical Electromagnetics Code (NEC2) and Artificial Intelligence (AI) to design antennas.
- CocoaNEC - Open source GUI front-end for Apple OS X. Includes NEC2 and supports NEC4 with separate license.
- AN-SOF - Simulation software for modeling wire antennas and scatterers. The free version is AN-SOF100.
- EZnec - A well known commercial-based antenna modeling package based on NEC3 and NEC4.
- NEC4WIN NEC4WIN /VM - A Windows XP, Vista simulation program based on Mininec 3.
- AC6LA antenna utilities - A collection of commercial antenna utilities
- Nec-Win plus - A commercial modeling package.
- GAL-ANA - A commercial antenna modeling package based on NEC2 and MININEC.
- GNEC - A commercial NEC package with a graphical user interface.
- MMANA-GAL PRO - A commercial modeling package, up to 45000 segments.