Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 690 lines (501 sloc) 20.03 kB
fef582a Initial commit of PyCOOL
Jani Sainio authored
1 #from potential import *
2
3 ###############################################################################
4 """
5 List of various functions needed when converting a (polynomial) potential
6 function given in string format to a form suitable to CUDA (i.e. C).
7
8 """
9 ###############################################################################
10
11 def replace_all(text, dic):
12 "Use the replacement rules from dictionary dic to text string"
13 for i, j in dic.iteritems():
14 text = text.replace(i, j)
15 return text
16
17 def rep(f,n):
18 """Write a (string) function 'f**n' into form 'f*f*...*f'
19 i.e. write the multiplication open for CUDA."""
20 tmp = f
21 for i in xrange(n-1):
22 tmp = f + '*' + tmp
23 return tmp
24
25 def format_to_cuda(V,var_list,C_list,D_list,n):
26 """Format a polynomial function V into a suitable form for CUDA.
27 n = the degree of V."""
28 tmp = V
29 for f in var_list:
30 for i in reversed(xrange(1,n+1)):
31 tmp = tmp.replace(f+'**'+str(float(i)),rep(f,i))
32 tmp = tmp.replace(f+'**'+str(i),rep(f,i))
33 for C in C_list:
34 for i in reversed(xrange(1,n+1)):
35 tmp = tmp.replace(C+'**'+str(float(i)),rep(f,i))
36 tmp = tmp.replace(C+'**'+str(i),rep(f,i))
37 for D in D_list:
38 for i in reversed(xrange(1,n+1)):
39 tmp = tmp.replace(D+'**'+str(float(i)),rep(f,i))
40 tmp = tmp.replace(D+'**'+str(i),rep(f,i))
41 return tmp
42
43 def new_poly(V_s, fields, n_coeffs):
44 """Make a new polynomial function that has the same powers as V_s function
45 but with coefficients C1, C2..."""
46
47 from sympy import Poly
48 from sympy import diff, Symbol, var, simplify, sympify, S
49 from sympy.core.sympify import SympifyError
50
51 P = Poly(V_s,*fields)
52 d = P.as_dict()
53 e = {}
54
55 for key in d.iterkeys():
56 #print d[key], str(d[key])
57 for i in xrange(1, n_coeffs+1):
58 if 'C' + str(i) in str(d[key]):
59 e[key] = sympify('C'+str(i))
60
61 P2 = Poly(e,*fields)
62 return str(P2.as_basic())
63
64
65 def V_calc(V_string, n, field_list, field_i, power_list,
66 C_list, D_list, kernel_type, deriv_n=0,
67 multiplier=1.0):
68 """Apply the necessary calculations (i.e. derivation and/or multiply
69 with a constant) to the potential function V_string:"""
70
71 from sympy import diff, Symbol, var, simplify, sympify, S, collect
72 from sympy.core.sympify import SympifyError
73
74 n_coeffs = len(C_list)
75 n2_coeffs = len(D_list)
76
77 try:
78 V = sympify(V_string)
79
80 m = sympify(multiplier)
81
82 except SympifyError:
83 print "Could not parse expression."
84
85 tmp = simplify(((m*diff(V, field_list[field_i-1], deriv_n)).expand()))
86
87 tmp = collect(tmp,field_list)
88
89 """Replace integer coefficients with float coefficients by
90 first separating the different terms of the function:"""
91 terms = tmp.as_coeff_factors()[1]
92
93 """The nominator and denominator of the SymPy function have to be
94 evaluated separately. Otherwise Sympy will use conjugate functions that
95 will not function in CUDA code:"""
96 new_terms = sympify('0')
97 for term in terms:
98 nom, denom = term.as_numer_denom()
99 if denom == 1:
100 new_terms += nom.evalf()
101 else:
102 new_terms += nom.evalf()/denom.evalf()
103
104 tmp = (format_to_cuda(str(new_terms),power_list,C_list,D_list,n)
105 .replace('(1 ','(1.0 '))
106
107 if kernel_type=='H3':
108 const_name='f_coeff'
859bce6 Added fourth order accurate discrete derivatives.
Jani Sainio authored
109 i0 = 4
fef582a Initial commit of PyCOOL
Jani Sainio authored
110 const2_name='d_coeff'
111 i1 = 0
112 elif kernel_type=='rp':
113 const_name='g_coeff'
114 i0 = 3
115 const2_name='d_coeff'
116 i1 = 0
117 elif kernel_type=='pd':
118 const_name='p_coeff'
119 i0 = 2
120 const2_name='d_coeff'
121 i1 = 0
122
123 "Replace C_is and D_is with the appropiate strings:"
124 r_cuda_V = {}
125 for i in xrange(n_coeffs):
126 r_cuda_V.update({'C'+str(i+1):const_name+'['+str(i0+i)+']'})
127 for i in xrange(n2_coeffs):
128 r_cuda_V.update({'D'+str(i+1):const2_name+'['+str(i1+i)+']'})
129
130 r_cuda_dV = {}
131 for i in xrange(n_coeffs):
132 r_cuda_dV.update({'C'+str(i+1):const_name+'['+str(i0+i)+']'})
133 for i in xrange(n2_coeffs):
134 r_cuda_dV.update({'D'+str(i+1):const2_name+'['+str(i1+i)+']'})
135
136 r_cuda_d2V = {}
137 for i in xrange(n_coeffs):
138 r_cuda_d2V.update({'C'+str(i+1):const_name+'['+str(i0+i)+']'})
139 for i in xrange(n2_coeffs):
140 r_cuda_d2V.update({'D'+str(i+1):const2_name+'['+str(i1+i)+']'})
141
142
143 if deriv_n == 0:
144 tmp2 = format_to_cuda(tmp, power_list, C_list, D_list, n)
145 res = replace_all(tmp2, r_cuda_V)
146 elif deriv_n == 1:
147 tmp2 = format_to_cuda(tmp, power_list, C_list, D_list, n)
148 res = replace_all(tmp2, r_cuda_dV)
149 elif deriv_n == 2:
150 tmp2 = format_to_cuda(tmp, power_list, C_list, D_list, n)
151 res = replace_all(tmp2, r_cuda_d2V)
152
153 return res
154
155 #V_string, n, field_list, field_i, n_coeffs, coeffs,
156 # deriv_n=0, multiplier=1.0
157
158 def V_calc_lin(V_string, n, field_list, field_i, power_list,
159 C_list, D_list, C_vals, D_vals,
160 deriv_n=0, multiplier=1.0):
161
162 """Apply the necessary calculations (i.e. derivation and/or multiply with a constant)
163 to the potential function V_string:"""
164
165 from sympy import diff, Symbol, var, simplify, sympify, S
166 from sympy.core.sympify import SympifyError
167
168 n_coeffs = len(C_list)
169 n2_coeffs = len(D_list)
170
171 try:
172 V = sympify(V_string)
173
174 m = sympify(multiplier)
175
176 except SympifyError:
177 print "Could not parse expression."
178
179 tmp = ((m*diff(V, field_list[field_i-1], deriv_n)).expand()).evalf()
180
8a6cc60 Fixed linearized evolution part. Also slightly changed curvaton Model…
Jani Sainio authored
181 "Replace C_i's and D_i's with the appropiate numerical values:"
fef582a Initial commit of PyCOOL
Jani Sainio authored
182 r_V_back = {}
183 for i in xrange(n_coeffs):
184 r_V_back.update({'C'+str(i+1):C_vals[i]})
185 for i in xrange(n2_coeffs):
186 r_V_back.update({'D'+str(i+1):D_vals[i]})
187
188 r_dV_back = {}
189 for i in xrange(n_coeffs):
190 r_dV_back.update({'C'+str(i+1):C_vals[i]})
191 for i in xrange(n2_coeffs):
192 r_dV_back.update({'D'+str(i+1):D_vals[i]})
193
194 r_d2V_back = {}
195 for i in xrange(n_coeffs):
196 r_d2V_back.update({'C'+str(i+1):C_vals[i]})
197 for i in xrange(n2_coeffs):
198 r_d2V_back.update({'D'+str(i+1):D_vals[i]})
199
200 f_repl = {}
201 for i in xrange(len(field_list)):
202 f_repl.update({'f'+str(i+1):'f0'+str(i+1)+'[0]'})
203
204 if deriv_n == 0:
205 tmp = (tmp.subs(r_V_back)).evalf()
206 tmp2 = format_to_cuda(str(tmp), power_list, C_list, D_list, n)
207 res = replace_all(tmp2,f_repl)
208 elif deriv_n == 1:
209 tmp = (tmp.subs(r_dV_back)).evalf()
210 tmp2 = format_to_cuda(str(tmp), power_list, C_list, D_list, n)
211 res = replace_all(tmp2,f_repl)
212 elif deriv_n == 2:
213 tmp = (tmp.subs(r_dV_back)).evalf()
214 tmp2 = format_to_cuda(str(tmp), power_list, C_list, D_list, n)
215 res = replace_all(tmp2,f_repl)
216
8a6cc60 Fixed linearized evolution part. Also slightly changed curvaton Model…
Jani Sainio authored
217 #print 'res', res
fef582a Initial commit of PyCOOL
Jani Sainio authored
218
219 return res
220
221
222 def dV_coeffs(lat, V_s, field_list, C_list, deriv_n):
223 """Read the different numerical coefficients
224 from dV/df or d^2V/df^2 terms."""
225 from sympy import diff, Symbol, var, simplify, sympify, S
226 from sympy.core.sympify import SympifyError
227 import numpy as np
228
229 repl = {}
230 for field in field_list:
231 repl[field] = '1'
232
233 dF = [diff(sympify(V_s),f, deriv_n) for f in field_list]
234
235 "Make substitutions f_{i} = 1:"
236 dF1 = [df.subs(repl) for df in dF]
237
238 """Calculate the coefficients of C_{i} terms by differentiating
239 with respect to them:"""
240 dV_mult = []
241 for Cf in dF1:
242 tmp = []
243 for Ci in C_list:
244 tmp.append(diff(Cf,Ci))
245 dV_mult.append(np.array(tmp, dtype=lat.prec_real))
246
247 return dV_mult
248
249 ###########################################################################################
250
251 def rho_init(V, fields0, pis0):
252 "Calculate the energy density of the homogeneous field values:"
253
254 from sympy import diff, Symbol, var, simplify, sympify, S, evalf
255 from sympy.core.sympify import SympifyError
256
257 C_coeff = V.C_coeff
258 D_coeff = V.D_coeff
259 V_string = V.V
260
261 try:
262 V = sympify(V_string)
263
264 except SympifyError:
265 print "Could not parse expression."
266
267 rep_list = {}
268 for i in xrange(len(C_coeff)):
269 rep_list.update({'C'+str(i+1):C_coeff[i]})
270 for i in xrange(len(D_coeff)):
271 rep_list.update({'D'+str(i+1):D_coeff[i]})
272
273 for i in xrange(len(fields0)):
274 rep_list.update({'f'+str(i+1):fields0[i]})
275
276 rho0 = 0.
277
278 for i in xrange(len(fields0)):
279 rho0 += 0.5*pis0[i]**2.0
280
281 "Initial value of the potential function:"
282 V0 = V.subs(rep_list)
283
284 rho0 += V0
285
286 return float(rho0)
287
288 def mass_eff(V, field_list, fields0, H0, deSitter=False):
289 "Calculate the initial effective masses of the fields:"
290
291 from sympy import diff, Symbol, var, simplify, sympify, S, evalf
292 from sympy.core.sympify import SympifyError
293
294 C_coeff = V.C_coeff
295 D_coeff = V.D_coeff
296 V_string = V.V
297
298 try:
299 d2V = [diff(sympify(V_string),f,2) for f in field_list]
300
301 except SympifyError:
302 print "Could not parse expression."
303
304 "Replacement list f(t)->f(t0), C_i->C_coeff[i], D_i->D_coeff[i]:"
305 rep_list = {}
306 for i in xrange(len(C_coeff)):
307 rep_list.update({'C'+str(i+1):C_coeff[i]})
308 for i in xrange(len(D_coeff)):
309 rep_list.update({'D'+str(i+1):D_coeff[i]})
310
311 for i in xrange(len(fields0)):
312 rep_list.update({'f'+str(i+1):fields0[i]})
313
314 "If a deSitter space include also a''/a term:"
315 if deSitter:
316 C = 1
317 else:
318 C = 0
319
320 "Initial value of the potential function:"
321 m2eff = [(float(x.subs(rep_list)) - C*9./4.*H0**2.0 ) for x in d2V]
322
e619416 Some changes:
Jani Sainio authored
323 for mass in m2eff:
324 if mass <0:
325 import sys
326 print 'Mass squared negative i.e. initial H too large.'
327 sys.exit()
328
329
fef582a Initial commit of PyCOOL
Jani Sainio authored
330 return m2eff
331
332
333 def V_func(lat, V):
334 "Calculate V:"
335
336 field_list = lat.field_list
337
338 from sympy import diff, Symbol, var, simplify, sympify, S, evalf
339 from sympy.utilities import lambdify
340 from sympy.core.sympify import SympifyError
341
342 C_coeff = V.C_coeff
343 D_coeff = V.D_coeff
344 V_string = V.V
345
346 try:
347 V = sympify(V_string)
348
349 except SympifyError:
350 print "Could not parse expression."
351
352 "Replacement list C_i->C_coeff[i], D_i->D_coeff[i]:"
353 rep_list = {}
354 for i in xrange(len(C_coeff)):
355 rep_list.update({'C'+str(i+1):C_coeff[i]})
356 for i in xrange(len(D_coeff)):
357 rep_list.update({'D'+str(i+1):D_coeff[i]})
358
359 V_func = lambdify(field_list,V.subs(rep_list))
360
361 return V_func
362
363 def dV_func(lat, V, field_var):
364 "Calculate dV/df:"
365
366 field_list = lat.field_list
367
368 from sympy import diff, Symbol, var, simplify, sympify, S, evalf
369 from sympy.utilities import lambdify
370 from sympy.core.sympify import SympifyError
371
372 C_coeff = V.C_coeff
373 D_coeff = V.D_coeff
374 V_string = V.V
375
376 try:
377 dV = diff(sympify(V_string),field_var)
378
379 except SympifyError:
380 print "Could not parse expression."
381
382 "Replacement list C_i->C_coeff[i], D_i->D_coeff[i]:"
383 rep_list = {}
384 for i in xrange(len(C_coeff)):
385 rep_list.update({'C'+str(i+1):C_coeff[i]})
386 for i in xrange(len(D_coeff)):
387 rep_list.update({'D'+str(i+1):D_coeff[i]})
8a6cc60 Fixed linearized evolution part. Also slightly changed curvaton Model…
Jani Sainio authored
388
fef582a Initial commit of PyCOOL
Jani Sainio authored
389 dV_func = lambdify(field_list,dV.subs(rep_list))
390
391 return dV_func
392
393 def d2V_func(lat, V, field_var):
394 "Calculate the masses of the fields in terms of the field values:"
395
396 field_list = lat.field_list
397
398 from sympy import diff, Symbol, var, simplify, sympify, S, evalf
399 from sympy.utilities import lambdify
400 from sympy.core.sympify import SympifyError
401
402 C_coeff = V.C_coeff
403 D_coeff = V.D_coeff
404 V_string = V.V
405
406 try:
407 d2V = diff(sympify(V_string),field_var,2)
408
409 except SympifyError:
410 print "Could not parse expression."
411
412 "Replacement list C_i->C_coeff[i], D_i->D_coeff[i]:"
413 rep_list = {}
414 for i in xrange(len(C_coeff)):
415 rep_list.update({'C'+str(i+1):C_coeff[i]})
416 for i in xrange(len(D_coeff)):
417 rep_list.update({'D'+str(i+1):D_coeff[i]})
418
419 d2V_func = lambdify(field_list,d2V.subs(rep_list))
420
421 return d2V_func
422
423 ###############################################################################
424 # Misc functions used when writing data to file
425 ###############################################################################
426
427 def sort_func(string):
428 "Sort file names with this function:"
429 start, i_value, end = string.split('.')
430
431 return int(i_value)
432
9781987 Two significant changes:
Jani Sainio authored
433 def make_dir(model, lat, V, sim, path = None):
fef582a Initial commit of PyCOOL
Jani Sainio authored
434 "Create a new folder for the simulation data:"
435 import os
436 import datetime
437
438 if path == None:
439 path = os.getcwd()
440
441 repl = {':':'_','.':'_','-':'_','T':'_T_'}
442
443 time_now = datetime.datetime.now().isoformat()
444 time_form = replace_all(time_now, repl)
445
446 time_text = time_now.replace('T',' ')
447
7151205 Big changes:
Jani Sainio authored
448 if model.superfolderQ:
449 data_path = path + '/data/' + model.superfolder + '/' + time_form
450 else:
451 data_path = path + '/data/' + time_form
452
fef582a Initial commit of PyCOOL
Jani Sainio authored
453 os.makedirs(data_path)
454
455 f = open(data_path + '/info.txt','w')
9781987 Two significant changes:
Jani Sainio authored
456 f.write(create_info_file(model, lat, V, sim, time_text))
fef582a Initial commit of PyCOOL
Jani Sainio authored
457 f.close()
458
459 return data_path
460
c36811c Simplified the structure of main_program.py by removing redundant steps.
Jani Sainio authored
461 def make_subdir(path, method= None, sim_number=None):
9781987 Two significant changes:
Jani Sainio authored
462 "Create a new subfolder for the simulation data:"
463 import os
464
c36811c Simplified the structure of main_program.py by removing redundant steps.
Jani Sainio authored
465 if method == 'homog':
e619416 Some changes:
Jani Sainio authored
466 data_path = path + '/homog/'
467 os.makedirs(data_path)
c36811c Simplified the structure of main_program.py by removing redundant steps.
Jani Sainio authored
468 else:
469 data_path = path + '/sim_' + str(sim_number) + '/'
470 os.makedirs(data_path)
471
9781987 Two significant changes:
Jani Sainio authored
472 return data_path
473
474
475 def create_info_file(model, lat, V, sim, time):
fef582a Initial commit of PyCOOL
Jani Sainio authored
476 "Create an info file of the simulation:"
477
478 fields0 = [field.f0_list[0] for field in sim.fields]
479 pis0 = [field.pi0_list[0] for field in sim.fields]
480
481 text = 'PyCOOL Simulation info file\n\n'
482
483 text += 'Simulation start time: ' + time + '\n\n'
484
485 text += 'Simulation model: ' + V.model_name + '\n\n'
486
487 text += 'mass m: ' + str(lat.m) + '\n'
488
489 text += 'Reduced Planck mass: ' + str(lat.mpl) + '\n\n'
490
9781987 Two significant changes:
Jani Sainio authored
491 text += 'Simulation initial time: ' + str(model.t_in*lat.m) + '/m \n'
fef582a Initial commit of PyCOOL
Jani Sainio authored
492
9781987 Two significant changes:
Jani Sainio authored
493 text += 'Simulation final time: ' + str(model.t_fin*lat.m) + '/m \n'
6943b59 Added homogeneous background solver to code.
Jani Sainio authored
494
9781987 Two significant changes:
Jani Sainio authored
495 text += 'Simulation initial scale parameter: ' + str(model.a_in) + '\n'
fef582a Initial commit of PyCOOL
Jani Sainio authored
496
497 text += ('Simulation initial radiation density: ' +
498 str(sim.rho_r0/lat.m**2) + '*m**2 \n')
499
500 text += ('Simulation initial matter density: ' +
501 str(sim.rho_m0/lat.m**2) + '*m**2 \n\n')
502
503 text += 'Is the spacetime deSitter? : ' + str(sim.deSitter) + '\n\n'
504
505 text += 'Is debugging mode on? : ' + str(lat.test) + '\n'
506
1ffd609 Fixed a critical bug that led to improper field momentum evolution.
Jani Sainio authored
507 text += 'Discretization method : ' + str(lat.discQ) + '\n'
508
509 text += 'Are gravitational waves solved? : ' + str(lat.gws) + '\n\n'
510
fef582a Initial commit of PyCOOL
Jani Sainio authored
511 text += 'Lattice size (n): ' + str(lat.n) + '\n'
512
513 text += 'Lattice side length: ' + str(lat.m*lat.L) + '/m \n'
514
515 text += 'Lattice spacing dx: ' + str(lat.m*lat.dx) + '/m \n'
516
517 text += 'Time step d\eta: ' + str(lat.m*lat.dtau) + '/m \n\n'
518
519 text += ('Initial field values: ' +
520 ', '.join([str(x) for x in fields0])
521 + '\n')
522
523 text += ('Initial field derivative values: ' +
524 ', '.join([str(x) for x in pis0])
525 + '\n\n')
526
527 if V.v_l==None:
528 V_term = 'None'
529 else:
530 V_term = ', '.join(V.v_l)
531
532 if V.v_int==None:
533 V_int_term = 'None'
534 else:
535 V_int_term = ', '.join(V.v_int)
536
537 text += ('Potential functions of the fields: ' + V_term
538 + '\n')
539 text += ('Interaction terms: ' + V_int_term
540 + '\n')
541
542 text += ('Numerical coefficients C_i: ' +
543 ', '.join([str(x) for x in V.C_coeff])
544 + '\n')
545
546 text += ('Numerical coefficients D_i: ' +
547 ', '.join([str(x) for x in V.D_coeff])
548 + '\n\n')
549
550 return text
551
552 def sim_time(time_sim, per_stp, steps, data_path):
553 "Write simulation time into info.txt file:"
554 import time, datetime
555
556 time_str = str(datetime.timedelta(seconds=time_sim))
557 per_stp_str = str(per_stp)
558
559 sim_time = ('\nSimulation finished. Time used: ' + time_str + ' Per step: ' +
560 per_stp_str + '\n')
561
562 steps = ('Number of steps taken: ' + str(steps) + '\n')
563
564 print sim_time
565
566 f = open(data_path + '/info.txt','a')
567 f.write(sim_time)
568 f.write(steps)
569 f.close()
570
571 def data_folders(path=None):
572 "Give a list of possible data folders:"
573 import os
574
575 if path == None:
576 path = os.getcwd() + '/data'
577
578 folders_l = []
579 for dirname, dirnames, filenames in os.walk(path):
cd15c37 Added option to read curvature perturbation simulation data from file.
Jani Sainio authored
580 tmp = []
581 for subdirname in dirnames:
582 #folders_l.append(os.path.join(dirname, subdirname))
583 tmp.append(os.path.join(dirname, subdirname))
584 folders_l.append(tmp)
585
586 return folders_l
587
588 #for item in os.listdir(data_path):
589 # if os.path.isdir(os.path.join(data_path, item)):
590 # print item
591
592 def sub_folders(path=None):
593 "Give a list of possible data folders:"
594 import os
595
596 if path == None:
597 path = os.getcwd() + '/data'
598
599 folders_l = []
600 for dirname, dirnames, filenames in os.walk(path):
fef582a Initial commit of PyCOOL
Jani Sainio authored
601 for subdirname in dirnames:
602 folders_l.append(os.path.join(dirname, subdirname))
603
604 return folders_l
605
cd15c37 Added option to read curvature perturbation simulation data from file.
Jani Sainio authored
606 def files_in_folder(path=None, filetype='silo', sort = True):
fef582a Initial commit of PyCOOL
Jani Sainio authored
607 "Give a list of sorted filenames in a data folder:"
608 import os
609
610 if path == None:
611 path = os.getcwd() + '/data'
612
613 #files = [path + filename for filename in os.listdir(path)]
614 files = []
615 for filename in os.listdir(path):
616 if filetype in filename:
617 files.append(path + '/' + filename)
618
cd15c37 Added option to read curvature perturbation simulation data from file.
Jani Sainio authored
619 if sort:
620 files.sort(key=sort_func)
fef582a Initial commit of PyCOOL
Jani Sainio authored
621
622 return files
623
7151205 Big changes:
Jani Sainio authored
624 def write_csv(lat, data_path, mode = 'non-lin', source = 'silo'):
fef582a Initial commit of PyCOOL
Jani Sainio authored
625 "This reads curves from a silo file and writes the data to a csv file:"
626
627 import os
628 import pyvisfile.silo as silo
629 import csv
630
e619416 Some changes:
Jani Sainio authored
631 if source == 'silo':
632
633 files = files_in_folder(path=data_path, filetype='silo')
fef582a Initial commit of PyCOOL
Jani Sainio authored
634
e619416 Some changes:
Jani Sainio authored
635 os.makedirs(data_path + '/csv')
fef582a Initial commit of PyCOOL
Jani Sainio authored
636
e619416 Some changes:
Jani Sainio authored
637 print 'Writing ' + str(len(files)) + ' cvs files.'
fef582a Initial commit of PyCOOL
Jani Sainio authored
638
e619416 Some changes:
Jani Sainio authored
639 i = 0
640 for x in files:
641 f = silo.SiloFile(x, create=False, mode=silo.DB_READ)
642 curves = f.get_toc().curve_names
fef582a Initial commit of PyCOOL
Jani Sainio authored
643
7151205 Big changes:
Jani Sainio authored
644 if lat.spect and mode == 'non-lin':
e619416 Some changes:
Jani Sainio authored
645 k_val = f.get_curve('field1'+'_S_k').x
edfa8e8 Added a new method to calculate the gravitational spectrum.
Jani Sainio authored
646 if lat.gws and mode == 'non-lin':
647 k_val2 = f.get_curve('gw_spectrum').x
7151205 Big changes:
Jani Sainio authored
648 if mode == 'non-lin':
649 t_val = f.get_curve('a').x
650 elif mode == 'homog':
651 t_val = f.get_curve('a_hom').x
e619416 Some changes:
Jani Sainio authored
652
653 f_name = data_path + '/csv/' + x.split('.')[-2] + '.csv'
654
655 csv_file = open(f_name,'w')
656 writer = csv.writer(csv_file)
edfa8e8 Added a new method to calculate the gravitational spectrum.
Jani Sainio authored
657 writer.writerow(['t_val','k_val','k_val2'] + curves)
e619416 Some changes:
Jani Sainio authored
658 writer.writerow(t_val)
7151205 Big changes:
Jani Sainio authored
659 if lat.spect and mode == 'non-lin':
c36811c Simplified the structure of main_program.py by removing redundant steps.
Jani Sainio authored
660 writer.writerow(k_val)
edfa8e8 Added a new method to calculate the gravitational spectrum.
Jani Sainio authored
661 if lat.gws and mode == 'non-lin':
662 writer.writerow(k_val2)
e619416 Some changes:
Jani Sainio authored
663 for curve in curves:
664 writer.writerow(f.get_curve(curve).y)
fef582a Initial commit of PyCOOL
Jani Sainio authored
665
e619416 Some changes:
Jani Sainio authored
666 csv_file.close()
667 f.close()
fef582a Initial commit of PyCOOL
Jani Sainio authored
668
e619416 Some changes:
Jani Sainio authored
669 i += 1
7151205 Big changes:
Jani Sainio authored
670
671
fef582a Initial commit of PyCOOL
Jani Sainio authored
672 ###############################################################################
673 # Misc CUDA functions
674 ###############################################################################
675
676 def show_GPU_mem():
677 import pycuda.driver as cuda
678
679 mem_free = float(cuda.mem_get_info()[0])
680 mem_free_per = mem_free/float(cuda.mem_get_info()[1])
681 mem_used = float(cuda.mem_get_info()[1] - cuda.mem_get_info()[0])
682 mem_used_per = mem_used/float(cuda.mem_get_info()[1])
683
684 print '\nGPU memory available {0} Mbytes, {1} % of total \n'.format(
685 mem_free/1024**2, 100*mem_free_per)
686
687 print 'GPU memory used {0} Mbytes, {1} % of total \n'.format(
688 mem_used/1024**2, 100*mem_used_per)
689
Something went wrong with that request. Please try again.