-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodpk_modules.f90
More file actions
368 lines (296 loc) · 10.2 KB
/
modpk_modules.f90
File metadata and controls
368 lines (296 loc) · 10.2 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
MODULE camb_interface
!Simple module to tell an external program, such as CAMB or the
!multimodecode_driver, that a given set of parameters does not give an
!appropriate inflationary realization.
IMPLICIT NONE
INTEGER :: pk_bad
LOGICAL :: pk_initialized
END MODULE camb_interface
MODULE modpkparams
!Module defining many "global" variables that various cosmology portions of
!the code will need access to. A variable added here can be seen in most
!places.
IMPLICIT NONE
!Double precision.
integer, parameter :: dp = selected_real_kind(15, 307)
!Quad precision; remember to compile with -r16
!INTEGER, parameter :: DP = selected_real_kind(33, 4931)
LOGICAL :: use_modpk, vnderivs, instreheat
! increase max_vparams to use more potential parameters
INTEGER*4, parameter :: max_vparams = 9
INTEGER :: potential_choice
INTEGER*4 :: nactual_bg, nactual_mode
INTEGER, PARAMETER :: nsteps=1e5
real(dp), PARAMETER :: M_Pl=1.0e0_dp
real(dp), PARAMETER :: Mpc2Mpl=2.6245e-57_dp
real(dp) :: k_pivot, N_pivot, N_tot, H_pivot
real(dp) :: a_end, a_pivot
real(dp) :: a_init
real(dp) :: h_init, rescale_factor
real(dp), ALLOCATABLE :: phidot_sign(:)
real(dp) :: Nefold_max=100000.e0_dp
real(dp) :: lna(nsteps)
real(dp) :: hubarr(nsteps), log_aharr(nsteps), epsarr(nsteps), dtheta_dN(nsteps)
LOGICAL :: slowroll_infl_end
LOGICAL :: slowroll_start=.false.
!MULTIFIELD
integer :: num_inflaton
real(dp), dimension(:,:), allocatable :: vparams
real(dp), allocatable :: phi_init0(:), phi_init(:)
real(dp), allocatable :: dphi_init0(:), dphi_init(:)
real(dp), allocatable:: phi_pivot(:), dphi_pivot(:), phi_infl_end(:)
real(dp), allocatable :: phiarr(:,:), dphiarr(:,:) !The first index is the multifield index
real(dp), allocatable :: param_arr(:)
real(dp) :: sigma_arr(nsteps)
real(dp) :: delsigma = M_Pl !specify total field distance travelled before inflation ends
!END MULTIFIELD
real(dp) :: findiffdphi
real(dp) :: modpk_ns, modpk_nt, modpk_nrun, modpk_As, modpk_r
!Flags for analytical calculations
logical :: use_deltaN_SR
logical :: evaluate_modes
!Technical options
type :: tech_options
integer :: accuracy_setting
logical :: use_dvode_integrator
real(dp) :: rk_accuracy_modes, rk_accuracy_back
real(dp) :: dvode_rtol_modes, dvode_rtol_back
real(dp), dimension(10000) :: dvode_atol_modes_real, dvode_atol_modes_imag, dvode_atol_back
end type tech_options
type(tech_options) :: tech_opt
END MODULE modpkparams
MODULE ode_path
!Module for control parameters for the numerical integration of either the
!background equations or the mode equations.
use modpkparams, only : dp
implicit none
INTEGER*4 :: nok,nbad,kount
LOGICAL, SAVE :: save_steps=.false.
LOGICAL :: ode_underflow
LOGICAL :: ode_ps_output
LOGICAL :: ode_infl_end
LOGICAL :: infl_ended
real(dp) :: dxsav
real(dp), DIMENSION(:), POINTER :: xp
real(dp), DIMENSION(:), POINTER :: param_p
real(dp), DIMENSION(:,:), POINTER :: yp
END MODULE ode_path
MODULE internals
!Module that defines some variables for internal use in the code.
use modpkparams, only : num_inflaton, dp
IMPLICIT NONE
real(dp), PARAMETER :: PI=3.141592653589793238462643383279502884197e0_dp
real(dp) :: h_ik
!MULTIFIELD
integer :: index_ptb_y, index_ptb_vel_y, index_tensor_y, index_uzeta_y
!END MULTIFIELD
real(dp) :: k, a_ik
END MODULE internals
module modpk_observables
!Module that defines the various observables one could calculate around the
!pivot scale. Defines objects for observables, power spectra, etc.
use modpkparams, only : dp, num_inflaton
use modpk_io, only : out_opt
use csv_file, only : csv_write
implicit none
integer*4 :: ik
real(dp) :: eval_ps,k_start, useq_ps
!Power spectrum type, used for one k
!Simplifies all the various defns for isocurv ptbs
type :: power_spectra
!Mode
real(dp) :: k
!Ptb spectra
complex(dp), dimension(:,:), allocatable :: phi_ij
!Proj ptb spectra onto adiab direction
real(dp) :: adiab
!Tensor mode spectrum
real(dp) :: tensor
!Approximated zeta spectrum
real(dp) :: powz
!Proj ptb spectra onto directions perpend to adiab
real(dp) :: isocurv
!Cross-spectrum for isocurv + adiab
real(dp) :: cross_ad_iso
!Total non-adiab pressure ptb spectrum
real(dp) :: pnad
!Total pressure ptb spectrum
real(dp) :: pressure
!Adiab pressure ptb spectrum
real(dp) :: press_ad
!Total entropic ptb spectrum, proportional to non-adiab pressure ptb
real(dp) :: entropy
!Expansion scalar for field space bundle width
real(dp) :: bundle_exp_scalar
end type
!For temporary calc of spectra in odeint
type(power_spectra) :: power_internal
type, public :: KahanSum
real(dp) :: summand = 0e0_dp
real(dp) :: remainder = 0e0_dp
contains
procedure, public :: add => kahan_summation
procedure, public :: clear => kahan_clear_mem
end type
!Type to save the ICs and observs. Add new observables here
type :: observables
real(dp), dimension(:), allocatable :: ic
!Spectra amplitudes
real(dp) :: As
real(dp) :: A_iso
real(dp) :: A_pnad
real(dp) :: A_ent
real(dp) :: A_cross_ad_iso
!Bundle width from arXiv:1203.2635
real(dp) :: A_bundle
!Spectral indices
real(dp) :: ns
real(dp) :: nt
real(dp) :: n_iso
real(dp) :: n_pnad
real(dp) :: n_ent
!Tensor-to-scalar
real(dp) :: r
!Running, etc
real(dp) :: alpha_s
real(dp) :: runofrun
!Non-Gaussianity
real(dp) :: f_NL
real(dp) :: tau_NL
contains
procedure, public :: printout => ic_print_observables
procedure, public :: print_header => ic_print_headers
procedure, public :: set_zero => set_observs_to_zero
procedure, public :: set_finite_diff => calculate_observs_finitediff
end type observables
private :: ic_print_observables, set_observs_to_zero, &
calculate_observs_finitediff,kahan_summation,kahan_clear_mem
contains
!Procedures for Kahan summation objects
!Algorithm for Kahan summation
subroutine kahan_summation(self,val)
class(KahanSum) :: self
real(dp), intent(in) :: val
real(dp) :: ytemp, ttemp
ytemp = val - self%remainder
ttemp = self%summand + ytemp
self%remainder = (ttemp - self%summand) - ytemp
self%summand = ttemp
end subroutine kahan_summation
subroutine kahan_clear_mem(self)
class(KahanSum) :: self
self%remainder=0e0_dp
self%summand=0e0_dp
end subroutine kahan_clear_mem
!Write the cosmo observables headers to file
subroutine ic_print_headers(self, outunit)
class(observables) :: self
integer, intent(in) :: outunit
character(1024) :: cname
integer :: ii
!First columns for IC
do ii=1,size(self%ic)
write(cname, "(A3,I4.4)") "phi_piv", ii
call csv_write(&
outunit,&
trim(cname), &
advance=.false.)
end do
!Remaining columns
call csv_write(outunit,&
(/character(len=10) ::&
'As', 'ns', 'r', 'nt', 'alpha_s', &
'A_iso', 'A_pnad', 'A_ent', 'A_bundle', &
'n_iso', 'n_pnad', 'n_ent', &
'A_cross', 'f_NL', 'tau_NL'/),&
advance=.true.)
end subroutine ic_print_headers
!Print the cosmo observables to file
subroutine ic_print_observables(self, outunit)
class(observables) :: self
integer, intent(in) :: outunit
call csv_write(outunit,&
(/ self%ic(:), &
self%As, &
self%ns,&
self%r, &
self%nt, &
self%alpha_s, &
self%A_iso, &
self%A_pnad,&
self%A_ent, &
self%A_bundle, &
self%n_iso, &
self%n_pnad, &
self%n_ent, &
self%A_cross_ad_iso, &
self%f_NL, &
self%tau_NL /), &
advance=.true.)
end subroutine ic_print_observables
subroutine set_observs_to_zero(self)
class(observables) :: self
self%As = 0e0_dp
self%A_iso = 0e0_dp
self%A_pnad = 0e0_dp
self%A_ent = 0e0_dp
self%A_cross_ad_iso = 0e0_dp
self%A_bundle = 0e0_dp
self%ns = 0e0_dp
self%nt = 0e0_dp
self%n_iso = 0e0_dp
self%n_pnad = 0e0_dp
self%n_ent = 0e0_dp
self%r = 0e0_dp
self%alpha_s = 0e0_dp
self%runofrun = 0e0_dp
self%f_NL = 0e0_dp
self%tau_NL = 0e0_dp
end subroutine set_observs_to_zero
subroutine calculate_observs_finitediff(self, dlnk, &
pk0, pklow1, pkhigh1, &
pklow2, pkhigh2, &
bundle_width)
class(observables) :: self
type(power_spectra), intent(in) :: pk0, pklow1, pkhigh1
type(power_spectra), intent(in), optional :: pklow2, pkhigh2
real(dp), intent(in) :: dlnk
real(dp), intent(in), optional :: bundle_width
logical :: runofrun
if (present(pklow2)) then
runofrun = .true.
else
runofrun = .false.
endif
!Amplitudes
self%As = pk0%adiab
self%A_iso=pk0%isocurv
self%A_pnad=pk0%pnad
self%A_ent=pk0%entropy
self%A_cross_ad_iso = pk0%cross_ad_iso
!Bundle width
self%A_bundle=bundle_width
!Finite difference evaluation of spectral indices
self%ns = 1.e0_dp+log(pkhigh1%adiab/pklow1%adiab)/dlnk/2.e0_dp
self%nt = log(pkhigh1%tensor/pklow1%tensor)/dlnk/2.e0_dp
self%n_iso=log(pkhigh1%isocurv/pklow1%isocurv)/dlnk/2.e0_dp
self%n_pnad=log(pkhigh1%pnad/pklow1%pnad)/dlnk/2.e0_dp
self%n_ent=log(pkhigh1%entropy/pklow1%entropy)/dlnk/2.e0_dp
!Tensor-to-scalar
self%r = pk0%tensor/pk0%adiab
if (runofrun) then
!alpha_s from 5-pt stencil
self%alpha_s = (1.0e0_dp/12.0e0_dp/dlnk**2)*&
(-log(pkhigh2%adiab) + 16.0e0_dp*log(pkhigh1%adiab) - &
30.0e0_dp*log(pk0%adiab) + 16.0e0_dp*log(pklow1%adiab) - &
log(pklow2%adiab))
self%runofrun = (1.0e0_dp/2.0e0_dp/dlnk**3)*&
(log(pkhigh2%adiab) -2.0e0_dp* log(pkhigh1%adiab) &
+ 2.0e0_dp*log(pklow1%adiab) -log(pklow2%adiab))
else
self%alpha_s = log(pkhigh1%adiab*pklow1%adiab/pk0%adiab**2)/dlnk**2
!Default
self%runofrun = 0e0_dp
end if
end subroutine calculate_observs_finitediff
end module modpk_observables