def setup_gas_particle_fields(self, ptype): super(GizmoFieldInfo, self).setup_gas_particle_fields(ptype) def _h_density(field, data): x_H = 1.0 - data[(ptype, "He_metallicity")] - \ data[(ptype, "metallicity")] return x_H * data[(ptype, "density")] * \ data[(ptype, "NeutralHydrogenAbundance")] self.add_field((ptype, "H_density"), function=_h_density, particle_type=True, units=self.ds.unit_system["density"]) add_species_field_by_density(self, ptype, "H", particle_type=True) for suffix in ["density", "fraction", "mass", "number_density"]: self.alias((ptype, "H_p0_%s" % suffix), (ptype, "H_%s" % suffix)) def _h_p1_density(field, data): x_H = 1.0 - data[(ptype, "He_metallicity")] - \ data[(ptype, "metallicity")] return x_H * data[(ptype, "density")] * \ (1.0 - data[(ptype, "NeutralHydrogenAbundance")]) self.add_field((ptype, "H_p1_density"), function=_h_p1_density, particle_type=True, units=self.ds.unit_system["density"]) add_species_field_by_density(self, ptype, "H_p1", particle_type=True) def _nuclei_mass_density_field(field, data): species = field.name[1][:field.name[1].find("_")] return data[ptype, "density"] * \ data[ptype, "%s_metallicity" % species] num_neighbors = 64 for species in ['H', 'H_p0', 'H_p1']: for suf in ["_density", "_number_density"]: field = "%s%s" % (species, suf) fn = add_volume_weighted_smoothed_field( ptype, "particle_position", "particle_mass", "smoothing_length", "density", field, self, num_neighbors) self.alias(("gas", field), fn[0]) for species in self.nuclei_names: self.add_field((ptype, "%s_nuclei_mass_density" % species), function=_nuclei_mass_density_field, particle_type=True, units=self.ds.unit_system["density"]) for suf in ["_nuclei_mass_density", "_metallicity"]: field = "%s%s" % (species, suf) fn = add_volume_weighted_smoothed_field( ptype, "particle_position", "particle_mass", "smoothing_length", "density", field, self, num_neighbors) self.alias(("gas", field), fn[0])
def setup_gas_particle_fields(self, ptype): super(GizmoFieldInfo, self).setup_gas_particle_fields(ptype) def _h_p0_density(field, data): x_H = 1.0 - data[(ptype, "He_metallicity")] - data[(ptype, "metallicity")] return (x_H * data[(ptype, "density")] * data[(ptype, "NeutralHydrogenAbundance")]) self.add_field( (ptype, "H_p0_density"), sampling_type="particle", function=_h_p0_density, units=self.ds.unit_system["density"], ) add_species_field_by_density(self, ptype, "H") def _h_p1_density(field, data): x_H = 1.0 - data[(ptype, "He_metallicity")] - data[(ptype, "metallicity")] return (x_H * data[(ptype, "density")] * (1.0 - data[(ptype, "NeutralHydrogenAbundance")])) 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") def _nuclei_mass_density_field(field, data): species = field.name[1][:field.name[1].find("_")] return data[ptype, "density"] * data[ptype, "%s_metallicity" % species] for species in ["H", "H_p0", "H_p1"]: for suf in ["_density", "_number_density"]: field = "%s%s" % (species, suf) self.alias(("gas", field), (ptype, field)) 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")) for species in self.nuclei_names: self.add_field( (ptype, "%s_nuclei_mass_density" % species), sampling_type="particle", function=_nuclei_mass_density_field, units=self.ds.unit_system["density"], ) for suf in ["_nuclei_mass_density", "_metallicity"]: field = "%s%s" % (species, suf) self.alias(("gas", field), (ptype, field)) def _metal_density_field(field, data): return data[ptype, "metallicity"] * data[ptype, "density"] self.add_field( (ptype, "metal_density"), sampling_type="local", function=_metal_density_field, units=self.ds.unit_system["density"], ) self.alias(("gas", "metal_density"), (ptype, "metal_density")) magnetic_field = "MagneticField" if (ptype, magnetic_field) in self.field_list: setup_magnetic_field_aliases(self, ptype, magnetic_field)
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)
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))
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)