Particles

A set of objects with different properties are represented by subtypes of AbstractParticles. While not absolutely necessary, these kind of objects generally have IDs, positions, and velocity as properties. In the context of cosmological simulations, this applies to particle and galaxy data.

For an example implementation of a concrete subtype of AbstractParticles, see the source code of Particles.

CosmoParticles.AbstractParticlesType
abstract type AbstractParticles end

Abstract supertype for storing particle data efficiently in arrays.

Particles generally have IDs, positions, and velocities as properties. The properties are expected to be stored in a Dict{Symbol,Any} as vectors of length $N$, matrices of size $m×N$, or as scalars (when the property is equal for all particles).

The inbuilt functionality of AbstractParticles includes accessing and setting properties via the following syntax:

p.id = [1, 2, 3]
p[:id] === p.id

If the struct has additional fields, these can also be accessed by p.field, but not by p[:field]. The latter syntax can only be used to access the particle properties.

Property keys

  • :id: vector of IDs
  • :pos: $2×N$ or $3×N$ matrix with positions
  • :vel: $2×N$ or $3×N$ matrix with velocities

Any arrays may be of the type AbstractArray, provided the arrays are 1-indexed.

Methods

The methods Base.keys, Base.values, Base.haskey, Base.empty, Base.empty!, Base.isempty, and Base.copy! are forwarded to the property Dict.

Concrete types of AbstractParticles should have the following methods implemented (also see the implementation of Particles):

  • Base.copy: returns new object containing a copy of the Dict
  • Base.empty: returns an identical object, but with an empty Dict
  • Base.:(==): should call Base.isequal to prevent obtaining missing results for properties with missing values (relevant for AllParticles)
  • CosmoParticles.particle_name: returns the name of the struct to be printed via Base.show
  • Base.propertynames: implement this if there are additional struct fields
  • Base.show(io, mime, p)
source
CosmoParticles.ParticlesType
struct Particles <: AbstractParticles
    type::Symbol
    props::Dict{Symbol,Any}
end

Particles of a certain type (typically something like :dm or :gas in the cosmological context) with their properties.

The following naming convention is to be used for specific properties:

  • :id: vector of IDs
  • :pos: $2×N$ or $3×N$ matrix with positions
  • :vel: $2×N$ or $3×N$ matrix with velocities
  • :mass: vector of masses or a scalar if all particles have the same mass
  • :temp: vector of temperatures
source
CosmoParticles.ParticlesMethod
Particles(type[, pairs::Pair...])

Create a Particles object with the given type and pairs of Symbol to the property values. These are passed to the underlying Dict. If no pairs are passed to the method, an empty Dict is created.

source
CosmoParticles.ParticlesType
Particles(p::AllParticles, props=nothing)

Materializes the particle properties in a new particle object of type :all.

To only copy certain properties, props can be passed as a tuple of Symbols.

source
CosmoParticles.get_propsFunction
CosmoParticles.get_props(p::AbstractParticles)

Return the property Dict belonging to the particles.

This returns p.props by default if not overridden.

This is not exported and should not be used outside of the defining files for particle types.

source
CosmoParticles.particle_nameFunction
CosmoParticles.particle_name(p::AbstractParticles)

Returns the name of the particle type, which is used when printing an object of this type via Base.show.

This is not exported.

source
CosmoParticles.particle_numberFunction
CosmoParticles.particle_number(p::AbstractParticles)

Returns the number of particles by determining the length of one of the property arrays.

This is not exported.

source
CosmoParticles.show_propertiesMethod
CosmoParticles.show_properties(io::IO, mime, p::AbstractParticles)

Prints the number of particles, the name of the type, and the property names.

Should be used internally when overriding Base.show for concrete implementations of AbstractParticles.

This is not exported.

source