示例#1
0
    def _parse_parameter_file(self):
        """
        Get the various simulation parameters & constants.
        """
        self.domain_left_edge = np.zeros(3, dtype='float')
        self.domain_right_edge = np.zeros(3, dtype='float') + 1.0
        self.dimensionality = 3
        self.refine_by = 2
        self.periodicity = (True, True, True)
        self.cosmological_simulation = True
        self.parameters = {}
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
        self.parameters.update(constants)
        self.parameters['Time'] = 1.0
        self.file_count = 1
        self.filename_template = self.parameter_filename

        # read the particle header
        self.particle_types = []
        self.particle_types_raw = ()
        assert self._file_particle_header
        with open(self._file_particle_header, "rb") as fh:
            seek = 4
            fh.seek(seek)
            headerstr = np.fromfile(fh, count=1, dtype=(str, 45))
            aexpn = np.fromfile(fh, count=1, dtype='>f4')
            aexp0 = np.fromfile(fh, count=1, dtype='>f4')
            amplt = np.fromfile(fh, count=1, dtype='>f4')
            astep = np.fromfile(fh, count=1, dtype='>f4')
            istep = np.fromfile(fh, count=1, dtype='>i4')
            partw = np.fromfile(fh, count=1, dtype='>f4')
            tintg = np.fromfile(fh, count=1, dtype='>f4')
            ekin = np.fromfile(fh, count=1, dtype='>f4')
            ekin1 = np.fromfile(fh, count=1, dtype='>f4')
            ekin2 = np.fromfile(fh, count=1, dtype='>f4')
            au0 = np.fromfile(fh, count=1, dtype='>f4')
            aeu0 = np.fromfile(fh, count=1, dtype='>f4')
            nrowc = np.fromfile(fh, count=1, dtype='>i4')
            ngridc = np.fromfile(fh, count=1, dtype='>i4')
            nspecs = np.fromfile(fh, count=1, dtype='>i4')
            nseed = np.fromfile(fh, count=1, dtype='>i4')
            Om0 = np.fromfile(fh, count=1, dtype='>f4')
            Oml0 = np.fromfile(fh, count=1, dtype='>f4')
            hubble = np.fromfile(fh, count=1, dtype='>f4')
            Wp5 = np.fromfile(fh, count=1, dtype='>f4')
            Ocurv = np.fromfile(fh, count=1, dtype='>f4')
            wspecies = np.fromfile(fh, count=10, dtype='>f4')
            lspecies = np.fromfile(fh, count=10, dtype='>i4')
            extras = np.fromfile(fh, count=79, dtype='>f4')
            boxsize = np.fromfile(fh, count=1, dtype='>f4')
        n = nspecs
        particle_header_vals = {}
        tmp = np.array([
            headerstr, aexpn, aexp0, amplt, astep, istep, partw, tintg, ekin,
            ekin1, ekin2, au0, aeu0, nrowc, ngridc, nspecs, nseed, Om0, Oml0,
            hubble, Wp5, Ocurv, wspecies, lspecies, extras, boxsize
        ])
        for i in range(len(tmp)):
            a1 = dmparticle_header_struct[0][i]
            a2 = dmparticle_header_struct[1][i]
            if a2 == 1:
                particle_header_vals[a1] = tmp[i][0]
            else:
                particle_header_vals[a1] = tmp[i][:a2]
        for specie in range(n):
            self.particle_types.append("specie%i" % specie)
        self.particle_types_raw = tuple(self.particle_types)
        ls_nonzero = np.diff(lspecies)[:n - 1]
        ls_nonzero = np.append(lspecies[0], ls_nonzero)
        self.star_type = len(ls_nonzero)
        mylog.info("Discovered %i species of particles", len(ls_nonzero))
        mylog.info("Particle populations: " + '%9i ' * len(ls_nonzero),
                   *ls_nonzero)
        for k, v in particle_header_vals.items():
            if k in self.parameters.keys():
                if not self.parameters[k] == v:
                    mylog.info("Inconsistent parameter %s %1.1e  %1.1e", k, v,
                               self.parameters[k])
            else:
                self.parameters[k] = v
        self.parameters_particles = particle_header_vals
        self.parameters.update(particle_header_vals)
        self.parameters['wspecies'] = wspecies[:n]
        self.parameters['lspecies'] = lspecies[:n]
        self.parameters['ng'] = self.parameters['Ngridc']
        self.parameters['ncell0'] = self.parameters['ng']**3
        self.parameters['boxh'] = self.parameters['boxsize']
        self.parameters['total_particles'] = ls_nonzero
        self.domain_dimensions = np.ones(3, dtype='int64') * 2  # NOT ng

        # setup standard simulation params yt expects to see
        self.current_redshift = self.parameters["aexpn"]**-1.0 - 1.0
        self.omega_lambda = particle_header_vals['Oml0']
        self.omega_matter = particle_header_vals['Om0']
        self.hubble_constant = particle_header_vals['hubble']
        self.min_level = 0
        self.max_level = 0
        #        self.min_level = particle_header_vals['min_level']
        #        self.max_level = particle_header_vals['max_level']
        #        if self.limit_level is not None:
        #            self.max_level = min(
        #                self.limit_level, particle_header_vals['max_level'])
        #        if self.force_max_level is not None:
        #            self.max_level = self.force_max_level
        self.hubble_time = 1.0 / (self.hubble_constant * 100 / 3.08568025e19)
        self.parameters['t'] = a2b(self.parameters['aexpn'])
        self.current_time = self.quan(b2t(self.parameters['t']), 'Gyr')
        self.gamma = self.parameters["gamma"]
        mylog.info("Max level is %02i", self.max_level)
示例#2
0
    def _parse_parameter_file(self):
        """
        Get the various simulation parameters & constants.
        """
        self.domain_left_edge = np.zeros(3, dtype="float")
        self.domain_right_edge = np.zeros(3, dtype="float") + 1.0
        self.dimensionality = 3
        self.refine_by = 2
        self.periodicity = (True, True, True)
        self.cosmological_simulation = True
        self.parameters = {}
        self.parameters.update(constants)
        self.parameters["Time"] = 1.0
        self.file_count = 1
        self.filename_template = self.parameter_filename

        # read the particle header
        self.particle_types = []
        self.particle_types_raw = ()
        assert self._file_particle_header
        with open(self._file_particle_header, "rb") as fh:
            seek = 4
            fh.seek(seek)
            headerstr = fh.read(45).decode("ascii")
            aexpn = np.fromfile(fh, count=1, dtype=">f4")
            aexp0 = np.fromfile(fh, count=1, dtype=">f4")
            amplt = np.fromfile(fh, count=1, dtype=">f4")
            astep = np.fromfile(fh, count=1, dtype=">f4")
            istep = np.fromfile(fh, count=1, dtype=">i4")
            partw = np.fromfile(fh, count=1, dtype=">f4")
            tintg = np.fromfile(fh, count=1, dtype=">f4")
            ekin = np.fromfile(fh, count=1, dtype=">f4")
            ekin1 = np.fromfile(fh, count=1, dtype=">f4")
            ekin2 = np.fromfile(fh, count=1, dtype=">f4")
            au0 = np.fromfile(fh, count=1, dtype=">f4")
            aeu0 = np.fromfile(fh, count=1, dtype=">f4")
            nrowc = np.fromfile(fh, count=1, dtype=">i4")
            ngridc = np.fromfile(fh, count=1, dtype=">i4")
            nspecs = np.fromfile(fh, count=1, dtype=">i4")
            nseed = np.fromfile(fh, count=1, dtype=">i4")
            Om0 = np.fromfile(fh, count=1, dtype=">f4")
            Oml0 = np.fromfile(fh, count=1, dtype=">f4")
            hubble = np.fromfile(fh, count=1, dtype=">f4")
            Wp5 = np.fromfile(fh, count=1, dtype=">f4")
            Ocurv = np.fromfile(fh, count=1, dtype=">f4")
            wspecies = np.fromfile(fh, count=10, dtype=">f4")
            lspecies = np.fromfile(fh, count=10, dtype=">i4")
            extras = np.fromfile(fh, count=79, dtype=">f4")
            boxsize = np.fromfile(fh, count=1, dtype=">f4")
        n = nspecs[0]
        particle_header_vals = {}
        tmp = np.array([
            headerstr,
            aexpn,
            aexp0,
            amplt,
            astep,
            istep,
            partw,
            tintg,
            ekin,
            ekin1,
            ekin2,
            au0,
            aeu0,
            nrowc,
            ngridc,
            nspecs,
            nseed,
            Om0,
            Oml0,
            hubble,
            Wp5,
            Ocurv,
            wspecies,
            lspecies,
            extras,
            boxsize,
        ])
        for i in range(len(tmp)):
            a1 = dmparticle_header_struct[0][i]
            a2 = dmparticle_header_struct[1][i]
            if a2 == 1:
                particle_header_vals[a1] = tmp[i][0]
            else:
                particle_header_vals[a1] = tmp[i][:a2]
        for specie in range(n):
            self.particle_types.append("specie%i" % specie)
        self.particle_types_raw = tuple(self.particle_types)
        ls_nonzero = np.diff(lspecies)[:n - 1]
        ls_nonzero = np.append(lspecies[0], ls_nonzero)
        self.star_type = len(ls_nonzero)
        mylog.info("Discovered %i species of particles", len(ls_nonzero))
        info_str = "Particle populations: " + "%9i " * len(ls_nonzero)
        mylog.info(info_str, *ls_nonzero)
        for k, v in particle_header_vals.items():
            if k in self.parameters.keys():
                if not self.parameters[k] == v:
                    mylog.info(
                        "Inconsistent parameter %s %1.1e  %1.1e",
                        k,
                        v,
                        self.parameters[k],
                    )
            else:
                self.parameters[k] = v
        self.parameters_particles = particle_header_vals
        self.parameters.update(particle_header_vals)
        self.parameters["wspecies"] = wspecies[:n]
        self.parameters["lspecies"] = lspecies[:n]
        self.parameters["ng"] = self.parameters["Ngridc"]
        self.parameters["ncell0"] = self.parameters["ng"]**3
        self.parameters["boxh"] = self.parameters["boxsize"]
        self.parameters["total_particles"] = ls_nonzero
        self.domain_dimensions = np.ones(3, dtype="int64") * 2  # NOT ng

        # setup standard simulation params yt expects to see
        # Convert to float to please unyt
        self.current_redshift = float(self.parameters["aexpn"]**-1.0 - 1.0)
        self.omega_lambda = float(particle_header_vals["Oml0"])
        self.omega_matter = float(particle_header_vals["Om0"])
        self.hubble_constant = float(particle_header_vals["hubble"])
        self.min_level = 0
        self.max_level = 0
        #        self.min_level = particle_header_vals['min_level']
        #        self.max_level = particle_header_vals['max_level']
        #        if self.limit_level is not None:
        #            self.max_level = min(
        #                self.limit_level, particle_header_vals['max_level'])
        #        if self.force_max_level is not None:
        #            self.max_level = self.force_max_level
        self.hubble_time = 1.0 / (self.hubble_constant * 100 / 3.08568025e19)
        self.parameters["t"] = a2b(self.parameters["aexpn"])
        self.current_time = self.quan(b2t(self.parameters["t"]), "Gyr")
        self.gamma = self.parameters["gamma"]
        mylog.info("Max level is %02i", self.max_level)