-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathnec_context.cpp
More file actions
6966 lines (5884 loc) · 185 KB
/
Copy pathnec_context.cpp
File metadata and controls
6966 lines (5884 loc) · 185 KB
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
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 "nec_context.h"
#include "c_geometry.h"
#include "nec_exception.h"
#include <cstdlib>
nec_context::nec_context() : fnorm(0,0), current_vector(0) {
m_output_fp=NULL;
m_geometry = new c_geometry();
inc=0;
isave=0;
nthic=0;
nphic=0;
impedance_norm_factor = 0.0; // was zpnorm
xpr1=0.0;
xpr2=0.0;
xpr3=0.0;
xpr4=0.0;
xpr5=0.0;
xpr7=0.0;
/*structure_currents is a pointer to the "nec_base_result" which takes care of storing and printing of the currents*/
structure_currents = NULL;
// allocate the ground grid
initialize();
}
nec_context::~nec_context() {
delete m_geometry;
}
/*! \brief
Initialize everything, called after construction so that we
can tell the geometry object what nec_context object to
point to.
*/
void nec_context::initialize() {
DEBUG_TRACE("initialize()");
nthi=0;
nphi=0;
iflow = 1;
thetis=0.0;
phiss=0.0;
iptag=0;
iptagf=0;
iptagt=0;
iptaq=0;
iptaqf=0;
iptaqt=0;
init_voltage_sources();
m_geometry->set_context(this);
}
/*! \brief Private method to initialize the voltage source buffers
*/
void nec_context::init_voltage_sources() {
/* Free vsource buffers */
ivqd.resize(0);
iqds.resize(0);
vqd.resize(0);
vqds.resize(0);
source_segment_array.resize(0);
source_voltage_array.resize(0);
voltage_source_count=0;
nvqd=0;
iped=0;
}
/*! \brief After the geometry has been specified, this function prepares for calculations
*/
void nec_context::calc_prepare()
{
DEBUG_TRACE("calc_prepare()");
iflow=1;
int n_plus_m = m_geometry->n_plus_m();
/* Allocate some buffers */
air.resize(n_plus_m);
aii.resize(n_plus_m);
bir.resize(n_plus_m);
bii.resize(n_plus_m);
cir.resize(n_plus_m);
cii.resize(n_plus_m);
ip.resize(m_geometry->n_plus_2m);
ASSERT((m_geometry->n_segments + m_geometry->m*3 == m_geometry->n_plus_3m));
// TODO FIX HERE... THIS SIZE AINT RIGHT
current_vector.resize(m_geometry->n_segments + m_geometry->m*4);
/* Matrix parameters */
neq= m_geometry->n_plus_2m;
neq2=0;
/* default values for input parameters and flags */
npeq = m_geometry->np + 2*m_geometry->mp;
processing_state = PROCESSING_MEMORY_ALLOC;
rkh=1.;
m_use_exk=false;
m_excitation_type = EXCITATION_VOLTAGE;
nload=0;
network_count=0;
m_near = -1;
ifar = -1;
ncoup=0;
icoup=0;
freq_mhz= em::speed_of_light() / 1.0e6;
ground.default_values();
nfrq=1;
iptflg = -2;
iptflq = -1;
iped=0;
}
/*!\brief Benchmark the libnecpp engine. A score of 1.0 is roughly an Athlon XP 1800. */
nec_float nec_context::benchmark()
{
nec_float start_timer, stop_timer;
secnds( &start_timer );
for (int i=0; i<20; i++)
{
{
/*
CMEXAMPLE 2. CENTER FED LINEAR ANTENNA.
CM CURRENT SLOPE DISCONTINUITY SOURCE.
CM 1. THIN PERFECTLY CONDUCTING WIRE
CE 2. THIN ALUMINUM WIRE
GW 0 8 0. 0. -.25 0. 0. .25 .00001
GE
FR 0 3 0 0 200. 50.
EX 5 0 5 1 1. 0. 50.
XQ
LD 5 0 0 0 3.720E+07
FR 0 1 0 0 300.
EX 5 0 5 0 1.
GN 1
XQ
EN
*/
nec_context nec;
nec.set_gain_only(true);
nec.initialize();
c_geometry* geo = nec.get_geometry();
geo->wire(0,8, 0.0, 0.0, -0.25,
0.0, 0.0, 0.25,
0.00001,
1.0, 1.0);
nec.geometry_complete(0);
nec.fr_card(0, 3, 200.0, 50.0);
nec.ex_card(EXCITATION_VOLTAGE_DISC, 0, 5, 1, 1.0, 0.0, 50.0, 0.0, 0.0, 0.0);
nec.xq_card(0);
nec.ld_card(5, 0, 0,0, 3.72e7, 0.0, 0.0);
nec.fr_card(0, 1, 300.0, 0.0);
nec.ex_card(EXCITATION_VOLTAGE_DISC, 0, 5, 0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0);
nec.gn_card(1, 0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0);
// TODO Keep testing here...
nec.xq_card(0);
/* This line kills the version on Wine! Very strange! I think that the gn card is bad
fixme:msvcrt:MSVCRT_signal (11 (nil)):stub
err:seh:EXC_DefaultHandling Unhandled exception code c0000005 flags 0 addr 0x404e2380
Wine failed with return code 1
*/
}
{
/*
An example showing how to evaluate for maximum gain.
CM GA - NEC FILE
CE go blue !
GW 0 36 0 0 0 -0.042 0.008 0.017 0.001
GW 0 21 -0.042 0.008 0.017 -0.048 0.021 -0.005 0.001
GW 0 70 -0.048 0.021 -0.005 0.039 0.032 -0.017 0.001
GW 0 70 -0.048 0.021 -0.005 0.035 0.043 0.014 0.001
GW 0 50 -0.042 0.008 0.017 0.017 -0.015 0.014 0.001
GW 0 66 0.017 -0.015 0.014 -0.027 0.04 -0.031 0.001
GW 0 85 -0.027 0.04 -0.031 0.046 -0.01 0.028 0.001
GW 0 47 0.046 -0.01 0.028 -0.013 -0.005 0.031 0.001
GW 0 70 0.017 -0.015 0.014 -0.048 -0.038 -0.04 0.001
GW 0 77 -0.048 -0.038 -0.04 0.049 -0.045 -0.04 0.001
GE 0
GN -1
LD 5 0 0 0 3.720E+07
FR 0 1 0 0 2400
PT -1
EX 1 1 1 0 0 0 0 0 0 0 0
RP 0 1 1 0500 90 90 0 0
EN
*/
nec_context nec;
nec.set_gain_only(false);
nec.initialize();
c_geometry* geo = nec.get_geometry();
geo->wire(0, 36, 0, 0, 0, -0.042, 0.008, 0.017, 0.001, 1.0, 1.0);
geo->wire(0, 21, 0.042, 0.002, 0.017, -0.028, 0.011, 0.005, 0.001, 1.0, 1.0);
geo->wire(0, 70, -0.058, 0.021, 0.005, 0.039, 0.062, 0.017, 0.001, 1.0, 1.0);
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, 50, 0.042, 0.018, 0.017, 0.017, 0.015, 0.024, 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, 85, 0.027, 0.04, 0.031, -0.046, -.01, 0.028, 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, 70, 0.027, 0.015, 0.014, -0.078, 0.038, -0.04, 0.001, 1.0, 1.0);
geo->wire(0, 77, 0.078, -0.038, 0.04, 0.049, 0.065, 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, 1, 1, 0,5,0,0, 90.0, 90.0, 0.0, 0.0, 0.0, 0.0);
nec.get_gain_max();
}
}
/* time the process */
secnds( &stop_timer );
stop_timer -= start_timer;
cout << endl << endl;
nec_float sec = stop_timer / 1000.0;
nec_float bench = 70.0 / sec;
return bench;
}
/*! \brief Signal the end of a geometry description.
This function prepares for a calculation by calling calc_prepare().
*/
void nec_context::geometry_complete(int gpflag) {
DEBUG_TRACE("geometry_complete()");
m_geometry->geometry_complete(this, gpflag);
calc_prepare();
}
/*! Add a wire to the geometry,
All co-ordinates are in meters.
\param tag_id The tag ID.
\param segment_count The number of segments.
\param xw1 The x coordinate of the wire starting point.
\param yw1 The y coordinate of the wire starting point.
\param zw1 The z coordinate of the wire starting point.
\param xw2 The x coordinate of the wire ending point.
\param yw2 The y coordinate of the wire ending point.
\param zw2 The z coordinate of the wire ending point.
\param rad The wire radius (meters)
\param rdel For tapered wires, the. Otherwise set to 1.0
\param rrad For tapered wires, the. Otherwise set to 1.0
*/
void nec_context::wire(int tag_id, int segment_count,
nec_float xw1, nec_float yw1, nec_float zw1,
nec_float xw2, nec_float yw2, nec_float zw2,
nec_float rad, nec_float rdel, nec_float rrad)
{
m_geometry->wire(tag_id, segment_count, xw1, yw1, zw1, xw2, yw2, zw2, rad, rdel, rrad);
}
void nec_context::sp_card(int ns,
nec_float x1, nec_float y1, nec_float z1,
nec_float x2, nec_float y2, nec_float z2)
{
m_geometry->sp_card(ns, x1, y1, z1, x2, y2, z2);
}
void nec_context::sc_card(int i2,
nec_float x3, nec_float y3, nec_float z3,
nec_float x4, nec_float y4, nec_float z4)
{
m_geometry->sc_card(i2, x3, y3, z3, x4, y4, z4);
}
void nec_context::gx_card(int i1, int i2) {
m_geometry->gx_card(i1, i2);
}
void nec_context::move( nec_float rox, nec_float roy, nec_float roz, nec_float xs,
nec_float ys, nec_float zs, int its, int nrpt, int itgi )
{
DEBUG_TRACE("nec_context::move nrpt=" << nrpt);
m_geometry->move(rox, roy, roz, xs, ys, zs, its, nrpt, itgi);
}
/*! Add an arc to the geometry,
All co-ordinates are in meters.
\param tag_id The tag ID.
\param segment_count The number of segments.
\param rada The radius.
\param ang1 The angle of the arc starting point.
\param ang2 The angle of the arc end point.
\param rad The wire radius.
*/
void nec_context::arc( int tag_id, int segment_count, nec_float rada,
nec_float ang1, nec_float ang2, nec_float rad ) {
m_geometry->arc(tag_id, segment_count, rada, ang1, ang2, rad);
}
/*! \brief Add an helix to the geometry,
\remark The helix is a versatile m_geometry->element. For example, to generate a spiral printed circuit antenna, use a helix of zero height.
All co-ordinates are in meters.
\param tag_id The tag ID.
\param segment_count The number of segments.
\param s The turn spacing.
\param h1 The total length of the helix (negative for a left-handed helix).
\param a1 x-start radius.
\param b1 y-start radius.
\param a2 x-end radius.
\param b2 y-end radius.
\param rad The wire radius.
*/
void nec_context::helix(int tag_id, int segment_count, nec_float s, nec_float hl, nec_float a1, nec_float b1,
nec_float a2, nec_float b2, nec_float rad) {
/* int tag_id, int segment_count,
nec_float s, nec_float hl, nec_float a1, nec_float b1,
nec_float a2, nec_float b2, nec_float rad
*/
m_geometry->helix(tag_id, segment_count, s, hl, a1, b1, a2, b2, rad);
}
/* "fr" card, frequency parameters
FREQUENCY
I1- O= LINEAR STEP, 1=MULTIPLICATIVE
I2- NO. STEPS, BLANK=1
I3- BLANK -- not used in this function
I4- BLANK -- not used in this function
F1- FREQUENCY OR START FREQUENCY
F2- FREQ INCREMENT, ADD OR MULTIPLY
*/
void nec_context::fr_card(int in_ifrq, int in_nfrq, nec_float in_freq_mhz, nec_float in_del_freq) {
DEBUG_TRACE("fr_card()");
ifrq = in_ifrq;
nfrq = in_nfrq;
if ( nfrq == 0)
nfrq=1;
freq_mhz = in_freq_mhz;
delfrq = in_del_freq;
if ( iped == 1)
impedance_norm_factor = 0.0;
processing_state = PROCESSING_MEMORY_ALLOC;
iflow = 1;
}
void nec_context::ld_card(int itmp1, int itmp2, int itmp3, int itmp4, nec_float tmp1, nec_float tmp2, nec_float tmp3)
{
DEBUG_TRACE("ld_card()");
if ( iflow != 3 )
{
iflow=3;
/* Free loading buffers */
nload=0;
ldtyp.resize(0);
ldtag.resize(0);
ldtagf.resize(0);
ldtagt.resize(0);
zlr.resize(0);
zli.resize(0);
zlc.resize(0);
reset_processing_to_structure_loading();
if ( itmp1 == -1 )
return; // continue card input loop
}
/* Reallocate loading buffers */
nload++;
ldtyp.resize(nload);
ldtag.resize(nload);
ldtagf.resize(nload);
ldtagt.resize(nload);
zlr.resize(nload);
zli.resize(nload);
zlc.resize(nload);
int idx = nload-1;
ldtyp[idx]= itmp1;
ldtag[idx]= itmp2;
if ( itmp4 == 0)
itmp4= itmp3;
ldtagf[idx]= itmp3;
ldtagt[idx]= itmp4;
if ( itmp4 < itmp3 )
{
nec_stop("DATA FAULT ON LOADING CARD No: %d: ITAG "
"STEP1: %d IS GREATER THAN ITAG STEP2: %d",
nload, itmp3, itmp4 );
}
zlr[idx]= tmp1;
zli[idx]= tmp2;
zlc[idx]= tmp3;
}
/* "gn" card, ground parameters under the antenna
GN NEAR GROUND, GROUND SCREEN, ADDED GROUND
I1- -1=SET FREE SPACE (A), 0=REFL COEFF, 1=IDEAL (B), 2-SOMMERFELD
I2- (A) BLANK), NO WIRES IN GND SCREEN (C), 0= NO WIRES (D)
I3- BLANK
I4- BLANK
F1- (A,B) BLANK, DIELECTRIC OF NEAR GROUND
F2- (A,B) BLANK, CONDUCTIVITY OF NEAR GROUND
F3- (A,B) BLANK, (C) RADIUS OF SCREEN, (D) DIELECTRIC 2ND MEDIUM
F4- (A,B) BLANK, (C) RADII SCREEN WIRES, (D) CONDUCT. 2ND MEDIUM
F5- (A,B) BLANK, (C) BLANK, (D) DIST TO 2ND MEDIUM, SEE RP
F6- (A,B) BLANK, (C) BLANK, (D) HEIGHT 2ND MEDIUM (AS IN GD)
*/
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)
{
DEBUG_TRACE("gn_card(" << ground_type << ")");
ground.parse_gn(ground_type, rad_wire_count, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
iflow=4;
reset_processing_to_structure_loading();
}
/*
EX EXCITE STRUCTURE, LAST ENCOUNTERED=USED
I1- 0=E VOLTAGE (A), 1=LINEAR WAVE (B), 2= R CIRC WAVE (B)
3=L CIRC WAVE (B), 4= CURRENT (C), 5= VOLTAGE DISC. (A)
I2- (A) SOURCE TAG#, (B) # TH ANGLS, (C) BLANK
I3- (A) SOURCE SEG#, (B) # PH ANGLS, (C) BLANK
I4- (A) XX= ADMIT.,IMPED. PRINT, X=0 NO/1 DO, (BC), 1= ADM. PRINT
F1- (A) EREAL, (B) TH ANGL, (C) X OF SOURCE
F2- (A) EIMAG, (B) PH ANGL, (C) Y OF SOURCE
F3- (A) NORM FOR I4, (B) ET ANGL, Z OF SOURCE
F4- (A) BLANK, (B) TH INC, (C) ALPHA ANGLE FROM XY
F5- (A) BLANK, (B) PH INC, (C) BETA ANGLE FROM X
F6- (A) BLANK, (B) MIN/MAJ AXIS, PRODUCT AMPS X LENGTH
// NOT YET DONE... F7- (A) BLANK, (B) INCIDENT AMPLITUDE (Volts/m)
*/
void nec_context::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)
{
DEBUG_TRACE("ex_card(" << itmp1
<< "," << itmp2
<< "," << itmp3
<< "," << itmp4
<< "," << tmp1
<< "," << tmp2
<< "," << tmp3
<< "," << tmp4
<< "," << tmp5
<< "," << tmp6
<< ")");
if ( iflow != 5) {
init_voltage_sources();
iflow=5;
reset_processing_to_excitation_setup();
}
masym = itmp4/10;
ASSERT(itmp1 >= 0);
m_excitation_type = itmp1;
if ( (m_excitation_type == EXCITATION_VOLTAGE) || (m_excitation_type == EXCITATION_VOLTAGE_DISC) ) // (Voltage excitation)
{
ntsol=0;
if ( m_excitation_type == EXCITATION_VOLTAGE_DISC) // Voltage DISC.
{
nvqd++;
ivqd.resize(nvqd );
iqds.resize(nvqd );
vqd.resize( nvqd );
vqds.resize(nvqd );
int indx = nvqd-1;
ivqd[indx]= m_geometry->get_segment_number( itmp2, itmp3);
vqd[indx]= nec_complex( tmp1, tmp2);
if ( abs( vqd[indx]) < 1.e-20)
vqd[indx] = cplx_10();
iped= itmp4- masym*10;
impedance_norm_factor= tmp3;
if ( (iped == 1) && (impedance_norm_factor > 0.0) )
iped=2;
return; /* continue card input loop */
} /* if ( m_excitation_type == EXCITATION_VOLTAGE_DISC) */
voltage_source_count++;
source_segment_array.resize(voltage_source_count );
source_voltage_array.resize(voltage_source_count );
{
int indx = voltage_source_count-1;
int seg_number = m_geometry->get_segment_number( itmp2, itmp3);
if (seg_number > m_geometry->segment_length.size()) {
nec_exception* nex = new nec_exception("CHECK DATA, PARAMETER SPECIFYING EXCITATION SOURCE SEGMENT [");
nex->append(seg_number);
nex->append("] IS TOO LARGE" );
throw nex;
}
source_segment_array[indx] = seg_number;
DEBUG_TRACE("Voltage Source: " << nec_complex( tmp1, tmp2));
source_voltage_array[indx]= nec_complex( tmp1, tmp2);
if ( abs( source_voltage_array[indx]) < 1.e-20)
source_voltage_array[indx] = cplx_10();
iped= itmp4- masym*10;
impedance_norm_factor= tmp3;
if ( (iped == 1) && (impedance_norm_factor > 0.0) )
iped = 2;
return; /* continue card input loop */
}
} /* if ( (m_excitation_type == 0) || (m_excitation_type == 5) ) */
nthi= itmp2;
nphi= itmp3;
xpr1= tmp1;
xpr2= tmp2;
xpr3= tmp3;
xpr4= tmp4;
xpr5= tmp5;
xpr6= tmp6;
// xpr7= tmp7; Put this in here once we are parsing NEC4 excitation stuff.
voltage_source_count=0;
nvqd=0;
thetis= xpr1;
phiss= xpr2;
}
/* 5: "tl" cards, network parameters
TL TRANSMISSION LINE
I1- PORT 1 TAG #, BLANK/0, USE I2 AS ABSOLUTE
I2- SEGMENT#, OR ABSOLUTE END 1 SEGMENT, -1=CANCEL NETS/LINES
I3- AS I1 FOR PORT 2
I4- AS I2 FOR PORT 2
F1- LINE Zo, -=CROSSED LINE
F2- LINE LENGTH METERS, BLANK=STRAIGHT LINE P1 TO P2
F3- REAL SHUNT ADM., END 1 MHOS
F4- IMAG SHUNT ADM., END 1
F5- REAL SHUNT ADM., END 2
F6- IMAG SHUNT ADM., END 2
*/
void nec_context::tl_card(int itmp1, int itmp2, int itmp3, int itmp4,
nec_float characteristic_impedance, nec_float tmp2, nec_float tmp3, nec_float tmp4, nec_float tmp5, nec_float tmp6)
{
if ( iflow != 6) {
network_count=0;
ntsol=0;
iflow=6;
reset_processing_to_excitation_setup();
if ( itmp2 == -1 )
return; /* continue card input loop */
}
/* Re-allocate network buffers */
network_count++;
ntyp.resize(network_count);
iseg1.resize(network_count);
iseg2.resize(network_count);
x11r.resize(network_count);
x11i.resize(network_count);
x12r.resize(network_count);
x12i.resize(network_count);
x22r.resize(network_count);
x22i.resize(network_count);
int idx = network_count-1;
ntyp[idx] = 2; // TL card
iseg1[idx]= m_geometry->get_segment_number( itmp1, itmp2);
iseg2[idx]= m_geometry->get_segment_number( itmp3, itmp4);
x11r[idx]= characteristic_impedance;
x11i[idx]= tmp2;
x12r[idx]= tmp3;
x12i[idx]= tmp4;
x22r[idx]= tmp5;
x22i[idx]= tmp6;
if (characteristic_impedance <= 0.0) {
// Negative characteristic impedance implies a crossed line
ntyp[idx] = 3;
x11r[idx] = -characteristic_impedance;
}
}
/* 4:
NT NETWORKS
I1- PORT 1 TAG #, BLANK/0, USE I2 AS ABSOLUTE
I2- SEGMENT#, OR ABSOLUTE END 1 SEGMENT, -1=CANCEL NETS/LINES
I3- AS I1 FOR PORT 2
I4- AS I2 FOR PORT 2
F1- REAL OF Y(11), MHOS
F2- IMAG OF Y(11)
F3- REAL OF Y(12)
F4- IMAG OF Y(12)
F5- REAL OF Y(22)
F6- IMAG OF Y(22)
*/
void nec_context::nt_card(int 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)
{
if ( iflow != 6) {
network_count=0;
ntsol=0;
iflow=6;
reset_processing_to_excitation_setup();
if ( itmp2 == -1 )
return; /* continue card input loop */
}
/* Re-allocate network buffers */
network_count++;
ntyp.resize(network_count);
iseg1.resize(network_count);
iseg2.resize(network_count);
x11r.resize(network_count);
x11i.resize(network_count);
x12r.resize(network_count);
x12i.resize(network_count);
x22r.resize(network_count);
x22i.resize(network_count);
int idx = network_count-1;
ntyp[idx]=1; // NT card
iseg1[idx]= m_geometry->get_segment_number( itmp1, itmp2);
iseg2[idx]= m_geometry->get_segment_number( itmp3, itmp4);
x11r[idx]= tmp1;
x11i[idx]= tmp2;
x12r[idx]= tmp3;
x12i[idx]= tmp4;
x22r[idx]= tmp5;
x22i[idx]= tmp6;
}
/* "xq" execute card - calc. including radiated fields
XQ EXECUTE ACCUMULATED CARD DECK
itmp1-
0=NO PATTERN,
1=XY PATTERN,
2= YZ PATTERN,
3=BOTH
(DO NOT USE FOR RADIAL GND SCREEN OR 2ND GND MEDIUM)
NOTES: FOR A SINGLE FREQUENCY, XQ, NE, NH, RP CAUSE IMMEDIATE EXECUTION
FOR MULTIPLE FREQS, ONLY XQ, RP CAUSE EXECUTION
*/
void nec_context::xq_card(int itmp1)
{
DEBUG_TRACE("xq_card(" << itmp1 << ")");
DEBUG_TRACE("iflow =" << iflow);
if ( ((iflow == 10) && (itmp1 == 0)) ||
((nfrq == 1) && (itmp1 == 0) && (iflow > 7)) )
return; /* continue card input loop */
if ( itmp1 == 0) {
if ( iflow > 7)
iflow=11;
else
iflow=7;
} else {
ifar=0;
rfld=0.;
ipd=0;
iavp=0;
m_rp_normalization=0;
m_rp_output_format=0;
nth=91;
nph=1;
thets=0.0;
phis=0.0;
dth=1.0;
dph=0.0;
if ( itmp1 == 2)
phis=90.0;
if ( itmp1 == 3)
{
nph=2;
dph=90.0;
}
} /* if ( itmp1 == 0) */
simulate(true);
}
/* "gd" card, ground representation */
void nec_context::gd_card(nec_float tmp1, nec_float tmp2, nec_float tmp3, nec_float tmp4) {
DEBUG_TRACE("gd_card(" << tmp1 << ")");
ground.setup_cliff(tmp1, tmp2, tmp3, tmp4);
iflow=9;
}
/*! \brief Standard radiation pattern parameters
\param calc_mode
\param n_theta
\param n_phi
\param output_format The output format (0 major axis, minor axis and total gain printed.
1 vertical, horizontal ant total gain printed.)
\param normalization Controls the type of normalization of the radiation pattern
N = 0 no normalized gain.
= 1 major axis gain normalized.
= 2 minor axis gain normalized.
= 3 vertical axis gain normalized.
= 4 horizontal axis gain normalized.
= 5 total gain normalized.
\param D Selects either power gain or directive gain for both standard printing and normalization. If the structure excitation is an incident plane wave, the quantities printed under the heading "gain" will actually be the scattering cross section (a/lambda 2 ) and will not be affected by the value of d. The column heading for the output will still read "power" or "directive gain," however.
<ul>
<li> D = 0 power gain.
<li> D = 1 directive gain.
</ul>
\param A - Requests calculation of average power gain over the region covered by field points.
<ul>
<li>A = 0 no averaging.
<li>A = 1 average gain computed.
<li>A = 2 average gain computed, printing of gain at the field points used for averaging is suppressed. If NTH or NPH is equal to one, average gain will not be computed for any value of A since the area of the region covered by field points vanishes.
</ul>
\param theta0 - Initial theta angle in degrees (initial z coordinate in meters if I1 = 1).
\param phi0 - Initial phi angle in degrees.
\param delta_theta - Increment for theta in degrees (increment for z in meters if I1 = 1).
\param delta_phi - Increment for phi in degrees.
\param radial_distance - Radial distance (R) of field point from the origin in meters. radial_distance is optional. If it is zero, the radiated electric field will have the factor exp(-jkR)/R omitted. If a value of R is specified, it should represent a point in the far-field region since near components of the field cannot be obtained with an RP card. (If I1 = 1, then radial_distance represents the cylindrical coordinate phi in meters and is not optional. It must be greater than about one wavelength.)
\param gain_norm - Determines the gain normalization factor if normalization has been requested in the normalization parameter. If gain_norm is zero, the gain will be normalized to its maximum value. If gain_norm is not zero, the gain w111 be normalized to the value of gain_norm.
*/
void nec_context::rp_card(int calc_mode, int n_theta, int n_phi,
int output_format, int normalization, int D, int A,
nec_float theta0, nec_float phi0,
nec_float delta_theta, nec_float delta_phi,
nec_float radial_distance, nec_float gain_norm)
{
DEBUG_TRACE("rp_card(" << calc_mode << ")");
ifar= calc_mode;
nth = n_theta;
nph = n_phi;
if ( nth == 0)
nth=1;
if ( nph == 0)
nph=1;
m_rp_output_format = output_format;
m_rp_normalization = normalization;
ipd = D;
iavp = A;
DEBUG_TRACE(" xnda = (" << m_rp_output_format << m_rp_normalization << ipd << iavp << ")");
if ( m_rp_output_format != 0)
m_rp_output_format=1;
if ( ipd != 0)
ipd=1;
// sanity check. Not point normalizing if there are too few data points to normalize on
if ( (nth < 2) || (nph < 2) || (ifar == 1) )
iavp=0;
thets = theta0;
phis = phi0;
dth = delta_theta;
dph = delta_phi;
rfld = radial_distance;
gnor = gain_norm;
iflow=10;
simulate(true);
}
/* "pt" card, print control for current */
void nec_context::pt_card(int itmp1, int itmp2, int itmp3, int itmp4) {
iptflg= itmp1;
iptag= itmp2;
iptagf= itmp3;
iptagt= itmp4;
if ( (itmp3 == 0) && (iptflg != -1) )
iptflg = -2;
if ( itmp4 == 0)
iptagt= iptagf;
}
/* "pq" card, print control for charge */
void nec_context::pq_card(int itmp1, int itmp2, int itmp3, int itmp4) {
iptflq= itmp1;
iptaq= itmp2;
iptaqf= itmp3;
iptaqt= itmp4;
if ( (itmp3 == 0) && (iptflq != -1) )
iptflq = -2;
if ( itmp4 == 0)
iptaqt= iptaqf;
}
/* "kh" card, matrix integration limit */
void nec_context::kh_card(nec_float tmp1) {
rkh = tmp1;
reset_processing_to_structure_loading();
iflow=1;
}
void nec_context::ne_card(int 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)
{
DEBUG_TRACE("ne_card(" << itmp1
<< "," << itmp2
<< "," << itmp3
<< "," << itmp4
<< "," << tmp1
<< "," << tmp2
<< "," << tmp3
<< "," << tmp4
<< "," << tmp5
<< "," << tmp6
<< ")");
ne_nh_card(0, itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
}
void nec_context::nh_card(int 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)
{
DEBUG_TRACE("nh_card(" << itmp1
<< "," << itmp2
<< "," << itmp3
<< "," << itmp4
<< "," << tmp1
<< "," << tmp2
<< "," << tmp3
<< "," << tmp4
<< "," << tmp5
<< "," << tmp6
<< ")");
ne_nh_card(1, itmp1, itmp2, itmp3, itmp4, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6);
}
/* \brief Near field calculation parameters
*/
void nec_context::ne_nh_card(int in_nfeh, int 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)
{
nfeh = in_nfeh;
if ( (iflow == 8) && (nfrq != 1) ) {
m_output.endl(2);
m_output.line("WHEN MULTIPLE FREQUENCIES ARE REQUESTED, "
"ONLY ONE NEAR FIELD CARD CAN BE USED -");
m_output.line(" LAST CARD READ WILL BE USED" );
}
m_near= itmp1;
nrx= itmp2;
nry= itmp3;
nrz= itmp4;
xnr= tmp1;
ynr= tmp2;
znr= tmp3;
dxnr= tmp4;
dynr= tmp5;
dznr= tmp6;
iflow=8;
if ( nfrq == 1)
simulate();
}
/* "ek" card, extended thin wire kernel option */
void nec_context::set_extended_thin_wire_kernel(bool ek_flag) {
m_use_exk = ek_flag;
reset_processing_to_structure_loading();
iflow=1;
}
/* "cp" card, maximum coupling between antennas */
void nec_context::cp_card(int itmp1, int itmp2, int itmp3, int itmp4) {
if ( iflow != 2) {
ncoup=0;
nctag.resize(0);
ncseg.resize(0);
y11a.resize(0);
y12a.resize(0);
}
icoup=0;
iflow=2;
if ( itmp2 == 0)
return; /* continue card input loop */
ncoup++;
nctag.resize(ncoup);
ncseg.resize(ncoup);
nctag[ncoup-1]= itmp1;
ncseg[ncoup-1]= itmp2;
if ( itmp4 == 0)
return; /* continue card input loop */
ncoup++;
nctag.resize(ncoup);
ncseg.resize(ncoup);
nctag[ncoup-1]= itmp3;
ncseg[ncoup-1]= itmp4;
}
/* "pl" card, plot flags
throws int on error.
*/
void nec_context::pl_card(const char* ploutput_filename, int itmp1, int itmp2, int itmp3, int itmp4) {
std::string fname(ploutput_filename);
plot_card = c_plot_card(itmp1,itmp2,itmp3,itmp4, fname);
}
/*! \brief Start a simulation
This function will trigger a calculation. In the traditional NEC
world, This signals the end of the main input section and the
beginning of the frequency do loop.
\param far_field_flag is true if last card was XQ or RP
\warning far_field_flag is should never be specified as true
because both the xq_card() and rp_card() functions will call
this function automatically.
*/
void nec_context::simulate(bool far_field_flag) {