Skip to content

Commit

Permalink
ENH: Enable exporting GAMER and FLASH datasets to octrees (#4134)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturk authored May 24, 2023
1 parent 4a3c266 commit 6c3bc26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion yt/frontends/stream/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +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,
"left_edge": self.ds.domain_left_edge,
"right_edge": self.ds.domain_right_edge,
"octree": self.ds.octree_mask,
Expand Down
26 changes: 23 additions & 3 deletions yt/geometry/oct_container.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,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
Expand All @@ -184,6 +184,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):
Expand Down Expand Up @@ -566,7 +576,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
Expand All @@ -581,6 +595,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
Expand All @@ -598,7 +618,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):
Expand Down
11 changes: 10 additions & 1 deletion yt/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ def load_octree(
default_species_fields=None,
*,
parameters=None,
domain_dimensions=None,
dataset_name: str = "OctreeData",
):
r"""Load an octree mask into yt.
Expand Down Expand Up @@ -1084,6 +1085,9 @@ def load_octree(
parameters: dictionary, optional
Optional dictionary used to populate the dataset parameters, useful
for storing dataset metadata.
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.
dataset_name : string, optional
Optional string used to assign a name to the dataset. Stream datasets will use
this value in place of a filename (in image prefixing, etc.)
Expand Down Expand Up @@ -1122,7 +1126,12 @@ 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 = 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")
Expand Down

0 comments on commit 6c3bc26

Please sign in to comment.