pisces.models.galaxy_clusters.spherical.MagnetizedSphericalGalaxyClusterModel.generate_particles#
- MagnetizedSphericalGalaxyClusterModel.generate_particles(filename: str | Path, num_particles: dict[str, int], overwrite: bool = False) ParticleDataset #
Convert this galaxy cluster model into a particle dataset.
This method creates a particle representation of the model by sampling positions, interpolating model fields onto particles, and (if appropriate) assigning velocities via Eddington inversion. The output is written to disk in the form of a
particles.base.ParticleDataset
.This is a common step in preparing a model for simulations as most simulation codes require that the collisionless components of the model be represented as particles.
- Parameters:
filename (
str
orPath
) – Filesystem path where the output particle dataset should be saved. If the path already exists, it will be overwritten if overwrite=True.num_particles (
dict
ofstr
,int
) –The number of each type of particle to generate. The dictionary may contain any of the following keys:
['gas','dark_matter','stars']
and values should correspond to the number of particles to be generated of each species.If a species is provided but is not one of the allowed particle types, then an error will be raised.
overwrite (
bool
, optional) – Whether to overwrite an existing file at path. Default is False.
- Returns:
The newly created and populated particle dataset. For each particle type, the particle positions, velocities, and masses will be included along with any other relevant fields that were interpolated from the model.
- Return type:
ParticleDataset
Notes
The particle generation process follows three main steps:
Sampling: Radial positions are sampled from the species-specific mass profile (interpreted as a CDF), and converted into 3D Cartesian coordinates. This ensures that particles are distributed according to the model’s density. Masses are assigned to each particle species so that each species has equal masses across all particles.
Interpolation: Once the particle positions are established, the values of various model fields can be assigned to each particle via interpolation.
Velocity Assignment: Velocity sampling is the most complex element of this procedure. For the collisionless species (dark matter and stars), the velocities are sampled from the the distribution function (the solution of the collisionless Boltzmann equation) using the Eddington inversion method.
This ensures that the generated particles are correctly virialized.
For the gas particles, velocities are set uniformly to zero indicating that they have (by default) no bulk motion and that their entire dispersive motion is thermal in nature.
Examples
To generate particles from a model, simple call this method:
from pisces.models.galaxy_clusters import ( SphericalGalaxyClusterModel, ) # Load an existing model from disk. model = SphericalGalaxyClusterModel( "path/to/model.hdf5" ) # Generate the particles for a specific number of each type. num_particles = { "gas": 100000, "dark_matter": 50000, "stars": 20000, } particle_dataset = model.generate_particles( path="path/to/particles.hdf5", num_particles=num_particles, overwrite=True, )