[Yt-svn] commit/yt: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon May 30 09:44:49 PDT 2011


3 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/2ed6c9d0d81b/
changeset:   2ed6c9d0d81b
branches:    
user:        MatthewTurk
date:        2011-05-30 18:13:26
summary:     First pass at merging quadtrees.
affected #:  1 file (1.4 KB)

--- a/yt/utilities/_amr_utils/QuadTree.pyx	Fri May 27 16:55:32 2011 -0400
+++ b/yt/utilities/_amr_utils/QuadTree.pyx	Mon May 30 12:13:26 2011 -0400
@@ -257,3 +257,35 @@
                 QTN_free(self.root_nodes[i][j])
             free(self.root_nodes[i])
         free(self.root_nodes)
+
+cdef void QTN_merge_nodes(QuadTreeNode *n1, QuadTreeNode *n2):
+    # We have four choices when merging nodes.
+    # 1. If both nodes have no refinement, then we add values of n2 to n1.
+    # 2. If both have refinement, we call QTN_merge_nodes on all four children.
+    # 3. If n2 has refinement and n1 does not, we detach n2's children and
+    #    attach them to n1.
+    # 4. If n1 has refinement and n2 does not, we add the value of n2 to n1.
+    cdef int i, j
+
+    if n1.children[0][0] == n2.children[0][0] == NULL:
+        QTN_add_value(n1, n2.val, n2.weight_val)
+    elif n1.children[0][0] != NULL and n2.children[0][0] != NULL:
+        for i in range(2):
+            for j in range(2):
+                QTN_merge_nodes(n1.children[i][j], n2.children[i][j])
+    elif n1.children[0][0] == NULL and n2.children[0][0] != NULL:
+        for i in range(2):
+            for j in range(2):
+                n1.children[i][j] = n2.children[i][j]
+                n2.children[i][j] = NULL
+    elif n1.children[0][0] != NULL and n2.children[0][0] == NULL:
+        QTN_add_value(n1, n2.val, n2.weight_val)
+    else:
+        raise RuntimeError
+
+def merge_quadtrees(QuadTree qt1, QuadTree qt2):
+    cdef int i, j
+    for i in range(qt1.top_grid_dims[0]):
+        for j in range(qt1.top_grid_dims[1]):
+            QTN_merge_nodes(qt1.root_nodes[i][j],
+                            qt2.root_nodes[i][j])


http://bitbucket.org/yt_analysis/yt/changeset/445ccaa15354/
changeset:   445ccaa15354
branches:    
user:        MatthewTurk
date:        2011-05-30 18:35:57
summary:     Adding a 'merger' flag.  Testing indicates agreement so far.
affected #:  1 file (783 bytes)

--- a/yt/utilities/_amr_utils/QuadTree.pyx	Mon May 30 12:13:26 2011 -0400
+++ b/yt/utilities/_amr_utils/QuadTree.pyx	Mon May 30 12:35:57 2011 -0400
@@ -103,9 +103,11 @@
     cdef np.int64_t po2[80] 
     cdef QuadTreeNode ***root_nodes
     cdef np.int64_t top_grid_dims[2]
+    cdef int merged
 
     def __cinit__(self, np.ndarray[np.int64_t, ndim=1] top_grid_dims,
                   int nvals):
+        self.merged = 0
         cdef int i, j
         cdef QuadTreeNode *node
         cdef np.int64_t pos[2]
@@ -207,10 +209,15 @@
         cdef np.int64_t *pdata = <np.int64_t *> npos.data
         cdef np.float64_t *vdata = <np.float64_t *> nvals.data
         cdef np.float64_t *wdata = <np.float64_t *> nwvals.data
+        cdef np.float64_t wtoadd
+        cdef np.float64_t *vtoadd = <np.float64_t *> \
+                alloca(sizeof(np.float64_t) * self.nvals)
         for i in range(self.top_grid_dims[0]):
             for j in range(self.top_grid_dims[1]):
+                for vi in range(self.nvals): vtoadd[i] = 0.0
+                wtoadd = 0.0
                 curpos += self.fill_from_level(self.root_nodes[i][j],
-                    level, curpos, pdata, vdata, wdata)
+                    level, curpos, pdata, vdata, wdata, vtoadd, wtoadd)
         return npos, nvals, nwvals
 
     cdef int count_at_level(self, QuadTreeNode *node, int level):
@@ -232,22 +239,33 @@
                               np.int64_t curpos,
                               np.int64_t *pdata,
                               np.float64_t *vdata,
-                              np.float64_t *wdata):
+                              np.float64_t *wdata,
+                              np.float64_t *vtoadd,
+                              np.float64_t wtoadd):
         cdef int i, j
         if node.level == level:
             if node.children[0][0] != NULL: return 0
             for i in range(self.nvals):
-                vdata[self.nvals * curpos + i] = node.val[i]
-            wdata[curpos] = node.weight_val
+                vdata[self.nvals * curpos + i] = node.val[i] + vtoadd[i]
+            wdata[curpos] = node.weight_val + wtoadd
             pdata[curpos * 2] = node.pos[0]
             pdata[curpos * 2 + 1] = node.pos[1]
             return 1
         if node.children[0][0] == NULL: return 0
         cdef np.int64_t added = 0
+        if self.merged == 1:
+            for i in range(self.nvals):
+                vtoadd[i] += node.val[i]
+                wtoadd += node.weight_val
         for i in range(2):
             for j in range(2):
                 added += self.fill_from_level(node.children[i][j],
-                        level, curpos + added, pdata, vdata, wdata)
+                        level, curpos + added, pdata, vdata, wdata,
+                        vtoadd, wtoadd)
+        if self.merged == 1:
+            for i in range(self.nvals):
+                vtoadd[i] -= node.val[i]
+                wtoadd -= node.weight_val
         return added
 
     def __dealloc__(self):
@@ -289,3 +307,4 @@
         for j in range(qt1.top_grid_dims[1]):
             QTN_merge_nodes(qt1.root_nodes[i][j],
                             qt2.root_nodes[i][j])
+    qt1.merged = 1


http://bitbucket.org/yt_analysis/yt/changeset/27ac9de7256c/
changeset:   27ac9de7256c
branches:    
user:        MatthewTurk
date:        2011-05-30 18:41:45
summary:     Adding an early return in case there are no grids to project.
affected #:  1 file (56 bytes)

--- a/yt/data_objects/data_containers.py	Mon May 30 12:35:57 2011 -0400
+++ b/yt/data_objects/data_containers.py	Mon May 30 12:41:45 2011 -0400
@@ -1591,7 +1591,7 @@
             else:
                 ds = 0.0
             dxs.append(na.ones(nvals.shape[0], dtype='float64') * ds)
-        del tree
+        #self._tree = tree
         coord_data = na.concatenate(coord_data, axis=0).transpose()
         field_data = na.concatenate(field_data, axis=0).transpose()
         weight_data = na.concatenate(weight_data, axis=0).transpose()
@@ -1655,6 +1655,7 @@
 
     def _add_level_to_tree(self, tree, level, fields):
         grids_to_project = self.source.select_grids(level)
+        if len(grids_to_project) == 0: return
         dls, convs = self._get_dls(grids_to_project[0], fields)
         zero_out = (level != self._max_level)
         pbar = get_pbar('Projecting  level % 2i / % 2i ' \

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