[yt-svn] commit/yt-3.0: MatthewTurk: Adding domain ID and a deallocator to the particle octree

Bitbucket commits-noreply at bitbucket.org
Sat Aug 18 06:25:50 PDT 2012


1 new commit in yt-3.0:


https://bitbucket.org/yt_analysis/yt-3.0/changeset/b5e577214c43/
changeset:   b5e577214c43
branch:      yt-3.0
user:        MatthewTurk
date:        2012-08-18 15:25:39
summary:     Adding domain ID and a deallocator to the particle octree
affected #:  1 file

diff -r cb951d475d849fa15692beb8a8c05a8ae5b2b5ef -r b5e577214c438bea26414a2cc558dc742b55fc5e yt/geometry/oct_container.pyx
--- a/yt/geometry/oct_container.pyx
+++ b/yt/geometry/oct_container.pyx
@@ -419,6 +419,27 @@
 
 cdef class ParticleOctreeContainer(OctreeContainer):
 
+    def __dealloc__(self):
+        cdef i, j, k
+        for i in range(self.nn[0]):
+            for j in range(self.nn[1]):
+                for k in range(self.nn[2]):
+                    self.visit_free(self.root_mesh[i][j][k])
+
+    cdef visit_free(self, Oct *o):
+        cdef int i, j, k
+        for i in range(2):
+            for j in range(2):
+                for k in range(2):
+                    if o.children[i][j][k] == NULL: continue
+                    self.visit_free(o.children[i][j][k])
+        if o.sd.np >= 0:
+            for i in range(3):
+                free(o.sd.pos[i])
+            free(o.sd.domain_id)
+            free(o.sd.pos)
+        free(o)
+
     def allocate_domains(self, domain_counts):
         cdef int count, i
 
@@ -440,10 +461,11 @@
         sd.pos[0] = <np.float64_t *> malloc(sizeof(np.float64_t) * 32)
         sd.pos[1] = <np.float64_t *> malloc(sizeof(np.float64_t) * 32)
         sd.pos[2] = <np.float64_t *> malloc(sizeof(np.float64_t) * 32)
+        sd.domain_id = <np.int64_t *> malloc(sizeof(np.int64_t) * 32)
         sd.np = 0
         return my_oct
 
-    def add(self, np.ndarray[np.float64_t, ndim=2] pos):
+    def add(self, np.ndarray[np.float64_t, ndim=2] pos, np.int64_t domain_id):
         cdef int no = pos.shape[0]
         cdef int p, i, level
         cdef np.float64_t dds[3], cp[3], pp[3]
@@ -480,6 +502,7 @@
             pi = cur.sd.np
             for i in range(3):
                 cur.sd.pos[i][pi] = pp[i]
+            cur.sd.domain_id[pi] = domain_id
             cur.sd.np += 1
 
     cdef refine_oct(self, Oct *o, np.float64_t pos[3]):
@@ -503,9 +526,35 @@
             k = noct.sd.np
             for i in range(3):
                 noct.sd.pos[i][k] = o.sd.pos[i][m]
+            noct.sd.domain_id[k] = o.sd.domain_id[k]
             noct.sd.np += 1
         o.sd.np = -1
         for i in range(3):
             free(o.sd.pos[i])
+        free(o.sd.domain_id)
         free(o.sd.pos)
 
+    def recursively_count(self):
+        cdef int i, j, k
+        cdef np.int64_t counts[128]
+        for i in range(128): counts[i] = 0
+        for i in range(self.nn[0]):
+            for j in range(self.nn[1]):
+                for k in range(self.nn[2]):
+                    if self.root_mesh[i][j][k] != NULL:
+                        self.visit(self.root_mesh[i][j][k], counts)
+        level_counts = {}
+        for i in range(128):
+            if counts[i] == 0: break
+            level_counts[i] = counts[i]
+        return level_counts
+        
+    cdef visit(self, Oct *o, np.int64_t *counts, level = 0):
+        cdef int i, j, k
+        counts[level] += 1
+        for i in range(2):
+            for j in range(2):
+                for k in range(2):
+                    if o.children[i][j][k] != NULL:
+                        self.visit(o.children[i][j][k], counts, level + 1)
+        return

Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/

--

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