@@ -70,28 +70,46 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
70
70
# Read in domain meta-data from master proc
71
71
proc_num = 0
72
72
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)
74
74
75
75
# Load hdf5 file
76
76
f = h5py .File (filename ,'r' )
77
77
78
78
# 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 ])
83
82
84
83
# 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
94
109
110
+ self .procs = [px ,py ,pz ]
111
+
112
+
95
113
# Need to get a mesh object here
96
114
x1 ,xn = 0 , dx * ax * px
97
115
y1 ,yn = 0 , dy * ay * py
@@ -102,6 +120,7 @@ def __init__(self, rootdir, var_list, periodic=[False,False,False]):
102
120
mesh_options ['xn' ] = [xn ,yn ,zn ]
103
121
mesh_options ['nn' ] = [nx ,ny ,nz ]
104
122
mesh_options ['periodic' ] = periodic
123
+
105
124
106
125
# Make pyranda instance
107
126
self .pysim = pyrandaSim ( rootdir + '_pyranda' , mesh_options )
@@ -141,6 +160,8 @@ def update(self, cycle,fileType=0):
141
160
self .data_dir = join (self .rootdir ,'marbl_' + str (cycle ).zfill (7 ))
142
161
elif fileType == 1 : # native miranda vis files
143
162
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 ))
144
165
145
166
146
167
# Check if file exists
@@ -166,6 +187,22 @@ def setNativeVizDict(self,rosetta):
166
187
for ii in self .var_list :
167
188
varDict [ii ] = miranda_viz_names [ rosetta [ii ] ]
168
189
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
169
206
170
207
def readChunkMiranda (pysim ,procs ,procMap ,dump ,cycle ,var_list ,var_index_dict ,fileType = 0 ):
171
208
"""
@@ -250,6 +287,7 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
250
287
Lj1 :Ljf ,
251
288
Lk1 :Lkf ]
252
289
290
+
253
291
elif fileType == 1 : # Miranda native graphics files
254
292
filename = join (dump , 'p' + str (proc_num ).zfill (8 ) )
255
293
@@ -274,7 +312,25 @@ def readChunkMiranda(pysim,procs,procMap,dump,cycle,var_list,var_index_dict,file
274
312
Kk1 :Kkf ] = DATA [Li1 :Lif ,
275
313
Lj1 :Ljf ,
276
314
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
+
278
334
279
335
def convert (str_array ): # Convert numpy array of binary encoded chars to string
280
336
s = ""
@@ -284,10 +340,21 @@ def convert(str_array): # Convert numpy array of binary encoded chars to str
284
340
285
341
def import_field (data , proc_num , var ):
286
342
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
+
291
358
n = (nx ,ny ,nz )
292
359
293
360
if var [0 ] == 'Y' :
@@ -303,3 +370,36 @@ def import_field(data, proc_num, var):
303
370
#print('Finished importing ' + var + '!')
304
371
305
372
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