-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermal_properties.py
executable file
·837 lines (689 loc) · 31.3 KB
/
thermal_properties.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
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
#!/usr/bin/python
import pylab as pl
import os
import argparse
import o_funcs as of
import scipy.constants as constants
# cross corelation between adjacent particles.
# See paper "Spatiotemporal oscillation patterns in the collective relaxation dynamics of
# interacting particles in periodic potentials
def adj_cross_cor(ancl):
# how much are we averaging over
how_much = int(40.0*pl.pi/ancl.dt)
# array to store all the values found for each value of A so we can plot them
k_arr = pl.array([])
# array to store sweeping variables in
var_arr = pl.array([])
for i,j in enumerate(ancl.list_dir):
if 'poindat.txt' not in j: continue
print('working with file ' + str(j))
f = open(j,'r')
# Store the parameter value from the first line
cur_sweep_var = float(f.readline().split()[-1])
var_arr = pl.append(var_arr,cur_sweep_var)
# data
data = pl.genfromtxt(f)
f.close()
# velocities will be the first N columns
# We need to sort out which particle is which column. Positions will be the next N columns.
# Give this job to a seperate function. F
# Last positions will do fine
pos = pl.copy(data[-1,ancl.N:])
# define array to keep indexes in
i_arr = pl.array([])
# Now comes figuring out the indexing
for i in range(ancl.N):
i_arr = pl.append(i_arr,pos.argmin())
# set the min to be more than the max so that the next min can befound but the array retain
# its shape
pos[pos.argmin()]=pos.max()+1
print('i_arr = ' + str(i_arr))
# measure the phase corelation betwee adjacent particles.
# See paper "Spatiotemporal oscillation patterns in the collective relaxation dynamics of
# interacting particles in periodic potentials
k = 0.0
for i,j in enumerate(i_arr):
v_i = pl.copy(data[-how_much:,j])
#v_(i+1)
if (i+1) == len(i_arr):
v_ip1 = data[-how_much:,i_arr[0]]
else:
v_ip1 = data[-how_much:,i_arr[i+1]]
# These lines are just for debugging
numerator = (v_i*v_ip1).mean()*2.0
print('numerator = ' +str(numerator))
denom = ((v_i*v_i).mean() + (v_ip1*v_ip1).mean())
print('denom = ' + str(denom))
k_i = numerator/denom
#k_i = (v_i*v_ip1).mean()*2.0/((v_i*v_i).mean() + (v_ip1*v_ip1).mean())
k += k_i
k = k/ancl.N
k_arr = pl.append(k_arr,k)
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
pl.scatter(var_arr,k_arr,c='k')
#pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
ax.set_xlabel(ancl.sweep_str,fontsize=30)
ax.set_ylabel(r'$K_v$',fontsize=30)
fig.tight_layout()
fig.savefig('adj_cross_cor.png',dpi=300)
pl.close(fig)
#******************************************************************************************************************************
#******************************************************************************************************************************
# sliced specific heat. using known zero potential of slices to find full energy variance and
# using A as tempature in calculation of specific heat. (pg 254 coputational physics book).
# C = (delta E)^2/kb*T^2
def ssheat(ancl):
print('sweep must be over A!! sweep_str is: '+ancl.sweep_str)
data_file_name = 'ssheat_data.txt'
if data_file_name in os.listdir('.'):
data_file = open(data_file_name,'r')
# first line is labels
labels = data_file.readline()
plotting_data = pl.genfromtxt(data_file)
#first column sweep variables
var_arr = plotting_data[:,0]
# evergy_stuff is next coulumn
delta_E_sqrd = plotting_data[:,1]
s_heat = plotting_data[:,2]
else:
data_file = open(data_file_name,'w')
data_file.write('sweep_var delta_E_sqrd specific_heat \n')
# how much of soluton do we want to use? 1 -> all, 0 -> none
# this can be bigger than in the unsliced ones becasue transients are more or less gone after
# several PCs anyway.
how_much = .8
delta_E_sqrd = pl.array([])
s_heat = pl.array([])
var_arr = pl.array([])
for i,j in enumerate(os.listdir('.')):
next_line = ''
if 'poindat.txt' not in j:
continue
cur_file = open(j,'r')
cur_sweep_var = float(cur_file.readline().split()[-1])
cur_data=pl.genfromtxt(cur_file)
cur_file.close()
next_line += str(cur_sweep_var)+ ' '
var_arr = pl.append(var_arr,cur_sweep_var)
# slice the data so we only have data for values of t=pi(2*n + 1/2)
cur_data = of.get_zpps(cur_data,ancl.Dim,ancl.N,ancl.dt)
if ancl.Dim==1:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2
if ancl.Dim==2:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2+cur_data[int(-how_much*len(cur_data)):,ancl.N:2*ancl.N]**2
if i==0: print('shape of mag_vel_arr_sqrd'+str(pl.shape(mag_vel_arr_sqrd)))
to_sum = 0.0
to_sum_avg_en = 0.0
for a in range(len(mag_vel_arr_sqrd[0,:])):
for b in range(len(mag_vel_arr_sqrd[0,:])):
first = (mag_vel_arr_sqrd[:,a]*mag_vel_arr_sqrd[:,b]).mean()
second = (mag_vel_arr_sqrd[:,a].mean())*(mag_vel_arr_sqrd[:,b].mean())
to_sum += first - second
cur_en_stuff = to_sum/4
delta_E_sqrd = pl.append(delta_E_sqrd,cur_en_stuff)
cur_s_heat = cur_en_stuff/(ancl.N*cur_sweep_var**2)
s_heat = pl.append(s_heat,cur_s_heat)
next_line += str(cur_en_stuff)+' '+str(cur_s_heat)+ '\n'
data_file.write(next_line)
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
pl.scatter(var_arr,s_heat,c='k')
#pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
ax.set_xlabel(ancl.sweep_str,fontsize=30)
ax.set_ylabel('Specific heat per particle',fontsize=20)
#ax.set_ylim([0.0,0.2])
fig.tight_layout()
fig.savefig('specific_heat_per_particle.png',dpi=300)
pl.close(fig)
print('\a')
os.system('say finnished calculating specific heat')
# sliced is boolean
def sheat_vs_tempature(ancl):
if 'ssheat_data.txt' not in os.listdir('.'):
print('Need specific heat data')
os.system('say Need specific heat data')
if 'temp_granular_sliced.txt' not in os.listdir('.'):
print('Need granular tempature data')
os.system('say Need granular tempature data')
tempature_file = open('temp_granular_sliced.txt','r')
sheat_file = open('ssheat_data.txt','r')
# first line is labels
tempature_labels = tempature_file.readline()
tempature_plotting_data = pl.genfromtxt(tempature_file)
tempature_arr = tempature_plotting_data[:,1]
# first line is labels
sheat_labels = sheat_file.readline()
sheat_plotting_data = pl.genfromtxt(sheat_file)
#first column sweep variables
var_arr = sheat_plotting_data[:,0]
# evergy_stuff is next coulumn
delta_E_sqrd = sheat_plotting_data[:,1]
s_heat_arr = sheat_plotting_data[:,2]
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
pl.scatter(tempature_arr,s_heat_arr,c='k')
#pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
ax.set_xlabel(r'T_g',fontsize=30)
ax.set_ylabel('Specific heat per particle',fontsize=20)
fig.tight_layout()
fig.savefig('T_vs_s_heat.png',dpi=300)
pl.close(fig)
print('\a')
os.system('say finnished plotting tempature against specific heat')
def temp_granular(ancl,sliced):
if sliced:
data_file_name = 'temp_granular_sliced.txt'
save_str = 'granular_tempature_sliced.png'
else:
data_file_name = 'temp_granular_not_sliced.txt'
save_str = 'granular_tempature_not_sliced.png'
if data_file_name in os.listdir('.'):
data_file = open(data_file_name,'r')
# first line is labels
labels = data_file.readline()
plotting_data = pl.genfromtxt(data_file)
#first column sweep variables
var_arr = plotting_data[:,0]
# tempature is next coulumn
temp_arr = plotting_data[:,1]
else:
data_file = open(data_file_name,'w')
data_file.write('sweep_var granular_tempature\n')
# how much of soluton do we want to use? 1 -> all, 0 -> none
# this can be bigger than in the unsliced ones becasue transients are more or less gone after
# several PCs anyway.
how_much = .6
temp_arr = pl.array([])
var_arr = pl.array([])
for i,j in enumerate(os.listdir('.')):
next_line = ''
if 'poindat.txt' not in j:
continue
cur_file = open(j,'r')
cur_sweep_var = float(cur_file.readline().split()[-1])
cur_data=pl.genfromtxt(cur_file)
cur_file.close()
next_line += str(cur_sweep_var)+ ' '
var_arr = pl.append(var_arr,cur_sweep_var)
if sliced:
# slice the data so we only have data for values of t=pi(2*n + 1/2)
cur_data = of.get_zpps(cur_data,ancl.Dim,ancl.N,ancl.dt)
if ancl.Dim==1:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2
if ancl.Dim==2:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2+cur_data[int(-how_much*len(cur_data)):,ancl.N:2*ancl.N]**2
if i==0: print('shape of mag_vel_arr_sqrd'+str(pl.shape(mag_vel_arr_sqrd)))
cur_temp = mag_vel_arr_sqrd.sum()/ancl.N
temp_arr = pl.append(temp_arr,cur_temp)
next_line += str(cur_temp)+ '\n'
data_file.write(next_line)
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
pl.scatter(var_arr,temp_arr,c='k')
#pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
ax.set_xlabel(ancl.sweep_str,fontsize=30)
ax.set_ylabel(r'$T_g$',fontsize=30)
fig.tight_layout()
fig.savefig(save_str,dpi=300)
pl.close(fig)
data_file.close()
print('\a')
os.system('say finnished calculating granular tempature')
def diffusion_coef(ancl,f):
# cur_poin_num = int(f[:f.find('p')])
# if (str(cur_poin_num)+'RunImages') not in os.listdir('.'):
# os.mkdir(str(cur_poin_num)+'RunImages')
print('dimension: '+str(ancl.Dim))
# to_save_dir = str(cur_poin_num)+'RunImages/TauACF_Var_'+v
# os.mkdir(to_save_dir)
work_file = open(f,'r')
print('working file is: ' +str(work_file))
sweep_var = float(work_file.readline().split()[-1])
print('sweep variable is: ' + str(sweep_var))
data = pl.genfromtxt(work_file)
print('shape of data is: ' + str(pl.shape(data)))
work_file.close()
# depending on the variable we want we need a number that controles how we slice the data
# lines. With the dimension of the system we can slice everything right. Can get the dimension with the
# following line.
# For including the average of all. NOT DONE YET HERE
diffusion_arr = pl.array([])
# make em for every particle in the simulation
for a in range(ancl.N):
# can use the dimension to slice everything right
cur_x = data[:,ancl.Dim*ancl.N+a]
if ancl.Dim ==2:
cur_y = data[:,(ancl.Dim+1)*ancl.N+a]
distance_arr = pl.sqrt(cur_x**2 + cur_y**2)
else:
distance_arr = cur_x
#print('shape of distance array: ' + str(pl.shape(input_arr)))
# This equation generaly holds and for now this is how we are going to calculate the
# diffusion coefficien:
# <x^2>=q*D*t where q is numerical constant that depends on dimesionality. q=2*ancl.Dim. D is the
# diffusion coefficient, and t is the time for which <x^2 is calculated>
# this and some usefull equations from
# http://www.life.illinois.edu/crofts/bioph354/diffusion1.html
# So we can find D
dist_arr_sqrd = distance_arr**2
mean_sqrd_dist = dist_arr_sqrd.mean()
total_time = len(distance_arr)*ancl.dt
Diff_coef = mean_sqrd_dist/(2.0*ancl.Dim*total_time)
print('Diffusion coefficient for particle ' + str(a) + ' = ' + str(Diff_coef))
# Lets also try to print a tempature from the equation D = kT/f. T -> Absolute tempature.
# k -> boltzman constat. f -> frictional constant (beta)
Temp = Diff_coef * ancl.beta
print('Tempature from Diffusion coef = ' +str(Temp))
print('\a')
print('\a')
#def kenetic_energy():
# qq,dt,beta,A,cycles,N,x_num_cell,y_num_cell,order,sweep_str,Dim = of.get_system_info()
# # how much of soluton do we want to use? 1 -> all 0 -> none
# how_much = .2
#
# averages= pl.array([])
# var_arr = pl.array([])
# # See paper j. chem phys., vol 120, No 1, 1 Jan 2004
# energy_stuff = pl.array([])
# for i,j in enumerate(os.listdir('.')):
# if 'poindat.txt' not in j:
# continue
# cur_file = open(j,'r')
# cur_sweep_var = float(cur_file.readline().split()[-1])
# cur_data=pl.genfromtxt(cur_file)
# cur_file.close()
#
# var_arr = pl.append(var_arr,cur_sweep_var)
#
# if ancl.Dim==1:
# mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:N]**2
# if ancl.Dim==2:
# mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:N]**2+cur_data[int(-how_much*len(cur_data)):,N:2*N]**2
# if i==0: print('shape of mag_vel_arr_sqrd'+str(pl.shape(mag_vel_arr_sqrd)))
#
# to_sum = 0.0
# to_sum_avg_en = 0.0
# for a in range(len(mag_vel_arr_sqrd[0,:])):
# for b in range(len(mag_vel_arr_sqrd[0,:])):
# first = (mag_vel_arr_sqrd[:,a]*mag_vel_arr_sqrd[:,b]).mean()
# second = (mag_vel_arr_sqrd[:,a].mean())*(mag_vel_arr_sqrd[:,b].mean())
#
# to_sum += first - second
# to_sum_avg_en += second
#
# #print('to_sum: ' +str(to_sum))
# #print('to_sum_avg_en: ' +str(to_sum_avg_en))
# energy_stuff = pl.append(energy_stuff,to_sum/to_sum_avg_en)
#
# # this is more or less wrong. you could find the varience and the eaverage but for the
# # enerygy you need to sum the KE of each particle. look as second varible.
# #avg_mag_vel_sqrd = mag_vel_arr_sqrd.mean()
#
# averages = pl.append(averages,pl.sqrt(to_sum_avg_en))
#
# fig = pl.figure()
# ax = fig.add_subplot(111)
# pl.scatter(var_arr,averages/2)
# #ax.set_xlim([.5,1.5])
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(r'$\langle v^2 \rangle / 2$',fontsize=30)
# fig.tight_layout()
# fig.savefig('v_sqrd_avg.png',dpi=300)
# pl.close(fig)
#
# fig = pl.figure()
# ax = fig.add_subplot(111)
# # deided by 4 comes from KE -> (1/2)**2
# pl.scatter(var_arr,energy_stuff/4)
# #ax.set_xlim([.5,1.5])
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(r'$\frac{\langle KE^2 \rangle - \langle KE \rangle ^ 2}{\langle KE \rangle ^ 2}$',fontsize=30)
# fig.tight_layout()
# fig.savefig('energy_stuff.png',dpi=300)
# pl.close(fig)
def frequency(ancl,f):
print('This function is NNOOOOTTT done yet')
# We know that the energy of the system when t=n pi/2 is only KE because the potential U(x,t) is
# flat at those times. We need to slice at t=pi(2*n + 1/2) in order to actualy et PC sections though.
def energy_fluctuation(ancl,keyword):
avg_save_str = 'avg_energy_stuff'
en_stuff_save_str = 'energy_stuff_'
if keyword == 'slice':
average_y_lbl = r"$ \langle E' \rangle $"
en_stuff_y_lbl = r"$\frac{\langle E' ^2 \rangle - \langle E' \rangle ^ 2}{\langle E' \rangle ^ 2}$"
avg_save_str = 'sliced_E_'+avg_save_str
en_stuff_save_str = 'sliced_E_' +en_stuff_save_str
if keyword == 'ke':
average_y_lbl = r'$ \langle KE \rangle $'
en_stuff_y_lbl = r'$\frac{\langle KE^2 \rangle - \langle KE \rangle ^ 2}{\langle KE \rangle ^ 2}$'
if keyword == 'slice': data_file_name = 'sliced_energy_data.txt'
if keyword == 'ke': data_file_name = 'ke_energy_data.txt'
if data_file_name in os.listdir('.'):
data_file = open(data_file_name,'r')
# first line is labels
labels = data_file.readline()
plotting_data = pl.genfromtxt(data_file)
#first column sweep variables
var_arr = plotting_data[:,0]
# evergy_stuff is next coulumn
energy_stuff_1 = plotting_data[:,1]
# energy_stuff_2 = plotting_data[:,2]
averages_1 = plotting_data[:,2]
# averages_2 = plotting_data[:,4]
# std_arr is only for averages_2
#std_arr = plotting_data[:,5]
else:
data_file = open(data_file_name,'w')
# data_file.write('sweep_var energy_stuff_1 energy_stuff_2 averages_1 averages_2 standard_dev\n')
data_file.write('sweep_var energy_stuff_1 averages_1 standard_dev\n')
# how much of soluton do we want to use? 1 -> all, 0 -> none
# this can be bigger than in the unsliced ones becasue transients are more or less gone after
# several PCs anyway.
how_much = .5
# See paper j. chem phys., vol 120, No 1, 1 Jan 2004
# energy_stuff_1 and averages_1 do not asume that the velocites are independently
# distributed. These use above paper eqn 14
# energy_sruff_2 and averages_2 assume this is a thermal system and use above paper eqn 15
energy_stuff_1 = pl.array([])
# energy_stuff_2 = pl.array([])
var_arr = pl.array([])
averages_1 = pl.array([])
# averages_2 = pl.array([])
std_arr = pl.array([])
for i,j in enumerate(ancl.list_dir):
print('working with file ' + str(j))
next_line = ''
cur_file = open(j,'r')
cur_sweep_var = float(cur_file.readline().split()[-1])
cur_data=pl.genfromtxt(cur_file)
cur_file.close()
next_line += str(cur_sweep_var)+ ' '
var_arr = pl.append(var_arr,cur_sweep_var)
if keyword == 'slice':
# slice the data so we only have data for values of t=pi(2*n + 1/2)
cur_data = of.get_zpps(cur_data,ancl.Dim,ancl.N,ancl.dt)
# For slices at t=0 use below
#cur_data = of.get_mpps(cur_data,ancl.Dim,ancl.N,ancl.dt)
if ancl.Dim==1:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2
if ancl.Dim==2:
mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:ancl.N]**2+cur_data[int(-how_much*len(cur_data)):,ancl.N:2*ancl.N]**2
if i==0: print('shape of mag_vel_arr_sqrd'+str(pl.shape(mag_vel_arr_sqrd)))
# cur_en_stuff_2 = N*((mag_vel_arr_sqrd**2).mean() - (mag_vel_arr_sqrd.mean())**2)/((mag_vel_arr_sqrd.mean())**2)/4
# energy_stuff_2 = pl.append(energy_stuff_2, cur_en_stuff_2)
# cur_av_2 = pl.sqrt(N*mag_vel_arr_sqrd.mean()**2/4)
# averages_2 = pl.append(averages_2,cur_av_2)
print('mag_vel_arr_sqrd: ' +str(mag_vel_arr_sqrd))
# cur_std = (mag_vel_arr_sqrd/2.0).std()
# std_arr = pl.append(std_arr,cur_std)
to_sum = 0.0
to_sum_avg_en = 0.0
for a in range(len(mag_vel_arr_sqrd[0,:])):
for b in range(len(mag_vel_arr_sqrd[0,:])):
first = (mag_vel_arr_sqrd[:,a]*mag_vel_arr_sqrd[:,b]).mean()
print('first: ' + str(first))
second = (mag_vel_arr_sqrd[:,a].mean())*(mag_vel_arr_sqrd[:,b].mean())
print('second: ' + str(second))
to_sum += first - second
print('in loop to_sum: ' +str(to_sum))
to_sum_avg_en += second
print('in loop to_sum_avg_en: ' +str(to_sum_avg_en))
print('after loop to_sum: ' +str(to_sum))
print('after loop to_sum_avg_en: ' +str(to_sum_avg_en))
cur_en_stuff_1 = to_sum/to_sum_avg_en/4
energy_stuff_1 = pl.append(energy_stuff_1,cur_en_stuff_1)
cur_av_1 = pl.sqrt(to_sum_avg_en/4/ancl.N)
averages_1 = pl.append(averages_1,cur_av_1)
# next_line += str(cur_en_stuff_1)+' '+str(cur_en_stuff_2)+' '+str(cur_av_1)+ \
# ' '+str(cur_av_2)+' '+str(cur_std)+'\n'
next_line += str(cur_en_stuff_1)+' '+str(cur_av_1)+'\n'
data_file.write(next_line)
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
pl.scatter(var_arr,averages_1,c='k')
#pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
ax.set_xlabel(ancl.sweep_str,fontsize=30)
ax.set_ylabel(average_y_lbl,fontsize=30)
fig.tight_layout()
fig.savefig(avg_save_str+'.png',dpi=300)
pl.close(fig)
fig = pl.figure()
ax = fig.add_subplot(111)
pl.scatter(var_arr,energy_stuff_1,c='k')
#pl.scatter(var_arr,energy_stuff_2,c='b')
#ax.set_xlim([0.0,1.6])
if ancl.y_upper_lim != None: ax.set_ylim([0.0,ancl.y_upper_lim])
if (ancl.x_upper_lim != None) & (ancl.x_lower_lim != None):
ax.set_xlim([ancl.x_lower_lim,ancl.x_upper_lim])
#ax.set_xlim([.5,1.0])
#ax.set_ylim([0,.24])
ax.set_xlabel(ancl.sweep_str,fontsize=30)
ax.set_ylabel(en_stuff_y_lbl,fontsize=30)
fig.tight_layout()
fig.savefig(en_stuff_save_str+'1.png',dpi=300)
pl.close(fig)
# fig = pl.figure()
# ax = fig.add_subplot(111)
# pl.scatter(var_arr,energy_stuff_2,c='b')
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(en_stuff_y_lbl,fontsize=30)
# #ax.set_xlim([.5,1.5])
# #ax.set_ylim([0,.03])
# fig.tight_layout()
# fig.savefig(en_stuff_save_str+'2.png',dpi=300)
# pl.close(fig)
print('\a')
def spatio_temporal(ancl):
os.mkdir('SpatioTemporalVels')
print('RIGHT NOW THIS IS ONLY FOR VX!!!!!!!')
p_arr = pl.arange(0,ancl.N)
# How many cycles do we want to look at?
how_many = 10
var_arr = pl.array([])
for i,j in enumerate(os.listdir('.')):
if 'poindat.txt' not in j:
continue
print('working on file ' + j)
poin_num = int(j[:j.find('p')])
cur_file = open(j,'r')
cur_sweep_var = float(cur_file.readline().split()[-1])
cur_data=pl.genfromtxt(cur_file)
cur_file.close()
var_arr = pl.append(var_arr,cur_sweep_var)
count = 0
grid = cur_data[-int(how_many*2.0*pl.pi/ancl.dt):,:ancl.N]
# in 1D because particles never cross eachother we can order them in the images to mathch
# their physical order.
grid_ordered = pl.zeros(pl.shape(grid))
# can just use the initial conditions to figure out where each is
init_x = cur_data[0,ancl.N:2*ancl.N]
sorted_x = sorted(init_x)
for a,alpha in enumerate(sorted_x):
for b,beta in enumerate(init_x):
if alpha == beta:
grid_ordered[:,a]=grid[:,b]
print('shape of grid_ordered: ' + str(pl.shape(grid_ordered)))
fig = pl.figure()
ax = fig.add_subplot(111)
# form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
ax.imshow(grid_ordered,interpolation="nearest", aspect='auto')
ax.set_xlabel('Particle',fontsize=30)
#ax.set_aspect('equal')
ax.set_ylabel(r'$ t $',fontsize=30)
fig.tight_layout()
fig.savefig('SpatioTemporalVels/%(number)04d.png'%{'number':poin_num})
pl.close(fig)
# slice the data so we only have data for values of t=pi(2*n + 1/2)
# new_data = pl.array([])
# for i in range(len(cur_data)):
# check_time = i*dt%(pl.pi*2.0)
# if check_time < dt and check_time > 0.0:
# new_data = pl.append(new_data,cur_data[i,:])
#
# cur_data = new_data.reshape(-1,ancl.Dim*2*N)
#
# if ancl.Dim==1:
# mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:N]**2
# if ancl.Dim==2:
# mag_vel_arr_sqrd = cur_data[int(-how_much*len(cur_data)):,:N]**2+cur_data[int(-how_much*len(cur_data)):,N:2*N]**2
# if i==0: print('shape of mag_vel_arr_sqrd'+str(pl.shape(mag_vel_arr_sqrd)))
#
# cur_en_stuff_2 = N*((mag_vel_arr_sqrd**2).mean() - (mag_vel_arr_sqrd.mean())**2)/((mag_vel_arr_sqrd.mean())**2)/4
# energy_stuff_2 = pl.append(energy_stuff_2, cur_en_stuff_2)
#
# cur_av_2 = pl.sqrt(N*mag_vel_arr_sqrd.mean()**2/4)
# averages_2 = pl.append(averages_2,cur_av_2)
# cur_std = pl.sqrt((N*mag_vel_arr_sqrd**2/4).std())
# std_arr = pl.append(std_arr,cur_std)
#
# to_sum = 0.0
# to_sum_avg_en = 0.0
# for a in range(len(mag_vel_arr_sqrd[0,:])):
# for b in range(len(mag_vel_arr_sqrd[0,:])):
# first = (mag_vel_arr_sqrd[:,a]*mag_vel_arr_sqrd[:,b]).mean()
# second = (mag_vel_arr_sqrd[:,a].mean())*(mag_vel_arr_sqrd[:,b].mean())
#
# to_sum += first - second
# to_sum_avg_en += second
#
# #print('to_sum: ' +str(to_sum))
# #print('to_sum_avg_en: ' +str(to_sum_avg_en))
# cur_en_stuff_1 = to_sum/to_sum_avg_en/4
# energy_stuff_1 = pl.append(energy_stuff_1,cur_en_stuff_1)
#
#
# cur_av_1 = pl.sqrt(to_sum_avg_en/4)
# averages_1 = pl.append(averages_1,cur_av_1)
#
# next_line += str(cur_en_stuff_1)+' '+str(cur_en_stuff_2)+' '+str(cur_av_1)+ \
# ' '+str(cur_av_2)+' '+str(cur_std)+'\n'
# data_file.write(next_line)
#
# fig = pl.figure()
# ax = fig.add_subplot(111)
# # form of errorbar(x,y,xerr=xerr_arr,yerr=yerr_arr)
# pl.scatter(var_arr,averages_1,c='r')
# pl.errorbar(var_arr,averages_2,yerr=std_arr,c='b',ls='none',fmt='o')
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(r'$ \langle E \rangle $',fontsize=30)
# fig.tight_layout()
# fig.savefig('sliced_E_avg.png',dpi=300)
# pl.close(fig)
#
# fig = pl.figure()
# ax = fig.add_subplot(111)
# # deided by 4 comes from KE -> (1/2)**2
# pl.scatter(var_arr,energy_stuff_1,c='r')
# #pl.scatter(var_arr,energy_stuff_2,c='b')
# #ax.set_xlim([0.0,1.6])
# #ax.set_ylim([0.0,.04])
# #ax.set_xlim([.5,1.5])
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(r'$\frac{\langle E^2 \rangle - \langle E \rangle ^ 2}{\langle E \rangle ^ 2}$',fontsize=30)
# fig.tight_layout()
# fig.savefig('sliced_energy_stuff_1.png',dpi=300)
# pl.close(fig)
#
# fig = pl.figure()
# ax = fig.add_subplot(111)
# # deided by 4 comes from KE -> (1/2)**2
# pl.scatter(var_arr,energy_stuff_2,c='b')
# ax.set_xlabel(ancl.sweep_str,fontsize=30)
# ax.set_ylabel(r'$\frac{\langle E^2 \rangle - \langle E \rangle ^ 2}{\langle E \rangle ^ 2}$',fontsize=30)
# fig.tight_layout()
# fig.savefig('sliced_energy_stuff_2.png',dpi=300)
# pl.close(fig)
#
# print('\a')
def main():
parser = argparse.ArgumentParser()
# d is for directory
parser.add_argument('-d',action='store',dest = 'd',type = str, required = False, default = './')
# f is for file this is needed for make_acf_tau_plot()
parser.add_argument('-f',action='store',dest = 'f',type = str, required = False)
# plot type
parser.add_argument('-t',action='store',dest = 't',type = str,required = True)
# This is going to be a unique option to collect AAAALLLLLL the data of several individual
# bifurcation runs (everything the same except random initial conditions) into one so that the
# diagram does not look so messy. The argument being passed is a directory --> no default
# option.
parser.add_argument('--together',action='store',dest='together',type = bool, required = False, default=False)
# So we can set the y upper lim without going into the program
parser.add_argument('--yu',action='store',dest='yu',type = float, required = False, default=None)
# So we can set the x lower lim without going into the program
parser.add_argument('--xl',action='store',dest='xl',type = float, required = False, default=None)
# So we can set the x upper lim without going into the program
parser.add_argument('--xu',action='store',dest='xu',type = float, required = False, default=None)
inargs = parser.parse_args()
together = inargs.together
d = inargs.d
f = inargs.f
plot_type = inargs.t
y_upper_lim = inargs.yu
x_lower_lim = inargs.xl
x_upper_lim = inargs.xu
os.chdir(d)
print('changed directory to'+ d)
# This is also a single particle operation. Lets make a directory and have an individual image
# for each run.
# ancl --> anal class
ancl = of.anal_run()
ancl.together = together
ancl.get_info()
ancl.set_list_dir()
ancl.y_upper_lim = y_upper_lim
ancl.x_lower_lim = x_lower_lim
ancl.x_upper_lim = x_upper_lim
# note: if ancl.Dim = 1 y_num_cell -> ' No y ' and order -> 'polygamma'
print('ancl.Dim is: ' +str(ancl.Dim))
print('ancl.x_num_cell: ' + str(ancl.x_num_cell))
if plot_type == 'diffusion':
print('calling diffusion_coef(f)')
diffusion_coef(ancl,f)
if plot_type == 'ke':
print('calling energy_fluctuation(ke)')
energy_fluctuation(ancl,'ke')
if plot_type == 'frequency':
print('calling frequency')
frequency(ancl,f)
# We know that the energy of the system when t=n pi/2 is only KE because the potential U(x,t) is
# flat at those times. We are going to aslo plot these results as a way fo observing total
# energy
if plot_type == 'sliced_E':
print('calling energy_fluctuation(slice)')
energy_fluctuation(ancl,'slice')
if plot_type =='st':
print('calling spatio_temporal')
spatio_temporal(ancl)
# sliced specific heat. using known zero potential of slices to find full energy variance and
# using A as tempature in calculation of specific heat. (pg 254 coputational physics book).
# C = (delta E)^2/kb*T^2
if plot_type == 'ssheat':
print('calling ssheat()')
ssheat(ancl)
if plot_type == 'temp_sliced':
temp_granular(ancl,True)
if plot_type == 'temp_not_sliced':
temp_granular(ancl,False)
if plot_type == 'sheat_v_temp':
sheat_vs_tempature(ancl)
if plot_type == 'adj_cross':
adj_cross_cor(ancl)
if __name__ == '__main__':
main()
# fig = pl.figure()
# ax = fig.add_subplot(111)
# #ax.set_xlim(x_rng)
# #ax.set_ylim(y_rng)
# ax.set_xlabel(x_lbl,fontsize=30)
# ax.set_ylabel(y_lbl,fontsize=30)
# ax.scatter(tau_arr,output_arr,c='k')
# fig.tight_layout()
# fig.savefig(to_save_dir+'/%(number)04d.png'%{'number':cur_poin_num})
# pl.close(fig)