forked from rwharvey/cql3d
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cql3d_plot_elecfld_200816.py
2940 lines (2750 loc) · 119 KB
/
cql3d_plot_elecfld_200816.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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 08 19:31:08 2013
Purpose: read file *.nc produced by CQL3D,
plot toroidal electric field, for each time step;
all iterations (Ampere-Faradey eqns) are plotted in one figure for a given t.
@author: YuP
"""
from numpy import *
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
from matplotlib import rc
from matplotlib.pyplot import cm,figure,axes,plot,xlabel,ylabel,title,savefig,show
import os
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import time
import pylab as pylab
import scipy.io.netcdf as nc
#import pandas as pd # to merge datasets ?
#matplotlib.interactive(True) # no plots on screen
matplotlib.interactive(False) # with plots on screen
#Render with externally installed LateX:
matplotlib.rc('text', usetex = True)
e0 = time.time() # elapsed time since the epoch
c0 = time.clock() # total cpu time spent in the script so far
#-----------------------------------------------
# NetCDF issues: machine-dependent
# Try netcdf=4 to envoke netCDF4,
# Or try netcdf=2 to work with older netCDF.
netcdf=4
#-----------------------------------------------
if netcdf==4: from netCDF4 import Dataset # YuP
#-----------------------------------------------
# Constants
pi=3.14159265358979
clight= 2.99792458e10 # speed of light [cm/s]
charge= 4.8032e-10 # e-charge [cgs]
e = 4.8032e-10 # e-charge [cgs]
p_mass= 1.67262158e-24 # proton mass [gram]
proton= 1.67262158e-24 # [gramm]
e_mass= 9.1095e-28 # [gramm]
ergtkev=1.6022e-09
#For plots: set fonts and line thicknesses ------------------------------
fnt = 19 #16 #20 #12 # font size for axis numbers (see 'params=' below)
linw = 1.0 # LineWidth for plots
view_azim=-110 #-140 #-135 # degrees For Axes3D() mesh plots over (rho,time)
view_elev=55 #30 #+72 # degrees For Axes3D() mesh plots over (rho,time)
imesh=0 # 0 for contour plots; 1 for mesh (over rho,time 2D grid)
Ncont=50 # Number of contour levels, in case of imesh=0
nt_plot=200 #40 #80 #40 #20 #501 # When nt is too large (say, 500 time steps),
# it is better to omit some points.
# Specify nt_plot for the approximate number of steps for plotting.
# The stride in time index is set below as
# ntstride= np.floor(nt/nt_plot) # floor()=nearest-lower integer.
#For example, (nt/20) means: leave only ~20 time points for plotting.
# If you want to plot ALL time steps, simply set nt_plot to a very
# large value (nstop, or larger); then ntstride will be 1.
t_low_lim=0. #810 #[ms] Lower limit for plots of mesh over (t,rho).
# Normally, it should be 0, but setting to a larger value
# allows zooming-in.
each_step=0 #Set to 1 to make&save Array(rho) plots for each time instant.
i_ko=0 # Set to 1, to plot KO source (0-noplots)
i_ra=1 # Set to 1, to plot Runaway-related plots
i_ampf=0
i_plasma_profiles=1 # to plot plasma profiles (density, T, <energy>, Zeff)
ksp=0 # those plasma profiles are made for ksp species (in python counting)
#Specify time steps for which plots like E(rho) will be shown, at these n-steps:
#it_select= [ 0, 14, 48, 80, 114,148, 180] #, 22, 25, 28, 31]
#col_select_it=['r','b','g','m','c','k', 'r'] #,'b','g','m','c'] # color for each it_select
it_select= [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
col_select_it=['r','b','g','m','c','k', 'r','b','g','m','c']
# For combined-files, specify selected time slices to show:
#t_combined_select= [1.14, 1.17,1.19,1.21,1.23,1.25,1.27,1.29] # [sec]
#col_t_combined_select=['g', 'm', 'c', 'k', 'r' ,'b', 'g', 'm' ] #,'c']
#t_combined_select= [0.89,0.91,1.14,1.30,1.39,1.42, 1.49] # [sec]
t_combined_select= [0.001,0.002,0.003] #,1.30,1.39,1.42, 1.49] # [sec]
col_t_combined_select=['r', 'b', 'g'] #, 'm', 'c', 'k', 'r' ] #,'b','g','m','c'] #
#Similarly, Plots of a func.vs.t will be made for these
# radial indexes (up to 12 radial points)
ir_select= [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
col_select=['r','b','g','m','c','k', 'r','b','g','m','c','k']
# For plotting the curve A*exp(-lam^2 *t / (4pi*sigma/c^2))
# Specify:
a= 70. # cm # Compare with printout of rgeomp (see below)
#lam= 2.4048/a # 2.4/a means that J0(r*lam) gets to zero at r=a
lam= 5.52008/a # second root of J0(a*lam)=0
#lam= 8.6537/a # 3rd root of J0(a*lam)=0
#lam= 11.79153444/a # 4th root of J0(a*lam)=0
#lam= 14.93091771/a # 5th root of J0(a*lam)=0
resist_phi_0= 3.123e-16 #8.6E-16 # resistivity (cgs) at r=0
#(printed during CQL3D run as resist_phi(lr) )
resist_phi_a= 3.215e-16 #9.5E-16 # resistivity (cgs) at plasma edge (r=a)
# Compare to printout of RESISTIVITY <E_phi/R>/<j_phi/R> (see below)
#-------------------------------------------------------------
# Optionally: Calculate the Spitzer el. conductivity,
# See NRL (p.37) sigma_par = 2*tau_ei * n_e * e**2 /e_mass
# Specify:
T_e= 100. # eV
n_e= 1.0e13 # cm-3
CL= 18 # Coulomb log. == gamaset
Z_i= 2. #10. # ==bnumb(ion)
# Then,
tau_ei= 3.44e5* T_e**1.5 / (n_e *CL* Z_i)
sigma_par = 2*tau_ei * n_e * e**2 /e_mass
print ' tau_ei = 3.44e5* T_e**1.5 / (n_e *CL* Z_i) ==', tau_ei
print ' sigma_par = 2*tau_ei * n_e * e**2 /e_mass ==', sigma_par
# HOWEVER: the 2* factor in front of tau_ei may have a dependence on Z_i.
# It should be changed to 3 for large Z_i (book by S.V.Mirnov)
# Evaluate tau_resistivity factors for further plotting:
sigma_0 = 1.0/resist_phi_0 # conductivity (cgs) at r=0
sigma_a = 1.0/resist_phi_a # conductivity (cgs) at r=a
print ' sigma_0 = 1.0/resist_phi_0 ==', sigma_0
print ' sigma_a = 1.0/resist_phi_a ==', sigma_a
iplot_tau_decay=0 #1 #Set to 1 if you want to add these plots (test/verification)
# The decay time of initially ~parabolic profile of E field
# (with max value at r=0, and zero at plasma edge r=a)
tau_decay_0 = 1e3*(4*pi*sigma_0/clight**2)/lam**2 # CONVERT to msec
tau_decay_a = 1e3*(4*pi*sigma_a/clight**2)/lam**2 # CONVERT
# Based on sigma_par, see above:
tau_decay_par=1e3*(4*pi*sigma_par/clight**2)/lam**2 # CONVERT to msec
print ' tau_decay at r=0 and r=a [msec]=', tau_decay_0, tau_decay_a
# So now we can plot A*exp(-t/tau_decay) curves.
# Factor A will be taken from the peak value of Itor(time) curve.
# For plots:
#---------------------------------------
params = {
'axes.linewidth': linw,
'lines.linewidth': linw,
'axes.labelsize': fnt+4,
'text.fontsize': fnt+4,
'legend.fontsize': fnt,
'xtick.labelsize':fnt,
'ytick.labelsize':fnt,
'xtick.linewidth':linw,
'ytick.linewidth':linw,
'font.weight' : 'regular'
}
plt.rcParams.update(params)
#rc.defaults() #to restore defaults
mpl.rcParams['font.size']=fnt+2 # set font size for text in mesh-plots
#----------------------------------------------------------------------
# Specify netcdf file name, with sub-directory if any:
###file_name= 'freidberg_full_eps_AF.0.1.nc'
#file_name= 'freidberg_full_eps_AF.0.8fixed.nc'
#file_name= 'freidberg_full_eps_AF.0.8conserv.nc'
#file_name= 'freidberg_full_eps_AF_5th_root_J0.4.1.6.nc'
#file_name= 'freidberg_full_eps_AF.0.10.8_170821.nc' # see /splines_2nd_root_dtr/
#file_name= 'freidberg_full_eps_AF.0.10.8_170821parab.nc'
#file_name='AF.0.11.7.nc'
#file_name='AF.0.11.8.6.nc'
#file_name= 'AF-EC-Edc.1.0.nc' # bad test with ECCD, fow_ver.170314.3 (or.2)
#file_name= 'AF-EC-Edc.1.0_YuP170821.nc' # 21-08-2017 test with ECCD (rayech file)
#file_name= 'AF-EC-Edc.1.0_YuP170821_nt20.nc' # 21-08-2017 test with ECCD (rayech file)
#file_name= 'AF-EC-Edc.1.0_YuP170821_nt20_colmodl1.nc' # 21-08-2017 test with ECCD (rayech file)
#file_name= 'AF-EC-Edc.1.0.nc'
#file_name='AF-EC-Edc.1.2.nc' #'AF-EC-Edc.1.4.nc' #'AF-EC-Edc.1.3.1.nc'
#file_name='AF-EC-Edc.1.5.nc'
file_name='tdep_ko_amp-far.4.nc' # Bob's run 171008 on runaway.
file_name='tdep_ko_amp-far.5.1.nc' # Bob's run 171008 on runaway.
file_name='tdep_ko_amp-far_Drr.0.nc' # Bob's run 171008 on runaway.
file_name='tdep_ko_amp-far_Drr.1c.nc' # Bob's run 171008 on runaway.
file_name='tdep_ko_amp-far_Drr.1c.nc' # Bob's run 171008 on runaway.
file_name='tdep_ko_amp-far.5.1.1c.nc'
#file_name='tdep_ko_NIMRODfiles_Tmin10eV_nstop680_dtr0.1em4_conserv.nc'
#file_name='cmod1101201020_AF.23.nc' # Bob's runs for CMOD (with LHCD)
# Short reruns, nstop=40..80 [2019-09-10], DIIID, flat profiles
#file_name='tdep_ko_amp-far.4.3_short_test_short_YuP_Intel_R8_fpconstant.nc'
file_name='tdep_ko_amp-far.5.1.1c_short_nstop80.nc' # lrz=11 Bad oscillations
file_name='tdep_ko_amp-far.5.1.1c_short_nstop80_lrz51.nc' # Good
#file_name='tdep_ko_amp-far.5.1.1c_short_nstop80_lrz21.nc' # Not bad; small oscillations
#file_name='tdep_ko_amp-far.5.1.1c_short_nstop80_lrz21_pellet7.nc'
#file_name='tdep_ko_amp-far.5.1.1c_lrz21_noPellet.nc' # just for reference
#file_name='tdep_ko_amp-far.5.1.1c_lrz21_Pellet.nc'
# after 2019-10-03 :
#file_name='tdep_ko_amp-far.5.1.1c_lrz51_Pellet.nc' #very nice smooth plots
#file_name='tdep_ko_amp-far.5.1.1c_lrz51_Pellet_dt01ms.nc' # run20
#file_name='tdep_ko_amp-far.5.1.1c_lrz51_Pellet_dt005ms.nc' # run21 and 21nb
# Starting from 21nb, Ne,bound are added into KO source.
#file_name='tdep_ko_amp-far.5.1.1c_lrz51_Pellet_dt0025ms.nc' #run22 temp_expt_tau=0.1d-3
#file_name='tdep_ko_amp-far.5.1.1c_lrz51_Pellet_dt0010ms.nc' #run22a, with smaller dtr
#file_name='tdep_ko_amp-far.5.1.1c_lrz101_Pellet_dt0020ms.nc'
#file_name='tdep_ko_amp-far_lrz51_Pellet_Te10keV_dt0010ms.nc' #bad
# Switched to lrz=101 More stable --------------------------------
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te10keV_dt0020ms.nc' # PC: good RE
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te10keV_dt0020ms_1.nc' #mpi32, nampfmax2-8
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te10keV_dt0020ms_1.nc'
#----------------- Good for presentation/APS2019:
# In /lrz101_AMPF_pellet_Te2keV_tau1ms_b/ (10/09/2019)
# Stable run on PC, with dtr=0.05e-3
# temp_expt_tau0= 30.0d-3 ![sec]slow decay time of Te(t)
# temp_expt_tau1= 1.0d-3 ![sec]fast decay time of Te(t)(for Thermal Quench)
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te2keV_dt0050ms.nc' # slow tau1, for slides
# In /lrz101_AMPF_pellet_Te2keV_tau01ms_a/ (10/10/2019)
# Stable run on PC, with dtr=0.05e-3, fast tau1 (but very small RE)
# temp_expt_tau0= 30.0d-3 ![sec]slow decay time of Te(t)
# temp_expt_tau1= 0.1d-3 ![sec]fast decay time of Te(t)(for Thermal Quench)
###file_name='tdep_ko_amp-far_lrz101_Pellet_Te2keV_dt0050ms_tau01.nc'
# Also see /lrz101_AMPF_pellet_Te2keV_tau01ms_b_coll_nohesslow/
# similar run, but hesslow gscreen and hbethe are disabled.
# Good 10keV run, /lrz101_AMPF_pellet_Te10keV_tau01ms_b_coll_nohesslow/ (10/11/2019)
# or /lrz101_AMPF_pellet_Te10keV_tau01ms_a/
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te10keV_dt0050ms_tau01.nc' #tau1=0.1ms
# Even faster tau1=0.05ms
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te10keV_dt0050ms_tau005.nc'
# Somewhat more conversion to RE, from larger rho (rho<0.2 - same RE current)
# Also faster tau1=0.05ms with Te0=2.5keV case
#file_name='tdep_ko_amp-far_lrz101_Pellet_Te2keV_dt0050ms_tau005.nc'
# Small fraction is converted (<30kA) Not taken for APS
# But see lrz101_AMPF_pellet_Te2keV_tau005ms_V200: Vpell->200m/s:
# 95kA of RE
# Replot NIMROD-CQL3D runs from
#file_name='tdep_ko_NIMRODfiles_Tmin10eV_nstop680_dtr0.1em4_conserv.nc' #2018-09-24
#-------- Bob's runs for C-mod -------------------------------
#file_name='cmod1101201020_AF_LH.2_pellet.1.nc'
# With AMP-FAR:
#file_name='cmod1101201020_AF_LH.2_pellet.3.nc' #AMP-FAR: bad
# No AMP-FAR, good run:
#file_name='cmod1101201020_AF_LH_Wpellet.nc' #see run W8a 200ms range looks good
#file_one='cmod1101201020_AF_LH.2.1_yup_short_nstop200_iprocur_norf_neohh.nc'
file_one='freidberg_cyl_PoP2008_yup2.nc'
file_one='cmod1101201020__LH.3.2_yup2.nc'
#file_one='cmod1101201020_AF_LH.3.2.nc'
file_one='cmod1101201020__LH.3.2_yup2_ampfar.nc' # corrupted
file_one='cmod1101201020__LH.3.2_yup3_ampfar.nc' # 20steps at dt=0.5ms
#file_one='cmod1101201020_3.2_AF_BS.nc'
#file_one='cmod1101201020_3.2_AF_tdboothi.nc'
file_one='cmod1101201020_3.2_AF_dbscurm.nc' # added bscurm into AMPFAR Eqn
file_one='cmod1101201020_3.2_AF_dsig.nc' # added ALL: bscurr, dcurr, dsig
file_one='cmod1101201020_3.2_AF_dsig_n20.nc'
# Set of runs 2.0--2.7 Set the list below, set nfiles accordingly.
# If you want JUST ONE file, leave one out of list, and set nfiles to 0
file=[]
#----- Start the list:
file.append(file_one) # If just one, leave this line, comment other lines
#file.append('cmod1101201020_AF_LH.2.nc') # start with this.
#file.append('cmod1101201020_AF_LH.2.0.nc')
#file.append('cmod1101201020_AF_LH.2.1.nc')
#file.append('cmod1101201020_AF_LH.2.2.nc')
#file.append('cmod1101201020_AF_LH.2.3.nc') # re-run 10-21
#-----
#file.append('cmod1101201020_AF_LH.2.4.nc')
#file.append('cmod1101201020_AF_LH.2.5.nc')
#file.append('cmod1101201020_AF_LH.2.6.nc')
#file.append('cmod1101201020_AF_LH.2.7.nc')
#----- End of list.
# Automatic procedure, if many files with same prefix (same file_base):
#for ifile in range(0, nfiles):
# file.append(file_base+str(ifile)+'.nc')
print file
#print shape(file)
nfiles=0 #5-1 #7-1 # number of files in the list above, minus 1
#Now file[] contains list of all *.nc files from above
#Put netCDF structures into list.
ifile=0
#snetcdf =nc.netcdf_file(file[ifile],'r') # Does not work for YuP
s_file_cql3d= Dataset(file[ifile], 'r', format='NETCDF4')
# to read the basic stuff, common for all files:
lrz=s_file_cql3d.variables['lrz'].getValue()
lrz=np.asscalar(lrz)
i_R_stop=lrz
iy=s_file_cql3d.variables['iy'].getValue()
iy=np.asscalar(iy)
jx=s_file_cql3d.variables['jx'].getValue()
jx=np.asscalar(jx)
print 'lrz,iy,jx =',lrz,iy,jx
dvol= array(s_file_cql3d.variables['dvol']) # cm^3
dvol= np.asarray(dvol)
darea=array(s_file_cql3d.variables['darea']) # cm^2
darea= np.asarray(darea)
#x=s_file_cql3d.variables['x'][:]
t_combined_low_lim=0. #0.750 #[sec] For plots like Ip_combined vs time_combined:
# set the lower limit in time axis.
time_combined=[]
Ip_combined=[]
I_RE_combined=[]
elecfld_combined=[]
curr_combined=[]
for ifile in range(0,nfiles+1):
snetcdf = Dataset(file[ifile], 'r', format='NETCDF4')
#snetcdf =nc.netcdf_file(file[ifile], 'r')
# 'bctshift' May not be available in *.nc files from older runs
bctshift= snetcdf.variables['bctshift'].getValue() #getValue() for scalar
time_ifile= array(snetcdf.variables['time']) +bctshift #[sec]
time_ifile=np.asarray(time_ifile)
print 'ifile, shape(time_ifile),MIN/MAX,bctshift=' , ifile, shape(time_ifile),\
np.min(time_ifile),np.max(time_ifile), bctshift
time_combined.extend(time_ifile)
#Now Total plasma current
ccurtor= array(snetcdf.variables['ccurtor']) # [Amps]
# CONVERT to kA:
#c ccurtor(lr_) is the cumulative toroidal current, integrating
#c curtor(lr) in poloidal cross-section (Amps),
#c accounting for pol variation of tor current.
#c See tddiag
ccurtor=ccurtor/1000. # kA
# i.e. size= (nstop+1,lrz)
#The value of ccurtor[itime,lrz] corresponds to the total integral of current:
Ip_ifile=ccurtor[:,lrz-1] # [kA] as a function of time.
if ifile==3:
Ip_ifile[0]=Ip_ifile[1] # Adjust the glitch in n=1 data point for this run
#print 'Ip_ifile: shape, min/max',Ip_ifile.shape,np.min(Ip_ifile),np.max(Ip_ifile)
Ip_combined.extend(Ip_ifile)
# Now RE current
curra=array(snetcdf.variables['curra']) #shape: (nstop+1,lrz)
#curra= np.absolute(curra) # Sometimes it is <0 (neg.tor.dir). Plot |curra|
# 'Runaway FSA parallel cur density above ucrit' 'Amps/cm**2'
I_RE_ifile= np.dot(curra,darea)/1e6 # 1/e6 is to MA
I_RE_combined.extend(I_RE_ifile) # MA
# Now E field (matrix)
elecfld= array(snetcdf.variables['elecfld']) # V/cm (nstop+1,lrz+1)
# evaluated at bin centers (use rho) ! Parallel Electric Field
elecfld=elecfld*100. # CONVERT to V/m
elecfld_combined.extend(elecfld[:,1:lrz+1]) # V/m, And [0] is omitted
#print 'curra : ',curra.shape #'(nstop+1,lrz)'
#print 'elecfld: ',elecfld.shape #'(nstop+1,lrz+1)'
# Now current density
curr=array(snetcdf.variables['curr']) #shape: (nstop+1,lrz)
curr= np.absolute(curr) # Sometimes it is <0 (neg.tor.dir). Plot |curr|
curr_combined.extend(curr) # A/cm^2
time_combined= np.asarray(time_combined) # 1D array
Ip_combined= np.asarray(Ip_combined) # 1D array
elecfld_combined=np.asarray(elecfld_combined) # 2D array
curr_combined= np.asarray(curr_combined) # 2D array
time_combined_min= np.min(time_combined)
time_combined_max= np.max(time_combined)
print 'time_combined=',shape(time_combined),time_combined_min,time_combined_max #sec
print 'Ip_combined=', shape(Ip_combined),np.min(Ip_combined),np.max(Ip_combined) #kA
print 'elecfld_combined=', shape(elecfld_combined),np.min(elecfld_combined),np.max(elecfld_combined) #V/m
print 'curr_combined=', shape(curr_combined),np.min(curr_combined),np.max(curr_combined) #A/cm^2
nt_combined= time_combined.size
# Adjust t_low_lim, to be less than max of timecode:
t_combined_low_lim= min(t_combined_low_lim, time_combined_max*0.99)
# Adjust t_combined_low_lim, to be not less than min of time_combined:
t_combined_low_lim= max(t_combined_low_lim, time_combined_min)
print 'Adjusted t_combined_low_lim to ', t_combined_low_lim
# Find indexes it_combined_select corresponding to t_combined_select[] values
# in the time_combined array (with some accuracy)
t_combined_select=np.asarray(t_combined_select)
it_combined_select=[]
for it in range(0,t_combined_select.size): # scan the list
t_combined_select1= t_combined_select[it] # a given slice
tdiff= np.abs(time_combined[:]-t_combined_select1)
it_found=[] # reset
it_found= np.min(np.where(tdiff==np.min(tdiff))) # What if cannot find?
it_found= np.asscalar(it_found)
print it_found
it_combined_select.append(it_found)
it_combined_select=np.asarray(it_combined_select)
print 't_combined_select ',t_combined_select
print 'it_combined_select',it_combined_select
print 'time_combined[it_combined_select]',time_combined[it_combined_select]
# Read data file (*.nc) :
print 'The input file contains:'
print '========================================'
print "The global attributes: ",s_file_cql3d.dimensions.keys()
print "File contains variables: ",s_file_cql3d.variables.keys()
print '========================================'
# FSA Parallel current (A/cm^2) as a func of (time,rho)
# Note: curr array may not exist in *.nc, so try to read it:
try:
try:
curr=array(s_file_cql3d.variables['curr']) # j_par(time,lr)
# also could plot 'curtor' (time,lr)
except:
print('No data on curr')
i_curr=0
else:
i_curr=1
#curr=array(s_file_cql3d.variables['curr']) # j_par(time,lr)
print 'curr:', curr.shape
finally:
print '----------------------------------------'
# Note: nstates may not exist in *.nc (added in 2019-09), so try to read it:
try:
try:
nstates=s_file_cql3d.variables['nstates'].getValue() # scalar
nstates=np.asscalar(nstates)
except:
print('No data on nstates')
nstates=0
else:
print 'nstates=', nstates
finally:
print '----------------------------------------'
unorm=s_file_cql3d.variables['vnorm'].getValue() #getValue() for scalar
unorm=np.asscalar(unorm)
unorm2=unorm**2
unorm3=unorm*unorm2
unorm4=unorm2*unorm2
# 'bctshift' May not be available in *.nc files from older runs
bctshift=s_file_cql3d.variables['bctshift'].getValue() #getValue() for scalar
print 'bctshift=',bctshift # 'Time shift of bctime(), for restarts' [sec]
#rfpwr=array(s_file_cql3d.variables['pwrrf'])
#print 'rfpwr:', rfpwr.shape
rmag=s_file_cql3d.variables['rmag'].getValue()
rmag=np.asscalar(rmag)
print 'Rmag[cm]=',rmag
btor=s_file_cql3d.variables['btor'].getValue()
btor=np.asscalar(btor)
print 'Nominal tor mag fld at radmaj btor[Gauss]=',btor
rgeomp=s_file_cql3d.variables['rgeomp'].getValue()
rgeomp=np.asscalar(rgeomp)
print '0.5*(max-min) of major radius rgeomp[cm]=' , rgeomp
restp=array(s_file_cql3d.variables['restp']) # [nt+1,lrz+1]
restp=np.asarray(restp)
#print restp.shape # [nt+1,lrz+1]
print 'RESISTIVITY <E_phi/R>/<j_phi/R> [cgs] restp(t=0, all ir):', restp[1,:]
sptzrp=array(s_file_cql3d.variables['sptzrp']) # [nt+1,lrz+1]
sptzrp=np.asarray(sptzrp)
# Spitzer resistivity, incl Zeff dependence [cgs: seconds]
rya=array(s_file_cql3d.variables['rya'])
# Normalized radial mesh at bin centers !
rya=np.asarray(rya)
print 'rya:', rya
bnumb=array(s_file_cql3d.variables['bnumb'])
# Atomic charge
bnumb=np.asarray(bnumb)
print 'Atomic charge bnumb:', bnumb
fmass=array(s_file_cql3d.variables['fmass'])
# mass [gram]
fmass=np.asarray(fmass)
print 'fmass [gram]:', fmass
ntotal= fmass.size # Number of species, including general and Maxw.
print 'Number of species: ntotal=', ntotal
Rp=array(s_file_cql3d.variables['Rp']) #[cm] Major rad. of surface at outerboard
Rp=np.asarray(Rp)
#print 'Rp:', Rp
Rm=array(s_file_cql3d.variables['Rm']) #[cm] Major rad. of surface at innerboard
Rm=np.asarray(Rm)
#print 'Rm:', Rm
rminor=(Rp-Rm)/2 # minor radius, cm
print 'rminor[0:lrz-1] ==(Rp-Rm)/2 [cm] =', rminor
timecode= array(s_file_cql3d.variables['time']) +bctshift #added the shift[sec]
print 'timecode.shape=',timecode.shape
#print 'timecode=',timecode
# CONVERT to msec
timecode=timecode*1e3
nt= timecode.size
print 'Number of time steps nt=',nt
# Adjust t_low_lim, to be less than max of timecode:
t_low_lim= min(t_low_lim, np.max(timecode)*0.99)
# Adjust t_low_lim, to be not less than min of timecode:
t_low_lim= max(t_low_lim, np.min(timecode))
print 'Adjusted t_low_lim to ', t_low_lim
# Find time index corresponding to t_low_lim:
it0= np.min(np.where(timecode>t_low_lim) )
print 'it0 that corresponds to t_low_lim:' , it0
print 'timecode[it0-1], timecode[it0]=', timecode[it0-1], timecode[it0]
elecfld= array(s_file_cql3d.variables['elecfld']) # V/cm
# evaluated at bin centers (use rho) ! Parallel Electric Field
# CONVERT to V/m:
elecfld=elecfld*100. # V/m
print 'elecfld: ',elecfld.shape,'(nstop+1,lrz+1)'
ipellet=0 # to be changed below, if pellet='enabled' in nc file
if nstates>0:
gamafac=s_file_cql3d.variables['gamafac'][:] # Character
#gamafac= gamafac[:].tostring()
print 'gamafac=', gamafac
pellet=s_file_cql3d.variables['pellet'][:] # Character
#pellet= pellet[:].tostring()
print 'pellet=', pellet
if pellet[0]== "e":
ipellet=1
else:
ipellet=0
print 'pellet=', pellet, ipellet
imp_type=s_file_cql3d.variables['imp_type'].getValue()
imp_type=np.asscalar(imp_type)
print 'imp_type=', imp_type
fmass_imp=s_file_cql3d.variables['fmass_imp'].getValue() #getValue() for scalar
fmass_imp=np.asscalar(fmass_imp)
print 'Impurity atom fmass_imp [gram]:', fmass_imp
print 'Impurity atom fmass_imp/proton:', fmass_imp/proton
# Atomic charge for each state
bnumb_imp=array(s_file_cql3d.variables['bnumb_imp'])
bnumb_imp=np.asarray(bnumb_imp) # 0:nstates
print 'Atomic charge for each state bnumb_imp:', bnumb_imp
# Related to pellet, if any:
pellet_Cablation=s_file_cql3d.variables['pellet_Cablation'].getValue()
pellet_Cablation=np.asscalar(pellet_Cablation)
print 'pellet_Cablation=', pellet_Cablation
pellet_M0=s_file_cql3d.variables['pellet_M0'].getValue()
pellet_M0=np.asscalar(pellet_M0)
print 'pellet_M0 [gram]=', pellet_M0
# rho(t) for pellet:
pellet_rho=array(s_file_cql3d.variables['pellet_rho'])
pellet_rho=np.asarray(pellet_rho) # 0:nt
print 'pellet_rho:', pellet_rho.shape
# Gablation(t) for pellet [gram/sec]:
Gablation=array(s_file_cql3d.variables['Gablation'])
Gablation=np.asarray(Gablation) # 0:nt
print 'Gablation:', Gablation.shape
# Remaining mass(t) for pellet:
pellet_Mrem=array(s_file_cql3d.variables['pellet_Mrem'])
pellet_Mrem=np.asarray(pellet_Mrem) # 0:nt
print 'pellet_Mrem[gram]:MIN/MAX', np.min(pellet_Mrem), np.max(pellet_Mrem)
# Find time index corresponding to instant when pellet_Mrem~0:
it_Mgone_arr= np.where(pellet_Mrem/pellet_M0<1.e-5)
print 'it_Mgone_arr=',it_Mgone_arr
if np.size(it_Mgone_arr)==0:
print ' No time point satisfying pellet_Mrem/pellet_M0<1.e-5'
print ' which means pellet got to inner side.'
print ' Setting it_Mgone to nt-1'
it_Mgone=nt-1
else:
it_Mgone= np.min(it_Mgone_arr)
print 'it_Mgone=',it_Mgone,' nt=',nt,' pellet_Mrem[it_Mgone]=',pellet_Mrem[it_Mgone]
dens_imp_allstates=array(s_file_cql3d.variables['dens_imp_allstates'])
# 'Density of impurity, all charge states together' '1/cm**3'
print 'dens_imp_allstates: ',dens_imp_allstates.shape #shape: (nstop+1,lrz)
dens_imp=array(s_file_cql3d.variables['dens_imp'])
# 'Density of impurity, for each charge state (incl.Z=0)' '1/cm**3'
print 'dens_imp: ',dens_imp.shape #shape: (nstop+1,lrz,0:nstates)
dens_imp_max=np.max(dens_imp)
print 'MAX of dens_imp =', dens_imp_max
print 'MIN of dens_imp =', np.min(dens_imp)
#----- Ne_bound INVENTORY
#[SUM(Nb(kstate)*density(rho,kstate))*dvol(rho) for each rho and t]
kstate_max= nstates
nb= dens_imp_allstates*0 # initialize shape: [ir,it]
for kstate in range(0,kstate_max+1): # loop in charge states
nb= nb +dens_imp[:,0:lrz,kstate]*(nstates-bnumb_imp[kstate])
#SUM over n(Zstate)*(Zatom-Zstate)
# nb # density of bound e
print 'nb: ',nb.shape #shape: (nstop+1,lrz)
if i_ampf==1:
elecfldn= array(s_file_cql3d.variables['elecfldn']) # statVolts/cm
# evaluated at bin centers !!!
print 'elecfldn: ',elecfldn.shape,'(niter,nstop+1,lrz+2)'
# CONVERT to V/m:
elecfldn=elecfldn*300.*100. # V/m
niter= elecfldn[:,0,0].size # Number of iterations
print 'Number of saved iterations(including it=0) niter=',niter
elecfld_min= np.min(elecfldn)
elecfld_max= np.max(elecfldn)
print 'min/max of elecfldn for all r, t, iterations:',elecfld_min,elecfld_max
# When nt is too large (say, 500), it is better to omit some points.
ntstride= np.floor(nt/nt_plot) # rint()= nearest integer, floor()=nearest-lower
# the above (nt/20) means: leave only ~20 points for plotting.
# ntstride=5 # Or set explicitly (the stride in time index)
ntstride= int(max(ntstride,1)) # To make sure it is >0
# runaway-related arrays
if i_ra==1:
runaway_rate=array(s_file_cql3d.variables['runaway_rate']) #shape: (nstop+1,lrz)
# 'Runaway rate, determined from e flux off grid'
# 'Runaway rate = 1/n * dn/dt / nu_Kulsrud'
# 'Unitless'
print 'runaway_rate: ',runaway_rate.shape
denra=array(s_file_cql3d.variables['denra']) #shape: (nstop+1,lrz)
# 'Runaway FSA density above ucrit' '1/cm**3'
print 'denra: ',denra.shape
curra=array(s_file_cql3d.variables['curra']) #shape: (nstop+1,lrz)
#curra= np.absolute(curra) # Sometimes it is <0 (neg.tor.dir). Plot |curra|
# 'Runaway FSA parallel cur density above ucrit' 'Amps/cm**2'
print 'curra: ',curra.shape
ucrit=array(s_file_cql3d.variables['ucrit']) #shape: (nstop+1,lrz)
# 'Critical momentum per mass for runaway' 'Normalized to vnorm'
print 'ucrit: ',ucrit.shape
edreicer=array(s_file_cql3d.variables['edreicer']) #shape: (nstop+1,lrzmax)
# 'E_D Dreicer elec fld, e.g., Kulsrud PRL(1973)' 'Volts/cm'
print 'edreicer: ',edreicer.shape
# CONVERT to V/m:
edreicer=edreicer*100. # V/m
if i_ko==1:
srckotot=array(s_file_cql3d.variables['srckotot']) #shape: (nstop+1,lrz)
# 'FSA Knockon source density rate' '#/cm**3*sec'
print 'srckotot: ',srckotot.shape
eoe0=array(s_file_cql3d.variables['eoe0']) #shape: (nstop+1,lrz)
# 'Elecfld/Critical knockon electric field' 'no units'
print 'eoe0: ',eoe0.shape
denfl=array(s_file_cql3d.variables['denfl']) #shape: (nstop+1,lrz)
# 'FSA Elec Density from KO Reduced Distn' '#/cm**3'
print 'denfl: ',denfl.shape
# density, temp, <energy> of all species, as a func. of t and rho
density=array(s_file_cql3d.variables['density']) #shape: (nstop+1,lrz,ntotal)
print 'density [1/cm**3]: ',density.shape # '1/cm**3'
temp=array(s_file_cql3d.variables['temp']) #shape: (nstop+1,lrz,ntotal)
print 'temp [keV]: ',temp.shape # 'keV'
energy=array(s_file_cql3d.variables['energy']) #shape: (nstop+1,lrz,ntotal)
print 'energy [keV]: ',energy.shape # 'keV' 'FSA Energy per particle'
#ntotal= density[0,0,:].size # Number of species, including general and Maxw.
#print 'Number of species: ntotal=', ntotal
# Also, Zeff
zeff=array(s_file_cql3d.variables['zeff']) #shape: (nstop+1,lrz)
print 'zeff: ',zeff.shape # Zeff
ccurtor=array(s_file_cql3d.variables['ccurtor']) # [Amps]
# CONVERT to kA:
#c ccurtor(lr_) is the cumulative toroidal current, integrating
#c curtor(lr) in poloidal cross-section (Amps),
#c accounting for pol variation of tor current.
#c See tddiag
ccurtor=ccurtor/1000. # kA
print 'ccurtor:', ccurtor.shape # Shape is same as for curr,
# i.e. size= (nstop+1,lrz)
#The value of ccurtor[itime,lrz] corresponds to the total integral of current:
Itor=ccurtor[:,lrz-1] # [kA] as a function of time.
#print 'Itor[kA] as a func of time:', Itor
#print Itor.shape, timecode.shape
bscurr_e_gen=array(s_file_cql3d.variables['bscurr_e_gen']) # [A/cm^2]
I_bs_e_gen= np.dot(bscurr_e_gen,darea)/1e6 # 1/e6 is to MA
bscurr_i_gen=array(s_file_cql3d.variables['bscurr_i_gen']) # [A/cm^2]
I_bs_i_gen= np.dot(bscurr_i_gen,darea)/1e6 # 1/e6 is to MA
bscurr_e_maxw=array(s_file_cql3d.variables['bscurr_e_maxw']) # [A/cm^2]
I_bs_e_maxw= np.dot(bscurr_e_maxw,darea)/1e6 # 1/e6 is to MA
bscurr_i_maxw=array(s_file_cql3d.variables['bscurr_i_maxw']) # [A/cm^2]
I_bs_i_maxw= np.dot(bscurr_i_maxw,darea)/1e6 # 1/e6 is to MA
currpar_starnue=array(s_file_cql3d.variables['currpar_starnue']) # [A/cm^2]
I_starnue= np.dot(currpar_starnue,darea)/1e6 # 1/e6 is to MA
currpar_starnue0=array(s_file_cql3d.variables['currpar_starnue0']) # [A/cm^2]
I_starnue0= np.dot(currpar_starnue0,darea)/1e6 # 1/e6 is to MA
#---------- Plot Itor vs time
# Add a plot of A*exp(-t/tau_decay) curves.
# Factor A will be taken from the peak value of Itor(time) curve.
A=0.
it_Imax=1
for itime in range(0,nt): # loop in time index
if abs(Itor[itime])>=abs(A):
A=Itor[itime]
it_Imax=itime
print ' Max or Min of Itor is at time step itime=it_Imax=',it_Imax
fig0=plt.figure(0)
ax = plt.subplot(111)
txt= "$I_{tor}$"+' $Black:curr,$ $Solid/Red:RE,$ '+\
r"$Dash/Red: \delta \sigma E$"
plt.xlabel('$time$ $(msec)$')
plt.ylabel('$I$ $(MA)$')
plt.title(txt,y=1.03)
plt.grid(True)
plt.hold(True)
# Flatten I for the initial few time steps, where Amp-Far was not turned on yet
it_flat= 0 #10-1 # use nonampf value here
for it in range(0,it_flat):
Itor[it]=Itor[it_flat]
plot(timecode, (Itor)/1e3, 'o-', color='k', linewidth=2) #1/e3 to MA
# This line is very close to Itor:
#plot(timecode, np.dot(curr,darea)/1e6 ,'g', linewidth=1) # 1/e6 is to MA
plot(timecode, I_starnue , 'r.', linewidth=0.5)
plot(timecode, I_starnue0 ,'m.', linewidth=0.5)
plot(timecode, I_starnue-I_starnue0 ,'r--', linewidth=1) #= delta_sigma*Ephi
plot(timecode, I_bs_e_gen , 'g--', linewidth=1) # Bootstrap
# Add RE current, if available:
if i_ra==1:
I_RE= np.dot(curra,darea)/1e6 # 1/e6 is to MA
print 'min/max of I_RE [MA]', np.min(I_RE), np.max(I_RE)
plot(timecode, I_RE , 'r', linewidth=1)
# Add a plots of A*exp(-t/tau_decay) curves.
#(Start from time step =it_Imax where Itor reaches Max value A)
if iplot_tau_decay==1:
t00= timecode[it_Imax]
plot(timecode[it_Imax:nt], A*exp(-(timecode[it_Imax:nt]-t00)/tau_decay_0),color='r',linewidth=1)
plot(timecode[it_Imax:nt], A*exp(-(timecode[it_Imax:nt]-t00)/tau_decay_a),color='k',linewidth=1)
plot(timecode[it_Imax:nt], A*exp(-(timecode[it_Imax:nt]-t00)/tau_decay_par),color='g',linewidth=1)
savefig('Itor_time'+'.png')
show() #--------------------------------------------------------------------------
#-------------------------------------------------------------------------------
fig0=plt.figure(0)
ax = plt.subplot(111)
txt= "$|I_{tor}|$ $(MA)$" + ' $Black:curr, $ $Red:RE$'
plt.xlabel('$time$ $(sec)$')
plt.ylabel('$MA$')
plt.title(txt,y=1.02)
plt.grid(True)
plt.hold(True)
plt.minorticks_on() # To add minor ticks
plt.tick_params(which='both', width=1)
plt.tick_params(which='major', length=7)
plt.tick_params(which='minor', length=4, color='k')
xlim(( t_combined_low_lim, time_combined_max ))
plot(time_combined, np.abs(Ip_combined)/1e3, 'o-',color='b',linewidth=2) #1/e3 to MA
# Add RE current, if available:
if i_ra==1:
print 'min/max of I_RE [MA]', np.min(I_RE_combined), np.max(I_RE_combined)
plot(time_combined, np.abs(I_RE_combined), 'r', linewidth=1)
savefig('Itor_time_combined'+'.png')
show() #--------------------------------------------------------------------------
#stop
if i_ampf==1:
#---------- Plot E(r=0) vs time
itera=niter-1 # Plot Efld for this iteration (or select other <niter)
# itera can be 0,1,...,niter-1 (niter-1 is equal to nampfmax in CQL3D)
ir=1 # ir=0 or 1 corresponds to r~0 (plasma core)
Epk=np.transpose(elecfldn[itera,:,ir]) # Efld[time] at rho=0
E_rho_t=elecfldn[itera,:,:] # as 2D array (rho,t)
print 'shape of E_rho_t', np.shape(E_rho_t) # [ntime,lrz]
Emean_vs_t=np.mean(E_rho_t[:,1:],axis=1) #func of time. (averaged over rho at each t)
print 'shape of Emean_vs_t', np.shape(Emean_vs_t) #
Emin_vs_t=np.min(E_rho_t[:,1:],axis=1) #func of time. (MIN over rho at each t)
Emax_vs_t=np.max(E_rho_t[:,1:],axis=1) #func of time. (MAX over rho at each t)
fig0=plt.figure(1)
ax = plt.subplot(111)
txt= "$-o-E(r=0);$ $Green:MEAN;$ $Blue/Red:MIN/MAX$ $(V/m)$"
plt.xlabel('$time$ $(msec)$')
plt.ylabel('$(V/m)$')
plt.title(txt,y=1.02)
plt.grid(True)
plt.hold(True)
plot(timecode, Epk, 'o', color='k')
plot(timecode, Emean_vs_t, '-', color='g', linewidth=2)
plot(timecode, Emin_vs_t, '-', color='b', linewidth=2)
plot(timecode, Emax_vs_t, '-', color='r', linewidth=2)
# Add a plots of A*exp(-t/tau_decay) curves.
#(Start from time step =it_Emax where Epk reaches Max value A)
if (iplot_tau_decay==1):
# Add a plot of A*exp(-t/tau_decay) curves.
# Factor A will be taken from the peak value of Epk(time) curve.
A=0.
it_Emax=1
for itime in range(0,nt): # loop in time index
if abs(Epk[itime])>=abs(A):
A=Epk[itime]
it_Emax=itime
print ' Max or Min of Epk is at time step itime=it_Emax=',it_Emax
it_Emax=it_Imax+1 # Better use the time step corresponding to peak of I(time)
it_Emax=min(it_Emax,nt-1)
A=Epk[it_Emax]
t00= timecode[it_Emax] # msec
plot(timecode[it_Emax:nt], A*exp(-(timecode[it_Emax:nt]-t00)/tau_decay_0),color='r',linewidth=1)
plot(timecode[it_Emax:nt], A*exp(-(timecode[it_Emax:nt]-t00)/tau_decay_a),color='k',linewidth=1)
plot(timecode[it_Emax:nt], A*exp(-(timecode[it_Emax:nt]-t00)/tau_decay_par),color='g',linewidth=1)
savefig('E_time'+'.png')
show() #--------------------------------------------------------------------------
# Problem: rho was absent in nc file.
#rho=np.arange(0,1.0001,1.0/(lrz-1))
rho=rya # 'rya' is saved from index 1 to lrz in CQL3D/netcdfrw2.f
# Limits for plots:
rho_min= 0.0 #min(rho)
rho_max= 1.0 #max(rho)
# For mesh-type plots:
time_adj=timecode[it0:nt:ntstride] # msec
R,T = np.meshgrid(time_adj,rho) # 2D grids
R_combined,T_combined = np.meshgrid(time_combined,rho) # 2D grids for combined t
zdir = (None) # direction for plotting text (title)
xdir = (None) # direction
ydir = (None) # direction
# Mesh-type plots: Jpar[rho,time] A/cm^2
Jpar=np.transpose(curr[it0:nt:ntstride,:]) # Jpar[rho,time]
Jpar=np.abs(Jpar) # Sometimes it is negative. Plot |Jpar|
print T.shape, R.shape, Jpar.shape
Jpar_min=np.min(Jpar)
Jpar_max=np.max(Jpar)
print 'min/max of |Jpar| (A/cm^2):', np.min(Jpar),np.max(Jpar)
A=Jpar
fig0=plt.figure(3)
if imesh==1:
ax = Axes3D(fig0,azim=view_azim,elev=view_elev)
ax.plot_wireframe(T,(R),(A),rstride=200,cstride=1,cmap=cm.jet)
#ax.set_zscale('log') #------------- LOG10 SCALE --------------
#ax.set_zlim3d(A_max/1e4, A_max)
ax.set_xlim3d(0.,1.0)
ax.set_ylim3d(t_low_lim,timecode[nt-1] )
zdir = (None) # direction for plotting text (title)
xdir = (None) # direction
ydir = (None) # direction
ax.set_ylabel(r"$time$ $(msec)$", xdir)
ax.set_xlabel(r"$\rho$", ydir)
else: # imesh=0
plt.axis([0.,1.1, t_low_lim, timecode[nt-1]])
#levels=np.arange(0.,300.,10) # set values, for detailed zoom-in
#CS=plt.contour(T,(R),(A),levels,linewidth=linw,cmap=plt.cm.jet)
CS=plt.contour(T,(R),(A),Ncont,linewidth=linw,cmap=plt.cm.jet)
CB=plt.colorbar(orientation='vertical', shrink=0.9, format='%.2e')
if nstates>0:
plt.plot(pellet_rho[1:it_Mgone],timecode[1:it_Mgone],color='r',linewidth=linw*2)
plt.plot(pellet_rho[1:it_Mgone],timecode[1:it_Mgone],'k.')
plt.ylabel(r"$time$ $(msec)$", xdir)
plt.xlabel(r"$\rho$", ydir)
plt.grid(True)
plt.minorticks_on() # To add minor ticks
plt.tick_params(which='both', width=1)
plt.tick_params(which='major', length=7)
plt.tick_params(which='minor', length=4, color='k')
plt.title('$|J_{||}|$ $(A/cm^2)$',y=1.02)
savefig('Jpar_2D'+'.png')
plt.show()
# Jpar(rho) plots for each time instant, all together.
# Define line thickness, different for different time slices
linw_mx= 9*linw # largest thickness
linw_mn= 0.5 # smallest
itt=0
for itime in range(0,nt,ntstride): # loop in time index
itt=itt+1
linw_reducing=zeros((itt)) # initialize
if itt>1:
dlinw= (linw_mx-linw_mn)/(itt-1)
else:
dlinw=0
itt=0
for itime in range(0,nt,ntstride): # loop in time index
linw_reducing[itt]=linw_mx-itt*dlinw
itt=itt+1
W=np.abs(curr[:,:]) # [t,r]
fig0=plt.figure(4)
ax = plt.subplot(111)
W_max=np.max(W)
W_min=np.min(W)
xlim((0.,rho_max))
ylim_min=min(0.,W_min/2)
ylim_max=W_max*1.05
ylim((ylim_min, ylim_max)) # few orders of magnitude to show.
txt= "$|J_{||}|$ $(A/cm^2)$"
plt.xlabel(r'$\rho$', fontsize=34)
plt.title(txt,y=1.02)
plt.grid(True)
plt.hold(True)
icount=0
for it in it_select:
if it<nt:
W1=W[it,:]
for ir in range(0,lrz): # loop in rho index
W1[ir]= max(W1[ir], ylim_min/10) # all r: impose lower limit
linww= 4*linw-icount # Start with bold line, then reduce
linww=max(linww,0.75) # line thickness: not lower than 0.75pt
plot(rho,W1,linewidth=linww,color=col_select_it[icount])
txt1= r"$it=$"+r"$%3i$" %(it+1) #
txt2= r" $t[ms]=$"+r"$%1.3f$" %(timecode[it])
xpos_txt=rya[lrz-1]
ypos_txt=W1[lrz-1]
#plt.text(xpos_txt, ypos_txt, txt2, fontsize=fnt,\
#color=col_select_it[icount]
q0=(btor/rmag)/(0.2*3.14*W1[0]) #W1[0] is current dens at m.axis[A/cm^2]
print 'J vs rho: Added it,time[ms]=',it,timecode[it],\
' Max=',np.max(W1),' q0=',q0
#plt.semilogy(rya,W1,linewidth=linww,color=col_select_it[icount])
plot(rya,W1,linewidth=linww,color=col_select_it[icount])
icount=icount+1
savefig('Jpar_selected_it'+'.png')
show()
# E(rho) plots for selected it_combined over combined time_combined axis
W=np.abs(curr_combined[:,:]) # [t,r]
print 'shape of W=A=E',shape(W)
fig0=plt.figure(190) # # Jpar(rho) plots for selected it
ax = plt.subplot(111)
W_max=np.max(W)
W_min=np.min(W)
xlim((0.,rho_max))
ylim_min= min(W_min,0)
ylim_max= W_max*1.05
ylim((ylim_min, ylim_max))
txt= "$|J_{||}|$ $(A/cm^2)$"
plt.xlabel(r'$\rho$', fontsize=34)
plt.ylabel('$A/cm^2$')
plt.title(txt,y=1.02)
plt.grid(True)
plt.hold(True)
icount=0
for it in it_combined_select:
if it<nt_combined:
W1=W[it,:]
for ir in range(0,lrz): # loop in rho index
W1[ir]= max(W1[ir], ylim_min/10) # all r: impose lower limit
linww= 4*linw-icount # Start with bold line, then reduce
linww=max(linww,0.75) # line thickness: not lower than 0.75pt
plot(rho,W1,linewidth=linww,color=col_t_combined_select[icount])
txt1= r"$it=$"+r"$%3i$" %(it+1) #
txt2= r"$%1.3f$" %(time_combined[it]) +"$s$"
ir_txt=0 #icount+np.mod(icount,3)
xpos_txt=rya[ir_txt]
ypos_txt=W1[ir_txt]
plt.text(xpos_txt, ypos_txt, txt2, fontsize=fnt,\
color=col_t_combined_select[icount] )
icount=icount+1
savefig('Jpar_combined_selected_it'+'.png')
show()
fig0=plt.figure(14)
ax = plt.subplot(111)
Jpar_min=np.min(Jpar)
Jpar_max=np.max(Jpar)*1.1
ax.axis([0.,rho_max, 0.,Jpar_max])
txt= "$|J_{||}|$ $(A/cm^2)$"
plt.xlabel(r'$\rho$', fontsize=34)