Repository navigation
Expand file tree
/
Copy pathanalyse3d.py
More file actions
executable file
·824 lines (618 loc) · 25.6 KB
/
Copy pathanalyse3d.py
File metadata and controls
executable file
·824 lines (618 loc) · 25.6 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
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
from pyPLUTO import nlast_info
import pyPLUTO.pload as pp
import numpy as np
import json
import tools3d as too
import math as m
def alphaRphiAverage(**kwargs):
''' calculate \alpha_r,phi disk viscosity parameter
Parameters
----------
tbeg : begin time value in file numbers (default:0)
tend : end time value in file numbers (default: nlast)
**kwargs: kwargs for setCompRange() in tools3d
Returns
-------
Dictionary with alpha averages:
Keywords: merAv -- 2D alpha values map, averaged over phi direction
RmerAv -- 1D alpha values in meridional directions, average over r and phi direction
Timeser -- Alpha values timeseries, averages over all spatial directions
TimeserMov -- Alpha values moving average timeseries, averages over all spatial directions
'''
#fetch time info and set analysis times
timeInfo = nlast_info()
tbeg = kwargs.get('tbeg',0)
tend = kwargs.get('tend',timeInfo['nlast'])
dt = tend-tbeg+1
rhoav = kwargs.get('rhoav',False)
#fetch grid info and set analysis domain
data = pp.pload(0)
data = too.setCompRange(data,**kwargs)
#set data structure & define arrays
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx1m1 = 1.0/(1.0*nx1)
nx2m1 = 1.0/(1.0*nx2)
nx3m1 = 1.0/(1.0*nx3)
dx1 = data.dx1
dx2 = data.dx2
dx3 = data.dx3[None,None,:]
#dx1 = data.x1*data.x1*data.dx1
deltax1= np.sum(data.dx1)
# deltax2=np.sum(data.dx2)
deltax3=np.sum(data.dx3)
#deltax1 = np.sum(dx1)
rhomean = np.zeros((nx1,nx2))
rhota = np.zeros((nx1,nx2))
rho1d = np.zeros(nx2)
rho1dta = np.zeros(nx2)
vx1vx3rhomean = np.zeros((nx1,nx2))
vx1vx3rhota = np.zeros((nx1,nx2))
vx1rhomean = np.zeros((nx1,nx2))
vx1rhota = np.zeros((nx1,nx2))
vx3mean = np.zeros((nx1,nx2))
vx3ta = np.zeros((nx1,nx2))
csmean = np.zeros((nx1,nx2))
csta = np.zeros((nx1,nx2))
alpha2d = np.zeros((nx1,nx2))
alpha2dta =np.zeros((nx1,nx2))
alpha1dth = np.zeros(nx2)
alpha1dmov = np.zeros(nx2)
alphaTs = np.zeros(dt)
alphaTsMov = np.zeros(dt)
for tt in range(0,dt):
data = pp.pload(tt+tbeg)
data = too.setCompRange(data,**kwargs)
ntm1 = 1.0/(1.0+tt)
# calculating phi,time averaged alpha(r,phi)
rhomean = np.sum(data.rho, axis=2)*nx3m1
csmean = np.sum(np.sqrt(data.prs/data.rho),axis=2)*nx3m1
vx1vx3rhomean = np.sum(data.vx1*data.vx3*data.rho*dx3,axis=2)/deltax3
vx1rhomean = np.sum(data.vx1*data.rho*dx3,axis=2)/deltax3
if rhoav:
vx3mean = np.sum(data.vx3*data.rho, axis=2)*nx3m1/rhomean
else:
vx3mean = np.sum(data.vx3, axis=2)*nx3m1
rhota += rhomean
vx1vx3rhota += vx1vx3rhomean
vx1rhota += vx1rhomean
vx3ta += vx3mean
csta += csmean
alpha2d = (vx1vx3rhomean - vx1rhomean*vx3mean)/(csmean*csmean*rhomean)
alpha2dta = (vx1vx3rhota*ntm1 - vx1rhota*ntm1*vx3ta*ntm1)/(csta*ntm1*csta*ntm1*rhota*ntm1)
# calculating density averaged radial average of alpha(r,theta)
# rho1d = np.sum(rhomean[:,j]*dx1)/deltax1
# rho1dta = np.sum(rhota[:,j]*dx1)*dtm1/deltax1
# alpha1dth = np.sum(alpha2d*rhomean*dx1[:,None], axis=0)/np.sum(rhomean*dx1[:,None], axis=0)
# alpha1dmov = np.sum(alpha2dta*rhota*dx1[:,None], axis=0)/np.sum(rhota*dx1[:,None], axis=0)
# calculating density averaged r,theta average of alpha
alphaTs[tt] = np.sum(alpha2d*rhomean*(data.x1*dx1)[:,None]*dx2[None,:])/np.sum(rhomean*(data.x1*dx1)[:,None]*dx2[None,:])
alphaTsMov[tt] = np.sum(alpha2dta*rhota*ntm1*(data.x1*dx1)[:,None]*dx2[None,:])/np.sum(rhota*ntm1*(data.x1*dx1)[:,None]*dx2[None,:])
ntm1 = 1.0/(1.0+dt)
# radial average of <alpha>_phi,t
alpha2d = (vx1vx3rhota*ntm1 - vx1rhota*ntm1*vx3ta*ntm1)/(csta*ntm1*csta*ntm1*rhota*ntm1)
alpha1dth = np.sum(alpha2d*rhota*ntm1*dx1[:,None], axis=0)/np.sum(rhota*ntm1*dx1[:,None], axis=0)
alphaDict = {}
alphaDict["merAv"] = alpha2d
alphaDict["RmerAv"]= alpha1dth
alphaDict["Timeser"]= alphaTs
alphaDict["TimeserMov"]= alphaTsMov
return alphaDict
def alphaZphiAverage(gamma,q,**kwargs):
''' calculate \alpha_z,phi disk viscosity proxy for vsi profile with constant temp. slope q.
UNDER CONSTRUCTION!!!!!
Parameters
----------
gamma : adiabatic constant
q : Temperature gradient slope
tbeg : begin time value in file numbers (default:0)
tend : end time value in file numbers (default: nlast)
**kwargs: kwargs for setCompRange() in tools3d
'''
#fetch time info and set analysis times
timeInfo = nlast_info()
tbeg = kwargs.get('tbeg',0)
tend = kwargs.get('tend',timeInfo['nlast'])
dt = tend-tbeg+1
#fetch grid info and set analysis domain
data = pp.pload(0)
data = too.setCompRange(data,**kwargs)
#set data structure & define arrays
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx1m1 = 1.0/(1.0*nx1)
nx2m1 = 1.0/(1.0*nx2)
nx3m1 = 1.0/(1.0*nx3)
dx1 = data.dx1
dx3 = data.dx3[None,None,:]
deltax1 = np.sum(data.dx1)
deltax3 = np.sum(data.dx3)
rhomean = np.zeros((nx1,nx2))
rhota = np.zeros((nx1,nx2))
rho1d = np.zeros(nx2)
rho1dta = np.zeros(nx2)
vx2vx3rhomean = np.zeros((nx1,nx2))
vx2vx3rhota = np.zeros((nx1,nx2))
vx2rhomean = np.zeros((nx1,nx2))
vx2rhota = np.zeros((nx1,nx2))
vx3mean = np.zeros((nx1,nx2))
vx3ta = np.zeros((nx1,nx2))
csmean = np.zeros((nx1,nx2))
csta = np.zeros((nx1,nx2))
alpha2d = np.zeros((nx1,nx2))
alpha2dta =np.zeros((nx1,nx2))
alpha1dth = np.zeros(nx2)
alpha1dmov = np.zeros(nx2)
alphaTs = np.zeros(dt)
alphaTsMov = np.zeros(dt)
for tt in range(0,dt):
data = pp.pload(tt+tbeg)
data = too.setCompRange(data,**kwargs)
ntm1 = 1.0/(1.0+tt)
# calculating phi,time averaged alpha(r,phi)
rhomean = np.sum(data.rho,axis=2)*nx3m1
vx2vx3rhomean = np.sum(data.vx2*data.vx3*data.rho*dx3,axis=2)/deltax3
vx2rhomean = np.sum(data.vx2*data.rho*dx3,axis=2)/deltax3
vx3mean = np.sum(data.vx3*dx3,axis=2)/deltax3
csmean = np.sum(np.sqrt(gamma*data.prs/data.rho)*dx3,axis=2)/deltax3
rhota += rhomean
vx2vx3rhota += vx2vx3rhomean
vx2rhota += vx2rhomean
vx3ta += vx3mean
csta += csmean
# z/R = cos(th)/sin(th)=0 at z=0. Use max(denominator,1e-20) to compensate
alpha2d = (vx2vx3rhomean - vx2rhomean*vx3mean)/np.max(csmean*csmean*rhomean*q/2.*(np.cos(data.x2)/np.sin(data.x2))[None,:],1.0e-20)
alpha2dta = (vx2vx3rhota*ntm1 - vx2rhota*ntm1*vx3ta*ntm1)/np.max(csta*ntm1*csta*ntm1*rhota*ntm1*q/2.*(np.cos(data.x2)/np.sin(data.x2))[None,:],1.0e-20)
# calculating density averaged radial average of alpha(r,theta)
# rho1d = np.sum(rhomean*dx1[:,None],axis=0)/deltax1
# rho1dta = np.sum(rhota*dx1[:,None],axis=0)*dtm1/deltax1
# alpha1dth = np.sum(alpha2d*dx1[:,None],axis=0)/deltax1
# alpha1dmov = np.sum(alpha2dta*dx1[:,None],axis=0)/deltax1
# calculating density averaged r,theta average of alpha
alphaTs[tt] = np.sum(alpha2d*rhomean*(data.x1*dx1)[:,None]*dx2[None,:])/np.sum(rhomean*(data.x1*dx1)[:,None]*dx2[None,:])
alphaTsMov[tt] = np.sum(alpha2dta*rhota/ntm1*(data.x1*dx1)[:,None]*dx2[None,:])/np.sum(rhota/ntm1*(data.x1*dx1)[:,None]*dx2[None,:])
ntm1 = 1.0/(1.0+dt)
alpha2d = (vx2vx3rhota*ntm1 - vx2rhota*ntm1*vx3ta*ntm1)/np.max(csta*ntm1*csta*ntm1*rhota*ntm1*q/2.*(np.cos(data.x2)/np.sin(data.x2))[None,:],1.0e-20)
# radial average of <alpha>_phi,t
alpha1dth = np.sum(alpha2d*rhota/ntm1*dx1[:,None], axis=0)/np.sum(rhota/ntm1*dx1[:,None], axis=0)
alphaDict = {}
alphaDict["merAv"] = alpha2d
alphaDict["RmerAv"]= alpha1dth
alphaDict["Timeser"]= alphaTs
alphaDict["TimeserMov"]= alphaTsMov
return alphaDict
def kappaSq(data):
''' calculate the epicyclic frequency of a disk
Parameters
----------
data: a pyPLUTO data object
return
------
kappasq: 3d array of epicyclic frequencies
omega: 3d array of angular frequencies
'''
omega = np.zeros((data.n1,data.n2,data.n3))
omegadr = np.zeros((data.n1,data.n2,data.n3))
kappasq = np.zeros((data.n1,data.n2,data.n3))
for i in data.irange:
for j in data.jrange:
for k in data.krange:
omega[i,j,k] = data.vx3[i,j,k]/data.x1[i]
# print 'Done omega'
for i in range(1,data.n1-1):
for j in data.jrange:
for k in data.krange:
#print i,j,k
#print omega[i,j,k]
omegadr[i,j,k] = (omega[i+1,j,k] - omega[i-1,j,k])/(data.x1[i+1]-data.x1[i-1])
kappasq[i,j,k] = 4.0*omega[i,j,k]*omega[i,j,k] + 2*data.x1[i]*omega[i,j,k]*omegadr[i,j,k]
omegadr[0,:,:] = omegadr[1,:,:]
kappasq[0,:,:] = kappasq[1,:,:]
omegadr[data.n1-1,:,:] = omegadr[data.n1-2,:,:]
kappasq[data.n1-1,:,:] = kappasq[data.n1-2,:,:]
return kappasq,omega
def rossbyL(data,gamma=1.0):
''' Calculate the function L(R) indicating rossby instability at its extrema
Parameters:
----------
data: a pyPLUTO data object
gamma: the adiabatic index of the model
'''
ksq,omeg = kappaSq(data)
rhor = np.average(data.rho,axis=(1,2))
prsr = np.average(data.prs,axis=(1,2))
ksqr = np.average(ksq,axis=(1,2))
omegr = np.average(omeg,axis=(1,2))
L = rhor*omegr/ksqr * np.power(prsr/np.power(rhor,gamma),2.0/gamma)
return L
def rossbyLTser(**kwargs):
''' Calculate the function L(R,T) indicating rossby instability at its extrema
Parameters:
----------
gamma: the adiabatic index of the model
tbeg: begin timestep, default is 0
tend: end timestep, default is nlast
kwargs: all other kwargs go to setCompRange in tools3d
return:
------
L: function L as function of radius and time coordinates
'''
gamma = kwargs.get('gamma',1.0)
#fetch time info and set analysis times
timeInfo = nlast_info()
tbeg = kwargs.get('tbeg',0)
tend = kwargs.get('tend',timeInfo['nlast'])
dt = tend-tbeg+1
#fetch grid info and set analysis domain
data = pp.pload(0)
data = too.setCompRange(data,**kwargs)
L = np.zeros((dt,data.n1))
for tt in range(0,dt):
data = pp.pload(tt+tbeg)
data = too.setCompRange(data,**kwargs)
L[tt,:] = rossbyL(data,gamma)
return L
def rhovrAverage(tbeg,tend,**kwargs):
'''
calculate non-weighted averages for radial mass flux
Parameters:
-----------
tbeg : beginning of time average
tend : end of time average
kwargs : arguments for clipping computational range with setCompRange
Returns:
--------
dictionary with numpy arrays as objects. Keys are:
rhovrMer : radial,azimuth and time average of rho*vx1
rhovrRad : meridional, azimuth and time average of rho*vx1
'''
data = pp.pload(tbeg)
data = too.setCompRange(data,**kwargs)
rhovrMer = np.zeros(data.n2)
rhovrRad = np.zeros(data.n1)
dt = tend-tbeg+1
for t in range(tbeg,tend+1):
if t > tbeg:
data = pp.pload(t)
data = too.setCompRange(data,**kwargs)
rhovrMer += np.average(data.rho*data.vx1,axis=(0,2))
rhovrRad += np.average(data.rho*data.vx1,axis=(1,2))
rhovrMer /= dt
rhovrRad /= dt
return {'rhovrMer':rhovrMer,'rhovrRad':rhovrRad}
def vrmsAzAverage(data,rhow=True,vphimean=None):
'''
calculate the azimuthal average of the rms velocity
Parameters:
-----------
data : input PLUTO dataset
rhow : use density weighting (optional, default: True)
vphimean : average phi-velocity profile (optional; default: None, calculates phi-average)
Returns:
--------
vrms : 2d - array containing vrms(R,Z)
'''
dx3 = data.dx3[None,None,:]
if (vphimean is None):
vphimean = np.sum(data.vx3*dx3,axis=2)/np.sum(data.dx3)
if rhow:
vsqmean = np.sum(data.rho*(data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))
*dx3,axis=2)/np.sum(data.rho*dx3,axis=2)
else:
vsqmean = np.sum((data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))*dx3,axis=2)/np.sum(data.x3)
return np.sqrt(vsqmean)
def vrmsAzMerAverage(data,rhow=True,vphimean=None):
'''
calcuclate the azimuthal and meridional average of the rms-velocity
Parameters:
-----------
data : input PLUTO dataset
rhow : use density weighting (optional, default: True)
vphimean : average phi-velocity profile (optional; default: None, calculates phi-average)
Returns:
--------
vrms : 1d - array containing vrms(R)
'''
dx3 = data.dx3[None,None,:]
if (vphimean is None):
vphimean = np.sum(data.vx3*dx3,axis=2)/np.sum(data.dx3)
if rhow:
vsqmean = np.sum(data.rho*(data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))*dx3
*(np.sin(data.x2)*data.dx2)[None,:,None],axis=(1,2))/np.sum(data.rho*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3)
else:
vsqmean = np.sum((data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3,axis=(1,2))/np.sum((np.sin(data.x2)*data.dx2)[None,:,None]*dx3,axis=(1,2))
return np.sqrt(vsqmean)
def vrmsAzRadAverage(data,rhow=True,vphimean=None):
'''
calculate the azimuthal and radial average of the rms-velocity
Parameters:
-----------
data : input PLUTO dataset
rhow : use density weighting (optional, default: True)
vphimean : average phi-velocity profile (optional; default: None, calculates phi-average)
Returns:
--------
vrms : 1d - array containing vrms(Z)
'''
dx3 = data.dx3[None,None,:]
if (vphimean is None):
vphimean = np.sum(data.vx3*dx3,axis=2)/np.sum(data.dx3)
if rhow:
vsqmean = np.sum(data.rho*(data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))
*(data.x1*data.dx1)[:,None,None]*dx3,axis=(0,2))/np.sum(data.rho*(data.x1*data.dx1)[:,None,None]*dx3,axis=(0,2))
else:
vsqmean = np.sum((data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))
*(data.x1*data.dx1)[:,None,None]*dx3,axis=(0,2))/np.sum((data.x1*data.dx1)[:,None,None]*dx3,axis=(0,2))
return np.sqrt(vsqmean)
def vrmsAllAverage(data,rhow=True,vphimean=None):
'''
calculates the average of the rms-velocity over the whole simulation domain
Parameters:
----------
data : The pyPLUTO dataset to evaluate
rhow : Weather to use density weighting, default is true.
vphimean : average phi-velocity profile (optional; default: None, calculates phi-average)
Returns:
-------
rms velocity values
'''
dx3 = data.dx3[None,None,:]
if (vphimean is None):
vphimean = np.sum(data.vx3*dx3,axis=2)/np.sum(data.dx3)
if rhow:
vsqmean = np.sum(data.rho*(data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))
*(data.x1*data.x1*data.dx1)[:,None,None]*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3)/np.sum(data.rho
*(data.x1*data.x1*data.dx1)[:,None,None]*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3)
else:
vsqmean = np.sum((data.vx1*data.vx1+data.vx2*data.vx2+(data.vx3-vphimean[:,:,None])*(data.vx3-vphimean[:,:,None]))
*(data.x1*data.x1*data.dx1)[:,None,None]*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3)/np.sum(
(data.x1*data.x1*data.dx1)[:,None,None]*(np.sin(data.x2)*data.dx2)[None,:,None]*dx3)
return np.sqrt(vsqmean)
def vrmsAverage(**kwargs):
'''
wrapper calculating rhe rms-velocity timeseries and various time-averages
Parameters:
-----------
tbeg: timestep to begin the vrms analysis, default is 0
tend: timestep to end the vrms analysis, default is nlast
rhow: weight the velocity with density, default is True
vphimean : average phi-velocity profile (optional; default: None,
options: value - 3d array containing vphimean
time - use phi,time average over last 100 orbits,
None - always use phi-average of current timestep)
**kwargs: all other kwargs are handed over to setCompRange
returns:
----
vrmsdict : dictionary containing averaged quantities
vrmsTs: Volume averaged vrms vs time
vrmsMer: R,phi,time averaged vrms vs theta
vrmsR: theta,phi,time averaged vrms vr r
'''
rhow = kwargs.pop('rhow',True)
vphimean = kwargs.pop('vphimean',None)
#fetch time info and set analysis times
timeInfo = nlast_info()
tbeg = kwargs.pop('tbeg',0)
tend = kwargs.pop('tend',timeInfo['nlast'])
dt = tend-tbeg+1
#fetch grid info and set analysis domain
data = pp.pload(0)
data = too.setCompRange(data,**kwargs)
#define & initialize arrays
vrmsTser= np.zeros(dt)
vrmsAzRTav = np.zeros(data.n2)
vrmsAzMerTav = np.zeros(data.n1)
#calculate vphimean if necessary
if (vphimean == 'time'):
vphimean = np.zeros((data.n1,data.n2))
if dt < 100:
tbegphi = tbeg
else:
tbegphi = tend - 100
for tt in range(tbegphi,tend):
data = pp.pload(tt)
data = too.setCompRange(data,**kwargs)
vphimean += np.sum(data.vx3*data.dx3[None,None,:],axis=2)/np.sum(data.dx3)
vphimean /= (tend-tbegphi)
for tt in range(0,dt):
data = pp.pload(tt+tbeg)
data = too.setCompRange(data,**kwargs)
vrmsTser[tt] = vrmsAllAverage(data,rhow,vphimean)
vrmsAzRTav += vrmsAzRadAverage(data,rhow,vphimean)
vrmsAzMerTav +=vrmsAzMerAverage(data,rhow,vphimean)
vrmsAzRTav /= dt
vrmsAzMerTav /= dt
vrmsdict = {'vrmsTs':vrmsTser,'vrmsMer':vrmsAzRTav,'vrmsR':vrmsAzMerTav}
return vrmsdict
def vrAverage(tbeg,tend,cr_kwargs,rhoAverage=True):
'''
calculate the averaged radial velocity quantities
parameters:
----------
tbeg: the begin timestep for the time average
tend: the end timestep for the time average
cr_kwargs: the kwargs for setComputationalRange()
rhoAverage: average the velocity values with density. Defaulte is True.
returns:
-------
vrdict: dictionay containing averaged quantites.
Keys: 'vrMer' -- radial velocity vs x2
'vrrmsMer' -- radial rms-velocity vs x2
'vrsqMer' -- radial velocity squared vs x2
'vrRad' -- radial velocity vs x1
'vrrmsRad' -- radial rms-velocity vs x1
'vrsqRad' -- radial velocity squared vs x1
'''
grid = pp.pload(0)
grid = too.setCompRange(grid,**cr_kwargs)
timeInfo = nlast_info()
if tbeg is None: tbeg = 0
if tend is None: tend = timeInfo['nlast']
dt = tend - tbeg+1
vrAzRadTav = np.zeros(grid.n2)
vrAzRadTavrms = np.zeros(grid.n2)
vrsqAzRadTav = np.zeros(grid.n2)
vrAzMerTav = np.zeros(grid.n1)
vrAzMerTavrms = np.zeros(grid.n1)
vrsqAzMerTav = np.zeros(grid.n1)
for t in range(tbeg,tend+1):
data = pp.pload(t)
data = too.setCompRange(data,**cr_kwargs)
if rhoAverage:
weights = data.rho
else:
weights = None
vrAzRadTav += np.average(data.vx1,axis=(0,2),weights=weights)
vrAzRadTavrms += np.sqrt(np.average(data.vx1*data.vx1,axis=(0,2),weights=weights))
vrsqAzRadTav += np.average(data.vx1*data.vx1,axis=(0,2),weights=weights)
vrAzMerTav += np.average(data.vx1,axis=(1,2),weights=weights)
vrAzMerTavrms += np.sqrt(np.average(data.vx1*data.vx1,axis=(1,2),weights=weights))
vrsqAzMerTav += np.average(data.vx1*data.vx1,axis=(1,2),weights=weights)
vrAzRadTav /= dt
vrAzRadTavrms /= dt
vrsqAzRadTav /= dt
vrAzMerTav /= dt
vrAzMerTavrms /= dt
vrsqAzMerTav /= dt
vrdict = {'vrMer':vrAzRadTav ,'vrrmsMer':vrAzRadTavrms ,'vrsqMer':vrsqAzRadTav
,'vrRad':vrAzMerTav , 'vrrmsRad':vrAzMerTavrms ,'vrsqRad':vrsqAzMerTav}
return vrdict
def vthAverage(cr_kwargs,tbeg=None,tend=None,rhoAverage=False):
'''
calculate multiple averages for meridional velocity
parameters:
----------
tbeg: the begin timestep for the time average
tend: the end timestep for the time average
cr_kwargs: the kwargs for setComputationalRange()
rhoAverage: average the velocity values with density. Defaulte is False.
returns:
-------
'''
grid = pp.pload(0)
grid = too.setCompRange(grid,**cr_kwargs)
timeInfo = nlast_info()
if tbeg is None: tbeg = 0
if tend is None: tend = timeInfo['nlast']
dt = tend - tbeg+1
vzAzRadTav = np.zeros(grid.n2)
vzAzRadTavrms = np.zeros(grid.n2)
vzsqAzRadTav = np.zeros(grid.n2)
vzAzMerTav = np.zeros(grid.n1)
vzAzMerTavrms = np.zeros(grid.n1)
vzsqAzMerTav = np.zeros(grid.n1)
for t in range(tbeg,tend+1):
data = pp.pload(t)
data = too.setCompRange(data,**cr_kwargs)
if rhoAverage:
weights = data.rho
else:
weights = None
vzAzRadTav += np.average(data.vx2,axis=(0,2),weights=weights)
vzAzRadTavrms += np.sqrt(np.average(data.vx2*data.vx2,axis=(0,2),weights=weights))
vzsqAzRadTav += np.average(data.vx2*data.vx2,axis=(0,2),weights=weights)
vzAzMerTav += np.average(data.vx2,axis=(1,2),weights=weights)
vzAzMerTavrms += np.sqrt(np.average(data.vx2*data.vx2,axis=(1,2),weights=weights))
vzsqAzMerTav += np.average(data.vx2*data.vx2,axis=(1,2),weights=weights)
vzAzRadTav /= dt
vzAzRadTavrms /= dt
vzsqAzRadTav /= dt
vzAzMerTav /= dt
vzAzMerTavrms /= dt
vzsqAzMerTav /= dt
vthdict = {'vthMer':vzAzRadTav ,'vthrmsMer':vzAzRadTavrms ,'vthsqMer':vzsqAzRadTav
,'vthRad':vzAzMerTav , 'vthrmsRad':vzAzMerTavrms ,'vthsqRad':vzsqAzMerTav}
return vthdict
def ekinAzAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
ekinmean = np.zeros((nx1,nx2))
ekins = 0.0
for i in data.irange:
for j in data.jrange:
ekinmean[i,j] = 0.5*np.sum(data.rho[i,j,:]*(data.vx1[i,j,:]*data.vx1[i,j,:]+data.vx2[i,j,:]*data.vx2[i,j,:]))*nx3m1
return ekinmean
def ekinAzMerAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
nx2m1 = 1.0/(1.0*nx2)
ekin1d = np.zeros(nx1)
ekin2d = ekinAzAverage(data)
for i in data.irange:
ekin1d = 0.5*np.sum(data.rho[i,:,:]*(data.vx1[i,:,:]*data.vx1[i,:,:]+data.vx2[i,:,:]*data.vx2[i,:,:]))*nx3m1*nx2m1
return ekin1d
def ekinAzRadAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
nx1m1 = 1.0/(1.0*nx1)
ekin1d = np.zeros(nx2)
for j in data.jrange:
ekin1d = 0.5*np.sum(data.rho[:,j,:]*(data.vx1[:,j,:]*data.vx1[:,j,:]+data.vx2[:,j,:]*data.vx2[:,j,:]))*nx3m1*nx1m1
return ekin1d
def ekinAllAverage(data):
nx1 = getattr(data,'n1')
nx1m1 = 1.0/(1.0*nx1)
ekin1d = ekinAzMerAverage(data)
ekinTot = np.sum(ekin1d)*nx1m1
return ekinTot
def ekinTAllAverage(beg,end):
T = 1.0*(end-beg+1)
ekinTav = 0.0
for i in range(beg,end+1):
data = pp.pload(i)
ekinTav += ekinAllAverage(data)
return ekinTav/T
def rhoAzAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
rhomean = np.zeros((nx1,nx2))
for i in data.irange:
for j in data.jrange:
rhomean[i,j] = np.sum(data.rho[i,j,:])*nx3m1
return rhomean
def rhoAzMerAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
nx2m1 = 1.0/(1.0*nx2)
rho1d = np.zeros(nx1)
for i in data.irange:
rho1d = np.sum(data.rho[i,:,:])*nx2m1*nx3m1
return rho1d
def rhoAzRadAverage(data):
nx1 = getattr(data,'n1')
nx2 = getattr(data,'n2')
nx3 = getattr(data,'n3')
nx3m1 = 1.0/(1.0*nx3)
nx1m1 = 1.0/(1.0*nx1)
rho1d = np.zeros(nx2)
for j in data.jrange:
rho1d = np.sum(data.rho[:,j,:])*nx1m1*nx3m1
return rho1d
def rhoAllAverage(data):
nx1 = getattr(data,'n1')
nx1m1 = 1.0/(1.0*nx1)
rho1d = rhoAzMerAverage(data)
rhoTot = np.sum(rho1d)*nx1m1
return rhoTot
def rhoTAllAverage(beg,end):
T = 1.0*(end-beg+1)
rhoTav = 0.0
for i in range(beg,end+1):
data = pp.pload(i)
rhoTav += rhoAllAverage(data)
return rhoTav/T
def dumpToFile(dataset,filename):
with open(filename,'w') as file:
json.dump(dataset.tolist(),file)