forked from ara-software/AraSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaySolver.cc
1511 lines (1196 loc) · 63.9 KB
/
RaySolver.cc
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
#include "RaySolver.h"
#include "Position.h"
#include "IceModel.h"
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include "Settings.h"
RaySolver::RaySolver() {
//default constructor
//
}
void RaySolver::Earth_to_Flat_same_depth (Position &source, Position &target, IceModel *antarctica) { // set both target, source has same depth from the surface : angle should be somewhat difficult to change
double D = target.Distance( source );
double target_depth = antarctica->Surface(target.Lon(), target.Lat()) - target.R();
double source_depth = antarctica->Surface(source.Lon(), source.Lat()) - source.R();
//--------------------------------------------------
// std::cout<<"source R : "<<source.R()<<" source Ice surface : "<<antarctica->Surface(source.Lon(), source.Lat())<<"\n";
//
// std::cout<<"target_depth : "<<target_depth<<" and source_depth : "<<source_depth<<"\n";
// std::cout<<"Surface R at source : "<<antarctica->Surface(source.Lon(), source.Lat())<<"\n";
//--------------------------------------------------
target.SetX( 0. );
target.SetY( 0. );
target.SetZ( -target_depth );
source.SetX( pow( D*D - pow(target_depth - source_depth, 2), 0.5) );
source.SetY( 0. );
source.SetZ( -source_depth );
}
void RaySolver::Earth_to_Flat_same_angle (Position &source, Position &target, IceModel *antarctica) { // set target depth as a same (but source depth changed). at target, any angle will be not changed... But there are a chance for source be out of surface (which mostly don't have solution for ray_solver).
double D = target.Distance( source );
double target_depth = antarctica->Surface(target.Lon(), target.Lat()) - target.R();
double ang_diff = target.Angle(source);
double depth_diff = target.R() - source.R()*cos(ang_diff);
//--------------------------------------------------
// std::cout<<"source R : "<<source.R()<<" source Ice surface : "<<antarctica->Surface(source.Lon(), source.Lat())<<"\n";
//
// std::cout<<"target_depth : "<<target_depth<<" and depth_diff : "<<depth_diff<<"\n";
// std::cout<<"Surface R at source : "<<antarctica->Surface(source.Lon(), source.Lat())<<"\n";
//--------------------------------------------------
target.SetX( 0. );
target.SetY( 0. );
target.SetZ( -target_depth );
source.SetX( pow( D*D - depth_diff*depth_diff, 0.5) );
source.SetY( 0. );
source.SetZ( -target_depth - depth_diff );
}
//
//
// Solve_Ray_org : don't change any positions from earth to flat.
//
// input positions are values for flat surface where z = 0 is at ice surface
//
//
void RaySolver::Solve_Ray_org (Position &source, Position &target, std::vector < std::vector <double> > &outputs, Settings *settings1) {
outputs.clear();
//--------------------------------------------------
// int argc = 7;
// int arg_length = 40;
// char argv_tmp[argc][arg_length];
// char *argv[argc];
//--------------------------------------------------
int sol_no = 0; // solution number (for vector solutions)
Position source_tmp = source;
Position target_tmp = target;
int test;
//--------------------------------------------------
// Earth_to_Flat_same_depth (source_tmp, target_tmp, antarctica);
//--------------------------------------------------
//--------------------------------------------------
// Earth_to_Flat_same_angle (source_tmp, target_tmp, antarctica);
//--------------------------------------------------
// set error message in case posnu is above Surface
if (source_tmp.GetZ() > 0.) {
source_over_surface = 1;
}
else {
source_over_surface = 0;
}
/*
test = sprintf(argv_tmp[1], "--src_x=%f", source_tmp.GetX() );
test = sprintf(argv_tmp[2], "--src_y=%f", source_tmp.GetY() );
test = sprintf(argv_tmp[3], "--src_z=%f", source_tmp.GetZ() );
test = sprintf(argv_tmp[4], "--trg_x=%f", target_tmp.GetX() );
test = sprintf(argv_tmp[5], "--trg_y=%f", target_tmp.GetY() );
test = sprintf(argv_tmp[6], "--trg_z=%f", target_tmp.GetZ() );
argv[1] = &argv_tmp[1][0]; //source x
argv[2] = &argv_tmp[2][0]; //source y
argv[3] = &argv_tmp[3][0]; //source z
argv[4] = &argv_tmp[4][0]; //target x
argv[5] = &argv_tmp[5][0]; //target y
argv[6] = &argv_tmp[6][0]; //target z
std::cout<<"argc : "<<argc<<"\n";
std::cout<<"argv[1] : "<<argv[1]<<"\n";
std::cout<<"argv[2] : "<<argv[2]<<"\n";
std::cout<<"argv[3] : "<<argv[3]<<"\n";
std::cout<<"argv[4] : "<<argv[4]<<"\n";
std::cout<<"argv[5] : "<<argv[5]<<"\n";
std::cout<<"argv[6] : "<<argv[6]<<"\n";
*/
//--------------------------------------------------
// std::cout<<"src_x : "<<source_tmp.GetX()<<"\n";
// std::cout<<"src_y : "<<source_tmp.GetY()<<"\n";
// std::cout<<"src_z : "<<source_tmp.GetZ()<<"\n";
// std::cout<<"trg_x : "<<target_tmp.GetX()<<"\n";
// std::cout<<"trg_y : "<<target_tmp.GetY()<<"\n";
// std::cout<<"trg_z : "<<target_tmp.GetZ()<<"\n";
//--------------------------------------------------
//--------------------------------------------------
// int main(int argc, char* argv[]){
//--------------------------------------------------
double ns,nd,nc;
double src_x, src_y, src_z, trg_x, trg_y, trg_z;
Vector src,trg;
bool showLabels=true;
bool dumpPaths=false;
bool surface_reflect;
bool bedrock_reflect;
double requiredAccuracy;
double frequency;
double polarization;
boost::shared_ptr<RayTrace::indexOfRefractionModel> refractionModel;
std::string refractionName;
boost::shared_ptr<RayTrace::attenuationModel> attenuationModel;
std::string attenuationName;
/*
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help,h","print usage information")
("src_x",boost::program_options::value<double>(&src_x),"source x coordinate")
("src_y",boost::program_options::value<double>(&src_y),"source y coordinate")
("src_z",boost::program_options::value<double>(&src_z),"source z coordinate")
("trg_x",boost::program_options::value<double>(&trg_x),"target x coordinate")
("trg_y",boost::program_options::value<double>(&trg_y),"target y coordinate")
("trg_z",boost::program_options::value<double>(&trg_z),"target z coordinate")
("quiet,q","quiet, hide column labels")
("show_paths,p","show paths; print out x and z coordinates of points visited along each path. Suppresses ordinary output")
("n_s",boost::program_options::value<double>(&ns)->default_value(1.35),"surface index of refraction")
("n_d",boost::program_options::value<double>(&nd)->default_value(1.78),"deep index of refraction")
("n_c",boost::program_options::value<double>(&nc)->default_value(.0132),"index of refraction transition coefficient")
("reflect_surface",boost::program_options::value<bool>(&surface_reflect)->default_value(true),"whether to search for surface\nreflected solutions")
("reflect_bedrock",boost::program_options::value<bool>(&bedrock_reflect)->default_value(false),"whether to search for bedrock\nreflected solutions")
("accuracy",boost::program_options::value<double>(&requiredAccuracy)->default_value(0.1),"the maximum acceptable vertical miss distance in meters")
("frequency",boost::program_options::value<double>(&frequency)->default_value(300),"the frequency of the signal, in MHz")
("polarization",boost::program_options::value<double>(&polarization)->default_value(RayTrace::pi/2),"the angle of the signal polarization, relative to the plane of propagation, in radians")
("index_of_refraction",boost::program_options::value<std::string>(&refractionName)->default_value("exponential"),
"the index of refraction function of the ice, recognized values are 'exponential', 'inverse_exponential', 'quadratic', 'todor_linear', 'todor_chi', and 'todor_LL'")
("attenuation",boost::program_options::value<std::string>(&attenuationName)->default_value("besson"),"the attenuation function of the ice, recognized values are 'negligible' and 'besson'")
;
boost::program_options::positional_options_description p;
p.add("src_x", 1);
p.add("src_y", 1);
p.add("src_z", 1);
p.add("trg_x", 1);
p.add("trg_y", 1);
p.add("trg_z", 1);
boost::program_options::variables_map vm;
try{
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
boost::program_options::notify(vm);
}catch(std::exception& except){
std::cerr << "Caught an exception during argument parsing: " << except.what() << std::endl;
//--------------------------------------------------
// return(1);
//--------------------------------------------------
}catch(...){
std::cerr << "An unknown exception was caught during argument parsing" << std::endl;
//--------------------------------------------------
// return(1);
//--------------------------------------------------
}
if (vm.count ("help") || argc < 2) {
//--------------------------------------------------
// std::cout << "Usage: ray_solver [OPTION]... " << underline("src.x") << ' ' << underline("src.y") << ' ' << underline("src.z") << ' '
// << underline("trg.x") << ' ' << underline("trg.y") << ' ' << underline("trg.z") << std::endl;
// std::cout << desc << std::endl;
// std::cout << "Angles are measured in radians from the downward vertical" << std::endl;
// std::cout << "The reported attenuation includes the effects of the ice attenuation model and reflections." << std::endl;
// std::cout << "The (electric field) amplitude value reported combines the attenuation with the divergence of rays." << std::endl;
//--------------------------------------------------
//--------------------------------------------------
// return(0);
//--------------------------------------------------
}
if(vm.count("quiet"))
showLabels=false;
if(vm.count("show_paths")){
dumpPaths=true;
showLabels=false;
}
if(refractionName=="exponential")
refractionModel=boost::shared_ptr<exponentialRefractiveIndex>(new exponentialRefractiveIndex(ns,nd,nc));
//refractionModel=boost::make_shared<exponentialRefractiveIndex>(ns,nd,nc);
else if(refractionName=="inverse_exponential")
refractionModel=boost::shared_ptr<inverseExponentialRefractiveIndex>(new inverseExponentialRefractiveIndex(ns,nd,nc));
//refractionModel=boost::make_shared<inverseExponentialRefractiveIndex>(ns,nd,nc);
else if(refractionName=="quadratic")
refractionModel=boost::shared_ptr<quadraticRefractiveIndex>(new quadraticRefractiveIndex(ns,nd,nc));
//refractionModel=boost::make_shared<quadraticRefractiveIndex>(ns,nd,nc);
else if(refractionName=="todor_linear")
refractionModel=boost::shared_ptr<todorLinearRefractiveIndex>(new todorLinearRefractiveIndex(ns,nd));
//refractionModel=boost::make_shared<todorLinearRefractiveIndex>(ns,nd);
else if(refractionName=="todor_chi")
refractionModel=boost::shared_ptr<todorChiRefractiveIndex>(new todorChiRefractiveIndex(ns,nd));
//refractionModel=boost::make_shared<todorChiRefractiveIndex>(ns,nd);
else if(refractionName=="todor_LL")
refractionModel=boost::shared_ptr<todorLLRefractiveIndex>(new todorLLRefractiveIndex(ns,nd));
//refractionModel=boost::make_shared<todorLLRefractiveIndex>(ns,nd);
else{
std::cerr << "Unrecognized refraction model name '" << refractionName << "'" << std::endl;
//--------------------------------------------------
// return(1);
//--------------------------------------------------
}
if(attenuationName=="besson")
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
//attenuationModel=boost::make_shared<basicAttenuationModel>();
else if(attenuationName=="negligible")
attenuationModel=boost::shared_ptr<negligibleAttenuationModel>(new negligibleAttenuationModel);
//attenuationModel=boost::make_shared<negligibleAttenuationModel>();
else{
std::cerr << "Unrecognized attenuation model name '" << attenuationName << "'" << std::endl;
//--------------------------------------------------
// return(1);
//--------------------------------------------------
}
*/
// Defaults!!!!
src = source_tmp;
trg = target_tmp;
if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 0){
// South Pole Values (AraSim original default, based on RICE)
ns = 1.35;
nd = 1.78;
nc = 0.0132;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 1){
// South Pole Values (RICE (2004))
ns = 1.35;
nd = 1.78;
nc = 0.014;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 2){
// South Pole Values (Eisen (2003))
ns = 1.30;
nd = 1.78;
nc = 0.02;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 3){
// South Pole values (Gow)
ns = 1.345;
nd = 1.78;
nc = 0.016;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 10){
// Moore's Bay values (MB #1)
ns = 1.32;
nd = 1.78;
nc = 0.029;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 11){
// Moore's Bay values (MB #2)
ns = 1.299;
nd = 1.78;
nc = 0.027;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 20){
// Byrd values (Ebimuna (1983))
ns = 1.316;
nd = 1.78;
nc = 0.0244;
} else if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 30){
// Mizuho values (Ebimuna (1983))
ns = 1.357;
nd = 1.78;
nc = 0.027;
}
else {
// South Pole Values (AraSim original default, based on RICE)
ns = 1.35;
nd = 1.78;
nc = 0.0132;
}
// cout << "ns, nd, nc: " << ns << ", " << nd << ", " << nc << endl;
surface_reflect = true;
bedrock_reflect = false;
//requiredAccuracy = 0.1;
//requiredAccuracy = 0.5;
requiredAccuracy = 0.2;
frequency = 300;
polarization = RayTrace::pi/2;
if (settings1->NOFZ == 1){
refractionModel=boost::shared_ptr<exponentialRefractiveIndex>(new exponentialRefractiveIndex(ns,nd,nc));
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
} else if (settings1->NOFZ == 0){
refractionModel=boost::shared_ptr<constantRefractiveIndex>(new constantRefractiveIndex(1.48));
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
}
else if (settings1->NOFZ == 2){
refractionModel=boost::shared_ptr<inverseExponentialRefractiveIndex>(new inverseExponentialRefractiveIndex(ns,nd,nc));
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
}
unsigned short refl = RayTrace::NoReflection;
if(surface_reflect)
refl|=RayTrace::SurfaceReflection;
if(bedrock_reflect)
refl|=RayTrace::BedrockReflection;
/*
src.SetX(src_x);
src.SetY(src_y);
src.SetZ(src_z);
trg.SetX(trg_x);
trg.SetY(trg_y);
trg.SetZ(trg_z);
*/
std::vector<RayTrace::TraceRecord> paths;
std::vector<RayTrace::TraceRecord> paths_exc;
RayTrace::TraceFinder tf(refractionModel,attenuationModel);
std::vector < std::vector < std::vector <double> > > testvector;
int sol_cnt;
int sol_error;
int sol_cnt_exc;
int sol_error_exc;
int SrcTrgExc = 0; // 0 not exchanged, 1 exchanged
paths=tf.findPaths(src,trg,frequency/1.0e3,polarization, sol_cnt, sol_error, refl,requiredAccuracy);
// have to fix src trg exchanged case angle outputs
//
if ( sol_cnt > 0 && sol_error > 0 ) { // this case do findPahts again with src, trg exchanged
paths_exc=tf.findPaths(trg,src,frequency/1.0e3,polarization, sol_cnt_exc, sol_error_exc, refl,requiredAccuracy);
if ( sol_error > sol_error_exc ) { // exchanged one is better (less sol_error)
paths = paths_exc;
SrcTrgExc = 1;
}
else if (sol_error == sol_error_exc) { // sol_error are same for both paths. Then use the better miss dist.
std::vector<RayTrace::TraceRecord>::const_iterator it_tmp=paths.begin();
std::vector<RayTrace::TraceRecord>::const_iterator it_tmp_exc=paths_exc.begin();
if ( it_tmp->miss > it_tmp_exc->miss ) { // if fist one miss dist is worse
paths = paths_exc;
SrcTrgExc = 1;
}
}
}
if(showLabels){
if(!paths.empty()){
//--------------------------------------------------
// std::cout << std::fixed
// << "path length (m) "
// << "path time (ns) "
// << "launch angle "
// << "recipt angle "
// << "reflect angle "
// << "miss dist. "
// << "attenuation "
// << "amplitude"
// << std::endl;
//--------------------------------------------------
solution_toggle = 1;
}
else {
//std::cout << "No solutions" << std::endl;
solution_toggle = 0;
}
}
if(!dumpPaths){
for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
if ( it->sol_error == 0 ) {
//double signal = tf.signalStrength(*it,src,trg,refl, sol_error );
//--------------------------------------------------
// std::cout << std::left << std::fixed
// << std::setprecision(2) << std::setw(15) << it->pathLen << ' '
// << std::setprecision(2) << std::setw(14) << 1e9*it->pathTime << ' '
// << std::setprecision(4) << std::setw(12) << it->launchAngle << ' '
// << std::setprecision(4) << std::setw(12) << it->receiptAngle << ' '
// << std::setprecision(3) << std::setw(13) << it->reflectionAngle << ' '
// << std::setprecision(2) << std::setw(10) << it->miss << ' '
// << std::scientific << std::setprecision(4) << std::setw(11) << it->attenuation << ' '
// //amplitude calculation, ignoring frequency response at both ends, angular response of receiver
// << std::setw(10) << (it->attenuation*signal)
// << std::endl;
//--------------------------------------------------
if ( SrcTrgExc == 0 ) { // src, trg as original
outputs.resize(3);
outputs[0].push_back(it->pathLen);
outputs[1].push_back(it->launchAngle);
outputs[2].push_back(it->receiptAngle);
//std::cout<<"outputs[0]["<<sol_no<<"] : "<<outputs[0][sol_no]<<"pathLen : "<<it->pathLen<<"\n";
std::string pathfilename;
if ( sol_no == 0 ) {
pathfilename = "./pathfile_0.txt";
}
else if ( sol_no == 1 ) {
pathfilename = "./pathfile_1.txt";
}
else {
pathfilename = "./pathfile.txt";
}
testvector.resize(sol_no+1); // x, z
// construct
pathStore_vector<RayTrace::minimalRayPosition> pathsave_test;
//pathStore_vector_2<RayTrace::minimalRayPosition> pathsave_test (testvector);
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test ("./pathfile.txt");
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test (pathfilename);
//tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, sol_error, &pathsave_test);
tf.doTrace<RayTrace::minimalRayPosition>(src.GetZ(), it->launchAngle, RayTrace::rayTargetRecord(trg.GetZ(),sqrt((trg.GetX()-src.GetX())*(trg.GetX()-src.GetX())+(trg.GetY()-src.GetY())*(trg.GetY()-src.GetY()))), refl, 0.0, 0.0, sol_error, &pathsave_test);
pathsave_test.CopyVector( testvector, sol_no );
pathsave_test.DelVector();
/*
double totalpath = 0.;
double dx, dz;
//cout<<"\nRayStep : "<<(int)testvector[0].size()<<endl;
for (int step=0; step<(int)testvector[sol_no][0].size(); step++ ) {
if ( step > 0 ) {
dx = fabs(testvector[sol_no][0][step-1] - testvector[sol_no][0][step]);
dz = fabs(testvector[sol_no][1][step-1] - testvector[sol_no][1][step]);
totalpath += sqrt( (dx*dx) + (dz*dz) );
}
}
*/
//cout<<"pathLen : "<<it->pathLen<<", pathSum : "<<totalpath<<endl;
//testvector.clear();
sol_no++;
}
else if ( SrcTrgExc == 1 ) { // src, trg exchanged
outputs.resize(3);
outputs[0].push_back(it->pathLen);
outputs[1].push_back(PI - it->receiptAngle);
outputs[2].push_back(PI - it->launchAngle);
//std::cout<<"outputs[0]["<<sol_no<<"] : "<<outputs[0][sol_no]<<"pathLen : "<<it->pathLen<<"\n";
std::string pathfilename;
if ( sol_no == 0 ) {
pathfilename = "./pathfile_0.txt";
}
else if ( sol_no == 1 ) {
pathfilename = "./pathfile_1.txt";
}
else {
pathfilename = "./pathfile.txt";
}
testvector.resize(sol_no+1); // x, z
// construct
pathStore_vector<RayTrace::minimalRayPosition> pathsave_test;
//pathStore_vector_2<RayTrace::minimalRayPosition> pathsave_test (testvector);
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test ("./pathfile.txt");
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test (pathfilename);
//tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, sol_error, &pathsave_test);
tf.doTrace<RayTrace::minimalRayPosition>(src.GetZ(), PI - it->receiptAngle, RayTrace::rayTargetRecord(trg.GetZ(),sqrt((trg.GetX()-src.GetX())*(trg.GetX()-src.GetX())+(trg.GetY()-src.GetY())*(trg.GetY()-src.GetY()))), refl, 0.0, 0.0, sol_error, &pathsave_test);
pathsave_test.CopyVector( testvector, sol_no );
pathsave_test.DelVector();
/*
double totalpath = 0.;
double dx, dz;
//cout<<"\nRayStep : "<<(int)testvector[0].size()<<endl;
for (int step=0; step<(int)testvector[sol_no][0].size(); step++ ) {
if ( step > 0 ) {
dx = fabs(testvector[sol_no][0][step-1] - testvector[sol_no][0][step]);
dz = fabs(testvector[sol_no][1][step-1] - testvector[sol_no][1][step]);
totalpath += sqrt( (dx*dx) + (dz*dz) );
}
}
*/
//cout<<"pathLen : "<<it->pathLen<<", pathSum : "<<totalpath<<endl;
//testvector.clear();
sol_no++;
}
}
}
}
else{ //do write out path data
// I didn't fix this part yet!
int sol_error;
pathPrinter<RayTrace::minimalRayPosition> print;
for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
//tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, &print);
tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, sol_error, &print);
//std::cout << "\n\n";
}
}
//--------------------------------------------------
// return(0);
//--------------------------------------------------
}
//
//
// Solve_Ray_org : don't change any positions from earth to flat. (also this version read x, y, z conponents and output travel time and travel distance only)
//
// input positions are values for flat surface where z = 0 is at ice surface
//
//
//void RaySolver::Solve_Ray_org (double source_x, double source_y, double source_z, double target_x, double target_y, double target_z ) {
void RaySolver::Solve_Ray_org (double source_x, double source_y, double source_z, double target_x, double target_y, double target_z, bool print_path ) {
//outputs.clear();
int sol_no = 0; // solution number (for vector solutions)
//Position source_tmp = source;
//Position target_tmp = target;
int test;
// set error message in case posnu is above Surface
if (source_z > 0.) {
source_over_surface = 1;
}
else {
source_over_surface = 0;
}
//--------------------------------------------------
// int main(int argc, char* argv[]){
//--------------------------------------------------
double ns,nd,nc;
double src_x, src_y, src_z, trg_x, trg_y, trg_z;
Vector src,trg;
bool showLabels=true;
//bool dumpPaths=false;
bool dumpPaths=print_path;
bool surface_reflect;
bool bedrock_reflect;
double requiredAccuracy;
double frequency;
double polarization;
boost::shared_ptr<RayTrace::indexOfRefractionModel> refractionModel;
std::string refractionName;
boost::shared_ptr<RayTrace::attenuationModel> attenuationModel;
std::string attenuationName;
// Defaults!!!!
//src = source_tmp;
//trg = target_tmp;
// if (settings1->RAY_TRACE_ICE_MODEL_PARAMS == 0){
// South Pole Values
ns = 1.35;
nd = 1.78;
nc = 0.0132;
// } else {
// Moore's Bay values (MB #1)
//ns = 1.32;
// nd = 1.78;
//nc = 0.029;
// }
// cout << "ns, nd, nc: " << ns << ", " << nd << ", " << nc << endl;
surface_reflect = true;
bedrock_reflect = false;
//requiredAccuracy = 0.1;
//requiredAccuracy = 0.5;
requiredAccuracy = 0.2;
frequency = 300;
polarization = RayTrace::pi/2;
//if (settings1->NOFZ == 1){
refractionModel=boost::shared_ptr<exponentialRefractiveIndex>(new exponentialRefractiveIndex(ns,nd,nc));
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
/*
} else if (settings1->NOFZ == 0){
refractionModel=boost::shared_ptr<constantRefractiveIndex>(new constantRefractiveIndex(1.48));
attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
}
*/
unsigned short refl = RayTrace::NoReflection;
if(surface_reflect)
refl|=RayTrace::SurfaceReflection;
if(bedrock_reflect)
refl|=RayTrace::BedrockReflection;
src.SetX(source_x);
src.SetY(source_y);
src.SetZ(source_z);
trg.SetX(target_x);
trg.SetY(target_y);
trg.SetZ(target_z);
std::vector<RayTrace::TraceRecord> paths;
std::vector<RayTrace::TraceRecord> paths_exc;
RayTrace::TraceFinder tf(refractionModel,attenuationModel);
std::vector < std::vector < std::vector <double> > > testvector;
int sol_cnt;
int sol_error;
int sol_cnt_exc;
int sol_error_exc;
int SrcTrgExc = 0; // 0 not exchanged, 1 exchanged
paths=tf.findPaths(src,trg,frequency/1.0e3,polarization, sol_cnt, sol_error, refl,requiredAccuracy);
// have to fix src trg exchanged case angle outputs
//
if ( sol_cnt > 0 && sol_error > 0 ) { // this case do findPahts again with src, trg exchanged
paths_exc=tf.findPaths(trg,src,frequency/1.0e3,polarization, sol_cnt_exc, sol_error_exc, refl,requiredAccuracy);
if ( sol_error > sol_error_exc ) { // exchanged one is better (less sol_error)
paths = paths_exc;
SrcTrgExc = 1;
}
else if (sol_error == sol_error_exc) { // sol_error are same for both paths. Then use the better miss dist.
std::vector<RayTrace::TraceRecord>::const_iterator it_tmp=paths.begin();
std::vector<RayTrace::TraceRecord>::const_iterator it_tmp_exc=paths_exc.begin();
if ( it_tmp->miss > it_tmp_exc->miss ) { // if fist one miss dist is worse
paths = paths_exc;
SrcTrgExc = 1;
}
}
}
if(showLabels){
if(!paths.empty()){
std::cout << std::fixed
<< "path length (m) "
<< "path time (ns) "
<< "launch angle "
<< "recipt angle "
<< "reflect angle "
<< "miss dist. "
<< "attenuation "
<< "amplitude"
<< std::endl;
solution_toggle = 1;
}
else {
std::cout << "No solutions" << std::endl;
solution_toggle = 0;
}
}
if(!dumpPaths){
for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
if ( it->sol_error == 0 ) {
//double signal = tf.signalStrength(*it,src,trg,refl);
double signal = tf.signalStrength(*it,src,trg,refl, sol_error );
std::cout << std::left << std::fixed
<< std::setprecision(2) << std::setw(15) << it->pathLen << ' '
<< std::setprecision(2) << std::setw(14) << 1e9*it->pathTime << ' '
<< std::setprecision(4) << std::setw(12) << it->launchAngle << ' '
<< std::setprecision(4) << std::setw(12) << it->receiptAngle << ' '
<< std::setprecision(3) << std::setw(13) << it->reflectionAngle << ' '
<< std::setprecision(2) << std::setw(10) << it->miss << ' '
<< std::scientific << std::setprecision(4) << std::setw(11) << it->attenuation << ' '
//amplitude calculation, ignoring frequency response at both ends, angular response of receiver
<< std::setw(10) << (it->attenuation*signal)
<< std::endl;
std::string pathfilename;
if ( sol_no == 0 ) {
pathfilename = "./pathfile_0.txt";
}
else if ( sol_no == 1 ) {
pathfilename = "./pathfile_1.txt";
}
else {
pathfilename = "./pathfile.txt";
}
testvector.resize(sol_no+1); // x, z
// construct
pathStore_vector<RayTrace::minimalRayPosition> pathsave_test;
//pathStore_vector_2<RayTrace::minimalRayPosition> pathsave_test (testvector);
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test ("./pathfile.txt");
//pathStore_test<RayTrace::minimalRayPosition> pathsave_test (pathfilename);
//tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, sol_error, &pathsave_test);
tf.doTrace<RayTrace::minimalRayPosition>(src.GetZ(), it->launchAngle, RayTrace::rayTargetRecord(trg.GetZ(),sqrt((trg.GetX()-src.GetX())*(trg.GetX()-src.GetX())+(trg.GetY()-src.GetY())*(trg.GetY()-src.GetY()))), refl, 0.0, 0.0, sol_error, &pathsave_test);
pathsave_test.CopyVector( testvector, sol_no );
pathsave_test.DelVector();
/*
double totalpath = 0.;
double dx, dz;
//cout<<"\nRayStep : "<<(int)testvector[0].size()<<endl;
for (int step=0; step<(int)testvector[sol_no][0].size(); step++ ) {
if ( step > 0 ) {
dx = fabs(testvector[sol_no][0][step-1] - testvector[sol_no][0][step]);
dz = fabs(testvector[sol_no][1][step-1] - testvector[sol_no][1][step]);
totalpath += sqrt( (dx*dx) + (dz*dz) );
}
}
*/
//cout<<"pathLen : "<<it->pathLen<<", pathSum : "<<totalpath<<endl;
//testvector.clear();
sol_no++;
if (sol_no == 1) { // save only first sol
//travel_dist = it->pathLen;
//travel_time = it->pathTime; // in s
}
}
}
}
else{ //do write out path data
// I didn't fix this part yet!
int sol_error;
pathPrinter<RayTrace::minimalRayPosition> print;
for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
//tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, &print);
tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, sol_error, &print);
std::cout << "\n\n";
}
}
//--------------------------------------------------
// return(0);
//--------------------------------------------------
//no_sol = sol_no;
}
//--------------------------------------------------
// void RaySolver::Solve_Ray (Position &source, Position &target, IceModel *antarctica, std::vector <double> &outputs) {
//--------------------------------------------------
//void RaySolver::Solve_Ray (Position &source, Position &target, IceModel *antarctica, std::vector < std::vector <double> > &outputs, Settings *settings1) {
void RaySolver::Solve_Ray (Position &source, Position &target, IceModel *antarctica, std::vector < std::vector <double> > &outputs, Settings *settings1, std::vector < std::vector < std::vector <double> > > &RayStep ) {
outputs.clear();
//--------------------------------------------------
// int argc = 7;
// int arg_length = 40;
// char argv_tmp[argc][arg_length];
// char *argv[argc];
//--------------------------------------------------
int sol_no = 0; // solution number (for vector solutions)
Position source_tmp = source;
Position target_tmp = target;
double distance_org = source.Distance( target );
int test;
//--------------------------------------------------
// Earth_to_Flat_same_depth (source_tmp, target_tmp, antarctica);
//--------------------------------------------------
Earth_to_Flat_same_angle (source_tmp, target_tmp, antarctica);
double distance_flat = source_tmp.Distance( target_tmp );
if ( fabs(distance_org - distance_flat) > 1. ) // if more than 1m difference
cout<<"source, target distance, org: "<<distance_org<<", flat: "<<distance_flat<<endl;
// set error message in case posnu is above Surface
if (source_tmp.GetZ() > 0.) {
source_over_surface = 1;
}
else {
source_over_surface = 0;
}
/*
test = sprintf(argv_tmp[1], "--src_x=%f", source_tmp.GetX() );
test = sprintf(argv_tmp[2], "--src_y=%f", source_tmp.GetY() );
test = sprintf(argv_tmp[3], "--src_z=%f", source_tmp.GetZ() );
test = sprintf(argv_tmp[4], "--trg_x=%f", target_tmp.GetX() );
test = sprintf(argv_tmp[5], "--trg_y=%f", target_tmp.GetY() );
test = sprintf(argv_tmp[6], "--trg_z=%f", target_tmp.GetZ() );
argv[1] = &argv_tmp[1][0]; //source x
argv[2] = &argv_tmp[2][0]; //source y
argv[3] = &argv_tmp[3][0]; //source z
argv[4] = &argv_tmp[4][0]; //target x
argv[5] = &argv_tmp[5][0]; //target y
argv[6] = &argv_tmp[6][0]; //target z
std::cout<<"argc : "<<argc<<"\n";
std::cout<<"argv[1] : "<<argv[1]<<"\n";
std::cout<<"argv[2] : "<<argv[2]<<"\n";
std::cout<<"argv[3] : "<<argv[3]<<"\n";
std::cout<<"argv[4] : "<<argv[4]<<"\n";
std::cout<<"argv[5] : "<<argv[5]<<"\n";
std::cout<<"argv[6] : "<<argv[6]<<"\n";
*/
//--------------------------------------------------
// std::cout<<"src_x : "<<source_tmp.GetX()<<"\n";
// std::cout<<"src_y : "<<source_tmp.GetY()<<"\n";
// std::cout<<"src_z : "<<source_tmp.GetZ()<<"\n";
// std::cout<<"trg_x : "<<target_tmp.GetX()<<"\n";
// std::cout<<"trg_y : "<<target_tmp.GetY()<<"\n";
// std::cout<<"trg_z : "<<target_tmp.GetZ()<<"\n";
//--------------------------------------------------
//--------------------------------------------------
// int main(int argc, char* argv[]){
//--------------------------------------------------
double ns,nd,nc;
double src_x, src_y, src_z, trg_x, trg_y, trg_z;
Vector src,trg;
bool showLabels=true;
bool dumpPaths=false;
bool surface_reflect;
bool bedrock_reflect;
double requiredAccuracy;
double frequency;
double polarization;
boost::shared_ptr<RayTrace::indexOfRefractionModel> refractionModel;
std::string refractionName;
boost::shared_ptr<RayTrace::attenuationModel> attenuationModel;
std::string attenuationName;
/*
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help,h","print usage information")
("src_x",boost::program_options::value<double>(&src_x),"source x coordinate")
("src_y",boost::program_options::value<double>(&src_y),"source y coordinate")
("src_z",boost::program_options::value<double>(&src_z),"source z coordinate")
("trg_x",boost::program_options::value<double>(&trg_x),"target x coordinate")
("trg_y",boost::program_options::value<double>(&trg_y),"target y coordinate")
("trg_z",boost::program_options::value<double>(&trg_z),"target z coordinate")
("quiet,q","quiet, hide column labels")
("show_paths,p","show paths; print out x and z coordinates of points visited along each path. Suppresses ordinary output")
("n_s",boost::program_options::value<double>(&ns)->default_value(1.35),"surface index of refraction")
("n_d",boost::program_options::value<double>(&nd)->default_value(1.78),"deep index of refraction")
("n_c",boost::program_options::value<double>(&nc)->default_value(.0132),"index of refraction transition coefficient")
("reflect_surface",boost::program_options::value<bool>(&surface_reflect)->default_value(true),"whether to search for surface\nreflected solutions")
("reflect_bedrock",boost::program_options::value<bool>(&bedrock_reflect)->default_value(false),"whether to search for bedrock\nreflected solutions")
("accuracy",boost::program_options::value<double>(&requiredAccuracy)->default_value(0.1),"the maximum acceptable vertical miss distance in meters")
("frequency",boost::program_options::value<double>(&frequency)->default_value(300),"the frequency of the signal, in MHz")
("polarization",boost::program_options::value<double>(&polarization)->default_value(RayTrace::pi/2),"the angle of the signal polarization, relative to the plane of propagation, in radians")
("index_of_refraction",boost::program_options::value<std::string>(&refractionName)->default_value("exponential"),
"the index of refraction function of the ice, recognized values are 'exponential', 'inverse_exponential', 'quadratic', 'todor_linear', 'todor_chi', and 'todor_LL'")
("attenuation",boost::program_options::value<std::string>(&attenuationName)->default_value("besson"),"the attenuation function of the ice, recognized values are 'negligible' and 'besson'")
;
boost::program_options::positional_options_description p;
p.add("src_x", 1);
p.add("src_y", 1);
p.add("src_z", 1);
p.add("trg_x", 1);
p.add("trg_y", 1);
p.add("trg_z", 1);