예제 #1
0
 def _parse_enzo3_parameter_file(self, f):
     self.parameters = p = libconf.load(f)
     sim = p["SimulationControl"]
     internal = p["Internal"]
     phys = p["Physics"]
     self.refine_by = sim["AMR"]["RefineBy"]
     self._periodicity = tuple(
         a == 3 for a in sim["Domain"]["LeftFaceBoundaryCondition"]
     )
     self.dimensionality = sim["Domain"]["TopGridRank"]
     self.domain_dimensions = np.array(
         sim["Domain"]["TopGridDimensions"], dtype="int64"
     )
     self.domain_left_edge = np.array(
         sim["Domain"]["DomainLeftEdge"], dtype="float64"
     )
     self.domain_right_edge = np.array(
         sim["Domain"]["DomainRightEdge"], dtype="float64"
     )
     self.gamma = phys["Hydro"]["Gamma"]
     self.unique_identifier = internal["Provenance"]["CurrentTimeIdentifier"]
     self.current_time = internal["InitialTime"]
     self.cosmological_simulation = phys["Cosmology"]["ComovingCoordinates"]
     if self.cosmological_simulation == 1:
         cosmo = phys["Cosmology"]
         self.current_redshift = internal["CosmologyCurrentRedshift"]
         self.omega_lambda = cosmo["OmegaLambdaNow"]
         self.omega_matter = cosmo["OmegaMatterNow"]
         self.hubble_constant = cosmo["HubbleConstantNow"]
     else:
         self.current_redshift = (
             self.omega_lambda
         ) = (
             self.omega_matter
         ) = self.hubble_constant = self.cosmological_simulation = 0.0
     self.particle_types = ["DarkMatter"] + phys["ActiveParticles"][
         "ActiveParticlesEnabled"
     ]
     self.particle_types = tuple(self.particle_types)
     self.particle_types_raw = self.particle_types
     if self.dimensionality == 1:
         self._setup_1d()
     elif self.dimensionality == 2:
         self._setup_2d()
예제 #2
0
    def _parse_parameter_file(self):
        """
        Parses the parameter file and establishes the various
        dictionaries.
        """

        f = open(self.parameter_filename, "r")
        # get dimension from first block name
        b0, fn0 = f.readline().strip().split()
        level0, left0, right0 = get_block_info(b0, min_dim=0)
        root_blocks = get_root_blocks(b0)
        f.close()
        self.dimensionality = left0.size
        self.periodicity = \
          ensure_tuple(np.ones(self.dimensionality, dtype=bool))

        lcfn = self.parameter_filename[:-len(self._suffix)] + ".libconfig"
        if os.path.exists(lcfn):
            with io.open(lcfn, "r") as lf:
                self.parameters = libconf.load(lf)
            cosmo = nested_dict_get(
                self.parameters, ("Physics", "cosmology"))
            if cosmo is not None:
                self.cosmological_simulation = 1
                co_pars = ["hubble_constant_now", "omega_matter_now",
                           "omega_lambda_now", "comoving_box_size",
                           "initial_redshift"]
                co_dict = \
                  dict((attr, nested_dict_get(self.parameters,
                    ("Physics", "cosmology", attr))) for attr in co_pars)
                for attr in ["hubble_constant",
                             "omega_matter",
                             "omega_lambda"]:
                    setattr(self, attr, co_dict["%s_now" % attr])

                # Current redshift is not stored, so it's not possible
                # to set all cosmological units yet.
                # Get the time units and use that to figure out redshift.
                k = cosmology_get_units(
                    self.hubble_constant, self.omega_matter,
                    co_dict["comoving_box_size"],
                    co_dict["initial_redshift"], 0)
                setdefaultattr(
                    self, 'time_unit', self.quan(k['utim'], 's'))
                co = Cosmology(hubble_constant=self.hubble_constant,
                               omega_matter=self.omega_matter,
                               omega_lambda=self.omega_lambda)
            else:
                self.cosmological_simulation = 0
        else:
            self.cosmological_simulation = 0


        fh = h5py.File(os.path.join(self.directory, fn0), "r")
        self.domain_left_edge  = fh.attrs["lower"]
        self.domain_right_edge = fh.attrs["upper"]

        # all blocks are the same size
        ablock = fh[list(fh.keys())[0]]
        self.current_time = ablock.attrs["time"][0]
        gsi = ablock.attrs["enzo_GridStartIndex"]
        gei = ablock.attrs["enzo_GridEndIndex"]
        self.ghost_zones = gsi[0]
        self.root_block_dimensions = root_blocks
        self.active_grid_dimensions = gei - gsi + 1
        self.grid_dimensions = ablock.attrs["enzo_GridDimension"]
        self.domain_dimensions = root_blocks * self.active_grid_dimensions
        fh.close()

        if self.cosmological_simulation:
            self.current_redshift = \
              co.z_from_t(self.current_time * self.time_unit)

        self.periodicity += (False, ) * (3 - self.dimensionality)
        self.gamma = nested_dict_get(self.parameters, ("Field", "gamma"))

        self.unique_identifier = \
          str(int(os.stat(self.parameter_filename)[stat.ST_CTIME]))