-
Notifications
You must be signed in to change notification settings - Fork 2
/
para_poynt.py
163 lines (145 loc) · 4.65 KB
/
para_poynt.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
import sys
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
from h5_utilities import *
import matplotlib.pyplot as plt
import sys
import getopt
import glob
import numpy as np
from mpi4py import MPI
def print_help():
print('para_poynt.py [options] <InputDir> <OutputName>')
print('options:')
print(' -n: average over n grid points at entrance (32 by default)')
print(' --avg: look into the -savg directory')
print(' --env: look into the -senv directory')
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:], "hxyn:", ['avg', 'env'])
except getopt.GetoptError:
print_help()
sys.exit(2)
if len(args) < 2:
print_help()
sys.exit(2)
dirName = args[0]
outFilename = args[1]
dir_ext = ''
n_avg = 32
sumdir = 1
tags = ''
for opt, arg in opts:
if opt == '-h':
print_help()
sys.exit()
elif opt == '--avg':
dir_ext = '-savg'
elif opt == '--env':
dir_ext = '-senv'
elif opt == '-n':
n_avg = arg
else:
print(print_help())
sys.exit(2)
avg_array=np.ones(n_avg)/n_avg
e2 = sorted(glob.glob(dirName + '/FLD/e2' + dir_ext + '/*.h5'))
e3 = sorted(glob.glob(dirName + '/FLD/e3' + dir_ext + '/*.h5'))
b2 = sorted(glob.glob(dirName + '/FLD/b2' + dir_ext + '/*.h5'))
b3 = sorted(glob.glob(dirName + '/FLD/b3' + dir_ext + '/*.h5'))
total_time = len(e2)
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
part = total_time / size
#
# read the second file to get the time-step
#
h5_filename = e2[1]
h5_data = osh5io.read_h5(h5_filename)
array_dims = h5_data.shape
nx = array_dims[0]
# ny = array_dims[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))
h5_output = np.zeros((total_time, nx))
total = np.zeros((total_time,nx))
#total = 0
total2 = 0
# if rank == 0:
# total = np.zeros((total_time, nx))
xaxis=h5_data.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(xaxis.min))
# print(repr(xaxis.max))
run_attrs = {'XMAX' : np.array( [ time_step * (total_time-1),xaxis.max] ) ,
'XMIN' : np.array( [0, xaxis.min, 0] ) }
# h5_output.run_attrs['TIME'] = 0.0
# h5_output.run_attrs['UNITS'] = 'm_e /T'
i_count = 0
file_number = 0
for file_number in range(i_begin, i_end):
e2_filename = e2[file_number]
e3_filename = e3[file_number]
b2_filename = b2[file_number]
b3_filename = b3[file_number]
if (i_count % 10 == 0 and rank == 0):
print(e2_filename)
i_count = i_count+1
e2_data = osh5io.read_h5(e2_filename)
e3_data = osh5io.read_h5(e3_filename)
b2_data = osh5io.read_h5(b2_filename)
b3_data = osh5io.read_h5(b3_filename)
s1_data = e2_data * b3_data - e3_data * b2_data
# print(s1_data.shape)
h5_output[file_number, 1:nx] = np.convolve(s1_data[1:nx],avg_array,mode='same')
# temp = np.sum(s1_data, axis=0) / nx
# h5_output.data[file_number, 1:ny] = temp[1:ny]
# temp = np.sum(s1_data[0:n_avg, :], axis=0) / n_avg
# income[file_number, 1:ny] = temp[1:ny]
# temp = np.sum(s1_data, axis=1) / ny
# h5_output2.data[file_number, 1:nx] = temp[1:nx]
# temp = np.sum(s1_data[:, 0:n_avg], axis=1) / n_avg
# income2[file_number, 1:nx] = temp[1:nx]
# file_number+=1
comm.Reduce(h5_output, total, op=MPI.SUM, root=0)
if rank == 0:
b=osh5def.H5Data(total, timestamp='x', data_attrs=data_attrs,
run_attrs=run_attrs, axes=[taxis,xaxis])
osh5io.write_h5(b,filename=outFilename)
# write_hdf(h5_output, outFilename)
print('Before barrier'+repr(rank))
comm.barrier()
# comm.Reduce(income, total, op=MPI.SUM, root=0)
# if rank == 0:
# h5_output.data = total
# newName = outFilename.rsplit('.', 1)[0] + '-x-n' + str(n_avg) + '.h5'
# write_hdf(h5_output, newName)
# comm.barrier()
# comm.Reduce(h5_output2.data, total2, op=MPI.SUM, root=0)
# if rank == 0:
# h5_output2.data = total2
# write_hdf(h5_output2, outFilename)
# comm.barrier()
# comm.Reduce(income2, total2, op=MPI.SUM, root=0)
# if rank == 0:
# h5_output2.data = total2
# newName = outFilename.rsplit('.', 1)[0] + '-y-n' + str(n_avg) + '.h5'
# write_hdf(h5_output2, newName)