Skip to content

Commit

Permalink
Set max_level from parameter file
Browse files Browse the repository at this point in the history
This allows to, e.g. create a sphere object without ever reading most of the AMR file
  • Loading branch information
cphyc committed Nov 20, 2024
1 parent 9e483ce commit 6ed3f95
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions yt/frontends/ramses/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def __init__(self, ds, domain_id):
for t in ["grav", "amr"]:
setattr(self, f"{t}_fn", basename % t)
self._part_file_descriptor = part_file_descriptor
self.max_level = self.ds.parameters["levelmax"] - self.ds.parameters["levelmin"]

# Autodetect field files
field_handlers = [FH(self) for FH in get_field_handlers() if FH.any_exist(ds)]
Expand Down Expand Up @@ -276,15 +275,6 @@ def _read_amr_header(self):
self._amr_header = hvals
self._amr_offset = position

# The maximum effective level is the deepest level
# that has a non-zero number of octs
nocts_to_this_level = hvals["numbl"].sum(axis=1).cumsum()
self._max_level = (
np.argwhere(nocts_to_this_level == nocts_to_this_level[-1])[0][0]
- self.ds.parameters["levelmin"]
+ 1
)

# update levelmax
force_max_level, convention = self.ds._force_max_level
if convention == "yt":
Expand Down Expand Up @@ -312,12 +302,7 @@ def amr_offset(self):

@property
def max_level(self):
self._read_amr_header()
return self._max_level

@max_level.setter
def max_level(self, value):
self._max_level = value
return self.ds.max_level

@property
def total_oct_count(self):
Expand Down Expand Up @@ -373,7 +358,7 @@ def oct_handler(self):
f"The maximum level detected in the AMR file ({new_max_level}) "
f" does not match the expected number {self.max_level}."
)
self.max_level = new_max_level

self._oct_handler_initialized = True

return oct_handler
Expand Down Expand Up @@ -617,12 +602,9 @@ def _initialize_oct_handler(self):

self.domains = [RAMSESDomainFile(self.dataset, i + 1) for i in cpu_list]

@cached_property
@property
def max_level(self):
force_max_level, convention = self.ds._force_max_level
if convention == "yt":
force_max_level += self.ds.min_level + 1
return min(force_max_level, max(dom.max_level for dom in self.domains))
return self.ds.max_level

@cached_property
def num_grids(self):
Expand Down

0 comments on commit 6ed3f95

Please sign in to comment.