python-necpp icon indicating copy to clipboard operation
python-necpp copied to clipboard

Odd errors in helix geometry

Open aeropung opened this issue 1 year ago • 0 comments

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 .

aeropung avatar Jun 21 '23 18:06 aeropung