[Yt-svn] commit/yt: MatthewTurk: Adding field caching for inline runs; don't bother re-searching for them.

Bitbucket commits-noreply at bitbucket.org
Thu Feb 24 18:34:06 PST 2011


1 new changeset in yt:

http://bitbucket.org/yt_analysis/yt/changeset/c81ca2e61e6a/
changeset:   r3770:c81ca2e61e6a
branch:      yt
user:        MatthewTurk
date:        2011-02-25 03:33:59
summary:     Adding field caching for inline runs; don't bother re-searching for them.
Also updating the contour tree to be slightly faster.
affected #:  3 files (1.1 KB)

--- a/yt/analysis_modules/level_sets/contour_finder.py	Thu Feb 24 19:25:31 2011 -0700
+++ b/yt/analysis_modules/level_sets/contour_finder.py	Thu Feb 24 18:33:59 2011 -0800
@@ -291,6 +291,7 @@
         total_contours += na.unique(grid["tempContours"][grid["tempContours"] > -1]).size
         new_contours = na.unique(grid["tempContours"][grid["tempContours"] > -1]).tolist()
         tree += zip(new_contours, new_contours)
+    tree = set(tree)
     pbar.finish()
     pbar = get_pbar("Calculating joins ", len(data_source._grids))
     grid_set = set()
@@ -299,9 +300,10 @@
         cg = grid.retrieve_ghost_zones(1, "tempContours", smoothed=False)
         grid_set.update(set(cg._grids))
         fd = cg["tempContours"].astype('int64')
-        tree += amr_utils.construct_boundary_relationships(fd)
+        boundary_tree = amr_utils.construct_boundary_relationships(fd)
+        tree.update(((a, b) for a, b in boundary_tree))
     pbar.finish()
-    sort_new = na.array(list(set(tree)), dtype='int64')
+    sort_new = na.array(list(tree), dtype='int64')
     mylog.info("Coalescing %s joins", sort_new.shape[0])
     joins = coalesce_join_tree(sort_new)
     #joins = [(i, na.array(list(j), dtype="int64")) for i, j in sorted(joins.items())]


--- a/yt/frontends/enzo/data_structures.py	Thu Feb 24 19:25:31 2011 -0700
+++ b/yt/frontends/enzo/data_structures.py	Thu Feb 24 18:33:59 2011 -0800
@@ -559,6 +559,18 @@
     def save_data(self, *args, **kwargs):
         pass
 
+    _cached_field_list = None
+    _cached_derived_field_list = None
+
+    def _detect_fields(self):
+        if self.__class__._cached_field_list is None:
+            EnzoHierarchy._detect_fields(self)
+            self.__class__._cached_field_list = self.field_list
+            self.__class__._cached_derived_field_list = self.derived_field_list
+        else:
+            self.field_list = self.__class__._cached_field_list
+            self.derived_field_list = self.__class__._cached_derived_field_list
+
     def _generate_random_grids(self):
         my_rank = self._mpi_get_rank()
         my_grids = self.grids[self.grid_procs.ravel() == my_rank]


--- a/yt/utilities/_amr_utils/ContourFinding.pyx	Thu Feb 24 19:25:31 2011 -0700
+++ b/yt/utilities/_amr_utils/ContourFinding.pyx	Thu Feb 24 18:33:59 2011 -0800
@@ -38,24 +38,27 @@
     if i0 < i1: return i0
     return i1
 
- at cython.boundscheck(False)
- at cython.wraparound(False)
+#@cython.boundscheck(False)
+#@cython.wraparound(False)
 def construct_boundary_relationships(
         np.ndarray[dtype=np.int64_t, ndim=3] contour_ids):
     # We only look at the boundary and one cell in
     cdef int i, j, nx, ny, nz, offset_i, offset_j, oi, oj
     cdef np.int64_t c1, c2
-    tree = []
     nx = contour_ids.shape[0]
     ny = contour_ids.shape[1]
     nz = contour_ids.shape[2]
+    # We allocate an array of fixed (maximum) size
+    cdef int s = (ny*nx + nx*nz + nx*nz - 4) * 9
+    cdef np.ndarray[np.int64_t, ndim=2] tree = np.zeros((s, 2), dtype="int64")
+    cdef int ti = 0
     # First x-pass
     for i in range(ny):
         for j in range(nz):
             for offset_i in range(3):
                 oi = offset_i - 1
                 if i == 0 and oi == -1: continue
-                if i == ny - 1 and oj == 1: continue
+                if i == ny - 1 and oi == 1: continue
                 for offset_j in range(3):
                     oj = offset_j - 1
                     if j == 0 and oj == -1: continue
@@ -63,18 +66,22 @@
                     c1 = contour_ids[0, i, j]
                     c2 = contour_ids[1, i + oi, j + oj]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
                     c1 = contour_ids[nx-1, i, j]
                     c2 = contour_ids[nx-2, i + oi, j + oj]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
     # Now y-pass
     for i in range(nx):
         for j in range(nz):
             for offset_i in range(3):
                 oi = offset_i - 1
                 if i == 0 and oi == -1: continue
-                if i == nx - 1 and oj == 1: continue
+                if i == nx - 1 and oi == 1: continue
                 for offset_j in range(3):
                     oj = offset_j - 1
                     if j == 0 and oj == -1: continue
@@ -82,17 +89,21 @@
                     c1 = contour_ids[i, 0, j]
                     c2 = contour_ids[i + oi, 1, j + oj]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
                     c1 = contour_ids[i, ny-1, j]
                     c2 = contour_ids[i + oi, ny-2, j + oj]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
     for i in range(nx):
         for j in range(ny):
             for offset_i in range(3):
                 oi = offset_i - 1
                 if i == 0 and oi == -1: continue
-                if i == nx - 1 and oj == 1: continue
+                if i == nx - 1 and oi == 1: continue
                 for offset_j in range(3):
                     oj = offset_j - 1
                     if j == 0 and oj == -1: continue
@@ -100,12 +111,16 @@
                     c1 = contour_ids[i, j, 0]
                     c2 = contour_ids[i + oi, j + oj, 1]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
                     c1 = contour_ids[i, j, nz-1]
                     c2 = contour_ids[i + oi, j + oj, nz-2]
                     if c1 > -1 and c2 > -1:
-                        tree.append((i64max(c1,c2), i64min(c1,c2)))
-    return tree
+                        tree[ti,0] = i64max(c1,c2)
+                        tree[ti,1] = i64min(c1,c2)
+                        ti += 1
+    return tree[:ti,:]
 
 cdef inline int are_neighbors(
             np.float64_t x1, np.float64_t y1, np.float64_t z1,

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