forked from chengchengcode/ADAF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADAF.f90
2262 lines (1776 loc) · 57.5 KB
/
ADAF.f90
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
module constant
implicit none
real*8,parameter :: pi=3.14159265d0
real*8,parameter :: c=3.d10
real*8,parameter :: h=6.62606896d-27
real*8,parameter :: pc=3.08d18
real*8,parameter :: M_sun=1.989d33
real*8,parameter :: G=6.672d-8
real*8,parameter :: m_H=1.673d-24
real*8,parameter :: m_p=1.673d-24
real*8,parameter :: sigma_t=6.652d-25
real*8,parameter :: sigma_SB = 5.67d-5
real*8,parameter :: e=4.8032d-10
real*8,parameter :: m_e=9.11d-28
real*8,parameter :: alpha_f=1./137.
real*8,parameter :: yr=3.15d7
real*8,parameter :: kpc=1000.*pc
real*8,parameter :: km=100000.
real*8,parameter :: k_bol=1.381d-16
end module constant
module vars_bh
use constant
implicit none
real*8 :: mm_bh=1.d8
real*8 :: mm_dot=1.d-5
real*8 :: M_bh,M_dot
real*8 :: r_g,r_sch
real*8 :: M_dot_edd
end module vars_bh
module vars_ADAF
use constant
use vars_bh
implicit none
real*8 :: alpha=0.1
real*8 :: beta=0.5
real*8 :: gamma=5./3.
real*8 :: mu_i=1.23
real*8 :: mu_e=1.14
real*8 :: T_i,T_e
real*8 :: theta_i
real*8 :: theta_e
real*8 :: sigma,w_i,w_e,n_i,n_e
! real*8 :: r
real*8 :: W,cs,P_ADAF
real*8 :: sonic_jump
real*8 :: sonic_crit
real*8 :: l_in
real*8 :: omega
! real*8 ::
end module vars_adaf
module vars_clouds
use constant
use vars_bh
implicit none
real*8 :: sigma_cl,v_r_cl,v_phi_cl
real*8 :: k_c_cl=0.
real*8 :: k_c_term=0.
real*8 :: cloud_1=0.
real*8 :: cloud_2=0.
real*8 :: cloud_3=0.
!
real*8 :: v_r_2
real*8 :: mass_ratio = 1.
real*8 :: mass_ratio_factor = 1.!2.
real*8 :: M_cl = 4.d23
real*8 :: R_cl = 0.!5.d10
real*8 :: R_cl_out = 1.d12
real*8 :: cloud_size_index = 0.5
real*8 :: T_cl = 1.d4
real*8 :: tao_cl,R_cl_max,R_cl_min, n_cl,qq_cl
real*8 :: rr_tidal
real*8 :: gamma_phi= 0.!-1.d-2
real*8 :: gamma_R = 0.!1.d-2
real*8 :: det_VR2 = 0.
real*8 :: det_VPhi2 = 0.
real*8 :: v_phi_ratio_v_R = 0.
end module vars_clouds
module vars_boundary
implicit none
real*8 :: Omega_boundary_factor = 0.8
real*8 :: T_out_factor = 0.1
end module vars_boundary
subroutine ADAF_solve()
use constant
use vars_bh
use vars_adaf
use vars_clouds
implicit none
real*8 :: a2,a3,a4,a5,a6,b21,b31,b32,b41,b42,b43,b51,b52,b53,b54,&
b61,b62,b63,b64,b65,c1,c2,c3,c4,c5,c6,dc1,dc2,dc3,dc4,dc5,dc6
parameter(a2=0.2d0,a3=0.3d0,a4=0.6d0,a5=1.0d0&
,a6=0.875d0,b21=0.2d0,b31=0.075d0,b32=0.225d0&
,b41=0.3d0,b42=-0.9d0, b43=1.2d0&
,b51=-11.0d0/54.0d0,b52=2.5d0,b53=-70.0d0/27.0d0&
,b54=35.0d0/27.0d0,b61=1631.0d0/55296.0d0&
,b62=175.0d0/512.0d0,b63=575.0d0/13824.0d0&
,b64=44275.0d0/110592.0d0,b65=253.0d0/4096.0d0,&
c1=37.0d0/378.0d0,c2=0.0d0,c3=250.0d0/621.0d0,&
c4=125.0d0/594.0d0,c5=0.0d0,c6=512.0d0/1771.0d0,&
dc1=c1-2825.0d0/27648.0d0,dc2=0.0d0,&
dc3=c3-18575.0d0/48384.0d0,dc4=c4-13525.0d0/55296.0d0,&
dc5=-277.0d0/14336.0d0,dc6=c6-0.25d0)
real*8 safety,pgrow,pshrnk,errcon,eacc_test
parameter(safety=0.9d0,pgrow=-0.20d0,pshrnk=-0.25d0,errcon=1.89d-4,&
eacc_test=1.0d-5)
integer,parameter :: N_step=50000000
integer :: i_test,i_test_0,i_mu,i,j
real*8 :: k1(3),k2(3),k3(3),k4(3),k5(3),k6(3)
real*8 :: x_now,wip,wep,sigp,sig(N_step),wi(N_step),we(N_step)
real*8 :: y1_0,y2_0,y3_0
real*8 :: x_test_0,x_test,y_test_0(3),y_test(3),yerr_test(3),df_test(3),&
k1_test(3),k2_test(3),k3_test(3),k4_test(3),k5_test(3),k6_test(3),&
h_step_test,df0_test(3)
real*8 :: x_in,x_out,y_in(3),y(3)
real*8 :: errmax_test,htemp_test
real*8 :: drstep_max=5.d-3
real*8 :: drstep_min=1.d-9
real*8 :: ww_i,ww_e,ssigma,rr
real*8 :: W_i_gas,W_e_gas,W_gas,sigma_gas,r
real*8 :: v_r,c_s
real*8 :: dim_W,dim_sigma,dim_l_in,dim_Q,dim_omega
real*8 :: SIGMA_GAS_0,SSIGMA_0,W_I_GAS_0,WW_I_0,W_E_GAS_0,WW_E_0,DSIGMA_DR,F_R,F_PHI,V_PHI_2,V_R_2_0
real*8 :: omega_0,x_last
! integer :: stat,error_allocate=0
integer*8,parameter :: N_radius = 1900
real*8 :: flux(200,N_radius),r_array(N_radius),tau_e_array(N_radius),T_e_array(N_radius)
real*8 :: sigma_array(N_radius),W_i_array(N_radius),W_e_array(N_radius)
real*8 :: mu(200),f_r_mu(N_radius,100),r_test(N_radius-1)!,f_mu(200)
real*8,external :: height,omega_k,integ_for_q,YITA_COMPTON,flux_nu,flux_nu_syn,flux_nu_bre
open(unit=21,file='r_sigma_W_i_W_e.txt')
!
! sigma_array=999.
! W_i_array=999.
! W_e_array=999.
!
!
! write(*,*)r
! stop
!
open(unit=35,file='./spec/nu.txt')
do i =1,200,1
read(35,*)mu(i)
end do
close(35)
dim_W=M_dot_edd*c/r_sch
dim_sigma=M_dot_edd/c/r_sch
dim_omega=c/r_sch
dim_l_in=c*r_sch
dim_Q=M_dot_edd*c*c/r_sch/r_sch
call INITIALIZATION_func(x_in,x_out,y_in)
!
open(unit=39,file='./spec/r_array.txt')
open(unit = 58, file= 'spec_r_mu.txt')
write(*,*)x_in,'x_out=',exp(x_out),y_in
! write(*,*)'x_out=',exp(x_in)
! stop
x_now=x_in
h_step_test=(x_out-x_now)/N_step
sig(1)=y_in(1)
wi(1)=y_in(2)
we(1)=y_in(3)
ssigma_0 = sig(1)
ww_i_0 = wi(1)
ww_e_0 = we(1)
v_R_2_0 = (M_dot/2./pi/ssigma_0/dim_sigma/exp(x_in)/r_sch)**2.
sigma_gas = ssigma_0*dim_sigma
W_i_gas = ww_i_0*dim_W
W_e_gas = ww_e_0*dim_W
W_gas=(W_i_gas+W_e_gas)/beta
omega_0 = l_in/(exp(x_in)*r_sch)**2.+2.*pi*(alpha/mass_ratio_factor)*W_gas/M_dot
write(*,*)'omega_ratio',omega_0/omega_k(exp(x_in)*r_sch)
! stop
x_last = x_in
do i_test=2,N_step,1
!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!!
!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!!
!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!!
!!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!! !!!!!!!!!!
i_test_0=i_test-1
40 sigp=sig(i_test_0)
wip=wi(i_test_0)
wep=we(i_test_0)
x_test_0=x_now
y_test_0(1)=sigp
y_test_0(2)=wip
y_test_0(3)=wep
call deriva_test(df_test,x_test_0,y_test_0)
k1_test=h_step_test*df_test
x_test=x_test_0+a2*h_step_test
y_test=y_test_0+b21*k1_test
x_now=x_test
sigp=y_test(1)
wip=y_test(2)
wep=y_test(3)
call deriva_test(df_test,x_test,y_test)
k2_test=h_step_test*df_test
x_test=x_test_0+a3*h_step_test
y_test=y_test_0+b31*k1+b32*k2
x_now=x_test
sigp=y_test(1)
wip=y_test(2)
wep=y_test(3)
call deriva_test(df_test,x_test,y_test)
k3_test=h_step_test*df_test
x_test=x_test_0+a4*h_step_test
y_test=y_test_0+b41*k1_test+b42*k2_test+b43*k3_test
x_now=x_test
sigp=y_test(1)
wip=y_test(2)
wep=y_test(3)
call deriva_test(df_test,x_test,y_test)
k4_test=h_step_test*df_test
x_test=x_test_0+a5*h_step_test
y_test=y_test_0+b51*k1_test+b52*k2_test+b53*k3_test+b54*k4_test
x_now=x_test
sigp=y_test(1)
wip=y_test(2)
wep=y_test(3)
call deriva_test(df_test,x_test,y_test)
k5_test=h_step_test*df_test
x_test=x_test_0+a6*h_step_test
y_test=y_test_0+b61*k1_test+b62*k2_test+b63*k3_test+b64*k4_test+b65*k5_test
x_now=x_test
sigp=y_test(1)
wip=y_test(2)
wep=y_test(3)
call deriva_test(df_test,x_test,y_test)
k6_test=h_step_test*df_test
y_test=c1*k1_test+c3*k3_test+c4*k4_test+c6*k6_test
df0_test=y_test/h_step_test
yerr_test=dc1*k1_test+dc3*k3_test+dc4*k4_test+dc5*k5_test+dc6*k6_test
errmax_test=0.d0
errmax_test=max(dabs(yerr_test(1)),dabs(yerr_test(2)))
errmax_test=max(errmax_test,dabs(yerr_test(3)))
errmax_test=errmax_test/eacc_test
! write(*,*)x_test,y_test,errmax_test,yerr_test
!stop
if(errmax_test.gt.1.0d0)then
htemp_test=safety*h_step_test*(errmax_test**pshrnk)/10.0
htemp_test=sign(max(dabs(htemp_test),0.1*dabs(h_step_test)),h_step_test)
if(dabs(htemp_test).lt.drstep_min)then
write(*,*)'hstep underflow'
htemp_test=-drstep_min
stop
end if
h_step_test=htemp_test
write(*,*)'goto 40'
goto 40
else
if(errmax_test.gt.errcon)then
htemp_test=safety*h_step_test*(errmax_test**pgrow)
else
htemp_test=5.0*h_step_test
end if
if(dabs(htemp_test).gt.drstep_max)then
htemp_test=-drstep_max
end if
x_test=x_test_0+h_step_test
sig(i_test)=sig(i_test_0)+y_test(1)
wi(i_test)=wi(i_test_0)+y_test(2)
we(i_test)=we(i_test_0)+y_test(3)
x_now = x_test
! sigp = y_test(1)
! wip = y_test(2)
! wep = y_test(3)
rr=exp(x_test)
ssigma=sig(i_test)
ww_i=wi(i_test)
ww_e=we(i_test)
r=rr*r_sch
sigma_gas = ssigma*dim_sigma
W_i_gas = ww_i*dim_W
W_e_gas = ww_e*dim_W
W_gas=(W_i_gas+W_e_gas)/beta
T_i=W_i_gas*mu_i*m_p/sigma_gas/k_bol
T_e=W_e_gas*mu_e*m_p/sigma_gas/k_bol
v_r=-M_dot/2./pi/sigma_gas/r
c_s=sqrt((3.0*gamma-1.0+2.0*(gamma-1.0)*alpha*alpha)/(gamma+1.0)*W_gas/sigma_gas )
if(-v_r/c_s>sonic_crit .and. - v_r/c_s<(2.-sonic_crit))then
! pause
write(*,*)'sony'!,x_test,x_test_0,i_test,h_step_test
! write(*,*) sig(i_test),sig(i_test_0),df0_test(1),(h_step_test*10.)
! pause
! call crosssonic(i_test_0,df0_test,-1.5d-1)
! stop
x_test = x_test_0-sonic_jump
sig(i_test) = sig(i_test_0)+df0_test(1)*(-sonic_jump)
wi(i_test) = wi(i_test_0)+df0_test(2)*(-sonic_jump)
we(i_test) = we(i_test_0)+df0_test(3)*(-sonic_jump)
rr=exp(x_test)
ssigma=sig(i_test)
ww_i=wi(i_test)
ww_e=we(i_test)
r=rr*r_sch
sigma_gas = ssigma*dim_sigma
W_i_gas = ww_i*dim_W
W_e_gas = ww_e*dim_W
W_gas=(W_i_gas+W_e_gas)/beta
T_i=W_i_gas*mu_i*m_p/sigma_gas/k_bol
T_e=W_e_gas*mu_e*m_p/sigma_gas/k_bol
v_r=-M_dot/2./pi/sigma_gas/r
c_s=sqrt( ((3.0*gamma-1.0+2.0*(gamma-1.0)*alpha*alpha)/(gamma+1.0))*W_gas/sigma_gas )
x_now = x_test
end if
write(11,*)log10(exp(x_test)),log10(sigma_gas)
write(12,*)log10(exp(x_test)),W_i_gas
write(13,*)log10(exp(x_test)),W_e_gas
sigma_array(i_test-1) = sigma_gas
W_i_array(i_test-1) = W_i_gas
W_e_array(i_test-1) = W_e_gas
write(21,*)exp(x_test)*r_sch,sigma_gas,W_i_gas,W_e_gas
write(14,*)log10(exp(x_test)),log10(T_i),log10(T_e)
! stop
write(15,*)log10(exp(x_test)),log10(-v_r/c),log10(c_s/c)
write(16,*)log10(exp(x_test)),height(exp(x_test)*r_sch,ssigma*dim_sigma,ww_i*dim_W,ww_e*dim_W)/r,&
sigma_gas*sigma_T/m_p
omega=l_in/r**2.+2.*pi*(alpha/mass_ratio_factor)*W_gas/M_dot+2.*pi*cloud_1/r**2./M_dot
write(17,*)log10(exp(x_test)),log10(omega*exp(x_test)*r_sch/c),log10(omega_k(exp(x_test)*r_sch)*exp(x_test)*r_sch/c)
write(18,*)log10(exp(x_test)),-v_r/c_s
! tao_cl = 500.
P_ADAF = W_gas/height(exp(x_test)*r_sch,ssigma*dim_sigma,ww_i*dim_W,ww_e*dim_W)/sqrt(2.*pi)
R_cl_max = 4.4d10*(mm_bh/1.d8)*(T_cl/1.d4)**0.5*(rr/10.)**1.5*2.
R_cl_max = sqrt(4*pi**2.*(rr*r_sch)**3.*k_bol*T_cl/G/M_bh/m_p)
R_cl_min = (5.4**(T_e/1.d10)**3.5/8./(P_ADAF/k_bol/T_cl/1.d14)**2.)**0.5*1.d10
n_cl = P_ADAF/k_bol/T_cl
qq_cl = ((sqrt(8./pi))*sigma_gas*det_VR2**(3./2.)*f_R - (sqrt(8./pi))*sigma_gas*det_VPhi2**(3./2.)*f_phi) &
/height(exp(x_test)*r_sch,ssigma*dim_sigma,ww_i*dim_W,ww_e*dim_W)
M_cl = (P_ADAF/k_bol/T_cl)*m_p*(4.*pi/3.)*R_cl**3.
tao_cl = (P_ADAF/k_bol/T_cl)*sigma_T*R_cl
! R_cl = (R_cl_max*R_cl_min)**0.5
R_cl = (5.4d8*(T_e/1.d10)**3.5/(-1.d-26*n_cl*(1.-n_cl*(1.d7)*exp(-118400./(T_cl+1.d3))+1.4d-2*sqrt(T_cl)*exp(-92./T_cl))))**0.5*1.d10
R_cl = R_cl_out*(rr/1.d3)**(cloud_size_index)
rr_tidal = (G*M_bh*m_p*R_cl**2./3./k_bol/T_cl)**(1./3.)/r_sch
write(19,'(F8.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3,ES17.3)')(exp(x_test)),&!log10(exp(x_test)),&
(P_ADAF/k_bol/T_cl)*m_p*(4.*pi/3.)*R_cl**3.,&
(P_ADAF/k_bol/T_cl)*sigma_T*R_cl,&
8.d8*(P_ADAF/k_bol/T_cl/1.d14)**2.,& ! lambda_line cooling rate erg/s/cm3
5.4d8*(T_e/1.d10)**3.5/(R_cl/1.d10)**2.,& ! Heating rate erg/s/cm3
R_cl_max/r_sch,& ! Rcl max
R_cl_min/r_sch,& ! Rcl min
(P_ADAF/k_bol/T_cl)*sigma_T*R_cl_max*2.,& ! tao_max
(P_ADAF/k_bol/T_cl)*sigma_T*R_cl_min*2.,& ! tao_min
(P_ADAF/k_bol/T_cl)*sigma_T*(R_cl_max*R_cl_min)**0.5,&
sigma_SB*T_cl**4.*(n_cl*sigma_T),&
qq_cl,&
(5.4d8*(T_e/1.d10)**3.5/(sigma_SB*T_cl**4.*n_cl*sigma_T + 8.8d8*(P_ADAF/k_bol/T_cl/1.d14)**2.*(T_cl/1.d4)**(-1.3)))**0.5*1.d10,&
n_cl*sigma_T*(5.4d8*(T_e/1.d10)**3.5/(sigma_SB*T_cl**4.*n_cl*sigma_T + 8.8d8*(P_ADAF/k_bol/T_cl/1.d14)**2.*(T_cl/1.d4)**(-1.3)))**0.5*1.d10,&
n_cl*sigma_T*R_cl,&
3.3d16*((T_e/1.d8)**(7./4.)/(P_ADAF/1.d-2)/10.),&
(G*M_bh*m_p*R_cl_max**2./4./pi/k_bol/T_cl)**(1./3.)/r_sch,&
8.*(R_cl_max/1.d11)**(2./3.),&
sqrt(4.*pi*k_bol*T_cl*(rr*r_sch)**3./G/M_bh/m_p)/r_sch,&
R_cl/r_sch,&
R_cl_out*(rr/1.d3)**(0.9)/r_sch,&
n_cl*sigma_T*R_cl,&
n_cl*sigma_T*R_cl_out*(rr/1.d3)**(0.9),&
rr_tidal
if ((G*M_bh*m_p*R_cl_max**2./4./pi/k_bol/T_cl)**(1./3.)/r_sch > exp(x_test))then
! stop
end if
if(R_cl_max< 1.d12)then
write(52,*) log10(exp(x_test)), R_cl_max, (P_ADAF/k_bol/T_cl)*sigma_T*R_cl_max
tao_cl = (P_ADAF/k_bol/T_cl)*sigma_T*R_cl_max
else
write(52,*) log10(exp(x_test)), 1.d12, (P_ADAF/k_bol/T_cl)*sigma_T*1.d12
tao_cl = (P_ADAF/k_bol/T_cl)*sigma_T*1.d12
end if
! if (W_i_gas/height(exp(x_test)*r_sch,ssigma*dim_sigma,ww_i*dim_W,ww_e*dim_W)/sqrt(2.*pi)<G*M_bh*(m_p/sigma_T)*tao_cl*R_cl/4./pi/r**3.)then
! write(*,*)exp(x_test)
! stop
! end if
!,(sigma_gas)/m_p*k_bol*T_i
! p_ADAF = (sigma_gas/height(exp(x_test)*r_sch,ssigma*dim_sigma,ww_i*dim_W,ww_e*dim_W))/m_p*k_bol*T_i
write(*,*) -v_r/c_s,i_test,log10(exp(x_test))
h_step_test=htemp_test
end if
sigma_gas_0 = ssigma_0*dim_sigma
W_i_gas_0 = ww_i_0*dim_W
W_e_gas_0 = ww_e_0*dim_W
! W_gas_0=(W_i_gas_0+W_e_gas_0)/beta
!
! T_i_0=W_i_gas_0*mu_i*m_p/sigma_gas_0/k_bol
! T_e_0=W_e_gas_0*mu_e*m_p/sigma_gas_0/k_bol
!
! v_r_0=M_dot/2./pi/sigma_gas_0/r
! c_s_0=sqrt((3.0*gamma-1.0+2.0*(gamma-1.0)*alpha*alpha)/(gamma+1.0)*W_gas_0/sigma_gas_0 )
!
dsigma_dR = (sigma_gas-sigma_gas_0)/(x_test-x_last)/exp(x_test)/r_sch
!
! l
f_R = gamma_R/r_sch
f_phi = gamma_phi/r_sch
v_phi_2 = (omega*r)**2.+v_r*(2.*r*omega + r**2.*(omega-omega_0)/(x_test-x_last)/exp(x_test)/r_sch)/r/f_phi
! write(*,*)v_phi_2, h_step_test,dsigma_dR
if(-v_r/c_s>sonic_crit .and. - v_r/c_s<(2.-sonic_crit))then
v_R_2 = v_R_2_0 + r_sch*exp(x_test)*(-sonic_jump)*(&
- v_R_2_0*dsigma_dR/sigma_gas - v_R_2_0/r+f_R*(v_R_2_0) + v_phi_2/R - G*M_bh/R/R - f_R*(M_dot/2./pi/sigma_gas/r)**2.)
else
v_R_2 = v_R_2_0 + r_sch*exp(x_test)*(x_test-x_last)*(&
- v_R_2_0*dsigma_dR/sigma_gas - v_R_2_0/r+f_R*(v_R_2_0) + v_phi_2/R - G*M_bh/R/R - f_R*(M_dot/2./pi/sigma_gas/r)**2.)
end if
det_VR2 = v_R_2 - v_r**2.
det_VPhi2 = v_phi_2 - (r*omega)**2.
v_phi_ratio_v_R = -r*omega/v_r
write(30,'(es17.7,es17.7,es17.7,es17.7,es17.7,es17.7,es17.7,es17.7)')&
v_R_2,dsigma_dR,-v_R_2_0*dsigma_dR/sigma_gas, v_R_2_0/r,f_R*(v_R_2_0),v_phi_2/R, G*M_bh/R/R ,f_R*(M_dot/2./pi/sigma_gas/r)**2.
write(31,*)log10(exp(x_test)), log10(v_R_2**0.5/c), log10(v_phi_2**0.5/c)
write(32,*)log10(exp(x_test)), omega,((omega-omega_0)/h_step_test/exp(x_test))!dsigma_dR
write(33,*)log10(r/r_sch),log10(v_phi_2/c/c),log10(v_R_2/c/c)
write(34,*)log10(exp(x_test)),h_step_test,-(x_test-x_last)
write(51,'(F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7,F17.7)')&
log10(exp(x_test)),log10(sigma_gas),log10(W_i_gas),log10(W_e_gas),&
log10(T_i),log10(T_e),log10(-v_r/c),log10(c_s/c),log10(omega*r/c),log10(omega_k(r)*r/c),&
log10(v_R_2**0.5/c), log10(v_phi_2**0.5/c)
! if(exp(x_test).le.8.)then
if(x_test.le.x_out)then
write(*,*)'x.le.x_in',i_test
exit
! else
! if(error_allocate .eq. 0)then
! allocate(ssigma_array(i_test),stat=error_allocate)
! ssigma_array(i_test) = sigma_gas/dim_sigma
! write(*,*)ssigma_array(i_test)
! end if
end if
ssigma_0 = ssigma
ww_i_0 = ww_i
ww_e_0 = ww_e
v_R_2_0 = v_R_2
omega_0 = omega
x_last = x_test
r_test(i_test-1) = r
!do i_mu = 1, 100
! mu = 10.**(9. + i_mu*(22. - 9.)/100.)
! f_r_mu(i_test,i_mu) = integ_for_q(mu,r,sigma_gas,W_i_gas,W_e_gas)/2./yita_compton(mu,r,sigma_gas,W_i_gas,W_e_gas)
! write(58,*) r_test(i_test-1), mu, f_r_mu(i_test,i_mu)
!end do
r_array(i_test-1)=r
T_e_array(i_test-1)=T_e
tau_e_array(i_test-1)=sigma_gas*sigma_t/m_p
do i=1,200,1
flux(i,i_test-1)=flux_nu(mu(i),r,sigma_gas,W_i_gas,W_e_gas)
end do
end do
close(58)
close(21)
! write(*,*)f_r_mu
! f_mu = 0.
!do i_mu = 1,100
! do i_test = 2,1358
! f_mu(i_mu) = f_mu(i_mu) + f_r_mu(i_test,i_mu)*2.*pi*r_test(i_test)*(-1)*(r_test(i_test)-r_test(i_test-1))
! write(23,*)r_test(i_test),r_test(i_test)-r_test(i_test-1),2.*pi*r_test(i_test)*(-1)*(r_test(i_test)-r_test(i_test-1))
! end do
! write(21,*)10.**(9. + i_mu*(22. - 9.)/100.), f_mu(i_mu)!*10.**(9. + i_mu*(22. - 9.)/100.)
!end do
do i=1,N_radius-1,1
if(mod(i,10) .eq. 1)then
write(39,*)r_array(i)
end if
end do
open(unit=34,file='spec_input.txt')
do j=1,N_radius-1,1
if(mod(j,10) .eq. 1)then
do i=1,200,1
write(34,*)T_e_array(j),tau_e_array(j),flux(i,j)
end do
end if
end do
close(34)
end subroutine ADAF_solve
function beta_gamma(gamma_factor)
implicit none
real*8 :: beta_gamma,gamma_factor
beta_gamma = 1.-1./gamma_factor**2.
return
end function beta_gamma
subroutine test_omega_integ()
implicit none
real*8 :: omega_incoming, gamma_factor,omega_ave,omega_ave_2,R_omega_gamma
omega_incoming = 20901553236.7367
gamma_factor = 1.35043649799882
call omega_integ(omega_incoming, gamma_factor,omega_ave,omega_ave_2,R_omega_gamma)
write(*,*)omega_ave,omega_ave_2,R_omega_gamma
! stop
return
end subroutine test_omega_integ
subroutine omega_integ(omega_incoming, gamma_factor,omega_ave,omega_ave_2,R_omega_gamma)
use constant
implicit none
integer*8,parameter :: n = 100
integer*8 :: i_mu,i
real*8 :: xx(n),ww(n)
real*8 :: omega_incoming,omega_ave,gamma_factor,omega_alpha_2
real*8 :: BETA_GAMMA,R_omega_gamma,R_alpha,omega_mean,omega_mean_2,omega_ave_2
real*8 :: x1,x2,mu,omega_alpha,alpha,x,xp_over_x,d_sigma_d_alpha,P_mu_alpha_omega_gamma
beta_gamma = sqrt(1.-1./gamma_factor**2.)
x1=-1.
x2=+1.
call gauleg(x1,x2,xx,ww,n)
omega_ave = 0.
omega_ave_2 = 0.
R_omega_gamma = 0.
do i_mu = 1,n,1
mu = xx(i_mu)
omega_alpha = 0.
omega_alpha_2 = 0.
R_alpha = 0.
do i = 1,n,1
alpha = xx(i)
x = gamma_factor*omega_incoming*(1.-beta_gamma*mu)
xp_over_x = 1./(1.+(1.-alpha)*x)
d_sigma_d_alpha = (3./8.)*sigma_T*(xp_over_x**2.)*(1./xp_over_x+xp_over_x-1.+alpha**2.)
P_mu_alpha_omega_gamma = c*(1.-beta_gamma*mu)*d_sigma_d_alpha
omega_mean = gamma_factor*omega_incoming*(gamma_factor*(1.-beta_gamma*mu) + gamma_factor*beta_gamma*alpha*(mu - beta_gamma))*xp_over_x
omega_mean_2 = gamma_factor*omega_incoming**2.&
*((gamma_factor*(1.-beta_gamma*mu)+gamma_factor*beta_gamma*alpha*(mu-beta_gamma))**2.+ 0.5*beta_gamma**2.*(1.-alpha**2.)*(1.-beta_gamma**2.))&
/(1.+gamma_factor*(1.-beta_gamma*mu)*(1-alpha)*omega_incoming)**2.
omega_alpha = omega_alpha + ww(i)*omega_mean * d_sigma_d_alpha
omega_alpha_2 = omega_alpha_2 + ww(i)*omega_mean_2 * d_sigma_d_alpha
R_alpha = R_alpha + ww(i)*d_sigma_d_alpha
end do
omega_ave = omega_ave + ww(i_mu)*omega_alpha*(1-beta_gamma*mu)*c/2.
omega_ave_2 = omega_ave_2 + ww(i_mu)*omega_alpha_2*(1-beta_gamma*mu)*c/2.
R_omega_gamma = R_omega_gamma + ww(i_mu)*R_alpha*(1-beta_gamma*mu)*c/2.
end do
omega_ave = omega_ave/R_omega_gamma
omega_ave_2 = omega_ave_2/R_omega_gamma
! call gauleg(x1,x2,xx,ww,n)
! result=0.
! do i=1,n,1
! result=result+ww(i)*func(xx(i))
! end do
return
end subroutine omega_integ
subroutine n_omega_in_out()
use constant
implicit none
integer*8,parameter :: n = 100
integer*8 :: i_omega,i_gamma
real*8 :: xx_gamma(n),ww_gamma(n),xx_omega(n),ww_omega(n),x1,x2
real*8 :: omega_out,f_mu_out,omega_int,f_mu_alpha,gamma_factor
real*8 :: omega_ave,R_omega_gamma,P_omega_omega_gamma
real*8 :: delta_omega_2,omega_ave_2,D_omega_omega,beta_gamma
real*8 :: omega_min,omega_max,theta_e
real*8 :: T_e
real*8,external :: BESSK,f_mu_input
! T_i=W_i_in*mu_i*m_p/k_bol/sigma_in
! T_e=W_e_in*mu_e*m_p/k_bol/sigma_in
! theta_i=k_bol*T_i/m_p/c/c
T_e = 10.**9.6
theta_e=k_bol*T_e/m_e/c/c
! n_e=sigma_in/sqrt(2.*pi)/Height(r,sigma_in,W_i_in,W_e_in)/m_p/mu_e
! n_i=sigma_in/sqrt(2.*pi)/Height(r,sigma_in,W_i_in,W_e_in)/m_p/mu_i
omega_min = 0.
omega_out = 10.**10.
write(*,*)'n_omega_in_out',omega_out,f_mu_out
! write(*,*)omega_out
x1=20.7233
x2=50.6569
call gauleg(x1,x2,xx_omega,ww_omega,n)
omega_min = exp(x1)
omega_max = exp(x2)
x1=dlog10(1.001d0)
x2=dlog10(50.0d0)
call gauleg(x1,x2,xx_gamma,ww_gamma,n)
f_mu_out = 0.
do i_omega = 1, n,1
omega_int = exp(xx_omega(i_omega))
f_mu_alpha = 0.
do i_gamma = 1, n,1
gamma_factor = exp(xx_gamma(i_gamma))
beta_gamma = sqrt(1.-1./gamma_factor**2.)
write(*,*)omega_int
call omega_integ(omega_int,gamma_factor,omega_ave,omega_ave_2,R_omega_gamma)
write(*,*)'omega_int',omega_int,gamma_factor,omega_ave,omega_ave_2,R_omega_gamma
call test_omega_integ(omega_int,gamma_factor)
! stop
delta_omega_2=omega_ave_2 - omega_ave**2.
if((sqrt(3.*delta_omega_2) < (omega_ave - omega_min)) .and. (sqrt(3.*delta_omega_2) < (omega_max - omega_ave)))then
D_omega_omega = sqrt(3.*delta_omega_2)
else if ((omega_ave - omega_min) < (sqrt(3.*delta_omega_2))&
.and.&
(omega_ave - omega_min) < (omega_max - omega_ave))then
D_omega_omega = (omega_ave - omega_min)
else
D_omega_omega = (omega_max - omega_ave)
end if
if(D_omega_omega > abs(omega_out - omega_ave))then
P_omega_omega_gamma = 1./2./D_omega_omega
else
P_omega_omega_gamma = 0.
end if
write(*,*)D_omega_omega,P_omega_omega_gamma
f_mu_alpha = f_mu_alpha + ww_gamma(i_gamma)*P_omega_omega_gamma*(R_omega_gamma/c/sigma_T)&
*(gamma_factor**2.*beta_gamma*exp(-gamma_factor/theta_e)/theta_e/bessk(2,1/theta_e))&
*(f_mu_input(omega_int)/h/omega_int)*omega_int*gamma_factor
write(*,*)'f_mu_input', ww_gamma(i_gamma),P_omega_omega_gamma*(R_omega_gamma/c/sigma_T)&
*(gamma_factor**2.*beta_gamma*exp(-gamma_factor/theta_e)/theta_e/bessk(2,1/theta_e))&
*(f_mu_input(omega_int)/h/omega_int)*omega_int*gamma_factor
end do
! stop
f_mu_out = f_mu_out + ww_omega(i_omega)*f_mu_alpha
end do
f_mu_out = f_mu_out!*(log(10.)**2.)*(10.**(-0.8)/m_p)*(0.5*1.d15)*sigma_T
write(*,*)'n_omega_in_out',omega_out,f_mu_out
return
end subroutine n_omega_in_out
function f_mu_input(omega_int)
implicit none
real*8 :: f_mu_input,omega_int
f_mu_input = 1.d40
return
end function f_mu_input
program none
implicit none
call INITIALIZATION_bh()
call INITIALIZATION_clouds()
! call test_omega_integ()
! call n_omega_in_out()
! stop
call ADAF_solve()
! call n_omega_in_out()
! call cloud_solve()
end program none
subroutine cloud_solve()
use constant
use vars_bh
use vars_adaf
use vars_clouds
implicit none
call interpolation()
return
end subroutine cloud_solve
subroutine interpolation()
use constant
use vars_bh
use vars_adaf
use vars_clouds
implicit none
!write(*,*)sigma_array
!write(*,*)W_i_array
!write(*,*)W_e_array
return
end subroutine interpolation
subroutine deriva_test(df_test,x_test,y_test)
use constant
use vars_bh
use vars_adaf
implicit none
real*8 :: x_test,y_test(3),df_test(3)
real*8 :: coefficient_a(3,3),coefficient_c(3)
real*8 :: W_i_in,W_e_in,sigma_in,r
! write(*,*)'derivs',exp(x),y
! stop
r=exp(x_test)*r_sch
sigma_in=y_test(1)*M_dot_edd/c/r_sch
W_i_in=y_test(2)*M_dot_edd*c/r_sch
W_e_in=y_test(3)*M_dot_edd*c/r_sch
call coefficient(r,sigma_in,W_i_in,W_e_in,coefficient_a,coefficient_c)
call tri_linear(coefficient_a,df_test,coefficient_c)
return
end subroutine deriva_test
subroutine derivs(x,y,dydx)
use constant
use vars_bh
use vars_adaf
implicit none
real*8 :: x,y(3),dydx(3)
real*8 :: coefficient_a(3,3),coefficient_c(3)
real*8 :: W_i_in,W_e_in,sigma_in,r
! write(*,*)'derivs',exp(x),y
! stop
r=exp(x)*r_sch
sigma_in=y(1)*M_dot_edd/c/r_sch
W_i_in=y(2)*M_dot_edd*c/r_sch
W_e_in=y(3)*M_dot_edd*c/r_sch
call coefficient(r,sigma_in,W_i_in,W_e_in,coefficient_a,coefficient_c)
call tri_linear(coefficient_a,dydx,coefficient_c)
return
end subroutine derivs
subroutine coefficient(r,sigma_in,W_i_in,W_e_in,coefficient_a,coefficient_c)
use constant
use vars_bh
use vars_adaf
use vars_clouds
implicit none
real*8 :: coefficient_a(3,3)
real*8 :: coefficient_c(3)
real*8 :: W_in,W_i_in,W_e_in,sigma_in,r,rr
real*8 :: ww_i,ww_e,ww,ssigma,x,ll_in,oomega,oomega_k,qq_rad,llambda_ie,ddlogomegakdr,f_R,f_phi
real*8 :: dim_W,dim_sigma,dim_l_in,dim_Q,dim_omega
real*8,external :: q_rad,lambda_ie,omega_k,dlogomegakdr,height
f_R = gamma_R/r_sch
f_phi = gamma_phi/r_sch
! initialization
! l_in, Omega, Omega_k, dlnomega_kdr
! qrad, lambda_ie
!
W_in=(W_i_in+W_e_in)/beta
! dimensionless
omega=l_in/r**2.+2.*pi*(alpha/mass_ratio_factor)*W_in/M_dot!+2.*pi*cloud_1/r**2./M_dot
dim_W=M_dot_edd*c/r_sch
dim_sigma=M_dot_edd/c/r_sch
dim_omega=c/r_sch
dim_l_in=c*r_sch
dim_Q=M_dot_edd*c*c/r_sch/r_sch
! write(*,*)'coeffecient: sigma_in,W_i_in,W_e_in',sigma_in,W_i_in,W_e_in
ww_i=W_i_in/dim_W
ww_e=W_e_in/dim_W
ww=W_in/dim_W
ssigma=sigma_in/dim_sigma
ll_in=l_in/dim_l_in
rr=r/r_sch
oomega=omega/dim_omega
! write(*,*)'omega',omega
oomega_k=omega_k(r)/dim_omega
qq_rad=q_rad(r,sigma_in,W_i_in,W_e_in)/dim_Q
T_i=W_i_in*mu_i*m_p/sigma_in/k_bol
T_e=W_e_in*mu_e*m_p/sigma_in/k_bol
llambda_ie=lambda_ie(r,sigma_in,W_i_in,W_e_in)/dim_Q
ddlogomegakdr=dlogomegakdr(r)*r_sch
! write(*,*)'coeffecient:q',dim_Q,qq_rad,llambda_ie
! stop
x=log(rr)
coefficient_a(1,1)=-mm_dot**2./4./pi**2./exp(3.*x)/ssigma**2.
coefficient_a(1,2)=1./beta/exp(x)
coefficient_a(1,3)=1./beta/exp(x)
coefficient_a(2,1)=-ww_i*mm_dot*(3.*gamma-1.)/ssigma**2./exp(x)/2./(gamma-1.)
coefficient_a(2,2)=mm_dot*(gamma+1.)/ssigma/exp(x)/2./(gamma-1.)&
-2.*pi*exp(x)*alpha**2.*ww*2.*pi/mm_dot/beta/mass_ratio_factor
coefficient_a(2,3)=-2.*pi*exp(x)*alpha**2.*ww*2.*pi/mm_dot/beta/mass_ratio_factor
coefficient_a(3,1)=-ww_e*mm_dot*(3.*gamma-1.)/ssigma**2./exp(x)/2./(gamma-1.)
coefficient_a(3,2)=0.
coefficient_a(3,3)=mm_dot*(gamma+1.)/ssigma/exp(x)/2./(gamma-1.)
cloud_2 = ssigma*gamma_R*(v_R_2/c/c - (mm_dot/2./pi/ssigma/rr)**2.)
write(41,*)r,ssigma*gamma_R*((v_R_2/c/c) - (mm_dot/2./pi/ssigma/rr)**2.)
write(42,*)r,v_R_2/c/c, (mm_dot/2./pi/ssigma/rr)**2.
!!!!!!!!!!
qq_cl = (-f_R*det_VR2-f_phi*det_VPhi2*v_phi_ratio_v_R)*M_dot/2./pi/r/dim_Q
qq_cl = (sqrt(8./pi))*sigma_in*det_VR2**(3./2.)*f_R/dim_Q - (sqrt(8./pi))*sigma_in*det_VPhi2**(3./2.)*f_phi/dim_Q
! write(*,*)det_VR2,det_VPhi2
!if(x<log(rr_tidal))then
cloud_2 = 0.
qq_cl = 0.
!end if
! sigma_in,-sigma_in*k_bol*T_i/height(exp(x)*r_sch,sigma_in,W_i_in,W_e_in)/m_p/dim_Q/qq_cl
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
coefficient_c(1)= mm_dot**2./4./pi**2./exp(3.*x)/ssigma&
+ssigma*exp(x)*(oomega**2.-oomega_k**2.)&
-ww*ddlogomegakdr!&
! -cloud_2
coefficient_c(2)= mm_dot*ww_i*ddlogomegakdr/ssigma&
-2.*pi*alpha*ww*2.*ll_in/exp(x)&
+2.*pi*exp(x)*llambda_ie!&
! +2.*pi*exp(x)*qq_cl*0.05
coefficient_c(3)= mm_dot*ww_e*ddlogomegakdr/ssigma&
+2.*pi*exp(x)*qq_rad&
-2.*pi*exp(x)*llambda_ie!&
! -2.*pi*exp(x)*qq_cl*0.5
! write(*,*)'coeffi_c:3',mm_dot*ww_e*ddlogomegakdr/ssigma,2.*pi*exp(x)*qq_rad&
! ,2.*pi*exp(x)*llambda_ie+k_c_term
write(99,'(es17.7,es17.7,es17.7,es17.7,es17.7,es17.7)')&
log10(r/r_sch),&
(dim_Q*qq_rad),&
(dim_Q*llambda_ie),&
(dim_Q*qq_cl*0.1),&
-((mm_dot*ww_i*ddlogomegakdr/ssigma)/(2.*pi*exp(x)))*dim_Q,&!-(dim_Q*qq_cl)-(dim_Q*llambda_ie)
-((mm_dot*ww_i*ddlogomegakdr/ssigma)/(2.*pi*exp(x)))*dim_Q+(dim_Q*qq_cl*0.1)-(dim_Q*llambda_ie)