Skip to content

Commit 0b0df02

Browse files
committed
Updated to marbl/miranda reader and adding support for miranda/samrai files.
1 parent a256e8a commit 0b0df02

File tree

1 file changed

+119
-19
lines changed

1 file changed

+119
-19
lines changed

pyranda/pyrandaMirandaReader.py

+119-19
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,46 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
7070
# Read in domain meta-data from master proc
7171
proc_num = 0
7272
filename = join(self.data_dir,'marbl_' + str(cycle).zfill(7) + '_' + str(proc_num).zfill(7) + '.hdf5')
73-
header = 'datagroup_' + str(proc_num).zfill(7)
73+
header = 'datagroup' #+ str(proc_num).zfill(7)
7474

7575
# Load hdf5 file
7676
f = h5py.File(filename,'r')
7777

7878
# Processor arrangement
79-
px = int(f[header + path_proc + 'px/value'].value)
80-
py = int(f[header + path_proc + 'py/value'].value)
81-
pz = int(f[header + path_proc + 'pz/value'].value)
82-
self.procs = [px,py,pz]
79+
px = int(f[header + path_proc + 'px/value'][0])
80+
py = int(f[header + path_proc + 'py/value'][0])
81+
pz = int(f[header + path_proc + 'pz/value'][0])
8382

8483
# Grid spacing
85-
dx = f[header + path_grid + 'dx/value'].value
86-
dy = f[header + path_grid + 'dy/value'].value
87-
dz = f[header + path_grid + 'dz/value'].value
88-
89-
# Import data as numpy array
90-
# Grab grid size for verificiation - Static location in blueprint?
91-
self.ax = ax = int(f[header + path_coord + 'i/value'].value) - 1
92-
self.ay = ay = int(f[header + path_coord + 'j/value'].value) - 1
93-
self.az = az = int(f[header + path_coord + 'k/value'].value) - 1
84+
try:
85+
dx = f[header + path_grid + 'dx/value'][0]
86+
self.ax = ax = int(f[header + path_coord + 'i/value'][0]) - 1
87+
except:
88+
dx = 1.0
89+
ax = 1
90+
91+
try:
92+
dy = f[header + path_grid + 'dy/value'][0]
93+
self.ay = ay = int(f[header + path_coord + 'j/value'][0]) - 1
94+
except:
95+
dy = 1.0
96+
ay = 1
97+
98+
try:
99+
dz = f[header + path_grid + 'dz/value'][0]
100+
self.az = az = int(f[header + path_coord + 'k/value'][0]) - 1
101+
except:
102+
dz = 1.0
103+
az = 1
104+
105+
# Correction for x-z 2D domains
106+
if (ax > 1) and (ay > 1) and (pz > 1) and (py==1):
107+
py = pz
108+
pz = 1
94109

110+
self.procs = [px,py,pz]
111+
112+
95113
# Need to get a mesh object here
96114
x1,xn = 0, dx*ax*px
97115
y1,yn = 0, dy*ay*py
@@ -102,6 +120,7 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
102120
mesh_options['xn'] = [xn,yn,zn]
103121
mesh_options['nn'] = [nx,ny,nz]
104122
mesh_options['periodic'] = periodic
123+
105124

106125
# Make pyranda instance
107126
self.pysim = pyrandaSim( rootdir + '_pyranda', mesh_options )
@@ -141,6 +160,8 @@ def update(self, cycle,fileType=0):
141160
self.data_dir = join(self.rootdir,'marbl_' + str(cycle).zfill(7))
142161
elif fileType == 1: # native miranda vis files
143162
self.data_dir = join(self.rootdir,'vis' + str(cycle).zfill(7))
163+
elif fileType == 2: # native miranda vis files
164+
self.data_dir = join(self.rootdir,'visit_dump.' + str(cycle).zfill(5))
144165

145166

146167
# Check if file exists
@@ -166,6 +187,22 @@ def setNativeVizDict(self,rosetta):
166187
for ii in self.var_list:
167188
varDict[ii] = miranda_viz_names[ rosetta[ii] ]
168189
self.var_index_dict = varDict
190+
191+
192+
def getMirandaSamraiVariables(self):
193+
194+
# Read in the first vis file to get variable list
195+
data_dir = join(self.rootdir,'visit_dump.' + str(0).zfill(5))
196+
filename = join(data_dir, 'processor_cluster.' + str(0).zfill(5) + ".samrai" )
197+
198+
# Load hdf5 file
199+
data = h5py.File(filename,'r')
200+
201+
# Use the 0-proc for variables
202+
sproc = str(0).zfill(5)
203+
header = 'processor.' + sproc + "/level.00000/patch." + sproc + "/"
204+
visit_vars = [dd for dd in data[header].keys()]
205+
return visit_vars
169206

170207
def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,fileType=0):
171208
"""
@@ -250,6 +287,7 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
250287
Lj1:Ljf,
251288
Lk1:Lkf]
252289

290+
253291
elif fileType == 1: # Miranda native graphics files
254292
filename = join(dump, 'p' + str(proc_num).zfill(8) )
255293

@@ -274,7 +312,25 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
274312
Kk1:Kkf] = DATA[Li1:Lif,
275313
Lj1:Ljf,
276314
Lk1:Lkf]
277-
315+
316+
317+
elif fileType == 2: # Samrai, single level only data
318+
filename = join(dump, 'processor_cluster.' + str(proc_num).zfill(5) + ".samrai" )
319+
320+
# Load hdf5 file
321+
f = h5py.File(filename,'r')
322+
file_grid_shape = ( int(ax), int(ay), int(az) )
323+
324+
for var in var_list:
325+
DATA = import_field_samrai(f,iproc,var,file_grid_shape)
326+
pysim.variables[var].data[Ki1:Kif,
327+
Kj1:Kjf,
328+
Kk1:Kkf] = DATA[Li1:Lif,
329+
Lj1:Ljf,
330+
Lk1:Lkf]
331+
332+
333+
278334

279335
def convert(str_array): # Convert numpy array of binary encoded chars to string
280336
s = ""
@@ -284,10 +340,21 @@ def convert(str_array): # Convert numpy array of binary encoded chars to str
284340

285341
def import_field(data, proc_num, var):
286342

287-
header = 'datagroup_' + str(proc_num).zfill(7)
288-
nx = int(data[header + path_coord + 'i/value'].value) - 1
289-
ny = int(data[header + path_coord + 'j/value'].value) - 1
290-
nz = int(data[header + path_coord + 'k/value'].value) - 1
343+
header = 'datagroup' #+ str(proc_num).zfill(7)
344+
try:
345+
nx = int(data[header + path_coord + 'i/value'][0]) - 1
346+
except:
347+
nx = 1
348+
try:
349+
ny = int(data[header + path_coord + 'j/value'][0]) - 1
350+
except:
351+
ny = 1
352+
try:
353+
nz = int(data[header + path_coord + 'k/value'][0]) - 1
354+
except:
355+
nz = 1
356+
357+
291358
n = (nx,ny,nz)
292359

293360
if var[0] == 'Y':
@@ -303,3 +370,36 @@ def import_field(data, proc_num, var):
303370
#print('Finished importing ' + var + '!')
304371

305372
return numpy.reshape(arr,n,order='F')
373+
374+
def import_field_samrai(data, proc_num, var, n):
375+
376+
sproc = str(proc_num).zfill(5)
377+
header = 'processor.' + sproc + "/level.00000/patch." + sproc + "/"
378+
379+
tmp = data[header + var] # Temp data holder
380+
arr = numpy.zeros(tmp.shape,dtype='float64') # Initialize array using dataset shape
381+
tmp.read_direct(arr) # Directly read in hdf5 dataset to numpy array
382+
383+
ax = n[0]
384+
ay = n[1]
385+
az = n[2]
386+
387+
xslc = slice(0,None)
388+
yslc = slice(0,None)
389+
zslc = slice(0,None)
390+
391+
if ax > 1:
392+
ax +=2
393+
xslc = slice(1,-1)
394+
if ay > 1:
395+
ay +=2
396+
yslc = slice(1,-1)
397+
if az > 1:
398+
az +=2
399+
zslc = slice(1,-1)
400+
401+
n_buffer = (ax,ay,az)
402+
403+
amrdata = numpy.reshape(arr,n_buffer,order='F')
404+
405+
return amrdata[xslc,yslc,zslc]

0 commit comments

Comments
 (0)