forked from tmolteno/necpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_geometry.cpp
More file actions
3257 lines (2742 loc) · 83.6 KB
/
Copy pathc_geometry.cpp
File metadata and controls
3257 lines (2742 loc) · 83.6 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-2011 Timothy C.A. Molteno
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 "c_geometry.h"
#include "nec_context.h"
#include "nec_exception.h"
#include <cstring>
#include <stdint.h>
c_geometry::c_geometry()
: patch_x1(0,0,0), patch_x2(0,0,0), patch_x3(0,0,0), patch_x4(0,0,0) {
n_segments = 0;
np = 0; // n_segments is the number of segments
m = 0;
mp = 0; // m is the number of patches
m_ipsym = 0;
n_plus_2m = 0;
n_plus_3m = 0;
jsno = 0;
nscon = 0;
maxcon = 0;
m_context = NULL;
m_output = NULL;
}
void c_geometry::set_context(nec_context* in_context) {
m_context = in_context;
m_output = &m_context->m_output;
}
/*! \brief Get a segment number for a specified tag.
\param in_tag The tag
\param in_m The mth segment with the specified tag will be returned.
\return The segment number of the mth segment having the
tag number in_tag. if in_tag=0 segment number m is returned.
*/
int c_geometry::get_segment_number( int in_tag, int in_m)
{
ASSERT(in_tag >= 0);
ASSERT(in_m >= 0);
if (in_m <= 0)
{
throw new nec_exception("CHECK DATA, PARAMETER SPECIFYING SEGMENT POSITION IN A GROUP OF EQUAL TAGS MUST NOT BE ZERO" );
}
if ( 0 == in_tag)
{
return( in_m );
}
int tag_seg_count=0;
for (int i = 0; i < n_segments; i++ )
{
if ( segment_tags[i] == in_tag )
{
tag_seg_count++;
if ( tag_seg_count == in_m)
{
return( i+1 );
}
}
}
throw new nec_exception("NO SEGMENT HAS AN ITAG OF ", in_tag);
return 0;
}
#include "c_plot_card.h"
#include <algorithm>
void str_toupper(std::string &str);
void str_toupper(std::string &str)
{
std::transform(str.begin(),
str.end(),
str.begin(),
::toupper);
}
void c_geometry::parse_geometry(nec_context* in_context, FILE* input_fp )
{
char gm[3];
const char ipt[4] = { 'P', 'R', 'T', 'Q' };
/* input card mnemonic list */
/* "XT" stands for "exit", added for testing */
/* #define GM_NUM 12
char *atst[GM_NUM] =
{
"GW", "GX", "GR", "GS", "GE", "GM", \
"SP", "SM", "GA", "SC", "GH", "GF"
};*/
bool print_structure_spec = true;
int nwire, isct, i1, i2;
int card_int_1, card_int_2; /* The two integer parameters from the geometry card */
nec_float rad, xs1, xs2, ys1, ys2, zs1, zs2, x4=0, y4=0, z4=0;
nec_float x3=0, y3=0, z3=0, xw1, xw2, yw1, yw2, zw1, zw2;
nec_float dummy;
m_ipsym=0;
nwire=0;
n_segments=0;
np=0;
m=0;
mp=0;
isct=0;
/* read geometry data card and branch to */
/* section for operation requested */
do
{
read_geometry_card(input_fp, gm, &card_int_1, &card_int_2, &xw1, &yw1, &zw1, &xw2, &yw2, &zw2, &rad);
/* identify card id mnemonic */
std::string card_id(gm);
str_toupper(card_id);
// int gm_num;
// for( gm_num = 0; gm_num < GM_NUM; gm_num++ )
// if ( strncmp( gm, atst[gm_num], 2) == 0 )
// break;
if ( print_structure_spec )
{
m_output->end_section();
m_output->set_indent(32);
m_output->line("-------- STRUCTURE SPECIFICATION --------");
m_output->line("COORDINATES MUST BE INPUT IN" );
m_output->line("METERS OR BE SCALED TO METERS" );
m_output->line("BEFORE STRUCTURE INPUT IS ENDED" );
m_output->set_indent(0);
m_output->line(" WIRE SEG FIRST LAST TAG");
m_output->line(" No: X1 Y1 Z1 X2 Y2 Z2 RADIUS No: SEG SEG No:" );
print_structure_spec = false;
}
if ( card_id != "SC") // gm_num != 10 )
isct=0;
/* "gw" card, generate segment data for straight wire.
GW STRAIGHT WIRE, ENDS 1,2
card_int_1- TAG NO.
card_int_2- NO. SEGMENTS
xw1- X1
F2- Y1
F3- Z1
F4- X2
F5- Y2
F6- Z2
F7- WIRE RAD., 0=USE GC FOR TAPERED WIRE
*/
if (card_id == "GW")
{
int wire_segment_count = card_int_2;
int wire_tag = card_int_1;
nwire++;
// output some wire diagnostics.
m_output->nec_printf( "\n"
" %5d %10.4f %10.4f %10.4f %10.4f"
" %10.4f %10.4f %10.4f %5d %5d %5d %4d",
nwire, xw1, yw1, zw1, xw2, yw2, zw2, rad, wire_segment_count, n_segments+1, n_segments + wire_segment_count, wire_tag );
if ( rad != 0.0) // rad == 0 implies a tapered wire
{
xs1 = 1.0;
ys1 = 1.0;
}
else
{
int ix,iy;
read_geometry_card(input_fp, gm, &ix, &iy, &xs1, &ys1, &zs1,
&dummy, &dummy, &dummy, &dummy);
if ( strcmp(gm, "GC" ) != 0 )
{
throw new nec_exception("GEOMETRY DATA CARD ERROR" );
}
m_output->nec_printf(
"\n ABOVE WIRE IS TAPERED. SEGMENT LENGTH RATIO: %9.5f\n"
" "
"RADIUS FROM: %9.5f TO: %9.5f", xs1, ys1, zs1 );
if ( (ys1 == 0) || (zs1 == 0) )
{
throw new nec_exception("GEOMETRY DATA CARD ERROR" );
}
rad= ys1;
ys1= pow( (zs1/ys1), (1./(wire_segment_count-1.)) );
}
wire(wire_tag, wire_segment_count, xw1, yw1, zw1, xw2, yw2, zw2, rad, xs1, ys1);
}
/* reflect structure along x,y, or z */
/* axes or rotate to form cylinder. */
/* "gx" card */
else if (card_id == "GX")
{ gx_card(card_int_1, card_int_2);
}
/* "gr" card */
else if (card_id == "GR")
{
m_output->nec_printf(
"\n STRUCTURE ROTATED ABOUT Z-AXIS %d TIMES"
" - LABELS INCREMENTED BY %d\n", card_int_2, card_int_1 );
int ix = -1;
int iy = 0;
int iz = 0;
reflect( ix, iy, iz, card_int_1, card_int_2);
}
/* "gs" card, scale structure dimensions by factor xw1. */
else if (card_id == "GS")
{
m_output->nec_printf(
"\n STRUCTURE SCALED BY FACTOR: %10.5f", xw1 );
scale(xw1);
}
/* "ge" card, terminate structure geometry input. */
else if (card_id == "GE")
{
geometry_complete(in_context, card_int_1);
return;
}
/* "gm" card, move structure or reproduce */
/* original structure in new positions. */
else if (card_id == "GM")
{
m_output->nec_printf(
"\n THE STRUCTURE HAS BEEN MOVED, MOVE DATA CARD IS:\n"
" %3d %5d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f",
card_int_1, card_int_2, xw1, yw1, zw1, xw2, yw2, zw2, rad );
xw1= degrees_to_rad(xw1);
yw1= degrees_to_rad(yw1);
zw1= degrees_to_rad(zw1);
move( xw1, yw1, zw1, xw2, yw2, zw2, (int)( rad+.5), card_int_2, card_int_1);
}
/* "sp" card, generate single new patch */
else if (card_id == "SP")
{
i1= m+1;
card_int_2++;
if ( card_int_1 != 0)
{
throw new nec_exception("PATCH DATA ERROR" );
}
m_output->nec_printf( "\n"
" %5d%c %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f",
i1, ipt[card_int_2-1], xw1, yw1, zw1, xw2, yw2, zw2 );
if ( (card_int_2 == 2) || (card_int_2 == 4) )
isct=1;
if ( card_int_2 > 1)
{
// read another geometry card for the rest of the patch data.
int ix,iy;
read_geometry_card(input_fp, gm, &ix, &iy, &x3, &y3, &z3, &x4, &y4, &z4, &dummy);
if ( (card_int_2 == 2) || (card_int_1 > 0) )
{
x4= xw1+ x3- xw2;
y4= yw1+ y3- yw2;
z4= zw1+ z3- zw2;
}
m_output->nec_printf( "\n"
" %11.5f %11.5f %11.5f %11.5f %11.5f %11.5f",
x3, y3, z3, x4, y4, z4 );
if ( strcmp(gm, "SC") != 0 )
{
throw new nec_exception("PATCH DATA ERROR" );
}
} /* if ( card_int_2 > 1) */
else
{
xw2= degrees_to_rad(xw2);
yw2= degrees_to_rad(yw2);
}
patch( card_int_1, card_int_2, xw1, yw1, zw1, xw2, yw2, zw2, x3, y3, z3, x4, y4, z4);
}
/* "sm" card, generate multiple-patch surface */
else if (card_id == "SM")
{
i1= m+1;
m_output->nec_printf( "\n"
" %5d%c %10.5f %11.5f %11.5f %11.5f %11.5f %11.5f"
" SURFACE - %d BY %d PATCHES",
i1, ipt[1], xw1, yw1, zw1, xw2, yw2, zw2, card_int_1, card_int_2 );
if ( (card_int_1 < 1) || (card_int_2 < 1) )
{
throw new nec_exception("PATCH DATA ERROR" );
}
int ix,iy;
read_geometry_card(input_fp, gm, &ix, &iy, &x3, &y3, &z3, &x4, &y4, &z4, &dummy);
if ( (card_int_2 == 2) || (card_int_1 > 0) )
{
x4= xw1+ x3- xw2;
y4= yw1+ y3- yw2;
z4= zw1+ z3- zw2;
}
m_output->nec_printf( "\n"
" %11.5f %11.5f %11.5f %11.5f %11.5f %11.5f",
x3, y3, z3, x4, y4, z4 );
if ( strcmp(gm, "SC" ) != 0 )
{
throw new nec_exception("PATCH DATA ERROR" );
}
patch( card_int_1, card_int_2, xw1, yw1, zw1, xw2, yw2, zw2, x3, y3, z3, x4, y4, z4);
}
/* "ga" card, generate segment data for wire arc */
else if (card_id == "GA")
{
nwire++;
i1= n_segments+1;
i2= n_segments+ card_int_2;
m_output->nec_printf( "\n"
" %5d ARC RADIUS: %9.5f FROM: %8.3f TO: %8.3f DEGREES"
" %11.5f %5d %5d %5d %4d",
nwire, xw1, yw1, zw1, xw2, card_int_2, i1, i2, card_int_1 );
arc( card_int_1, card_int_2, xw1, yw1, zw1, xw2);
}
/* "sc" card */
else if (card_id == "SC")
{
if ( isct == 0)
{
throw new nec_exception("PATCH DATA ERROR" );
}
i1= m+1;
card_int_2++;
if ( (card_int_1 != 0) || ((card_int_2 != 2) && (card_int_2 != 4)) )
{
throw new nec_exception("PATCH DATA ERROR" );
}
xs1= x4;
ys1= y4;
zs1= z4;
xs2= x3;
ys2= y3;
zs2= z3;
x3= xw1;
y3= yw1;
z3= zw1;
if ( card_int_2 == 4)
{
x4= xw2;
y4= yw2;
z4= zw2;
}
xw1= xs1;
yw1= ys1;
zw1= zs1;
xw2= xs2;
yw2= ys2;
zw2= zs2;
if ( card_int_2 != 4)
{
x4= xw1+ x3- xw2;
y4= yw1+ y3- yw2;
z4= zw1+ z3- zw2;
}
m_output->nec_printf( "\n"
" %5d%c %10.5f %11.5f %11.5f %11.5f %11.5f %11.5f",
i1, ipt[card_int_2-1], xw1, yw1, zw1, xw2, yw2, zw2 );
m_output->nec_printf( "\n"
" %11.5f %11.5f %11.5f %11.5f %11.5f %11.5f",
x3, y3, z3, x4, y4, z4 );
patch( card_int_1, card_int_2, xw1, yw1, zw1, xw2, yw2, zw2, x3, y3, z3, x4, y4, z4);
}
/* "gh" card, generate helix */
else if (card_id == "GH")
{
nwire++;
i1= n_segments+1;
i2= n_segments+ card_int_2;
m_output->nec_printf( "\n"
" %5d HELIX STRUCTURE - SPACING OF TURNS: %8.3f AXIAL"
" LENGTH: %8.3f %8.3f %5d %5d %5d %4d\n "
" RADIUS X1:%8.3f Y1:%8.3f X2:%8.3f Y2:%8.3f ",
nwire, xw1, yw1, rad, card_int_2, i1, i2, card_int_1, zw1, xw2, yw2, zw2 );
int tag_id(card_int_1);
int segment_count(card_int_2);
nec_float s(xw1);
nec_float hl(yw1);
nec_float a1(zw1);
nec_float b1(xw2);
nec_float a2(yw2);
nec_float b2(zw2);
helix(tag_id, segment_count,
s, hl, a1, b1, a2, b2, rad);
}
/* "gf" card, not supported */
else if (card_id == "GF")
throw new nec_exception("NGF solution option not supported");
/* error message */
else
{
m_output->nec_printf( "\n GEOMETRY DATA CARD ERROR" );
m_output->nec_printf( "\n"
" %2s %3d %5d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f",
gm, card_int_1, card_int_2, xw1, yw1, zw1, xw2, yw2, zw2, rad );
throw new nec_exception("GEOMETRY DATA CARD ERROR");
}
} /* do */
while( true );
}
#include "nec_wire.h"
/**
We have finished with the geometry description, now connect
things up.
*/
void c_geometry::geometry_complete(nec_context* in_context, int gpflag)
{
if (0 == np + mp)
throw new nec_exception("Geometry has no wires or patches.");
/* Check to see whether any wires intersect with one another */
for (uint32_t i=0; i<m_wires.size(); i++)
{
nec_wire a = m_wires[i];
for (uint32_t j=0; j<m_wires.size(); j++)
{
if (i > j)
{
nec_wire b = m_wires[j];
vector<nec_wire> wires = a.intersect(b);
if (wires.size() > 2)
{
nec_exception* nex = new nec_exception("GEOMETRY DATA ERROR -- WIRE #");
nex->append(j+1);
nex->append(" (TAG ID #"); nex->append(b.tag_id());
nex->append(") INTERSECTS WIRE #");
nex->append(i+1);
nex->append(" (TAG ID #"); nex->append(a.tag_id()); nex->append(")");
throw nex;
}
}
}
}
// now proceed and complete the geometry setup...
// Check here that patches form a closed surfaceAntennaInput
/*
From Jerry Burke (the original author of NEC2):
Patches are modeled in NEC-2
and NEC-4 with the magnetic field integral equation, and it is valid
only for closed perfectly conducting surfaces. �You start with a
single patch and connect a wire to its center so that it splits into
four patches. �You would need to use the SM command to make a surface
with more patches, then use other SM or MV commands to form the other
five faces of a closed box. �People often do
use the NEC patch model for non-closed surfaces, and it is completely
invalid. �It would be very useful to have a check for non-closed
patch surfaces in NEC-2 or in GUIs written for it , but determining
whether a bunch of patches forms a closed surface is not easy. �If
you want to model a monopole on a surface in NEC-2, you should model
the surface as a wire grid.
*/
connect_segments( gpflag);
if ( n_segments != 0)
{
/* Allocate wire buffers */
segment_length.resize(n_segments);
sab.resize(n_segments);
cab.resize(n_segments);
salp.resize(n_segments);
m_output->nec_printf( "\n\n\n"
" "
" ---------- SEGMENTATION DATA ----------\n"
" "
" COORDINATES IN METERS\n"
" "
" I+ AND I- INDICATE THE SEGMENTS BEFORE AND AFTER I\n" );
m_output->nec_printf( "\n"
" SEG COORDINATES OF SEGM CENTER SEGM ORIENTATION"
" ANGLES WIRE CONNECTION DATA TAG\n"
" No: X Y Z LENGTH ALPHA "
" BETA RADIUS I- I I+ NO:" );
for(int i = 0; i < n_segments; i++ )
{
nec_float xw1= x2[i]- x[i];
nec_float yw1= y2[i]- y[i];
nec_float zw1= z2[i]- z[i];
x[i]=( x[i]+ x2[i])*.5;
y[i]=( y[i]+ y2[i])*.5;
z[i]=( z[i]+ z2[i])*.5;
nec_float xw2= xw1* xw1+ yw1* yw1+ zw1* zw1;
nec_float yw2= sqrt( xw2);
yw2=( xw2/ yw2+ yw2)*.5;
segment_length[i]= yw2;
cab[i]= xw1/ yw2;
sab[i]= yw1/ yw2;
xw2= zw1/ yw2;
if ( xw2 > 1.)
xw2=1.;
if ( xw2 < -1.)
xw2 = -1.;
salp[i]= xw2;
xw2= rad_to_degrees(asin( xw2));
yw2= rad_to_degrees(atan2( yw1, xw1));
m_output->nec_printf( "\n"
" %5d %9.4f %9.4f %9.4f %9.4f"
" %9.4f %9.4f %9.4f %5d %5d %5d %5d",
i+1, x[i], y[i], z[i], segment_length[i], xw2, yw2,
segment_radius[i], icon1[i], i+1, icon2[i], segment_tags[i] );
in_context->plot_card.plot_segments(i,x,y,z,segment_length,xw2,yw2,segment_radius,icon1,icon2);
if ( (segment_length[i] <= 1.e-20) || (segment_radius[i] <= 0.) )
{
throw new nec_exception("SEGMENT DATA ERROR" );
}
} /* for( i = 0; i < n_segments; i++ ) */
} /* if ( n_segments != 0) */
if ( m != 0)
{
m_output->nec_printf( "\n\n\n"
" "
" --------- SURFACE PATCH DATA ---------\n"
" "
" COORDINATES IN METERS\n\n"
" PATCH COORD. OF PATCH CENTER UNIT NORMAL VECTOR "
" PATCH COMPONENTS OF UNIT TANGENT VECTORS\n"
" NO: X Y Z X Y Z "
" AREA X1 Y1 Z1 X2 Y2 Z2" );
for(int i = 0; i < m; i++ )
{
nec_float xw1=( t1y[i]* t2z[i]- t1z[i]* t2y[i])* psalp[i];
nec_float yw1=( t1z[i]* t2x[i]- t1x[i]* t2z[i])* psalp[i];
nec_float zw1=( t1x[i]* t2y[i]- t1y[i]* t2x[i])* psalp[i];
m_output->nec_printf( "\n"
" %4d %10.5f %10.5f %10.5f %8.4f %8.4f %8.4f"
" %10.5f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f",
i+1, px[i], py[i], pz[i], xw1, yw1, zw1, pbi[i],
t1x[i], t1y[i], t1z[i], t2x[i], t2y[i], t2z[i] );
} /* for( i = 0; i < m; i++ ) */
} /* if ( m == 0) */
n_plus_2m = n_segments+2*m;
n_plus_3m = n_segments+3*m;
x_unscaled.resize(n_segments);
y_unscaled.resize(n_segments);
z_unscaled.resize(n_segments);
si_unscaled.resize(n_segments);
bi_unscaled.resize(n_segments);
px_unscaled.resize(m);
py_unscaled.resize(m);
pz_unscaled.resize(m);
pbi_unscaled.resize(m);
// Fill the unscaled segments...
for (int i = 0; i < n_segments; i++ )
{
x_unscaled[i]= x[i];
y_unscaled[i]= y[i];
z_unscaled[i]= z[i];
si_unscaled[i]= segment_length[i];
bi_unscaled[i]= segment_radius[i];
}
// Fill the unscaled patches...
for (int i = 0; i < m; i++ )
{
px_unscaled[i]= px[i];
py_unscaled[i]= py[i];
pz_unscaled[i]= pz[i];
pbi_unscaled[i]= pbi[i];
}
}
/*! \brief Generates segment geometry for a straingt wire
\param tag_id
\param segment_count Number of Elements (should be around 12-20 per wavelength)
\param rad Wire radius of first segment (in Meters)
\param rdel Ratio of the length of a segment to the length of the previous segment. (Set to 1.0 if segments have uniform length)
\param rrad The ratio of the radii of adjacent segments (Set to 1.0 if not tapered)
*/
void c_geometry::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 )
{
nec_float delz, rd, fns, radz;
int istart = n_segments;
n_segments += segment_count;
np= n_segments;
mp= m;
m_ipsym=0;
if ( segment_count < 1)
return;
/* Reallocate tags buffer */
segment_tags.resize(n_segments + m);
/* Reallocate wire buffers */
x.resize(n_segments);
y.resize(n_segments);
z.resize(n_segments);
x2.resize(n_segments);
y2.resize(n_segments);
z2.resize(n_segments);
segment_radius.resize(n_segments);
nec_3vector dx(xw2- xw1, yw2- yw1, zw2- zw1);
if ( fabs(rdel-1.0) >= 1.0e-6) // Use a tapered wire
{
delz= dx.norm();
dx /= delz;
delz= delz*(1.- rdel)/(1.- pow(rdel, segment_count) );
rd= rdel;
}
else
{
fns= segment_count;
dx /= fns;
delz=1.0;
rd=1.0;
}
/*
There is no restriction on the angle between two wires, but accuracy will be lost if the center of a segment falls within the
volume of the wire the segment connects to. The risk of this reduces as the angle between wires approaches 180 degrees.
Wires which intersect away from their ends are not connected, but errors will occur if one wire occupies the space of another one. For accuracy, separate wire centers by several radii of the largest wire.
*/
// check that none of the existing wires intersect with the midpoint
// of the first and last segment
nec_3vector wire_start(xw1,yw1,zw1);
nec_3vector wire_end(xw2,yw2,zw2);
nec_3vector seg_midpoint(wire_start + (dx/2)*delz);
nec_3vector end_seg_midpoint = wire_end - (dx*delz / 2);
/* Check to see whether any wires intersect with the segment_midpoint */
for (uint32_t i=0; i<m_wires.size(); i++)
{
nec_wire a = m_wires[i];
if (a.intersect(seg_midpoint))
{
nec_exception* nex = new nec_exception("GEOMETRY DATA ERROR -- FIRST SEGMENT MIDPOINT");
nex->append(" OF WIRE #");
nex->append(m_wires.size()+1);
nex->append(" (TAG ID #"); nex->append(tag_id);
nex->append(") INTERSECTS WIRE #");
nex->append(i+1);
nex->append(" (TAG ID #"); nex->append(a.tag_id()); nex->append(")");
throw nex;
}
if (a.intersect(end_seg_midpoint))
{
nec_exception* nex = new nec_exception("GEOMETRY DATA ERROR -- LAST SEGMENT MIDPOINT");
nex->append(" OF WIRE #");
nex->append(m_wires.size()+1);
nex->append(" (TAG ID #"); nex->append(tag_id);
nex->append(") INTERSECTS WIRE #");
nex->append(i+1);
nex->append(" (TAG ID #"); nex->append(a.tag_id()); nex->append(")");
throw nex;
}
}
radz= rad;
nec_3vector xs1(xw1,yw1,zw1);
nec_3vector x_end(xw2,yw2,zw2);
m_wires.push_back(nec_wire(xs1, x_end, rad, tag_id));
for (int i = istart; i < n_segments; i++ )
{
segment_tags[i]= tag_id;
nec_3vector xs2(xs1 + dx*delz);
x[i]= xs1.x();
y[i]= xs1.y();
z[i]= xs1.z();
x2[i]= xs2.x();
y2[i]= xs2.y();
z2[i]= xs2.z();
ASSERT(0.0 != radz);
segment_radius[i]= radz;
delz= delz* rd;
radz= radz* rrad;
xs1 = xs2;
}
x2[n_segments-1]= xw2;
y2[n_segments-1]= yw2;
z2[n_segments-1]= zw2;
}
/*-----------------------------------------------------------------------*/
/* subroutine helix generates segment geometry
data for a helix of segment_count segments
S (F1) - Spacing between turns.
HL (F2) - Total length of the helix.
A1 (F3) - Radius in x at z = 0.
B1 (F4) - Radius in y at z = 0.
A2 (F5) - Radius in x at z = HL.
B2 (F6) - Radius in y at z = HL.
RAD (F7) - Radius of wire.
*/
void c_geometry::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 ist;
nec_float zinc, sangle, hdia, turn, pitch, hmaj, hmin;
ist= n_segments;
n_segments += segment_count;
np= n_segments;
mp= m;
m_ipsym=0;
if ( segment_count < 1)
return;
zinc= fabs( hl/ segment_count);
segment_tags.resize(n_segments+m); /*????*/
/* Reallocate wire buffers */
x.resize(n_segments);
y.resize(n_segments);
z.resize(n_segments);
x2.resize(n_segments);
y2.resize(n_segments);
z2.resize(n_segments);
segment_radius.resize(n_segments);
z[ist]=0.;
for(int i = ist; i < n_segments; i++ ) {
segment_radius[i]= rad;
segment_tags[i]= tag_id;
if ( i != ist )
z[i]= z[i-1]+ zinc;
z2[i]= z[i]+ zinc;
if ( a2 == a1) {
if ( b1 == 0.)
b1= a1;
x[i]= a1* cos(2.* pi()* z[i]/ s);
y[i]= b1* sin(2.* pi()* z[i]/ s);
x2[i]= a1* cos(2.* pi()* z2[i]/ s);
y2[i]= b1* sin(2.* pi()* z2[i]/ s);
} else {
if ( b2 == 0.)
b2= a2;
x[i]=( a1+( a2- a1)* z[i]/ fabs( hl))* cos(2.* pi()* z[i]/ s);
y[i]=( b1+( b2- b1)* z[i]/ fabs( hl))* sin(2.* pi()* z[i]/ s);
x2[i]=( a1+( a2- a1)* z2[i]/ fabs( hl))* cos(2.* pi()* z2[i]/ s);
y2[i]=( b1+( b2- b1)* z2[i]/ fabs( hl))* sin(2.* pi()* z2[i]/ s);
} /* if ( a2 == a1) */
if ( hl <= 0.) {
nec_float copy= x[i];
x[i]= y[i];
y[i]= copy;
copy= x2[i];
x2[i]= y2[i];
y2[i]= copy;
}
} /* for( i = ist; i < n_segments; i++ ) */
if ( a2 != a1) {
sangle= atan( a2/( fabs( hl)+( fabs( hl)* a1)/( a2- a1)));
m_output->nec_printf(
"\n THE CONE ANGLE OF THE SPIRAL IS %10.4f", sangle );
return;
}
if ( a1 == b1) {
hdia=2.* a1;
turn= hdia* pi();
pitch= atan( s/( pi()* hdia));
turn= turn/ cos( pitch);
pitch=180.* pitch/ pi();
} else {
if ( a1 >= b1) {
hmaj=2.* a1;
hmin=2.* b1;
} else {
hmaj=2.* b1;
hmin=2.* a1;
}
hdia= sqrt(( hmaj*hmaj+ hmin*hmin)/2* hmaj);
turn=2.* pi()* hdia;
pitch=(180./ pi())* atan( s/( pi()* hdia));
} /* if ( a1 == b1) */
m_output->nec_printf( "\n"
" THE PITCH ANGLE IS: %.4f THE LENGTH OF WIRE/TURN IS: %.4f",
pitch, turn );
}
/*-----------------------------------------------------------------------*/
/* subroutine move moves the structure with respect to its */
/* coordinate system or reproduces structure in new positions. */
/* structure is rotated about x,y,z axes by rox,roy,roz */
/* respectively, then shifted by xs,ys,zs */
void c_geometry::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("move " << nrpt << " Copies");
int nrp, ix, i1, k;
nec_float sps, cps, sth, cth, sph, cph, xx, xy;
nec_float xz, yx, yy, yz, zx, zy, zz, xi, yi, zi;
if ( fabs( rox)+ fabs( roy) > 1.0e-10)
m_ipsym= m_ipsym*3;
sps= sin( rox);
cps= cos( rox);
sth= sin( roy);
cth= cos( roy);
sph= sin( roz);
cph= cos( roz);
xx= cph* cth;
xy= cph* sth* sps- sph* cps;
xz= cph* sth* cps+ sph* sps;
yx= sph* cth;
yy= sph* sth* sps+ cph* cps;
yz= sph* sth* cps- cph* sps;
zx = - sth;
zy= cth* sps;
zz= cth* cps;
if ( nrpt == 0)
nrp=1;
else
nrp= nrpt;
ix=1;
if ( n_segments > 0) {
i1= get_segment_number( its, 1);
if ( i1 < 1)
i1= 1;
ix= i1;
if ( nrpt == 0) {
k= i1-1;
} else {
k= n_segments;
/* Reallocate tags buffer */
segment_tags.resize(n_segments+m + (n_segments+1-i1)*nrpt);
// mreq = n_segments+m + (n_segments+1-i1)*nrpt;
// segment_tags.resize(mreq);
/* Reallocate wire buffers */
int new_size = (n_segments+(n_segments+1-i1)*nrpt);
x.resize(new_size);
y.resize(new_size);
z.resize(new_size);
x2.resize(new_size);
y2.resize(new_size);
z2.resize(new_size);
segment_radius.resize(new_size);
}
for (int ir = 0; ir < nrp; ir++ ) {
DEBUG_TRACE("GM: Segment Copy #" << ir);
for (int i = i1-1; i < n_segments; i++ ) {
xi= x[i];
yi= y[i];
zi= z[i];
x[k]= xi* xx+ yi* xy+ zi* xz+ xs;
y[k]= xi* yx+ yi* yy+ zi* yz+ ys;
z[k]= xi* zx+ yi* zy+ zi* zz+ zs;
xi= x2[i];
yi= y2[i];
zi= z2[i];
x2[k]= xi* xx+ yi* xy+ zi* xz+ xs;
y2[k]= xi* yx+ yi* yy+ zi* yz+ ys;
z2[k]= xi* zx+ yi* zy+ zi* zz+ zs;
segment_radius[k]= segment_radius[i];
segment_tags[k]= segment_tags[i];
if ( segment_tags[i] != 0)
segment_tags[k]= segment_tags[i]+ itgi;
k++;
} /* for( i = i1; i < n_segments; i++ ) */
i1= n_segments+1;
n_segments= k;
} /* for( ir = 0; ir < nrp; ir++ ) */
} /* if ( n_segments >= n2) */
if ( m > 0) {
i1 = 0;
if ( nrpt == 0)
k= 0;
else
k = m;
/* Reallocate patch buffers */
int new_size = m * (1+nrpt);
px.resize(new_size);
py.resize(new_size);
pz.resize(new_size);
t1x.resize(new_size);