tmolteno / python-necpp Goto Github PK
View Code? Open in Web Editor NEWPyPI module for nec2++
License: GNU General Public License v2.0
PyPI module for nec2++
License: GNU General Public License v2.0
Hi, I try to install PyNEC for Python 3 on Linux Mint 18.3. With the method described in the readme.md. It only installs the python 2 library. Is there an argument for installing for Python 3?
I also tried installing with PIP3 but I get a compiler error:
PyNEC_wrap.cxx:3062:27: fatal error: src/math_util.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
pip3 source file: https://files.pythonhosted.org/packages/11/16/8004bac8412d1cc501ef0cc78b4935086f502711c2db711a2c839aeeeeae/PyNEC-1.7.3.1.tar.gz
At the moment, this library is licensed under GPLv2 which means any code that uses the library(derivative works) must also use the GPLv2 license. This isn't ideal considering this is a library, so I am requesting that it is re-licensed under LGPL which contains a clause allowing other programs to be linked against it without also licensing those programs under GPLv2.
See Geometry issue noted in other issue: If you start with a Wire or something that has a tag number you do not get that error message. If you start with one of the patch commands that does not have explicit tag number, you get that error.
When dealing with a helix - If you put the tag number at the end as the documentation suggests, the move command does not recognize tag number. That is a problem since you have to move the helix after you create it.
The original documentation and websites like this, lead me to believe that NEC prints information regarding Input Power, Radiated Power, Wire Loss, and Efficiency. However, I have yet to see this information when running PyNEC. Which card am I missing? Simple examples like this and this, do not show the printout for these parameters.
Alternatively, how can I access these parameters even if they're not being printed? Is there an online example I missed? I'm hoping to access this information specifically:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
INPUT POWER = 6.8603E-02 WATTS
RADIATED POWER= 5.6868E-02 WATTS
WIRE LOSS = 1.1735E-02 WATTS
EFFICIENCY = 82.89 PERCENT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Hello, I've tried to get PyNEC installed but instructions are a bit messed up all over different links (most likely I'm a beginner with this stuff so it's complicated for me). After I read some of your instructions regarding the installation of PyNEC, this is what I did:
git clone https://github.com/tmolteno/python-necpp.git
cd python-necpp
git submodule init
git submodule update --remote
cd PyNEC
./build.sh
But I got the following error after the last instruction (./build.sh
):
~/python-necpp/necpp_src ~/python-necpp/PyNEC
libtoolize --force --copy
make: libtoolize: Command not found
Makefile.git:12: recipe for target 'all' failed
make: *** [all] Error 127
./build.sh: line 11: ./configure: No such file or directory
~/python-necpp/PyNEC
./build.sh: line 15: pandoc: command not found
Language subdirectory: python
Search paths:
./
./swig_lib/python/
/usr/share/swig3.0/python/
./swig_lib/
/usr/share/swig3.0/
Preprocessing...
Starting language-specific parse...
Processing types...
C++ analysis...
Processing nested classes...
Generating wrappers...
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying PyNEC.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_PyNEC' extension
creating build/necpp_src
creating build/necpp_src/src
creating build/temp.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DBUILD_PYTHON=1 -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -I/usr/lib/python2.7/dist-packages/numpy/core/include -I../necpp_src/src -I../necpp_src/ -I/usr/include/python2.7 -c ../necpp_src/src/matrix_algebra.cpp -o build/temp.linux-x86_64-2.7/../necpp_src/src/matrix_algebra.o -fPIC
In file included from ../necpp_src/src/math_util.h:25:0,
from ../necpp_src/src/matrix_algebra.cpp:203:
../necpp_src/src/common.h:42:20: fatal error: config.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Please, could you help me with this?
hi,
The build.sh includes make and configure. These is not available in windows which shows error/warning.
Python handles build internally, so building separately is not required i think. I tried without these and it worked well. These should be included as options to setup.py, there should be someway to include it.
Thanks
I'm using Python 3.7.2 on MacOS Catalina 10.15.3. python-necpp 1.7.3.5 was installed using virtualenv + pip3:
pip3 install necpp
An example on https://pypi.org/project/necpp/ was rewritten a little to model a dipole on 14 Mhz frequency, 10 meters above the ground:
#!/usr/bin/env python3
import necpp
def handle_nec(result):
if (result != 0):
print(necpp.nec_error_message())
def impedance(frequency):
nec = necpp.nec_create()
handle_nec(necpp.nec_wire(nec, 1, 17, 0, -5.0, 10.0, 0, 5.0, 10.0, 0.001, 1, 1))
# handle_nec(necpp.nec_geometry_complete(nec, 1, 0))
handle_nec(necpp.nec_geometry_complete(nec, 1))
handle_nec(necpp.nec_gn_card(nec, 1, 0, 0, 0, 0, 0, 0, 0))
handle_nec(necpp.nec_fr_card(nec, 0, 1, frequency, 0))
handle_nec(necpp.nec_ex_card(nec, 0, 0, 1, 0, 1.0, 0, 0, 0, 0, 0))
handle_nec(necpp.nec_rp_card(nec, 0, 90, 1, 0,5,0,0, 0, 90, 1, 0, 0, 0))
result_index = 0
z = complex(necpp.nec_impedance_real(nec,result_index),
necpp.nec_impedance_imag(nec,result_index))
necpp.nec_delete(nec)
return z
z = impedance(frequency = 14.0)
print("Impedance \t(%6.1f,%+6.1fI) Ohms" % (z.real, z.imag))
The impedance should be somewhere around 50..72 Ohm, but it's not even close:
Impedance (1162.6,-3578.8I) Ohms
As a side note an original example passes two arguments to nec_geometry_complete while according to http://tmolteno.github.io/necpp/libnecpp_8h.html#a8b6825e0707240cb673bd5ad9166a6ba there is only one argument.
RuntimeError: GEOMETRY HAS ONE OR FEWER SEGMENTS. Please send bug report. This causes an error that we're trying to fix.
The error log requested a bug report, thought I'd submit this.
Not sure how useful this is if you knew about the bug already but this is a reproducible example (I'm running this on python 3.7.4 on windows, haven't tested on linux):
import PyNEC as nec
context = nec.nec_context()
geo = context.get_geometry()
parent = [0, 0, 0]
child = [-0.001, 0, 0.001]
geo.wire(
tag_id=0,
segment_count=1,
xw1=parent[0],
yw1=parent[1],
zw1=parent[2],
xw2=child[0],
yw2=child[1],
zw2=child[2],
rad=0.001,
rdel=1.0,
rrad=1.0
)
context.geometry_complete(0)
The bug itself isn't a huge issue for me, but am happy to help if needed. Let me know if you need any more information.
Hello, I have a problem installing Pynec on Win. As not being able to use Pynec, I'm using Necpp but I have a problem getting the output values, eg the radiation pattern. I was reading that to return the results we use the necpp / antlr / nec.g section. Is there another method?
When testing a dipole antenna in python-necpp the ground does not have an effect even when placing the antenna 2m above ground (80m wavelength, HF). Is there a problem with ground in this Python wrapper or in necpp itself?
Check: when testing a dipole antenna over ground in 4nec2 (NEC2 with GUI) on HF, the ground has a definitive effect on the impedance.
I have tried set_finite_ground(self, ground_dielectric, ground_conductivity) and set_perfect_ground(self) as well as free space modelling. The impedance is unchanged with the different settings in the ground card and with different heights above ground. This seems to be either me using the library incorrectly or a problem in the library / wrapper itself..
Dear Tim Molteno - thank for sharing your necpp/PyNEC package. I am starting to learn using them. I have previously used nec2++.
Unfortunately I encountered some problems with logperiodic_opt.py - and it seems that I have corrected them.
My installation:
$ pip freeze
cycler==0.10.0
kiwisolver==1.1.0
matplotlib==3.0.3
necpp==1.7.3.5
numpy==1.18.0
PyNEC==1.7.3.4
pyparsing==2.4.6
python-dateutil==2.8.1
scipy==1.4.1
six==1.13.0
$
$ python -V
Python 3.5.9
$
I encountered the same exception as #11 :
$ python /Volumes/.../logperiodic_opt.py
Wavelength is 0.1224m, initial length is 0.0612m
Unoptimized antenna...
Traceback (most recent call last):
File "/Volumes/.../logperiodic_opt.py", line 225, in
show_report(initial_l1, initial_x1, initial_tau)
File "/Volumes/.../logperiodic_opt.py", line 168, in show_report
nec = geometry_logperiodic(l1, x1, tau)
File "/Volumes/.../logperiodic_opt.py", line 30, in geometry_logperiodic
nec.set_extended_thin_wire_kernel(True)
File "/Volumes/.../context_clean.py", line 104, in set_extended_thin_wire_kernel
self.context.set_extended_thin_wire_kernel(1)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PyNEC.py", line 181, in set_extended_thin_wire_kernel
return _PyNEC.nec_context_set_extended_thin_wire_kernel(self, ekflag)
TypeError: in method 'nec_context_set_extended_thin_wire_kernel', argument 2 of type 'bool'
$
It was corrected in "context_clean.py" by changing:
def set_extended_thin_wire_kernel(self, enable):
if enable:
debug ("EK", 0)
self.context.set_extended_thin_wire_kernel(1)
else:
debug ("EK", -1)
self.context.set_extended_thin_wire_kernel(0)
to:
def set_extended_thin_wire_kernel(self, enable):
if enable:
debug ("EK", 0)
self.context.set_extended_thin_wire_kernel(True)
else:
debug ("EK", -1)
self.context.set_extended_thin_wire_kernel(False)
Alternative (untested):
def set_extended_thin_wire_kernel(self, enable):
if enable:
debug ("EK", 0) # "0" is bool value?
else:
debug ("EK", -1) # "-1" is bool value?
self.context.set_extended_thin_wire_kernel(enable)
Next problem:
$ python /Volumes/.../logperiodic_opt.py
Wavelength is 0.1224m, initial length is 0.0612m
Unoptimized antenna...
Traceback (most recent call last):
File "/Volumes/.../logperiodic_opt.py", line 225, in
show_report(initial_l1, initial_x1, initial_tau)
File "/Volumes/.../logperiodic_opt.py", line 168, in show_report
nec = geometry_logperiodic(l1, x1, tau)
File "/Volumes/.../logperiodic_opt.py", line 73, in geometry_logperiodic
nec.transmission_line((src_tag, src_seg), (dst_tag, dst_seg), tl_impedance, crossed_line=True)
File "/Volumes/.../context_clean.py", line 166, in transmission_line
self.context.tl_card(src[0], src[1], dst[0], dst[1], impedance, length, shunt_admittance_src.real, shunt_admittance_src.imag, shunt_admittance_dst.real, shunt_admittance_dst.imag)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PyNEC.py", line 154, in tl_card
return _PyNEC.nec_context_tl_card(self, itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6)
TypeError: in method 'nec_context_tl_card', argument 3 of type 'int'
$
It was corrected in "logperiodic_opt.py" by changing:
dipole_center_segs[dipole_tag] = nr_segments / 2 + 1
to:
dipole_center_segs[dipole_tag] = int(nr_segments / 2 + 1)
Next problem:
$ python /Volumes/.../logperiodic_opt.py
Wavelength is 0.1224m, initial length is 0.0612m
Unoptimized antenna...
Initial impedance: ( 68.7, +15.2I) Ohms
Traceback (most recent call last):
File "/Volumes/.../logperiodic_opt_k.py", line 233, in
show_report(initial_l1, initial_x1, initial_tau)
File "/Volumes/.../logperiodic_opt_k.py", line 181, in show_report
print("VSWR @ 50 Ohm is %6.6f" % vswr(z, 50))
NameError: name 'vswr' is not defined
$
It was solved by adding some lines to "antenna_util.py":
comment: https://www.spectrum-soft.com/news/fall2009/vswr.shtm
comment: VSWR = (1 + Γ)/(1 - Γ)
def vswr(z, z0):
refcoef= reflection_coefficient(z, z0)
return np.abs((1+refcoef) / (1-refcoef))
Found a cosmetic feature in "logperiodic_opt.py":
dipoles_count = 5
ax.set_title("Gains of a 5-element log-periodic antenna")
but this statement text has 6-elements/dipoles:
ax.set_title("VSWR of a 6-element log-periodic antenna @ 50 Ohm impedance")
Should be:
ax.set_title("VSWR of a 5-element log-periodic antenna @ 50 Ohm impedance")
Succes!:
$ python /Volumes/.../logperiodic_opt_k.py
Wavelength is 0.1224m, initial length is 0.0612m
Unoptimized antenna...
Initial impedance: ( 68.7, +15.2I) Ohms
VSWR @ 50 Ohm is 1.504232
Optimizing antenna...
[170067.57691282]
[2.99352006e+10]
[664.2220855]
[3172.92141886]
[2.21130758e+14]
[1.65932765e+14]
[-72.51254898]
[7.63701399e+162]
[-85.88192809]
/Volumes/.../logperiodic_opt_k.py:131: RuntimeWarning: overflow encountered in exp
vswr = np.exp(vswr) # a penalty :)
[inf]
[162.31141884]
[2814657.84820799]
[56219791.79510748]
[18389.94075227]
[353.62636522]
[1.04932153e+10]
[1.72020809e+63]
[337.17978192]
[36.15144309]
[inf]
[1214.97294178]
[77.61071636]
[1173.85291273]
[38.56281545]
[11137.11554739]
[227.97267165]
[1.42045473e+78]
[1.80043447e+08]
[inf]
[6.90097778e+299]
[3767.86482674]
[8732.28863228]
[617.89070673]
[4454.19322561]
[800.37870254]
[-27.46209332]
[176.58148057]
[inf]
[7.93680992]
[inf]
[9989.73170367]
[23111.85741754]
[26.86474651]
[266.00280082]
[-67.95101194]
[149.06319162]
[471.85372324]
[4.7626389e+08]
[6.91955508e+99]
[23002.38276151]
[856.38344357]
[27502.95254484]
[172.33542013]
[468275.74625434]
[186.11469588]
[379.27366099]
[-114.46329135]
[170.41566677]
[14602.1149273]
[1.451782e+08]
[11515.15454498]
[146.90249581]
[24557.27793267]
[inf]
[4474.43904716]
[-65.3828824]
[-72.51254898]
[1.15124135e+133]
[62585.72296157]
[1.18280525e+14]
[58597.07656704]
[5.38593198e+08]
[56219791.79510748]
[inf]
[93.83808477]
[3264.25007888]
[2.32784717e+15]
[125.67695268]
[-51.87531769]
[3.00585958e+166]
[2.51282921e+25]
[146.77997042]
[inf]
[2133.37934061]
[234.81718886]
[227.97267165]
[inf]
[-60.83496243]
[63575.38382402]
[81993133.72013435]
[1.65688015e+89]
[74.75227041]
[206.51604418]
[inf]
[914.50576563]
[15.19406269]
[158.71377636]
[inf]
[329.94371578]
[2.95903776e+67]
[5269.0413253]
[91.20128694]
[8.96633509e+08]
[1726461.05702233]
[65397.76404396]
[95.55338681]
[14521.2914334]
[9195025.00934777]
[5160.10179738]
[402.38837302]
[1.22506763e+16]
[256.90713717]
[15.09376148]
[123.06507156]
[1.08631569e+16]
[41917.39233814]
[1.75913081e+17]
[inf]
[1.17850955e+52]
[1.10583884e+40]
differential_evolution step 1: f(x)= -114.463
[618740.32197906]
[550182.9607047]
[1869.54312649]
[214.00305106]
[381.44324215]
[-66.43497009]
[9041.19159919]
[930.8959931]
[inf]
[1.18280525e+14]
[inf]
[42584704.23346002]
[1.49188163e+64]
[-94.0676438]
[5.72728318e+09]
[808.27810112]
[2.27621864e+85]
[96.81384044]
[-9.15306632]
[2.12095806e+10]
[128.60680342]
[390.33215525]
[300.64266903]
[7.80311963e+17]
[16363418.44605475]
[87.0975673]
[12969271.20767927]
[1.7085976e+63]
[-91.34584279]
[8065318.63810747]
[2.23900035e+31]
[12044.72045611]
[1.76096267e+17]
[1088.12148031]
[245.31172266]
[66.08423299]
[1.24334922]
[inf]
[3.0587745e+112]
[1.96921542e+15]
[5269.0413253]
[82.702122]
[177.02112642]
[464.66818866]
[9379.73268852]
[193.81147953]
[inf]
[1.51429799e+08]
[1664.2838717]
[159.29596769]
[338.21607614]
[4892852.38468167]
[193.19507344]
[913.01764471]
[6.39686773e+19]
[-23.86098566]
[170067.57691282]
[27591.70735804]
[-41.49690113]
[1.451782e+08]
differential_evolution step 2: f(x)= -114.463
[4639.01669956]
[189.05366873]
[4915.40567491]
[inf]
[5.48726195e+16]
[68.20165277]
[2.17037366e+13]
[80.01564337]
[5.41554835e+63]
[39749181.51138189]
[inf]
[131.46177975]
[7.36441477e+17]
[-80.07450162]
[1764.20887851]
[26642.47204234]
[8.75515007e+212]
[105.28030639]
[1.39295725e+10]
[5261.4531293]
[3405.81809541]
[-28.23803539]
[10693.55696003]
[-111.19565711]
[inf]
[-57.70057234]
[253.73091661]
[267.04540708]
[4575.04286572]
[9.77489908e+09]
[252.79992851]
[2170.38263892]
[1071.33281531]
[45698759.4355659]
[16474.21908442]
[5621.05018185]
[6.44871548e+17]
[493.20675083]
[inf]
[2877.61051914]
[3667.0682415]
[-112.70427006]
[-109.46227213]
[227.56212346]
[243.61311959]
[1.05480073e+09]
[140.55021493]
[445.36056708]
[1097.7877589]
[111.51259431]
[inf]
[138.58119966]
[242.54972862]
[136.94706515]
[1.10443377e+08]
[4.8206399e+76]
[82187958.64659853]
[1711.1281231]
[-51.65369168]
[39.14463694]
differential_evolution step 3: f(x)= -114.463
[42.62076451]
[inf]
[1.04106961e+12]
[7380041.52669562]
[1632169.01857952]
[inf]
[5599.96483339]
[-36.96147163]
[-85.88192809]
[880.87038267]
[8184505.76472934]
[-24.96440744]
[8691.79511745]
[184.67399979]
[1203.54657982]
[-105.05690237]
[7.36161722e+12]
[702.56181107]
[4.84712728e+15]
[4716.3491683]
[-109.40456119]
[3985.61033585]
[140.19844505]
[-40.53098658]
[2.94632852]
[7208.87367459]
[2237.18710243]
[2.65300397e+43]
[1758.08066794]
[20631.35171498]
[1.35333404e+08]
[94533.34930842]
[1441746.8403909]
[2.70256873e+193]
[1.59810655e+09]
[555.32277551]
[1.45398838e+109]
[518.34764917]
[-59.48212455]
[1324.18986175]
[4161448.603732]
[inf]
[-114.12642718]
[582.75068444]
[2340.60915627]
[7634.92583128]
[640065.41240113]
[65.37599295]
[153.64352677]
[4.31030337e+85]
[921.83968606]
[1.35392206e+14]
[2.20342555e+10]
[178.77298767]
[14040.77317605]
[14160.24164791]
[24997.48151468]
[5.69157376e+09]
[5.04384652e+08]
[189581.78378474]
differential_evolution step 4: f(x)= -114.463
[-28.26125304]
[17101.1558064]
[1631.49928776]
[inf]
[3.86507553e+57]
[1.17365085e+12]
[333.87907712]
[-23.32927606]
[3.6292299e+08]
[4388469.7339449]
[151.08557186]
[1.35952977e+107]
[176.72526384]
[-40.68559776]
[3.15510987e+14]
[697830.74930455]
[82.51692676]
[5796.70980855]
[-39.63406238]
[19021.0204998]
[9.02722422e+11]
[818.07523636]
[1834.99261586]
[2655.28751986]
[207.33408923]
[-3.05906231]
[174.61087673]
[155301.28312455]
[-47.96552479]
[322.65897547]
[45.97316678]
[4.32603027e+11]
[-6.62634109]
[193.84541081]
[316.43806197]
[-27.46209332]
[1.24334922]
[3198.45519679]
[17804.63768788]
[758.60290033]
[5.3762958e+10]
[231.63398614]
[49.9076216]
[42745.66663893]
[807.98736642]
[3047.30996477]
[2987.20549049]
[243.04065869]
[-108.24942404]
[-13.63131641]
[338.49444505]
[300443.77534377]
[inf]
[-86.11384327]
[249.57363326]
[239.00883459]
[3613.89331]
[4061.75880375]
[1107.30838526]
[872.96542637]
differential_evolution step 5: f(x)= -114.463
[80.45367592]
[75136734.90864053]
[-10.67421086]
[563168.98893767]
[6756823.91834454]
[-5.15118894]
[317.89915121]
[inf]
[-85.88192809]
[214.29444008]
[-104.80402682]
[-24.96440744]
[-95.64275663]
[181.18767639]
[1.27751637e+109]
[11711.47352893]
[1.2542132e+15]
[6.3746591e+08]
[2833.66311818]
[inf]
[2454.20460143]
[1.01576229e+57]
[5220495.17828399]
[-111.19565711]
[543.06595941]
[5732.29194248]
[2560.26975773]
[5858.11485032]
[-39.30721045]
[-108.8348618]
[10.62799715]
[6.45734233e+11]
[16101770.58896932]
[241.69216723]
[338.76251874]
[-18.36069649]
[2.30401284e+08]
[2821.78606162]
[1915.02139993]
[-104.81683545]
[2.16046535e+165]
[294057.70273965]
[-11.88714063]
[577.61231898]
[5796.45415254]
[935.39659282]
[1.12004335e+35]
[1.37629632e+21]
[inf]
[-37.08447946]
[-0.71984112]
[-33.31685377]
[5.57417068e+14]
[374.56349327]
[22854013.51063121]
[273.48800749]
[inf]
[inf]
[inf]
[3686.32749024]
differential_evolution step 6: f(x)= -114.463
[-116.31911018]
[311.27694171]
[-22.03937525]
[235.52492996]
[3.69508306e+17]
[8.02001632]
[26612120.21840215]
[-37.39708595]
[1064.95944147]
[1.33603663e+12]
[-64.92081606]
[89134.07081884]
[49190538.0638246]
[865198.55933129]
[72.18333415]
[7.57942974e+08]
[467.8347474]
[1535.99231034]
[1.76394081e+09]
[19024.08906226]
[1345.05596975]
[-27.76162205]
[140.19844505]
[1124.76014763]
[56.63773824]
[28998503.79448122]
[3.18008403e+19]
[-114.95003401]
[-105.89958119]
[36545.81061536]
[-105.75774565]
[297.87758969]
[3303.23158711]
[3.18328722e+09]
[483.46762349]
[3.03994794e+09]
[40218.52571217]
[1659.97520743]
[26.59325196]
[50035396.58818633]
[3667.0682415]
[-53.09675364]
[inf]
[-80.85343357]
[-95.52250973]
[66.81389835]
[74.15771556]
[-36.33743924]
[-61.31461241]
[-107.8207509]
[-113.33399607]
[33452.51232867]
[26032521.43137714]
[35.53082536]
[640831.56720303]
[3.39447684e+08]
[384.7095059]
[692.59819029]
[11071155.90335257]
[-65.74852079]
differential_evolution step 7: f(x)= -116.319
[498.81700013]
[39182.50162821]
[-86.92111666]
[49275.76980321]
[25321836.11913819]
[325.51474415]
[-45.22446542]
[2989.06680433]
[2766.25580038]
[-19.37450379]
[39126294.49149166]
[5.25936364e+10]
[-96.03750342]
[-106.96132195]
[-68.4695362]
[-112.46512492]
[125.11772655]
[2886.58039359]
[-46.97971549]
[-112.09005363]
[6.95564745e+47]
[3.88565222e+13]
[-98.49454371]
[-107.33733076]
[562469.62098427]
[208.92126593]
[411.133138]
[1660837.98608009]
[318.09044398]
[-105.7167565]
[4777.23063744]
[1082.55109255]
[962.65209336]
[610.27938056]
[-116.83996744]
[11278.50880439]
[242.49052584]
[1499.27505472]
[-0.59558552]
[-89.52113094]
[205.62896476]
[-107.15171868]
[-116.35209208]
[-49.82809307]
[2297.33453008]
[99916762.5983476]
[-41.65113847]
[-10.58116078]
[127.17367608]
[-107.43657847]
[-114.69160721]
[-108.21439808]
[1293.62368891]
[57.26673918]
[2315.44300378]
[-100.47041112]
[531.57959287]
[9.59224275]
[1.35850815e+09]
[-111.82178271]
differential_evolution step 8: f(x)= -116.84
[-114.19350744]
[2.12718571e+11]
[1109.41381878]
[-116.78412572]
[-112.2179942]
[1403430.88473923]
[1691.75697879]
[123.24051036]
[inf]
[-115.60806086]
[13386.66043371]
[-106.69761524]
[-50.45224535]
[278.30313124]
[247.3189491]
[20232.39547799]
[52381504.89194211]
[10802150.004029]
[2844.43495279]
[-106.05481824]
[455.20180047]
[-86.44510659]
[-59.28301563]
[1767.20048066]
[42765.89365573]
[-99.36388419]
[253.38903654]
[-112.60765377]
[-47.31995951]
[-64.76030573]
[2.57389174e+237]
[-101.17409214]
[-6.62634109]
[231.23396527]
[-66.91016687]
[-111.58081708]
[-49.67158494]
[424.13990701]
[20.52522195]
[2.60469616e+09]
[-105.77813112]
[6.35632281e+10]
[-97.36689358]
[-112.24576863]
[-106.52095309]
[-111.92712175]
[-114.18810524]
[-94.40166224]
[-108.24942404]
[24958.74204043]
[9.98088211]
[5257428.16451064]
[-2.46584675]
[-110.87812825]
[-111.68740518]
[-5.13449308]
[-114.79444278]
[inf]
[-49.96455689]
[30777899.80688861]
differential_evolution step 9: f(x)= -116.84
[29.68874439]
[33.04661156]
[-23.50799169]
[-107.2307721]
[-112.50466473]
[-70.94209183]
[-45.89747494]
[7.8263863]
[-115.83367869]
[2.84008638e+08]
[-116.28688601]
[-107.44057546]
[131.52931939]
[29.59134611]
[109.02580251]
[-106.85992876]
[59.09109222]
[17119.19658008]
[43.12263979]
[-29.87964417]
[-109.40456119]
[-105.05159103]
[51.26224893]
[-64.03510191]
[-54.07261162]
[3.03361128e+08]
[-112.07941456]
[-107.52280929]
[-101.21838961]
[-111.48403527]
[-106.83076521]
[-107.82394649]
[9.82197329]
[121.79457232]
[1.36717935e+08]
[-43.42032416]
[1.36717935e+08]
[-58.17285486]
[-95.05049444]
[-113.08334493]
[-116.1275876]
[-102.40570974]
[-107.90138956]
[60.76808554]
[-74.58948484]
[-113.63310928]
[-110.26767997]
[-110.85693177]
[12.000214]
[193.95676829]
[-114.41609975]
[-113.42264158]
[-113.10395201]
[-114.58669577]
[-97.76918661]
[-115.49673601]
[-111.46516421]
[-84.81720747]
[-110.85265449]
[-113.77451832]
differential_evolution step 10: f(x)= -116.84
[-116.13839351]
[-84.78147059]
[-91.62252596]
[-86.50528925]
[-116.63767016]
[-98.1813219]
[-83.03997138]
[74.77272458]
[-112.47406299]
[-115.04555737]
[4.31596188e+14]
[-102.19074503]
[-101.06202857]
[-102.352767]
[-112.96961718]
[-113.17991231]
[-115.62556185]
[-100.05336925]
[-96.64274715]
[-109.56193009]
[-116.34628925]
[-112.83692494]
[26.12489332]
[-115.28771928]
[-59.26925469]
[-86.33841186]
[-111.3349228]
[-115.97225002]
[-61.44281997]
[-36.96796466]
[-100.59610802]
[-102.18556614]
[13513.75991724]
[88.98941475]
[-115.00685668]
[-115.06247839]
[-114.60005568]
[-113.35352284]
[-95.05049444]
[-64.86198781]
[-115.51811212]
[-114.88800881]
[-112.55789008]
[-110.59894438]
[-18.68752698]
[-106.52159233]
[-110.04944759]
[-102.09542946]
[-107.89835799]
[-111.0782435]
[-99.82380013]
[-112.30089057]
[-105.92916172]
[-115.09103575]
[-108.85036709]
[-99.55361738]
[-114.97414261]
[-110.80168506]
[-91.94330082]
[-114.82347999]
differential_evolution step 11: f(x)= -116.84
[-111.23121419]
[-111.13597133]
[-105.73136463]
[-75.68863583]
[-32.19472051]
[-106.3793061]
[-111.87659428]
[44.34886501]
[-114.73558283]
[-95.83329317]
[-115.10955161]
[-116.54269633]
[-96.53842845]
[-115.82631598]
[-112.96961718]
[-115.02570675]
[-113.16461767]
[-97.92685876]
[-109.05643912]
[-110.31308446]
[-80.70092981]
[-111.61716097]
[120.87818154]
[-110.65348882]
[-97.91707282]
[-78.858221]
[-109.60328125]
[-114.84500522]
[72.88241991]
[-111.48403527]
[-112.88414773]
[-107.91219282]
[-115.19927802]
[-114.80216021]
[-51.0977708]
[-114.97140849]
[-114.60005568]
[-114.54428024]
[-113.49282368]
[-87.60450055]
[-116.4892705]
[-114.9963979]
[-67.73854367]
[-115.26780344]
[-115.05211981]
[-116.26799859]
[-110.13161494]
[-113.93432779]
[-116.79692797]
[-115.19144038]
[-113.72974628]
[-115.61896996]
[-113.10395201]
[-115.08119134]
[-115.26620523]
[-116.2541272]
[-116.00079956]
[-116.23990783]
[-114.23313813]
[-116.48122762]
differential_evolution step 12: f(x)= -116.84
[-116.58395603]
[-115.99408497]
[-114.43535689]
[-115.94481053]
[-115.07128372]
[-111.56821891]
[-112.38569552]
[2032.59026195]
[-114.48474727]
[-116.36171499]
[-116.76451653]
[-116.73607514]
[-110.0744164]
[-116.72287156]
[-116.33960818]
[-59.48229846]
[-115.06953217]
[-115.70492746]
[-111.84622705]
[-112.09005363]
[-71.29290255]
[-116.74912814]
[-100.57692059]
[-114.41788913]
[-101.59116474]
[-115.07451017]
[-111.70006826]
[-115.90800518]
[-114.40387658]
[-113.83597531]
[-113.91210279]
[-111.79648564]
[-107.59811792]
[-115.80129657]
[-96.80448874]
[-107.0855299]
[-116.42871607]
[-115.1430191]
[-113.30935815]
[-114.70805347]
[-116.4892705]
[-107.31753332]
[-116.12316956]
[-116.78552908]
[-115.74230686]
[-114.23924369]
[-115.00300092]
[-115.33056778]
[-113.34173359]
[-115.19144038]
[-116.64933515]
[-116.27967867]
[-108.84214351]
[-113.12580573]
[-109.79108701]
[-107.23066015]
[-116.2354586]
[-116.17717534]
[-114.24591758]
[-116.7765306]
differential_evolution step 13: f(x)= -116.84
[-116.27524721]
[-116.5742217]
[-45.01990678]
[-115.07194072]
[-116.63767016]
[-113.14897249]
[-115.13575344]
[-113.94082548]
[-116.4429901]
[-116.26183781]
[-114.5677583]
[-115.33656343]
[-116.23767849]
[-116.86256079]
[-115.12655548]
[-114.44235626]
[-116.14198562]
[-115.8414892]
[-115.03563395]
[-115.17315907]
[-116.31047378]
[-116.71083255]
[-116.87025615]
[-115.72914958]
[-97.46722418]
[-114.04864538]
[-116.43241076]
[-115.35088158]
[-115.92804203]
[-115.32399115]
[-111.0988616]
[-102.20553615]
[-116.7788565]
[-111.08083366]
[-116.65332264]
[-115.70313431]
[-116.52527857]
[-115.34072869]
[-115.3138047]
[-111.13031586]
[-116.46630565]
[-116.25664808]
[-114.52572411]
[-113.73553672]
[-116.5925617]
[-115.29096951]
[-115.51748766]
[-111.23842172]
[-116.83769197]
[-115.10006224]
[-114.91623583]
[-115.31503431]
[-115.1864204]
[-116.05801645]
[-115.15369034]
[-115.00175895]
[-115.62845157]
[-115.84073213]
[-111.97835137]
[-115.66968304]
differential_evolution step 14: f(x)= -116.87
[-116.37924236]
[-116.26631471]
[-115.2422387]
[-114.60721558]
[-115.60269691]
[-114.24336394]
[-115.44006041]
[-116.42117767]
[-116.34998942]
[-116.20795181]
[-115.20579018]
[-115.56176325]
[-114.38378565]
[-115.18265756]
[-116.03609692]
[-116.51722107]
[-116.40412892]
[-116.71601585]
[-114.95799291]
[-115.34627945]
[-116.84631089]
[-116.34635034]
[-116.81926656]
[-115.08334949]
[-115.93707202]
[-115.34626719]
[-116.73170971]
[-115.42235303]
[-116.13425449]
[-115.02092789]
[-115.40320096]
[-109.92059424]
[-116.79569922]
[-116.82437975]
[-114.68490646]
[-116.80815926]
[-116.71010516]
[-116.81590664]
[-115.42235303]
[-114.52520366]
[-116.44889217]
[-113.67002278]
[-115.31047012]
[-116.86215743]
[-116.77968582]
[-116.62331038]
[-115.60360515]
[-116.18016162]
[-116.4502355]
[-116.50045831]
[-116.74426995]
[-116.84493591]
[-115.47838096]
[-115.21052154]
[-116.31793569]
[-115.21735038]
[-115.87662749]
[-116.58025637]
[-114.74166175]
[-116.79160744]
differential_evolution step 15: f(x)= -116.87
[-116.87025615]
[-116.87025615]
[-116.87025776]
[-116.87025622]
[244.24580611]
[244.24580611]
[244.24614624]
[244.24594933]
[75863.8557295]
[75863.8557295]
[75864.21997209]
[75864.20634283]
[53461.81349522]
[53461.81349522]
[53461.65217205]
[53461.80634969]
[-116.87026207]
[-116.87026207]
[-116.87026368]
[-116.87026214]
[-116.87050131]
[-116.87050131]
[-116.87050287]
[-116.87050138]
[151.57525324]
[151.57525324]
[151.57680019]
[151.57501419]
[-116.32527665]
[-116.32527665]
[-116.3252569]
[-116.3252783]
[-116.87450663]
[-116.87450663]
[-116.87450706]
[-116.87450677]
[-116.87494887]
[-116.87494887]
[-116.87494868]
[-116.87494903]
[-116.87504919]
[-116.87504919]
[-116.87504905]
[-116.87504935]
[-116.87538899]
[-116.87538899]
[-116.87538903]
[-116.87538912]
[-116.87643248]
[-116.87643248]
[-116.8764328]
[-116.87643253]
[-116.87682789]
[-116.87682789]
[-116.87682797]
[-116.87682789]
[-116.87683309]
[-116.87683309]
[-116.87683309]
[-116.87683309]
[-116.87683327]
[-116.87683327]
[-116.87683327]
[-116.87683327]
Optimized antenna...
Initial impedance: ( 58.3, +20.7I) Ohms
VSWR @ 50 Ohm is 1.507538
$
VSWR can go negative. The correct way to calculate VSWR is: VSWR= (1 + | Γ |)/(1 - | Γ |)
In the code below, the absolute value operators are not included so the VSWR looks like can be negative.
https://github.com/tmolteno/python-necpp/blob/03713c8a53e6114db5ba5a7a4e49601f213e4500/PyNEC/example/antenna_util.py
-Undocumented arguments in wire method. What are they?
-Segment voltage and current? get_structure_currents () returns a unrecognized object. How to parse this?
-Feedpoint impedance?
Why the some source code examples import necpp and other handle the NEC by this
from PyNEC import *
(as TART antenna simulator does)
What is up to date method?
Thanks
The documentation for multiple_patch
in PyNEC follows the original documentation, stating that, "A second card with the following format must immediately follow a SM card", but neither the PyNEC documentation nor the NEC2 documentation state what the SC card is, or how it is implemented.
Since the SC card is not included in the NEC2 documentation, I don't think this is an issue with PyNEC, per se, but since multiple_patch
is a PyNEC feature, it would be great to see an example of this contained somewhere in the documentation given the prevalence of gridded antennas in the booming satellite industry.
Hi @tmolteno ,
There have been trouble compiling and building pynec on windows, macos, linux. To solve this problem, it is required to upgrade the python packaging & distribution. Current version use distutils which has been obsolete by the Python packaging Authority. It is available as legacy version.
Python 2 distutils: https://docs.python.org/2/library/distutils.html
Python 3 distutils: https://docs.python.org/3/library/distutils.html
As per documentation, it is required to upgrade the packaging module. Also, it should be noted that the pip uses setuptools by default, it does not support distutils.
Moreover, distutils can not generate wheels. This error can be seen in the logs of issue #4 . Therefore, it has become a requirement for future version of pynec to use the setuptools as python packaging & distribution module.
@tmolteno Please consider this request.
For more information, visit https://packaging.python.org
Thanks
It seems like the build.sh
script it is specifically designed for Debian-based distros. Also, there are some permission errors that come up. Thus, there are some minor changes that one needs to take into consideration while running this library on Arch-based distros.
build.sh
change swig3.0
to swig-3
. Also, if you don't already have swig3 installed, remember to install it from the archive, as you specifically need this version. sudo pacman -U https://archive.archlinux.org/packages/s/swig3/swig3-3.0.12-3-x86_64.pkg.tar.xz
should take care of that.python setup.py install
, because running sudo python setup.py install
didn't work for me, by using pyenv. Particularly, I am using python 3.6.0, but perhaps there is another version that works. (Just as a reminder, remember to install the dependencies for PyNEC, if you weren't already using pyenv)I believe those are some of the major "patches" that I implemented, but feel free to add something else if it's needed for other systems.
Hello. Trying to install python-necpp with pip, and pip gives this.
'creating build/bdist.linux-x86_64/wheel/necpp-1.7.3.2.data/data/examples
error: can't copy '../necpp_src/example/test.py': doesn't exist or not a regular file
Failed building wheel for necpp'
and in the end
'running install_data
error: can't copy '../necpp_src/example/test.py': doesn't exist or not a regular file
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-HzMynH/necpp/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-iaoCNk-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-HzMynH/necpp/
'
I am on RHEL7. The shared library buids successfully but when I try to do "from PyNEC import *" it produces the error: ModuleNotFoundError: No module named 'PyNEC'
My PYTHONPATH includes $HOME/.local/lib/python3.8/site-packages as confirmed by print(sys.path).
The contents of that directory is:
easy-install.pth PyNEC-1.7.3.6-py3.8-linux-x86_64.egg
There is no directory called PyNEC containing an init.py file.
Here are the contents of the one directory:
$ ls PyNEC-1.7.3.6-py3.8-linux-x86_64.egg/
EGG-INFO examples pycache _PyNEC.cpython-38-x86_64-linux-gnu.so _PyNEC.py
As I understand after compilation of PyNEC, component is added only for python2.7 so I used 2.7.
There was exception in my environment for
python2.7 dipole.py
Wavelength is 0.1224m, initial length is 0.0612m
Traceback (most recent call last):
File "dipole.py", line 96, in <module>
z = impedance(design_freq_mhz, initial_length, nr_segments)
File "dipole.py", line 40, in impedance
nec = geometry(freq_mhz, length, nr_segments)
File "dipole.py", line 17, in geometry
nec.set_extended_thin_wire_kernel(False)
File "/home/(..)/python-necpp/PyNEC/example/context_clean.py", line 107, in set_extended_thin_wire_kernel
self.context.set_extended_thin_wire_kernel(0)
File "/usr/lib64/python2.7/site-packages/PyNEC.py", line 181, in set_extended_thin_wire_kernel
return _PyNEC.nec_context_set_extended_thin_wire_kernel(self, ekflag)
TypeError: in method 'nec_context_set_extended_thin_wire_kernel', argument 2 of type 'bool'
To see example result I have added locally that change which works:
+++ b/PyNEC/example/context_clean.py
@@ -101,10 +101,10 @@ class context_clean(object):
def set_extended_thin_wire_kernel(self, enable):
if enable:
debug ("EK", 0)
- self.context.set_extended_thin_wire_kernel(1)
+ self.context.set_extended_thin_wire_kernel(True)
else:
debug ("EK", -1)
- self.context.set_extended_thin_wire_kernel(0)
+ self.context.set_extended_thin_wire_kernel(False)
BTW: Is there any reconfiguration trick to install PyNec for Python3?
Long story short, I'm trying to build a helical antenna based on physical parameters. What I mean by this is that the user should be able to specify a desired frequency [MHz] which is then converted to wavelength [m] and used to build the antenna. For instance, the relationship between the distance between each turn of the helix and wavelength.
I wrote a function to specify this in more user-friendly terms:
def create_helix(s=1, hl=3, a1=1.0, b1=1.0, a2=1.0, b2=1.0, rad=0.001, tagid=0,
segcnt=36):
'''
Generates a helix or spiral of wire segments.
Parameters:
s: Spacing between helix turns
hl: Total length of the helix
a1: Helical radius (X) at z = 0
b1: Helical radius (Y) at z = 0
a2: Helical radius (X) at z = hl
b2: Helical radius (Y) at z = hl
rad: Radius of the wire
seg_cnt: Number of segments comprising the helix
tag_id: Tag number assigned to all segments of the helix
Returns:
object: <PyNEC geometry object>
NOTES:
* The segments generated by GA form a section of polygons inscribed within
the arc
- If an arc in a different position or orientation is desired, the segements
may be moved within a GM card.
* Use of GA to form a circle will not result in symmetry being used in the
calculation. It is a good way to form the beginning of the circle, to be
completed by GR, however.
'''
return context, geo.helix(s, hl, a1, b1, a2, b2, rad, tagid, segcnt)
Of course, this calls the helix
function from PyNEC:
def helix(self, s, hl, a1, b1, a2, b2, rad, segment_count, tag_id):
return _PyNEC.c_geometry_helix(self, s, hl, a1, b1, a2, b2, rad, segment_count, tag_id)
As a base use case, create_helix(s=1, hl=3, a1=1.0, b1=1.0, a2=1.0, b2=1.0, rad=0.001, tagid=0, segcnt=36)
works fine.
ISSUE 1
If I use a desired frequency of 400 MHz, this is equivalent to a wavelength of 0.749 meters and results in a vertical separation between turns for the helical antenna (S = 0.225*wavelength) of 0.225 * 0.749 = 0.1685. Plugging S = 0.1685
into the previous use case:
create_helix(s=0.1685, hl=3, a1=1.0, b1=1.0, a2=1.0, b2=1.0, rad=0.001, tagid=0, segcnt=36)
results in an error:
Traceback (most recent call last):
File "/Users/apung/Documents/Repositories/antenna-modeling/src/radPattern_3d.py", line 139, in <module>
geometry_module.define_excitation()
File "/Users/apung/Documents/Repositories/antenna-modeling/src/geometry_module.py", line 463, in define_excitation
return context.ex_card(extype, tagTheta, rnkPhi, pntRa, chkimp, vltTheta,
File "/Users/apung/anaconda3/lib/python3.10/site-packages/PyNEC.py", line 151, in ex_card
return _PyNEC.nec_context_ex_card(self, *args)
RuntimeError: NO SEGMENT HAS AN ITAG OF 1
In fact, I get the same error for a value of S = 0.99
, but the simulation run fine with S = 1.0
.
What's causing this? I read through the NEC documentation and the PyNEC documentation, but nothing seems to explain the units well.
Additionally, is there a way I can extract the (X,Y,Z) points of the 36 components that comprise the helix within the context
geometry?
ISSUE 2
For a moment, let's accept that S
simply needs to be greater than 1 to get a working helix. The documentation also states that the helix can be made into a spiral by setting the height (hl
) equal to zero. However, this also seems to be broken, because
geometry_module.create_helix(s=1.5, hl=0, a1=a1, b1=b1, a2=a2, b2=b2, rad=0.001, tagid=0, segcnt=36)
results in the following error:
Traceback (most recent call last):
File "/Users/apung/Documents/Repositories/antenna-modeling/src/radPattern_3d.py", line 134, in <module>
context.geometry_complete(0)
File "/Users/apung/anaconda3/lib/python3.10/site-packages/PyNEC.py", line 148, in geometry_complete
return _PyNEC.nec_context_geometry_complete(self, *args)
RuntimeError: Geometry has no wires or patches.
I would really appreciate any work-arounds and explanations on either of these issues, because I'm at a loss and I cannot seem to find anything in the documentation .
Do this before we create a source distribution.
Hi,
While running
$ python setup.py test
It worked well for example 1-3 and half of example 4. I received ERROR for example 4-and beyond. I think the old syntax is in place.
test_example4 (tests.test_get_gain.TestDipoleGain) ... ERROR
test_patch (tests.test_multiple_sc_cards.TestSurfacePatches) ... ERROR
======================================================================
ERROR: test_example4 (tests.test_get_gain.TestDipoleGain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\users\blue\desktop\python-necpp\pynec\tests\test_get_gain.py", line 25, in test_example4
nec = nec_create()
NameError: name 'nec_create' is not defined
======================================================================
ERROR: test_patch (tests.test_multiple_sc_cards.TestSurfacePatches)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\users\blue\desktop\python-necpp\pynec\tests\test_multiple_sc_cards.py", line 61, in test_patch
self.handle_nec(nec_sp_card(nec, 3, 0.019000, -0.001424, 0.078830, 0.019000, 0.001424, 0.078830))
AttributeError: 'TestSurfacePatches' object has no attribute 'handle_nec'
----------------------------------------------------------------------
Ran 6 tests in 0.326s
FAILED (errors=2)
Test failed: <unittest.runner.TextTestResult run=6 errors=2 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=6 errors=2 failures=0>```
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.