示例#1
0
    def setup_particle_fields(self, ptype):
        """ additional particle fields derived from those in snapshot.
        we also need to add the smoothed fields here b/c setup_fluid_fields
        is called before setup_particle_fields. """

        smoothed_suffixes = ("_number_density", "_density", "_mass")

        # we add particle element fields for stars and gas
        #-----------------------------------------------------
        if ptype in self._add_elements:

            # this adds the particle element fields
            # X_density, X_mass, and X_number_density
            # where X is an item of self._elements.
            # X_fraction are defined in snapshot
            #-----------------------------------------------
            for s in self._elements:
                add_species_field_by_fraction(self,
                                              ptype,
                                              s,
                                              particle_type=True)

        # this needs to be called after the call to
        # add_species_field_by_fraction for some reason ...
        # not sure why yet.
        #-------------------------------------------------------
        if ptype == 'PartType0':
            ftype = 'gas'
        elif ptype == 'PartType1':
            ftype = 'dm'
        elif ptype == 'PartType2':
            ftype = 'PartType2'
        elif ptype == 'PartType3':
            ftype = 'PartType3'
        elif ptype == 'PartType4':
            ftype = 'star'
        elif ptype == 'PartType5':
            ftype = 'BH'
        elif ptype == 'all':
            ftype = 'all'

        super(OWLSFieldInfo,
              self).setup_particle_fields(ptype,
                                          num_neighbors=self._num_neighbors,
                                          ftype=ftype)

        # and now we add the smoothed versions for PartType0
        #-----------------------------------------------------
        if ptype == 'PartType0':

            # we only add ion fields for gas.  this takes some
            # time as the ion abundances have to be interpolated
            # from cloudy tables (optically thin)
            #-----------------------------------------------------

            # this defines the ion density on particles
            # X_density for all items in self._ions
            #-----------------------------------------------
            self.setup_gas_ion_density_particle_fields(ptype)

            # this adds the rest of the ion particle fields
            # X_fraction, X_mass, X_number_density
            #-----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                #---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                if (ptype, symbol + "_fraction") not in self.field_aliases:
                    continue

                pstr = "_p" + str(roman - 1)
                yt_ion = symbol + pstr

                # add particle field
                #---------------------------------------------------
                add_species_field_by_density(self,
                                             ptype,
                                             yt_ion,
                                             particle_type=True)

            # add smoothed ion fields
            #-----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                #---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                if (ptype, symbol + "_fraction") not in self.field_aliases:
                    continue

                pstr = "_p" + str(roman - 1)
                yt_ion = symbol + pstr

                loaded = []
                for sfx in smoothed_suffixes:
                    fname = yt_ion + sfx
                    fn = add_volume_weighted_smoothed_field(
                        ptype, "particle_position", "particle_mass",
                        "smoothing_length", "density", fname, self,
                        self._num_neighbors)
                    loaded += fn

                    self.alias(("gas", fname), fn[0])

                self._show_field_errors += loaded
                self.find_dependencies(loaded)
示例#2
0
文件: fields.py 项目: cphyc/yt
    def setup_particle_fields(self, ptype):
        """additional particle fields derived from those in snapshot.
        we also need to add the smoothed fields here b/c setup_fluid_fields
        is called before setup_particle_fields."""

        smoothed_suffixes = ("_number_density", "_density", "_mass")

        # we add particle element fields for stars and gas
        # -----------------------------------------------------
        if ptype in self._add_elements:

            # this adds the particle element fields
            # X_density, X_mass, and X_number_density
            # where X is an item of self._elements.
            # X_fraction are defined in snapshot
            # -----------------------------------------------
            for s in self._elements:
                field_names = add_species_field_by_fraction(self, ptype, s)
                if ptype == self.ds._sph_ptypes[0]:
                    for fn in field_names:
                        self.alias(("gas", fn[1]), fn)

        # this needs to be called after the call to
        # add_species_field_by_fraction for some reason ...
        # not sure why yet.
        # -------------------------------------------------------
        if ptype == "PartType0":
            ftype = "gas"
        else:
            ftype = ptype

        super().setup_particle_fields(
            ptype, num_neighbors=self._num_neighbors, ftype=ftype
        )

        # and now we add the smoothed versions for PartType0
        # -----------------------------------------------------
        if ptype == "PartType0":

            # we only add ion fields for gas.  this takes some
            # time as the ion abundances have to be interpolated
            # from cloudy tables (optically thin)
            # -----------------------------------------------------

            # this defines the ion density on particles
            # X_density for all items in self._ions
            # -----------------------------------------------
            self.setup_gas_ion_particle_fields(ptype)

            # this adds the rest of the ion particle fields
            # X_fraction, X_mass, X_number_density
            # -----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                # ---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                if (ptype, symbol + "_fraction") not in self.field_aliases:
                    continue

                pstr = f"_p{roman - 1}"
                yt_ion = symbol + pstr

                # add particle field
                # ---------------------------------------------------
                add_species_field_by_density(self, ptype, yt_ion)

            def _h_p1_density(field, data):
                return data[ptype, "H_density"] - data[ptype, "H_p0_density"]

            self.add_field(
                (ptype, "H_p1_density"),
                sampling_type="particle",
                function=_h_p1_density,
                units=self.ds.unit_system["density"],
            )

            add_species_field_by_density(self, ptype, "H_p1")
            for sfx in ["mass", "density", "number_density"]:
                fname = "H_p1_" + sfx
                self.alias(("gas", fname), (ptype, fname))

            def _el_number_density(field, data):
                n_e = data[ptype, "H_p1_number_density"]
                n_e += data[ptype, "He_p1_number_density"]
                n_e += 2.0 * data[ptype, "He_p2_number_density"]

            self.add_field(
                (ptype, "El_number_density"),
                sampling_type="particle",
                function=_el_number_density,
                units=self.ds.unit_system["number_density"],
            )
            self.alias(("gas", "El_number_density"), (ptype, "El_number_density"))

            # alias ion fields
            # -----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                # ---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                if (ptype, symbol + "_fraction") not in self.field_aliases:
                    continue

                pstr = f"_p{roman - 1}"
                yt_ion = symbol + pstr

                for sfx in smoothed_suffixes:
                    fname = yt_ion + sfx
                    self.alias(("gas", fname), (ptype, fname))
示例#3
0
    def setup_gas_particle_fields(self, ptype):
        super().setup_gas_particle_fields(ptype)

        if (ptype, "InternalEnergy") in self.field_list:

            def _pressure(field, data):
                return ((data.ds.gamma - 1.0) * data[ptype, "density"] *
                        data[ptype, "InternalEnergy"])

            self.add_field(
                (ptype, "pressure"),
                function=_pressure,
                sampling_type="particle",
                units=self.ds.unit_system["pressure"],
            )

        if (ptype, "GFM_Metals_00") in self.field_list:
            self.nuclei_names = metal_elements
            self.species_names = ["H"]
            if (ptype, "NeutralHydrogenAbundance") in self.field_list:
                self.species_names += ["H_p0", "H_p1"]
            self.species_names += metal_elements

        if (ptype, "MagneticField") in self.field_list:
            setup_magnetic_field_aliases(self, ptype, "MagneticField")

        if (ptype, "NeutralHydrogenAbundance") in self.field_list:

            def _h_p0_fraction(field, data):
                return (data[ptype, "GFM_Metals_00"] *
                        data[ptype, "NeutralHydrogenAbundance"])

            self.add_field(
                (ptype, "H_p0_fraction"),
                sampling_type="particle",
                function=_h_p0_fraction,
                units="",
            )

            def _h_p1_fraction(field, data):
                return data[ptype, "GFM_Metals_00"] * (
                    1.0 - data[ptype, "NeutralHydrogenAbundance"])

            self.add_field(
                (ptype, "H_p1_fraction"),
                sampling_type="particle",
                function=_h_p1_fraction,
                units="",
            )

            add_species_field_by_fraction(self, ptype, "H_p0")
            add_species_field_by_fraction(self, ptype, "H_p1")

            for species in ["H", "H_p0", "H_p1"]:
                for suf in ["_density", "_number_density"]:
                    field = f"{species}{suf}"
                    self.alias(("gas", field), (ptype, field))

            self.alias(("gas", "H_nuclei_density"),
                       ("gas", "H_number_density"))

        if (ptype, "ElectronAbundance") in self.field_list:

            def _el_number_density(field, data):
                return (data[ptype, "ElectronAbundance"] *
                        data[ptype, "H_number_density"])

            self.add_field(
                (ptype, "El_number_density"),
                sampling_type="particle",
                function=_el_number_density,
                units=self.ds.unit_system["number_density"],
            )
            self.alias(("gas", "El_number_density"),
                       (ptype, "El_number_density"))
示例#4
0
    def setup_gas_particle_fields(self, ptype):
        super().setup_gas_particle_fields(ptype)

        # Since the AREPO gas "particles" are Voronoi cells, we can
        # define a volume here
        def _volume(field, data):
            return data[ptype, "mass"] / data[ptype, "density"]

        self.add_field(
            (ptype, "cell_volume"),
            function=_volume,
            sampling_type="local",
            units=self.ds.unit_system["volume"],
        )

        if (ptype, "InternalEnergy") in self.field_list:

            def _pressure(field, data):
                return ((data.ds.gamma - 1.0) * data[ptype, "density"] *
                        data[ptype, "InternalEnergy"])

            self.add_field(
                (ptype, "pressure"),
                function=_pressure,
                sampling_type="particle",
                units=self.ds.unit_system["pressure"],
            )

            self.alias((ptype, "pressure"), ("gas", "pressure"))

        if (ptype, "GFM_Metals_00") in self.field_list:
            self.nuclei_names = metal_elements
            self.species_names = ["H"]
            if (ptype, "NeutralHydrogenAbundance") in self.field_list:
                self.species_names += ["H_p0", "H_p1"]
            self.species_names += metal_elements

        if (ptype, "MagneticField") in self.field_list:
            setup_magnetic_field_aliases(self, ptype, "MagneticField")

        if (ptype, "NeutralHydrogenAbundance") in self.field_list:

            def _h_p0_fraction(field, data):
                return (data[ptype, "GFM_Metals_00"] *
                        data[ptype, "NeutralHydrogenAbundance"])

            self.add_field(
                (ptype, "H_p0_fraction"),
                sampling_type="particle",
                function=_h_p0_fraction,
                units="",
            )

            def _h_p1_fraction(field, data):
                return data[ptype, "GFM_Metals_00"] * (
                    1.0 - data[ptype, "NeutralHydrogenAbundance"])

            self.add_field(
                (ptype, "H_p1_fraction"),
                sampling_type="particle",
                function=_h_p1_fraction,
                units="",
            )

            add_species_field_by_fraction(self, ptype, "H_p0")
            add_species_field_by_fraction(self, ptype, "H_p1")

            for species in ["H", "H_p0", "H_p1"]:
                for suf in ["_density", "_number_density"]:
                    field = f"{species}{suf}"
                    self.alias(("gas", field), (ptype, field))

            self.alias(("gas", "H_nuclei_density"),
                       ("gas", "H_number_density"))

        if (ptype, "ElectronAbundance") in self.field_list:

            def _el_number_density(field, data):
                return (data[ptype, "ElectronAbundance"] *
                        data[ptype, "H_number_density"])

            self.add_field(
                (ptype, "El_number_density"),
                sampling_type="particle",
                function=_el_number_density,
                units=self.ds.unit_system["number_density"],
            )
            self.alias(("gas", "El_number_density"),
                       (ptype, "El_number_density"))

        if (ptype, "CosmicRaySpecificEnergy") in self.field_list:

            self.alias(
                (ptype, "specific_cosmic_ray_energy"),
                ("gas", "specific_cosmic_ray_energy"),
            )

            def _cr_energy_density(field, data):
                return (data["PartType0", "specific_cosmic_ray_energy"] *
                        data["gas", "density"])

            self.add_field(
                ("gas", "cosmic_ray_energy_density"),
                _cr_energy_density,
                sampling_type="local",
                units=self.ds.unit_system["pressure"],
            )

            self.alias(
                ("PartType0", "specific_cr_energy"),
                ("PartType0", "specific_cosmic_ray_energy"),
                deprecate=("4.1.0", "4.2.0"),
            )

            self.alias(
                ("gas", "cr_energy_density"),
                ("gas", "cosmic_ray_energy_density"),
                deprecate=("4.1.0", "4.2.0"),
            )

            def _cr_pressure(field, data):
                return (data.ds.gamma_cr - 1.0) * data["gas",
                                                       "cr_energy_density"]

            self.add_field(
                ("gas", "cosmic_ray_pressure"),
                _cr_pressure,
                sampling_type="local",
                units=self.ds.unit_system["pressure"],
            )
    def setup_particle_fields(self, ptype):
        """ additional particle fields derived from those in snapshot.
        we also need to add the smoothed fields here b/c setup_fluid_fields
        is called before setup_particle_fields. """ 

        smoothed_suffixes = ("_number_density", "_density", "_mass")



        # we add particle element fields for stars and gas
        #-----------------------------------------------------
        if ptype in self._add_elements:


            # this adds the particle element fields
            # X_density, X_mass, and X_number_density
            # where X is an item of self._elements.
            # X_fraction are defined in snapshot
            #-----------------------------------------------
            for s in self._elements:
                add_species_field_by_fraction(self, ptype, s,
                                              particle_type=True)

        # this needs to be called after the call to 
        # add_species_field_by_fraction for some reason ...
        # not sure why yet. 
        #-------------------------------------------------------
        if ptype == 'PartType0':
            ftype='gas'
        elif ptype == 'PartType1':
            ftype='dm'
        elif ptype == 'PartType2':
            ftype='PartType2'
        elif ptype == 'PartType3':
            ftype='PartType3'
        elif ptype == 'PartType4':
            ftype='star'
        elif ptype == 'PartType5':
            ftype='BH'
        elif ptype == 'all':
            ftype='all'
        
        super(OWLSFieldInfo,self).setup_particle_fields(
            ptype, num_neighbors=self._num_neighbors, ftype=ftype)


        # and now we add the smoothed versions for PartType0
        #-----------------------------------------------------
        if ptype == 'PartType0':

            # we only add ion fields for gas.  this takes some 
            # time as the ion abundances have to be interpolated
            # from cloudy tables (optically thin)
            #-----------------------------------------------------
    

            # this defines the ion density on particles
            # X_density for all items in self._ions
            #-----------------------------------------------
            self.setup_gas_ion_density_particle_fields( ptype )

            # this adds the rest of the ion particle fields
            # X_fraction, X_mass, X_number_density
            #-----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                #---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                pstr = "_p" + str(roman-1)
                yt_ion = symbol + pstr

                # add particle field
                #---------------------------------------------------
                add_species_field_by_density(self, ptype, yt_ion,
                                             particle_type=True)


            # add smoothed ion fields
            #-----------------------------------------------
            for ion in self._ions:

                # construct yt name for ion
                #---------------------------------------------------
                if ion[0:2].isalpha():
                    symbol = ion[0:2].capitalize()
                    roman = int(ion[2:])
                else:
                    symbol = ion[0:1].capitalize()
                    roman = int(ion[1:])

                pstr = "_p" + str(roman-1)
                yt_ion = symbol + pstr

                loaded = []
                for sfx in smoothed_suffixes:
                    fname = yt_ion + sfx
                    fn = add_volume_weighted_smoothed_field( 
                        ptype, "particle_position", "particle_mass",
                        "smoothing_length", "density", fname, self,
                        self._num_neighbors)
                    loaded += fn

                    self.alias(("gas", fname), fn[0])

                self._show_field_errors += loaded
                self.find_dependencies(loaded)