Code Monkey home page Code Monkey logo

nec2-toys's Introduction

nec2-toys

Experiments in Python-assisted nec2 antenna modeling

Goals, History, and Current Status

Update 2015-07-29:

Chris Kuethe has taken over maintainership of this tool. Release 0.2.0 adds support for helixes.

Originally penned by Will Snook:

I started this project because I wanted to modify Kent Britain's 2m "Cheap Yagi" to work with a local repeater. Kent's published 2m Yagi designs are tuned for use near 145 MHz with a relatively narrow usable bandwidth. Since I wanted an antenna for transmitting between 146 and 147 MHz, my initial goal was to model a 2 element Cheap Yagi and adjust it to work at a higher frequency range. I'm now starting to branch out a bit into experimenting with other types of antennas.

Before I started this project, I was manually entering geometry into the xnec2c modeling software for linux. That didn't work out, so I began using Python to generate nec2 format antenna model files. Now my Python code abstracts away many of the details of the arcane nec2 card stack file format, so it's much easier for me to iterate through changes in antenna geometry.

My new workflow is to specify geometry in terms of variables and formulas in python, run the script to translate that into an antenna model in the nec2 file format, then open the .nec file in xnec2c to simulate the model's performance. So far this has been working reasonably well.

I'm gradually building more intelligence about nec2 into my utility code so that I can model increasingly complicated antennas with less and less arcane nec2-related clutter. My first generation model generators included blocks of hardcoded nec2 format text, a good abstraction system for generating straight wires, and a functional but ugly kludge for modeling a single circular wire arc (one was good enough for my initial prototypes).

Since I now want to experiment with folded dipoles, which require two wire arcs, I've started a second generation of my utility code as/nec2utils.py. I moved the first generation utility code into /oldStuff/gen1/ along with the related model generator scripts. For the moment I want to keep those designs around as a reference.

In addition to a good abstraction for multiple circular arcs, my second generation utility code is smart enough to generate GE, FR, EX, RP, and EN cards. Those changes mean my model generators can now communicate various high-level intentions in small amounts of python code rather than lots of obscure hard-coded nec2 text blocks.

Nec2 Antenna Modeling

The Numerical Electromagnetics Code antenna modeling software originated at Lawrence Livermore Labs in the 1970's. It started in FORTRAN and was later translated to C. Currently there are many nec2 based modeling programs, some text based, and some with fancy GUI's. However, they still revolve around an input format which is closely based on what was used with the original FORTRAN punch cards (see http://www.nec2.org/)

Usage

My utility code for dealing with the messy details of nec2 is located in nec2utils.py. It is meant to be imported by the generator scripts for individual antenna models.

Model generators, say antenna1.py or antenna2.py, are meant to be run with python from the console. At the moment the generators each include a hardcoded output filename to which they write a nec2 formatted card stack. For example, running

$ python antenna1.py

might write antenna geometry to the file antenna1.nec in the current working directory. My generator scripts so far also read the file back out to the console for a quick sanity check.

To make plots or other output, you need to feed the .nec files to a nec2 based antenna modeling program. I use xnec2c on Linux, but there are plenty of other options which should theoretically work too.

License

I'm releasing this project under the MIT license, a copy of which is included in the LICENSE file.

Credits

Kent Britain created the "Cheap Yagi" design (http://www.wa5vjb.com/references.html) Will Snook is the author of the original tool from which this was forked.

Authors & Copyright

Copyright (c) 2012 Will Snook (http://willsnook.com) Copyright (c) 2015 Chris Kuethe (https://github.com/ckuethe)

nec2-toys's People

Contributors

ckuethe avatar wsnook avatar

Watchers

 avatar  avatar  avatar

Forkers

rodprice

nec2-toys's Issues

Refactor the rotation unwinding

Now that addHelix uses the same rotation unwinding as addArc, it is clear that this functionality should be moved into a separate method, which both of them can use ... and #3 (turtle graphics) would probably find this handy too.

Grouping and copy-paste-paste-paste-paste...

The GM command does this partially already, but it would be nice to have a way to group multiple elements - say a loop and a wire - into one object (let's call it a "stage") then have the GM wrapper nicely copy and paste a few appropriate replicas of that object.

polygonal approximations to circular patches

NEC2 can only model three- and four-sided patches. Figure out how to approximate a circle to some arbitrarily acceptable degree of precision and generate the appropriate cards...

"turtle graphics" and relative positioning for elements

It would be nice to be able to be able add Point()s, which would make it possible to do turtle graphics with segments...

quarterwave = Point(0, 0, 0.25 * wavelength)
ep = model.last_endpoint
model.addWire(segs, ep, ep + quarterwave)

Accurately tracking the end of the last segment for chaining

It would nice if the user didn't always have to track the position of wire ends. Instead, there should be a method or a property to get that information. That would allow fairly simple instructions like "generate a wire. Stick a helix on the end of that wire. Now attach another wire to the end of a helix..."

wire_start = Point(...)
wire_end = Point(...)
model.addWire(segs, wire_start, wire_end)
wire_append = model.last_endpoint

helix_params = { ... }
rotate = Rotation(...)
xlate = Point(...)
model.addHelix(segs, wire_append, helix_params, rotate, xlate)
wire_append = model.last_endpoint

wire_end = Point(...)
model.addWire(segs,wire_append, wire_end)

Define models in terms of wavelengths

It would be useful to to specify a model in terms of wavelengths rather than absolute physical distances.

"half wave wire, with a 1 turn quarter-wave loop, then a 3/4 wave wire... show me how well that works when scaled for 434, 920, 1090, 2450MHz"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.