Beispiel #1
0
    def setup_particle_mass_field(self, ptype):
        name = "particle_mass"
        if ptype in self.ds.particle_unions:
            add_union_field(self, ptype, name, "code_mass")
            return

        constants = nested_dict_get(self.ds.parameters,
                                    ("Particle", ptype, "constants"),
                                    default=[])
        if not constants:
            names = []
        else:
            if not isinstance(constants[0], tuple):
                constants = (constants, )
            names = [c[0] for c in constants]

        if "mass" in names:
            val = constants[names.index("mass")][2]
            val = self.ds.quan(val, self.ds.mass_unit)
            if self.ds.cosmological_simulation:
                val = val / self.ds.domain_dimensions.prod()

            def _pmass(field, data):
                return val * data[ptype, "particle_ones"]

            self.add_field(
                (ptype, name),
                function=_pmass,
                units="code_mass",
                sampling_type="particle",
            )
Beispiel #2
0
    def setup_particle_mass_field(self, ptype):
        fname = "particle_mass"
        if ptype in self.ds.particle_unions:
            add_union_field(self, ptype, fname, "code_mass")
            return

        pdict = self.ds.parameters.get("Particle", None)
        if pdict is None:
            return

        constants = nested_dict_get(pdict, (ptype, "constants"), default=())
        if not constants:
            return

        # constants should be a tuple consisting of multiple tuples of (name, type, value).
        # When there is only one entry, the enclosing tuple gets stripped, so we put it back.
        if not isinstance(constants[0], tuple):
            constants = (constants,)
        names = [c[0] for c in constants]

        if "mass" not in names:
            return

        val = constants[names.index("mass")][2] * self.ds.mass_unit
        if not self.ds.index.io._particle_mass_is_mass:
            val = val * get_particle_mass_correction(self.ds)

        def _pmass(field, data):
            return val * data[ptype, "particle_ones"]

        self.add_field(
            (ptype, fname),
            function=_pmass,
            units="code_mass",
            sampling_type="particle",
        )