EppicDist

class PlasmaCalcs.hookups.eppic.eppic_dimensions.EppicDist(m, q, n0, *, N=None, name=None, i=None, params=None)

Bases: DictlikeFromKeysAndGetitem, Fluid

info about a single distribution.

see cls.from_dict() to create an instance from a dict of values from an eppic.i file.
units are “raw”. Numerical values equal those from the eppic.i file.
m: real number
mass of a single “real” particle in the distribution
q: real number
charge of a single “real” particle in the distribution
n0: real number
background “physical” number density of this distribution of particles.
N: None, int, or str
distribution number; will be internally stored as int (or None).
Optional because distribution number doesn’t affect distribution physics,
however all distributions from eppic.i files will have a number.
i: None or int
index of this distribution in a DistributionList.
raise NotImplementedError if i and N are incompatible
(i.e. both non-None and representing different values).
params: None or dict
additional parameters.
Provide dict with keys with trailing distN removed,
e.g. “coll_rate” not “coll_rate1” (if dist=’1’)
name: None or str
name of this distribution.
Optional, and probably not found in eppic.i files.
Provide to improve human-readability.

Methods

__eq__(v)

return self==v.

__getitem__(key)

usually return self.params[key]; if key is special return self.key instead.

__init_subclass__(*[, _serial_typename])

register cls as a subclass of XarrayIoSerializable.

__iter__()

raises TypeError; use .keys(), .values(), or .items() instead.

copy(**kw_init)

return a copy of self.

deserialize(serial)

creates an XarrayIoSerializable object from a serialized representation.

dists_from_dict(d)

return dict of distributions, given a dict of {N: dict of distribution values}.

equal_except_i(v)

returns whether self == v (another DimensionValue), ignoring i.

from_dict(d)

return cls from dict d.

from_dict_and_N(d, N)

return EppicDist from dict and N.

get(key[, default])

return self[key].

get_n0()

returns background (mean) density of this distribution.

get_npd(*[, default])

return number of PIC particles for this distribution in each processor.

get_nvsqr0([x])

returns original (t=0) nvsqr, as a tuple of (vx^2, vy^2, vz^2) values,

get_v0([x])

returns original (t=0) velocity, as a tuple of (vx, vy, xz) values,

get_velocity_coords(units)

Returns a dictionary of vdist coordinates (vx, vy, vz) for this EppicDist.

get_vth0([x])

returns original (t=0) thermal velocity, as a tuple of (vx, vy, xz) values,

is_charged()

tells whether self is a charged fluid.

is_electron()

tells whether self is an electron.

is_hybrid()

return whether this distribution is "hybrid", i.e. fluid model instead of PIC.

is_ion()

tells whether self is an ion.

is_neutral()

tells whether self is a neutral fluid.

items()

return tuple of (key, value) pairs corresponding to self.keys() and self.values().

keys()

return tuple of keys which are special or in self.params

lookup_dict()

returns dict for looking up self within a DimensionValueList, given int, str, or self.

register_type(cls_to_register[, ...])

register cls_to_register as a serializable subclass of XarrayIoSerializable.

serialize()

return dict of info about self, including 'typename' key.

to_dict()

return dictionary of info about self.

values()

return tuple of values corresponding to self.keys().

with_i(i)

return copy of self with i=i, or self if self.i==i already.

_repr_contents()

contents used by self.__repr__

_repr_simple()

return simple repr for self: Classname(s, i).

Attributes

SERIAL_TYPES

SPECIAL

name

alias to s

ndim

precision

size

__eq__(v)

return self==v. Equal if:

- v is an instance of type(self), and
all 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, just compares self.s==v.s and self.i==v.i.
Subclasses may add more kwargs to compare by altering _kw_def.
- or, self.s == v or self.i == v, and v is not another DimensionValue
- or, v is a DimensionSingleValueSpecifier and v.checker(self) gives True.
Not equal if v is a DimensionValue but not an instance of type(self),
e.g. class Fluid(DimensionValue):…; class Snap(DimensionValue):…;
Fluid(‘H’, 0) != Snap(‘H’, 0).
__getitem__(key)

usually return self.params[key]; if key is special return self.key instead.

special keys are determined by self.SPECIAL; default (‘m’, ‘q’, ‘n0’, ‘N’, ‘name’).
else, return self.params[key].
classmethod __init_subclass__(*, _serial_typename=None, **kw)

register cls as a subclass of XarrayIoSerializable.

_serial_typename: None or str
name to use for this type, for serialization purposes.
None –> use cls.__name__.
This method also sets cls._serial_typename = _serial_typename.
__iter__()

raises TypeError; use .keys(), .values(), or .items() instead.

_repr_contents()

contents used by self.__repr__

_repr_simple()

return simple repr for self: Classname(s, i).

if s is None, use Classname(i) instead.
if i is None, use Classname(s, i=None) instead.
Called when using PlasmaCalcs.tools.repr_simple.
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]
classmethod dists_from_dict(d)

return dict of distributions, given a dict of {N: dict of distribution values}.

equal_except_i(v)

returns whether self == v (another DimensionValue), ignoring i.

equal if v is an instance of type(self) and
all 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.
classmethod from_dict_and_N(d, N)

return EppicDist from dict and N.

d: dict
result of eppic_io_tools.read_eppic_i_file()[N].
must have keys mdN, qdN, n0dN. E.g. “md1” for N=’1’
other keys must end in N, and one N will be removed from end of each.
e.g. “coll_rate1” –> “coll_rate”.
raise ValueError if any key doesn’t end with N.
if ‘nameN’ appears in d, it will be used as name.
N: None, str or int
distribution number. if int, will be converted to str.
get(key, default=UNSET)

return self[key]. if default is provided and self[key] doesn’t exist, return default.

get_n0()

returns background (mean) density of this distribution. Equivalent: self[‘n0’]

get_npd(*, default=UNSET)

return number of PIC particles for this distribution in each processor.

If that is not possible (due to using alternate option for npd), raise FluidKeyError
Alternate options include: nptotd, npcelld, nptotcelld;
those options tell npd info but scaled by number of cells and/or processors.
number of cells & processors are global parameters not known by EppicDist,
so EppicDist cannot calculate npd from those options.
default: UNSET or any value
return default instead of error when npd not found, if default provided (not UNSET).
get_nvsqr0(x=None)

returns original (t=0) nvsqr, as a tuple of (vx^2, vy^2, vz^2) values,

or the x component if x = ‘x’, ‘y’, or ‘z’.
The result should be comparable to eppic nvsqr output.
To convert from known values to nvsqr…:
Ta_x = m * (vsqr_x - u_x^2) / kB # copied from EppicCalculator.help(‘Ta’)
–> vsqr_x = u_x^2 + kB * Ta_x / m.
we know vth0_x == kB * Ta_x / m,
and we know v0_x == u_x.
–> nvsqr_x == n0 * (v0_x^2 + vth0_x^2)
get_v0(x=None)

returns original (t=0) velocity, as a tuple of (vx, vy, xz) values,

or the x component if x provided (x should be a string if provided).
get_velocity_coords(units)

Returns a dictionary of vdist coordinates (vx, vy, vz) for this EppicDist.

For example, “vx”: np.linspace(self[“pvxmin”], self[“pvxmax”], num=self[“pnvx”]).
get_vth0(x=None)

returns original (t=0) thermal velocity, as a tuple of (vx, vy, xz) values,

or the x component if x = ‘x’, ‘y’, or ‘z’.
if x is Ellipsis (i.e., x=…), assert all three components are the same,
and return the one value which they all equal.
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_hybrid()

return whether this distribution is “hybrid”, i.e. fluid model instead of PIC.

as a proxy, guessing hybrid iff self.get(‘method’, 0) != 0.
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.
items()

return tuple of (key, value) pairs corresponding to self.keys() and self.values().

keys()

return tuple of keys which are special or in self.params

lookup_dict()

returns dict for looking up self within a DimensionValueList, given int, str, or self.

(used by DimensionValueList.lookup_dict)
property name

alias to s

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__.
serialize()

return dict of info about self, including ‘typename’ key.

to_dict()

return dictionary of info about self. Attribute values for keys in self._kw_def.

e.g. if _kw_def={‘s’, ‘i’}: result = {‘s’: self.s, ‘i’: self.i}
values()

return tuple of values corresponding to self.keys().

with_i(i)

return copy of self with i=i, or self if self.i==i already.