PlasmaCalcs.mhd.multifluid.mhd_fluids.IonMixture
- class PlasmaCalcs.mhd.multifluid.mhd_fluids.IonMixture(species, i=None, *, q=UNSET, name=UNSET, m_mean_mode='simple', m_tol=UNSET)
Bases:
MhdFluidFluid corresponding to multiple ions grouped together, e.g. Mg+Al+Si_II- CAUTION: some code assumes (without checking) that IonMixture objects are immutable.
- Changing an IonMixture after creating it could lead to unexpected behavior.
IonMixtures usually have a name. Every IonMixture has a charge (probably charge=1).Name and charge can be inferred from the species in the mixture.- species: iterable of Specie or dict objects
- the list of Species in this mixture. length must be at least 1.internally stored as SpecieList(species)dicts –> convert to SpecieList via SpecieList.from_dicts(species).
- i: None or int
- the index of this mixture (within an IonMixtureList or MhdFluidList)None –> cannot convert self to int.
- q: UNSET or number
- charge, in elementary charge units (e.g. +1 for H_II).all species must have the same charge else raise NotImplementedError.UNSET –> infer q from species.number –> assert q > 0, and q == spec.q for spec in species.
- name: UNSET, None, or str
- name of this mixture. None –> unnamed.UNSET –> infer from species. E.g. Mg_II, Al_II, Si_II –> Mg+Al+Si_II
- m_mean_mode: str in {‘simple’, ‘density’}
- how to calculate the mass of this mixture.‘simple’ –> m = mean(spec.m for spec in species). This is a constant.‘density’ –> m = density weighted mean of spec.m for spec in species.this might vary across maindims and snaps…
- m_tol: UNSET, None, or number
- crash if any |m_s - mean(m)| is more than m_tol * mean(m).(using simple mean for this test, regardless of m_mean_mode)(Prevents accidentally creating a mixture of ions with very different masses.)UNSET –> use self.DEFAULT_M_TOL (default=0.1)None –> allow any masses.
- __init__(species, i=None, *, q=UNSET, name=UNSET, m_mean_mode='simple', m_tol=UNSET)
Methods
__init__(species[, i, q, name, m_mean_mode, ...])copy(**kw_init)deserialize(serial)from_dict(d)get_element([default])get_elements([default])ion([q])is_ion()neutral(**kw_specie)register_type(cls_to_register[, ...])saha_list(*[, istart])to_dict(*[, species_to_dict])with_i(i)Attributes
DEFAULT_M_TOL_DENSITYDEFAULT_M_TOL_SIMPLESERIAL_TYPESndimsize- copy(**kw_init)
- return a copy of self. Can provide new kwargs here to override old values in result.E.g. self.copy(i=7) makes a copy of self but with i=7 instead of self.i.
- static deserialize(serial)
- creates an XarrayIoSerializable object from a serialized representation.
- serial: dict or str
- str –> convert to dict via ast.literal_eval.dict must contain ‘typename’ key.
The output here will be an instance of XarrayIoSerializable.SERIAL_TYPES[typename]
- equal_except_i(v)
- returns whether self == v (another DimensionValue), ignoring i.equal if v is an instance of type(self) andall kw from both self._kw_eq and v._kw_eq have the same values.(any kw missing attrs will be treated as UNSET.)For DimensionValue: self.s==v.s and self.i==v.i. Subclasses may add more.
- classmethod from_dict(d)
- return cls from dict d.If ‘d’ contains ‘typename’, result is like cls.deserialize(d) instead,however, first require that result is an instance of cls (or subclass of cls).E.g. Fluid.from_dict(dict(typename=’EppicDist’, …)) returns EppicDist,but Snap.from_dict(dict(typename=’EppicDist’, …)) crashes with InputError.Subclasses wishing to alter deserialize behavior will probably override this method instead.
- property get
- return self.species.get(key)
- property get_I
- alias to neutral
- property get_II
- alias to ion
- get_element(default=NO_VALUE)
- return self.element if it exists and is not None, else crash with FluidKeyError.
- default: NO_VALUE or any value.
- If provided, when element missing or None, return default instead of crash.
- get_elements(default=NO_VALUE)
- return list of elements in self, i.e. spec.get_element() for spec in self.
- infer_name()
- infer name based on species’ names.if all species’ names have the same suffix (starting at underscore),‘+’.join(names without suffix) + suffix.else, ‘+’.join(names).
- ion(q=1, **kw_specie)
- return ionized Specie of self.get_element()
q: charge in elementary charge units. (default: +1)
- is_charged()
- tells whether self is a charged fluid. i.e. self.q != 0.if self.q is None, returns None instead of bool.
- is_electron()
- tells whether self is an electron. i.e. self.q < 0.if self.q is None, returns None instead of bool.
- is_ion()
- tells whether self is an ion. i.e. self.q > 0.if self.q is None, returns None instead of bool.
- is_neutral()
- tells whether self is a neutral fluid. i.e. self.q == 0.if self.q is None, returns None instead of bool.
- lookup_dict()
- return dict for looking up self within a DimensionValueList, given int, str, or self.(used by DimensionValueList.lookup_dict)in addition to being able to lookup self,also allows lookup of any species within self, by name or object (but not index).E.g. if H_II=Specie(‘H_II’, i=3) in self,result will include {‘H_II’: H_II, H_II: H_II}, but will not include {3: H_II}
- property m_mean
- return mean mass of species in this mixture.(Always using a simple mean: sum(s.m for s in species)/len(species))
- property m_mean_mode
- str telling how to calculate the mass of this mixture.‘simple’ –> m = mean(spec.m for spec in species). This is a constant.‘density’ –> m = density weighted mean of spec.m for spec in species.this might vary across maindims and snaps…
- property name
- alias to s
- neutral(**kw_specie)
- return neutral Specie of self.get_element().
- static register_type(cls_to_register, _serial_typename=None)
- register cls_to_register as a serializable subclass of XarrayIoSerializable.
- _serial_typename: str or None
- name to use for serialization. if None, use cls_to_register.__name__.
- saha_list(*, istart=0, **kw_specie)
- return SpecieList of neutral & once-ionized ions of self.get_element().
istart: start index for the SpecieList. Index affects conversion to int.
- serialize()
- return dict of info about self, including ‘typename’ key.
- specie_list_cls
alias of
SpecieList
- to_dict(*, species_to_dict=True)
- return dictionary of info about self. Attribute values for keys in self._kw_def.
- species_to_dict: bool, default True
- whether to also convert result[‘species’].to_dict() too.
- with_i(i)
- return copy of self with i=i, or self if self.i==i already.