[Yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Sep 15 15:14:45 PDT 2011
2 new changesets in yt:
http://bitbucket.org/yt_analysis/yt/changeset/c7425a0fb5a8/
changeset: c7425a0fb5a8
branch: yt
user: MatthewTurk
date: 2011-09-15 17:27:57
summary: Speedup for hierarchy parsing in Enzo.
affected #: 2 files (-1 bytes)
--- a/yt/data_objects/grid_patch.py Mon Sep 12 20:21:17 2011 -0400
+++ b/yt/data_objects/grid_patch.py Thu Sep 15 11:27:57 2011 -0400
@@ -71,7 +71,7 @@
level.
"""
- if self.start_index != None:
+ if self.start_index is not None:
return self.start_index
if self.Parent == None:
iLE = self.LeftEdge - self.pf.domain_left_edge
--- a/yt/frontends/enzo/data_structures.py Mon Sep 12 20:21:17 2011 -0400
+++ b/yt/frontends/enzo/data_structures.py Thu Sep 15 11:27:57 2011 -0400
@@ -220,10 +220,9 @@
# Sets are sorted, so that won't work!
def _parse_hierarchy(self):
def _next_token_line(token, f):
- line = f.readline()
- while token not in line:
- line = f.readline()
- return line.split()[2:]
+ for line in f:
+ if line.startswith(token):
+ return line.split()[2:]
if os.path.exists(self.hierarchy_filename[:-9] + "harrays"):
if self._parse_binary_hierarchy(): return
t1 = time.time()
@@ -234,7 +233,6 @@
self.grids[0].Level = 0
si, ei, LE, RE, fn, np = [], [], [], [], [], []
all = [si, ei, LE, RE, fn]
- f.readline() # Blank at top
pbar = get_pbar("Parsing Hierarchy", self.num_grids)
for grid_id in xrange(self.num_grids):
pbar.update(grid_id)
@@ -248,15 +246,11 @@
if nb > 0: fn[-1] = _next_token_line("BaryonFileName", f)
np.append(int(_next_token_line("NumberOfParticles", f)[0]))
if nb == 0 and np[-1] > 0: fn[-1] = _next_token_line("FileName", f)
- line = f.readline()
- while len(line) > 2:
+ for line in f:
+ if len(line) < 2: break
if line.startswith("Pointer:"):
vv = patt.findall(line)[0]
self.__pointer_handler(vv)
- line = f.readline()
- continue
- params = line.split()
- line = f.readline()
pbar.finish()
self._fill_arrays(ei, si, LE, RE, np)
self.grids = na.array(self.grids, dtype='object')
http://bitbucket.org/yt_analysis/yt/changeset/5056a6511926/
changeset: 5056a6511926
branch: yt
user: MatthewTurk
date: 2011-09-16 00:14:29
summary: Merging
affected #: 3 files (-1 bytes)
--- a/yt/frontends/enzo/data_structures.py Thu Sep 15 11:27:57 2011 -0400
+++ b/yt/frontends/enzo/data_structures.py Thu Sep 15 18:14:29 2011 -0400
@@ -758,6 +758,8 @@
else:
if any("." in v or "e+" in v or "e-" in v for v in vals):
pcast = float
+ elif v == "inf":
+ pcast = str
else:
pcast = int
# Now we figure out what to do with it.
--- a/yt/utilities/amr_kdtree/amr_kdtree.py Thu Sep 15 11:27:57 2011 -0400
+++ b/yt/utilities/amr_kdtree/amr_kdtree.py Thu Sep 15 18:14:29 2011 -0400
@@ -60,6 +60,38 @@
def _rchild_id(id): return (id<<1) + 2
def _parent_id(id): return (id-1)>>1
+steps = na.array([[-1, -1, -1],
+ [-1, -1, 0],
+ [-1, -1, 1],
+ [-1, 0, -1],
+ [-1, 0, 0],
+ [-1, 0, 1],
+ [-1, 1, -1],
+ [-1, 1, 0],
+ [-1, 1, 1],
+
+ [ 0, -1, -1],
+ [ 0, -1, 0],
+ [ 0, -1, 1],
+ [ 0, 0, -1],
+ # [ 0, 0, 0],
+ [ 0, 0, 1],
+ [ 0, 1, -1],
+ [ 0, 1, 0],
+ [ 0, 1, 1],
+
+ [ 1, -1, -1],
+ [ 1, -1, 0],
+ [ 1, -1, 1],
+ [ 1, 0, -1],
+ [ 1, 0, 0],
+ [ 1, 0, 1],
+ [ 1, 1, -1],
+ [ 1, 1, 0],
+ [ 1, 1, 1]
+ ])
+
+
class MasterNode(object):
r"""
A MasterNode object is the building block of the AMR kd-Tree.
@@ -259,6 +291,7 @@
self.current_split_dim = 0
self.pf = pf
+ self.sdx = self.pf.h.get_smallest_dx()
self._id_offset = pf.h.grids[0]._id_offset
if nprocs > len(pf.h.grids):
mylog.info('Parallel rendering requires that the number of \n \
@@ -487,9 +520,97 @@
brick, le=le, re=re, periodic=periodic)]
return grids
+ def locate_neighbors_from_position(self, position):
+ r"""Given a position, finds the 26 neighbor grids
+ and cell indices.
+
+ This is a mostly a wrapper for locate_neighbors.
+
+ Parameters
+ ----------
+ position: array-like
+ Position of interest
+
+ Returns
+ -------
+ grids: Numpy array of Grid objects
+ cis: List of neighbor cell index tuples
+
+ Both of these are neighbors that, relative to the current cell
+ index (i,j,k), are ordered as:
+
+ (i-1, j-1, k-1), (i-1, j-1, k ), (i-1, j-1, k+1), ...
+ (i-1, j , k-1), (i-1, j , k ), (i-1, j , k+1), ...
+ (i+1, j+1, k-1), (i-1, j-1, k ), (i+1, j+1, k+1)
+
+ That is they start from the lower left and proceed to upper
+ right varying the third index most frequently. Note that the
+ center cell (i,j,k) is ommitted.
+
+ """
+ position = na.array(position)
+ grid = self.locate_brick(position).grid
+ ci = ((position-grid.LeftEdge)/grid.dds).astype('int64')
+ return self.locate_neighbors(grid,ci)
+
+ def locate_neighbors(self, grid, ci):
+ r"""Given a grid and cell index, finds the 26 neighbor grids
+ and cell indices.
+
+ Parameters
+ ----------
+ grid: Grid Object
+ Grid containing the cell of interest
+ ci: array-like
+ The cell index of the cell of interest
+
+ Returns
+ -------
+ grids: Numpy array of Grid objects
+ cis: List of neighbor cell index tuples
+
+ Both of these are neighbors that, relative to the current cell
+ index (i,j,k), are ordered as:
+
+ (i-1, j-1, k-1), (i-1, j-1, k ), (i-1, j-1, k+1), ...
+ (i-1, j , k-1), (i-1, j , k ), (i-1, j , k+1), ...
+ (i+1, j+1, k-1), (i-1, j-1, k ), (i+1, j+1, k+1)
+
+ That is they start from the lower left and proceed to upper
+ right varying the third index most frequently. Note that the
+ center cell (i,j,k) is ommitted.
+
+ """
+ ci = na.array(ci)
+ center_dds = grid.dds
+ position = grid.LeftEdge + (na.array(ci)+0.5)*grid.dds
+ grids = na.empty(26, dtype='object')
+ cis = na.empty([26,3], dtype='int64')
+ offs = 0.5*(center_dds + self.sdx)
+
+ new_cis = ci + steps
+ in_grid = na.all((new_cis >=0)*
+ (new_cis < grid.ActiveDimensions),axis=1)
+ new_positions = position + steps*offs
+ grids[in_grid] = grid
+
+ get_them = na.argwhere(in_grid != True).ravel()
+ cis[in_grid] = new_cis[in_grid]
+
+ if (in_grid != True).sum()>0:
+ grids[in_grid != True] = \
+ [self.locate_brick(new_positions[i]).grid for i in get_them]
+ cis[in_grid != True] = \
+ [(new_positions[i]-grids[i].LeftEdge)/
+ grids[i].dds for i in get_them]
+ cis = [tuple(ci) for ci in cis]
+ return grids, cis
+
def locate_brick(self, position):
r"""Given a position, find the node that contains it.
+ Will modify the position to account for periodicity.
+
Parameters
----------
pos: array_like
@@ -502,11 +623,17 @@
"""
node = self.tree
+ w = self.pf.domain_right_edge-self.pf.domain_left_edge
+ for i in range(3):
+ if position[i] < self.pf.domain_left_edge[i]:
+ position[i] += w[i]
+ if position[i] > self.pf.domain_right_edge[i]:
+ position[i] -= w[i]
while True:
if node.grid is not None:
return node
else:
- if position[node.split_ax] <= node.split_pos:
+ if position[node.split_ax] < node.split_pos:
node = node.left_child
else:
node = node.right_child
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list