From 4e7ae8d5c195ba744dc2d9e58fb0017b5b8a6365 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 17 Sep 2022 08:44:59 -0500 Subject: [PATCH 1/8] Allow passing domain_dimensions to load_octree --- yt/frontends/stream/data_structures.py | 2 +- yt/loaders.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/yt/frontends/stream/data_structures.py b/yt/frontends/stream/data_structures.py index c5d9f4afc7e..28c54871743 100644 --- a/yt/frontends/stream/data_structures.py +++ b/yt/frontends/stream/data_structures.py @@ -836,7 +836,7 @@ def _setup_data_io(self): def _initialize_oct_handler(self): header = dict( - dims=[1, 1, 1], + dims=self.ds.domain_dimensions // self.ds.num_zones, left_edge=self.ds.domain_left_edge, right_edge=self.ds.domain_right_edge, octree=self.ds.octree_mask, diff --git a/yt/loaders.py b/yt/loaders.py index 7631032cfa4..a31c73c6edb 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -925,6 +925,7 @@ def load_octree( periodicity=(True, True, True), over_refine_factor=None, num_zones=2, + domain_dimensions=None, partial_coverage=1, unit_system="cgs", default_species_fields=None, @@ -977,6 +978,9 @@ def load_octree( determine the mean molecular weight. Options are "ionized" and "neutral". num_zones : int The number of zones along each dimension in an oct + domain_dimensions : array_like This is the domain dimensions of the root + *mesh*, which can be used to specify (indirectly) the number of root + oct nodes. parameters: dictionary, optional Optional dictionary used to populate the dataset parameters, useful for storing dataset metadata. @@ -1015,7 +1019,11 @@ def load_octree( # for compatibility if over_refine_factor is not None: nz = 1 << over_refine_factor - domain_dimensions = np.array([nz, nz, nz]) + if domain_dimensions is None: + # We assume that if it isn't specified, it defaults to the number of + # zones (i.e., a single root oct.) + domain_dimensions = [nz, nz, nz] + domain_dimensions = np.array(domain_dimensions) nprocs = 1 if bbox is None: bbox = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]], "float64") From 5497295922a5ff975c01c91d7211caada88dbb91 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sat, 17 Sep 2022 09:53:44 -0500 Subject: [PATCH 2/8] Re-arrange arguments --- yt/loaders.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yt/loaders.py b/yt/loaders.py index a31c73c6edb..2223a0bbb44 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -925,12 +925,12 @@ def load_octree( periodicity=(True, True, True), over_refine_factor=None, num_zones=2, - domain_dimensions=None, partial_coverage=1, unit_system="cgs", default_species_fields=None, *, parameters=None, + domain_dimensions=None, ): r"""Load an octree mask into yt. @@ -978,12 +978,12 @@ def load_octree( determine the mean molecular weight. Options are "ionized" and "neutral". num_zones : int The number of zones along each dimension in an oct - domain_dimensions : array_like This is the domain dimensions of the root - *mesh*, which can be used to specify (indirectly) the number of root - oct nodes. parameters: dictionary, optional Optional dictionary used to populate the dataset parameters, useful for storing dataset metadata. + domain_dimensions : array_like, optional + This is the domain dimensions of the root *mesh*, which can be used to + specify (indirectly) the number of root oct nodes. Example ------- From b58f6c3b640612421dac5baa7594b3a175d7214c Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Mon, 19 Sep 2022 10:09:57 -0500 Subject: [PATCH 3/8] Adding diagnostics for octree dev --- yt/geometry/oct_container.pyx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/yt/geometry/oct_container.pyx b/yt/geometry/oct_container.pyx index b0cbd6a4333..1f887a770c3 100644 --- a/yt/geometry/oct_container.pyx +++ b/yt/geometry/oct_container.pyx @@ -171,7 +171,7 @@ cdef class OctreeContainer: pos[2] = self.DLE[2] + dds[2]/2.0 for k in range(self.nn[2]): if self.root_mesh[i][j][k] == NULL: - raise RuntimeError + raise KeyError(i,j,k) visitor.pos[0] = i visitor.pos[1] = j visitor.pos[2] = k @@ -185,6 +185,16 @@ cdef class OctreeContainer: cdef np.int64_t get_domain_offset(self, int domain_id): return 0 + def check_root_mesh(self): + cdef count = 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: + print("Missing ", i, j, k) + count += 1 + print("Missing total of %s out of %s" % (count, self.nn[0] * self.nn[1] * self.nn[2])) + cdef int get_root(self, int ind[3], Oct **o) nogil: cdef int i for i in range(3): From 2a6d56d960267829186a3556c0c506e149b6e404 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Mon, 19 Sep 2022 11:06:20 -0500 Subject: [PATCH 4/8] Allow passing levels array to octree add --- yt/geometry/oct_container.pyx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yt/geometry/oct_container.pyx b/yt/geometry/oct_container.pyx index 1f887a770c3..f40bd0d22af 100644 --- a/yt/geometry/oct_container.pyx +++ b/yt/geometry/oct_container.pyx @@ -577,7 +577,11 @@ cdef class OctreeContainer: def add(self, int curdom, int curlevel, np.ndarray[np.float64_t, ndim=2] pos, int skip_boundary = 1, - int count_boundary = 0): + int count_boundary = 0, + np.ndarray[np.uint64_t, ndim=1, cast=True] levels = None + ): + # In this function, if we specify curlevel = -1, then we query the + # (optional) levels array for the oct level. cdef int no, p, i cdef int ind[3] cdef int nb = 0 @@ -592,6 +596,12 @@ cdef class OctreeContainer: cdef int in_boundary = 0 # How do we bootstrap ourselves? for p in range(no): + # We allow specifying curlevel = -1 to query from the levels array + # instead. + if curlevel == -1: + this_level = levels[p] + else: + this_level = curlevel #for every oct we're trying to add find the #floating point unitary position on this level in_boundary = 0 @@ -609,7 +619,7 @@ cdef class OctreeContainer: if cur == NULL: raise RuntimeError # Now we find the location we want # Note that RAMSES I think 1-findiceses levels, but we don't. - for _ in range(curlevel): + for _ in range(this_level): # At every level, find the cell this oct # lives inside for i in range(3): From 8e8a477e4be101384501cd5120ecddb03919903b Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Wed, 24 May 2023 10:26:11 -0500 Subject: [PATCH 5/8] Update yt/loaders.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- yt/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/loaders.py b/yt/loaders.py index 2223a0bbb44..61e91c6d8db 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -981,7 +981,7 @@ def load_octree( parameters: dictionary, optional Optional dictionary used to populate the dataset parameters, useful for storing dataset metadata. - domain_dimensions : array_like, optional + domain_dimensions : 3 elements array-like, optional This is the domain dimensions of the root *mesh*, which can be used to specify (indirectly) the number of root oct nodes. From c80a1e253b0cf7f7f93fb4edb3427412c1d40b46 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Wed, 24 May 2023 10:28:32 -0500 Subject: [PATCH 6/8] Update yt/geometry/oct_container.pyx --- yt/geometry/oct_container.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/geometry/oct_container.pyx b/yt/geometry/oct_container.pyx index b343e50cc5e..4156fe10716 100644 --- a/yt/geometry/oct_container.pyx +++ b/yt/geometry/oct_container.pyx @@ -184,7 +184,7 @@ cdef class OctreeContainer: cdef np.int64_t get_domain_offset(self, int domain_id): return 0 - def check_root_mesh(self): + def _check_root_mesh(self): cdef count = 0 for i in range(self.nn[0]): for j in range(self.nn[1]): From 397acc458515aa70e1e5412a372494e9fe14a6a8 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Wed, 24 May 2023 10:44:21 -0500 Subject: [PATCH 7/8] Update yt/loaders.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- yt/loaders.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yt/loaders.py b/yt/loaders.py index 20a27368da1..9f96b32e3e5 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -1129,8 +1129,9 @@ def load_octree( if domain_dimensions is None: # We assume that if it isn't specified, it defaults to the number of # zones (i.e., a single root oct.) - domain_dimensions = [nz, nz, nz] - domain_dimensions = np.array(domain_dimensions) + domain_dimensions = np.array([nz, nz, nz]) + else: + domain_dimensions = np.array(domain_dimensions) nprocs = 1 if bbox is None: bbox = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]], "float64") From 3e9ffaa75004b733f3d70eacde93d9da1fce2059 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Wed, 24 May 2023 10:50:28 -0500 Subject: [PATCH 8/8] Fix my merge conflict fix --- yt/frontends/stream/data_structures.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yt/frontends/stream/data_structures.py b/yt/frontends/stream/data_structures.py index 389fabfb556..61585d17b1a 100644 --- a/yt/frontends/stream/data_structures.py +++ b/yt/frontends/stream/data_structures.py @@ -858,8 +858,7 @@ def _setup_data_io(self): def _initialize_oct_handler(self): header = { - "dims": [1, 1, 1], - "dims" : self.ds.domain_dimensions // self.ds.num_zones, + "dims": self.ds.domain_dimensions // self.ds.num_zones, "left_edge": self.ds.domain_left_edge, "right_edge": self.ds.domain_right_edge, "octree": self.ds.octree_mask,