[yt-svn] commit/yt: chummels: Merged in brittonsmith/yt (pull request #2442)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Nov 22 14:52:16 PST 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/5499b32cce88/
Changeset: 5499b32cce88
Branch: yt
User: chummels
Date: 2016-11-22 22:51:50+00:00
Summary: Merged in brittonsmith/yt (pull request #2442)
Making nuclei density fields more robust
Affected #: 2 files
diff -r 9373defa8ed5e8c707b5d36a1dc3568885807ea6 -r 5499b32cce889b3306cf6718b80bc55fa5ce9315 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -145,32 +145,53 @@
unit_system = registry.ds.unit_system
elements = _get_all_elements(registry.species_names)
for element in elements:
- registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell",
+ registry.add_field((ftype, "%s_nuclei_density" % element),
+ sampling_type="cell",
function = _nuclei_density,
particle_type = particle_type,
units = unit_system["number_density"])
- if len(elements) == 0:
- for element in ["H", "He"]:
- registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell",
- function = _default_nuclei_density,
- particle_type = particle_type,
- units = unit_system["number_density"])
+
+ for element in ["H", "He"]:
+ if element in elements:
+ continue
+ registry.add_field((ftype, "%s_nuclei_density" % element),
+ sampling_type="cell",
+ function = _default_nuclei_density,
+ particle_type = particle_type,
+ units = unit_system["number_density"])
def _default_nuclei_density(field, data):
+ ftype = field.name[0]
element = field.name[1][:field.name[1].find("_")]
- return data["gas", "density"] * _primordial_mass_fraction[element] / \
+ return data[ftype, "density"] * _primordial_mass_fraction[element] / \
ChemicalFormula(element).weight / amu_cgs
def _nuclei_density(field, data):
+ ftype = field.name[0]
element = field.name[1][:field.name[1].find("_")]
- field_data = np.zeros_like(data["gas", "%s_number_density" %
+
+ nuclei_mass_field = "%s_nuclei_mass_density" % element
+ if (ftype, nuclei_mass_field) in data.ds.field_info:
+ return data[(ftype, nuclei_mass_field)] / \
+ ChemicalFormula(element).weight / amu_cgs
+ metal_field = "%s_metallicity" % element
+ if (ftype, metal_field) in data.ds.field_info:
+ return data[ftype, "density"] * data[(ftype, metal_field)] / \
+ ChemicalFormula(element).weight / amu_cgs
+
+ field_data = np.zeros_like(data[ftype, "%s_number_density" %
data.ds.field_info.species_names[0]])
for species in data.ds.field_info.species_names:
nucleus = species
if "_" in species:
nucleus = species[:species.find("_")]
+ # num is the number of nuclei contributed by this species.
num = _get_element_multiple(nucleus, element)
- field_data += num * data["gas", "%s_number_density" % species]
+ # Since this is a loop over all species existing in this dataset,
+ # we will encounter species that contribute nothing, so we skip them.
+ if num == 0:
+ continue
+ field_data += num * data[ftype, "%s_number_density" % species]
return field_data
def _get_all_elements(species_list):
diff -r 9373defa8ed5e8c707b5d36a1dc3568885807ea6 -r 5499b32cce889b3306cf6718b80bc55fa5ce9315 yt/frontends/gizmo/fields.py
--- a/yt/frontends/gizmo/fields.py
+++ b/yt/frontends/gizmo/fields.py
@@ -14,15 +14,21 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
+from yt.fields.field_info_container import \
+ FieldInfoContainer
from yt.fields.particle_fields import \
add_volume_weighted_smoothed_field
from yt.fields.species_fields import \
- add_species_field_by_density
+ add_species_field_by_density, \
+ setup_species_fields
from yt.frontends.gadget.fields import \
GadgetFieldInfo
from yt.frontends.sph.fields import \
SPHFieldInfo
+metal_elements = ["He", "C", "N", "O", "Ne",
+ "Mg", "Si", "S", "Ca", "Fe"]
+
class GizmoFieldInfo(GadgetFieldInfo):
known_particle_fields = (
("Mass", ("code_mass", ["particle_mass"], None)),
@@ -58,8 +64,14 @@
def __init__(self, *args, **kwargs):
super(SPHFieldInfo, self).__init__(*args, **kwargs)
if ("PartType0", "Metallicity_00") in self.field_list:
- self.nuclei_names = ["He", "C", "N", "O", "Ne", "Mg", "Si", "S",
- "Ca", "Fe"]
+ self.nuclei_names = metal_elements
+ self.species_names = ["H", "H_p1"] + metal_elements
+
+ def setup_particle_fields(self, ptype):
+ FieldInfoContainer.setup_particle_fields(self, ptype)
+ if ptype in ("PartType0",):
+ self.setup_gas_particle_fields(ptype)
+ setup_species_fields(self, ptype)
def setup_gas_particle_fields(self, ptype):
super(GizmoFieldInfo, self).setup_gas_particle_fields(ptype)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list