-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.py
162 lines (115 loc) · 4.21 KB
/
flow.py
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
import numpy as np
# import random
from scipy.integrate import solve_ivp
OUTFILE1_NAME = "nr.dat"
OUTFILE2_NAME = "esigma.dat"
NEQS = 8
kmax = 20000
NUMPOINTS = 20000
NUMEFOLDSMAX = 60.0
NUMEFOLDSMIN = 40.0
SMALLNUM = 0.0001
VERYSMALLNUM = 1e-18
LOTSOFEFOLDS = 1000.0
class Calc:
def __init__(self):
self.Y = numpy.zeros(NEQS, dtype=float, order='C')
self.initY = numpy.zeros(NEQS, dtype=float, order='C')
self.ret = ""
self.npoints = 0
self.Nefolds = 0.0
# Fills vector * yinit with randomly chosen initial values of the flow
# parameters, as well as a randomly chosen amount of inflation, Nefolds.
# POSSIBLE ISSUE WITH EXACT DECIMAL NUMBERS
def pick_init_vals():
init_vals = numpy.zeros (NEQS, dtype=float, order='C')
init_vals[0] = 0.0
init_vals[1] = 1.0
init_vals[2] = random.uniform(0.0 , 0.8)
init_vals[3] = random.uniform(-0.5 , 0.5)
init_vals[4] = random.uniform(-0.05 , 0.05)
for i in range (5 , NEQS):
upper_val = 1 * 0.05 * 0.1 ** (i-5) - 0.5 * 0.05 * 0.1 ** (i-5)
init_vals[i] = random.uniform(-upper_val , upper_val)
init_Nefolds = random.uniform(NUMEFOLDSMIN, NUMEFOLDSMAX)
return init_vals , init_Nefolds
def derivs(t, y):
dydN = numpy.zeros(NEQS , dtype=float , order='C')
if y[2] >= 1.0:
dydN = numpy.zeros(NEQS , dtype=float , order='C')
else:
if y[2] > VERYSMALLNUM:
dydN[0] = - numpy.sqrt ( y[2] / (4 * numpy.pi ) )
else:
dydN[0] = 0.0
dydN[1] = y[1] * y[2]
dydN[2] = y[2] * ( y[3] + 2.0 * y[2] )
dydN[3] = 2.0 * y[4] - 5.0 * y[2] * y[3] - 12.0 * y[2] * y[2]
for i in range (4 , NEQS-1):
dydN[i] = ( 0.5 * (i-3) * y[3] + (i-4) * y[2] ) * y[i] + y[i+1]
dydN[NEQS-1] = ( 0.5 * (NEQS-4) * y[3] + (NEQS-5) * y[2] ) * y[NEQS-1]
return dydN
def int_de (y, N, Nend, derivs):
h = 1e-6
ydoub = y.copy()
Nsol = solve_ivp(derivs, (N , Nend), ydoub, method='RK45', t_eval=None, dense_output=False, events=None, vectorized=False , first_step=h)
sol_status = Nsol['status']
sol_length = len ( Nsol['t'] )
sol_x = Nsol['t']
sol_Y = Nsol['y']
if sol_length > kmax:
sol_length = kmax
sol_x = sol_x [0:kmax]
sol_Y = sol_Y [: , 0:kmax]
return sol_status , sol_length , sol_x , sol_Y
calc = Calc()
path = numpy.zeros (( NEQS , kmax ))
# Open output files
try:
outfile1 = open (OUTFILE1_NAME, "w")
except IOError as e:
print ("Could not open file" , str(OUTFILE1_NAME) , ", errno =" , str(e) , ".")
try:
outfile2 = open (OUTFILE2_NAME, "w")
except IOError as e:
print ("Could not open file" , str(OUTFILE2_NAME) , ", errno =" , str(e) , ".")
# Allocate buffers
y = numpy.zeros(NEQS, dtype=float, order='C')
yinit = numpy.zeros(NEQS, dtype=float, order='C')
# iters = total number of iterations
# points = points saved with n < NMAX
# asymcount = points with 0 < n < NMAX , r = 0
# nontrivcount = nontrivial points
# insuffcount = points where slow roll breaks down before N efolds
# noconvcount = points that do not converge to either a late
# time attractor or end of inflation.
iters = 0
points = 0
errcount = 0
outcount = 0
asymcount = 0
nontrivcount = 0
insuffcount = 0
noconvcount = 0
badncount = 0
savedone = 0
# Currently this loop is set to depend on the number of
# nontrivial points. This can be changed to depend on total
# number of models, or other criteria.
deyancount = 0
while nontrivcount < NUMPOINTS:
deyancount += 1
iters += 1
if iters % 100 == 0:
if iters % 1000 == 0:
print ("\n asymcount =" , asymcount , ",nontrivcount =" , nontrivcount , ",insuffcount =" , insuffcount , ", noconvcount =" , noconvcount , ", badncount =" , badncount , ", errcount =" , errcount , "\n")
print ("\n", iters)
else:
print (".")
# Select a random initial condition such that the slow
# roll hierarchy converges.
yinit , calc.Nefolds = pick_init_vals()
y = yinit.copy()
calc.ret = calcpath ( calc.Nefolds , y , path , calc.npoints)
if deyancount > 100:
break