Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _cpui_level_iterator(cpu, amr_filename, bisection_order, maxlevel, ndim):
f = open(amr_filename, 'rb')
header = read_fortran_series(f, ramses_amr_header)
skip_fortran(f, 13)
n_per_level = read_fortran(f, _int_type, header[
'nlevelmax'] * header['ncpu']).reshape((header['nlevelmax'], header['ncpu']))
skip_fortran(f, 1)
if header['nboundary'] > 0:
skip_fortran(f, 2)
n_per_level_boundary = read_fortran(f, _int_type, header[
'nlevelmax'] * header['nboundary']).reshape((header['nlevelmax'], header['nboundary']))
skip_fortran(f, 2)
if bisection_order:
skip_fortran(f, 5)
else:
skip_fortran(f, 1)
skip_fortran(f, 3)
offset = np.array(header['ng'], dtype='f8') / 2
offset -= 0.5
coords = np.zeros(3, dtype=_float_type)
for level in xrange(maxlevel or header['nlevelmax']):
# loop through those CPUs with grid data (includes ghost regions)
for cpuf in 1 + np.where(n_per_level[level, :] != 0)[0]:
# print "CPU=",cpu,"CPU on
# disk=",cpuf,"npl=",n_per_level[level,cpuf-1]
offset = np.array(header['ng'], dtype='f8') / 2
offset -= 0.5
coords = np.zeros(3, dtype=_float_type)
for level in xrange(maxlevel or header['nlevelmax']):
# loop through those CPUs with grid data (includes ghost regions)
for cpuf in 1 + np.where(n_per_level[level, :] != 0)[0]:
# print "CPU=",cpu,"CPU on
# disk=",cpuf,"npl=",n_per_level[level,cpuf-1]
if cpuf == cpu:
# this is the data we want
skip_fortran(f, 3) # grid, next, prev index
# store the coordinates in temporary arrays. We only want
# to copy it if the cell is not refined
coords = [
read_fortran(f, _float_type, n_per_level[level, cpu - 1]) for ar in range(ndim)]
# stick on zeros if we're in less than 3D
coords += [np.zeros_like(coords[0]) for ar in range(3 - ndim)]
skip_fortran(f, 1 # father index
+ 2 * ndim # nbor index
# son index,cpumap,refinement map
+ 2 * (2 ** ndim)
)
refine = np.array(
# disk=",cpuf,"npl=",n_per_level[level,cpuf-1]
if cpuf == cpu:
# this is the data we want
skip_fortran(f, 3) # grid, next, prev index
# store the coordinates in temporary arrays. We only want
# to copy it if the cell is not refined
coords = [
read_fortran(f, _float_type, n_per_level[level, cpu - 1]) for ar in range(ndim)]
# stick on zeros if we're in less than 3D
coords += [np.zeros_like(coords[0]) for ar in range(3 - ndim)]
skip_fortran(f, 1 # father index
+ 2 * ndim # nbor index
# son index,cpumap,refinement map
+ 2 * (2 ** ndim)
)
refine = np.array(
[read_fortran(f, _int_type, n_per_level[level, cpu - 1]) for i in xrange(2 ** ndim)])
if level == maxlevel:
refine[:] = 0
coords[0] -= offset[0]
coords[1] -= offset[1]
coords[2] -= offset[2]
# x0-=offset[0]; y0-=offset[1]; z0-=offset[2]
header = read_fortran_series(f, ramses_amr_header)
skip_fortran(f, 13)
n_per_level = read_fortran(f, _int_type, header[
'nlevelmax'] * header['ncpu']).reshape((header['nlevelmax'], header['ncpu']))
skip_fortran(f, 1)
if header['nboundary'] > 0:
skip_fortran(f, 2)
n_per_level_boundary = read_fortran(f, _int_type, header[
'nlevelmax'] * header['nboundary']).reshape((header['nlevelmax'], header['nboundary']))
skip_fortran(f, 2)
if bisection_order:
skip_fortran(f, 5)
else:
skip_fortran(f, 1)
skip_fortran(f, 3)
offset = np.array(header['ng'], dtype='f8') / 2
offset -= 0.5
coords = np.zeros(3, dtype=_float_type)
for level in xrange(maxlevel or header['nlevelmax']):
# loop through those CPUs with grid data (includes ghost regions)
for cpuf in 1 + np.where(n_per_level[level, :] != 0)[0]:
# print "CPU=",cpu,"CPU on
# disk=",cpuf,"npl=",n_per_level[level,cpuf-1]
if cpuf == cpu:
def _cpui_level_iterator(cpu, amr_filename, bisection_order, maxlevel, ndim):
f = open(amr_filename, 'rb')
header = read_fortran_series(f, ramses_amr_header)
skip_fortran(f, 13)
n_per_level = read_fortran(f, _int_type, header[
'nlevelmax'] * header['ncpu']).reshape((header['nlevelmax'], header['ncpu']))
skip_fortran(f, 1)
if header['nboundary'] > 0:
skip_fortran(f, 2)
n_per_level_boundary = read_fortran(f, _int_type, header[
'nlevelmax'] * header['nboundary']).reshape((header['nlevelmax'], header['nboundary']))
skip_fortran(f, 2)
if bisection_order:
skip_fortran(f, 5)
else:
skip_fortran(f, 1)
skip_fortran(f, 3)
def _cpui_level_iterator(cpu, amr_filename, bisection_order, maxlevel, ndim):
f = open(amr_filename, 'rb')
header = read_fortran_series(f, ramses_amr_header)
skip_fortran(f, 13)
n_per_level = read_fortran(f, _int_type, header[
'nlevelmax'] * header['ncpu']).reshape((header['nlevelmax'], header['ncpu']))
skip_fortran(f, 1)
if header['nboundary'] > 0:
skip_fortran(f, 2)
n_per_level_boundary = read_fortran(f, _int_type, header[
'nlevelmax'] * header['nboundary']).reshape((header['nlevelmax'], header['nboundary']))
skip_fortran(f, 2)
if bisection_order:
skip_fortran(f, 5)
else:
skip_fortran(f, 1)
skip_fortran(f, 3)
offset = np.array(header['ng'], dtype='f8') / 2
offset -= 0.5
coords = np.zeros(3, dtype=_float_type)
skip_fortran(f, 13)
n_per_level = read_fortran(f, _int_type, header[
'nlevelmax'] * header['ncpu']).reshape((header['nlevelmax'], header['ncpu']))
skip_fortran(f, 1)
if header['nboundary'] > 0:
skip_fortran(f, 2)
n_per_level_boundary = read_fortran(f, _int_type, header[
'nlevelmax'] * header['nboundary']).reshape((header['nlevelmax'], header['nboundary']))
skip_fortran(f, 2)
if bisection_order:
skip_fortran(f, 5)
else:
skip_fortran(f, 1)
skip_fortran(f, 3)
offset = np.array(header['ng'], dtype='f8') / 2
offset -= 0.5
coords = np.zeros(3, dtype=_float_type)
for level in xrange(maxlevel or header['nlevelmax']):
# loop through those CPUs with grid data (includes ghost regions)
for cpuf in 1 + np.where(n_per_level[level, :] != 0)[0]:
# print "CPU=",cpu,"CPU on
# disk=",cpuf,"npl=",n_per_level[level,cpuf-1]
if cpuf == cpu:
# this is the data we want