-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraytracing.cpp
673 lines (540 loc) · 29.1 KB
/
raytracing.cpp
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
#include<bits/stdc++.h>
using namespace std;
class useful_functions{ //this class contains the christoffel coefficients and the length scales Delta, Sigma, and A as defined https://en.wikipedia.org/wiki/Kerr_metric#Metric
public:
//first the length scales
double Kerr_Delta(double r,double a){
double kerr_delta=r*r-2*r+a*a;
return kerr_delta;
}
double Kerr_Sigma(double r,double a,double theta){
double kerr_sigma=r*r+a*a*cos(theta)*cos(theta);
return kerr_sigma;
}
double Kerr_A(double r,double a,double theta){
double kerr_a=(r*r+a*a)*(r*r+a*a)-a*a*Kerr_Delta(r,a)*sin(theta)*sin(theta);
return kerr_a;
}
//These are the coefficients of the line element in Boyer-Lindquist coordinates
double line_element_coeff_1(double r,double a,double theta){
double LINE_ELEMENT_COEFF_1=-(1-2*r/Kerr_Sigma(r,a,theta));
return LINE_ELEMENT_COEFF_1;
}
double line_element_coeff_2(double r,double a,double theta){
double LINE_ELEMENT_COEFF_2=-2*a*r*sin(theta)*sin(theta)/Kerr_Sigma(r,a,theta);
return LINE_ELEMENT_COEFF_2;
}
double line_element_coeff_3(double r,double a,double theta){
double LINE_ELEMENT_COEFF_3=Kerr_Sigma(r,a,theta)/Kerr_Delta(r,a);
return LINE_ELEMENT_COEFF_3;
}
double line_element_coeff_4(double r,double a,double theta){
double LINE_ELEMENT_COEFF_4=Kerr_Sigma(r,a,theta);
return LINE_ELEMENT_COEFF_4;
}
double line_element_coeff_5(double r,double a,double theta){
double LINE_ELEMENT_COEFF_5=(r*r+a*a+ 2*a*a*r*sin(theta)*sin(theta)/Kerr_Sigma(r,a,theta))*sin(theta)*sin(theta);
return LINE_ELEMENT_COEFF_5;
}
//now the christoffel coefficients
//the radial coefficients are first, the angular ones second
double gamma_r_tt(double r,double a,double theta){
double GAMMA_R_TT=Kerr_Delta(r,a)*(r*r-a*a*cos(theta)*cos(theta))/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_R_TT;
}
double gamma_r_rr(double r,double a,double theta){
double GAMMA_R_RR=(r*a*a*sin(theta)*sin(theta)-(r*r-a*a*cos(theta)*cos(theta)))/(Kerr_Sigma(r,a,theta)*Kerr_Delta(r,a));
return GAMMA_R_RR;
}
double gamma_r_oo(double r,double a,double theta){
double GAMMA_R_OO=- r*Kerr_Delta(r,a)/Kerr_Sigma(r,a,theta);
return GAMMA_R_OO;
}
double gamma_r_pp(double r,double a,double theta){
double GAMMA_R_PP= Kerr_Delta(r,a)*sin(theta)*sin(theta)*(-r*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)+a*a*sin(theta)*sin(theta)*(r*r-a*a*cos(theta)*cos(theta)))/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_R_PP;
}
double gamma_r_tp(double r,double a,double theta){
double GAMMA_R_TP=- Kerr_Delta(r,a)*a*sin(theta)*sin(theta)*(r*r-a*a*cos(theta)*cos(theta))/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_R_TP;
}
double gamma_r_ro(double r,double a,double theta){
double GAMMA_R_RO=- a*a*sin(theta)*cos(theta)/(Kerr_Sigma(r,a,theta));
return GAMMA_R_RO;
}
double gamma_o_tt(double r,double a,double theta){
double GAMMA_O_TT=-2*a*a*r*sin(theta)*cos(theta)/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_O_TT;
}
double gamma_o_rr(double r,double a,double theta){
double GAMMA_O_RR=a*a*sin(theta)*cos(theta)/(Kerr_Sigma(r,a,theta)*Kerr_Delta(r,a));
return GAMMA_O_RR;
}
double gamma_o_oo(double r,double a,double theta){
double GAMMA_O_OO=- a*a*sin(theta)*cos(theta)/Kerr_Sigma(r,a,theta);
return GAMMA_O_OO;
}
double gamma_o_pp(double r,double a,double theta){
double GAMMA_O_PP=- sin(theta)*cos(theta)*(Kerr_A(r,a,theta)*Kerr_Sigma(r,a,theta)+2*(r*r+a*a)*a*a*r*sin(theta)*sin(theta))/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_O_PP;
}
double gamma_o_tp(double r,double a,double theta){
double GAMMA_O_TP=2*a*r*(r*r+a*a)*sin(theta)*cos(theta)/(Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta)*Kerr_Sigma(r,a,theta));
return GAMMA_O_TP;
}
double gamma_o_ro(double r,double a,double theta){
double GAMMA_O_RO=r/Kerr_Sigma(r,a,theta);
return GAMMA_O_RO;
}
//to catch errors propagating through the integration before they do too much damage, this function is defined. The flag should always be -1 for a photon!
double check_integral_error_propagation(double r,double a,double theta,double td,double rd,double od,double pd){
double propagated_integral_error_flag=(line_element_coeff_3(r,a,theta)*rd*rd+line_element_coeff_5(r,a,theta)*pd*pd+line_element_coeff_4(r,a,theta)*od*od+2*line_element_coeff_2(r,a,theta)*td*pd)/(line_element_coeff_1(r,a,theta)*td*td);
return propagated_integral_error_flag;
}
//there are two quantities conserved along the geodesic - the total photon energy and the angular momentum. (if a photon hits the black hole the angular momentum gets transferred!)
double conserved_energy(double r,double a,double theta,double td,double pd){
double CONSERVED_ENERGY=- line_element_coeff_1(r,a,theta)*td-line_element_coeff_2(r,a,theta)*pd;
return CONSERVED_ENERGY;
}
double conserved_angular_momentum(double r,double a,double theta,double td,double pd){
double CONSERVED_ANGULAR_MOMENTUM=line_element_coeff_5(r,a,theta)*pd+line_element_coeff_2(r,a,theta)*td ;
return CONSERVED_ANGULAR_MOMENTUM;
}
double normalized_angular_momentum(double r,double a,double theta,double td,double pd){
double NORMALIZED_ANGULAR_MOMENTUM=conserved_angular_momentum(r,a,theta,td,pd)/conserved_energy(r,a,theta,td,pd);
return NORMALIZED_ANGULAR_MOMENTUM;
}
};
class Initial_conditions{
public:
//these functions take a position in the image plane - say initial_x,initial_y - and have an angle initial_theta from the center of the black hole.
//they then turn them into initial conditions in Boyer-Lindquist coordinates
//also the initial photon 4-velocity is generated
//first initialize the position
useful_functions uf;
double initial_r(double d,double initial_x,double initial_y){
double R_INIT=sqrt(d*d+initial_x*initial_x+initial_y*initial_y);
return R_INIT;
}
double initial_theta(double d,double initial_x,double initial_y,double initial_theta){
double THETA_INIT=acos( (d*cos(initial_theta)+ initial_y*sin(initial_theta))/initial_r(d,initial_x,initial_y) );
return THETA_INIT;
}
double initial_phi(double d,double initial_x,double initial_y,double initial_theta){
double PHI_INIT=atan(initial_x/(d*sin(initial_theta)-initial_y*cos(initial_theta)));
return PHI_INIT;
}
// now initialize the 4-velocity
double initial_vr(double d,double initial_x,double initial_y){
double VR_INIT=-d/initial_r(d,initial_x,initial_y);
return VR_INIT;
}
double initial_vo(double d,double initial_x,double initial_y,double initial_theta){
double VO_INIT=-(-cos(initial_theta)+d/(pow(initial_r(d,initial_x,initial_y),2))*(d*cos(initial_theta)+initial_y*sin(initial_theta)))/sqrt(pow(initial_r(d,initial_x,initial_y),2)-pow((d*cos(initial_theta)+initial_y*sin(initial_theta)),2) );
return VO_INIT;
}
double initial_vp(double d,double initial_x,double initial_y,double initial_theta){
double VP_INIT=- (-initial_x*sin(initial_theta)/(pow(d*sin(initial_theta)-initial_y*cos(initial_theta),2)+initial_x*initial_x));
return VP_INIT;
}
double initial_vt(double a,double d,double initial_x,double initial_y,double initial_theta){
double creative_variable_1=uf.line_element_coeff_1(initial_r(d,initial_x,initial_y),a,initial_theta);
double creative_variable_2=2*uf.line_element_coeff_2(initial_r(d,initial_x,initial_y),a,initial_theta)*initial_vp(d,initial_x,initial_y,initial_theta);
double creative_variable_3 =uf.line_element_coeff_3(initial_r(d,initial_x,initial_y),a,initial_theta)*initial_vr(d,initial_x,initial_y)*initial_vr(d,initial_x,initial_y)+uf.line_element_coeff_4(initial_r(d,initial_x,initial_y),a,initial_theta)*initial_vo(d,initial_x,initial_y,initial_theta)*initial_vo(d,initial_x,initial_y,initial_theta)+uf.line_element_coeff_5(initial_r(d,initial_x,initial_y),a,initial_theta)*initial_vp(d,initial_x,initial_y,initial_theta)*initial_vp(d,initial_x,initial_y,initial_theta);
//for an actual physical verobjectsion, this has to be greater than 0
double VT_INIT=(-creative_variable_2-sqrt(creative_variable_2*creative_variable_2-4*creative_variable_1*creative_variable_3))/(2*creative_variable_1);
return VT_INIT;
}
};
class motion_equations{
public:
//now it's time for the equations of motion
//phi and t evolve according to first-order equations
//r and theta evolve according to second-order geodesic equations
//for the second-order equations we solve them as first order to get velocities and then use those velocities in further calculations
useful_functions uf;
double t_dot(double r,double a,double theta,double j){
double T_DOT=-(uf.line_element_coeff_5(r,a,theta)+j*uf.line_element_coeff_2(r,a,theta))/(uf.line_element_coeff_5(r,a,theta)*uf.line_element_coeff_1(r,a,theta)-uf.line_element_coeff_2(r,a,theta)*uf.line_element_coeff_2(r,a,theta));
return T_DOT;
}
double p_dot(double r,double a,double theta,double j){
double P_DOT=(j*uf.line_element_coeff_1(r,a,theta)+uf.line_element_coeff_2(r,a,theta))/(uf.line_element_coeff_5(r,a,theta)*uf.line_element_coeff_1(r,a,theta)-uf.line_element_coeff_2(r,a,theta)*uf.line_element_coeff_2(r,a,theta));
return P_DOT;
}
double vr_dot(double r,double a,double theta,double td,double rd,double od,double pd){
double VR_DOT=(-uf.gamma_r_tt(r,a,theta)*td*td-uf.gamma_r_rr(r,a,theta)*rd*rd-uf.gamma_r_oo(r,a,theta)*od*od-uf.gamma_r_pp(r,a,theta)*pd*pd-2*uf.gamma_r_tp(r,a,theta)*td*pd-2*uf.gamma_r_ro(r,a,theta)*rd*od);
return VR_DOT;
}
double vo_dot(double r,double a,double theta,double td,double rd,double od,double pd){
double VO_DOT=-uf.gamma_o_tt(r,a,theta)*td*td-uf.gamma_o_rr(r,a,theta)*rd*rd-uf.gamma_o_oo(r,a,theta)*od*od-uf.gamma_o_pp(r,a,theta)*pd*pd-2*uf.gamma_o_tp(r,a,theta)*td*pd-2*uf.gamma_o_ro(r,a,theta)*rd*od;
return VO_DOT;
}
};
class Integrators{
//DO NOT TOUCH THIS CODE - MESSING WITH THIS WILL BREAK THE INTEGRATOR IN UNRECOVERABLE WAYS
//if you want funny results then change the denominators of the RK4 solver
public:
motion_equations motion_equation;
useful_functions uf;
void rk4_1(double r,double a,double theta,double td,double rd,double od,double pd,double j,double h,double* k1){
k1[0]=motion_equation.vr_dot(r,a,theta,td,rd,od,pd);
k1[1]=motion_equation.vo_dot(r,a,theta,td,rd,od,pd);
k1[2]=motion_equation.t_dot(r,a,theta,j);
k1[3]=rd;
k1[4]=od;
k1[5]=motion_equation.p_dot(r,a,theta,j);
}
void rk4_2(double r,double a,double theta,double td,double rd,double od,double pd,double j,double h,double* k1,double* k2){
k2[0]=motion_equation.vr_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,motion_equation.t_dot(r+ h*k1[3]/2,a,theta+h*k1[4]/2,j ),rd+h*k1[0]/2,od+h*k1[1]/2,motion_equation.p_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,j ));
k2[1]=motion_equation.vo_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,motion_equation.t_dot(r+ h*k1[3]/2,a,theta+h*k1[4]/2,j ),rd+h*k1[0]/2,od+h*k1[1]/2,motion_equation.p_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,j ));
k2[2]=motion_equation.t_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,j );
k2[3]=rd+h*k1[0]/2;
k2[4]=od+h*k1[1]/2;
k2[5]=motion_equation.p_dot(r+h*k1[3]/2,a,theta+h*k1[4]/2,j );
}
void rk4_3(double r,double a,double theta,double td,double rd,double od,double pd,double j,double h,double* k2,double* k3){
k3[0]=motion_equation.vr_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,motion_equation.t_dot(r+ h*k2[3]/2,a,theta+h*k2[4]/2,j ),rd+h*k2[0]/2,od+h*k2[1]/2,motion_equation.p_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,j ));
k3[1]=motion_equation.vo_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,motion_equation.t_dot(r+ h*k2[3]/2,a,theta+h*k2[4]/2,j ),rd+h*k2[0]/2,od+h*k2[1]/2,motion_equation.p_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,j ));
k3[2]=motion_equation.t_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,j );
k3[3]=rd+h*k2[0]/2;
k3[4]=od+h*k2[1]/2;
k3[5]=motion_equation.p_dot(r+h*k2[3]/2,a,theta+h*k2[4]/2,j );
}
void rk4_4(double r,double a,double theta,double td,double rd,double od,double pd,double j,double h,double* k3,double* k4){
k4[0]=motion_equation.vr_dot(r+h*k3[3],a,theta+h*k3[4],motion_equation.t_dot(r+ h*k3[3],a,theta+h*k3[4],j ),rd+h*k3[0],od+h*k3[1],motion_equation.p_dot(r+h*k3[3],a,theta+h*k3[4],j ));
k4[1]=motion_equation.vo_dot(r+h*k3[3],a,theta+h*k3[4],motion_equation.t_dot(r+ h*k3[3],a,theta+h*k3[4],j ),rd+h*k3[0],od+h*k3[1],motion_equation.p_dot(r+h*k3[3],a,theta+h*k3[4],j ));
k4[2]=motion_equation.t_dot(r+h*k3[3],a,theta+h*k3[4],j );
k4[3]=rd+h*k3[0];
k4[4]=od+h*k3[1];
k4[5]=motion_equation.p_dot(r+h*k3[3],a,theta+h*k3[4],j );
}
void one_time_step(double* Y,double a,double j,double h,double* k1,double* k2,double* k3,double* k4){
double r=Y[3];
double theta=Y[4];
double rd=Y[0];
double od=Y[1];
double td=motion_equation.t_dot(r,a,theta,j);
double pd=motion_equation.p_dot(r,a,theta,j);
rk4_1(r,a,theta,td,rd,od,pd,j,h,k1);
rk4_2(r,a,theta,td,rd,od,pd,j,h,k1,k2);
rk4_3(r,a,theta,td,rd,od,pd,j,h,k2,k3);
rk4_4(r,a,theta,td,rd,od,pd,j,h,k3,k4);
Y[0]=Y[0]+1.0/6.0*h*(k1[0]+2*k2[0]+2*k3[0]+k4[0]);
Y[1]=Y[1]+1.0/6.0*h*(k1[1]+2*k2[1]+2*k3[1]+k4[1]);
Y[2]=Y[2]+1.0/6.0*h*(k1[2]+2*k2[2]+2*k3[2]+k4[2]);
Y[3]=Y[3]+1.0/6.0*h*(k1[3]+2*k2[3]+2*k3[3]+k4[3]);
Y[4]=Y[4]+1.0/6.0*h*(k1[4]+2*k2[4]+2*k3[4]+k4[4]);
Y[5]=Y[5]+1.0/6.0*h*(k1[5]+2*k2[5]+2*k3[5]+k4[5]);
}
double next_time_step(double initial_x,double rad,double vrad,double thet,double vthet,double ph,double vph,double F){
// gets the next time-step in the algorithm.
double elm[3];
double min;
double dT;
if (initial_x != 0){// dT is set by F multiplied by the shortest variability time-scale in the problem.
elm[0]=abs(rad/vrad);
elm[1]=abs(thet/vthet);
elm[2]=abs(ph/vph);
min=elm[0];
for (int m=0; m<2; m ++){
if (elm[m]<min){
min=elm[m];
}
}
dT=F*min;
}
else{//If initial_x=0,then \phi=0,and we will pass over the pole \theta=0,at some point in the trajectory.
// We must only consider the radial time-scale in that case.
dT=F*abs(rad/vrad);
}
return dT;
}
};
class photon{
// This will solve the geodesic equations for a single photon
public:
useful_functions uf;
motion_equations motion_equation;
Integrators integrator;
Initial_conditions start;
void raytracing_output(vector<double> arr,int len_arr){
// Takes a vector input arr,with length len_arr
// and outputs it as one big string.
//
// This string can be converted into a numpy array
// quite easily within python.
stringstream ss;
for(int i=0; i<len_arr; ++i)
{
if(i != 0)
ss<<",";
ss<<arr[i];
}
string s=ss.str();
cout<<s<<endl;
}
double innermost_stable_circular_orbit_prograde(double a){
// Returns the ISCO radius for prograde spins,a>0.
double Z_1=1+pow(1-a*a,1.0/3.0)*(pow(1+a,1.0/3.0)+pow(1-a,1.0/3.0));
double Z_2=sqrt(3*a*a+Z_1*Z_1);
double innermost_stable_circular_orbit= (3+Z_2- sqrt((3-Z_1)*(3+Z_1+2*Z_2)));
return innermost_stable_circular_orbit;
}
double innermost_stable_circular_orbit_retrograde(double a){
// Returns the ISCO radius for retrograde spins,a<0.
double Z_1=1+pow(1-a*a,1.0/3.0)*(pow(1+a,1.0/3.0)+pow(1-a,1.0/3.0));
double Z_2=sqrt(3*a*a+Z_1*Z_1);
double innermost_stable_circular_orbit= (3+Z_2+sqrt((3-Z_1)*(3+Z_1+2*Z_2)));
return innermost_stable_circular_orbit;
}
double get_innermost_stable_circular_orbit(double a){
// Gets the ISCO radius for a given BH spin parameter
double ri=1.0;
if (a == 0){
ri=6;// Schwarzschild result.
}
else if (a>0){
ri=innermost_stable_circular_orbit_prograde(a);// Analytic formula for the ISCO depends on the sign of the spin parameter.
}
else {
ri=innermost_stable_circular_orbit_retrograde(a);// Analytic formula for the ISCO depends on the sign of the spin parameter.
}
return ri;
}
double obtain_event_horizon(double a){
// Gets the event horizon for a given BH spin parameter.
double rH= 1+sqrt(1-a*a);
return rH;
}
void compute_orbit(double a,double initial_x,double initial_y,double initial_theta,double d,double F,const int n,double& rf,double& phif,double& thetaf,string method){
// First we initialise the photons 4-velocities.
double vt0=start.initial_vt(a,d,initial_x,initial_y,initial_theta);
double vr0=start.initial_vr(d,initial_x,initial_y);
double vo0=start.initial_vo(d,initial_x,initial_y,initial_theta);
double vp0=start.initial_vp(d,initial_x,initial_y,initial_theta);
// then we initialise the photons position
double t0=1;
double r0=start.initial_r(d,initial_x,initial_y);
double theta0=start.initial_theta(d,initial_x,initial_y,initial_theta);
double phi0=start.initial_phi(d,initial_x,initial_y,initial_theta);
// calculate the photons normalised angular momentum
// the important quantity for red-shift calculations
double j=uf.normalized_angular_momentum(r0,a,theta0,vt0,vp0);
// calculate initial r and theta acceleration
double vr_dot0=motion_equation.vr_dot(r0,a,theta0,vt0,vr0,vo0,vp0);
double vo_dot0=motion_equation.vo_dot(r0,a,theta0,vt0,vr0,vo0,vp0);
// important vectors for algorithm implimentation
vector<double> t(1);
double dT=0;
// Varying time-stepping,time-step in integration is
// a fixed fraction of the time-scale of the
// rapidest changing variable
// d tau == F*min( r/r_dot,theta/theta_dot,phi/phi_dot )
dT=integrator.next_time_step(initial_x,r0,vr0,theta0,vo0,phi0,vp0,F);
t[0]=dT;
// set-up for the algorithm implimentation
double rk4y[6];
double k1[6];
double k2[6];
double k3[6];
double k4[6];
rk4y[0]=vr0;
rk4y[1]=vo0;
rk4y[2]=t0;
rk4y[3]=r0;
rk4y[4]=theta0;
rk4y[5]=phi0;
k1[0]=k1[1]=k1[2]=k1[3]=k1[4]=k1[5]=0;
k2[0]=k2[1]=k2[2]=k2[3]=k2[4]=k2[5]=0;
k3[0]=k3[1]=k3[2]=k3[3]=k3[4]=k3[5]=0;
k4[0]=k4[1]=k4[2]=k4[3]=k4[4]=k4[5]=0;
// Quantities calculated at every time-step
vector<double> r(1);
vector<double> theta(1);
vector<double> phi(1);
r[0]=r0;
theta[0]=theta0;
phi[0]=phi0;
int m=0;// For watching the time-steps.
// First method,all photon paths terminated when they move through the disk plane (z=0).
// Even if they pass between the ISCO and event horizon.
if (method == "Simple"){
double rH=obtain_event_horizon(a);
while (rk4y[3]*cos(rk4y[4])>0){ // stops when z<0
if (m<n){ // unless algorithm has got stuck (generally happens when photon hits black-hole)
if (rk4y[3]>rH){ // if r<rH then in the black-hole
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
}
else{//I am in the black hole.
break;
}
++m; // in case algorithm gets stuck
}
else{// Too many steps.
break;
}
}
}
// Second method,allows light rays to pass between the disk and event horizon: rH<r<rI.
if (method == "Disk"){
double rI=get_innermost_stable_circular_orbit(a);
double rH=obtain_event_horizon(a);
while (rk4y[3]*cos(rk4y[4])>-20){
if (m<n){
if (rk4y[0]*cos(rk4y[4])-rk4y[3]*sin(rk4y[4])*rk4y[1]<0){
if (rk4y[3]>rH){
if (abs(rk4y[3]*cos(rk4y[4]))>0.05){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else if (rk4y[3]<rI){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else{
break;
}
}
else{
break;
}
}
else if (rk4y[3]*cos(rk4y[4])<20){
if (rk4y[3]>rH){
if (abs(rk4y[3]*cos(rk4y[4]))>0.1){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else if (rk4y[3]<rI){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else{
break;
}
}
else{
break;
}
}
else{
break;
}
}
}
}
// Third method,assumes no disk in the z=0 plane.
if (method == "NoDisk"){
double rH=obtain_event_horizon(a);
while ( (rk4y[3]*cos(rk4y[4])>-20) && (rk4y[3]*sin(rk4y[4])*cos(rk4y[5])>-30)){// stops when photon reaches z=-20 or x=-30,or x>30 and v_x>0.
if ( ((rk4y[0]*sin(rk4y[4])*cos(rk4y[5])+rk4y[3]*rk4y[1]*cos(rk4y[4])*cos(rk4y[5])-rk4y[3]*motion_equation.p_dot(rk4y[3],a,rk4y[4],j)*sin(rk4y[4])*sin(rk4y[5])>0) && rk4y[3]*sin(rk4y[4])*cos(rk4y[5])>30) ){
break;// Breaks if x>30 and v_x>0.
}
if (m<n){
if (rk4y[0]*cos(rk4y[4])-rk4y[3]*sin(rk4y[4])*rk4y[1]<0){// if z-velocity is negative.
if (rk4y[3]>rH){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else{
break;
}
}
else if (rk4y[3]*cos(rk4y[4])<20){// else I am going up,and z <+20.
if (rk4y[3]>rH){
integrator.one_time_step(rk4y,a,j,dT,k1,k2,k3,k4); // implements the RK4 algorithm
r.push_back(rk4y[3]);
theta.push_back(rk4y[4]); // updates the variables
phi.push_back(rk4y[5]);
dT=integrator.next_time_step(initial_x,rk4y[3],rk4y[0],rk4y[4],rk4y[1],rk4y[5],motion_equation.p_dot(rk4y[3],a,rk4y[4],j),F);
t.push_back(t[m]+dT);
++m;
}
else{
break;
}
}
else{
break;
}
}
}
}
raytracing_output(r,m);
raytracing_output(theta,m);
raytracing_output(phi,m);
raytracing_output(t,m);
cout<<j<<endl;
rf=r[m];
thetaf=theta[m]; // Edits these variables in the main script
phif=phi[m];
}
};
int main(int argc,const char*argv[]) {
// We import the class of one photon orbit integrators
photon example_photon;
if (argc != 6){// Should get 1: C++ file name (always happens),2-5: Parameters alphinitial_x,betinitial_x,theta0,a & 6: method to be used.
throw runtime_error("There aren't enough input parameters.");
return -1;
}
double initial_x=atof(argv[1]);
double initial_y=atof(argv[2]);
double initial_theta=atof(argv[3])*M_PI/180;
double a=atof(argv[4]);
string method= argv[5];
if (abs(a)>1){// Unphysical black hole spin parameter.
throw runtime_error("A black hole cannot exist with this spin value");
return -1;
}
if (method != "Simple" && method != "Disk" && method != "NoDisk"){
throw runtime_error("The method to be followed must be one of Simple,Disk,and NoDisk.");
return -1;
}
// These parameters are unchanging for the Photon orbit
// d=observer distance (approximation as in reality -> infinity)
// F involved in time step in algorithm
// n is a maximum number of steps per integration per photon,exists to avoid algorithm getting stuck. (Happens when the photon reaches the event horizon).
double d=1000;
double F=1.0/128.0;
const int n=5000;
// these will be updated after photon integration with the
// points in the disk where the photon originated from
double rf=0;
double phif=0;
double thetaf=0;
example_photon.compute_orbit(a,initial_x,initial_y,initial_theta,d,F,n,rf,phif,thetaf,method); // solve the orbit equations for a single photon
cout<<rf<<endl;
cout<<thetaf<<endl;
cout<<phif<<endl;
return 0;
};