-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccretion_disk.c
More file actions
1609 lines (1303 loc) · 66.1 KB
/
accretion_disk.c
File metadata and controls
1609 lines (1303 loc) · 66.1 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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "accretion_disk.h"
/** Code specific declaration */
//#define Nr 66 /** layers **/
//#define Ntheta 66 /** zones per layers **/
/** Code specific declaration */
#define Nr 22 /** layers **/
#define Ntheta 22 /** zones per layers **/
/** Definition of the physical constants **/
/** Constant CGS */
#define c 2.99792458e10 /** cm.s^-1 */
#define Msun 1.989e33 /** g */
#define h 6.6260755e-27 /** erg.s */
#define hc 1.9864474610385790e-16
#define kb 1.380657e-16 /** erg.K^-1 */
#define sigmaSB 5.67051e-5 /** erg.cm^-2 K^-4 s^-1 */
#define Ggrav 6.67259e-8 /** cm^3.g^-1.s^-2 */
#define pc 3.08568e18 /** cm */
#define nm 1e-7 /** cm */
#define angstrom 1e-8 /** cm */
#define second_to_day 1.157407407e-5
/** Other constant */
#define pi 3.14159265358979
#define degree_to_radian 0.0174532925
/** Husne, 09/10/2018
* Here I define all the function to create and fill the disk
*/
///** define the Function of the Flux **/
int find_index(int Ntime, double t, double *time, double tau, double *flux){
/** Husne, 13/12/2018
* Find the position of the t-tau in the light curve using Binary search algorithm
*/
double t_tau = t-tau;
int nb_loop = 0;
/** Step1 */
int L = time [0];
int R = Ntime-1;
/** Step2 */
int m = 0;
/** Check boundaries for element ouside of the array */
if((t_tau)< time[0] || (t_tau)>time[R]){
// printf("Undefined flux t-tau = %g\n",t_tau);
return -1;
}
/** Check the boundaries */
if(time[0] == (t_tau)){
return 0;
}
if(time[R] == (t_tau)){
return -1;
}
/** The element we are looking for is not at the boundary */
while (L < R){
/** Step3 */
m = floor((L+R)/2);
nb_loop +=1;
if(time[m] == (t_tau)){
return m;
}
if(time[m+1] == (t_tau)){
return m+1;
}
/** Step4 */
if (time[m] < (t_tau)){
L = m ;
}
/** Step5 */
if (time[m] > (t_tau)){
R = m ;
}
if(R == L+1){
return L;
}
}
// printf("Undefined flux outside \n");
return -1;
}
///** define the Function of the luminosity **/
double L_star(double L_bol, int Ntime, double t, double *time, double tau, double *flux){///double omega, double t){
//omega = 3*c/R_out
/** Look for the index */
int index_flux = find_index(Ntime, t, time, tau, flux);
if(index_flux == -1){
return -1.0;
}
/** It is ok it is inside the time */
double f = flux[index_flux]+(flux[index_flux+1]-flux[index_flux])*(t-tau-time[index_flux])/(time[index_flux+1]-time[index_flux]);;
///return 0.15*L_bol*f;
return L_bol*f;
}
/** define the Function of the distance from the central variable source to disk elements **/
double r_star(double r, double h_star){
return sqrt(pow(h_star,2.0)+pow(r,2.0));
}
/** define the Function of the temperature profile **/
double temp_profile(double t, double r, double rstar, double tau, double theta, double M, double M_rate, double r_in, double A, double h_star, double inc_angle, double L_bol, int Ntime, double *time, double *flux){
/// Compute the time lag up to the radius. For speed purposed, it is now computed only one time in the main code.
// double tau = sqrt(pow(h_star,2.0)+pow(r,2.0))+h_star*cos(inc_angle)-r*cos(theta*0.0174532925)*sin(inc_angle);
// tau = tau/c;
double Lstar = L_star(L_bol, Ntime, t, time, tau, flux);
if(Lstar < 0.0){
return -1.0;
}
//double rstar = r_star(r, h_star);
//printf("Contrib 1 = %g\t contrib 2 = %g\n ",((3.0*Ggrav*M*M_rate)/(8.0*pi*sigmaSB*pow(r,3.0)))*(1.0-sqrt(r_in/r)), ((1.0-A)*(h_star*Lstar/(4.0*pi*sigmaSB*pow(rstar,3.0)))));
//getchar();
//printf()
return pow(((3.0*Ggrav*M*M_rate)/(8.0*pi*sigmaSB*pow(r,3.0)))*(1.0-sqrt(r_in/r)) +((1.0-A)*(h_star*Lstar/(4.0*pi*sigmaSB*pow(rstar,3.0)))) ,0.25);
}
/** define the Function of the temperature profile when there is no illumination **/
double Temp_profile_steady(double r, double rstar, double M, double M_rate, double r_in){
return pow(((3.0*Ggrav*M*M_rate)/(8.0*pi*sigmaSB*pow(r,3.0)))*(1.0-sqrt(r_in/r)) ,0.25);
}
/** Husne, 09/10/2018
* Here I define all the function required to compute the spectra
*/
/** define the Planck Function **/
double Planck_Function(double lambda3, double lambda, double temperature){
return ((2.0*hc)/lambda3)/(exp(hc/(lambda*kb*temperature))-1.0);
}
/** define the Function of predicted spectrum (SED) **/
double spectrum(double cos_inc_angle, double D2, double theta_in, double theta_out, double R_in, double R_out, double lambda3, double lambda, double temperature){
return (cos_inc_angle/D2)*Planck_Function(lambda3, lambda, temperature)*(theta_out-theta_in)*0.5*(R_out*R_out - R_in*R_in);
}
/** define new type as regions and its elements to create disk **/
typedef struct region {
double radius;
double theta;
double temp;
double rstar;
double tau;
double temp_t;
double temp_tptau;
} region;
/************************************* COMPUTE THE COLOR VARIABILITY ********************************************************/
int make_computation(int Nfilter, long int *computed_filter, double *time, double *flux, double *ratio, double *tau_time, int Ntime, int Ntau){
/*
int ii;
FILE *output;
output = fopen("lc.txt","a");
for(ii = 0; ii < Ntime; ii++){
fprintf(output, "%g\t%g\n", time[ii], flux[ii]);
}
fclose(output);
*/
/** Husne, 9/10/2018
* Here I create and fill the disk. I compute the temperature and settle all the regions of the disk.
*/
double *r; /** radius which is from the center of disk to the center of any region**/
double *theta; /** azimuth angle which is from the origine to the r for any region**/
r = (double *) calloc(Nr,sizeof(double));
theta = (double *) calloc(Ntheta,sizeof(double));
double M = 3.2e7*Msun; /** M_sun, the black hole mass, converted to gr **/
double Rg= (Ggrav*M)/(c*c); /** gravitational radius **/
double r_in= 6.0*Rg; /** inner radius **/
double r_out=10000*Rg; /** outer radius **/
double inc_angle = 45.0*0.0174532925; /** inclination angle , converted to radian **/
double cos_inc_angle = cos(inc_angle); /** Cos of the inclination angle, avoid to recompute it all the time */
double h_star = 10.0*Rg; /** the vertical distance from the cetral variable source to disk **/
double M_rate = 1.0*Msun/31557600.0; /** M_sun yr^-1, the typical black hole accretion rate , converted to gr **/
/** the numerical factor converts from year to second: we are working in cgs: cm gram second.*/
double A = 0.5; /** the disk albedo **/
double L_bol = 2.82e44; /** erg/s^-1, the bolometric luminosity **/
/** Checking the values of the radii */
// printf("Rg = %g\tR_int = %g\tR_out = %g \n", Rg, r_in, r_out);
// getchar();
/** create disks which contain the regions **/
region *disk;
disk = (region *) malloc(Nr*Ntheta*sizeof(region));
/** the ratio of the outher and inner radius of each rings fixed **/
double step = exp(log(r_out/r_in)/Nr);
int i;
for (i=0; i < Nr; i++){
r[i] = r_in*pow(step,i);
}
for (i=0; i < Ntheta; i++){
theta[i] = i*(360.0/Ntheta)*degree_to_radian;
}
/** fill the disks with elements (radius and theta) of regions **/
int j;
double tau;
for (i=0; i < Nr; i++){
for (j=0; j < Ntheta; j++){
disk[i*Ntheta+j].radius = r[i]; /** disk[0] region1, ... **/
disk[i*Ntheta+j].theta = theta[j];
disk[i*Ntheta+j].rstar = r_star(r[i], h_star); /** disk[0] region1, ... **/
/// Compute the time lag up to the radius.
tau = sqrt(pow(h_star,2.0)+pow(r[i],2.0))+h_star*cos_inc_angle-r[i]*cos(theta[j])*sin(inc_angle);
tau = (tau/c)*second_to_day;
disk[i*Ntheta+j].tau = tau;
}
}
//double L_star = 0.5*L_bol; /** the luminosity of central variable source **/
//printf("Rg = %g\t r_star = %g\t M_rate = %g\t")
/** Husne, 9/10/2018
*
*/
/** for the computation of luminosity so it is for temperature **/
///double omega = 10.0*c/r_out;
/** for the computation of the radiation from the disk. **/
double D = 75.01*1e6*pc; /** Mpc distance from observer to the source, converted to cm **/
double D2 = D*D;
double R_in;
double R_out;
double theta_in;
double theta_out;
/** ************************************************
* ************************************************
* ************************************************
* ************************************************
* ************************************************
*/
/** Husne, 11/10/2018
* Convolotion with the filter bandpass.
Read a txt file for U bandpass.
*/
//double filtername[6] = {0, 1, 2, 3, 4, 5}; //* filter names: 0=UVW2, 1=UVM2, 2=UVW1, 3=U, 4=B, 5=V */
//int Nfilter = 6;
double **wavelength;
double **wavelength3;
wavelength = (double **) malloc(Nfilter*sizeof(double*)); //* create an array */
wavelength3 = (double **) malloc(Nfilter*sizeof(double*)); //* create an array */
double **transmission;
transmission = (double **) malloc(Nfilter*sizeof(double*));
double c1_filtername, c2_filtername;
int numberofloop_filtername;
int *numberofloop;
numberofloop = (int*) calloc(Nfilter,sizeof(int)); //* create an array */
for (j=0; j < Nfilter; j++){
//printf("Begining of loop \t j = %d\tNfilter = %d\n", j, Nfilter);
//getchar();
FILE *input_filtername;
numberofloop_filtername = 0.0;
//*it is important, when the filter number given as a "0" make computation*/
if (computed_filter[j] == 0){
switch(j) {
case 0 : //*it is UVW2 filter then*/
input_filtername=fopen("Filter/UVW2_binned5.txt","r");//* open a text file for reading */
/** Here %lf means type double */
/// step 1 caunt the number of loop
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
case 1 : //*it is UVM2 filter then*/
input_filtername=fopen("Filter/UVM2_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
case 2 : //*it is UVW1 filter then*/
input_filtername=fopen("Filter/UVW1_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
case 3 : //*it is U filter then*/
input_filtername=fopen("Filter/U_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
case 4 : //*it is B filter then*/
input_filtername=fopen("Filter/B_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
case 5 : //*it is V filter then*/
input_filtername=fopen("Filter/V_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop_filtername = numberofloop_filtername + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
numberofloop[j] = numberofloop_filtername;
fclose(input_filtername);
break;
}
}
/// step 2 to create arrays
wavelength[j] = (double *) calloc(numberofloop[j],sizeof(double)); //* create an array */
wavelength3[j] = (double *) calloc(numberofloop[j],sizeof(double)); //* create an array */
transmission[j] = (double *) calloc(numberofloop[j],sizeof(double));
/// step 3 fill the arrays
//*it is important, when the filter number given as a "0" make computation*/
if (computed_filter[j] == 0){
switch(j) {
case 0 : //*it is UVW2 filter then*/
input_filtername=fopen("Filter/UVW2_binned5.txt","r");//* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 1 : //*it is UVM2 filter then*/
input_filtername=fopen("Filter/UVM2_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 2 : //*it is UVW1 filter then*/
input_filtername=fopen("Filter/UVW1_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 3 : //*it is U filter then*/
input_filtername=fopen("Filter/U_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 4 : //*it is B filter then*/
input_filtername=fopen("Filter/B_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 5 : //*it is V filter then*/
input_filtername=fopen("Filter/V_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[j][i]= c1_filtername*angstrom;
wavelength3[j][i]= wavelength[j][i]*wavelength[j][i]*wavelength[j][i];
transmission[j][i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
}
}
}
/*for (j=0;j<Nfilter;j++){
printf("j = %d\t %d\n",j, numberofloop[j]);
}*/
/** ************************************************
* ************************************************
* ************************************************
* ************************************************
* ************************************************
*/
/** Husne, 20/10/2018
* I define the time and tau_time as arrays
*/
// 1) SET the tau so give the value of tau
//const int Ntau = 7;
//double tau_time[7] = {3.0, 6.0, 10.0, 20.0, 40.0, 100.0, 200.0};
//printf("%g\t\n",tau_time); //* print the arrays */
int Nt = 2200; /** time[Ntime-1]-time[0]=1048.1724000000004 **/
double *t;
t = (double *) calloc(Nt,sizeof(double));
for (i=0; i<Nt; i++){
t[i] = ((double) i)/2.0;
//printf("t=%g\n", t[i]);
}
// a) make the sum of all the S(tau, t)*1/Nt
// i) compute all S for all t
/** Husne, 19/10/2018 * compute the color variability and plot them */
double avarage_SBU = 0.0;
double S_BU; /**color_variation of BU */
/** Husne, 18/10/2018 * Now compute the integral for U band. */
double deltaLambda_U;
/** Husne, 19/10/2018 * Now compute the integral for B band.*/
double deltaLambda_B;
double flux_t_U;
double flux_t_B;
double flux_tptau_U;
double flux_tptau_B;
double Temperature_t;
double Temperature_tptau;
double Integral;
double f_U_im1 = 0.0;
double f_B_im1 = 0.0;
double f_U_i = 0.0;
double f_B_i = 0.0;
int m;
int n;
int l;
int k;
double stepR = exp(log(r_out/r_in)/Nr);
double sqrt_stepR = sqrt(stepR);
double stepT = 360.0*degree_to_radian/Ntheta;
int can_do_computation;
int nb_computation;
double stau;
/** Loop for the Number of filter, because I need to compute the average S for all tau by using two bands */
for (m=0;m<Nfilter;m++){
for (n=m+1;n<Nfilter;n++){
//*it is important, when the filter number given as a "0" make computation for all casses between two filters */
if(computed_filter[m] == 0 && computed_filter[n] == 0){
printf("\n");
/** Loop for the tau, because I need to compute the average S for all tau */
for (l=0; l < Ntau; l++){
S_BU = 0.0;
nb_computation = 0;
/** Loop for the time, because I need to compute an average with respect to time */
/// to put back k < Nt
for (k=0; k < Nt; k++){
if(k % 100 == 0){
printf("m = %d\tn=%d\tl=%d\ttau=%g\tk = %d\n", m, n, l, tau_time[l], k);
}
/** I need to compute S for all t
* I need to compute f(t+tau), f(t) for U band
*/
flux_t_U = 0.0;
flux_t_B = 0.0;
flux_tptau_U = 0.0;
flux_tptau_B = 0.0;
/** I need to check that for all elements of the disk I never obtained a negative temperature, which means that the computation can be done. */
can_do_computation = 0;
for (j=0; j < Nr*Ntheta; j++){
/// temperature at time t in U
Temperature_t = temp_profile(t[k], disk[j].radius, disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
disk[j].temp_t = Temperature_t;
/// temperature at time t + tau in U
Temperature_tptau = temp_profile(t[k] + tau_time[l], disk[j].radius, disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
disk[j].temp_tptau = Temperature_tptau;
if(Temperature_t < 0.0 || Temperature_tptau < 0.0){
can_do_computation = 1;
}
}
/** Loop for the radius and theta, because I need to compute the temparature and spectrum of disk */
/// f is the summ of contribution from all the disk elements.
if(can_do_computation == 0){
//nb_computation += 1;
for (j=0; j < Nr*Ntheta; j++){
R_in = disk[j].radius/sqrt_stepR; /** from the center to the first layer of any region **/
R_out = disk[j].radius*sqrt_stepR; /** from the center to the last layer of any region **/
theta_in = disk[j].theta - 0.5*stepT; /** from the origine to the first layer of any region on the bottom**/
theta_out = disk[j].theta + 0.5*stepT; /** from the origine to the last layer of any region on the top**/
/** Now I compute the integral for the U-band */
/// temperature at time t in U
// stored in the disk structure for every time
//Temperature_t = temp_profile(t[k], disk[j].radius,disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
Temperature_t = disk[j].temp_t;
// printf("temperature 1 = %g\t", Temperature_t);
/// Initialization of the sum to compute the integral over the filter
Integral = 0.0;
/** Loop for the band, because I need to compute the integral over bandpass */
///numberofloop_U = numberofloop[m]
for(i = 1; i < numberofloop[m] ; i++){
deltaLambda_U = (wavelength[m][i] - wavelength[m][i-1]);
f_U_i = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[m][i], wavelength[m][i], Temperature_t)*transmission[m][i];
f_U_im1 = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[m][i-1], wavelength[m][i-1], Temperature_t)*transmission[m][i-1];
Integral += (f_U_i+f_U_im1)*deltaLambda_U/2.0;
}
flux_t_U = flux_t_U + Integral;
if(flux_t_U != flux_t_U){
printf("Flux_t_u = NAN \t j = %d\t Integral = %g\n", j, Integral);
getchar();
}
/// temperature at time t + tau in U
//Temperature_tptau = temp_profile(t[k] + tau_time[l], disk[j].radius, disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
Temperature_tptau = disk[j].temp_tptau;
// printf("temperature 2 = %g\t", Temperature_tptau);
/// Initialization of the sum to compute the integral over the filter
Integral = 0.0;
/** Loop for the one band, because I need to compute the integral over bandpass */
///numberofloop_U = numberofloop[m]
for(i = 1; i < numberofloop[m] ; i++){
deltaLambda_U = (wavelength[m][i] - wavelength[m][i-1]);
f_U_i = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[m][i], wavelength[m][i], Temperature_tptau)*transmission[m][i];
f_U_im1 = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[m][i-1], wavelength[m][i-1], Temperature_tptau)*transmission[m][i-1];
Integral += (f_U_i+f_U_im1)*deltaLambda_U/2.0;
}
flux_tptau_U = flux_tptau_U + Integral;
if(flux_tptau_U != flux_tptau_U){
printf("Flux_t_uptau = NAN \t j = %d\t Integral = %g\n", j, Integral);
getchar();
}
/** Now I compute the integral for the B-band */
/// temperature at time t in B, no need to recompute it
//Temperature_t = temp_profile(t[k], disk[j].radius, disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
// printf("temperature 3 = %g\t", Temperature_t);
///if(Temperature_t!=Temperature_t){
///printf("%.13g\t\n", Temperature_t);
///getchar();
///}
/// Initialization of the sum to compute the integral over the filter
Integral = 0.0;
/** Loop for the another band, because I need to compute the integral over bandpass */
///numberofloop_B = numberofloop[n]
for(i = 1; i < numberofloop[n] ; i++){
deltaLambda_B = (wavelength[n][i] - wavelength[n][i-1]);
f_B_i = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[n][i], wavelength[n][i], Temperature_t)*transmission[n][i];
f_B_im1 = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[n][i-1], wavelength[n][i-1], Temperature_t)*transmission[n][i-1];
Integral += (f_B_i+f_B_im1)*deltaLambda_B/2.0;
}
flux_t_B = flux_t_B + Integral;
if(flux_t_B != flux_t_B){
printf("Flux_t_b = NAN \t j = %d\t Integral = %g\n", j, Integral);
getchar();
}
/// temperature at time t + tau in U
// No need to recompute
//Temperature_tptau = temp_profile(t[k] + tau_time[l], disk[j].radius, disk[j].rstar, disk[j].tau, disk[j].theta, M, M_rate, r_in, A, h_star, inc_angle, L_bol, Ntime, time, flux);
// printf("temperature 4 = %g\n", Temperature_tptau);
/// Initialization of the sum to compute the integral over the filter
Integral = 0.0;
/** Loop for the another band, because I need to compute the integral over bandpass */
///numberofloop_B = numberofloop[n]
for(i = 1; i < numberofloop[n] ; i++){
deltaLambda_B = (wavelength[n][i] - wavelength[n][i-1]);
f_B_i = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[n][i], wavelength[n][i], Temperature_tptau)*transmission[n][i];
f_B_im1 = spectrum(cos_inc_angle, D2, theta_in, theta_out, R_in, R_out, wavelength3[n][i-1], wavelength[n][i-1], Temperature_tptau)*transmission[n][i-1];
Integral += (f_B_i+f_B_im1)*deltaLambda_B/2.0;
}
flux_tptau_B = flux_tptau_B + Integral;
if(flux_tptau_B != flux_tptau_B){
printf("Flux_tptau_b = NAN \t j = %d\t Integral = %g\n", j, Integral);
getchar();
}
}
stau = (flux_tptau_B-flux_t_B) / (flux_tptau_U-flux_t_U);
if(stau > 0.0){
S_BU = S_BU + stau;
nb_computation +=1;
}
//printf("%.13g\t\n", flux_t_B);
//printf("%.13g\t\n", flux_t_U);
}
}
//avarage_SBU = S_BU/Nt;
avarage_SBU = S_BU/ ((double) nb_computation);
ratio[l] = avarage_SBU;
printf("%.13g\t\n", avarage_SBU);
}
}
}
}
for (j=0; j < Nfilter; j++){
free(wavelength[j]);
free(wavelength3[j]);
free(transmission[j]);
}
free(r);
free(theta);
free(disk);
free(wavelength);
free(wavelength3);
free(transmission);
return 0;
}
/******************************************** COMPUTE LIGHT CURVE ****************************************************************/
/** What are the parameters ?
* 1- filter_name : name of the filter
* 2- time_ILC : time of the illuminating light-curve
* 3- flux_ILC : flux of the illuminating light-curve
* 4- Ntime_ILC : length of array time_ILC and flux_ILC
* 5- t : the time at which the LC should be computed
* 6- flux : the vector to be filled by the light-curve
* 7- Nt : the length of those arrays
*/
int compute_LC(int filter_name, double *time_ILC, double *flux_ILC, int Ntime_ILC, double *t, double *flux, int Nt, double multiplicator){
/** Husne, 9/10/2018
* Here I create and fill the disk. I compute the temperature and settle all the regions of the disk.
*/
double *r; /** radius which is from the center of disk to the center of any region**/
double *theta; /** azimuth angle which is from the origine to the r for any region**/
r = (double *) calloc(Nr,sizeof(double));
theta = (double *) calloc(Ntheta,sizeof(double));
double M = 3.2e7*Msun; /** M_sun, the black hole mass, converted to gr **/
double Rg= (Ggrav*M)/(c*c); /** gravitational radius **/
double r_in= 6.0*Rg; /** inner radius **/
double r_out=10000*Rg; /** outer radius **/
double inc_angle = 45.0*degree_to_radian; /** inclination angle , converted to radian **/
double cos_inc_angle = cos(inc_angle); /** Cos of the inclination angle, avoid to recompute it all the time */
double h_star = 10.0*Rg; /** the vertical distance from the cetral variable source to disk **/
double M_rate = 1.0*Msun/31557600.0; /** M_sun yr^-1, the typical black hole accretion rate , converted to g.s^-1 **/
/** the numerical factor converts from year to second: we are working in cgs: cm gram second.*/
double A = 0.5; /** the disk albedo **/
double L_bol = multiplicator*2.82e44; /** erg/s^-1, the bolometric luminosity **/
/** Checking the values of the radii */
// printf("Rg = %g\tR_int = %g\tR_out = %g \n", Rg, r_in, r_out);
// getchar();
/** create disks which contain the regions **/
region *disk;
disk = (region *) malloc(Nr*Ntheta*sizeof(region));
/** the ratio of the outher and inner radius of each rings fixed **/
double step = exp(log(r_out/r_in)/Nr);
int i;
for (i=0; i < Nr; i++){
r[i] = r_in*pow(step,(double) i);
}
for (i=0; i < Ntheta; i++){
theta[i] = ((double) i)*(360.0/Ntheta)*degree_to_radian;
}
/** fill the disks with elements (radius and theta) of regions **/
int j;
double tau;
for (i=0; i < Nr; i++){
for (j=0; j < Ntheta; j++){
disk[i*Ntheta+j].radius = r[i]; /** disk[0] region1, ... **/
disk[i*Ntheta+j].theta = theta[j];
disk[i*Ntheta+j].rstar = r_star(r[i], h_star); /** disk[0] region1, ... **/
/// Compute the time lag up to the radius.
tau = sqrt(pow(h_star,2.0)+pow(r[i],2.0))+h_star*cos_inc_angle-r[i]*cos(theta[j])*sin(inc_angle);
tau = (tau/c)*second_to_day;
disk[i*Ntheta+j].tau = tau;
}
}
/** Husne, 9/10/2018
*
*/
/** for the computation of luminosity so it is for temperature **/
///double omega = 10.0*c/r_out;
/** for the computation of the radiation from the disk. **/
double D = 75.01*1e6*pc; /** Mpc distance from observer to the source, converted to cm **/
double D2 = D*D;
double R_in;
double R_out;
double theta_in;
double theta_out;
/** ************************************************
* ************************************************
* ************************************************
* ************************************************
* ************************************************
*/
/** Husne, 11/10/2018
* Convolotion with the filter bandpass.
Read a txt file for U bandpass.
*/
//double filtername[6] = {0, 1, 2, 3, 4, 5}; //* filter names: 0=UVW2, 1=UVM2, 2=UVW1, 3=U, 4=B, 5=V */
//int Nfilter = 6;
double *wavelength;
double *wavelength3;
double *transmission;
double c1_filtername, c2_filtername;
int numberofloop = 0;
FILE *input_filtername;
//*it is important, when the filter number given as a "0" make computation*/
switch(filter_name) {
case 0 : //*it is UVW2 filter then*/
input_filtername=fopen("Filter/UVW2_binned5.txt","r");//* open a text file for reading */
/** Here %lf means type double */
/// step 1 caunt the number of loop
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
case 1 : //*it is UVM2 filter then*/
input_filtername=fopen("Filter/UVM2_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
case 2 : //*it is UVW1 filter then*/
input_filtername=fopen("Filter/UVW1_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
case 3 : //*it is U filter then*/
input_filtername=fopen("Filter/U_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
case 4 : //*it is B filter then*/
input_filtername=fopen("Filter/B_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
case 5 : //*it is V filter then*/
input_filtername=fopen("Filter/V_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
if(c2_filtername > 0.01){
numberofloop = numberofloop + 1; //* caunt the number of loop */
}
/// Previous line is equivalent to numberofloop_U = numberofloop_U + 1; //* caunt the number of loop */
}
fclose(input_filtername);
break;
}
/** DAMIEN : WE STOP LOOKING AT THE PB HERE */
/// step 2 to create arrays
wavelength = (double *) calloc(numberofloop,sizeof(double)); //* create an array */
wavelength3 = (double *) calloc(numberofloop,sizeof(double)); //* create an array */
transmission = (double *) calloc(numberofloop,sizeof(double));
/// step 3 fill the arrays
//*it is important, when the filter number given as a "0" make computation*/
switch(filter_name) {
case 0 : //*it is UVW2 filter then*/
input_filtername=fopen("Filter/UVW2_binned5.txt","r");//* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[i]= c1_filtername*angstrom;
wavelength3[i]= wavelength[i]*wavelength[i]*wavelength[i];
transmission[i]= c2_filtername;
i += 1;
}
}
fclose(input_filtername);
break;
case 1 : //*it is UVM2 filter then*/
input_filtername=fopen("Filter/UVM2_binned5.txt","r"); //* open a text file for reading */
/** Here %lf means type double */
/// step 1
i = 0;
while(fscanf(input_filtername,"%lf%lf", &c1_filtername, &c2_filtername) !=EOF ){
/// i = i + 1 ;
if(c2_filtername > 0.01){
wavelength[i]= c1_filtername*angstrom;
wavelength3[i]= wavelength[i]*wavelength[i]*wavelength[i];
transmission[i]= c2_filtername;
i += 1;
}
}