forked from AlexMontgomerie/4NEC2_helical_gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnec2_class.py
361 lines (277 loc) · 7.75 KB
/
nec2_class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
"""
Classes to implimented
- EK (maybe?)
- EN
- EX
- FR
- GE
- GH
- GN
- GD
- GS
- LD
- PQ
- RP
"""
class EN:
"""
To indicate to the program the end of all execution
Refer to http://www.nec2.org/part_3/cards/en.html for more information
"""
def __init__(self):
self.EN_out = "EN"
def explain(self):
pass
def construct(self):
return self.EN_out
def validate(self):
pass
class GE:
"""
terminate reading of geometry data cards and reset geometry if
a ground plane is used
GPflag:
* 0 - no ground plane present
* 1 - ground plane present (wire touching ground is interpolated
* -1 - ground plane present (segments touching ground go to zero)
Refer to http://www.nec2.org/part_3/cards/ge.html for more information
"""
def __init__(self, gpflag=0):
self.gpflag = gpflag
self.GE_out = "GE"
def construct(self):
self.GE_out = "GE " + gpflag + "\n"
def validate(self):
if not isinstance(gpflag, int):
raise ValueError('GE: gpflag must be an integer')
if !(gpflag >= -1 or gpflag <= 1):
raise ValueError('GE: gpflag out of bounds')
class GH:
"""
Purpose to generate helix or spiral of wire segments
ITG: tag number assigned to all segments of the helix/spiral
NS: number of segments into which the helix/spiral is divided
S: Spacing between turns
HL: Total length of the helix
A1: radius in x at z = 0
B1: radius in y at z = 0
A2: radius in x at z = HL
B2: radius in y at z = HL
RAD: Radius of the wire
Note,
Structure is a helix if A2 = A1 and HL > 0
Structure is a spiral if A2 = A1 and HL = 0
HL > 0 gives right-handed helix
HL < 0 gives left-handed helix
Refer to http://www.nec2.org/part_3/cards/gh.html for more information
"""
def __init__(self,ITG=0,NS=0,S=0,HL=0,A1=0,B1=0,A2=0,B2=0,RAD=0):
self.ITG = ITG
self.NS = NS
self.S = S
self.HL = HL
self.A1 = A1
self.B1 = B1
self.A2 = A2
self.B2 = B2
self.RAD = RAD
self.GH_out = "GH"
def explain(self):
pass
def construct(self):
self.GH_out = "GH " + self.ITG + " " + self.NS + " " + self.S + " " + \
self.HL + " " + self.A1 + " " + self.B1 + " " + self.A2 + " " + self.B2 + " " + self.RAD + "\n"
return self.GH_out
def get_pitch(self):
#TODO: calculate pitch as a function of the other parameters
pitch = None
return pitch
def get_spacing(self):
#TODO: calculate spacing between wires as function of parameters
spacing = None
return spacing
def validate(self):
#check that they are of the right type (at least ITG and NS are > 0 and integers)
if not isinstance(self.ITG, int):
raise ValueError('GH: ITG must be an integer')
if not isinstance(self.NS, int):
raise ValueError('GH: NS must be an integer')
#check rad > 0
if self.RAD <= 0:
raise ValueError('GH: wire radius must be larger than 0')
class GN:
"""
specify the ground plane parameters
IPERF: ground type flag
* -1 - nullifies previous ground parameters (remainder must be blank)
* 0 - finite ground, reflection coefficient approximation
* 1 - perfectly conductig ground
* 2 - finite ground, Sommerfield/Norton method
NRADL: number of radial wires in ground plane screen
EPSE: dielectric constant for ground (in antenna vicintity)
SIG: conductivity of ground (in antenna vicintity)
"""
def __init__(self):
pass
def explain(self):
pass
def construct(self):
pass
def validate(self):
pass
class GD:
"""
"""
def __init__(self):
pass
def construct(self):
pass
def validate(self):
pass
class GS:
"""
"""
def __init__(self):
pass
def construct(self):
pass
def validate(self):
pass
class LD:
"""
"""
def __init__(self):
pass
def construct(self):
pass
def validate(self):
pass
class PQ:
"""
"""
def __init__(self):
pass
def construct(self):
pass
def validate(self):
pass
class CM:
"""
The CM class is used to comment the calculations, it has one attribute: the comment text.
A CM class is required for each input file.
"""
def __init__(self, comment):
self.comment = comment
self.CM_out = None
def explain(self):
pass
def construct(self):
""" This writes the appropriate line in the .nec file"""
self.CM_out = "CM " + self.comment + "\n"
#Should we just return that string instead of creating a new prop?
def validate(self):
pass
#TODO: this might only be for 4nec2, so maybe not have it?
class SY:
"""
"""
def __init__(self, name, value):
self.name = name
self.value = value
def explain(self):
pass
def construct(self):
pass
#TODO: construct the SY type
def validate(self):
pass
class GW:
"""
The GW class defines a strait wire. A (GW) segment has the folowing properties:
-start_x, start_y, start_z The coordinates of the start point (float)
-end_x, end_y, end_z The coordinates of the end point of the segment (float)
-wire_num an ID for the wire (int)
-wire_seg ??
-radius physical radius of the wire (float)
Refer to http://www.nec2.org/part_3/cards/gw.html for more information
"""
def __init__(self, wire_num, wire_seg, start, end, radius):
self.wire_num = wire_num
self.wire_seg = wire_seg
self.radius = radius
self.start_x = start[0]
self.start_y = start[1]
self.start_z = start[2]
self.end_x = end[0]
self.end_y = end[1]
self.end_z = end[2]
def explain(self):
def construct(self):
pass
def validate(self):
pass
class LD:
"""
"""
def __init__(self):
pass
def explain(self):
def construct(self):
pass
def validate(self):
pass
class EX:
"""
"""
def __init__(self):
pass
def explain(self):
pass
def construct(self):
pass
def validate(self):
pass
class FR:
"""
The FR class describes the frequencies used for the analysis,
it has the folowing properties:
- frequency, the first frequency considered in MHz (float)
- increment, size of steps in MHz or noUnits when sweeping
a frequency domain (float)
- nsteps, number of steps considered (default 1) (int)
- incType, type of incrementation: (int)
+ 0 : linear, frequency incremented by self.increment at each step
+ 1 : logarithmic frequency multiplied by self.increment at each step
More information at: http://www.nec2.org/part_3/cards/fr.html
"""
def __init__(self, frequency = 298.8):
#define single frequency analysis as default case
self.frequency = frequency
self.increment = 0. #MHz
self.nsteps = 1
self.incType = 0
def withLinSpace(self, increment = 0., nsteps = 1):
""" To define a linear incrementation. Give increment in MHz"""
self.increment = increment
self.nsteps = nsteps
self.incType = 0
def withLogSpace(self, increment = 1.,nsteps = 1):
""" To define a logarithmic incrementation. Give increment without units """
self.increment = increment
self.nsteps = nsteps
self.incType = 1
def explain(self):
"""Provides some details on the current FR definition, for debug"""
strFreq1 = str(self.frequency)
if self.nsteps == 1:
print('Describing single frequency analysis at ', strFreq1, ' MHz')
elif self.incType == 0:
strFreq2 = str(self.frequency + self.increment*(self.nsteps - 1))
print('Sweeping linear domain from ', strFreq1, ' to ', strFreq2,' MHz using ', str(self.nsteps), ' steps')
elif self.incType == 1:
strFreq2 = str(self.frequency*(self.increment**(self.nsteps - 1)))
print('Sweeping log domain from ', strFreq1, ' to ', strFreq2,' MHz using ', str(self.nsteps), ' steps')
def construct(self):
pass
def validate(self):
pass