Skip to content

Commit

Permalink
code deduplication: remove setup1d and setup2d in BoxlibDataset
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Sep 16, 2020
1 parent 86594af commit 8bcf84d
Showing 1 changed file with 24 additions and 43 deletions.
67 changes: 24 additions & 43 deletions yt/frontends/boxlib/data_structures.py
Expand Up @@ -755,7 +755,10 @@ def _parse_cparams(self):
elif param == "amr.ref_ratio":
vals = self.refine_by = int(vals[0])
elif param == "Prob.lo_bc":
vals = self.periodicity = tuple(p == "1" for p in vals.split())
vals = tuple(p == "1" for p in vals.split())
periodicity = [False, False, False]
periodicity[: len(vals)] = vals
self.periodicity = tuple(periodicity)
elif param == "castro.use_comoving":
vals = self.cosmological_simulation = int(vals)
else:
Expand Down Expand Up @@ -828,12 +831,16 @@ def _parse_header_file(self):
# This is traditionally a index attribute, so we will set it, but
# in a slightly hidden variable.
self._max_level = int(header_file.readline())
self.domain_left_edge = np.array(
dle = np.zeros(3, dtype="float64")
dle[: self.dimensionality] = np.array(
header_file.readline().split(), dtype="float64"
)
self.domain_right_edge = np.array(
self.domain_left_edge = dle
dre = np.ones(3, dtype="float64")
dre[: self.dimensionality] = np.array(
header_file.readline().split(), dtype="float64"
)
self.domain_right_edge = dre
ref_factors = np.array([int(i) for i in header_file.readline().split()])
if ref_factors.size == 0:
# We use a default of two, as Nyx doesn't always output this value
Expand Down Expand Up @@ -872,7 +879,10 @@ def _parse_header_file(self):
root_space = index_space.replace("(", "").replace(")", "").split()[:2]
start = np.array(root_space[0].split(","), dtype="int64")
stop = np.array(root_space[1].split(","), dtype="int64")
self.domain_dimensions = stop - start + 1
dd = np.ones(3, dtype="int64")
dd[: self.dimensionality] = stop - start + 1
self.domain_dimensions = dd

# Skip timesteps per level
header_file.readline()
self._header_mesh_start = header_file.tell()
Expand All @@ -885,53 +895,24 @@ def _parse_header_file(self):
coordinate_type = int(next_line)
else:
coordinate_type = 0
if coordinate_type == 0:
self.geometry = "cartesian"
elif coordinate_type == 1:
self.geometry = "cylindrical"
elif coordinate_type == 2:
self.geometry = "spherical"
else:
raise RuntimeError("Unknown BoxLib coord_type")

# overrides for 1/2-dimensional data
if self.dimensionality == 1:
self._setup1d()
elif self.dimensionality == 2:
self._setup2d()
known_types = {0: "cartesian", 1: "cylindrical", 2: "spherical"}
try:
self.geometry = known_types[coordinate_type]
except KeyError as err:
raise ValueError(f"Unknown BoxLib coord_type `{coordinate_type}`.") from err

if self.geometry == "cylindrical":
dre = self.domain_right_edge
dre[2] = 2.0 * np.pi
self.domain_right_edge = dre

def _set_code_unit_attributes(self):
setdefaultattr(self, "length_unit", self.quan(1.0, "cm"))
setdefaultattr(self, "mass_unit", self.quan(1.0, "g"))
setdefaultattr(self, "time_unit", self.quan(1.0, "s"))
setdefaultattr(self, "velocity_unit", self.quan(1.0, "cm/s"))

def _setup1d(self):
# self._index_class = BoxlibHierarchy1D
# self._fieldinfo_fallback = Orion1DFieldInfo
self.domain_left_edge = np.concatenate([self.domain_left_edge, [0.0, 0.0]])
self.domain_right_edge = np.concatenate([self.domain_right_edge, [1.0, 1.0]])
tmp = self.domain_dimensions.tolist()
tmp.extend((1, 1))
self.domain_dimensions = np.array(tmp)
periodicity = list(self.periodicity)
periodicity[1:] = False
self.periodicity = tuple(periodicity)

def _setup2d(self):
self.domain_left_edge = np.concatenate([self.domain_left_edge, [0.0]])
self.domain_right_edge = np.concatenate([self.domain_right_edge, [1.0]])
if self.geometry == "cylindrical":
dre = self.domain_right_edge
dre[2] = 2.0 * np.pi
self.domain_right_edge = dre
tmp = self.domain_dimensions.tolist()
tmp.append(1)
self.domain_dimensions = np.array(tmp)
periodicity = list(self.periodicity)
periodicity[2] = False
self.periodicity = tuple(tmp)

@parallel_root_only
def print_key_parameters(self):
for a in [
Expand Down

0 comments on commit 8bcf84d

Please sign in to comment.