Exemplo n.º 1
0
    def load_kd_bricks(self, fn=None):
        if fn is None:
            fn = '%s_kd_bricks.h5' % self.ds
        if self.comm.rank != 0:
            self.comm.recv_array(self.comm.rank - 1, tag=self.comm.rank - 1)
        try:
            f = h5py.File(fn, "a")
            for node in depth_traverse(self.tree):
                i = node.node_id
                if node.grid != -1:
                    data = [
                        f["brick_%s_%s" % (hex(i), field)][:].astype('float64')
                        for field in self.fields
                    ]
                    node.data = PartitionedGrid(node.grid.id, data,
                                                node.l_corner.copy(),
                                                node.r_corner.copy(),
                                                node.dims.astype('int64'))

                    self.bricks.append(node.data)
                    self.brick_dimensions.append(node.dims)

            self.bricks = np.array(self.bricks)
            self.brick_dimensions = np.array(self.brick_dimensions)

            self._initialized = True
            f.close()
            del f
        except:
            pass
        if self.comm.rank != (self.comm.size - 1):
            self.comm.send_array([0], self.comm.rank + 1, tag=self.comm.rank)
    def load_kd_bricks(self,fn=None):
        if fn is None:
            fn = '%s_kd_bricks.h5' % self.ds
        if self.comm.rank != 0:
            self.comm.recv_array(self.comm.rank-1, tag=self.comm.rank-1)
        try:
            f = h5py.File(fn,"a")
            for node in depth_traverse(self.tree):
                i = node.node_id
                if node.grid != -1:
                    data = [f["brick_%s_%s" %
                              (hex(i), field)][:].astype('float64') for field in self.fields]
                    node.data = PartitionedGrid(node.grid.id, data,
                                                 node.l_corner.copy(), 
                                                 node.r_corner.copy(), 
                                                 node.dims.astype('int64'))
                    
                    self.bricks.append(node.data)
                    self.brick_dimensions.append(node.dims)

            self.bricks = np.array(self.bricks)
            self.brick_dimensions = np.array(self.brick_dimensions)

            self._initialized=True
            f.close()
            del f
        except:
            pass
        if self.comm.rank != (self.comm.size-1):
            self.comm.send_array([0],self.comm.rank+1, tag=self.comm.rank)
Exemplo n.º 3
0
 def sum_cells(self, all_cells=False):
     cells = 0
     for node in depth_traverse(self.trunk):
         if node.grid == -1:
             continue
         if not all_cells and not kd_is_leaf(node):
             continue
         grid = self.ds.index.grids[node.grid - self._id_offset]
         dds = grid.dds
         gle = grid.LeftEdge
         nle = self.ds.arr(get_left_edge(node), input_units="code_length")
         nre = self.ds.arr(get_right_edge(node), input_units="code_length")
         li = np.rint((nle - gle) / dds).astype('int32')
         ri = np.rint((nre - gle) / dds).astype('int32')
         dims = (ri - li).astype('int32')
         cells += np.prod(dims)
     return cells
 def sum_cells(self, all_cells=False):
     cells = 0
     for node in depth_traverse(self.trunk):
         if node.grid == -1:
             continue
         if not all_cells and not kd_is_leaf(node):
             continue
         grid = self.ds.index.grids[node.grid - self._id_offset]
         dds = grid.dds
         gle = grid.LeftEdge
         nle = self.ds.arr(get_left_edge(node), input_units="code_length")
         nre = self.ds.arr(get_right_edge(node), input_units="code_length")
         li = np.rint((nle-gle)/dds).astype('int32')
         ri = np.rint((nre-gle)/dds).astype('int32')
         dims = (ri - li).astype('int32')
         cells += np.prod(dims)
     return cells
Exemplo n.º 5
0
    def check_tree(self):
        for node in depth_traverse(self.trunk):
            if node.grid == -1:
                continue
            grid = self.ds.index.grids[node.grid - self._id_offset]
            dds = grid.dds
            gle = grid.LeftEdge
            nle = self.ds.arr(get_left_edge(node), input_units="code_length")
            nre = self.ds.arr(get_right_edge(node), input_units="code_length")
            li = np.rint((nle - gle) / dds).astype('int32')
            ri = np.rint((nre - gle) / dds).astype('int32')
            dims = (ri - li).astype('int32')
            assert (np.all(grid.LeftEdge <= nle))
            assert (np.all(grid.RightEdge >= nre))
            assert (np.all(dims > 0))
            # print grid, dims, li, ri

        # Calculate the Volume
        vol = kd_sum_volume(self.trunk)
        mylog.debug('AMRKDTree volume = %e' % vol)
        kd_node_check(self.trunk)
    def check_tree(self):
        for node in depth_traverse(self.trunk):
            if node.grid == -1:
                continue
            grid = self.ds.index.grids[node.grid - self._id_offset]
            dds = grid.dds
            gle = grid.LeftEdge
            nle = self.ds.arr(get_left_edge(node), input_units="code_length")
            nre = self.ds.arr(get_right_edge(node), input_units="code_length")
            li = np.rint((nle-gle)/dds).astype('int32')
            ri = np.rint((nre-gle)/dds).astype('int32')
            dims = (ri - li).astype('int32')
            assert(np.all(grid.LeftEdge <= nle))
            assert(np.all(grid.RightEdge >= nre))
            assert(np.all(dims > 0))
            # print grid, dims, li, ri

        # Calculate the Volume
        vol = kd_sum_volume(self.trunk)
        mylog.debug('AMRKDTree volume = %e' % vol)
        kd_node_check(self.trunk)
 def store_kd_bricks(self, fn=None):
     if not self._initialized:
         self.initialize_source()
     if fn is None:
         fn = '%s_kd_bricks.h5'%self.ds
     if self.comm.rank != 0:
         self.comm.recv_array(self.comm.rank-1, tag=self.comm.rank-1)
     f = h5py.File(fn,'w')
     for node in depth_traverse(self.tree):
         i = node.node_id
         if node.data is not None:
             for fi,field in enumerate(self.fields):
                 try:
                     f.create_dataset("/brick_%s_%s" % (hex(i),field),
                                      data = node.data.my_data[fi].astype('float64'))
                 except:
                     pass
     f.close()
     del f
     if self.comm.rank != (self.comm.size-1):
         self.comm.send_array([0],self.comm.rank+1, tag=self.comm.rank)
Exemplo n.º 8
0
 def store_kd_bricks(self, fn=None):
     if not self._initialized:
         self.initialize_source()
     if fn is None:
         fn = '%s_kd_bricks.h5' % self.ds
     if self.comm.rank != 0:
         self.comm.recv_array(self.comm.rank - 1, tag=self.comm.rank - 1)
     f = h5py.File(fn, 'w')
     for node in depth_traverse(self.tree):
         i = node.node_id
         if node.data is not None:
             for fi, field in enumerate(self.fields):
                 try:
                     f.create_dataset(
                         "/brick_%s_%s" % (hex(i), field),
                         data=node.data.my_data[fi].astype('float64'))
                 except:
                     pass
     f.close()
     del f
     if self.comm.rank != (self.comm.size - 1):
         self.comm.send_array([0], self.comm.rank + 1, tag=self.comm.rank)
Exemplo n.º 9
0
def test_amr_kdtree_coverage():
    return  #TESTDISABLED
    domain_dims = (32, 32, 32)
    data = np.zeros(domain_dims) + 0.25
    fo = [
        ic.CoredSphere(0.05, 0.3, [0.7, 0.4, 0.75], {"density": (0.25, 100.0)})
    ]
    rc = [fm.flagging_method_registry["overdensity"](8.0)]
    ug = load_uniform_grid({"density": data}, domain_dims, 1.0)
    ds = refine_amr(ug, rc, fo, 5)

    kd = AMRKDTree(ds)

    volume = kd.count_volume()
    yield assert_equal, volume, \
        np.prod(ds.domain_right_edge - ds.domain_left_edge)

    cells = kd.count_cells()
    true_cells = ds.all_data().quantities['TotalQuantity']('Ones')[0]
    yield assert_equal, cells, true_cells

    # This largely reproduces the AMRKDTree.tree.check_tree() functionality
    tree_ok = True
    for node in depth_traverse(kd.tree.trunk):
        if node.grid is None:
            continue
        grid = ds.index.grids[node.grid - kd._id_offset]
        dds = grid.dds
        gle = grid.LeftEdge
        nle = get_left_edge(node)
        nre = get_right_edge(node)
        li = np.rint((nle - gle) / dds).astype('int32')
        ri = np.rint((nre - gle) / dds).astype('int32')
        dims = (ri - li).astype('int32')
        tree_ok *= np.all(grid.LeftEdge <= nle)
        tree_ok *= np.all(grid.RightEdge >= nre)
        tree_ok *= np.all(dims > 0)

    yield assert_equal, True, tree_ok
def test_amr_kdtree_coverage():
    return #TESTDISABLED
    domain_dims = (32, 32, 32)
    data = np.zeros(domain_dims) + 0.25
    fo = [ic.CoredSphere(0.05, 0.3, [0.7, 0.4, 0.75],
                         {"density": (0.25, 100.0)})]
    rc = [fm.flagging_method_registry["overdensity"](8.0)]
    ug = load_uniform_grid({"density": data}, domain_dims, 1.0)
    ds = refine_amr(ug, rc, fo, 5)

    kd = AMRKDTree(ds)

    volume = kd.count_volume()
    yield assert_equal, volume, \
        np.prod(ds.domain_right_edge - ds.domain_left_edge)

    cells = kd.count_cells()
    true_cells = ds.all_data().quantities['TotalQuantity']('Ones')[0]
    yield assert_equal, cells, true_cells

    # This largely reproduces the AMRKDTree.tree.check_tree() functionality
    tree_ok = True
    for node in depth_traverse(kd.tree.trunk):
        if node.grid is None:
            continue
        grid = ds.index.grids[node.grid - kd._id_offset]
        dds = grid.dds
        gle = grid.LeftEdge
        nle = get_left_edge(node)
        nre = get_right_edge(node)
        li = np.rint((nle-gle)/dds).astype('int32')
        ri = np.rint((nre-gle)/dds).astype('int32')
        dims = (ri - li).astype('int32')
        tree_ok *= np.all(grid.LeftEdge <= nle)
        tree_ok *= np.all(grid.RightEdge >= nre)
        tree_ok *= np.all(dims > 0)

    yield assert_equal, True, tree_ok