-
Notifications
You must be signed in to change notification settings - Fork 2
/
para_filamentation_2d.py
197 lines (153 loc) · 5.18 KB
/
para_filamentation_2d.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
##################################################################################
# this script calculates growth of filamentation in LPI
# generated plasmas. In English, it looks at time history as a function of
# k_perp near k_parallel = 0.
# the script processes the entire
###################################################################################
#
import sys
# including my path and Han Wen's path
sys.path.append('/Users/franktsung/Documents/codes/python-tsung/')
sys.path.append('/Volumes/Lacie-5TB/codes/pyVisOS/')
#
import osh5io
import osh5def
import osh5vis
import osh5utils
# *****************************************************************************
# *****************************************************************************
# MPI related
import mpi4py
from mpi4py import MPI
# MPI related
# *****************************************************************************
# *****************************************************************************
from h5_utilities import *
import matplotlib.pyplot as plt
import sys
# command line options (argc, argv stuff)
import getopt
#
# glob -> finding files in a directory
import glob
#
import numpy as np
def file_name_field(path,field,file_no):
filename=path+'/FLD/'+field+'/'+field+'-'+repr(file_no).zfill(6)+'.h5'
# print(filename)
return(filename)
def file_name_phase(path,field,species,file_no):
filename=path+'/PHA/'+field+'/'+species+'/'+field+'-'+species+'-'+repr(file_no).zfill(6)+'.h5'
# print(filename)
return(filename)
def file_name_density(path,field,species,file_no):
filename=path+'/DENSITY/'+species+'/'+field+'/'+field+'-'+species+'-'+repr(file_no).zfill(6)+'.h5'
# print(filename)
return(filename)
def dir_name_density(path,field,species):
dirname = path+'/DENSITY/'+species+'/'+field+'/'
return(dirname)
def print_help():
print('mpirun -n X python para_filamentation_2d.py <xmin> <xmax> <InputDir> <OutputName>')
print('options:')
print(' -s: only process every S files')
# *****************************************************************************
# *****************************************************************************
# MPI initialization
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
# *****************************************************************************
# *****************************************************************************
# *****************************************************************************
argc = len(sys.argv)
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "hs:", ['avg', 'env'])
except getopt.GetoptError:
print_help()
sys.exit(2)
if len(args) < 4:
print_help()
sys.exit(2)
xmin = float(args[1])
xmax = float(args[2])
dirName = args[3]
outFilename = args[4]
dir_ext = ''
# default skip is 1
skip = 1
#
# set defaults for xmin and xmax
xmin=300
xmax=400
#
tags = ''
for opt, arg in opts:
if opt == '-h':
print_help()
sys.exit()
elif opt == '-s':
skip = arg
else:
print(print_help())
sys.exit(2)
ion_species_name = 'species_2'
ion_files = sorted(glob.glob(dirName + dir_ext + '/*.h5'))
total_time = len(ion_files)
my_share = total_time // size
i_begin = rank * my_share
if rank < (size - 1):
i_end = (rank + 1) * my_share
else:
i_end = total_time
avg_array=np.ones(n_avg)/n_avg
#
# read the second file to get the time-step
#
h5_filename = ion_files[0]
rho_0 = osh5io.read_h5(h5_filename)
rho_0_inverse = osh5utils.fft2(rho_0(rho_0.loc[:,xmin:xmax]))
array_dims = rho_0_inverse.shape
nx = array_dims[0]
ny = array_dims[1]
h5_data = osh5io.read_h5(ion_files[1])
time_step = h5_data.run_attrs['TIME'][0]
# h5_output = hdf_data()
# h5_output.shape = [total_time, nx]
print('nx=' + repr(nx))
print('ny=' + repr(ny))
print('time_step=' + repr(time_step))
print('total_time=' + repr(total_time))
# Here we initialize 2 variables
h5_output = np.zeros((total_time, nx))
total = np.zeros((total_time,nx))
#total = 0
total2 = 0
rho_0 = osh5io.read_h5()
kxaxis = rho_0_inverse.axes[0]
taxis=osh5def.DataAxis(0, time_step * (total_time -1), total_time,
attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'})
data_attrs = { 'UNITS': osh5def.OSUnits('m_e \omega_p^3'), 'NAME': 's1', 'LONG_NAME': 'S_1' }
print(repr(kxaxis.min))
print(repr(kxaxis.max))
run_attrs = {'XMAX' : np.array( [time_step * (total_time-1), kxaxis.max] ) ,
'XMIN' : np.array( [0, kxaxis.min ] ) }
# h5_output.run_attrs['TIME'] = 0.0
# h5_output.run_attrs['UNITS'] = 'm_e /T'
file_number = 0
for file_number in range(i_begin, i_end,skip):
# print(file_number)
ion_filename = ion_files[file_number]
ion_data = osh5io.read_h5(ion_filename)
del_ion = ion_data - rho_0
#if(file_number % 10 == 0):
#print(s1_data.shape)
rho_inverse= np.abs(osh5utils.fft2(del_ion.loc[:,xmin:xmax]))
# print(temp.shape)
h5_output[file_number, 1:nx] = rho_inverse[:,0.0]
comm.Reduce(h5_output, total, op=MPI.SUM, root=0)
if rank == 0:
h5_output = total
if rank == 0:
b=osh5def.H5Data(h5_output, timestamp='x', data_attrs=data_attrs,run_attrs=run_attrs, axes=[taxis, xaxis])
osh5io.write_h5(b,filename=outFilename)