Particle Data

ParticlesBase

The dataclass for particle data. It stores, allocates, extends, prunes data.

Important

The particle data contains dead particles.

To access only the live particles, use the is_alive property:

like particles.ux[particles.is_alive] += 10 and np.histogram(particles.ux[particles.is_alive], weights=particles.w[particles.is_alive]).

class lambdapic.core.particles.ParticlesBase(ipatch: int | None = None, rank: int | None = None)[source]

The dataclass of particle data.

This class stores and manages particle attributes including position, momentum, electromagnetic fields at particle positions, and particle status (alive/dead).

x,y,z

Particle positions in x, y, z coordinates

Type:

NDArray[float64]

w

Particle weights

Type:

NDArray[float64]

ux,uy,uz

Normalized momentum \(u_i = \gamma\beta_i\)

Type:

NDArray[float64]

inv_gamma

Inverse relativistic gamma factor

Type:

NDArray[float64]

ex_part,ey_part,ez_part

Electric fields interpolated at particle positions

Type:

NDArray[float64]

bx_part,by_part,bz_part

Magnetic fields interpolated at particle positions

Type:

NDArray[float64]

is_dead

Boolean array indicating dead particles

Type:

NDArray[bool]

_id

Unique particle IDs stored as float64

Type:

NDArray[float64]

npart

Total number of particles (including dead)

Type:

int

_npart_created

Counter for generating sequential local IDs

Type:

int

attrs

List of particle attributes. All attributes will be automatically synced during simulation unless specified.

Type:

list[str]

Note

You can extend/modify the particle attributes manually before calling ParticlesBase.initialize.

Parameters:
  • ipatch (Optional[int]) – Patch index the particles belong to

  • rank (Optional[int]) – MPI rank (default: 0)

__init__(ipatch: int | None = None, rank: int | None = None) None[source]
Parameters:
  • ipatch (Optional[int]) – Patch index the particles belong to

  • rank (Optional[int]) – MPI rank (default: 0)

initialize(npart: int) None[source]

Initialize particle arrays with given size. You can extend the particle attributes before calling initialize.

Parameters:

npart (int) – Number of particles to initialize

Raises:

AssertionError – If npart is negative

extend(n: int)[source]

Extend particle arrays by n elements.

Be careful when using this method, as it changes the address of particle data arrays. Update any typed.List storing particle data arrays accordingly.

Parameters:

n (int) – Number of elements to add (must be positive)

prune(extra_buff: float = 0.1) ndarray | None[source]

Remove dead particles and shrink arrays.

Parameters:

extra_buff (float) – Buffer size multiplier (default: 0.1)

Returns:

Sorting indices used if pruning occurred

Return type:

Optional[np.ndarray]

property id: ndarray[tuple[Any, ...], dtype[uint64]]

Get particle IDs as uint64 array.

Returns:

Particle IDs

Return type:

NDArray[uint64]

property is_alive: ndarray

Get boolean mask of alive particles.

Returns:

Boolean array where True indicates alive particles

Return type:

np.ndarray

__weakref__

list of weak references to the object (if defined)

QEDParticles

Inherited from ParticlesBase, it adds additional attributes for QED processes.

class lambdapic.core.particles.QEDParticles(ipatch: int | None, rank: int | None = 0)[source]

Bases: ParticlesBase

Particle class used for QED processes. With additional attributes below:

chi

Quantum parameter for radiation

Type:

NDArray[float64]

tau

Optical depth for pair production

Type:

NDArray[float64]

delta

Energy loss fraction

Type:

NDArray[float64]

event

Flags for QED events

Type:

NDArray[bool]

Initialize QED particle class.

Parameters:
  • ipatch (Optional[int]) – Patch index the particles belong to

  • rank (Optional[int]) – MPI rank (default: 0)

initialize(npart: int) None[source]

Initialize QED particle arrays.

Parameters:

npart (int) – Number of particles to initialize

extend(n: int)[source]

Extend QED particle arrays.

Parameters:

n (int) – Number of elements to add

prune(extra_buff: float = 0.1) None[source]

Prune dead QED particles.

Parameters:

extra_buff (float) – Buffer size multiplier (default: 0.1)