Skip to content
Projects

plasmacoll.markers

Marker storage that plasmacoll.mcc.MonteCarloCollisions.collide_species works on.

Any object with positions, velocities and weights arrays and remove/add methods (the MarkerSet protocol) can be collided, so a particle-in-cell code can pass its own particle containers through a thin adapter. ParticleArrays is a simple implementation that keeps the markers in three arrays and compacts them on removal.

Classes

NameDescription
MarkerSetThe markers of one species, as the collision operator needs them.
ParticleArraysMarkers of one species held in three arrays.

MarkerSetclass#

class MarkerSet(Protocol)

Bases: Protocol

The markers of one species, as the collision operator needs them.

positions has shape (N, ndim) (any ndim, read only by density profiles and copied to products), velocities shape (N, 3) in m/s, weights shape (N,): the number of physical particles per marker. Collisions update rows of velocities in place.

positionsproperty#

positions: Array

Return the marker positions, shape (N, ndim).

velocitiesproperty#

velocities: Array

Return the marker velocities, shape (N, 3), updated in place.

weightsproperty#

weights: Array

Return the marker weights, shape (N,).

addmethod#

def add(positions: Array, velocities: Array, weights: Array) -> None

Append new markers.

removemethod#

def remove(mask: Array) -> None

Remove the markers flagged in the boolean mask of length N.

ParticleArraysclassdataclass#

class ParticleArrays(positions: Array, velocities: Array, weights: Array)

Markers of one species held in three arrays.

Attributes

NameTypeDescription
positionsArrayPositions, shape (N, ndim).
velocitiesArrayVelocities in m/s, shape (N, 3).
weightsArrayPhysical particles per marker, shape (N,).

positionsattributeinstance attribute#

positions: Array

velocitiesattributeinstance attribute#

velocities: Array

weightsattributeinstance attribute#

weights: Array

total_weightproperty#

total_weight: float

Return the number of physical particles the markers represent.

addmethod#

def add(positions: Array, velocities: Array, weights: Array) -> None

Append new markers.

emptymethodclassmethod#

def empty(ndim: int = 1) -> ParticleArrays

Return a set without markers, with ndim position components.

maxwellianmethodclassmethod#

def maxwellian(num: int, mass: float, temperature: float, weight: float = 1.0, drift: tuple[float, float, float] = (0.0, 0.0, 0.0), ndim: int = 1, rng: Any = None, seed: int | None = None) -> ParticleArrays

Sample num markers from a drifting Maxwellian, all at the origin.

mass, temperature and drift take astropy Quantities, strings such as "300 K" or plain numbers in the units below.

Parameters

NameTypeDefaultDescription
numintrequiredThe number of markers.
massfloatrequiredParticle mass in kg.
temperaturefloatrequiredTemperature kT in eV (a Quantity also in K); see plasmacoll.constants.kelvin_to_ev.
weightfloat1.0Physical particles per marker.
drifttuple[float, float, float](0.0, 0.0, 0.0)Mean velocity in m/s.
ndimint1Number of position components.
rngAnyNoneA NumPy or CuPy Generator; one seeded with seed if None.
seedint | NoneNoneSeed of the generator made when rng is None.

mean_energy_evmethod#

def mean_energy_ev(mass: float) -> float

Return the weighted mean kinetic energy in eV (0 without markers).

removemethod#

def remove(mask: Array) -> None

Remove the markers flagged in the boolean mask.

temperaturemethod#

def temperature(mass: float) -> float

Return the kinetic temperature kT in eV about the mean (0 if empty).

Numerics

temperature

kT=m3e ∑iwi∣vi−u∣2∑iwi,u=∑iwivi∑iwikT = \frac{m}{3e}\,\frac{\sum_i w_i |\mathbf v_i - \mathbf u|^2}{\sum_i w_i}, \qquad \mathbf u = \frac{\sum_i w_i \mathbf v_i}{\sum_i w_i}

Assumptions:

  • weights wiw_i; zero without markers