Skip to content

particula.particles.particle_data

Provide a batched particle data container for multi-box CFD simulations.

ParticleData isolates per-particle arrays from behavior while embedding the batch dimension required for CFD experiments spanning multiple boxes.

Classes

NameDescription
ParticleDataBatched particle data container for multi-box simulations.

Functions

NameDescription
_replacement_volumesStage an independent volume value for each box before updating state.

ParticleDataclassdataclass#

class ParticleData(masses: NDArray[np.float64], concentration: NDArray[np.float64] | None = None, charge: NDArray[np.float64] | None = None, density: NDArray[np.float64] | None = None, volume: NDArray[np.float64] | None = None, distribution_type: str | None = None, radius_grid: NDArray[np.float64] | None = None, *, population: NDArray[np.float64] | None = None)

Batched particle data container for multi-box simulations.

Simple data container with batch dimension built-in. All per-particle arrays have shape (n_boxes, n_particles, …) to support multi-box CFD. Single-box simulations use n_boxes=1.

This is NOT a frozen dataclass - arrays can be updated in place for performance in tight simulation loops. Use copy() if immutability needed.

Attributes

NameTypeDescription
massesNDArray[np.float64]Per-species masses in kg. Shape: (n_boxes, n_particles, n_species)
populationNDArray[np.float64]Extensive weights of shape (n_boxes, n_particles). Bins and resolved slots store counts. Radius PDFs store dN/dr in m^-1.
chargeNDArray[np.float64]Particle charges (dimensionless integer counts). Shape: (n_boxes, n_particles)
densityNDArray[np.float64]Material densities in kg/m^3. Shape: (n_species,) - shared across all boxes
volumeNDArray[np.float64]Simulation volume per box in m^3, shape (n_boxes,). All tagged populations use finite positive air volumes.
distribution_typestr | NoneExplicit storage interpretation, or None for untagged legacy carriers. New bulk helpers reject untagged data.
radius_gridNDArray[np.float64] | NoneExplicit PDF radius nodes in metres, shape (n_particles,); absent for other kinds.

Raises

ValueError
If array shapes are inconsistent.

chargeattributeinstance attribute#

charge: NDArray[np.float64] = charge

densityattributeinstance attribute#

density: NDArray[np.float64] = density

distribution_typeattributeclass attributeinstance attribute#

distribution_type: str | None = distribution_type

massesattributeinstance attribute#

masses: NDArray[np.float64] = masses

populationattributeinstance attribute#

population: NDArray[np.float64] = population

radius_gridattributeclass attributeinstance attribute#

radius_grid: NDArray[np.float64] | None = radius_grid

volumeattributeinstance attribute#

volume: NDArray[np.float64] = volume

concentrationpropertywritable#

concentration: NDArray[np.float64]

Deprecated writable 0.3 alias for legacy-compatible volumes.

effective_densityproperty#

effective_density: NDArray[np.float64]

Mixture density from total mass divided by additive material volume.

Returns

NDArray[np.float64]
Effective density in kg/m^3 with shape (n_boxes, n_particles).

mass_fractionsproperty#

mass_fractions: NDArray[np.float64]

Mass fractions per species for each particle.

Returns

NDArray[np.float64]
Mass fractions with shape (n_boxes, n_particles, n_species).

n_boxesproperty#

n_boxes: int

Number of simulation boxes.

Returns

int
The size of the batch dimension (n_boxes).

n_particlesproperty#

n_particles: int

Number of particles per box.

Returns

int
The number of particles (n_particles).

n_speciesproperty#

n_species: int

Number of chemical species.

Returns

int
The number of species (n_species).

number_densityproperty#

number_density: NDArray[np.float64]

Return fresh per-box number density in m^-3.

Sum discrete/resolved slot densities; integrate PDF node density over the explicit radius grid using trapezoidal quadrature.

Returns

NDArray[np.float64]
Number density with shape (n_boxes,).

Raises

ValueError
If the representation fails read-only validation.

radiiproperty#

radii: NDArray[np.float64]

Particle radii derived from mass and density.

Returns

NDArray[np.float64]
Radii in meters with shape (n_boxes, n_particles).

slot_concentration_densityproperty#

slot_concentration_density: NDArray[np.float64]

Return fresh per-slot number density or radius-PDF density.

Discrete and resolved slots have units m^-3; PDF nodes have units m^-4. The result has shape (n_boxes, n_particles) and is detached from the raw population array.

Returns

NDArray[np.float64]
Per-slot density on the declared representation’s grid.

Raises

ValueError
If the kind, grid, volume, or raw data is invalid.

species_mass_densityproperty#

species_mass_density: NDArray[np.float64]

Return fresh per-species particle mass density in kg/m^3.

Weight species masses by raw slot density. For PDFs, integrate the product of mass and dN/dr on the explicit radius grid using trapezoidal node weights, rather than summing PDF nodes.

Returns

NDArray[np.float64]
Particle mass density with shape (n_boxes, n_species).

Raises

ValueError
If the representation fails read-only validation.

species_mass_inventoryproperty#

species_mass_inventory: NDArray[np.float64]

Return fresh extensive particle mass per species in kg.

Returns

NDArray[np.float64]
Mass inventory with shape (n_boxes, n_species).

Raises

ValueError
If the representation fails read-only validation.

total_massproperty#

total_mass: NDArray[np.float64]

Total mass per particle.

Returns

NDArray[np.float64]
Total mass in kilograms with shape (n_boxes, n_particles).

__init__method#

def __init__(masses: NDArray[np.float64], concentration: NDArray[np.float64] | None = None, charge: NDArray[np.float64] | None = None, density: NDArray[np.float64] | None = None, volume: NDArray[np.float64] | None = None, distribution_type: str | None = None, radius_grid: NDArray[np.float64] | None = None, *, population: NDArray[np.float64] | None = None) -> None

Bind extensive storage or the compatible 0.3 concentration array.

__post_init__method#

def __post_init__() -> None

Validate raw array shapes without interpreting distribution kind.

Raises

ValueError
If raw field shapes or species dimensions disagree.

_check_legacy_populationmethod#

def _check_legacy_population() -> None

copymethod#

def copy() -> ParticleData

Create a deep copy of this ParticleData.

Returns

ParticleData
A new ParticleData with detached raw arrays and radius grid,
ParticleData
preserving the explicit distribution type when present.

set_slot_concentration_densitymethod#

def set_slot_concentration_density(density_by_slot: ArrayLike, *, volume: ArrayLike | None = None) -> None

Replace particle population from per-slot density and air volume.

Parameters

NameTypeDefaultDescription
density_by_slotArrayLikerequiredNonnegative number densities (m^-3) for bins or resolved slots, or radius-PDF ordinates (m^-4). Supply shape (n_boxes, n_particles), or (n_particles,) for one box.
volumeArrayLike | NoneNoneRepresented air volume (m^3), as one positive scalar for all boxes or an array of shape (n_boxes,). Omit to use each box’s current volume.

Writes density times the selected volume into the existing population array. A supplied volume is committed in the same update.

Raises

TypeError
If an input does not contain real numbers.
ValueError
If the representation, shape, values or storage prevent an in-place update. Both arrays retain their values.

validate_representationmethod#

def validate_representation() -> None

Validate storage for its declared distribution interpretation.

Call after directly changing writable arrays. This read-only check never repairs state; derived population helpers call it on every read. Each box requires positive represented volume. PDF nodes must form an increasing, positive radius grid with at least two nodes.

Raises

ValueError
If kind, grid, volume, shape, or values are invalid.

_replacement_volumesfunction#

def _replacement_volumes(volume: ArrayLike, shape: tuple[int, ...]) -> NDArray[np.float64]

Stage an independent volume value for each box before updating state.