7 nIndicesInRefLvl = list()
8 for refLvl
in np.arange(1,10):
9 nIndicesInRefLvl.append(gridSize * 2 ** ((refLvl - 1) * 3))
11 for i
in np.arange(len(nIndicesInRefLvl)):
12 if id <= sum(nIndicesInRefLvl[:i+1]):
17 print(
"cell {:3d}".format(id)+
" is not refined")
22 id2 = id - sum(nIndicesInRefLvl[:refLvl])
23 ix = (id2 - 1) % (xdim * 2 ** refLvl) + 1
24 iy = (id2 - 1) / (xdim * 2 ** refLvl) % (ydim * 2 ** refLvl) + 1
25 iz = (id2 - 1) / (xdim * 2 ** refLvl * ydim * 2 ** refLvl) + 1
26 parentId = (int(np.ceil(iz / 2.0) - 1) * xdim * 2 ** (refLvl - 1) * ydim * 2 ** (refLvl - 1) +
27 int(np.ceil(iy / 2.0) - 1) * xdim * 2 ** (refLvl - 1) +
28 int(np.ceil(ix / 2.0)) +
29 sum(nIndicesInRefLvl[:refLvl-1]))
31 print(
"id = {:3d}".format(id)+
", id2 = {:3d}".format(id2)+
32 ", col = {:2d}".format(ix)+
", row = {:2d}".format(iy)+
33 ", plane = {:2d}".format(iz)+
", parentId = {:2d}".format(parentId)+
34 ", refLvl = {:1d}".format(refLvl))
36 print(
"cell {:3d}".format(id)+
" is the child of cell {:2d}".format(parentId))
39 return parentId, refLvl
41def getChildren(children, parentIds, dimension = 0, up = True, left = True):
95 if id
in children.keys():
96 myChildren.extend(children[id][i1::N])
97 myChildren.extend(children[id][i2::N])
100 myChildren.append(id)
108filename =
"refined_4.out"
110lines = fh.readlines()
115for i,line
in enumerate(lines):
121 zdim = int(words[10])
123 ids.append(int(words[3]))
125gridSize = xdim*ydim*zdim
141 parents[id] = parentId
146 if not parentId
in ids
and parentId > 0:
151 if not parentId
in hasChildren:
152 children[parentId] = list()
153 hasChildren.append(parentId)
156 children[parentId].append(id)
160for key
in children.keys():
169 parentId = parents[id]
170 while parentId
is not 0:
171 isRefined[parentId] = refLvls[id] - refLvls[parentId]
172 parentId = parents[parentId]
183 dims = (zdim, ydim, xdim)
189 dims = (zdim, xdim, ydim)
191 x_index = (id-1) % xdim
192 y_index = ((id-1) / xdim) % ydim
193 idMapped = id - (x_index + y_index * xdim) + y_index + x_index * ydim
197 dims = (ydim, xdim, zdim)
199 x_index = (id-1) % xdim
200 y_index = ((id-1) / xdim) % ydim
201 z_index = ((id-1) / (xdim * ydim))
202 idMapped = 1 + z_index + y_index * zdim + x_index * ydim * zdim
206 mapping[idMapped] = id
217unrefinedPencils = list()
218for i
in np.arange(dims[0]):
219 for j
in np.arange(dims[1]):
220 ibeg = 1 + i * dims[2] * dims[1] + j * dims[2]
221 iend = 1 + i * dims[2] * dims[1] + (j + 1) * dims[2]
224 for k
in np.arange(ibeg,iend):
225 myIds.append(mapping[k])
226 myIsRefined.append(isRefined[mapping[k]])
227 unrefinedPencils.append({
'ids' : myIds,
228 'refLvl' : myIsRefined})
243for row,unrefinedPencil
in enumerate(unrefinedPencils):
245 maxRefLvl =
max(unrefinedPencil[
'refLvl'])
248 for i
in np.arange(2 ** maxRefLvl):
249 for j
in np.arange(2 ** maxRefLvl):
251 print(
'Starting new pencil, row = {:1d}, subrow = {:1d}, column = {:1d}'.format(row,i,j))
254 for ix
in np.arange(dims[2]):
255 maxLocalRefLvl = unrefinedPencil[
'refLvl'][ix]
257 print(
' ix = {:1d}, maxLocalRefLvl = {:1d}'.format(ix,maxLocalRefLvl))
259 parentIds.append(unrefinedPencil[
'ids'][ix])
263 for iref
in np.arange(
max(maxLocalRefLvl,1)):
266 left = ( (j / 2 ** (maxRefLvl - iref - 1)) % 2 == 0 )
267 up = ( (i / 2 ** (maxRefLvl - iref - 1)) % 2 == 0 )
269 print(
' iref = {:1d}, up = {:b}, left = {:b}'.format(iref,up,left))
276 offset = nUnRefined - iRefined
277 for k,icell
in enumerate(cells):
282 if isRefined[icell] == 0:
289 pencilIds.insert(-offset,icell)
291 pencilIds.append(icell)
297 parentIds.append(icell)
303 if len(pencils) == 0
or not pencilIds == pencils[-1][
'ids']:
304 pencils.append({
'ids' : pencilIds,
305 'length': len(pencilIds),
306 'width' : 2.0 ** -
max(unrefinedPencil[
'refLvl']),
311 print(
'Removing duplicate pencil')
317for i,pencil
in enumerate(pencils):
318 print(
"pencil {:2d}, ids: ".format(i), pencil[
'ids'])
getChildren(children, parentIds, dimension=0, up=True, left=True)
findParent(id, gridSize, debug)
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)