-
Notifications
You must be signed in to change notification settings - Fork 0
/
sco_model_LOGbb.f90
272 lines (214 loc) · 11.6 KB
/
sco_model_LOGbb.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
SUBROUTINE sco_MODEL_LOGbb(disk_size, corona_size, Tcorona, Tdisk, tau, QPO_frequency, DHext, eta_frac, Nsss, Ssss,Tsss, &
Nreal, Sreal, Treal, Nimag,Simag, Timag, dTe_mod, dTs_mod, dTe_arg, dTs_arg, Hexo0_out, eta_int)
USE iso_fortran_env, ONLY : WP => REAL64
USE sco_global
USE sco_arrays
IMPLICIT NONE
! scalar arguments
REAL(WP), INTENT(INOUT) :: disk_size, corona_size, Tcorona, Tdisk, tau, QPO_frequency, DHext, eta_frac
REAL(WP) Emin_adim, Emax_adim, Emin, Emax
! REAL :: param(5), photar(meshlog-1), EAR(0:meshlog-1), photer(meshlog-1)
REAL :: Tdisk2, h_T, Tdisk3, Tbb
REAL :: photarbb(meshlog-2), earbb(0:meshlog-2), photerbb(meshlog-2), photarbb2(meshlog-2), photerbb2(meshlog-2)
REAL :: photarbb3(meshlog-2), photerbb3(meshlog-2)
! integer :: near
integer :: ifl
! CHARACTER(4) method
! array arguments
REAL(WP) :: x2(meshlog) , x_use(meshlog-2), xlog(meshlog), xlog_use(meshlog-2), dbb_t(meshlog-2), blackbody3(meshlog-2)
! parameters steady state solution
REAL(WP) :: c2(meshlog-2), nc, c5, c6, c11, Nesc(meshlog-2), Vc, omega, dxlog, xtot_low, xtot_up, dx
REAL(WP) :: KN_corr_interpol(meshlog-2), ccsub(meshlog-2), blackbody(meshlog-2), blackbody2(meshlog-2)
INTEGER Ntri, columns_CC, INFO, nestsol, Nsss, Nreal, Nimag
REAL(WP) :: L(meshlog-3), U(meshlog-3), D(meshlog-2), n0(meshlog)
! !parameters perturbative solution
REAL(WP) :: Nescp(meshlog), c2p(meshlog), dn0log(meshlog), dn02log(meshlog), factor1
REAL(WP) :: KNp_int(meshlog), Hexo0, eta_max, eta, transf, xlog_square(meshlog), xlog_use_square(meshlog-2)
REAL(WP) :: x_use_square(meshlog-2), x2square(meshlog)
! REAL(WP) :: L_subsol(mesh_size-3), U_subsol(mesh_size-3), L_dn0(mesh_size-3), U_dn0(mesh_size-3), Nescp_use(mesh_size-2)
REAL(WP) :: Q1(meshlog-2), Q2(meshlog-2), Q3(meshlog-2), stau_kn(meshlog-2)
REAL(WP) :: A1(meshlog-2), A2(meshlog-2), p1, x_withunit(meshlog), rad_sphere, surf, corona_simps
REAL(WP) :: corona_Lum, corona_Lum_out, vect4(meshlog), Iex01, Iex02, Iex03, Nescp_use(meshlog-2)
REAL(WP) :: area, tc, to_phys, vect1(meshlog-2), vect2(meshlog-2), vect3(meshlog-2), xlog_trans(meshlog)
REAL(WP) :: SOLsss(meshlog), SOLreal(meshlog), SOLimag(meshlog), Tsss(meshlog+4), Ssss(meshlog+4)
REAL(WP) :: Treal(meshlog+4), Sreal(meshlog+4), Timag(meshlog+4), Simag(meshlog+4)
COMPLEX(WP), DIMENSION(meshlog-3) :: Lp, Up
COMPLEX(WP), DIMENSION(meshlog-2) :: Dp, sol_ongrid, k0n
COMPLEX(WP), DIMENSION(meshlog) :: solution, auxiliar, auxiliar2, auxiliar3
COMPLEX(WP) :: dTe, dTs, dTesimps1, dTesimps2, dTssimps, denom, k0, k1, k2
REAL(WP) :: dTesimps1_real, dTesimps2_real, dTesimps1_imag, dTesimps2_imag, dTssimps_real, dTssimps_imag
REAL(WP) :: dTe_mod, dTs_mod, dTe_arg, dTs_arg, Hexo0_out, eta_int
! REAL(WP), DIMENSION(:), ALLOCATABLE :: x2 , x_use , L, U, D, CC, n0
call sco_constants(dist, mass, time, energy_norm, eV2J, keV2J, MeV2J, J2keV, Etrans, kbol, hplanck, c, cc2, me, sigma, stau)
!---We define the energy regime for the BVP solution
Emin_adim = 1.e-6
Emax_adim = 40.
Emin = Emin_adim * Tcorona
Emax = Emax_adim * Tcorona
!---The output is an array, whose components are evenly spaced numbers between log(Emin/Tcorona) and log(Emax/Tcorona)
CALL sco_linspace(log(Emin_adim), log(Emax_adim), meshlog, xlog)
!---We define the grid of energy spaced evenly on a log scale
x2 = exp(xlog)
!---We transform input parameters to the internal units
Tcorona = Tcorona * Etrans
Tdisk = Tdisk * Etrans
disk_size = disk_size * 1000. * (1. / dist)
corona_size = corona_size * 1000. * (1. / dist)
QPO_frequency = QPO_frequency * time
!---We define the energy step size for the numerical integration
dxlog = xlog(4) - xlog(3)
dx = x2(4) - x2(3)
!---We define the integration limits for the energy averaged rms
xtot_low = 2. * Etrans / Tcorona
xtot_up = 60. * Etrans / Tcorona
DO I = 1, meshlog-2
xlog_use(i) = xlog(i+1)
x_use(i) = x2(i+1)
ENDDO
!--------BEGIN OF: construction of the steady state solution----------
Ntri=meshlog-2 !dimension of the x_use and then it will be the dimension of the tridiagonal matrix &
!the constant vector of the system that we need to solve
CALL sco_par(disk_size, corona_size, Tcorona, Tdisk, tau, QPO_frequency, Ntri, x_use, c2, nc, c5, c6, c11, Nesc, &
Vc, KN_corr_interpol)
omega = 2.0 * PI * QPO_frequency
!---Preparing to solve the steady state Kompaneets equation (SS) after discretization
DO I=2, Ntri
L(I-1) = 1. / (dxlog **2) - (x_use(i)-1.) / (2. * dxlog) ! sub-diagonal elements
U(I-1) = 1. / (dxlog **2) + (x_use(i-1)-1.) / (2. * dxlog) ! super-diagonal elements
ENDDO
D = -2. + 2. * x_use - c2 - 2. / (dxlog **2) ! diagonal elements: x-dependent
!---Array that has the boundaries of the energy channels
earbb(0) = real(x_use(1)*(Tcorona/Etrans) / sqrt(exp(dxlog)))
DO I = 1, Ntri
earbb(i) = real(earbb(i-1) * exp(dxlog))
ENDDO
Tbb = real(Tdisk/Etrans)
ifl = 0
CALL xsbbrd(earbb, Ntri, Tbb, ifl, photarbb, photerbb)
DO i = 1, Ntri
blackbody(i) = photarbb(i) / ( (Tcorona/Etrans)**2 * 1.0344E-3 * (earbb(i)-earbb(i-1))) ! the subroutine gives as BB(E) * dE * 1.0344E-3
ccsub (i) = -blackbody(i)
ENDDO
!---Derivative of BB with respect to Tdisk
ifl = 0
h_T = real(Tdisk/Etrans) * 1.e-2
Tdisk2 = real(Tdisk/Etrans) + h_T
Tdisk3 = real(Tdisk/Etrans)-h_T
CALL xsbbrd(earbb, Ntri, Tdisk2, ifl, photarbb2, photerbb2)
DO i = 1, Ntri
blackbody2(i) = photarbb2(i) / ( (Tcorona/Etrans)**2 * 1.0344E-3 * (earbb(i)-earbb(i-1))) ! the subroutine gives as BB(E) * dE * 1.0344E-3
ENDDO
CALL xsbbrd(earbb, Ntri, Tdisk3, ifl, photarbb3, photerbb3)
DO i = 1, Ntri
blackbody3(i) = photarbb3(i) / ( (Tcorona/Etrans)**2 * 1.0344E-3 * (earbb(i)-earbb(i-1))) ! the subroutine gives as BB(E) * dE * 1.0344E-3
ENDDO
dBB_T = (blackbody2-blackbody3)/(2*h_T)
columns_CC=1
CALL dgtsv(Ntri, columns_CC, L, D, U, CCsub, Ntri, INFO) ! on exit, CC has the solution of (LDU)*X=CC
n0(1) = 0.0
n0(meshlog) = 0.0
DO I =1, Ntri
n0(I+1) = CCsub(I)
ENDDO
!--- n0 is the steady state solution
!---BEGIN OF: construction of the linearized equation
CALL sco_par(disk_size, corona_size, Tcorona, Tdisk, tau, QPO_frequency, meshlog, x2, c2p, &
nc, c5, c6, c11, Nescp, Vc, KNp_int)
!---We define the first and second order derivative of n0
dn0log(1) = (-n0(3) + 4. * n0(2) - 3. * n0(1)) / (2. * dxlog)
dn0log(meshlog) = (3. * n0(meshlog) - 4. * n0(meshlog-1) + n0(meshlog-2)) / (2. * dxlog)
dn02log(1) = (2. * n0(1) - 5. * n0(2) + 4. * n0(3) - n0(4))
dn02log(meshlog) = (2. * n0(meshlog) + 5. * n0(meshlog-1) + 4. * n0(meshlog-2) + n0(meshlog-3))
DO I = 1, Ntri
dn0log(i+1) = (n0(i+2) - n0(i)) / (2.0 * dxlog)
dn02log(i+1) = (n0(i+2) - 2.0 * n0(i+1) + n0(i)) / (dxlog * dxlog)
x_use_square(i) = (x_use(i))**2
xlog_use_square(i) = (xlog_use(i))**2
Nescp_use(i) = Nescp(i+1)
ENDDO
DO I = 1, meshlog
x2square(i) = (x2(i))**2
xlog_square(i) = (xlog(i))**2
ENDDO
Dp= dcmplx(2. + (dxlog**2) * blackbody / CCsub , -c5 * dxlog**2 )
DO I=1, Ntri -1
Lp (i) = dcmplx(-1. + (x_use(i+1)-1) * dxlog/2. + (dn0log(i+2) * dxlog)/ CCsub(i+1) , 0)
Up (i)= dcmplx(-1. - (x_use(i)-1) * dxlog/2. - (dn0log(i+1) * dxlog)/ CCsub(I) , 0)
ENDDO
stau_kn = (3. / 4.) * stau * KN_corr_interpol ! klein Nishina correction
Q2 = x_use_square * x_use * CCsub * stau_kn
Q1 = CCsub * x_use_square * stau_kn
Q3 = CCsub * x_use_square / Nescp_use
vect1 = CCsub * x_use_square* stau_kn
CALL sco_SIMPSON(Ntri,vect1,xlog_use,Iex01)
vect2 = CCsub * x_use * x_use_square * stau_kn
CALL sco_SIMPSON(Ntri,vect2,xlog_use,Iex02)
vect3 = CCsub * x_use_square/ Nescp_use
CALL sco_SIMPSON(Ntri,vect3,xlog_use,Iex03)
factor1 = ((Tcorona ** 3) * nc) / (me * c)
Hexo0 = factor1 * (4. * Iex01 - Iex02)
eta_max = c11 / Iex03
eta = eta_frac * eta_max
denom = dcmplx(4. * factor1 * Iex01 , - (3. / 2.) * omega * Tcorona) ! denominator in eq (A6) of Karpouzas et al 2019
eta_int = eta ! we record eta_int (\tilde\eta)
k0 = DHext * Hexo0 / denom ! first term in eq (A6) of Karpouzas et al 2019
k1 = -4. * factor1 / denom ! multiplicative factor of the 3rd term in eq (A6) of Karpouzas et al 2019
k2 = factor1 / denom ! multiplicative factor of the 2nd term in eq (A6) of Karpouzas et al 2019
DO I = 1, Ntri
A1(I) = (dxlog**2) * (-2. -dn0log(i+1)/ccsub(i) + dn02log(I+1) / CCsub(I))
ENDDO
A2 = (dxlog**2) *(Tdisk/Etrans) * (dBB_T / CCsub)
p1 = c6 * eta ! multiplicative factor in eq (A7) of Karpouzas et al 2019
k0n = k0 ! the mppinv needs a vector
!---Calculation of the solution
CALL sco_MPPINV(Lp, Dp, Up, p1, A1, A2, k0n, k1, k2, Q1, Q2, Q3, dxlog, Ntri, sol_ongrid)
solution(1) = (0,0) ! boundary conditions
solution(meshlog) = (0,0)
DO I = 1, Ntri
solution(i+1) = sol_ongrid(i)
ENDDO
SOLreal = REALPART(solution)
SOLimag = IMAGPART(solution)
x_withunit = x2 * Tcorona ! energy grid in internal units
rad_sphere = disk_size + corona_size
surf = 4. * pi * rad_sphere ** 2
vect4 = x2 * n0/ Nescp
CALL sco_SIMPSON(meshlog,vect4,xlog,corona_simps)
corona_Lum = surf * (1. - eta) * c * nc * Tcorona ** 2 * corona_simps ! this is probably wrong
corona_Lum_out = corona_Lum * keV2J / (time * Etrans)
!---Vector to go from grid units to physical units in ph cm^-2 s^-1 keV^-1 @ 1kpc
area = 4. * pi * (3e19/dist) **2
tc = disk_size / (c * tau)
to_phys = (1.-eta)*Vc*nc/area/(tau+tau**2/3)/tc
to_phys = to_phys* 1e-4 / dist**2 /time * Etrans
transf = Etrans/Tcorona ! parameter used to transform the input grid from keV to internal units
xlog_trans = x2/transf
nestsol= meshlog + 4
SOLsss = n0*transf*to_phys
!---Calculation of the fractional amplitude of the corona temperature oscillation
auxiliar = x2square * n0 * solution * (3. / 4.) * stau * KNp_int
CALL sco_SIMPSON(size(xlog),realpart(auxiliar),xlog,dTesimps1_real)
CALL sco_SIMPSON(size(xlog),imagpart(auxiliar),xlog,dTesimps1_imag)
dTesimps1 = complex(dTesimps1_real,dTesimps1_imag)
auxiliar2 = x2 * auxiliar
CALL sco_SIMPSON(size(xlog),realpart(auxiliar2),xlog,dTesimps2_real)
CALL sco_SIMPSON(size(xlog),imagpart(auxiliar2),xlog,dTesimps2_imag)
dTesimps2 = complex(dTesimps2_real,dTesimps2_imag)
dTe = k0 + k1 * dTesimps1 + k2 * dTesimps2
dTe_mod = cdabs(dTe)
dTe_arg = atan2(imagpart(dTe),realpart(dTe))
!---Calculation of the fractional amplitude of the seed source temperature oscillation
auxiliar3 = x2square * n0 * solution / Nescp
CALL sco_SIMPSON(size(xlog),realpart(auxiliar3),xlog,dTssimps_real)
CALL sco_SIMPSON(size(xlog),imagpart(auxiliar3),xlog,dTssimps_imag)
dTssimps=complex(dTssimps_real,dTssimps_imag)
dTs = p1 * dTssimps
dTs_mod = cdabs(dTs)
dTs_arg = atan2(imagpart(dTs),realpart(dTs))
!---Calculation of the external heating rate at thermal equilibrium
Hexo0_out = Hexo0 * keV2J / (time * Etrans) ! units : Joules per second
!---Interpolating splines
CALL sco_InterpolatedUnivariateSpline(meshlog,xlog_trans,SOLsss,nestsol,Nsss,Tsss,Ssss)
CALL sco_InterpolatedUnivariateSpline(meshlog,xlog_trans,SOLreal,nestsol,Nreal,Treal,Sreal)
CALL sco_InterpolatedUnivariateSpline(meshlog,xlog_trans,SOLimag,nestsol,Nimag,Timag,Simag)
ENDSUBROUTINE