Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] RAMSES: set max_level from parameter file #5060

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@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
Loading