### Main function calling all nec2++ examples Source: https://tmolteno.github.io/necpp/test_nec_8c-example.html Calls the three example functions in order: simple_example, example3, and seven_wire_antenna. ```C int main() { simple_example(); example3(); seven_wire_antenna(); return 0; } ``` -------------------------------- ### reset_processing_to_excitation_setup Source: https://tmolteno.github.io/necpp/classnec__context.html Resets the processing state to excitation setup. ```APIDOC ## reset_processing_to_excitation_setup ### Description Resets the processing state to excitation setup. ### Method reset_processing_to_excitation_setup ### Signature void reset_processing_to_excitation_setup() ### Parameters None ### Returns void ``` -------------------------------- ### nec_ground::setup_cliff() Source: https://tmolteno.github.io/necpp/classnec__ground.html Sets up the cliff geometry with given parameters. ```APIDOC ## nec_ground::setup_cliff(nec_float in_eprs2, nec_float in_sig2, nec_float clt, nec_float cht) ### Description Sets up the cliff geometry with given parameters. ### Parameters - in_eprs2 (nec_float) - Relative dielectric constant of medium 2. - in_sig2 (nec_float) - Conductivity of medium 2. - clt (nec_float) - Cliff edge distance. - cht (nec_float) - Cliff height. ### Method Member function ``` -------------------------------- ### get_xpr2 Source: https://tmolteno.github.io/necpp/classnec__context.html Gets the xpr2 parameter. ```APIDOC ## get_xpr2 ### Description Gets the xpr2 parameter. ### Method get_xpr2 ### Signature nec_float get_xpr2() n ### Parameters None ### Returns nec_float - The xpr2 value. ``` -------------------------------- ### Setup cliff ground Source: https://tmolteno.github.io/necpp/nec__ground_8h_source.html Sets up a cliff (two medium ground) with the given second medium parameters and cliff dimensions. ```cpp void setup_cliff(nec_float in_eprs2, nec_float in_sig2, nec_float clt, nec_float cht); ``` -------------------------------- ### get_xpr1 Source: https://tmolteno.github.io/necpp/classnec__context.html Gets the xpr1 parameter. ```APIDOC ## get_xpr1 ### Description Gets the xpr1 parameter. ### Method get_xpr1 ### Signature nec_float get_xpr1() n ### Parameters None ### Returns nec_float - The xpr1 value. ``` -------------------------------- ### get_inc Source: https://tmolteno.github.io/necpp/classnec__context.html Gets the inc parameter. ```APIDOC ## get_inc ### Description Gets the inc parameter. ### Method get_inc ### Signature int get_inc() n ### Parameters None ### Returns int - The inc value. ``` -------------------------------- ### C++ example using nec_context, c_geometry, and nec_radiation_pattern Source: https://tmolteno.github.io/necpp/test_cpp_8cpp-example.html Complete C++ program that builds a NEC2++ geometry, sets ground and loading cards, excites a linear antenna, and prints the radiation pattern. Requires the nec2++ headers and the test_cpp makefile target to compile. The program catches nec_exception and prints its message on failure. ```cpp #include using namespace std; /* An example of how to use nec2++ from within a C++ program. See the makefile target 'test_cpp' for how to compile this (as well as the nec2++) source code. Copyright (C) 2005,2015 Timothy C.A. Molteno (tim@molteno.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "c_geometry.h" #include "nec_context.h" #include "nec_exception.h" #include "nec_radiation_pattern.h" int main(int argc, char **argv) { try { cout << "Nec2++ C++ example. Running (takes a few minutes...)" << endl; nec_context nec; nec.initialize(); c_geometry* geo = nec.get_geometry(); geo->wire(0, 70, -0.048, 0.021, -0.005, 0.035, 0.043, 0.014, 0.001, 1.0, 1.0); geo->wire(0, 66, 0.017, -0.015, 0.014, -0.027, 0.04, -0.031, 0.001, 1.0, 1.0); geo->wire(0, 47, 0.046, -0.01, 0.028, -0.013, -0.005, 0.031, 0.001, 1.0, 1.0); geo->wire(0, 77, -0.048, -0.038, -0.04, 0.049, -0.045, -0.04, 0.001, 1.0, 1.0); nec.geometry_complete(0); nec.gn_card(-1,0,0.0, 0.0, 0.0,0.0, 0.0, 0.0); nec.ld_card(5,0,0,0,3.72e7,0.0,0.0); nec.pt_card(-1, 0, 0, 0); nec.ex_card(EXCITATION_LINEAR, 1, 1, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); nec.fr_card(0, 2, 2400.0, 100.0); nec.rp_card(0, 10, 10, 0,5,0,0, 0.0, 0.0, 9.0, 9.0, 0.0, 0.0); // now get the radiation pattern data. The result index is 0 since // this is the first (and only) radiation pattern. nec_radiation_pattern* rp = nec.get_radiation_pattern(0); int nth = rp->get_ntheta(); int nph = rp->get_nphi(); cout << endl << "Theta \tPhi \tHorizontal \tVertical \tTotal" << endl; for (int j=0; jget_theta(i) << " \t" << rp->get_phi(j) << " \t" << rp->get_power_gain_horiz(i,j) << " \t" << rp->get_power_gain_vert(i,j) << " \t" << rp->get_power_gain(i,j) << " \t" << rp->get_etheta_magnitude(i,j) << " \t" << rp->get_etheta_phase(i,j) << " \t" << rp->get_ephi_magnitude(i,j) << " \t" << rp->get_ephi_phase(i,j) << endl; } } } catch (const nec_exception& e) { cout << e.get_message() << endl; } return 0; } ``` -------------------------------- ### get_frequency Source: https://tmolteno.github.io/necpp/classnec__base__result.html Gets the frequency of the results. ```APIDOC ## get_frequency ### Description Gets the frequency of the results. ### Method get_frequency ### Signature nec_float get_frequency() ### Parameters None ### Returns nec_float - The frequency value. ``` -------------------------------- ### void initialize() Source: https://tmolteno.github.io/necpp/nec__context_8h_source.html Initializes everything, called after construction so that the geometry object can be told about the nec_context. ```APIDOC ## void initialize() ### Description Initializes everything, called after construction so that the geometry object can be told about the nec_context. ### Method initialize ### Parameters None. ### Response No return value. ``` -------------------------------- ### Simple dipole example using nec2++ library Source: https://tmolteno.github.io/necpp/test_nec_8c-example.html Defines a simple dipole using nec_wire, sets up geometry, ground, frequency, excitation, and radiation pattern cards, then prints gain values. Includes a commented NEC card equivalent. ```C void simple_example() { /* GW 0 9 0. 0. 2. 0. 0. 7 .1 GE 1 FR 0 1 0 30. EX 0 5 0 1. GN 1 RP 0 90 1 0000 0 90 1 0 */ nec_context* nec; nec = nec_create(); nec_wire(nec, 0, 9, 0, 0, 2, 0, 0, 7, 0.1, 1, 1); nec_geometry_complete(nec, 1); nec_gn_card(nec, 1, 0, 0, 0, 0, 0, 0, 0); nec_fr_card(nec, 0, 1, 30, 0); nec_ex_card(nec, 0, 0, 5, 0, 1.0, 0, 0, 0, 0, 0); nec_rp_card(nec, 0, 90, 1, 0,5,0,0, 0, 90, 1, 0, 0, 0); printf("Gain: %f, %f +/- %f dB\n",nec_gain_max(nec,0), nec_gain_mean(nec,0), nec_gain_sd(nec,0)); printf("RHCP Gain: %f, %f +/- %f dB\n",nec_gain_rhcp_max(nec,0), nec_gain_rhcp_mean(nec,0), nec_gain_rhcp_sd(nec,0)); printf("LHCP Gain: %f, %f +/- %f dB\n",nec_gain_lhcp_max(nec,0), nec_gain_lhcp_mean(nec,0), nec_gain_lhcp_sd(nec,0)); nec_delete(nec); } ``` -------------------------------- ### safe_array segment and eigen_segment methods Source: https://tmolteno.github.io/necpp/safe__array_8h_source.html Creates a non-owning view of a sub-range of the array. segment takes start and end indices, while eigen_segment takes start and length. The segment method throws a string exception if end_index is -1. ```cpp safe_array segment(int64_t start_index, int64_t end_index) { if (int64_t(-1) == end_index) throw "foo"; int64_t n = end_index - start_index + 1; safe_array result; result._view_ptr = data() + start_index; result._len = n; result._rows = 0; result._cols = 0; result._own_data = false; return result; } safe_array eigen_segment(int64_t start_index, int64_t n) { return segment(start_index, start_index + n - 1); } ``` -------------------------------- ### Seven-wire antenna example using nec2++ library Source: https://tmolteno.github.io/necpp/test_nec_8c-example.html Defines a seven-wire antenna using nec_wire calls, sets up geometry, ground, frequency, excitation, and radiation pattern cards, then prints impedance and gain values. Uses the NEC_ERROR_HANDLE macro to check for errors. ```C #include #include /* C Example using nec2++ as a library Enter the following file into test_nec.c, and compile with gcc -o test_nec test_nec.c -L . -lnecpp -lm */ #define NEC_ERROR_HANDLE(_x) { if (_x != 0) printf("Error: %s\n", nec_error_message()); } void seven_wire_antenna() { nec_context* nec; nec = nec_create(); NEC_ERROR_HANDLE(nec_wire(nec, 1, 9, 0.0, 0.0, 0.0, -0.0166, 0.0045, 0.0714, 0.001, 1.0, 1.0)); NEC_ERROR_HANDLE(nec_wire(nec, 2, 7, -0.0166, 0.0045, 0.0714, -0.0318, -0.0166, 0.017, 0.001, 1.0, 1.0)); NEC_ERROR_HANDLE(nec_wire(nec, 3, 7, -0.0318, -0.0166, 0.017, -0.0318, -0.0287, 0.0775, 0.001, 1.0, 1.0)); NEC_ERROR_HANDLE(nec_wire(nec, 4, 11, -0.0318, -0.0287, 0.0775, -0.0318, 0.0439, 0.014, 0.001, 1.0, 1.0)); /* NEC_ERROR_HANDLE(nec_wire(nec, 5, 7, -0.0318, 0.0439, 0.014, -0.0318, 0.0045, 0.0624, 0.001, 1.0, 1.0));*/ NEC_ERROR_HANDLE(nec_wire(nec, 6, 5, -0.0318, 0.0045, 0.0624, -0.0106, 0.0378, 0.0866, 0.001, 1.0, 1.0)); NEC_ERROR_HANDLE(nec_wire(nec, 7, 7, -0.0106, 0.0378, 0.0866, -0.0106, 0.0257, 0.023, 0.001, 1.0, 1.0)); NEC_ERROR_HANDLE(nec_geometry_complete(nec, 1)); NEC_ERROR_HANDLE(nec_gn_card(nec, 1, 0, 0, 0, 0, 0, 0, 0)); NEC_ERROR_HANDLE(nec_fr_card(nec, 0, 1, 1600.0, 0.0)); NEC_ERROR_HANDLE(nec_ex_card(nec, 0, 1, 1, 0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0)); NEC_ERROR_HANDLE(nec_rp_card(nec, 0, 17, 45, 0,5,0,0, 0, 0, 5, 8, 0, 0)); printf("Impedance: %f, %f\n",nec_impedance_real(nec,0), nec_impedance_imag(nec,0)); printf("Gain: %f, %f +/- %f dB\n",nec_gain_max(nec,0), nec_gain_mean(nec,0), nec_gain_sd(nec,0)); printf("RHCP Gain: %f, %f +/- %f dB\n",nec_gain_rhcp_max(nec,0), nec_gain_rhcp_mean(nec,0), nec_gain_rhcp_sd(nec,0)); printf("LHCP Gain: %f, %f +/- %f dB\n",nec_gain_lhcp_max(nec,0), nec_gain_lhcp_mean(nec,0), nec_gain_lhcp_sd(nec,0)); nec_delete(nec); } ``` -------------------------------- ### nec_radiation_pattern::get_pol_sense Source: https://tmolteno.github.io/necpp/nec__radiation__pattern_8h_source.html Get the polarization sense. ```APIDOC ## get_pol_sense ### Description Get the polarization sense. ### Method const ### Endpoint nec_radiation_pattern::get_pol_sense ### Parameters - **theta_index** (int) - Required - The index of the theta angle. - **phi_index** (int) - Required - The index of the phi angle. ### Returns - **int** - The polarization sense. ``` -------------------------------- ### Vertical half-wavelength antenna over ground example using nec2++ library Source: https://tmolteno.github.io/necpp/test_nec_8c-example.html Defines a vertical half-wavelength antenna over ground, using extended thin wire kernel (EK), and demonstrates both perfect and imperfect ground cases. Prints impedance values for each case. ```C void example3() { /* CMEXAMPLE 3. VERTICAL HALF WAVELENGTH ANTENNA OVER GROUND CM EXTENDED THIN WIRE KERNEL USED CM 1. PERFECT GROUND CM 2. IMPERFECT GROUND INCLUDING GROUND WAVE AND RECEIVING CE PATTERN CALCULATIONS GW 0 9 0. 0. 2. 0. 0. 7. .03 GE 1 EK FR 0 1 0 0 30. EX 0 0 5 0 1. GN 1 RP 0 10 2 1301 0. 0. 10. 90. GN 0 0 0 0 6. 1.000E-03 RP 0 10 2 1301 0. 0. 10. 90. RP 1 10 1 0 1. 0. 2. 0. 1.000E+05 EX 1 10 1 0 0. 0. 0. 10. PT 2 0 5 5 XQ EN */ nec_context* nec; nec = nec_create(); nec_wire(nec, 0, 9, 0., 0.0, 2.0, 0.0, 0.0, 7.0, 0.03, 1.0, 1.0); nec_geometry_complete(nec, 1); nec_ek_card(nec, 0); nec_fr_card(nec, 0, 1, 30., 0 ); nec_ex_card(nec, 0, 0, 5, 0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0); nec_gn_card(nec, 1, 0, 0, 0, 0, 0, 0, 0); nec_rp_card(nec, 0,10,2,1,3,0,1,0.0,0.0,10.0,90.0, 0, 0); printf("Impedance %f\n", nec_impedance_real(nec,0)); // 83.7552291016712) nec_gn_card(nec, 0, 0, 6.0, 1.000E-03, 0.0, 0.0, 0.0, 0.0); nec_rp_card(nec, 0,10,2,1,3,0,1, 0.0,0.0,10.0,90.0, 0, 0); printf("Impedance 2 %f\n", nec_impedance_real(nec,0)); // 83.7552291016712) } ``` -------------------------------- ### nec_impedance_real Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Gets the real part of the impedance. ```APIDOC ## nec_impedance_real ### Description Gets the real part of the impedance. ### Function Signature double nec_impedance_real(nec_context *in_context, int freq_index) ### Parameters - **in_context** (nec_context*) - Required - Pointer to the NEC context. - **freq_index** (int) - Required - Frequency index. ### Returns - **double** - Real part of impedance. ``` -------------------------------- ### nec_gain Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Get the gain from a radiation pattern. ```APIDOC ## nec_gain ### Description Get the gain from a radiation pattern. ### Syntax ```c double nec_gain(nec_context *in_context, int freq_index, int theta_index, int phi_index) ``` n ### Parameters - **in_context** (nec_context*) - Pointer to the NEC context. - **freq_index** (int) - Frequency index. - **theta_index** (int) - Theta index. - **phi_index** (int) - Phi index. ### Returns - **double** - Gain value. ``` -------------------------------- ### c_ggrid class definition with initialization and interpolation methods Source: https://tmolteno.github.io/necpp/c__ggrid_8h_source.html Defines the c_ggrid class with static grid parameters, complex arrays, and an evlcom member. The initialize() method resizes arrays and sets interpolation cache defaults. The interpolate() method performs bivariate cubic interpolation, and sommerfeld() computes Sommerfeld attenuation. ```cpp class c_ggrid { public: static int m_nxa[3], m_nya[3]; static nec_float m_dxa[3], m_dya[3]; static nec_float m_xsa[3], m_ysa[3]; nec_complex m_epscf; complex_array m_ar1, m_ar2, m_ar3; c_evlcom m_evlcom; void initialize() { m_ar1.resize(11*10*4); m_ar2.resize(17*5*4); m_ar3.resize(9*8*4); // initialize interpolation cache m_ip_ixs = -10; m_ip_iys = -10; m_ip_igrs = -10; m_ip_ixeg = 0; m_ip_iyeg = 0; m_ip_dx = 1.0; m_ip_dy = 1.0; m_ip_xs = 0.0; m_ip_ys = 0.0; } void interpolate( nec_float x, nec_float y, nec_complex *f1, nec_complex *f2, nec_complex *f3, nec_complex *f4 ); void sommerfeld( nec_float epr, nec_float sig, nec_float wavelength ); private: // interpolation cache (per-instance, thread-safe) int m_ip_ix, m_ip_iy, m_ip_ixs, m_ip_iys, m_ip_igrs, m_ip_ixeg, m_ip_iyeg; int m_ip_nxm2, m_ip_nym2, m_ip_nxms, m_ip_nyms, m_ip_nd, m_ip_ndp; nec_float m_ip_dx, m_ip_dy, m_ip_xs, m_ip_ys, m_ip_xz, m_ip_yz; nec_complex m_ip_a[4][4], m_ip_b[4][4], m_ip_c[4][4], m_ip_d[4][4]; }; ``` -------------------------------- ### nec_structure_currents::get_frequency Source: https://tmolteno.github.io/necpp/classnec__structure__currents.html Gets the frequency for the results. ```APIDOC ## nec_structure_currents::get_frequency ### Description Gets the frequency for the results. ### Method Member function ### Signature nec_float get_frequency() ### Parameters None. ### Returns - **nec_float** - The frequency value. ``` -------------------------------- ### nec_gn_card Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Sets up ground parameters. ```APIDOC ## nec_gn_card ### Description Sets up ground parameters. ### Function Signature long nec_gn_card(nec_context *in_context, int iperf, int nradl, double epse, double sig, double tmp3, double tmp4, double tmp5, double tmp6) ### Parameters - **in_context** (nec_context*) - Required - Pointer to the NEC context. - **iperf** (int) - Required - Iperf parameter. - **nradl** (int) - Required - Nradl parameter. - **epse** (double) - Required - Epse parameter. - **sig** (double) - Required - Sig parameter. - **tmp3** (double) - Required - Temporary parameter. - **tmp4** (double) - Required - Temporary parameter. - **tmp5** (double) - Required - Temporary parameter. - **tmp6** (double) - Required - Temporary parameter. ### Returns - **long** - Status code. ``` -------------------------------- ### nec_structure_currents::get_patch_number Source: https://tmolteno.github.io/necpp/classnec__structure__currents.html Gets the patch numbers. ```APIDOC ## nec_structure_currents::get_patch_number ### Description Gets the patch numbers. ### Method Member function ### Signature vector get_patch_number() n ### Parameters None. ### Returns - **vector** - Vector of patch numbers. ``` -------------------------------- ### simulate Source: https://tmolteno.github.io/necpp/classnec__context.html Starts a simulation. Optionally computes far fields if the flag is set. ```APIDOC ## simulate ### Description Starts a simulation. Optionally computes far fields if the flag is set. ### Method void ### Signature void simulate(bool far_field_flag=false) ### Parameters - far_field_flag (bool) - Optional - If true, compute far fields (default false) ``` -------------------------------- ### void nec_context::gn_card(int _ground_type_, int _rad_wire_count_, nec_float _tmp1_, nec_float _tmp2_, nec_float _tmp3_, nec_float _tmp4_, nec_float _tmp5_, nec_float _tmp6_) Source: https://tmolteno.github.io/necpp/classnec__context.html Sets ground parameters under the antenna. Specifies the relative dielectric constant and conductivity of ground, and optionally models a radial wire ground screen or a second medium. ```APIDOC ## void nec_context::gn_card(int _ground_type_, int _rad_wire_count_, nec_float _tmp1_, nec_float _tmp2_, nec_float _tmp3_, nec_float _tmp4_, nec_float _tmp5_, nec_float _tmp6_) ### Description Sets ground parameters under the antenna. Specifies the relative dielectric constant and conductivity of ground in the vicinity of the antenna. A second set of ground parameters for a second medium can be specified, or a radial wire ground screen can be modeled using a reflection coefficient approximation. ### Method C++ method ### Parameters - **_ground_type_** (int) - Required - Ground-type flag. Options: -1 (nullifies ground parameters, free-space condition), 0 (finite ground, reflection-coefficient approximation), 1 (perfectly conducting ground), 2 (finite ground, Sommerfeld/Norton method). - **_rad_wire_count_** (int) - Required - Number of radial wires in the ground screen approximation; set to zero implies no ground screen. - **_tmp1_** (nec_float) - Required - Relative dielectric constant for ground (EPSE). Set to zero for perfect ground. - **_tmp2_** (nec_float) - Required - Conductivity in mhos/meter of ground (SIG). Set to zero for perfect ground. If negative, complex dielectric constant is set to EPSR - |SIG|. - **_tmp3_** (nec_float) - Required - For radial wire ground screen: radius of screen in meters. For second medium: relative dielectric constant of medium 2. - **_tmp4_** (nec_float) - Required - For radial wire ground screen: radius of wires in meters. For second medium: conductivity of medium 2 in mhos/meter. - **_tmp5_** (nec_float) - Required - For second medium: distance in meters from origin to join between medium 1 and 2. - **_tmp6_** (nec_float) - Required - For second medium: distance in meters (positive or zero) by which surface of medium 2 is below medium 1. ### Remarks Options for remaining floating point fields (F3-F6): - For infinite ground plane, F3 through F6 are blank. - Radial wire ground screen approximation (NRADL nonzero): screen centered at origin, lies in XY plane. F3 is radius of screen, F4 is radius of wires, F5 and F6 blank. - Second medium parameters (NRADL = 0) for medium outside the first medium (cliff problem). These alter far field patterns but not antenna impedance or current distribution. F3 is relative dielectric constant of medium 2, F4 is conductivity of medium 2, F5 is distance to join, F6 is height difference. ### Examples Referenced by benchmark(), and nec_gn_card(). ``` -------------------------------- ### nec_structure_currents::get_m Source: https://tmolteno.github.io/necpp/classnec__structure__currents.html Gets the number of patches. ```APIDOC ## nec_structure_currents::get_m ### Description Gets the number of patches. ### Method Member function ### Signature int get_m() n ### Parameters None. ### Returns - **int** - The number of patches. ``` -------------------------------- ### nec_structure_currents::get_n Source: https://tmolteno.github.io/necpp/classnec__structure__currents.html Gets the number of segments. ```APIDOC ## nec_structure_currents::get_n ### Description Gets the number of segments. ### Method Member function ### Signature int get_n() n ### Parameters None. ### Returns - **int** - The number of segments. ``` -------------------------------- ### Build geometry programmatically with c_geometry methods Source: https://tmolteno.github.io/necpp/c__geometry_8h.html Builds geometry programmatically by calling wire(), arc(), and other geometry methods, then finalizes with geometry_complete(). Use this when constructing the antenna from primitives rather than reading a file. ```cpp c_geometry g = new c_geometry(); g.wire(xxxxxxx); g.arc(); ... g.geometry_complete(); ``` -------------------------------- ### nec_ex_card() Source: https://tmolteno.github.io/necpp/libnecpp_8h.html Sets up an EX card (Excitation) for the NEC simulation. The function accepts a nec_context pointer and parameters defining the excitation type and source segment. Returns 0 on success, 1 on error. ```APIDOC ## nec_ex_card() ### Description Sets up an EX card (Excitation) for the NEC simulation. The function accepts a nec_context pointer and parameters defining the excitation type and source segment. Returns 0 on success, 1 on error. ### Function Signature long nec_ex_card(nec_context *_in_context_, int _extype_, int _i2_, int _i3_, int _i4_, double _tmp1_, double _tmp2_, double _tmp3_, double _tmp4_, double _tmp5_, double _tmp6_) ### Parameters - **_in_context_** (nec_context*) - Required - The nec_context created with nec_create(). - **_extype_** (int) - Required - Type of excitation. Possible values: - `0` - voltage source (applied-E-field source). - `1` - incident plane wave, linear polarization. - `2` - incident plane wave, right-hand (thumb along the incident k vector) elliptic polarization. - `3` - incident plane wave, left-hand elliptic polarization. - `4` - elementary current source. - `5` - voltage source (current-slope-discontinuity). - **_i2_** (int) - Required - Tag number of the source segment. This tag number along with the number given in (i3) uniquely defines the source segment. If zero, the source segment is identified by the absolute segment number in (i3). - **_i3_** (int) - Required - Specifies the mth segment of the set of segments whose tag numbers equal the number set by the previous parameter. If the previous parameter is zero, this must be the absolute segment number of the source. - **_i4_** (int) - Required - Meaning depends on the extype parameter. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp1_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp2_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp3_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp4_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp5_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. - **_tmp6_** (double) - Required - Floating point parameter, meaning depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for details. ### Return Values - **err** (long) - `0` indicates success, `1` indicates an error occurred. Call nec_error_message() for a detailed message. ### Remarks Simpler versions of the function are provided for common uses: nec_voltage_excitation, nec_current_excitation, and nec_planewave_excitation. The meaning of the floating point parameters depends on the excitation type. See http://www.nec2.org/part_3/cards/ex.html for more details. ### References References nec_context::ex_card(). ``` -------------------------------- ### nec_radiation_pattern::get_etheta_magnitude Source: https://tmolteno.github.io/necpp/nec__radiation__pattern_8h_source.html Get the magnitude of E(THETA). ```APIDOC ## get_etheta_magnitude ### Description Get the magnitude of E(THETA). ### Method non-const ### Endpoint nec_radiation_pattern::get_etheta_magnitude ### Parameters - **theta_index** (int) - Required - The index of the theta angle. - **phi_index** (int) - Required - The index of the phi angle. ### Returns - **nec_float** - The magnitude of E(THETA). ``` -------------------------------- ### void simulate(bool far_field_flag=false) Source: https://tmolteno.github.io/necpp/nec__context_8h_source.html Starts a simulation. The far_field_flag indicates whether to compute far-field patterns. ```APIDOC ## void simulate(bool far_field_flag=false) ### Description Starts a simulation. The far_field_flag indicates whether to compute far-field patterns. ### Method simulate ### Parameters - **far_field_flag** (bool) - Optional - If true, compute far-field patterns. Default is false. ### Response No return value. ``` -------------------------------- ### nec_radiation_pattern::get_ephi_magnitude Source: https://tmolteno.github.io/necpp/nec__radiation__pattern_8h_source.html Get the magnitude of E(PHI). ```APIDOC ## get_ephi_magnitude ### Description Get the magnitude of E(PHI). ### Method non-const ### Endpoint nec_radiation_pattern::get_ephi_magnitude ### Parameters - **theta_index** (int) - Required - The index of the theta angle. - **phi_index** (int) - Required - The index of the phi angle. ### Returns - **nec_float** - The magnitude of E(PHI). ``` -------------------------------- ### nec_radiation_pattern::get_pol_axial_ratio Source: https://tmolteno.github.io/necpp/nec__radiation__pattern_8h_source.html Get the polarization axial ratio. ```APIDOC ## get_pol_axial_ratio ### Description Get the polarization axial ratio. ### Method const ### Endpoint nec_radiation_pattern::get_pol_axial_ratio ### Parameters - **theta_index** (int) - Required - The index of the theta angle. - **phi_index** (int) - Required - The index of the phi angle. ### Returns - **nec_float** - The polarization axial ratio. ``` -------------------------------- ### ex_card (first overload) Source: https://tmolteno.github.io/necpp/classnec__context.html Sets excitation parameters (ex card) with 4 integer parameters. ```APIDOC ## ex_card (first overload) ### Description Sets excitation parameters. ### Method ex_card ### Signature void ex_card(enum excitation_type itmp1, int itmp2, int itmp3, int itmp4, nec_float tmp1, nec_float tmp2, nec_float tmp3, nec_float tmp4, nec_float tmp5, nec_float tmp6) ### Parameters - **itmp1** (enum excitation_type) - Required - Excitation type. - **itmp2** (int) - Required - Second integer parameter. - **itmp3** (int) - Required - Third integer parameter. - **itmp4** (int) - Required - Fourth integer parameter. - **tmp1** (nec_float) - Required - First float parameter. - **tmp2** (nec_float) - Required - Second float parameter. - **tmp3** (nec_float) - Required - Third float parameter. - **tmp4** (nec_float) - Required - Fourth float parameter. - **tmp5** (nec_float) - Required - Fifth float parameter. - **tmp6** (nec_float) - Required - Sixth float parameter. ### Returns void ``` -------------------------------- ### Get ground conductivity Source: https://tmolteno.github.io/necpp/nec__ground_8h_source.html Returns the conductivity of the ground. ```cpp nec_float get_conductivity() const { return this->sig; } ``` -------------------------------- ### NEC2++ Command Line Usage Source: https://tmolteno.github.io/necpp/index.html Displays the available command-line arguments for the nec2++ executable. ```text usage: nec2++ [-i] [-o] -g: print maximum gain to stdout. -b: Perform NEC++ Benchmark. -s: print results to standard output. -c: print results in comma-separated-value (CSV) format, this options is used in conjunction with (-s) above. -h: print this usage information and exit. -v: print nec2++ version number and exit. ``` -------------------------------- ### nec_gain_max Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Gets the maximum gain from a radiation pattern. ```APIDOC ## nec_gain_max ### Description Gets the maximum gain from a radiation pattern. ### Function Signature double nec_gain_max(nec_context *in_context, int freq_index) ### Parameters - **in_context** (nec_context*) - Required - Pointer to the NEC context. - **freq_index** (int) - Required - Frequency index. ### Returns - **double** - Maximum gain value. ``` -------------------------------- ### get_segment_number Source: https://tmolteno.github.io/necpp/classc__geometry.html Gets a segment number for a specified tag. ```APIDOC ## get_segment_number ### Description Gets a segment number for a specified tag. ### Method int64_t get_segment_number(int in_tag, int m) ### Parameters - in_tag (int) - Required - Tag identifier. - m (int) - Required - Index of the segment within the tag. ### Response Returns the segment number as an int64_t. ``` -------------------------------- ### Accessing Multi-Feed Impedance in C++ Source: https://tmolteno.github.io/necpp/index.html Demonstrates how to retrieve real and imaginary impedance values for specific feeds in a multi-excitation simulation using nec_context. ```cpp // Single feed — default feed_index=0 works nec_context nec; // ... set up geometry, excitation ... nec.simulate(); double zr = nec.get_impedance_real(); // feed 0 // Multiple feeds — request specific feeds nec.ex_card(EXCITATION_VOLTAGE, tag1, seg, 0, 1.0, 0.0, ...); nec.ex_card(EXCITATION_VOLTAGE, tag2, seg, 0, 1.0, 0.0, ...); nec.ex_card(EXCITATION_VOLTAGE, tag3, seg, 0, 1.0, 0.0, ...); // ... simulate ... double z0r = nec.get_impedance_real(0, 0); // first feed double z1r = nec.get_impedance_real(0, 1); // second feed double z2i = nec.get_impedance_imag(0, 2); // third feed, imag ``` -------------------------------- ### nec_gain_min Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Gets the minimum gain from a radiation pattern. ```APIDOC ## nec_gain_min ### Description Gets the minimum gain from a radiation pattern. ### Function Signature double nec_gain_min(nec_context *in_context, int freq_index) ### Parameters - **in_context** (nec_context*) - Required - Pointer to the NEC context. - **freq_index** (int) - Required - Frequency index. ### Returns - **double** - Minimum gain value. ``` -------------------------------- ### math_util.h Header with Type Definitions and Math Utilities Source: https://tmolteno.github.io/necpp/math__util_8h_source.html This is the complete math_util.h header file. It includes common.h and safe_array.h, defines typedefs for safe arrays and matrices, Eigen 3D vectors, and provides inline functions for complex constants, exponentials, pi constants, angle conversions, polar/argument helpers, decibel conversions, and vector norms. The file is licensed under GPL. ```cpp #pragma once /* Various Useful Math Utilities for nec2++ Copyright (C) 2004-2015 Timothy C.A. Molteno tim@molteno.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "common.h" #include "safe_array.h" typedef safe_array int_array; typedef safe_array int64_array; typedef safe_array real_array; typedef safe_array complex_array; typedef safe_matrix int_matrix; typedef safe_matrix real_matrix; typedef safe_matrix complex_matrix; typedef Eigen::Matrix nec_3vector; typedef Eigen::Matrix nec_c3vector; inline void vector_fill(complex_array& x, int64_t start, int64_t N, const nec_complex& y) { x.fill(start, N, y); } inline nec_complex cplx_00() { static nec_complex _cplx00(0.0,0.0); return _cplx00; } inline nec_complex cplx_01() { static nec_complex _cplx01(0.0,1.0); return _cplx01; } inline nec_complex cplx_10() { static nec_complex _cplx10(1.0,0.0); return _cplx10; } inline nec_complex cplx_11() { static nec_complex _cplx11(1.0,1.0); return _cplx11; } inline nec_complex cplx_exp(const nec_float& x) { return nec_complex(cos(x),sin(x)); } inline nec_float pi() { static nec_float _pi = 3.1415926536; return _pi; } inline nec_float two_pi() { static nec_float _tmp = 2.0 * pi(); return _tmp; } inline nec_float four_pi() { static nec_float _tmp = 4.0 * pi(); return _tmp; } inline nec_float pi_two() { static nec_float _tmp = pi() / 2.0; return _tmp; } inline nec_float sqrt_pi() { // was SP from common.h static nec_float _tmp = sqrt(pi()); return _tmp; } inline nec_complex two_pi_j() { static nec_complex _tmp(0.0,two_pi()); return _tmp; } inline nec_float rad_to_degrees(nec_float in_radians) { static nec_float _rad_to_deg = 360.0 / (2 * pi()); // 57.29577951 return in_radians * _rad_to_deg; } inline nec_float degrees_to_rad(nec_float in_degrees) { static nec_float _deg_to_rad = (2 * pi()) / 360.0; return in_degrees * _deg_to_rad; } inline nec_complex deg_polar(nec_float r, nec_float theta) { return std::polar(r, degrees_to_rad(theta)); } inline nec_float arg_degrees(nec_complex z) { return rad_to_degrees(std::arg(z)); } inline nec_float atgn2( nec_float x, nec_float y) { if ((0.0 == y) && (0.0 == x)) return 0.0; return( std::atan2(y, x) ); } inline nec_float db10( nec_float x ) { if ( x < 1.0e-20 ) return( -999.99 ); return( 10.0 * log10(x) ); } inline nec_float from_db10( nec_float x ) { if ( x < -99.9 ) return( 0.0 ); return( std::pow(10,x / 10.0)); } inline nec_float db20( nec_float x ) { if ( x < 1.0e-20 ) return( -999.99 ); return( 20.0 * log10(x) ); } inline nec_float norm(const nec_float x, const nec_float y) { return std::sqrt(x*x + y*y); } inline nec_float norm2(const nec_float x, const nec_float y, const nec_float z) { return (x*x + y*y + z*z); } inline nec_float norm(const nec_float x, const nec_float y, const nec_float z) { return std::sqrt(norm2(x,y,z)); } inline nec_float normL1(const nec_float x, const nec_float y, const nec_float z) { return std::fabs(x) + std::fabs(y) + std::fabs(z); } inline nec_float norm(const nec_3vector& v) { return v.norm(); } inline nec_float normL1(const nec_3vector& v) { return normL1(v(0), v(1), v(2)); } ``` -------------------------------- ### nec_gain_min Source: https://tmolteno.github.io/necpp/libnecpp_8h_source.html Get the minimum gain from a radiation pattern. ```APIDOC ## nec_gain_min ### Description Get the minimum gain from a radiation pattern. ### Syntax ```c double nec_gain_min(nec_context *in_context, int freq_index) ``` n ### Parameters - **in_context** (nec_context*) - Pointer to the NEC context. - **freq_index** (int) - Frequency index. ### Returns - **double** - Minimum gain value. ```