Skip to content

Commit

Permalink
cached max amr level
Browse files Browse the repository at this point in the history
  • Loading branch information
markusbattarbee committed Jan 21, 2021
1 parent d6673d7 commit 333eb57
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pyVlsv/vlsvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, file_name):
self.__fptr = open(self.file_name,"rb")
self.__xml_root = ET.fromstring("<VLSV></VLSV>")
self.__fileindex_for_cellid={}
self.__max_spatial_amr_level = -1

self.use_dict_for_blocks = False
self.__fileindex_for_cellid_blocks={} # [0] is index, [1] is blockcount
Expand Down Expand Up @@ -1097,15 +1098,18 @@ def read_variable_info(self, name, cellids=-1, operator="pass"):
def get_max_refinement_level(self):
''' Returns the maximum refinement level of the AMR
'''
# Read the file index for cellid
cellids=self.read(mesh="SpatialGrid",name="CellID", tag="VARIABLE")
maxcellid = max(cellids)

AMR_count = 0
while (maxcellid > 0):
maxcellid -= 2**(3*(AMR_count))*(self.__xcells*self.__ycells*self.__zcells)
AMR_count += 1
return AMR_count - 1
if self.__max_spatial_amr_level < 0:
# Read the file index for cellid
cellids=self.read(mesh="SpatialGrid",name="CellID", tag="VARIABLE")
maxcellid = max(cellids)

AMR_count = 0
while (maxcellid > 0):
maxcellid -= 2**(3*(AMR_count))*(self.__xcells*self.__ycells*self.__zcells)
AMR_count += 1

self.__max_spatial_amr_level = AMR_count - 1
return self.__max_spatial_amr_level

def get_amr_level(self,cellid):
'''Returns the AMR level of a given cell defined by its cellid
Expand Down

0 comments on commit 333eb57

Please sign in to comment.