Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to marbl/miranda reader and adding support for miranda/samrai… #79

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 119 additions & 19 deletions pyranda/pyrandaMirandaReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,46 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
# Read in domain meta-data from master proc
proc_num = 0
filename = join(self.data_dir,'marbl_' + str(cycle).zfill(7) + '_' + str(proc_num).zfill(7) + '.hdf5')
header = 'datagroup_' + str(proc_num).zfill(7)
header = 'datagroup' #+ str(proc_num).zfill(7)

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

# Processor arrangement
px = int(f[header + path_proc + 'px/value'].value)
py = int(f[header + path_proc + 'py/value'].value)
pz = int(f[header + path_proc + 'pz/value'].value)
self.procs = [px,py,pz]
px = int(f[header + path_proc + 'px/value'][0])
py = int(f[header + path_proc + 'py/value'][0])
pz = int(f[header + path_proc + 'pz/value'][0])

# Grid spacing
dx = f[header + path_grid + 'dx/value'].value
dy = f[header + path_grid + 'dy/value'].value
dz = f[header + path_grid + 'dz/value'].value

# Import data as numpy array
# Grab grid size for verificiation - Static location in blueprint?
self.ax = ax = int(f[header + path_coord + 'i/value'].value) - 1
self.ay = ay = int(f[header + path_coord + 'j/value'].value) - 1
self.az = az = int(f[header + path_coord + 'k/value'].value) - 1
try:
dx = f[header + path_grid + 'dx/value'][0]
self.ax = ax = int(f[header + path_coord + 'i/value'][0]) - 1
except:
dx = 1.0
ax = 1

try:
dy = f[header + path_grid + 'dy/value'][0]
self.ay = ay = int(f[header + path_coord + 'j/value'][0]) - 1
except:
dy = 1.0
ay = 1

try:
dz = f[header + path_grid + 'dz/value'][0]
self.az = az = int(f[header + path_coord + 'k/value'][0]) - 1
except:
dz = 1.0
az = 1

# Correction for x-z 2D domains
if (ax > 1) and (ay > 1) and (pz > 1) and (py==1):
py = pz
pz = 1

self.procs = [px,py,pz]


# Need to get a mesh object here
x1,xn = 0, dx*ax*px
y1,yn = 0, dy*ay*py
Expand All @@ -102,6 +120,7 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
mesh_options['xn'] = [xn,yn,zn]
mesh_options['nn'] = [nx,ny,nz]
mesh_options['periodic'] = periodic


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


# Check if file exists
Expand All @@ -166,6 +187,22 @@ def setNativeVizDict(self,rosetta):
for ii in self.var_list:
varDict[ii] = miranda_viz_names[ rosetta[ii] ]
self.var_index_dict = varDict


def getMirandaSamraiVariables(self):

# Read in the first vis file to get variable list
data_dir = join(self.rootdir,'visit_dump.' + str(0).zfill(5))
filename = join(data_dir, 'processor_cluster.' + str(0).zfill(5) + ".samrai" )

# Load hdf5 file
data = h5py.File(filename,'r')

# Use the 0-proc for variables
sproc = str(0).zfill(5)
header = 'processor.' + sproc + "/level.00000/patch." + sproc + "/"
visit_vars = [dd for dd in data[header].keys()]
return visit_vars

def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,fileType=0):
"""
Expand Down Expand Up @@ -250,6 +287,7 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
Lj1:Ljf,
Lk1:Lkf]


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

Expand All @@ -274,7 +312,25 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
Kk1:Kkf] = DATA[Li1:Lif,
Lj1:Ljf,
Lk1:Lkf]



elif fileType == 2: # Samrai, single level only data
filename = join(dump, 'processor_cluster.' + str(proc_num).zfill(5) + ".samrai" )

# Load hdf5 file
f = h5py.File(filename,'r')
file_grid_shape = ( int(ax), int(ay), int(az) )

for var in var_list:
DATA = import_field_samrai(f,iproc,var,file_grid_shape)
pysim.variables[var].data[Ki1:Kif,
Kj1:Kjf,
Kk1:Kkf] = DATA[Li1:Lif,
Lj1:Ljf,
Lk1:Lkf]




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

def import_field(data, proc_num, var):

header = 'datagroup_' + str(proc_num).zfill(7)
nx = int(data[header + path_coord + 'i/value'].value) - 1
ny = int(data[header + path_coord + 'j/value'].value) - 1
nz = int(data[header + path_coord + 'k/value'].value) - 1
header = 'datagroup' #+ str(proc_num).zfill(7)
try:
nx = int(data[header + path_coord + 'i/value'][0]) - 1
except:
nx = 1
try:
ny = int(data[header + path_coord + 'j/value'][0]) - 1
except:
ny = 1
try:
nz = int(data[header + path_coord + 'k/value'][0]) - 1
except:
nz = 1


n = (nx,ny,nz)

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

return numpy.reshape(arr,n,order='F')

def import_field_samrai(data, proc_num, var, n):

sproc = str(proc_num).zfill(5)
header = 'processor.' + sproc + "/level.00000/patch." + sproc + "/"

tmp = data[header + var] # Temp data holder
arr = numpy.zeros(tmp.shape,dtype='float64') # Initialize array using dataset shape
tmp.read_direct(arr) # Directly read in hdf5 dataset to numpy array

ax = n[0]
ay = n[1]
az = n[2]

xslc = slice(0,None)
yslc = slice(0,None)
zslc = slice(0,None)

if ax > 1:
ax +=2
xslc = slice(1,-1)
if ay > 1:
ay +=2
yslc = slice(1,-1)
if az > 1:
az +=2
zslc = slice(1,-1)

n_buffer = (ax,ay,az)

amrdata = numpy.reshape(arr,n_buffer,order='F')

return amrdata[xslc,yslc,zslc]
Loading